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]);
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;
}
};
mTimeSpacing = 1;
mTimeOrigin = 0;
mImageDimension = 0;
+ mrange[0] = std::numeric_limits<int>::max();;//min
+ mrange[1] = std::numeric_limits<int>::min();;//max
}
//--------------------------------------------------------------------
#else
int* extent = input->GetInformation()->Get(vtkDataObject::DATA_EXTENT());
#endif
-
if (extent[4] != extent[5])
mImageDimension = 3;
else if (extent[3] != extent[4])
//--------------------------------------------------------------------
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];
}
//--------------------------------------------------------------------
#include <vector>
#include <itkObjectFactory.h>
#include <itkProcessObject.h>
+#include <itkMinimumMaximumImageCalculator.h>
+#include <itkCastImageFilter.h>
#define VTK_EXCLUDE_STRSTREAM_HEADERS
#include <vtkSmartPointer.h>
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();
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;
double mTimeOrigin;
double mTimeSpacing;
unsigned int mImageDimension;
+ double mrange[2];
};
//------------------------------------------------------------------------------
- CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
===========================================================================*/
#include <itkImageToVTKImageFilter.h>
+#include <itkPixelTraits.h>
//--------------------------------------------------------------------
template<class TItkImageType>
// 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;
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];
+}
+//--------------------------------------------------------------------
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;
#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;
// 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();
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;