ITK  5.0.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 #include "vnl/vnl_cross.h"
30 
31 namespace itk
32 {
44 template< typename TInputMesh, typename TOutputMesh >
45 class ITK_TEMPLATE_EXPORT SimplexMeshAdaptTopologyFilter:public MeshToMeshFilter< TInputMesh, TOutputMesh >
46 {
47 public:
48  ITK_DISALLOW_COPY_AND_ASSIGN(SimplexMeshAdaptTopologyFilter);
49 
52 
55 
58 
61 
63  itkNewMacro(Self);
64 
67 
68  using InputMeshType = TInputMesh;
69  using InputMeshPointer = typename InputMeshType::Pointer;
72  using InputPixelType = typename InputMeshType::PixelType;
73  using InputCellTraitsType = typename InputMeshType::MeshTraits::CellTraits;
74  using InputCellType = typename InputMeshType::CellType;
75  using PointIdentifier = typename InputMeshType::PointIdentifier;
76  using CellIdentifier = typename InputMeshType::CellIdentifier;
77  using InputCellPointIdIterator = typename InputCellType::PointIdIterator;
78  using InputCellAutoPointer = typename InputCellType::CellAutoPointer;
79  using CellAutoPointer = typename InputMeshType::CellAutoPointer;
81  using InputPolygonPointIdIterator = typename InputPolygonType::PointIdIterator;
83  using OutputMeshType = TOutputMesh;
84  using OutputMeshPointer = typename OutputMeshType::Pointer;
85  using OutputCellType = typename OutputMeshType::CellType;
87 
89  using DoubleContainerIterator = typename DoubleValueMapType::Iterator;
90 
99  {
100 public:
102  double totalArea;
104  double minCellSize;
105  double maxCellSize;
106  typename DoubleValueMapType::Pointer areaMap;
107  typename DoubleValueMapType::Pointer curvatureMap;
108 
109  double minCurvature;
110  double maxCurvature;
111 
113  {
114  areaMap = DoubleValueMapType::New();
115  curvatureMap = DoubleValueMapType::New();
116  totalArea = 0;
117  totalCurvature = 0;
118  minCellSize = NumericTraits< double >::max();
119  maxCellSize = 0;
120  minCurvature = NumericTraits< double >::max();
121  maxCurvature = 0;
122  }
123 
128  {
129  typename InputPolygonType::PointIdIterator it = poly->PointIdsBegin();
130 
131  double meanCurvature = 0;
132  PointIdentifier refPoint = *it;
133  double val = mesh->GetMeanCurvature(*it++);
134  meanCurvature += std::abs(val);
135 
136  PointIdentifier id1 = *it;
137  val = mesh->GetMeanCurvature(*it++);
138  meanCurvature += std::abs(val);
139 
140  PointIdentifier id2;
141 
142  double area = 0;
143 
144  int cnt = 0;
145 
146  while ( it != poly->PointIdsEnd() )
147  {
148  id2 = *it;
149  area += ComputeArea(refPoint, id1, id2);
150  id1 = id2;
151  val = mesh->GetMeanCurvature(*it);
152  meanCurvature += std::abs(val);
153  cnt++;
154  it++;
155  }
156 
157  meanCurvature /= (double)cnt;
158  totalArea += area;
159  totalCurvature += meanCurvature;
160 
161  areaMap->InsertElement(cellId, area);
162  curvatureMap->InsertElement(cellId, meanCurvature);
163 
164  if ( area > maxCellSize ) { maxCellSize = area; }
165  if ( area < minCellSize ) { minCellSize = area; }
166  if ( meanCurvature > maxCurvature ) { maxCurvature = meanCurvature; }
167  if ( meanCurvature < minCurvature ) { minCurvature = meanCurvature; }
168  }
169 
171  {
172  InputPointType v1, v2, v3;
173 
174  v1.Fill(0);
175  v2.Fill(0);
176  v3.Fill(0);
177 
178  mesh->GetPoint(p1, &v1);
179  mesh->GetPoint(p2, &v2);
180  mesh->GetPoint(p3, &v3);
181  return std::abs (vnl_cross_3d( ( v2 - v1 ).GetVnlVector(), ( v3 - v1 ).GetVnlVector() ).two_norm() / 2.0);
182  }
183 
184  typename DoubleValueMapType::Pointer GetAreaMap()
185  {
186  return areaMap;
187  }
188 
189  typename DoubleValueMapType::Pointer GetCurvatureMap()
190  {
191  return curvatureMap;
192  }
193 
195  {
196  return totalArea;
197  }
198 
200  {
201  return totalCurvature / ( curvatureMap->Size() );
202  }
203 
205  {
206  return maxCellSize;
207  }
208 
210  {
211  return minCellSize;
212  }
213 
215  {
216  return maxCurvature;
217  }
218 
220  {
221  return minCurvature;
222  }
223  };
224 
225  // cell visitor stuff
226  using SimplexVisitorInterfaceType = itk::CellInterfaceVisitorImplementation<
227  InputPixelType,
228  InputCellTraitsType,
229  InputPolygonType,
231 
233  using CellMultiVisitorType = typename InputCellType::MultiVisitor;
234  using CellMultiVisitorPointer = typename CellMultiVisitorType::Pointer;
235 
236  itkSetMacro(Threshold, double);
237  itkGetConstMacro(Threshold, double);
238 
239  itkSetMacro(SelectionMethod, int);
240  itkGetConstMacro(SelectionMethod, int);
241 
242  itkGetConstMacro(ModifiedCount, int);
243 
244 protected:
245 
247  ~SimplexMeshAdaptTopologyFilter() override = default;
248 
249  void PrintSelf(std::ostream & os, Indent indent) const override;
250 
251  void GenerateData() override;
252 
256  void Initialize();
257 
263  void ComputeCellParameters();
264 
266  void CopyInputMeshToOutputMeshGeometryData();
267 
273  void ModifyNeighborCells(CellIdentifier id1, CellIdentifier id2, PointIdentifier insertPointId);
274 
278  InputPointType ComputeCellCenter(InputCellAutoPointer & simplexCell);
279 
284 
289  double m_Threshold{0.5};
290 
294  int m_SelectionMethod{0};
295 
300  int m_ModifiedCount{0};
301 
307 
309 };
310 } //end of namespace
311 
312 #ifndef ITK_MANUAL_INSTANTIATION
313 #include "itkSimplexMeshAdaptTopologyFilter.hxx"
314 #endif
315 
316 #endif // itkSimplexMeshAdaptTopologyFilter_h
typename InputMeshType::PointType InputPointType
typename CellMultiVisitorType::Pointer CellMultiVisitorPointer
typename itk::MapContainer< CellIdentifier, double > DoubleValueMapType
Light weight base class for most itk classes.
typename InputMeshType::CellIdentifier CellIdentifier
TOutputMesh OutputMeshType
Definition: itkMeshSource.h:68
A template class used to implement a visitor object.
Define numeric traits for std::vector.
A wrapper of the STL &quot;map&quot; container.
PointIdIterator PointIdsBegin() override
MeshToMeshFilter is the base class for all process objects that output mesh data, and require mesh da...
typename InputMeshType::MeshTraits::CellTraits InputCellTraitsType
typename InputMeshType::Pointer InputMeshPointer
This filter changes the topology of a 2-simplex mesh.
typename SimplexVisitorInterfaceType::Pointer SimplexVisitorInterfacePointer
void Visit(CellIdentifier cellId, InputPolygonType *poly)
visits all polygon cells and computes the area, NOTE: works for convex polygons only!!! ...
double ComputeArea(PointIdentifier p1, PointIdentifier p2, PointIdentifier p3)
typename InputMeshType::PixelType InputPixelType
Represents a polygon in a Mesh.
OutputMeshPointer m_Output
member for accessing the filter result during creation
typename InputCellType::PointIdIterator InputCellPointIdIterator
typename InputMeshType::CellAutoPointer CellAutoPointer
typename OutputMeshType::Pointer OutputMeshPointer
Definition: itkMeshSource.h:69
typename InputCellType::CellAutoPointer InputCellAutoPointer
typename InputPolygonType::PointIdIterator InputPolygonPointIdIterator
typename InputMeshType::VectorType InputVectorType
typename DoubleValueMapType::Iterator DoubleContainerIterator
typename InputCellType::MultiVisitor CellMultiVisitorType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
typename InputMeshType::PointIdentifier PointIdentifier
A templated class holding a n-Dimensional covariant vector.
typename OutputMeshType::CellType OutputCellType
PointIdIterator PointIdsEnd() override