18 #include <vtkCellArray.h> 19 #include <vtkProperty.h> 20 #include <vtkDataSetMapper.h> 21 #include <vtkLODActor.h> 22 #include <vtkPoints.h> 23 #include <vtkPolyData.h> 24 #include <vtkPolygon.h> 25 #include <vtkSmartPointer.h> 26 #include <vtkRenderer.h> 27 #include <vtkRenderWindow.h> 28 #include <vtkRenderWindowInteractor.h> 29 #include <vtkDelaunay3D.h> 30 #include <vtkVertexGlyphFilter.h> 31 #include <vtkPolyDataMapper.h> 32 #include <vtkSphereSource.h> 33 #include <vtkUnsignedCharArray.h> 34 #include <vtkPointData.h> 35 #include <vtkGlyph3D.h> 36 #include <vtkCamera.h> 38 #include <vtkWindowToImageFilter.h> 39 #include <vtkPNGWriter.h> 41 #include "OrientationsViewerCLP.h" 53 main (
int argc,
char *argv[] )
58 int numberOfShells = _OrientationFile.size();
60 std::cout << numberOfShells <<
" shells" << std::endl << std::flush;
62 if (!_OnlyCombined && _OpacityMesh.size()!=numberOfShells)
64 _OpacityMesh.resize(numberOfShells);
65 for (
int i = 0; i < numberOfShells; i += 1 )
66 _OpacityMesh[i]=1.0- 0.7/(
double)(numberOfShells-1)*i;
69 if (!_OnlyCombined && _OpacitySphere.size()!=numberOfShells)
71 _OpacitySphere.resize(numberOfShells);
72 for (
int i = 0; i < numberOfShells; i += 1 )
73 _OpacitySphere[i]=_OpacityMesh[i];
76 std::vector<std::vector<double> > radiusVec;
77 if (_RadiusFileArg.isSet())
79 double maxRadius = -1;
81 for (
int i = 0; i < numberOfShells; i += 1 )
83 std::vector<double> tmp;
85 radiusVec.push_back(tmp);
90 for (
int i = 0; i < numberOfShells; i += 1 )
91 for (
int j = 0; j < radiusVec[i].size(); j += 1 )
92 radiusVec[i][j] /= maxRadius;
96 if (_Radius.size()!=numberOfShells)
98 _Radius.resize(numberOfShells);
99 for (
int i = 0; i < numberOfShells; i += 1 )
104 if (_Color.size()!=3*numberOfShells)
106 _Color.resize(3*numberOfShells);
107 if (numberOfShells==1)
109 _Color[0]=1.0, _Color[1]=1.0, _Color[2]=1.0;
113 if (numberOfShells>1)
115 _Color[0]=1.0, _Color[1]=0.0, _Color[2]=0.0;
116 if (numberOfShells>=2)
117 _Color[3]=0.0, _Color[4]=1.0, _Color[5]=0.0;
118 if (numberOfShells==3)
119 _Color[6]=0.0, _Color[7]=0.0, _Color[8]=1.0;
121 if (numberOfShells>3 && numberOfShells<=6)
123 _Color[9]=0.5, _Color[10]=0.0, _Color[11]=0.0;
124 if (numberOfShells>=7)
125 _Color[12]=0.0, _Color[13]=0.5, _Color[14]=0.0;
126 if (numberOfShells==8)
127 _Color[15]=0.0, _Color[16]=0.0, _Color[17]=0.5;
133 vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
134 vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
135 renderer->SetBackground(_BackgroundColor[0], _BackgroundColor[1], _BackgroundColor[2]);
139 std::vector<vtkSmartPointer<vtkPoints> > points(numberOfShells+1);
140 std::vector<vtkSmartPointer<vtkPolyData> > polydata(numberOfShells+1);
141 std::vector<vtkSmartPointer<vtkGlyph3D> > glyph3D(numberOfShells+1);
143 std::vector<vtkSmartPointer<vtkVertexGlyphFilter> > vertexGlyphFilter(numberOfShells+1);
144 std::vector<vtkSmartPointer<vtkPolyDataMapper> > pointsMapper(numberOfShells+1);
145 std::vector<vtkSmartPointer<vtkLODActor> > pointsActor(numberOfShells+1);
147 std::vector<vtkSmartPointer<vtkDelaunay3D> > delaunay3D(numberOfShells+1);
148 std::vector<vtkSmartPointer<vtkDataSetMapper> > delaunayMapper(numberOfShells+1);
149 std::vector<vtkSmartPointer<vtkLODActor> > delaunayActor(numberOfShells+1);
151 std::vector<vtkSmartPointer<vtkSphereSource> > sphereSource(numberOfShells+1);
152 std::vector<vtkSmartPointer<vtkPolyDataMapper> > sphereMapper(numberOfShells+1);
153 std::vector<vtkSmartPointer<vtkLODActor> > sphereActor(numberOfShells+1);
155 unsigned char colorPoint[3] = {0, 0, 0};
156 vtkSmartPointer<vtkUnsignedCharArray> colors = vtkSmartPointer<vtkUnsignedCharArray>::New();
157 colors->SetName(
"colors");
161 points.back() = vtkSmartPointer<vtkPoints>::New();
162 polydata.back() = vtkSmartPointer<vtkPolyData>::New();
163 colors->SetNumberOfComponents(3);
166 vtkSmartPointer<vtkSphereSource> sphereSourceTemp = vtkSmartPointer<vtkSphereSource>::New();
167 sphereSourceTemp->SetCenter(0.0, 0.0, 0.0);
168 sphereSourceTemp->SetRadius(_SpherePointSize);
169 sphereSourceTemp->SetThetaResolution(20);
170 sphereSourceTemp->SetPhiResolution(20);
173 for (
int i = 0; i < _OrientationFile.size(); i += 1 )
175 SamplingType::Pointer sampling = SamplingType::New();
177 if (_NoSymmetricPoints)
182 std::cout <<
"shell " << i+1 <<
", " << sampling->GetNumberOfSamples() << (_NoSymmetricPoints?
" points":
" antipodal symmetric points") << std::endl << std::flush;
184 points[i] = vtkSmartPointer<vtkPoints>::New();
188 colorPoint[0] = (
unsigned char)(255*_Color[3*i]);
189 colorPoint[1] = (
unsigned char)(255*_Color[3*i+1]);
190 colorPoint[2] = (
unsigned char)(255*_Color[3*i+2]);
195 for (
unsigned int j = 0; j < sampling->GetNumberOfSamples(); j++ )
197 double x0 = (*sampling)[j][0];
198 double x1 = (*sampling)[j][1];
199 double x2 = (*sampling)[j][2];
201 if (_RadiusFileArg.isSet())
202 points[i]->InsertNextPoint( radiusVec[i][j]*x0, radiusVec[i][j]*x1, radiusVec[i][j]*x2 );
204 points[i]->InsertNextPoint( _Radius[i]*x0, _Radius[i]*x1, _Radius[i]*x2 );
207 points.back()->InsertNextPoint( x0, x1, x2 );
208 colors->InsertNextTupleValue(colorPoint);
212 polydata[i] = vtkSmartPointer<vtkPolyData>::New();
213 polydata[i]->SetPoints(points[i]);
216 if (!_NoPoints && !_OnlyCombined)
218 if (_PointType==
"SPHERE")
220 glyph3D[i] = vtkSmartPointer<vtkGlyph3D>::New();
221 glyph3D[i]->SetSourceConnection(sphereSourceTemp->GetOutputPort());
223 glyph3D[i]->Update();
224 pointsMapper[i] = vtkSmartPointer<vtkPolyDataMapper>::New();
227 else if (_PointType==
"VERTEX")
229 vertexGlyphFilter[i] = vtkSmartPointer<vtkVertexGlyphFilter>::New();
231 vertexGlyphFilter[i]->Update();
232 pointsMapper[i] = vtkSmartPointer<vtkPolyDataMapper>::New();
247 pointsActor[i] = vtkSmartPointer<vtkLODActor>::New();
248 pointsActor[i]->SetMapper(pointsMapper[i]);
249 pointsActor[i]->GetProperty()->SetColor(_Color[3*i],_Color[3*i+1],_Color[3*i+2]);
250 if (_PointType==
"VERTEX")
251 pointsActor[i]->GetProperty()->SetPointSize(_VertexPointSize);
253 renderer->AddActor(pointsActor[i]);
256 if (_Mesh && !_OnlyCombined)
258 delaunay3D[i] = vtkSmartPointer<vtkDelaunay3D>::New();
260 delaunay3D[i]->SetTolerance(1e-8);
261 delaunay3D[i]->SetOffset(10);
262 delaunay3D[i]->Update();
265 delaunayMapper[i] = vtkSmartPointer<vtkDataSetMapper>::New();
266 delaunayMapper[i]->SetInputConnection(delaunay3D[i]->GetOutputPort());
268 delaunayActor[i] = vtkSmartPointer<vtkLODActor>::New();
269 delaunayActor[i]->SetMapper(delaunayMapper[i]);
270 delaunayActor[i]->GetProperty()->SetColor(1,1,1);
271 delaunayActor[i]->GetProperty()->SetOpacity(_OpacityMesh[i]);
273 renderer->AddActor(delaunayActor[i]);
276 if (_Sphere && !_OnlyCombined)
278 sphereSource[i] = vtkSmartPointer<vtkSphereSource>::New();
279 sphereSource[i]->SetCenter(0.0, 0.0, 0.0);
280 utlGlobalException(_RadiusFileArg.isSet(),
"not support to visualize sphere if _RadiusFile is set");
281 sphereSource[i]->SetRadius(_Radius[i]);
282 sphereSource[i]->SetThetaResolution(50);
283 sphereSource[i]->SetPhiResolution(50);
285 sphereMapper[i] = vtkSmartPointer<vtkPolyDataMapper>::New();
286 sphereMapper[i]->SetInputConnection(sphereSource[i]->GetOutputPort());
288 sphereActor[i] = vtkSmartPointer<vtkLODActor>::New();
289 sphereActor[i]->SetMapper(sphereMapper[i]);
291 sphereActor[i]->GetProperty()->SetColor(1,1,1);
292 sphereActor[i]->GetProperty()->SetOpacity(_OpacitySphere[i]);
294 renderer->AddActor(sphereActor[i]);
300 polydata.back() = vtkSmartPointer<vtkPolyData>::New();
301 polydata.back()->SetPoints(points.back());
302 polydata.back()->GetPointData()->AddArray(colors);
306 vtkSmartPointer<vtkPolyData> polydata2 = vtkSmartPointer<vtkPolyData>::New();
307 if (_PointType==
"SPHERE")
309 glyph3D.back() = vtkSmartPointer<vtkGlyph3D>::New();
310 glyph3D.back()->SetSourceConnection(sphereSourceTemp->GetOutputPort());
312 glyph3D.back()->Update();
315 pointsMapper.back() = vtkSmartPointer<vtkPolyDataMapper>::New();
318 else if (_PointType==
"VERTEX")
320 vertexGlyphFilter.back() = vtkSmartPointer<vtkVertexGlyphFilter>::New();
322 vertexGlyphFilter.back()->Update();
325 pointsMapper.back() = vtkSmartPointer<vtkPolyDataMapper>::New();
326 vtkSetInputData(pointsMapper.back(), vertexGlyphFilter.back()->GetOutput());
329 pointsMapper.back()->ScalarVisibilityOn();
330 pointsMapper.back()->SetScalarModeToUsePointFieldData();
331 pointsMapper.back()->SetColorModeToDefault();
332 pointsMapper.back()->SelectColorArray(
"colors");
339 pointsActor.back() = vtkSmartPointer<vtkLODActor>::New();
340 pointsActor.back()->SetMapper(pointsMapper.back());
341 if (_PointType==
"VERTEX")
342 pointsActor.back()->GetProperty()->SetPointSize(_VertexPointSize);
344 renderer->AddActor(pointsActor.back());
349 delaunay3D.back() = vtkSmartPointer<vtkDelaunay3D>::New();
351 delaunay3D.back()->SetTolerance(1e-8);
352 delaunay3D.back()->SetOffset(10);
353 delaunay3D.back()->Update();
356 delaunayMapper.back() = vtkSmartPointer<vtkDataSetMapper>::New();
357 delaunayMapper.back()->SetInputConnection(delaunay3D.back()->GetOutputPort());
359 delaunayActor.back() = vtkSmartPointer<vtkLODActor>::New();
360 delaunayActor.back()->SetMapper(delaunayMapper.back());
361 delaunayActor.back()->GetProperty()->SetColor(1,1,1);
362 delaunayActor.back()->GetProperty()->SetOpacity(_OpacityMesh[0]);
364 renderer->AddActor(delaunayActor.back());
369 sphereSource.back() = vtkSmartPointer<vtkSphereSource>::New();
370 sphereSource.back()->SetCenter(0.0, 0.0, 0.0);
371 sphereSource.back()->SetRadius(1.0);
372 sphereSource.back()->SetThetaResolution(50);
373 sphereSource.back()->SetPhiResolution(50);
375 sphereMapper.back() = vtkSmartPointer<vtkPolyDataMapper>::New();
376 sphereMapper.back()->SetInputConnection(sphereSource.back()->GetOutputPort());
378 sphereActor.back() = vtkSmartPointer<vtkLODActor>::New();
379 sphereActor.back()->SetMapper(sphereMapper.back());
384 renderer->AddActor(sphereActor.back());
389 renderWindow->AddRenderer(renderer);
390 renderWindow->SetSize(_Window[0],_Window[1]);
392 vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
393 renderWindowInteractor->SetRenderWindow(renderWindow);
394 renderWindowInteractor->SetDesiredUpdateRate(25);
396 renderWindow->Render();
398 renderer->GetActiveCamera()->Roll(_Angle[0]);
399 renderer->GetActiveCamera()->Elevation(_Angle[1]);
401 renderWindow->Render();
405 vtkSmartPointer<vtkWindowToImageFilter> windowToImage = vtkSmartPointer<vtkWindowToImageFilter>::New();
406 windowToImage->SetInput(renderWindow);
408 vtkSmartPointer<vtkPNGWriter> pngWriter = vtkSmartPointer<vtkPNGWriter>::New();
409 pngWriter->SetInputConnection(windowToImage->GetOutputPort());
410 pngWriter->SetFileName(_PNGFile.c_str());
414 renderWindowInteractor->Start();
helper functions specifically used in dmritool
#define utlGlobalException(cond, expout)
this class describes sampling in a 3D space (Q space or R space).
#define vtkSetInputData(x, y)
int main(int argc, char *argv[])
orientations visualization
void ReadVector(const std::string &vectorStr, std::vector< T > &vec, const char *cc=" ")
T max_element(const std::vector< T > &v)