00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00035 #ifdef _USE_ITK_
00036
00037 #include "bbitkImageSeriesReader.h"
00038 #include "bbitkPackage.h"
00039 #include "itkImageSeriesReader.h"
00040
00041 namespace bbitk
00042 {
00043 BBTK_BLACK_BOX_IMPLEMENTATION(ImageSeriesReader,bbtk::AtomicBlackBox);
00044
00045 BBTK_ADD_BLACK_BOX_TO_PACKAGE(itk,ImageSeriesReader);
00046
00047 void ImageSeriesReader::Read()
00048 {
00049 const std::vector<std::string>& filenames = bbGetInputFileNames();
00050 if (!filenames.size())
00051 {
00052 typedef Image_uint8_t_2_ptr itype;
00053 Image_uint8_t_2::Pointer p = Image_uint8_t_2::New();
00054 Image_uint8_t_2::IndexType i;
00055 i.Fill(0);
00056 Image_uint8_t_2::SizeType s;
00057 s.Fill(1);
00058 Image_uint8_t_2::RegionType r(i,s);
00059 p->SetRegions(r);
00060 p->Allocate();
00061 p->Register();
00062 bbSetOutputOut(p.GetPointer());
00063 return;
00064
00065 }
00066
00067 std::string filename = filenames[0];
00068
00069 itk::ImageIOBase::Pointer genericReader =
00070 itk::ImageIOFactory::CreateImageIO(filename.c_str(),
00071 itk::ImageIOFactory::ReadMode);
00072 if (!genericReader)
00073 {
00074 bbtkError(bbGetFullName()<<" : File format unknown (while reading \"" << filename << "\")");
00075 }
00076 genericReader->SetFileName(filename.c_str());
00077 genericReader->ReadImageInformation();
00078
00079 bbtk::TypeInfo typ = GetITKImagePtrTypeInfoFromPixelTypeInfoAndDimension(genericReader->GetComponentTypeInfo(), genericReader->GetNumberOfDimensions());
00080
00081 BBTK_TEMPLATE_ITK_IMAGE_SWITCH(typ,Read);
00082
00083 }
00084
00088 template<class T>
00089 void ImageSeriesReader::Read()
00090 {
00091 bbtkDebugMessageInc("Core",9,"bbitk::ImageSeriesReader<"
00092 <<bbtk::TypeName<T>()
00093 <<">::Read()"<<std::endl);
00094
00095 typedef T itkImageType;
00096 typedef itk::ImageSeriesReader< itkImageType > itkReaderType;
00097
00098 typename itkReaderType::Pointer reader = itkReaderType::New();
00099 const std::vector<std::string>& filenames = bbGetInputFileNames();
00100 reader->SetFileNames(filenames);
00101 try { reader->Update(); }
00102 catch( std::exception& e )
00103 {
00104 bbtkError("could not read image series : "<<e.what());
00105 }
00106
00107 reader->GetOutput()->Register();
00108
00109 bbSetOutputOut ( reader->GetOutput() );
00110
00111 bbtkDebugDecTab("Core",9);
00112 }
00113
00114
00115
00116
00117
00118
00119 }
00120
00121
00122 #endif