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
31namespace itk
32{
44template <typename TInputMesh, typename TOutputMesh>
45class ITK_TEMPLATE_EXPORT SimplexMeshAdaptTopologyFilter : public MeshToMeshFilter<TInputMesh, TOutputMesh>
46{
47public:
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;
108
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
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
259protected:
262
263 void
264 PrintSelf(std::ostream & os, Indent indent) const override;
265
266 void
267 GenerateData() override;
268
272 void
274
280 void
282
284 void
286
292 void
294
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
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
A template class used to implement a visitor object.
A templated class holding a n-Dimensional covariant vector.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
A wrapper of the STL "map" container.
typename OutputMeshType::Pointer OutputMeshPointer
Definition: itkMeshSource.h:69
TOutputMesh OutputMeshType
Definition: itkMeshSource.h:68
MeshToMeshFilter is the base class for all process objects that output mesh data, and require mesh da...
typename InputMeshType::Pointer InputMeshPointer
static constexpr T max(const T &)
Represents a polygon in a Mesh.
PointIdIterator PointIdsEnd() override
PointIdIterator PointIdsBegin() override
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)
This filter changes the topology of a 2-simplex mesh.
typename InputCellType::PointIdIterator InputCellPointIdIterator
typename InputCellType::MultiVisitor CellMultiVisitorType
typename InputMeshType::PointType InputPointType
void ModifyNeighborCells(CellIdentifier id1, CellIdentifier id2, PointIdentifier insertPointId)
typename InputCellType::CellAutoPointer InputCellAutoPointer
typename InputMeshType::VectorType InputVectorType
typename InputMeshType::CellIdentifier CellIdentifier
typename InputMeshType::MeshTraits::CellTraits InputCellTraitsType
void PrintSelf(std::ostream &os, Indent indent) const override
typename DoubleValueMapType::Iterator DoubleContainerIterator
typename InputMeshType::PointIdentifier PointIdentifier
typename CellMultiVisitorType::Pointer CellMultiVisitorPointer
typename SimplexVisitorInterfaceType::Pointer SimplexVisitorInterfacePointer
typename InputMeshType::CellAutoPointer CellAutoPointer
~SimplexMeshAdaptTopologyFilter() override=default
typename InputMeshType::PixelType InputPixelType
typename itk::MapContainer< CellIdentifier, double > DoubleValueMapType
typename OutputMeshType::CellType OutputCellType
typename InputPolygonType::PointIdIterator InputPolygonPointIdIterator
InputPointType ComputeCellCenter(InputCellAutoPointer &simplexCell)
static Pointer New()
SmartPointer< Self > Pointer
bool abs(bool x)
Definition: itkMath.h:839
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....