Orfeo Toolbox  3.16
itkInteriorExteriorMeshFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkInteriorExteriorMeshFilter.txx,v $
5  Language: C++
6  Date: $Date: 2009-09-17 11:14:56 $
7  Version: $Revision: 1.13 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkInteriorExteriorMeshFilter_txx
18 #define __itkInteriorExteriorMeshFilter_txx
19 
21 #include "itkExceptionObject.h"
22 #include "itkNumericTraits.h"
23 #include "itkProgressReporter.h"
24 
25 namespace itk
26 {
27 
31 template <class TInputMesh, class TOutputMesh, class TSpatialFunction>
34 {
35  m_SpatialFunction = SpatialFunctionType::New();
36  SpatialFunctionDataObjectPointer spatialFunctionObject =
37  SpatialFunctionDataObjectType::New();
38  spatialFunctionObject->Set( m_SpatialFunction );
39  this->ProcessObject::SetNthInput( 1, spatialFunctionObject );
40 }
41 
42 
46 template <class TInputMesh, class TOutputMesh, class TSpatialFunction>
47 void
49 ::PrintSelf(std::ostream& os, Indent indent) const
50 {
51  Superclass::PrintSelf(os,indent);
52  os << indent << m_SpatialFunction << std::endl;
53 }
54 
55 
59 template <class TInputMesh, class TOutputMesh, class TSpatialFunction>
60 void
63 {
64 
65  typedef typename TInputMesh::PointsContainer InputPointsContainer;
66  typedef typename TOutputMesh::PointsContainer OutputPointsContainer;
67 
68  typedef typename TInputMesh::PointsContainerConstPointer InputPointsContainerConstPointer;
69  typedef typename TOutputMesh::PointsContainerPointer OutputPointsContainerPointer;
70 
71  typedef typename TInputMesh::PointDataContainer InputPointDataContainer;
72  typedef typename TOutputMesh::PointDataContainer OutputPointDataContainer;
73 
74  typedef typename TInputMesh::PointDataContainerConstPointer InputPointDataContainerConstPointer;
75  typedef typename TOutputMesh::PointDataContainerPointer OutputPointDataContainerPointer;
76 
77  const InputMeshType * inputMesh = this->GetInput();
78  OutputMeshPointer outputMesh = this->GetOutput();
79 
80  if( !inputMesh )
81  {
82  ExceptionObject exception(__FILE__, __LINE__);
83  exception.SetDescription("Missing Input Mesh");
84  exception.SetLocation(ITK_LOCATION);
85  throw exception;
86  }
87 
88  if( !outputMesh )
89  {
90  ExceptionObject exception(__FILE__, __LINE__);
91  exception.SetDescription("Missing Output Mesh");
92  exception.SetLocation(ITK_LOCATION);
93  throw exception;
94  }
95 
96  outputMesh->SetBufferedRegion( outputMesh->GetRequestedRegion() );
97 
98  InputPointsContainerConstPointer inPoints = inputMesh->GetPoints();
99  InputPointDataContainerConstPointer inData = inputMesh->GetPointData();
100 
101  typename InputPointsContainer::ConstIterator inputPoint = inPoints->Begin();
102  typename InputPointDataContainer::ConstIterator inputData;
103 
104  bool inputDataExists = false;
105  if( inData )
106  {
107  inputDataExists = true;
108  }
109 
110  if( inputDataExists )
111  {
112  inputData = inData->Begin();
113  }
114 
115  // support progress methods/callbacks
116  ProgressReporter progress(this, 0, inPoints->Size());
117 
118  typedef typename TSpatialFunction::OutputType ValueType;
119 
120  typedef typename TOutputMesh::PointIdentifier PointIdType;
121  PointIdType pointId = NumericTraits< PointIdType >::Zero;
122 
123  while( inputPoint != inPoints->End() )
124  {
125  ValueType value = m_SpatialFunction->Evaluate( inputPoint.Value() );
126 
127  if( value ) // Assumes return type is "bool"
128  {
129  outputMesh->SetPoint( pointId, inputPoint.Value() );
130  if( inputDataExists )
131  {
132  outputMesh->SetPointData( pointId, inputData.Value() );
133  }
134  pointId++;
135  }
136 
137  ++inputPoint;
138  if( inputDataExists )
139  {
140  ++inputData;
141  }
142  progress.CompletedPixel();
143  }
144 
145  // Create duplicate references to the rest of data in the mesh
146  this->CopyInputMeshToOutputMeshCellLinks();
147  this->CopyInputMeshToOutputMeshCells();
148  this->CopyInputMeshToOutputMeshCellData();
149 
150  unsigned int maxDimension = TInputMesh::MaxTopologicalDimension;
151 
152  for( unsigned int dim = 0; dim < maxDimension; dim++ )
153  {
154  outputMesh->SetBoundaryAssignments( dim,
155  inputMesh->GetBoundaryAssignments(dim) );
156  }
157 
158 }
159 
160 } // end namespace itk
161 
162 #endif

Generated at Sat Feb 2 2013 23:46:04 for Orfeo Toolbox with doxygen 1.8.1.1