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