diff --git a/src/Frame.cpp b/src/Frame.cpp index fe3eee6fb0c3c4587822d8ee51b1d604b2993a84..481c1e3e08b1355fb7d3fe2df1d8c431b6a34d66 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -35,9 +35,18 @@ #include "TrajectoryPoint.h" #include "Frame.h" +#include <vtkPolyData.h> +#include <vtkSmartPointer.h> +#include <vtkFloatArray.h> +#include <vtkPointData.h> + + +#define VTK_CREATE(type, name) \ + vtkSmartPointer<type> name = vtkSmartPointer<type>::New() Frame::Frame() { elementCursor=0; + _polydata = vtkPolyData::New(); } Frame::~Frame() { @@ -46,6 +55,8 @@ Frame::~Frame() { framePoints.pop_back(); } framePoints.clear(); + + _polydata->Delete(); } int Frame::getSize(){ @@ -95,9 +106,36 @@ TrajectoryPoint* Frame::getNextElement(){ }else{ return framePoints.at(elementCursor++); } - +//next test } +vtkPolyData* Frame::GetPolyData() { + + VTK_CREATE (vtkPoints, points); + VTK_CREATE (vtkFloatArray, colors); + colors->SetName("color"); + 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); + 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"); + return _polydata; +} unsigned int Frame::getElementCursor(){ diff --git a/src/Frame.h b/src/Frame.h index daea38d0430c9555490b67a8737c5e0ba51490b4..55101be6ed7131229c24a4c3a6c50a2e2379e93d 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -33,6 +33,7 @@ #define Frame_H_ class TrajectoryPoint; +class vtkPolyData; class Frame { public: @@ -54,10 +55,15 @@ public: void resetCursor(); + vtkPolyData* GetPolyData(); + + vtkPolyData* GetSclarData(); private: std::vector <TrajectoryPoint *> framePoints; + vtkPolyData * _polydata; + /// points to the actual element in the frame unsigned int elementCursor; }; diff --git a/src/InteractorStyle.cpp b/src/InteractorStyle.cpp index 61fcbb1733af55dd02289070c815cffe6b5982c9..6be369cb60e3b0c2f799c9e1de3efbb1f44989ff 100644 --- a/src/InteractorStyle.cpp +++ b/src/InteractorStyle.cpp @@ -71,7 +71,7 @@ void InteractorStyle::SetSource() { //forward the event only if not in 2d mode void InteractorStyle::Rotate() { - //if(!SystemSettings::get2D()) + if(!SystemSettings::get2D()) vtkInteractorStyleTrackballCamera::Rotate(); } diff --git a/src/SaxParser.cpp b/src/SaxParser.cpp index de2e3b444f29a8490616d70da6752649064ea9e4..aae6141d2679575614a5aa55526391169ca28e99 100644 --- a/src/SaxParser.cpp +++ b/src/SaxParser.cpp @@ -74,7 +74,6 @@ bool SaxParser::startElement(const QString & /* namespaceURI */, const QString & /* localName */, const QString &qName, const QXmlAttributes &at) { - if (qName == "header") { for(int i=0;i<at.length();i++){ if(at.localName(i)=="version") @@ -554,6 +553,7 @@ bool SaxParser::endElement(const QString & /* namespaceURI */, while(!currentFrame.empty()){ frame->addElement(currentFrame.back()); currentFrame.pop_back(); + //cout<<"not adding"<<endl; } dataset->addFrame(frame); @@ -590,12 +590,13 @@ bool SaxParser::attributeDecl(const QString& eName, const QString& aName, void SaxParser::clearPoints(){ - currentPointsList.clear(); +// currentPointsList.clear(); while (!currentPointsList.empty()){ delete currentPointsList.back(); currentPointsList.pop_back(); } + currentPointsList.clear(); return; } @@ -690,7 +691,7 @@ void SaxParser::parseGeometryPG3(QString fileName, FacilityGeometry *geometry){ /// provided for convenience and will be removed in the next version void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QDomNode geo){ - + cout<<"external geometery fouind"<<endl; //creating am empty document // to be filled QDomDocument doc(""); @@ -702,16 +703,22 @@ void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QD QFile file(content); if (!file.open(QIODevice::ReadOnly)) { //slotErrorOutput("could not open the File" ); + cout<<"could not open the File"<<endl; return ; } QString *errorCode = new QString(); if (!doc.setContent(&file, errorCode)) { file.close(); //slotErrorOutput(*errorCode); + cout<<errorCode->toStdString()<<endl; return ; } file.close(); - geoNode =doc.elementsByTagName("geometry").item(0); + geoNode =doc.documentElement().namedItem("geometry"); + + if (geoNode.isNull()){ + cout<<"No geometry information found. <geometry> <geometry/> tag is missing."<<endl; + } } else { @@ -796,7 +803,7 @@ void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QD double x2=points.item(i+1).toElement().attribute("xPos", "0").toDouble(); double y2=points.item(i+1).toElement().attribute("yPos", "0").toDouble(); - double z2=points.item(i+1).toElement().attribute("z", "0").toDouble(); + double z2=points.item(i+1).toElement().attribute("zPos", "0").toDouble(); geometry->addDoor(x1, y1, z1, x2, y2,z2,thickness,height,color); } } @@ -875,6 +882,13 @@ 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; + } + if (!file.open(QIODevice::ReadOnly)) { qDebug()<<"could not open the file: "<<filename<<endl; return ; diff --git a/src/SyncData.cpp b/src/SyncData.cpp index 62056fbc6848fe767f2e933834f8732832937a09..af19786306de4e48aae805727de6ebe706b26950 100644 --- a/src/SyncData.cpp +++ b/src/SyncData.cpp @@ -251,6 +251,7 @@ void SyncData::setFrameCursorTo(int position){ int SyncData::getNumberOfAgents() { + return 0; return numberOfAgents; } diff --git a/src/ThreadVisualisation.cpp b/src/ThreadVisualisation.cpp index 95318e448d08bf117e55b01ee2020e1f273fcddb..a49653f8db8df6cd1e4d0854d4ade6c5928f99db 100644 --- a/src/ThreadVisualisation.cpp +++ b/src/ThreadVisualisation.cpp @@ -142,6 +142,7 @@ void ThreadVisualisation::run(){ //initialize the datasets init(); + initGlyphs(); // add axis axis= vtkAxesActor::New(); @@ -196,19 +197,19 @@ void ThreadVisualisation::run(){ // Create a real circle, not a sphere { -// VTK_CREATE(vtkRegularPolygonSource, polygonSource); -// polygonSource->GeneratePolygonOff(); -// polygonSource->SetNumberOfSides(50); -// polygonSource->SetRadius(700); -// polygonSource->SetCenter(0,0,0); -// polygonSource->Update(); -// -// VTK_CREATE(vtkPolyDataMapper,mapper); -// mapper->SetInputConnection(polygonSource->GetOutputPort()); -// VTK_CREATE(vtkActor,actor); -// actor->GetProperty()->SetColor(180.0/255,180.0/255.0,180.0/255.0); -// actor->SetMapper(mapper); -// renderer->AddActor(actor); + VTK_CREATE(vtkRegularPolygonSource, polygonSource); + polygonSource->GeneratePolygonOff(); + polygonSource->SetNumberOfSides(50); + polygonSource->SetRadius(1000); + polygonSource->SetCenter(0,0,0); + polygonSource->Update(); + + VTK_CREATE(vtkPolyDataMapper,mapper); + mapper->SetInputConnection(polygonSource->GetOutputPort()); + VTK_CREATE(vtkActor,actor); + actor->GetProperty()->SetColor(180.0/255,180.0/255.0,180.0/255.0); + actor->SetMapper(mapper); + //renderer->AddActor(actor); } @@ -425,6 +426,42 @@ void ThreadVisualisation::showDoors(bool status){ } } +void ThreadVisualisation::initGlyphs(){ + + VTK_CREATE (vtkSphereSource, sphereSource); + sphereSource->SetRadius(30); + //sphereSource->SetPhiResolution(20); + //sphereSource->SetThetaResolution(20); + + //extern_glyphs_pedestrians->SetSource(sphereSource->GetOutput()); + extern_glyphs_pedestrians->SetSourceConnection(sphereSource->GetOutputPort()); + extern_glyphs_pedestrians->SetInputConnection(sphereSource->GetOutputPort()); + + extern_glyphs_pedestrians->SetColorModeToColorByScalar(); + extern_glyphs_pedestrians->SetScaleModeToDataScalingOff(); + extern_glyphs_pedestrians->Update(); + + + 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->SetNumberOfTableValues(256); + lut->Build(); + mapper->SetLookupTable(lut); + + VTK_CREATE(vtkActor, actor); + actor->SetMapper(mapper); + renderer->AddActor(actor); +} void ThreadVisualisation::init(){ //get the datasets parameters. diff --git a/src/ThreadVisualisation.h b/src/ThreadVisualisation.h index 67ee074896b4ad02d0fc4e4bd8d041363ddbfa19..5bed3979987093bc2fc403f1f27fcb14c911246a 100644 --- a/src/ThreadVisualisation.h +++ b/src/ThreadVisualisation.h @@ -37,7 +37,9 @@ #include <QThread> #include <QObject> - +#include <vtkGlyph3D.h> +#include <vtkSmartPointer.h> +#include <vtkPolyDataMapper.h> // forwarded classes class QThread; @@ -61,6 +63,8 @@ extern Pedestrian** extern_pedestrians_firstSet; extern Pedestrian** extern_pedestrians_secondSet; extern Pedestrian** extern_pedestrians_thirdSet; +extern vtkSmartPointer<vtkGlyph3D> extern_glyphs_pedestrians; + extern SyncData extern_trajectories_firstSet; extern SyncData extern_trajectories_secondSet; extern SyncData extern_trajectories_thirdSet; @@ -149,6 +153,9 @@ private: /// initialize the datasets void init(); + /// initialize the datasets + void initGlyphs(); + //finalize the datasets void finalize(); diff --git a/src/TimerCallback.cpp b/src/TimerCallback.cpp index 0ce3bd376c52527053b456c40fd28cd80623662c..85d054cc030c0926d774028a2e10a2409c5e9724 100644 --- a/src/TimerCallback.cpp +++ b/src/TimerCallback.cpp @@ -56,6 +56,7 @@ #include <qwaitcondition.h> #include <vtkCommand.h> +#include <vtkPolyData.h> #include <vtkWindowToImageFilter.h> #include <vtkRenderer.h> #include <vtkRendererCollection.h> @@ -67,6 +68,12 @@ #include <vtkTextActor.h> #include <vtkCamera.h> #include <vtkTextProperty.h> +#include <vtkSphereSource.h> +#include <vtkGlyph3D.h> +#include <vtkSmartPointer.h> +#include <vtkPolyDataMapper.h> + + #include "geometry/FacilityGeometry.h" @@ -79,9 +86,11 @@ #include "SystemSettings.h" #include "TimerCallback.h" -//#include <vtkPostScriptWriter.h> +#define VTK_CREATE(type, name) \ + vtkSmartPointer<type> name = vtkSmartPointer<type>::New() using namespace std; + TimerCallback* TimerCallback::New() { TimerCallback *cb = new TimerCallback; @@ -131,6 +140,38 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId, if(frame==NULL){ + }else{ + + frameNumber=extern_trajectories_firstSet.getFrameCursor(); + +#if VTK_MAJOR_VERSION <= 5 + extern_glyphs_pedestrians->SetInput(frame->GetPolyData()); +#else + extern_glyphs_pedestrians->SetInputData(frame->GetPolyData()); +#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 @@ -140,22 +181,6 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId, TrajectoryPoint* point=NULL; while(NULL!=(point=frame->getNextElement())){ -// if(point->getIndex()==152) continue; -// if(point->getIndex()==60) continue; -// if(point->getIndex()==57) continue; -// if(point->getIndex()==9) continue; -// if(point->getIndex()==124) continue; -// if(point->getIndex()==81) continue; -// if(point->getIndex()==55) continue; -// -// if(point->getIndex()==158) continue; -// if(point->getIndex()==192) continue; -// if(point->getIndex()==150) continue; -// if(point->getIndex()==169) continue; -// if(point->getIndex()==113) continue; -// - //if(point->getIndex()==16) continue; - //if(point->getIndex()==17) continue; //point index start at 1. this may needed to be fixed extern_pedestrians_firstSet[point->getIndex()]->moveTo(point); @@ -286,7 +311,7 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId, pAVIWriter=vtkFFMPEGWriter::New(); #endif - pAVIWriter->SetQuality(2);//FIXME 2 is better + pAVIWriter->SetQuality(2); pAVIWriter->SetRate(1000.0/iren->GetTimerDuration(tid)); //static int videoID=0; diff --git a/src/TimerCallback.h b/src/TimerCallback.h index 96a63fb9e84d4f10188a1a545874bda7662e9895..3d975ec6d260e7feae50d798ce03af579007fef2 100644 --- a/src/TimerCallback.h +++ b/src/TimerCallback.h @@ -48,6 +48,9 @@ class vtkFFMPEGWriter; #endif +#include <vtkGlyph3D.h> +#include <vtkSmartPointer.h> +#include <vtkPolyDataMapper.h> class SyncData; class QObject; @@ -76,6 +79,8 @@ extern Pedestrian** extern_pedestrians_firstSet; extern Pedestrian** extern_pedestrians_secondSet; extern Pedestrian** extern_pedestrians_thirdSet; +extern vtkSmartPointer<vtkGlyph3D> extern_glyphs_pedestrians; + extern SyncData extern_trajectories_firstSet; extern SyncData extern_trajectories_secondSet; extern SyncData extern_trajectories_thirdSet; diff --git a/src/TrajectoryPoint.h b/src/TrajectoryPoint.h index 117a7be8ccd3f2666d42b1c5b72069332b462ed9..0714bf3288587c1019d90fbb31bc988b7a4f6cd8 100644 --- a/src/TrajectoryPoint.h +++ b/src/TrajectoryPoint.h @@ -58,13 +58,13 @@ public: * set/get the coordinate of the modelled ellipse. * @param ellipse, the center coordinates and the 2 semi-axes */ - void getEllipse(double ellipse[4]); + void getEllipse(double ellipse[7]); /** * set/get the coordinate of the modelled ellipse. * @param ellipse, the center coordinates , the 2 semi-axes, the color and the orientation */ - void setEllipse(double ellipse[4]); + void setEllipse(double ellipse[7]); /** * set/get other agents infos: the color and the orientation. diff --git a/src/extern_var.h b/src/extern_var.h index 78749d8cdd40b9c6f6d5462f40431925f9d65540..8fa0ee21789959dd024511493122196a9ee4674a 100644 --- a/src/extern_var.h +++ b/src/extern_var.h @@ -33,6 +33,13 @@ #include "SyncData.h" #include "Pedestrian.h" +#include <vtkGlyph3D.h> +#include <vtkSmartPointer.h> +#include <vtkPolyDataMapper.h> + + +#define VTK_CREATE(type, name) \ + vtkSmartPointer<type> name = vtkSmartPointer<type>::New() //external variables /// define the speed/rate/pace at which the trajectories are displayed. @@ -72,6 +79,9 @@ Pedestrian** extern_pedestrians_secondSet=NULL; ///The third pedestrian group Pedestrian** extern_pedestrians_thirdSet=NULL; + +VTK_CREATE (vtkGlyph3D, extern_glyphs_pedestrians); + // and here the corresponding dataset ///The first dataset diff --git a/src/geometry/FacilityGeometry.cpp b/src/geometry/FacilityGeometry.cpp index f7c0259458eb12d1c152a51a74913f4a61afb1a1..1b660f398efe1e1e3c0ee48cbfbdbf0f9ffb3fc9 100644 --- a/src/geometry/FacilityGeometry.cpp +++ b/src/geometry/FacilityGeometry.cpp @@ -570,7 +570,7 @@ vtkActor2DCollection* FacilityGeometry::getCaptions(){ void FacilityGeometry::addNewElementText(double center[3], double orientation[3], string text, double color) { - //return ; + return ; {//caption VTK_CREATE(vtkTextActor3D,caption); diff --git a/src/travisto.cpp b/src/travisto.cpp index 3cf0668525a68bdc92a37f2d0f178291678fc999..4891ec1651a139227fc5698f1a00f40718e0fef4 100644 --- a/src/travisto.cpp +++ b/src/travisto.cpp @@ -564,7 +564,6 @@ bool TraVisTo::addPedestrianGroup(int groupID,QString fileName){ if (fileName.isNull()) { return false; } - //the geometry actor //FacilityGeometry* geometry=NULL; FacilityGeometry* geometry = visualisationThread->getGeometry(); @@ -640,7 +639,7 @@ bool TraVisTo::addPedestrianGroup(int groupID,QString fileName){ QXmlInputSource source(&file); QXmlSimpleReader reader; - // no other geometry format was detected + //no other geometry format was detected if(geometry==NULL) geometry=new FacilityGeometry(); SaxParser handler(geometry,dataset,&frameRate); @@ -648,6 +647,7 @@ bool TraVisTo::addPedestrianGroup(int groupID,QString fileName){ reader.parse(source); file.close(); + QString frameRateStr=QString::number(frameRate); SystemSettings::setFilenamePrefix(QFileInfo ( fileName ).baseName()+"_");