#if defined(USE_GDCM2)
#include <vtkGDCMImageReader.h>
+#include "gdcmSystem.h"
+#include "gdcmCryptographicMessageSyntax.h"
+#include "gdcmUIDGenerator.h"
+#include "gdcmAnonymizer.h"
+#include "gdcmGlobal.h"
#endif
}
else
{
- boost::shared_ptr<ImageExtent> ie=boost::shared_ptr<ImageExtent>(new ImageExtent((*sel).GetAttribute("D0028_0010"),
+ boost::shared_ptr<ImageExtent> ie=boost::shared_ptr<ImageExtent>(new ImageExtent((*sel).GetAttribute("D0028_0010"),
(*sel).GetAttribute("D0028_0011"),
(*sel).GetAttribute("D0028_0012"),
""));
+
if(mImageExtent==0)
{
mImageExtent=ie;
//======================================================================
void GimmickView::modifyValidationSignal(bool ivalid)
{
+
mValidationSignal(ivalid);
}
double spc[3];
first->GetSpacing(spc);
- spc[2]=OrderTheFileNameVector(im);
+
+ // OrderTheFileNameVector is not here anymore.
+ // Try orderFilesWithZSpacing from OutputModel FCY
+ // spc[2]=OrderTheFileNameVector(im);
+ spc[2] =1;
out->SetSpacing(spc);
}
//======================================================================
-#if defined(USE_GDCM)
- double GimmickView::OrderTheFileNameVector(std::vector<std::string> &im)
-{
- double spacing=1;
- typedef std::vector<GDCM_NAME_SPACE::File* > FileList;
- FileList fileVector;
- //GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
- GDCM_NAME_SPACE::SerieHelper *sh = GDCM_NAME_SPACE::SerieHelper::New();
- std::vector<std::string> lstAux;
- std::vector<std::string>::iterator it;
- for (it=im.begin(); it!=im.end(); ++it)
+
+
+ //////////////////////////////////////////////////////////
+ // Test if the image is a multiple or single frame.
+ // For the moment only with the creation of vtkImageDta.
+ // TO DO with image size and dim!!!
+ //////////////////////////////////////////////////////////
+ bool GimmickView::isSingle(const std::string i_file)
{
- ///\TODO liberer les GDCM_NAME_SPACE::File a la fin! // JPR
- GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
- f->SetFileName(*it);
- f->Load();
- if (f->IsReadable())
+ bool bres = true;
+ vtkImageData* first = mReader.GetImage( i_file);
+ int dim[3];
+ first->GetDimensions(dim);
+ if (dim[2] > 1)
{
- fileVector.push_back(f);
- } else {
- lstAux.push_back(*it);
+ bres = false;
}
- } // for
-
+ else
+ {
+ }
+ return bres;
+ }
+
+ //////////////////////////////////////////////////////////
+ // get Attributes values for a file
+ //////////////////////////////////////////////////////////
- if ((fileVector.size()>1) && (sh->IsCoherent( &fileVector )))
+ void GimmickView::getAttributes(const std::string i_file, std::map<std::string, std::string> &o_infos, OutputAttr i_attr)
{
- sh->OrderFileList(&fileVector);
- spacing= sh->GetZSpacing();
- im.clear();
- int i;
- for (i=0; i<fileVector.size(); i++)
- {
- im.push_back( (fileVector[i])->GetFileName() );
- }
- for (i=0; i<lstAux.size(); i++)
+ if(i_attr.inside.size() >0)
+ {
+ mGimmick->GetAttributes(i_file,o_infos,i_attr);
+ }
+ if(i_attr.outside.size()>0)
+ {
+ mReader.getAttributes(i_file,o_infos, i_attr.outside);
+ }
+ }
+
+ //////////////////////////////////////////////////////////
+ // create an output structure with n entries = n output
+ //////////////////////////////////////////////////////////
+ void GimmickView::readImages1(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
+ OutputAttr i_attr)
+ {
+ std::vector<std::string>::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)
+ getAttributes((*it),out.infos,i_attr);
+ 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);
+ }
+
+ }
+
+ //////////////////////////////////////////////////////////
+ // create an output structure with n entries = 1 output
+ //////////////////////////////////////////////////////////
+ void GimmickView::readImages3(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
+ OutputAttr i_attr, double i_zspc)
+ {
+ OutStrGimmick out;
+ vtkImageData* first = mReader.GetImage( im.front());
+ out.img = vtkImageData::New();
+ out.img->SetScalarType(first->GetScalarType());
+ out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
+ int ext[6];
+ 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
+ }
+ out.img->SetExtent(ext);
+ int dim[3];
+ first->GetDimensions(dim);
+ out.img->SetDimensions(dim[0], dim[1], im.size() );
+ out.img->AllocateScalars();
+ out.img->Update();
+ unsigned long imsize = dim[0] * dim[1];
+ imsize = imsize * dim[2] ; // deal with multiframes here
+ // differents formats char , short, etc...
+ // differents components 1..3 ex. jpg ->RGB 3
+ imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
+ // Order the file name vector already did with the OutputModel!!!
+ //!!!!out.img->SetSpacing(i_zspc);
+ int slice = 0;
+ std::vector<std::string>::iterator it;
+ for (it=im.begin(); it!=im.end(); ++it)
+ {
+ vtkImageData* cur = mReader.GetImage( (*it) );
+ memcpy(out.img->GetScalarPointer(0,0,slice), cur->GetScalarPointer(0,0,0), imsize);
+ slice++;
+ }
+ getAttributes(im.front(),out.infos, i_attr);
+ o_output.push_back(out);
+ }
+
+
+ // TO DO NO VERY SURE : NEED TO BE TESTED
+ //////////////////////////////////////////////////////////
+ // create an output structure with n entries (T size) = T output (n size)
+ //////////////////////////////////////////////////////////
+ void GimmickView::readImages2(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
+ OutputAttr i_attr, double i_zspc)
+ {
+ vtkImageData* first = mReader.GetImage( im.front());
+ int dim[3];
+ first->GetDimensions(dim);
+ // differents formats char , short, etc...
+ // differents components 1..3 ex. jpg ->RGB 3
+ unsigned long imsize = dim[0] * dim[1];
+ imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
+
+ // Order the file name vector already did with the OutputModel!!!
+ std::vector<std::string>::iterator it;
+ std::vector<OutStrGimmick>::iterator it_out = o_output.begin();
+
+ for (it=im.begin(); it!=im.end(); ++it, it_out += dim[2])
+ {
+ vtkImageData* cur = mReader.GetImage( (*it) );
+ for (int slice= 0 ; slice <dim[2]; slice++)
{
- im.push_back( lstAux[i] );
+ OutStrGimmick out;
+ out.img = vtkImageData::New();
+ out.img->SetScalarType(first->GetScalarType());
+
+ out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
+ int ext[6];
+ first->GetWholeExtent(ext); // send also 0,0 in Z
+ ext[5] = 0;
+ out.img->SetExtent(ext);
+
+ out.img->SetDimensions(dim[0], dim[1], 1 );
+ out.img->AllocateScalars();
+ out.img->Update();
+ memcpy(out.img->GetScalarPointer(0,0,0), cur->GetScalarPointer(0,0,slice), imsize);
+ o_output.push_back(out);
}
- }else {
- std::sort( im.begin(), im.end() );
+ if(i_attr.mult)
+ getAttributes((*it),(*it_out).infos,i_attr);
+ }
+ if(!i_attr.mult)
+ {
+ getAttributes(im.front(), o_output.front().infos,i_attr);
+ }
+
}
+
+ //////////////////////////////////////////////////////////
+ // create an output structure with n entries (T size) = T + n output
+ //////////////////////////////////////////////////////////
+ void GimmickView::readImages4(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
+ OutputAttr i_attr)
+ {
+ std::vector<std::string>::iterator it;
+ std::vector<OutStrGimmick>::iterator it_out = o_output.begin();
+ vtkImageData* first = mReader.GetImage( im.front());
+ int dim[3];
+ first->GetDimensions(dim);
- return spacing;
-}
+ for (int slice= 0 ; slice <dim[2]; slice++)
+ {
+ OutStrGimmick out;
+ out.img = vtkImageData::New();
+ out.img->SetScalarType(first->GetScalarType());
+ out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
+
+ int ext[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() );
+ out.img->AllocateScalars();
+ out.img->Update();
+ unsigned long imsize = dim[0] * dim[1];
+ imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
+ int index = 0;
+
+ for (it=im.begin(); it!=im.end(); ++it, index ++)
+ {
+ vtkImageData* cur = mReader.GetImage( (*it) );
+ memcpy(out.img->GetScalarPointer(0,0,index), cur->GetScalarPointer(0,0,slice), imsize);
+ o_output.push_back(out);
+ }
+ }
+ if(!i_attr.mult) // No sense to take informations in all images
+ {
+ getAttributes(im.front(), o_output.front().infos,i_attr);
+ }
+ }
-#endif
-#if defined(USE_GDCM2)
- // TO DO
- double GimmickView::OrderTheFileNameVector(std::vector<std::string> &im)
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Global function to read Images and create wished output (informations, multiple, type and size of output...)
+// In function of type (file, vector) and size, the correct readImages function is selected
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ void GimmickView::readImages(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
+ OutputAttr i_attr, int i_dim, double i_zspc)
{
- return 1;
+ int size = im.size();
+ if ( size == 0)
+ {
+ return;
+ }
+ 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
+ {
+ // multiple or single frame
+ if ( isSingle(im.front()) )
+ {
+ //we deal with 2D images
+ if(i_dim == 1)
+ {
+ // 2D to 3D
+ readImages3(o_output,im, i_attr,i_zspc);
+ }
+ else
+ {
+ readImages1(o_output,im, i_attr);
+ }
+ }
+ 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)
+ {
+ // put in a vector of n x T (2D)
+ readImages2(o_output,im, i_attr,i_zspc);
+ }
+ else if( i_dim == 3)
+ {
+ // put in a vector of n (2D x T)
+ // No transformations.
+ readImages1(o_output,im, i_attr);
+ }
+ else
+ {
+ // put in a vector of T (2D x n)
+ readImages4(o_output,im, i_attr);
+ }
+ }
+ }
}
-#endif
-//======================================================================
+
void GimmickView::ReadImagesNotThreadedInVector(std::vector<vtkImageData*>& s, std::vector<std::string> im, int dimension)
mValidationSignal.connect(callback);
}
-} // EO namespace creaImageIO
-//////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
//void GimmickView::Anonymize(std::vector<std::string> i_filenames, int type)
+//{
+//
+// gdcm::FileMetaInformation::SetSourceApplicationEntityTitle( "gdcmanon" );
+// gdcm::Global& g = gdcm::Global::GetInstance();
+// //if( !resourcespath )
+// // {
+// // const char *xmlpathenv = getenv("GDCM_RESOURCES_PATH");
+// // if( xmlpathenv )
+// // {
+// // // Make sure to look for XML dict in user explicitly specified dir first:
+// // xmlpath = xmlpathenv;
+// // resourcespath = 1;
+// // }
+// // }
+// // if( resourcespath )
+// // {
+// // // xmlpath is set either by the cmd line option or the env var
+// // if( !g.Prepend( xmlpath.c_str() ) )
+// // {
+// // std::cerr << "Specified Resources Path is not valid: " << xmlpath << std::endl;
+// // return 1;
+// // }
+// // }
+// // All set, then load the XML files:
+// if( !g.LoadResourcesFiles() )
+// {
+// return ;
+// }
+// const gdcm::Defs &defs = g.GetDefs(); (void)defs;
+// if( !rootuid )
+// {
+// // only read the env var if no explicit cmd line option
+// // maybe there is an env var defined... let's check
+// const char *rootuid_env = getenv("GDCM_ROOT_UID");
+// if( rootuid_env )
+// {
+// rootuid = 1;
+// root = rootuid_env;
+// }
+// }
+// if( rootuid )
+// {
+// // root is set either by the cmd line option or the env var
+// if( !gdcm::UIDGenerator::IsValid( root.c_str() ) )
+// {
+// std::cerr << "specified Root UID is not valid: " << root << std::endl;
+// return 1;
+// }
+// gdcm::UIDGenerator::SetRoot( root.c_str() );
+// }
+//
+// if(type == 0)
// {
- //if(type == 0)
- //{
- // // Get private key/certificate
- // gdcm::CryptographicMessageSyntax cms;
- //if( !dumb_mode )
- // {
- // if( !GetRSAKeys(cms, rsa_path.c_str(), cert_path.c_str() ) )
- // {
- // return 1;
- // }
- // cms.SetCipherType( ciphertype );
- // }
-
- //// Setup gdcm::Anonymizer
- //gdcm::Anonymizer anon;
- //if( !dumb_mode )
- // anon.SetCryptographicMessageSyntax( &cms );
-
- //if( dumb_mode )
- // {
- // for(unsigned int i = 0; i < nfiles; ++i)
- // {
- // const char *in = filenames[i].c_str();
- // const char *out = outfilenames[i].c_str();
- // if( !AnonymizeOneFileDumb(anon, in, out, empty_tags, remove_tags, replace_tags_value) )
- // {
- // //std::cerr << "Could not anonymize: " << in << std::endl;
- // return 1;
- // }
- // }
- // }
- //else
- // {
- // for(unsigned int i = 0; i < nfiles; ++i)
- // {
- // const char *in = filenames[i].c_str();
- // const char *out = outfilenames[i].c_str();
- // if( !AnonymizeOneFile(anon, in, out) )
- // {
- // //std::cerr << "Could not anonymize: " << in << std::endl;
- // return 1;
- // }
- // }
- // }
-// }
\ No newline at end of file
+// // Get private key/certificate
+// gdcm::CryptographicMessageSyntax cms;
+// if( !dumb_mode )
+// {
+// if( !GetRSAKeys(cms, rsa_path.c_str(), cert_path.c_str() ) )
+// {
+// return 1;
+// }
+// cms.SetCipherType( ciphertype );
+// }
+//
+// // Setup gdcm::Anonymizer
+// gdcm::Anonymizer anon;
+// if( !dumb_mode )
+// anon.SetCryptographicMessageSyntax( &cms );
+//
+// if( dumb_mode )
+// {
+// for(unsigned int i = 0; i < nfiles; ++i)
+// {
+// const char *in = filenames[i].c_str();
+// const char *out = outfilenames[i].c_str();
+// if( !AnonymizeOneFileDumb(anon, in, out, empty_tags, remove_tags, replace_tags_value) )
+// {
+// //std::cerr << "Could not anonymize: " << in << std::endl;
+// return 1;
+// }
+// }
+// }
+// //else
+// // {
+// // for(unsigned int i = 0; i < nfiles; ++i)
+// // {
+// // const char *in = filenames[i].c_str();
+// // const char *out = outfilenames[i].c_str();
+// // if( !AnonymizeOneFile(anon, in, out) )
+// // {
+// // //std::cerr << "Could not anonymize: " << in << std::endl;
+// // return 1;
+// // }
+// // }
+// // }
+// }
+//}
+//
+} // EO namespace creaImageIO