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  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  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 += itk::Math::abs(val);
154  ++cnt;
155  ++it;
156  }
157 
158  meanCurvature /= static_cast<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;
187  InputPointType v2;
188  InputPointType v3;
189 
190  v1.Fill(0);
191  v2.Fill(0);
192  v3.Fill(0);
193 
194  mesh->GetPoint(p1, &v1);
195  mesh->GetPoint(p2, &v2);
196  mesh->GetPoint(p3, &v3);
197  return itk::Math::abs(vnl_cross_3d((v2 - v1).GetVnlVector(), (v3 - v1).GetVnlVector()).two_norm() / 2.0);
198  }
199 
202  {
203  return areaMap;
204  }
205 
208  {
209  return curvatureMap;
210  }
211 
212  double
214  {
215  return totalArea;
216  }
217 
218  double
220  {
221  return totalCurvature / (curvatureMap->Size());
222  }
223 
224  double
226  {
227  return maxCellSize;
228  }
229 
230  double
232  {
233  return minCellSize;
234  }
235 
236  double
238  {
239  return maxCurvature;
240  }
241 
242  double
244  {
245  return minCurvature;
246  }
247  };
248 
249  // cell visitor stuff
250  using SimplexVisitorInterfaceType =
252 
254  using CellMultiVisitorType = typename InputCellType::MultiVisitor;
256 
257  itkSetMacro(Threshold, double);
258  itkGetConstMacro(Threshold, double);
259 
260  itkSetMacro(SelectionMethod, int);
261  itkGetConstMacro(SelectionMethod, int);
262 
263  itkGetConstMacro(ModifiedCount, int);
264 
265 protected:
267  ~SimplexMeshAdaptTopologyFilter() override = default;
268 
269  void
270  PrintSelf(std::ostream & os, Indent indent) const override;
271 
272  void
273  GenerateData() override;
274 
278  void
279  Initialize();
280 
286  void
287  ComputeCellParameters();
288 
290  void
291  CopyInputMeshToOutputMeshGeometryData();
292 
298  void
299  ModifyNeighborCells(CellIdentifier id1, CellIdentifier id2, PointIdentifier insertPointId);
300 
305  ComputeCellCenter(InputCellAutoPointer & simplexCell);
306 
310  CellIdentifier m_IdOffset{};
311 
316  double m_Threshold{ 0.5 };
317 
321  int m_SelectionMethod{ 0 };
322 
327  int m_ModifiedCount{ 0 };
328 
333  OutputMeshPointer m_Output{};
334 
335  InputCellAutoPointer m_NewSimplexCellPointer{};
336 };
337 } // namespace itk
338 
339 #ifndef ITK_MANUAL_INSTANTIATION
340 # include "itkSimplexMeshAdaptTopologyFilter.hxx"
341 #endif
342 
343 #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:225
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:237
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:184
itk::SimplexMeshAdaptTopologyFilter::InputCellType
typename InputMeshType::CellType InputCellType
Definition: itkSimplexMeshAdaptTopologyFilter.h:74
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::GetAreaMap
DoubleValueMapType::Pointer GetAreaMap()
Definition: itkSimplexMeshAdaptTopologyFilter.h:201
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:219
itk::Math::abs
bool abs(bool x)
Definition: itkMath.h:840
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:213
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:255
itk::PolygonCell::PointIdsEnd
PointIdIterator PointIdsEnd() override
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::GetCurvatureMap
DoubleValueMapType::Pointer GetCurvatureMap()
Definition: itkSimplexMeshAdaptTopologyFilter.h:207
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:253
itk::SimplexMeshAdaptTopologyFilter::SimplexCellVisitor::GetMinimumCurvature
double GetMinimumCurvature()
Definition: itkSimplexMeshAdaptTopologyFilter.h:243
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:231
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:254
itk::SimplexMeshAdaptTopologyFilter::InputCellPointIdIterator
typename InputCellType::PointIdIterator InputCellPointIdIterator
Definition: itkSimplexMeshAdaptTopologyFilter.h:77