DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
MeshFromPeaks.cxx
Go to the documentation of this file.
1 
12 #include "MeshFromPeaksCLP.h"
13 
14 #include "vtkPolyDataWriter.h"
15 
17 
18 #include "utl.h"
19 #include "utlVTK.h"
20 
21 #include "vtkPolyDataViewer.h"
22 
26  int
27 main (int argc, char const* argv[])
28 {
29  PARSE_ARGS;
30 
31  typedef double PixelType;
32  typedef itk::VectorImage<PixelType, 3> InputImageType;
33 
34  // Time Probe
35  itk::TimeProbe clock;
36 
37  utlGlobalException(_BoxView.size()!=6, "need 6 parameters in --box");
38  utlGlobalException(_SliceView.size()!=3, "need 3 parameters in --box");
39  utlGlobalException(_Flip.size()!=3, "need 3 parameters in --flip");
40 
41  InputImageType::Pointer inputImage;
42  itk::ReadVectorImage(_InputFile, inputImage);
43 
44  typedef itk::MeshFromPeaksImageFilter<InputImageType> MeshCreatorType;
45  MeshCreatorType::Pointer filter = MeshCreatorType::New();
46 
47  filter->SetInput( inputImage );
48  filter->SetPeakType(itk::PeakContainerHelper::GetPeakType(_PeakType));
49  if (_ColorScheme == "DIRECTION") { filter->SetColorScheme(MeshCreatorType::DIRECTION); }
50  if (_ColorScheme == "FIXED") { filter->SetColorScheme(MeshCreatorType::FIXED); }
51  utlGlobalException(_ColorPeak.size()!=3, "wrong size of _ColorPeak");
52  filter->SetColorPeak(_ColorPeak[0], _ColorPeak[1], _ColorPeak[2]);
53  filter->SetMaxNumberOfPeaks(_MaxNumber);
54 
55  filter->SetScale( _Scale );
56  filter->SetTubeRadius( _TubeRadius );
57 
58  filter->SetFlip(_Flip[0], _Flip[1], _Flip[2]);
59  filter->SetBoxView(_BoxView[0], _BoxView[1], _BoxView[2], _BoxView[3], _BoxView[4], _BoxView[5]);
60  filter->SetSliceView(_SliceView[0], _SliceView[1], _SliceView[2]);
61 
63  if (_ShowProgressArg.isSet())
64  filter->AddObserver( itk::ProgressEvent(), observer );
65  if (_SingleThreadArg.isSet())
66  filter->SetNumberOfThreads(1);
67  filter->SetDebug(_DebugArg.isSet());
68 
69  std::cout << "Generating mesh ... " << std::flush;
70  clock.Start();
71  filter->Update();
72  clock.Stop();
73  std::cout << clock.GetMean() << "s elapsed" << std::endl;
74 
75  MeshCreatorType::OutputMeshPolyDataType* mesh = filter->GetOutput();
76 
77  if (_OutputFileArg.isSet())
78  {
79  utl::WriteVtkPolyData(mesh, _OutputFile);
80  }
81  else
82  {
83  utlGlobalException(_WindowSize.size()!=2, "wrong window size");
84  utlGlobalException(_Angle.size()!=2, "wrong angle size");
85  utlGlobalException(_BackgroundColor.size()!=3, "wrong size of background color");
86  vtk::VisualizePolyData(mesh, _Angle, _WindowSize, !_NoNormalArg.isSet(), !_NoLightingArg.isSet(), _Zoom, _PNGFile, _BackgroundColor);
87  }
88 
89  return EXIT_SUCCESS;
90 
91 
92  return 0;
93 }
helper functions specifically used in dmritool
Created "06-08-2017.
Created "06-06-2017.
Generate a mesh from given peaks.
Created "08-26-2016.
void ReadVectorImage(const std::string &filename, SmartPointer< VectorImage< PixelType, 3 > > &image, const std::string &printInfo="Reading Image:")
Definition: utl.h:66
static PeakType GetPeakType(const std::string &str)
#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 const *argv[])
Gnerate mesh from peaks.
void WriteVtkPolyData(vtkPolyData *mesh, const std::string &filename)
Definition: utlVTK.h:45