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 "cmtkSplineWarpGroupwiseRegistrationRMIFunctional.h"
00034
00035 #include <Base/cmtkMathUtil.h>
00036 #include <Base/cmtkMatrix.h>
00037
00038 #include <System/cmtkThreadParameterArray.h>
00039
00040 #include <algorithm>
00041
00042 #ifdef CMTK_BUILD_MPI
00043 # include <mpi.h>
00044 #endif
00045
00046 namespace
00047 cmtk
00048 {
00049
00052
00053 void
00054 SplineWarpGroupwiseRegistrationRMIFunctional
00055 ::UpdateInformationByControlPoint()
00056 {
00057 this->m_NeedsUpdateInformationByControlPoint = false;
00058
00059 const size_t numberOfControlPoints = this->m_VolumeOfInfluenceArray.size();
00060 #ifdef CMTK_BUILD_MPI
00061 const size_t cpPerNode = 1 + numberOfControlPoints / this->m_SizeMPI;
00062 std::vector<byte> tmpInformationByCP( cpPerNode );
00063 #else
00064 this->m_InformationByControlPoint.resize( numberOfControlPoints );
00065 #endif
00066
00067 const byte paddingValue = this->m_PaddingValue;
00068
00069 #ifdef CMTK_BUILD_MPI
00070 const size_t beginCP = this->m_RankMPI * cpPerNode;
00071 const size_t endCP = std::min<size_t>( beginCP + cpPerNode, numberOfControlPoints );
00072 #else
00073 const size_t beginCP = 0;
00074 const size_t endCP = numberOfControlPoints;
00075 #endif
00076 for ( size_t cp = beginCP; cp < endCP; ++cp )
00077 {
00078 #ifdef CMTK_BUILD_MPI
00079 const size_t ofs = cp-beginCP;
00080 tmpInformationByCP[ofs] = 0;
00081 #else
00082 this->m_InformationByControlPoint[cp] = 0;
00083 #endif
00084
00085 std::vector<DataGrid::RegionType>::const_iterator voi = this->m_VolumeOfInfluenceArray.begin() + cp;
00086 for ( size_t img = this->m_ActiveImagesFrom; img < this->m_ActiveImagesTo; ++img )
00087 {
00088 const byte* dataPtrImg = this->m_Data[img];
00089
00090 byte voiMin = 255, voiMax = 0;
00091 for ( int z = voi->From()[2]; z < voi->To()[2]; ++z )
00092 {
00093 for ( int y = voi->From()[1]; y < voi->To()[1]; ++y )
00094 {
00095 size_t ofs = this->m_TemplateGrid->GetOffsetFromIndex( voi->From()[0], y, z );
00096 for ( int x = voi->From()[0]; x < voi->To()[0]; ++x, ++ofs )
00097 {
00098 const byte data = dataPtrImg[ofs];
00099 if ( data != paddingValue )
00100 {
00101 voiMin = std::min( data, voiMin );
00102 voiMax = std::max( data, voiMax );
00103 }
00104 }
00105 }
00106 }
00107 #ifdef CMTK_BUILD_MPI
00108 tmpInformationByCP[ofs] = std::max( (byte)(voiMax-voiMin), tmpInformationByCP[ofs] );
00109 #else
00110 this->m_InformationByControlPoint[cp] = std::max( (byte)(voiMax-voiMin), this->m_InformationByControlPoint[cp] );
00111 #endif
00112 }
00113 }
00114
00115 #ifdef CMTK_BUILD_MPI
00116 this->m_InformationByControlPoint.resize( cpPerNode * this->m_SizeMPI );
00117 MPI::COMM_WORLD.Allgather( &tmpInformationByCP[0], cpPerNode, MPI::CHAR, &this->m_InformationByControlPoint[0], cpPerNode, MPI::CHAR );
00118 #endif
00119
00120 this->UpdateActiveControlPoints();
00121 }
00122
00123 void
00124 SplineWarpGroupwiseRegistrationRMIFunctional::UpdateControlPointSchedule()
00125 {
00126 const SplineWarpXform* xform0 = this->GetXformByIndex(0);
00127 this->m_ControlPointSchedule.resize( xform0->GetNumberOfControlPoints() );
00128 this->m_ControlPointScheduleOverlapFreeMaxLength = (xform0->m_Dims[0] / 4) * (xform0->m_Dims[1] / 4) * (xform0->m_Dims[2] / 4);
00129
00130 size_t ofs = 0;
00131 for ( int z = 0; z < 4; ++z )
00132 {
00133 for ( int y = 0; y < 4; ++y )
00134 {
00135 for ( int x = 0; x < 4; ++x )
00136 {
00137 for ( int k = z; k < xform0->m_Dims[2]; k += 4 )
00138 {
00139 for ( int j = y; j < xform0->m_Dims[1]; j += 4 )
00140 {
00141 for ( int i = x; i < xform0->m_Dims[0]; i += 4, ++ofs )
00142 {
00143 this->m_ControlPointSchedule[ofs] = i + xform0->m_Dims[0] * ( j + xform0->m_Dims[1] * k );
00144 }
00145 }
00146 }
00147 }
00148 }
00149 }
00150 }
00151
00152 void
00153 SplineWarpGroupwiseRegistrationRMIFunctional::UpdateActiveControlPoints()
00154 {
00155 if ( this->m_DeactivateUninformativeMode )
00156 {
00157 const size_t numberOfControlPoints = this->m_VolumeOfInfluenceArray.size();
00158
00159 if ( numberOfControlPoints )
00160 {
00161 this->m_ActiveControlPointFlags.resize( numberOfControlPoints );
00162 this->m_NumberOfActiveControlPoints = 0;
00163
00164 const Vector3D templateFrom( this->m_TemplateGrid->m_Offset );
00165 const Vector3D templateTo( this->m_TemplateGrid->m_Offset + this->m_TemplateGrid->Size );
00166 Vector3D fromVOI, toVOI;
00167
00168 std::vector<DataGrid::RegionType>::const_iterator voi = this->m_VolumeOfInfluenceArray.begin();
00169 for ( size_t cp = 0; cp < numberOfControlPoints; ++cp, ++voi )
00170 {
00171 this->m_ActiveControlPointFlags[cp] = (this->m_InformationByControlPoint[cp] > (this->m_HistogramBins / 4) );
00172 if ( this->m_ActiveControlPointFlags[cp] )
00173 ++this->m_NumberOfActiveControlPoints;
00174 }
00175
00176 StdErr << "Enabled " << this->m_NumberOfActiveControlPoints
00177 << "/" << this->m_ParametersPerXform / 3
00178 << " control points.\n";
00179 }
00180 }
00181 else
00182 {
00183 this->m_NumberOfActiveControlPoints = this->m_VolumeOfInfluenceArray.size();
00184 }
00185
00186 this->UpdateParamStepArray();
00187 this->UpdateControlPointSchedule();
00188 }
00189
00190 SplineWarpGroupwiseRegistrationRMIFunctional::ReturnType
00191 SplineWarpGroupwiseRegistrationRMIFunctional::Evaluate()
00192 {
00193 return this->Superclass::Evaluate();
00194 }
00195
00197
00198 }
00199
00200 #ifdef CMTK_BUILD_MPI
00201 # include "cmtkSplineWarpGroupwiseRegistrationRMIFunctionalMPI.txx"
00202 #else
00203 # include "cmtkSplineWarpGroupwiseRegistrationRMIFunctional.txx"
00204 #endif