ITK  6.0.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  * https://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 
66  itkOverrideGetNameOfClassMacro(SimplexMeshAdaptTopologyFilter);
67 
68  using InputMeshType = TInputMesh;
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;
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;
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  const PointIdentifier refPoint = *it;
134  double val = mesh->GetMeanCurvature(*it++);
135  meanCurvature += itk::Math::abs(val);
136 
137  PointIdentifier id1 = *it;
138  val = mesh->GetMeanCurvature(*it++);
139  meanCurvature += itk::Math::abs(val);
140 
141  double area = 0;
142 
143  int cnt = 0;
144 
145  while (it != poly->PointIdsEnd())
146  {
147  const PointIdentifier id2 = *it;
148  area += ComputeArea(refPoint, id1, id2);
149  id1 = id2;
150  val = mesh->GetMeanCurvature(*it);
151  meanCurvature += itk::Math::abs(val);
152  ++cnt;
153  ++it;
154  }
155 
156  meanCurvature /= static_cast<double>(cnt);
157  totalArea += area;
158  totalCurvature += meanCurvature;
159 
160  areaMap->InsertElement(cellId, area);
161  curvatureMap->InsertElement(cellId, meanCurvature);
162 
163  if (area > maxCellSize)
164  {
165  maxCellSize = area;
166  }
167  if (area < minCellSize)
168  {
169  minCellSize = area;
170  }
171  if (meanCurvature > maxCurvature)
172  {
173  maxCurvature = meanCurvature;
174  }
175  if (meanCurvature < minCurvature)
176  {
177  minCurvature = meanCurvature;
178  }
179  }
180 
181  double
183  {
184  InputPointType v1{};
185  InputPointType v2{};
186  InputPointType v3{};
187 
188  mesh->GetPoint(p1, &v1);
189  mesh->GetPoint(p2, &v2);
190  mesh->GetPoint(p3, &v3);
191  return itk::Math::abs(vnl_cross_3d((v2 - v1).GetVnlVector(), (v3 - v1).GetVnlVector()).two_norm() / 2.0);
192  }
193 
196  {
197  return areaMap;
198  }
199 
202  {
203  return curvatureMap;
204  }
205 
206  double
208  {
209  return totalArea;
210  }
211 
212  double
214  {
215  return totalCurvature / (curvatureMap->Size());
216  }
217 
218  double
220  {
221  return maxCellSize;
222  }
223 
224  double
226  {
227  return minCellSize;
228  }
229 
230  double
232  {
233  return maxCurvature;
234  }
235 
236  double
238  {
239  return minCurvature;
240  }
241  };
242 
243  // cell visitor stuff
244  using SimplexVisitorInterfaceType =
246 
248  using CellMultiVisitorType = typename InputCellType::MultiVisitor;
250 
251  itkSetMacro(Threshold, double);
252  itkGetConstMacro(Threshold, double);
253 
254  itkSetMacro(SelectionMethod, int);
255  itkGetConstMacro(SelectionMethod, int);
256 
257  itkGetConstMacro(ModifiedCount, int);
258 
259 protected:
261  ~SimplexMeshAdaptTopologyFilter() override = default;
262 
263  void
264  PrintSelf(std::ostream & os, Indent indent) const override;
265 
266  void
267  GenerateData() override;
268 
272  void
273  Initialize();
274 
280  void
281  ComputeCellParameters();
282 
284  void
285  CopyInputMeshToOutputMeshGeometryData();
286 
292  void
293  ModifyNeighborCells(CellIdentifier id1, CellIdentifier id2, PointIdentifier insertPointId);
294 
299  ComputeCellCenter(InputCellAutoPointer & simplexCell);
300 
304  CellIdentifier m_IdOffset{};
305 
310  double m_Threshold{ 0.5 };
311 
315  int m_SelectionMethod{ 0 };
316 
321  int m_ModifiedCount{ 0 };
322 
327  OutputMeshPointer m_Output{};
328 
329  InputCellAutoPointer m_NewSimplexCellPointer{};
330 };
331 } // namespace itk
332 
333 #ifndef ITK_MANUAL_INSTANTIATION
334 # include "itkSimplexMeshAdaptTopologyFilter.hxx"
335 #endif
336 
337 #endif // itkSimplexMeshAdaptTopologyFilter_h
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::maxCellSize
double maxCellSize
Definition: itkSimplexMeshAdaptTopologyFilter.h:105
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::GetMaximumCellSize
double GetMaximumCellSize()
Definition: itkSimplexMeshAdaptTopologyFilter.h:219
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:231
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::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:182
itk::SimplexMeshAdaptTopologyFilter::InputCellType
typename InputMeshType::CellType InputCellType
Definition: itkSimplexMeshAdaptTopologyFilter.h:74
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::GetAreaMap
DoubleValueMapType::Pointer GetAreaMap()
Definition: itkSimplexMeshAdaptTopologyFilter.h:195
itk::PolygonCell
Represents a polygon in a Mesh.
Definition: itkPolygonCell.h:49
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:213
itk::Math::abs
bool abs(bool x)
Definition: itkMath.h:839
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:55
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::GetTotalMeshArea
double GetTotalMeshArea()
Definition: itkSimplexMeshAdaptTopologyFilter.h:207
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:249
itk::PolygonCell::PointIdsEnd
PointIdIterator PointIdsEnd() override
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::GetCurvatureMap
DoubleValueMapType::Pointer GetCurvatureMap()
Definition: itkSimplexMeshAdaptTopologyFilter.h:201
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:247
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::GetMinimumCurvature
double GetMinimumCurvature()
Definition: itkSimplexMeshAdaptTopologyFilter.h:237
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:169
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: itkAnatomicalOrientation.h:29
itkPolygonCell.h
itk::SimplexMeshAdaptTopologyFilter::InputPixelType
typename InputMeshType::PixelType InputPixelType
Definition: itkSimplexMeshAdaptTopologyFilter.h:72
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::GetMinimumCellSize
double GetMinimumCellSize()
Definition: itkSimplexMeshAdaptTopologyFilter.h:225
itk::MeshSource::OutputMeshType
TOutputMesh OutputMeshType
Definition: itkMeshSource.h:68
New
static Pointer New()
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::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:248
itk::SimplexMeshAdaptTopologyFilter::InputCellPointIdIterator
typename InputCellType::PointIdIterator InputCellPointIdIterator
Definition: itkSimplexMeshAdaptTopologyFilter.h:77