diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 09784a6565a69273f2d16810ae23a5ed24755e30..94d340b9b53a22b6ef06d1c794d8575fe210b137 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -599,6 +599,7 @@ border-color: rgb(255, 255, 255);</string> </widget> <addaction name="actionBackground_Color"/> <addaction name="menuCaption_Color"/> + <addaction name="actionFloor_Color"/> <addaction name="actionWalls_Color"/> <addaction name="actionExits_Color"/> <addaction name="actionNavigation_Lines_Color"/> @@ -628,6 +629,7 @@ border-color: rgb(255, 255, 255);</string> <addaction name="actionShow_Trajectories"/> <addaction name="separator"/> <addaction name="actionShow_Geometry"/> + <addaction name="actionShow_Floor"/> <addaction name="actionShow_Exits"/> <addaction name="actionShow_Walls"/> <addaction name="actionShow_Legend"/> @@ -1286,6 +1288,22 @@ border-color: rgb(255, 255, 255);</string> <string>Navigation Lines Color</string> </property> </action> + <action name="actionFloor_Color"> + <property name="text"> + <string>Floor Color</string> + </property> + </action> + <action name="actionShow_Floor"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="checked"> + <bool>true</bool> + </property> + <property name="text"> + <string>Show Floor</string> + </property> + </action> </widget> <resources> <include location="icons.qrc"/> @@ -2123,6 +2141,38 @@ border-color: rgb(255, 255, 255);</string> </hint> </hints> </connection> + <connection> + <sender>actionShow_Floor</sender> + <signal>changed()</signal> + <receiver>mainwindow</receiver> + <slot>slotShowHideFloor()</slot> + <hints> + <hint type="sourcelabel"> + <x>-1</x> + <y>-1</y> + </hint> + <hint type="destinationlabel"> + <x>224</x> + <y>199</y> + </hint> + </hints> + </connection> + <connection> + <sender>actionFloor_Color</sender> + <signal>triggered()</signal> + <receiver>mainwindow</receiver> + <slot>slotChangeFloorColor()</slot> + <hints> + <hint type="sourcelabel"> + <x>-1</x> + <y>-1</y> + </hint> + <hint type="destinationlabel"> + <x>224</x> + <y>199</y> + </hint> + </hints> + </connection> </connections> <slots> <slot>slotHelpAbout()</slot> @@ -2184,5 +2234,7 @@ border-color: rgb(255, 255, 255);</string> <slot>slotShowHideGeometryCaptions()</slot> <slot>slotShowHideNavLines()</slot> <slot>slotChangeNavLinesColor()</slot> + <slot>slotShowHideFloor()</slot> + <slot>slotChangeFloorColor()</slot> </slots> </ui> diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index c96632e06d99510c2a1a6ff94aa9b1724653eec8..7022cd85579103938949bb534767067056d30124 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1071,6 +1071,14 @@ void MainWindow::slotShowHideNavLines() } } +//todo: add to the system settings +void MainWindow::slotShowHideFloor() +{ + bool status = ui.actionShow_Floor->isChecked(); + visualisationThread->getGeometry()->showFloor(status); + SystemSettings::setShowFloor(status); +} + /// update the playing speed void MainWindow::slotUpdateSpeedSlider(int newValue){ @@ -1470,6 +1478,22 @@ void MainWindow::slotChangeNavLinesColor(){ delete colorDialog; } +void MainWindow::slotChangeFloorColor() +{ + QColorDialog* colorDialog = new QColorDialog(this); + colorDialog->setToolTip("Choose a new color for teh floor"); + QColor col=colorDialog->getColor(Qt::white,this,"Select new floor color"); + + //the user may have cancelled the process + if(col.isValid()==false) return; + + double color[3]={(double)col.red()/255.0 ,(double)col.green()/255.0 ,(double)col.blue()/255.0}; + + visualisationThread->getGeometry()->changeFloorColor(color); + + delete colorDialog; +} + void MainWindow::slotSetCameraPerspectiveToTop(){ int p= 1; //TOP diff --git a/src/MainWindow.h b/src/MainWindow.h index 09761aaea596a7cc5a2f6ed2c127c05b5c2220af..ee30ea8194862c003a46336c219993d7de1d29fb 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -175,18 +175,16 @@ public Q_SLOTS: void slotShowHideWalls(); /// shows/hide navigation lines void slotShowHideNavLines(); + /// shows/hide navigation lines + void slotShowHideFloor(); /// shows/hide geometry captions void slotShowHideGeometryCaptions(); /// show pedestrians only without trail void slotShowPedestrianOnly(); - /// update the playing speed void slotUpdateSpeedSlider(int newValue); - //void slotSpeedSliderPressed(); - //void slotSpeedSliderReleased(); - //void slotSpeedSliderChanged(); /// update the position slider void slotUpdateFrameSlider(int newValue); @@ -246,6 +244,9 @@ public Q_SLOTS: /// change the navigation lines color void slotChangeNavLinesColor(); + /// change the floor color + void slotChangeFloorColor(); + /// show/hide onscreen information /// information include Time and pedestrians left in the facility void slotShowOnScreenInfos(); diff --git a/src/SaxParser.cpp b/src/SaxParser.cpp index 8c580b003b01d9504126adcc7fdc08714cee6dfe..b9901dd9c2a880c90fa5ad6927e4b770c65fe8eb 100644 --- a/src/SaxParser.cpp +++ b/src/SaxParser.cpp @@ -61,6 +61,9 @@ #include <vtkProperty.h> #include <vtkTriangleFilter.h> +#define VTK_CREATE(type, name) \ + vtkSmartPointer<type> name = vtkSmartPointer<type>::New() + using namespace std; @@ -650,6 +653,8 @@ void SaxParser::clearPoints(){ /// provided for convenience and will be removed in the next version void SaxParser::parseGeometryJPS(QString fileName, FacilityGeometry *geometry){ + double captionsColor=0;//red + if(!fileName.endsWith(".xml",Qt::CaseInsensitive)) return ; QString wd; @@ -665,12 +670,9 @@ void SaxParser::parseGeometryJPS(QString fileName, FacilityGeometry *geometry){ int currentID=0; // Setup the points - vtkSmartPointer<vtkPoints> points = - vtkSmartPointer<vtkPoints>::New(); - + VTK_CREATE(vtkPoints,points); // Add the polygon to a list of polygons - vtkSmartPointer<vtkCellArray> polygons = - vtkSmartPointer<vtkCellArray>::New(); + VTK_CREATE(vtkCellArray,polygons); for (int i = 0; i < building->GetNumberOfRooms(); i++) { @@ -688,8 +690,7 @@ void SaxParser::parseGeometryJPS(QString fileName, FacilityGeometry *geometry){ } // Create the polygon - vtkSmartPointer<vtkPolygon> polygon = - vtkSmartPointer<vtkPolygon>::New(); + VTK_CREATE(vtkPolygon,polygon); polygon->GetPointIds()->SetNumberOfIds(poly.size()); for (unsigned int s=0;s<poly.size();s++){ @@ -699,55 +700,83 @@ void SaxParser::parseGeometryJPS(QString fileName, FacilityGeometry *geometry){ polygons->InsertNextCell(polygon); //plot the walls only for not stairs - if(sub->GetType()=="stair") continue; - const vector<Wall>& walls= sub->GetAllWalls(); - for(unsigned int w=0;w<walls.size();w++){ - Point p1 = walls[w].GetPoint1(); - Point p2 = walls[w].GetPoint2(); - double z1= sub->GetElevation(p1); - double z2= sub->GetElevation(p2); - geometry->addWall(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR); + if(sub->GetType()!="stair"){ + const vector<Wall>& walls= sub->GetAllWalls(); + for(unsigned int w=0;w<walls.size();w++){ + Point p1 = walls[w].GetPoint1(); + Point p2 = walls[w].GetPoint2(); + double z1= sub->GetElevation(p1); + double z2= sub->GetElevation(p2); + geometry->addWall(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR); + } } + //insert the subroom caption + string caption=r->GetCaption()+" ( " + QString::number(sub->GetSubRoomID()).toStdString() + " ) "; + const Point& p=sub->GetCentroid(); + double z= sub->GetElevation(p); + double pos[3]={p._x*FAKTOR,p._y*FAKTOR,z*FAKTOR}; + geometry->addObjectLabel(pos,pos,caption,captionsColor); + + //plot the obstacles + const vector<Obstacle*>& obstacles = sub->GetAllObstacles(); + for( unsigned int j=0; j<obstacles.size(); j++) { + Obstacle* obst= obstacles[j]; + const vector<Wall>& walls= obst->GetAllWalls(); + for(unsigned int w=0;w<walls.size();w++){ + Point p1 = walls[w].GetPoint1(); + Point p2 = walls[w].GetPoint2(); + double z1= sub->GetElevation(p1); + double z2= sub->GetElevation(p2); + geometry->addWall(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR); + } + //add the obstacle caption + const Point& p=obst->GetCentroid(); + double z= sub->GetElevation(p); + double pos[3]={p._x*FAKTOR,p._y*FAKTOR,z*FAKTOR}; + geometry->addObjectLabel(pos,pos,obst->GetCaption(),captionsColor); + } } } - // Create a PolyData - vtkSmartPointer<vtkPolyData> polygonPolyData = - vtkSmartPointer<vtkPolyData>::New(); - polygonPolyData->SetPoints(points); + // Create a PolyData to represent the floor + VTK_CREATE(vtkPolyData, polygonPolyData); + polygonPolyData->SetPoints(points); polygonPolyData->SetPolys(polygons); - - //triagulate everything - vtkSmartPointer<vtkTriangleFilter> filter=vtkSmartPointer<vtkTriangleFilter>::New(); - - // Create a mapper and actor - vtkSmartPointer<vtkPolyDataMapper> mapper = - vtkSmartPointer<vtkPolyDataMapper>::New(); - - - -#if VTK_MAJOR_VERSION <= 5 - filter->SetInput(polygonPolyData); - mapper->SetInput(filter->GetOutput()); -#else - filter->SetInputData(polygonPolyData); - mapper->SetInputConnection(filter->GetOutputPort()); -#endif - - vtkSmartPointer<vtkActor> actor = - vtkSmartPointer<vtkActor>::New(); - actor->SetMapper(mapper); - actor->GetProperty()->SetColor(0,0,1); - actor->GetProperty()->SetOpacity(0.5); - //actor->GetProperty()->SetLineWidth(5); - - geometry->getActor2D()->AddPart(actor); - geometry->getActor3D()->AddPart(actor); + geometry->addFloor(polygonPolyData); // add the crossings + const map<int, Crossing*>& crossings=building->GetAllCrossings(); + for (std::map<int, Crossing*>::const_iterator it=crossings.begin(); it!=crossings.end(); ++it) + { + Crossing* cr=it->second; + Point p1 = cr->GetPoint1(); + Point p2 = cr->GetPoint2(); + double z1= cr->GetSubRoom1()->GetElevation(p1); + double z2= cr->GetSubRoom1()->GetElevation(p2); + geometry->addNavLine(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR); + + const Point& p =cr->GetCentre(); + double pos[3]={p._x*FAKTOR,p._y*FAKTOR,z1*FAKTOR}; + geometry->addObjectLabel(pos,pos,"nav_"+QString::number(cr->GetID()).toStdString(),captionsColor); + } + // add the exits + const map<int, Transition*>& transitions=building->GetAllTransitions(); + for (std::map<int, Transition*>::const_iterator it=transitions.begin(); it!=transitions.end(); ++it) + { + Transition* tr=it->second; + Point p1 = tr->GetPoint1(); + Point p2 = tr->GetPoint2(); + double z1= tr->GetSubRoom1()->GetElevation(p1); + double z2= tr->GetSubRoom1()->GetElevation(p2); + geometry->addDoor(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR); + + const Point& p =tr->GetCentre(); + double pos[3]={p._x*FAKTOR,p._y*FAKTOR,z1*FAKTOR}; + geometry->addObjectLabel(pos,pos,"door_"+QString::number(tr->GetID()).toStdString(),captionsColor); + } // free memory delete building; diff --git a/src/SystemSettings.cpp b/src/SystemSettings.cpp index 43be1c214892dc5a74165c8e7837a883edc7e121..8e69f3f90707e5534712622c989af00d59b3f3e9 100644 --- a/src/SystemSettings.cpp +++ b/src/SystemSettings.cpp @@ -44,6 +44,7 @@ bool SystemSettings::showAgentsCaptions=false; bool SystemSettings::is2D=false; bool SystemSettings::showAgents=true; bool SystemSettings::showGeometry=true; +bool SystemSettings::showFloor=true; unsigned short SystemSettings::port=8989; double SystemSettings::bgColor[]={1.0,1.0,1.0}; int SystemSettings::pedestriansColor[3][3]={{255 , 17, 224},{122, 255, 122},{130, 130, 130}}; @@ -127,6 +128,16 @@ bool SystemSettings::getShowGeometry() return showGeometry; } +void SystemSettings::setShowFloor(bool status) +{ + showFloor=status; +} + +bool SystemSettings::getShowFloor() +{ + return showFloor; +} + void SystemSettings::setWorkingDirectory(QString dir) { workingDir=dir; diff --git a/src/SystemSettings.h b/src/SystemSettings.h index 58a12ae684a25fb3ebc70b1b517c5b82d75c911d..df2e8e384c5ef4ce1e795f17686a4824f7e3ebb4 100644 --- a/src/SystemSettings.h +++ b/src/SystemSettings.h @@ -67,6 +67,10 @@ public: void static setShowGeometry(bool status); bool static getShowGeometry(); + // set/get the geometry visibility + void static setShowFloor(bool status); + bool static getShowFloor(); + void static setWorkingDirectory(QString dir); void static getWorkingDirectory(QString& dir); @@ -158,6 +162,7 @@ private: static bool is2D; // Toggle 2D/3D mode static bool showAgents; static bool showGeometry; + static bool showFloor; static unsigned short port; static double bgColor[3]; static int ellipseResolution; diff --git a/src/ThreadVisualisation.cpp b/src/ThreadVisualisation.cpp index 6f70f14e8204d3e37e0d9984c20bf10755bc2f7e..3a51d82366171625e53b9a1c45e9ad99dc128d9a 100644 --- a/src/ThreadVisualisation.cpp +++ b/src/ThreadVisualisation.cpp @@ -151,6 +151,7 @@ void ThreadVisualisation::run(){ //renderer->SetBackground(.00,.00,.00); renderer->SetBackground(1.0,1.0,1.0); //add the geometry + geometry->CreateActors(); renderer->AddActor(geometry->getActor2D()); renderer->AddActor(geometry->getActor3D()); @@ -1045,9 +1046,9 @@ void ThreadVisualisation::setGeometry(FacilityGeometry* geometry){ } FacilityGeometry* ThreadVisualisation::getGeometry() { - //if(geometry==NULL){ //FIXME TODO restore me + if(geometry==NULL){ geometry=new FacilityGeometry(); - //} + } return geometry; } diff --git a/src/geometry/FacilityGeometry.cpp b/src/geometry/FacilityGeometry.cpp index 05b2d74aa4f2eecb6256d4ab8736e688f982f667..150fa885b80da34be9f13cffbe35e85a256f5102 100644 --- a/src/geometry/FacilityGeometry.cpp +++ b/src/geometry/FacilityGeometry.cpp @@ -57,6 +57,7 @@ #include <vtkTextActor3D.h> #include <vtkTextProperty.h> #include <vtkActor2DCollection.h> +#include <vtkTriangleFilter.h> #define PI 3.1415926535 @@ -64,77 +65,80 @@ using namespace std; #define VTK_CREATE(type, name) \ - vtkSmartPointer<type> name = vtkSmartPointer<type>::New() + vtkSmartPointer<type> name = vtkSmartPointer<type>::New() FacilityGeometry::FacilityGeometry() { - assembly = vtkAssembly::New(); - assembly2D = vtkAssembly::New(); - assemblyCaptions= vtkAssembly::New(); + assembly = vtkAssembly::New(); + assembly2D = vtkAssembly::New(); + assemblyCaptions= vtkAssembly::New(); assemblyWalls3D = vtkAssembly::New(); assemblyDoors3D = vtkAssembly::New(); assembly3D = vtkAssembly::New(); - captions=vtkActor2DCollection::New(); - linesPlotter2D = new LinePlotter2D(); - - // initializing the lookup table for the colors - // rainbow colors ranging from red to blue - lookupTable = vtkLookupTable::New(); - lookupTable->SetTableRange(0,255); - //lookupTable->SetHueRange(0.0,0.566); - //lut->SetSaturationRange(0,0); - //lut->SetValueRange(0.0,1.0); - lookupTable->SetNumberOfTableValues(256); - lookupTable->Build(); - - // geometry parameters all in cm - doorThickness = 3; - wallThickness = 3; - wallHeight=250; - doorHeight=250; - stepHeight = 40; - wallColor = 255; - stepColor = 130; - doorColor = 50; + floorActor = vtkActor::New(); + + captions=vtkActor2DCollection::New(); + linesPlotter2D = new LinePlotter2D(); + + // initializing the lookup table for the colors + // rainbow colors ranging from red to blue + lookupTable = vtkLookupTable::New(); + lookupTable->SetTableRange(0,255); + //lookupTable->SetHueRange(0.0,0.566); + //lut->SetSaturationRange(0,0); + //lut->SetValueRange(0.0,1.0); + lookupTable->SetNumberOfTableValues(256); + lookupTable->Build(); + + // geometry parameters all in cm + doorThickness = 3; + wallThickness = 3; + wallHeight=250; + doorHeight=250; + stepHeight = 40; + wallColor = 255; + stepColor = 130; + doorColor = 50; navlineColor=95; } FacilityGeometry::~FacilityGeometry() { - if(assembly) - assembly->Delete(); + if(assembly) + assembly->Delete(); - lookupTable->Delete(); + lookupTable->Delete(); - delete linesPlotter2D; + delete linesPlotter2D; } -//todo: -// each time this is called, the assemblies parts are added -// very bad -vtkAssembly* FacilityGeometry::getActor2D(){ +vtkAssembly* FacilityGeometry::getActor2D() +{ + return assembly2D; +} - assembly2D->AddPart(linesPlotter2D->createAssembly()); - assembly2D->AddPart(assemblyCaptions); +vtkAssembly* FacilityGeometry::getCaptionsActor() +{ + return assemblyCaptions; +} - return assembly2D; +vtkAssembly* FacilityGeometry::getActor3D() +{ + return assembly3D; } - vtkAssembly* FacilityGeometry::getCaptionsActor() - { - return assemblyCaptions; - } +void FacilityGeometry::CreateActors() +{ + assembly2D->AddPart(linesPlotter2D->createAssembly()); + assembly2D->AddPart(assemblyCaptions); - vtkAssembly* FacilityGeometry::getActor3D() - { - assembly3D->AddPart(assemblyDoors3D); - assembly3D->AddPart(assemblyWalls3D); - assembly3D->AddPart(assemblyCaptions); - return assembly3D; - } + assembly3D->AddPart(assemblyDoors3D); + assembly3D->AddPart(assemblyWalls3D); + assembly3D->AddPart(assemblyCaptions); +} //void FacilityGeometry::drawWall(Point *p1, Point *p2){ // double scale =1; @@ -229,7 +233,7 @@ void FacilityGeometry::addNewElement(double center[3], double length, double ori actor->GetProperty()->SetOpacity(0.5); assemblyDoors3D->AddPart(actor); } - break; + break; case WALL: { double colorRGB[3]; @@ -244,7 +248,7 @@ void FacilityGeometry::addNewElement(double center[3], double length, double ori //src->SetRadius(wallWidth); assemblyWalls3D->AddPart(actor); } - break; + break; case STEP: { double colorRGB[3]; @@ -254,9 +258,9 @@ void FacilityGeometry::addNewElement(double center[3], double length, double ori src->SetZLength(stepHeight); assemblyDoors3D->AddPart(actor); } - break; + break; - //default behaviour not defined + //default behaviour not defined default: break; } @@ -270,13 +274,13 @@ void FacilityGeometry::addNewElement(double center[3], double length, double ori void FacilityGeometry::addWall(double x1, double y1, double z1, double x2, double y2, double z2,double thickness,double height,double color){ - // all walls will have this parameters until changed - wallColor=color; + // all walls will have this parameters until changed + wallColor=color; - // if(SystemSettings::get2D()){ - double m[]={x1,y1,z1}; - double n[]={x2,y2,z2}; - linesPlotter2D->PlotWall(m,n,wallColor/255.0); + // if(SystemSettings::get2D()){ + double m[]={x1,y1,z1}; + double n[]={x2,y2,z2}; + linesPlotter2D->PlotWall(m,n,wallColor/255.0); JPoint *p1 = new JPoint(x1,y1,z1); @@ -294,14 +298,14 @@ void FacilityGeometry::addWall(double x1, double y1, double z1, double x2, doubl void FacilityGeometry::addDoor(double x1, double y1, double z1, double x2, double y2, double z2,double thickness ,double height, double color){ - // all doors will take this color upon changed - doorColor=color; - //constructing the 2D assembly - // if(SystemSettings::get2D()){ - double m[]={x1,y1,z1}; - double n[]={x2,y2,z2}; + // all doors will take this color upon changed + doorColor=color; + //constructing the 2D assembly + // if(SystemSettings::get2D()){ + double m[]={x1,y1,z1}; + double n[]={x2,y2,z2}; - linesPlotter2D->PlotDoor(m,n,doorColor/255.0); + linesPlotter2D->PlotDoor(m,n,doorColor/255.0); JPoint *p1 = new JPoint(x1,y1,z1); JPoint *p2 = new JPoint(x2,y2,z2); @@ -327,24 +331,24 @@ void FacilityGeometry::addNavLine(double x1, double y1, double z1, double x2, do linesPlotter2D->PlotNavLine(m,n,navlineColor/255.0); -// JPoint *p1 = new JPoint(x1,y1,z1); -// JPoint *p2 = new JPoint(x2,y2,z2); -// double *center = p1->centreCoordinatesWith(*p2); -// double angle =p1->angleMadeWith(*p2); -// double length =p1->distanceTo(*p2)+wallThickness; + // JPoint *p1 = new JPoint(x1,y1,z1); + // JPoint *p2 = new JPoint(x2,y2,z2); + // double *center = p1->centreCoordinatesWith(*p2); + // double angle =p1->angleMadeWith(*p2); + // double length =p1->distanceTo(*p2)+wallThickness; -// addNewElement(center, length, angle, DOOR); + // addNewElement(center, length, angle, DOOR); -// delete p1; -// delete p2; -// delete center; + // delete p1; + // delete p2; + // delete center; } void FacilityGeometry::addStep(double x1, double y1, double z1, double x2, double y2, double z2) { - double m[]={x1,y1,z1}; - double n[]={x2,y2,z2}; - linesPlotter2D->PlotDoor(m,n,doorColor/255.0); + double m[]={x1,y1,z1}; + double n[]={x2,y2,z2}; + linesPlotter2D->PlotDoor(m,n,doorColor/255.0); JPoint *p1 = new JPoint(x1,y1,z1); JPoint *p2 = new JPoint(x2,y2,z2); @@ -361,18 +365,18 @@ void FacilityGeometry::addStep(double x1, double y1, double z1, double x2, doubl void FacilityGeometry::addStep(JPoint* p1, JPoint* p2){ - double m[3]; - double n[3]; - double CHT[3]; + double m[3]; + double n[3]; + double CHT[3]; - p1->getXYZ(m); - p2->getXYZ(n); - p1->getColorHeightThicknes(CHT); + p1->getXYZ(m); + p2->getXYZ(n); + p1->getColorHeightThicknes(CHT); - stepHeight=CHT[1]; - stepColor = CHT[0]; + stepHeight=CHT[1]; + stepColor = CHT[0]; - linesPlotter2D->PlotDoor(m,n,doorColor/255.0); + linesPlotter2D->PlotDoor(m,n,doorColor/255.0); double *center = p1->centreCoordinatesWith(*p2); double angle =p1->angleMadeWith(*p2); @@ -412,32 +416,32 @@ void FacilityGeometry::addWall(JPoint* p1, JPoint* p2, string caption){ void FacilityGeometry::addDoor(JPoint* p1, JPoint* p2, string caption){ - double m[3]; - double n[3]; - double CHT[3]; + double m[3]; + double n[3]; + double CHT[3]; - p1->getXYZ(m); - p2->getXYZ(n); - //to get the exits over the walls - //m[0]++; m[1]++; m[2]++; - //n[0]++; n[1]++; n[2]++; - p1->getColorHeightThicknes(CHT); + p1->getXYZ(m); + p2->getXYZ(n); + //to get the exits over the walls + //m[0]++; m[1]++; m[2]++; + //n[0]++; n[1]++; n[2]++; + p1->getColorHeightThicknes(CHT); - doorThickness = CHT[2]; - doorHeight=CHT[1]; - doorColor = CHT[0]; + doorThickness = CHT[2]; + doorHeight=CHT[1]; + doorColor = CHT[0]; - linesPlotter2D->PlotDoor(m,n,doorColor/255.0); + linesPlotter2D->PlotDoor(m,n,doorColor/255.0); - if (caption.compare("") != 0){ + if (caption.compare("") != 0){ - double center[3]; - center[0]=0.5*(m[0]+n[0]); - center[1]=0.5*(m[1]+n[1]); - center[2]=0.5*(m[2]+n[2]); - double orientation[3]={0,0,0}; - addNewElementText(center,orientation,caption.c_str(),0); - } + double center[3]; + center[0]=0.5*(m[0]+n[0]); + center[1]=0.5*(m[1]+n[1]); + center[2]=0.5*(m[2]+n[2]); + double orientation[3]={0,0,0}; + addNewElementText(center,orientation,caption.c_str(),0); + } double *center = p1->centreCoordinatesWith(*p2); double angle =p1->angleMadeWith(*p2); @@ -476,73 +480,71 @@ void FacilityGeometry::addNavLine(JPoint* p1, JPoint* p2, string caption){ } +void FacilityGeometry::addFloor(vtkPolyData* polygonPolyData ) +{ + //triagulate everything + // Create a mapper and actor + VTK_CREATE(vtkTriangleFilter,filter); + VTK_CREATE(vtkPolyDataMapper,mapper); + +#if VTK_MAJOR_VERSION <= 5 + filter->SetInput(polygonPolyData); + mapper->SetInput(filter->GetOutput()); +#else + filter->SetInputData(polygonPolyData); + mapper->SetInputConnection(filter->GetOutputPort()); +#endif + + floorActor->SetMapper(mapper); + floorActor->GetProperty()->SetColor(0,0,1); + floorActor->GetProperty()->SetOpacity(0.5); + + assembly2D->AddPart(floorActor); + assembly3D->AddPart(floorActor); +} + + void FacilityGeometry::addFloor(double x1, double y1, double x2, double y2, double z){ - //if(z!=1)return; - const double cellSize=40; //cm - // const int dimX=(x2-x1)/cellSize+1; - // const int dimY=(y2-y1)/cellSize+1; - const int dimX= (int)ceil((x2-x1)/cellSize) +1; - const int dimY= (int)ceil((y2-y1)/cellSize) +1; - - - const int dimZ=1; - //vtkDoubleArray *scalars = vtkDoubleArray::New(); - vtkDataArray* pData = vtkUnsignedCharArray::New(); - pData->SetNumberOfComponents(3); - - double color[2][3]={{100, 100, 100},{150,150,150}}; - bool idx=0; - bool firstIdx=1; - - // for(int i=0;i<dimX-1;i++){ - // firstIdx=!firstIdx; - // idx=firstIdx; - // for(int j=0;j<dimY-1;j++){ - // pData->InsertNextTuple3(color[idx][0],color[idx][1],color[idx][2]); - // idx=!idx; - // } - // } - // bool lastColorUsed=0; - // for(int i=0;i<dimX-1;i++){ - // - // if(idx==lastColorUsed){ - // lastColorUsed= !lastColorUsed; - // idx=lastColorUsed; - // }else{ - // lastColorUsed=idx; - // } - // - // for(int j=0;j<dimY-1;j++){ - // pData->InsertNextTuple3(color[idx][0],color[idx][1],color[idx][2]); - // idx=!idx; - // } - // } - - bool lastColorUsed=0; - for(int i=0;i<dimY-1;i++){ - - if(idx==lastColorUsed){ - lastColorUsed= !lastColorUsed; - idx=lastColorUsed; - }else{ - lastColorUsed=idx; - } - - for(int j=0;j<dimX-1;j++){ - pData->InsertNextTuple3(color[idx][0],color[idx][1],color[idx][2]); - idx=!idx; - } - } - - // data as cellData of imageData - VTK_CREATE(vtkImageData, image); - image->SetDimensions(dimX, dimY, dimZ); - image->SetSpacing(cellSize, cellSize, cellSize); - image->GetCellData()->SetScalars(pData); - - - VTK_CREATE(vtkActor, imageActor); - VTK_CREATE(vtkDataSetMapper, map); + //if(z!=1)return; + const double cellSize=40; //cm + // const int dimX=(x2-x1)/cellSize+1; + // const int dimY=(y2-y1)/cellSize+1; + const int dimX= (int)ceil((x2-x1)/cellSize) +1; + const int dimY= (int)ceil((y2-y1)/cellSize) +1; + + + const int dimZ=1; + //vtkDoubleArray *scalars = vtkDoubleArray::New(); + vtkDataArray* pData = vtkUnsignedCharArray::New(); + pData->SetNumberOfComponents(3); + + double color[2][3]={{100, 100, 100},{150,150,150}}; + bool idx=0; + bool lastColorUsed=0; + for(int i=0;i<dimY-1;i++){ + + if(idx==lastColorUsed){ + lastColorUsed= !lastColorUsed; + idx=lastColorUsed; + }else{ + lastColorUsed=idx; + } + + for(int j=0;j<dimX-1;j++){ + pData->InsertNextTuple3(color[idx][0],color[idx][1],color[idx][2]); + idx=!idx; + } + } + + // data as cellData of imageData + VTK_CREATE(vtkImageData, image); + image->SetDimensions(dimX, dimY, dimZ); + image->SetSpacing(cellSize, cellSize, cellSize); + image->GetCellData()->SetScalars(pData); + + + VTK_CREATE(vtkActor, imageActor); + VTK_CREATE(vtkDataSetMapper, map); #if VTK_MAJOR_VERSION <= 5 map->SetInput(image); @@ -550,95 +552,95 @@ void FacilityGeometry::addFloor(double x1, double y1, double x2, double y2, doub map->SetInputData(image); #endif - //map->SetLookupTable(lookupTable); - imageActor->SetMapper(map); - imageActor->GetProperty()->SetAmbient(0.2); - //imageActor->GetProperty()->SetDiffuse(0.8); + //map->SetLookupTable(lookupTable); + imageActor->SetMapper(map); + imageActor->GetProperty()->SetAmbient(0.2); + //imageActor->GetProperty()->SetDiffuse(0.8); - // move the actor in x-direction - imageActor->SetPosition(x1, y1, z); - assembly2D->AddPart(imageActor); + // move the actor in x-direction + imageActor->SetPosition(x1, y1, z); + assembly2D->AddPart(imageActor); } void FacilityGeometry::addObjectSphere(double center[3], double radius, - double color) { +double color) { - double colorRGB[3]; - lookupTable->GetColor(color, colorRGB); + double colorRGB[3]; + lookupTable->GetColor(color, colorRGB); - //create a disk for the 2D world - { - VTK_CREATE(vtkDiskSource, disk); - disk->SetCircumferentialResolution(10); - disk->SetInnerRadius(0); - disk->SetOuterRadius(radius); + //create a disk for the 2D world + { + VTK_CREATE(vtkDiskSource, disk); + disk->SetCircumferentialResolution(10); + disk->SetInnerRadius(0); + disk->SetOuterRadius(radius); - VTK_CREATE(vtkPolyDataMapper, mapper); - mapper->SetInputConnection(disk->GetOutputPort()); + VTK_CREATE(vtkPolyDataMapper, mapper); + mapper->SetInputConnection(disk->GetOutputPort()); - VTK_CREATE(vtkActor, actor); - actor->SetMapper(mapper); - actor->GetProperty()->SetColor(colorRGB); + VTK_CREATE(vtkActor, actor); + actor->SetMapper(mapper); + actor->GetProperty()->SetColor(colorRGB); - actor->SetPosition(center[0], center[1], center[2]); - assembly2D->AddPart(actor); - } + actor->SetPosition(center[0], center[1], center[2]); + assembly2D->AddPart(actor); + } } void FacilityGeometry::addObjectCylinder(double center[3], double radius, - double height, double orientation[3],double color) { +double height, double orientation[3],double color) { - double colorRGB[3]; - lookupTable->GetColor(color, colorRGB); + double colorRGB[3]; + lookupTable->GetColor(color, colorRGB); - //create a disk for the 2D world - //TODO: this is of course a wrong projection - { - VTK_CREATE(vtkDiskSource, disk); - disk->SetCircumferentialResolution(10); - disk->SetInnerRadius(0); - disk->SetOuterRadius(radius); + //create a disk for the 2D world + //TODO: this is of course a wrong projection + { + VTK_CREATE(vtkDiskSource, disk); + disk->SetCircumferentialResolution(10); + disk->SetInnerRadius(0); + disk->SetOuterRadius(radius); - VTK_CREATE(vtkPolyDataMapper, mapper); - mapper->SetInputConnection(disk->GetOutputPort()); + VTK_CREATE(vtkPolyDataMapper, mapper); + mapper->SetInputConnection(disk->GetOutputPort()); - VTK_CREATE(vtkActor, actor); - actor->SetMapper(mapper); - actor->GetProperty()->SetColor(colorRGB); + VTK_CREATE(vtkActor, actor); + actor->SetMapper(mapper); + actor->GetProperty()->SetColor(colorRGB); - actor->SetPosition(center[0], center[1], center[2]); - assembly2D->AddPart(actor); - } + actor->SetPosition(center[0], center[1], center[2]); + assembly2D->AddPart(actor); + } } void FacilityGeometry::addObjectBox(double center[3], double height, - double width, double length, double color) { - - double colorRGB[3]; - lookupTable->GetColor(color, colorRGB); - - { - VTK_CREATE(vtkCubeSource,src); - src->SetCenter(center[0], center[1], center[2]); - src->SetZLength(1); //todo: fake projection - src->SetYLength(length); - src->SetXLength(width); +double width, double length, double color) { - VTK_CREATE(vtkPolyDataMapper,mapper); - mapper->SetInputConnection(src->GetOutputPort()); + double colorRGB[3]; + lookupTable->GetColor(color, colorRGB); - VTK_CREATE(vtkActor,actor); - actor->GetProperty()->SetLighting(true); - actor->SetOrigin(center[0], center[1], 0); - actor->GetProperty()->SetColor(colorRGB); - actor->GetProperty()->SetAmbient(0.2); - actor->GetProperty()->SetDiffuse(0.8); - actor->SetMapper(mapper); - assembly2D->AddPart(actor); - } + { + VTK_CREATE(vtkCubeSource,src); + src->SetCenter(center[0], center[1], center[2]); + src->SetZLength(1); //todo: fake projection + src->SetYLength(length); + src->SetXLength(width); + + VTK_CREATE(vtkPolyDataMapper,mapper); + mapper->SetInputConnection(src->GetOutputPort()); + + VTK_CREATE(vtkActor,actor); + actor->GetProperty()->SetLighting(true); + actor->SetOrigin(center[0], center[1], 0); + actor->GetProperty()->SetColor(colorRGB); + actor->GetProperty()->SetAmbient(0.2); + actor->GetProperty()->SetDiffuse(0.8); + actor->SetMapper(mapper); + assembly2D->AddPart(actor); + } } void FacilityGeometry::changeWallsColor(double* color) @@ -683,13 +685,18 @@ void FacilityGeometry::changeNavLinesColor(double *color) assembly2D->Modified(); } +void FacilityGeometry::changeFloorColor(double *color) +{ + floorActor->GetProperty()->SetColor(color); +} + void FacilityGeometry::set2D(bool status){ - assembly2D->SetVisibility(status); + assembly2D->SetVisibility(status); } void FacilityGeometry::set3D(bool status){ if(assembly3D!=NULL) - assembly3D->SetVisibility(status); + assembly3D->SetVisibility(status); } void FacilityGeometry::showDoors(bool status){ @@ -732,14 +739,20 @@ void FacilityGeometry::showNavLines(bool status) linesPlotter2D->showNavLines(status); } +void FacilityGeometry::showFloor(bool status) +{ + floorActor->SetVisibility(status); +} + void FacilityGeometry::addObjectLabel(double center[3], double orientation[3], std::string caption, double color){ - addNewElementText(center, orientation, caption, color); + addNewElementText(center, orientation, caption, color); } vtkActor2DCollection* FacilityGeometry::getCaptions(){ - return captions; + return captions; } + // orientation and color ignored void FacilityGeometry::addNewElementText(double center[3], double orientation[3], string text, double color) { @@ -772,14 +785,14 @@ string text, double color) { void FacilityGeometry::showGeometryLabels(int status){ - vtkProp3DCollection* col=assemblyCaptions->GetParts(); - assemblyCaptions->GetActors(col); + vtkProp3DCollection* col=assemblyCaptions->GetParts(); + assemblyCaptions->GetActors(col); - int count = col->GetNumberOfItems(); - for (int i=0;i<count;i++){ - ((vtkActor*)col->GetItemAsObject(i))->SetVisibility(status); - } - assemblyCaptions->Modified(); + int count = col->GetNumberOfItems(); + for (int i=0;i<count;i++){ + ((vtkActor*)col->GetItemAsObject(i))->SetVisibility(status); + } + assemblyCaptions->Modified(); } diff --git a/src/geometry/FacilityGeometry.h b/src/geometry/FacilityGeometry.h index 4bf7d2c4ac7321bc1b610787c964156fecca6154..3f885a84817d34216095b19abcd0880fd16d8938 100644 --- a/src/geometry/FacilityGeometry.h +++ b/src/geometry/FacilityGeometry.h @@ -74,6 +74,8 @@ public: vtkActor2DCollection* getCaptions(); + void CreateActors(); + ///draw a wall void addWall(double x1, double y1, double z1, double x2, double y2, double z2, double thickness=15, double height=250,double col=255); //void addWall(double center[3], double width, double orientation); @@ -96,6 +98,7 @@ public: /// draw a floor, divided in cells, void addFloor(double x1, double y1, double x2, double y2, double z=0); + void addFloor(vtkPolyData* polygonPolyData); /// draw other kinds of objects void addObjectSphere(double center[3], double radius, double couleur=1); @@ -107,6 +110,7 @@ public: void changeWallsColor(double* color); void changeExitsColor(double* color); void changeNavLinesColor(double* color); + void changeFloorColor(double* color); void set2D(bool status); void set3D(bool status); @@ -115,7 +119,8 @@ public: void showStairs(bool status); void showWalls(bool status); void showNavLines(bool status); - void showGeometryLabels(int v); + void showFloor(bool status); + void showGeometryLabels(int status); private: @@ -151,6 +156,8 @@ private: vtkAssembly* assemblyDoors3D; vtkAssembly* assembly3D; + vtkActor* floorActor; + // other parts vtkAssembly* assemblyCaptions; vtkActor2DCollection* captions;