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 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, 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 itk::Math::abs(vnl_cross_3d((v2 - v1).GetVnlVector(), (v3 - v1).GetVnlVector()).two_norm() / 2.0);
196 }
197
200 {
201 return areaMap;
202 }
203
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
250
252 using CellMultiVisitorType = typename InputCellType::MultiVisitor;
254
255 itkSetMacro(Threshold, double);
256 itkGetConstMacro(Threshold, double);
257
258 itkSetMacro(SelectionMethod, int);
259 itkGetConstMacro(SelectionMethod, int);
260
261 itkGetConstMacro(ModifiedCount, int);
262
263protected:
266
267 void
268 PrintSelf(std::ostream & os, Indent indent) const override;
269
270 void
271 GenerateData() override;
272
276 void
278
284 void
286
288 void
290
296 void
298
304
308 CellIdentifier m_IdOffset{};
309
314 double m_Threshold{ 0.5 };
315
319 int m_SelectionMethod{ 0 };
320
325 int m_ModifiedCount{ 0 };
326
332
333 InputCellAutoPointer m_NewSimplexCellPointer{};
334};
335} // namespace itk
336
337#ifndef ITK_MANUAL_INSTANTIATION
338# include "itkSimplexMeshAdaptTopologyFilter.hxx"
339#endif
340
341#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:840
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....