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 "cmtkUniformVolume.h"
00034
00035 namespace
00036 cmtk
00037 {
00038
00041
00042 void
00043 UniformVolume::SetHighResCropRegion
00044 ( const Self::CoordinateRegionType& crop )
00045 {
00046 if ( !this->m_HighResCropRegion )
00047 this->m_HighResCropRegion = Self::CoordinateRegionType::SmartPtr( new CoordinateRegionType );
00048
00049 *this->m_HighResCropRegion = crop;
00050
00051 for ( int dim = 0; dim<3; ++dim )
00052 {
00053 this->CropRegion().From()[dim] = std::max<Self::IndexType::ValueType>( static_cast<Self::IndexType::ValueType>( (crop.From()[dim] - this->m_Offset[dim]) / this->m_Delta[dim] ), 0 );
00054
00055 this->CropRegion().To()[dim] = 1 + std::min<Self::IndexType::ValueType>( static_cast<Self::IndexType::ValueType>( (crop.To()[dim] - this->m_Offset[dim]) / this->m_Delta[dim] ), this->m_Dims[dim]-1 );
00056 }
00057 }
00058
00059 const UniformVolume::CoordinateRegionType
00060 UniformVolume::GetHighResCropRegion
00061 () const
00062 {
00063 if ( this->m_HighResCropRegion )
00064 {
00065 return *this->m_HighResCropRegion;
00066 }
00067 else
00068 {
00069 UniformVolume::CoordinateRegionType region;
00070
00071 for ( int dim = 0; dim<3; ++dim )
00072 {
00073 region.From()[dim] = this->m_Offset[dim] + this->m_Delta[dim] * (this->CropRegion().From()[dim]);
00074 region.To()[dim] = this->m_Offset[dim] + this->m_Delta[dim] * (this->CropRegion().To()[dim]-1);
00075
00076
00077 }
00078 return region;
00079 }
00080 }
00081
00082 UniformVolume::SmartPtr
00083 UniformVolume::GetCroppedVolume() const
00084 {
00085 const Self::IndexType cropDims = this->CropRegion().To() - this->CropRegion().From();
00086
00087 Self::CoordinateVectorType cropSize( cropDims );
00088 for ( size_t i = 0; i < 3; ++i )
00089 (cropSize[i] -= 1) *= this->m_Delta[i];
00090
00091 Self::SmartPtr volume( new UniformVolume( cropDims, cropSize ) );
00092
00093
00094 TypedArray::SmartPtr croppedData( this->GetCroppedData() );
00095 volume->SetData( croppedData );
00096
00097
00098 volume->m_IndexToPhysicalMatrix = this->m_IndexToPhysicalMatrix;
00099 for ( int i = 0; i < 3; ++i )
00100 for ( int j = 0; j < 3; ++j )
00101 volume->m_IndexToPhysicalMatrix[3][i] += this->CropRegion().From()[j] * volume->m_IndexToPhysicalMatrix[j][i];
00102
00103
00104 Self::CoordinateVectorType volumeOffset = this->m_Offset;
00105 for ( int i = 0; i < 3; ++i )
00106 volumeOffset[i] += (this->CropRegion().From()[i] * this->m_Delta[i]);
00107 volume->SetOffset( volumeOffset );
00108
00109 if ( this->m_HighResCropRegion )
00110 volume->SetHighResCropRegion( *this->m_HighResCropRegion );
00111
00112 volume->m_MetaInformation[META_IMAGE_ORIENTATION] = this->m_MetaInformation[META_IMAGE_ORIENTATION];
00113 volume->m_MetaInformation[META_IMAGE_ORIENTATION_ORIGINAL] = this->m_MetaInformation[META_IMAGE_ORIENTATION_ORIGINAL];
00114
00115 volume->m_MetaInformation[META_SPACE] = this->m_MetaInformation[META_SPACE];
00116
00117 return volume;
00118 }
00119
00120 }