diff --git a/JPSvis.pro b/JPSvis.pro index 334a50ea1e6b6ebe0a0d3cf27a28d8d479321fdb..b74510598845b27da683e5044caa9866e0c76de0 100644 --- a/JPSvis.pro +++ b/JPSvis.pro @@ -1,21 +1,23 @@ TEMPLATE = app TARGET = TraVisTo CONFIG += qt -#CONFIG += static +CONFIG += static QT += xml network #avoid some annoying dependencies #QMAKE_LFLAGS += -static -static-libgcc -static-libstdc++ -#QMAKE_LFLAGS += -static-libstdc++ +#QMAKE_LFLAGS += -static-libstdc++ -lstdc++ #QMAKE_CXXFLAGS += -static -static -static-libstdc++ #QMAKE_CXXFLAGS += -static +#QMAKE_LFLAGS_RELEASE += -static-libgcc greaterThan(QT_MAJOR_VERSION, 4):QT += widgets -win32 { - INCLUDEPATH += C:/VTK/include/vtk-6.1 - - LIBS += -LC:/VTK/bin \ +#Dynamic linking +#Windows VTK 6.1 +win32_te { + INCLUDEPATH += C:/VTK/VTK6.1/include + LIBS += -LC:/VTK/VTK6.1/bin_shared \ #LIBS += -LC:/VTK/bin_static/lib \ -lwsock32 \ -lvtkCommonCore-6.1 \ @@ -56,51 +58,13 @@ win32 { -lvtkInteractionStyle-6.1 \ -lvtkCommonCore-6.1 \ -lvtksys-6.1 \ -#second round -# -lvtksys-6.1 \ -# -lvtkRenderingOpenGL-6.1 \ -# -lvtkCommonCore-6.1 \ -# -lvtkCommonDataModel-6.1 \ -# -lvtkCommonMath-6.1 \ -# -lvtkCommonMisc-6.1 \ -# -lvtkCommonSystem-6.1 \ -# -lvtkCommonTransforms-6.1 \ -# -lvtkCommonExecutionModel-6.1 \ -# -lvtkImagingHybrid-6.1 \ -# -lvtkIOImage-6.1 \ -# -lvtkDICOMParser-6.1 \ -# -lvtkjpeg-6.1 \ -# -lvtkmetaio-6.1 \ -# -lvtkzlib-6.1 \ -# -lvtkpng-6.1 \ -# -lvtktiff-6.1 \ -# -lvtkRenderingCore-6.1 \ -# -lvtkCommonComputationalGeometry-6.1 \ -# -lvtkFiltersCore-6.1 \ -# -lvtkFiltersExtraction-6.1 \ -# -lvtkFiltersGeneral-6.1 \ -# -lvtkFiltersStatistics-6.1 \ -# -lvtkalglib-6.1 \ -# -lvtkImagingFourier-6.1 \ -# -lvtkImagingCore-6.1 \ -# -lvtkFiltersGeometry-6.1 \ -# -lvtkFiltersSources-6.1 \ -# -lvtkRenderingLabel-6.1 \ -# -lvtkRenderingFreeType-6.1 \ -# -lvtkfreetype-6.1 \ -# -lvtkftgl-6.1 \ -# -lvtkRenderingFreeTypeOpenGL-6.1 \ -# -lvtkRenderingAnnotation-6.1 \ -# -lvtkIOMovie-6.1 \ -# -lvtkoggtheora-6.1 \ -# -lvtkInteractionStyle-6.1 \ } -win32_ { - INCLUDEPATH += C:/VTK/include/vtk-6.1 - - LIBS += -LC:/VTK/bin \ -# LIBS += -LC:/VTK/bin_static/lib \ +#Static linking +#Windows VTK 6.1 +win32_6.1 { + INCLUDEPATH += C:/VTK/VTK6.1/include + LIBS += -LC:/VTK/VTK6.1/bin_static \ -lvtkCommonCore-6.1 \ -lvtkalglib-6.1 \ -lvtkChartsCore-6.1 \ @@ -217,11 +181,12 @@ win32_ { -lvtkzlib-6.1 \ -lwsock32 } - -win32_5 { - INCLUDEPATH += C:/VTK/include/vtk-5.10 - - LIBS += -LC:/VTK/bin_5 \ + +#Dynamic linking +#Windows VTK 5.10 +win32_dyn { + INCLUDEPATH += C:/VTK/VTK5.1/include + LIBS += -LC:/VTK/VTK5.1/bin_shared \ -lvtksys \ -lvtkzlib \ -lvtkjpeg \ @@ -243,17 +208,65 @@ win32_5 { -lvtkGraphics \ -lvtkIO \ -lvtkRendering \ - -lvtkParallel \ -lvtkHybrid \ -lvtkWidgets \ -lvtkInfovis\ -lvtkViews\ -lwsock32\ } - + +#Static compilation +#VTK 5.10 Windows +win32 { + INCLUDEPATH += C:/VTK/VTK5.1/static_2/include/vtk-5.10 + LIBS += -LC:\VTK\VTK5.1\static_2\lib\vtk-5.10 \ + C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkCharts.a C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkViews.a \ + C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkInfovis.a C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkWidgets.a \ + C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkHybrid.a C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkVolumeRendering.a \ + C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkParallel.a C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkRendering.a \ + C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkGraphics.a C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkverdict.a \ + C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkImaging.a C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkIO.a \ + C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkFiltering.a C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkDICOMParser.a \ + C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkNetCDF_cxx.a C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkmetaio.a \ + C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtksqlite.a C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkpng.a \ + C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtktiff.a C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkjpeg.a \ + C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkexpat.a C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libVPIC.a \ + C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libCosmo.a C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkCommon.a \ + C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libLSDyna.a C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtksys.a \ + C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkexoIIc.a C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkNetCDF.a \ + C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkhdf5_hl.a C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkhdf5.a \ + C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtklibxml2.a C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkzlib.a \ + C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkalglib.a C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkftgl.a \ + C:\VTK\VTK5.1\static_2\lib\vtk-5.10/libvtkfreetype.a \ + -lwsock32 -lglu32 -lvfw32 -lgdi32 -lopengl32 -lws2_32 -lgdi32 \ + -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 \ + -luuid -lcomdlg32 -ladvapi32\ +} + +#Static compilation +#VTK 5.10 Windows +win32_old { + INCLUDEPATH += C:/VTK/VTK5.1/include + #LIBS += -LC:/VTK/VTK5.1/bin_static \ + LIBS += -LC:\VTK\VTK5.1\static_2\lib\vtk-5.10 \ + -lvtkCharts -lvtkViews -lvtkInfovis\ + -lvtkWidgets -lvtkHybrid\ + -lvtkVolumeRendering -lvtkParallel\ + -lvtkRendering -lvtkGraphics\ + -lvtkverdict -lvtkImaging -lvtkIO\ + -lvtkFiltering -lvtkDICOMParser\ + -lvtkNetCDF_cxx -lvtkmetaio -lvtksqlite\ + -lvtkpng -lvtktiff -lvtkjpeg\ + -lvtkexpat -lVPIC -lCosmo -lvtkCommon\ + -lLSDyna -lvtksys -lvtkexoIIc\ + -lvtkNetCDF -lvtkhdf5_hl -lvtkhdf5\ + -lvtklibxml2 -lvtkzlib -lvtkalglib\ + -lvtkftgl -lvtkfreetype \ + -lvfw32 -lwsock32\ + } + unix_6 { INCLUDEPATH += /usr/local/include/vtk-6.0 - LIBS += -L/usr/local/lib/ \ -lvtkalglib-6.0 \ -lvtkChartsCore-6.0 \ @@ -404,7 +417,7 @@ LIBS += -L/usr/lib \ } -#Static compilation +#Static compilation linux unix_static { #INCLUDEPATH += /usr/include/vtk-5.8 #LIBS += -L/usr/lib \ @@ -424,7 +437,7 @@ LIBS += -L/usr/local/lib/vtk-5.10 \ -lvtkDICOMParser \ -lvtkmetaio \ -lvtkftgl \ -#-lLSDyna \ +-lLSDyna \ -lvtkViews \ -lvtksys \ -lvtkpng \ @@ -439,13 +452,6 @@ LIBS += -L/usr/local/lib/vtk-5.10 \ -lX11 \ -lXext \ -ldl \ -#-lpng \ -#-ltiff \ -#-ljpeg \ -#-lxml2 \ -#-lz \ -#-lexpat \ -#-lfreetype \ } macx { @@ -599,7 +605,7 @@ HEADERS += src/geometry/Building.h \ src/ThreadDataTransfert.h \ src/ThreadVisualisation.h \ src/TimerCallback.h \ - src/TrajectoryPoint.h \ + src/FrameElement.h \ src/extern_var.h \ src/geometry/FacilityGeometry.h \ src/geometry/LinePlotter.h \ @@ -607,7 +613,8 @@ HEADERS += src/geometry/Building.h \ src/geometry/LinePlotter2D.h \ src/geometry/PointPlotter2D.h \ src/network/TraVisToServer.h \ - src/MainWindow.h + src/MainWindow.h \ + src/TrailPlotter.h SOURCES += src/geometry/Building.cpp \ src/geometry/Crossing.cpp \ @@ -641,14 +648,16 @@ SOURCES += src/geometry/Building.cpp \ src/ThreadDataTransfert.cpp \ src/ThreadVisualisation.cpp \ src/TimerCallback.cpp \ - src/TrajectoryPoint.cpp \ + src/FrameElement.cpp \ src/geometry/LinePlotter2D.cpp \ src/geometry/PointPlotter2D.cpp \ src/geometry/FacilityGeometry.cpp \ src/geometry/LinePlotter.cpp \ src/geometry/PointPlotter.cpp \ src/network/TraVisToServer.cpp \ - src/MainWindow.cpp + src/MainWindow.cpp \ + src/TrailPlotter.cpp + FORMS += forms/settings.ui \ forms/mainwindow.ui RESOURCES += forms/icons.qrc diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 3340f6e4d58ca09fcaa44838f7c2f1fac4a08a6f..94d340b9b53a22b6ef06d1c794d8575fe210b137 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -61,9 +61,9 @@ <property name="geometry"> <rect> <x>160</x> - <y>30</y> + <y>20</y> <width>271</width> - <height>151</height> + <height>161</height> </rect> </property> <property name="sizePolicy"> @@ -183,9 +183,9 @@ <property name="geometry"> <rect> <x>30</x> - <y>30</y> + <y>20</y> <width>111</width> - <height>201</height> + <height>161</height> </rect> </property> <property name="sizePolicy"> @@ -200,10 +200,10 @@ <widget class="QPushButton" name="BtStart"> <property name="geometry"> <rect> - <x>10</x> - <y>24</y> - <width>81</width> - <height>28</height> + <x>11</x> + <y>21</y> + <width>80</width> + <height>30</height> </rect> </property> <property name="toolTip"> @@ -229,10 +229,10 @@ </property> <property name="geometry"> <rect> - <x>10</x> - <y>58</y> - <width>81</width> - <height>28</height> + <x>11</x> + <y>55</y> + <width>80</width> + <height>30</height> </rect> </property> <property name="toolTip"> @@ -258,10 +258,10 @@ </property> <property name="geometry"> <rect> - <x>10</x> - <y>92</y> - <width>81</width> - <height>28</height> + <x>11</x> + <y>89</y> + <width>80</width> + <height>30</height> </rect> </property> <property name="toolTip"> @@ -281,46 +281,20 @@ </size> </property> </widget> - <widget class="QPushButton" name="BtFullscreen"> - <property name="enabled"> - <bool>false</bool> - </property> + <widget class="QPushButton" name="BtReset"> <property name="geometry"> <rect> - <x>10</x> - <y>126</y> - <width>81</width> - <height>28</height> + <x>11</x> + <y>123</y> + <width>80</width> + <height>30</height> </rect> </property> - <property name="toolTip"> - <string>Fullscreen</string> - </property> - <property name="autoFillBackground"> - <bool>false</bool> - </property> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset resource="icons.qrc"> - <normaloff>:/new/iconsS/icons/window_fullscreen-64.png</normaloff>:/new/iconsS/icons/window_fullscreen-64.png</iconset> - </property> - <property name="iconSize"> + <property name="minimumSize"> <size> - <width>20</width> - <height>20</height> - </size> - </property> - </widget> - <widget class="QPushButton" name="BtReset"> - <property name="geometry"> - <rect> - <x>10</x> - <y>160</y> - <width>81</width> + <width>0</width> <height>23</height> - </rect> + </size> </property> <property name="toolTip"> <string>Reset the simulation and clear all datasets loaded</string> @@ -526,6 +500,38 @@ border-color: rgb(255, 255, 255);</string> <string>Previous</string> </property> </widget> + <widget class="QPushButton" name="BtFullscreen"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="geometry"> + <rect> + <x>40</x> + <y>200</y> + <width>80</width> + <height>30</height> + </rect> + </property> + <property name="toolTip"> + <string>Fullscreen</string> + </property> + <property name="autoFillBackground"> + <bool>false</bool> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset resource="icons.qrc"> + <normaloff>:/new/iconsS/icons/window_fullscreen-64.png</normaloff>:/new/iconsS/icons/window_fullscreen-64.png</iconset> + </property> + <property name="iconSize"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </widget> </widget> <widget class="QMenuBar" name="menubar"> <property name="geometry"> @@ -593,8 +599,10 @@ 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"/> <addaction name="separator"/> <addaction name="actionPedestrian_Shape"/> <addaction name="actionNetwork_settings"/> @@ -614,26 +622,27 @@ border-color: rgb(255, 255, 255);</string> </widget> <addaction name="action2_D"/> <addaction name="action3_D"/> + <addaction name="menuCamera_View"/> <addaction name="separator"/> <addaction name="actionShow_Agents"/> + <addaction name="actionShow_Captions"/> <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"/> - <addaction name="actionShow_Captions"/> <addaction name="actionShow_Axis"/> <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="separator"/> <addaction name="actionFirst_Group"/> <addaction name="actionSecond_Group"/> <addaction name="actionThird_Group"/> <addaction name="separator"/> - <addaction name="menuCamera_View"/> - <addaction name="separator"/> <addaction name="actionShow_Onscreen_Infos"/> <addaction name="separator"/> </widget> @@ -734,7 +743,7 @@ border-color: rgb(255, 255, 255);</string> <bool>true</bool> </property> <property name="text"> - <string>Network settings</string> + <string>Listening Port</string> </property> </action> <action name="actionOnline"> @@ -778,6 +787,9 @@ border-color: rgb(255, 255, 255);</string> <property name="text"> <string>Fullscreen</string> </property> + <property name="visible"> + <bool>false</bool> + </property> </action> <action name="actionRecord"> <property name="enabled"> @@ -797,6 +809,9 @@ border-color: rgb(255, 255, 255);</string> <property name="text"> <string>Load Project</string> </property> + <property name="visible"> + <bool>false</bool> + </property> </action> <action name="action2_D"> <property name="checkable"> @@ -822,7 +837,7 @@ border-color: rgb(255, 255, 255);</string> </action> <action name="actionAdd_Trajectories_File"> <property name="enabled"> - <bool>true</bool> + <bool>false</bool> </property> <property name="text"> <string>Add Trajectories File</string> @@ -830,10 +845,13 @@ border-color: rgb(255, 255, 255);</string> <property name="shortcut"> <string>Ctrl+A</string> </property> + <property name="visible"> + <bool>false</bool> + </property> </action> <action name="actionClear_Trajectories_Files"> <property name="enabled"> - <bool>true</bool> + <bool>false</bool> </property> <property name="text"> <string>Clear Trajectories Files</string> @@ -841,6 +859,9 @@ border-color: rgb(255, 255, 255);</string> <property name="shortcut"> <string>Ctrl+C</string> </property> + <property name="visible"> + <bool>false</bool> + </property> </action> <action name="actionLoad_Geometry"> <property name="text"> @@ -855,7 +876,7 @@ border-color: rgb(255, 255, 255);</string> <bool>true</bool> </property> <property name="text"> - <string>Load File</string> + <string>Open File</string> </property> <property name="shortcut"> <string>Ctrl+O</string> @@ -885,6 +906,9 @@ border-color: rgb(255, 255, 255);</string> <property name="text"> <string>First Group</string> </property> + <property name="visible"> + <bool>false</bool> + </property> </action> <action name="actionSecond_Group"> <property name="checkable"> @@ -896,6 +920,9 @@ border-color: rgb(255, 255, 255);</string> <property name="text"> <string>Second Group</string> </property> + <property name="visible"> + <bool>false</bool> + </property> </action> <action name="actionThird_Group"> <property name="checkable"> @@ -907,13 +934,16 @@ border-color: rgb(255, 255, 255);</string> <property name="text"> <string>Third Group</string> </property> + <property name="visible"> + <bool>false</bool> + </property> </action> <action name="actionShow_Legend"> <property name="checkable"> <bool>true</bool> </property> <property name="enabled"> - <bool>true</bool> + <bool>false</bool> </property> <property name="text"> <string>Show Legend</string> @@ -924,6 +954,9 @@ border-color: rgb(255, 255, 255);</string> <property name="shortcut"> <string>S, L</string> </property> + <property name="visible"> + <bool>false</bool> + </property> </action> <action name="action3_D"> <property name="checkable"> @@ -950,7 +983,7 @@ border-color: rgb(255, 255, 255);</string> <bool>true</bool> </property> <property name="enabled"> - <bool>false</bool> + <bool>true</bool> </property> <property name="text"> <string>Show Agents</string> @@ -1003,7 +1036,7 @@ border-color: rgb(255, 255, 255);</string> <bool>false</bool> </property> <property name="text"> - <string>Show Captions</string> + <string>Show Agents Captions</string> </property> <property name="shortcut"> <string>S, C</string> @@ -1041,6 +1074,9 @@ border-color: rgb(255, 255, 255);</string> <property name="shortcut"> <string>S, A</string> </property> + <property name="visible"> + <bool>false</bool> + </property> </action> <action name="actionCameraViewTop"> <property name="checkable"> @@ -1063,6 +1099,9 @@ border-color: rgb(255, 255, 255);</string> <property name="text"> <string>Side</string> </property> + <property name="visible"> + <bool>false</bool> + </property> </action> <action name="actionCameraViewFront"> <property name="checkable"> @@ -1074,6 +1113,9 @@ border-color: rgb(255, 255, 255);</string> <property name="text"> <string>Front</string> </property> + <property name="visible"> + <bool>false</bool> + </property> </action> <action name="actionPedestrian_Shape"> <property name="text"> @@ -1082,6 +1124,9 @@ border-color: rgb(255, 255, 255);</string> <property name="shortcut"> <string>Ctrl+,</string> </property> + <property name="visible"> + <bool>false</bool> + </property> </action> <action name="actionSnapshot"> <property name="text"> @@ -1114,6 +1159,9 @@ border-color: rgb(255, 255, 255);</string> </property> </action> <action name="actionCameraViewAgent"> + <property name="enabled"> + <bool>false</bool> + </property> <property name="text"> <string>Agent View</string> </property> @@ -1224,6 +1272,38 @@ border-color: rgb(255, 255, 255);</string> <string>Show Geometry Captions</string> </property> </action> + <action name="actionShow_Navigation_Lines"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="checked"> + <bool>true</bool> + </property> + <property name="text"> + <string>Show Navigation Lines</string> + </property> + </action> + <action name="actionNavigation_Lines_Color"> + <property name="text"> + <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"/> @@ -2029,6 +2109,70 @@ 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> + <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> @@ -2088,5 +2232,9 @@ border-color: rgb(255, 255, 255);</string> <slot>slotShowHideExits()</slot> <slot>slotShowHideWalls()</slot> <slot>slotShowHideGeometryCaptions()</slot> + <slot>slotShowHideNavLines()</slot> + <slot>slotChangeNavLinesColor()</slot> + <slot>slotShowHideFloor()</slot> + <slot>slotChangeFloorColor()</slot> </slots> </ui> diff --git a/forms/settings.ui b/forms/settings.ui index 5f4661b7b3e1ee022f0f4f49cb2ba05f62ebb107..52d4fddce6bd1534f3d5fa1969d363965a16ce4b 100644 --- a/forms/settings.ui +++ b/forms/settings.ui @@ -35,7 +35,7 @@ </rect> </property> <property name="currentIndex"> - <number>0</number> + <number>3</number> </property> <widget class="QWidget" name="tab"> <attribute name="title"> diff --git a/src/Frame.cpp b/src/Frame.cpp index 90cdff1649b73e23b3a0841d8dbed58c87581e3f..dddd5705d94b2cce6174682393e0e264a6c0a6cb 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -33,119 +33,186 @@ #include <vector> #include <iostream> -#include "TrajectoryPoint.h" +#include "FrameElement.h" #include "Frame.h" #include <vtkPolyData.h> #include <vtkSmartPointer.h> #include <vtkFloatArray.h> #include <vtkPointData.h> #include <vtkMath.h> -#include <vtkIntArray.h> +#include <vtkMatrix3x3.h> #define VTK_CREATE(type, name) \ - vtkSmartPointer<type> name = vtkSmartPointer<type>::New() + vtkSmartPointer<type> name = vtkSmartPointer<type>::New() -Frame::Frame() { - elementCursor=0; - _polydata = vtkPolyData::New(); - _polydataLabels = vtkPolyData::New(); +Frame::Frame() +{ + _elementCursor=0; + //_polydata = vtkPolyData::New(); + _polydata2D = vtkPolyData::New(); + _polydata3D = vtkPolyData::New(); + _framePoints.reserve(1500); } -Frame::~Frame() { - while (!framePoints.empty()){ - delete framePoints.back(); - framePoints.pop_back(); - } - framePoints.clear(); +Frame::~Frame() +{ + while (!_framePoints.empty()){ + delete _framePoints.back(); + _framePoints.pop_back(); + } + _framePoints.clear(); + + _polydata2D->Delete(); + _polydata3D->Delete(); +} - _polydata->Delete(); - _polydataLabels->Delete(); +int Frame::getSize() +{ + return _framePoints.size(); } -int Frame::getSize(){ - return this->framePoints.size(); +void Frame::addElement(FrameElement* point) +{ + _framePoints.push_back(point); } -void Frame::addElement(TrajectoryPoint* point){ - framePoints.push_back(point); +void Frame::clear() +{ + while (!_framePoints.empty()){ + delete _framePoints.back(); + _framePoints.pop_back(); + } + _framePoints.clear(); + + _elementCursor=0; } -void Frame::clear(){ - while (!framePoints.empty()){ - delete framePoints.back(); - framePoints.pop_back(); - } - framePoints.clear(); +FrameElement* Frame::getNextElement() +{ + if(_elementCursor>=_framePoints.size()) { + return NULL; - elementCursor=0; + }else{ + return _framePoints.at(_elementCursor++); + } + //next test } -TrajectoryPoint* Frame::getNextElement(){ + /* - TrajectoryPoint* res; - if(framePoints.empty()) { - return NULL; - } - else{ - res= framePoints.front(); - // dont delete the elements..... - framePoints.erase(framePoints.begin()); - return res; - } -*/ +vtkPolyData* Frame::GetPolyData(bool is_ellipse) +{ + VTK_CREATE (vtkPoints, points); + VTK_CREATE (vtkFloatArray, colors); + VTK_CREATE (vtkFloatArray, tensors); + + colors->SetName("color"); + colors->SetNumberOfComponents(1); + + tensors->SetName("tensors"); + tensors->SetNumberOfComponents(9); + for (unsigned int i=0;i<_framePoints.size();i++) + { + double pos[3]={0,0,0}; + double rad[3]={1.0,1.0,1.0}; + double rot[3]; + double color; + _framePoints[i]->GetPos(pos); //pos[2]=90; + _framePoints[i]->GetOrientation(rot); + _framePoints[i]->GetColor(&color); + _framePoints[i]->GetRadius(rad); - //The navigation is only allowed in one direction - // so elementCursor cannot be negative - if (elementCursor<0) { - //Debug::Messages("CURSOR VALUE(NULL): %d" ,elementCursor); - return NULL; - } + //only scale the ellipse 2D + if(is_ellipse) + { + rad[0]/=30;rad[1]/=30;rad[2]/=120; + } + else + { + double height_i=170; + rot[0]=vtkMath::RadiansFromDegrees(90.0); + rot[1]=vtkMath::RadiansFromDegrees(00.0); + pos[2]=height_i/2.0; // slightly above ground + rad[0]/=30; + rad[2]/=30; + //?height default to 30 in SaxParser and 160 in Renderingengine + rad[1]=height_i/160.0; - if(elementCursor>=framePoints.size()) { - return NULL; + } - }else{ - return framePoints.at(elementCursor++); - } -//next test -} + points->InsertNextPoint(pos); + + rot[2]=vtkMath::RadiansFromDegrees(rot[2]); + + //scaling matrix + double sc[3][3] = {{rad[0],0,0}, + {0,rad[1],0}, + {0,0,rad[2]}}; -vtkPolyData* Frame::GetPolyData() { - -// VTK_CREATE (vtkPoints, points); -// VTK_CREATE (vtkFloatArray, colors); -// colors->SetName("color"); -// //colors->SetNumberOfComponents(3); -// colors->SetNumberOfComponents(1); -// for (unsigned int i=0;i<framePoints.size();i++){ -// double pos[3]; -// double data[7]; -// framePoints[i]->getPos(pos); -// framePoints[i]->getEllipse(data); -// points->InsertNextPoint(pos); -// if(data[6]==-1){ -// colors->InsertNextValue(NAN); -// } -// else{ -// colors->InsertNextValue(data[6]/255.0); -// } -// } -// //scalars->Print(cout); -// VTK_CREATE (vtkFloatArray, data); -// data->SetNumberOfComponents(2); -// data->SetNumberOfTuples(framePoints.size()); -// data->CopyComponent(0, colors, 0); -// data->CopyComponent(1, colors, 0); // radius can come here later -// data->SetName("data"); - -// _polydata->SetPoints(points); -// _polydata->GetPointData()->AddArray(data); -// _polydata->GetPointData()->SetActiveScalars("data"); + //rotation matrix around x-axis + double roX[3][3] = {{1, 0, 0}, + {0, cos(rot[0]),-sin(rot[0])}, + {0, sin(rot[0]), cos(rot[0])}}; + + //rotation matrix around y-axis + double roY[3][3] = {{cos(rot[1]), 0,sin(rot[1])}, + {0, 1, 0}, + {-sin(rot[1]),0,cos(rot[1])}}; + + //rotation matrix around z-axis + double roZ[3][3] = {{cos(rot[2]),sin(rot[2]),0.0}, + {-sin(rot[2]),cos(rot[2]),0.0}, + {0.0,0.0,1.0}}; + + + //final rotation matrix + double ro[3][3]; + vtkMath::Multiply3x3(roX,roY,ro); + vtkMath::Multiply3x3(ro,roZ,ro); + + //final transformation matrix + double rs[3][3]; + vtkMath::Multiply3x3(sc,ro,rs); + + tensors->InsertNextTuple9(rs[0][0],rs[0][1],rs[0][2], + rs[1][0],rs[1][1],rs[1][2], + rs[2][0],rs[2][1],rs[2][2]); + + + if(color==-1){ + colors->InsertNextValue(NAN); + } + else{ + colors->InsertNextValue(color/255.0); + } + } + + // setting the colors + _polydata->SetPoints(points); + _polydata->GetPointData()->AddArray(colors); + _polydata->GetPointData()->SetActiveScalars("color"); + + // setting the scaling and rotation + _polydata->GetPointData()->SetTensors(tensors); + _polydata->GetPointData()->SetActiveTensors("tensors"); + + + return _polydata; +} +*/ + +void Frame::ComputePolyData() +{ + ComputePolyData2D(); + ComputePolyData3D(); +} +void Frame::ComputePolyData2D() +{ VTK_CREATE (vtkPoints, points); VTK_CREATE (vtkFloatArray, colors); VTK_CREATE (vtkFloatArray, tensors); @@ -160,36 +227,131 @@ vtkPolyData* Frame::GetPolyData() { labels->SetName("labels"); labels->SetNumberOfComponents(1); - for (unsigned int i=0;i<framePoints.size();i++){ + for (unsigned int i=0;i<_framePoints.size();i++) + { double pos[3]={0,0,0}; - double rad[3]; + double rad[3]={1.0,1.0,1.0}; double rot[3]; - - framePoints[i]->getPos(pos); //pos[2]=90; + double color; + _framePoints[i]->GetPos(pos); //pos[2]=90; + _framePoints[i]->GetOrientation(rot); + _framePoints[i]->GetColor(&color); + _framePoints[i]->GetRadius(rad); + labels->InsertNextValue(_framePoints[i]->GetId()+1); + + rad[0]/=30;rad[1]/=30;rad[2]/=120; points->InsertNextPoint(pos); - labels->InsertNextValue(framePoints[i]->getIndex()+1); + rot[2]=vtkMath::RadiansFromDegrees(rot[2]); + + //scaling matrix + double sc[3][3] = {{rad[0],0,0}, + {0,rad[1],0}, + {0,0,rad[2]}}; + + + //rotation matrix around x-axis + double roX[3][3] = {{1, 0, 0}, + {0, cos(rot[0]),-sin(rot[0])}, + {0, sin(rot[0]), cos(rot[0])}}; + + //rotation matrix around y-axis + double roY[3][3] = {{cos(rot[1]), 0,sin(rot[1])}, + {0, 1, 0}, + {-sin(rot[1]),0,cos(rot[1])}}; + + //rotation matrix around z-axis + double roZ[3][3] = {{cos(rot[2]),sin(rot[2]),0.0}, + {-sin(rot[2]),cos(rot[2]),0.0}, + {0.0,0.0,1.0}}; + + + //final rotation matrix + double ro[3][3]; + vtkMath::Multiply3x3(roX,roY,ro); + vtkMath::Multiply3x3(ro,roZ,ro); + + //final transformation matrix + double rs[3][3]; + vtkMath::Multiply3x3(sc,ro,rs); + + tensors->InsertNextTuple9(rs[0][0],rs[0][1],rs[0][2], + rs[1][0],rs[1][1],rs[1][2], + rs[2][0],rs[2][1],rs[2][2]); - double data[7]; - framePoints[i]->getEllipse(data); + if(color==-1){ + colors->InsertNextValue(NAN); + } + else{ + colors->InsertNextValue(color/255.0); + } + } - //framePoints[i]->GetRadius(rad); - rad[0]=data[3]/30; - rad[1]=data[4]/30; - rad[2]=30.0/120.0; + // setting the colors + _polydata2D->SetPoints(points); + _polydata2D->GetPointData()->AddArray(colors); + _polydata2D->GetPointData()->SetActiveScalars("color"); - //rad[0]=1; - //rad[1]=1; - //rad[2]=1.0; + // setting the scaling and rotation + _polydata2D->GetPointData()->SetTensors(tensors); + _polydata2D->GetPointData()->SetActiveTensors("tensors"); - rot[0]=vtkMath::RadiansFromDegrees(0.0); - rot[1]=vtkMath::RadiansFromDegrees(0.0); - rot[2]=vtkMath::RadiansFromDegrees(data[5]); + //setting the labels + _polydata2D->GetPointData()->AddArray(labels); +} + +void Frame::ComputePolyData3D() +{ + VTK_CREATE (vtkPoints, points); + VTK_CREATE (vtkFloatArray, colors); + VTK_CREATE (vtkFloatArray, tensors); + + colors->SetName("color"); + colors->SetNumberOfComponents(1); + + tensors->SetName("tensors"); + tensors->SetNumberOfComponents(9); + + for (unsigned int i=0;i<_framePoints.size();i++){ + double pos[3]={0,0,0}; + double rad[3]={1.0,1.0,1.0}; + double rot[3]; + double color; + _framePoints[i]->GetPos(pos); //pos[2]=90; + _framePoints[i]->GetOrientation(rot); + _framePoints[i]->GetColor(&color); + _framePoints[i]->GetRadius(rad); + + + //values for cylindar + double height_i=170; + double max_height=160; + rot[0]=vtkMath::RadiansFromDegrees(90.0); + rot[1]=vtkMath::RadiansFromDegrees(00.0); + int angle_offset=0; + + //values for charlie + //rot[0]=vtkMath::RadiansFromDegrees(00.0); + //rot[1]=vtkMath::RadiansFromDegrees(00.0); + //int angle_offset=90; + //double max_height=350; + + + pos[2]+=height_i/2.0; // slightly above ground + rad[0]/=20; rad[0]=1; + rad[2]/=20; rad[2]=1; + //?height default to 30 in SaxParser and 160 in Renderingengine + //rad[1]=height_i/160.0; + rad[1]=height_i/max_height; + + + points->InsertNextPoint(pos); + rot[2]=vtkMath::RadiansFromDegrees(rot[2] + angle_offset); //scaling matrix double sc[3][3] = {{rad[0],0,0}, - {0,rad[1],0}, - {0,0,rad[2]}}; + {0,rad[1],0}, + {0,0,rad[2]}}; //rotation matrix around x-axis @@ -207,61 +369,61 @@ vtkPolyData* Frame::GetPolyData() { {-sin(rot[2]),cos(rot[2]),0.0}, {0.0,0.0,1.0}}; + //final rotation matrix double ro[3][3]; vtkMath::Multiply3x3(roX,roY,ro); vtkMath::Multiply3x3(ro,roZ,ro); - //final transformation matrix double rs[3][3]; vtkMath::Multiply3x3(sc,ro,rs); tensors->InsertNextTuple9(rs[0][0],rs[0][1],rs[0][2], - rs[1][0],rs[1][1],rs[1][2], - rs[2][0],rs[2][1],rs[2][2]); + rs[1][0],rs[1][1],rs[1][2], + rs[2][0],rs[2][1],rs[2][2]); - //color - if(data[6]==-1){ + if(color==-1){ colors->InsertNextValue(NAN); } else{ - colors->InsertNextValue(data[6]/255.0); + colors->InsertNextValue(color/255.0); } - - } + } // setting the colors - _polydata->SetPoints(points); - _polydata->GetPointData()->AddArray(colors); - _polydata->GetPointData()->SetActiveScalars("color"); + _polydata3D->SetPoints(points); + _polydata3D->GetPointData()->AddArray(colors); + _polydata3D->GetPointData()->SetActiveScalars("color"); // setting the scaling and rotation - _polydata->GetPointData()->SetTensors(tensors); - _polydata->GetPointData()->SetActiveTensors("tensors"); - - - // setting the labels - _polydata->GetPointData()->AddArray(labels); - //_polydata->GetPointData()->set + _polydata3D->GetPointData()->SetTensors(tensors); + _polydata3D->GetPointData()->SetActiveTensors("tensors"); +} - //labels - //_polydataLabels->SetPoints(points); - return _polydata; +vtkPolyData* Frame::GetPolyData2D() +{ + return _polydata2D; } -vtkPolyData *Frame::GetPolyDataLabels() +vtkPolyData* Frame::GetPolyData3D() { - return _polydataLabels; + return _polydata3D; } -unsigned int Frame::getElementCursor(){ +const std::vector<FrameElement *> &Frame::GetFrameElements() const +{ + return _framePoints; +} - return elementCursor; +unsigned int Frame::getElementCursor() +{ + return _elementCursor; } -void Frame::resetCursor(){ - elementCursor=0; +void Frame::resetCursor() +{ + _elementCursor=0; } diff --git a/src/Frame.h b/src/Frame.h index 7392c9893d718623c648fd6d639d3fc393cdaa23..1dd955e3d9476213ff582d8747b1d5ff818e33ae 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -32,46 +32,66 @@ #ifndef Frame_H_ #define Frame_H_ -class TrajectoryPoint; +class FrameElement; class vtkPolyData; -class Frame { +class Frame +{ public: - Frame(); + /// constructor + Frame(); + /// destructor virtual ~Frame(); /// add an element to the Frame - void addElement(TrajectoryPoint* point); + void addElement(FrameElement* point); ///clear all Points in the frame void clear(); ///return the next object in the frame - TrajectoryPoint* getNextElement(); + FrameElement *getNextElement(); - int getSize(); + ///compute the polydata. + ///Call this after all elements have been added. + void ComputePolyData(); - unsigned int getElementCursor(); + /// return the number of element in this frame + int getSize(); + + /// reset the position of the cursor for reading the data + void resetCursor(); + + //vtkPolyData *GetSclarData(); - void resetCursor(); + /// return the 3D polydata set + vtkPolyData *GetPolyData3D(); - vtkPolyData* GetPolyData(); + /// return the 2D polydata set + vtkPolyData *GetPolyData2D(); + /// return the pedestrians labels vtkPolyData* GetPolyDataLabels(); - vtkPolyData* GetSclarData(); + const std::vector <FrameElement *>& GetFrameElements() const; private: - std::vector <TrajectoryPoint *> framePoints; + /// compute the 2D polydata + void ComputePolyData2D(); + /// compute the 3D polydata + void ComputePolyData3D(); + + unsigned int getElementCursor(); - /// ellipse parameters - vtkPolyData * _polydata; - /// pedestrians labels - vtkPolyData * _polydataLabels; +private: + std::vector <FrameElement *> _framePoints; + //vtkPolyData * _polydata; + vtkPolyData * _polydata2D; + vtkPolyData * _polydata3D; /// points to the actual element in the frame - unsigned int elementCursor; + unsigned int _elementCursor; }; #endif /* Frame_H_ */ diff --git a/src/FrameElement.cpp b/src/FrameElement.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9bd235dbea3ca2310b49751899e1db2edb8d5555 --- /dev/null +++ b/src/FrameElement.cpp @@ -0,0 +1,116 @@ +/** +* @file FrameElement.cpp +* @author Ulrich Kemloh <kemlohulrich@gmail.com> +* @version 0.1 +* Copyright (C) <2009-2014> +* +* @section LICENSE +* This file is part of JuPedsim. +* +* JuPedSim is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* any later version. +* +* OpenPedSim is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with OpenPedSim. If not, see <http://www.gnu.org/licenses/>. +* +* @section DESCRIPTION +* +* \brief +* +* +*/ + + + +#include <limits> +#include "FrameElement.h" + + +FrameElement::FrameElement(int id) +{ + _id=id; + _pos[0] = std::numeric_limits<double>::quiet_NaN(); + _pos[1] = std::numeric_limits<double>::quiet_NaN(); + _pos[2] = std::numeric_limits<double>::quiet_NaN(); + + _orientation[0] = std::numeric_limits<double>::quiet_NaN(); + _orientation[1] = std::numeric_limits<double>::quiet_NaN(); + _orientation[2] = std::numeric_limits<double>::quiet_NaN(); + + _radius[0] = std::numeric_limits<double>::quiet_NaN(); + _radius[1] = std::numeric_limits<double>::quiet_NaN(); + _radius[2] = std::numeric_limits<double>::quiet_NaN(); +} + +FrameElement::~FrameElement() { + +} + +void FrameElement::SetId(int index) { + _id = index; +} + +void FrameElement::SetPos(double pos[3]) +{ + _pos[0] = pos[0]; + _pos[1] = pos[1]; + _pos[2] = pos[2]; +} + +void FrameElement::SetRadius(double radius[]) +{ + _radius[0] = radius[0]; + _radius[1] = radius[1]; + _radius[2] = radius[2]; +} + +void FrameElement::GetRadius(double radius[]) +{ + radius[0] = _radius[0]; + radius[1] = _radius[1]; + radius[2] = _radius[2]; +} + +void FrameElement::GetPos(double pos[3]) +{ + pos[0] = _pos[0]; + pos[1] = _pos[1]; + pos[2] = _pos[2]; +} + +void FrameElement::SetOrientation(double angle[]) +{ + _orientation[0]=angle[0]; + _orientation[1]=angle[1]; + _orientation[2]=angle[2]; +} + +void FrameElement::GetOrientation(double angle[]) +{ + angle[0]=_orientation[0]; + angle[1]=_orientation[1]; + angle[2]=_orientation[2]; +} + +void FrameElement::SetColor(double color) +{ + _color=color; +} + +void FrameElement::GetColor(double *color) +{ + *color=_color; +} + +int FrameElement::GetId() +{ + return _id; +} + diff --git a/src/FrameElement.h b/src/FrameElement.h new file mode 100644 index 0000000000000000000000000000000000000000..58e4ac9fc195a6ae6809e74078292210de3b57d1 --- /dev/null +++ b/src/FrameElement.h @@ -0,0 +1,71 @@ +/** +* @headerfile FrameElement.h +* @author Ulrich Kemloh <kemlohulrich@gmail.com> +* @version 0.5 +* Copyright (C) <2009-2014> +* +* @section LICENSE +* This file is part of JuPedSim. +* +* OpenPedSim is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* any later version. +* +* OpenPedSim is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with OpenPedSim. If not, see <http://www.gnu.org/licenses/>. +* +* @section DESCRIPTION +* +* \brief +* +* +*/ + + +#ifndef FRAME_ELEMENT_H_ +#define FRAME_ELEMENT_H_ + +class FrameElement { + +public: + FrameElement(int _id); + virtual ~FrameElement(); + + /// set/get the point ID + void SetId(int _id); + /// set/get the point ID + int GetId(); + + /// set/get the position of the point/agent + void GetPos(double pos[3]); + /// set/get the position of the point/agent + void SetPos(double pos[3]); + + ///Set/Get the agent scaling, semi axes of the ellipses + void SetRadius(double radius[3]); + void GetRadius(double radius[3]); + + /// Set/Get the phisical orientation of the agent + void SetOrientation(double angle[3]); + void GetOrientation(double angle[3]); + + /// Set/Get the color which codes the velocity + void SetColor(double color); + void GetColor(double* color); + +private: + int _id; + double _pos[3]; + double _radius[3]; + double _orientation[3]; + double _color; + +}; + +#endif /* FRAME_ELEMENT_H_ */ diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 6c3f0df55b58431be47db84c9ef77c180b4399e6..7b46263cbc6c8068e9ed9ac8f2f49864f71b21a7 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -61,6 +61,8 @@ #include <QColorDialog> #include <QDebug> #include <QtXml> +#include <QTemporaryFile> + #include <iostream> #include <limits> @@ -139,6 +141,8 @@ MainWindow::MainWindow(QWidget *parent) : numberOfDatasetLoaded=0; frameSliderHold=false; + //some hand made stuffs + ui.BtFullscreen->setVisible(false); labelCurrentAction = new QLabel(); labelCurrentAction->setFrameStyle(QFrame::Panel | QFrame::Sunken); @@ -178,7 +182,7 @@ MainWindow::MainWindow(QWidget *parent) : int group=1; // there are max 3 groups of pedestrians bool mayPlay=false; - // arguments.append("-online"); + // arguments.append("-online"); // arguments.append("-caption"); arguments.append("-2D"); // parse arguments list @@ -285,7 +289,7 @@ void MainWindow::slotNetworkSettings() { bool ok; int port = QInputDialog::getInt(this, tr("input a port "), tr( - "port(default to 8081):"), 8989, 5000, 65355, 1, &ok); + "port(default to 8989):"), 8989, 5000, 65355, 1, &ok); if (ok) { SystemSettings::setListningPort(port); @@ -326,12 +330,6 @@ void MainWindow::slotStartPlaying() { ui.BtRecord->setEnabled(true); labelCurrentAction->setText(" playing "); - ui.action3_D->setEnabled(false); - ui.action2_D->setEnabled(false); - - //disable legend - ui.actionShow_Legend->setEnabled(false); - //change Icon to Pause QIcon icon1; icon1.addPixmap(QPixmap(QString::fromUtf8( @@ -367,6 +365,7 @@ void MainWindow::slotStartPlaying() { //no matter what, the stop button should be enabled ui.BtStop->setEnabled(true); + } void MainWindow::slotStopPlaying() { @@ -390,6 +389,7 @@ void MainWindow::slotStopPlaying() { // maybe this is a feature ! extern_shutdown_visual_thread=true; waitForVisioThread(); + //waitForDataThread(); //reset all frames cursors resetAllFrameCursor(); @@ -427,10 +427,8 @@ FacilityGeometry* MainWindow::parseGeometry(QDomNode geoNode){ { if (fileName.endsWith(".xml",Qt::CaseInsensitive)) { - //cout<<"good bye"<<endl; exit(0); - //should be a file name - //return parseGeometryPG3(fileName); - //SaxParser::parseGeometryPG3(fileName,geometry); + //parsing the file + SaxParser::parseGeometryJPS(fileName,geometry); } else if (fileName.endsWith(".trav",Qt::CaseInsensitive)) { @@ -442,12 +440,94 @@ FacilityGeometry* MainWindow::parseGeometry(QDomNode geoNode){ //which is the only one which can directly be inserted into a file else { + //cout<<"online geo: "<<geoNode.toDocument().toString().toStdString()<<endl; exit(0); + //geoNode.toText().toComment().toDocument().toString() + QDomDocument doc(""); + QDomNode geoNode; + if(!geoNode.isNull()){ + cout<<"online geo: "<<geoNode.toElement().toDocument().toString().toStdString()<<endl; exit(0); + } + //must not be a file name SaxParser::parseGeometryTRAV(fileName,geometry,geoNode); } return geometry; } +// This function is only used in online Mode +FacilityGeometry* MainWindow::parseGeometry(QString geometryString) +{ + +// QDomDocument doc(""); +// data = "<travisto>\n" +data+ "\n</travisto>\n"; + +// QString errorMsg=""; +// doc.setContent(data,&errorMsg); + +// if(!errorMsg.isEmpty()){ +// Debug::Error("%s", (const char *)errorMsg.toStdString().c_str()); +// return; +// } + +// QDomNode geoNode =doc.elementsByTagName("geometry").item(0); + + //create a temporary file with the content geonode + +// QTemporaryFile file; +// file.setFileName(file.fileName()+".xml"); +// if (file.open()) { +// QTextStream stream(&file); +// stream << geoNode << endl; +// } + + QFile file("_geometry_tmp_file.xml"); + if (file.open(QIODevice::WriteOnly | QIODevice::Text)) + { + QTextStream stream(&file); + stream << geometryString << endl; + } + + QString tmpFileName = file.fileName(); + + //check if there is a tag 'file' there in + QString geofileName = SaxParser::extractGeometryFilename(tmpFileName); + + //cout<<"filename: "<<geofileName.toStdString()<<endl;exit(0); + + FacilityGeometry* geometry = visualisationThread->getGeometry(); + + if(!geofileName.isEmpty()) + { + if (geofileName.endsWith(".xml",Qt::CaseInsensitive)) + { + //parsing the file + if(!SaxParser::parseGeometryJPS(geofileName,geometry)) + { + SaxParser::parseGeometryXMLV04(geofileName,geometry); + } + } + else if (geofileName.endsWith(".trav",Qt::CaseInsensitive)) + { + //must not be a file name + SaxParser::parseGeometryTRAV(geofileName,geometry); + } + } + // I assume it is a trav format node, + //which is the only one which can directly be inserted into a file + else + { + QDomDocument doc(""); + QDomNode geoNode; + + //must not be a file name + SaxParser::parseGeometryTRAV(geometryString,geometry,geoNode); + } + + //delete the file + file.remove(); + return geometry; +} + // TODO: still used? bool MainWindow::parsePedestrianShapes(QDomNode shapeNode, int groupID){ @@ -457,7 +537,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); @@ -505,23 +585,23 @@ bool MainWindow::parsePedestrianShapes(QDomNode shapeNode, int groupID){ /// add a new dataset bool MainWindow::slotAddDataSet(){ - if (numberOfDatasetLoaded>=3){ - QMessageBox::information(this,"notice","You can load at most 3 datasets.\n In" - " Order to load other data, please first clear previously loaded data."); - return false; - } - // if at least one data set was loaded - if (numberOfDatasetLoaded>=1){ - int res = QMessageBox::question(this, "action", - "adding a new dataset will reset the visualisation process. Continue?", QMessageBox::Discard - | QMessageBox::Yes, QMessageBox::Yes); +// if (numberOfDatasetLoaded>=3){ +// QMessageBox::information(this,"notice","You can load at most 3 datasets.\n In" +// " Order to load other data, please first clear previously loaded data."); +// return false; +// } - if (res == QMessageBox::Discard) return false; +// // if at least one data set was loaded +// if (numberOfDatasetLoaded>=1){ +// int res = QMessageBox::question(this, "action", +// "adding a new dataset will reset the visualisation process. Continue?", QMessageBox::Discard +// | QMessageBox::Yes, QMessageBox::Yes); - } +// if (res == QMessageBox::Discard) return false; +// } // just continue - numberOfDatasetLoaded++; + numberOfDatasetLoaded=1; if(addPedestrianGroup(numberOfDatasetLoaded)==false){ numberOfDatasetLoaded--; return false; @@ -532,6 +612,8 @@ bool MainWindow::slotAddDataSet(){ stre.append(" dataset loaded"); statusBar()->showMessage(stre); + slotStartPlaying(); + return true; } @@ -545,25 +627,62 @@ void MainWindow::slotClearAllDataset(){ } -bool MainWindow::addPedestrianGroup(int groupID,QString fileName){ +bool MainWindow::addPedestrianGroup(int groupID,QString fileName) +{ statusBar()->showMessage(tr("Select a file")); - if(fileName.isEmpty()) fileName = QFileDialog::getOpenFileName(this, - "Select the file containing data to visualize", + "Select the file containing the data to visualize", "F:\\workspace\\JPSvis\\data", - "Visualisation Files (*.dat *.trav *.xml *.pg3 *.jul);;All Files (*.*)"); + "Visualisation Files (*.dat *.trav *.xml);;All Files (*.*)"); if (fileName.isNull()) { return false; } + + + + //get and set the working dir + QFileInfo fileInfo(fileName); + QString wd=fileInfo.absoluteDir().absolutePath(); + SystemSettings::setWorkingDirectory(wd); + //the geometry actor - //FacilityGeometry* geometry=NULL; FacilityGeometry* geometry = visualisationThread->getGeometry(); + //try to get a geometry filename + QString geometry_file=SaxParser::extractGeometryFilename(fileName); + //cout<<"geometry name: "<<geometry_file.toStdString()<<endl; + // if xml is detected, just load and show the geometry then exit - if(fileName.endsWith(".xml",Qt::CaseInsensitive)){ - SaxParser::parseGeometryXMLV04(fileName,geometry); + if(geometry_file.endsWith(".xml",Qt::CaseInsensitive)){ + + //try to parse the correct way + // fall back to this if it fails + SystemSettings::CreateLogfile(); + + if(! SaxParser::parseGeometryJPS(geometry_file,geometry)) + { + int res = QMessageBox::warning(this, "Errors in Geometry. Continue Parsing?", + "JuPedSim has detected an error in the supplied geometry.\n" + "The simulation will likely failed using that geometry.\n" + "Also make sure to validate your file.\n" + "More information are provided in the log file:\n" + +SystemSettings::getLogfile()+ + "\n\nShould I try to parse and display what I can ?" + , QMessageBox::Yes + | QMessageBox::No, QMessageBox::No); + if (res == QMessageBox::No) { + return false; + } + SaxParser::parseGeometryXMLV04(wd+"/"+geometry_file,geometry); + } + else + { //everything was fine. Delete the log file + SystemSettings::DeleteLogfile(); + } + + //SaxParser::parseGeometryXMLV04(fileName,geometry); //slotLoadParseShowGeometry(fileName); //return false; } @@ -574,8 +693,11 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName){ return false; } - SyncData* dataset=NULL; + SyncData* dataset=NULL; + extern_trajectories_firstSet.clearFrames(); + extern_trajectories_secondSet.clearFrames(); + extern_trajectories_thirdSet.clearFrames(); switch(groupID){ case 1: @@ -611,10 +733,12 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName){ default: Debug::Error("invalid pedestrian group: %d " ,groupID); Debug::Error("should be 1, 2 or 3"); - return false; + //return false; break; } + + double frameRate=15; //default frame rate statusBar()->showMessage(tr("parsing the file")); QXmlInputSource source(&file); @@ -628,10 +752,10 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName){ reader.parse(source); file.close(); - QString frameRateStr=QString::number(frameRate); SystemSettings::setFilenamePrefix(QFileInfo ( fileName ).baseName()+"_"); + // set the visualisation window title visualisationThread->setWindowTitle(fileName); visualisationThread->slotSetFrameRate(frameRate); @@ -683,10 +807,8 @@ void MainWindow::slotFullScreen(bool status) { Debug::Messages("changing full screen status %d",status); extern_fullscreen_enable = true; - //dont forget this. extern_force_system_update=true; - } void MainWindow::slotSetOfflineMode(bool status) { @@ -920,7 +1042,7 @@ void MainWindow::resetGraphicalElements(){ ui.BtRecord->setEnabled(false); //disable fullscreen - ui.BtFullscreen->setEnabled(false); + //ui.BtFullscreen->setEnabled(false); //disable stop button @@ -991,21 +1113,32 @@ bool MainWindow::anyDatasetLoaded(){ extern_third_dataset_loaded); } -void MainWindow::slotShowTrajectoryOnly(){ - if(ui.actionShow_Trajectories->isChecked()){ - //visualisationThread->setTrailVisibility(true); +void MainWindow::slotShowTrajectoryOnly() +{ + if(ui.actionShow_Trajectories->isChecked()) + { extern_tracking_enable=true; - //ui.actionShow_Trajectories->setEnabled(false); - }else{ + } + else + { extern_tracking_enable=false; - //visualisationThread->setTrailVisibility(false); } + extern_force_system_update=true; } -/// TODO: implement me -void MainWindow::slotShowPedestrianOnly(){ - Debug::Error("Not implemented"); +void MainWindow::slotShowPedestrianOnly() +{ + + if(ui.actionShow_Agents->isChecked()) + { + SystemSettings::setShowAgents(true); + } + else + { + SystemSettings::setShowAgents(false); + } + extern_force_system_update=true; } void MainWindow::slotShowGeometry(){ @@ -1014,13 +1147,21 @@ void MainWindow::slotShowGeometry(){ visualisationThread->setGeometryVisibility(true); ui.actionShow_Exits->setEnabled(true); ui.actionShow_Walls->setEnabled(true); + ui.actionShow_Geometry_Captions->setEnabled(true); + ui.actionShow_Navigation_Lines->setEnabled(true); + ui.actionShow_Floor->setEnabled(true); + SystemSettings::setShowGeometry(true); } else{ visualisationThread->setGeometryVisibility(false); ui.actionShow_Exits->setEnabled(false); ui.actionShow_Walls->setEnabled(false); + ui.actionShow_Geometry_Captions->setEnabled(false); + ui.actionShow_Navigation_Lines->setEnabled(false); + ui.actionShow_Floor->setEnabled(false); + SystemSettings::setShowGeometry(false); } - + extern_force_system_update=true; } /// shows/hide geometry @@ -1043,6 +1184,24 @@ void MainWindow::slotShowHideWalls(){ } } +void MainWindow::slotShowHideNavLines() +{ + if (ui.actionShow_Navigation_Lines->isChecked()){ + visualisationThread->showNavLines(true); + } + else{ + visualisationThread->showNavLines(false); + } +} + +//todo: add to the system settings +void MainWindow::slotShowHideFloor() +{ + bool status = ui.actionShow_Floor->isChecked(); + visualisationThread->showFloor(status); + SystemSettings::setShowFloor(status); +} + /// update the playing speed void MainWindow::slotUpdateSpeedSlider(int newValue){ @@ -1208,7 +1367,8 @@ void MainWindow::slotToogle2D(){ ui.action3_D->setChecked(true); SystemSettings::set2D(false); } - visualisationThread->setGeometryVisibility2D(SystemSettings::get2D()); + bool status=SystemSettings::get2D() && SystemSettings::getShowGeometry(); + visualisationThread->setGeometryVisibility2D(status); extern_force_system_update=true; } @@ -1224,7 +1384,8 @@ void MainWindow::slotToogle3D(){ ui.action2_D->setChecked(true); SystemSettings::set2D(true); } - visualisationThread->setGeometryVisibility3D(!SystemSettings::get2D()); + bool status= !SystemSettings::get2D() && SystemSettings::getShowGeometry(); + visualisationThread->setGeometryVisibility3D(status); extern_force_system_update=true; } @@ -1260,7 +1421,6 @@ void MainWindow::slotStartVisualisationThread(QString data,int numberOfAgents,fl slotToggleFirstPedestrianGroup(); QDomDocument doc(""); - data = "<travisto>\n" +data+ "\n</travisto>\n"; QString errorMsg=""; doc.setContent(data,&errorMsg); @@ -1270,12 +1430,17 @@ void MainWindow::slotStartVisualisationThread(QString data,int numberOfAgents,fl return; } - QDomNode geoNode =doc.elementsByTagName("geometry").item(0); - FacilityGeometry *geo = parseGeometry(geoNode); + //FacilityGeometry *geo = parseGeometry(geoNode); + FacilityGeometry *geo = parseGeometry(data); visualisationThread->slotSetFrameRate(frameRate); visualisationThread->setGeometry(geo); visualisationThread->start(); + + //enable some buttons + ui.BtRecord->setEnabled(true); + ui.BtStop->setEnabled(true); + } /// this method is called by the data transfer thread @@ -1342,7 +1507,7 @@ void MainWindow::slotPreviousFrame(){ void MainWindow::slotShowPedestrianCaption(){ - SystemSettings::setShowCaptions(ui.actionShow_Captions->isChecked()); + SystemSettings::setShowAgentsCaptions(ui.actionShow_Captions->isChecked()); extern_force_system_update=true; } @@ -1410,16 +1575,48 @@ 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; +} + +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->setFloorColor(color); delete colorDialog; } @@ -1544,7 +1741,6 @@ void MainWindow::dropEvent(QDropEvent *event) { mayPlay = true; } } - if (mayPlay) { slotStartPlaying(); } @@ -1563,5 +1759,6 @@ void MainWindow::slotShowHideGeometryCaptions(){ bool value=ui.actionShow_Geometry_Captions->isChecked(); visualisationThread->setGeometryLabelsVisibility(value); + //SystemSettings::setShowCaptions(value); //SystemSettings::setOnScreenInfos(value); } diff --git a/src/MainWindow.h b/src/MainWindow.h index 6c5e91e1035459f675c02c8fc03cd52f31f31e2a..2263fbb9cb80c8765643335c6d7a74464722eaf9 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -173,18 +173,18 @@ public Q_SLOTS: void slotShowHideExits(); /// shows/hide geometry 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); @@ -241,6 +241,12 @@ public Q_SLOTS: /// change the exits color void slotChangeExitsColor(); + /// 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(); @@ -249,8 +255,6 @@ private: Q_SIGNALS: void signal_controlSequence(QString); - - protected: virtual void closeEvent(QCloseEvent* event); void dragEnterEvent(QDragEnterEvent *event); @@ -274,7 +278,7 @@ private: /// parse the geometry Node and return a pointer to geometry object /// used in online mode only FacilityGeometry* parseGeometry(QDomNode geoNode); - + FacilityGeometry* parseGeometry(QString geometryString); /** * parse a shape node and get the initials heights and colors of pedestrians. diff --git a/src/Pedestrian.cpp b/src/Pedestrian.cpp index 5cc3a350951043380b0a89b0895a91cfb8545684..0ba08551323532bda2ed368e669620cc9f135091 100644 --- a/src/Pedestrian.cpp +++ b/src/Pedestrian.cpp @@ -1235,14 +1235,15 @@ vtkAssembly * Pedestrian::getTrailActor(){ void Pedestrian::moveTo(TrajectoryPoint *point) { - double xNew = point->getX(); - double yNew = point->getY(); - double zNew = point->getZ(); + double xNew ;//= point->getX(); + double yNew ;//= point->getY(); + double zNew ;//= point->getZ(); + double ellipse[7]; double agentColorAngle[2]; - point->getEllipse(ellipse); - point->getAgentInfo(agentColorAngle); + //point->getEllipse(ellipse); + //point->getAgentInfo(agentColorAngle); // this are radius double ellipseColor=1; //red diff --git a/src/SaxParser.cpp b/src/SaxParser.cpp index 8734ce20d9351716d6edfdb0ba6e9745cc6364ec..78eaeff4677990c201e2c2b39b65a4c5828530db 100644 --- a/src/SaxParser.cpp +++ b/src/SaxParser.cpp @@ -29,6 +29,7 @@ #include "SaxParser.h" #include "TrajectoryPoint.h" +#include "FrameElement.h" #include "Frame.h" #include "SyncData.h" #include "Debug.h" @@ -36,6 +37,8 @@ #include "geometry/JPoint.h" #include "geometry/FacilityGeometry.h" #include "geometry/Building.h" +#include "geometry/Wall.h" +#include "SystemSettings.h" #include <QMessageBox> #include <QString> @@ -43,7 +46,6 @@ #include <iostream> #include <cmath> - #include <vtkVersion.h> #include <vtkSmartPointer.h> #include <vtkPolygon.h> @@ -58,6 +60,9 @@ #include <vtkProperty.h> #include <vtkTriangleFilter.h> +#define VTK_CREATE(type, name) \ + vtkSmartPointer<type> name = vtkSmartPointer<type>::New() + using namespace std; @@ -72,12 +77,14 @@ using namespace std; */ SaxParser::SaxParser(FacilityGeometry* geo, SyncData* data, double* fps){ geometry=geo; - dataset=data; + dataset=data; para=fps; parsingWalls=false; + parsingCrossings=false; color=0.0; - - dataset->clearFrames(); + dataset->clearFrames(); + //default header + InitHeader(0,0,0); } SaxParser::~SaxParser() { @@ -92,8 +99,26 @@ bool SaxParser::startElement(const QString & /* namespaceURI */, for(int i=0;i<at.length();i++){ if(at.localName(i)=="version") { - double version=at.value(i).toDouble(); - InitHeader(version); + QStringList query = at.value(i).split("."); + int major=0; + int minor=0; + int patch=0; + switch (query.size() ) { + case 1: + major=query.at(0).toInt(); + break; + case 2: + major=query.at(0).toInt(); + minor=query.at(1).toInt(); + break; + case 3: + major=query.at(0).toInt(); + minor=query.at(1).toInt(); + patch=query.at(2).toInt(); + break; + } + InitHeader(major,minor,patch); + //cout<<"version found:"<<at.value(i).toStdString()<<endl;exit(0); } } }else if (qName == "file") { @@ -105,7 +130,7 @@ bool SaxParser::startElement(const QString & /* namespaceURI */, { if(fileName.endsWith(".xml",Qt::CaseInsensitive)) { - SaxParser::parseGeometryJPS(fileName,geometry); + //SaxParser::parseGeometryJPS(fileName,geometry); } else if (fileName.endsWith(".trav",Qt::CaseInsensitive)) { @@ -342,6 +367,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") { @@ -422,9 +477,11 @@ bool SaxParser::startElement(const QString & /* namespaceURI */, else if(at.localName(i)==_jps_xPos) { xPos=at.value(i).toDouble()*FAKTOR; + //xPos=at.value(i).toDouble(); } else if(at.localName(i)==_jps_yPos) { + //yPos=at.value(i).toDouble(); yPos=at.value(i).toDouble()*FAKTOR; } else if(at.localName(i)==_jps_zPos) @@ -435,10 +492,12 @@ bool SaxParser::startElement(const QString & /* namespaceURI */, else if(at.localName(i)==_jps_radiusA) { dia_a=at.value(i).toDouble()*FAKTOR; + //dia_a=at.value(i).toDouble(); } else if(at.localName(i)==_jps_radiusB) { dia_b=at.value(i).toDouble()*FAKTOR; + //dia_b=at.value(i).toDouble(); } else if(at.localName(i)==_jps_ellipseOrientation) { @@ -472,17 +531,22 @@ bool SaxParser::startElement(const QString & /* namespaceURI */, if(isnan(el_y)) el_y=yPos; if(isnan(el_z)) el_z=zPos; - double pos[3]={xPos,yPos,zPos}; + //double pos[3]={xPos,yPos,zPos}; double vel[3]={xVel,yPos,zPos}; double ellipse[7]={el_x,el_y,el_z,dia_a,dia_b,el_angle,el_color}; double para[2]={agent_color,el_angle}; - TrajectoryPoint * point = new TrajectoryPoint(id-1); - point->setEllipse(ellipse); - point->setPos(pos); - point->setVel(vel); - point->setAgentInfo(para); - currentFrame.push_back(point); + double pos[3]={xPos,yPos,zPos}; + double angle[3]={0,0,el_angle}; + double radius[3]={dia_a,dia_b,30.0}; + + FrameElement *element = new FrameElement(id-1); + element->SetPos(pos); + element->SetOrientation(angle); + element->SetRadius(radius); + element->SetColor(el_color); + currentFrame.push_back(element); + } else if (qName == "agentInfo") { @@ -534,6 +598,7 @@ bool SaxParser::endElement(const QString & /* namespaceURI */, } else if (qName == "frameRate") { para[0]=currentText.toFloat(); } else if (qName == "wall") { + if(currentPointsList.size()>1) for(unsigned int i=0;i<currentPointsList.size()-1;i++){ geometry->addWall(currentPointsList[i],currentPointsList[i+1],caption.toStdString()); } @@ -543,7 +608,19 @@ bool SaxParser::endElement(const QString & /* namespaceURI */, geometry->addDoor(currentPointsList[i],currentPointsList[i+1],caption.toStdString()); } clearPoints(); - } else if (qName == "step") {//FIXME + } else if (qName == "crossing") { + if(currentPointsList.size()>1) //hack + for(unsigned int i=0;i<currentPointsList.size()-1;i++){ + geometry->addNavLine(currentPointsList[i],currentPointsList[i+1],caption.toStdString()); + } + clearPoints(); + } else if (qName == "hline") { + if(currentPointsList.size()>1) //hack + 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()); } @@ -553,10 +630,13 @@ bool SaxParser::endElement(const QString & /* namespaceURI */, while(!currentFrame.empty()){ frame->addElement(currentFrame.back()); currentFrame.pop_back(); - //cout<<"not adding"<<endl; + //cout<<"not adding"<<endl; } - dataset->addFrame(frame); + //compute the polydata, might increase the runtime + frame->ComputePolyData(); + + dataset->addFrame(frame); //to be on the safe side currentFrame.clear(); @@ -589,9 +669,6 @@ bool SaxParser::attributeDecl(const QString& eName, const QString& aName, } void SaxParser::clearPoints(){ - -// currentPointsList.clear(); - while (!currentPointsList.empty()){ delete currentPointsList.back(); currentPointsList.pop_back(); @@ -604,91 +681,153 @@ void SaxParser::clearPoints(){ /// provided for convenience and will be removed in the next version -void SaxParser::parseGeometryJPS(QString fileName, FacilityGeometry *geometry){ - - if(!fileName.endsWith(".xml",Qt::CaseInsensitive)) return ; +bool SaxParser::parseGeometryJPS(QString fileName, FacilityGeometry *geometry) +{ - Building* building = new Building(); - string geometrypath = fileName.toStdString(); + double captionsColor=0;//red + if(!fileName.endsWith(".xml",Qt::CaseInsensitive)) return false; + QString wd; + SystemSettings::getWorkingDirectory(wd); + fileName=wd+"/"+fileName; - // read the geometry - building->LoadBuildingFromFile(geometrypath); - building->InitGeometry(); // create the polygons + Building* building = new Building(); + string geometrypath = fileName.toStdString(); - int currentID=0; - // Setup the points - vtkSmartPointer<vtkPoints> points = - vtkSmartPointer<vtkPoints>::New(); + // read the geometry + if(!building->LoadBuildingFromFile(geometrypath)) + return false; + if(!building->InitGeometry()) + return false; // create the polygons - // Add the polygon to a list of polygons - vtkSmartPointer<vtkCellArray> polygons = - vtkSmartPointer<vtkCellArray>::New(); + int currentID=0; + // Setup the points + VTK_CREATE(vtkPoints,points); + // Add the polygon to a list of polygons + VTK_CREATE(vtkCellArray,polygons); - for (int i = 0; i < building->GetNumberOfRooms(); i++) { - Room* r = building->GetRoom(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++) { - SubRoom* sub = r->GetSubRoom(k); + for (int k = 0; k < r->GetNumberOfSubRooms(); k++) + { + SubRoom* sub = r->GetSubRoom(k); + vector<Point> poly = sub->GetPolygon(); if(sub->IsClockwise()==true){ std::reverse(poly.begin(),poly.end()); } - // Create the polygon - vtkSmartPointer<vtkPolygon> polygon = - vtkSmartPointer<vtkPolygon>::New(); - polygon->GetPointIds()->SetNumberOfIds(poly.size()); + // Create the polygon + VTK_CREATE(vtkPolygon,polygon); + polygon->GetPointIds()->SetNumberOfIds(poly.size()); - for (unsigned int s=0;s<poly.size();s++){ - points->InsertNextPoint(poly[s]._x*FAKTOR,poly[s]._y*FAKTOR,sub->GetElevation(poly[s])*FAKTOR); - polygon->GetPointIds()->SetId(s, currentID++); - } + for (unsigned int s=0;s<poly.size();s++){ + points->InsertNextPoint(poly[s]._x*FAKTOR,poly[s]._y*FAKTOR,sub->GetElevation(poly[s])*FAKTOR); + polygon->GetPointIds()->SetId(s, currentID++); + } + polygons->InsertNextCell(polygon); - polygons->InsertNextCell(polygon); - } - } + //plot the walls only for not stairs - // Create a PolyData - vtkSmartPointer<vtkPolyData> polygonPolyData = - vtkSmartPointer<vtkPolyData>::New(); - polygonPolyData->SetPoints(points); - polygonPolyData->SetPolys(polygons); + 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); - //triagulate everything - vtkSmartPointer<vtkTriangleFilter> filter=vtkSmartPointer<vtkTriangleFilter>::New(); + if(sub->GetType()=="stair") + { + geometry->addStair(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR); + } + else + { + geometry->addWall(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR); + } + } - // Create a mapper and actor - vtkSmartPointer<vtkPolyDataMapper> mapper = - vtkSmartPointer<vtkPolyDataMapper>::New(); + //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 to represent the floor + VTK_CREATE(vtkPolyData, polygonPolyData); + polygonPolyData->SetPoints(points); + polygonPolyData->SetPolys(polygons); + geometry->addFloor(polygonPolyData); -#if VTK_MAJOR_VERSION <= 5 - filter->SetInput(polygonPolyData); - mapper->SetInput(filter->GetOutput()); -#else - filter->SetInputData(polygonPolyData); - mapper->SetInputConnection(filter->GetOutputPort()); -#endif + // 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); + } - vtkSmartPointer<vtkActor> actor = - vtkSmartPointer<vtkActor>::New(); - actor->SetMapper(mapper); - actor->GetProperty()->SetColor(0,0,1); - actor->GetProperty()->SetOpacity(0.5); - //actor->GetProperty()->SetLineWidth(5); + // 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); + } - geometry->getActor()->AddPart(actor); + //TODO:dirty hack for parsing the Hlines + // free memory + delete building; - // free memory - delete building; + return true; } /// provided for convenience and will be removed in the next version -void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QDomNode geo){ + +void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QDomNode geo) +{ cout<<"external geometry found"<<endl; //creating am empty document @@ -752,7 +891,7 @@ void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QD //parsing the walls - for (unsigned int i = 0; i < walls.length(); i++) { + for ( int i = 0; i < walls.length(); i++) { QDomElement el = walls.item(i).toElement(); //wall thickness, default to 30 cm @@ -765,7 +904,7 @@ void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QD //get the points defining each wall //not that a wall is not necessarily defined by two points, could be more... QDomNodeList points = el.elementsByTagName("point"); - for (unsigned int i = 0; i < points.length() - 1; i++) { + for ( int i = 0; i < points.length() - 1; i++) { double x1=points.item(i).toElement().attribute("xPos", "0").toDouble()*FAKTOR; double y1=points.item(i).toElement().attribute("yPos", "0").toDouble()*FAKTOR; @@ -780,7 +919,7 @@ void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QD //parsing the doors if(doors.length()>0) - for (unsigned int i = 0; i < doors.length(); i++) { + for ( int i = 0; i < doors.length(); i++) { QDomElement el = doors.item(i).toElement(); //door thickness, default to 15 cm @@ -794,7 +933,7 @@ void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QD //not that a wall is not necesarily defined by two points, could be more... QDomNodeList points = el.elementsByTagName("point"); //Debug::Messages("found: " << points.length() <<" for this wall" <<endl; - for (unsigned int i = 0; i < points.length() - 1; i++) { + for ( int i = 0; i < points.length() - 1; i++) { double x1=points.item(i).toElement().attribute("xPos", "0").toDouble()*FAKTOR; double y1=points.item(i).toElement().attribute("yPos", "0").toDouble()*FAKTOR; @@ -808,7 +947,7 @@ void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QD } // parsing the objets - for (unsigned int i = 0; i < spheres.length(); i++) { + for ( int i = 0; i < spheres.length(); i++) { double center[3]; center[0] = spheres.item(i).toElement().attribute("centerX", "0").toDouble()*FAKTOR; @@ -822,7 +961,7 @@ void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QD geometry->addObjectSphere(center,radius,color); } // cubic shapes - for (unsigned int i = 0; i < cuboids.length(); i++) { + for ( int i = 0; i < cuboids.length(); i++) { double center[3]; center[0] = cuboids.item(i).toElement().attribute("centerX", "0").toDouble()*FAKTOR; @@ -874,19 +1013,82 @@ void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QD } // you should normally have only one geometry node, but one never knows... geoNode = geoNode.nextSiblingElement("geometry"); - } + } } -void SaxParser::parseGeometryXMLV04(QString filename, FacilityGeometry *geo){ +QString SaxParser::extractGeometryFilename(QString &filename) +{ + QString extracted_geo_name=""; + //first try to look at a string <file location="filename.xml"/> + QFile file(filename); + QString line; + if (file.open(QIODevice::ReadOnly | QIODevice::Text)) + { + QTextStream in(&file); + while (!in.atEnd()) { + //look for a line with + line = in.readLine(); + //cout<<"checking: "<<line.toStdString()<<endl; + if(line.contains("location" ,Qt::CaseInsensitive)) + if(line.contains("<file" ,Qt::CaseInsensitive)) + {//try to extract what ever is inside the quotes + + QString begin="\""; + QString end="\""; + int startIndex = line.indexOf(begin)+begin.length(); + if(startIndex <= 0)continue; //false alarm + int endIndex = line.indexOf(end,startIndex); + if(endIndex <= 0)continue; // false alarm + extracted_geo_name= line.mid(startIndex,endIndex - startIndex); + cout<<"geoName:"<<extracted_geo_name.toStdString()<<endl; + return extracted_geo_name; + //break;// we are done + } + if(line.contains("<geometry" ,Qt::CaseInsensitive)) + if(line.contains("version" ,Qt::CaseInsensitive)) + {//real geometry file + QFileInfo fileInfoGeometry(filename); + extracted_geo_name=fileInfoGeometry.fileName(); + return extracted_geo_name; + } + } + } + + //maybe this is already the geometry file itself ? + //do a rapid test +// FacilityGeometry* geo = new FacilityGeometry(); +// QFileInfo fileInfoGeometry(filename); +// extracted_geo_name=fileInfoGeometry.fileName(); + +// //just check if it starts with geometry +// //if(parseGeometryJPS(extracted_geo_name,geo)==true) +// //{ +// return extracted_geo_name; +// //} +// delete geo; + + return ""; +} + + +void SaxParser::parseGeometryXMLV04(QString filename, FacilityGeometry *geo) +{ QDomDocument doc(""); QFile file(filename); - //int size =file.size()/(1024*1024); - //if(size>100){ - // cout<<"The file is too large: "<<filename.toStdString()<<endl; - // return; - //} + int size =file.size()/(1024*1024); + + //avoid dom parsing a very large dataset + if(size>500){ + //cout<<"The file is too large: "<<filename.toStdString()<<endl; + return; + } + + //cout<<"filename: "<<filename.toStdString()<<endl; + + //TODO: check if you can parse this with the building classes. + // This should be a fall back option if (!file.open(QIODevice::ReadOnly)) { qDebug()<<"could not open the file: "<<filename<<endl; @@ -919,7 +1121,7 @@ void SaxParser::parseGeometryXMLV04(QString filename, FacilityGeometry *geo){ //parsing the subrooms QDomNodeList xSubRoomsNodeList=doc.elementsByTagName("subroom"); //parsing the walls - for (unsigned int i = 0; i < xSubRoomsNodeList.length(); i++) { + for ( int i = 0; i < xSubRoomsNodeList.length(); i++) { QDomElement xPoly = xSubRoomsNodeList.item(i).firstChildElement("polygon"); double position[3]={0,0,0}; double pos_count=1; @@ -993,6 +1195,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"); @@ -1002,7 +1205,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; @@ -1012,14 +1215,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"); @@ -1045,22 +1248,9 @@ void SaxParser::parseGeometryXMLV04(QString filename, FacilityGeometry *geo){ } } -void SaxParser::InitHeader(double version) +void SaxParser::InitHeader(int major, int minor, int patch) { - // set the parsing String map - if(version==0.5){ - _jps_xPos=QString("xPos"); - _jps_yPos=QString("yPos"); - _jps_zPos=QString("zPos"); - _jps_xVel=QString("xVel"); - _jps_yVel=QString("yVel"); - _jps_zVel=QString("zVel"); - _jps_radiusA=QString("radiusA"); - _jps_radiusB=QString("radiusB"); - _jps_ellipseOrientation=QString("ellipseOrientation"); - _jps_ellipseColor=QString("ellipseColor"); - } - else if (version==0.6){ + if ( (minor==6) || (minor==5 && patch==1) ){ _jps_xPos=QString("x"); _jps_yPos=QString("y"); _jps_zPos=QString("z"); @@ -1074,8 +1264,20 @@ void SaxParser::InitHeader(double version) } else { - cout<<"unsupported header version: "<<version<<endl; - cout<<"Please use 0.5 or 0.6 "<<endl; + _jps_xPos=QString("xPos"); + _jps_yPos=QString("yPos"); + _jps_zPos=QString("zPos"); + _jps_xVel=QString("xVel"); + _jps_yVel=QString("yVel"); + _jps_zVel=QString("zVel"); + _jps_radiusA=QString("radiusA"); + _jps_radiusB=QString("radiusB"); + _jps_ellipseOrientation=QString("ellipseOrientation"); + _jps_ellipseColor=QString("ellipseColor"); + } + if(major!=0){ + cout<<"unsupported header version: "<<major<<"."<<minor<<"."<<patch<<endl; + cout<<"Please use 0.5 0.5.1 or 0.6 "<<endl; exit(0); } } diff --git a/src/SaxParser.h b/src/SaxParser.h index a4ae9edd73f936ecb670cd8f5924aa1a9f5d4714..dbd4f6dd9e6e80e50884e2d13925828310bca764 100644 --- a/src/SaxParser.h +++ b/src/SaxParser.h @@ -40,6 +40,7 @@ //forwarded classes class JPoint; class TrajectoryPoint; +class FrameElement; class SyncData; class FacilityGeometry; @@ -64,7 +65,7 @@ public: const QString& value); /// provided for convenience and will be removed in the next version - static void parseGeometryJPS(QString content, FacilityGeometry *geo); + static bool parseGeometryJPS(QString content, FacilityGeometry *geo); /// provided for convenience and will be removed in the next version static void parseGeometryXMLV04(QString content, FacilityGeometry *geo); @@ -72,10 +73,13 @@ public: /// provided for convenience and will be removed in the next version static void parseGeometryTRAV(QString content, FacilityGeometry *geo,QDomNode geoNode=QDomNode()); + /// take a large file and find the geometry file location. + static QString extractGeometryFilename(QString& filename); + private: //clear the mo void clearPoints(); - void InitHeader(double version); + void InitHeader(int major, int minor, int patch); private: FacilityGeometry* geometry; @@ -85,8 +89,9 @@ private: QStringList initialPedestriansColors; QStringList initialPedestriansHeights; std::vector<JPoint *> currentPointsList; - std::vector<TrajectoryPoint *> currentFrame; + std::vector<FrameElement *> currentFrame; bool parsingWalls; + bool parsingCrossings; //wall and door parameters double thickness; diff --git a/src/SystemSettings.cpp b/src/SystemSettings.cpp index 7151f5581bd7f2f6492e5bc6c4afbf8e6c1e5e39..8cbd50756b66875e835f123121a2df6ce5058099 100644 --- a/src/SystemSettings.cpp +++ b/src/SystemSettings.cpp @@ -36,16 +36,20 @@ #include "SystemSettings.h" #include "Debug.h" +#include "qdebug.h" +#include "QDateTime" +#include "IO/OutputHandler.h" #include "./forms/Settings.h" bool SystemSettings::showLegend=false; bool SystemSettings::pedColorProfileReadFromFile=true; -bool SystemSettings::showCaption=false; +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}; -//double SystemSettings::ellipseShape[]={21.0,21.0}; -//int SystemSettings::pedestriansColor[3][3]={{255 , 0, 255},{122, 255, 122},{130, 130, 130}}; int SystemSettings::pedestriansColor[3][3]={{255 , 17, 224},{122, 255, 122},{130, 130, 130}}; int SystemSettings::pedesShape=Settings::PINGUINS; int SystemSettings::ellipseResolution=10; @@ -63,8 +67,12 @@ bool SystemSettings::onScreenInfos=true; bool SystemSettings::recordPNGsequence=false; //QString SystemSettings::outputDir =QDir::currentPath()+"/"; QString SystemSettings::outputDir = QDir::homePath() +"/Desktop/TraVisTo_Files/"; +QString SystemSettings::workingDir = QDir::currentPath(); QString SystemSettings::filesPrefix=""; +QString SystemSettings::logfile="log.txt"; +//the log file is writting by a different module +extern OutputHandler* Log; SystemSettings::SystemSettings() {} @@ -90,12 +98,12 @@ unsigned short SystemSettings::getListeningPort(){ } -void SystemSettings::setShowCaptions(bool caption){ - showCaption=caption; +void SystemSettings::setShowAgentsCaptions(bool caption){ + showAgentsCaptions=caption; } -bool SystemSettings::getShowCaption(){ - return showCaption; +bool SystemSettings::getShowAgentsCaptions(){ + return showAgentsCaptions; } void SystemSettings::set2D(bool lis2D){ @@ -105,6 +113,46 @@ bool SystemSettings::get2D(){ return is2D; } +// set/get the 2D visio +void SystemSettings::setShowAgents(bool status) +{ + showAgents=status; +} + +bool SystemSettings::getShowAgents() +{ + return showAgents; +} + +void SystemSettings::setShowGeometry(bool status) +{ + showGeometry=status; +} + +bool SystemSettings::getShowGeometry() +{ + return showGeometry; +} + +void SystemSettings::setShowFloor(bool status) +{ + showFloor=status; +} + +bool SystemSettings::getShowFloor() +{ + return showFloor; +} + +void SystemSettings::setWorkingDirectory(QString dir) +{ + workingDir=dir; +} + +void SystemSettings::getWorkingDirectory(QString& dir) +{ + dir=workingDir; +} void SystemSettings::getBackgroundColor(double* col){ col[0]=bgColor[0]; @@ -176,15 +224,12 @@ void SystemSettings::getPedestrianColor(int groupID, int color[3]){ void SystemSettings::setOutputDirectory(QString dir){ outputDir=dir; } + void SystemSettings::getOutputDirectory(QString& dir){ dir=QString(outputDir); } -//void SystemSettings::setPedestrianCaptionSize( int size){ -// captionSize =size; -//} - int SystemSettings::getPedestrianCaptionSize(){ return captionSize; } @@ -201,7 +246,35 @@ void SystemSettings::setFilenamePrefix(QString prefix){ } QString SystemSettings::getFilenamePrefix() { - return filesPrefix; + return filesPrefix; +} + +void SystemSettings::CreateLogfile() +{ + //create directory if not exits + if(!QDir(outputDir).exists()){ + QDir dir; + if(!dir.mkpath (outputDir )){ + qDebug()<<"could not create directory: "<< outputDir; + outputDir=""; // current + } + } + + logfile = outputDir+"log_"+QDateTime::currentDateTime().toString("yyMMdd_hh_mm_").append(SystemSettings::getFilenamePrefix()).append(".txt"); +} + + QString &SystemSettings::getLogfile() +{ + return logfile; +} + +void SystemSettings::DeleteLogfile() +{ + //first close the opened file + delete Log; + if(! QFile::remove(logfile)){ + qDebug()<<"he log file could not delete the file"<<endl; + } } void SystemSettings::setPedestrianColorProfileFromFile(bool readFromFile) { diff --git a/src/SystemSettings.h b/src/SystemSettings.h index 31cbf0469515e66e7dc364487ff386ac5a7e6ce7..54327419cd3f36e9dc44990223e1da80ef1e48e2 100644 --- a/src/SystemSettings.h +++ b/src/SystemSettings.h @@ -48,17 +48,32 @@ public: bool static getShowLegend(); //set/get the caption status - void static setShowCaptions(bool caption); - bool static getShowCaption(); + void static setShowAgentsCaptions(bool caption); + bool static getShowAgentsCaptions(); // set/get the listening port void static setListningPort(unsigned short port); unsigned short static getListeningPort(); - // set/get the visio + // set/get the 2D visio void static set2D(bool is2D); bool static get2D(); + // set/get the agents visio + void static setShowAgents(bool status); + bool static getShowAgents(); + + // set/get the geometry visibility + 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); + // set/get the bk color // todo done directly in the travisto.cpp void static getBackgroundColor(double* col); @@ -99,18 +114,18 @@ public: /** * set the caption parameters - * - * @param size the caption size in point, default is 30 - * @param Col the color in rgb format - * @param orientation 0 is default, 1 is billboard - * @param automaticRotation true if the captions should keep their original orientation + * + * @param size the caption size in point, default is 30 + * @param Col the color in rgb format + * @param orientation 0 is default, 1 is billboard + * @param automaticRotation true if the captions should keep their original orientation */ void static setCaptionsParameters(int size, const QColor& Col, int orientation=0, bool automaticRotation=true); /** * * retrieve the caption parameters - * + * * @param size the caption size in point, default ist 30 * @param Col the color in rgb format * @param orientation 0 is default, 1 is billboard @@ -138,16 +153,22 @@ public: /// This is just the name of the input file. static QString getFilenamePrefix(); + static void CreateLogfile(); + static QString &getLogfile(); + static void DeleteLogfile(); + private: static bool recordPNGsequence; static bool pedColorProfileReadFromFile; static bool showLegend; - static bool showCaption; + static bool showAgentsCaptions; 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 double ellipseShape[2]; static int ellipseResolution; static int pedestriansColor[3][3]; // 3 groups, and 3 color per groups static int pedesShape; @@ -156,6 +177,8 @@ private: static int trailingType; static int trailingGeometry; static QString outputDir; + static QString workingDir; + static QString logfile; static int captionSize; static QColor captionColor; static int captionOrientaton; diff --git a/src/ThreadDataTransfert.cpp b/src/ThreadDataTransfert.cpp index 2a4251cd63d99fc5efec9485ffc8f4f137d18727..dc9a0da92a215140df4e18240e8e073425eff5cd 100644 --- a/src/ThreadDataTransfert.cpp +++ b/src/ThreadDataTransfert.cpp @@ -51,7 +51,7 @@ #include "ThreadDataTransfert.h" #include "SyncData.h" #include "Frame.h" -#include "TrajectoryPoint.h" +#include "FrameElement.h" #include "network/TraVisToServer.h" #include "geometry/FacilityGeometry.h" @@ -70,10 +70,9 @@ ThreadDataTransfer::ThreadDataTransfer(QObject *parent): headerParsed=false; errNr=0; finished=false; + //Debug::setDebugLevel(Debug::ALL); } - - ThreadDataTransfer::~ThreadDataTransfer() { } @@ -159,17 +158,16 @@ void ThreadDataTransfer::slotReadMessage(){ void ThreadDataTransfer::slotProcessMessage(QString& data){ QDomDocument doc(""); - data = "<travisto>\n" +data+ "\n</travisto>\n"; - - //cout<<data.toStdString()<<endl; + //data = "<travisto>\n" +data+ "</travisto>"; + //cout<<data.toStdString()<<endl; QString errorMsg=""; doc.setContent(data,&errorMsg); if(!errorMsg.isEmpty()){ errNr++; - Debug::Error(">> %s",(const char *)errorMsg.toStdString().c_str()); - Debug::Error(">> %s",(const char *)data.toStdString().c_str()); + //Debug::Error(">> %s",(const char *)errorMsg.toStdString().c_str()); + //Debug::Error(">> %s",(const char *)data.toStdString().c_str()); return; } @@ -191,6 +189,7 @@ void ThreadDataTransfer::slotProcessMessage(QString& data){ if(!geometry.isNull()) { //emit signal_loadGeometry(data); geoData=data; + Debug::Messages("geometry received and parsed"); //parseGeometryNode(geometry); } if(!dataList.isEmpty()) { @@ -227,11 +226,6 @@ void ThreadDataTransfer::parseHeaderNode(QDomNode header ){ emit signal_stopVisualisationThread(true); } - - // no need - //unsigned long timeFirstFrame_us = header.toElement().elementsByTagName("timeFirstFrame").item(0) - //unsigned long timeFirstFrame_s = header.toElement().elementsByTagName("timeFirstFrame").item(0) - // .toElement().attribute("sec",0).toUInt(); QString frameRateStr=getTagValueFromElement(header, "frameRate"); frameRate =frameRateStr.toFloat(&ok); @@ -245,8 +239,34 @@ void ThreadDataTransfer::parseHeaderNode(QDomNode header ){ msgBox.setIcon(QMessageBox::Critical); msgBox.exec(); frameRate=25; - } + + //get the header version + if(header.toElement().hasAttributes()) + { + QString version=header.toElement().attribute("version"); + QStringList query = version.split("."); + int major=0; + int minor=0; + int patch=0; + switch (query.size() ) { + case 1: + major=query.at(0).toInt(); + break; + case 2: + major=query.at(0).toInt(); + minor=query.at(1).toInt(); + break; + case 3: + major=query.at(0).toInt(); + minor=query.at(1).toInt(); + patch=query.at(2).toInt(); + break; + } + InitHeader(major,minor,patch); + //cout<<"version found:"<<at.value(i).toStdString()<<endl;exit(0); + } + headerParsed=true; } @@ -259,80 +279,57 @@ QString ThreadDataTransfer::getTagValueFromElement(QDomNode node, } void ThreadDataTransfer::parseDataNode(QDomNodeList frames){ - //static int frameNumbers=0; - - //parsing the data - // TODO: i amybe a problem - //emit signal_CurrentAction("parsing data"); - for (int i = 0; i < frames.length(); i++) { Frame *newFrame = new Frame(); QDomElement el = frames.item(i).toElement(); QDomNodeList agents = el.elementsByTagName("agent"); - //cout << "found: " << agents.length() <<" agents" <<endl; - for (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); if(!ok) continue; // invalid ID - double xPos=agents.item(i).toElement().attribute("xPos","0").toDouble()*FAKTOR; - double yPos=agents.item(i).toElement().attribute("yPos","0").toDouble()*FAKTOR; - double zPos=agents.item(i).toElement().attribute("zPos","0").toDouble()*FAKTOR; - - double agent_color =std::numeric_limits<double>::quiet_NaN(); - - double xVel=agents.item(i).toElement().attribute("xVel").toDouble(&ok)*FAKTOR; - if(!ok)xVel=std::numeric_limits<double>::quiet_NaN(); - double yVel=agents.item(i).toElement().attribute("yVel").toDouble(&ok)*FAKTOR; - if(!ok)yVel=std::numeric_limits<double>::quiet_NaN(); - double zVel=agents.item(i).toElement().attribute("zVel").toDouble(&ok)*FAKTOR; - if(!ok)zVel=std::numeric_limits<double>::quiet_NaN(); - - //coordinates of the ellipse, default to the head of the agent - double el_x=agents.item(i).toElement().attribute("xEll").toDouble(&ok)*FAKTOR; - if(!ok) el_x=xPos; - double el_y=agents.item(i).toElement().attribute("yEll").toDouble(&ok)*FAKTOR; - if(!ok) el_y=yPos; - double el_z=agents.item(i).toElement().attribute("zEll").toDouble(&ok)*FAKTOR; - if(!ok) el_z=zPos; - - double dia_a=agents.item(i).toElement().attribute("radiusA").toDouble(&ok)*FAKTOR; + double xPos=agents.item(i).toElement().attribute(_jps_xPos,"0").toDouble()*FAKTOR; + double yPos=agents.item(i).toElement().attribute(_jps_yPos,"0").toDouble()*FAKTOR; + double zPos=agents.item(i).toElement().attribute(_jps_zPos,"0").toDouble()*FAKTOR; + + double dia_a=agents.item(i).toElement().attribute(_jps_radiusA).toDouble(&ok)*FAKTOR; if(!ok)dia_a=std::numeric_limits<double>::quiet_NaN(); - double dia_b=agents.item(i).toElement().attribute("radiusB").toDouble(&ok)*FAKTOR; + double dia_b=agents.item(i).toElement().attribute(_jps_radiusB).toDouble(&ok)*FAKTOR; if(!ok)dia_b=std::numeric_limits<double>::quiet_NaN(); - double el_angle=agents.item(i).toElement().attribute("ellipseOrientation").toDouble(&ok); + double el_angle=agents.item(i).toElement().attribute(_jps_ellipseOrientation).toDouble(&ok); if(!ok){el_angle=std::numeric_limits<double>::quiet_NaN(); } - double el_color=agents.item(i).toElement().attribute("ellipseColor").toDouble(&ok); + double el_color=agents.item(i).toElement().attribute(_jps_ellipseColor).toDouble(&ok); if(!ok)el_color=std::numeric_limits<double>::quiet_NaN(); double pos[3]={xPos,yPos,zPos}; - double vel[3]={xVel,yPos,zPos}; - double ellipse[7]={el_x,el_y,el_z,dia_a,dia_b,el_angle,el_color}; - double para[2]={agent_color,el_angle}; - - TrajectoryPoint * point = new TrajectoryPoint(id-1); - point->setEllipse(ellipse); - point->setPos(pos); - point->setVel(vel); - point->setAgentInfo(para); - newFrame->addElement(point); + //double vel[3]={xVel,yPos,zPos}; + //double ellipse[7]={el_x,el_y,el_z,dia_a,dia_b,el_angle,el_color}; + //double para[2]={agent_color,el_angle}; + double angle[3]={0,0,el_angle}; + double radius[3]={dia_a,dia_b,30.0}; + + FrameElement *element = new FrameElement(id-1); + element->SetPos(pos); + element->SetOrientation(angle); + element->SetRadius(radius); + element->SetColor(el_color); + newFrame->addElement(element); } //adding the new frame to the right dataset + newFrame->ComputePolyData(); extern_trajectories_firstSet.addFrame(newFrame); // frameNumbers++; } - // cout <<"frames size: "<<extern_trajectories_firstSet.getSize()<<endl; - // cout <<"frames numbes: "<<frameNumbers<<endl; if(headerParsed==true){ // static int count=1; // count++; // if (count<100) return; // start after 100 frames emit signal_startVisualisationThread(geoData,numberOfAgents,frameRate); headerParsed=false; - // count=0; } } @@ -384,8 +381,6 @@ void ThreadDataTransfer::parseShapeNode(QDomNode shape){ QDomNodeList agents = shape.toElement().elementsByTagName("agentInfo"); QStringList heights; QStringList colors; - - for (int i = 0; i < agents.length(); i++) { bool ok=false; @@ -412,3 +407,31 @@ void ThreadDataTransfer::parseShapeNode(QDomNode shape){ extern_trajectories_firstSet.setInitialHeights(heights); extern_trajectories_firstSet.setInitialColors(colors); } + +void ThreadDataTransfer::InitHeader(int major, int minor, int patch) +{ + // set the parsing String map + if(minor==5 && patch==0){ + _jps_xPos=QString("xPos"); + _jps_yPos=QString("yPos"); + _jps_zPos=QString("zPos"); + _jps_radiusA=QString("radiusA"); + _jps_radiusB=QString("radiusB"); + _jps_ellipseOrientation=QString("ellipseOrientation"); + _jps_ellipseColor=QString("ellipseColor"); + } + else if ( (minor==6) || (minor==5 && patch==1) ){ + _jps_xPos=QString("x"); + _jps_yPos=QString("y"); + _jps_zPos=QString("z"); + _jps_radiusA=QString("rA"); + _jps_radiusB=QString("rB"); + _jps_ellipseOrientation=QString("eO"); + _jps_ellipseColor=QString("eC"); + } + else + { + cout<<"unsupported header version: "<<major<<"."<<minor<<"."<<patch<<endl; + cout<<"Please use 0.5 0.5.1 or 0.6 "<<endl; + } +} diff --git a/src/ThreadDataTransfert.h b/src/ThreadDataTransfert.h index e2f2a42f75226a316f96425b3f81f3e90374a93b..f738cfe13c4cab602b4343b7e8ea88631a5ea038 100644 --- a/src/ThreadDataTransfert.h +++ b/src/ThreadDataTransfert.h @@ -74,6 +74,10 @@ public: /// parse data node void parseDataNode(QDomNodeList data); + //old and new geometry format + void InitHeader(int major, int minor, int patch); + + private: QString getTagValueFromElement(QDomNode node, const char * tagName); @@ -107,8 +111,6 @@ public Q_SLOTS: void slotProcessMessage(QString& data); void slotConnectionClosed(); void slotDisplayError(QAbstractSocket::SocketError socketError); - //void slotConnected(); - //void slotDisconnected(); private: @@ -121,6 +123,16 @@ private: int numberOfAgents; float frameRate; bool finished; + + // temp variables to be removed in the next versions + //header dependant variables + QString _jps_xPos; + QString _jps_yPos; + QString _jps_zPos; + QString _jps_radiusA; + QString _jps_radiusB; + QString _jps_ellipseOrientation; + QString _jps_ellipseColor; }; #endif /* THREADDATATRANSFERT_H_ */ diff --git a/src/ThreadVisualisation.cpp b/src/ThreadVisualisation.cpp index e7692077c48177185904f4a7c00ed62eb71046f4..f40ea417f1969004d776ec1d5fa8a8e9b8f743bf 100644 --- a/src/ThreadVisualisation.cpp +++ b/src/ThreadVisualisation.cpp @@ -67,6 +67,13 @@ #include <vtkRegularPolygonSource.h> #include <vtkLabeledDataMapper.h> #include <vtkDiskSource.h> +#include <vtkTriangleFilter.h> +#include <vtkStripper.h> +#include <vtkSphereSource.h> +#include <vtkCylinderSource.h> +#include <vtkWindowToImageFilter.h> +#include <vtkActor.h> +#include <vtkLightKit.h> #include "geometry/FacilityGeometry.h" @@ -80,11 +87,8 @@ #include "SyncData.h" #include "InteractorStyle.h" #include "SystemSettings.h" +#include "geometry/PointPlotter.h" #include "Debug.h" -#include <vtkSphereSource.h> -#include <vtkCylinderSource.h> -#include <vtkWindowToImageFilter.h> -#include <vtkActor.h> //#include <vector> @@ -138,10 +142,6 @@ void ThreadVisualisation::run(){ //deactivate the output windows vtkObject::GlobalWarningDisplayOff(); -// vtkOutputWindow *w = vtkFileOutputWindow::New(); -// w->SetFileName("vtk_errors.txt"); -// vtkOutputWindow::SetInstance(w); -// w->Delete(); // now SetInstance owns the reference //emit signalStatusMessage("running"); @@ -150,28 +150,35 @@ void ThreadVisualisation::run(){ // set the background //renderer->SetBackground(.00,.00,.00); renderer->SetBackground(1.0,1.0,1.0); - //set the view port - //renderer->SetViewport(0,.5,1.0,1.0); //add the geometry - renderer->AddActor(geometry->getActor()); - + geometry->CreateActors(); + renderer->AddActor(geometry->getActor2D()); + renderer->AddActor(geometry->getActor3D()); //initialize the datasets - init(); - initGlyphs(); + //mem leak + extern_glyphs_pedestrians = vtkTensorGlyph::New(); + extern_glyphs_pedestrians_3D = vtkTensorGlyph::New(); + + initGlyphs2D(); + initGlyphs3D(); + + //create the trails + extern_trail_plotter = new PointPlotter(); + renderer->AddActor(extern_trail_plotter->getActor()); // add axis - axis= vtkAxesActor::New(); + //axis= vtkAxesActor::New(); //axis->SetScale(10); //axis->SetConeRadius(30); //axis->SetXAxisLabelText("1 Meter"); //axis->SetYAxisLabelText("1 Meter"); //axis->SetZAxisLabelText("1 Meter"); - axis->AxisLabelsOff(); + //axis->AxisLabelsOff(); //axis->SetCylinderRadius(100); //axis->set - axis->SetTotalLength(1000,1000,1000); - axis->SetVisibility(true); + //axis->SetTotalLength(1000,1000,1000); + //axis->SetVisibility(true); //renderer->AddActor(axis); //add big circle at null point @@ -212,7 +219,6 @@ void ThreadVisualisation::run(){ // Create a real circle, not a sphere { - VTK_CREATE(vtkRegularPolygonSource, polygonSource); polygonSource->GeneratePolygonOff(); polygonSource->SetNumberOfSides(50); @@ -228,13 +234,6 @@ void ThreadVisualisation::run(){ //renderer->AddActor(actor); } - - //cout << "diffuse: "<<actor->GetProperty()->GetDiffuse()<<" [" << actor->GetProperty()->GetDiffuseMinValue()<<" , "<<actor->GetProperty()->GetDiffuseMaxValue() << " ]"<<endl; - //cout << "ambiant: "<<actor->GetProperty()->GetAmbient()<<" [" << actor->GetProperty()->GetAmbientMinValue()<<" , "<<actor->GetProperty()->GetAmbientMaxValue() << " ]"<<endl; - //cout << "specular:"<<actor->GetProperty()->GetSpecular()<<" [" << actor->GetProperty()->GetSpecularMinValue()<<" , "<<actor->GetProperty()->GetSpecularMaxValue()<< " ]"<<endl; - - - //compute the relatives delays // necessary in the case several dataset were loaded computeDelays(); @@ -248,8 +247,8 @@ void ThreadVisualisation::run(){ //renderWindow->SetSize(1280, 960); // add the legend - if(SystemSettings::getShowLegend()) - initLegend(); + //if(SystemSettings::getShowLegend()) + // initLegend(); //add the running time frame runningTime = vtkTextActor::New(); @@ -284,59 +283,24 @@ void ThreadVisualisation::run(){ renderWindow->SetInteractor( renderWinInteractor ); renderWinInteractor->Initialize(); - //add at least three lights sources - { - vtkLight *light = vtkLight::New(); - light->SetIntensity(0.1); - light->SetPosition(30,30 ,500); - light->SetLightTypeToSceneLight(); - //renderer->AddLight(light); - light->Delete(); - } - { - vtkLight *light = vtkLight::New(); - light->SetIntensity(0.10); - light->SetPosition(2500,6500, 500); - light->SetLightTypeToSceneLight(); - //renderer->AddLight(light); - light->Delete(); - } - { - vtkLight *light = vtkLight::New(); - light->SetIntensity(0.1); - light->SetPosition(30,30 ,500); - light->SetLightTypeToSceneLight(); - //renderer->AddLight(light); - light->Delete(); - } + //add a light kit + { + VTK_CREATE(vtkLightKit, lightKit); + //lightKit->SetKeyLightIntensity(1); + //lightKit->SetKeyLightWarmth(5); + //lightKit->SetBackLightAngle(30,40); + //lightKit->SetKeyLightWarmth(2.0); + //lightKit->SetMaintainLuminance(true); + //lightKit->AddLightsToRenderer(renderer); + } - if(SystemSettings::get2D()){ - renderer->GetActiveCamera()->OrthogonalizeViewUp(); - renderer->GetActiveCamera()->ParallelProjectionOn(); - renderer->ResetCamera(); - } - //renderer->GetActiveCamera()->Print(cout); - if(0){//save the actual camera settings - vtkCamera *Camera = renderer->GetActiveCamera(); - - Camera->GetPosition( camPosTop ); - //fprintf( stdout, "Position=%lg,%lg,%lg\n", camPosTop[0], camPosTop[1], camPosTop[2] ); - Camera->GetFocalPoint( camFocalPointTop ); - //fprintf( stdout, "FocalPoint=%lg,%lg,%lg\n", camFocalPointTop[0], camFocalPointTop[1], camFocalPointTop[2] ); - Camera->GetViewUp( camViewUpTop ); - //fprintf( stdout, "ViewUp=%lg,%lg,%lg\n", camViewUpTop[0], camViewUpTop[1], camViewUpTop[2] ); - camViewAngleTop = Camera->GetViewAngle(); - //fprintf( stdout, "ViewAngle=%lg\n", camViewAngleTop ); - camParallelScale = Camera->GetParallelScale(); - //fprintf( stdout, "ParallelScale=%lg\n", camParallelScale ); - - renderer->GetActiveCamera()->GetPosition(camPosTop); - renderer->GetActiveCamera()->GetClippingRange(camClipTop); - //renderer->GetActiveCamera()->GetViewPlaneNormal(camViewPlan); - renderer->GetActiveCamera()->GetFocalPoint(camFocalPointTop); - } +// if(true || SystemSettings::get2D()){ +// renderer->GetActiveCamera()->OrthogonalizeViewUp(); +// renderer->GetActiveCamera()->ParallelProjectionOn(); +// renderer->ResetCamera(); +// } //create a timer for rendering the window TimerCallback *renderingTimer = new TimerCallback(); @@ -345,13 +309,6 @@ void ThreadVisualisation::run(){ renderingTimer->setTextActor(runningTime); renderWinInteractor->AddObserver(vtkCommand::TimerEvent,renderingTimer); - // check for windows changes - - //WindowCallback* windowModified = new WindowCallback(); - //VTK_CREATE(vtkCallbackCommand,windowModified); - //windowModified->SetCallback (WindowModifiedCallback); - //renderWindow->AddObserver(vtkCommand::ModifiedEvent ,windowModified); - //create the necessary connections QObject::connect(renderingTimer, SIGNAL(signalRunningTime(unsigned long )), @@ -372,8 +329,9 @@ void ThreadVisualisation::run(){ //create special camera for the virtual reality feeling //renderer->GetActiveCamera()->SetRoll(90); //renderer->GetRenderers()->GetFirstRenderer()->GetActiveCamera(); - Pedestrian::setCamera(renderer->GetActiveCamera()); - renderer->ResetCamera(); + + //Pedestrian::setCamera(renderer->GetActiveCamera()); + //renderer->ResetCamera(); // just a workaround @@ -383,35 +341,49 @@ 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(); // Initialize and enter interactive mode // should be called after the observer has been added - renderWinInteractor->Start(); + //renderWindow->Modified(); + + //style->SetKeyPressActivationValue('R'); + //style->SetKeyPressActivation(true); + + //save the top view camera + _topViewCamera=vtkCamera::New(); + //renderer->GetActiveCamera()->Modified(); + _topViewCamera->DeepCopy(renderer->GetActiveCamera()); + + //TODO: update all system settings + setGeometryVisibility2D(SystemSettings::get2D()); + setGeometryVisibility3D(!SystemSettings::get2D()); + + renderWinInteractor->Start(); //emit signalStatusMessage("Idle"); emit signal_controlSequences("CONTROL_RESET"); - //renderWinInteractor->RemoveAllObservers(); - //renderWinInteractor->DestroyTimer(timer); //clear some stuffs + delete extern_trail_plotter; finalize(); renderer->Delete(); renderWindow->Delete(); renderWinInteractor->Delete(); + _topViewCamera->Delete(); renderer=NULL; - exit(0); } -void ThreadVisualisation::slotControlSequence(const char* sex){ +void ThreadVisualisation::slotControlSequence(const char* para){ //cout <<"control sequence received: " <<sex<<endl; } @@ -423,8 +395,6 @@ void ThreadVisualisation::setGeometryVisibility( bool status){ }else{ geometry->set3D(status); } - //geometry->getActor()->SetVisibility(status); - //geometry->getActor()->Modified(); } } @@ -439,16 +409,29 @@ 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::initGlyphs(){ +void ThreadVisualisation::showFloor(bool status) +{ + geometry->showFloor(status); +} +void ThreadVisualisation::initGlyphs2D() +{ - //VTK_CREATE (vtkSphereSource, agentShape); - //agentShape->SetRadius(30); - //agentShape->SetPhiResolution(20); - //agentShape->SetThetaResolution(20); + //glyphs with ellipsoids + // VTK_CREATE (vtkSphereSource, agentShape); + // agentShape->SetRadius(30); + // agentShape->SetPhiResolution(20); + // agentShape->SetThetaResolution(20); //now create the glyphs with ellipses VTK_CREATE (vtkDiskSource, agentShape); @@ -456,60 +439,54 @@ void ThreadVisualisation::initGlyphs(){ agentShape->SetInnerRadius(0); agentShape->SetOuterRadius(30); - extern_glyphs_pedestrians->SetSourceConnection(agentShape->GetOutputPort()); - -#if VTK_MAJOR_VERSION <= 5 - extern_glyphs_pedestrians->SetSource(agentShape->GetOutput()); -#else - extern_glyphs_pedestrians->SetInputConnection(agentShape->GetOutputPort()); -#endif + //speed the rendering using triangles stripers + vtkTriangleFilter *tris = vtkTriangleFilter::New(); + tris->SetInputConnection(agentShape->GetOutputPort()); + //tris->GetOutput()->ReleaseData(); + vtkStripper *strip = vtkStripper::New(); + strip->SetInputConnection(tris->GetOutputPort()); + //strip->GetOutput()->ReleaseData(); -/* - VTK_CREATE (vtkCylinderSource, agentShape); - agentShape->SetHeight(160); - agentShape->SetRadius(30); + extern_glyphs_pedestrians->SetSourceConnection(strip->GetOutputPort()); + //extern_glyphs_pedestrians->SetSourceConnection(agentShape->GetOutputPort()); + //first frame + Frame * frame = extern_trajectories_firstSet.getFrame(0); + vtkPolyData* pData=NULL; + if(frame) pData=frame->GetPolyData2D(); #if VTK_MAJOR_VERSION <= 5 - extern_glyphs_pedestrians->SetSource(cylinderSource->GetOutput()); + extern_glyphs_pedestrians->SetSource(agentShape->GetOutput()); + if (frame )extern_glyphs_pedestrians->SetInput(pData); #else - extern_glyphs_pedestrians->SetSourceConnection(cylinderSource->GetOutputPort()); - extern_glyphs_pedestrians->SetInputConnection(cylinderSource->GetOutputPort()); + extern_glyphs_pedestrians->SetInputConnection(agentShape->GetOutputPort()); + if (frame) extern_glyphs_pedestrians->SetInputData(pData); #endif -*/ - extern_glyphs_pedestrians->ThreeGlyphsOff(); extern_glyphs_pedestrians->ExtractEigenvaluesOff(); + //_agents->SymmetricOn(); + //_agents->Update(); - //extern_glyphs_pedestrians->SetColorModeToScalars(); - //extern_glyphs_pedestrians->SetScaleModeToDataScalingOff(); - //extern_glyphs_pedestrians->Update(); - + VTK_CREATE(vtkPolyDataMapper, mapper); + mapper->SetInputConnection(extern_glyphs_pedestrians->GetOutputPort()); + //improve the performance + mapper->GlobalImmediateModeRenderingOn(); - VTK_CREATE(vtkPolyDataMapper, mapper); - mapper->SetInputConnection(extern_glyphs_pedestrians->GetOutputPort()); - - //mapper->SetScalarModeToUsePointData(); - //mapper->ScalarVisibilityOn(); - //mapper->SelectColorArray("color"); - //mapper->ColorByArrayComponent("data", 0); - //mapper->SetColorModeToMapScalars(); - - VTK_CREATE(vtkLookupTable, lut); - lut->SetHueRange(0.0,0.470); - //lut->SetSaturationRange(0,0); - lut->SetValueRange(1.0,1.0); - lut->SetNanColor(0.2,0.2,0.2,0.5); - lut->SetNumberOfTableValues(256); - lut->Build(); - mapper->SetLookupTable(lut); - VTK_CREATE(vtkActor, actor); - actor->SetMapper(mapper); - renderer->AddActor(actor); + VTK_CREATE(vtkLookupTable, lut); + lut->SetHueRange(0.0,0.470); + //lut->SetSaturationRange(0,0); + lut->SetValueRange(1.0,1.0); + lut->SetNanColor(0.2,0.2,0.2,0.5); + lut->SetNumberOfTableValues(256); + lut->Build(); + mapper->SetLookupTable(lut); + extern_glyphs_pedestrians_actor_2D->SetMapper(mapper); + //extern_glyphs_pedestrians_actor_2D->GetProperty()->BackfaceCullingOn(); + renderer->AddActor(extern_glyphs_pedestrians_actor_2D); // structure for the labels VTK_CREATE(vtkLabeledDataMapper, labelMapper); @@ -520,254 +497,325 @@ void ThreadVisualisation::initGlyphs(){ extern_pedestrians_labels->SetVisibility(false); } -void ThreadVisualisation::init(){ - //get the datasets parameters. - // CAUTION: the functions will return 0 if no datasets were initialized - int numOfAgents1=extern_trajectories_firstSet.getNumberOfAgents(); - int numOfAgents2=extern_trajectories_secondSet.getNumberOfAgents(); - int numOfAgents3=extern_trajectories_thirdSet.getNumberOfAgents(); - - // super Pedestrians are declared extern - // CAUTION: the start ID is 1. - if(numOfAgents1>0){ - //get the first frame from the trajectories and initialize pedes positions - Frame * frame = extern_trajectories_firstSet.getNextFrame(); - // this is not usual, but may happen - //just get out if the frame is empty - if(frame==NULL) { - cerr<<"FATAL 1: Frame is null, the first dataset was not initialised"<<endl; - //exit(1); - - } - - //extern_pedestrians_firstSet = new Pedestrian*[numOfAgents1]; - extern_pedestrians_firstSet =(Pedestrian **)malloc(numOfAgents1*sizeof(Pedestrian*)); - - //extern_pedestrians_firstSet =(Pedestrian **)malloc(numOfAgents1*sizeof(Pedestrian*)); - if(extern_pedestrians_firstSet==NULL){ - cerr<<"could not allocate memory"<<endl; - exit(1); - } - - //The initialisation is just to avoid - // pedestrians having not defined (0,0,0) position at beginning. - - for(int i=0;i<numOfAgents1;i++){ - - TrajectoryPoint* point=NULL; - int color[3]; - SystemSettings::getPedestrianColor(0,color); - - if( (NULL!=frame) && (NULL!=(point=frame->getNextElement()))){ - extern_pedestrians_firstSet[i]=new Pedestrian(i,point->getX(),point->getY(),point->getZ()); - // they are all of type 1 (belonging to the first sets) - // extern_pedestrians_firstSet[i]->setType(1); - extern_pedestrians_firstSet[i]->setColor(color); - - }else{ - - extern_pedestrians_firstSet[i]=new Pedestrian(i,0.0,0.0,0.0); - extern_pedestrians_firstSet[i]->setVisibility(false); - - //extern_pedestrians_firstSet[i]->initVisibility(false); - //extern_pedestrians_firstSet[i]->setType(1); - extern_pedestrians_firstSet[i]->setColor(color); - } - - } - - //CAUTION: reset the fucking counter. - //TODO: include the reset cursor in the getnextFrame routine - // which shall be executed when null is returned - if (NULL!=frame) - frame->resetCursor(); - - // init the pedestrians sizes - QStringList heights=extern_trajectories_firstSet.getInitialHeights(); - for(int i=0;i<heights.size()-1;i+=2){ - bool ok=false; - int id = heights[i].toInt(&ok); - if(!ok) {cerr<<"skipping size arguments" <<endl;continue;} - double size= heights[i+1].toDouble(&ok); - if(!ok) {cerr<<"skipping size arguments" <<endl;continue;} - //caution: id start with 0 - extern_pedestrians_firstSet[id-1]->setSize(size); - } - - //init the pedestrians colors, - // overwrite the previously set colors - if(SystemSettings::getPedestrianColorProfileFromFile()){ - QStringList colors=extern_trajectories_firstSet.getInitialColors(); - for(int i=0;i<colors.size()-1;i+=2){ - bool ok=false; - int id = colors[i].toInt(&ok); - if(!ok) {cerr<<"skipping color arguments" <<endl;continue;} - int color= colors[i+1].toInt(&ok); - if(!ok) {cerr<<"skipping color arguments" <<endl;continue;} - //cout << id<< " :"<<size<<endl; - //caution: id start with 0 - extern_pedestrians_firstSet[id-1]->setColor(color); - - } - } - - //all initialisations are done , now create the actors - for(int i=0;i<numOfAgents1;i++){ - renderer->AddActor((vtkProp*)extern_pedestrians_firstSet[i]->getActor()); - renderer->AddActor((vtkProp*)extern_pedestrians_firstSet[i]->getTrailActor()); - - } - } - - // initialize the second dataset - if(numOfAgents2>0){ - Frame * frame = extern_trajectories_secondSet.getNextFrame(); - extern_pedestrians_secondSet =(Pedestrian **)malloc(numOfAgents2*sizeof(Pedestrian*)); - for(int i=0;i<numOfAgents2;i++){ - - // this is not usual, but may happen - //just get out if the frame is empty - if(frame==NULL) { - cerr<<"FATAL 2: Frame is null, the second dataset was not initialised"<<endl; - //exit(1); - //return; - } - - TrajectoryPoint* point=NULL; - int color[3]; - SystemSettings::getPedestrianColor(1,color); - - if( (NULL!=frame) && (NULL!=(point=frame->getNextElement()))){ - extern_pedestrians_secondSet[i]=new Pedestrian(i,point->getX(),point->getY(),point->getZ()); - // they are all of type 1 (belonging to the first sets) - extern_pedestrians_secondSet[i]->setColor(color); - //extern_pedestrians_secondSet[i]->setType(2); - //extern_pedestrians_firstSet[i]->CreateActor(); - }else{ - extern_pedestrians_secondSet[i]=new Pedestrian(i,0.0,0.0,0.0); - extern_pedestrians_secondSet[i]->setColor(color); - // extern_pedestrians_secondSet[i]->setType(2); - //extern_pedestrians_secondSet[i]->initVisibility(false); - extern_pedestrians_secondSet[i]->setVisibility(false); - } - - //renderer->AddActor((vtkProp*)extern_pedestrians_secondSet[i]->getActor()); - //renderer->AddActor((vtkProp*)extern_pedestrians_secondSet[i]->getTrailActor()); - } - //CAUTION: reset the fucking counter - // the frame objects are passed by reference, so the "cursor" stays - // at the last index used. - frame->resetCursor(); - - // init the pedestians sizes - QStringList tokens=extern_trajectories_secondSet.getInitialHeights(); - for(int i=0;i<tokens.size()-1;i+=2){ - - bool ok=false; - int id = tokens[i].toInt(&ok); - if(!ok) {cerr<<"skipping size arguments" <<endl;continue;} - double size= tokens[i+1].toDouble(&ok); - if(!ok) {cerr<<"skipping size arguments" <<endl;continue;} - extern_pedestrians_secondSet[id-1]->setSize(size); - } - - //init the pedestrians colors, - // overwrite the previously set colors - if(SystemSettings::getPedestrianColorProfileFromFile()){ - QStringList colors=extern_trajectories_secondSet.getInitialColors(); - for(int i=0;i<colors.size()-1;i+=2){ - bool ok=false; - int id = colors[i].toInt(&ok); - if(!ok) {cerr<<"skipping color arguments" <<endl;continue;} - int color= colors[i+1].toInt(&ok); - if(!ok) {cerr<<"skipping color arguments" <<endl;continue;} - //caution: id start with 0 - extern_pedestrians_secondSet[id-1]->setColor(color); - - } - } +void ThreadVisualisation::initGlyphs3D() +{ + //now create the glyphs with zylinders + VTK_CREATE (vtkCylinderSource, agentShape); + agentShape->SetHeight(160); + agentShape->SetRadius(20); + //agentShape->SetCenter(0,0,80); + agentShape->SetResolution(20); + /* + //VTK_CREATE (vtkAssembly, agentShape); + vtk3DSImporter* importer = vtk3DSImporter::New(); + importer->SetFileName("data/140404_charles.3ds"); + importer->Read(); + importer->Update(); + //importer->GetRenderer()->GetLights(); + //importer->GetRenderWindow()->GetInteractor()->Start(); + + ////collect all the elements from the 3ds + vtkActorCollection* collection=importer->GetRenderer()->GetActors(); + vtkActor *actorCharlie= collection->GetLastActor(); + actorCharlie->InitPathTraversal(); + vtkMapper *mapperCharlie=actorCharlie->GetMapper(); + mapperCharlie->Update(); + //_agents3D->SetColorGlyphs(false); + vtkPolyData *dataCharlie=vtkPolyData::SafeDownCast(mapperCharlie->GetInput()); + + //strip the data, again + //speed the rendering using triangles stripers + VTK_CREATE(vtkTriangleFilter, tris); + tris->SetInputData(dataCharlie); + VTK_CREATE(vtkStripper, agentShape); + agentShape->SetInputConnection(tris->GetOutputPort()); +*/ - //all initialisations are done , now create the actors - for(int i=0;i<numOfAgents2;i++){ - renderer->AddActor((vtkProp*)extern_pedestrians_secondSet[i]->getActor()); - renderer->AddActor((vtkProp*)extern_pedestrians_secondSet[i]->getTrailActor()); + extern_glyphs_pedestrians_3D->SetSourceConnection(agentShape->GetOutputPort()); - } + //first frame + Frame * frame = extern_trajectories_firstSet.getFrame(0); + vtkPolyData* pData=NULL; + if(frame) pData=frame->GetPolyData2D(); - } +#if VTK_MAJOR_VERSION <= 5 + extern_glyphs_pedestrians_3D->SetSource(agentShape->GetOutput()); + if (frame )extern_glyphs_pedestrians_3D->SetInput(pData); +#else + extern_glyphs_pedestrians_3D->SetInputConnection(agentShape->GetOutputPort()); + if (frame )extern_glyphs_pedestrians_3D->SetInputData(pData); +#endif - if(numOfAgents3>0){ + extern_glyphs_pedestrians_3D->ThreeGlyphsOff(); + extern_glyphs_pedestrians_3D->ExtractEigenvaluesOff(); - Frame * frame = extern_trajectories_thirdSet.getNextFrame(); - extern_pedestrians_thirdSet =(Pedestrian **)malloc(numOfAgents3*sizeof(Pedestrian*)); - for(int i=0;i<numOfAgents3;i++){ + VTK_CREATE(vtkPolyDataMapper, mapper); + mapper->SetInputConnection(extern_glyphs_pedestrians_3D->GetOutputPort()); + mapper->GlobalImmediateModeRenderingOn(); - // this is not usual, but may happen - //just get out if the frame is empty - if(frame==NULL) { - cerr<<"FATAL 3: Frame is null, the third dataset was not initialised"<<endl; - //exit(1); - - } - - TrajectoryPoint* point=NULL; - int color[3]; - SystemSettings::getPedestrianColor(2,color); - - if( (NULL!=frame) && (NULL!=(point=frame->getNextElement()))){ - extern_pedestrians_thirdSet[i]=new Pedestrian(i,point->getX(),point->getY(),point->getZ()); - // they are all of type 1 (belonging to the first sets) - //extern_pedestrians_thirdSet[i]->setType(3); - extern_pedestrians_thirdSet[i]->setColor(color); - //extern_pedestrians_firstSet[i]->CreateActor(); - }else{ - extern_pedestrians_thirdSet[i]=new Pedestrian(i,0.0,0.0,0.0); - // extern_pedestrians_thirdSet[i]->setType(3); - extern_pedestrians_thirdSet[i]->setColor(color); - //extern_pedestrians_thirdSet[i]->initVisibility(false); - extern_pedestrians_thirdSet[i]->setVisibility(false); - } - - //renderer->AddActor((vtkProp*)extern_pedestrians_thirdSet[i]->getActor()); - //renderer->AddActor((vtkProp*)extern_pedestrians_thirdSet[i]->getTrailActor()); - } - //CAUTION: reset the fucking counter. - frame->resetCursor(); - - // init the pedestians sizes - QStringList tokens=extern_trajectories_thirdSet.getInitialHeights(); - for(int i=0;i<tokens.size()-1;i+=2){ - bool ok=false; - int id = tokens[i].toInt(&ok); - if(!ok) {cerr<<"skipping size arguments" <<endl;continue;} - double size= tokens[i+1].toDouble(&ok); - if(!ok) {cerr<<"skipping size arguments" <<endl;continue;} - //cout << id<< " :"<<size<<endl; - extern_pedestrians_thirdSet[id-1]->setSize(size); - } - //init the pedestrians colors, - // overwrite the previously set colors - if(SystemSettings::getPedestrianColorProfileFromFile()){ - QStringList colors=extern_trajectories_thirdSet.getInitialColors(); - for(int i=0;i<colors.size()-1;i+=2){ - bool ok=false; - int id = colors[i].toInt(&ok); - if(!ok) {cerr<<"skipping color arguments" <<endl;continue;} - int color= colors[i+1].toInt(&ok); - if(!ok) {cerr<<"skipping color arguments" <<endl;continue;} - //caution: id start with 0 - extern_pedestrians_thirdSet[id-1]->setColor(color); - } - } + VTK_CREATE(vtkLookupTable, lut); + lut->SetHueRange(0.0,0.470); + //lut->SetSaturationRange(0,0); + lut->SetValueRange(1.0,1.0); + lut->SetNanColor(0.2,0.2,0.2,0.5); + lut->SetNumberOfTableValues(256); + lut->Build(); + mapper->SetLookupTable(lut); - //all initialisations are done , now create the actors - for(int i=0;i<numOfAgents3;i++){ - renderer->AddActor((vtkProp*)extern_pedestrians_thirdSet[i]->getActor()); - renderer->AddActor((vtkProp*)extern_pedestrians_thirdSet[i]->getTrailActor()); + extern_glyphs_pedestrians_actor_3D->SetMapper(mapper); + //extern_glyphs_pedestrians_actor_3D->GetProperty()->BackfaceCullingOn(); + renderer->AddActor(extern_glyphs_pedestrians_actor_3D); - } +} - } +void ThreadVisualisation::init(){ +// //get the datasets parameters. +// // CAUTION: the functions will return 0 if no datasets were initialized +// int numOfAgents1=extern_trajectories_firstSet.getNumberOfAgents(); +// int numOfAgents2=extern_trajectories_secondSet.getNumberOfAgents(); +// int numOfAgents3=extern_trajectories_thirdSet.getNumberOfAgents(); + +// // super Pedestrians are declared extern +// // CAUTION: the start ID is 1. +// if(numOfAgents1>0){ +// //get the first frame from the trajectories and initialize pedes positions +// Frame * frame = extern_trajectories_firstSet.getNextFrame(); +// // this is not usual, but may happen +// //just get out if the frame is empty +// if(frame==NULL) { +// cerr<<"FATAL 1: Frame is null, the first dataset was not initialised"<<endl; +// //exit(1); + +// } + +// //extern_pedestrians_firstSet = new Pedestrian*[numOfAgents1]; +// extern_pedestrians_firstSet =(Pedestrian **)malloc(numOfAgents1*sizeof(Pedestrian*)); + +// //extern_pedestrians_firstSet =(Pedestrian **)malloc(numOfAgents1*sizeof(Pedestrian*)); +// if(extern_pedestrians_firstSet==NULL){ +// cerr<<"could not allocate memory"<<endl; +// exit(1); +// } + +// //The initialisation is just to avoid +// // pedestrians having not defined (0,0,0) position at beginning. + +// for(int i=0;i<numOfAgents1;i++){ + +// TrajectoryPoint* point=NULL; +// int color[3]; +// SystemSettings::getPedestrianColor(0,color); + +// if( (NULL!=frame) && (NULL!=(point=frame->getNextElement()))){ +// extern_pedestrians_firstSet[i]=new Pedestrian(i,point->getX(),point->getY(),point->getZ()); +// // they are all of type 1 (belonging to the first sets) +// // extern_pedestrians_firstSet[i]->setType(1); +// extern_pedestrians_firstSet[i]->setColor(color); + +// }else{ + +// extern_pedestrians_firstSet[i]=new Pedestrian(i,0.0,0.0,0.0); +// extern_pedestrians_firstSet[i]->setVisibility(false); + +// //extern_pedestrians_firstSet[i]->initVisibility(false); +// //extern_pedestrians_firstSet[i]->setType(1); +// extern_pedestrians_firstSet[i]->setColor(color); +// } + +// } + +// //CAUTION: reset the fucking counter. +// //TODO: include the reset cursor in the getnextFrame routine +// // which shall be executed when null is returned +// if (NULL!=frame) +// frame->resetCursor(); + +// // init the pedestrians sizes +// QStringList heights=extern_trajectories_firstSet.getInitialHeights(); +// for(int i=0;i<heights.size()-1;i+=2){ +// bool ok=false; +// int id = heights[i].toInt(&ok); +// if(!ok) {cerr<<"skipping size arguments" <<endl;continue;} +// double size= heights[i+1].toDouble(&ok); +// if(!ok) {cerr<<"skipping size arguments" <<endl;continue;} +// //caution: id start with 0 +// extern_pedestrians_firstSet[id-1]->setSize(size); +// } + +// //init the pedestrians colors, +// // overwrite the previously set colors +// if(SystemSettings::getPedestrianColorProfileFromFile()){ +// QStringList colors=extern_trajectories_firstSet.getInitialColors(); +// for(int i=0;i<colors.size()-1;i+=2){ +// bool ok=false; +// int id = colors[i].toInt(&ok); +// if(!ok) {cerr<<"skipping color arguments" <<endl;continue;} +// int color= colors[i+1].toInt(&ok); +// if(!ok) {cerr<<"skipping color arguments" <<endl;continue;} +// //cout << id<< " :"<<size<<endl; +// //caution: id start with 0 +// extern_pedestrians_firstSet[id-1]->setColor(color); + +// } +// } + +// //all initialisations are done , now create the actors +// for(int i=0;i<numOfAgents1;i++){ +// renderer->AddActor((vtkProp*)extern_pedestrians_firstSet[i]->getActor()); +// renderer->AddActor((vtkProp*)extern_pedestrians_firstSet[i]->getTrailActor()); + +// } +// } + +// // initialize the second dataset +// if(numOfAgents2>0){ +// Frame * frame = extern_trajectories_secondSet.getNextFrame(); +// extern_pedestrians_secondSet =(Pedestrian **)malloc(numOfAgents2*sizeof(Pedestrian*)); +// for(int i=0;i<numOfAgents2;i++){ + +// // this is not usual, but may happen +// //just get out if the frame is empty +// if(frame==NULL) { +// cerr<<"FATAL 2: Frame is null, the second dataset was not initialised"<<endl; +// //exit(1); +// //return; +// } + +// TrajectoryPoint* point=NULL; +// int color[3]; +// SystemSettings::getPedestrianColor(1,color); + +// if( (NULL!=frame) && (NULL!=(point=frame->getNextElement()))){ +// extern_pedestrians_secondSet[i]=new Pedestrian(i,point->getX(),point->getY(),point->getZ()); +// // they are all of type 1 (belonging to the first sets) +// extern_pedestrians_secondSet[i]->setColor(color); +// //extern_pedestrians_secondSet[i]->setType(2); +// //extern_pedestrians_firstSet[i]->CreateActor(); +// }else{ +// extern_pedestrians_secondSet[i]=new Pedestrian(i,0.0,0.0,0.0); +// extern_pedestrians_secondSet[i]->setColor(color); +// // extern_pedestrians_secondSet[i]->setType(2); +// //extern_pedestrians_secondSet[i]->initVisibility(false); +// extern_pedestrians_secondSet[i]->setVisibility(false); +// } + +// //renderer->AddActor((vtkProp*)extern_pedestrians_secondSet[i]->getActor()); +// //renderer->AddActor((vtkProp*)extern_pedestrians_secondSet[i]->getTrailActor()); +// } +// //CAUTION: reset the fucking counter +// // the frame objects are passed by reference, so the "cursor" stays +// // at the last index used. +// frame->resetCursor(); + +// // init the pedestians sizes +// QStringList tokens=extern_trajectories_secondSet.getInitialHeights(); +// for(int i=0;i<tokens.size()-1;i+=2){ + +// bool ok=false; +// int id = tokens[i].toInt(&ok); +// if(!ok) {cerr<<"skipping size arguments" <<endl;continue;} +// double size= tokens[i+1].toDouble(&ok); +// if(!ok) {cerr<<"skipping size arguments" <<endl;continue;} +// extern_pedestrians_secondSet[id-1]->setSize(size); +// } + +// //init the pedestrians colors, +// // overwrite the previously set colors +// if(SystemSettings::getPedestrianColorProfileFromFile()){ +// QStringList colors=extern_trajectories_secondSet.getInitialColors(); +// for(int i=0;i<colors.size()-1;i+=2){ +// bool ok=false; +// int id = colors[i].toInt(&ok); +// if(!ok) {cerr<<"skipping color arguments" <<endl;continue;} +// int color= colors[i+1].toInt(&ok); +// if(!ok) {cerr<<"skipping color arguments" <<endl;continue;} +// //caution: id start with 0 +// extern_pedestrians_secondSet[id-1]->setColor(color); + +// } +// } + +// //all initialisations are done , now create the actors +// for(int i=0;i<numOfAgents2;i++){ +// renderer->AddActor((vtkProp*)extern_pedestrians_secondSet[i]->getActor()); +// renderer->AddActor((vtkProp*)extern_pedestrians_secondSet[i]->getTrailActor()); + +// } + +// } + +// if(numOfAgents3>0){ + +// Frame * frame = extern_trajectories_thirdSet.getNextFrame(); +// extern_pedestrians_thirdSet =(Pedestrian **)malloc(numOfAgents3*sizeof(Pedestrian*)); +// for(int i=0;i<numOfAgents3;i++){ + +// // this is not usual, but may happen +// //just get out if the frame is empty +// if(frame==NULL) { +// cerr<<"FATAL 3: Frame is null, the third dataset was not initialised"<<endl; +// //exit(1); + +// } + +// TrajectoryPoint* point=NULL; +// int color[3]; +// SystemSettings::getPedestrianColor(2,color); + +// if( (NULL!=frame) && (NULL!=(point=frame->getNextElement()))){ +// extern_pedestrians_thirdSet[i]=new Pedestrian(i,point->getX(),point->getY(),point->getZ()); +// // they are all of type 1 (belonging to the first sets) +// //extern_pedestrians_thirdSet[i]->setType(3); +// extern_pedestrians_thirdSet[i]->setColor(color); +// //extern_pedestrians_firstSet[i]->CreateActor(); +// }else{ +// extern_pedestrians_thirdSet[i]=new Pedestrian(i,0.0,0.0,0.0); +// // extern_pedestrians_thirdSet[i]->setType(3); +// extern_pedestrians_thirdSet[i]->setColor(color); +// //extern_pedestrians_thirdSet[i]->initVisibility(false); +// extern_pedestrians_thirdSet[i]->setVisibility(false); +// } + +// //renderer->AddActor((vtkProp*)extern_pedestrians_thirdSet[i]->getActor()); +// //renderer->AddActor((vtkProp*)extern_pedestrians_thirdSet[i]->getTrailActor()); +// } +// //CAUTION: reset the fucking counter. +// frame->resetCursor(); + +// // init the pedestians sizes +// QStringList tokens=extern_trajectories_thirdSet.getInitialHeights(); +// for(int i=0;i<tokens.size()-1;i+=2){ +// bool ok=false; +// int id = tokens[i].toInt(&ok); +// if(!ok) {cerr<<"skipping size arguments" <<endl;continue;} +// double size= tokens[i+1].toDouble(&ok); +// if(!ok) {cerr<<"skipping size arguments" <<endl;continue;} +// //cout << id<< " :"<<size<<endl; +// extern_pedestrians_thirdSet[id-1]->setSize(size); +// } +// //init the pedestrians colors, +// // overwrite the previously set colors +// if(SystemSettings::getPedestrianColorProfileFromFile()){ +// QStringList colors=extern_trajectories_thirdSet.getInitialColors(); +// for(int i=0;i<colors.size()-1;i+=2){ +// bool ok=false; +// int id = colors[i].toInt(&ok); +// if(!ok) {cerr<<"skipping color arguments" <<endl;continue;} +// int color= colors[i+1].toInt(&ok); +// if(!ok) {cerr<<"skipping color arguments" <<endl;continue;} +// //caution: id start with 0 +// extern_pedestrians_thirdSet[id-1]->setColor(color); +// } +// } + +// //all initialisations are done , now create the actors +// for(int i=0;i<numOfAgents3;i++){ +// renderer->AddActor((vtkProp*)extern_pedestrians_thirdSet[i]->getActor()); +// renderer->AddActor((vtkProp*)extern_pedestrians_thirdSet[i]->getTrailActor()); + +// } + +// } } @@ -977,29 +1025,10 @@ void ThreadVisualisation::setAxisVisible(bool status){ void ThreadVisualisation::setCameraPerspective(int mode){ if(renderer==NULL) return; - renderer->GetActiveCamera()->Print(cout); - //vtkMatrix4x4 *m = /* vtkMatrix4x4::New();*/ - // vtkHomogeneousTransform *m = /* vtkMatrix4x4::New();*/ - // renderer->GetActiveCamera()->GetViewTransformMatrix(); - //renderer->GetActiveCamera()->GetUserTransform()->GetMatrix(); - //m->Print(cout); - switch (mode) { - case 1: //TOP - { - vtkCamera *camera = renderer->GetActiveCamera(); - - camera->SetPosition(camPosTop); - camera->SetFocalPoint(camFocalPointTop); - camera->SetViewUp(camViewUpTop); - camera->SetViewAngle(camViewAngleTop); - //camera->SetViewPlaneNormal(camViewPlanNormalTop); - camera->SetParallelScale(camParallelScale); - camera->Modified(); - renderer->ResetCameraClippingRange(); - - } + case 1: //TOP oder RESET + renderer->GetActiveCamera()->DeepCopy(_topViewCamera); break; case 2://SIDE @@ -1040,14 +1069,19 @@ void ThreadVisualisation::setGeometry(FacilityGeometry* geometry){ } FacilityGeometry* ThreadVisualisation::getGeometry() { - //if(geometry==NULL){ //FIXME TODO restore me + //if(geometry==NULL){ geometry=new FacilityGeometry(); - //} + //} return geometry; } void ThreadVisualisation::setWallsColor(double* color){ - geometry->changeWallsColor(color); + geometry->changeWallsColor(color); +} + +void ThreadVisualisation::setFloorColor(double *color) +{ + geometry->changeFloorColor(color); } void ThreadVisualisation::setGeometryLabelsVisibility(int v){ @@ -1055,7 +1089,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 @@ -1076,14 +1115,3 @@ void ThreadVisualisation::setOnscreenInformationVisibility(bool show){ runningTime->SetVisibility(show); } -//void ThreadVisualisation::WindowModifiedCallback( vtkObject* -// caller, unsigned long eventId,void* clientData ,void* callData ) -//{ -// vtkRenderWindow* window = static_cast<vtkRenderWindow*>(caller); -// int* windowSize = window->GetSize(); -// -// -// int *pos=renderWindow->GetSize(); -// runningTime->SetPosition(pos[1]/2,pos[0]); -// -//} diff --git a/src/ThreadVisualisation.h b/src/ThreadVisualisation.h index cdbb94c15e60830baa855acc2f1a2d92a1578ffb..56159ca758d2387b9decbe61e4dc08c4066beacb 100644 --- a/src/ThreadVisualisation.h +++ b/src/ThreadVisualisation.h @@ -59,13 +59,20 @@ class vtkObject; class Pedestrian; class SyncData; class FacilityGeometry; +class TrailPlotter; +class PointPlotter; extern Pedestrian** extern_pedestrians_firstSet; extern Pedestrian** extern_pedestrians_secondSet; extern Pedestrian** extern_pedestrians_thirdSet; +extern PointPlotter* extern_trail_plotter; + //extern vtkSmartPointer<vtkGlyph3D> extern_glyphs_pedestrians; extern vtkSmartPointer<vtkTensorGlyph> extern_glyphs_pedestrians; +extern vtkSmartPointer<vtkTensorGlyph> extern_glyphs_pedestrians_3D; +extern vtkSmartPointer<vtkActor> extern_glyphs_pedestrians_actor_2D; +extern vtkSmartPointer<vtkActor> extern_glyphs_pedestrians_actor_3D; extern SyncData extern_trajectories_firstSet; extern SyncData extern_trajectories_secondSet; @@ -85,8 +92,6 @@ public: /// set the camera to one of TOP/FRONT/SIDE void setCameraPerspective(int mode); - /// load the data for the legend - //void setLegendValues(); /// load and display the geometry where /// the pedestrians will move @@ -111,24 +116,33 @@ public: /// enable/disable 3D void setGeometryVisibility3D(bool status); - /// set trajectories/trail visibility - void setTrailVisibility(bool status); - /// change the background color of the rendering windows void setBackgroundColor(double* color); /// change the walls color void setWallsColor(double* color); + /// change the floor color + void setFloorColor(double* color); + /// 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 the floor + void showFloor(bool status); + /// show / hide stairs ///not implemented void showStairs(bool status); @@ -137,18 +151,17 @@ public: public Q_SLOTS: /**control sequence received*/ - void slotControlSequence(const char* sex); + void slotControlSequence(const char* para); /// set the frame rate in frames per second void slotSetFrameRate( float fps); Q_SIGNALS: - void signal_controlSequences(const char* sex); + void signal_controlSequences(const char* para); private: - /// initialize the legend void initLegend(/*std::vector scalars*/); @@ -156,7 +169,10 @@ private: void init(); /// initialize the datasets - void initGlyphs(); + void initGlyphs2D(); + + //initialize the 3D agents + void initGlyphs3D(); //finalize the datasets void finalize(); @@ -175,6 +191,7 @@ private: vtkRenderWindowInteractor* renderWinInteractor; vtkAxesActor* axis; vtkTextActor* runningTime; + vtkCamera* _topViewCamera; QString winTitle; float framePerSecond; diff --git a/src/TimerCallback.cpp b/src/TimerCallback.cpp index 5ebf3d625f27356dc52ca0b23789f1253944d377..13d57b866645627475b6121e641e7522fb78cb71 100644 --- a/src/TimerCallback.cpp +++ b/src/TimerCallback.cpp @@ -87,9 +87,12 @@ #include "Pedestrian.h" #include "Frame.h" +#include "FrameElement.h" #include "TrajectoryPoint.h" #include "SyncData.h" #include "SystemSettings.h" +#include "TrailPlotter.h" +#include "geometry/PointPlotter.h" #include "TimerCallback.h" #define VTK_CREATE(type, name) \ @@ -115,7 +118,6 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId, int nPeds=0; static bool isRecording =false; int tid = * static_cast<int *>(callData); - //double renderingTime=0; if (tid == this->RenderTimerId) { @@ -128,8 +130,6 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId, if (iren && renderWindow && renderer) { - // very important - setAllPedestriansInvisible(); //first pedestrian group if(extern_first_dataset_loaded) { @@ -144,116 +144,58 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId, else frame = extern_trajectories_firstSet.getNextFrame(); - if(frame==NULL){ - - }else{ + if(frame==NULL) + { + } + else + { frameNumber=extern_trajectories_firstSet.getFrameCursor(); - vtkPolyData* pData=frame->GetPolyData(); + nPeds= frame->getSize(); + if(SystemSettings::get2D()==true) + { + vtkPolyData* pData=frame->GetPolyData2D(); #if VTK_MAJOR_VERSION <= 5 - extern_glyphs_pedestrians->SetInput(pData); - ((vtkLabeledDataMapper*)extern_pedestrians_labels->GetMapper())->SetInput(pData); + extern_glyphs_pedestrians->SetInput(pData); + ((vtkLabeledDataMapper*)extern_pedestrians_labels->GetMapper())->SetInput(pData); #else - extern_glyphs_pedestrians->SetInputData(pData); - extern_pedestrians_labels->GetMapper()->SetInputDataObject(pData); + extern_glyphs_pedestrians->SetInputData(pData); + extern_pedestrians_labels->GetMapper()->SetInputDataObject(pData); #endif - - extern_glyphs_pedestrians->Update(); - - nPeds= frame->getSize(); - - } - } - - // TODO: restore this if you want to use actors instead of glyphs - if(extern_first_dataset_loaded && false) { - Frame * frame=NULL; - - // return the same frame if the system is paused - // in fact you could just return, but in this case no update will be made - // e.g showing captions/trails... - - if(extern_is_pause) - frame=extern_trajectories_firstSet.getFrame(extern_trajectories_firstSet.getFrameCursor()); - else - frame = extern_trajectories_firstSet.getNextFrame(); - - if(frame==NULL){ - - }else{ - - // just take the frame number given by this dataset - frameNumber=extern_trajectories_firstSet.getFrameCursor(); - if(extern_tracking_enable) - getTrail(1,frameNumber); - - TrajectoryPoint* point=NULL; - while(NULL!=(point=frame->getNextElement())){ - - //point index start at 1. this may needed to be fixed - extern_pedestrians_firstSet[point->getIndex()]->moveTo(point); - nPeds++; + extern_glyphs_pedestrians->Update(); } - //CAUTION: reset the fucking counter - frame->resetCursor(); - } - } - - //second pedestrian group - if(extern_second_dataset_loaded){ - - Frame * frame=NULL; - if(extern_is_pause) - frame=extern_trajectories_secondSet.getFrame(extern_trajectories_secondSet.getFrameCursor()); - else - frame = extern_trajectories_secondSet.getNextFrame(); - - if(frame==NULL){ - - }else{ - // just take the frame number given by this dataset - frameNumber=extern_trajectories_secondSet.getFrameCursor(); - if(extern_tracking_enable) - getTrail(2,frameNumber); - - TrajectoryPoint* point=NULL; - while(NULL!=(point=frame->getNextElement())){ - extern_pedestrians_secondSet[point->getIndex()]->moveTo(point); + else + { + vtkPolyData* pData=frame->GetPolyData3D(); +#if VTK_MAJOR_VERSION <= 5 + extern_glyphs_pedestrians_3D->SetInput(pData); + ((vtkLabeledDataMapper*)extern_pedestrians_labels->GetMapper())->SetInput(pData); +#else + extern_glyphs_pedestrians_3D->SetInputData(pData); + extern_pedestrians_labels->GetMapper()->SetInputDataObject(pData); +#endif + extern_glyphs_pedestrians_3D->Update(); } - //CAUTION: reset the fucking counter - frame->resetCursor(); - } - } - //third pedestrian group - if(extern_third_dataset_loaded){ - - Frame * frame=NULL; - if(extern_is_pause) - frame=extern_trajectories_thirdSet.getFrame(extern_trajectories_thirdSet.getFrameCursor()); - else - frame = extern_trajectories_thirdSet.getNextFrame(); - - if(frame==NULL){ - - }else { - // just take the frame number given by this dataset - frameNumber=extern_trajectories_thirdSet.getFrameCursor(); if(extern_tracking_enable) - getTrail(3,frameNumber); - - TrajectoryPoint* point=NULL; - while(NULL!=(point=frame->getNextElement())){ - //point index start at 1. this may needed to be fixed - extern_pedestrians_thirdSet[point->getIndex()]->moveTo(point); - //set visible to true + { + const std::vector<FrameElement *> &elements=frame->GetFrameElements(); + + for(unsigned int i=0;i<elements.size();i++) + { + FrameElement* el = elements[i]; + double pos[3]; + double color; + el->GetPos(pos); + el->GetColor(&color); + extern_trail_plotter->PlotPoint(pos,color); + } } - //CAUTION: reset the fucking counter - frame->resetCursor(); } } + int* winSize=renderWindow->GetSize(); static int lastWinX=winSize[0]+1; // +1 to trigger a first change static int lastWinY=winSize[1]; @@ -324,12 +266,6 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId, pAVIWriter->SetQuality(2); pAVIWriter->SetRate(1000.0/iren->GetTimerDuration(tid)); - //static int videoID=0; - //char filename[20]={0}; - //sprintf(filename,"travisto_video_%d.avi",videoID++); - //pAVIWriter->SetFileName(filename); - - QString videoName; SystemSettings::getOutputDirectory(videoName); //create directory if not exits @@ -382,8 +318,6 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId, //exit if and only if the recording process is terminated if(isRecording) extern_recording_enable=false; else iren->ExitCallback(); - - } } } @@ -394,68 +328,14 @@ void TimerCallback::updateSettings(vtkRenderWindow* renderWindow) { static bool fullscreen=false; - // check the caption colour mode - int captionSize, orientation; - bool automaticRotation, autoCaptionMode; - QColor captionColor; - SystemSettings::getCaptionsParameters(captionSize,captionColor,orientation,automaticRotation); - - autoCaptionMode= !(captionColor.isValid()); - - if(autoCaptionMode==false){ // tODO set the colour to auto mode - - } - - if(extern_first_dataset_loaded){ - int pedColor[3]; - SystemSettings::getPedestrianColor(0,pedColor); - for(int i=0;i<extern_trajectories_firstSet.getNumberOfAgents();i++){ - extern_pedestrians_firstSet[i]->enableCaption(SystemSettings::getShowCaption()); - if(SystemSettings::getPedestrianColorProfileFromFile()==false){ - extern_pedestrians_firstSet[i]->setColor(pedColor); - } - extern_pedestrians_firstSet[i]->setGroupVisibility(extern_first_dataset_visible); - extern_pedestrians_firstSet[i]->setCaptionSize(captionSize); - extern_pedestrians_firstSet[i]->setCaptionsColorModeToAuto(autoCaptionMode); - extern_pedestrians_firstSet[i]->setCaptionsColor(captionColor); - extern_pedestrians_firstSet[i]->setResolution(SystemSettings::getEllipseResolution()); - } - extern_pedestrians_labels->SetVisibility(SystemSettings::getShowCaption()); - } - - if(extern_second_dataset_loaded){ - int pedColor[3]; - SystemSettings::getPedestrianColor(1,pedColor); - for(int i=0;i<extern_trajectories_secondSet.getNumberOfAgents();i++){ - extern_pedestrians_secondSet[i]->enableCaption(SystemSettings::getShowCaption()); - if(SystemSettings::getPedestrianColorProfileFromFile()==false){ - extern_pedestrians_secondSet[i]->setColor(pedColor); - } - extern_pedestrians_secondSet[i]->setGroupVisibility(extern_second_dataset_visible); - extern_pedestrians_secondSet[i]->setCaptionSize(captionSize); - extern_pedestrians_secondSet[i]->setCaptionsColorModeToAuto(autoCaptionMode); - extern_pedestrians_secondSet[i]->setCaptionsColor(captionColor); - extern_pedestrians_secondSet[i]->setResolution(SystemSettings::getEllipseResolution()); - - } - } + extern_glyphs_pedestrians_actor_2D->SetVisibility(SystemSettings::getShowAgents()&& SystemSettings::get2D()); + extern_glyphs_pedestrians_actor_3D->SetVisibility(SystemSettings::getShowAgents()&& !SystemSettings::get2D()); + extern_trail_plotter->SetVisibility(extern_tracking_enable); - if(extern_third_dataset_loaded){ - int pedColor[3]; - SystemSettings::getPedestrianColor(2,pedColor); - for(int i=0;i<extern_trajectories_thirdSet.getNumberOfAgents();i++){ - extern_pedestrians_thirdSet[i]->enableCaption(SystemSettings::getShowCaption()); + //agents captions + extern_pedestrians_labels->SetVisibility(SystemSettings::getShowAgentsCaptions()); - if(SystemSettings::getPedestrianColorProfileFromFile()==false){ - extern_pedestrians_thirdSet[i]->setColor(pedColor); - } - extern_pedestrians_thirdSet[i]->setGroupVisibility(extern_third_dataset_visible); - extern_pedestrians_thirdSet[i]->setCaptionSize(captionSize); - extern_pedestrians_thirdSet[i]->setCaptionsColorModeToAuto(autoCaptionMode); - extern_pedestrians_thirdSet[i]->setCaptionsColor(captionColor); - extern_pedestrians_thirdSet[i]->setResolution(SystemSettings::getEllipseResolution()); - } - } + //geometry captions //enable / disable full screen if(fullscreen!=extern_fullscreen_enable){ @@ -469,26 +349,6 @@ void TimerCallback::updateSettings(vtkRenderWindow* renderWindow) { } -void TimerCallback::setAllPedestriansInvisible() -{ - if(extern_first_dataset_loaded){ - for(int i=0;i<extern_trajectories_firstSet.getNumberOfAgents();i++) - extern_pedestrians_firstSet[i]->setVisibility(false); - } - - if(extern_second_dataset_loaded){ - for(int i=0;i<extern_trajectories_secondSet.getNumberOfAgents();i++) - extern_pedestrians_secondSet[i]->setVisibility(false); - } - - if(extern_third_dataset_loaded){ - for(int i=0;i<extern_trajectories_thirdSet.getNumberOfAgents();i++) - extern_pedestrians_thirdSet[i]->setVisibility(false); - } -} - - - void TimerCallback::getTrail(int datasetID, int frameNumber){ int trailCount=0; @@ -518,66 +378,20 @@ void TimerCallback::getTrail(int datasetID, int frameNumber){ } - switch(datasetID){ - case 1: - { - for (int i=tcMin;i<tcMax;i++){ - Frame* frame = extern_trajectories_firstSet.getFrame(i); - if(frame==NULL){ - // cerr<<"Trajectory not available in getTrail(), first data set"<<endl; - }else { - TrajectoryPoint* point=NULL; - while(NULL!=(point=frame->getNextElement())){ - extern_pedestrians_firstSet[point->getIndex()]->plotTrail(point->getX(),point->getY(),point->getZ()); - extern_pedestrians_firstSet[point->getIndex()]->setTrailGeometry(trailForm); - } - frame->resetCursor(); - } - } - } - break; - - case 2: - { - for (int i=tcMin;i<tcMax;i++){ - Frame* frame = extern_trajectories_secondSet.getFrame(i); - if(frame==NULL){ - // cerr<<"Trajectory not available in getTrail(), second data set"<<endl; - }else { - - TrajectoryPoint* point=NULL; - while(NULL!=(point=frame->getNextElement())){ - extern_pedestrians_secondSet[point->getIndex()]->plotTrail(point->getX(),point->getY(),point->getZ()); - extern_pedestrians_secondSet[point->getIndex()]->setTrailGeometry(trailForm); - } - frame->resetCursor(); - } - } - } - - break; - case 3: - { - for (int i=tcMin;i<tcMax;i++){ - Frame* frame = extern_trajectories_thirdSet.getFrame(i); - if(frame==NULL){ - // cerr<<"Trajectory not available in getTrail(), third data set"<<endl; - }else { - - TrajectoryPoint* point=NULL; - while(NULL!=(point=frame->getNextElement())){ - extern_pedestrians_thirdSet[point->getIndex()]->plotTrail(point->getX(),point->getY(),point->getZ()); - extern_pedestrians_thirdSet[point->getIndex()]->setTrailGeometry(trailForm); - } - frame->resetCursor(); + for (int i=tcMin;i<tcMax;i++){ + Frame* frame = extern_trajectories_firstSet.getFrame(i); + if(frame==NULL){ + // cerr<<"Trajectory not available in getTrail(), first data set"<<endl; + }else { + FrameElement* point=NULL; + while(NULL!=(point=frame->getNextElement())){ + //extern_pedestrians_firstSet[point->getIndex()]->plotTrail(point->getX(),point->getY(),point->getZ()); + //extern_pedestrians_firstSet[point->getIndex()]->setTrailGeometry(trailForm); } + frame->resetCursor(); } } - - break; - - } } @@ -671,17 +485,3 @@ void TimerCallback::setTextActor(vtkTextActor* ra){ runningTime=ra; } - -// -//WindowCallback* WindowCallback::New() -//{ -// WindowCallback *cb = new WindowCallback; -// return cb; -//} - - -//void WindowCallback::Execute(vtkObject *caller, unsigned long eventId, -// void *callData){ -// -// -//} diff --git a/src/TimerCallback.h b/src/TimerCallback.h index d2c3bfac535b346b0bbe83a0794e1383738bb58f..6ebd21d2734b0a53724a7b3dfaa101676d2e6b3a 100644 --- a/src/TimerCallback.h +++ b/src/TimerCallback.h @@ -57,7 +57,6 @@ class SyncData; class QObject; class QString; class Pedestrian; -class Pedestrian; class vtkCommand; class vtkRenderWindow; class vtkWindowToImageFilter; @@ -65,6 +64,8 @@ class Frame; class vtkPNGWriter; class vtkTextActor; class vtkActor2D; +class TrailPlotter; +class PointPlotter; //extern variables @@ -76,6 +77,7 @@ extern bool extern_recording_enable; extern bool extern_launch_recording; extern bool extern_fullscreen_enable; extern bool extern_take_screenshot; +extern bool extern_tracking_enable; extern Pedestrian** extern_pedestrians_firstSet; extern Pedestrian** extern_pedestrians_secondSet; @@ -83,7 +85,10 @@ extern Pedestrian** extern_pedestrians_thirdSet; extern vtkSmartPointer<vtkActor2D> extern_pedestrians_labels; extern vtkSmartPointer<vtkTensorGlyph> extern_glyphs_pedestrians; - +extern vtkSmartPointer<vtkTensorGlyph> extern_glyphs_pedestrians_3D; +extern vtkSmartPointer<vtkActor> extern_glyphs_pedestrians_actor_2D; +extern vtkSmartPointer<vtkActor> extern_glyphs_pedestrians_actor_3D; +extern PointPlotter* extern_trail_plotter; extern SyncData extern_trajectories_firstSet; extern SyncData extern_trajectories_secondSet; @@ -141,10 +146,6 @@ private: /// take png screenshots sequence void takeScreenshotSequence(vtkRenderWindow* renderWindow); - /// set all pedestrians invisible. - /// this is necessary for blending the peds - /// who are not longer in the system. - void setAllPedestriansInvisible(); /// create directory //bool createDirectory( const std::string& ac_sPath ); diff --git a/src/TrailPlotter.cpp b/src/TrailPlotter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9c7b1e85a6e4df60f17f2186d031a1f994c9cfcc --- /dev/null +++ b/src/TrailPlotter.cpp @@ -0,0 +1,78 @@ +#include "TrailPlotter.h" + +#include <vtkActor.h> +#include <vtkPolyData.h> +#include <vtkSmartPointer.h> +#include <vtkCleanPolyData.h> +#include <vtkPolyDataMapper.h> +#include <vtkAppendPolyData.h> +#include <vtkDiskSource.h> +#include <vtkTriangleFilter.h> +#include <vtkStripper.h> + + +#define VTK_CREATE(type, name) \ + vtkSmartPointer<type> name = vtkSmartPointer<type>::New() + + +TrailPlotter::TrailPlotter() +{ + // trails sources + VTK_CREATE (vtkDiskSource, agentShape); + agentShape->SetCircumferentialResolution(20); + agentShape->SetInnerRadius(0); + agentShape->SetOuterRadius(30); + + //speed the rendering using triangles stripers + vtkTriangleFilter *tris = vtkTriangleFilter::New(); + tris->SetInputConnection(agentShape->GetOutputPort()); + //tris->GetOutput()->ReleaseData(); + + vtkStripper *strip = vtkStripper::New(); + strip->SetInputConnection(tris->GetOutputPort()); + //strip->GetOutput()->ReleaseData(); + + + _appendFilter = vtkSmartPointer<vtkAppendPolyData>::New(); + _appendFilter->SetInputConnection(strip->GetOutputPort()); + + // Remove any duplicate points. + _cleanFilter = vtkSmartPointer<vtkCleanPolyData>::New(); + //_cleanFilter->SetInputConnection(_appendFilter->GetOutputPort()); + + //Create a mapper and actor + vtkSmartPointer<vtkPolyDataMapper> mapper = + vtkSmartPointer<vtkPolyDataMapper>::New(); + //mapper->SetInputConnection(_cleanFilter->GetOutputPort()); + + _trailActor = vtkSmartPointer<vtkActor>::New(); + //_trailActor->SetMapper(mapper); +} + +TrailPlotter::~TrailPlotter() +{ + +} + +void TrailPlotter::AddDataSet(vtkPolyData *_polydata) +{ + +#if VTK_MAJOR_VERSION <= 5 + _appendFilter->AddInputConnection(_polydata->GetProducerPort()); +#else + _appendFilter->AddInputData(_polydata); +#endif + + _appendFilter->Update(); + _cleanFilter->Update(); +} + +vtkActor *TrailPlotter::getActor() +{ + return _trailActor; +} + +void TrailPlotter::SetVisibility(bool status) +{ + _trailActor->SetVisibility(status); +} diff --git a/src/TrailPlotter.h b/src/TrailPlotter.h new file mode 100644 index 0000000000000000000000000000000000000000..c9cc3dcfcb76fe12c9d58d32aaaf540c1688b7c7 --- /dev/null +++ b/src/TrailPlotter.h @@ -0,0 +1,38 @@ +#ifndef TRAILPLOTTER_H +#define TRAILPLOTTER_H + +//forwarded classes +class vtkPolyData; +class vtkActor; +class vtkAppendPolyData; +class vtkAppendPolyData; +class vtkCleanPolyData; + + +class TrailPlotter +{ +public: + /// constructor + TrailPlotter(); + + /// destructor + virtual ~TrailPlotter(); + + /// add a dataset to plot + void AddDataSet(vtkPolyData * _polydata); + + /// return the actor responsible for the plotting + vtkActor* getActor(); + + /// set the visibility satus of the trails + void SetVisibility(bool status); + +private: + vtkActor* _trailActor; + // combine polydatas sets + vtkAppendPolyData* _appendFilter; + // Remove any duplicate points. + vtkCleanPolyData* _cleanFilter; +}; + +#endif // TRAILPLOTTER_H diff --git a/src/extern_var.h b/src/extern_var.h index 67e57693f337955fd257c7e8d47150a9c04ec77a..b88416aea16f6c9445c5b19c13907d55f2903ad2 100644 --- a/src/extern_var.h +++ b/src/extern_var.h @@ -30,15 +30,21 @@ #ifndef EXTERN_VAR_H_ #define EXTERN_VAR_H_ 1 +#define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL,vtkRenderingOpenGL) +#define vtkRenderingVolume_AUTOINIT 1(vtkRenderingVolumeOpenGL) + #include "SyncData.h" #include "Pedestrian.h" +#include "TrailPlotter.h" #include <vtkActor2D.h> +#include <vtkActor.h> #include <vtkTensorGlyph.h> #include <vtkSmartPointer.h> #include <vtkPolyDataMapper.h> + #define VTK_CREATE(type, name) \ vtkSmartPointer<type> name = vtkSmartPointer<type>::New() @@ -67,6 +73,7 @@ bool extern_force_system_update=false; /// With this enable, moving pedestrians will leave a /// trail behind them bool extern_tracking_enable=false; +PointPlotter* extern_trail_plotter=NULL; ///relative scale from pedestrian to the geometry (environment) double extern_scale=0.1; @@ -80,12 +87,16 @@ Pedestrian** extern_pedestrians_secondSet=NULL; ///The third pedestrian group Pedestrian** extern_pedestrians_thirdSet=NULL; +vtkSmartPointer<vtkTensorGlyph> extern_glyphs_pedestrians=NULL; +vtkSmartPointer<vtkTensorGlyph> extern_glyphs_pedestrians_3D=NULL; -//VTK_CREATE (vtkGlyph3D, extern_glyphs_pedestrians); -VTK_CREATE (vtkTensorGlyph, extern_glyphs_pedestrians); - +//VTK_CREATE (vtkTensorGlyph, extern_glyphs_pedestrians); +//VTK_CREATE (vtkTensorGlyph, extern_glyphs_pedestrians_3D); VTK_CREATE (vtkActor2D, extern_pedestrians_labels); +VTK_CREATE (vtkActor, extern_glyphs_pedestrians_actor_2D); +VTK_CREATE (vtkActor, extern_glyphs_pedestrians_actor_3D); + // and here the corresponding dataset ///The first dataset diff --git a/src/geometry/Building.cpp b/src/geometry/Building.cpp index 5fcc440f7324f8bbcb8e066fbbd0ff0805a75c85..6039ed264ff9effaf46fab620259863004c19da5 100644 --- a/src/geometry/Building.cpp +++ b/src/geometry/Building.cpp @@ -28,6 +28,10 @@ #include "Building.h" #include "../tinyxml/tinyxml.h" +//qt stuff +#include <QString> +#include "../SystemSettings.h" + #ifdef _SIMULATOR #include "../pedestrian/Pedestrian.h" #include "../mpi/LCGrid.h" @@ -43,7 +47,8 @@ #define omp_get_max_threads() 1 #endif -OutputHandler* Log = new STDIOHandler();; +//OutputHandler* Log = new STDIOHandler(); +OutputHandler* Log = NULL; using namespace std; @@ -58,6 +63,7 @@ Building::Building() { _routingEngine = NULL; _linkedCellGrid = NULL; _savePathway = false; + Log = new FileHandler(SystemSettings::getLogfile().toStdString().c_str()); } @@ -238,7 +244,7 @@ void Building::AddSurroundingRoom() { } -void Building::InitGeometry() { +bool Building::InitGeometry() { Log->Write("INFO: \tInit Geometry"); for (int i = 0; i < GetNumberOfRooms(); i++) { Room* room = GetRoom(i); @@ -262,7 +268,8 @@ void Building::InitGeometry() { } // initialize the poly - s->ConvertLineToPoly(goals); + if(!s->ConvertLineToPoly(goals)) + return false; s->CalculateArea(); goals.clear(); @@ -270,11 +277,13 @@ void Building::InitGeometry() { const vector<Obstacle*>& obstacles = s->GetAllObstacles(); for (unsigned int obs = 0; obs < obstacles.size(); ++obs) { if (obstacles[obs]->GetClosed() == 1) - obstacles[obs]->ConvertLineToPoly(); + if(!obstacles[obs]->ConvertLineToPoly()) + return false; } } } Log->Write("INFO: \tInit Geometry successful!!!\n"); + return true; } @@ -297,7 +306,7 @@ const string& Building::GetProjectRootDir() const{ } -void Building::LoadBuildingFromFile(const std::string &filename) { +bool Building::LoadBuildingFromFile(const std::string &filename) { //get the geometry filename from the project file if none was supplied string geoFilename=filename; @@ -306,7 +315,7 @@ void Building::LoadBuildingFromFile(const std::string &filename) { if (!doc.LoadFile()){ Log->Write("ERROR: \t%s", doc.ErrorDesc()); Log->Write("ERROR: \t could not parse the project file"); - exit(EXIT_FAILURE); + return false; } Log->Write("INFO: \tParsing the geometry file"); @@ -322,31 +331,31 @@ void Building::LoadBuildingFromFile(const std::string &filename) { TiXmlDocument docGeo(geoFilename); if (!docGeo.LoadFile()){ Log->Write("ERROR: \t%s", docGeo.ErrorDesc()); - Log->Write("ERROR: \t could not parse the geometry file"); - exit(EXIT_FAILURE); + Log->Write("ERROR: \t could not parse the geometry file [%s]",geoFilename.c_str()); + return false; } TiXmlElement* xRootNode = docGeo.RootElement(); if( ! xRootNode ) { Log->Write("ERROR:\tRoot element does not exist"); - exit(EXIT_FAILURE); + return false; } if( xRootNode->ValueStr () != "geometry" ) { Log->Write("ERROR:\tRoot element value is not 'geometry'."); - exit(EXIT_FAILURE); + return false; } if(string(xRootNode->Attribute("unit"))!="m") { Log->Write("ERROR:\tOnly the unit m (metres) is supported. \n\tYou supplied [%s]",xRootNode->Attribute("unit")); - exit(EXIT_FAILURE); + return false; } double version = xmltof(xRootNode->Attribute("version"), -1); if (version < 0.4) { - Log->Write("ERROR: \tOnly version > 0.4 supported"); + Log->Write("ERROR: \tOnly version > 0.4 supported. Your version is %f",version); Log->Write("ERROR: \tparsing geometry file failed!"); - exit(EXIT_FAILURE); + return false; } _caption = xmltoa(xRootNode->Attribute("caption"), "virtual building"); @@ -359,7 +368,7 @@ void Building::LoadBuildingFromFile(const std::string &filename) { TiXmlNode* xRoomsNode = xRootNode->FirstChild("rooms"); if (!xRoomsNode){ Log->Write("ERROR: \tThe geometry should have at least one room and one subroom"); - exit(EXIT_FAILURE); + return false; } for(TiXmlElement* xRoom = xRoomsNode->FirstChildElement("room"); xRoom; diff --git a/src/geometry/Building.h b/src/geometry/Building.h index ba40c002407cf850e8e6bc4ad3ededc1080b6e58..514f48618603c97180a06bf27cbeec03a5e9e93d 100644 --- a/src/geometry/Building.h +++ b/src/geometry/Building.h @@ -148,7 +148,7 @@ public: LCGrid* GetGrid() const; // Sonstiges - void InitGeometry(); + bool InitGeometry(); void InitGrid(double cellSize); //void InitRoomsAndSubroomsMap(); void InitPhiAllPeds(double pDt); // initialize the direction of the ellipses @@ -174,7 +174,7 @@ public: const std::string& GetProjectFilename() const; void SetProjectFilename(const std::string &filename) ; void SetProjectRootDir(const std::string &filename); - void LoadBuildingFromFile(const std::string &filename=""); + bool LoadBuildingFromFile(const std::string &filename=""); void LoadTrafficInfo(); void LoadRoutingInfo(const std::string &filename); void WriteToErrorLog() const; diff --git a/src/geometry/FacilityGeometry.cpp b/src/geometry/FacilityGeometry.cpp index 6a1f8beb297df2a5f7f104cc14ef1f6d7b48ab29..853e2a2080f271657110f83540ddb97b0bf9a370 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,62 +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(); - - 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; - + assembly = vtkAssembly::New(); + assembly2D = vtkAssembly::New(); + assemblyCaptions= vtkAssembly::New(); + + assemblyWalls3D = vtkAssembly::New(); + assemblyDoors3D = vtkAssembly::New(); + assembly3D = vtkAssembly::New(); + + 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::getActor(){ +vtkAssembly* FacilityGeometry::getActor2D() +{ + return assembly2D; +} - assembly2D->AddPart(linesPlotter2D->createAssembly()); - assembly2D->AddPart(assemblyCaptions); +vtkAssembly* FacilityGeometry::getCaptionsActor() +{ + return assemblyCaptions; +} - return assembly2D; +vtkAssembly* FacilityGeometry::getActor3D() +{ + return assembly3D; } +void FacilityGeometry::CreateActors() +{ + assembly2D->AddPart(linesPlotter2D->createAssembly()); + assembly2D->AddPart(assemblyCaptions); + + assembly3D->AddPart(assemblyDoors3D); + assembly3D->AddPart(assemblyWalls3D); + assembly3D->AddPart(assemblyCaptions); +} //void FacilityGeometry::drawWall(Point *p1, Point *p2){ // double scale =1; @@ -178,260 +197,407 @@ vtkAssembly* FacilityGeometry::getActor(){ * This is the main build method and should be called by all functions * drawing a wall or a door. Important */ -//void FacilityGeometry::addNewElement(double center[3], double length, double orientation, ELEMENT_TYPE type){ -// -// vtkCubeSource* src = vtkCubeSource::New(); -// src->SetCenter(center[0],center[1],center[2]); -// src->SetYLength(length); -// -// vtkPolyDataMapper* mapper = vtkPolyDataMapper::New(); -// mapper->SetInputConnection(src->GetOutputPort()); -// src->Delete(); -// -// vtkActor* actor = vtkActor::New(); -// actor->SetMapper(mapper); -// mapper->Delete(); -// actor->GetProperty()->SetLighting(true); -// actor->SetOrigin(center[0],center[1],center[2]); -// actor->RotateZ(orientation); -// actor->GetProperty()->SetAmbient(0.2); -// actor->GetProperty()->SetDiffuse(0.8); -// -// // double data[3]; -// // actor->GetPosition(data); -// // actor->SetPosition(data[0],data[1],src->GetZLength()/2); -// -// switch (type) -// { -// case DOOR: -// { -// double colorRGB[3]; -// lookupTable->GetColor(doorColor, colorRGB); -// actor->GetProperty()->SetColor(colorRGB); -// src->SetXLength(doorThickness); -// src->SetZLength(doorHeight); -// //src->SetRadius(doorWidth); -// actor->GetProperty()->SetOpacity(1.00); -// assemblyDoors3D->AddPart(actor); -// } -// break; -// case WALL: -// { -// double colorRGB[3]; -// lookupTable->GetColor(wallColor, colorRGB); -// actor->GetProperty()->SetColor(colorRGB); -// //actor->GetProperty()->SetSpecular(1); -// //actor->GetProperty()->SetDiffuse(1); -// //actor->GetProperty()->SetAmbient(1); -// -// src->SetXLength(wallThickness); -// src->SetZLength(wallHeight); -// //src->SetRadius(wallWidth); -// assemblyWalls3D->AddPart(actor); -// } -// break; -// case STEP: -// { -// double colorRGB[3]; -// lookupTable->GetColor(stepColor, colorRGB); -// actor->GetProperty()->SetColor(colorRGB); -// src->SetXLength(wallThickness); //FIXME, this is wrong -// src->SetZLength(stepHeight); -// assemblyDoors3D->AddPart(actor); -// } -// break; -// -// //default behaviour not defined -// default: -// break; -// } -// -// // now adjusting the z coordinates -// double data[3]; -// actor->GetPosition(data); -// actor->SetPosition(data[0],data[1],src->GetZLength()/2); -// -// actor->Delete(); -//} +void FacilityGeometry::addNewElement(double center[3], double length, double orientation, ELEMENT_TYPE type){ + + vtkCubeSource* src = vtkCubeSource::New(); + src->SetCenter(center[0],center[1],center[2]); + src->SetYLength(length); + + vtkPolyDataMapper* mapper = vtkPolyDataMapper::New(); + mapper->SetInputConnection(src->GetOutputPort()); + src->Delete(); + + vtkActor* actor = vtkActor::New(); + actor->SetMapper(mapper); + mapper->Delete(); + actor->GetProperty()->SetLighting(true); + actor->SetOrigin(center[0],center[1],center[2]); + actor->RotateZ(orientation); + actor->GetProperty()->SetAmbient(0.2); + actor->GetProperty()->SetDiffuse(0.8); + + // double data[3]; + // actor->GetPosition(data); + // actor->SetPosition(data[0],data[1],src->GetZLength()/2); + + switch (type) + { + case DOOR: + { + double colorRGB[3]; + lookupTable->GetColor(doorColor, colorRGB); + actor->GetProperty()->SetColor(colorRGB); + src->SetXLength(doorThickness); + src->SetZLength(doorHeight); + //src->SetRadius(doorWidth); + actor->GetProperty()->SetOpacity(0.5); + assemblyDoors3D->AddPart(actor); + } + break; + case WALL: + { + double colorRGB[3]; + lookupTable->GetColor(wallColor, colorRGB); + actor->GetProperty()->SetColor(colorRGB); + //actor->GetProperty()->SetSpecular(1); + //actor->GetProperty()->SetDiffuse(1); + //actor->GetProperty()->SetAmbient(1); + + src->SetXLength(wallThickness); + src->SetZLength(wallHeight); + //src->SetRadius(wallWidth); + assemblyWalls3D->AddPart(actor); + } + break; + case STEP: + { + double colorRGB[3]; + lookupTable->GetColor(stepColor, colorRGB); + actor->GetProperty()->SetColor(colorRGB); + src->SetXLength(wallThickness); //FIXME, this is wrong + src->SetZLength(stepHeight); + assemblyDoors3D->AddPart(actor); + } + break; + + //default behaviour not defined + default: + break; + } + + // now adjusting the z coordinates + double data[3]; + actor->GetPosition(data); + actor->SetPosition(data[0],data[1],src->GetZLength()/2); + actor->Delete(); +} 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); + + + 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; - // if(SystemSettings::get2D()){ - double m[]={x1,y1,z1}; - double n[]={x2,y2,z2}; - linesPlotter2D->PlotWall(m,n,wallColor/255.0); + addNewElement(center, length, angle, WALL); + + delete p1; + delete p2; + delete center; +} + +void FacilityGeometry::addStair(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; + + // 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); +// 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, WALL); + +// delete p1; +// delete p2; +// delete center; } 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); + + 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; - //double m[]={x1,y1,z+1}; - //double n[]={x2,y2,z+1}; - //printf("[%f %f %f]---[%f %f %f]\n",x1,y1,z,x2,y2,z); + addNewElement(center, length, angle, DOOR); - linesPlotter2D->PlotDoor(m,n,doorColor/255.0); + delete p1; + delete p2; + 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}; - 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); + double *center = p1->centreCoordinatesWith(*p2); + double angle =p1->angleMadeWith(*p2); + double length =p1->distanceTo(*p2)+wallThickness; + + addNewElement(center, length, angle, STEP); + + delete p1; + delete p2; + delete center; } 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); + double length =p1->distanceTo(*p2)+wallThickness; + addNewElement( center, length, angle, STEP); } void FacilityGeometry::addWall(JPoint* p1, JPoint* p2, string caption){ - double m[3]; - double n[3]; - double CHT[3]; - p1->getXYZ(m); - p2->getXYZ(n); - p1->getColorHeightThicknes(CHT); + double m[3]; + double n[3]; + double CHT[3]; + p1->getXYZ(m); + p2->getXYZ(n); + p1->getColorHeightThicknes(CHT); + + wallThickness = CHT[2]; + wallHeight=CHT[1]; + wallColor = CHT[0]; + linesPlotter2D->PlotWall(m,n,wallColor/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(),50); + } + + double *center = p1->centreCoordinatesWith(*p2); + double angle =p1->angleMadeWith(*p2); + double length =p1->distanceTo(*p2)+wallThickness; + addNewElement( center, length, angle, WALL); +} - wallThickness = CHT[2]; - wallHeight=CHT[1]; - wallColor = CHT[0]; - linesPlotter2D->PlotWall(m,n,wallColor/255.0); +void FacilityGeometry::addStair(JPoint* p1, JPoint* p2, string caption){ + double m[3]; + double n[3]; + double CHT[3]; + p1->getXYZ(m); + p2->getXYZ(n); + p1->getColorHeightThicknes(CHT); + + wallThickness = CHT[2]; + wallHeight=CHT[1]; + wallColor = CHT[0]; + linesPlotter2D->PlotWall(m,n,wallColor/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(),50); + } + +// double *center = p1->centreCoordinatesWith(*p2); +// double angle =p1->angleMadeWith(*p2); +// double length =p1->distanceTo(*p2)+wallThickness; +// addNewElement( center, length, angle, WALL); +} +void FacilityGeometry::addDoor(JPoint* p1, JPoint* p2, string caption){ - if (caption.compare("") != 0){ + 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->PlotDoor(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); + } + + double *center = p1->centreCoordinatesWith(*p2); + double angle =p1->angleMadeWith(*p2); + double length =p1->distanceTo(*p2)+wallThickness; + addNewElement( center, length, angle, DOOR); +} - 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(),50); - } +void FacilityGeometry::addNavLine(JPoint* p1, JPoint* p2, string caption){ -} + double m[3]; + double n[3]; + double CHT[3]; -void FacilityGeometry::addDoor(JPoint* p1, JPoint* p2, string caption){ + 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); - double m[3]; - double n[3]; - double CHT[3]; + doorThickness = CHT[2]; + doorHeight=CHT[1]; + doorColor = CHT[0]; - 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); + linesPlotter2D->PlotNavLine(m,n,doorColor/255.0); - doorThickness = CHT[2]; - doorHeight=CHT[1]; - doorColor = CHT[0]; + if (caption.compare("") != 0){ - linesPlotter2D->PlotDoor(m,n,doorColor/255.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(vtkPolyData* polygonPolyData ) +{ + //triagulate everything + // Create a mapper and actor + VTK_CREATE(vtkTriangleFilter,filter); + VTK_CREATE(vtkPolyDataMapper,mapper); - if (caption.compare("") != 0){ +#if VTK_MAJOR_VERSION <= 5 + filter->SetInput(polygonPolyData); + mapper->SetInput(filter->GetOutput()); +#else + filter->SetInputData(polygonPolyData); + mapper->SetInputConnection(filter->GetOutputPort()); +#endif - 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); - } + floorActor->SetMapper(mapper); + floorActor->GetProperty()->SetColor(0,0,1); + floorActor->GetProperty()->SetOpacity(0.4); + 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); @@ -439,183 +605,247 @@ 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); +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); + + 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); + } +} - { - VTK_CREATE(vtkCubeSource,src); - src->SetCenter(center[0], center[1], center[2]); - src->SetZLength(1); //todo: fake projection - src->SetYLength(length); - src->SetXLength(width); +void FacilityGeometry::changeWallsColor(double* color) +{ + //2D part + linesPlotter2D->changeWallsColor(color); + assembly2D->Modified(); + + //3D parts + vtkProp3DCollection* col=assemblyWalls3D->GetParts(); + assemblyWalls3D->GetActors(col); + + int count = col->GetNumberOfItems(); + for (int i=0;i<count;i++){ + ((vtkActor*)col->GetItemAsObject(i))->GetProperty()->SetColor(color); + } + assemblyWalls3D->Modified(); +} - VTK_CREATE(vtkPolyDataMapper,mapper); - mapper->SetInputConnection(src->GetOutputPort()); +void FacilityGeometry::changeExitsColor(double* color) +{ + //2D part + linesPlotter2D->changeDoorsColor(color); + assembly2D->Modified(); - 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); - } -} + //3D part + vtkProp3DCollection* col=assemblyDoors3D->GetParts(); + assemblyDoors3D->GetActors(col); -void FacilityGeometry::changeWallsColor(double* color){ + int count = col->GetNumberOfItems(); + for (int i=0;i<count;i++){ + ((vtkActor*)col->GetItemAsObject(i))->GetProperty()->SetColor(color); + } + assemblyDoors3D->Modified(); - linesPlotter2D->changeWallsColor(color); - assembly2D->Modified(); } -void FacilityGeometry::changeExitsColor(double* color){ - - linesPlotter2D->changeDoorsColor(color); - assembly2D->Modified(); +void FacilityGeometry::changeNavLinesColor(double *color) +{ + //2D part + linesPlotter2D->changeNavLinesColor(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); } void FacilityGeometry::showDoors(bool status){ - linesPlotter2D->showDoors(status); - assembly2D->Modified(); + linesPlotter2D->showDoors(status); + assembly2D->Modified(); + + vtkProp3DCollection* col=assemblyDoors3D->GetParts(); + assemblyDoors3D->GetActors(col); + + int count = col->GetNumberOfItems(); + for (int i=0;i<count;i++){ + ((vtkActor*)col->GetItemAsObject(i))->SetVisibility(status); + } + assemblyDoors3D->Modified(); } -void FacilityGeometry::showStairs(bool status){ +void FacilityGeometry::showStairs(bool status) +{ } -void FacilityGeometry::showWalls(bool status){ - linesPlotter2D->showWalls(status); - assembly2D->Modified(); +void FacilityGeometry::showWalls(bool status) +{ + linesPlotter2D->showWalls(status); + assembly2D->Modified(); + + vtkProp3DCollection* col=assemblyWalls3D->GetParts(); + assemblyWalls3D->GetActors(col); + + int count = col->GetNumberOfItems(); + for (int i=0;i<count;i++){ + ((vtkActor*)col->GetItemAsObject(i))->SetVisibility(status); + } + assemblyWalls3D->Modified(); +} + +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) { - - //return ; +string text, double color) { - {//caption - VTK_CREATE(vtkTextActor3D,caption); - caption = vtkTextActor3D ::New(); + //return ; - //caption->SetVisibility(false); - caption->SetInput(text.c_str()); - // set the properties of the caption - //FARBE - vtkTextProperty* tprop = caption->GetTextProperty(); - //tprop->SetFontFamilyToArial(); - //tprop->BoldOn(); - //tprop->ShadowOn(); - //tprop->SetLineSpacing(1.0); - tprop->SetFontSize(SystemSettings::getPedestrianCaptionSize()); + //caption + VTK_CREATE(vtkTextActor3D,caption); + caption = vtkTextActor3D ::New(); - double colorRGB[3]; - lookupTable->GetColor(color, colorRGB); - tprop->SetColor(colorRGB); + //caption->SetVisibility(false); + caption->SetInput(text.c_str()); + // set the properties of the caption + //FARBE + vtkTextProperty* tprop = caption->GetTextProperty(); + //tprop->SetFontFamilyToArial(); + //tprop->BoldOn(); + //tprop->ShadowOn(); + //tprop->SetLineSpacing(1.0); + tprop->SetFontSize(SystemSettings::getPedestrianCaptionSize()); - //cout<<"size:" <<tprop->GetFontSize()<<endl; - //tprop->SetColor(1,0,0); + double colorRGB[3]; + lookupTable->GetColor(color, colorRGB); + tprop->SetColor(colorRGB); - caption->SetPosition(center); - assemblyCaptions->AddPart(caption); + caption->SetPosition(center); + assemblyCaptions->AddPart(caption); - } } 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 7b567cc970b48ce6973bf49a654f03eb7148e8e8..37d5db7048084ed8de8951bd9f322630c2b64d56 100644 --- a/src/geometry/FacilityGeometry.h +++ b/src/geometry/FacilityGeometry.h @@ -51,7 +51,7 @@ class FacilityGeometry{ public: /** - * Building element types that are actually supported + * Building element types that are actually supported */ enum ELEMENT_TYPE{ DOOR, //!< DOOR defined by two coordinates points are needed. @@ -66,28 +66,45 @@ public: FacilityGeometry(); virtual ~FacilityGeometry(); - vtkAssembly* getActor(); + vtkAssembly* getActor2D(); + + vtkAssembly* getActor3D(); + + vtkAssembly* getCaptionsActor(); 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); void addWall(JPoint* p1, JPoint* p2, std::string caption=""); + ///draw a stair + void addStair(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); + void addStair(JPoint* p1, JPoint* p2, std::string caption=""); + + ///draw a door void addDoor(double x1, double y1, double z1 ,double x2, double y2, double z2, double thickness=17, double height=250,double col=30); //void addDoor(double center[3], double width, double orientation); void addDoor(JPoint* p1, JPoint* p2, std::string caption=""); - + ///draw a step - ///todo: implement thickness and color + ///todo: implement thickness and color void addStep(double x1, double y1, double z1, double x2, double y2, double z2=0/*, double thickness=30, double height=10,double col=50*/); //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); + void addFloor(vtkPolyData* polygonPolyData); /// draw other kinds of objects void addObjectSphere(double center[3], double radius, double couleur=1); @@ -98,6 +115,8 @@ 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); @@ -105,7 +124,9 @@ public: void showDoors(bool status); void showStairs(bool status); void showWalls(bool status); - void showGeometryLabels(int v); + void showNavLines(bool status); + void showFloor(bool status); + void showGeometryLabels(int status); private: @@ -126,6 +147,7 @@ private: double wallColor; double stepColor; double doorColor; + double navlineColor; // geometry assembly vtkAssembly* assembly; @@ -134,19 +156,17 @@ private: LinePlotter2D* linesPlotter2D; vtkAssembly* assembly2D; -// // 3-d parts -// vtkAssembly* assemblyObjects; -// vtkAssembly* assemblyWalls3D; -// vtkAssembly* assemblyDoors3D; -// vtkAssembly* assembly3D; + // 3-d parts + //vtkAssembly* assemblyObjects; + vtkAssembly* assemblyWalls3D; + vtkAssembly* assemblyDoors3D; + vtkAssembly* assembly3D; + + vtkActor* floorActor; // other parts vtkAssembly* assemblyCaptions; - vtkActor2DCollection* captions; - - - }; #endif /* FACILITYGEOMETRY_H_ */ diff --git a/src/geometry/LinePlotter2D.cpp b/src/geometry/LinePlotter2D.cpp index f210724eaae4bb110b006c13617b4adcc851c144..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,42 +113,6 @@ LinePlotter2D::~LinePlotter2D(){ wall_actor->Delete(); } -void LinePlotter2D::SetScalarRange(double minval, double maxval) -{ - m_scalarMin = minval ; - m_scalarMax = maxval ; -} - -//void LinePlotter2D::SetLookupTable(vtkLookupTable* table) -//{ -// m_lookupTable = table ; -//} -//void LinePlotter2D::PlotLine(double m[3], double n[3], double scalar) -//{ -// -// m_lineScalars->SetNumberOfComponents(1); -// m_points->InsertNextPoint(m); -// m_lineScalars->InsertNextTuple1(scalar); -// m_points->InsertNextPoint(n); -// m_lineScalars->InsertNextTuple1(scalar); -// -// m_lines->InsertNextCell(2); -// m_lines->InsertCellPoint(m_curPointID); -// m_lines->InsertCellPoint(m_curPointID+1); -// -// m_curPointID+=2; -//} -//void LinePlotter2D::PlotLine(double x, double y, double z, -// double x2, double y2, double z2, double scalar) -//{ -// double m[3],n[3] ; -// m[0]=x; m[1]=y; m[2]=z; -// n[0]=x2; n[1]=y2; n[2]=z2; -// PlotLine(m,n,scalar); -// -//} - - void LinePlotter2D::SetAllLineWidth(int width) { //m_allLineWidth = width ; @@ -172,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) @@ -227,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 diff --git a/src/geometry/Obstacle.cpp b/src/geometry/Obstacle.cpp index 89eecf0c0861ce881c9f177843d9599edc26d12f..f36458d18613631538dc4917f6b98a2e66920f47 100644 --- a/src/geometry/Obstacle.cpp +++ b/src/geometry/Obstacle.cpp @@ -193,13 +193,13 @@ bool Obstacle::Contains(const Point& ped) const { return false; } -void Obstacle::ConvertLineToPoly() { +bool Obstacle::ConvertLineToPoly() { if(_isClosed==0.0){ char tmp[CLENGTH]; sprintf(tmp, "INFO: \tObstacle [%d] is not closed. Not converting to polyline.\n", _id); Log->Write(tmp); - return; + return true; } vector<Line*> copy; vector<Point> tmpPoly; @@ -235,9 +235,10 @@ void Obstacle::ConvertLineToPoly() { char tmp[CLENGTH]; sprintf(tmp, "ERROR: \tObstacle::ConvertLineToPoly(): ID %d !!!\n", _id); Log->Write(tmp); - exit(0); + return false; } _poly = tmpPoly; + return true; } const Point Obstacle::GetCentroid() const{ diff --git a/src/geometry/Obstacle.h b/src/geometry/Obstacle.h index 79d3ed2c74946927865b0de849ef4804168ab4e5..6456bd22cc43a29458ff85bf0ba086ed6c60b032 100644 --- a/src/geometry/Obstacle.h +++ b/src/geometry/Obstacle.h @@ -111,7 +111,7 @@ public: /** * Create the obstacles polygonal structure from the walls */ - void ConvertLineToPoly(); + bool ConvertLineToPoly(); /** * @return the obstacle as a polygon diff --git a/src/geometry/PointPlotter.cpp b/src/geometry/PointPlotter.cpp index f8b388ee89f41e147bf3ba65137f5d8bb308db3b..e36aa27155cef4a0ce36bb64a5e24834e0b0e376 100644 --- a/src/geometry/PointPlotter.cpp +++ b/src/geometry/PointPlotter.cpp @@ -10,11 +10,14 @@ #include <vtkPolyData.h> #include <vtkActor.h> #include <vtkDataArray.h> +#include <vtkFloatArray.h> #include <vtkGlyph3D.h> #include <vtkDiskSource.h> #include <vtkPolyDataMapper.h> #include <vtkPointData.h> #include <vtkSmartPointer.h> +#include <vtkLookupTable.h> +#include <vtkRegularPolygonSource.h> #include "JPoint.h" #include "PointPlotter.h" @@ -26,7 +29,6 @@ PointPlotter::PointPlotter() { - pts = vtkPoints::New(); //pts->Allocate(30); //pts->SetNumberOfPoints(30); @@ -35,46 +37,48 @@ PointPlotter::PointPlotter() SetPointResolution(); scalars = vtkUnsignedCharArray::New(); - //scalars->Allocate(30); scalars->SetNumberOfComponents(3); - //scalars->setn + colors=vtkFloatArray::New(); + +// VTK_CREATE(vtkDiskSource,src); +// src->SetRadialResolution(5); +// src->SetCircumferentialResolution(pt_res); +// src->SetInnerRadius(0.00); +// src->SetOuterRadius(pt_radius); - //vtkDiskSource* src = vtkDiskSource::New(); - VTK_CREATE(vtkDiskSource,src); - src->SetRadialResolution(5); - src->SetCircumferentialResolution(pt_res); - src->SetInnerRadius(0.00); - src->SetOuterRadius(pt_radius); + VTK_CREATE(vtkRegularPolygonSource,src); + src->SetRadius(2.0); + src->SetNumberOfSides(5); - //vtkPolyData* polyData = vtkPolyData::New(); VTK_CREATE(vtkPolyData,polyData); polyData->SetPoints(pts); - polyData->GetPointData()->SetScalars(scalars); + //polyData->GetPointData()->SetScalars(scalars); + polyData->GetPointData()->SetScalars(colors); -// vtkGlyph3D* glyph = vtkGlyph3D::New(); VTK_CREATE(vtkGlyph3D,glyph); glyph->SetSourceConnection(src->GetOutputPort()); + #if VTK_MAJOR_VERSION <= 5 glyph->SetInput(polyData); #else glyph->SetInputData(polyData); #endif - //src->Delete(); - //polyData->Delete(); - glyph->SetColorModeToColorByScalar(); + + glyph->SetColorModeToColorByScalar(); glyph->SetScaleModeToDataScalingOff() ; - //vtkPolyDataMapper* mapper = vtkPolyDataMapper::New(); VTK_CREATE(vtkPolyDataMapper,mapper); mapper->SetInputConnection(glyph->GetOutputPort()); - //glyph->Delete(); - //vtkActor + //borrow the lookup table from the peds glyphs + mapper->SetLookupTable( + extern_glyphs_pedestrians_actor_2D->GetMapper()->GetLookupTable()); + + //vtkActor pointActor = vtkActor::New(); pointActor->SetMapper(mapper); - //mapper->Delete(); /// initizliae the ID nextPointID=0; @@ -86,6 +90,8 @@ PointPlotter::~PointPlotter() pts->Delete(); if (scalars) scalars->Delete(); + if (colors) + colors->Delete(); if (pointActor) pointActor->Delete(); } @@ -106,6 +112,23 @@ void PointPlotter::PlotPoint(JPoint * point){ PlotPoint( x, y, z, r, g, b); } +void PointPlotter::PlotPoint(double pos[3], double col) +{ + nextPointID++; + if(col==-1) + { + colors->InsertTuple1(nextPointID,NAN); + } + else + { + colors->InsertTuple1(nextPointID,col/255.0); + } + + pts->InsertPoint(nextPointID,pos); + pts->Modified(); + colors->Modified(); +} + void PointPlotter::PlotPoint(double x, double y, double z, unsigned char r, unsigned char g, unsigned char b) { @@ -115,17 +138,21 @@ void PointPlotter::PlotPoint(double x, double y, double z, SystemSettings::getTrailsInfo(&PointsCount,&dummy,&dummy1); - nextPointID=nextPointID%PointsCount; + //nextPointID=nextPointID%PointsCount; pts->InsertPoint(nextPointID,x,y,z); - //pts->SetPoint(nextPointID,x,y,z); - //scalars->SetTuple3(nextPointID,r,g,b); - scalars->InsertTuple3(nextPointID,r,g,b); - //scalars->InsertNextTuple3(r,g,b); + //pts->SetPoint(nextPointID,x,y,z); + //scalars->SetTuple3(nextPointID,r,g,b); + scalars->InsertTuple3(nextPointID,r,g,b); + //scalars->InsertNextTuple3(r,g,b); pts->Modified(); - scalars->Modified(); + scalars->Modified(); } +void PointPlotter::SetVisibility(bool status) +{ + pointActor->SetVisibility(status); +} vtkActor * PointPlotter::getActor(){ return pointActor;} diff --git a/src/geometry/PointPlotter.h b/src/geometry/PointPlotter.h index 9d5e48120d21e8721c88351cbcdca1a533ca41c1..341d82bbf7c03f362415aae094e917ec85906a87 100644 --- a/src/geometry/PointPlotter.h +++ b/src/geometry/PointPlotter.h @@ -41,8 +41,12 @@ class vtkUnsignedCharArray ; class vtkPolyData ; class vtkActor ; class vtkDataArray ; +class vtkFloatArray ; class JPoint; +//for borrowing the lookup table +extern vtkSmartPointer<vtkActor> extern_glyphs_pedestrians_actor_2D; + class PointPlotter { public: @@ -54,7 +58,8 @@ public: void PlotPoint(double x, double y, double z, unsigned char r='a', unsigned char g='b', unsigned char b='c'); - void PlotPoint(JPoint* pt); + void PlotPoint(JPoint* pt); + void PlotPoint(double Position[3], double colour); void SetPointRadius(double radius = 1.0) { pt_radius = radius ; } void SetPointResolution(int res = 15) { pt_res = res ;} @@ -62,11 +67,14 @@ public: ///return the actors vtkActor* getActor(); + void SetVisibility(bool status); + private: vtkActor* pointActor; vtkPoints* pts ; vtkDataArray* scalars ; + vtkFloatArray* colors; vtkIdType nextPointID; int scalar_mode ; double pt_radius ; diff --git a/src/geometry/SubRoom.cpp b/src/geometry/SubRoom.cpp index e0868cdc73453984f1fa41b048cb73dac0d41442..cab0d05a920c9375cfd11398d458c3f6412f3817 100644 --- a/src/geometry/SubRoom.cpp +++ b/src/geometry/SubRoom.cpp @@ -594,7 +594,7 @@ void NormalSubRoom::WriteToErrorLog() const { } } -void NormalSubRoom::ConvertLineToPoly(vector<Line*> goals) { +bool NormalSubRoom::ConvertLineToPoly(vector<Line*> goals) { vector<Line*> copy; vector<Point> tmpPoly; Point point; @@ -635,9 +635,10 @@ void NormalSubRoom::ConvertLineToPoly(vector<Line*> goals) { Log->Write(tmp); sprintf(tmp, "ERROR: \tDistance between the points: %lf !!!\n", (tmpPoly[0] - point).Norm()); Log->Write(tmp); - exit(EXIT_FAILURE); + return false; } _poly = tmpPoly; + return true; } @@ -830,7 +831,7 @@ const Point* Stair::CheckCorner(const Point** otherPoint, const Point** aktPoint return rueck; } -void Stair::ConvertLineToPoly(vector<Line*> goals) { +bool Stair::ConvertLineToPoly(vector<Line*> goals) { //return NormalSubRoom::ConvertLineToPoly(goals); @@ -887,7 +888,7 @@ void Stair::ConvertLineToPoly(vector<Line*> goals) { sprintf(tmp, "ERROR: \tStair::ConvertLineToPoly(): SubRoom %d Room %d Anfangspunkt ungleich Endpunkt!!!\n" "\t(%f, %f) != (%f, %f)\n", GetSubRoomID(), GetRoomID(), x1, y1, x2, y2); Log->Write(tmp); - exit(EXIT_FAILURE); + return false; } if (orgPoly.size() != 4) { @@ -895,7 +896,7 @@ void Stair::ConvertLineToPoly(vector<Line*> goals) { sprintf(tmp, "ERROR: \tStair::ConvertLineToPoly(): Stair %d Room %d ist kein Viereck!!!\n" "Anzahl Ecken: %d\n", GetSubRoomID(), GetRoomID(), orgPoly.size()); Log->Write(tmp); - exit(EXIT_FAILURE); + return false; } vector<Point> neuPoly = (orgPoly); // ganz kleine Treppen (nur eine Stufe) nicht @@ -920,6 +921,7 @@ void Stair::ConvertLineToPoly(vector<Line*> goals) { } } _poly = neuPoly; + return true; } bool Stair::IsInSubRoom(const Point& ped) const { diff --git a/src/geometry/SubRoom.h b/src/geometry/SubRoom.h index 5fc028546cc38131f328cbf5a53539700dba6b78..a73b90209630f80646caca43d7fd5a644b4923cb 100644 --- a/src/geometry/SubRoom.h +++ b/src/geometry/SubRoom.h @@ -307,7 +307,7 @@ public: virtual std::string WritePolyLine() const=0; /// convert all walls and transitions(doors) into a polygon representing the subroom - virtual void ConvertLineToPoly(std::vector<Line*> goals) = 0; + virtual bool ConvertLineToPoly(std::vector<Line*> goals) = 0; ///check whether the pedestrians is still in the subroom virtual bool IsInSubRoom(const Point& ped) const = 0; @@ -352,8 +352,8 @@ public: std::string WriteSubRoom() const; std::string WritePolyLine() const; - void WriteToErrorLog() const; - void ConvertLineToPoly(std::vector<Line*> goals); + virtual void WriteToErrorLog() const; + virtual bool ConvertLineToPoly(std::vector<Line*> goals); bool IsInSubRoom(const Point& ped) const; }; @@ -388,7 +388,7 @@ public: std::string WriteSubRoom() const; std::string WritePolyLine() const; virtual void WriteToErrorLog() const; - virtual void ConvertLineToPoly(std::vector<Line*> goals); + virtual bool ConvertLineToPoly(std::vector<Line*> goals); bool IsInSubRoom(const Point& ped) const; }; diff --git a/src/main.cpp b/src/main.cpp index 035b704f97107ad5572a422f0071500113e217de..5cb9a4dc85a2b8dc4b3b6803dea0e24d8e30824b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -61,7 +61,8 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); // To ensure that decimal numbers use a "point" instead of "colon" on some systems - setlocale(LC_NUMERIC, "en_US" ); + //setlocale(LC_NUMERIC, "en_US" ); + setlocale(LC_NUMERIC,"C"); MainWindow w; w.show();