12 #ifndef __itkMeshFromPeaksImageFilter_hxx 13 #define __itkMeshFromPeaksImageFilter_hxx 16 #include <vtkTubeFilter.h> 20 template <
class TInputImage,
class TOutputMesh>
25 m_TubeRadius = 0.1*this->m_Scale;
26 m_MaxNumberOfPeaks = -1;
28 this->m_ColorScheme = Superclass::FIXED;
29 m_ColorPeak[0]=255, m_ColorPeak[1]=0, m_ColorPeak[2]=0;
32 template <
class TInputImage,
class TOutputMesh>
33 typename LightObject::Pointer
37 typename LightObject::Pointer loPtr = Superclass::InternalClone();
42 itkExceptionMacro(<<
"downcast to type " << this->GetNameOfClass()<<
" failed.");
45 rval->m_PeakType = m_PeakType;
46 rval->m_TubeRadius = m_TubeRadius;
47 rval->m_MaxNumberOfPeaks = m_MaxNumberOfPeaks;
49 for (
int i = 0; i < 3; ++i )
50 rval->m_ColorPeak[i] = m_ColorPeak[i];
56 template <
class TInputImage,
class TOutputMesh>
60 VerifyInputParameters();
72 ImageRegionConstIterator<InputImageType> inputIt(inputPtr, inputPtr->GetRequestedRegion());
74 vtkSmartPointer<OutputMeshPointsType> outputMeshPoints = vtkSmartPointer<OutputMeshPointsType>::New();
75 vtkSmartPointer<OutputMeshCellArrayType> outputMeshCellArray = vtkSmartPointer<OutputMeshCellArrayType>::New();
76 vtkSmartPointer<OutputMeshRGBType> outputMeshRGB = vtkSmartPointer<OutputMeshRGBType>::New();
77 outputMeshRGB->SetNumberOfComponents(3);
78 outputMeshRGB->SetName(
"RGB_scalars");
80 double outputMeshPoint1[3];
81 double outputMeshPoint2[3];
82 unsigned int numberOfCellPoints = 2;
84 unsigned long offset=0;
88 int realNumberOfPeaks = m_MaxNumberOfPeaks>0 ?
utl::min(numberOfPeaks, m_MaxNumberOfPeaks) : numberOfPeaks;
91 std::vector<double> peak(3);
94 while( !inputIt.IsAtEnd() )
96 inputIndex = inputIt.GetIndex();
97 if (!this->IsPixelIndexVisible(inputIndex))
103 inputPtr->TransformIndexToPhysicalPoint(inputIndex, inputPhysicalPoint);
104 inputPixel = inputIt.Get();
106 for (
unsigned int k=0;k<realNumberOfPeaks;k++)
110 for (
int d = 0; d < 3; ++d )
111 peak[d] = this->m_Flip[d]? -peak[d] : peak[d];
113 for (
unsigned int d=0; d<3; d++)
115 norm += peak[d]*peak[d];
117 outputMeshPoint1[d] = peak[d] * this->m_Scale + inputPhysicalPoint[d];
118 outputMeshPoint2[d] = -peak[d] * this->m_Scale + inputPhysicalPoint[d];
119 if (this->m_ColorScheme==Superclass::DIRECTION)
120 RGB[d] =
static_cast<VTK_TYPE_NAME_UNSIGNED_CHAR
>(std::fabs(peak[d])*255.0);
122 RGB[d] =
static_cast<VTK_TYPE_NAME_UNSIGNED_CHAR
>(m_ColorPeak[d]);
127 outputMeshPoints->InsertNextPoint( outputMeshPoint1 );
128 outputMeshPoints->InsertNextPoint( outputMeshPoint2 );
129 outputMeshRGB->InsertNextTupleValue(RGB);
130 outputMeshRGB->InsertNextTupleValue(RGB);
132 outputMeshCellArray->InsertNextCell(numberOfCellPoints);
134 for( vtkIdType p = 0; p < numberOfCellPoints; p++ )
135 outputMeshCellArray->InsertCellPoint( offset + p );
137 offset += numberOfCellPoints;
145 this->m_Mesh->SetPoints( outputMeshPoints );
146 this->m_Mesh->SetLines( outputMeshCellArray );
147 this->m_Mesh->GetPointData()->SetScalars( outputMeshRGB );
151 vtkSmartPointer<vtkTubeFilter> tubeFilter = vtkTubeFilter::New();
152 tubeFilter->SetInputData(this->m_Mesh);
153 tubeFilter->SetRadius(m_TubeRadius);
154 tubeFilter->SetNumberOfSides(6);
155 tubeFilter->SetCapping(1);
156 tubeFilter->Update();
157 this->m_Mesh = tubeFilter->GetOutput();
MeshFromPeaksImageFilter()
InputImageType::RegionType InputImageRegionType
InputImageType::PointType InputImagePointType
const T & min(const T &a, const T &b)
Return the minimum between a and b.
Compute mesh from SH coefficients.
InputImageType::ConstPointer InputImageConstPointer
static VectorType GetPeak(const ContainerType &vec, const int index, const PeakType peakType)
LightObject::Pointer InternalClone() const ITK_OVERRIDE
static int GetNumberOfPeaks(const PeakType peakType, const int dimension)
virtual void GenerateData() ITK_OVERRIDE
InputImageType::PixelType InputImagePixelType
InputImageType::IndexType InputImageIndexType
SmartPointer< Self > Pointer
static int GetDimensionPerPeak(const PeakType peakType)