2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbitkImageSeriesReader.cxx,v $
32 Date: $Date: 2012/11/16 08:50:39 $
33 Version: $Revision: 1.12 $
34 =========================================================================*/
44 #include "bbitkImageSeriesReader.h"
45 #include "bbitkPackage.h"
46 #include "itkImageSeriesReader.h"
50 BBTK_BLACK_BOX_IMPLEMENTATION(ImageSeriesReader,bbtk::AtomicBlackBox);
52 BBTK_ADD_BLACK_BOX_TO_PACKAGE(itk,ImageSeriesReader);
55 //-----------------------------------------------------------------
56 void ImageSeriesReader::bbUserSetDefaultValues()
58 bbSetInputXSpacing(-1.0);
59 bbSetInputYSpacing(-1.0);
60 bbSetInputZSpacing(-1.0);
63 //-----------------------------------------------------------------
64 void ImageSeriesReader::bbUserInitializeProcessing()
68 //-----------------------------------------------------------------
69 void ImageSeriesReader::bbUserFinalizeProcessing()
75 void ImageSeriesReader::Read()
77 std::cout << "--------------------------------------------------- ImageSeriesReader::Read( NO template)" << std::endl;
78 const std::vector<std::string>& filenames = bbGetInputFileNames();
79 if (!filenames.size())
81 typedef Image_uint8_t_2_ptr itype;
82 Image_uint8_t_2::Pointer p = Image_uint8_t_2::New();
83 Image_uint8_t_2::IndexType i;
85 Image_uint8_t_2::SizeType s;
87 Image_uint8_t_2::RegionType r(i,s);
91 bbSetOutputOut(p.GetPointer());
92 std::cout << "--------------------------------------------------- ImageSeriesReader::Read( NO image found)" << std::endl;
94 //bbtkError("Void vector passed to "<<bbGetFullName());
97 std::string filename = filenames[0];
98 std::cout << "--------------------------------------------------- size " << filenames.size() << std::endl;
99 std::cout << "--------------------------------------------------- filenames[0] : " << filenames[0]<< std::endl;
100 std::cout << "--------------------------------------------------- filename.c_str : " << filename.c_str()<< std::endl;
102 itk::ImageIOBase::Pointer genericReader =
103 itk::ImageIOFactory::CreateImageIO(filename.c_str(),
104 itk::ImageIOFactory::ReadMode);
108 bbtkError(bbGetFullName()<<" : File format unknown (while reading [" << filename << "])");
110 genericReader->SetFileName(filename.c_str());
111 genericReader->ReadImageInformation();
113 // a stack of 2D images will result as a 3D image // JPRx
115 if (filenames.size()>1)
120 bbtk::TypeInfo typ = GetITKImagePtrTypeInfoFromPixelTypeInfoAndDimension(genericReader->GetComponentTypeInfo(), genericReader->GetNumberOfDimensions() + plusUn);
122 BBTK_TEMPLATE_ITK_IMAGE_SWITCH(typ,Read);
130 void ImageSeriesReader::Read()
132 std::cout << "--------------------------------------------------- ImageSeriesReader::Read()" << std::endl;
133 bbtkDebugMessageInc("Core",9,"bbitk::ImageSeriesReader<"
134 <<bbtk::TypeName<T>()
135 <<">::Read()"<<std::endl);
137 typedef T itkImageType;
138 typedef itk::ImageSeriesReader< itkImageType > itkReaderType;
140 typename itkReaderType::Pointer reader = itkReaderType::New();
141 const std::vector<std::string>& filenames = bbGetInputFileNames();
143 std::cout << "--------------------------------------------------- size " << filenames.size() << std::endl;
144 for (int i = 0; i< (int)(filenames.size()); i++)
145 std::cout << "-- [" <<filenames[i] << "]" << std::endl;
147 reader->SetFileNames(filenames);
149 try { reader->Update(); }
150 catch( std::exception& e )
152 bbtkError("could not read image series : "<<e.what());
156 typename itkImageType::SpacingType spacingJPRx;
158 bool spacingToBeSet = false;
159 if (bbGetInputXSpacing() > 0.)
161 spacingToBeSet = true;
162 spacingJPRx[0]= bbGetInputXSpacing();
165 if (bbGetInputYSpacing() > 0.)
167 spacingToBeSet = true;
168 spacingJPRx[1]= bbGetInputYSpacing();
171 if (bbGetInputZSpacing() > 0.)
173 spacingToBeSet = true;
174 spacingJPRx[2]= bbGetInputZSpacing();
178 reader->GetOutput()->SetSpacing(spacingJPRx);
181 reader->GetOutput()->Register();
182 // if (bbGetOutputOut())
183 bbSetOutputOut ( reader->GetOutput() );
185 bbtkDebugDecTab("Core",9);