diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 71c85ab82a8685ef7c948c56bfa2458a4170927d..09784a6565a69273f2d16810ae23a5ed24755e30 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -601,6 +601,7 @@ border-color: rgb(255, 255, 255);</string> <addaction name="menuCaption_Color"/> <addaction name="actionWalls_Color"/> <addaction name="actionExits_Color"/> + <addaction name="actionNavigation_Lines_Color"/> <addaction name="separator"/> <addaction name="actionPedestrian_Shape"/> <addaction name="actionNetwork_settings"/> @@ -634,6 +635,7 @@ border-color: rgb(255, 255, 255);</string> <addaction name="actionShow_Wall_Caption"/> <addaction name="actionShow_Room_Caption"/> <addaction name="actionShow_Door_Caption"/> + <addaction name="actionShow_Navigation_Lines"/> <addaction name="actionShow_Geometry_Captions"/> <addaction name="actionFirst_Group"/> <addaction name="actionSecond_Group"/> @@ -1268,9 +1270,20 @@ border-color: rgb(255, 255, 255);</string> <string>Show Geometry Captions</string> </property> </action> - <action name="actionTest"> + <action name="actionShow_Navigation_Lines"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="checked"> + <bool>true</bool> + </property> <property name="text"> - <string>test</string> + <string>Show Navigation Lines</string> + </property> + </action> + <action name="actionNavigation_Lines_Color"> + <property name="text"> + <string>Navigation Lines Color</string> </property> </action> </widget> @@ -2078,6 +2091,38 @@ border-color: rgb(255, 255, 255);</string> </hint> </hints> </connection> + <connection> + <sender>actionNavigation_Lines_Color</sender> + <signal>triggered()</signal> + <receiver>mainwindow</receiver> + <slot>slotChangeNavLinesColor()</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>actionShow_Navigation_Lines</sender> + <signal>changed()</signal> + <receiver>mainwindow</receiver> + <slot>slotShowHideNavLines()</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> @@ -2137,5 +2182,7 @@ border-color: rgb(255, 255, 255);</string> <slot>slotShowHideExits()</slot> <slot>slotShowHideWalls()</slot> <slot>slotShowHideGeometryCaptions()</slot> + <slot>slotShowHideNavLines()</slot> + <slot>slotChangeNavLinesColor()</slot> </slots> </ui> diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index f48b9304e7ef7a1ec930317770918ac725d832de..c96632e06d99510c2a1a6ff94aa9b1724653eec8 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -454,7 +454,7 @@ bool MainWindow::parsePedestrianShapes(QDomNode shapeNode, int groupID){ QDomNodeList agents = shapeNode.toElement().elementsByTagName("agentInfo"); - for (unsigned int i = 0; i < agents.length(); i++) { + for (int i = 0; i < agents.length(); i++) { bool ok=false; int id=agents.item(i).toElement().attribute("ID").toInt(&ok); @@ -1027,6 +1027,7 @@ void MainWindow::slotShowGeometry(){ ui.actionShow_Exits->setEnabled(true); ui.actionShow_Walls->setEnabled(true); ui.actionShow_Geometry_Captions->setEnabled(true); + ui.actionShow_Navigation_Lines->setEnabled(true); SystemSettings::setShowGeometry(true); } else{ @@ -1034,6 +1035,7 @@ void MainWindow::slotShowGeometry(){ ui.actionShow_Exits->setEnabled(false); ui.actionShow_Walls->setEnabled(false); ui.actionShow_Geometry_Captions->setEnabled(false); + ui.actionShow_Navigation_Lines->setEnabled(false); SystemSettings::setShowGeometry(false); } extern_force_system_update=true; @@ -1059,6 +1061,16 @@ void MainWindow::slotShowHideWalls(){ } } +void MainWindow::slotShowHideNavLines() +{ + if (ui.actionShow_Navigation_Lines->isChecked()){ + visualisationThread->showNavLines(true); + } + else{ + visualisationThread->showNavLines(false); + } +} + /// update the playing speed void MainWindow::slotUpdateSpeedSlider(int newValue){ @@ -1428,16 +1440,32 @@ void MainWindow::slotChangeWallsColor(){ /// change the exits color void MainWindow::slotChangeExitsColor(){ + QColorDialog* colorDialog = new QColorDialog(this); + colorDialog->setToolTip("Choose a new color for the exits"); + QColor col=colorDialog->getColor(Qt::white,this,"Select new exit 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->setExitsColor(color); + + delete colorDialog; +} + +/// change the navigation lines colors +void MainWindow::slotChangeNavLinesColor(){ QColorDialog* colorDialog = new QColorDialog(this); colorDialog->setToolTip("Choose a new color for walls"); - QColor col=colorDialog->getColor(Qt::white,this,"Select new wall color"); + QColor col=colorDialog->getColor(Qt::white,this,"Select new navigation lines color"); //the user may have cancelled the process if(col.isValid()==false) return; - double bkcolor[3]={(double)col.red()/255.0 ,(double)col.green()/255.0 ,(double)col.blue()/255.0}; + double color[3]={(double)col.red()/255.0 ,(double)col.green()/255.0 ,(double)col.blue()/255.0}; - visualisationThread->setExitsColor(bkcolor); + visualisationThread->setNavLinesColor(color); delete colorDialog; } diff --git a/src/MainWindow.h b/src/MainWindow.h index 6c5e91e1035459f675c02c8fc03cd52f31f31e2a..09761aaea596a7cc5a2f6ed2c127c05b5c2220af 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -173,6 +173,8 @@ public Q_SLOTS: void slotShowHideExits(); /// shows/hide geometry void slotShowHideWalls(); + /// shows/hide navigation lines + void slotShowHideNavLines(); /// shows/hide geometry captions void slotShowHideGeometryCaptions(); @@ -241,6 +243,9 @@ public Q_SLOTS: /// change the exits color void slotChangeExitsColor(); + /// change the navigation lines color + void slotChangeNavLinesColor(); + /// show/hide onscreen information /// information include Time and pedestrians left in the facility void slotShowOnScreenInfos(); @@ -249,8 +254,6 @@ private: Q_SIGNALS: void signal_controlSequence(QString); - - protected: virtual void closeEvent(QCloseEvent* event); void dragEnterEvent(QDragEnterEvent *event); diff --git a/src/SaxParser.cpp b/src/SaxParser.cpp index 2d21f305dfe0503d1e959667e5c275bd1b120f84..8c580b003b01d9504126adcc7fdc08714cee6dfe 100644 --- a/src/SaxParser.cpp +++ b/src/SaxParser.cpp @@ -37,6 +37,7 @@ #include "geometry/JPoint.h" #include "geometry/FacilityGeometry.h" #include "geometry/Building.h" +#include "geometry/Wall.h" #include "SystemSettings.h" #include <QMessageBox> @@ -77,6 +78,7 @@ SaxParser::SaxParser(FacilityGeometry* geo, SyncData* data, double* fps){ dataset=data; para=fps; parsingWalls=false; + parsingCrossings=false; color=0.0; dataset->clearFrames(); @@ -344,6 +346,36 @@ bool SaxParser::startElement(const QString & /* namespaceURI */, } } + } + //FIXME + else if (qName == "crossing") + { + parsingWalls=false; + parsingCrossings=true; + thickness=15; + height=250; + color=255; + caption=""; + + for(int i=0;i<at.length();i++){ + if(at.localName(i)=="thickness") + { + thickness=at.value(i).toDouble()*FAKTOR; + } + else if(at.localName(i)=="height") + { + height=at.value(i).toDouble()*FAKTOR; + } + else if(at.localName(i)=="color") + { + color=at.value(i).toDouble(); + } + else if(at.localName(i)=="caption") + { + caption=at.value(i); + } + } + } else if (qName == "timeFirstFrame") { @@ -550,6 +582,11 @@ bool SaxParser::endElement(const QString & /* namespaceURI */, geometry->addDoor(currentPointsList[i],currentPointsList[i+1],caption.toStdString()); } clearPoints(); + } else if (qName == "crossing") { + for(unsigned int i=0;i<currentPointsList.size()-1;i++){ + geometry->addNavLine(currentPointsList[i],currentPointsList[i+1],caption.toStdString()); + } + clearPoints(); } else if (qName == "step") {//FIXME for(unsigned int i=0;i<currentPointsList.size()-1;i++){ geometry->addDoor(currentPointsList[i],currentPointsList[i+1],caption.toStdString()); @@ -599,9 +636,6 @@ bool SaxParser::attributeDecl(const QString& eName, const QString& aName, } void SaxParser::clearPoints(){ - -// currentPointsList.clear(); - while (!currentPointsList.empty()){ delete currentPointsList.back(); currentPointsList.pop_back(); @@ -638,12 +672,15 @@ void SaxParser::parseGeometryJPS(QString fileName, FacilityGeometry *geometry){ vtkSmartPointer<vtkCellArray> polygons = vtkSmartPointer<vtkCellArray>::New(); - for (int i = 0; i < building->GetNumberOfRooms(); i++) { + for (int i = 0; i < building->GetNumberOfRooms(); i++) + { Room* r = building->GetRoom(i); //string caption = r->GetCaption(); - for (int k = 0; k < r->GetNumberOfSubRooms(); k++) { + for (int k = 0; k < r->GetNumberOfSubRooms(); k++) + { SubRoom* sub = r->GetSubRoom(k); + vector<Point> poly = sub->GetPolygon(); if(sub->IsClockwise()==true){ @@ -659,8 +696,19 @@ void SaxParser::parseGeometryJPS(QString fileName, FacilityGeometry *geometry){ points->InsertNextPoint(poly[s]._x*FAKTOR,poly[s]._y*FAKTOR,sub->GetElevation(poly[s])*FAKTOR); polygon->GetPointIds()->SetId(s, currentID++); } - 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); + } + } } @@ -695,6 +743,11 @@ void SaxParser::parseGeometryJPS(QString fileName, FacilityGeometry *geometry){ //actor->GetProperty()->SetLineWidth(5); geometry->getActor2D()->AddPart(actor); + geometry->getActor3D()->AddPart(actor); + + + // add the crossings + // add the exits // free memory delete building; @@ -1004,6 +1057,7 @@ void SaxParser::parseGeometryXMLV04(QString filename, FacilityGeometry *geo){ } QDomNodeList xCrossingsList=doc.elementsByTagName("crossing"); + for (int i = 0; i < xCrossingsList.length(); i++) { QDomElement xCrossing = xCrossingsList.item(i).toElement(); QDomNodeList xVertices=xCrossing.elementsByTagName("vertex"); @@ -1013,7 +1067,7 @@ void SaxParser::parseGeometryXMLV04(QString filename, FacilityGeometry *geo){ //door height default to 250 cm double height = xCrossing.attribute("height","250").toDouble(); //door color default to blue - double color = xCrossing.attribute("color","255").toDouble(); + double color = xCrossing.attribute("color","120").toDouble(); QString id= xCrossing.attribute("id","-1"); double x1=xVertices.item(0).toElement().attribute("px", "0").toDouble()*xToCmfactor; @@ -1023,14 +1077,14 @@ void SaxParser::parseGeometryXMLV04(QString filename, FacilityGeometry *geo){ double x2=xVertices.item(1).toElement().attribute("px", "0").toDouble()*xToCmfactor; double y2=xVertices.item(1).toElement().attribute("py", "0").toDouble()*xToCmfactor; double z2=xVertices.item(1).toElement().attribute("pz", "0").toDouble()*xToCmfactor; - geo->addDoor(x1, y1, z1, x2, y2,z2,thickness,height,color); + geo->addNavLine(x1, y1, z1, x2, y2,z2,thickness,height,color); double center[3]={(x1+x2)/2.0, (y1+y2)/2.0, (z2+z1)/2.0}; geo->addObjectLabel(center,center,id.toStdString(),21); } QDomNodeList xTransitionsList=doc.elementsByTagName("transition"); - for ( int i = 0; i < xTransitionsList.length(); i++) { + for (int i = 0; i < xTransitionsList.length(); i++) { QDomElement xTransition = xTransitionsList.item(i).toElement(); QDomNodeList xVertices=xTransition.elementsByTagName("vertex"); diff --git a/src/SaxParser.h b/src/SaxParser.h index 14699cd8a46b1d7dbb20065c3bbee4c815c2bf05..382bec30453a79fe004d1954f348b9aca516c7a4 100644 --- a/src/SaxParser.h +++ b/src/SaxParser.h @@ -89,6 +89,7 @@ private: std::vector<FrameElement *> currentFrame; //std::vector<TrajectoryPoint *> currentFrame; bool parsingWalls; + bool parsingCrossings; //wall and door parameters double thickness; diff --git a/src/ThreadVisualisation.cpp b/src/ThreadVisualisation.cpp index 534cadea0ca5a5db4d24f35c461d88e4328f5635..6f70f14e8204d3e37e0d9984c20bf10755bc2f7e 100644 --- a/src/ThreadVisualisation.cpp +++ b/src/ThreadVisualisation.cpp @@ -337,8 +337,10 @@ void ThreadVisualisation::run(){ double col[3]={82.0/255,218.0 /255.0,255.0/255.0}; double wallcol[3]={180.0/255,180.0/255.0,180.0/255.0}; double exitcol[3]={175.0/255,175.0/255.0,255.0/255.0}; + double navlinecol[3]={165.0/255,175.0/255.0,225.0/255.0}; setExitsColor(exitcol); setWallsColor(wallcol); + //setNavLinesColor(navlinecol); //showDoors(false); } //renderWinInteractor->Initialize(); @@ -401,7 +403,14 @@ void ThreadVisualisation::showWalls(bool status){ void ThreadVisualisation::showDoors(bool status){ if(geometry){ geometry->showDoors(status); - } + } +} + +void ThreadVisualisation::showNavLines(bool status) +{ + if(geometry){ + geometry->showNavLines(status); + } } void ThreadVisualisation::initGlyphs2D() @@ -1051,7 +1060,12 @@ void ThreadVisualisation::setGeometryLabelsVisibility(int v){ } void ThreadVisualisation::setExitsColor(double* color){ - geometry->changeExitsColor(color); + geometry->changeExitsColor(color); +} + +void ThreadVisualisation::setNavLinesColor(double *color) +{ + geometry->changeNavLinesColor(color); } /// enable/disable 2D diff --git a/src/ThreadVisualisation.h b/src/ThreadVisualisation.h index 3be0ddada3eedf169512a175bb215c96b52755b8..ad56e15ec40cb47f767761ff018d80130ec3f590 100644 --- a/src/ThreadVisualisation.h +++ b/src/ThreadVisualisation.h @@ -125,12 +125,18 @@ public: /// change the exits color. void setExitsColor(double* color); + /// change the exits color. + void setNavLinesColor(double* color); + /// show / hide the walls void showWalls(bool status); /// show/ hide the exits void showDoors(bool status); + /// show/ hide the exits + void showNavLines(bool status); + /// show / hide stairs ///not implemented void showStairs(bool status); diff --git a/src/geometry/FacilityGeometry.cpp b/src/geometry/FacilityGeometry.cpp index f0001c774d0ee7d293bede903664de0e7d4ea7b0..05b2d74aa4f2eecb6256d4ab8736e688f982f667 100644 --- a/src/geometry/FacilityGeometry.cpp +++ b/src/geometry/FacilityGeometry.cpp @@ -99,7 +99,7 @@ FacilityGeometry::FacilityGeometry() { wallColor = 255; stepColor = 130; doorColor = 50; - + navlineColor=95; } FacilityGeometry::~FacilityGeometry() { @@ -316,6 +316,30 @@ void FacilityGeometry::addDoor(double x1, double y1, double z1, double x2, doubl delete center; } +void FacilityGeometry::addNavLine(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 + navlineColor=color; + //constructing the 2D assembly + // if(SystemSettings::get2D()){ + double m[]={x1,y1,z1}; + double n[]={x2,y2,z2}; + + 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; + +// addNewElement(center, length, angle, DOOR); + +// 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}; @@ -421,6 +445,36 @@ void FacilityGeometry::addDoor(JPoint* p1, JPoint* p2, string caption){ addNewElement( center, length, angle, DOOR); } +void FacilityGeometry::addNavLine(JPoint* p1, JPoint* p2, string caption){ + + 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); + + doorThickness = CHT[2]; + doorHeight=CHT[1]; + doorColor = CHT[0]; + + linesPlotter2D->PlotNavLine(m,n,doorColor/255.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); + } +} + void FacilityGeometry::addFloor(double x1, double y1, double x2, double y2, double z){ //if(z!=1)return; @@ -622,6 +676,13 @@ void FacilityGeometry::changeExitsColor(double* color) } +void FacilityGeometry::changeNavLinesColor(double *color) +{ + //2D part + linesPlotter2D->changeNavLinesColor(color); + assembly2D->Modified(); +} + void FacilityGeometry::set2D(bool status){ assembly2D->SetVisibility(status); } @@ -646,11 +707,13 @@ void FacilityGeometry::showDoors(bool status){ assemblyDoors3D->Modified(); } -void FacilityGeometry::showStairs(bool status){ +void FacilityGeometry::showStairs(bool status) +{ } -void FacilityGeometry::showWalls(bool status){ +void FacilityGeometry::showWalls(bool status) +{ linesPlotter2D->showWalls(status); assembly2D->Modified(); @@ -664,6 +727,11 @@ void FacilityGeometry::showWalls(bool status){ assemblyWalls3D->Modified(); } +void FacilityGeometry::showNavLines(bool status) +{ + linesPlotter2D->showNavLines(status); +} + void FacilityGeometry::addObjectLabel(double center[3], double orientation[3], std::string caption, double color){ addNewElementText(center, orientation, caption, color); } diff --git a/src/geometry/FacilityGeometry.h b/src/geometry/FacilityGeometry.h index 49aae3ed57c879cd33668431d41da42cfc284659..4bf7d2c4ac7321bc1b610787c964156fecca6154 100644 --- a/src/geometry/FacilityGeometry.h +++ b/src/geometry/FacilityGeometry.h @@ -90,7 +90,11 @@ public: //void addStep(double center[3], double width, double orientation); void addStep(JPoint* p1, JPoint* p2); - /// draw a floor, divided in cells, + /// draw a navigation line + void addNavLine(double x1, double y1, double z1, double x2, double y2, double z2, double thickness=2, double height=250, double color=95); + void addNavLine(JPoint* p1, JPoint* p2, std::string caption=""); + + /// draw a floor, divided in cells, void addFloor(double x1, double y1, double x2, double y2, double z=0); /// draw other kinds of objects @@ -102,6 +106,7 @@ public: void changeWallsColor(double* color); void changeExitsColor(double* color); + void changeNavLinesColor(double* color); void set2D(bool status); void set3D(bool status); @@ -109,6 +114,7 @@ public: void showDoors(bool status); void showStairs(bool status); void showWalls(bool status); + void showNavLines(bool status); void showGeometryLabels(int v); @@ -130,6 +136,7 @@ private: double wallColor; double stepColor; double doorColor; + double navlineColor; // geometry assembly vtkAssembly* assembly; @@ -138,8 +145,8 @@ private: LinePlotter2D* linesPlotter2D; vtkAssembly* assembly2D; -// // 3-d parts -// vtkAssembly* assemblyObjects; + // 3-d parts + //vtkAssembly* assemblyObjects; vtkAssembly* assemblyWalls3D; vtkAssembly* assemblyDoors3D; vtkAssembly* assembly3D; diff --git a/src/geometry/LinePlotter2D.cpp b/src/geometry/LinePlotter2D.cpp index 44e35e8d44a084aac67cd2eb1200e3a24ba3b7df..0ea0de3ae5a5cd6346235640cd645923ec6fe606 100644 --- a/src/geometry/LinePlotter2D.cpp +++ b/src/geometry/LinePlotter2D.cpp @@ -52,41 +52,46 @@ bool LinePlotter2D::doorColorsToDefault=true; LinePlotter2D::LinePlotter2D() -:m_scalarMin(0.0), m_scalarMax(1.0) { - assembly=vtkAssembly::New(); - - door_mapper= vtkPolyDataMapper::New(); - door_actor= vtkActor::New(); - door_points = vtkPoints::New(); - door_lines = vtkCellArray::New(); - door_lineScalars = vtkFloatArray::New(); - door_curPointID=0; - door_width=3.5; - - wall_mapper= vtkPolyDataMapper::New(); - wall_actor= vtkActor::New(); - wall_points = vtkPoints::New(); - wall_lines = vtkCellArray::New(); - wall_lineScalars = vtkFloatArray::New(); - wall_curPointID=0; - wall_width=2; - - - // create a color lookup table - m_lookupTable = vtkLookupTable::New(); - m_lookupTable->SetTableRange(0,255); - m_lookupTable->SetNumberOfTableValues(256); - - // m_lookupTable->SetHueRange(0.0,0.566); - // m_lookupTable->SetSaturationRange(0,0); - // m_lookupTable->SetValueRange(0.0,1.0); - - //m_lookupTable->SetHueRange(0.0,0.0); - //m_lookupTable->SetValueRange(0.0,1.0); - //m_lookupTable->SetSaturationRange(0.0,0.0); - m_lookupTable->Build(); + assembly=vtkAssembly::New(); + + door_mapper= vtkPolyDataMapper::New(); + door_actor= vtkActor::New(); + door_points = vtkPoints::New(); + door_lines = vtkCellArray::New(); + door_lineScalars = vtkFloatArray::New(); + door_curPointID=0; + door_width=3.5; + + wall_mapper= vtkPolyDataMapper::New(); + wall_actor= vtkActor::New(); + wall_points = vtkPoints::New(); + wall_lines = vtkCellArray::New(); + wall_lineScalars = vtkFloatArray::New(); + wall_curPointID=0; + wall_width=2; + + navline_curPointID =0; + navline_width=2; + navline_points= vtkPoints::New(); + navline_lines=vtkCellArray::New(); + navline_lineScalars= vtkFloatArray::New(); + navline_mapper=vtkPolyDataMapper::New(); + navline_actor= vtkActor::New(); + + // create a color lookup table + m_lookupTable = vtkLookupTable::New(); + m_lookupTable->SetTableRange(0,255); + m_lookupTable->SetNumberOfTableValues(256); + + //m_lookupTable->SetHueRange(0.0,0.566); + //m_lookupTable->SetSaturationRange(0,0); + //m_lookupTable->SetValueRange(0.0,1.0); + //m_lookupTable->SetHueRange(0.0,0.0); + //m_lookupTable->SetValueRange(0.0,1.0); + //m_lookupTable->SetSaturationRange(0.0,0.0); + m_lookupTable->Build(); @@ -108,13 +113,6 @@ LinePlotter2D::~LinePlotter2D(){ wall_actor->Delete(); } -void LinePlotter2D::SetScalarRange(double minval, double maxval) -{ - m_scalarMin = minval ; - m_scalarMax = maxval ; -} - - void LinePlotter2D::SetAllLineWidth(int width) { //m_allLineWidth = width ; @@ -143,7 +141,29 @@ void LinePlotter2D::changeWallsColor(double *col) //first switch off the automatic mapping wall_mapper->SetScalarVisibility(0); //then set the new color - wall_actor->GetProperty()->SetColor(col); + wall_actor->GetProperty()->SetColor(col); +} + +void LinePlotter2D::PlotNavLine(double m[], double n[], double scalar) +{ + navline_points->InsertNextPoint(m); + navline_lineScalars->InsertNextTuple1(scalar); + navline_points->InsertNextPoint(n); + navline_lineScalars->InsertNextTuple1(scalar); + + navline_lines->InsertNextCell(2); + navline_lines->InsertCellPoint(navline_curPointID); + navline_lines->InsertCellPoint(navline_curPointID+1); + + navline_curPointID+=2; +} + +void LinePlotter2D::changeNavLinesColor(double *col) +{ + //first switch off the automatic mapping + navline_mapper->SetScalarVisibility(0); + //then set the new color + navline_actor->GetProperty()->SetColor(col); } void LinePlotter2D::changeDoorsColor(double *col) @@ -198,71 +218,97 @@ void LinePlotter2D::PlotWall(double m[3], double n[3], double scalar) // return actor ; //} -vtkAssembly* LinePlotter2D::createAssembly(){ - //doors - { - // Create poly data - //vtkPolyData* polyData =vtkPolyData::New(); - VTK_CREATE(vtkPolyData,polyData); - polyData->SetPoints(door_points); - polyData->SetLines(door_lines); - polyData->GetPointData()->SetScalars(door_lineScalars); +vtkAssembly* LinePlotter2D::createAssembly() +{ + //doors + { + // Create poly data + //vtkPolyData* polyData =vtkPolyData::New(); + VTK_CREATE(vtkPolyData,polyData); + polyData->SetPoints(door_points); + polyData->SetLines(door_lines); + polyData->GetPointData()->SetScalars(door_lineScalars); - // create mapper + // create mapper #if VTK_MAJOR_VERSION <= 5 door_mapper->SetInput(polyData); #else door_mapper->SetInputData(polyData); #endif - door_mapper->SetLookupTable(m_lookupTable); - door_mapper->SetColorModeToMapScalars(); - //mapper->SetScalarRange(m_scalarMin, m_scalarMax); - door_mapper->SetScalarModeToUsePointData(); - // create actor - door_actor->SetMapper(door_mapper); - door_actor->GetProperty()->SetLineWidth(door_width); - assembly->AddPart(door_actor); - - //if default, then hide all doors - // fixme: not working - if(doorColorsToDefault){ - double col[3]={1.0,1.0,1.0}; - SystemSettings::getBackgroundColor(col); - door_actor->GetProperty()->SetColor(col); - door_actor->Modified(); - } - } - - //walls - { - // Create poly data - VTK_CREATE(vtkPolyData,polyData); - polyData->SetPoints(wall_points); - polyData->SetLines(wall_lines); - polyData->GetPointData()->SetScalars(wall_lineScalars); + door_mapper->SetLookupTable(m_lookupTable); + door_mapper->SetColorModeToMapScalars(); + door_mapper->SetScalarModeToUsePointData(); + // create actor + door_actor->SetMapper(door_mapper); + door_actor->GetProperty()->SetLineWidth(door_width); + assembly->AddPart(door_actor); + + //if default, then hide all doors + // fixme: not working + if(doorColorsToDefault){ + double col[3]={1.0,1.0,1.0}; + SystemSettings::getBackgroundColor(col); + door_actor->GetProperty()->SetColor(col); + door_actor->Modified(); + } + } + + //walls + { + // Create poly data + VTK_CREATE(vtkPolyData,polyData); + polyData->SetPoints(wall_points); + polyData->SetLines(wall_lines); + polyData->GetPointData()->SetScalars(wall_lineScalars); // create mapper #if VTK_MAJOR_VERSION <= 5 wall_mapper->SetInput(polyData); #else wall_mapper->SetInputData(polyData); #endif - wall_mapper->SetLookupTable(m_lookupTable); - wall_mapper->SetColorModeToMapScalars(); - //mapper->SetScalarRange(m_scalarMin, m_scalarMax); - wall_mapper->SetScalarModeToUsePointData(); - // create actor - wall_actor->SetMapper(wall_mapper); - wall_actor->GetProperty()->SetLineWidth(wall_width); - assembly->AddPart(wall_actor); - } - - return assembly; + wall_mapper->SetLookupTable(m_lookupTable); + wall_mapper->SetColorModeToMapScalars(); + wall_mapper->SetScalarModeToUsePointData(); + // create actor + wall_actor->SetMapper(wall_mapper); + wall_actor->GetProperty()->SetLineWidth(wall_width); + assembly->AddPart(wall_actor); + } + + //navlines + { + // Create poly data + VTK_CREATE(vtkPolyData,polyData); + polyData->SetPoints(navline_points); + polyData->SetLines(navline_lines); + polyData->GetPointData()->SetScalars(navline_lineScalars); + // create mapper +#if VTK_MAJOR_VERSION <= 5 + navline_mapper->SetInput(polyData); +#else + navline_mapper->SetInputData(polyData); +#endif + navline_mapper->SetLookupTable(m_lookupTable); + navline_mapper->SetColorModeToMapScalars(); + navline_mapper->SetScalarModeToUsePointData(); + // create actor + navline_actor->SetMapper(navline_mapper); + navline_actor->GetProperty()->SetLineWidth(navline_width); + assembly->AddPart(navline_actor); + } + + return assembly; } void LinePlotter2D::showDoors(bool status){ door_actor->SetVisibility(status); } void LinePlotter2D::showWalls(bool status){ - wall_actor->SetVisibility(status); + wall_actor->SetVisibility(status); +} + +void LinePlotter2D::showNavLines(bool status) +{ + navline_actor->SetVisibility(status); } diff --git a/src/geometry/LinePlotter2D.h b/src/geometry/LinePlotter2D.h index 4304577fe695a5305085e6b4b4382b4514b05b6b..46776870578a6294bb083f4bcfec5807c6006f98 100644 --- a/src/geometry/LinePlotter2D.h +++ b/src/geometry/LinePlotter2D.h @@ -50,8 +50,6 @@ public: LinePlotter2D(); ~LinePlotter2D(); - void SetScalarRange(double minval=0.0, double maxval=1.0); - void SetAllLineWidth(int width = 1); void PlotDoor(double m[3], double n[3], double scalar); @@ -60,24 +58,26 @@ public: void PlotWall(double m[3], double n[3], double scalar); void changeWallsColor(double *col); + + void PlotNavLine(double m[3], double n[3], double scalar); + void changeNavLinesColor(double *col); + void showDoors(bool status); void showWalls(bool status); + void showNavLines(bool status); vtkAssembly* createAssembly(); static bool doorColorsToDefault; private: - double m_scalarMin, m_scalarMax ; vtkLookupTable* m_lookupTable ; - - vtkAssembly* assembly; /// doors parameters int door_curPointID ; - float door_width; + double door_width; vtkPoints* door_points; vtkCellArray* door_lines; vtkFloatArray* door_lineScalars ; @@ -86,13 +86,22 @@ private: /// walls parameters int wall_curPointID ; - float wall_width; + double wall_width; vtkPoints* wall_points; vtkCellArray* wall_lines; vtkFloatArray* wall_lineScalars ; vtkPolyDataMapper* wall_mapper; vtkActor* wall_actor; + /// navigation lines parameters + int navline_curPointID ; + double navline_width; + vtkPoints* navline_points; + vtkCellArray* navline_lines; + vtkFloatArray* navline_lineScalars ; + vtkPolyDataMapper* navline_mapper; + vtkActor* navline_actor; + }; #endif // LINE_PLOTTER2D_H