cmtkUniformVolumePainter.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: 2022 $
00026 //
00027 //  $LastChangedDate: 2010-07-21 15:26:03 -0700 (Wed, 21 Jul 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #include "cmtkUniformVolumePainter.h"
00034 
00035 void
00036 cmtk::UniformVolumePainter::DrawSphere
00037 ( const UniformVolume::CoordinateVectorType& center, const Types::Coordinate radius, const Types::DataItem value )
00038 {
00039   UniformVolume::CoordinateVectorType centerAbsolute( center );
00040   Types::Coordinate radiusAbsolute[3] = { radius, radius, radius };
00041   
00042   switch ( this->m_CoordinateMode )
00043     {
00044     default:
00045     case Self::COORDINATES_ABSOLUTE:
00046       // nothing to do - already absolute
00047       break;
00048     case Self::COORDINATES_RELATIVE:
00049       for ( int dim = 0; dim < 3; ++dim )
00050         {
00051         centerAbsolute[dim] *= this->m_Volume->Size[dim];
00052         radiusAbsolute[dim] *= this->m_Volume->Size[dim];
00053         }
00054       break;
00055     case Self::COORDINATES_INDEXED:
00056       for ( int dim = 0; dim < 3; ++dim )
00057         {
00058         centerAbsolute[dim] *= this->m_Volume->m_Delta[dim];
00059         radiusAbsolute[dim] *= this->m_Volume->m_Delta[dim];
00060         }
00061       break;
00062     }
00063   
00064   size_t offset = 0;
00065   for ( int k = 0; k < this->m_Volume->m_Dims[2]; ++k )
00066     {
00067     const Types::Coordinate Z = this->m_Volume->GetPlaneCoord( 2, k );
00068     for ( int j = 0; j < this->m_Volume->m_Dims[1]; ++j )
00069       {
00070     const Types::Coordinate Y = this->m_Volume->GetPlaneCoord( 1, j );
00071       for ( int i = 0; i < this->m_Volume->m_Dims[0]; ++i, ++offset )
00072         {
00073         const Types::Coordinate X = this->m_Volume->GetPlaneCoord( 0, i );
00074         
00075         UniformVolume::CoordinateVectorType v = FixedVectorStaticInitializer<3,Types::Coordinate>::Init( X, Y, Z );
00076         v -= centerAbsolute;
00077 
00078         for ( int dim = 0; dim < 3; ++dim )
00079           {
00080           v[dim] /= radiusAbsolute[dim];
00081           }
00082 
00083         if ( v.RootSumOfSquares() <= 1.0 )
00084           this->m_Volume->SetDataAt( value, offset );
00085         }
00086       }
00087     }
00088 }
00089 
00090 void
00091 cmtk::UniformVolumePainter::DrawBox
00092 ( const UniformVolume::CoordinateVectorType& boxFrom, const UniformVolume::CoordinateVectorType& boxTo, const Types::DataItem value )
00093 {
00094   int indexFrom[3], indexTo[3];
00095 
00096   switch ( this->m_CoordinateMode )
00097     {
00098     default:
00099     case Self::COORDINATES_ABSOLUTE:
00100       for ( int dim = 0; dim < 3; ++dim )
00101         {
00102         indexFrom[dim] = static_cast<int>( MathUtil::Round( boxFrom[dim] / this->m_Volume->m_Delta[dim] ) );
00103         indexTo[dim] = static_cast<int>( MathUtil::Round( boxTo[dim] / this->m_Volume->m_Delta[dim] ) );
00104         }
00105       break;
00106     case Self::COORDINATES_RELATIVE:
00107       for ( int dim = 0; dim < 3; ++dim )
00108         {
00109         indexFrom[dim] = static_cast<int>( MathUtil::Round( boxFrom[dim] * this->m_Volume->Size[dim] / this->m_Volume->m_Delta[dim] ) );
00110         indexTo[dim] = static_cast<int>( MathUtil::Round( boxTo[dim] * this->m_Volume->Size[dim] / this->m_Volume->m_Delta[dim] ) );
00111         }
00112       break;
00113     case Self::COORDINATES_INDEXED:
00114       // nothing to do - already indexed
00115       for ( int dim = 0; dim < 3; ++dim )
00116         {
00117         indexFrom[dim] = static_cast<int>( boxFrom[dim] );
00118         indexTo[dim] = static_cast<int>( boxTo[dim] );
00119         }
00120       break;
00121     }
00122   
00123   for ( int k = indexFrom[2]; k <= indexTo[2]; ++k )
00124     {
00125     for ( int j = indexFrom[1]; j <= indexTo[1]; ++j )
00126       {
00127       for ( int i = indexFrom[0]; i <= indexTo[0]; ++i )
00128         {
00129         this->m_Volume->SetDataAt( value, this->m_Volume->GetOffsetFromIndex( i, j, k ) );
00130         }
00131       }
00132     }
00133 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines