00001 #ifndef PCL_CLOUD_TOOLS_MISC_H_
00002 #define PCL_CLOUD_TOOLS_MISC_H_
00003
00004 #include <vtkLODActor.h>
00005 #include <vtkProperty.h>
00006 #include <vtkPolyDataReader.h>
00007 #include <vtkMaskPoints.h>
00008 #include <vtkSmartPointer.h>
00009 #include <vtkDataSetMapper.h>
00010
00011 #include <vtkCellArray.h>
00012 #include <vtkLookupTable.h>
00013 #include <vtkScalarBarActor.h>
00014 #include <vtkTextProperty.h>
00015 #include <vtkInteractorStyleTrackballCamera.h>
00016 #include <vtkRendererCollection.h>
00017 #include <vtkPNGWriter.h>
00018 #include <vtkWindowToImageFilter.h>
00019 #include <vtkDataArrayCollection.h>
00020 #include <vtkLegendScaleActor.h>
00021 #include <vtkTextActor.h>
00022 #include <vtkRenderWindow.h>
00023 #include <vtkRenderWindowInteractor.h>
00024 #include <vtkCommand.h>
00025 #include <vtkProperty.h>
00026 #include <vtkProperty2D.h>
00027 #include <vtkPointPicker.h>
00028 #include <vtkObjectFactory.h>
00029 #include <vtkAssemblyPath.h>
00030
00031
00032 #include <vtkGraphicsFactory.h>
00033 #include <vtkGeneralTransform.h>
00034 #include <vtkGeometryFilter.h>
00035 #include <vtkImagingFactory.h>
00036 #include <vtkAbstractTransform.h>
00037 #include <vtkActor.h>
00038 #include <vtkAlgorithmOutput.h>
00039 #include <vtkAppendPolyData.h>
00040 #include <vtkArrowSource.h>
00041 #include <vtkAssemblyPath.h>
00042 #include <vtkAssembly.h>
00043 #include <vtkCubeSource.h>
00044 #include <vtkConeSource.h>
00045 #include <vtkCylindricalTransform.h>
00046 #include <vtkTransformTextureCoords.h>
00047 #include <vtkBMPReader.h>
00048 #include <vtkTexture.h>
00049 #include <vtkAxes.h>
00050 #include <vtkAxisActor2D.h>
00051 #include <vtkButterflySubdivisionFilter.h>
00052 #include <vtkBoxWidget.h>
00053 #include <vtkCamera.h>
00054 #include <vtkCameraInterpolator.h>
00055 #include <vtkCommand.h>
00056 #include <vtkCellData.h>
00057 #include <vtkCellArray.h>
00058 #include <vtkCleanPolyData.h>
00059 #include <vtkClipPolyData.h>
00060 #include <vtkContourFilter.h>
00061 #include <vtkCylinderSource.h>
00062 #include <vtkCutter.h>
00063 #include <vtkDataSetMapper.h>
00064 #include <vtkDataObjectCollection.h>
00065 #include <vtkDiskSource.h>
00066 #include <vtkDataSetTriangleFilter.h>
00067 #include <vtkDataSetWriter.h>
00068 #include <vtkDataSetCollection.h>
00069 #include <vtkDataArrayCollection.h>
00070 #include <vtkDebugLeaks.h>
00071 #include <vtkDelaunay2D.h>
00072 #include <vtkDelaunay3D.h>
00073 #include <vtkDoubleArray.h>
00074 #include <vtkExtractEdges.h>
00075 #include <vtkInteractorEventRecorder.h>
00076 #include <vtkFeatureEdges.h>
00077 #include <vtkFloatArray.h>
00078 #include <vtkFFMPEGWriter.h>
00079 #include <vtkFollower.h>
00080 #include <vtkGenericPointIterator.h>
00081 #include <vtkGlyph3D.h>
00082 #include <vtkGreedyTerrainDecimation.h>
00083 #include <vtkHedgeHog.h>
00084 #include <vtkHull.h>
00085 #include <vtkHexahedron.h>
00086 #include <vtkInterpolatingSubdivisionFilter.h>
00087 #include <vtkImageBlend.h>
00088 #include <vtkImageMapper.h>
00089 #include <vtkImplicitModeller.h>
00090 #include <vtkImplicitPlaneWidget.h>
00091 #include <vtkIntArray.h>
00092 #include <vtkInteractorStyleTrackballCamera.h>
00093 #include <vtkJPEGWriter.h>
00094 #include <vtkKdTree.h>
00095 #include <vtkLightKit.h>
00096 #include <vtkLinearSubdivisionFilter.h>
00097 #include <vtkLegendScaleActor.h>
00098 #include <vtkLeaderActor2D.h>
00099 #include <vtkLineSource.h>
00100 #include <vtkLODActor.h>
00101 #include <vtkLandmarkTransform.h>
00102 #include <vtkLookupTable.h>
00103 #include <vtkLogLookupTable.h>
00104 #include <vtkLoopSubdivisionFilter.h>
00105 #include <vtkMarchingCubes.h>
00106 #include <vtkMaskPoints.h>
00107 #include <vtkMath.h>
00108 #include <vtkMatrix4x4.h>
00109 #include <vtkMatrixToLinearTransform.h>
00110 #include <vtkMassProperties.h>
00111 #include <vtkOBBTree.h>
00112 #include <vtkObjectFactory.h>
00113 #include <vtkOBJReader.h>
00114 #include <vtkOBJExporter.h>
00115 #include <vtkOrderedTriangulator.h>
00116 #include <vtkPerspectiveTransform.h>
00117 #include <vtkPlane.h>
00118 #include <vtkPlanes.h>
00119 #include <vtkPolygon.h>
00120 #include <vtkPlatonicSolidSource.h>
00121 #include <vtkPLYReader.h>
00122 #include <vtkPNGReader.h>
00123 #include <vtkPNGWriter.h>
00124 #include <vtkPlaneSource.h>
00125 #include <vtkSuperquadricSource.h>
00126 #include <vtkSphericalTransform.h>
00127 #include <vtkSubdivideTetra.h>
00128 #include <vtkPointData.h>
00129 #include <vtkPointPicker.h>
00130 #include <vtkPointDataToCellData.h>
00131 #include <vtkPointLocator.h>
00132 #include <vtkPoints.h>
00133 #include <vtkPointSet.h>
00134 #include <vtkPolyData.h>
00135 #include <vtkPolyLine.h>
00136 #include <vtkPolyDataAlgorithm.h>
00137 #include <vtkPolyDataMapper.h>
00138 #include <vtkOpenGLPolyDataMapper.h>
00139 #include <vtkPainterPolyDataMapper.h>
00140 #include <vtkPolyDataNormals.h>
00141 #include <vtkPolyDataReader.h>
00142 #include <vtkPolyDataWriter.h>
00143 #include <vtkPolyVertex.h>
00144 #include <vtkProperty.h>
00145 #include <vtkProperty2D.h>
00146 #include <vtkQuad.h>
00147 #include <vtkRecursiveDividingCubes.h>
00148 #include <vtkRenderWindow.h>
00149 #include <vtkRenderWindowInteractor.h>
00150 #include <vtkRenderer.h>
00151 #include <vtkRendererCollection.h>
00152 #include <vtkScalarBarActor.h>
00153 #include <vtkSmartPointer.h>
00154 #include <vtkSpatialRepresentationFilter.h>
00155 #include <vtkSphere.h>
00156 #include <vtkSphereSource.h>
00157 #include <vtkStripper.h>
00158 #include <vtkStructuredPointsReader.h>
00159 #include <vtkSurfaceReconstructionFilter.h>
00160 #include <vtkSystemIncludes.h>
00161 #include <vtkTextActor.h>
00162 #include <vtkTextProperty.h>
00163 #include <vtkTimerLog.h>
00164 #include <vtkTransform.h>
00165 #include <vtkTransformFilter.h>
00166 #include <vtkTransformPolyDataFilter.h>
00167 #include <vtkTriangleFilter.h>
00168 #include <vtkTubeFilter.h>
00169 #include <vtkUnstructuredGrid.h>
00170 #include <vtkUnstructuredGridReader.h>
00171 #include <vtkUnsignedIntArray.h>
00172 #include <vtkVectorText.h>
00173 #include <vtkVoxel.h>
00174 #include <vtkVoxelContoursToSurfaceFilter.h>
00175 #include <vtkVRMLImporter.h>
00176 #include <vtkWindowedSincPolyDataFilter.h>
00177 #include <vtkWindowToImageFilter.h>
00178 #include <vtkXRenderWindowInteractor.h>
00179 #include <vtkXMLPolyDataReader.h>
00180 #include <vtkXMLPPolyDataReader.h>
00181 #include <vtkXYPlotActor.h>
00182 #include <vtkXYPlotWidget.h>
00183 #include <vtkGraphToPolyData.h>
00184 #include <vtkGraphLayout.h>
00185 #include <vtkGraphReader.h>
00186 #include <vtkGraph.h>
00187 #include <vtkDirectedGraph.h>
00188 #include <vtkUndirectedGraph.h>
00189 #include <vtkMutableUndirectedGraph.h>
00190 #include <vtkPolyDataCollection.h>
00191
00192 #define NR_COLOR 65536
00193 #define S_COLOR 100
00194 #define RENWIN_WIDTH 1200
00195 #define RENWIN_HEIGHT 800
00196 #define _sqr(x) ((x)*(x))
00197 #define _sqr_dist(x,y) ( _sqr((x[0])-(y[0])) + _sqr((x[1])-(y[1])) + _sqr((x[2])-(y[2])) )
00198 #define SPACE_KEY 32
00199 #define KEY_PLUS 43
00200 #define KEY_MINUS 45
00201
00202
00203
00204
00205
00206
00207
00208
00210
00211
00212 vtkPolyData*
00213 load_poly_data_as_data_set (const char* fileName)
00214 {
00215 vtkPolyDataReader* reader = vtkPolyDataReader::New ();
00216 reader->SetFileName (fileName);
00217 reader->Update ();
00218 return reader->GetOutput ();
00219 }
00220
00222
00223 vtkActor* create_actor_from_data_set (vtkDataSet *data, double c1, double c2, double c3, bool lod_enable = false)
00224 {
00225 vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
00226
00227
00228 mapper->SetInput ((vtkPolyData*)data);
00229 mapper->ScalarVisibilityOff ();
00230
00231 vtkActor *actor;
00232 if (lod_enable)
00233 {
00234 vtkSmartPointer<vtkMaskPoints> low_mask = vtkSmartPointer<vtkMaskPoints>::New ();
00235 low_mask->SetMaximumNumberOfPoints (data->GetNumberOfPoints () / 16);
00236 actor = vtkLODActor::New ();
00237 reinterpret_cast<vtkLODActor*>(actor)->SetNumberOfCloudPoints (data->GetNumberOfPoints () / 4);
00238 reinterpret_cast<vtkLODActor*>(actor)->SetLowResFilter (low_mask);
00239 actor->GetProperty ()->SetInterpolationToFlat ();
00240 }
00241 else
00242 {
00243 actor = vtkActor::New ();
00244 actor->GetProperty ()->SetInterpolationToPhong ();
00245
00246 }
00247 actor->GetProperty ()->SetColor (c1, c2, c3);
00248 actor->GetProperty ()->SetAmbientColor (c1, c2, c3);
00249 actor->GetProperty ()->SetSpecularColor (c1, c2, c3);
00250 actor->GetProperty ()->SetAmbient (0.8);
00251 actor->SetMapper (mapper);
00252
00253
00254
00255 return actor;
00256 }
00257
00258 vtkActor*
00259 create_actor_from_data_set (vtkDataSet *data, double c1, double c2, double c3, double psize, bool lod_enable)
00260 {
00261 vtkActor *actor = create_actor_from_data_set (data, c1, c2, c3, lod_enable);
00262 actor->GetProperty ()->SetPointSize (psize);
00263 return actor;
00264 }
00265
00267
00268 vtkActor*
00269 create_actor_from_data_set (vtkDataSet *data, double psize, vtkLookupTable* lut, double minmax[2], bool lod_enable)
00270 {
00271 vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
00272 mapper->SetInput (data);
00273 mapper->SetLookupTable (lut);
00274 mapper->SetScalarRange (minmax);
00275 mapper->SetScalarModeToUsePointData ();
00276 mapper->ScalarVisibilityOn ();
00277
00278 vtkActor *actor;
00279 if (lod_enable)
00280 {
00281 actor = vtkLODActor::New ();
00282 reinterpret_cast<vtkLODActor*>(actor)->SetNumberOfCloudPoints (data->GetNumberOfPoints () / 10);
00283 actor->GetProperty ()->SetInterpolationToFlat ();
00284 }
00285 else
00286 {
00287 actor = vtkActor::New ();
00288
00289 actor->GetProperty ()->SetInterpolationToPhong ();
00290 }
00291 actor->GetProperty()->SetPointSize(psize);
00292 actor->SetMapper (mapper);
00293
00294 return actor;
00295 }
00296
00298
00299 vtkActor*
00300 create_actor_from_data_set (vtkDataSet *data, bool lod_enable)
00301 {
00302 vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
00303 mapper->SetInput (data);
00304 mapper->SetScalarModeToUsePointData ();
00305
00306 mapper->ScalarVisibilityOn ();
00307
00308 vtkActor *actor;
00309 if (lod_enable)
00310 {
00311 actor = vtkLODActor::New ();
00312 reinterpret_cast<vtkLODActor*>(actor)->SetNumberOfCloudPoints (data->GetNumberOfPoints () / 10);
00313 actor->GetProperty ()->SetInterpolationToFlat ();
00314 }
00315 else
00316 {
00317 actor = vtkActor::New ();
00318
00319 actor->GetProperty ()->SetInterpolationToPhong ();
00320 }
00321 actor->SetMapper (mapper);
00322
00323 return actor;
00324 }
00325
00326
00327 vtkActor*
00328 create_actor_from_data_set (vtkDataSet *data, double psize, bool lod_enable)
00329 {
00330 vtkActor *actor = create_actor_from_data_set (data, lod_enable);
00331 actor->GetProperty ()->SetPointSize (psize);
00332 return actor;
00333 }
00334
00336
00338
00339 static unsigned stepRGBA = 100;
00340 inline void
00341 srandRGBA (unsigned seed, unsigned step)
00342 {
00343 srand (seed);
00344 stepRGBA = step;
00345 }
00346
00347 inline double*
00348 randRGBA1 (double min=0.2, double max=2.8)
00349 {
00350 double* rgba = new double[4];
00351 double sum;
00352 do
00353 {
00354 sum = 0;
00355 rgba[0] = (rand ()%stepRGBA) / (double)stepRGBA;
00356 while ((rgba[1] = (rand ()%stepRGBA) / (double)stepRGBA) == rgba[0]);
00357 while (((rgba[2] = (rand ()%stepRGBA) / (double)stepRGBA) == rgba[0]) && (rgba[2] == rgba[1]));
00358 sum = rgba[0] + rgba[1] + rgba[2];
00359 } while (sum <= min || sum >= max);
00360 rgba[3] = 1.0;
00361
00362 return rgba;
00363 }
00364
00366
00367 vtkSmartPointer<vtkLookupTable>
00368 create_LUT (double minmax[2], int log, int seed_rand, int nr_colors, unsigned step_rand, bool debug)
00369 {
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383 vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New ();
00384 lut->SetScaleToLinear ();
00385 lut->SetRampToLinear ();
00386
00387 lut->SetNumberOfTableValues (nr_colors);
00388 if (seed_rand >= 0)
00389 {
00390 srandRGBA ((unsigned)seed_rand, step_rand);
00391 for (vtkIdType i=0; i<nr_colors; i++)
00392 lut->SetTableValue (i, randRGBA1 ());
00393 }
00394 if (log != 0)
00395 lut->SetScaleToLog10 ();
00396
00397 lut->SetRange (minmax);
00398 lut->Build ();
00399 return lut;
00400 }
00401
00403
00404 vtkSmartPointer<vtkLookupTable>
00405 create_LUT (double minmax[2], int argc, char** argv)
00406 {
00407 int log = 0; terminal_tools::parse_argument (argc, argv, "-log", log);
00408 int nr_colors = NR_COLOR; terminal_tools::parse_argument (argc, argv, "-nrRGBcolors", nr_colors);
00409 int step_rand = S_COLOR; terminal_tools::parse_argument (argc, argv, "-randRGBstep", step_rand);
00410 int seed_rand = -1; terminal_tools::parse_argument (argc, argv, "-randRGBseed", seed_rand);
00412 terminal_tools::parse_2x_arguments (argc, argv, "-lut_limits", minmax[0], minmax[1]);
00413 return create_LUT (minmax, log, seed_rand, nr_colors, (unsigned)step_rand, false);
00414 }
00415
00417
00418
00419 vtkScalarBarActor*
00420 create_scalar_bar_actor (vtkLookupTable *lut, int argc, char** argv)
00421 {
00422
00423 vtkScalarBarActor *barActor = vtkScalarBarActor::New ();
00424 barActor->SetLookupTable (lut);
00425 barActor->SetTitle ("");
00426 barActor->SetOrientationToHorizontal ();
00427 barActor->SetPosition (0.05, 0.01);
00428
00429 int nr_labels = barActor->GetNumberOfLabels ();
00430 terminal_tools::parse_argument (argc, argv, "-nr_bar_labels", nr_labels);
00431 barActor->SetNumberOfLabels (nr_labels);
00432
00433 barActor->SetWidth (0.9); barActor->SetHeight (0.1);
00434 vtkTextProperty *prop = barActor->GetLabelTextProperty ();
00435 prop->SetFontSize (10);
00436 barActor->SetLabelTextProperty (prop);
00437 barActor->SetTitleTextProperty (prop);
00438
00439 return barActor;
00440 }
00441
00442 struct ScalarsContainer
00443 {
00444 vtkDataArrayCollection* scalars;
00445 std::vector<double> minScalar;
00446 std::vector<double> maxScalar;
00447 std::vector<std::string> dimensions;
00448
00449 vtkActor* actor;
00450
00451
00452 vtkDoubleArray* histogram;
00453 };
00454
00455
00457
00459 class vtkInteractorStyleTUM : public vtkInteractorStyleTrackballCamera
00460 {
00461 public:
00462 static vtkInteractorStyleTUM *New ();
00463 void OnChar ();
00464 void OnTimer ();
00465 void setRenderer (vtkRenderer* ren);
00466 vtkRenderer* getRenderer () { return this->renderer; }
00467 void setRendererCollection (vtkRendererCollection* rencol);
00468 void setWriter (vtkPNGWriter* w) { this->writer = w; }
00469 void setWindowFilter (vtkWindowToImageFilter *f) { this->filter = f; }
00470 vtkWindowToImageFilter* getWindowFilter () { return this->filter; }
00471
00472 void ZoomIn ();
00473 void ZoomOut ();
00474
00475 void setAdvancedMode (bool mode);
00476 std::vector<ScalarsContainer> allScalars;
00477
00478 void setHistogramNrBins (unsigned int nr_bins)
00479 { this->histNrBins = nr_bins; terminal_tools::print_info (stderr, "Number of histogram bins used: "); terminal_tools::print_value (stderr, "%d\n", this->histNrBins); };
00480
00481 void setTextsList (std::vector<std::string> texts) { this->textList = texts; };
00482 std::vector<std::string> getTextsList () { return this->textList; };
00483
00484 void setTextsProp (double x, double y, double s) { this->tAx = x; this->tAy = y; this->tS = s; };
00485 void setTextsColor (double r, double g, double b) { this->tR = r; this->tG = g; this->tB = b; };
00486
00487 protected:
00488 vtkRenderer *renderer;
00489 vtkRendererCollection *rendererCollection;
00490 bool one_renderer;
00491 int pointsize;
00492 public:
00493 vtkPNGWriter* writer;
00494 vtkWindowToImageFilter *filter;
00495 protected:
00496 char fileName[80];
00497 char camFN[80];
00498
00499 bool advanced;
00500 vtkLegendScaleActor* gridActor;
00501 vtkScalarBarActor* lutActor;
00502 bool grid_enabled, lut_enabled;
00503
00504 public:
00505 unsigned int histNrBins;
00506
00507 private:
00508
00509 std::vector<std::string> textList;
00510 vtkTextActor* textActor;
00511 float tAx, tAy, tS;
00512 float tR, tG, tB;
00513 bool texts_enabled;
00514 int cur_text;
00515
00516 public:
00517 int argc;
00518 char** argv;
00519 };
00520
00521
00522 class vtkCameraCallback : public vtkCommand
00523 {
00524 public:
00525 static vtkCameraCallback *New () { return new vtkCameraCallback;}
00526 void SetTextActor (vtkTextActor *txt);
00527 virtual void Execute (vtkObject *caller, unsigned long, void*);
00528 protected:
00529 vtkTextActor *camTextActor;
00530 };
00531
00533
00535 void
00536 vtkCameraCallback::SetTextActor (vtkTextActor *txt)
00537 {
00538 this->camTextActor = txt;
00539 }
00540 void
00541 vtkCameraCallback::Execute (vtkObject *caller, unsigned long, void*)
00542 {
00543 vtkRenderer *ren = reinterpret_cast<vtkRenderer *> (caller);
00544 vtkCamera *cam = ren->GetActiveCamera ();
00545 double eye[3], up[3], viewray[3];
00546 cam->GetPosition (eye);
00547 cam->GetViewUp (up);
00548 cam->GetDirectionOfProjection (viewray);
00549
00550 char camTextBuff[256];
00551 snprintf (camTextBuff, 255, "Position: %.3g,%.3g,%.3g ; ViewUp: %.3g,%.3g,%.3g ; Direction Of Projection %.3g,%.3g,%.3g", eye[0], eye[1], eye[2], up[0], up[1], up[2], viewray[0], viewray[1], viewray[2]);
00552
00553 }
00554
00556
00558 class vtkMouseCallback : public vtkCommand
00559 {
00560 public:
00561 static vtkMouseCallback *New () { return new vtkMouseCallback; }
00562
00563 virtual void
00564 Execute (vtkObject *caller, unsigned long eventid, void*)
00565 {
00566 vtkInteractorStyleTUM *style = reinterpret_cast<vtkInteractorStyleTUM*>(caller);
00567 vtkRenderWindowInteractor* iren = style->GetInteractor ();
00568 vtkRenderer* ren_main = iren->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ();
00569
00570 if ((eventid == vtkCommand::LeftButtonPressEvent) && (iren->GetShiftKey () == 1))
00571 {
00572 int idx = PerformPick (iren);
00573 if (idx < 0)
00574 return;
00575
00576 if ((iren->GetControlKey () == 1) && (style->allScalars.size () > 0))
00577 {
00578
00579 char text[10];
00580 sprintf (text, "%d", idx);
00581 vtkVectorText *atext = vtkVectorText::New ();
00582 atext->SetText (text);
00583
00584
00585 double tr = 1.0, tg = 1.0 , tb = 1.0;
00586 terminal_tools::parse_3x_arguments (style->argc, style->argv, "-texts_color", tr, tg, tb);
00587 double index_scale = 0.001;
00588 terminal_tools::parse_argument (style->argc, style->argv, "-index_scale", index_scale);
00589 vtkPolyDataMapper *textMapper = vtkPolyDataMapper::New ();
00590 textMapper->SetInputConnection (atext->GetOutputPort ());
00591 vtkFollower *textActor = vtkFollower::New ();
00592 textActor->SetMapper (textMapper);
00593 textActor->SetScale (index_scale);
00594 textActor->SetPosition (pt[0], pt[1], pt[2]);
00595 textActor->GetProperty ()->SetColor (tr, tg, tb);
00596 textActor->SetCamera (ren_main->GetActiveCamera ());
00597 ren_main->AddActor (textActor);
00598 ren_main->Render ();
00599
00600
00601 ScalarsContainer s = style->allScalars[0];
00602
00603 cerr << " -> Dimensions: ";
00604 vtkDataArrayCollection* scalars = s.scalars;
00605 for (unsigned int d = 0; d < s.dimensions.size (); d++)
00606 {
00607 vtkDataArray *scalar = scalars->GetItem (d);
00608 double value[1];
00609 scalar->GetTuple (idx, value);
00610 cerr << s.dimensions.at (d).c_str () << " = " << value[0] << " ";
00611 }
00612 cerr << endl;
00613
00614
00615 if ((s.histogram != NULL) && (style->histNrBins > 0))
00616 {
00617
00618 double hist[style->histNrBins ];
00619 s.histogram->GetTuple (idx, hist);
00620
00621 cerr << " -> Feature Histogram: ";
00622 for (unsigned int d = 0; d < style->histNrBins; d++)
00623 {
00624 cerr << hist[d] << " ";
00625 }
00626 cerr << endl;
00627 vtkSmartPointer<vtkXYPlotActor> xyplot = vtkSmartPointer<vtkXYPlotActor>::New ();
00628 xyplot->SetDataObjectPlotModeToColumns ();
00629 xyplot->SetXValuesToValue ();
00630
00631 vtkSmartPointer<vtkDoubleArray> XYarray = vtkSmartPointer<vtkDoubleArray>::New ();
00632 XYarray->SetNumberOfComponents (2);
00633 XYarray->SetNumberOfTuples (style->histNrBins);
00634
00635
00636 for (unsigned int d = 0; d < style->histNrBins; d++)
00637 {
00638 double xy[2];
00639 xy[0] = d;
00640 xy[1] = hist[d];
00641 if (xy[1] > 99.99)
00642 xy[1] = 99.99;
00643 XYarray->SetTuple (d, xy);
00644 }
00645
00646 vtkSmartPointer<vtkFieldData> fieldValues = vtkSmartPointer<vtkFieldData>::New ();
00647 fieldValues->AddArray (XYarray);
00648 vtkSmartPointer<vtkDataObject> data = vtkSmartPointer<vtkDataObject>::New ();
00649 data->SetFieldData (fieldValues);
00650
00651 xyplot->AddDataObjectInput (data);
00652
00653 xyplot->SetPlotColor (0, 1.0, 0.0, 0.0);
00654
00655 xyplot->SetDataObjectXComponent (0, 0); xyplot->SetDataObjectYComponent (0, 1);
00656 xyplot->PlotPointsOn ();
00657
00658
00659 xyplot->PlotCurveLinesOn ();
00660
00661 char title[128];
00662 sprintf (title, "Feature Histogram for point %d", idx);
00663 xyplot->SetYTitle (""); xyplot->SetXTitle ("");
00664 xyplot->SetYRange (0, 100); xyplot->SetXRange (0, style->histNrBins - 1);
00665
00666 xyplot->GetProperty ()->SetColor (0, 0, 0);
00667 vtkSmartPointer<vtkTextProperty> tprop = xyplot->GetTitleTextProperty ();
00668 xyplot->AdjustTitlePositionOn ();
00669 tprop->SetFontSize (8);
00670 tprop->ShadowOff (); tprop->ItalicOff ();
00671 tprop->SetColor (xyplot->GetProperty ()->GetColor ());
00672
00673 xyplot->SetAxisLabelTextProperty (tprop);
00674 xyplot->SetAxisTitleTextProperty (tprop);
00675 xyplot->SetNumberOfXLabels (8);
00676 xyplot->GetProperty ()->SetPointSize (10);
00677 xyplot->GetProperty ()->SetLineWidth (4);
00678
00679 xyplot->SetPosition (0, 0);
00680 xyplot->SetWidth (1); xyplot->SetHeight (1);
00681
00682 vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New ();
00683 ren->AddActor2D (xyplot);
00684 ren->SetBackground (1, 1, 1);
00685
00686 vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New ();
00687 renWin->SetWindowName (title);
00688 renWin->AddRenderer (ren);
00689 renWin->SetSize (640, 240);
00690 renWin->SetBorders (1);
00691
00692
00693 vtkRenderWindowInteractor *iren = renWin->MakeRenderWindowInteractor ();
00694 iren->Start ();
00695 }
00696 }
00697 }
00698 else if ((eventid == vtkCommand::LeftButtonPressEvent) && (iren->GetAltKey () == 1))
00699 {
00700 pick_first = !pick_first;
00701 if (pick_first)
00702 idx_1 = PerformPick (iren, point_1);
00703 else
00704 idx_2 = PerformPick (iren, point_2);
00705
00706 if ((idx_1 > 0) && (idx_2 > 0))
00707 {
00708 double dist = sqrt (_sqr_dist (point_1, point_2));
00709 cerr << "Distance between " << idx_1 << ": [" << point_1[0] << ", " << point_1[1] << ", " << point_1[2] << "] and " <<
00710 idx_2 << ": [" << point_2[0] << ", " << point_2[1] << ", " << point_2[2] << "] is: " << dist << endl;
00711
00712 vtkLeaderActor2D *leader = vtkLeaderActor2D::New ();
00713 leader->GetPositionCoordinate ()->SetCoordinateSystemToWorld ();
00714 leader->GetPositionCoordinate ()->SetValue (point_1[0], point_1[1], point_1[2]);
00715 leader->GetPosition2Coordinate ()->SetCoordinateSystemToWorld ();
00716 leader->GetPosition2Coordinate ()->SetValue (point_2[0], point_2[1], point_2[2]);
00717 leader->SetArrowStyleToFilled ();
00718 leader->AutoLabelOn ();
00719
00720 vtkRenderWindow* renWin = iren->GetRenderWindow ();
00721 vtkRendererCollection *coll = renWin->GetRenderers ();
00722 coll->GetFirstRenderer ()->AddActor (leader);
00723 renWin->Render ();
00724 }
00725 }
00726 else
00727 {
00728 reinterpret_cast<vtkInteractorStyle*>(caller)->OnLeftButtonDown ();
00729 }
00730 }
00731
00732 public:
00733
00734 int idx_1, idx_2;
00735
00736 bool pick_first;
00737
00738 private:
00739
00740 int
00741 PerformPick (vtkRenderWindowInteractor *iren)
00742 {
00743 int mouse_x, mouse_y;
00744
00745 cerr.precision (10);
00746
00747
00748 vtkPointPicker *picker = (vtkPointPicker*) iren->GetPicker ();
00749 iren->GetMousePosition (&mouse_x, &mouse_y);
00750
00751 vtkRenderWindow* renWin = iren->GetRenderWindow ();
00752 vtkRendererCollection *coll = renWin->GetRenderers ();
00753
00754 iren->StartPickCallback ();
00755
00756 picker->Pick (mouse_x, mouse_y, 0.0, coll->GetFirstRenderer ());
00757 idx = picker->GetPointId ();
00758 cerr << "Picked Point with Index: " << idx;
00759
00760 if (idx < 0)
00761 {
00762 cerr << endl;
00763 return idx;
00764 }
00765
00766 if (picker->GetDataSet () != NULL)
00767 {
00768 picker->GetDataSet ()->GetPoint (idx, pt);
00769 cerr << " [" << pt[0] << ", " << pt[1] << ", " << pt[2] << "]" << endl;
00770 }
00771 else
00772 cerr << endl;
00773 iren->EndPickCallback ();
00774 return idx;
00775 }
00776
00777 int
00778 PerformPick (vtkRenderWindowInteractor *iren, double point[3])
00779 {
00780 int mouse_x, mouse_y;
00781
00782
00783 vtkPointPicker *picker = (vtkPointPicker*) iren->GetPicker ();
00784 iren->GetMousePosition (&mouse_x, &mouse_y);
00785
00786 vtkRenderWindow* renWin = iren->GetRenderWindow ();
00787 vtkRendererCollection *coll = renWin->GetRenderers ();
00788
00789 iren->StartPickCallback ();
00790
00791 picker->Pick (mouse_x, mouse_y, 0.0, coll->GetFirstRenderer ());
00792 idx = picker->GetPointId ();
00793 cerr << "Picked Point with Index: " << idx;
00794
00795 if (idx < 0)
00796 {
00797 cerr << endl;
00798 return idx;
00799 }
00800
00801 if (picker->GetDataSet () != NULL)
00802 {
00803 picker->GetDataSet ()->GetPoint (idx, point);
00804 cerr << " [" << point[0] << ", " << point[1] << ", " << point[2] << "]" << endl;
00805 }
00806 else
00807 cerr << endl;
00808 iren->EndPickCallback ();
00809 return idx;
00810 }
00811
00812 int idx;
00813 double pt[3], point_1[3], point_2[3];
00814 };
00815
00816 vtkStandardNewMacro (vtkInteractorStyleTUM);
00817 void
00818 vtkInteractorStyleTUM::setAdvancedMode (bool mode)
00819 {
00820 this->advanced = mode;
00821 this->gridActor = vtkLegendScaleActor::New ();
00822 this->grid_enabled = false;
00823 this->lut_enabled = false;
00824 this->lutActor = vtkScalarBarActor::New ();
00825 this->lutActor->SetTitle ("");
00826 this->lutActor->SetOrientationToHorizontal ();
00827 this->lutActor->SetPosition (0.05, 0.01);
00828 this->lutActor->SetWidth (0.9);
00829 this->lutActor->SetHeight (0.1);
00830 this->lutActor->SetNumberOfLabels (this->lutActor->GetNumberOfLabels () * 2);
00831 vtkSmartPointer<vtkTextProperty> prop = this->lutActor->GetLabelTextProperty ();
00832 prop->SetFontSize (10);
00833 this->lutActor->SetLabelTextProperty (prop);
00834 this->lutActor->SetTitleTextProperty (prop);
00835
00836
00837 vtkTextActor* camTxt = vtkTextActor::New ();
00838 vtkSmartPointer<vtkCameraCallback> camUpdateInfo = vtkSmartPointer<vtkCameraCallback>::New ();
00839 camUpdateInfo->SetTextActor (camTxt);
00840 double *camTxtPos = camTxt->GetPosition ();
00841 camTxt->SetPosition (camTxtPos[0], camTxtPos[0]+20);
00842 camTxt->GetProperty ()->SetColor (0.0, 1.0, 0.0);
00843
00844 if (one_renderer)
00845 {
00846 this->renderer->AddObserver (vtkCommand::EndEvent, camUpdateInfo);
00847 this->renderer->AddActor (camTxt);
00848 }
00849
00850 vtkMouseCallback *mc = vtkMouseCallback::New ();
00851
00852 mc->idx_1 = mc->idx_2 = -1;
00853 mc->pick_first = true;
00854
00855 this->AddObserver (vtkCommand::LeftButtonPressEvent, mc);
00856
00857
00858
00859 mc->Delete ();
00860 cerr << "Advanced mode enabled." << endl;
00861 }
00862
00863 void
00864 vtkInteractorStyleTUM::setRenderer (vtkRenderer *ren)
00865 {
00866 this->advanced = false;
00867 this->renderer = ren;
00868 pointsize = 1;
00869 one_renderer = true;
00870
00871 this->texts_enabled = false;
00872 this->textActor = NULL;
00873 }
00874
00875 void
00876 vtkInteractorStyleTUM::setRendererCollection (vtkRendererCollection *rencol)
00877 {
00878 this->advanced = false;
00879 this->rendererCollection = rencol;
00880 pointsize = 1;
00881 one_renderer = false;
00882
00883 this->texts_enabled = false;
00884 this->textActor = NULL;
00885 }
00886
00887
00888 void
00889 vtkInteractorStyleTUM::OnTimer ()
00890 {
00891
00892 this->filter->Modified ();
00893 if (one_renderer)
00894 this->renderer->Render ();
00895 else
00896 {
00897 this->rendererCollection->Render ();
00898 }
00899 }
00900
00901 void
00902 vtkInteractorStyleTUM::ZoomIn ()
00903 {
00904 vtkRenderWindowInteractor *rwi = this->Interactor;
00905 this->FindPokedRenderer(rwi->GetEventPosition()[0],
00906 rwi->GetEventPosition()[1]);
00907
00908 this->StartDolly ();
00909 double factor = 10.0 * 0.2 * .5;
00910 this->Dolly (pow (1.1, factor));
00911 this->EndDolly ();
00912 }
00913
00914 void
00915 vtkInteractorStyleTUM::ZoomOut ()
00916 {
00917 vtkRenderWindowInteractor *rwi = this->Interactor;
00918 this->FindPokedRenderer(rwi->GetEventPosition()[0],
00919 rwi->GetEventPosition()[1]);
00920
00921 this->StartDolly ();
00922 double factor = 10.0 * -0.2 * .5;
00923 this->Dolly (pow (1.1, factor));
00924 this->EndDolly ();
00925 }
00926
00928
00929 void
00930 SaveDataSetAsVTK (vtkDataSet *data, const char *fileName)
00931 {
00932 vtkDataSetWriter *writer = vtkDataSetWriter::New ();
00933
00934 writer->SetInput (data);
00935 writer->SetFileName (fileName);
00936 writer->SetFileTypeToASCII ();
00937
00938 writer->Write ();
00939 }
00940
00941
00943
00944
00945 void
00946 SaveDataSet (vtkDataSet *data, const char *fileName)
00947 {
00948 std::string fname = std::string (fileName);
00949
00950 if (fname.compare (fname.size () - 3, 3, "vtk") == 0)
00951 SaveDataSetAsVTK (data, fileName);
00952
00953
00954
00955
00956
00957
00958
00959
00960 }
00961
00963 void
00964 changeActorScalarAppearance (ScalarsContainer s, int dim, int argc, char** argv)
00965 {
00966 double minmax[2];
00967 vtkSmartPointer<vtkLookupTable> lut;
00968 vtkPolyData *data = static_cast<vtkPolyData*>(s.actor->GetMapper ()->GetInput ());
00969
00970 if (dim != -1)
00971 {
00972 minmax[0] = s.minScalar[dim]; minmax[1] = s.maxScalar[dim];
00973 lut = create_LUT (minmax, argc, argv);
00974
00975 s.scalars->InitTraversal ();
00976 for (int i = 0; i < dim; i++) s.scalars->GetNextItem ();
00977 data->GetPointData ()->SetScalars (s.scalars->GetNextItem ());
00978 }
00979
00980 data->Update ();
00981
00982 vtkPolyDataMapper* mapper = static_cast<vtkPolyDataMapper*>(s.actor->GetMapper ());
00984 mapper->SetInput (data);
00985 if (dim != -1)
00986 {
00987 mapper->SetLookupTable (lut);
00988 mapper->SetScalarRange (minmax);
00989 mapper->SetScalarModeToUsePointData ();
00990 mapper->ScalarVisibilityOn ();
00991 }
00992 else
00993 {
00994 mapper->ScalarVisibilityOff ();
00995 }
00996
00997 s.actor->SetMapper (mapper);
00998 s.actor->Modified ();
00999 }
01000
01001 void
01002 vtkInteractorStyleTUM::OnChar ()
01003 {
01004 if (pointsize < 1)
01005 pointsize = 1;
01006
01007 bool shift = this->Interactor->GetShiftKey ();
01008 bool ctrl = this->Interactor->GetControlKey ();
01009 bool alt = this->Interactor->GetAltKey ();
01010
01011 if (shift);
01012
01013 bool potentialPCDSave = false;
01014
01015 vtkRenderWindowInteractor *rwi = this->Interactor;
01016 if (ctrl && alt)
01017 potentialPCDSave = true;
01018
01019
01020
01021 std::string key (this->Interactor->GetKeySym ());
01022
01023 if (key.find ("XF86ZoomIn") != std::string::npos)
01024 this->ZoomIn ();
01025 else if (key.find ("XF86ZoomOut") != std::string::npos)
01026 this->ZoomOut ();
01027 else if (key.find ("space") != std::string::npos)
01028 {
01029 vtkAppendPolyData *allData = vtkAppendPolyData::New ();
01030 vtkActorCollection *ac;
01031 vtkActor *anActor, *aPart;
01032 vtkAssemblyPath *path;
01033 this->FindPokedRenderer(rwi->GetEventPosition()[0],
01034 rwi->GetEventPosition()[1]);
01035 ac = this->CurrentRenderer->GetActors();
01036 vtkCollectionSimpleIterator ait;
01037 for (ac->InitTraversal(ait); (anActor = ac->GetNextActor(ait)); )
01038 {
01039 for (anActor->InitPathTraversal(); (path=anActor->GetNextPath()); )
01040 {
01041 aPart=(vtkActor *)path->GetLastNode()->GetViewProp();
01042 vtkProperty *prop = aPart->GetProperty ();
01043 double prop_rgb[3];
01044 prop->GetDiffuseColor (prop_rgb);
01045 prop_rgb[0] *= 255; prop_rgb[1] *= 255; prop_rgb[2] *= 255;
01046
01047 vtkPolyData *aData = (vtkPolyData*)(aPart->GetMapper ()->GetInput ());
01048 aData->Update ();
01049
01050
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069 allData->AddInput (aData);
01070 }
01071 }
01072
01073 allData->Update ();
01074 cerr << "Total number of points on screen: " << allData->GetOutput ()->GetNumberOfPoints () << "... Dumping...";
01075 if (potentialPCDSave)
01076 {
01077
01078 std::ofstream fs;
01079 fs.precision (5);
01080 fs.open ("dump-screen.pcd");
01081 fs << "COLUMNS x y z" << std::endl;
01082 vtkSmartPointer<vtkCleanPolyData> cleaner = vtkSmartPointer<vtkCleanPolyData>::New ();
01083 cleaner->SetTolerance (0.0);
01084 cleaner->SetInput (allData->GetOutput ());
01085 cleaner->ConvertLinesToPointsOff ();
01086 cleaner->ConvertPolysToLinesOff ();
01087 cleaner->ConvertStripsToPolysOff ();
01088 cleaner->PointMergingOn ();
01089 cleaner->Update ();
01090 fs << "POINTS " << cleaner->GetOutput ()->GetNumberOfPoints () << std::endl;
01091
01092 double p[3];
01093 for (int i = 0; i < cleaner->GetOutput ()->GetNumberOfPoints (); i++)
01094 {
01095 cleaner->GetOutput ()->GetPoint (i, p);
01096 for (unsigned int j = 0; j < 3; j++)
01097 fs << p[j] << " ";
01098 fs << std::endl;
01099 }
01100 fs.close ();
01101
01102 cerr << "...pruned " <<
01103 allData->GetOutput ()->GetNumberOfPoints () - cleaner->GetOutput ()->GetNumberOfPoints () <<
01104 ", left " << cleaner->GetOutput ()->GetNumberOfPoints () << " (PCD)";
01105 }
01106 else
01107 {
01108 cerr << "(VTK)";
01109 SaveDataSet (allData->GetOutput (), "dump-screen.vtk");
01110 }
01111 cerr << "[done]" << endl;
01112 }
01113
01114 this->FindPokedRenderer (rwi->GetEventPosition ()[0], rwi->GetEventPosition ()[1]);
01115
01116
01117 switch (this->Interactor->GetKeyCode ())
01118 {
01119 case 'h':
01120 case 'H':
01121 {
01122 cerr << "History/Legend:" << endl;
01123 cerr << " p, P : switch to a point-based representation" << endl;
01124 cerr << " w, W : switch to a wireframe-based representation" << endl;
01125 cerr << " s, S : switch to a surface-based representation" << endl;
01126 cerr << endl;
01127 cerr << " i, I : display information about each dataset (using printself)" << endl;
01128 cerr << endl;
01129 cerr << " j, J : take a .PNG snapshot of the current window view" << endl;
01130 cerr << " <space> : save all data to file in VTK format" << endl;
01131 cerr << "CTRL+ALT+<space> : perform a vtkCleanPolyData and save all data to file in PCD format" << endl;
01132 cerr << endl;
01133 cerr << " c, C : display current camera settings/parameters" << endl;
01134 cerr << " + : increment overall point size" << endl;
01135 cerr << " - : decrement overall point size" << endl;
01136 cerr << endl;
01137 cerr << " t, T : enable/disable the display of texts (given as command line parameters) on screen" << endl;
01138 cerr << " <, > : display 'previous', 'next' text in the list" << endl;
01139 cerr << endl;
01140 cerr << " g, G : display scale grid (on/off)" << endl;
01141 cerr << " 0 - 9 : change the scalars (see L)" << endl;
01142 cerr << " l, L : display scalar legend at the console" << endl;
01143 cerr << " u, U : display the LUT (LookUp Table) actor (on/off)" << endl;
01144 cerr << " o, O : switch the LUT (LookUp Table) between logarithmic and linear" << endl;
01145 break;
01146 }
01147
01148 case 't':
01149 case 'T':
01150 {
01151
01152 if (textList.size () == 0)
01153 break;
01154
01155
01156 if (this->textActor == NULL)
01157 {
01158 this->cur_text = 0;
01159
01160 this->textActor = vtkTextActor::New ();
01161 this->textActor->SetInput (this->textList.at (this->cur_text).c_str ());
01162 this->textActor->GetTextProperty ()->SetFontSize (this->tS);
01163 this->textActor->GetTextProperty ()->SetFontFamilyToArial ();
01164 this->textActor->GetTextProperty ()->BoldOn ();
01165 this->textActor->GetTextProperty ()->SetJustificationToRight ();
01166 this->textActor->GetTextProperty ()->SetVerticalJustificationToTop ();
01167 this->textActor->GetTextProperty ()->SetColor (this->tR, this->tG, this->tB);
01168 this->textActor->GetProperty ()->SetOpacity (0.75);
01169
01170 this->textActor->SetDisplayPosition (this->tAx, this->tAy);
01171 this->textActor->VisibilityOn ();
01172
01173 if (one_renderer)
01174 this->renderer->AddActor (textActor);
01175 else
01176 {
01177 this->rendererCollection->InitTraversal ();
01178 vtkRenderer *ren = this->rendererCollection->GetFirstRenderer ();
01179 do
01180 {
01181 ren->AddActor (textActor);
01182 }
01183 while ((ren = this->rendererCollection->GetNextItem ()) != NULL);
01184 }
01185
01186 this->texts_enabled = true;
01187
01188 break;
01189 }
01190
01191 if (!texts_enabled)
01192 {
01193 this->textActor->VisibilityOn ();
01194 this->texts_enabled = true;
01195 }
01196 else
01197 {
01198 this->textActor->VisibilityOff ();
01199 this->texts_enabled = false;
01200 }
01201
01202 break;
01203 }
01204
01205 case '<':
01206 {
01207 if (this->textActor == NULL)
01208 break;
01209
01210 this->cur_text--;
01211
01212
01213 if (this->cur_text < 0)
01214 this->cur_text = this->textList.size () - 1;
01215
01216
01217 this->textActor->SetInput (this->textList.at (this->cur_text).c_str ());
01218 this->textActor->Modified ();
01219 break;
01220 }
01221
01222 case '>':
01223 {
01224 if (this->textActor == NULL)
01225 break;
01226
01227 this->cur_text++;
01228
01229
01230 if (this->cur_text > (int)this->textList.size () - 1)
01231 this->cur_text = 0;
01232
01233
01234 this->textActor->SetInput (this->textList.at (this->cur_text).c_str ());
01235 this->textActor->Modified ();
01236 break;
01237 }
01238
01239 case 'i':
01240 case 'I':
01241 {
01242 vtkActorCollection *ac;
01243 vtkActor *anActor, *aPart;
01244 vtkAssemblyPath *path;
01245 ac = this->CurrentRenderer->GetActors ();
01246 vtkCollectionSimpleIterator ait;
01247 for (ac->InitTraversal (ait); (anActor = ac->GetNextActor (ait)); )
01248 {
01249 for (anActor->InitPathTraversal (); (path = anActor->GetNextPath ()); )
01250 {
01251 aPart=(vtkActor *)path->GetLastNode ()->GetViewProp ();
01252
01253 }
01254 }
01255 break;
01256 }
01257 case 'p':
01258 case 'P':
01259 {
01260 vtkActorCollection *ac;
01261 vtkActor *anActor, *aPart;
01262 vtkAssemblyPath *path;
01263 ac = this->CurrentRenderer->GetActors ();
01264 vtkCollectionSimpleIterator ait;
01265 for (ac->InitTraversal (ait); (anActor = ac->GetNextActor (ait)); )
01266 {
01267 for (anActor->InitPathTraversal (); (path = anActor->GetNextPath ()); )
01268 {
01269 aPart=(vtkActor *)path->GetLastNode ()->GetViewProp ();
01270 aPart->GetProperty ()->SetRepresentationToPoints ();
01271 }
01272 }
01273 break;
01274 }
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292 case 'J':
01293 case 'j':
01294 {
01295 unsigned t = time (0);
01296 sprintf (camFN, "screenshot-%d.cam", t);
01297 sprintf (fileName, "screenshot-%d.png" , t);
01298 this->writer->SetFileName (fileName);
01299 this->writer->Write ();
01300 cerr << "> Wrote " << fileName << "..." << endl;
01301
01302 ofstream ofs_cam;
01303 ofs_cam.open (camFN);
01304
01305 vtkCamera* cam = rwi->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->GetActiveCamera ();
01306 double clip[2], focal[3], pos[3], view[3];
01307 cam->GetClippingRange (clip);
01308 cam->GetFocalPoint (focal);
01309 cam->GetPosition (pos);
01310 cam->GetViewUp (view);
01311 ofs_cam << clip[0] << "," << clip[1] << "/" <<
01312 focal[0] << "," << focal[1] << "," << focal[2] << "/" <<
01313 pos[0] << "," << pos[1] << "," << pos[2] << "/" <<
01314 view[0] << "," << view[1] << "," << view[2] << endl;
01315 ofs_cam.close ();
01316 cerr << "> Wrote camera information to file (" << camFN << ") : -[ Clipping Range / Focal Point / Position / ViewUp ]-" << endl;
01317 cerr << clip[0] << "," << clip[1] << "/" <<
01318 focal[0] << "," << focal[1] << "," << focal[2] << "/" <<
01319 pos[0] << "," << pos[1] << "," << pos[2] << "/" <<
01320 view[0] << "," << view[1] << "," << view[2] << endl;
01321 break;
01322 }
01323 case 'C':
01324 case 'c':
01325 {
01326 vtkCamera* cam = rwi->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->GetActiveCamera ();
01327
01328 double clip[2], focal[3], pos[3], view[3];
01329 cam->GetClippingRange (clip);
01330 cam->GetFocalPoint (focal);
01331 cam->GetPosition (pos);
01332 cam->GetViewUp (view);
01333 cerr << "-[ Clipping Range / Focal Point / Position / ViewUp ]-" << endl;
01334 cerr << clip[0] << "," << clip[1] << "/" <<
01335 focal[0] << "," << focal[1] << "," << focal[2] << "/" <<
01336 pos[0] << "," << pos[1] << "," << pos[2] << "/" <<
01337 view[0] << "," << view[1] << "," << view[2] << endl;
01338 break;
01339 }
01340 case KEY_PLUS:
01341 {
01342 cerr << "Current point size: " << pointsize << endl;
01343 vtkActorCollection *ac;
01344 vtkActor *anActor, *aPart;
01345 vtkAssemblyPath *path;
01346 ac = this->CurrentRenderer->GetActors ();
01347 vtkCollectionSimpleIterator ait;
01348 for (ac->InitTraversal (ait); (anActor = ac->GetNextActor (ait)); )
01349 {
01350 for (anActor->InitPathTraversal (); (path=anActor->GetNextPath ()); )
01351 {
01352 aPart=(vtkActor *)path->GetLastNode ()->GetViewProp ();
01353 aPart->GetProperty ()->SetPointSize (aPart->GetProperty ()->GetPointSize () + 1);
01354 }
01355 }
01356 break;
01357 }
01358 case KEY_MINUS:
01359 {
01360 vtkActorCollection *ac;
01361 vtkActor *anActor, *aPart;
01362 vtkAssemblyPath *path;
01363 ac = this->CurrentRenderer->GetActors ();
01364 vtkCollectionSimpleIterator ait;
01365 for (ac->InitTraversal (ait); (anActor = ac->GetNextActor (ait)); )
01366 {
01367 for (anActor->InitPathTraversal (); (path=anActor->GetNextPath ()); )
01368 {
01369 aPart=(vtkActor *)path->GetLastNode ()->GetViewProp ();
01370 aPart->GetProperty ()->SetPointSize (aPart->GetProperty ()->GetPointSize () - 1);
01371 }
01372 }
01373 break;
01374 }
01375
01376
01377 case 'G':
01378 case 'g':
01379 {
01380 if (!grid_enabled)
01381 {
01382 gridActor->TopAxisVisibilityOn ();
01383 this->CurrentRenderer->AddViewProp (gridActor);
01384
01385 this->grid_enabled = true;
01386 }
01387 else
01388 {
01389 this->CurrentRenderer->RemoveViewProp (gridActor);
01390 this->grid_enabled = false;
01391 }
01392 this->CurrentRenderer->RemoveActor (lutActor);
01393 this->lut_enabled = false;
01394
01395 break;
01396 }
01397
01400
01401 case '0':
01402 {
01403 if (!advanced) break;
01404
01405 for (unsigned int cp = 0; cp < this->allScalars.size (); cp++)
01406 {
01407 ScalarsContainer s = this->allScalars[cp];
01408 changeActorScalarAppearance (s, -1, argc, argv);
01409 lutActor->SetVisibility (false);
01410 }
01411
01412
01413 if (this->textActor == NULL)
01414 break;
01415
01416 if (this->textList.size () > 0)
01417 this->cur_text = 0;
01418
01419
01420 this->textActor->SetInput (this->textList.at (this->cur_text).c_str ());
01421 this->textActor->Modified ();
01422 break;
01423 }
01425
01426 case '1':
01427 {
01428 if (!advanced) break;
01429
01430 if (this->Interactor->GetControlKey ());
01432 else
01433 {
01434 for (unsigned int cp = 0; cp < this->allScalars.size (); cp++)
01435 {
01436 ScalarsContainer s = this->allScalars[cp];
01437 if (s.dimensions.size () == 0) continue;
01438 changeActorScalarAppearance (s, 0, argc, argv);
01439
01440 vtkLookupTable* lut = static_cast<vtkLookupTable*>(s.actor->GetMapper ()->GetLookupTable ());
01441 lutActor->SetLookupTable (lut);
01442 lutActor->Modified ();
01443 }
01444 }
01445
01446
01447 if (this->textActor == NULL)
01448 break;
01449
01450 if (this->textList.size () > 1)
01451 this->cur_text = 1;
01452
01453
01454 lutActor->SetTitle (this->textList.at (this->cur_text).c_str ());
01455 lutActor->Modified ();
01456 this->textActor->SetInput (this->textList.at (this->cur_text).c_str ());
01457 this->textActor->Modified ();
01458 break;
01459 }
01461 case '2':
01462 {
01463 if (!advanced) break;
01464
01465 if (this->Interactor->GetControlKey ());
01467 else
01468 for (unsigned int cp = 0; cp < this->allScalars.size (); cp++)
01469 {
01470 ScalarsContainer s = this->allScalars[cp];
01471 if (s.dimensions.size () < 2) continue;
01472 changeActorScalarAppearance (s, 1, argc, argv);
01473
01474 vtkLookupTable* lut = static_cast<vtkLookupTable*>(s.actor->GetMapper ()->GetLookupTable ());
01475 lutActor->SetLookupTable (lut);
01476 lutActor->Modified ();
01477 }
01478
01479
01480 if (this->textActor == NULL)
01481 break;
01482
01483 if (this->textList.size () > 2)
01484 this->cur_text = 2;
01485
01486
01487 lutActor->SetTitle (this->textList.at (this->cur_text).c_str ());
01488 lutActor->Modified ();
01489 this->textActor->SetInput (this->textList.at (this->cur_text).c_str ());
01490 this->textActor->Modified ();
01491 break;
01492 }
01494 case '3':
01495 {
01496 if (!advanced) break;
01497
01498 if (this->Interactor->GetControlKey ());
01500 else
01501 for (unsigned int cp = 0; cp < this->allScalars.size (); cp++)
01502 {
01503 ScalarsContainer s = this->allScalars[cp];
01504 if (s.dimensions.size () < 3) continue;
01505 changeActorScalarAppearance (s, 2, argc, argv);
01506
01507 vtkLookupTable* lut = static_cast<vtkLookupTable*>(s.actor->GetMapper ()->GetLookupTable ());
01508 lutActor->SetLookupTable (lut);
01509 lutActor->Modified ();
01510 }
01511
01512
01513 if (this->textActor == NULL)
01514 break;
01515
01516 if (this->textList.size () > 3)
01517 this->cur_text = 3;
01518
01519
01520 lutActor->SetTitle (this->textList.at (this->cur_text).c_str ());
01521 lutActor->Modified ();
01522 this->textActor->SetInput (this->textList.at (this->cur_text).c_str ());
01523 this->textActor->Modified ();
01524 break;
01525 }
01527 case '4':
01528 {
01529 if (!advanced) break;
01530
01531 if (this->Interactor->GetControlKey ());
01533 else
01534 for (unsigned int cp = 0; cp < this->allScalars.size (); cp++)
01535 {
01536 ScalarsContainer s = this->allScalars[cp];
01537 if (s.dimensions.size () < 4) break;
01538 changeActorScalarAppearance (s, 3, argc, argv);
01539
01540 vtkLookupTable* lut = static_cast<vtkLookupTable*>(s.actor->GetMapper ()->GetLookupTable ());
01541 lutActor->SetLookupTable (lut);
01542 lutActor->Modified ();
01543 }
01544
01545
01546 if (this->textActor == NULL)
01547 break;
01548
01549 if (this->textList.size () > 4)
01550 this->cur_text = 4;
01551
01552
01553 lutActor->SetTitle (this->textList.at (this->cur_text).c_str ());
01554 lutActor->Modified ();
01555 this->textActor->SetInput (this->textList.at (this->cur_text).c_str ());
01556 this->textActor->Modified ();
01557 break;
01558 }
01560 case '5':
01561 {
01562 if (!advanced) break;
01563
01564 if (this->Interactor->GetControlKey ());
01566 else
01567 for (unsigned int cp = 0; cp < this->allScalars.size (); cp++)
01568 {
01569 ScalarsContainer s = this->allScalars[cp];
01570 if (s.dimensions.size () < 5) continue;
01571 changeActorScalarAppearance (s, 4, argc, argv);
01572
01573 vtkLookupTable* lut = static_cast<vtkLookupTable*>(s.actor->GetMapper ()->GetLookupTable ());
01574 lutActor->SetLookupTable (lut);
01575 lutActor->Modified ();
01576 }
01577
01578
01579 if (this->textActor == NULL)
01580 break;
01581
01582 if (this->textList.size () > 5)
01583 this->cur_text = 5;
01584
01585
01586 lutActor->SetTitle (this->textList.at (this->cur_text).c_str ());
01587 lutActor->Modified ();
01588 this->textActor->SetInput (this->textList.at (this->cur_text).c_str ());
01589 this->textActor->Modified ();
01590 break;
01591 }
01593 case '6':
01594 {
01595 if (!advanced) break;
01596
01597 if (this->Interactor->GetControlKey ());
01599 else
01600 for (unsigned int cp = 0; cp < this->allScalars.size (); cp++)
01601 {
01602 ScalarsContainer s = this->allScalars[cp];
01603 if (s.dimensions.size () < 6) continue;
01604 changeActorScalarAppearance (s, 5, argc, argv);
01605
01606 vtkLookupTable* lut = static_cast<vtkLookupTable*>(s.actor->GetMapper ()->GetLookupTable ());
01607 lutActor->SetLookupTable (lut);
01608 lutActor->Modified ();
01609 }
01610
01611
01612 if (this->textActor == NULL)
01613 break;
01614
01615 if (this->textList.size () > 6)
01616 this->cur_text = 6;
01617
01618
01619 lutActor->SetTitle (this->textList.at (this->cur_text).c_str ());
01620 lutActor->Modified ();
01621 this->textActor->SetInput (this->textList.at (this->cur_text).c_str ());
01622 this->textActor->Modified ();
01623 break;
01624 }
01626 case '7':
01627 {
01628 if (!advanced) break;
01629
01630 if (this->Interactor->GetControlKey ());
01632 else
01633 for (unsigned int cp = 0; cp < this->allScalars.size (); cp++)
01634 {
01635 ScalarsContainer s = this->allScalars[cp];
01636 if (s.dimensions.size () < 7) continue;
01637 changeActorScalarAppearance (s, 6, argc, argv);
01638
01639 vtkLookupTable* lut = static_cast<vtkLookupTable*>(s.actor->GetMapper ()->GetLookupTable ());
01640 lutActor->SetLookupTable (lut);
01641 lutActor->Modified ();
01642 }
01643
01644
01645 if (this->textActor == NULL)
01646 break;
01647
01648 if (this->textList.size () > 7)
01649 this->cur_text = 7;
01650
01651
01652 lutActor->SetTitle (this->textList.at (this->cur_text).c_str ());
01653 lutActor->Modified ();
01654 this->textActor->SetInput (this->textList.at (this->cur_text).c_str ());
01655 this->textActor->Modified ();
01656 break;
01657 }
01659 case '8':
01660 {
01661 if (!advanced) break;
01662
01663 if (this->Interactor->GetControlKey ());
01665 else
01666 for (unsigned int cp = 0; cp < this->allScalars.size (); cp++)
01667 {
01668 ScalarsContainer s = this->allScalars[cp];
01669 if (s.dimensions.size () < 8) continue;
01670 changeActorScalarAppearance (s, 7, argc, argv);
01671
01672 vtkLookupTable* lut = static_cast<vtkLookupTable*>(s.actor->GetMapper ()->GetLookupTable ());
01673 lutActor->SetLookupTable (lut);
01674 lutActor->Modified ();
01675 }
01676
01677
01678 if (this->textActor == NULL)
01679 break;
01680
01681 if (this->textList.size () > 8)
01682 this->cur_text = 8;
01683
01684
01685 lutActor->SetTitle (this->textList.at (this->cur_text).c_str ());
01686 lutActor->Modified ();
01687 this->textActor->SetInput (this->textList.at (this->cur_text).c_str ());
01688 this->textActor->Modified ();
01689 break;
01690 }
01692 case '9':
01693 {
01694 if (!advanced) break;
01695
01696 if (this->Interactor->GetControlKey ());
01698 else
01699 for (unsigned int cp = 0; cp < this->allScalars.size (); cp++)
01700 {
01701 ScalarsContainer s = this->allScalars[cp];
01702 if (s.dimensions.size () < 9) continue;
01703 changeActorScalarAppearance (s, 8, argc, argv);
01704
01705 vtkLookupTable* lut = static_cast<vtkLookupTable*>(s.actor->GetMapper ()->GetLookupTable ());
01706 lutActor->SetLookupTable (lut);
01707 lutActor->Modified ();
01708 }
01709
01710
01711 if (this->textActor == NULL)
01712 break;
01713
01714 if (this->textList.size () > 9)
01715 this->cur_text = 9;
01716
01717
01718 lutActor->SetTitle (this->textList.at (this->cur_text).c_str ());
01719 lutActor->Modified ();
01720 this->textActor->SetInput (this->textList.at (this->cur_text).c_str ());
01721 this->textActor->Modified ();
01722 break;
01723 }
01726
01727
01728
01729
01730 case 'U':
01731 case 'u':
01732 {
01733 if (!advanced) break;
01734
01735 this->FindPokedRenderer (rwi->GetEventPosition ()[0],
01736 rwi->GetEventPosition ()[1]);
01737
01738 for (unsigned int cp = 0; cp < this->allScalars.size (); cp++)
01739 {
01740 ScalarsContainer s = this->allScalars[cp];
01741 if (s.dimensions.size () == 0) break;
01742 vtkLookupTable* lut = static_cast<vtkLookupTable*>(s.actor->GetMapper ()->GetLookupTable ());
01743 lutActor->SetLookupTable (lut);
01744 lutActor->Modified ();
01745
01746 if (!lut_enabled)
01747 {
01748 this->CurrentRenderer->AddActor (lutActor);
01749 lutActor->SetVisibility (true);
01750 this->lut_enabled = true;
01751 }
01752 else
01753 {
01754 this->CurrentRenderer->RemoveActor (lutActor);
01755 this->lut_enabled = false;
01756 }
01757 }
01758
01759 rwi->Render();
01760 break;
01761 }
01762
01763
01764 case 'O':
01765 case 'o':
01766 {
01767 if (!advanced) break;
01768
01769 this->FindPokedRenderer (rwi->GetEventPosition ()[0],
01770 rwi->GetEventPosition ()[1]);
01771
01772 for (unsigned int cp = 0; cp < this->allScalars.size (); cp++)
01773 {
01774 ScalarsContainer s = this->allScalars[cp];
01775 if (s.dimensions.size () < 1) break;
01776 vtkLookupTable* lut = static_cast<vtkLookupTable*>(s.actor->GetMapper ()->GetLookupTable ());
01778 lut->SetScale (!lut->GetScale ());
01779
01780 lutActor->SetLookupTable (lut);
01781 lutActor->Modified ();
01782
01783 s.actor->GetMapper ()->SetLookupTable (lut);
01784 s.actor->Modified ();
01785 }
01786
01787 rwi->Render();
01788 break;
01789 }
01790
01791 case 'L':
01792 case 'l':
01793 {
01794 if (!advanced) break;
01795
01796 for (unsigned int cp = 0; cp < this->allScalars.size (); cp++)
01797 {
01798 ScalarsContainer s = this->allScalars[cp];
01799 if (s.dimensions.size () == 0) break;
01800
01801 cerr << "Available dimensions: default(0) ";
01802 for (unsigned int dim = 0; dim < s.dimensions.size (); dim++)
01803 cerr << s.dimensions[dim] << "(" << dim+1 << ") ";
01804 cerr << endl;
01805 }
01806 if (this->Interactor->GetControlKey ())
01807 cerr << "control" << endl;
01808
01809
01810 break;
01811 }
01812 default:
01813 {
01814
01815 this->Superclass::OnChar ();
01816 break;
01817 }
01818 }
01819
01820
01821 rwi->Render();
01822 }
01823
01824
01825 class vtkFPSCallback : public vtkCommand
01826 {
01827 public:
01828 static vtkFPSCallback *New () { return new vtkFPSCallback;}
01829 void SetTextActor (vtkTextActor *txt);
01830 virtual void Execute (vtkObject *caller, unsigned long, void*);
01831 protected:
01832 vtkTextActor *TextActor;
01833 char TextBuff[128];
01834 };
01835
01837
01839 void
01840 vtkFPSCallback::SetTextActor (vtkTextActor *txt)
01841 {
01842 this->TextActor = txt;
01843 }
01844
01845 void
01846 vtkFPSCallback::Execute (vtkObject *caller, unsigned long, void*)
01847 {
01848 vtkRenderer *ren = reinterpret_cast<vtkRenderer *> (caller);
01849
01850 long int nr_points = 0;
01851 vtkActorCollection *ac = ren->GetActors ();
01852 vtkActor *anActor, *aPart;
01853 vtkCollectionSimpleIterator ait;
01854 vtkAssemblyPath *path;
01855 for (ac->InitTraversal (ait); (anActor = ac->GetNextActor (ait)); )
01856 {
01857 for (anActor->InitPathTraversal(); (path=anActor->GetNextPath ()); )
01858 {
01859 aPart=(vtkActor *)path->GetLastNode ()->GetViewProp ();
01860 nr_points += aPart->GetMapper ()->GetInputAsDataSet ()->GetNumberOfPoints ();
01861 }
01862 }
01863
01864 float fps = 1.0/ren->GetLastRenderTimeInSeconds ();
01865 snprintf (this->TextBuff, 127, "%.1f FPS, %ld points", fps, nr_points);
01866 this->TextActor->SetInput (this->TextBuff);
01867 }
01868
01869
01871
01872 vtkRenderWindowInteractor*
01873 CreateRenderWindowAndInteractor (vtkRenderer *ren, const char* title)
01874 {
01875
01876
01877
01878 vtkSmartPointer<vtkTextActor> txt = vtkSmartPointer<vtkTextActor>::New ();
01879 vtkSmartPointer<vtkFPSCallback> UpdateFPS = vtkSmartPointer<vtkFPSCallback>::New ();
01880 UpdateFPS->SetTextActor (txt);
01881 ren->AddObserver (vtkCommand::EndEvent, UpdateFPS);
01882 txt->GetProperty ()->SetColor (0.0, 0.0, 1.0);
01883 ren->AddActor (txt);
01884
01885 vtkRenderWindow *renWin = vtkRenderWindow::New ();
01886 renWin->SetWindowName (title);
01887 renWin->AddRenderer (ren);
01888 renWin->SetSize (RENWIN_WIDTH, RENWIN_HEIGHT);
01889
01890 vtkSmartPointer<vtkWindowToImageFilter> wif = vtkSmartPointer<vtkWindowToImageFilter>::New ();
01891 wif->SetInput (renWin);
01892
01893
01894 vtkPNGWriter* w = vtkPNGWriter::New ();
01895
01896 w->SetInputConnection (wif->GetOutputPort ());
01897
01898 vtkRenderWindowInteractor *iren = renWin->MakeRenderWindowInteractor ();
01899 vtkSmartPointer<vtkInteractorStyleTUM> style = vtkSmartPointer<vtkInteractorStyleTUM>::New ();
01900 style->setRenderer (ren);
01901 style->UseTimersOn ();
01902 style->setWriter (w);
01903 style->setWindowFilter (wif);
01904
01905 vtkPointPicker *pp = vtkPointPicker::New ();
01906 iren->SetPicker (pp);
01907
01908 iren->SetInteractorStyle (style);
01909 iren->Initialize ();
01910
01911 iren->CreateRepeatingTimer (5000L);
01912 return iren;
01913 }
01914
01915 void tokenize(const std::string& str,
01916 std::vector<std::string>& tokens,
01917 const std::string& delimiters = " ")
01918 {
01919
01920 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
01921
01922 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
01923
01924 while (std::string::npos != pos || std::string::npos != lastPos)
01925 {
01926
01927 tokens.push_back(str.substr(lastPos, pos - lastPos));
01928
01929 lastPos = str.find_first_not_of(delimiters, pos);
01930
01931 pos = str.find_first_of(delimiters, lastPos);
01932 }
01933 }
01934
01936
01937
01938 std::vector<std::string>
01939 parse_texts_argument (int argc, char** argv, const std::string &token)
01940 {
01941 std::vector<std::string> texts;
01942 for (int i = 1; i < argc; i++)
01943 {
01944
01945 if ((strcmp (argv[i], "-texts") == 0) && (++i < argc))
01946 {
01947
01948 std::string val = std::string (argv[i]);
01949
01950
01951
01952
01953
01954
01955
01956 tokenize(val, texts, token);
01957 }
01958 }
01959 return texts;
01960 }
01961
01962
01964
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974
01975
01976
01977
01978
01979
01980
01981
01982
01983
01984
01985
01986
01987
01988
01990
01991 vtkActor*
01992 createAxes (double scale)
01993 {
01994 vtkSmartPointer<vtkAxes> axes = vtkSmartPointer<vtkAxes>::New ();
01995 axes->SetOrigin (0, 0, 0);
01996 axes->SetScaleFactor (scale);
01997
01998 vtkSmartPointer<vtkFloatArray> colors = vtkSmartPointer<vtkFloatArray>::New ();
01999 colors->Allocate (6);
02000 colors->InsertNextValue (0.0);
02001 colors->InsertNextValue (0.0);
02002 colors->InsertNextValue (0.5);
02003 colors->InsertNextValue (0.5);
02004 colors->InsertNextValue (1.0);
02005 colors->InsertNextValue (1.0);
02006
02007 vtkSmartPointer<vtkPolyData> data = axes->GetOutput ();
02008 data->Update ();
02009 data->GetPointData ()->SetScalars (colors);
02010
02011 vtkSmartPointer<vtkTubeFilter> axesTubes = vtkSmartPointer<vtkTubeFilter>::New ();
02012 axesTubes->SetInput (data);
02013
02014 axesTubes->SetRadius (axes->GetScaleFactor () / 50.0);
02015 axesTubes->SetNumberOfSides (6);
02016
02017 vtkSmartPointer<vtkPolyDataMapper> axesMapper = vtkSmartPointer<vtkPolyDataMapper>::New ();
02018 axesMapper->SetScalarModeToUsePointData ();
02019 axesMapper->SetInput (axesTubes->GetOutput ());
02020
02021 vtkActor* axesActor = vtkActor::New ();
02022 axesActor->SetMapper (axesMapper);
02023
02024 return axesActor;
02025 }
02026
02027
02031 vtkRenderWindowInteractor*
02032 CreateRenderWindowAndInteractor (vtkRenderer *ren, const char* title, int argc, char** argv)
02033 {
02034 vtkRenderWindowInteractor* iren = CreateRenderWindowAndInteractor (ren, title);
02035
02036 vtkInteractorStyleTUM* s = reinterpret_cast<vtkInteractorStyleTUM*> (iren->GetInteractorStyle ());
02037 s->argc = argc;
02038 s->argv = argv;
02039
02040
02041 std::string token;
02042 terminal_tools::parse_argument (argc, argv, "-texts_sep", token);
02043
02044 s->setTextsList (parse_texts_argument (argc, argv, token));
02045 double tx = RENWIN_WIDTH - 10, ty = RENWIN_HEIGHT - 10, ts = 40.0;
02046 terminal_tools::parse_3x_arguments (argc, argv, "-texts_prop", tx, ty, ts);
02047 s->setTextsProp (tx, ty, ts);
02048 double tr = 1.0, tg = 1.0 , tb = 1.0;
02049 terminal_tools::parse_3x_arguments (argc, argv, "-texts_color", tr, tg, tb);
02050 s->setTextsColor (tr, tg, tb);
02051
02052
02053
02054
02055
02056 int quality = 1;
02057 terminal_tools::parse_argument (argc, argv, "-q", quality);
02058 if (quality != 0)
02059 {
02060 iren->GetRenderWindow ()->AlphaBitPlanesOn ();
02061 iren->GetRenderWindow ()->PointSmoothingOn ();
02062 iren->GetRenderWindow ()->LineSmoothingOn ();
02063 iren->GetRenderWindow ()->PolygonSmoothingOn ();
02064
02065
02066
02067 cerr << "Using the following quality settings: AlphaBitPlanes/{Point/Line/Polygon}Smoothing/AAFrames: ";
02068 cerr << iren->GetRenderWindow ()->GetAlphaBitPlanes () << "/";
02069 cerr << iren->GetRenderWindow ()->GetPointSmoothing () << "/";
02070 cerr << iren->GetRenderWindow ()->GetLineSmoothing () << "/";
02071 cerr << iren->GetRenderWindow ()->GetPolygonSmoothing () << "/";
02072 cerr << iren->GetRenderWindow ()->GetAAFrames () << endl;
02073 }
02074
02075 vtkActor *anActor, *aPart;
02076 vtkActorCollection *ac = iren->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->GetActors ();
02077 vtkAssemblyPath *path;
02078 vtkCollectionSimpleIterator ait;
02079 for (ac->InitTraversal (ait); (anActor = ac->GetNextActor (ait)); )
02080 {
02081 for (anActor->InitPathTraversal (); (path = anActor->GetNextPath ()); )
02082 {
02083 aPart=(vtkActor *)path->GetLastNode ()->GetViewProp ();
02084 if (quality == 0)
02085 aPart->GetProperty ()->SetInterpolationToFlat ();
02086 else
02087
02088 aPart->GetProperty ()->SetInterpolationToPhong ();
02089 }
02090 }
02091
02092
02093 double axes = 0.0;
02094 terminal_tools::parse_argument (argc, argv, "-ax", axes);
02095 if (axes != 0.0)
02096 {
02097 double ax_x = 0.0, ax_y = 0.0, ax_z = 0.0;
02098 terminal_tools::parse_3x_arguments (argc, argv, "-ax_pos", ax_x, ax_y, ax_z, false);
02099
02100 vtkActor* axActor = createAxes (axes);
02101 axActor->SetPosition (ax_x, ax_y, ax_z);
02102 iren->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->AddActor (axActor);
02103 }
02104
02105
02106 double bcolor[3] = {0.0, 0.0, 0.0};
02107 iren->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->GetBackground (bcolor);
02108 terminal_tools::parse_3x_arguments (argc, argv, "-bc", bcolor[0], bcolor[1], bcolor[2]);
02109 iren->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->SetBackground (bcolor[0], bcolor[1], bcolor[2]);
02110 iren->Render ();
02111
02112 return iren;
02113 }
02114 #endif