20 #include <vtkAppendPolyData.h> 21 #include <vtkCamera.h> 22 #include <vtkColorTransferFunction.h> 23 #include <vtkDataSetReader.h> 24 #include <vtkDataSetSurfaceFilter.h> 25 #include <vtkFloatArray.h> 26 #include <vtkGlyph3D.h> 27 #include <vtkOBJReader.h> 28 #include <vtkPDBReader.h> 29 #include <vtkPLYReader.h> 30 #include <vtkPNGWriter.h> 31 #include <vtkPointData.h> 32 #include <vtkPolyData.h> 33 #include <vtkPolyDataMapper.h> 34 #include <vtkPolyDataNormals.h> 35 #include <vtkPolyDataReader.h> 36 #include <vtkProperty.h> 37 #include <vtkRenderWindow.h> 38 #include <vtkSphereSource.h> 39 #include <vtkSTLReader.h> 40 #include <vtkTubeFilter.h> 41 #include <vtkVersion.h> 42 #include <vtkWindowToImageFilter.h> 43 #include <vtkXMLImageDataReader.h> 44 #include <vtkXMLPolyDataReader.h> 45 #include <vtkXMLRectilinearGridReader.h> 46 #include <vtkXMLStructuredGridReader.h> 47 #include <vtkXMLUnstructuredGridReader.h> 48 #if VTK_MAJOR_VERSION <= 5 49 #define setInputData(x,y) ((x)->SetInput(y)) 50 #define addInputData(x,y) ((x)->AddInput(y)) 52 #define setInputData(x,y) ((x)->SetInputData(y)) 53 #define addInputData(x,y) ((x)->AddInputData(y)) 60 static vtkSmartPointer< vtkPolyData >
ReadPDB(
61 const char * file_name)
63 vtkSmartPointer<vtkPDBReader> pdb =
64 vtkSmartPointer<vtkPDBReader>::New();
65 pdb->SetFileName(file_name);
70 vtkSmartPointer<vtkSphereSource> sphere =
71 vtkSmartPointer<vtkSphereSource>::New();
72 sphere->SetCenter(0, 0, 0);
75 vtkSmartPointer<vtkGlyph3D> glyph =
76 vtkSmartPointer<vtkGlyph3D>::New();
77 glyph->SetInputConnection(pdb->GetOutputPort());
78 glyph->SetSourceConnection(sphere->GetOutputPort());
80 glyph->SetColorMode(1);
81 glyph->SetScaleMode(2);
82 glyph->SetScaleFactor(.25);
85 vtkSmartPointer<vtkTubeFilter> tube =
86 vtkSmartPointer<vtkTubeFilter>::New();
87 tube->SetInputConnection(pdb->GetOutputPort());
88 tube->SetNumberOfSides(6);
91 tube->SetVaryRadius(0);
92 tube->SetRadiusFactor(10);
95 vtkSmartPointer< vtkPolyData > tubeMesh =
96 vtkSmartPointer< vtkPolyData >::New();
97 tubeMesh->ShallowCopy(tube->GetOutput());
98 vtkIdType N = tubeMesh->GetNumberOfPoints();
100 vtkUnsignedCharArray * rgb_colors
101 = vtkUnsignedCharArray::SafeDownCast(
102 tubeMesh->GetPointData()->GetArray(
"rgb_colors"));
103 const unsigned char tuple[3] = {127,127,127};
104 if ((rgb_colors != NULL) & (rgb_colors->GetNumberOfComponents() == 3))
105 for (vtkIdType i = 0; i < N ; ++i)
106 rgb_colors->SetTupleValue(i, tuple);
108 vtkSmartPointer< vtkAppendPolyData > appendFilter =
109 vtkSmartPointer< vtkAppendPolyData >::New();
110 appendFilter->AddInputConnection(glyph->GetOutputPort());
112 appendFilter->Update();
114 vtkSmartPointer< vtkPolyData > polyData = appendFilter->GetOutput();
119 vtkAlgorithmOutput * outputPort)
121 vtkSmartPointer< vtkDataSetSurfaceFilter > dataSetSurfaceFilter =
122 vtkSmartPointer< vtkDataSetSurfaceFilter >::New();
123 dataSetSurfaceFilter->SetInputConnection(outputPort);
124 dataSetSurfaceFilter->Update();
125 vtkSmartPointer< vtkPolyData > polyData =
126 dataSetSurfaceFilter->GetOutput();
130 template <
typename T>
131 static vtkSmartPointer< vtkPolyData >
read(
const char * file_name)
133 vtkSmartPointer< T > reader = vtkSmartPointer< T >::New();
134 reader->SetFileName(file_name);
136 vtkSmartPointer< vtkPolyData > polyData =
141 template <
typename T>
142 static vtkSmartPointer< vtkPolyData >
readDataSet(
const char * file_name)
144 vtkSmartPointer< T > reader = vtkSmartPointer< T >::New();
145 reader->SetFileName(file_name);
152 vtkSmartPointer < vtkDataSetReader > reader =
153 vtkSmartPointer < vtkDataSetReader >::New();
154 reader->SetFileName(file_name);
156 if (NULL != reader->GetPolyDataOutput())
158 vtkSmartPointer< vtkPolyData > polyData =
159 reader->GetPolyDataOutput();
163 (NULL != reader->GetUnstructuredGridOutput()) ||
164 (NULL != reader->GetStructuredPointsOutput()) ||
165 (NULL != reader->GetStructuredGridOutput()) ||
166 (NULL != reader->GetRectilinearGridOutput()))
172 std::cerr <<
"unsupported: ????????\n";
173 return vtkSmartPointer< vtkPolyData >::New();
178 if (stereoType ==
"CRYSTAL_EYES")
180 return (VTK_STEREO_CRYSTAL_EYES);
182 else if (stereoType ==
"RED_BLUE")
184 return (VTK_STEREO_RED_BLUE);
186 else if (stereoType ==
"INTERLACED")
188 return (VTK_STEREO_INTERLACED);
190 else if (stereoType ==
"LEFT")
192 return (VTK_STEREO_LEFT);
194 else if (stereoType ==
"RIGHT")
196 return (VTK_STEREO_RIGHT);
198 else if (stereoType ==
"DRESDEN")
200 return (VTK_STEREO_DRESDEN);
202 else if (stereoType ==
"ANAGLYPH")
204 return (VTK_STEREO_ANAGLYPH);
206 else if (stereoType ==
"CHECKERBOARD")
208 return (VTK_STEREO_CHECKERBOARD);
210 #ifdef VTK_STEREO_SPLITVIEWPORT_HORIZONTAL 211 else if (stereoType ==
"SPLITVIEWPORT_HORIZONTAL")
213 return (VTK_STEREO_SPLITVIEWPORT_HORIZONTAL);
223 m_renderer(vtkSmartPointer < vtkRenderer >::New())
225 vtkSmartPointer < vtkRenderWindow > renderWindow =
226 vtkSmartPointer < vtkRenderWindow >::New();
227 renderWindow->StereoCapableWindowOn();
229 QByteArray stereoType = qgetenv(
"STEREO_TYPE" );
231 if (vtkStereoType != -1)
233 renderWindow->SetStereoType(vtkStereoType);
237 renderWindow->SetStereoType(VTK_STEREO_RED_BLUE);
242 this->SetRenderWindow(renderWindow);
243 this->resize(480, 480);
245 connect(&(
m_timer), SIGNAL(timeout()),
this, SLOT(
rotate()));
258 polyData->GetScalarRange(range);
266 vtkSmartPointer < vtkPolyDataMapper > mapper =
267 vtkSmartPointer < vtkPolyDataMapper >::New();
269 if (polyData->GetPointData()->GetNormals() == NULL)
271 vtkSmartPointer< vtkPolyDataNormals > polyDataNormals
272 = vtkSmartPointer< vtkPolyDataNormals >::New();
275 mapper->SetInputConnection(polyDataNormals->GetOutputPort());
281 vtkSmartPointer < vtkActor > actor =
282 vtkSmartPointer < vtkActor >::New();
283 actor->GetProperty()->SetPointSize(3);
284 actor->SetMapper(mapper);
291 QString filename = QString::fromUtf8(file_name).toLower();
292 if (filename.endsWith(
".vtk"))
296 else if (filename.endsWith(
".vtp"))
298 this->
add(read< vtkXMLPolyDataReader >(file_name));
300 else if (filename.endsWith(
".ply"))
302 this->
add(read< vtkPLYReader >(file_name));
304 else if (filename.endsWith(
".obj"))
306 this->
add(read< vtkOBJReader >(file_name));
308 else if (filename.endsWith(
".stl"))
310 this->
add(read< vtkSTLReader >(file_name));
312 else if (filename.endsWith(
".vtu"))
314 vtkSmartPointer< vtkXMLUnstructuredGridReader > reader =
315 vtkSmartPointer< vtkXMLUnstructuredGridReader >::New();
316 reader->SetFileName(file_name);
320 else if (filename.endsWith(
".pdb"))
324 else if (filename.endsWith(
".vti"))
326 this->
add(readDataSet< vtkXMLImageDataReader >(file_name));
328 else if (filename.endsWith(
".vts"))
330 this->
add(readDataSet< vtkXMLStructuredGridReader >(file_name));
332 else if (filename.endsWith(
".vtr"))
334 this->
add(readDataSet< vtkXMLRectilinearGridReader >(file_name));
338 std::cerr << file_name
339 <<
": BAD FILE NAME. " 340 "Should end in VTK, VTP, PLY, OBJ, STL, VTU, or PDB.\n";
356 vtkCamera * camera =
m_renderer->GetActiveCamera();
357 assert(camera != NULL);
364 vtkRenderWindow * rw =
m_renderer->GetRenderWindow();
366 rw->SetStereoType(vtkStereoType);
371 vtkRenderWindow * rw =
m_renderer->GetRenderWindow();
373 rw->SetStereoRender(! rw->GetStereoRender());
379 vtkRenderWindow * rw =
m_renderer->GetRenderWindow();
381 int type = rw->GetStereoType();
382 type = (type % 9) + 1;
386 case 1: cout <<
"VTK_STEREO_CRYSTAL_EYES\n";
break;
387 case 2: cout <<
"VTK_STEREO_RED_BLUE\n";
break;
388 case 3: cout <<
"VTK_STEREO_INTERLACED\n";
break;
389 case 4: cout <<
"VTK_STEREO_LEFT\n";
break;
390 case 5: cout <<
"VTK_STEREO_RIGHT\n";
break;
391 case 6: cout <<
"VTK_STEREO_DRESDEN\n";
break;
392 case 7: cout <<
"VTK_STEREO_ANAGLYPH\n";
break;
393 case 8: cout <<
"VTK_STEREO_CHECKERBOARD\n";
break;
394 case 9: cout <<
"VTK_STEREO_SPLITVIEWPORT_HORIZONTAL\n";
break;
401 vtkSmartPointer< vtkWindowToImageFilter > windowToImageFilter =
402 vtkSmartPointer< vtkWindowToImageFilter >::New();
403 windowToImageFilter->SetInput( this->GetRenderWindow() );
404 windowToImageFilter->SetMagnification(2);
405 windowToImageFilter->SetInputBufferTypeToRGBA();
406 windowToImageFilter->Update();
407 vtkSmartPointer< vtkPNGWriter > writer =
408 vtkSmartPointer< vtkPNGWriter >::New();
409 writer->SetInputConnection(windowToImageFilter->GetOutputPort());
410 const char filename[] =
"/tmp/screenshot.png";
411 writer->SetFileName(filename);
413 cout << filename <<
'\n';
#define setInputData(x, y)
void add(vtkPolyData *polyData)
vtkSmartPointer< vtkRenderer > m_renderer
static vtkSmartPointer< vtkPolyData > ConvertDataSetToSurface(vtkAlgorithmOutput *outputPort)
static vtkSmartPointer< vtkPolyData > read(const char *file_name)
static vtkSmartPointer< vtkPolyData > readDataSet(const char *file_name)
static vtkSmartPointer< vtkPolyData > ReadLegacyVTK(const char *file_name)
static vtkSmartPointer< vtkPolyData > ReadPDB(const char *file_name)
void setsize(double s1, double s2)
int GetVTKStereoType(const QByteArray &stereoType)
void setStereoType(int vtkStereoType)
#define addInputData(x, y)