cmtkPlane.cxx

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //
00005 //  Copyright 2004-2010 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: 2398 $
00026 //
00027 //  $LastChangedDate: 2010-10-05 14:54:37 -0700 (Tue, 05 Oct 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #include <cmtkconfig.h>
00034 
00035 #include <Pipeline/cmtkPlane.h>
00036 
00037 namespace
00038 cmtk
00039 {
00040 
00043 
00044 Plane::Plane()
00045 {
00046   Dims[0] = Dims[1] = 0;
00047   Spacing[0] = Spacing[1] = 1;
00048   Origin[0] = Origin[1] = Origin[2] = 0;
00049   DirectionX[0] = 1;
00050   DirectionY[1] = 1;
00051   DirectionX[1] = DirectionX[2] = DirectionY[0] = DirectionY[2] = 0;
00052 }
00053 
00054 void Plane::CopyStructure( const Plane *plane )
00055 {
00056   this->SetDims( plane->GetDims() );
00057   this->SetSpacing( plane->GetSpacing() );
00058   this->SetOrigin( plane->GetOrigin() );
00059   this->SetDirectionX( plane->GetDirectionX() );
00060   this->SetDirectionY( plane->GetDirectionY() );
00061 }
00062 
00063 void Plane::Project( Vector3D& p, const Vector3D& q ) const
00064 {
00065   Vector3D v( q );
00066   v[0] -= Origin[0];
00067   v[1] -= Origin[1];
00068   v[2] -= Origin[2];
00069 
00070   p[0] = 
00071     ( v[0] * DirectionX[0] + v[1] * DirectionX[1] + v[2] * DirectionX[2] ) /
00072     ( MathUtil::Square( DirectionX[0] ) + MathUtil::Square( DirectionX[1] ) + MathUtil::Square( DirectionX[2] ) );
00073   p[1] = 
00074     ( v[0] * DirectionY[0] + v[1] * DirectionY[1] + v[2] * DirectionY[2] ) /
00075     ( MathUtil::Square( DirectionY[0] ) + MathUtil::Square( DirectionY[1] ) + MathUtil::Square( DirectionY[2] ) );
00076   p[2] = 0;
00077 }
00078 
00079 void
00080 Plane::ProjectPixel( const Vector3D& v, unsigned int& i, unsigned int& j ) const
00081 {
00082   Vector3D q(v), p;
00083   this->Project( p, q );
00084 
00085   i = MathUtil::Round( p[0] / Spacing[0] );
00086   j = MathUtil::Round( p[1] / Spacing[1] );
00087 }
00088 
00089 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines