ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkSimplexMeshAdaptTopologyFilter.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 itkSimplexMeshAdaptTopologyFilter_h
19 #define itkSimplexMeshAdaptTopologyFilter_h
20 
21 #include "itkPolygonCell.h"
23 
24 #include "itkSimplexMesh.h"
25 #include "itkMeshToMeshFilter.h"
26 #include "itkVectorContainer.h"
27 
28 #include "vxl_version.h"
29 #if VXL_VERSION_DATE_FULL > 20040406
30 #include "vnl/vnl_cross.h"
31 #define itk_cross_3d vnl_cross_3d
32 #else
33 #define itk_cross_3d cross_3d
34 #endif
35 
36 namespace itk
37 {
49 template< typename TInputMesh, typename TOutputMesh >
50 class SimplexMeshAdaptTopologyFilter:public MeshToMeshFilter< TInputMesh, TOutputMesh >
51 {
52 public:
55 
58 
61 
64 
66  itkNewMacro(Self);
67 
70 
71  typedef TInputMesh InputMeshType;
72  typedef typename InputMeshType::Pointer InputMeshPointer;
73  typedef typename InputMeshType::PointType InputPointType;
74  typedef typename InputMeshType::VectorType InputVectorType;
75  typedef typename InputMeshType::PixelType InputPixelType;
76  typedef typename InputMeshType::MeshTraits::CellTraits InputCellTraitsType;
77  typedef typename InputMeshType::CellType InputCellType;
78  typedef typename InputMeshType::PointIdentifier PointIdentifier;
79  typedef typename InputMeshType::CellIdentifier CellIdentifier;
80  typedef typename InputCellType::PointIdIterator InputCellPointIdIterator;
81  typedef typename InputCellType::CellAutoPointer InputCellAutoPointer;
82  typedef typename InputMeshType::CellAutoPointer CellAutoPointer;
84  typedef typename InputPolygonType::PointIdIterator InputPolygonPointIdIterator;
86  typedef TOutputMesh OutputMeshType;
87  typedef typename OutputMeshType::Pointer OutputMeshPointer;
88  typedef typename OutputMeshType::CellType OutputCellType;
90 
93 
102  {
103 public:
105  double totalArea;
107  double minCellSize;
108  double maxCellSize;
111 
112  double minCurvature;
113  double maxCurvature;
114 
116  {
119  totalArea = 0;
120  totalCurvature = 0;
122  maxCellSize = 0;
124  maxCurvature = 0;
125  }
126 
131  {
132  typename InputPolygonType::PointIdIterator it = poly->PointIdsBegin();
133 
134  double meanCurvature = 0;
135  PointIdentifier refPoint = *it;
136  double val = mesh->GetMeanCurvature(*it++);
137  meanCurvature += std::abs(val);
138 
139  PointIdentifier id1 = *it;
140  val = mesh->GetMeanCurvature(*it++);
141  meanCurvature += std::abs(val);
142 
143  PointIdentifier id2;
144 
145  double area = 0;
146 
147  int cnt = 0;
148 
149  while ( it != poly->PointIdsEnd() )
150  {
151  id2 = *it;
152  area += ComputeArea(refPoint, id1, id2);
153  id1 = id2;
154  val = mesh->GetMeanCurvature(*it);
155  meanCurvature += std::abs(val);
156  cnt++;
157  it++;
158  }
159 
160  meanCurvature /= (double)cnt;
161  totalArea += area;
162  totalCurvature += meanCurvature;
163 
164  areaMap->InsertElement(cellId, area);
165  curvatureMap->InsertElement(cellId, meanCurvature);
166 
167  if ( area > maxCellSize ) { maxCellSize = area; }
168  if ( area < minCellSize ) { minCellSize = area; }
169  if ( meanCurvature > maxCurvature ) { maxCurvature = meanCurvature; }
170  if ( meanCurvature < minCurvature ) { minCurvature = meanCurvature; }
171  }
172 
174  {
175  InputPointType v1, v2, v3;
176 
177  v1.Fill(0);
178  v2.Fill(0);
179  v3.Fill(0);
180 
181  mesh->GetPoint(p1, &v1);
182  mesh->GetPoint(p2, &v2);
183  mesh->GetPoint(p3, &v3);
184  return std::abs (itk_cross_3d( ( v2 - v1 ).GetVnlVector(), ( v3 - v1 ).GetVnlVector() ).two_norm() / 2.0);
185  }
186 
188  {
189  return areaMap;
190  }
191 
193  {
194  return curvatureMap;
195  }
196 
198  {
199  return totalArea;
200  }
201 
203  {
204  return totalCurvature / ( curvatureMap->Size() );
205  }
206 
208  {
209  return maxCellSize;
210  }
211 
213  {
214  return minCellSize;
215  }
216 
218  {
219  return maxCurvature;
220  }
221 
223  {
224  return minCurvature;
225  }
226  };
227 
228  // cell visitor stuff
232  SimplexCellVisitor >
234 
236  typedef typename InputCellType::MultiVisitor CellMultiVisitorType;
237  typedef typename CellMultiVisitorType::Pointer CellMultiVisitorPointer;
238 
239  itkSetMacro(Threshold, double);
240  itkGetConstMacro(Threshold, double);
241 
242  itkSetMacro(SelectionMethod, int);
243  itkGetConstMacro(SelectionMethod, int);
244 
245  itkGetConstMacro(ModifiedCount, int);
246 
247 protected:
248 
252 
253  void operator=(const Self &) {}
254 
255  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
256 
257  virtual void GenerateData() ITK_OVERRIDE;
258 
262  void Initialize();
263 
269  void ComputeCellParameters();
270 
273 
280 
285 
290 
295  double m_Threshold;
296 
301 
307 
313 
315 };
316 } //end of namespace
317 
318 #ifndef ITK_MANUAL_INSTANTIATION
319 #include "itkSimplexMeshAdaptTopologyFilter.hxx"
320 #endif
321 
322 #endif // itkSimplexMeshAdaptTopologyFilter_h
Light weight base class for most itk classes.
CovariantVector< typename InputVectorType::ValueType, 3 > CovariantVectorType
A template class used to implement a visitor object.
InputCellType::PointIdIterator InputCellPointIdIterator
A wrapper of the STL &quot;map&quot; container.
virtual void GenerateData() override
MeshToMeshFilter is the base class for all process objects that output mesh data, and require mesh da...
itk::MapContainer< CellIdentifier, double > DoubleValueMapType
virtual PointIdIterator PointIdsEnd(void) override
static Pointer New()
This filter changes the topology of a 2-simplex mesh.
void Visit(CellIdentifier cellId, InputPolygonType *poly)
visits all polygon cells and computes the area, NOTE: works for convex polygons only!!! ...
The non-const iterator type for the map.
SimplexVisitorInterfaceType::Pointer SimplexVisitorInterfacePointer
double ComputeArea(PointIdentifier p1, PointIdentifier p2, PointIdentifier p3)
static T max(const T &)
virtual PointIdIterator PointIdsBegin(void) override
InputPolygonType::PointIdIterator InputPolygonPointIdIterator
Represents a polygon in a Mesh.
OutputMeshPointer m_Output
member for accessing the filter result during creation
void ModifyNeighborCells(CellIdentifier id1, CellIdentifier id2, PointIdentifier insertPointId)
InputMeshType::Pointer InputMeshPointer
itk::CellInterfaceVisitorImplementation< InputPixelType, InputCellTraitsType, InputPolygonType, SimplexCellVisitor > SimplexVisitorInterfaceType
OutputMeshType::Pointer OutputMeshPointer
Definition: itkMeshSource.h:67
InputMeshType::MeshTraits::CellTraits InputCellTraitsType
itk::PolygonCell< InputCellType > InputPolygonType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
InputPointType ComputeCellCenter(InputCellAutoPointer &simplexCell)
itk::PolygonCell< OutputCellType > OutputPolygonType
void PrintSelf(std::ostream &os, Indent indent) const override
A templated class holding a n-Dimensional covariant vector.
MeshToMeshFilter< TInputMesh, TOutputMesh > Superclass