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 #include "cmtkTypedArraySimilarityMemory.h"
00033
00034 namespace
00035 cmtk
00036 {
00037
00040 const Types::DataItemRange
00041 TypedArraySimilarityMemory::GetRangeX
00042 ( const TypedArray* array, const size_t numBins )
00043 {
00044 if ( ! this->ValidX )
00045 this->NumberBinsX = numBins;
00046
00047 if ( ! this->ValidX || this->RepeatCheck )
00048 {
00049 const Types::DataItemRange range = array->GetRange();
00050 if ( ! this->ValidX )
00051 {
00052 this->RangeX.m_LowerBound = range.m_LowerBound;
00053 this->RangeX.m_UpperBound = range.m_UpperBound;
00054 this->ValidX = true;
00055 }
00056 else
00057 if ( (range.m_LowerBound < this->RangeX.m_LowerBound) || (range.m_UpperBound > this->RangeX.m_UpperBound ) )
00058 {
00059 Types::DataItem binDelta = (this->RangeX.m_UpperBound - this->RangeX.m_LowerBound) / (this->NumberBinsX - 1);
00060
00061 if ( range.m_LowerBound < this->RangeX.m_LowerBound )
00062 {
00063 const size_t addBins = 1 + static_cast<size_t>( (this->RangeX.m_LowerBound - range.m_LowerBound) / binDelta);
00064 this->RangeX.m_LowerBound -= ( binDelta * addBins );
00065 this->NumberBinsY += addBins;
00066 }
00067
00068 if ( range.m_UpperBound > this->RangeX.m_UpperBound )
00069 {
00070 const size_t addBins = 1 + static_cast<size_t>( (range.m_UpperBound - this->RangeX.m_UpperBound) / binDelta);
00071 this->RangeX.m_UpperBound += ( binDelta * addBins );
00072 this->NumberBinsY += addBins;
00073 }
00074 }
00075 }
00076
00077 return this->RangeX;
00078 }
00079
00080 const Types::DataItemRange
00081 TypedArraySimilarityMemory::GetRangeY
00082 ( const TypedArray* array, const size_t numBins )
00083 {
00084 if ( ! this->ValidY )
00085 this->NumberBinsY = numBins;
00086
00087 if ( ! this->ValidY || this->RepeatCheck )
00088 {
00089 const Types::DataItemRange range = array->GetRange();
00090 if ( ! this->ValidY )
00091 {
00092 this->RangeY.m_LowerBound = range.m_LowerBound;
00093 this->RangeY.m_UpperBound = range.m_UpperBound;
00094 this->ValidY = true;
00095 }
00096 else
00097 if ( (range.m_LowerBound < this->RangeY.m_LowerBound) || (range.m_UpperBound > this->RangeY.m_UpperBound ) )
00098 {
00099 Types::DataItem binDelta = (this->RangeY.m_UpperBound - this->RangeY.m_LowerBound) / (this->NumberBinsY - 1);
00100
00101 if ( range.m_LowerBound < this->RangeY.m_LowerBound )
00102 {
00103 const size_t addBins = 1 + static_cast<size_t>( (this->RangeY.m_LowerBound - range.m_LowerBound) / binDelta);
00104 this->RangeY.m_LowerBound -= ( binDelta * addBins );
00105 this->NumberBinsY += addBins;
00106 }
00107
00108 if ( range.m_UpperBound > this->RangeY.m_UpperBound )
00109 {
00110 const size_t addBins = 1 + static_cast<size_t>( (range.m_UpperBound - this->RangeY.m_UpperBound) / binDelta);
00111 this->RangeY.m_UpperBound += ( binDelta * addBins );
00112 this->NumberBinsY += addBins;
00113 }
00114 }
00115 }
00116
00117 return this->RangeY;
00118 }
00119
00120 JointHistogram<unsigned int>::SmartPtr
00121 TypedArraySimilarityMemory::CreateHistogram
00122 ( const TypedArray* array0, const TypedArray* array1 )
00123 {
00124 const unsigned int dataSize = array0->GetDataSize();
00125 const size_t numBins = std::max<unsigned>( std::min<unsigned>( static_cast<unsigned>( sqrt( (float)dataSize ) ), this->MaxNumBins ), this->MinNumBins );
00126
00127 Types::DataItemRange rangeX = this->GetRangeX( array0, numBins );
00128 Types::DataItemRange rangeY = this->GetRangeY( array1, numBins );
00129
00130 JointHistogram<unsigned int>::SmartPtr histogram( new JointHistogram<unsigned int>( this->NumberBinsX, this->NumberBinsY ) );
00131
00132 histogram->SetRangeX( rangeX );
00133 histogram->SetRangeY( rangeY );
00134
00135 return histogram;
00136 }
00137
00138 }