X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FcreaImageIOGimmickView.cpp;h=4ada3a9c54277a33230e0bee464de9bc514f3f3f;hb=bebe9cec5af89cf1461b3230c9aa31e930d49fb8;hp=2fbc2586920fd133520f917c62c7193345900ef1;hpb=80dc7421c0a44fa7f37d19c7c5752ff6d0c0d38c;p=creaImageIO.git diff --git a/src/creaImageIOGimmickView.cpp b/src/creaImageIOGimmickView.cpp index 2fbc258..4ada3a9 100644 --- a/src/creaImageIOGimmickView.cpp +++ b/src/creaImageIOGimmickView.cpp @@ -1,23 +1,55 @@ +/* +# --------------------------------------------------------------------- +# +# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image +# pour la Santé) +# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton +# Previous Authors : Laurent Guigues, Jean-Pierre Roux +# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil +# +# This software is governed by the CeCILL-B license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL-B +# license as circulated by CEA, CNRS and INRIA at the following URL +# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +# or in the file LICENSE.txt. +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL-B license and that you accept its terms. +# ------------------------------------------------------------------------ +*/ + + #include -#include + #include "boost/filesystem.hpp" #if defined(USE_GDCM) #include #include +#include +#include #include #endif -#if defined(USE_GDCM2) +/*#if defined(USE_GDCM2) #include #include "gdcmSystem.h" #include "gdcmCryptographicMessageSyntax.h" #include "gdcmUIDGenerator.h" #include "gdcmAnonymizer.h" #include "gdcmGlobal.h" +#endif*/ +#if defined(_WIN32) +#pragma warning(disable: 4996) #endif - namespace fs = boost::filesystem; namespace creaImageIO { @@ -28,20 +60,20 @@ namespace creaImageIO public: ImageExtent(const std::string& x, const std::string& y, const std::string& z, const std::string& t) { - sscanf(x.c_str(),"%d",&mExtent[0]); - sscanf(y.c_str(),"%d",&mExtent[1]); - sscanf(z.c_str(),"%d",&mExtent[2]); - sscanf(t.c_str(),"%d",&mExtent[3]); - if(x==""){mExtent[0]=1;} - if(y==""){mExtent[1]=1;} - if(z==""){mExtent[2]=1;} - if(t==""){mExtent[3]=1;} - - if (mExtent[3]>1) mDim=4; - else if (mExtent[2]>1) mDim=3; - else if (mExtent[1]>1) mDim=2; - else if (mExtent[0]>1) mDim=1; - else mDim=0; + sscanf(x.c_str(),"%d",&mExtent[0]); + sscanf(y.c_str(),"%d",&mExtent[1]); + sscanf(z.c_str(),"%d",&mExtent[2]); + sscanf(t.c_str(),"%d",&mExtent[3]); + if(x==""){mExtent[0]=1;} + if(y==""){mExtent[1]=1;} + if(z==""){mExtent[2]=1;} + if(t==""){mExtent[3]=1;} + + if (mExtent[3]>1) mDim=4; + else if (mExtent[2]>1) mDim=3; + else if (mExtent[1]>1) mDim=2; + else if (mExtent[0]>1) mDim=1; + else mDim=0; } @@ -296,11 +328,16 @@ namespace creaImageIO mValidationSignal(ivalid); } + void GimmickView::stopReader() + { + mReader.Stop(); + } + //====================================================================== ///Reads Images (Non Threaded) void GimmickView::ReadImagesNotThreaded(std::vector& s, std::vector im, int dimension) { - mReader.Stop(); + stopReader(); /* remember! #define GIMMICK_NO_IMAGE_SELECTION 0 @@ -347,11 +384,11 @@ void GimmickView::ReadImagesNotThreaded(std::vector& s, std::vect if(ext[5] == 0) { - ext[5] = im.size()-1; + ext[5] = (int)im.size()-1; } else { - ext[5] = ext[5] * im.size()-1; // to deal with multiframes - JPR + ext[5] = ext[5] * (int)im.size()-1; // to deal with multiframes - JPR } out->SetExtent(ext); @@ -360,7 +397,7 @@ void GimmickView::ReadImagesNotThreaded(std::vector& s, std::vect int dim[3]; first->GetDimensions(dim); - out->SetDimensions(dim[0], dim[1], im.size() ); + out->SetDimensions(dim[0], dim[1], (int)im.size() ); out->AllocateScalars(); out->Update(); @@ -417,7 +454,7 @@ void GimmickView::ReadImagesNotThreaded(std::vector& s, std::vect vtkImageData* first = mReader.GetImage( i_file); int dim[3]; first->GetDimensions(dim); - if (dim[3] > 1) + if (dim[2] > 1) { bres = false; } @@ -449,20 +486,37 @@ void GimmickView::ReadImagesNotThreaded(std::vector& s, std::vect void GimmickView::readImages1(std::vector& o_output, std::vector im, OutputAttr i_attr) { + + i_attr.outside.push_back("D0019_100a"); // simens Number Of Images In Mosaic + +//EED Borrame + int i,isize=i_attr.outside.size(); + for (i=0;i::iterator it; for (it=im.begin(); it!=im.end(); ++it) { OutStrGimmick out; out.img = vtkImageData::New(); out.img->ShallowCopy(mReader.GetImage(*it)); - if(i_attr.mult) +printf("EED GimmickView::readImages1 A\n "); + if(i_attr.mult) + { getAttributes((*it),out.infos,i_attr); +printf("EED GimmickView::readImages1 B %s \n ", out.infos.find("D0019_100a")->second.c_str() ); + } o_output.push_back(out); } // If we want only one output information structure, we set it outside the loop if(!i_attr.mult) { - getAttributes(im.front(), o_output.front().infos,i_attr); + getAttributes(im.front(), o_output.front().infos, i_attr); +printf("EED GimmickView::readImages1 C %s \n ", o_output.front().infos.find("D0019_100a")->second.c_str() ); } } @@ -482,16 +536,17 @@ void GimmickView::ReadImagesNotThreaded(std::vector& s, std::vect first->GetWholeExtent(ext); // send also 0,0 in Z if(ext[5] == 0) { - ext[5] = im.size()-1; - } - else - { - ext[5] = ext[5] * im.size()-1; // to deal with multiframes + ext[5] = (int)im.size()-1; + } else { + ext[5] = ext[5] * (int)im.size()-1; // to deal with multiframes } out.img->SetExtent(ext); int dim[3]; + double spac[3]; first->GetDimensions(dim); - out.img->SetDimensions(dim[0], dim[1], im.size() ); + first->GetSpacing(spac); + out.img->SetSpacing(spac); + out.img->SetDimensions(dim[0], dim[1], (int)im.size() ); out.img->AllocateScalars(); out.img->Update(); unsigned long imsize = dim[0] * dim[1]; @@ -523,7 +578,9 @@ void GimmickView::ReadImagesNotThreaded(std::vector& s, std::vect { vtkImageData* first = mReader.GetImage( im.front()); int dim[3]; + double spac[3]; first->GetDimensions(dim); + first->GetSpacing(spac); // differents formats char , short, etc... // differents components 1..3 ex. jpg ->RGB 3 unsigned long imsize = dim[0] * dim[1]; @@ -533,7 +590,7 @@ void GimmickView::ReadImagesNotThreaded(std::vector& s, std::vect std::vector::iterator it; std::vector::iterator it_out = o_output.begin(); - for (it=im.begin(); it!=im.end(); ++it, it_out += dim[2]) + for (it=im.begin(); it!=im.end(); ++it)//, it_out ++) { vtkImageData* cur = mReader.GetImage( (*it) ); for (int slice= 0 ; slice & s, std::vect OutStrGimmick out; out.img = vtkImageData::New(); out.img->SetScalarType(first->GetScalarType()); - + out.img->SetSpacing(spac); out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents()); int ext[6]; first->GetWholeExtent(ext); // send also 0,0 in Z @@ -554,8 +611,8 @@ void GimmickView::ReadImagesNotThreaded(std::vector& s, std::vect memcpy(out.img->GetScalarPointer(0,0,0), cur->GetScalarPointer(0,0,slice), imsize); o_output.push_back(out); } - if(i_attr.mult) - getAttributes((*it),(*it_out).infos,i_attr); + // if(i_attr.mult) + // getAttributes((*it),(*it_out).infos,i_attr); } if(!i_attr.mult) { @@ -564,7 +621,7 @@ void GimmickView::ReadImagesNotThreaded(std::vector& s, std::vect } - ////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////// // create an output structure with n entries (T size) = T + n output ////////////////////////////////////////////////////////// void GimmickView::readImages4(std::vector& o_output, std::vector im, @@ -584,11 +641,13 @@ void GimmickView::ReadImagesNotThreaded(std::vector& s, std::vect out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents()); int ext[6]; + double spac[6]; first->GetWholeExtent(ext); // send also 0,0 in Z ext[5] = 0; out.img->SetExtent(ext); - - out.img->SetDimensions(dim[0], dim[1], im.size() ); + first->GetSpacing(spac); + out.img->SetSpacing(spac); + out.img->SetDimensions(dim[0], dim[1], (int)im.size() ); out.img->AllocateScalars(); out.img->Update(); unsigned long imsize = dim[0] * dim[1]; @@ -617,28 +676,21 @@ void GimmickView::ReadImagesNotThreaded(std::vector& s, std::vect void GimmickView::readImages(std::vector& o_output, std::vector im, OutputAttr i_attr, int i_dim, double i_zspc) { - int size = im.size(); + int size = (int)im.size(); if ( size == 0) { return; - } - else if (size == 1) - { + } else if (size == 1) { // Simplest case // Only one image : give it // But take in count multiframe possibility if ( isSingle(im.front()) || i_dim != 1) { readImages1(o_output,im, i_attr); - } - else - { - readImages2(o_output,im, i_attr,i_zspc); - } - - } - else - { + } else { + readImages2(o_output,im, i_attr,i_zspc); + } + } else { // multiple or single frame if ( isSingle(im.front()) ) { @@ -647,42 +699,34 @@ void GimmickView::ReadImagesNotThreaded(std::vector& s, std::vect { // 2D to 3D readImages3(o_output,im, i_attr,i_zspc); - } - else - { + } else { readImages1(o_output,im, i_attr); } - } - else - { + } else { // we deal with multiple frames n x (2D x T) // Differents outputs are avaialable if(i_dim == 1) { // put all in one output readImages3(o_output,im, i_attr,i_zspc); - - } - else if( i_dim == 2) - { + } else if( i_dim == 2) { // put in a vector of n x T (2D) readImages2(o_output,im, i_attr,i_zspc); - } - else if( i_dim == 3) - { + } else if( i_dim == 3) { // put in a vector of n (2D x T) // No transformations. readImages1(o_output,im, i_attr); - } - else - { + } else { // put in a vector of T (2D x n) readImages4(o_output,im, i_attr); - } - } - } - } + } // i_dim + } //isSingle(im.front()) + } // if size +//EED UnMosaic step... +//How to verifie if is a mosaic file , with how many images inside?? + + } @@ -701,7 +745,8 @@ void GimmickView::ReadImagesNotThreadedInVector(std::vector& s, s } else if (im.size()>1) // Test inutile ? JPR { - vtkImageData* first = mReader.GetImage( im.front()); + /// \TODO fix unused variable 'first' +// vtkImageData* first = mReader.GetImage( im.front()); if (dimension == 2) { // n3D @@ -711,10 +756,8 @@ void GimmickView::ReadImagesNotThreadedInVector(std::vector& s, s vtkImageData* out = vtkImageData::New(); out->ShallowCopy(mReader.GetImage(*it)); s.push_back(out); - } - } - else - { + } // for + } else { // n2D to 3D // NO! // n *2D + T in a vector : @@ -723,9 +766,9 @@ void GimmickView::ReadImagesNotThreadedInVector(std::vector& s, s { vtkImageData* out = mReader.GetImage( (*it)); s.push_back(out); - } - } - } + } // for + } // if dimension + } // if im.size } //====================================================================== @@ -826,7 +869,74 @@ void GimmickView::ReadImagesNotThreadedInVector(std::vector& s, s } - +#if defined(USE_GDCM) +//////////////////////////////////////////////////////////////////////// +void GimmickView::Anonymize(std::vector i_filenames, int type) +{ + bool res = true; + std::vector filesH; + std::vector suid; + std::map msuid; + std::string tempuid = GDCM_NAME_SPACE::Util::CreateUniqueUID(); + int i = 1; + std::vector::iterator it = i_filenames.begin(); + for(; it != i_filenames.end(); it++) + { + + GDCM_NAME_SPACE::File *file; + file = GDCM_NAME_SPACE::File::New( ); + file->SetLoadMode( GDCM_NAME_SPACE::LD_ALL ); + file->SetFileName( (*it).c_str() ); + res = file->Load(); + if ( !res ) + { + std::cerr << "Sorry, " << (*it).c_str() <<" not a gdcm-readable " + << "DICOM / ACR File" <Delete(); + //return 0; + } + std::cout << " ... is readable " << std::endl; + + // We need a gdcm::FileHelper, since we want to load the pixels + GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(file); + +//Borrame +//EED uint8_t *imageData = fh->GetImageData(); + + // Institution name + file->AddAnonymizeElement(0x0008, 0x0080, "*"); + // Patient's name + file->AddAnonymizeElement(0x0010, 0x0010, "*"); + // Patient's ID + file->AddAnonymizeElement( 0x0010, 0x0020,"1515" ); + // Study Instance UID + file->AddAnonymizeElement(0x0020, 0x000d, tempuid ); + // Telephone + file->AddAnonymizeElement(0x0010, 0x2154, "3615" ); + + // Aware user will add here more fields to anonymize here + + // The gdcm::File is modified in memory + + file->AnonymizeFile(); + + + i++; + fh->SetContentType(GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE); + + fh->WriteDcmExplVR(file->GetFileName() +".ano1" ); + std::cout << i <<" End Anonymize" << std::endl; + file->ClearAnonymizeList(); + file->Delete(); + fh->Delete(); + } +} +#endif +#if defined(USE_GDCM2) +void GimmickView::Anonymize(std::vector i_filenames, int type) +{ +} +#endif //////////////////////////////////////////////////////////////////////// //void GimmickView::Anonymize(std::vector i_filenames, int type) //{ @@ -927,4 +1037,4 @@ void GimmickView::ReadImagesNotThreadedInVector(std::vector& s, s // } //} // -} // EO namespace creaImageIO \ No newline at end of file +} // EO namespace creaImageIO