From: tbaudier Date: Mon, 21 Dec 2015 15:11:47 +0000 (+0100) Subject: Debug slowness of scalar range computation X-Git-Tag: v1.4.0~81 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=7ecd8498ac882223280979e6090d1af4763e9eac;p=clitk.git Debug slowness of scalar range computation --- diff --git a/common/vvFromITK.h b/common/vvFromITK.h index 30e1bfe..69e41a6 100644 --- a/common/vvFromITK.h +++ b/common/vvFromITK.h @@ -58,6 +58,7 @@ static inline void ReadTimeSequence (vvImage::Pointer& vv_image, typename itk::I filter->SetInput(input); filter->ReleaseDataFlagOn(); vv_image->AddItkImage(filter->GetOutput()); + vv_image->ComputeScalarRangeBase(filter->GetOutput()); } vv_image->SetTimeSpacing(input->GetSpacing()[Dim-1]); vv_image->SetTimeOrigin(input->GetOrigin()[Dim-1]); @@ -73,9 +74,10 @@ struct vvImageFromITK_Impl if (time_sequence) //The time sequence case: create a series of VTK images ReadTimeSequence(vv_image, input, time_sequence); - else //Dim == 1,2,3 and not time_sequence + else { //Dim == 1,2,3 and not time_sequence vv_image->AddItkImage(input); - + vv_image->ComputeScalarRangeBase(input); + } return vv_image; } }; diff --git a/common/vvImage.cxx b/common/vvImage.cxx index 6ba06c5..47a0e34 100644 --- a/common/vvImage.cxx +++ b/common/vvImage.cxx @@ -49,6 +49,8 @@ void vvImage::Init() mTimeSpacing = 1; mTimeOrigin = 0; mImageDimension = 0; + mrange[0] = std::numeric_limits::max();;//min + mrange[1] = std::numeric_limits::min();;//max } //-------------------------------------------------------------------- @@ -80,7 +82,6 @@ void vvImage::AddVtkImage(vtkImageData* input) #else int* extent = input->GetInformation()->Get(vtkDataObject::DATA_EXTENT()); #endif - if (extent[4] != extent[5]) mImageDimension = 3; else if (extent[3] != extent[4]) @@ -116,15 +117,8 @@ int vvImage::GetNumberOfDimensions() const //-------------------------------------------------------------------- void vvImage::GetScalarRange(double* range) { - assert(mVtkImages.size()); - double * temp = mVtkImages[0]->GetScalarRange(); - range[0]=temp[0]; - range[1]=temp[1]; - for (unsigned int i=1; iGetScalarRange(); - if (temp[0] < range[0]) range[0]=temp[0]; - if (temp[1] > range[1]) range[1]=temp[1]; - } + range[0]=mrange[0]; + range[1]=mrange[1]; } //-------------------------------------------------------------------- diff --git a/common/vvImage.h b/common/vvImage.h index 10ffc86..d18ee98 100644 --- a/common/vvImage.h +++ b/common/vvImage.h @@ -22,6 +22,8 @@ #include #include #include +#include +#include #define VTK_EXCLUDE_STRSTREAM_HEADERS #include @@ -37,6 +39,10 @@ public : typedef itk::SmartPointer Pointer; typedef itk::ProcessObject::Pointer ConverterPointer; itkNewMacro(Self); + + struct DimensionDispatchBase {}; + template< unsigned int VDimension > + struct DimensionDispatch:public DimensionDispatchBase {}; void Init(); void Reset(); @@ -47,6 +53,9 @@ public : int GetNumberOfDimensions() const; int GetNumberOfSpatialDimensions(); void GetScalarRange(double* range); + template void ComputeScalarRangeBase(itk::Image *input); + template void ComputeScalarRange(DimensionDispatchBase, itk::Image *input); + template void ComputeScalarRange(DimensionDispatch< 1 >, itk::Image *input); unsigned long GetActualMemorySize(); std::vector GetSpacing(); std::vector GetOrigin() const; @@ -77,6 +86,7 @@ private: double mTimeOrigin; double mTimeSpacing; unsigned int mImageDimension; + double mrange[2]; }; //------------------------------------------------------------------------------ diff --git a/common/vvImage.txx b/common/vvImage.txx index a6d37c8..ab518cb 100644 --- a/common/vvImage.txx +++ b/common/vvImage.txx @@ -16,6 +16,7 @@ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html ===========================================================================*/ #include +#include //-------------------------------------------------------------------- template @@ -24,7 +25,7 @@ void vvImage::AddItkImage(TItkImageType *input) // Update input before conversion to enable exceptions thrown by the ITK pipeline. // Otherwise, vtkImageImport catches the exception for us. input->Update(); - + // Convert from ITK object to VTK object mImageDimension = TItkImageType::ImageDimension; typedef itk::ImageToVTKImageFilter ConverterType; @@ -56,4 +57,45 @@ void vvImage::AddItkImage(TItkImageType *input) mDictionary.push_back(&(input->GetMetaDataDictionary())); } //-------------------------------------------------------------------- + +/** Dispatch the computation of scalar range between vector and scalar image */ +template +void vvImage::ComputeScalarRangeBase(itk::Image *input) +{ + itkStaticConstMacro(Dimension1, unsigned int, itk::PixelTraits< TPixelType >::Dimension); + ComputeScalarRange(DimensionDispatch< Dimension1 >(), input); +} + +//-------------------------------------------------------------------- +/** Compute the scalar range for a vector pixel type */ +/** TO DO*/ +template +void vvImage::ComputeScalarRange(DimensionDispatchBase, itk::Image *input) +{ + cout << "try" << endl; +} + +//-------------------------------------------------------------------- +/** Compute the scalar range for a scalar pixel type */ +template +void vvImage::ComputeScalarRange(DimensionDispatch< 1 >, itk::Image *input) +{ + typedef typename itk::Image TItkImageType; + typedef itk::MinimumMaximumImageCalculator ImageCalculatorFilterType; + + typename ImageCalculatorFilterType::Pointer imageCalculatorFilter = ImageCalculatorFilterType::New (); + TPixelType tempMin, tempMax; + double tempRange[2]; + imageCalculatorFilter->SetImage(input); + imageCalculatorFilter->Compute(); + tempMin= imageCalculatorFilter->GetMinimum(); + tempMax= imageCalculatorFilter->GetMaximum(); + + tempRange[0] = (double) tempMin; + tempRange[1] = (double) tempMax; + + if (tempRange[0] < mrange[0]) mrange[0]=tempRange[0]; + if (tempRange[1] > mrange[1]) mrange[1]=tempRange[1]; +} +//-------------------------------------------------------------------- diff --git a/common/vvImageReader.txx b/common/vvImageReader.txx index 3ef04c6..551f113 100644 --- a/common/vvImageReader.txx +++ b/common/vvImageReader.txx @@ -86,6 +86,7 @@ void vvImageReader::UpdateWithDimAndInputPixelType() reader->SetFileName(*i); try { mImage->AddItkImage(reader->GetOutput()); + mImage->ComputeScalarRangeBase(reader->GetOutput()); } catch ( itk::ExceptionObject & err ) { std::cerr << "Error while reading " << mInputFilenames[0].c_str() << " " << err << std::endl; @@ -125,6 +126,7 @@ void vvImageReader::UpdateWithDimAndInputPixelType() #endif try { mImage->AddItkImage(filter->GetOutput()); + mImage->ComputeScalarRangeBase(filter->GetOutput()); } catch ( itk::ExceptionObject & err ) { std::cerr << "Error while slicing " << mInputFilenames[0].c_str() << "(slice #" << mSlice << ") " << err << std::endl; diff --git a/vv/vvSlicer.cxx b/vv/vvSlicer.cxx index 57500bb..d7caa17 100644 --- a/vv/vvSlicer.cxx +++ b/vv/vvSlicer.cxx @@ -380,7 +380,6 @@ void vvSlicer::SetImage(vvImage::Pointer image) // Make sure that the required part image has been computed extent[SliceOrientation*2] = Slice; extent[SliceOrientation*2+1] = Slice; - #if VTK_MAJOR_VERSION <= 5 mImageReslice->GetOutput()->SetUpdateExtent(extent); mImageReslice->GetOutput()->Update(); @@ -1090,7 +1089,6 @@ void vvSlicer::UpdateDisplayExtent() if (mUseReducedExtent) { copyExtent(mReducedExtent, w_ext); } - cout << mUseReducedExtent<< " " << w_ext[0] << " " << w_ext[1] << " " << w_ext[2] << " " << w_ext[3] << " " << w_ext[4] << " " << w_ext[5] << endl; // Set slice value w_ext[ this->SliceOrientation*2 ] = this->Slice;