ITK  6.0.0
Insight Toolkit
itkQuadEdgeMeshParamMatrixCoefficients.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 itkQuadEdgeMeshParamMatrixCoefficients_h
19#define itkQuadEdgeMeshParamMatrixCoefficients_h
20
21#include "itkQuadEdgeMesh.h"
22#include "itkTriangleHelper.h"
23#include "itkMath.h"
24
25namespace itk
26{
32template <typename TInputMesh>
34{
35public:
36 using InputMeshType = TInputMesh;
37 using InputCoordRepType = typename InputMeshType::CoordRepType;
38 using InputQEType = typename InputMeshType::QEType;
39
40 MatrixCoefficients() = default;
41 virtual ~MatrixCoefficients() = default;
42
43 virtual InputCoordRepType
44 operator()(const InputMeshType * iMesh, InputQEType * iEdge) const = 0;
45};
46
54template <typename TInputMesh>
55class ITK_TEMPLATE_EXPORT OnesMatrixCoefficients : public MatrixCoefficients<TInputMesh>
56{
57public:
59
60 using InputMeshType = TInputMesh;
61 using InputCoordRepType = typename InputMeshType::CoordRepType;
62 using InputQEType = typename InputMeshType::QEType;
63
65
70 operator()(const InputMeshType * itkNotUsed(iMesh), InputQEType * itkNotUsed(iEdge)) const override
71 {
72 return 1.0;
73 }
74};
75
83template <typename TInputMesh>
84class ITK_TEMPLATE_EXPORT InverseEuclideanDistanceMatrixCoefficients : public MatrixCoefficients<TInputMesh>
85{
86public:
88
89 using InputMeshType = TInputMesh;
90 using InputCoordRepType = typename InputMeshType::CoordRepType;
92 using InputPointIdentifier = typename InputMeshType::PointIdentifier;
93 using InputQEType = typename InputMeshType::QEType;
95
97
104 operator()(const InputMeshType * iMesh, InputQEType * iEdge) const override
105 {
106 InputPointIdentifier id1 = iEdge->GetOrigin();
107 InputPointIdentifier id2 = iEdge->GetDestination();
110 InputPointType pt1 = iMesh->GetPoint(id1);
111 InputPointType pt2 = iMesh->GetPoint(id2);
112
113 InputCoordRepType oValue = 1.0 / pt1.EuclideanDistanceTo(pt2);
114
115 return oValue;
116 }
117};
118
126template <typename TInputMesh>
127class ITK_TEMPLATE_EXPORT ConformalMatrixCoefficients : public MatrixCoefficients<TInputMesh>
128{
129public:
131
132 using InputMeshType = TInputMesh;
133 using InputCoordRepType = typename InputMeshType::CoordRepType;
135 using InputPointIdentifier = typename InputMeshType::PointIdentifier;
136 using InputQEType = typename InputMeshType::QEType;
137
139
146 operator()(const InputMeshType * iMesh, InputQEType * iEdge) const override
147 {
148 InputPointIdentifier id1 = iEdge->GetOrigin();
149 InputPointIdentifier id2 = iEdge->GetDestination();
150 InputPointType pt1 = iMesh->GetPoint(id1);
151 InputPointType pt2 = iMesh->GetPoint(id2);
154 InputCoordRepType oValue(0.0);
155
156 if (iEdge->IsLeftSet())
157 {
158 InputPointIdentifier idA = iEdge->GetLnext()->GetDestination();
159 InputPointType ptA = iMesh->GetPoint(idA);
160 oValue += TriangleHelper<InputPointType>::Cotangent(pt1, ptA, pt2);
161 }
162 if (iEdge->IsRightSet())
163 {
164 InputPointIdentifier idB = iEdge->GetRnext()->GetOrigin();
165 InputPointType ptB = iMesh->GetPoint(idB);
166 oValue += TriangleHelper<InputPointType>::Cotangent(pt1, ptB, pt2);
167 }
168
169 return std::max(InputCoordRepType{}, oValue);
170 }
171};
172
181template <typename TInputMesh>
182class ITK_TEMPLATE_EXPORT AuthalicMatrixCoefficients : public MatrixCoefficients<TInputMesh>
183{
184public:
186
187 using InputMeshType = TInputMesh;
188 using InputCoordRepType = typename InputMeshType::CoordRepType;
190 using InputPointIdentifier = typename InputMeshType::PointIdentifier;
191 using InputQEType = typename InputMeshType::QEType;
192
194
202 operator()(const InputMeshType * iMesh, InputQEType * iEdge) const override
203 {
204 InputPointIdentifier id1 = iEdge->GetOrigin();
205 InputPointType pt1 = iMesh->GetPoint(id1);
208 InputPointIdentifier id2 = iEdge->GetDestination();
209 InputPointType pt2 = iMesh->GetPoint(id2);
210
211 InputCoordRepType oValue{};
212
213 if (iEdge->IsLeftSet())
214 {
215 InputPointIdentifier idA = iEdge->GetLnext()->GetDestination();
216 InputPointType ptA = iMesh->GetPoint(idA);
217 oValue += TriangleHelper<InputPointType>::Cotangent(pt1, pt2, ptA);
218 }
219
220 if (iEdge->IsRightSet())
221 {
222 InputPointIdentifier idB = iEdge->GetRnext()->GetOrigin();
223 InputPointType ptB = iMesh->GetPoint(idB);
224 oValue += TriangleHelper<InputPointType>::Cotangent(pt1, pt2, ptB);
225 }
226
227 return oValue / pt1.SquaredEuclideanDistanceTo(pt2);
228 }
229};
230
238template <typename TInputMesh>
239class ITK_TEMPLATE_EXPORT IntrinsicMatrixCoefficients : public MatrixCoefficients<TInputMesh>
240{
241public:
243
244 using InputMeshType = TInputMesh;
245 using InputCoordRepType = typename InputMeshType::CoordRepType;
246 using InputQEType = typename InputMeshType::QEType;
247
249
251 : m_Lambda(iLambda)
252 {}
253
254 InputCoordRepType
255 operator()(const InputMeshType * iMesh, InputQEType * iEdge) const
256 {
259
260 InputCoordRepType oValue = m_Lambda * conformal(iMesh, iEdge) + (1.0 - m_Lambda) * authalic(iMesh, iEdge);
261
262 return oValue;
263 }
264};
265
273template <typename TInputMesh>
274class ITK_TEMPLATE_EXPORT HarmonicMatrixCoefficients : public MatrixCoefficients<TInputMesh>
275{
276public:
278
279 using InputMeshType = TInputMesh;
280 using InputCoordRepType = typename InputMeshType::CoordRepType;
283 using InputPointIdentifier = typename InputMeshType::PointIdentifier;
284 using InputQEType = typename InputMeshType::QEType;
285
286 static constexpr unsigned int PointDimension = InputPointType::PointDimension;
287
289
291 operator()(const InputMeshType * iMesh, InputQEType * iEdge) const override
292 {
293 InputPointIdentifier id1 = iEdge->GetOrigin();
294 InputPointIdentifier id2 = iEdge->GetDestination();
295
296 InputPointIdentifier idA = iEdge->GetLnext()->GetDestination();
297 InputPointIdentifier idB = iEdge->GetRnext()->GetOrigin();
298
299 InputPointType pt1 = iMesh->GetPoint(id1);
300 InputPointType pt2 = iMesh->GetPoint(id2);
301 InputPointType ptA = iMesh->GetPoint(idA);
302 InputPointType ptB = iMesh->GetPoint(idB);
303
304 InputVectorType v1A = ptA - pt1;
305 InputVectorType v1B = ptB - pt1;
306 InputVectorType v12 = pt2 - pt1;
307
308 InputCoordRepType L1A = v1A * v1A;
309 InputCoordRepType L1B = v1B * v1B;
310 InputCoordRepType L12 = v12 * v12;
311
312 InputCoordRepType L2A = pt2.SquaredEuclideanDistanceTo(ptA);
313 InputCoordRepType L2B = pt2.SquaredEuclideanDistanceTo(ptB);
314
316
317 InputCoordRepType AreaA = 0.5 * (cross(v1A, v12).GetNorm());
318 InputCoordRepType AreaB = 0.5 * (cross(v1B, v12).GetNorm());
319
320 InputCoordRepType oValue = (L1A + L2A - L12) / AreaA + (L1B + L2B - L12) / AreaB;
321
322 return oValue;
323 }
324};
325} // namespace itk
326#endif
Compute a matrix filled with Authalic Coefficients of the edge, wherever two vertices are connected w...
typename InputMeshType::PointIdentifier InputPointIdentifier
InputCoordRepType operator()(const InputMeshType *iMesh, InputQEType *iEdge) const override
Compute a matrix filed by Conformal Coefficients of the edge wherever two vertices are connected by a...
typename InputMeshType::PointIdentifier InputPointIdentifier
InputCoordRepType operator()(const InputMeshType *iMesh, InputQEType *iEdge) const override
Compute a matrix filled with Harmonic coefficients, wherever two vertices are connected by an edge.
typename InputMeshType::PointIdentifier InputPointIdentifier
InputCoordRepType operator()(const InputMeshType *iMesh, InputQEType *iEdge) const override
typename InputPointType::VectorType InputVectorType
Compute a matrix filled by intrinsic Coefficients of the edge, wherever two vertices are connected by...
IntrinsicMatrixCoefficients(const InputCoordRepType &iLambda)
InputCoordRepType operator()(const InputMeshType *iMesh, InputQEType *iEdge) const
Compute a matrix filed with the inverse of the euclidean distance wherever two vertices are connected...
InputCoordRepType operator()(const InputMeshType *iMesh, InputQEType *iEdge) const override
Superclass for all the matrix coefficients computation classes.
virtual InputCoordRepType operator()(const InputMeshType *iMesh, InputQEType *iEdge) const =0
typename InputMeshType::QEType InputQEType
typename InputMeshType::CoordRepType InputCoordRepType
virtual ~MatrixCoefficients()=default
Compute a matrix filled by 1s wherever two vertices are connected by an edge.
InputCoordRepType operator()(const InputMeshType *, InputQEType *) const override
static CoordRepType Cotangent(const PointType &iA, const PointType &iB, const PointType &iC)
Compute cotangent(iA,iB,iC)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....