diff --git a/src/Frame.cpp b/src/Frame.cpp index 2cc5a06bbc581b7c8d55827f555657d520a870ce..3d2731d15445640f3ee58ea151dd35ab534b125c 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -39,6 +39,7 @@ #include <vtkSmartPointer.h> #include <vtkFloatArray.h> #include <vtkPointData.h> +#include <vtkMath.h> #define VTK_CREATE(type, name) \ @@ -111,35 +112,133 @@ TrajectoryPoint* Frame::getNextElement(){ 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"); +// 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"); + + + 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]; + double rot[3]; + + framePoints[i]->getPos(pos); //pos[2]=90; + points->InsertNextPoint(pos); + + double data[7]; + framePoints[i]->getEllipse(data); + + + //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; + + rot[0]=vtkMath::RadiansFromDegrees(0.0); + rot[1]=vtkMath::RadiansFromDegrees(0.0); + rot[2]=vtkMath::RadiansFromDegrees(data[5]); + + //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]); + + + //color + if(data[6]==-1){ + colors->InsertNextValue(NAN); + } + else{ + colors->InsertNextValue(data[6]/255.0); + } + + } + + // setting the colors + _polydata->SetPoints(points); + _polydata->GetPointData()->AddArray(colors); + _polydata->GetPointData()->SetActiveScalars("color"); + + // setting the scaling and rotation + _polydata->GetPointData()->SetTensors(tensors); + _polydata->GetPointData()->SetActiveTensors("tensors"); + + +// if(framePoints.size()<0) { +// cout<<"not good"<<endl; +// exit(0); +// } + return _polydata; } diff --git a/src/ThreadVisualisation.cpp b/src/ThreadVisualisation.cpp index 4328d7b9f9a4849a658220023ae180a4fe6f2f18..cb8e47f1857cef03f2578f4511d4aa52923f5e28 100644 --- a/src/ThreadVisualisation.cpp +++ b/src/ThreadVisualisation.cpp @@ -41,6 +41,7 @@ #define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL,vtkRenderingOpenGL) #define vtkRenderingVolume_AUTOINIT 1(vtkRenderingVolumeOpenGL) + #include <vtkRenderer.h> #include <vtkCamera.h> #include <vtkAssembly.h> @@ -58,8 +59,8 @@ #include <vtkLookupTable.h> #include <vtkTextProperty.h> #include <vtkProperty.h> -//#include <vtkMatrix4x4.h> -//#include <vtkHomogeneousTransform.h> +#include <vtkOutputWindow.h> +#include <vtkFileOutputWindow.h> #include <vtkCallbackCommand.h> #include <vtkSmartPointer.h> #include <vtkActor2DCollection.h> @@ -133,6 +134,13 @@ void ThreadVisualisation::slotSetFrameRate(float fps){ void ThreadVisualisation::run(){ + //deactivate the output windows + vtkObject::GlobalWarningDisplayOff(); +// vtkOutputWindow *w = vtkFileOutputWindow::New(); +// w->SetFileName("vtk_errors.txt"); +// vtkOutputWindow::SetInstance(w); +// w->Delete(); // now SetInstance owns the reference + //emit signalStatusMessage("running"); // Create the renderer @@ -434,6 +442,7 @@ void ThreadVisualisation::showDoors(bool status){ void ThreadVisualisation::initGlyphs(){ + VTK_CREATE (vtkSphereSource, sphereSource); sphereSource->SetRadius(30); sphereSource->SetPhiResolution(20); @@ -447,28 +456,37 @@ void ThreadVisualisation::initGlyphs(){ #endif +/* + VTK_CREATE (vtkCylinderSource, cylinderSource); + cylinderSource->SetHeight(160); + cylinderSource->SetRadius(30); - //VTK_CREATE (vtkCylinderSource, cylinderSource); - //cylinderSource->SetHeight(160); - //cylinderSource->SetRadius(30); - //extern_glyphs_pedestrians->SetSourceConnection(cylinderSource->GetOutputPort()); - //extern_glyphs_pedestrians->SetInputConnection(cylinderSource->GetOutputPort()); +#if VTK_MAJOR_VERSION <= 5 + extern_glyphs_pedestrians->SetSource(cylinderSource->GetOutput()); +#else + extern_glyphs_pedestrians->SetSourceConnection(cylinderSource->GetOutputPort()); + extern_glyphs_pedestrians->SetInputConnection(cylinderSource->GetOutputPort()); +#endif +*/ + extern_glyphs_pedestrians->ThreeGlyphsOff(); + extern_glyphs_pedestrians->ExtractEigenvaluesOff(); - extern_glyphs_pedestrians->SetColorModeToColorByScalar(); - extern_glyphs_pedestrians->SetScaleModeToDataScalingOff(); - extern_glyphs_pedestrians->Update(); + //extern_glyphs_pedestrians->SetColorModeToScalars(); + //extern_glyphs_pedestrians->SetScaleModeToDataScalingOff(); + //extern_glyphs_pedestrians->Update(); VTK_CREATE(vtkPolyDataMapper, mapper); mapper->SetInputConnection(extern_glyphs_pedestrians->GetOutputPort()); - mapper->SetScalarModeToUsePointData(); - mapper->ScalarVisibilityOn(); + + //mapper->SetScalarModeToUsePointData(); + //mapper->ScalarVisibilityOn(); //mapper->SelectColorArray("color"); - mapper->ColorByArrayComponent("data", 0); - mapper->SetColorModeToMapScalars(); + //mapper->ColorByArrayComponent("data", 0); + //mapper->SetColorModeToMapScalars(); VTK_CREATE(vtkLookupTable, lut); lut->SetHueRange(0.0,0.470); diff --git a/src/ThreadVisualisation.h b/src/ThreadVisualisation.h index 37f326429936ac8ccf2628116d37f9adc3f0956c..cdbb94c15e60830baa855acc2f1a2d92a1578ffb 100644 --- a/src/ThreadVisualisation.h +++ b/src/ThreadVisualisation.h @@ -64,8 +64,8 @@ extern Pedestrian** extern_pedestrians_firstSet; extern Pedestrian** extern_pedestrians_secondSet; extern Pedestrian** extern_pedestrians_thirdSet; -extern vtkSmartPointer<vtkGlyph3D> extern_glyphs_pedestrians; -//extern vtkSmartPointer<vtkTensorGlyph> extern_glyphs_pedestrians; +//extern vtkSmartPointer<vtkGlyph3D> extern_glyphs_pedestrians; +extern vtkSmartPointer<vtkTensorGlyph> extern_glyphs_pedestrians; extern SyncData extern_trajectories_firstSet; extern SyncData extern_trajectories_secondSet; diff --git a/src/TimerCallback.cpp b/src/TimerCallback.cpp index 4c5b7cdd9bda3e1b6b0437a37969c3448fe5c296..76a5fb42b5c9ff75d91fc723579fba264d0f1234 100644 --- a/src/TimerCallback.cpp +++ b/src/TimerCallback.cpp @@ -73,7 +73,7 @@ #include <vtkCamera.h> #include <vtkTextProperty.h> #include <vtkSphereSource.h> -#include <vtkGlyph3D.h> +//#include <vtkGlyph3D.h> #include <vtkSmartPointer.h> #include <vtkPolyDataMapper.h> @@ -154,7 +154,7 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId, extern_glyphs_pedestrians->SetInputData(frame->GetPolyData()); #endif - extern_glyphs_pedestrians->Update(); + extern_glyphs_pedestrians->Update(); nPeds= frame->getSize(); diff --git a/src/TimerCallback.h b/src/TimerCallback.h index 3d975ec6d260e7feae50d798ce03af579007fef2..ecb8134444936e308a51d814e2f460bd09012dcd 100644 --- a/src/TimerCallback.h +++ b/src/TimerCallback.h @@ -48,7 +48,8 @@ class vtkFFMPEGWriter; #endif -#include <vtkGlyph3D.h> +//#include <vtkGlyph3D.h> +#include <vtkTensorGlyph.h> #include <vtkSmartPointer.h> #include <vtkPolyDataMapper.h> @@ -79,7 +80,8 @@ extern Pedestrian** extern_pedestrians_firstSet; extern Pedestrian** extern_pedestrians_secondSet; extern Pedestrian** extern_pedestrians_thirdSet; -extern vtkSmartPointer<vtkGlyph3D> extern_glyphs_pedestrians; +//extern vtkSmartPointer<vtkGlyph3D> extern_glyphs_pedestrians; +extern vtkSmartPointer<vtkTensorGlyph> extern_glyphs_pedestrians; extern SyncData extern_trajectories_firstSet; extern SyncData extern_trajectories_secondSet; @@ -166,7 +168,7 @@ private: /** - * A callback for windows changes + * A callback for windows changes */ //class WindowCallback: public vtkCommand{ diff --git a/src/extern_var.h b/src/extern_var.h index 0d89eeb03cf0ec52860fa5302ccca28d9e45d0b5..7039792d17851c8d44fb93886ee6ad63cfce7fd2 100644 --- a/src/extern_var.h +++ b/src/extern_var.h @@ -33,7 +33,7 @@ #include "SyncData.h" #include "Pedestrian.h" -#include <vtkGlyph3D.h> +//#include <vtkGlyph3D.h> #include <vtkTensorGlyph.h> #include <vtkSmartPointer.h> #include <vtkPolyDataMapper.h> @@ -81,8 +81,8 @@ Pedestrian** extern_pedestrians_secondSet=NULL; Pedestrian** extern_pedestrians_thirdSet=NULL; -VTK_CREATE (vtkGlyph3D, extern_glyphs_pedestrians); -//VTK_CREATE (vtkTensorGlyph, extern_glyphs_pedestrians); +//VTK_CREATE (vtkGlyph3D, extern_glyphs_pedestrians); +VTK_CREATE (vtkTensorGlyph, extern_glyphs_pedestrians); // and here the corresponding dataset diff --git a/src/main.cpp b/src/main.cpp index 187d6a6b2eb67632a6f19bd418730fcc8a2d42b0..b75ef2010d9073cf1f23921d161c989b0e230edd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,6 +54,9 @@ #include <QApplication> #include "travisto.h" + +#define vtkErrorMacro (x) () + int main(int argc, char *argv[]) { QApplication a(argc, argv);