ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkQuadEdgeMeshParamMatrixCoefficients.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 "vnl/vnl_math.h"
24 
25 namespace itk
26 {
32 template< typename TInputMesh >
33 class ITK_EXPORT MatrixCoefficients
34 {
35 public:
36  typedef TInputMesh InputMeshType;
37  typedef typename InputMeshType::CoordRepType InputCoordRepType;
38  typedef typename InputMeshType::QEType InputQEType;
39 
41  virtual ~MatrixCoefficients() {}
42 
43  virtual InputCoordRepType operator()
44  (const InputMeshType *iMesh, InputQEType *iEdge) const = 0;
45 };
46 
54 template< typename TInputMesh >
55 class ITK_EXPORT OnesMatrixCoefficients:public MatrixCoefficients< TInputMesh >
56 {
57 public:
59 
60  typedef TInputMesh InputMeshType;
61  typedef typename InputMeshType::CoordRepType InputCoordRepType;
62  typedef typename InputMeshType::QEType InputQEType;
63 
65 
69  InputCoordRepType operator()( const InputMeshType *itkNotUsed(iMesh),
70  InputQEType *itkNotUsed(iEdge) ) const
71  {
72  return 1.0;
73  }
74 };
76 
84 template< typename TInputMesh >
86  public MatrixCoefficients< TInputMesh >
87 {
88 public:
90 
91  typedef TInputMesh InputMeshType;
92  typedef typename InputMeshType::CoordRepType InputCoordRepType;
93  typedef typename InputMeshType::PointType InputPointType;
94  typedef typename InputMeshType::PointIdentifier InputPointIdentifier;
95  typedef typename InputMeshType::QEType InputQEType;
96  typedef typename InputMeshType::VectorType InputVectorType;
97 
99 
105  InputCoordRepType operator()(const InputMeshType *iMesh, InputQEType *iEdge) const
106  {
107  InputPointIdentifier id1 = iEdge->GetOrigin();
108  InputPointIdentifier id2 = iEdge->GetDestination();
110 
111  InputPointType pt1 = iMesh->GetPoint(id1);
112  InputPointType pt2 = iMesh->GetPoint(id2);
113 
114  InputCoordRepType oValue = 1.0 / pt1.EuclideanDistanceTo(pt2);
115 
116  return oValue;
117  }
118 };
119 
127 template< typename TInputMesh >
128 class ITK_EXPORT ConformalMatrixCoefficients:public MatrixCoefficients< TInputMesh >
129 {
130 public:
132 
133  typedef TInputMesh InputMeshType;
134  typedef typename InputMeshType::CoordRepType InputCoordRepType;
135  typedef typename InputMeshType::PointType InputPointType;
136  typedef typename InputMeshType::PointIdentifier InputPointIdentifier;
137  typedef typename InputMeshType::QEType InputQEType;
138 
140 
146  InputCoordRepType operator()(const InputMeshType *iMesh, InputQEType *iEdge) const
147  {
148  InputPointIdentifier id1 = iEdge->GetOrigin();
149  InputPointIdentifier id2 = iEdge->GetDestination();
150  InputPointType pt1 = iMesh->GetPoint(id1);
151  InputPointType pt2 = iMesh->GetPoint(id2);
153 
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 vnl_math_max( NumericTraits< InputCoordRepType >::Zero, oValue);
170  }
171 };
172 
181 template< typename TInputMesh >
182 class ITK_EXPORT AuthalicMatrixCoefficients:public MatrixCoefficients< TInputMesh >
183 {
184 public:
186 
187  typedef TInputMesh InputMeshType;
188  typedef typename InputMeshType::CoordRepType InputCoordRepType;
189  typedef typename InputMeshType::PointType InputPointType;
190  typedef typename InputMeshType::PointIdentifier InputPointIdentifier;
191  typedef typename InputMeshType::QEType InputQEType;
192 
194 
201  InputCoordRepType operator()(const InputMeshType *iMesh, InputQEType *iEdge) const
202  {
203  InputPointIdentifier id1 = iEdge->GetOrigin();
204  InputPointType pt1 = iMesh->GetPoint(id1);
206 
207  InputPointIdentifier id2 = iEdge->GetDestination();
208  InputPointType pt2 = iMesh->GetPoint(id2);
209 
211 
212  if ( iEdge->IsLeftSet() )
213  {
214  InputPointIdentifier idA = iEdge->GetLnext()->GetDestination();
215  InputPointType ptA = iMesh->GetPoint(idA);
216  oValue +=
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 
238 template< typename TInputMesh >
239 class ITK_EXPORT IntrinsicMatrixCoefficients:public MatrixCoefficients< TInputMesh >
240 {
241 public:
243 
244  typedef TInputMesh InputMeshType;
245  typedef typename InputMeshType::CoordRepType InputCoordRepType;
246  typedef typename InputMeshType::QEType InputQEType;
247 
249 
251  m_Lambda(iLambda)
252  {}
253 
254  InputCoordRepType operator()(const InputMeshType *iMesh,
255  InputQEType *iEdge) const
256  {
259 
260  InputCoordRepType oValue = m_Lambda * conformal(iMesh, iEdge)
261  + ( 1.0 - m_Lambda ) * authalic(iMesh, iEdge);
262 
263  return oValue;
264  }
265 };
266 
274 template< typename TInputMesh >
275 class ITK_EXPORT HarmonicMatrixCoefficients:public MatrixCoefficients< TInputMesh >
276 {
277 public:
279 
280  typedef TInputMesh InputMeshType;
281  typedef typename InputMeshType::CoordRepType InputCoordRepType;
282  typedef typename InputMeshType::PointType InputPointType;
283  typedef typename InputPointType::VectorType InputVectorType;
284  typedef typename InputMeshType::PointIdentifier InputPointIdentifier;
285  typedef typename InputMeshType::QEType InputQEType;
286 
287  itkStaticConstMacro(PointDimension, unsigned int,
288  InputPointType::PointDimension);
289 
291 
292  InputCoordRepType operator()(const InputMeshType *iMesh, InputQEType *iEdge) const
293  {
294  InputPointIdentifier id1 = iEdge->GetOrigin();
295  InputPointIdentifier id2 = iEdge->GetDestination();
296 
297  InputPointIdentifier idA = iEdge->GetLnext()->GetDestination();
298  InputPointIdentifier idB = iEdge->GetRnext()->GetOrigin();
299 
300  InputPointType pt1 = iMesh->GetPoint(id1);
301  InputPointType pt2 = iMesh->GetPoint(id2);
302  InputPointType ptA = iMesh->GetPoint(idA);
303  InputPointType ptB = iMesh->GetPoint(idB);
304 
305  InputVectorType v1A = ptA - pt1;
306  InputVectorType v1B = ptB - pt1;
307  InputVectorType v12 = pt2 - pt1;
308 
309  InputCoordRepType L1A = v1A * v1A;
310  InputCoordRepType L1B = v1B * v1B;
311  InputCoordRepType L12 = v12 * v12;
312 
313  InputCoordRepType L2A = pt2.SquaredEuclideanDistanceTo(ptA);
314  InputCoordRepType L2B = pt2.SquaredEuclideanDistanceTo(ptB);
315 
317 
318  InputCoordRepType AreaA = 0.5 * ( cross(v1A, v12).GetNorm() );
319  InputCoordRepType AreaB = 0.5 * ( cross(v1B, v12).GetNorm() );
320 
322  oValue = ( L1A + L2A - L12 ) / AreaA + ( L1B + L2B - L12 ) / AreaB;
323 
324  return oValue;
325  }
326 };
327 }
328 #endif
329