cmtkTransformedVolumeAxes.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: 2464 $
00026 //
00027 //  $LastChangedDate: 2010-10-19 09:54:33 -0700 (Tue, 19 Oct 2010) $
00028 //
00029 //  $LastChangedBy: torsten_at_home $
00030 //
00031 */
00032 
00033 #include "cmtkTransformedVolumeAxes.h"
00034 
00035 #include <cassert>
00036 
00037 namespace
00038 cmtk
00039 {
00040 
00043 
00044 TransformedVolumeAxes::TransformedVolumeAxes
00045 ( const UniformVolume& volume, const AffineXform* xform, const Types::Coordinate* deltas, const Types::Coordinate* otherOrigin )
00046 {
00047   // define volume corners
00048   UniformVolume::CoordinateVectorType dX = FixedVectorStaticInitializer<3,Types::Coordinate>::Init(1,0,0);
00049   UniformVolume::CoordinateVectorType dY = FixedVectorStaticInitializer<3,Types::Coordinate>::Init(0,1,0);
00050   UniformVolume::CoordinateVectorType dZ = FixedVectorStaticInitializer<3,Types::Coordinate>::Init(0,0,1);
00051   UniformVolume::CoordinateVectorType V( volume.m_Offset );
00052   
00053   dX += volume.m_Offset;
00054   dY += volume.m_Offset;
00055   dZ += volume.m_Offset;
00056     
00057   if ( xform ) 
00058     {
00059     xform->ApplyInPlace(V);
00060     xform->ApplyInPlace(dX);
00061     xform->ApplyInPlace(dY);
00062     xform->ApplyInPlace(dZ);
00063     }
00064 
00065   dX -= V;
00066   dY -= V;
00067   dZ -= V;
00068   
00069   if ( otherOrigin )
00070     {
00071     V -= FixedVector<3,Types::Coordinate>( otherOrigin );
00072     }
00073   
00074   // Apply post-transformation scaling
00075   if ( deltas ) 
00076     {
00077     const UniformVolume::CoordinateVectorType deltasV( deltas );
00078     dX /= deltasV;
00079     dY /= deltasV;
00080     dZ /= deltasV;
00081     V /= deltasV;
00082     }
00083   
00084   this->MakeHash( volume, V, dX, dY, dZ );
00085 }
00086 
00087 TransformedVolumeAxes::TransformedVolumeAxes
00088 ( const UniformVolume& volume, const ParametricPlane& mirrorPlane, const Types::Coordinate* deltas )
00089 {
00090   // define volume corners
00091   UniformVolume::CoordinateVectorType dX = FixedVectorStaticInitializer<3,Types::Coordinate>::Init(1,0,0);
00092   UniformVolume::CoordinateVectorType dY = FixedVectorStaticInitializer<3,Types::Coordinate>::Init(0,1,0);
00093   UniformVolume::CoordinateVectorType dZ = FixedVectorStaticInitializer<3,Types::Coordinate>::Init(0,0,1);
00094   UniformVolume::CoordinateVectorType V( volume.m_Offset );
00095   
00096   // apply mirror transformation  
00097   mirrorPlane.MirrorInPlace(V);
00098   mirrorPlane.MirrorInPlace(dX);
00099   dX -= V;
00100   mirrorPlane.MirrorInPlace(dY);
00101   dY -= V;
00102   mirrorPlane.MirrorInPlace(dZ);
00103   dZ -= V;
00104   
00105   // Apply post-transformation scaling
00106   if ( deltas ) 
00107     {
00108     const UniformVolume::CoordinateVectorType deltasV( deltas );
00109     dX /= deltasV;
00110     dY /= deltasV;
00111     dZ /= deltasV;
00112     V /= deltasV;
00113     }
00114 
00115   this->MakeHash( volume, V, dX, dY, dZ );
00116 }
00117 
00118 void
00119 TransformedVolumeAxes::MakeHash
00120 ( const UniformVolume& volume, const UniformVolume::SpaceVectorType& offset, const UniformVolume::SpaceVectorType& dX, const UniformVolume::SpaceVectorType& dY, const UniformVolume::SpaceVectorType& dZ )
00121 {
00122   this->m_Dims = volume.m_Dims;  
00123   for ( int dim = 0; dim<3; ++dim ) 
00124     {
00125     this->m_Hash[dim] = Memory::AllocateArray<UniformVolume::SpaceVectorType>( this->m_Dims[dim] );
00126     assert( this->m_Hash[dim] != NULL );
00127     }
00128 
00129   const Types::Coordinate deltaX = volume.m_Delta[0];
00130   const Types::Coordinate deltaY = volume.m_Delta[1];
00131   const Types::Coordinate deltaZ = volume.m_Delta[2];
00132   
00133   int idx;
00134   for ( idx=0; idx < this->m_Dims[0]; ++idx )
00135     this->m_Hash[0][idx] = deltaX*idx*dX;
00136 
00137   for ( idx=0; idx < this->m_Dims[1]; ++idx )
00138     this->m_Hash[1][idx] = deltaY*idx*dY;
00139 
00140   for ( idx=0; idx < this->m_Dims[2]; ++idx )
00141     (this->m_Hash[2][idx] = deltaZ*idx*dZ) += offset;
00142 }
00143 
00144 TransformedVolumeAxes::~TransformedVolumeAxes()
00145 {
00146   for ( int dim = 0; dim<3; ++dim ) 
00147     {
00148     assert( this->m_Hash[dim] != NULL );
00149     Memory::DeleteArray( this->m_Hash[dim] );
00150     }
00151 }
00152 
00153 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines