ITK  5.3.0
Insight Toolkit
itkSimplexMeshAdaptTopologyFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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_MOVE(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 
127  void
129  {
130  typename InputPolygonType::PointIdIterator it = poly->PointIdsBegin();
131 
132  double meanCurvature = 0;
133  PointIdentifier refPoint = *it;
134  double val = mesh->GetMeanCurvature(*it++);
135  meanCurvature += std::abs(val);
136 
137  PointIdentifier id1 = *it;
138  val = mesh->GetMeanCurvature(*it++);
139  meanCurvature += std::abs(val);
140 
141  PointIdentifier id2;
142 
143  double area = 0;
144 
145  int cnt = 0;
146 
147  while (it != poly->PointIdsEnd())
148  {
149  id2 = *it;
150  area += ComputeArea(refPoint, id1, id2);
151  id1 = id2;
152  val = mesh->GetMeanCurvature(*it);
153  meanCurvature += std::abs(val);
154  cnt++;
155  it++;
156  }
157 
158  meanCurvature /= (double)cnt;
159  totalArea += area;
160  totalCurvature += meanCurvature;
161 
162  areaMap->InsertElement(cellId, area);
163  curvatureMap->InsertElement(cellId, meanCurvature);
164 
165  if (area > maxCellSize)
166  {
167  maxCellSize = area;
168  }
169  if (area < minCellSize)
170  {
171  minCellSize = area;
172  }
173  if (meanCurvature > maxCurvature)
174  {
175  maxCurvature = meanCurvature;
176  }
177  if (meanCurvature < minCurvature)
178  {
179  minCurvature = meanCurvature;
180  }
181  }
182 
183  double
185  {
186  InputPointType v1, v2, v3;
187 
188  v1.Fill(0);
189  v2.Fill(0);
190  v3.Fill(0);
191 
192  mesh->GetPoint(p1, &v1);
193  mesh->GetPoint(p2, &v2);
194  mesh->GetPoint(p3, &v3);
195  return std::abs(vnl_cross_3d((v2 - v1).GetVnlVector(), (v3 - v1).GetVnlVector()).two_norm() / 2.0);
196  }
197 
198  typename DoubleValueMapType::Pointer
200  {
201  return areaMap;
202  }
203 
204  typename DoubleValueMapType::Pointer
206  {
207  return curvatureMap;
208  }
209 
210  double
212  {
213  return totalArea;
214  }
215 
216  double
218  {
219  return totalCurvature / (curvatureMap->Size());
220  }
221 
222  double
224  {
225  return maxCellSize;
226  }
227 
228  double
230  {
231  return minCellSize;
232  }
233 
234  double
236  {
237  return maxCurvature;
238  }
239 
240  double
242  {
243  return minCurvature;
244  }
245  };
246 
247  // cell visitor stuff
248  using SimplexVisitorInterfaceType =
250 
252  using CellMultiVisitorType = typename InputCellType::MultiVisitor;
253  using CellMultiVisitorPointer = typename CellMultiVisitorType::Pointer;
254 
255  itkSetMacro(Threshold, double);
256  itkGetConstMacro(Threshold, double);
257 
258  itkSetMacro(SelectionMethod, int);
259  itkGetConstMacro(SelectionMethod, int);
260 
261  itkGetConstMacro(ModifiedCount, int);
262 
263 protected:
265  ~SimplexMeshAdaptTopologyFilter() override = default;
266 
267  void
268  PrintSelf(std::ostream & os, Indent indent) const override;
269 
270  void
271  GenerateData() override;
272 
276  void
277  Initialize();
278 
284  void
285  ComputeCellParameters();
286 
288  void
289  CopyInputMeshToOutputMeshGeometryData();
290 
296  void
297  ModifyNeighborCells(CellIdentifier id1, CellIdentifier id2, PointIdentifier insertPointId);
298 
303  ComputeCellCenter(InputCellAutoPointer & simplexCell);
304 
309 
314  double m_Threshold{ 0.5 };
315 
319  int m_SelectionMethod{ 0 };
320 
325  int m_ModifiedCount{ 0 };
326 
332 
334 };
335 } // namespace itk
336 
337 #ifndef ITK_MANUAL_INSTANTIATION
338 # include "itkSimplexMeshAdaptTopologyFilter.hxx"
339 #endif
340 
341 #endif // itkSimplexMeshAdaptTopologyFilter_h
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::maxCellSize
double maxCellSize
Definition: itkSimplexMeshAdaptTopologyFilter.h:105
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::GetMaximumCellSize
double GetMaximumCellSize()
Definition: itkSimplexMeshAdaptTopologyFilter.h:223
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::totalCurvature
double totalCurvature
Definition: itkSimplexMeshAdaptTopologyFilter.h:103
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor
Definition: itkSimplexMeshAdaptTopologyFilter.h:98
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::Visit
void Visit(CellIdentifier cellId, InputPolygonType *poly)
visits all polygon cells and computes the area, NOTE: works for convex polygons only!...
Definition: itkSimplexMeshAdaptTopologyFilter.h:128
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::GetMaximumCurvature
double GetMaximumCurvature()
Definition: itkSimplexMeshAdaptTopologyFilter.h:235
itk::MeshSource::OutputMeshPointer
typename OutputMeshType::Pointer OutputMeshPointer
Definition: itkMeshSource.h:69
itk::SimplexMeshAdaptTopologyFilter::OutputCellType
typename OutputMeshType::CellType OutputCellType
Definition: itkSimplexMeshAdaptTopologyFilter.h:85
itk::SimplexMeshAdaptTopologyFilter
This filter changes the topology of a 2-simplex mesh.
Definition: itkSimplexMeshAdaptTopologyFilter.h:45
itk::SimplexMeshAdaptTopologyFilter::CellIdentifier
typename InputMeshType::CellIdentifier CellIdentifier
Definition: itkSimplexMeshAdaptTopologyFilter.h:76
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::maxCurvature
double maxCurvature
Definition: itkSimplexMeshAdaptTopologyFilter.h:110
itk::SimplexMeshAdaptTopologyFilter::m_Output
OutputMeshPointer m_Output
member for accessing the filter result during creation
Definition: itkSimplexMeshAdaptTopologyFilter.h:331
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::minCurvature
double minCurvature
Definition: itkSimplexMeshAdaptTopologyFilter.h:109
itk::MeshToMeshFilter::InputMeshPointer
typename InputMeshType::Pointer InputMeshPointer
Definition: itkMeshToMeshFilter.h:66
itk::GTest::TypedefsAndConstructors::Dimension2::VectorType
ImageBaseType::SpacingType VectorType
Definition: itkGTestTypedefsAndConstructors.h:53
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::SimplexMeshAdaptTopologyFilter::InputCellAutoPointer
typename InputCellType::CellAutoPointer InputCellAutoPointer
Definition: itkSimplexMeshAdaptTopologyFilter.h:78
itk::SimplexMeshAdaptTopologyFilter::DoubleContainerIterator
typename DoubleValueMapType::Iterator DoubleContainerIterator
Definition: itkSimplexMeshAdaptTopologyFilter.h:89
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::ComputeArea
double ComputeArea(PointIdentifier p1, PointIdentifier p2, PointIdentifier p3)
Definition: itkSimplexMeshAdaptTopologyFilter.h:184
itk::SimplexMeshAdaptTopologyFilter::InputCellType
typename InputMeshType::CellType InputCellType
Definition: itkSimplexMeshAdaptTopologyFilter.h:74
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::GetAreaMap
DoubleValueMapType::Pointer GetAreaMap()
Definition: itkSimplexMeshAdaptTopologyFilter.h:199
itk::SimplexMeshAdaptTopologyFilter::m_IdOffset
CellIdentifier m_IdOffset
Definition: itkSimplexMeshAdaptTopologyFilter.h:308
itk::PolygonCell
Represents a polygon in a Mesh.
Definition: itkPolygonCell.h:53
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::areaMap
DoubleValueMapType::Pointer areaMap
Definition: itkSimplexMeshAdaptTopologyFilter.h:106
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::totalArea
double totalArea
Definition: itkSimplexMeshAdaptTopologyFilter.h:102
itk::MeshToMeshFilter::InputMeshType
TInputMesh InputMeshType
Definition: itkMeshToMeshFilter.h:65
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::GetTotalMeanCurvature
double GetTotalMeanCurvature()
Definition: itkSimplexMeshAdaptTopologyFilter.h:217
itk::MapContainer
A wrapper of the STL "map" container.
Definition: itkMapContainer.h:45
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::minCellSize
double minCellSize
Definition: itkSimplexMeshAdaptTopologyFilter.h:104
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::GetTotalMeshArea
double GetTotalMeshArea()
Definition: itkSimplexMeshAdaptTopologyFilter.h:211
itk::SimplexMeshAdaptTopologyFilter::PointIdentifier
typename InputMeshType::PointIdentifier PointIdentifier
Definition: itkSimplexMeshAdaptTopologyFilter.h:75
itk::CellInterfaceVisitorImplementation
A template class used to implement a visitor object.
Definition: itkCellInterfaceVisitor.h:100
itk::SimplexMeshAdaptTopologyFilter::CellMultiVisitorPointer
typename CellMultiVisitorType::Pointer CellMultiVisitorPointer
Definition: itkSimplexMeshAdaptTopologyFilter.h:253
itk::PolygonCell::PointIdsEnd
PointIdIterator PointIdsEnd() override
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::GetCurvatureMap
DoubleValueMapType::Pointer GetCurvatureMap()
Definition: itkSimplexMeshAdaptTopologyFilter.h:205
itk::MeshToMeshFilter
MeshToMeshFilter is the base class for all process objects that output mesh data, and require mesh da...
Definition: itkMeshToMeshFilter.h:47
itk::SimplexMeshAdaptTopologyFilter::InputCellTraitsType
typename InputMeshType::MeshTraits::CellTraits InputCellTraitsType
Definition: itkSimplexMeshAdaptTopologyFilter.h:73
itk::SimplexMeshAdaptTopologyFilter::DoubleValueMapType
typename itk::MapContainer< CellIdentifier, double > DoubleValueMapType
Definition: itkSimplexMeshAdaptTopologyFilter.h:88
itk::SimplexMeshAdaptTopologyFilter::InputPointType
typename InputMeshType::PointType InputPointType
Definition: itkSimplexMeshAdaptTopologyFilter.h:70
itk::SimplexMeshAdaptTopologyFilter::SimplexVisitorInterfacePointer
typename SimplexVisitorInterfaceType::Pointer SimplexVisitorInterfacePointer
Definition: itkSimplexMeshAdaptTopologyFilter.h:251
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::GetMinimumCurvature
double GetMinimumCurvature()
Definition: itkSimplexMeshAdaptTopologyFilter.h:241
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:70
itk::NumericTraits::max
static constexpr T max(const T &)
Definition: itkNumericTraits.h:167
itkMeshToMeshFilter.h
itk::SimplexMeshAdaptTopologyFilter::CellAutoPointer
typename InputMeshType::CellAutoPointer CellAutoPointer
Definition: itkSimplexMeshAdaptTopologyFilter.h:79
itkVectorContainer.h
itk::SimplexMeshAdaptTopologyFilter::InputVectorType
typename InputMeshType::VectorType InputVectorType
Definition: itkSimplexMeshAdaptTopologyFilter.h:71
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itkPolygonCell.h
itk::SimplexMeshAdaptTopologyFilter::InputPixelType
typename InputMeshType::PixelType InputPixelType
Definition: itkSimplexMeshAdaptTopologyFilter.h:72
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::GetMinimumCellSize
double GetMinimumCellSize()
Definition: itkSimplexMeshAdaptTopologyFilter.h:229
itk::MeshSource::OutputMeshType
TOutputMesh OutputMeshType
Definition: itkMeshSource.h:68
itk::PolygonCell::PointIdsBegin
PointIdIterator PointIdsBegin() override
itkSimplexMesh.h
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::SimplexCellVisitor
SimplexCellVisitor()
Definition: itkSimplexMeshAdaptTopologyFilter.h:112
itkCellInterfaceVisitor.h
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::mesh
InputMeshPointer mesh
Definition: itkSimplexMeshAdaptTopologyFilter.h:101
itk::SimplexMeshAdaptTopologyFilter::m_NewSimplexCellPointer
InputCellAutoPointer m_NewSimplexCellPointer
Definition: itkSimplexMeshAdaptTopologyFilter.h:333
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::curvatureMap
DoubleValueMapType::Pointer curvatureMap
Definition: itkSimplexMeshAdaptTopologyFilter.h:107
itk::SimplexMeshAdaptTopologyFilter::InputPolygonPointIdIterator
typename InputPolygonType::PointIdIterator InputPolygonPointIdIterator
Definition: itkSimplexMeshAdaptTopologyFilter.h:81
itk::SimplexMeshAdaptTopologyFilter::CellMultiVisitorType
typename InputCellType::MultiVisitor CellMultiVisitorType
Definition: itkSimplexMeshAdaptTopologyFilter.h:252
itk::SimplexMeshAdaptTopologyFilter::InputCellPointIdIterator
typename InputCellType::PointIdIterator InputCellPointIdIterator
Definition: itkSimplexMeshAdaptTopologyFilter.h:77