ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkCuberilleImageToMeshFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkCuberilleImageToMeshFilter_h
19 #define itkCuberilleImageToMeshFilter_h
20 
21 #define DEBUG_PRINT 0
22 #define USE_GRADIENT_RECURSIVE_GAUSSIAN 0
23 #define USE_ADVANCED_PROJECTION 0
24 #define USE_LINESEARCH_PROJECTION 0
25 
26 #include "itkMacro.h"
27 #include "itkMesh.h"
28 #include "itkImageToMeshFilter.h"
29 #include "itkCellInterface.h"
30 #include "itkTriangleCell.h"
31 #include "itkQuadrilateralCell.h"
35 #include "itkGradientImageFilter.h"
38 
39 namespace itk
40 {
41 
113 template < class TInputImage, class TOutputMesh, class TInterpolator=itk::LinearInterpolateImageFunction<TInputImage> >
114 class CuberilleImageToMeshFilter : public ImageToMeshFilter< TInputImage, TOutputMesh >
115 {
116 public:
117  ITK_DISALLOW_COPY_AND_ASSIGN(CuberilleImageToMeshFilter);
118 
124 
126  itkNewMacro(Self);
127 
130 
132  using OutputMeshType = TOutputMesh;
133  using OutputMeshPointer = typename OutputMeshType::Pointer;
134  using OutputMeshTraits = typename OutputMeshType::MeshTraits;
136  using OutputPixelType = typename OutputMeshTraits::PixelType;
137  using CellTraits = typename OutputMeshType::CellTraits;
138  using PointsContainerPointer = typename OutputMeshType::PointsContainerPointer;
139  using PointsContainer = typename OutputMeshType::PointsContainer;
140  using CellsContainerPointer = typename OutputMeshType::CellsContainerPointer;
141  using CellsContainer = typename OutputMeshType::CellsContainer;
142  using PointIdentifier = typename OutputMeshType::PointIdentifier;
143  using CellIdentifier = typename OutputMeshType::CellIdentifier;
146  using TriangleAutoPointer = typename TriangleCellType::SelfAutoPointer;
147  using TriangleCellAutoPointer = typename TriangleCellType::CellAutoPointer;
149  using QuadrilateralAutoPointer = typename QuadrilateralCellType::SelfAutoPointer;
150  using QuadrilateralCellAutoPointer = typename QuadrilateralCellType::CellAutoPointer;
151 
152  using InputImageType = TInputImage;
153  using InputImagePointer = typename InputImageType::Pointer;
154  using InputImageConstPointer = typename InputImageType::ConstPointer;
155  using InputPixelType = typename InputImageType::PixelType;
157  using SpacingType = typename InputImageType::SpacingType;
158  using SpacingValueType = typename InputImageType::SpacingValueType;
161 
162  using InterpolatorType = TInterpolator;
163  using InterpolatorPointer = typename InterpolatorType::Pointer;
164  using InterpolatorOutputType = typename InterpolatorType::OutputType;
165 
168 #if USE_GRADIENT_RECURSIVE_GAUSSIAN
170 #else
172 #endif
175  using GradientImagePointer = typename GradientImageType::Pointer;
179 
185  itkGetMacro( IsoSurfaceValue, InputPixelType );
186  itkSetMacro( IsoSurfaceValue, InputPixelType );
188 
190  using Superclass::SetInput;
191  virtual void SetInput( const InputImageType * inputImage );
192 
194  itkGetConstObjectMacro( Interpolator, InterpolatorType );
195  itkSetObjectMacro( Interpolator, InterpolatorType );
197 
201  itkGetMacro( GenerateTriangleFaces, bool );
202  itkSetMacro( GenerateTriangleFaces, bool );
203  itkBooleanMacro( GenerateTriangleFaces );
205 
208  itkGetMacro( ProjectVerticesToIsoSurface, bool );
209  itkSetMacro( ProjectVerticesToIsoSurface, bool );
210  itkBooleanMacro( ProjectVerticesToIsoSurface );
212 
219  itkGetMacro( ProjectVertexSurfaceDistanceThreshold, double );
220  itkSetClampMacro( ProjectVertexSurfaceDistanceThreshold, double, 0.0, NumericTraits<InputPixelType>::max() );
222 
226  itkGetMacro( ProjectVertexStepLength, double );
227  itkSetClampMacro( ProjectVertexStepLength, double, 0.0, 100000.0 );
229 
234  itkGetMacro( ProjectVertexStepLengthRelaxationFactor, double );
235  itkSetClampMacro( ProjectVertexStepLengthRelaxationFactor, double, 0.0, 1.0 );
237 
240  itkGetMacro( ProjectVertexMaximumNumberOfSteps, unsigned int );
241  itkSetMacro( ProjectVertexMaximumNumberOfSteps, unsigned int );
243 
244 protected:
246  ~CuberilleImageToMeshFilter() override;
247  void PrintSelf(std::ostream& os, Indent indent) const override;
248 
249  void GenerateData() override;
250  void GenerateOutputInformation() override{ }; // do nothing
251 
252 private:
256  {
257  public:
260 
262  VertexLookupNode() : m_X( 0 ), m_Y( 0 ) { }
263  VertexLookupNode(unsigned long x, unsigned long y) : m_X( x ), m_Y( y ) { }
265 
267  unsigned long GetX() { return m_X; }
268  unsigned long GetY() { return m_Y; }
270 
272  bool operator> ( const Self& node ) const
273  { return (m_Y > node.m_Y) || ( (m_Y == node.m_Y) && (m_X > node.m_X) ); }
274  bool operator>= ( const Self& node ) const
275  { return (m_Y >= node.m_Y) || ( (m_Y == node.m_Y) && (m_X >= node.m_X) ); }
276  bool operator< ( const Self& node ) const
277  { return (m_Y < node.m_Y) || ( (m_Y == node.m_Y) && (m_X < node.m_X) ); }
278  bool operator<= ( const Self& node ) const
279  { return (m_Y <= node.m_Y) || ( (m_Y == node.m_Y) && (m_X <= node.m_X) ); }
281 
282  private:
283  unsigned long m_X;
284  unsigned long m_Y;
285  };
286 
289  template< class TMeshType >
291  {
292  public:
295  using PointIdentifier = typename TMeshType::PointIdentifier;
296  using MapType = std::map< VertexLookupNode, PointIdentifier >;
297 
300 
302  void Clear() { m_Map.clear(); }
303 
305  void AddVertex( unsigned int x, unsigned int y, PointIdentifier id )
306  {
307  VertexLookupNode node( x, y );
308  m_Map.insert( typename MapType::value_type(node, id) );
309  }
311 
315  bool GetVertex( unsigned int x, unsigned int y, PointIdentifier &id )
316  {
317  bool result = false;
318  VertexLookupNode node( x, y );
319  auto it = m_Map.find( node );
320  if ( it != m_Map.end() )
321  {
322  result = true;
323  id = it->second;
324  }
325  return result;
326  }
328 
329  private:
331  };
332 
335 
339  inline void ComputeGradientImage();
340 
342  inline void SetVerticesFromFace( unsigned int face, bool *vertexHasQuad );
343 
345  inline IndexType GetVertexLookupIndex( unsigned int vertex, IndexType index );
346 
348  inline void ProjectVertexToIsoSurface( PointType &vertex );
349 
351  inline void AddVertex( PointIdentifier &id, IndexType index, const InputImageType* image, OutputMeshType* mesh );
352 
354  inline void AddQuadFace( CellIdentifier &id, PointIdentifier f[4], OutputMeshType* mesh );
355 
366 #if DEBUG_PRINT
367  unsigned int m_ProjectVertexTerminate[3];
368 #endif
369 };
370 
371 } // end namespace itk
372 
373 #ifndef ITK_MANUAL_INSTANTIATION
374 #include "itkCuberilleImageToMeshFilter.hxx"
375 #endif
376 
377 #endif
Const version of ShapedNeighborhoodIterator, defining iteration of a local N-dimensional neighborhood...
typename OutputMeshType::PointType PointType
typename InputImageType::PixelType InputPixelType
Light weight base class for most itk classes.
typename InputImageType::SpacingValueType SpacingValueType
typename OutputMeshType::CellsContainer CellsContainer
GradientInterpolatorPointer m_GradientInterpolator
Define numeric traits for std::vector.
typename OutputMeshType::PointsContainerPointer PointsContainerPointer
typename OutputMeshTraits::PixelType OutputPixelType
typename GradientInterpolatorType::Pointer GradientInterpolatorPointer
typename GradientFilterType::OutputPixelType GradientPixelType
typename QuadrilateralCellType::SelfAutoPointer QuadrilateralAutoPointer
typename OutputImageType::PixelType OutputPixelType
typename TriangleCellType::CellAutoPointer TriangleCellAutoPointer
Computes the gradient of an image by convolution with the first derivative of a Gaussian.
An abstract interface for cells.
typename OutputMeshType::Pointer OutputMeshPointer
void SetVerticesFromFace(unsigned int face, bool *vertexHasQuad)
virtual void SetInput(const InputImageType *inputImage)
typename GradientFilterType::OutputImageType GradientImageType
ImageToMeshFilter is the base class for all process objects that output Mesh data and require image d...
typename GradientImageType::Pointer GradientImagePointer
SmartPointer< Self > Pointer
typename InputImageType::Pointer InputImagePointer
std::map< VertexLookupNode, PointIdentifier > MapType
void ProjectVertexToIsoSurface(PointType &vertex)
typename OutputMeshType::CellsContainerPointer CellsContainerPointer
typename OutputMeshType::PointsContainer PointsContainer
typename InterpolatorType::OutputType InterpolatorOutputType
void AddVertex(PointIdentifier &id, IndexType index, const InputImageType *image, OutputMeshType *mesh)
typename InterpolatorType::Pointer InterpolatorPointer
IndexType GetVertexLookupIndex(unsigned int vertex, IndexType index)
typename OutputMeshType::CellTraits CellTraits
typename TriangleCellType::SelfAutoPointer TriangleAutoPointer
void AddQuadFace(CellIdentifier &id, PointIdentifier f[4], OutputMeshType *mesh)
void PrintSelf(std::ostream &os, Indent indent) const override
Control indentation during Print() invocation.
Definition: itkIndent.h:49
typename OutputMeshType::PointType OutputPointType
void SetInput(unsigned int idx, const InputImageType *input)
typename GradientFilterType::Pointer GradientFilterPointer
typename QuadrilateralCellType::CellAutoPointer QuadrilateralCellAutoPointer
bool GetVertex(unsigned int x, unsigned int y, PointIdentifier &id)
typename OutputMeshType::MeshTraits OutputMeshTraits
typename InputImageType::ConstPointer InputImageConstPointer
Represents a quadrilateral for a Mesh.
typename OutputMeshType::PointIdentifier PointIdentifier
typename InputImageType::IndexType IndexType
void AddVertex(unsigned int x, unsigned int y, PointIdentifier id)
typename InputImageType::SizeType SizeType
typename OutputMeshType::CellIdentifier CellIdentifier
Linearly interpolate a vector image at specified positions.
Computes the gradient of an image using directional derivatives.
typename InputImageType::SpacingType SpacingType