From ae0f3542394946f0733d1825b854e78790b24d3a Mon Sep 17 00:00:00 2001 From: Ulrich Kemloh <kemlohulrich@gmail.com> Date: Tue, 2 Jun 2015 14:51:42 +0200 Subject: [PATCH] added Geoemtryfactory for a detailed control og the geometry elements --- src/MainWindow.cpp | 144 ++++++------------ src/MainWindow.h | 2 +- src/geometry/FacilityGeometry.cpp | 6 + src/geometry/FacilityGeometry.h | 2 + src/geometry/GeometryFactory.cpp | 236 ++++++++++++++++++++++++++++++ src/geometry/GeometryFactory.h | 48 ++++++ 6 files changed, 341 insertions(+), 97 deletions(-) create mode 100644 src/geometry/GeometryFactory.cpp create mode 100644 src/geometry/GeometryFactory.h diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index fe3af9a..5c9da19 100755 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -111,7 +111,7 @@ MainWindow::MainWindow(QWidget *parent) : //create the 2 threads and connect them dataTransferThread = new ThreadDataTransfer(this); - visualisationThread = new ThreadVisualisation(this); + _visualisationThread = new ThreadVisualisation(this); travistoOptions = new Settings(this); @@ -143,7 +143,7 @@ MainWindow::MainWindow(QWidget *parent) : Debug::Error("signal_errorMessage not connected "); } - QObject::connect(visualisationThread, + QObject::connect(_visualisationThread, SIGNAL(signal_controlSequences(const char*)), this, SLOT(slotControlSequence(const char *))); @@ -158,7 +158,7 @@ MainWindow::MainWindow(QWidget *parent) : travistoOptions, SLOT(slotControlSequence(QString))); - QObject::connect(&visualisationThread->getGeometry().GetModel(), + QObject::connect(&_visualisationThread->getGeometry().GetModel(), SIGNAL(itemChanged(QStandardItem*)),this,SLOT(slotOnGeometryItemChanged(QStandardItem*))); isPlaying = false; @@ -277,7 +277,7 @@ MainWindow::~MainWindow() } - if (visualisationThread->isRunning()) { + if (_visualisationThread->isRunning()) { //std::Debug::Messages("Thread visualisation is still running" << std::endl; waitForVisioThread(); } @@ -289,7 +289,7 @@ MainWindow::~MainWindow() } delete dataTransferThread; - delete visualisationThread; + delete _visualisationThread; delete travistoOptions; delete labelCurrentAction; delete labelFrameNumber; @@ -355,7 +355,7 @@ void MainWindow::slotStartPlaying() visualisationThread->run(); }); #else - visualisationThread->start(); + _visualisationThread->start(); #endif @@ -466,7 +466,7 @@ void MainWindow::parseGeometry(const QDomNode &geoNode) //check if there is a tag 'file' there in QString fileName = geoNode.toElement().elementsByTagName("file").item(0).toElement().attribute("location"); - auto&& geometry = visualisationThread->getGeometry(); + auto&& geometry = _visualisationThread->getGeometry(); if(!fileName.isEmpty()) { if (fileName.endsWith(".xml",Qt::CaseInsensitive)) { @@ -534,7 +534,7 @@ void MainWindow::parseGeometry(const QString& geometryString) //cout<<"filename: "<<geofileName.toStdString()<<endl;exit(0); - auto&& geometry = visualisationThread->getGeometry(); + auto&& geometry = _visualisationThread->getGeometry(); @@ -659,7 +659,7 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName) SystemSettings::setFilenamePrefix(QFileInfo ( fileName ).baseName()+"_"); //the geometry actor - auto&& geometry = visualisationThread->getGeometry(); + auto&& geometry = _visualisationThread->getGeometry(); //try to get a geometry filename QString geometry_file=SaxParser::extractGeometryFilename(fileName); @@ -748,8 +748,8 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName) QString frameRateStr=QString::number(frameRate); // set the visualisation window title - visualisationThread->setWindowTitle(fileName); - visualisationThread->slotSetFrameRate(frameRate); + _visualisationThread->setWindowTitle(fileName); + _visualisationThread->slotSetFrameRate(frameRate); //visualisationThread->setGeometry(geometry); //visualisationThread->setWindowTitle(caption); labelFrameNumber->setText("fps: " + frameRateStr+"/"+frameRateStr); @@ -1090,7 +1090,7 @@ void MainWindow::slotShowPedestrianOnly() void MainWindow::slotShowGeometry() { if (ui.actionShow_Geometry->isChecked()) { - visualisationThread->setGeometryVisibility(true); + _visualisationThread->setGeometryVisibility(true); ui.actionShow_Exits->setEnabled(true); ui.actionShow_Walls->setEnabled(true); ui.actionShow_Geometry_Captions->setEnabled(true); @@ -1098,7 +1098,7 @@ void MainWindow::slotShowGeometry() ui.actionShow_Floor->setEnabled(true); SystemSettings::setShowGeometry(true); } else { - visualisationThread->setGeometryVisibility(false); + _visualisationThread->setGeometryVisibility(false); ui.actionShow_Exits->setEnabled(false); ui.actionShow_Walls->setEnabled(false); ui.actionShow_Geometry_Captions->setEnabled(false); @@ -1113,7 +1113,7 @@ void MainWindow::slotShowGeometry() void MainWindow::slotShowHideExits() { bool status = ui.actionShow_Exits->isChecked(); - visualisationThread->showDoors(status); + _visualisationThread->showDoors(status); SystemSettings::setShowExits(status); } @@ -1121,14 +1121,14 @@ void MainWindow::slotShowHideExits() void MainWindow::slotShowHideWalls() { bool status = ui.actionShow_Walls->isChecked(); - visualisationThread->showWalls(status); + _visualisationThread->showWalls(status); SystemSettings::setShowWalls(status); } void MainWindow::slotShowHideNavLines() { bool status = ui.actionShow_Navigation_Lines->isChecked(); - visualisationThread->showNavLines(status); + _visualisationThread->showNavLines(status); SystemSettings::setShowNavLines(status); } @@ -1136,7 +1136,7 @@ void MainWindow::slotShowHideNavLines() void MainWindow::slotShowHideFloor() { bool status = ui.actionShow_Floor->isChecked(); - visualisationThread->showFloor(status); + _visualisationThread->showFloor(status); SystemSettings::setShowFloor(status); } @@ -1222,11 +1222,11 @@ void MainWindow::resetAllFrameCursor() ///@todo why two different threads shutdown procedure. void MainWindow::waitForVisioThread() { - while(visualisationThread->isRunning()) { - visualisationThread->wait(200); + while(_visualisationThread->isRunning()) { + _visualisationThread->wait(200); Debug::Messages("waiting for visualisation engine to terminate ..."); #ifdef __linux__ - visualisationThread->quit(); + _visualisationThread->quit(); #else visualisationThread->terminate(); #endif @@ -1263,7 +1263,7 @@ void MainWindow::slotToogle2D() SystemSettings::set2D(false); } bool status=SystemSettings::get2D() && SystemSettings::getShowGeometry(); - visualisationThread->setGeometryVisibility2D(status); + _visualisationThread->setGeometryVisibility2D(status); extern_force_system_update=true; } @@ -1281,7 +1281,7 @@ void MainWindow::slotToogle3D() SystemSettings::set2D(true); } bool status= !SystemSettings::get2D() && SystemSettings::getShowGeometry(); - visualisationThread->setGeometryVisibility3D(status); + _visualisationThread->setGeometryVisibility3D(status); extern_force_system_update=true; } @@ -1332,9 +1332,9 @@ void MainWindow::slotStartVisualisationThread(QString data,int numberOfAgents,fl //FacilityGeometry *geo = parseGeometry(geoNode); parseGeometry(data); - visualisationThread->slotSetFrameRate(frameRate); + _visualisationThread->slotSetFrameRate(frameRate); //visualisationThread->setGeometry(geo); - visualisationThread->start(); + _visualisationThread->start(); //enable some buttons ui.BtRecord->setEnabled(true); @@ -1395,7 +1395,7 @@ void MainWindow::slotShowPedestrianCaption() void MainWindow::slotToogleShowAxis() { - visualisationThread->setAxisVisible(ui.actionShow_Axis->isChecked()); + _visualisationThread->setAxisVisible(ui.actionShow_Axis->isChecked()); } //todo: rename this to slotChangeSettting @@ -1434,7 +1434,7 @@ void MainWindow::slotChangeBackgroundColor() if(col.isValid()==false) return; //double bkcolor[3]= {(double)col.red()/255.0 ,(double)col.green()/255.0 ,(double)col.blue()/255.0}; - visualisationThread->setBackgroundColor(col); + _visualisationThread->setBackgroundColor(col); QSettings settings; settings.setValue("options/bgColor", col); @@ -1453,7 +1453,7 @@ void MainWindow::slotChangeWallsColor() //the user may have cancelled the process if(col.isValid()==false) return; - visualisationThread->setWallsColor(col); + _visualisationThread->setWallsColor(col); QSettings settings; settings.setValue("options/wallsColor", col); @@ -1472,7 +1472,7 @@ void MainWindow::slotChangeExitsColor() //the user may have cancelled the process if(col.isValid()==false) return; - visualisationThread->setExitsColor(col); + _visualisationThread->setExitsColor(col); QSettings settings; settings.setValue("options/exitsColor", col); @@ -1490,7 +1490,7 @@ void MainWindow::slotChangeNavLinesColor() //the user may have cancelled the process if(col.isValid()==false) return; - visualisationThread->setNavLinesColor(col); + _visualisationThread->setNavLinesColor(col); QSettings settings; settings.setValue("options/navLinesColor", col); @@ -1507,7 +1507,7 @@ void MainWindow::slotChangeFloorColor() //the user may have cancelled the process if(col.isValid()==false) return; - visualisationThread->setFloorColor(col); + _visualisationThread->setFloorColor(col); QSettings settings; settings.setValue("options/floorColor", col); @@ -1519,7 +1519,7 @@ void MainWindow::slotSetCameraPerspectiveToTop() { int p= 1; //TOP - visualisationThread->setCameraPerspective(p); + _visualisationThread->setCameraPerspective(p); //disable the virtual agent view SystemSettings::setVirtualAgent(-1); //cerr <<"Setting camera view to top"<<endl; @@ -1528,7 +1528,7 @@ void MainWindow::slotSetCameraPerspectiveToTop() void MainWindow::slotSetCameraPerspectiveToFront() { int p= 2; //FRONT - visualisationThread->setCameraPerspective(p); + _visualisationThread->setCameraPerspective(p); //disable the virtual agent view SystemSettings::setVirtualAgent(-1); // cerr <<"Setting camera view to FRONT"<<endl; @@ -1537,7 +1537,7 @@ void MainWindow::slotSetCameraPerspectiveToFront() void MainWindow::slotSetCameraPerspectiveToSide() { int p= 3; //SIDE - visualisationThread->setCameraPerspective(p); + _visualisationThread->setCameraPerspective(p); //disable the virtual agent view SystemSettings::setVirtualAgent(-1); //cerr <<"Setting camera view to Side"<<endl; @@ -1552,7 +1552,7 @@ void MainWindow::slotSetCameraPerspectiveToVirtualAgent() if (ok) { int p= 4; //virtual agent - visualisationThread->setCameraPerspective(p); + _visualisationThread->setCameraPerspective(p); //get the virtual agent ID SystemSettings::setVirtualAgent(agent); @@ -1562,7 +1562,7 @@ void MainWindow::slotSetCameraPerspectiveToVirtualAgent() /// @todo does it work? mem check? void MainWindow::slotClearGeometry() { - visualisationThread->setGeometry(NULL); + _visualisationThread->setGeometry(NULL); } void MainWindow::slotErrorOutput(QString err) @@ -1832,7 +1832,7 @@ void MainWindow::dropEvent(QDropEvent *event) void MainWindow::slotShowOnScreenInfos() { bool value=ui.actionShow_Onscreen_Infos->isChecked(); - visualisationThread->setOnscreenInformationVisibility(value); + _visualisationThread->setOnscreenInformationVisibility(value); SystemSettings::setOnScreenInfos(value); } @@ -1840,7 +1840,7 @@ void MainWindow::slotShowOnScreenInfos() void MainWindow::slotShowHideGeometryCaptions() { bool value=ui.actionShow_Geometry_Captions->isChecked(); - visualisationThread->setGeometryLabelsVisibility(value); + _visualisationThread->setGeometryLabelsVisibility(value); SystemSettings::setShowGeometryCaptions(value); //SystemSettings::setShowCaptions(value); //SystemSettings::setOnScreenInfos(value); @@ -1851,68 +1851,20 @@ void MainWindow::slotShowGeometryStructure() //QListView list; _geoStructure.setWindowTitle("Geometry structure"); _geoStructure.setVisible(! _geoStructure.isVisible()); + //_geoStructure.showColumn(0); _geoStructure.show(); - visualisationThread->getGeometry().RefreshView(); - _geoStructure.setModel(&visualisationThread->getGeometry().GetModel()); - cout<<"showing the list"<<endl; - - - /* - QFileSystemModel *model = new QFileSystemModel; - model->setRootPath(QDir::currentPath()); - QTreeView *tree = new QTreeView(&_splitter); - tree->setModel(model); - _splitter.show(); -*/ - - /* - QTreeView *tree = new QTreeView(&_splitter); - QListView *list = new QListView(); - QTableView *table = new QTableView(); - - - _splitter.addWidget( tree ); - _splitter.addWidget( list ); - _splitter.addWidget( table ); - - QStandardItemModel* model = new QStandardItemModel( 5, 2 ); - - for( int r=0; r<5; r++ ) - for( int c=0; c<2; c++) - { - QStandardItem *item = new QStandardItem( QString("Row:%0, Column:%1").arg(r).arg(c) ); - item->setCheckable(true); - - if( c == 0 ) - for( int i=0; i<3; i++ ) - { - QStandardItem *child = new QStandardItem( QString("Item %0").arg(i) ); - child->setEditable( false ); - child->setCheckable(true); - item->appendRow( child ); - cout<<"adding"<<endl; - } - - model->setItem(r, c, item); - } - - model->setHorizontalHeaderItem( 0, new QStandardItem( "Foo" ) ); - model->setHorizontalHeaderItem( 1, new QStandardItem( "Bar-Baz" ) ); - - tree->setModel( model ); - list->setModel( model ); - table->setModel( model ); - - list->setSelectionModel( tree->selectionModel() ); - table->setSelectionModel( tree->selectionModel() ); - - table->setSelectionBehavior( QAbstractItemView::SelectRows ); - table->setSelectionMode( QAbstractItemView::SingleSelection ); - _splitter.show(); -*/ + _visualisationThread->getGeometry().RefreshView(); + _geoStructure.setModel(&_visualisationThread->getGeometry().GetModel()); } void MainWindow::slotOnGeometryItemChanged( QStandardItem *item) { - cout<<"triggered"<<endl; + QStringList l=item->data().toString().split(":"); + if(l.length()>1) + { + int room=l[0].toInt(); + int subr=l[1].toInt(); + bool state=item->checkState(); + _visualisationThread->getGeometry().UpdateVisibility(room,subr,state); + } } diff --git a/src/MainWindow.h b/src/MainWindow.h index a2df0c2..a487756 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -322,7 +322,7 @@ private: Settings* travistoOptions; ThreadDataTransfer* dataTransferThread; - ThreadVisualisation* visualisationThread; + ThreadVisualisation* _visualisationThread; QLabel *labelCurrentAction; QLabel *labelFrameNumber; QLabel *labelRecording; diff --git a/src/geometry/FacilityGeometry.cpp b/src/geometry/FacilityGeometry.cpp index 8ecf48c..ab9168a 100644 --- a/src/geometry/FacilityGeometry.cpp +++ b/src/geometry/FacilityGeometry.cpp @@ -151,6 +151,12 @@ void FacilityGeometry::CreateActors() assembly3D->AddPart(assemblyCaptions); } + void FacilityGeometry::setVisibility(bool status) + { + assembly2D->SetVisibility(status); + assembly3D->SetVisibility(status); + } + //void FacilityGeometry::drawWall(Point *p1, Point *p2){ // double scale =1; // diff --git a/src/geometry/FacilityGeometry.h b/src/geometry/FacilityGeometry.h index bea3e52..0af9ad2 100644 --- a/src/geometry/FacilityGeometry.h +++ b/src/geometry/FacilityGeometry.h @@ -135,6 +135,8 @@ public: void showFloor(bool status); void showGeometryLabels(int status); + void setVisibility(bool status); + private: // TODO Check if this function is really necessary diff --git a/src/geometry/GeometryFactory.cpp b/src/geometry/GeometryFactory.cpp new file mode 100644 index 0000000..fd89158 --- /dev/null +++ b/src/geometry/GeometryFactory.cpp @@ -0,0 +1,236 @@ +#include "GeometryFactory.h" + +#include "FacilityGeometry.h" +#include <vtkRenderer.h> +#include <vtkAssembly.h> + +GeometryFactory::GeometryFactory() +{ + +} + +void GeometryFactory::Init(vtkRenderer* renderer) +{ + for (auto&& rooms: _geometryFactory) + { + for(auto&& subroom:rooms.second) + { + subroom.second->CreateActors(); + renderer->AddActor(subroom.second->getActor2D()); + renderer->AddActor(subroom.second->getActor3D()); + } + } +} + +void GeometryFactory::Set2D(bool status) +{ + for (auto&& room: _geometryFactory) + { + for(auto&& subroom:room.second) + { + subroom.second->set2D(status); + } + } +} + +void GeometryFactory::Set3D(bool status) +{ + for (auto&& room: _geometryFactory) + { + for(auto&& subroom:room.second) + { + subroom.second->set3D(status); + } + } +} + +void GeometryFactory::Clear() +{ + for (auto&& src: _geometryFactory) + { + cout<<"cleaning..."; + } +} + +void GeometryFactory::ChangeWallsColor(double* color) +{ + for (auto&& room: _geometryFactory) + { + for(auto&& subroom:room.second) + { + subroom.second->changeWallsColor(color); + } + } +} + +void GeometryFactory::ChangeExitsColor(double* color) +{ + for (auto&& room: _geometryFactory) + { + for(auto&& subroom:room.second) + { + subroom.second->changeExitsColor(color); + } + } +} + +void GeometryFactory::ChangeNavLinesColor(double* color) +{ + for (auto&& room: _geometryFactory) + { + for(auto&& subroom:room.second) + { + subroom.second->changeNavLinesColor(color); + } + } +} + +void GeometryFactory::ChangeFloorColor(double* color) +{ + for (auto&& room: _geometryFactory) + { + for(auto&& subroom:room.second) + { + subroom.second->changeFloorColor(color); + } + } +} + +void GeometryFactory::ChangeObstaclesColor(double* color) +{ + for (auto&& room: _geometryFactory) + { + for(auto&& subroom:room.second) + { + subroom.second->changeObstaclesColor(color); + } + } +} + +void GeometryFactory::ShowDoors(bool status) +{ + for (auto&& room: _geometryFactory) + { + for(auto&& subroom:room.second) + { + subroom.second->showDoors(status); + } + } +} + +void GeometryFactory::ShowStairs(bool status) +{ + for (auto&& room: _geometryFactory) + { + for(auto&& subroom:room.second) + { + subroom.second->showStairs(status); + } + } +} + +void GeometryFactory::ShowWalls(bool status) +{ + for (auto&& room: _geometryFactory) + { + for(auto&& subroom:room.second) + { + subroom.second->showWalls(status); + } + } +} + +void GeometryFactory::ShowNavLines(bool status) +{ + for (auto&& room: _geometryFactory) + { + for(auto&& subroom:room.second) + { + subroom.second->showNavLines(status); + } + } +} + +void GeometryFactory::ShowFloor(bool status) +{ + for (auto&& room: _geometryFactory) + { + for(auto&& subroom:room.second) + { + subroom.second->showFloor(status); + } + } +} + +void GeometryFactory::ShowGeometryLabels(int status) +{ + for (auto&& room: _geometryFactory) + { + for(auto&& subroom:room.second) + { + subroom.second->showGeometryLabels(status); + } + } +} + +void GeometryFactory::RefreshView() +{ + _model.setHorizontalHeaderItem( 0, new QStandardItem( "Entity" ) ); + _model.setHorizontalHeaderItem( 1, new QStandardItem( "Description" ) ); + + for (auto&& room: _geometryFactory) + { + //room caption + //QStandardItem *roomcaption = new QStandardItem( QString("R %0").arg(room.first)); + //roomcaption->setEditable( false ); + //_model.setItem(room.first, 1, roomcaption); + + QStandardItem *item = new QStandardItem( QString("Room:%0").arg(room.first)); + item->setCheckable(false); + item->setCheckState(Qt::Checked); + + for(auto&& subroom:room.second) + { + QStandardItem *child = new QStandardItem( QString("Subroom: %0").arg(subroom.first)); + child->setEditable( false ); + child->setCheckable(true); + child->setCheckState(Qt::Checked); + item->appendRow( child ); + _model.setItem(room.first, 0, item); + QString data = QString("%0:%1").arg(room.first).arg(subroom.first); + child->setData(data); + + //Subroom caption + //QStandardItem *childcaption = new QStandardItem( QString("S %0").arg(subroom.first)); + //childcaption->setEditable( false ); + //_model.setItem(room.first, 1, childcaption); + } + } +} + +const std::map<int , std::map<int, std::shared_ptr<FacilityGeometry> > > & GeometryFactory::GetGeometry() const +{ + return _geometryFactory; +} + +void GeometryFactory::AddElement(int room, int subroom, std::shared_ptr<FacilityGeometry> geo) +{ + //_geometryFactory.insert({room,{subroom,geo}}); + _geometryFactory[room][subroom]=geo; +} + +void GeometryFactory::UpdateVisibility(int room,int subroom,bool status) +{ + if(_geometryFactory.count(room)) + { + if(_geometryFactory[room].count(subroom)) + { + _geometryFactory[room][subroom]->setVisibility(status); + } + } +} + +QStandardItemModel& GeometryFactory::GetModel() +{ + return _model; +} diff --git a/src/geometry/GeometryFactory.h b/src/geometry/GeometryFactory.h new file mode 100644 index 0000000..e6b3fe4 --- /dev/null +++ b/src/geometry/GeometryFactory.h @@ -0,0 +1,48 @@ +#ifndef GEOMETRYFACTORY_H +#define GEOMETRYFACTORY_H + +#include<map> +#include<memory> +#include<iostream> + +#include <QStandardItemModel> +#include "FacilityGeometry.h" + +//forward classes +class FacilityGeometry; +class vtkRenderer; + +class GeometryFactory +{ +public: + GeometryFactory(); + + void Init(vtkRenderer* renderer); + void ChangeWallsColor(double* color); + void ChangeExitsColor(double* color); + void ChangeNavLinesColor(double* color); + void ChangeFloorColor(double* color); + void ChangeObstaclesColor(double* color); + void Set2D(bool status); + void Set3D(bool status); + void ShowDoors(bool status); + void ShowStairs(bool status); + void ShowWalls(bool status); + void ShowNavLines(bool status); + void ShowFloor(bool status); + void ShowGeometryLabels(int status); + void RefreshView(); + void Clear(); + + const std::map<int , std::map<int, std::shared_ptr<FacilityGeometry> > > & GetGeometry() const; + void AddElement(int room, int subroom, std::shared_ptr<FacilityGeometry> geo); + void UpdateVisibility(int room,int subroom,bool status); + QStandardItemModel& GetModel(); + +private: + //map a room,subroom id to a geometry element + std::map<int , std::map<int, std::shared_ptr<FacilityGeometry> > >_geometryFactory; + QStandardItemModel _model; +}; + +#endif // GEOMETRYFACTORY_H -- GitLab