diff --git a/JPSvis.pro b/JPSvis.pro index 33c1a4d7f5ab968804fd67461b4c59967cae7370..05789e3042e5ea2ab5537d38e347217e8aecff6b 100644 --- a/JPSvis.pro +++ b/JPSvis.pro @@ -551,7 +551,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 \ @@ -593,7 +593,7 @@ 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 \ diff --git a/src/Frame.cpp b/src/Frame.cpp index 90cdff1649b73e23b3a0841d8dbed58c87581e3f..89ae8d8ccae8af7f2a447c504fe8d6232e46b164 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -33,123 +33,80 @@ #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(); - - _polydata->Delete(); - _polydataLabels->Delete(); +Frame::~Frame() +{ + while (!_framePoints.empty()){ + delete _framePoints.back(); + _framePoints.pop_back(); + } + _framePoints.clear(); + + //_polydata->Delete(); + _polydata2D->Delete(); + _polydata3D->Delete(); } -int Frame::getSize(){ - return this->framePoints.size(); +int Frame::getSize() +{ + return _framePoints.size(); } -void Frame::addElement(TrajectoryPoint* point){ - framePoints.push_back(point); +void Frame::addElement(FrameElement* point) +{ + _framePoints.push_back(point); } -void Frame::clear(){ - while (!framePoints.empty()){ - delete framePoints.back(); - framePoints.pop_back(); - } - framePoints.clear(); +void Frame::clear() +{ + while (!_framePoints.empty()){ + delete _framePoints.back(); + _framePoints.pop_back(); + } + _framePoints.clear(); - elementCursor=0; + _elementCursor=0; } -TrajectoryPoint* Frame::getNextElement(){ -/* - TrajectoryPoint* res; - if(framePoints.empty()) { - return NULL; - } - else{ - res= framePoints.front(); - // dont delete the elements..... - framePoints.erase(framePoints.begin()); - return res; - } -*/ - - - - //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; - } - - if(elementCursor>=framePoints.size()) { - return NULL; +FrameElement* Frame::getNextElement() +{ + if(_elementCursor>=_framePoints.size()) { + return NULL; - }else{ - return framePoints.at(elementCursor++); - } -//next test + }else{ + return _framePoints.at(_elementCursor++); + } + //next test } -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"); - +/* +vtkPolyData* Frame::GetPolyData(bool is_ellipse) +{ VTK_CREATE (vtkPoints, points); VTK_CREATE (vtkFloatArray, colors); VTK_CREATE (vtkFloatArray, tensors); - VTK_CREATE (vtkIntArray, labels); colors->SetName("color"); colors->SetNumberOfComponents(1); @@ -157,39 +114,44 @@ vtkPolyData* Frame::GetPolyData() { tensors->SetName("tensors"); tensors->SetNumberOfComponents(9); - 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]; + double color; + _framePoints[i]->GetPos(pos); //pos[2]=90; + _framePoints[i]->GetOrientation(rot); + _framePoints[i]->GetColor(&color); + _framePoints[i]->GetRadius(rad); - framePoints[i]->getPos(pos); //pos[2]=90; - points->InsertNextPoint(pos); - labels->InsertNextValue(framePoints[i]->getIndex()+1); - - double data[7]; - framePoints[i]->getEllipse(data); + //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; - //framePoints[i]->GetRadius(rad); - rad[0]=data[3]/30; - rad[1]=data[4]/30; - rad[2]=30.0/120.0; + } - //rad[0]=1; - //rad[1]=1; - //rad[2]=1.0; + points->InsertNextPoint(pos); - rot[0]=vtkMath::RadiansFromDegrees(0.0); - rot[1]=vtkMath::RadiansFromDegrees(0.0); - rot[2]=vtkMath::RadiansFromDegrees(data[5]); + rot[2]=vtkMath::RadiansFromDegrees(rot[2]); //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,30 +169,28 @@ 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); @@ -242,26 +202,216 @@ vtkPolyData* Frame::GetPolyData() { _polydata->GetPointData()->SetActiveTensors("tensors"); - // setting the labels - _polydata->GetPointData()->AddArray(labels); - //_polydata->GetPointData()->set + return _polydata; +} +*/ - //labels - //_polydataLabels->SetPoints(points); +void Frame::ComputePolyData() +{ + ComputePolyData2D(); + ComputePolyData3D(); +} - return _polydata; +void Frame::ComputePolyData2D() +{ + 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); + + rad[0]/=30;rad[1]/=30;rad[2]/=120; + 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]}}; + + + //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 + _polydata2D->SetPoints(points); + _polydata2D->GetPointData()->AddArray(colors); + _polydata2D->GetPointData()->SetActiveScalars("color"); + + // setting the scaling and rotation + _polydata2D->GetPointData()->SetTensors(tensors); + _polydata2D->GetPointData()->SetActiveTensors("tensors"); +} + +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]}}; + + + //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 + _polydata3D->SetPoints(points); + _polydata3D->GetPointData()->AddArray(colors); + _polydata3D->GetPointData()->SetActiveScalars("color"); + + // setting the scaling and rotation + _polydata3D->GetPointData()->SetTensors(tensors); + _polydata3D->GetPointData()->SetActiveTensors("tensors"); } -vtkPolyData *Frame::GetPolyDataLabels() + +vtkPolyData* Frame::GetPolyData2D() { - return _polydataLabels; + return _polydata2D; } -unsigned int Frame::getElementCursor(){ +vtkPolyData* Frame::GetPolyData3D() +{ + return _polydata3D; +} - 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..0236f668458302a3a53225bcea937a2c9d6bfe17 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -32,7 +32,7 @@ #ifndef Frame_H_ #define Frame_H_ -class TrajectoryPoint; +class FrameElement; class vtkPolyData; class Frame { @@ -41,13 +41,19 @@ public: 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(); + + ///compute the polydata. + ///Call this after all elements have been added. + void ComputePolyData(); + void ComputePolyData2D(); + void ComputePolyData3D(); int getSize(); @@ -55,23 +61,22 @@ public: void resetCursor(); - vtkPolyData* GetPolyData(); - - vtkPolyData* GetPolyDataLabels(); + //vtkPolyData *GetPolyData(bool is_ellipse=true); - vtkPolyData* GetSclarData(); + vtkPolyData *GetSclarData(); -private: - std::vector <TrajectoryPoint *> framePoints; + vtkPolyData *GetPolyData3D(); - /// ellipse parameters - vtkPolyData * _polydata; + vtkPolyData *GetPolyData2D(); - /// 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 001e4d01f4a1fac4235a684b71bf8f8c12a7f5be..4575b2e7985495b6fd6aeebaa4beefc24758128d 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -328,12 +328,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( 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..e9748b8e78cd3580dee20b88360ae9019921d9dd 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" @@ -472,17 +473,30 @@ 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); +// 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") { @@ -556,7 +570,10 @@ bool SaxParser::endElement(const QString & /* namespaceURI */, //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(); diff --git a/src/SaxParser.h b/src/SaxParser.h index a4ae9edd73f936ecb670cd8f5924aa1a9f5d4714..14699cd8a46b1d7dbb20065c3bbee4c815c2bf05 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; @@ -85,7 +86,8 @@ private: QStringList initialPedestriansColors; QStringList initialPedestriansHeights; std::vector<JPoint *> currentPointsList; - std::vector<TrajectoryPoint *> currentFrame; + std::vector<FrameElement *> currentFrame; + //std::vector<TrajectoryPoint *> currentFrame; bool parsingWalls; //wall and door parameters diff --git a/src/ThreadDataTransfert.cpp b/src/ThreadDataTransfert.cpp index 2a4251cd63d99fc5efec9485ffc8f4f137d18727..8b34b435d59f2815fd615076a1fe59c7cc1315dc 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" @@ -310,13 +310,15 @@ void ThreadDataTransfer::parseDataNode(QDomNodeList frames){ 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 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 diff --git a/src/ThreadVisualisation.cpp b/src/ThreadVisualisation.cpp index 66aaf5fff2a9fc71b7b9f3ee5b6923cefbd81131..1e89378ffa68d1c4fd931a50cf02accb80d2b8e5 100644 --- a/src/ThreadVisualisation.cpp +++ b/src/ThreadVisualisation.cpp @@ -67,6 +67,8 @@ #include <vtkRegularPolygonSource.h> #include <vtkLabeledDataMapper.h> #include <vtkDiskSource.h> +#include <vtkTriangleFilter.h> +#include <vtkStripper.h> #include "geometry/FacilityGeometry.h" @@ -158,7 +160,8 @@ void ThreadVisualisation::run(){ //initialize the datasets init(); - initGlyphs(); + initGlyphs2D(); + initGlyphs3D(); // add axis //axis= vtkAxesActor::New(); @@ -277,32 +280,7 @@ 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 if(SystemSettings::get2D()){ @@ -310,6 +288,7 @@ void ThreadVisualisation::run(){ renderer->GetActiveCamera()->ParallelProjectionOn(); renderer->ResetCamera(); } + //renderer->GetActiveCamera()->Print(cout); if(0){//save the actual camera settings vtkCamera *Camera = renderer->GetActiveCamera(); @@ -359,7 +338,7 @@ void ThreadVisualisation::run(){ //renderer->GetActiveCamera()->SetRoll(90); //renderer->GetRenderers()->GetFirstRenderer()->GetActiveCamera(); Pedestrian::setCamera(renderer->GetActiveCamera()); - renderer->ResetCamera(); + renderer->ResetCamera(); // just a workaround @@ -428,74 +407,108 @@ void ThreadVisualisation::showDoors(bool status){ } } -void ThreadVisualisation::initGlyphs(){ +void ThreadVisualisation::initGlyphs2D() +{ + // //VTK_CREATE (vtkSphereSource, agentShape); + // //agentShape->SetRadius(30); + // //agentShape->SetPhiResolution(20); + // //agentShape->SetThetaResolution(20); + // //now create the glyphs with ellipses + // VTK_CREATE (vtkDiskSource, agentShape); + // agentShape->SetCircumferentialResolution(20); + // agentShape->SetInnerRadius(0); + // agentShape->SetOuterRadius(30); - //VTK_CREATE (vtkSphereSource, agentShape); - //agentShape->SetRadius(30); - //agentShape->SetPhiResolution(20); - //agentShape->SetThetaResolution(20); + // extern_glyphs_pedestrians->SetSourceConnection(agentShape->GetOutputPort()); - //now create the glyphs with ellipses - VTK_CREATE (vtkDiskSource, agentShape); - agentShape->SetCircumferentialResolution(20); - agentShape->SetInnerRadius(0); - agentShape->SetOuterRadius(30); + //#if VTK_MAJOR_VERSION <= 5 + // extern_glyphs_pedestrians->SetSource(agentShape->GetOutput()); + //#else + // extern_glyphs_pedestrians->SetInputConnection(agentShape->GetOutputPort()); + //#endif - 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 + // extern_glyphs_pedestrians->ThreeGlyphsOff(); + // extern_glyphs_pedestrians->ExtractEigenvaluesOff(); + // //extern_glyphs_pedestrians->SetColorModeToScalars(); + // //extern_glyphs_pedestrians->SetScaleModeToDataScalingOff(); + // //extern_glyphs_pedestrians->Update(); -/* - VTK_CREATE (vtkCylinderSource, agentShape); - agentShape->SetHeight(160); + + // VTK_CREATE(vtkPolyDataMapper, mapper); + // mapper->SetInputConnection(extern_glyphs_pedestrians->GetOutputPort()); + + // 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); + + + //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); + //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(); + + extern_glyphs_pedestrians->SetSourceConnection(strip->GetOutputPort()); + //_agents2D->SetSourceConnection(agentShape->GetOutputPort()); #if VTK_MAJOR_VERSION <= 5 - extern_glyphs_pedestrians->SetSource(cylinderSource->GetOutput()); + extern_glyphs_pedestrians->SetSource(agentShape->GetOutput()); #else - extern_glyphs_pedestrians->SetSourceConnection(cylinderSource->GetOutputPort()); - extern_glyphs_pedestrians->SetInputConnection(cylinderSource->GetOutputPort()); + extern_glyphs_pedestrians->SetInputConnection(agentShape->GetOutputPort()); #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); + VTK_CREATE(vtkActor, actor); + actor->SetMapper(mapper); + actor->GetProperty()->BackfaceCullingOn(); + renderer->AddActor(actor); // structure for the labels VTK_CREATE(vtkLabeledDataMapper, labelMapper); @@ -506,254 +519,317 @@ 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); - - } - } - - //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){ +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()); +*/ - Frame * frame = extern_trajectories_thirdSet.getNextFrame(); - extern_pedestrians_thirdSet =(Pedestrian **)malloc(numOfAgents3*sizeof(Pedestrian*)); - for(int i=0;i<numOfAgents3;i++){ + extern_glyphs_pedestrians_3D->SetSourceConnection(agentShape->GetOutputPort()); - // 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()); +#if VTK_MAJOR_VERSION <= 5 + extern_glyphs_pedestrians_3D->SetSource(agentShape->GetOutput()); +#else + extern_glyphs_pedestrians_3D->SetInputConnection(agentShape->GetOutputPort()); +#endif - } + extern_glyphs_pedestrians_3D->ThreeGlyphsOff(); + extern_glyphs_pedestrians_3D->ExtractEigenvaluesOff(); + + VTK_CREATE(vtkPolyDataMapper, mapper); + mapper->SetInputConnection(extern_glyphs_pedestrians_3D->GetOutputPort()); + mapper->GlobalImmediateModeRenderingOn(); + + 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); +} - } +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()); + +// } + +// } } @@ -964,15 +1040,9 @@ 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 + case 1: //TOP oder RESET { vtkCamera *camera = renderer->GetActiveCamera(); diff --git a/src/ThreadVisualisation.h b/src/ThreadVisualisation.h index cdbb94c15e60830baa855acc2f1a2d92a1578ffb..3949e62d632da904d27cc103bad74aaa7291cfde 100644 --- a/src/ThreadVisualisation.h +++ b/src/ThreadVisualisation.h @@ -66,6 +66,7 @@ extern Pedestrian** extern_pedestrians_thirdSet; //extern vtkSmartPointer<vtkGlyph3D> extern_glyphs_pedestrians; extern vtkSmartPointer<vtkTensorGlyph> extern_glyphs_pedestrians; +extern vtkSmartPointer<vtkTensorGlyph> extern_glyphs_pedestrians_3D; extern SyncData extern_trajectories_firstSet; extern SyncData extern_trajectories_secondSet; @@ -85,8 +86,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 @@ -156,7 +155,10 @@ private: void init(); /// initialize the datasets - void initGlyphs(); + void initGlyphs2D(); + + //initialize the 3D agents + void initGlyphs3D(); //finalize the datasets void finalize(); diff --git a/src/TimerCallback.cpp b/src/TimerCallback.cpp index a98f4317e2f8a2cd4fa2a0bbcc250fe7cb8dfea3..108f837e99462e388c6f3cdbaaf0ed468830a837 100644 --- a/src/TimerCallback.cpp +++ b/src/TimerCallback.cpp @@ -115,7 +115,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) { @@ -144,115 +143,43 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId, else frame = extern_trajectories_firstSet.getNextFrame(); - if(frame==NULL){ + if(frame==NULL) + { - }else{ + } + 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 - } - //CAUTION: reset the fucking counter - frame->resetCursor(); - } - } int* winSize=renderWindow->GetSize(); static int lastWinX=winSize[0]+1; // +1 to trigger a first change @@ -510,66 +437,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; - - } } diff --git a/src/TimerCallback.h b/src/TimerCallback.h index d2c3bfac535b346b0bbe83a0794e1383738bb58f..f1e76f7f91e8352eb6454ecf5260ca8608adeb5c 100644 --- a/src/TimerCallback.h +++ b/src/TimerCallback.h @@ -83,6 +83,7 @@ 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 SyncData extern_trajectories_firstSet; diff --git a/src/extern_var.h b/src/extern_var.h index 67e57693f337955fd257c7e8d47150a9c04ec77a..172bbd3ef56356942cc95fab0f2afd2b55de2846 100644 --- a/src/extern_var.h +++ b/src/extern_var.h @@ -81,9 +81,10 @@ Pedestrian** extern_pedestrians_secondSet=NULL; Pedestrian** extern_pedestrians_thirdSet=NULL; -//VTK_CREATE (vtkGlyph3D, extern_glyphs_pedestrians); VTK_CREATE (vtkTensorGlyph, extern_glyphs_pedestrians); +VTK_CREATE (vtkTensorGlyph, extern_glyphs_pedestrians_3D); + VTK_CREATE (vtkActor2D, extern_pedestrians_labels);