Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
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
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 }