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 GimmickDebugMessage(1,"GimmickView::~GimmickView"
130 //======================================================================
132 //======================================================================
133 /// Initializes the view :
134 /// Creates the TreeViews for all the TreeHandler of the Controller
136 void GimmickView::Initialize()
138 mReaderStarted=false;
140 //======================================================================
142 //======================================================================
144 void GimmickView::Finalize()
146 printf("EED GimmickView::Finalize \n");
149 //======================================================================
151 //======================================================================
152 /// Create the tree views
153 void GimmickView::CreateTreeViews()
155 GimmickMessage(2,"Creating the tree views"<<std::endl);
156 Gimmick::TreeHandlerMapType::const_iterator i;
157 for (i = mGimmick->GetTreeHandlerMap().begin();
158 i!= mGimmick->GetTreeHandlerMap().end();
161 this->CreateTreeView(i->second);
165 /// Create a tree view with a given name
166 void GimmickView::CreateSingleTreeView(std::string &i_name)
168 this->CreateTreeView(mGimmick->GetTreeHandlerMap()[i_name]);
173 //======================================================================
175 //======================================================================
176 /// Updates the TreeView of given name from level l to bottom
177 /// (calls the virtual method TreeView::Update())
178 void GimmickView::UpdateTreeViewLevel(const std::string& t, int l)
180 TreeViewMapType::iterator i;
181 i = GetTreeViewMap().find(t);
182 if ( i == GetTreeViewMap().end() )
184 GimmickError("INTERNAL ERROR : GimmickView::UpdateTreeView : '"
185 <<t<<"' is not in TreeViewMap");
187 i->second->UpdateLevel(l);
190 //======================================================================
191 /// Clears the status and begins a new selection process
192 void GimmickView::ResetExtent()
196 mImageExtent.reset();
201 //======================================================================
203 //======================================================================
204 bool ImageExtent::IsCompatible(const ImageExtent& ie)
206 bool compatible=true;
207 ImageExtent * extent= (ImageExtent*)&ie;
208 if((*extent).Get(0)!=Get(0)
209 || (*extent).Get(1)!=Get(1))
216 //======================================================================
218 //======================================================================
219 void ImageExtent::Add(const ImageExtent& ie)
221 ImageExtent * extent= (ImageExtent*)&ie;
222 mExtent[2]+=(*extent).Get(2);
229 //======================================================================
230 /// No selected image
231 bool GimmickView::NoValidateSelected ()
233 GimmickDebugMessage(2,"Validating selected"<<std::endl);
234 std::string mMessage;
235 mMessage="Cannot have 0 images selected!";
237 modifyValidationSignal(valid);
238 SetMessage(mMessage);
242 //======================================================================
243 ///Validates the dimension compliance of the images with the maximum and
244 ///minimum given, and between their sizes
245 bool GimmickView::ValidateSelected (tree::Node* sel, int min_dim, int max_dim)
247 GimmickDebugMessage(2,"Validating selected"<<std::endl);
248 std::string mMessage;
252 mMessage="Cannot have 0 images selected!";
257 boost::shared_ptr<ImageExtent> ie=boost::shared_ptr<ImageExtent>(new ImageExtent((*sel).GetAttribute("D0028_0010"),
258 (*sel).GetAttribute("D0028_0011"),
259 (*sel).GetAttribute("D0028_0012"),
265 if((mImageExtent->Get(min_dim-1)<2)||(mImageExtent->Get(max_dim)>1))
271 std::stringstream out;
272 out << mImageExtent->GetDimension() << "D image " << mImageExtent->Get(0) << "x"<< mImageExtent->Get(1) << "x"<< mImageExtent->Get(2) <<" selected";
273 mMessage = out.str();
274 mImageExtent->SetDimension(2);
280 if(mImageExtent->IsCompatible(*ie))
282 if(mImageExtent->GetDimension()==max_dim && mImageExtent->Get(max_dim)>2)
284 std::stringstream out;
285 out<<"Cannot add this image to selection : would result in a "<<mImageExtent->GetDimension()+1<<"D image!";
291 std::stringstream out;
292 out<<"Selecting "<<mImageExtent->GetDimension()<<"D images is not allowed !";
296 else if(min_dim==3 && (ie->Get(2)+mImageExtent->Get(2))<2)
298 std::stringstream out;
299 out << "Cannot build the selection as it would result in a ";
300 out << mImageExtent->GetDimension();
301 out << "D image, and the minimum is ";
309 mImageExtent->Add(*ie);
310 std::stringstream out;
311 out << mImageExtent->GetDimension() << "D image " << mImageExtent->Get(0) << "x"<< mImageExtent->Get(1) << "x"<< mImageExtent->Get(2) <<" selected";
312 mMessage = out.str();
317 mMessage="The selected images are not compatible.";
323 modifyValidationSignal(valid);
324 SetMessage(mMessage);
328 //======================================================================
329 void GimmickView::modifyValidationSignal(bool ivalid)
332 mValidationSignal(ivalid);
335 void GimmickView::stopReader()
340 //======================================================================
341 ///Reads Images (Non Threaded)
342 void GimmickView::ReadImagesNotThreaded(std::vector<vtkImageData*>& s, std::vector<std::string> im, int dimension)
347 #define GIMMICK_NO_IMAGE_SELECTION 0
348 #define GIMMICK_2D_IMAGE_SELECTION 2
349 #define GIMMICK_3D_IMAGE_SELECTION 3
350 #define GIMMICK_4D_IMAGE_SELECTION 4
357 // Create the output data
360 vtkImageData * out=vtkImageData::New();
361 out->ShallowCopy(mReader.GetImage(im.front()));
364 else if (im.size()>1) // Test inutile ? JPR
366 vtkImageData* first = mReader.GetImage( im.front());
370 std::vector<std::string>::iterator it;
371 for (it=im.begin(); it!=im.end(); ++it)
373 vtkImageData* out = vtkImageData::New();
374 out->ShallowCopy(mReader.GetImage(*it));
381 vtkImageData* out = vtkImageData::New();
382 // out->CopyStructure(first);
384 //first->GetExtent(ext); // JPR
385 //EED 2017-01-01 Migration VTK7
386 #if VTK_MAJOR_VERSION <= 5
387 first->GetWholeExtent(ext); // renvoie egalement 0,0 en Z // JPR
389 first->GetExtent(ext); // renvoie egalement 0,0 en Z // JPR
394 ext[5] = (int)im.size()-1;
398 ext[5] = ext[5] * (int)im.size()-1; // to deal with multiframes - JPR
402 // LG : TODO : Z Spacing ?
405 first->GetDimensions(dim);
406 out->SetDimensions(dim[0], dim[1], (int)im.size() );
408 //EED 2017-01-01 Migration VTK7
409 #if VTK_MAJOR_VERSION <= 5
410 out->SetScalarType(first->GetScalarType());
411 out->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
412 out->AllocateScalars();
415 out->AllocateScalars(first->GetScalarType(),first->GetNumberOfScalarComponents());
418 unsigned long imsize = dim[0] * dim[1];
419 imsize = imsize * dim[2] ; // deal with multiframes // JPR
423 // differents formats char , short, etc...
424 // differents components 1..3 ex. jpg ->RGB 3
425 imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
428 // Order the file name vector
431 first->GetSpacing(spc);
433 // OrderTheFileNameVector is not here anymore.
434 // Try orderFilesWithZSpacing from OutputModel FCY
435 // spc[2]=OrderTheFileNameVector(im);
438 out->SetSpacing(spc);
441 std::vector<std::string>::iterator it;
443 for (it=im.begin(); it!=im.end(); ++it)
445 vtkImageData* cur = mReader.GetImage( (*it) );
446 memcpy(out->GetScalarPointer(0,0,slice), cur->GetScalarPointer(0,0,0), imsize);
456 //======================================================================
460 //////////////////////////////////////////////////////////
461 // Test if the image is a multiple or single frame.
462 // For the moment only with the creation of vtkImageDta.
463 // TO DO with image size and dim!!!
464 //////////////////////////////////////////////////////////
465 bool GimmickView::isSingle(const std::string i_file)
468 vtkImageData* first = mReader.GetImage( i_file);
470 first->GetDimensions(dim);
481 //////////////////////////////////////////////////////////
482 // get Attributes values for a file
483 //////////////////////////////////////////////////////////
485 void GimmickView::getAttributes(const std::string i_file, std::map<std::string, std::string> &o_infos, OutputAttr i_attr)
487 if(i_attr.inside.size() >0)
489 mGimmick->GetAttributes(i_file,o_infos,i_attr);
491 if(i_attr.outside.size()>0)
493 mReader.getAttributes(i_file,o_infos, i_attr.outside);
497 //////////////////////////////////////////////////////////
498 // create an output structure with n entries = n output
499 //////////////////////////////////////////////////////////
500 void GimmickView::readImages1(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
503 i_attr.outside.push_back("D0019_100a"); // simens Number Of Images In Mosaic
504 std::vector<std::string>::iterator it;
505 for (it=im.begin(); it!=im.end(); ++it)
508 out.img = vtkImageData::New();
509 out.img->ShallowCopy(mReader.GetImage(*it));
512 getAttributes((*it),out.infos,i_attr);
514 o_output.push_back(out);
516 // If we want only one output information structure, we set it outside the loop
519 getAttributes(im.front(), o_output.front().infos, i_attr);
524 //////////////////////////////////////////////////////////
525 // create an output structure with n entries = 1 output
526 //////////////////////////////////////////////////////////
527 void GimmickView::readImages3(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
528 OutputAttr i_attr, double i_zspc)
531 vtkImageData* first = mReader.GetImage( im.front() );
532 out.img = vtkImageData::New();
534 //EED 2017-01-01 Migration VTK7
535 #if VTK_MAJOR_VERSION <= 5
536 first->GetWholeExtent(ext); // send also 0,0 in Z
538 first->GetExtent(ext); // send also 0,0 in Z
542 ext[5] = (int)im.size()-1;
544 ext[5] = ext[5] * (int)im.size()-1; // to deal with multiframes
546 out.img->SetExtent(ext);
549 first->GetDimensions(dim);
550 first->GetSpacing(spac);
551 out.img->SetSpacing(spac);
552 out.img->SetDimensions(dim[0], dim[1], (int)im.size() );
556 //EED 2017-01-01 Migration VTK7
557 #if VTK_MAJOR_VERSION <= 5
558 out.img->SetScalarType(first->GetScalarType());
559 out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
560 out.img->AllocateScalars();
563 out.img->AllocateScalars(first->GetScalarType(), first->GetNumberOfScalarComponents());
566 unsigned long imsize = dim[0] * dim[1];
567 imsize = imsize * dim[2] ; // deal with multiframes here
568 // differents formats char , short, etc...
569 // differents components 1..3 ex. jpg ->RGB 3
570 imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
571 // Order the file name vector already did with the OutputModel!!!
572 //!!!!out.img->SetSpacing(i_zspc);
574 std::vector<std::string>::iterator it;
576 for (it=im.begin(); it!=im.end(); ++it)
578 vtkImageData* cur = mReader.GetImage( (*it) );
579 memcpy(out.img->GetScalarPointer(0,0,slice), cur->GetScalarPointer(0,0,0), imsize);
583 getAttributes(im.front(),out.infos, i_attr);
584 o_output.push_back(out);
588 // TO DO NO VERY SURE : NEED TO BE TESTED
589 //////////////////////////////////////////////////////////
590 // create an output structure with n entries (T size) = T output (n size)
591 //////////////////////////////////////////////////////////
592 void GimmickView::readImages2(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
593 OutputAttr i_attr, double i_zspc)
595 vtkImageData* first = mReader.GetImage( im.front());
598 first->GetDimensions(dim);
599 first->GetSpacing(spac);
600 // differents formats char , short, etc...
601 // differents components 1..3 ex. jpg ->RGB 3
602 unsigned long imsize = dim[0] * dim[1];
603 imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
605 // Order the file name vector already did with the OutputModel!!!
606 std::vector<std::string>::iterator it;
607 std::vector<OutStrGimmick>::iterator it_out = o_output.begin();
609 for (it=im.begin(); it!=im.end(); ++it)//, it_out ++)
611 vtkImageData* cur = mReader.GetImage( (*it) );
612 for (int slice= 0 ; slice <dim[2]; slice++)
615 out.img = vtkImageData::New();
616 out.img->SetSpacing(spac);
618 //EED 2017-01-01 Migration VTK7
619 #if VTK_MAJOR_VERSION <= 5
620 first->GetWholeExtent(ext); // send also 0,0 in Z
622 first->GetExtent(ext); // send also 0,0 in Z
625 out.img->SetExtent(ext);
626 out.img->SetDimensions(dim[0], dim[1], 1 );
628 //EED 2017-01-01 Migration VTK7
629 #if VTK_MAJOR_VERSION <= 5
630 out.img->SetScalarType(first->GetScalarType());
631 out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
632 out.img->AllocateScalars();
635 out.img->AllocateScalars(first->GetScalarType(),first->GetNumberOfScalarComponents());
639 memcpy(out.img->GetScalarPointer(0,0,0), cur->GetScalarPointer(0,0,slice), imsize);
640 o_output.push_back(out);
643 // getAttributes((*it),(*it_out).infos,i_attr);
647 getAttributes(im.front(), o_output.front().infos,i_attr);
652 //////////////////////////////////////////////////////////
653 // create an output structure with n entries (T size) = T + n output
654 //////////////////////////////////////////////////////////
655 void GimmickView::readImages4(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
658 std::vector<std::string>::iterator it;
659 std::vector<OutStrGimmick>::iterator it_out = o_output.begin();
660 vtkImageData* first = mReader.GetImage( im.front());
662 first->GetDimensions(dim);
664 for (int slice= 0 ; slice <dim[2]; slice++)
667 out.img = vtkImageData::New();
671 //EED 2017-01-01 Migration VTK7
672 #if VTK_MAJOR_VERSION <= 5
673 first->GetWholeExtent(ext); // send also 0,0 in Z
675 first->GetExtent(ext); // send also 0,0 in Z
680 out.img->SetExtent(ext);
681 first->GetSpacing(spac);
682 out.img->SetSpacing(spac);
683 out.img->SetDimensions(dim[0], dim[1], (int)im.size() );
685 //EED 2017-01-01 Migration VTK7
686 #if VTK_MAJOR_VERSION <= 5
687 out.img->SetScalarType(first->GetScalarType());
688 out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
689 out.img->AllocateScalars();
692 out.img->AllocateScalars(first->GetScalarType(), first->GetNumberOfScalarComponents());
695 unsigned long imsize = dim[0] * dim[1];
696 imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
699 for (it=im.begin(); it!=im.end(); ++it, index ++)
701 vtkImageData* cur = mReader.GetImage( (*it) );
702 memcpy(out.img->GetScalarPointer(0,0,index), cur->GetScalarPointer(0,0,slice), imsize);
703 o_output.push_back(out);
706 if(!i_attr.mult) // No sense to take informations in all images
708 getAttributes(im.front(), o_output.front().infos,i_attr);
714 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
715 // Global function to read Images and create wished output (informations, multiple, type and size of output...)
716 // In function of type (file, vector) and size, the correct readImages function is selected
717 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
718 void GimmickView::readImages(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
719 OutputAttr i_attr, int i_dim, double i_zspc)
721 int size = (int)im.size();
725 } else if (size == 1) {
727 // Only one image : give it
728 // But take in count multiframe possibility
729 if ( isSingle(im.front()) || i_dim != 1)
731 readImages1(o_output,im, i_attr);
733 readImages2(o_output,im, i_attr,i_zspc);
736 // multiple or single frame
737 if ( isSingle(im.front()) )
739 //we deal with 2D images
743 readImages3(o_output,im, i_attr,i_zspc);
745 readImages1(o_output,im, i_attr);
748 // we deal with multiple frames n x (2D x T)
749 // Differents outputs are avaialable
752 // put all in one output
753 readImages3(o_output,im, i_attr,i_zspc);
754 } else if( i_dim == 2) {
755 // put in a vector of n x T (2D)
756 readImages2(o_output,im, i_attr,i_zspc);
757 } else if( i_dim == 3) {
758 // put in a vector of n (2D x T)
759 // No transformations.
760 readImages1(o_output,im, i_attr);
762 // put in a vector of T (2D x n)
763 readImages4(o_output,im, i_attr);
765 } //isSingle(im.front())
768 //EED UnMosaic step...
769 //How to verifie if is a mosaic file , with how many images inside??
774 void GimmickView::ReadImagesNotThreadedInVector(std::vector<vtkImageData*>& s, std::vector<std::string> im, int dimension)
776 // Create the output data
779 // Only one image : give it
780 vtkImageData* out = vtkImageData::New();
781 GimmickDebugMessage(3, "State Check: Full Filename: "
784 out->ShallowCopy(mReader.GetImage(im.front()));
787 else if (im.size()>1) // Test inutile ? JPR
789 /// \TODO fix unused variable 'first'
790 // vtkImageData* first = mReader.GetImage( im.front());
794 std::vector<std::string>::iterator it;
795 for (it=im.begin(); it!=im.end(); ++it)
797 vtkImageData* out = vtkImageData::New();
798 out->ShallowCopy(mReader.GetImage(*it));
803 // n *2D + T in a vector :
805 std::vector<std::string>::iterator it;
806 for (it=im.begin(); it!=im.end(); ++it)
808 vtkImageData* out = mReader.GetImage( (*it));
814 //======================================================================
816 //======================================================================
817 ///Requests the reading of an image
818 void GimmickView::RequestReading(tree::Node* n,
819 int prio, int selection_index, boost::shared_ptr<ImagePointerHolder> p)
826 ImageEventType t(n,selection_index);
828 mImageEventMap[n->GetAttribute("FullFileName")] = t;
829 mReader.Request(this,n->GetAttribute("FullFileName"),prio);
831 //======================================================================
833 //======================================================================
835 OnMultiThreadImageReaderEvent(const std::string& filename,
836 MultiThreadImageReaderUser::EventType e,
839 GimmickDebugMessage(7,
840 "MultiThreadImageReader event : "<<e<<std::endl);
843 if (filename.size()==0)
845 //What to do in this case?
847 GimmickDebugMessage(5,
848 "Pushing unknown image in queue"
850 mImageEventQueue.push_back(ImageEventType(image));*/
853 ImageEventTypeMap::iterator i;
854 //JCP 22-06-2009, test mImageEventMap.size() > 0
855 if(mImageEventMap.size()>0){
856 i = mImageEventMap.find(filename);
857 if (i!=mImageEventMap.end())
859 GimmickDebugMessage(5,
860 "Putting image of file '"<<filename<<"' on pointer"
862 ImageEventType ie(i->second);
864 ie.pointerHolder->Set(ie.image);
865 //mImageEventMap.erase(i);
871 std::string mess="ERROR: MultiThreadImageReader: Cannot read image in file ";
874 GimmickMessage(1,mess);
875 ImageEventTypeMap::iterator i;
876 i = mImageEventMap.find(filename);
877 if (i!=mImageEventMap.end())
879 ImageEventType ie(i->second);
881 ie.pointerHolder->Set(GetDefaultImage());
882 //mImageEventMap.erase(i);
886 else if (e==ImageUnloaded)
888 std::string mess="Unloaded image in file ";
891 GimmickMessage(1,mess);
892 ImageEventTypeMap::iterator i;
893 i = mImageEventMap.find(filename);
894 if (i!=mImageEventMap.end())
896 ImageEventType ie(i->second);
898 ie.pointerHolder->Set(GetDefaultImage());
899 //mImageEventMap.erase(i);
904 //====================================================================
906 //====================================================================
907 void GimmickView::ConnectValidationObserver(ValidationCallbackType callback)
909 mValidationSignal.connect(callback);
913 #if defined(USE_GDCM)
914 ////////////////////////////////////////////////////////////////////////
915 void GimmickView::Anonymize(std::vector<std::string> i_filenames, int type)
918 std::vector<GDCM_NAME_SPACE::FileHelper *> filesH;
919 std::vector<std::string> suid;
920 std::map<std::string, std::string> msuid;
921 std::string tempuid = GDCM_NAME_SPACE::Util::CreateUniqueUID();
923 std::vector<std::string>::iterator it = i_filenames.begin();
924 for(; it != i_filenames.end(); it++)
927 GDCM_NAME_SPACE::File *file;
928 file = GDCM_NAME_SPACE::File::New( );
929 file->SetLoadMode( GDCM_NAME_SPACE::LD_ALL );
930 file->SetFileName( (*it).c_str() );
934 std::cerr << "Sorry, " << (*it).c_str() <<" not a gdcm-readable "
935 << "DICOM / ACR File" <<std::endl;
939 std::cout << " ... is readable " << std::endl;
941 // We need a gdcm::FileHelper, since we want to load the pixels
942 GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(file);
945 //EED uint8_t *imageData = fh->GetImageData();
948 file->AddAnonymizeElement(0x0008, 0x0080, "*");
950 file->AddAnonymizeElement(0x0010, 0x0010, "*");
952 file->AddAnonymizeElement( 0x0010, 0x0020,"1515" );
953 // Study Instance UID
954 file->AddAnonymizeElement(0x0020, 0x000d, tempuid );
956 file->AddAnonymizeElement(0x0010, 0x2154, "3615" );
958 // Aware user will add here more fields to anonymize here
960 // The gdcm::File is modified in memory
962 file->AnonymizeFile();
966 fh->SetContentType(GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE);
968 fh->WriteDcmExplVR(file->GetFileName() +".ano1" );
969 std::cout << i <<" End Anonymize" << std::endl;
970 file->ClearAnonymizeList();
976 #if defined(USE_GDCM2)
977 void GimmickView::Anonymize(std::vector<std::string> i_filenames, int type)
981 ////////////////////////////////////////////////////////////////////////
982 //void GimmickView::Anonymize(std::vector<std::string> i_filenames, int type)
985 // gdcm::FileMetaInformation::SetSourceApplicationEntityTitle( "gdcmanon" );
986 // gdcm::Global& g = gdcm::Global::GetInstance();
987 // //if( !resourcespath )
989 // // const char *xmlpathenv = getenv("GDCM_RESOURCES_PATH");
990 // // if( xmlpathenv )
992 // // // Make sure to look for XML dict in user explicitly specified dir first:
993 // // xmlpath = xmlpathenv;
994 // // resourcespath = 1;
997 // // if( resourcespath )
999 // // // xmlpath is set either by the cmd line option or the env var
1000 // // if( !g.Prepend( xmlpath.c_str() ) )
1002 // // std::cerr << "Specified Resources Path is not valid: " << xmlpath << std::endl;
1006 // // All set, then load the XML files:
1007 // if( !g.LoadResourcesFiles() )
1011 // const gdcm::Defs &defs = g.GetDefs(); (void)defs;
1014 // // only read the env var if no explicit cmd line option
1015 // // maybe there is an env var defined... let's check
1016 // const char *rootuid_env = getenv("GDCM_ROOT_UID");
1017 // if( rootuid_env )
1020 // root = rootuid_env;
1025 // // root is set either by the cmd line option or the env var
1026 // if( !gdcm::UIDGenerator::IsValid( root.c_str() ) )
1028 // std::cerr << "specified Root UID is not valid: " << root << std::endl;
1031 // gdcm::UIDGenerator::SetRoot( root.c_str() );
1036 // // Get private key/certificate
1037 // gdcm::CryptographicMessageSyntax cms;
1040 // if( !GetRSAKeys(cms, rsa_path.c_str(), cert_path.c_str() ) )
1044 // cms.SetCipherType( ciphertype );
1047 // // Setup gdcm::Anonymizer
1048 // gdcm::Anonymizer anon;
1050 // anon.SetCryptographicMessageSyntax( &cms );
1054 // for(unsigned int i = 0; i < nfiles; ++i)
1056 // const char *in = filenames[i].c_str();
1057 // const char *out = outfilenames[i].c_str();
1058 // if( !AnonymizeOneFileDumb(anon, in, out, empty_tags, remove_tags, replace_tags_value) )
1060 // //std::cerr << "Could not anonymize: " << in << std::endl;
1067 // // for(unsigned int i = 0; i < nfiles; ++i)
1069 // // const char *in = filenames[i].c_str();
1070 // // const char *out = outfilenames[i].c_str();
1071 // // if( !AnonymizeOneFile(anon, in, out) )
1073 // // //std::cerr << "Could not anonymize: " << in << std::endl;
1081 } // EO namespace creaImageIO