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 #include "cmtkSimpleLevelsetDevice.h"
00032
00033 #include <Base/cmtkGaussianKernel.h>
00034 #include <Base/cmtkUnits.h>
00035
00036 #include <System/cmtkProgress.h>
00037
00038 #include <GPU/cmtkDeviceMemory.h>
00039 #include <GPU/cmtkDeviceUniformVolume.h>
00040 #include <GPU/cmtkDeviceUniformVolumeArray.h>
00041 #include <GPU/cmtkDeviceImageConvolution_kernels.h>
00042 #include <GPU/cmtkDeviceThresholdData_kernels.h>
00043 #include <GPU/cmtkSimpleLevelsetDevice_kernels.h>
00044
00045 #include <vector>
00046
00047 void
00048 cmtk::SimpleLevelsetDevice
00049 ::Evolve( const int numberOfIterations, const bool forceIterations )
00050 {
00051 FixedVector< 3, std::vector<float> > kernels;
00052
00053 for ( int dim = 0; dim < 3; ++dim )
00054 {
00055 kernels[dim] = GaussianKernel<float>::GetSymmetricKernel( this->m_FilterSigma / this->m_Volume->Deltas()[dim], 0.01 );
00056 }
00057
00058 const size_t numberOfPixels = this->m_Levelset->GetNumberOfPixels();
00059
00060 DeviceUniformVolume::SmartPtr deviceVolume = DeviceUniformVolume::Create( *(this->m_Volume) );
00061 DeviceUniformVolumeArray::SmartPtr deviceLevelset = DeviceUniformVolumeArray::Create( *(this->m_Levelset) );
00062
00063 DeviceMemory<float>::SmartPtr temporary = DeviceMemory<float>::Create( numberOfPixels );
00064
00065 int nInsideOld = 0, nInside = 1;
00066
00067 Progress::Begin( 0, numberOfIterations, 1, "Levelset Evolution" );
00068 for ( int it = 0; (it < numberOfIterations) && ((nInside!=nInsideOld) || forceIterations); ++it )
00069 {
00070 Progress::SetProgress( it );
00071
00072 DeviceImageConvolution( temporary->Ptr(), this->m_Volume->GetDims().begin(), deviceLevelset->GetDeviceArrayPtr()->GetArrayOnDevice(),
00073 kernels[0].size(), &kernels[0][0], kernels[1].size(), &kernels[1][0], kernels[2].size(), &kernels[2][0] );
00074
00075 float insideSum, outsideSum;
00076 SimpleLevelsetDeviceUpdateInsideOutside( temporary->Ptr(), deviceVolume->GetDataOnDevice().Ptr(), numberOfPixels, &insideSum, &outsideSum, &nInside );
00077
00078 const int nOutside = numberOfPixels - nInside;
00079 SimpleLevelsetDeviceUpdateLevelset( temporary->Ptr(), deviceVolume->GetDataOnDevice().Ptr(), numberOfPixels, insideSum / nInside, outsideSum / nOutside, 1.0 * nInside / nOutside, this->m_TimeDelta, this->m_LevelsetThreshold );
00080
00081 deviceLevelset->GetDeviceArrayPtr()->CopyOnDeviceToArray( temporary->Ptr() );
00082 }
00083
00084 temporary->CopyToHost( this->m_Levelset->GetData()->GetDataPtr(), numberOfPixels );
00085
00086 Progress::Done();
00087 }