11 #ifndef __vtkPolyDataViewer_h 12 #define __vtkPolyDataViewer_h 14 #include <vtkObject.h> 15 #include <vtkPolyData.h> 16 #include <vtkPointData.h> 17 #include <vtkLookupTable.h> 18 #include <vtkSmartPointer.h> 19 #include <vtkRenderer.h> 21 #include <vtkProperty.h> 23 #include <vtkCamera.h> 24 #include <vtkPolyDataMapper.h> 25 #include <vtkPolyDataWriter.h> 26 #include <vtkWindowToImageFilter.h> 27 #include <vtkPNGWriter.h> 28 #include <vtkLODActor.h> 29 #include <vtkPolyDataNormals.h> 30 #include <vtkObjectFactory.h> 33 #include <vtkRenderWindow.h> 34 #include <vtkRenderWindowInteractor.h> 42 inline vtkSmartPointer<vtkLODActor>
43 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 )
45 vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
49 vtkSmartPointer<vtkPolyDataNormals> polyDataNormals = vtkPolyDataNormals::New();
50 polyDataNormals->SetInputData(mesh);
51 mapper->SetInputConnection(polyDataNormals->GetOutputPort());
54 mapper->SetInputData(mesh);
57 if (mesh->GetPointData()->GetScalars() && mesh->GetPointData()->GetScalars()->GetNumberOfComponents()==1)
59 vtkSmartPointer<vtkLookupTable> lut = vtkLookupTable::New();
60 double* valueRange = mesh->GetScalarRange();
62 rangeUsed[0] = std::fabs(scalarRange[0]+1.0) < 1.0e-8 ? valueRange[0] : scalarRange[0];
63 rangeUsed[1] = std::fabs(scalarRange[1]+1.0) < 1.0e-8 ? valueRange[1] : scalarRange[1];
65 lut->SetTableRange(rangeUsed[0], rangeUsed[1]);
66 lut->SetHueRange(hueRange[0],hueRange[1]);
67 lut->SetRampToLinear();
70 mapper->SetLookupTable(lut);
71 mapper->SetScalarRange(rangeUsed[0], rangeUsed[1]);
74 vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::New();
75 actor->SetMapper(mapper);
77 actor->GetProperty()->SetLighting(lighting);
78 actor->GetProperty()->SetOpacity(opacity);
115 void Add(
const vtkSmartPointer<vtkPolyData>& mesh,
const double opacity=1.0);
118 void Add(
const vtkSmartPointer<vtkPolyData>& mesh,
const double opacity,
const std::vector<double>& hueRange,
bool useNormal,
const std::vector<double>& scalarRange={-1.0,-1.0},
bool lighting=true );
120 void Add(
const vtkSmartPointer<vtkLODActor>& actor)
132 void SavePNG(
const std::string& pngfile);
146 vtkSmartPointer<vtkRenderer>
Renderer = vtkSmartPointer<vtkRenderer>::New();
148 vtkSmartPointer<vtkRenderWindow>
RenderWindow = vtkSmartPointer<vtkRenderWindow>::New();
149 vtkSmartPointer<vtkRenderWindowInteractor>
Interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
172 VisualizePolyDataWithScalarRange (
const std::vector<vtkPolyData*>& meshes,
const std::vector<double>& opacity,
const std::vector<double>& scalarRange={-1.0,-1.0},
const std::vector<double>& hueRange={0.6667,0.0},
const std::vector<double>& angle={0.0,0.0},
const std::vector<int>& windowSize={600,600},
const bool useNormal=
true,
const bool lighting=
true,
const double zoom=1.0,
const std::string& pngfile=
"",
const std::vector<double>& bgColor={0,0,0} )
176 viewer->SetScalarRange(scalarRange[0], scalarRange[1]);
177 viewer->SetHueRange(hueRange[0], hueRange[1]);
178 viewer->SetAngle(angle[0], angle[1]);
179 viewer->SetWindowSize(windowSize[0], windowSize[1]);
180 viewer->SetUseNormal(useNormal);
181 viewer->SetLighting(lighting);
182 viewer->SetZoom(zoom);
183 viewer->SetBackground(bgColor[0], bgColor[1], bgColor[2]);
185 utlException(meshes.size()!=opacity.size(),
"meshes and opacity should have the same size");
187 for (
int i = 0; i < meshes.size(); ++i )
190 viewer->Add(meshes[i], opacity[i]);
196 viewer->SavePNG(pngfile);
201 VisualizePolyDataWithScalarRange ( vtkPolyData* mesh,
const std::vector<double>& scalarRange={-1.0,-1.0},
const std::vector<double>& hueRange={0.6667,0.0},
const std::vector<double>& angle={0.0,0.0},
const std::vector<int>& windowSize={600,600},
const bool useNormal=
true,
const bool lighting=
true,
const double zoom=1.0,
const std::string& pngfile=
"",
const std::vector<double>& bgColor={0,0,0} )
205 viewer->SetScalarRange(scalarRange[0], scalarRange[1]);
206 viewer->SetHueRange(hueRange[0], hueRange[1]);
207 viewer->SetAngle(angle[0], angle[1]);
208 viewer->SetWindowSize(windowSize[0], windowSize[1]);
209 viewer->SetUseNormal(useNormal);
210 viewer->SetLighting(lighting);
211 viewer->SetZoom(zoom);
212 viewer->SetBackground(bgColor[0], bgColor[1], bgColor[2]);
219 viewer->SavePNG(pngfile);
224 VisualizePolyData ( vtkPolyData* mesh,
const std::vector<double>& angle={0.0,0.0},
const std::vector<int>& windowSize={600,600},
const bool useNormal=
true,
const bool lighting=
true,
const double zoom=1.0,
const std::string& pngfile=
"",
const std::vector<double>& bgColor={0,0,0} )
226 VisualizePolyDataWithScalarRange(mesh, {-1.0,-1.0}, {0.6667,0.0}, angle, windowSize, useNormal, lighting, zoom, pngfile, bgColor);
232 #if !defined(__vtkPolyDataViewer_hxx)
vtkSetMacro(UseNormal, bool)
vtkSmartPointer< vtkRenderWindowInteractor > Interactor
void RenderWindowUpdate()
#define utlException(cond, expout)
vtkStandardNewMacro(vtkPolyDataViewer)
vtkTypeMacro(vtkPolyDataViewer, vtkObject)
void Add(const vtkSmartPointer< vtkLODActor > &actor)
static vtkPolyDataViewer * New()
void SavePNG(const std::string &pngfile)
helper class to visualize vtkPolyData.
void VisualizePolyData(vtkPolyData *mesh, const std::vector< double > &angle={0.0, 0.0}, const std::vector< int > &windowSize={600, 600}, const bool useNormal=true, const bool lighting=true, const double zoom=1.0, const std::string &pngfile="", const std::vector< double > &bgColor={0, 0, 0})
vtkGetMacro(UseNormal, bool)
void VisualizePolyDataWithScalarRange(const std::vector< vtkPolyData * > &meshes, const std::vector< double > &opacity, const std::vector< double > &scalarRange={-1.0,-1.0}, const std::vector< double > &hueRange={0.6667, 0.0}, const std::vector< double > &angle={0.0, 0.0}, const std::vector< int > &windowSize={600, 600}, const bool useNormal=true, const bool lighting=true, const double zoom=1.0, const std::string &pngfile="", const std::vector< double > &bgColor={0, 0, 0})
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)
vtkGetVector2Macro(Angle, double)
void SetBackground(double r, double g, double b)
vtkSmartPointer< vtkRenderer > Renderer
vtkSmartPointer< vtkRenderWindow > RenderWindow
vtkSetVector2Macro(ScalarRange, double)