00001 /* 00002 // 00003 // Copyright 1997-2009 Torsten Rohlfing 00004 // 00005 // Copyright 2004-2011 SRI International 00006 // 00007 // This file is part of the Computational Morphometry Toolkit. 00008 // 00009 // http://www.nitrc.org/projects/cmtk/ 00010 // 00011 // The Computational Morphometry Toolkit is free software: you can 00012 // redistribute it and/or modify it under the terms of the GNU General Public 00013 // License as published by the Free Software Foundation, either version 3 of 00014 // the License, or (at your option) any later version. 00015 // 00016 // The Computational Morphometry Toolkit is distributed in the hope that it 00017 // will be useful, but WITHOUT ANY WARRANTY; without even the implied 00018 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU General Public License along 00022 // with the Computational Morphometry Toolkit. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 // 00025 // $Revision: 2752 $ 00026 // 00027 // $LastChangedDate: 2011-01-17 11:33:31 -0800 (Mon, 17 Jan 2011) $ 00028 // 00029 // $LastChangedBy: torstenrohlfing $ 00030 // 00031 */ 00032 00033 #ifndef __cmtkParametricPlane_h_included_ 00034 #define __cmtkParametricPlane_h_included_ 00035 00036 #include <cmtkconfig.h> 00037 00038 #include <Base/cmtkMacros.h> 00039 #include <Base/cmtkVector.h> 00040 #include <Base/cmtkAffineXform.h> 00041 #include <Base/cmtkMathUtil.h> 00042 #include <Base/cmtkUnits.h> 00043 00044 namespace 00045 cmtk 00046 { 00047 00050 00053 class ParametricPlane 00054 { 00055 public: 00057 typedef ParametricPlane Self; 00058 00060 typedef SmartPointer<Self> SmartPtr; 00061 00063 typedef FixedVector<3,Types::Coordinate> CoordinateVectorType; 00064 00066 ParametricPlane(); 00067 00073 cmtkGetSetMacro(Self::CoordinateVectorType,Origin); 00074 00076 void SetRho( const Types::Coordinate rho ) 00077 { 00078 Rho = rho; this->Update(); 00079 } 00080 00082 Types::Coordinate GetRho() const 00083 { 00084 return Rho; 00085 } 00086 00088 void SetTheta( const Units::Degrees& theta ) 00089 { 00090 Theta = theta; this->Update(); 00091 } 00092 00094 const Units::Degrees GetTheta() const 00095 { 00096 return Theta; 00097 } 00098 00100 void SetPhi( const Units::Degrees& phi ) 00101 { 00102 Phi = phi; this->Update(); 00103 } 00104 00106 const Units::Degrees GetPhi() const 00107 { 00108 return Phi; 00109 } 00110 00112 void SetNormal( const Self::CoordinateVectorType& normal ); 00113 00115 void GetParameters( CoordinateVector& v ) const 00116 { 00117 v.SetDim( 6 ); 00118 v[0] = Rho; v[1] = Theta.Value(); v[2] = Phi.Value(); 00119 v[3] = this->m_Origin[0]; v[4] = this->m_Origin[1]; v[5] = this->m_Origin[2]; 00120 } 00121 00123 void SetParameters( const CoordinateVector& v ) 00124 { 00125 Rho = v[0]; Theta = Units::Degrees( v[1] ); Phi = Units::Degrees( v[2] ); 00126 this->m_Origin[0] = v[3]; this->m_Origin[1] = v[4]; this->m_Origin[2] = v[5]; 00127 this->Update(); 00128 } 00129 00134 char GetWhichSide( const Self::CoordinateVectorType& point ) const 00135 { 00136 // move given origin to coordinate origin 00137 Self::CoordinateVectorType p = point; 00138 p -= this->m_Origin; 00139 00140 // compute line parameter of orthogonal projection of "point" onto this plane 00141 const Types::Coordinate intersect = Normal*p - Rho; 00142 return (intersect < 0) ? -1 : (intersect > 0) ? 1 : 0; 00143 } 00144 00146 void Mirror( Self::CoordinateVectorType& toPoint, const Self::CoordinateVectorType& fromPoint ) const 00147 { 00148 toPoint = fromPoint; 00149 this->MirrorInPlace( toPoint ); 00150 } 00151 00153 void MirrorInPlace( Self::CoordinateVectorType& point ) const 00154 { 00155 // move given origin to coordinate origin 00156 point -= this->m_Origin; 00157 00158 // compute line parameter of orthogonal projection of "point" onto 00159 // this plane and multiply by two to get parameter of mirrored point 00160 const Types::Coordinate intersect = 2 * (( Normal * point - Rho ) / SquareNormal); 00161 00162 // compute mirrored point 00163 for ( int dim = 0; dim < 3; ++dim ) 00164 point[dim] -= intersect * Normal[dim]; 00165 00166 // move given origin back to its given location 00167 point += this->m_Origin; 00168 } 00169 00171 void Project( Self::CoordinateVectorType& toPoint, const Self::CoordinateVectorType& fromPoint ) const 00172 { 00173 toPoint = fromPoint; 00174 this->ProjectInPlace( toPoint ); 00175 } 00176 00178 void ProjectInPlace( Self::CoordinateVectorType& point ) const 00179 { 00180 // move given origin to coordinate origin 00181 point -= this->m_Origin; 00182 00183 // compute line parameter of orthogonal projection of "point" onto 00184 // this plane 00185 const Types::Coordinate intersect = ( Normal * point - Rho ) / SquareNormal; 00186 00187 // compute projected point 00188 for ( int dim = 0; dim < 3; ++dim ) 00189 point[dim] -= intersect * Normal[dim]; 00190 00191 // move given origin back to its given location 00192 point += this->m_Origin; 00193 } 00194 00202 AffineXform* GetAlignmentXform( const byte normalAxis = 0 ) const; 00203 00205 AffineXform::MatrixType GetMirrorXformMatrix() const; 00206 00209 const Self::CoordinateVectorType& GetNormal() const { return Normal; } 00210 00211 private: 00213 Types::Coordinate Rho; 00214 00216 Units::Degrees Theta; 00217 00219 Units::Degrees Phi; 00220 00222 Self::CoordinateVectorType Normal; 00223 00225 Types::Coordinate SquareNormal; 00226 00228 void Update(); 00229 }; 00230 00232 00233 } // namespace cmtk 00234 00235 #endif // #ifndef __cmtkParametricPlane_h_included_