DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
vtkPolyDataViewer.hxx
Go to the documentation of this file.
1 
12 #ifndef __vtkPolyDataViewer_hxx
13 #define __vtkPolyDataViewer_hxx
14 
15 #include "vtkPolyDataViewer.h"
16 
17 namespace vtk
18 {
19 
20 void vtkPolyDataViewer::Add(const vtkSmartPointer<vtkPolyData>& mesh, const double opacity)
21 {
22  vtkSmartPointer<vtkLODActor> actor = vtkPolyDataToActor(mesh, opacity, {HueRange[0], HueRange[1]}, UseNormal, {ScalarRange[0],ScalarRange[1]}, Lighting);
23  this->Add(actor);
24 }
25 
26 void vtkPolyDataViewer::Add(const vtkSmartPointer<vtkPolyData>& mesh, const double opacity, const std::vector<double>& hueRange, bool useNormal, const std::vector<double>& scalarRange, bool lighting )
27 {
28  vtkSmartPointer<vtkLODActor> actor;
29  if (std::fabs(scalarRange[0]+1.0)<1e-8 && std::fabs(scalarRange[1]+1.0)<1e-8)
30  actor = vtkPolyDataToActor(mesh, opacity, {hueRange[0], hueRange[1]}, useNormal, {ScalarRange[0],ScalarRange[1]}, lighting);
31  else
32  actor = vtkPolyDataToActor(mesh, opacity, {hueRange[0], hueRange[1]}, useNormal, {scalarRange[0],scalarRange[1]}, lighting);
33  this->Add(actor);
34 }
35 
37 {
38  vtkSmartPointer<vtkCamera> camera = Renderer->GetActiveCamera();
39  camera->Roll(Angle[0]);
40  camera->Elevation(Angle[1]);
41  camera->Zoom(Zoom);
42 }
43 
45 {
46  RenderWindow->AddRenderer( Renderer );
47  RenderWindow->SetSize(WindowSize[0], WindowSize[1]);
48 
49  Interactor->SetRenderWindow( RenderWindow );
50  Interactor->Initialize();
51 
52  RenderWindow->Render();
53 
54  Renderer->ResetCamera();
55  this->SetCamara();
56 
57  RenderWindow->Render();
58 }
59 
61 {
62  this->RenderWindowUpdate();
63 
64  Interactor->Start();
65 }
66 
67 void vtkPolyDataViewer::SavePNG(const std::string& pngfile)
68 {
69  this->RenderWindowUpdate();
70 
71  vtkSmartPointer<vtkWindowToImageFilter> window2image= vtkWindowToImageFilter::New();
72  window2image->SetInput(RenderWindow);
73  vtkSmartPointer<vtkPNGWriter> png_writer = vtkPNGWriter::New();
74  png_writer->SetInputConnection(window2image->GetOutputPort());
75  png_writer->SetFileName(pngfile.c_str());
76  png_writer->Write();
77 }
78 
79 }
80 
81 
82 #endif
83 
Created "06-08-2017.
vtkSmartPointer< vtkRenderWindowInteractor > Interactor
void SavePNG(const std::string &pngfile)
void Add(const vtkSmartPointer< vtkPolyData > &mesh, const double opacity=1.0)
vtkSmartPointer< vtkLODActor > vtkPolyDataToActor(const vtkSmartPointer< vtkPolyData > &mesh, const double opacity=1.0, const std::vector< double > &hueRange={0.6667, 0.0}, bool useNormal=true, const std::vector< double > &scalarRange={-1.0,-1.0}, bool lighting=true)
vtkSmartPointer< vtkRenderer > Renderer
vtkSmartPointer< vtkRenderWindow > RenderWindow