]> Creatis software - creaImageIO.git/blob - src/creaImageIOGimmickView.cpp
0281042c2c1e5e62502f8c8972c3cfb9d22f1348
[creaImageIO.git] / src / creaImageIOGimmickView.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
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
9 #
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.
16 #
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
21 #  liability. 
22 #
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 # ------------------------------------------------------------------------
26 */
27
28
29 #include <creaImageIOGimmickView.h>
30
31 #include "boost/filesystem.hpp"
32
33 #if defined(USE_GDCM)
34 #include <gdcmGlobal.h>
35 #include <gdcmSerieHelper.h>
36 #include <gdcmFileHelper.h>
37 #include <gdcmUtil.h>
38 #include <vtkGdcmReader.h>
39 #endif
40
41 /*#if defined(USE_GDCM2)
42 #include <vtkGDCMImageReader.h>
43 #include "gdcmSystem.h"
44 #include "gdcmCryptographicMessageSyntax.h"
45 #include "gdcmUIDGenerator.h"
46 #include "gdcmAnonymizer.h"
47 #include "gdcmGlobal.h"
48 #endif*/
49 #if defined(_WIN32)
50 #pragma warning(disable: 4996)
51 #endif
52
53 namespace fs = boost::filesystem;
54 namespace creaImageIO
55 {
56
57         ///Class used to represent the actual state of the image selected and to perform comparisons on its values
58   class ImageExtent
59   {
60   public:
61     ImageExtent(const std::string& x, const std::string& y, const std::string& z, const std::string& t)
62         {
63                 sscanf(x.c_str(),"%d",&mExtent[0]);
64                 sscanf(y.c_str(),"%d",&mExtent[1]);
65                 sscanf(z.c_str(),"%d",&mExtent[2]);
66                 sscanf(t.c_str(),"%d",&mExtent[3]);
67                 if(x==""){mExtent[0]=1;}
68                 if(y==""){mExtent[1]=1;}
69                 if(z==""){mExtent[2]=1;}
70                 if(t==""){mExtent[3]=1;}
71
72                 if (mExtent[3]>1) mDim=4;
73                 else if (mExtent[2]>1) mDim=3;
74                 else if (mExtent[1]>1) mDim=2;
75                 else if (mExtent[0]>1) mDim=1;
76                 else mDim=0;
77         }
78         
79
80         ///Clears the extent
81     void Clear() { mExtent[0] = mExtent[1] = mExtent[2] = mExtent[3] = 1; }
82
83         ///Returns true if the two extents are compatible
84     bool IsCompatible( const ImageExtent& );
85
86         ///Adds the extent passed as a parameter to the current extent
87     void Add ( const ImageExtent& );
88                 
89         ///Returns the ieth position of the extent
90     int Get(int i) { return mExtent[i]; }
91     
92         ///Returns the dimension of the current image
93     void SetDimension(int dim) { mDim=dim; }
94
95         ///Returns the dimension of the current image
96     int GetDimension() { return mDim; }
97
98   private:
99     int mExtent[4];
100     int mDim;
101   };
102
103   //======================================================================
104
105   //======================================================================
106   // CTor
107   GimmickView::GimmickView(boost::shared_ptr<Gimmick> gimmick, int threads)
108     : mGimmick(gimmick),
109           mReader(threads)
110   {
111     GimmickDebugMessage(1,"GimmickView::GimmickView"
112                         <<std::endl);
113         // Anciently started the threads ...
114     // Threads now automatically start at first image request
115     //mReader.Start();
116
117   }
118   //======================================================================
119
120   //======================================================================
121   /// Destructor
122   GimmickView::~GimmickView()
123   {
124     GimmickDebugMessage(1,"GimmickView::~GimmickView"
125                         <<std::endl);
126   }
127    //======================================================================
128  
129   //======================================================================  
130   /// Initializes the view : 
131   /// Creates the TreeViews for all the TreeHandler of the Controller
132   /// 
133   void GimmickView::Initialize()
134   {
135         mReaderStarted=false;
136   }
137   //======================================================================
138
139   //======================================================================
140   /// Finalize 
141   void GimmickView::Finalize()
142   {
143   }
144
145   //======================================================================
146
147   //======================================================================
148   /// Create the tree views 
149   void GimmickView::CreateTreeViews()
150   {
151     GimmickMessage(2,"Creating the tree views"<<std::endl);
152     Gimmick::TreeHandlerMapType::const_iterator i;
153     for (i = mGimmick->GetTreeHandlerMap().begin();
154          i!= mGimmick->GetTreeHandlerMap().end();
155          ++i)
156       {
157         this->CreateTreeView(i->second);
158       }
159   }
160
161   /// Create a tree view with a given name
162   void GimmickView::CreateSingleTreeView(std::string &i_name)
163   {
164         this->CreateTreeView(mGimmick->GetTreeHandlerMap()[i_name]);
165      
166   }
167
168
169   //======================================================================
170
171   //======================================================================
172   /// Updates the TreeView of given name from level l to bottom
173   /// (calls the virtual method TreeView::Update())
174   void GimmickView::UpdateTreeViewLevel(const std::string& t, int l)
175   {
176     TreeViewMapType::iterator i;
177     i = GetTreeViewMap().find(t);
178     if ( i == GetTreeViewMap().end() )
179       {
180         GimmickError("INTERNAL ERROR : GimmickView::UpdateTreeView : '"
181                      <<t<<"' is not in TreeViewMap");
182       }
183     i->second->UpdateLevel(l);
184   }
185
186   //======================================================================
187   /// Clears the status and begins a new selection process
188   void GimmickView::ResetExtent()
189   {
190           if(mImageExtent!=0)
191           {
192                   mImageExtent.reset();
193           }
194           valid=true;
195   }
196
197   //======================================================================
198
199   //======================================================================
200   bool ImageExtent::IsCompatible(const ImageExtent& ie)
201   {
202           bool compatible=true;
203           ImageExtent * extent= (ImageExtent*)&ie;
204           if((*extent).Get(0)!=Get(0)
205                  || (*extent).Get(1)!=Get(1))
206           {
207                   compatible=false;
208           }
209           return compatible;
210   }
211
212   //======================================================================
213
214   //======================================================================
215   void ImageExtent::Add(const ImageExtent& ie)
216   {
217           ImageExtent * extent= (ImageExtent*)&ie;
218           mExtent[2]+=(*extent).Get(2);
219           if(mExtent[2]>1)
220           {
221           SetDimension(3);
222           }
223   }
224
225   //======================================================================
226   /// No selected image
227   bool GimmickView::NoValidateSelected ()
228   {
229         GimmickDebugMessage(2,"Validating selected"<<std::endl);
230         std::string mMessage;
231         mMessage="Cannot have 0 images selected!";
232         valid=false;
233         modifyValidationSignal(valid);
234         SetMessage(mMessage);
235         return valid;
236   }
237
238   //======================================================================
239   ///Validates the dimension compliance of the images with the maximum and 
240   ///minimum given, and between their sizes
241   bool GimmickView::ValidateSelected (tree::Node* sel, int min_dim, int max_dim)
242   {
243         GimmickDebugMessage(2,"Validating selected"<<std::endl);
244         std::string mMessage;
245         
246         if(sel==0)
247         {
248                 mMessage="Cannot have 0 images selected!";
249                 valid=false;
250         }
251         else
252         {
253                         boost::shared_ptr<ImageExtent> ie=boost::shared_ptr<ImageExtent>(new ImageExtent((*sel).GetAttribute("D0028_0010"),
254                                                                         (*sel).GetAttribute("D0028_0011"),
255                                                                         (*sel).GetAttribute("D0028_0012"), 
256                                                                         ""));
257
258         if(mImageExtent==0)
259         {
260                 mImageExtent=ie;
261                 if((mImageExtent->Get(min_dim-1)<2)||(mImageExtent->Get(max_dim)>1))
262                 {
263                         valid=false;
264                 }
265                 else
266                 {
267                         std::stringstream out;
268                         out << mImageExtent->GetDimension() << "D image " << mImageExtent->Get(0) << "x"<< mImageExtent->Get(1) << "x"<< mImageExtent->Get(2) <<" selected";
269                         mMessage = out.str();
270                         mImageExtent->SetDimension(2);
271                         valid=true;
272                 }
273         }
274         else
275         {
276                 if(mImageExtent->IsCompatible(*ie))
277                 {
278                         if(mImageExtent->GetDimension()==max_dim && mImageExtent->Get(max_dim)>2)
279                         {
280                                 std::stringstream out;
281                                 out<<"Cannot add this image to selection : would result in a "<<mImageExtent->GetDimension()+1<<"D image!";
282                                 mMessage=out.str();
283                                 valid=false;
284                         }
285                         else if(max_dim<3)
286                         {
287                                 std::stringstream out;
288                                 out<<"Selecting "<<mImageExtent->GetDimension()<<"D images is not allowed !";
289                                 mMessage=out.str();
290                                 valid=false;
291                         }
292                         else if(min_dim==3 && (ie->Get(2)+mImageExtent->Get(2))<2)
293                         {
294                                 std::stringstream out;
295                                 out << "Cannot build the selection as it would result in a ";
296                                 out << mImageExtent->GetDimension();
297                                 out << "D image, and the minimum is ";
298                                 out << min_dim;
299                                 out << "D!";
300                                 mMessage=out.str();
301                                 valid=false;
302                         }
303                         else
304                         {
305                                 mImageExtent->Add(*ie);
306                                 std::stringstream out;
307                                 out << mImageExtent->GetDimension() << "D image " << mImageExtent->Get(0) << "x"<< mImageExtent->Get(1) << "x"<< mImageExtent->Get(2) <<" selected";
308                                 mMessage = out.str();
309                         }
310                 }
311                 else
312                 {
313                         mMessage="The selected images are not compatible.";
314                         valid=false;
315                 }
316           }
317         }
318
319         modifyValidationSignal(valid);
320         SetMessage(mMessage);
321         return valid;
322   }
323
324   //======================================================================
325   void GimmickView::modifyValidationSignal(bool ivalid)
326   {
327
328           mValidationSignal(ivalid);
329   }
330
331   void GimmickView::stopReader()
332   {
333           mReader.Stop();
334   }
335
336    //======================================================================
337   ///Reads Images (Non Threaded)
338 void GimmickView::ReadImagesNotThreaded(std::vector<vtkImageData*>& s, std::vector<std::string> im, int dimension)
339 {
340         stopReader();
341 /* remember!
342
343 #define GIMMICK_NO_IMAGE_SELECTION 0
344 #define GIMMICK_2D_IMAGE_SELECTION 2
345 #define GIMMICK_3D_IMAGE_SELECTION 3
346 #define GIMMICK_4D_IMAGE_SELECTION 4
347
348 #define NATIVE 0
349 #define _2D    2
350 #define _3D    3
351
352 */
353         // Create the output data
354         if (im.size()==1) 
355         {
356                 vtkImageData * out=vtkImageData::New();
357                 out->ShallowCopy(mReader.GetImage(im.front()));
358                 s.push_back(out);
359         }
360     else if (im.size()>1) // Test inutile ? JPR
361         {
362                 vtkImageData* first = mReader.GetImage( im.front());
363                 if (dimension == 2)
364                 {
365                  // n3D
366                     std::vector<std::string>::iterator it;
367                         for (it=im.begin(); it!=im.end(); ++it) 
368                         {
369                                 vtkImageData* out = vtkImageData::New();
370                                 out->ShallowCopy(mReader.GetImage(*it));
371                                 s.push_back(out);
372                         }
373                 }         
374                 else 
375                 {
376                         // n*2D to 3D
377                         vtkImageData* out = vtkImageData::New();
378 //                      out->CopyStructure(first);      
379                         out->SetScalarType(first->GetScalarType());
380                         out->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
381                         int ext[6];
382                         //first->GetExtent(ext);  // JPR
383                         first->GetWholeExtent(ext);  // renvoie egalement 0,0 en Z // JPR
384
385                         if(ext[5] == 0)
386                         {
387                                 ext[5] = (int)im.size()-1;
388                         }
389                         else
390                         {
391                                 ext[5] = ext[5] * (int)im.size()-1; // to deal with multiframes - JPR
392                         }
393                         out->SetExtent(ext);
394
395                         // LG : TODO : Z Spacing  ?
396
397                         int dim[3];
398                         first->GetDimensions(dim);
399
400                         out->SetDimensions(dim[0], dim[1], (int)im.size() );
401                         out->AllocateScalars();
402                         out->Update();
403
404                         unsigned long imsize = dim[0] * dim[1];
405                         imsize = imsize * dim[2] ;  // deal with multiframes // JPR
406
407
408 //EED 03-11-2009
409                         // differents formats char , short, etc...
410                         // differents components 1..3  ex. jpg ->RGB 3
411                         imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
412
413
414                         // Order the file name vector
415
416                         double spc[3];
417                         first->GetSpacing(spc);
418
419                         // OrderTheFileNameVector is not here anymore.
420                         // Try orderFilesWithZSpacing from OutputModel FCY
421                         // spc[2]=OrderTheFileNameVector(im);   
422                         spc[2] =1;
423
424                         out->SetSpacing(spc);
425
426                         int slice = 0;
427                         std::vector<std::string>::iterator it;
428
429                         for (it=im.begin(); it!=im.end(); ++it) 
430                         {
431                                 vtkImageData* cur = mReader.GetImage( (*it) );
432                                 memcpy(out->GetScalarPointer(0,0,slice), cur->GetScalarPointer(0,0,0), imsize);
433                                 slice++;
434                         }       
435                         s.push_back(out);
436
437                 }  // dimension == 3
438
439         }  // size >1
440
441 }
442   //======================================================================
443
444
445
446         //////////////////////////////////////////////////////////
447         // Test if the image is a multiple or single frame. 
448         // For the moment only with the creation of vtkImageDta.
449         // TO DO with image size and dim!!!
450         //////////////////////////////////////////////////////////
451         bool GimmickView::isSingle(const std::string i_file)
452         {
453                 bool bres = true;
454                 vtkImageData* first = mReader.GetImage( i_file);
455                 int dim[3];
456                 first->GetDimensions(dim);
457                 if (dim[2] > 1)
458                 {
459                         bres = false;
460                 }
461                 else
462                 {
463                 }
464                 return bres;
465         }
466
467         //////////////////////////////////////////////////////////
468         // get Attributes values for a file
469         //////////////////////////////////////////////////////////
470         
471         void GimmickView::getAttributes(const std::string i_file, std::map<std::string, std::string> &o_infos, OutputAttr i_attr)
472         {
473                 if(i_attr.inside.size() >0)
474                 {
475                         mGimmick->GetAttributes(i_file,o_infos,i_attr);
476                 }
477                 if(i_attr.outside.size()>0)
478                 {
479                         mReader.getAttributes(i_file,o_infos, i_attr.outside);
480                 }
481         }
482
483         //////////////////////////////////////////////////////////
484         // create an output structure with n entries = n output
485         //////////////////////////////////////////////////////////
486         void GimmickView::readImages1(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
487                          OutputAttr i_attr)
488         {
489
490                 i_attr.outside.push_back("D0019_100a");  // simens Number Of Images In Mosaic
491
492 //EED Borrame
493                 int i,isize=i_attr.outside.size();
494                 for (i=0;i<isize;i++)
495                 {
496                 printf("EED GimmickView::readImages1 A  i_attr out %s \n", i_attr.outside[i].c_str());
497                 }
498
499
500
501                 std::vector<std::string>::iterator it;
502                 for (it=im.begin(); it!=im.end(); ++it)
503                 {
504                         OutStrGimmick out;
505                         out.img = vtkImageData::New();
506                         out.img->ShallowCopy(mReader.GetImage(*it));
507 printf("EED GimmickView::readImages1 A\n ");
508                         if(i_attr.mult) 
509                         {
510                                 getAttributes((*it),out.infos,i_attr);
511 printf("EED GimmickView::readImages1 B   %s \n ", out.infos.find("D0019_100a")->second.c_str() );                               
512                         }
513                         o_output.push_back(out);
514                 }
515                 // If we want only one output information structure, we set it outside the loop
516                 if(!i_attr.mult)
517                 {
518                         getAttributes(im.front(), o_output.front().infos, i_attr);
519 printf("EED GimmickView::readImages1 C   %s \n ", o_output.front().infos.find("D0019_100a")->second.c_str() );
520                 }
521                 
522         }
523
524         //////////////////////////////////////////////////////////
525         // create an output structure with n entries = 1 output
526         //////////////////////////////////////////////////////////
527         void GimmickView::readImages3(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
528                          OutputAttr i_attr, double i_zspc)
529         {
530                 OutStrGimmick out;
531                 vtkImageData* first = mReader.GetImage( im.front());
532                 out.img  = vtkImageData::New();
533                 out.img->SetScalarType(first->GetScalarType());
534                 out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
535                 int ext[6];
536                 first->GetWholeExtent(ext);  // send also 0,0 in Z 
537                 if(ext[5] == 0)
538                 {
539                         ext[5] = (int)im.size()-1;
540                 } else {
541                         ext[5] = ext[5] * (int)im.size()-1; // to deal with multiframes 
542                 }
543                 out.img->SetExtent(ext);
544                 int dim[3];
545                 double spac[3];
546                 first->GetDimensions(dim);
547                 first->GetSpacing(spac);
548                 out.img->SetSpacing(spac);
549                 out.img->SetDimensions(dim[0], dim[1], (int)im.size() );
550                 out.img->AllocateScalars();
551                 out.img->Update();
552                 unsigned long imsize = dim[0] * dim[1];
553                 imsize = imsize * dim[2] ;  // deal with multiframes here
554                 // differents formats char , short, etc...
555                 // differents components 1..3  ex. jpg ->RGB 3
556                 imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
557                 // Order the file name vector already did with the OutputModel!!!
558                 //!!!!out.img->SetSpacing(i_zspc);
559                 int slice = 0;
560                 std::vector<std::string>::iterator it;
561                 for (it=im.begin(); it!=im.end(); ++it) 
562                 {
563                         vtkImageData* cur = mReader.GetImage( (*it) );
564                         memcpy(out.img->GetScalarPointer(0,0,slice), cur->GetScalarPointer(0,0,0), imsize);
565                         slice++;
566                 }       
567                 getAttributes(im.front(),out.infos, i_attr);
568                 o_output.push_back(out);
569         }
570
571
572         // TO DO  NO VERY SURE : NEED TO BE TESTED
573         //////////////////////////////////////////////////////////
574         // create an output structure with n entries (T size) = T output (n size)
575         //////////////////////////////////////////////////////////
576         void GimmickView::readImages2(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
577                          OutputAttr i_attr, double i_zspc)
578         {
579                 vtkImageData* first = mReader.GetImage( im.front());
580                 int dim[3];
581                 double spac[3];
582                 first->GetDimensions(dim);
583                 first->GetSpacing(spac);
584                 // differents formats char , short, etc...
585                 // differents components 1..3  ex. jpg ->RGB 3
586                 unsigned long imsize = dim[0] * dim[1];
587                 imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
588
589                 // Order the file name vector already did with the OutputModel!!!
590                 std::vector<std::string>::iterator it;
591                 std::vector<OutStrGimmick>::iterator it_out = o_output.begin();
592
593                 for (it=im.begin(); it!=im.end(); ++it)//, it_out ++)
594                 {
595                         vtkImageData* cur = mReader.GetImage( (*it) );
596                         for (int slice= 0 ; slice <dim[2]; slice++)
597                         {
598                                 OutStrGimmick out;
599                                 out.img = vtkImageData::New();
600                                 out.img->SetScalarType(first->GetScalarType());
601                                 out.img->SetSpacing(spac);
602                                 out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
603                                 int ext[6];
604                                 first->GetWholeExtent(ext);  // send also 0,0 in Z 
605                                 ext[5] = 0;
606                                 out.img->SetExtent(ext);
607
608                                 out.img->SetDimensions(dim[0], dim[1], 1 );
609                                 out.img->AllocateScalars();
610                                 out.img->Update();
611                                 memcpy(out.img->GetScalarPointer(0,0,0), cur->GetScalarPointer(0,0,slice), imsize);
612                                 o_output.push_back(out);
613                         }
614         //              if(i_attr.mult)
615                 //              getAttributes((*it),(*it_out).infos,i_attr);
616                 }
617                 if(!i_attr.mult)
618                 {
619                         getAttributes(im.front(), o_output.front().infos,i_attr);
620                 }
621
622         }
623
624         //////////////////////////////////////////////////////////
625         // create an output structure with n entries (T size) = T + n output
626         //////////////////////////////////////////////////////////
627         void GimmickView::readImages4(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
628                          OutputAttr i_attr)
629         {
630                 std::vector<std::string>::iterator it;
631                 std::vector<OutStrGimmick>::iterator it_out = o_output.begin();
632                 vtkImageData* first = mReader.GetImage( im.front());
633                 int dim[3];
634                 first->GetDimensions(dim);
635                         
636                 for (int slice= 0 ; slice <dim[2]; slice++)
637                 {
638                         OutStrGimmick out;
639                         out.img = vtkImageData::New();
640                         out.img->SetScalarType(first->GetScalarType());
641                         out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
642                         
643                         int ext[6];
644                         double spac[6];
645                         first->GetWholeExtent(ext);  // send also 0,0 in Z 
646                         ext[5] = 0;
647                         out.img->SetExtent(ext);
648                         first->GetSpacing(spac);
649                         out.img->SetSpacing(spac);
650                         out.img->SetDimensions(dim[0], dim[1], (int)im.size() );
651                         out.img->AllocateScalars();
652                         out.img->Update();
653                         unsigned long imsize = dim[0] * dim[1];
654                         imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
655                         int index = 0;
656         
657                         for (it=im.begin(); it!=im.end(); ++it, index ++)
658                         {
659                                 vtkImageData* cur = mReader.GetImage( (*it) );
660                                 memcpy(out.img->GetScalarPointer(0,0,index), cur->GetScalarPointer(0,0,slice), imsize);
661                                 o_output.push_back(out);
662                         }
663                 }
664                 if(!i_attr.mult) // No sense to take informations in all images
665                 {
666                         getAttributes(im.front(), o_output.front().infos,i_attr);
667                 }
668
669         }
670
671
672 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
673 // Global function to read Images and create wished output (informations, multiple, type and size of output...)
674 // In function of type (file, vector) and size, the correct readImages function is selected
675 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
676         void GimmickView::readImages(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
677                          OutputAttr i_attr, int i_dim, double i_zspc)
678         {
679                 int size = (int)im.size();
680                 if ( size == 0)
681                 {
682                         return;
683                 } else if (size == 1) {
684                         // Simplest case
685                         // Only one image : give it
686                         // But take in count multiframe possibility
687                         if ( isSingle(im.front()) || i_dim != 1)
688                         {
689                                  readImages1(o_output,im, i_attr);
690                         } else {
691                                  readImages2(o_output,im, i_attr,i_zspc);
692                         }                       
693                 } else {
694                         // multiple or single frame
695                         if ( isSingle(im.front()) )
696                         {
697                                 //we deal with 2D images
698                                 if(i_dim == 1)
699                                 {
700                                         // 2D to 3D
701                                         readImages3(o_output,im, i_attr,i_zspc);
702                                 } else {
703                                         readImages1(o_output,im, i_attr);
704                                 }
705                         } else {
706                                 // we deal with multiple frames n x (2D x T)
707                                 // Differents outputs are avaialable
708                                 if(i_dim == 1)
709                                 {
710                                         // put all in one output
711                                         readImages3(o_output,im, i_attr,i_zspc);
712                                 } else if( i_dim == 2) {
713                                         // put in a vector of n x T (2D)
714                                         readImages2(o_output,im, i_attr,i_zspc);
715                                 } else if( i_dim == 3) {
716                                         // put in a vector of n (2D x T)
717                                         // No transformations.
718                                         readImages1(o_output,im, i_attr);
719                                 } else {
720                                         // put in a vector of T (2D x n)
721                                         readImages4(o_output,im, i_attr);
722                                 } // i_dim
723                         } //isSingle(im.front())
724                 } // if size
725
726 //EED UnMosaic step...  
727 //How to verifie if is a mosaic file , with how many images inside??
728
729         }
730
731
732
733 void GimmickView::ReadImagesNotThreadedInVector(std::vector<vtkImageData*>& s, std::vector<std::string> im, int dimension)
734 {
735         // Create the output data
736         if (im.size()==1)
737         {
738                 // Only one image : give it
739                 vtkImageData* out = vtkImageData::New();
740                 GimmickDebugMessage(3, "State Check: Full Filename: "
741                                                 <<im.front()
742                                                 <<std::endl);
743                 out->ShallowCopy(mReader.GetImage(im.front()));
744                 s.push_back( out );
745         }
746         else if (im.size()>1) // Test inutile ? JPR
747         {
748                 /// \TODO fix unused variable 'first'
749                 vtkImageData* first = mReader.GetImage( im.front());
750                 if (dimension == 2)
751                 {
752                  // n3D
753                   std::vector<std::string>::iterator it;
754                         for (it=im.begin(); it!=im.end(); ++it)
755                         {
756                                 vtkImageData* out = vtkImageData::New();
757                                 out->ShallowCopy(mReader.GetImage(*it));
758                                 s.push_back(out);
759                         }
760                 }
761                 else
762                 {
763                         // n2D to 3D // NO!
764                         // n *2D + T in a vector :
765                         
766                         std::vector<std::string>::iterator it;
767                         for (it=im.begin(); it!=im.end(); ++it) 
768                         {
769                                 vtkImageData* out = mReader.GetImage( (*it));
770                                 s.push_back(out);
771                         }
772                 }
773         }
774 }
775   //======================================================================
776
777   //======================================================================
778   ///Requests the reading of an image
779   void GimmickView::RequestReading(tree::Node* n, 
780           int prio, int selection_index, boost::shared_ptr<ImagePointerHolder> p)
781   {
782           if(!mReaderStarted)
783           {
784                 mReader.Start();
785                 mReaderStarted=true;
786           }
787     ImageEventType t(n,selection_index);
788         t.pointerHolder = p;
789     mImageEventMap[n->GetAttribute("FullFileName")] = t;    
790     mReader.Request(this,n->GetAttribute("FullFileName"),prio);
791   }
792   //======================================================================
793
794   //======================================================================
795   void GimmickView::
796   OnMultiThreadImageReaderEvent(const std::string& filename,
797                                 MultiThreadImageReaderUser::EventType e,
798                                 vtkImageData* image)
799   {
800     GimmickDebugMessage(7,
801                         "MultiThreadImageReader event : "<<e<<std::endl);
802         if (e==ImageLoaded)
803         {
804                 if (filename.size()==0)
805                 {
806                   //What to do in this case?
807                   /*
808                         GimmickDebugMessage(5,
809                                         "Pushing unknown image in queue"
810                                         <<std::endl);
811                         mImageEventQueue.push_back(ImageEventType(image));*/
812                         return;
813                 }
814                 ImageEventTypeMap::iterator i;
815 //JCP 22-06-2009, test mImageEventMap.size() > 0
816                 if(mImageEventMap.size()>0){
817                         i = mImageEventMap.find(filename);
818                         if (i!=mImageEventMap.end())
819                         {
820                                 GimmickDebugMessage(5,
821                                                 "Putting image of file '"<<filename<<"' on pointer"
822                                                 <<std::endl);
823                                 ImageEventType ie(i->second);
824                                 ie.image = image;
825                                 ie.pointerHolder->Set(ie.image);
826                                 //mImageEventMap.erase(i);
827                         }
828                 }    
829         }
830         else if (e==Error)
831         {
832                 std::string mess="ERROR: MultiThreadImageReader: Cannot read image in file ";
833                 mess+=filename;
834                 mess+="\n";
835                 GimmickMessage(1,mess);
836                 ImageEventTypeMap::iterator i;
837                 i = mImageEventMap.find(filename);
838                 if (i!=mImageEventMap.end())
839                 {
840                 ImageEventType ie(i->second);
841                 ie.image = image;
842                 ie.pointerHolder->Set(GetDefaultImage());
843                 //mImageEventMap.erase(i);
844                 }
845         }
846
847         else if (e==ImageUnloaded)
848         {
849                 std::string mess="Unloaded image in file ";
850                 mess+=filename;
851                 mess+="\n";
852                 GimmickMessage(1,mess);
853                                 ImageEventTypeMap::iterator i;
854                 i = mImageEventMap.find(filename);
855                 if (i!=mImageEventMap.end())
856                 {
857                 ImageEventType ie(i->second);
858                 ie.image = image;
859                 ie.pointerHolder->Set(GetDefaultImage());
860                 //mImageEventMap.erase(i);
861                 }
862         }
863   }
864
865   //====================================================================
866
867   //====================================================================
868   void GimmickView::ConnectValidationObserver(ValidationCallbackType callback)
869   {
870     mValidationSignal.connect(callback);
871   }       
872   
873
874 #if defined(USE_GDCM)
875 ////////////////////////////////////////////////////////////////////////
876 void GimmickView::Anonymize(std::vector<std::string> i_filenames, int type)
877 {
878         bool res = true;
879    std::vector<GDCM_NAME_SPACE::FileHelper *> filesH;
880    std::vector<std::string> suid;
881    std::map<std::string, std::string> msuid;
882    std::string tempuid = GDCM_NAME_SPACE::Util::CreateUniqueUID();
883    int i = 1;
884    std::vector<std::string>::iterator it = i_filenames.begin();
885    for(; it != i_filenames.end(); it++)
886    {
887
888            GDCM_NAME_SPACE::File *file;
889            file = GDCM_NAME_SPACE::File::New(  );
890            file->SetLoadMode( GDCM_NAME_SPACE::LD_ALL );
891            file->SetFileName( (*it).c_str() );
892            res = file->Load();
893            if ( !res ) 
894            {
895                         std::cerr << "Sorry, " <<  (*it).c_str()  <<"  not a gdcm-readable "
896                  << "DICOM / ACR File" <<std::endl;
897                         file ->Delete();
898        //return 0;
899                 }
900                 std::cout << " ... is readable " << std::endl;
901                 
902                 // We need a gdcm::FileHelper, since we want to load the pixels        
903                 GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(file);
904         
905    uint8_t *imageData = fh->GetImageData();
906
907            // Institution name 
908            file->AddAnonymizeElement(0x0008, 0x0080, "*"); 
909            // Patient's name 
910            file->AddAnonymizeElement(0x0010, 0x0010, "*");   
911            // Patient's ID
912            file->AddAnonymizeElement( 0x0010, 0x0020,"1515" );   
913            // Study Instance UID
914            file->AddAnonymizeElement(0x0020, 0x000d, tempuid );
915            // Telephone
916            file->AddAnonymizeElement(0x0010, 0x2154, "3615" );
917
918            // Aware user will add here more fields to anonymize here
919
920            // The gdcm::File is modified in memory
921
922            file->AnonymizeFile();
923
924            
925            i++;
926            fh->SetContentType(GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE);
927    
928            fh->WriteDcmExplVR(file->GetFileName() +".ano1" );
929            std::cout << i <<"  End Anonymize" << std::cout;  
930            file->ClearAnonymizeList();
931            file->Delete();
932            fh->Delete();
933    }
934 }
935 #endif
936 #if defined(USE_GDCM2)
937 void GimmickView::Anonymize(std::vector<std::string> i_filenames, int type)
938 {
939 }
940 #endif
941 ////////////////////////////////////////////////////////////////////////
942 //void GimmickView::Anonymize(std::vector<std::string> i_filenames, int type)
943 //{
944 //
945 //      gdcm::FileMetaInformation::SetSourceApplicationEntityTitle( "gdcmanon" );
946 //    gdcm::Global& g = gdcm::Global::GetInstance();
947 //      //if( !resourcespath )
948 // //   {
949 //      //      const char *xmlpathenv = getenv("GDCM_RESOURCES_PATH");
950 //      //      if( xmlpathenv )
951 //      //        {
952 //      //        // Make sure to look for XML dict in user explicitly specified dir first:
953 //      //        xmlpath = xmlpathenv;
954 //      //        resourcespath = 1;
955 //      //        }
956 // //   }
957 // // if( resourcespath )
958 // //   {
959 // //   // xmlpath is set either by the cmd line option or the env var
960 // //   if( !g.Prepend( xmlpath.c_str() ) )
961 // //     {
962 // //     std::cerr << "Specified Resources Path is not valid: " << xmlpath << std::endl;
963 // //     return 1;
964 // //     }
965 // //   }
966 //  // All set, then load the XML files:
967 //  if( !g.LoadResourcesFiles() )
968 //  {
969 //    return ;
970 //  }
971 //  const gdcm::Defs &defs = g.GetDefs(); (void)defs;
972 //  if( !rootuid )
973 //    {
974 //    // only read the env var if no explicit cmd line option
975 //    // maybe there is an env var defined... let's check
976 //    const char *rootuid_env = getenv("GDCM_ROOT_UID");
977 //    if( rootuid_env )
978 //      {
979 //      rootuid = 1;
980 //      root = rootuid_env;
981 //      }
982 //    }
983 //  if( rootuid )
984 //    {
985 //    // root is set either by the cmd line option or the env var
986 //    if( !gdcm::UIDGenerator::IsValid( root.c_str() ) )
987 //      {
988 //      std::cerr << "specified Root UID is not valid: " << root << std::endl;
989 //      return 1;
990 //      }
991 //    gdcm::UIDGenerator::SetRoot( root.c_str() );
992 //    }
993 //
994 //      if(type == 0)
995 //      {
996 //                 // Get private key/certificate
997 //           gdcm::CryptographicMessageSyntax cms;
998 //              if( !dumb_mode )
999 //              {
1000 //                      if( !GetRSAKeys(cms, rsa_path.c_str(), cert_path.c_str() ) )
1001 //                      {
1002 //                              return 1;
1003 //                      }
1004 //                      cms.SetCipherType( ciphertype );
1005 //              }
1006 //
1007 //      // Setup gdcm::Anonymizer
1008 //      gdcm::Anonymizer anon;
1009 //              if( !dumb_mode )
1010 //              anon.SetCryptographicMessageSyntax( &cms );
1011 //
1012 //              if( dumb_mode )
1013 //              {
1014 //                      for(unsigned int i = 0; i < nfiles; ++i)
1015 //              {
1016 //              const char *in  = filenames[i].c_str();
1017 //              const char *out = outfilenames[i].c_str();
1018 //              if( !AnonymizeOneFileDumb(anon, in, out, empty_tags, remove_tags, replace_tags_value) )
1019 //        {
1020 //                      //std::cerr << "Could not anonymize: " << in << std::endl;
1021 //                      return 1;
1022 //              }
1023 //      }
1024 //    }
1025 //  //else
1026 //  //  {
1027 //  //  for(unsigned int i = 0; i < nfiles; ++i)
1028 //  //    {
1029 //  //    const char *in  = filenames[i].c_str();
1030 //  //    const char *out = outfilenames[i].c_str();
1031 //  //    if( !AnonymizeOneFile(anon, in, out) )
1032 //  //      {
1033 //  //      //std::cerr << "Could not anonymize: " << in << std::endl;
1034 //  //      return 1;
1035 //  //      }
1036 //  //    }
1037 //  //  }
1038 //      }
1039 //}
1040 //
1041 } // EO namespace creaImageIO