ITK  4.4.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< class TInputMesh, class TOutputMesh >
50 class ITK_EXPORT 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  {
117  areaMap = DoubleValueMapType::New();
118  curvatureMap = DoubleValueMapType::New();
119  totalArea = 0;
120  totalCurvature = 0;
121  minCellSize = NumericTraits< double >::max();
122  maxCellSize = 0;
123  minCurvature = NumericTraits< double >::max();
124  maxCurvature = 0;
125  }
126 
130  void Visit(CellIdentifier cellId, InputPolygonType *poly)
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 += vcl_abs(val);
138 
139  PointIdentifier id1 = *it;
140  val = mesh->GetMeanCurvature(*it++);
141  meanCurvature += vcl_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 += vcl_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 
173  double ComputeArea(PointIdentifier p1, PointIdentifier p2, PointIdentifier p3)
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 vcl_abs (itk_cross_3d( ( v2 - v1 ).GetVnlVector(), ( v3 - v1 ).GetVnlVector() ).two_norm() / 2.0);
185  }
186 
187  typename DoubleValueMapType::Pointer GetAreaMap()
188  {
189  return areaMap;
190  }
191 
192  typename DoubleValueMapType::Pointer GetCurvatureMap()
193  {
194  return curvatureMap;
195  }
196 
197  double GetTotalMeshArea()
198  {
199  return totalArea;
200  }
201 
202  double GetTotalMeanCurvature()
203  {
204  return totalCurvature / ( curvatureMap->Size() );
205  }
206 
207  double GetMaximumCellSize()
208  {
209  return maxCellSize;
210  }
211 
212  double GetMinimumCellSize()
213  {
214  return minCellSize;
215  }
216 
217  double GetMaximumCurvature()
218  {
219  return maxCurvature;
220  }
221 
222  double GetMinimumCurvature()
223  {
224  return minCurvature;
225  }
226  };
227 
228  // cell visitor stuff
229  typedef itk::CellInterfaceVisitorImplementation< InputPixelType,
230  InputCellTraitsType,
231  InputPolygonType,
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;
256 
257  virtual void GenerateData();
258 
262  void Initialize();
263 
269  void ComputeCellParameters();
270 
272  void CopyInputMeshToOutputMeshGeometryData();
273 
279  void ModifyNeighborCells(CellIdentifier id1, CellIdentifier id2, PointIdentifier insertPointId);
280 
284  InputPointType ComputeCellCenter(InputCellAutoPointer & simplexCell);
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
323