2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
29 #include <creaImageIOGimmickView.h>
31 #include "boost/filesystem.hpp"
34 #include <gdcmGlobal.h>
35 #include <gdcmSerieHelper.h>
36 #include <gdcmFileHelper.h>
38 #include <vtkGdcmReader.h>
42 #include <vtkMetaImageWriter.h>
44 /*#if defined(USE_GDCM2)
45 #include <vtkGDCMImageReader.h>
46 #include "gdcmSystem.h"
47 #include "gdcmCryptographicMessageSyntax.h"
48 #include "gdcmUIDGenerator.h"
49 #include "gdcmAnonymizer.h"
50 #include "gdcmGlobal.h"
53 #pragma warning(disable: 4996)
56 namespace fs = boost::filesystem;
60 ///Class used to represent the actual state of the image selected and to perform comparisons on its values
64 ImageExtent(const std::string& x, const std::string& y, const std::string& z, const std::string& t)
66 sscanf(x.c_str(),"%d",&mExtent[0]);
67 sscanf(y.c_str(),"%d",&mExtent[1]);
68 sscanf(z.c_str(),"%d",&mExtent[2]);
69 sscanf(t.c_str(),"%d",&mExtent[3]);
70 if(x==""){mExtent[0]=1;}
71 if(y==""){mExtent[1]=1;}
72 if(z==""){mExtent[2]=1;}
73 if(t==""){mExtent[3]=1;}
75 if (mExtent[3]>1) mDim=4;
76 else if (mExtent[2]>1) mDim=3;
77 else if (mExtent[1]>1) mDim=2;
78 else if (mExtent[0]>1) mDim=1;
84 void Clear() { mExtent[0] = mExtent[1] = mExtent[2] = mExtent[3] = 1; }
86 ///Returns true if the two extents are compatible
87 bool IsCompatible( const ImageExtent& );
89 ///Adds the extent passed as a parameter to the current extent
90 void Add ( const ImageExtent& );
92 ///Returns the ieth position of the extent
93 int Get(int i) { return mExtent[i]; }
95 ///Returns the dimension of the current image
96 void SetDimension(int dim) { mDim=dim; }
98 ///Returns the dimension of the current image
99 int GetDimension() { return mDim; }
106 //======================================================================
108 //======================================================================
110 GimmickView::GimmickView(boost::shared_ptr<Gimmick> gimmick, int threads)
114 GimmickDebugMessage(1,"GimmickView::GimmickView"
116 // Anciently started the threads ...
117 // Threads now automatically start at first image request
121 //======================================================================
123 //======================================================================
125 GimmickView::~GimmickView()
127 printf("EED GimmickView::~GimmickView DESTROCTEUR \n");
128 GimmickDebugMessage(1,"GimmickView::~GimmickView"
131 //======================================================================
133 //======================================================================
134 /// Initializes the view :
135 /// Creates the TreeViews for all the TreeHandler of the Controller
137 void GimmickView::Initialize()
139 mReaderStarted=false;
141 //======================================================================
143 //======================================================================
145 void GimmickView::Finalize()
147 printf("EED GimmickView::Finalize \n");
150 //======================================================================
152 //======================================================================
153 /// Create the tree views
154 void GimmickView::CreateTreeViews()
156 GimmickMessage(2,"Creating the tree views"<<std::endl);
157 Gimmick::TreeHandlerMapType::const_iterator i;
158 for (i = mGimmick->GetTreeHandlerMap().begin();
159 i!= mGimmick->GetTreeHandlerMap().end();
162 this->CreateTreeView(i->second);
166 /// Create a tree view with a given name
167 void GimmickView::CreateSingleTreeView(std::string &i_name)
169 this->CreateTreeView(mGimmick->GetTreeHandlerMap()[i_name]);
174 //======================================================================
176 //======================================================================
177 /// Updates the TreeView of given name from level l to bottom
178 /// (calls the virtual method TreeView::Update())
179 void GimmickView::UpdateTreeViewLevel(const std::string& t, int l)
181 TreeViewMapType::iterator i;
182 i = GetTreeViewMap().find(t);
183 if ( i == GetTreeViewMap().end() )
185 GimmickError("INTERNAL ERROR : GimmickView::UpdateTreeView : '"
186 <<t<<"' is not in TreeViewMap");
188 i->second->UpdateLevel(l);
191 //======================================================================
192 /// Clears the status and begins a new selection process
193 void GimmickView::ResetExtent()
197 mImageExtent.reset();
202 //======================================================================
204 //======================================================================
205 bool ImageExtent::IsCompatible(const ImageExtent& ie)
207 bool compatible=true;
208 ImageExtent * extent= (ImageExtent*)&ie;
209 if((*extent).Get(0)!=Get(0)
210 || (*extent).Get(1)!=Get(1))
217 //======================================================================
219 //======================================================================
220 void ImageExtent::Add(const ImageExtent& ie)
222 ImageExtent * extent= (ImageExtent*)&ie;
223 mExtent[2]+=(*extent).Get(2);
230 //======================================================================
231 /// No selected image
232 bool GimmickView::NoValidateSelected ()
234 GimmickDebugMessage(2,"Validating selected"<<std::endl);
235 std::string mMessage;
236 mMessage="Cannot have 0 images selected!";
238 modifyValidationSignal(valid);
239 SetMessage(mMessage);
243 //======================================================================
244 ///Validates the dimension compliance of the images with the maximum and
245 ///minimum given, and between their sizes
246 bool GimmickView::ValidateSelected (tree::Node* sel, int min_dim, int max_dim)
248 GimmickDebugMessage(2,"Validating selected"<<std::endl);
249 std::string mMessage;
253 mMessage="Cannot have 0 images selected!";
258 boost::shared_ptr<ImageExtent> ie=boost::shared_ptr<ImageExtent>(new ImageExtent((*sel).GetAttribute("D0028_0010"),
259 (*sel).GetAttribute("D0028_0011"),
260 (*sel).GetAttribute("D0028_0012"),
266 if((mImageExtent->Get(min_dim-1)<2)||(mImageExtent->Get(max_dim)>1))
272 std::stringstream out;
273 out << mImageExtent->GetDimension() << "D image " << mImageExtent->Get(0) << "x"<< mImageExtent->Get(1) << "x"<< mImageExtent->Get(2) <<" selected";
274 mMessage = out.str();
275 mImageExtent->SetDimension(2);
281 if(mImageExtent->IsCompatible(*ie))
283 if(mImageExtent->GetDimension()==max_dim && mImageExtent->Get(max_dim)>2)
285 std::stringstream out;
286 out<<"Cannot add this image to selection : would result in a "<<mImageExtent->GetDimension()+1<<"D image!";
292 std::stringstream out;
293 out<<"Selecting "<<mImageExtent->GetDimension()<<"D images is not allowed !";
297 else if(min_dim==3 && (ie->Get(2)+mImageExtent->Get(2))<2)
299 std::stringstream out;
300 out << "Cannot build the selection as it would result in a ";
301 out << mImageExtent->GetDimension();
302 out << "D image, and the minimum is ";
310 mImageExtent->Add(*ie);
311 std::stringstream out;
312 out << mImageExtent->GetDimension() << "D image " << mImageExtent->Get(0) << "x"<< mImageExtent->Get(1) << "x"<< mImageExtent->Get(2) <<" selected";
313 mMessage = out.str();
318 mMessage="The selected images are not compatible.";
324 modifyValidationSignal(valid);
325 SetMessage(mMessage);
329 //======================================================================
330 void GimmickView::modifyValidationSignal(bool ivalid)
333 mValidationSignal(ivalid);
336 void GimmickView::stopReader()
341 //======================================================================
342 ///Reads Images (Non Threaded)
343 void GimmickView::ReadImagesNotThreaded(std::vector<vtkImageData*>& s, std::vector<std::string> im, int dimension)
348 #define GIMMICK_NO_IMAGE_SELECTION 0
349 #define GIMMICK_2D_IMAGE_SELECTION 2
350 #define GIMMICK_3D_IMAGE_SELECTION 3
351 #define GIMMICK_4D_IMAGE_SELECTION 4
358 // Create the output data
361 vtkImageData * out=vtkImageData::New();
362 out->ShallowCopy(mReader.GetImage(im.front()));
365 else if (im.size()>1) // Test inutile ? JPR
367 vtkImageData* first = mReader.GetImage( im.front());
371 std::vector<std::string>::iterator it;
372 for (it=im.begin(); it!=im.end(); ++it)
374 vtkImageData* out = vtkImageData::New();
375 out->ShallowCopy(mReader.GetImage(*it));
382 vtkImageData* out = vtkImageData::New();
383 // out->CopyStructure(first);
385 //first->GetExtent(ext); // JPR
386 //EED 2017-01-01 Migration VTK7
387 #if VTK_MAJOR_VERSION <= 5
388 first->GetWholeExtent(ext); // renvoie egalement 0,0 en Z // JPR
390 first->GetExtent(ext); // renvoie egalement 0,0 en Z // JPR
395 ext[5] = (int)im.size()-1;
399 ext[5] = ext[5] * (int)im.size()-1; // to deal with multiframes - JPR
403 // LG : TODO : Z Spacing ?
406 first->GetDimensions(dim);
407 out->SetDimensions(dim[0], dim[1], (int)im.size() );
409 //EED 2017-01-01 Migration VTK7
410 #if VTK_MAJOR_VERSION <= 5
411 out->SetScalarType(first->GetScalarType());
412 out->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
413 out->AllocateScalars();
416 out->AllocateScalars(first->GetScalarType(),first->GetNumberOfScalarComponents());
419 unsigned long imsize = dim[0] * dim[1];
420 imsize = imsize * dim[2] ; // deal with multiframes // JPR
424 // differents formats char , short, etc...
425 // differents components 1..3 ex. jpg ->RGB 3
426 imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
429 // Order the file name vector
432 first->GetSpacing(spc);
434 // OrderTheFileNameVector is not here anymore.
435 // Try orderFilesWithZSpacing from OutputModel FCY
436 // spc[2]=OrderTheFileNameVector(im);
439 out->SetSpacing(spc);
442 std::vector<std::string>::iterator it;
444 for (it=im.begin(); it!=im.end(); ++it)
446 vtkImageData* cur = mReader.GetImage( (*it) );
447 memcpy(out->GetScalarPointer(0,0,slice), cur->GetScalarPointer(0,0,0), imsize);
457 //======================================================================
461 //////////////////////////////////////////////////////////
462 // Test if the image is a multiple or single frame.
463 // For the moment only with the creation of vtkImageDta.
464 // TO DO with image size and dim!!!
465 //////////////////////////////////////////////////////////
466 bool GimmickView::isSingle(const std::string i_file)
469 vtkImageData* first = mReader.GetImage( i_file);
471 first->GetDimensions(dim);
482 //////////////////////////////////////////////////////////
483 // get Attributes values for a file
484 //////////////////////////////////////////////////////////
486 void GimmickView::getAttributes(const std::string i_file, std::map<std::string, std::string> &o_infos, OutputAttr i_attr)
488 if(i_attr.inside.size() >0)
490 mGimmick->GetAttributes(i_file,o_infos,i_attr);
492 if(i_attr.outside.size()>0)
494 mReader.getAttributes(i_file,o_infos, i_attr.outside);
498 //////////////////////////////////////////////////////////
499 // create an output structure with n entries = n output
500 //////////////////////////////////////////////////////////
501 void GimmickView::readImages1(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
504 i_attr.outside.push_back("D0019_100a"); // simens Number Of Images In Mosaic
505 std::vector<std::string>::iterator it;
506 for (it=im.begin(); it!=im.end(); ++it)
509 out.img = vtkImageData::New();
510 out.img->ShallowCopy(mReader.GetImage(*it));
513 getAttributes((*it),out.infos,i_attr);
515 o_output.push_back(out);
517 // If we want only one output information structure, we set it outside the loop
520 getAttributes(im.front(), o_output.front().infos, i_attr);
525 //////////////////////////////////////////////////////////
526 // create an output structure with n entries = 1 output
527 //////////////////////////////////////////////////////////
528 void GimmickView::readImages3(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
529 OutputAttr i_attr, double i_zspc)
532 vtkImageData* first = mReader.GetImage( im.front());
533 out.img = vtkImageData::New();
535 //EED 2017-01-01 Migration VTK7
536 #if VTK_MAJOR_VERSION <= 5
537 first->GetWholeExtent(ext); // send also 0,0 in Z
539 first->GetExtent(ext); // send also 0,0 in Z
543 ext[5] = (int)im.size()-1;
545 ext[5] = ext[5] * (int)im.size()-1; // to deal with multiframes
547 out.img->SetExtent(ext);
550 first->GetDimensions(dim);
551 first->GetSpacing(spac);
552 out.img->SetSpacing(spac);
553 out.img->SetDimensions(dim[0], dim[1], (int)im.size() );
557 //EED 2017-01-01 Migration VTK7
558 #if VTK_MAJOR_VERSION <= 5
559 out.img->SetScalarType(first->GetScalarType());
560 out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
561 out.img->AllocateScalars();
564 out.img->AllocateScalars(first->GetScalarType(), first->GetNumberOfScalarComponents());
568 unsigned long imsize = dim[0] * dim[1];
569 imsize = imsize * dim[2] ; // deal with multiframes here
570 // differents formats char , short, etc...
571 // differents components 1..3 ex. jpg ->RGB 3
572 imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
573 // Order the file name vector already did with the OutputModel!!!
574 //!!!!out.img->SetSpacing(i_zspc);
576 std::vector<std::string>::iterator it;
577 for (it=im.begin(); it!=im.end(); ++it)
579 vtkImageData* cur = mReader.GetImage( (*it) );
580 memcpy(out.img->GetScalarPointer(0,0,slice), cur->GetScalarPointer(0,0,0), imsize);
584 getAttributes(im.front(),out.infos, i_attr);
585 o_output.push_back(out);
589 // TO DO NO VERY SURE : NEED TO BE TESTED
590 //////////////////////////////////////////////////////////
591 // create an output structure with n entries (T size) = T output (n size)
592 //////////////////////////////////////////////////////////
593 void GimmickView::readImages2(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
594 OutputAttr i_attr, double i_zspc)
596 vtkImageData* first = mReader.GetImage( im.front());
599 first->GetDimensions(dim);
600 first->GetSpacing(spac);
601 // differents formats char , short, etc...
602 // differents components 1..3 ex. jpg ->RGB 3
603 unsigned long imsize = dim[0] * dim[1];
604 imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
606 // Order the file name vector already did with the OutputModel!!!
607 std::vector<std::string>::iterator it;
608 std::vector<OutStrGimmick>::iterator it_out = o_output.begin();
610 for (it=im.begin(); it!=im.end(); ++it)//, it_out ++)
612 vtkImageData* cur = mReader.GetImage( (*it) );
613 for (int slice= 0 ; slice <dim[2]; slice++)
616 out.img = vtkImageData::New();
617 out.img->SetSpacing(spac);
619 //EED 2017-01-01 Migration VTK7
620 #if VTK_MAJOR_VERSION <= 5
621 first->GetWholeExtent(ext); // send also 0,0 in Z
623 first->GetExtent(ext); // send also 0,0 in Z
626 out.img->SetExtent(ext);
627 out.img->SetDimensions(dim[0], dim[1], 1 );
629 //EED 2017-01-01 Migration VTK7
630 #if VTK_MAJOR_VERSION <= 5
631 out.img->SetScalarType(first->GetScalarType());
632 out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
633 out.img->AllocateScalars();
636 out.img->AllocateScalars(first->GetScalarType(),first->GetNumberOfScalarComponents());
640 memcpy(out.img->GetScalarPointer(0,0,0), cur->GetScalarPointer(0,0,slice), imsize);
641 o_output.push_back(out);
644 // getAttributes((*it),(*it_out).infos,i_attr);
648 getAttributes(im.front(), o_output.front().infos,i_attr);
653 //////////////////////////////////////////////////////////
654 // create an output structure with n entries (T size) = T + n output
655 //////////////////////////////////////////////////////////
656 void GimmickView::readImages4(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
659 std::vector<std::string>::iterator it;
660 std::vector<OutStrGimmick>::iterator it_out = o_output.begin();
661 vtkImageData* first = mReader.GetImage( im.front());
663 first->GetDimensions(dim);
665 for (int slice= 0 ; slice <dim[2]; slice++)
668 out.img = vtkImageData::New();
672 //EED 2017-01-01 Migration VTK7
673 #if VTK_MAJOR_VERSION <= 5
674 first->GetWholeExtent(ext); // send also 0,0 in Z
676 first->GetExtent(ext); // send also 0,0 in Z
681 out.img->SetExtent(ext);
682 first->GetSpacing(spac);
683 out.img->SetSpacing(spac);
684 out.img->SetDimensions(dim[0], dim[1], (int)im.size() );
686 //EED 2017-01-01 Migration VTK7
687 #if VTK_MAJOR_VERSION <= 5
688 out.img->SetScalarType(first->GetScalarType());
689 out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
690 out.img->AllocateScalars();
693 out.img->AllocateScalars(first->GetScalarType(), first->GetNumberOfScalarComponents());
696 unsigned long imsize = dim[0] * dim[1];
697 imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
700 for (it=im.begin(); it!=im.end(); ++it, index ++)
702 vtkImageData* cur = mReader.GetImage( (*it) );
703 memcpy(out.img->GetScalarPointer(0,0,index), cur->GetScalarPointer(0,0,slice), imsize);
704 o_output.push_back(out);
707 if(!i_attr.mult) // No sense to take informations in all images
709 getAttributes(im.front(), o_output.front().infos,i_attr);
715 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
716 // Global function to read Images and create wished output (informations, multiple, type and size of output...)
717 // In function of type (file, vector) and size, the correct readImages function is selected
718 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
719 void GimmickView::readImages(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
720 OutputAttr i_attr, int i_dim, double i_zspc)
722 int size = (int)im.size();
726 } else if (size == 1) {
728 // Only one image : give it
729 // But take in count multiframe possibility
730 if ( isSingle(im.front()) || i_dim != 1)
732 readImages1(o_output,im, i_attr);
734 readImages2(o_output,im, i_attr,i_zspc);
737 // multiple or single frame
738 if ( isSingle(im.front()) )
740 //we deal with 2D images
744 readImages3(o_output,im, i_attr,i_zspc);
746 readImages1(o_output,im, i_attr);
749 // we deal with multiple frames n x (2D x T)
750 // Differents outputs are avaialable
753 // put all in one output
754 readImages3(o_output,im, i_attr,i_zspc);
755 } else if( i_dim == 2) {
756 // put in a vector of n x T (2D)
757 readImages2(o_output,im, i_attr,i_zspc);
758 } else if( i_dim == 3) {
759 // put in a vector of n (2D x T)
760 // No transformations.
761 readImages1(o_output,im, i_attr);
763 // put in a vector of T (2D x n)
764 readImages4(o_output,im, i_attr);
766 } //isSingle(im.front())
769 //EED UnMosaic step...
770 //How to verifie if is a mosaic file , with how many images inside??
776 void GimmickView::ReadImagesNotThreadedInVector(std::vector<vtkImageData*>& s, std::vector<std::string> im, int dimension)
778 // Create the output data
781 // Only one image : give it
782 vtkImageData* out = vtkImageData::New();
783 GimmickDebugMessage(3, "State Check: Full Filename: "
786 out->ShallowCopy(mReader.GetImage(im.front()));
789 else if (im.size()>1) // Test inutile ? JPR
791 /// \TODO fix unused variable 'first'
792 // vtkImageData* first = mReader.GetImage( im.front());
796 std::vector<std::string>::iterator it;
797 for (it=im.begin(); it!=im.end(); ++it)
799 vtkImageData* out = vtkImageData::New();
800 out->ShallowCopy(mReader.GetImage(*it));
805 // n *2D + T in a vector :
807 std::vector<std::string>::iterator it;
808 for (it=im.begin(); it!=im.end(); ++it)
810 vtkImageData* out = mReader.GetImage( (*it));
816 //======================================================================
818 //======================================================================
819 ///Requests the reading of an image
820 void GimmickView::RequestReading(tree::Node* n,
821 int prio, int selection_index, boost::shared_ptr<ImagePointerHolder> p)
828 ImageEventType t(n,selection_index);
830 mImageEventMap[n->GetAttribute("FullFileName")] = t;
831 mReader.Request(this,n->GetAttribute("FullFileName"),prio);
833 //======================================================================
835 //======================================================================
837 OnMultiThreadImageReaderEvent(const std::string& filename,
838 MultiThreadImageReaderUser::EventType e,
841 GimmickDebugMessage(7,
842 "MultiThreadImageReader event : "<<e<<std::endl);
845 if (filename.size()==0)
847 //What to do in this case?
849 GimmickDebugMessage(5,
850 "Pushing unknown image in queue"
852 mImageEventQueue.push_back(ImageEventType(image));*/
855 ImageEventTypeMap::iterator i;
856 //JCP 22-06-2009, test mImageEventMap.size() > 0
857 if(mImageEventMap.size()>0){
858 i = mImageEventMap.find(filename);
859 if (i!=mImageEventMap.end())
861 GimmickDebugMessage(5,
862 "Putting image of file '"<<filename<<"' on pointer"
864 ImageEventType ie(i->second);
866 ie.pointerHolder->Set(ie.image);
867 //mImageEventMap.erase(i);
873 std::string mess="ERROR: MultiThreadImageReader: Cannot read image in file ";
876 GimmickMessage(1,mess);
877 ImageEventTypeMap::iterator i;
878 i = mImageEventMap.find(filename);
879 if (i!=mImageEventMap.end())
881 ImageEventType ie(i->second);
883 ie.pointerHolder->Set(GetDefaultImage());
884 //mImageEventMap.erase(i);
888 else if (e==ImageUnloaded)
890 std::string mess="Unloaded image in file ";
893 GimmickMessage(1,mess);
894 ImageEventTypeMap::iterator i;
895 i = mImageEventMap.find(filename);
896 if (i!=mImageEventMap.end())
898 ImageEventType ie(i->second);
900 ie.pointerHolder->Set(GetDefaultImage());
901 //mImageEventMap.erase(i);
906 //====================================================================
908 //====================================================================
909 void GimmickView::ConnectValidationObserver(ValidationCallbackType callback)
911 mValidationSignal.connect(callback);
915 #if defined(USE_GDCM)
916 ////////////////////////////////////////////////////////////////////////
917 void GimmickView::Anonymize(std::vector<std::string> i_filenames, int type)
920 std::vector<GDCM_NAME_SPACE::FileHelper *> filesH;
921 std::vector<std::string> suid;
922 std::map<std::string, std::string> msuid;
923 std::string tempuid = GDCM_NAME_SPACE::Util::CreateUniqueUID();
925 std::vector<std::string>::iterator it = i_filenames.begin();
926 for(; it != i_filenames.end(); it++)
929 GDCM_NAME_SPACE::File *file;
930 file = GDCM_NAME_SPACE::File::New( );
931 file->SetLoadMode( GDCM_NAME_SPACE::LD_ALL );
932 file->SetFileName( (*it).c_str() );
936 std::cerr << "Sorry, " << (*it).c_str() <<" not a gdcm-readable "
937 << "DICOM / ACR File" <<std::endl;
941 std::cout << " ... is readable " << std::endl;
943 // We need a gdcm::FileHelper, since we want to load the pixels
944 GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(file);
947 //EED uint8_t *imageData = fh->GetImageData();
950 file->AddAnonymizeElement(0x0008, 0x0080, "*");
952 file->AddAnonymizeElement(0x0010, 0x0010, "*");
954 file->AddAnonymizeElement( 0x0010, 0x0020,"1515" );
955 // Study Instance UID
956 file->AddAnonymizeElement(0x0020, 0x000d, tempuid );
958 file->AddAnonymizeElement(0x0010, 0x2154, "3615" );
960 // Aware user will add here more fields to anonymize here
962 // The gdcm::File is modified in memory
964 file->AnonymizeFile();
968 fh->SetContentType(GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE);
970 fh->WriteDcmExplVR(file->GetFileName() +".ano1" );
971 std::cout << i <<" End Anonymize" << std::endl;
972 file->ClearAnonymizeList();
978 #if defined(USE_GDCM2)
979 void GimmickView::Anonymize(std::vector<std::string> i_filenames, int type)
983 ////////////////////////////////////////////////////////////////////////
984 //void GimmickView::Anonymize(std::vector<std::string> i_filenames, int type)
987 // gdcm::FileMetaInformation::SetSourceApplicationEntityTitle( "gdcmanon" );
988 // gdcm::Global& g = gdcm::Global::GetInstance();
989 // //if( !resourcespath )
991 // // const char *xmlpathenv = getenv("GDCM_RESOURCES_PATH");
992 // // if( xmlpathenv )
994 // // // Make sure to look for XML dict in user explicitly specified dir first:
995 // // xmlpath = xmlpathenv;
996 // // resourcespath = 1;
999 // // if( resourcespath )
1001 // // // xmlpath is set either by the cmd line option or the env var
1002 // // if( !g.Prepend( xmlpath.c_str() ) )
1004 // // std::cerr << "Specified Resources Path is not valid: " << xmlpath << std::endl;
1008 // // All set, then load the XML files:
1009 // if( !g.LoadResourcesFiles() )
1013 // const gdcm::Defs &defs = g.GetDefs(); (void)defs;
1016 // // only read the env var if no explicit cmd line option
1017 // // maybe there is an env var defined... let's check
1018 // const char *rootuid_env = getenv("GDCM_ROOT_UID");
1019 // if( rootuid_env )
1022 // root = rootuid_env;
1027 // // root is set either by the cmd line option or the env var
1028 // if( !gdcm::UIDGenerator::IsValid( root.c_str() ) )
1030 // std::cerr << "specified Root UID is not valid: " << root << std::endl;
1033 // gdcm::UIDGenerator::SetRoot( root.c_str() );
1038 // // Get private key/certificate
1039 // gdcm::CryptographicMessageSyntax cms;
1042 // if( !GetRSAKeys(cms, rsa_path.c_str(), cert_path.c_str() ) )
1046 // cms.SetCipherType( ciphertype );
1049 // // Setup gdcm::Anonymizer
1050 // gdcm::Anonymizer anon;
1052 // anon.SetCryptographicMessageSyntax( &cms );
1056 // for(unsigned int i = 0; i < nfiles; ++i)
1058 // const char *in = filenames[i].c_str();
1059 // const char *out = outfilenames[i].c_str();
1060 // if( !AnonymizeOneFileDumb(anon, in, out, empty_tags, remove_tags, replace_tags_value) )
1062 // //std::cerr << "Could not anonymize: " << in << std::endl;
1069 // // for(unsigned int i = 0; i < nfiles; ++i)
1071 // // const char *in = filenames[i].c_str();
1072 // // const char *out = outfilenames[i].c_str();
1073 // // if( !AnonymizeOneFile(anon, in, out) )
1075 // // //std::cerr << "Could not anonymize: " << in << std::endl;
1083 } // EO namespace creaImageIO