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 "cmtkPlaneSource.h"
00034
00035 #include <Base/cmtkMathUtil.h>
00036
00037 namespace
00038 cmtk
00039 {
00040
00043
00044 PlaneSource::PlaneSource()
00045 {
00046 Direction = 0;
00047 Position = 0;
00048 Resolution = 1;
00049 Input[0] = Input[1] = NULL;
00050 this->RegisterInput( &Input[0] );
00051 this->RegisterInput( &Input[1] );
00052 ReferenceVolumeIndex = 0;
00053 }
00054
00055 int
00056 PlaneSource::HasValidInputs() const
00057 {
00058 if ( (Input[0] == NULL) || (Input[1] == NULL) ) return 0;
00059 Input[0]->Update();
00060 Input[1]->Update();
00061 if ( ! Input[0]->GetVolume() ) return 0;
00062 if ( ! Input[1]->GetVolume() ) return 0;
00063 if ( ! (Input[0]->GetVolume()->GetData()) ) return 0;
00064 if ( ! (Input[1]->GetVolume()->GetData()) ) return 0;
00065 return 1;
00066 }
00067
00068 void
00069 PlaneSource::SetInput
00070 ( const int index, VolumeWrapper *const input )
00071 {
00072 if ( (index < 0) || (index > 1) ) return;
00073
00074 this->ReplaceObject( Input[index], input );
00075 }
00076
00077 Types::Coordinate
00078 PlaneSource::GetMinPosition()
00079 {
00080 return 0;
00081 }
00082
00083 Types::Coordinate
00084 PlaneSource::GetMaxPosition()
00085 {
00086 if ( !Input[ReferenceVolumeIndex] ) return 0;
00087
00088 this->Update();
00089
00090 const Volume *volume = Input[ReferenceVolumeIndex]->GetVolume();
00091 if ( volume == NULL ) return 0;
00092
00093 switch ( Direction )
00094 {
00095 case SCANDIRECTION_CAUDAL_CRANIAL:
00096 case SCANDIRECTION_CRANIAL_CAUDAL:
00097 return volume->Size[2];
00098 case SCANDIRECTION_RIGHT_LEFT:
00099 case SCANDIRECTION_LEFT_RIGHT:
00100 return volume->Size[0];
00101 case SCANDIRECTION_VENTRAL_DORSAL:
00102 case SCANDIRECTION_DORSAL_VENTRAL:
00103 return volume->Size[1];
00104 }
00105
00106 return 0;
00107 }
00108
00109 Types::Coordinate
00110 PlaneSource::GetMaxResolution()
00111 {
00112 this->Update();
00113
00114 double maxResolution = 1000;
00115 for ( int i=0; i<2; ++i )
00116 {
00117 if ( Input[i] )
00118 {
00119 const UniformVolume *volume = Input[i]->GetVolume();
00120 if ( volume )
00121 maxResolution = std::min<Types::Coordinate>( maxResolution, volume->GetMinDelta() );
00122 }
00123 }
00124
00125
00126 return std::max<Types::Coordinate>( 0.05, maxResolution );
00127 }
00128
00129 void
00130 PlaneSource::Execute()
00131 {
00132 if ( !Input[ReferenceVolumeIndex] ) return;
00133 const Volume *volume = Input[ReferenceVolumeIndex]->GetVolume();
00134 if ( volume == NULL ) return;
00135
00136 Plane *output = this->GetOutput();
00137
00138 if ( Position < 0 ) Position = 0;
00139 output->SetSpacing( Resolution, Resolution );
00140
00141 switch ( Direction )
00142 {
00143 case SCANDIRECTION_CAUDAL_CRANIAL:
00144 case SCANDIRECTION_CRANIAL_CAUDAL:
00145 if ( Position > volume->Size[2] ) Position = volume->Size[2];
00146
00147 output->SetDims( 1+(int)(volume->Size[0]/Resolution), 1+(int)(volume->Size[1]/Resolution) );
00148
00149 output->SetDirectionY( 0, 1, 0 );
00150
00151 if ( Direction == SCANDIRECTION_CAUDAL_CRANIAL )
00152 {
00153 output->SetOrigin( 0, 0, Position );
00154 output->SetDirectionX( 1, 0, 0 );
00155 }
00156 else
00157 {
00158 output->SetOrigin( volume->Size[0], 0, Position );
00159 output->SetDirectionX( -1, 0, 0 );
00160 }
00161 break;
00162 case SCANDIRECTION_RIGHT_LEFT:
00163 case SCANDIRECTION_LEFT_RIGHT:
00164 if ( Position > volume->Size[0] ) Position = volume->Size[0];
00165
00166 output->SetDims( 1+(int)(volume->Size[1]/Resolution), 1+(int)(volume->Size[2]/Resolution) );
00167
00168 output->SetDirectionY( 0, 0, -1 );
00169
00170 if ( Direction == SCANDIRECTION_RIGHT_LEFT )
00171 {
00172 output->SetOrigin( Position, 0, volume->Size[2] );
00173 output->SetDirectionX( 0, 1, 0 );
00174 }
00175 else
00176 {
00177 output->SetOrigin( Position, volume->Size[1], volume->Size[2] );
00178 output->SetDirectionX( 0, -1, 0 );
00179 }
00180 break;
00181 case SCANDIRECTION_VENTRAL_DORSAL:
00182 case SCANDIRECTION_DORSAL_VENTRAL:
00183 if ( Position > volume->Size[1] ) Position = volume->Size[1];
00184
00185 output->SetDims( 1+(int)(volume->Size[0]/Resolution), 1+(int)(volume->Size[2]/Resolution) );
00186
00187 output->SetDirectionY( 0, 0, -1 );
00188
00189 if ( Direction == SCANDIRECTION_DORSAL_VENTRAL )
00190 {
00191 output->SetOrigin( 0, Position, volume->Size[2] );
00192 output->SetDirectionX( 1, 0, 0 );
00193 }
00194 else
00195 {
00196 output->SetOrigin( volume->Size[0], Position, volume->Size[2] );
00197 output->SetDirectionX( -1, 0, 0 );
00198 }
00199
00200 break;
00201 }
00202 }
00203
00204 }