ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkQuadEdgeMeshParamMatrixCoefficients_h 00019 #define __itkQuadEdgeMeshParamMatrixCoefficients_h 00020 00021 #include "itkQuadEdgeMesh.h" 00022 #include "itkTriangleHelper.h" 00023 #include "vnl/vnl_math.h" 00024 00025 namespace itk 00026 { 00032 template< typename TInputMesh > 00033 class ITK_EXPORT MatrixCoefficients 00034 { 00035 public: 00036 typedef TInputMesh InputMeshType; 00037 typedef typename InputMeshType::CoordRepType InputCoordRepType; 00038 typedef typename InputMeshType::QEType InputQEType; 00039 00040 MatrixCoefficients(){} 00041 virtual ~MatrixCoefficients() {} 00042 00043 virtual InputCoordRepType operator() 00044 (const InputMeshType *iMesh, InputQEType *iEdge) const = 0; 00045 }; 00046 00054 template< typename TInputMesh > 00055 class ITK_EXPORT OnesMatrixCoefficients:public MatrixCoefficients< TInputMesh > 00056 { 00057 public: 00058 typedef MatrixCoefficients< TInputMesh > Superclass; 00059 00060 typedef TInputMesh InputMeshType; 00061 typedef typename InputMeshType::CoordRepType InputCoordRepType; 00062 typedef typename InputMeshType::QEType InputQEType; 00063 00064 OnesMatrixCoefficients() {} 00065 00069 InputCoordRepType operator()( const InputMeshType *itkNotUsed(iMesh), 00070 InputQEType *itkNotUsed(iEdge) ) const 00071 { 00072 return 1.0; 00073 } 00074 }; 00076 00084 template< typename TInputMesh > 00085 class ITK_EXPORT InverseEuclideanDistanceMatrixCoefficients: 00086 public MatrixCoefficients< TInputMesh > 00087 { 00088 public: 00089 typedef MatrixCoefficients< TInputMesh > Superclass; 00090 00091 typedef TInputMesh InputMeshType; 00092 typedef typename InputMeshType::CoordRepType InputCoordRepType; 00093 typedef typename InputMeshType::PointType InputPointType; 00094 typedef typename InputMeshType::PointIdentifier InputPointIdentifier; 00095 typedef typename InputMeshType::QEType InputQEType; 00096 typedef typename InputMeshType::VectorType InputVectorType; 00097 00098 InverseEuclideanDistanceMatrixCoefficients() {} 00099 00105 InputCoordRepType operator()(const InputMeshType *iMesh, InputQEType *iEdge) const 00106 { 00107 InputPointIdentifier id1 = iEdge->GetOrigin(); 00108 InputPointIdentifier id2 = iEdge->GetDestination(); 00110 00111 InputPointType pt1 = iMesh->GetPoint(id1); 00112 InputPointType pt2 = iMesh->GetPoint(id2); 00113 00114 InputCoordRepType oValue = 1.0 / pt1.EuclideanDistanceTo(pt2); 00115 00116 return oValue; 00117 } 00118 }; 00119 00127 template< typename TInputMesh > 00128 class ITK_EXPORT ConformalMatrixCoefficients:public MatrixCoefficients< TInputMesh > 00129 { 00130 public: 00131 typedef MatrixCoefficients< TInputMesh > Superclass; 00132 00133 typedef TInputMesh InputMeshType; 00134 typedef typename InputMeshType::CoordRepType InputCoordRepType; 00135 typedef typename InputMeshType::PointType InputPointType; 00136 typedef typename InputMeshType::PointIdentifier InputPointIdentifier; 00137 typedef typename InputMeshType::QEType InputQEType; 00138 00139 ConformalMatrixCoefficients() {} 00140 00146 InputCoordRepType operator()(const InputMeshType *iMesh, InputQEType *iEdge) const 00147 { 00148 InputPointIdentifier id1 = iEdge->GetOrigin(); 00149 InputPointIdentifier id2 = iEdge->GetDestination(); 00150 InputPointType pt1 = iMesh->GetPoint(id1); 00151 InputPointType pt2 = iMesh->GetPoint(id2); 00153 00154 InputCoordRepType oValue(0.0); 00155 00156 if ( iEdge->IsLeftSet() ) 00157 { 00158 InputPointIdentifier idA = iEdge->GetLnext()->GetDestination(); 00159 InputPointType ptA = iMesh->GetPoint(idA); 00160 oValue += TriangleHelper< InputPointType >::Cotangent(pt1, ptA, pt2); 00161 } 00162 if ( iEdge->IsRightSet() ) 00163 { 00164 InputPointIdentifier idB = iEdge->GetRnext()->GetOrigin(); 00165 InputPointType ptB = iMesh->GetPoint(idB); 00166 oValue += TriangleHelper< InputPointType >::Cotangent(pt1, ptB, pt2); 00167 } 00168 00169 return vnl_math_max(static_cast< InputCoordRepType >( 0.0 ), oValue); 00170 } 00171 }; 00172 00181 template< typename TInputMesh > 00182 class ITK_EXPORT AuthalicMatrixCoefficients:public MatrixCoefficients< TInputMesh > 00183 { 00184 public: 00185 typedef MatrixCoefficients< TInputMesh > Superclass; 00186 00187 typedef TInputMesh InputMeshType; 00188 typedef typename InputMeshType::CoordRepType InputCoordRepType; 00189 typedef typename InputMeshType::PointType InputPointType; 00190 typedef typename InputMeshType::PointIdentifier InputPointIdentifier; 00191 typedef typename InputMeshType::QEType InputQEType; 00192 00193 AuthalicMatrixCoefficients() {} 00194 00201 InputCoordRepType operator()(const InputMeshType *iMesh, InputQEType *iEdge) const 00202 { 00203 InputPointIdentifier id1 = iEdge->GetOrigin(); 00204 InputPointType pt1 = iMesh->GetPoint(id1); 00206 00207 InputPointIdentifier id2 = iEdge->GetDestination(); 00208 InputPointType pt2 = iMesh->GetPoint(id2); 00209 00210 InputCoordRepType oValue(0.0); 00211 00212 if ( iEdge->IsLeftSet() ) 00213 { 00214 InputPointIdentifier idA = iEdge->GetLnext()->GetDestination(); 00215 InputPointType ptA = iMesh->GetPoint(idA); 00216 oValue += 00217 TriangleHelper< InputPointType >::Cotangent(pt1, pt2, ptA); 00218 } 00219 00220 if ( iEdge->IsRightSet() ) 00221 { 00222 InputPointIdentifier idB = iEdge->GetRnext()->GetOrigin(); 00223 InputPointType ptB = iMesh->GetPoint(idB); 00224 oValue += TriangleHelper< InputPointType >::Cotangent(pt1, pt2, ptB); 00225 } 00226 00227 return oValue / pt1.SquaredEuclideanDistanceTo(pt2); 00228 } 00229 }; 00230 00238 template< typename TInputMesh > 00239 class ITK_EXPORT IntrinsicMatrixCoefficients:public MatrixCoefficients< TInputMesh > 00240 { 00241 public: 00242 typedef MatrixCoefficients< TInputMesh > Superclass; 00243 00244 typedef TInputMesh InputMeshType; 00245 typedef typename InputMeshType::CoordRepType InputCoordRepType; 00246 typedef typename InputMeshType::QEType InputQEType; 00247 00248 InputCoordRepType m_Lambda; 00249 00250 IntrinsicMatrixCoefficients(const InputCoordRepType & iLambda): 00251 m_Lambda(iLambda) 00252 {} 00253 00254 InputCoordRepType operator()(const InputMeshType *iMesh, 00255 InputQEType *iEdge) const 00256 { 00257 AuthalicMatrixCoefficients< TInputMesh > authalic; 00258 ConformalMatrixCoefficients< TInputMesh > conformal; 00259 00260 InputCoordRepType oValue = m_Lambda * conformal(iMesh, iEdge) 00261 + ( 1.0 - m_Lambda ) * authalic(iMesh, iEdge); 00262 00263 return oValue; 00264 } 00265 }; 00266 00274 template< typename TInputMesh > 00275 class ITK_EXPORT HarmonicMatrixCoefficients:public MatrixCoefficients< TInputMesh > 00276 { 00277 public: 00278 typedef MatrixCoefficients< TInputMesh > Superclass; 00279 00280 typedef TInputMesh InputMeshType; 00281 typedef typename InputMeshType::CoordRepType InputCoordRepType; 00282 typedef typename InputMeshType::PointType InputPointType; 00283 typedef typename InputPointType::VectorType InputVectorType; 00284 typedef typename InputMeshType::PointIdentifier InputPointIdentifier; 00285 typedef typename InputMeshType::QEType InputQEType; 00286 00287 itkStaticConstMacro(PointDimension, unsigned int, 00288 InputPointType::PointDimension); 00289 00290 HarmonicMatrixCoefficients() {} 00291 00292 InputCoordRepType operator()(const InputMeshType *iMesh, InputQEType *iEdge) const 00293 { 00294 InputPointIdentifier id1 = iEdge->GetOrigin(); 00295 InputPointIdentifier id2 = iEdge->GetDestination(); 00296 00297 InputPointIdentifier idA = iEdge->GetLnext()->GetDestination(); 00298 InputPointIdentifier idB = iEdge->GetRnext()->GetOrigin(); 00299 00300 InputPointType pt1 = iMesh->GetPoint(id1); 00301 InputPointType pt2 = iMesh->GetPoint(id2); 00302 InputPointType ptA = iMesh->GetPoint(idA); 00303 InputPointType ptB = iMesh->GetPoint(idB); 00304 00305 InputVectorType v1A = ptA - pt1; 00306 InputVectorType v1B = ptB - pt1; 00307 InputVectorType v12 = pt2 - pt1; 00308 00309 InputCoordRepType L1A = v1A * v1A; 00310 InputCoordRepType L1B = v1B * v1B; 00311 InputCoordRepType L12 = v12 * v12; 00312 00313 InputCoordRepType L2A = pt2.SquaredEuclideanDistanceTo(ptA); 00314 InputCoordRepType L2B = pt2.SquaredEuclideanDistanceTo(ptB); 00315 00316 CrossHelper< InputVectorType > cross; 00317 00318 InputCoordRepType AreaA = 0.5 * ( cross(v1A, v12).GetNorm() ); 00319 InputCoordRepType AreaB = 0.5 * ( cross(v1B, v12).GetNorm() ); 00320 00321 InputCoordRepType 00322 oValue = ( L1A + L2A - L12 ) / AreaA + ( L1B + L2B - L12 ) / AreaB; 00323 00324 return oValue; 00325 } 00326 }; 00327 } 00328 #endif 00329