//========================================================================================
//Threaded execution should implement generate threaded data
- void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId );
+#if ITK_VERSION_MAJOR >= 4
+ void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId );
+#else
+ void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId );
+#endif
bool m_Verbose;
PixelType m_EdgePaddingValue;
//=========================================================================================================================
//update the output for the outputRegionForThread
+#if ITK_VERSION_MAJOR >= 4
+ template<class InputImageType, class OutputImageType>
+ void ComposeVFFilter<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId )
+#else
template<class InputImageType, class OutputImageType>
void ComposeVFFilter<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId )
+#endif
{
//Get pointer to the output
//the actual processing
void BeforeThreadedGenerateData();
+#if ITK_VERSION_MAJOR >= 4
+ void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId );
+#else
void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId );
+#endif
//member data
typename WeightsImageType::Pointer m_Weights;
//=========================================================================================================================
//update the output for the outputRegionForThread
template<class InputImageType, class OutputImageType>
+#if ITK_VERSION_MAJOR >= 4
+void HelperClass1<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId )
+#else
void HelperClass1<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId )
+#endif
{
//std::cout << "HelperClass1::ThreadedGenerateData - IN" << std::endl;
//Get pointer to the input
//the actual processing
+#if ITK_VERSION_MAJOR >= 4
+ void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId );
+#else
void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId );
-
+#endif
//member data
typename WeightsImageType::Pointer m_Weights;
//=========================================================================================================================
//update the output for the outputRegionForThread
+#if ITK_VERSION_MAJOR >= 4
+template<class InputImageType, class OutputImageType > void HelperClass2<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId )
+#else
template<class InputImageType, class OutputImageType > void HelperClass2<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId )
+#endif
{
//std::cout << "HelperClass2::ThreadedGenerateData - IN" << std::endl;
for(unsigned int i=0; i<args_info.inputs_num; i++) {
//std::cout << "Reading <" << input_files[i] << std::endl;
#if GDCM_MAJOR_VERSION == 2
+ if (args_info.verbose_flag)
+ std::cout << "Using GDCM-2.x" << std::endl;
gdcm::Reader hreader;
hreader.SetFileName(input_files[i].c_str());
hreader.Read();
exit(0);
}
#else
+ if (args_info.verbose_flag)
+ std::cout << "Not using GDCM-2.x" << std::endl;
gdcm::File *header = new gdcm::File();
header->SetFileName(input_files[i]);
header->SetMaxSizeLoadEntry(16384); // required ?
if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
UpdateWithDimAndPixelType<Dimension, signed short, Components>();
}
- // else if(PixelType == "unsigned_short"){
- // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
- // UpdateWithDimAndPixelType<Dimension, unsigned short>();
- // }
+ else if(PixelType == "unsigned_short"){
+ if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
+ UpdateWithDimAndPixelType<Dimension, unsigned short, Components>();
+ }
else if (PixelType == "unsigned_char"){
if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
UpdateWithDimAndPixelType<Dimension, unsigned char, Components>();
}
+// else if (PixelType == "unsigned_int"){
+// if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_int..." << std::endl;
+// UpdateWithDimAndPixelType<Dimension, unsigned int, Components>();
+// }
// else if (PixelType == "char"){
// if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
// UpdateWithDimAndPixelType<Dimension, signed char>();
// }
+ else if(PixelType == "double"){
+ if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and double..." << std::endl;
+ UpdateWithDimAndPixelType<Dimension, double, Components>();
+ }
else {
if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
UpdateWithDimAndPixelType<Dimension, float, Components>();
}
//--------------------------------------------------------------------
-
//--------------------------------------------------------------------
template<unsigned int Dim>
void clitk::SplitImageGenericFilter::InitializeImageType()
{
ADD_DEFAULT_IMAGE_TYPES(Dim);
- //ADD_VEC_IMAGE_TYPE(Dim, 3,float);
+ ADD_VEC_IMAGE_TYPE(Dim, 3,float);
+}
+//--------------------------------------------------------------------
+
+//--------------------------------------------------------------------
+template <class ImageType>
+typename clitk::SplitImageGenericFilter::PngConversion<ImageType>::OutputPngImagePointer
+clitk::SplitImageGenericFilter::PngConversion<ImageType>::Do(double window,
+ double level,
+ ImagePointer input)
+{
+ static const unsigned int PixelDimension = itk::PixelTraits<typename ImageType::PixelType>::Dimension;
+ return this->Do(window, level, input, static_cast< PixelDimType<PixelDimension> *>(NULL) );
+}
+//--------------------------------------------------------------------
+
+//--------------------------------------------------------------------
+template <class ImageType>
+template<unsigned int Dim>
+typename clitk::SplitImageGenericFilter::PngConversion<ImageType>::OutputPngImagePointer
+clitk::SplitImageGenericFilter::PngConversion<ImageType>::Do(double window,
+ double level,
+ ImagePointer input,
+ PixelDimType<Dim> *)
+{
+ clitkExceptionMacro("Png conversion is not implemented for vector fields");
+ return NULL;
+}
+//--------------------------------------------------------------------
+
+//--------------------------------------------------------------------
+template <class ImageType>
+typename clitk::SplitImageGenericFilter::PngConversion<ImageType>::OutputPngImagePointer
+clitk::SplitImageGenericFilter::PngConversion<ImageType>::Do(double window,
+ double level,
+ ImagePointer input,
+ PixelDimType<1> *)
+{
+ typedef itk::IntensityWindowingImageFilter< ImageType, OutputPngImageType > CastFilterType;
+ typename CastFilterType::Pointer cast = CastFilterType::New();
+ cast->SetWindowLevel(window, level);
+ cast->SetInput(input);
+ return cast->GetOutput();
}
//--------------------------------------------------------------------
filter->SetExtractionRegion(extracted_region);
filter->Update();
if(this->m_Png){
- typedef itk::Image< unsigned char, ImageType::ImageDimension-1 > OutputPngImageType;
- typedef itk::IntensityWindowingImageFilter< OutputImageType, OutputPngImageType > CastFilterType;
- typename CastFilterType::Pointer cast = CastFilterType::New();
- cast->SetWindowLevel(this->m_Window, this->m_Level);
- cast->SetInput(filter->GetOutput());
+ PngConversion<OutputImageType> png;
SetOutputFilename(base_filename+"_"+ss.str()+".png");
- SetNextOutput<OutputPngImageType>(cast->GetOutput());
+ typename PngConversion<OutputImageType>::OutputPngImagePointer output;
+ output = png.Do(this->m_Window, this->m_Level, filter->GetOutput());
+ this->template SetNextOutput<typename PngConversion<OutputImageType>::OutputPngImageType>(output);
}
else {
SetOutputFilename(base_filename+"_"+ss.str()+".mhd");
void UpdateWithInputImageType();
protected:
+ template <class ImageType>
+ class PngConversion
+ {
+ public:
+ typedef typename ImageType::Pointer ImagePointer;
+ typedef itk::Image< unsigned char, ImageType::ImageDimension > OutputPngImageType;
+ typedef typename OutputPngImageType::Pointer OutputPngImagePointer;
+ OutputPngImagePointer Do(double window, double level, ImagePointer input);
+ private:
+ template<unsigned int> struct PixelDimType {};
+ template<unsigned int Dim> OutputPngImagePointer Do(double window,
+ double level,
+ ImagePointer input,
+ PixelDimType<Dim> *);
+ OutputPngImagePointer Do(double window, double level, ImagePointer input, PixelDimType<1> *);
+ };
+
template<unsigned int Dim> void InitializeImageType();
int mSplitDimension;
bool m_Verbose;
//----------------------------------------
// Update
//----------------------------------------
+#if ITK_VERSION_MAJOR >= 4
+ void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, itk::ThreadIdType threadId );
+#else
void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, int threadId );
+#endif
//----------------------------------------
// Data members
//-------------------------------------------------------------------
template<class InputImageType, class OutputImageType>
void
+#if ITK_VERSION_MAJOR >= 4
+ VectorImageToImageFilter<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, itk::ThreadIdType threadId)
+#else
VectorImageToImageFilter<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, int threadId)
+#endif
{
// Iterators
typename OutputImageType::Pointer output=this->GetOutput();
option "outputDir" o "Output dicom directory" string yes
option "key" k "Keys of tags to modify" string no multiple default="0008|103e"
option "tag" t "Tags values" string no multiple default="MIDPOSITION"
-option "midP" m "Modify tags using defaults, for MidPosition" flag off
option "useSizeAsReference" s "Use the size of the dicom image as reference for an occasional resampling" flag off
\ No newline at end of file
if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
UpdateWithDimAndPixelType<Dimension, signed short>();
}
- // else if(PixelType == "unsigned_short"){
- // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
- // UpdateWithDimAndPixelType<Dimension, unsigned short>();
- // }
+ else if(PixelType == "unsigned_short"){
+ if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
+ UpdateWithDimAndPixelType<Dimension, unsigned short>();
+ }
else if (PixelType == "unsigned_char") {
if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
// if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
// UpdateWithDimAndPixelType<Dimension, signed char>();
// }
+ else if (PixelType == "double") {
+ if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and double..." << std::endl;
+ UpdateWithDimAndPixelType<Dimension, double>();
+ }
else {
if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
UpdateWithDimAndPixelType<Dimension, float>();
}
}
- filter->Update();
- input = filter->GetOutput();
+ try {
+ filter->Update();
+ input = filter->GetOutput();
+ } catch( itk::ExceptionObject & excp ) {
+ std::cerr << "Error: Exception thrown while resampling!!" << std::endl;
+ std::cerr << excp << std::endl;
+ }
}
-
+
// In some cases, due to resampling approximation issues,
// the number of slices in the MHD file may be different (smaller)
// from the number of files in the template dicom directory.
// in verbose mode
const RegionType volumeRegion = input->GetLargestPossibleRegion();
const SizeType& volumeSize = volumeRegion.GetSize();
+ if (m_Verbose) {
+ std::cout << volumeRegion << volumeSize << std::endl;
+ }
if (Dimension == 3 && volumeSize[2] < numberOfFilenames) {
if (m_Verbose)
std::cout << "Warning: The number of files in " << m_ArgsInfo.inputDir_arg << " (" << filenames_in.size() << " files) is greater than the number of slices in MHD (" << volumeSize[2] << " slices). Using only " << volumeSize[2] << " files." << std::endl;
const std::vector<DictionaryType*>* dictionary = reader->GetMetaDataDictionaryArray();
// Get keys
- unsigned int numberOfKeysGiven=0;
- if(m_ArgsInfo.midP_flag && m_ArgsInfo.key_given)
- std::cerr<<"Error: both keys and midP option are given"<<std::endl;
- else if (m_ArgsInfo.midP_flag)
- numberOfKeysGiven=1;
- else
- numberOfKeysGiven=m_ArgsInfo.key_given;
+ unsigned int numberOfKeysGiven=m_ArgsInfo.key_given;
for (unsigned int i = 0; i < numberOfKeysGiven; i++) {
std::string entryId(m_ArgsInfo.key_arg[i] );
std::string value( m_ArgsInfo.tag_arg[i] );
+ std::cout << entryId << " " << value << std::endl;
for(unsigned int fni = 0; fni<numberOfFilenames; fni++)
itk::EncapsulateMetaData<std::string>( *((*dictionary)[fni]), entryId, value );
}
+
// Output directory and filenames
itksys::SystemTools::MakeDirectory( m_ArgsInfo.outputDir_arg ); // create if it doesn't exist