]> Creatis software - clitk.git/commitdiff
Debug slowness of scalar range computation
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Mon, 21 Dec 2015 15:11:47 +0000 (16:11 +0100)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Mon, 21 Dec 2015 15:11:47 +0000 (16:11 +0100)
common/vvFromITK.h
common/vvImage.cxx
common/vvImage.h
common/vvImage.txx
common/vvImageReader.txx
vv/vvSlicer.cxx

index 30e1bfe6325c3205a6cb47dee118483ce8c120a0..69e41a6da39cb4b76f49938d01baf3cb0f7fa3fa 100644 (file)
@@ -58,6 +58,7 @@ static inline void ReadTimeSequence (vvImage::Pointer& vv_image, typename itk::I
     filter->SetInput(input);
     filter->ReleaseDataFlagOn();
     vv_image->AddItkImage<ItkImageType>(filter->GetOutput());
+    vv_image->ComputeScalarRangeBase<PixelType, Dim-1>(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<Dim,PixelType>(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<InputImageType>(input);
-
+      vv_image->ComputeScalarRangeBase<PixelType, Dim>(input);
+    }
     return vv_image;
   }
 };
index 6ba06c5a17b4b0de30d07af5eb887e13c68dce05..47a0e3464bd1d6e995b8a3103bab742566a5459b 100644 (file)
@@ -49,6 +49,8 @@ void vvImage::Init()
   mTimeSpacing = 1;
   mTimeOrigin = 0;
   mImageDimension = 0;
+  mrange[0] = std::numeric_limits<int>::max();;//min
+  mrange[1] = std::numeric_limits<int>::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; i<mVtkImages.size(); i++) {
-    temp = mVtkImages[i]->GetScalarRange();
-    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];
 }
 //--------------------------------------------------------------------
 
index 10ffc865fa2ed353605e4844abd6c456e5e678ee..d18ee9865303e217099ba4c40b5247c437ed66e7 100644 (file)
@@ -22,6 +22,8 @@
 #include <vector>
 #include <itkObjectFactory.h>
 #include <itkProcessObject.h>
+#include <itkMinimumMaximumImageCalculator.h>
+#include <itkCastImageFilter.h>
 
 #define VTK_EXCLUDE_STRSTREAM_HEADERS
 #include <vtkSmartPointer.h>
@@ -37,6 +39,10 @@ public :
   typedef itk::SmartPointer<Self> 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<class TPixelType, unsigned int VImageDimension> void ComputeScalarRangeBase(itk::Image<TPixelType,VImageDimension> *input);
+  template<class TPixelType, unsigned int VImageDimension> void ComputeScalarRange(DimensionDispatchBase, itk::Image<TPixelType,VImageDimension> *input);
+  template<class TPixelType, unsigned int VImageDimension> void ComputeScalarRange(DimensionDispatch< 1 >, itk::Image<TPixelType,VImageDimension> *input);
   unsigned long GetActualMemorySize();
   std::vector<double> GetSpacing();
   std::vector<double> GetOrigin() const;
@@ -77,6 +86,7 @@ private:
   double mTimeOrigin;
   double mTimeSpacing;
   unsigned int mImageDimension;
+  double mrange[2];
 };
 //------------------------------------------------------------------------------
 
index a6d37c8cbbd8f0447f69c990235fa0963afedb53..ab518cb9095f60df17204d5d74e9614096fe8890 100644 (file)
@@ -16,6 +16,7 @@
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
 ===========================================================================*/
 #include <itkImageToVTKImageFilter.h>
+#include <itkPixelTraits.h>
 
 //--------------------------------------------------------------------
 template<class TItkImageType>
@@ -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 <TItkImageType> 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<class TPixelType, unsigned int VImageDimension>
+void vvImage::ComputeScalarRangeBase(itk::Image<TPixelType,VImageDimension> *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<class TPixelType, unsigned int VImageDimension>
+void vvImage::ComputeScalarRange(DimensionDispatchBase, itk::Image<TPixelType,VImageDimension> *input)
+{
+     cout << "try" << endl;
+}
+
+//--------------------------------------------------------------------
+/** Compute the scalar range for a scalar pixel type */
+template<class TPixelType, unsigned int VImageDimension>
+void vvImage::ComputeScalarRange(DimensionDispatch< 1 >, itk::Image<TPixelType,VImageDimension> *input)
+{  
+  typedef typename itk::Image<TPixelType,VImageDimension> TItkImageType;
+  typedef itk::MinimumMaximumImageCalculator <TItkImageType> 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];
+}
+//--------------------------------------------------------------------
 
index 3ef04c6e0487f9b6bcec51e294e4f3075a6032e0..551f1139691d31eb944a721741a740a18644a3dd 100644 (file)
@@ -86,6 +86,7 @@ void vvImageReader::UpdateWithDimAndInputPixelType()
       reader->SetFileName(*i);
       try {
         mImage->AddItkImage<InputImageType>(reader->GetOutput());
+        mImage->ComputeScalarRangeBase<InputPixelType, VImageDimension-1>(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<SlicedImageType>(filter->GetOutput());
+      mImage->ComputeScalarRangeBase<InputPixelType, VImageDimension-1>(filter->GetOutput());
     } catch ( itk::ExceptionObject & err ) {
       std::cerr << "Error while slicing " << mInputFilenames[0].c_str()
                 << "(slice #" << mSlice << ") " << err << std::endl;
index 57500bb27e6fdb3c04b89e7913864d49463352fe..d7caa177fcdbd2853fa8230c563a9b0bb960f641 100644 (file)
@@ -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;