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 #include "boost/filesystem/operations.hpp"
29 #include "boost/filesystem/fstream.hpp"
31 #include "creaImageIOSimpleView.h"
32 #include "creaImageIOUnMosaicVtkImageData.h"
36 bool SimpleView::readFile( std::vector<std::string> i_filenames, // in information names
37 std::vector<std::string> i_attr, // in information attributes names
38 std::vector<std::map <std::string , std::string> > &i_imgAttr, // out information attributes names-values
39 std::vector<vtkImageData *> &i_img) // out information vtkImageData
42 //Mosaic Attribute for Simens
43 i_attr.push_back("D0019_100a"); // Number of images in mosaic (Simens)
44 i_attr.push_back("D0018_0088"); // Spacing Between Slices
48 creaImageIOUnMosaicVtkImageData Mosaic;
49 vtkImageData* tmpImg1;
50 vtkImageData* tmpImg2;
51 int numberOfImagesInMosaic;
55 bool bresult, bfinal = true;
56 ImageReader *mReader = new ImageReader();
57 std::vector<std::string>::iterator it = i_filenames.begin();
58 for (; it != i_filenames.end(); it++)
60 bresult = mReader->CanRead((*it).c_str());
63 std::map <std::string , std::string> mapAttr;
64 mReader->getAttributes( (*it).c_str() , mapAttr, i_attr ); // filename, outMapAttr-NameValue, inVectAttributeName
65 i_imgAttr.push_back( mapAttr );
68 // i_img.push_back( mReader->ReadImage( (*it).c_str() ) );
72 std::map <std::string , std::string>::iterator itMapAttr;
73 std::string numberOfImagesInMosaicStr="";
74 std::string spaceBetweenSliceStr="";
76 itMapAttr = mapAttr.find("D0019_100a");
77 if ( itMapAttr!=mapAttr.end() ) numberOfImagesInMosaicStr = itMapAttr->second;
79 // std::string numberOfImagesInMosaicStr = mapAttr.find("D0019_100a")->second;
80 itMapAttr = mapAttr.find("D0018_0088");
81 if ( itMapAttr!=mapAttr.end() ) spaceBetweenSliceStr = itMapAttr->second;
83 // std::string spaceBetweenSliceStr = mapAttr.find("D0018_0088")->second;
84 if (numberOfImagesInMosaicStr=="")
86 i_img.push_back( mReader->ReadImage( (*it).c_str() ) );
88 numberOfImagesInMosaic = atoi(numberOfImagesInMosaicStr.c_str());
89 spcZ = atoi(spaceBetweenSliceStr.c_str());
90 tmpImg1 = mReader->ReadImage( (*it).c_str() ) ;
91 tmpImg1->GetSpacing( spc );
92 tmpImg2 = Mosaic.unMosaic( tmpImg1 , numberOfImagesInMosaic );
93 tmpImg2->SetSpacing( spc[0], spc[1], spcZ );
94 i_img.push_back( tmpImg2 );
98 printf("ERROR. Impossible to read file %s\n", (*it).c_str() );
108 bool SimpleView::readDirectory( const std::string i_pathname, // in information names
109 std::vector<std::string> i_attr, // in information attributes names
110 std::vector<std::map <std::string , std::string> > &i_imgAttr, // out information attributes names-values
111 std::vector<vtkImageData *> &i_imgs) // out information vtkImageData
114 ImageReader *mReader = new ImageReader();
115 std::vector<std::string> names;
116 bresult = boost::filesystem::exists( i_pathname );
119 boost::filesystem::directory_iterator itr(i_pathname);
120 boost::filesystem::directory_iterator end_itr;
121 for(;itr != end_itr; ++itr)
123 if (!boost::filesystem::is_directory(itr->status()))
125 if( mReader->CanRead(itr->path().string()) )
127 names.push_back(itr->path().string());
131 std::sort (names.begin(), names.end()); // make sure names are in lexicographical order
132 int lgr = (int)names.size();
134 for(int i=0; i<lgr; i++)
136 std::cout << names[i] << std::endl;
138 std::map <std::string , std::string> mapAttr;
139 mReader->getAttributes( names[i] , mapAttr, i_attr ); // filename, outMapAttr-NameValue, inVectAttributeName
140 i_imgAttr.push_back( mapAttr );
144 i_imgs.push_back( mReader->ReadImage(names[i]) );