DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
MeshFromSphericalFunctionTessellatedSamples.cxx
Go to the documentation of this file.
1 
20 #include "MeshFromSphericalFunctionTessellatedSamplesCLP.h"
21 #include "vtkPolyDataWriter.h"
22 #include "utl.h"
23 #include "utlVTK.h"
24 #include "vtkPolyDataViewer.h"
25 
28 
29 
36 int
37 main(int argc, char *argv[])
38 {
39  PARSE_ARGS;
40 
41  utlGlobalException(_BoxView.size()!=6, "need 6 parameters in --box");
42  utlGlobalException(_SliceView.size()!=3, "need 3 parameters in --box");
43  utlGlobalException(_Flip.size()!=3, "need 3 parameters in --flip");
44 
45  // Define Variables
46  typedef float PixelType;
47  typedef itk::VectorImage<PixelType, 3> InputImageType;
48 
49  InputImageType::Pointer inputImage = InputImageType::New();
50  if (itk::IsSparseImage(_InputFile))
51  {
52  typedef itk::SpatiallyDenseSparseVectorImage<PixelType, 3> InputSparseImageType;
53 
54  InputSparseImageType::Pointer inputSparseImage = InputSparseImageType::New();
56 
57  itk::ReadImage<InputSparseImageType, ReaderType>(_InputFile, inputSparseImage);
58  itk::ImageToImage<InputSparseImageType, InputImageType>(inputSparseImage, inputImage);
59  }
60  else
61  itk::ReadVectorImage(_InputFile, inputImage);
62 
63  // Create mesh
65  MeshCreatorType::Pointer filter = MeshCreatorType::New();
66  filter->SetScale( _Scale );
67 
68  if (_Normalization=="NONE") filter->SetNormalization( MeshCreatorType::NONE );
69  if (_Normalization=="MIN_MAX") filter->SetNormalization( MeshCreatorType::MIN_MAX );
70  if (_Normalization=="UNIT_MAX") filter->SetNormalization( MeshCreatorType::UNIT_MAX );
71  if (_Normalization=="UNIT_INTEGRAL") filter->SetNormalization( MeshCreatorType::UNIT_INTEGRAL );
72 
73  filter->SetPow(_Pow);
74  filter->SetRemoveNegativeValues(_RemoveNegativeValuesArg.isSet());
75  filter->SetStretch(!_NoStretchArg.isSet());
76  filter->SetInput( inputImage );
77 
78  filter->SetBoxView(_BoxView[0], _BoxView[1], _BoxView[2], _BoxView[3], _BoxView[4], _BoxView[5]);
79  filter->SetSliceView(_SliceView[0], _SliceView[1], _SliceView[2]);
80  filter->SetFlip(_Flip[0], _Flip[1], _Flip[2]);
81 
82  if (_BasicShape == "TETRAHEDRON") { filter->SetBasicShape(MeshCreatorType::SphereTessellatorType::TETRAHEDRON); }
83  if (_BasicShape == "OCTAHEDRON") { filter->SetBasicShape(MeshCreatorType::SphereTessellatorType::OCTAHEDRON); }
84  if (_BasicShape == "ICOSAHEDRON") { filter->SetBasicShape(MeshCreatorType::SphereTessellatorType::ICOSAHEDRON); }
85  filter->SetTessellationOrder(_TessellationOrder);
86 
87  if (_ColorScheme == "DIRECTION") { filter->SetColorScheme(MeshCreatorType::DIRECTION); }
88  if (_ColorScheme == "MAGNITUDE") { filter->SetColorScheme(MeshCreatorType::MAGNITUDE); }
89 
90  if (_SingleThreadArg.isSet())
91  filter->SetNumberOfThreads(1);
92  filter->SetDebug(_DebugArg.isSet());
93 
94  MeshCreatorType::MatrixPointer grad = utl::ReadGrad<double>(_OrientationsFile, DIRECTION_NODUPLICATE, CARTESIAN_TO_CARTESIAN);
95  filter->SetDataOrientations(grad);
96 
97  std::cout << "Generating mesh ... " << std::flush;
98  filter->Update();
99 
100  MeshCreatorType::OutputMeshPolyDataType* mesh = filter->GetOutput();
101 
102  if (_OutputFileArg.isSet())
103  {
104  utl::WriteVtkPolyData(mesh, _OutputFile);
105  }
106  else
107  {
108  utlGlobalException(_WindowSize.size()!=2, "wrong window size");
109  utlGlobalException(_Angle.size()!=2, "wrong angle size");
110  utlGlobalException(_BackgroundColor.size()!=3, "wrong size of background color");
111  vtk::VisualizePolyData(mesh, _Angle, _WindowSize, !_NoNormalArg.isSet(), !_NoLightingArg.isSet(), _Zoom, _PNGFile, _BackgroundColor);
112  }
113 
114  return EXIT_SUCCESS;
115 }
Compute mesh from spherical samples in the pre-stored tessellated vertices.
helper functions specifically used in dmritool
Created "06-08-2017.
Created "06-06-2017.
void ReadVectorImage(const std::string &filename, SmartPointer< VectorImage< PixelType, 3 > > &image, const std::string &printInfo="Reading Image:")
Definition: utl.h:66
bool IsSparseImage(const std::string &filename)
Definition: utlITK.h:426
#define utlGlobalException(cond, expout)
Definition: utlCoreMacro.h:372
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})
int main(int argc, char *argv[])
Mesh From spherical samples using a given tessellation Create mesh (a spherical function) from discre...
An n-dimensional vector image with a sparse memory model.
void WriteVtkPolyData(vtkPolyData *mesh, const std::string &filename)
Definition: utlVTK.h:45