]> Creatis software - creaImageIO.git/blob - src/creaImageIOGimmickView.cpp
bug on spacing
[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                         boost::shared_ptr<ImageExtent> ie=boost::shared_ptr<ImageExtent>(new ImageExtent((*sel).GetAttribute("D0028_0010"),
222                                                                         (*sel).GetAttribute("D0028_0011"),
223                                                                         (*sel).GetAttribute("D0028_0012"), 
224                                                                         ""));
225
226         if(mImageExtent==0)
227         {
228                 mImageExtent=ie;
229                 if((mImageExtent->Get(min_dim-1)<2)||(mImageExtent->Get(max_dim)>1))
230                 {
231                         valid=false;
232                 }
233                 else
234                 {
235                         std::stringstream out;
236                         out << mImageExtent->GetDimension() << "D image " << mImageExtent->Get(0) << "x"<< mImageExtent->Get(1) << "x"<< mImageExtent->Get(2) <<" selected";
237                         mMessage = out.str();
238                         mImageExtent->SetDimension(2);
239                         valid=true;
240                 }
241         }
242         else
243         {
244                 if(mImageExtent->IsCompatible(*ie))
245                 {
246                         if(mImageExtent->GetDimension()==max_dim && mImageExtent->Get(max_dim)>2)
247                         {
248                                 std::stringstream out;
249                                 out<<"Cannot add this image to selection : would result in a "<<mImageExtent->GetDimension()+1<<"D image!";
250                                 mMessage=out.str();
251                                 valid=false;
252                         }
253                         else if(max_dim<3)
254                         {
255                                 std::stringstream out;
256                                 out<<"Selecting "<<mImageExtent->GetDimension()<<"D images is not allowed !";
257                                 mMessage=out.str();
258                                 valid=false;
259                         }
260                         else if(min_dim==3 && (ie->Get(2)+mImageExtent->Get(2))<2)
261                         {
262                                 std::stringstream out;
263                                 out << "Cannot build the selection as it would result in a ";
264                                 out << mImageExtent->GetDimension();
265                                 out << "D image, and the minimum is ";
266                                 out << min_dim;
267                                 out << "D!";
268                                 mMessage=out.str();
269                                 valid=false;
270                         }
271                         else
272                         {
273                                 mImageExtent->Add(*ie);
274                                 std::stringstream out;
275                                 out << mImageExtent->GetDimension() << "D image " << mImageExtent->Get(0) << "x"<< mImageExtent->Get(1) << "x"<< mImageExtent->Get(2) <<" selected";
276                                 mMessage = out.str();
277                         }
278                 }
279                 else
280                 {
281                         mMessage="The selected images are not compatible.";
282                         valid=false;
283                 }
284           }
285         }
286
287         modifyValidationSignal(valid);
288         SetMessage(mMessage);
289         return valid;
290   }
291
292   //======================================================================
293   void GimmickView::modifyValidationSignal(bool ivalid)
294   {
295
296           mValidationSignal(ivalid);
297   }
298
299   void GimmickView::stopReader()
300   {
301           mReader.Stop();
302   }
303
304    //======================================================================
305   ///Reads Images (Non Threaded)
306 void GimmickView::ReadImagesNotThreaded(std::vector<vtkImageData*>& s, std::vector<std::string> im, int dimension)
307 {
308         stopReader();
309 /* remember!
310
311 #define GIMMICK_NO_IMAGE_SELECTION 0
312 #define GIMMICK_2D_IMAGE_SELECTION 2
313 #define GIMMICK_3D_IMAGE_SELECTION 3
314 #define GIMMICK_4D_IMAGE_SELECTION 4
315
316 #define NATIVE 0
317 #define _2D    2
318 #define _3D    3
319
320 */
321         // Create the output data
322         if (im.size()==1) 
323         {
324                 vtkImageData * out=vtkImageData::New();
325                 out->ShallowCopy(mReader.GetImage(im.front()));
326                 s.push_back(out);
327         }
328     else if (im.size()>1) // Test inutile ? JPR
329         {
330                 vtkImageData* first = mReader.GetImage( im.front());
331                 if (dimension == 2)
332                 {
333                  // n3D
334                     std::vector<std::string>::iterator it;
335                         for (it=im.begin(); it!=im.end(); ++it) 
336                         {
337                                 vtkImageData* out = vtkImageData::New();
338                                 out->ShallowCopy(mReader.GetImage(*it));
339                                 s.push_back(out);
340                         }
341                 }         
342                 else 
343                 {
344                         // n*2D to 3D
345                         vtkImageData* out = vtkImageData::New();
346 //                      out->CopyStructure(first);      
347                         out->SetScalarType(first->GetScalarType());
348                         out->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
349                         int ext[6];
350                         //first->GetExtent(ext);  // JPR
351                         first->GetWholeExtent(ext);  // renvoie egalement 0,0 en Z // JPR
352
353                         if(ext[5] == 0)
354                         {
355                                 ext[5] = im.size()-1;
356                         }
357                         else
358                         {
359                                 ext[5] = ext[5] * im.size()-1; // to deal with multiframes - JPR
360                         }
361                         out->SetExtent(ext);
362
363                         // LG : TODO : Z Spacing  ?
364
365                         int dim[3];
366                         first->GetDimensions(dim);
367
368                         out->SetDimensions(dim[0], dim[1], im.size() );
369                         out->AllocateScalars();
370                         out->Update();
371
372                         unsigned long imsize = dim[0] * dim[1];
373                         imsize = imsize * dim[2] ;  // deal with multiframes // JPR
374
375
376 //EED 03-11-2009
377                         // differents formats char , short, etc...
378                         // differents components 1..3  ex. jpg ->RGB 3
379                         imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
380
381
382                         // Order the file name vector
383
384                         double spc[3];
385                         first->GetSpacing(spc);
386
387                         // OrderTheFileNameVector is not here anymore.
388                         // Try orderFilesWithZSpacing from OutputModel FCY
389                         // spc[2]=OrderTheFileNameVector(im);   
390                         spc[2] =1;
391
392                         out->SetSpacing(spc);
393
394                         int slice = 0;
395                         std::vector<std::string>::iterator it;
396
397                         for (it=im.begin(); it!=im.end(); ++it) 
398                         {
399                                 vtkImageData* cur = mReader.GetImage( (*it) );
400                                 memcpy(out->GetScalarPointer(0,0,slice), cur->GetScalarPointer(0,0,0), imsize);
401                                 slice++;
402                         }       
403                         s.push_back(out);
404
405                 }  // dimension == 3
406
407         }  // size >1
408
409 }
410   //======================================================================
411
412
413
414         //////////////////////////////////////////////////////////
415         // Test if the image is a multiple or single frame. 
416         // For the moment only with the creation of vtkImageDta.
417         // TO DO with image size and dim!!!
418         //////////////////////////////////////////////////////////
419         bool GimmickView::isSingle(const std::string i_file)
420         {
421                 bool bres = true;
422                 vtkImageData* first = mReader.GetImage( i_file);
423                 int dim[3];
424                 first->GetDimensions(dim);
425                 if (dim[2] > 1)
426                 {
427                         bres = false;
428                 }
429                 else
430                 {
431                 }
432                 return bres;
433         }
434
435         //////////////////////////////////////////////////////////
436         // get Attributes values for a file
437         //////////////////////////////////////////////////////////
438         
439         void GimmickView::getAttributes(const std::string i_file, std::map<std::string, std::string> &o_infos, OutputAttr i_attr)
440         {
441                 if(i_attr.inside.size() >0)
442                 {
443                         mGimmick->GetAttributes(i_file,o_infos,i_attr);
444                 }
445                 if(i_attr.outside.size()>0)
446                 {
447                         mReader.getAttributes(i_file,o_infos, i_attr.outside);
448                 }
449         }
450
451         //////////////////////////////////////////////////////////
452         // create an output structure with n entries = n output
453         //////////////////////////////////////////////////////////
454         void GimmickView::readImages1(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
455                          OutputAttr i_attr)
456         {
457                 std::vector<std::string>::iterator it;
458                 for (it=im.begin(); it!=im.end(); ++it)
459                 {
460                         OutStrGimmick out;
461                         out.img = vtkImageData::New();
462                         out.img->ShallowCopy(mReader.GetImage(*it));
463                         if(i_attr.mult)
464                                 getAttributes((*it),out.infos,i_attr);
465                         o_output.push_back(out);
466                 }
467                 // If we want only one output information structure, we set it outside the loop
468                 if(!i_attr.mult)
469                 {
470                         getAttributes(im.front(), o_output.front().infos, i_attr);
471                 }
472                 
473         }
474
475         //////////////////////////////////////////////////////////
476         // create an output structure with n entries = 1 output
477         //////////////////////////////////////////////////////////
478         void GimmickView::readImages3(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
479                          OutputAttr i_attr, double i_zspc)
480         {
481                 OutStrGimmick out;
482                 vtkImageData* first = mReader.GetImage( im.front());
483                 out.img  = vtkImageData::New();
484                 out.img->SetScalarType(first->GetScalarType());
485                 out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
486                 int ext[6];
487                 first->GetWholeExtent(ext);  // send also 0,0 in Z 
488                 if(ext[5] == 0)
489                 {
490                         ext[5] = im.size()-1;
491                 }
492                 else
493                 {
494                         ext[5] = ext[5] * im.size()-1; // to deal with multiframes 
495                 }
496                 out.img->SetExtent(ext);
497                 int dim[3];
498                 double spac[3];
499                 first->GetDimensions(dim);
500                 first->GetSpacing(spac);
501                 out.img->SetSpacing(spac);
502                 out.img->SetDimensions(dim[0], dim[1], im.size() );
503                 out.img->AllocateScalars();
504                 out.img->Update();
505                 unsigned long imsize = dim[0] * dim[1];
506                 imsize = imsize * dim[2] ;  // deal with multiframes here
507                 // differents formats char , short, etc...
508                 // differents components 1..3  ex. jpg ->RGB 3
509                 imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
510                 // Order the file name vector already did with the OutputModel!!!
511                 //!!!!out.img->SetSpacing(i_zspc);
512                 int slice = 0;
513                 std::vector<std::string>::iterator it;
514                 for (it=im.begin(); it!=im.end(); ++it) 
515                 {
516                         vtkImageData* cur = mReader.GetImage( (*it) );
517                         memcpy(out.img->GetScalarPointer(0,0,slice), cur->GetScalarPointer(0,0,0), imsize);
518                         slice++;
519                 }       
520                 getAttributes(im.front(),out.infos, i_attr);
521                 o_output.push_back(out);
522         }
523
524
525         // TO DO  NO VERY SURE : NEED TO BE TESTED
526         //////////////////////////////////////////////////////////
527         // create an output structure with n entries (T size) = T output (n size)
528         //////////////////////////////////////////////////////////
529         void GimmickView::readImages2(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
530                          OutputAttr i_attr, double i_zspc)
531         {
532                 vtkImageData* first = mReader.GetImage( im.front());
533                 int dim[3];
534                 double spac[3];
535                 first->GetDimensions(dim);
536                 first->GetSpacing(spac);
537                 // differents formats char , short, etc...
538                 // differents components 1..3  ex. jpg ->RGB 3
539                 unsigned long imsize = dim[0] * dim[1];
540                 imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
541
542                 // Order the file name vector already did with the OutputModel!!!
543                 std::vector<std::string>::iterator it;
544                 std::vector<OutStrGimmick>::iterator it_out = o_output.begin();
545
546                 for (it=im.begin(); it!=im.end(); ++it, it_out += dim[2])
547                 {
548                         vtkImageData* cur = mReader.GetImage( (*it) );
549                         for (int slice= 0 ; slice <dim[2]; slice++)
550                         {
551                                 OutStrGimmick out;
552                                 out.img = vtkImageData::New();
553                                 out.img->SetScalarType(first->GetScalarType());
554                                 out.img->SetSpacing(spac);
555                                 out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
556                                 int ext[6];
557                                 first->GetWholeExtent(ext);  // send also 0,0 in Z 
558                                 ext[5] = 0;
559                                 out.img->SetExtent(ext);
560
561                                 out.img->SetDimensions(dim[0], dim[1], 1 );
562                                 out.img->AllocateScalars();
563                                 out.img->Update();
564                                 memcpy(out.img->GetScalarPointer(0,0,0), cur->GetScalarPointer(0,0,slice), imsize);
565                                 o_output.push_back(out);
566                         }
567                         if(i_attr.mult)
568                                 getAttributes((*it),(*it_out).infos,i_attr);
569                 }
570                 if(!i_attr.mult)
571                 {
572                         getAttributes(im.front(), o_output.front().infos,i_attr);
573                 }
574
575         }
576
577         //////////////////////////////////////////////////////////
578         // create an output structure with n entries (T size) = T + n output
579         //////////////////////////////////////////////////////////
580         void GimmickView::readImages4(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
581                          OutputAttr i_attr)
582         {
583                 std::vector<std::string>::iterator it;
584                 std::vector<OutStrGimmick>::iterator it_out = o_output.begin();
585                 vtkImageData* first = mReader.GetImage( im.front());
586                 int dim[3];
587                 first->GetDimensions(dim);
588                         
589                 for (int slice= 0 ; slice <dim[2]; slice++)
590                 {
591                         OutStrGimmick out;
592                         out.img = vtkImageData::New();
593                         out.img->SetScalarType(first->GetScalarType());
594                         out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
595                         
596                         int ext[6];
597                         double spac[6];
598                         first->GetWholeExtent(ext);  // send also 0,0 in Z 
599                         ext[5] = 0;
600                         out.img->SetExtent(ext);
601                         first->GetSpacing(spac);
602                         out.img->SetSpacing(spac);
603                         out.img->SetDimensions(dim[0], dim[1], im.size() );
604                         out.img->AllocateScalars();
605                         out.img->Update();
606                         unsigned long imsize = dim[0] * dim[1];
607                         imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
608                         int index = 0;
609         
610                         for (it=im.begin(); it!=im.end(); ++it, index ++)
611                         {
612                                 vtkImageData* cur = mReader.GetImage( (*it) );
613                                 memcpy(out.img->GetScalarPointer(0,0,index), cur->GetScalarPointer(0,0,slice), imsize);
614                                 o_output.push_back(out);
615                         }
616                 }
617                 if(!i_attr.mult) // No sense to take informations in all images
618                 {
619                         getAttributes(im.front(), o_output.front().infos,i_attr);
620                 }
621
622         }
623
624
625 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
626 // Global function to read Images and create wished output (informations, multiple, type and size of output...)
627 // In function of type (file, vector) and size, the correct readImages function is selected
628 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
629         void GimmickView::readImages(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
630                          OutputAttr i_attr, int i_dim, double i_zspc)
631         {
632                 int size = im.size();
633                 if ( size == 0)
634                 {
635                         return;
636                 }
637                 else if (size == 1)
638                 {
639                         // Simplest case
640                         // Only one image : give it
641                         // But take in count multiframe possibility
642                         if ( isSingle(im.front()) || i_dim != 1)
643                         {
644                                  readImages1(o_output,im, i_attr);
645                         }
646                         else
647                         {
648                                 readImages2(o_output,im, i_attr,i_zspc);
649                         }
650                         
651                 }
652                 else
653                 {
654                         // multiple or single frame
655                         if ( isSingle(im.front()) )
656                         {
657                                 //we deal with 2D images
658                                 if(i_dim == 1)
659                                 {
660                                         // 2D to 3D
661                                         readImages3(o_output,im, i_attr,i_zspc);
662                                 }
663                                 else
664                                 {
665                                         readImages1(o_output,im, i_attr);
666                                 }
667                         }
668                         else
669                         {
670                                 // we deal with multiple frames n x (2D x T)
671                                 // Differents outputs are avaialable
672                                 if(i_dim == 1)
673                                 {
674                                         // put all in one output
675                                         readImages3(o_output,im, i_attr,i_zspc);
676
677                                 }
678                                 else if( i_dim == 2)
679                                 {
680                                         // put in a vector of n x T (2D)
681                                         readImages2(o_output,im, i_attr,i_zspc);
682                                 }
683                                 else if( i_dim == 3)
684                                 {
685                                         // put in a vector of n (2D x T)
686                                         // No transformations.
687                                         readImages1(o_output,im, i_attr);
688                                 }
689                                 else
690                                 {
691                                         // put in a vector of T (2D x n)
692                                         readImages4(o_output,im, i_attr);
693                                 }
694                         }
695                 }
696         }
697
698
699
700 void GimmickView::ReadImagesNotThreadedInVector(std::vector<vtkImageData*>& s, std::vector<std::string> im, int dimension)
701 {
702         // Create the output data
703         if (im.size()==1)
704         {
705                 // Only one image : give it
706                 vtkImageData* out = vtkImageData::New();
707                 GimmickDebugMessage(3, "State Check: Full Filename: "
708                                                 <<im.front()
709                                                 <<std::endl);
710                 out->ShallowCopy(mReader.GetImage(im.front()));
711                 s.push_back( out );
712         }
713         else if (im.size()>1) // Test inutile ? JPR
714         {
715                 /// \TODO fix unused variable 'first'
716                 vtkImageData* first = mReader.GetImage( im.front());
717                 if (dimension == 2)
718                 {
719                  // n3D
720                   std::vector<std::string>::iterator it;
721                         for (it=im.begin(); it!=im.end(); ++it)
722                         {
723                                 vtkImageData* out = vtkImageData::New();
724                                 out->ShallowCopy(mReader.GetImage(*it));
725                                 s.push_back(out);
726                         }
727                 }
728                 else
729                 {
730                         // n2D to 3D // NO!
731                         // n *2D + T in a vector :
732                         
733                         std::vector<std::string>::iterator it;
734                         for (it=im.begin(); it!=im.end(); ++it) 
735                         {
736                                 vtkImageData* out = mReader.GetImage( (*it));
737                                 s.push_back(out);
738                         }
739                 }
740         }
741 }
742   //======================================================================
743
744   //======================================================================
745   ///Requests the reading of an image
746   void GimmickView::RequestReading(tree::Node* n, 
747           int prio, int selection_index, boost::shared_ptr<ImagePointerHolder> p)
748   {
749           if(!mReaderStarted)
750           {
751                 mReader.Start();
752                 mReaderStarted=true;
753           }
754     ImageEventType t(n,selection_index);
755         t.pointerHolder = p;
756     mImageEventMap[n->GetAttribute("FullFileName")] = t;    
757     mReader.Request(this,n->GetAttribute("FullFileName"),prio);
758   }
759   //======================================================================
760
761   //======================================================================
762   void GimmickView::
763   OnMultiThreadImageReaderEvent(const std::string& filename,
764                                 MultiThreadImageReaderUser::EventType e,
765                                 vtkImageData* image)
766   {
767     GimmickDebugMessage(7,
768                         "MultiThreadImageReader event : "<<e<<std::endl);
769         if (e==ImageLoaded)
770         {
771                 if (filename.size()==0)
772                 {
773                   //What to do in this case?
774                   /*
775                         GimmickDebugMessage(5,
776                                         "Pushing unknown image in queue"
777                                         <<std::endl);
778                         mImageEventQueue.push_back(ImageEventType(image));*/
779                         return;
780                 }
781                 ImageEventTypeMap::iterator i;
782 //JCP 22-06-2009, test mImageEventMap.size() > 0
783                 if(mImageEventMap.size()>0){
784                         i = mImageEventMap.find(filename);
785                         if (i!=mImageEventMap.end())
786                         {
787                                 GimmickDebugMessage(5,
788                                                 "Putting image of file '"<<filename<<"' on pointer"
789                                                 <<std::endl);
790                                 ImageEventType ie(i->second);
791                                 ie.image = image;
792                                 ie.pointerHolder->Set(ie.image);
793                                 //mImageEventMap.erase(i);
794                         }
795                 }    
796         }
797         else if (e==Error)
798         {
799                 std::string mess="ERROR: MultiThreadImageReader: Cannot read image in file ";
800                 mess+=filename;
801                 mess+="\n";
802                 GimmickMessage(1,mess);
803                 ImageEventTypeMap::iterator i;
804                 i = mImageEventMap.find(filename);
805                 if (i!=mImageEventMap.end())
806                 {
807                 ImageEventType ie(i->second);
808                 ie.image = image;
809                 ie.pointerHolder->Set(GetDefaultImage());
810                 //mImageEventMap.erase(i);
811                 }
812         }
813
814         else if (e==ImageUnloaded)
815         {
816                 std::string mess="Unloaded image in file ";
817                 mess+=filename;
818                 mess+="\n";
819                 GimmickMessage(1,mess);
820                                 ImageEventTypeMap::iterator i;
821                 i = mImageEventMap.find(filename);
822                 if (i!=mImageEventMap.end())
823                 {
824                 ImageEventType ie(i->second);
825                 ie.image = image;
826                 ie.pointerHolder->Set(GetDefaultImage());
827                 //mImageEventMap.erase(i);
828                 }
829         }
830   }
831
832   //====================================================================
833
834   //====================================================================
835   void GimmickView::ConnectValidationObserver(ValidationCallbackType callback)
836   {
837     mValidationSignal.connect(callback);
838   }       
839   
840
841
842 ////////////////////////////////////////////////////////////////////////
843 //void GimmickView::Anonymize(std::vector<std::string> i_filenames, int type)
844 //{
845 //
846 //      gdcm::FileMetaInformation::SetSourceApplicationEntityTitle( "gdcmanon" );
847 //    gdcm::Global& g = gdcm::Global::GetInstance();
848 //      //if( !resourcespath )
849 // //   {
850 //      //      const char *xmlpathenv = getenv("GDCM_RESOURCES_PATH");
851 //      //      if( xmlpathenv )
852 //      //        {
853 //      //        // Make sure to look for XML dict in user explicitly specified dir first:
854 //      //        xmlpath = xmlpathenv;
855 //      //        resourcespath = 1;
856 //      //        }
857 // //   }
858 // // if( resourcespath )
859 // //   {
860 // //   // xmlpath is set either by the cmd line option or the env var
861 // //   if( !g.Prepend( xmlpath.c_str() ) )
862 // //     {
863 // //     std::cerr << "Specified Resources Path is not valid: " << xmlpath << std::endl;
864 // //     return 1;
865 // //     }
866 // //   }
867 //  // All set, then load the XML files:
868 //  if( !g.LoadResourcesFiles() )
869 //  {
870 //    return ;
871 //  }
872 //  const gdcm::Defs &defs = g.GetDefs(); (void)defs;
873 //  if( !rootuid )
874 //    {
875 //    // only read the env var if no explicit cmd line option
876 //    // maybe there is an env var defined... let's check
877 //    const char *rootuid_env = getenv("GDCM_ROOT_UID");
878 //    if( rootuid_env )
879 //      {
880 //      rootuid = 1;
881 //      root = rootuid_env;
882 //      }
883 //    }
884 //  if( rootuid )
885 //    {
886 //    // root is set either by the cmd line option or the env var
887 //    if( !gdcm::UIDGenerator::IsValid( root.c_str() ) )
888 //      {
889 //      std::cerr << "specified Root UID is not valid: " << root << std::endl;
890 //      return 1;
891 //      }
892 //    gdcm::UIDGenerator::SetRoot( root.c_str() );
893 //    }
894 //
895 //      if(type == 0)
896 //      {
897 //                 // Get private key/certificate
898 //           gdcm::CryptographicMessageSyntax cms;
899 //              if( !dumb_mode )
900 //              {
901 //                      if( !GetRSAKeys(cms, rsa_path.c_str(), cert_path.c_str() ) )
902 //                      {
903 //                              return 1;
904 //                      }
905 //                      cms.SetCipherType( ciphertype );
906 //              }
907 //
908 //      // Setup gdcm::Anonymizer
909 //      gdcm::Anonymizer anon;
910 //              if( !dumb_mode )
911 //              anon.SetCryptographicMessageSyntax( &cms );
912 //
913 //              if( dumb_mode )
914 //              {
915 //                      for(unsigned int i = 0; i < nfiles; ++i)
916 //              {
917 //              const char *in  = filenames[i].c_str();
918 //              const char *out = outfilenames[i].c_str();
919 //              if( !AnonymizeOneFileDumb(anon, in, out, empty_tags, remove_tags, replace_tags_value) )
920 //        {
921 //                      //std::cerr << "Could not anonymize: " << in << std::endl;
922 //                      return 1;
923 //              }
924 //      }
925 //    }
926 //  //else
927 //  //  {
928 //  //  for(unsigned int i = 0; i < nfiles; ++i)
929 //  //    {
930 //  //    const char *in  = filenames[i].c_str();
931 //  //    const char *out = outfilenames[i].c_str();
932 //  //    if( !AnonymizeOneFile(anon, in, out) )
933 //  //      {
934 //  //      //std::cerr << "Could not anonymize: " << in << std::endl;
935 //  //      return 1;
936 //  //      }
937 //  //    }
938 //  //  }
939 //      }
940 //}
941 //
942 } // EO namespace creaImageIO