| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkSimplexMeshGeometry.cxx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:48 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 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 |
DEF |
=========================================================================*/ |
| 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 |
|
|
| 31 |
|
SimplexMeshGeometry |
| 32 |
|
::SimplexMeshGeometry() |
| 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 |
|
|
| 57 |
|
SimplexMeshGeometry |
| 58 |
|
::~SimplexMeshGeometry() |
| 59 |
|
{ |
| 60 |
|
} |
| 61 |
|
|
| 62 |
|
void |
| 63 |
|
SimplexMeshGeometry |
| 64 |
|
::ComputeGeometry() |
| 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 |
LEN,IND |
************************cross_3d<double>( cXb.GetVnlVector(), c.GetVnlVector() ) + |
| 76 |
IND |
**********************c.GetSquaredNorm() * |
| 77 |
LEN,IND |
************************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 |
IND |
****************************b.GetSquaredNorm()* dXc.GetVnlVector() + |
| 96 |
IND |
****************************c.GetSquaredNorm()* bXd.GetVnlVector() |
| 97 |
IND |
**************************); |
| 98 |
|
|
| 99 |
|
double val = 2 * (c[0]*(b[1]*d[2]-b[2]*d[1]) - |
| 100 |
IND |
********************c[1]*( b[0]*d[2]-b[2]*d[0] ) + |
| 101 |
IND |
********************c[2]*( b[0]*d[1]-b[1]*d[0] )); |
| 102 |
|
|
| 103 |
|
// fix for points which lay on their neighbors plane |
| 104 |
|
// necessary ?? |
| 105 |
|
if (val == 0) |
| 106 |
|
{ |
| 107 |
|
val = 1; // assert (val != 0 ); |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
sphereRadius = sphereTmp.GetNorm()/val; |
| 111 |
|
|
| 112 |
|
if (sphereRadius < 0) { |
| 113 |
|
sphereRadius = -1 * sphereRadius; |
| 114 |
IND |
**} |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
|
| 118 |
EML |
|
| 119 |
|
} // end namespace itk |
| 120 |
|
|
| 121 |
EOF |
|