Commit 50ffcdd3 authored by Rashad Kanavath's avatar Rashad Kanavath

BUG: optimization patches on mantis #1040 #1041 #1043. Authored by Luc Hermitte

parent 63ea76a0
......@@ -99,14 +99,13 @@ MultiToMonoChannelExtractROI<TInputPixelType, TOutputPixelType>
InputIterator inIt(inputPtr, inputRegionForThread);
// Parcours des canaux a traiter
unsigned int channelIn(m_Channel - 1);
const unsigned int channelIn(m_Channel - 1);
InputImagePixelType pixelInput;
while (!outIt.IsAtEnd())
{
OutputImagePixelType pixelOutput;
pixelInput = inIt.Get();
pixelOutput = static_cast<OutputValueType>(pixelInput[channelIn]);
InputImagePixelType const& pixelInput = inIt.Get();
OutputImagePixelType const pixelOutput = static_cast<OutputValueType>(pixelInput[channelIn]);
outIt.Set(pixelOutput);
++outIt;
++inIt;
......
......@@ -55,6 +55,9 @@ public:
typedef typename InputImage2Type::Pointer InputImage2PointerType;
typedef typename OutputImageType::Pointer OutputImagePointerType;
typedef typename InputImage1Type::PixelType InputPixel1Type;
typedef typename InputImage2Type::PixelType InputPixel2Type;
typedef typename OutputImageType::PixelType OutputPixelType;
typedef typename OutputImageType::InternalPixelType OutputInternalPixelType;
typedef typename OutputImageType::RegionType OutputImageRegionType;
......
......@@ -157,31 +157,38 @@ ConcatenateVectorImageFilter<TInputImage1, TInputImage2, TOutputImage>
input2It.GoToBegin();
outputIt.GoToBegin();
typename OutputImageType::PixelType outputPix(outputIt.Get().GetSize());
// Retrieve the size of each input pixel
const unsigned int l1 = input1It.Get().GetSize();
const unsigned int l2 = input2It.Get().GetSize();
// Iterate through the pixel
while (!outputIt.IsAtEnd())
{
// define an output pixel
typename OutputImageType::PixelType outpix;
// Retrieve the size of each input pixel
unsigned int l1 = input1It.Get().GetSize();
unsigned int l2 = input2It.Get().GetSize();
// Set the output pixel size
outpix.SetSize(l1 + l2);
// Check the size of each input pixel
assert(l1 == input1It.Get().GetSize());
assert(l2 == input2It.Get().GetSize());
// Check the size of the output pixel
assert(l1 + l2 == outputPix.GetSize());
// References to the input pixels
InputPixel1Type const& pix1 = input1It.Get();
InputPixel2Type const& pix2 = input2It.Get();
// Loop through each band of the first image
for (unsigned int i = 0; i < l1; ++i)
{
// Fill the output pixel
outpix[i] = static_cast<typename OutputImageType::InternalPixelType>(input1It.Get()[i]);
outputPix[i] = static_cast<typename OutputImageType::InternalPixelType>(pix1[i]);
}
// Loop though each band of the second image
for (unsigned int i = 0; i < l2; ++i)
{
// Fill the output pixel
outpix[i + l1] = static_cast<typename OutputImageType::InternalPixelType>(input2It.Get()[i]);
outputPix[i + l1] = static_cast<typename OutputImageType::InternalPixelType>(pix2[i]);
}
// Set the output pixel
outputIt.Set(outpix);
outputIt.Set(outputPix);
// Increment the iterator
++input1It;
++input2It;
......
......@@ -155,10 +155,12 @@ void BandMathImageFilter<TImage>
std::vector< std::string > tmpIdxVarNames;
tmpIdxVarNames.resize(nbAccessIndex);
tmpIdxVarNames.at(0) = "idxX";
tmpIdxVarNames.at(1) = "idxY";
tmpIdxVarNames.at(2) = "idxPhyX";
tmpIdxVarNames.at(3) = "idxPhyY";
tmpIdxVarNames.resize(nbAccessIndex);
tmpIdxVarNames[0] = "idxX";
tmpIdxVarNames[1] = "idxY";
tmpIdxVarNames[2] = "idxPhyX";
tmpIdxVarNames[3] = "idxPhyY";
// Check if input image dimensions matches
inputSize[0] = this->GetNthInput(0)->GetLargestPossibleRegion().GetSize(0);
......@@ -198,18 +200,18 @@ void BandMathImageFilter<TImage>
for(i = 0; i < nbThreads; ++i)
{
m_AImage.at(i).resize(m_NbVar);
m_VParser.at(i)->SetExpr(m_Expression);
m_AImage[i].resize(m_NbVar);
m_VParser[i]->SetExpr(m_Expression);
for(j=0; j < nbInputImages; ++j)
{
m_VParser.at(i)->DefineVar(m_VVarName.at(j), &(m_AImage.at(i).at(j)));
m_VParser[i]->DefineVar(m_VVarName[j], &(m_AImage[i][j]));
}
for(j=nbInputImages; j < nbInputImages+nbAccessIndex; ++j)
{
m_VVarName.at(j) = tmpIdxVarNames.at(j-nbInputImages);
m_VParser.at(i)->DefineVar(m_VVarName.at(j), &(m_AImage.at(i).at(j)));
m_VVarName[j] = tmpIdxVarNames[j-nbInputImages];
m_VParser[i]->DefineVar(m_VVarName[j], &(m_AImage[i][j]));
}
}
}
......@@ -252,8 +254,9 @@ void BandMathImageFilter<TImage>
typedef itk::ImageRegionConstIterator<TImage> ImageRegionConstIteratorType;
std::vector< ImageRegionConstIteratorType > Vit;
Vit.resize(nbInputImages);
assert(nbInputImages);
std::vector< ImageRegionConstIteratorType > Vit(nbInputImages);
for(j=0; j < nbInputImages; ++j)
{
Vit[j] = ImageRegionConstIteratorType (this->GetNthInput(j), outputRegionForThread);
......@@ -264,27 +267,33 @@ void BandMathImageFilter<TImage>
// support progress methods/callbacks
itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
while(!Vit.at(0).IsAtEnd())
{
for(j=0; j < nbInputImages; ++j)
{
m_AImage.at(threadId).at(j) = static_cast<double>(Vit.at(j).Get());
}
std::vector<double> & threadImage = m_AImage[threadId];
ParserType::Pointer const& threadParser = m_VParser[threadId];
long & threadUnderflow = m_ThreadUnderflow[threadId];
long & threadOverflow = m_ThreadOverflow[threadId];
ImageRegionConstIteratorType & firstImageRegion = Vit.front(); // alias for better perfs
while(!firstImageRegion.IsAtEnd())
{
for(j=0; j < nbInputImages; ++j)
{
threadImage[j] = static_cast<double>(Vit[j].Get());
}
// Image Indexes
for(j=0; j < 2; ++j)
{
m_AImage.at(threadId).at(nbInputImages+j) = static_cast<double>(Vit.at(0).GetIndex()[j]);
threadImage[nbInputImages+j] = static_cast<double>(firstImageRegion.GetIndex()[j]);
}
for(j=0; j < 2; ++j)
{
m_AImage.at(threadId).at(nbInputImages+2+j) = static_cast<double>(m_Origin[j])
+static_cast<double>(Vit.at(0).GetIndex()[j]) * static_cast<double>(m_Spacing[j]);
threadImage[nbInputImages+2+j] = static_cast<double>(m_Origin[j])
+ static_cast<double>(firstImageRegion.GetIndex()[j]) * static_cast<double>(m_Spacing[j]);
}
try
{
value = m_VParser.at(threadId)->Eval();
value = threadParser->Eval();
}
catch(itk::ExceptionObject& err)
{
......@@ -296,14 +305,14 @@ void BandMathImageFilter<TImage>
if (value < double(itk::NumericTraits<PixelType>::NonpositiveMin()))
{
ot.Set(itk::NumericTraits<PixelType>::NonpositiveMin());
m_ThreadUnderflow[threadId]++;
threadUnderflow++;
}
// Case value is equal to inf or superior to the maximum value
// allowed by the pixelType cast
else if (value > double(itk::NumericTraits<PixelType>::max()))
{
ot.Set(itk::NumericTraits<PixelType>::max());
m_ThreadOverflow[threadId]++;
threadOverflow++;
}
else
{
......@@ -312,12 +321,13 @@ void BandMathImageFilter<TImage>
for(j=0; j < nbInputImages; ++j)
{
++(Vit.at(j));
++Vit[j];
}
++ot;
progress.CompletedPixel();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment