Orfeo Toolbox  3.16
itkSimplexMeshGeometry.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkSimplexMeshGeometry.cxx,v $
5  Language: C++
6  Date: $Date: 2009-03-03 15:09:26 $
7  Version: $Revision: 1.7 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 
18 #include "itkSimplexMeshGeometry.h"
19 #include "itkNumericTraits.h"
20 
21 #include <vxl_version.h>
22 #if VXL_VERSION_DATE_FULL > 20040406
23 # include <vnl/vnl_cross.h>
24 # define cross_3d vnl_cross_3d
25 #endif
26 
27 namespace itk
28 {
29 
30 
33 {
34  double c = 1.0/3.0;
35  PointType p;
36  p.Fill(0.0);
37 
38  pos.Fill(0);
39  oldPos.Fill(0);
40  referenceMetrics.Fill(c);
41  eps.Fill(c);
42  normal.Fill(0);
43  externalForce.Fill(0);
44  internalForce.Fill(0);
45  circleRadius = 0;
46  circleCenter.Fill(0);
47  sphereRadius = 0;
48  distance = 0;
49  phi = 0;
50 
51  neighborIndices.Fill((unsigned long) NumericTraits<unsigned long>::max());
52  neighbors.Fill(p);
53  meanCurvature = c;
54 }
55 
56 
59 {
60 }
61 
62 void
65 {
66  VectorType b,c,cXb, tmp;
67 
68  //compute the circum circle (center and radius)
69  b = this->neighbors[2] - this->neighbors[0];
70  c = this->neighbors[1] - this->neighbors[0];
71 
72  cXb.SetVnlVector( cross_3d<double>(c.GetVnlVector(),b.GetVnlVector()) );
73 
74  tmp.SetVnlVector( b.GetSquaredNorm() *
75  cross_3d<double>( cXb.GetVnlVector(), c.GetVnlVector() ) +
76  c.GetSquaredNorm() *
77  cross_3d<double>( b.GetVnlVector() , cXb.GetVnlVector() ) );
78 
79  double cXbSquaredNorm = 2 * cXb.GetSquaredNorm();
80 
81  circleRadius = tmp.GetNorm()/(cXbSquaredNorm);
82  tmp[0] /= (cXbSquaredNorm);
83  tmp[1] /= (cXbSquaredNorm);
84  tmp[2] /= (cXbSquaredNorm);
85  circleCenter = this->neighbors[0] + tmp;
86 
87  // Compute the circum sphere (center and radius) of a point
88  VectorType d,dXc,bXd,sphereTmp, denom;
89 
90  d = pos - this->neighbors[0];
91  dXc.SetVnlVector( cross_3d<double>(d.GetVnlVector(),c.GetVnlVector()) );
92  bXd.SetVnlVector( cross_3d<double>(b.GetVnlVector(),d.GetVnlVector()) );
93 
94  sphereTmp.SetVnlVector( d.GetSquaredNorm()* cXb.GetVnlVector() +
95  b.GetSquaredNorm()* dXc.GetVnlVector() +
96  c.GetSquaredNorm()* bXd.GetVnlVector());
97 
98  double val = 2 * (c[0]*(b[1]*d[2]-b[2]*d[1]) -
99  c[1]*( b[0]*d[2]-b[2]*d[0] ) +
100  c[2]*( b[0]*d[1]-b[1]*d[0] ));
101 
102  // fix for points which lay on their neighbors plane
103  // necessary ??
104  if (val == 0)
105  {
106  val = 1; // assert (val != 0 );
107  }
108 
109  sphereRadius = sphereTmp.GetNorm()/val;
110 
111  if (sphereRadius < 0)
112  {
113  sphereRadius = -1 * sphereRadius;
114  }
115 }
116 
117 } // end namespace itk

Generated at Sun Feb 3 2013 00:07:33 for Orfeo Toolbox with doxygen 1.8.1.1