31 #include "boost/filesystem.hpp"
34 #include <gdcmGlobal.h>
35 #include <gdcmSerieHelper.h>
36 #include <gdcmFileHelper.h>
38 #include <vtkGdcmReader.h>
50 #pragma warning(disable: 4996)
53 namespace fs = boost::filesystem;
61 ImageExtent(
const std::string& x,
const std::string& y,
const std::string& z,
const std::string& t)
63 sscanf(x.c_str(),
"%d",&
mExtent[0]);
64 sscanf(y.c_str(),
"%d",&
mExtent[1]);
65 sscanf(z.c_str(),
"%d",&
mExtent[2]);
66 sscanf(t.c_str(),
"%d",&
mExtent[3]);
152 Gimmick::TreeHandlerMapType::const_iterator i;
153 for (i =
mGimmick->GetTreeHandlerMap().begin();
154 i!=
mGimmick->GetTreeHandlerMap().end();
176 TreeViewMapType::iterator i;
180 GimmickError(
"INTERNAL ERROR : GimmickView::UpdateTreeView : '"
181 <<t<<
"' is not in TreeViewMap");
183 i->second->UpdateLevel(l);
202 bool compatible=
true;
204 if((*extent).Get(0)!=
Get(0)
205 || (*extent).Get(1)!=
Get(1))
230 std::string mMessage;
231 mMessage=
"Cannot have 0 images selected!";
244 std::string mMessage;
248 mMessage=
"Cannot have 0 images selected!";
253 boost::shared_ptr<ImageExtent> ie=boost::shared_ptr<ImageExtent>(
new ImageExtent((*sel).GetAttribute(
"D0028_0010"),
254 (*sel).GetAttribute(
"D0028_0011"),
255 (*sel).GetAttribute(
"D0028_0012"),
267 std::stringstream out;
269 mMessage = out.str();
280 std::stringstream out;
281 out<<
"Cannot add this image to selection : would result in a "<<
mImageExtent->GetDimension()+1<<
"D image!";
287 std::stringstream out;
288 out<<
"Selecting "<<
mImageExtent->GetDimension()<<
"D images is not allowed !";
292 else if(min_dim==3 && (ie->Get(2)+
mImageExtent->Get(2))<2)
294 std::stringstream out;
295 out <<
"Cannot build the selection as it would result in a ";
297 out <<
"D image, and the minimum is ";
306 std::stringstream out;
308 mMessage = out.str();
313 mMessage=
"The selected images are not compatible.";
356 vtkImageData * out=vtkImageData::New();
360 else if (im.size()>1)
366 std::vector<std::string>::iterator it;
367 for (it=im.begin(); it!=im.end(); ++it)
369 vtkImageData* out = vtkImageData::New();
377 vtkImageData* out = vtkImageData::New();
379 out->SetScalarType(first->GetScalarType());
380 out->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
383 first->GetWholeExtent(ext);
387 ext[5] = (int)im.size()-1;
391 ext[5] = ext[5] * (int)im.size()-1;
398 first->GetDimensions(dim);
400 out->SetDimensions(dim[0], dim[1], (
int)im.size() );
401 out->AllocateScalars();
404 unsigned long imsize = dim[0] * dim[1];
405 imsize = imsize * dim[2] ;
411 imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
417 first->GetSpacing(spc);
424 out->SetSpacing(spc);
427 std::vector<std::string>::iterator it;
429 for (it=im.begin(); it!=im.end(); ++it)
432 memcpy(out->GetScalarPointer(0,0,slice), cur->GetScalarPointer(0,0,0), imsize);
456 first->GetDimensions(dim);
473 if(i_attr.
inside.size() >0)
475 mGimmick->GetAttributes(i_file,o_infos,i_attr);
489 std::vector<std::string>::iterator it;
490 for (it=im.begin(); it!=im.end(); ++it)
493 out.
img = vtkImageData::New();
497 o_output.push_back(out);
515 out.
img = vtkImageData::New();
516 out.
img->SetScalarType(first->GetScalarType());
517 out.
img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
519 first->GetWholeExtent(ext);
522 ext[5] = (int)im.size()-1;
526 ext[5] = ext[5] * (int)im.size()-1;
528 out.
img->SetExtent(ext);
531 first->GetDimensions(dim);
532 first->GetSpacing(spac);
533 out.
img->SetSpacing(spac);
534 out.
img->SetDimensions(dim[0], dim[1], (
int)im.size() );
535 out.
img->AllocateScalars();
537 unsigned long imsize = dim[0] * dim[1];
538 imsize = imsize * dim[2] ;
541 imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
545 std::vector<std::string>::iterator it;
546 for (it=im.begin(); it!=im.end(); ++it)
549 memcpy(out.
img->GetScalarPointer(0,0,slice), cur->GetScalarPointer(0,0,0), imsize);
553 o_output.push_back(out);
567 first->GetDimensions(dim);
568 first->GetSpacing(spac);
571 unsigned long imsize = dim[0] * dim[1];
572 imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
575 std::vector<std::string>::iterator it;
576 std::vector<OutStrGimmick>::iterator it_out = o_output.begin();
578 for (it=im.begin(); it!=im.end(); ++it)
581 for (
int slice= 0 ; slice <dim[2]; slice++)
584 out.
img = vtkImageData::New();
585 out.
img->SetScalarType(first->GetScalarType());
586 out.
img->SetSpacing(spac);
587 out.
img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
589 first->GetWholeExtent(ext);
591 out.
img->SetExtent(ext);
593 out.
img->SetDimensions(dim[0], dim[1], 1 );
594 out.
img->AllocateScalars();
596 memcpy(out.
img->GetScalarPointer(0,0,0), cur->GetScalarPointer(0,0,slice), imsize);
597 o_output.push_back(out);
615 std::vector<std::string>::iterator it;
616 std::vector<OutStrGimmick>::iterator it_out = o_output.begin();
619 first->GetDimensions(dim);
621 for (
int slice= 0 ; slice <dim[2]; slice++)
624 out.
img = vtkImageData::New();
625 out.
img->SetScalarType(first->GetScalarType());
626 out.
img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
630 first->GetWholeExtent(ext);
632 out.
img->SetExtent(ext);
633 first->GetSpacing(spac);
634 out.
img->SetSpacing(spac);
635 out.
img->SetDimensions(dim[0], dim[1], (
int)im.size() );
636 out.
img->AllocateScalars();
638 unsigned long imsize = dim[0] * dim[1];
639 imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
642 for (it=im.begin(); it!=im.end(); ++it, index ++)
645 memcpy(out.
img->GetScalarPointer(0,0,index), cur->GetScalarPointer(0,0,slice), imsize);
646 o_output.push_back(out);
664 int size = (int)im.size();
674 if (
isSingle(im.front()) || i_dim != 1)
738 vtkImageData* out = vtkImageData::New();
745 else if (im.size()>1)
752 std::vector<std::string>::iterator it;
753 for (it=im.begin(); it!=im.end(); ++it)
755 vtkImageData* out = vtkImageData::New();
765 std::vector<std::string>::iterator it;
766 for (it=im.begin(); it!=im.end(); ++it)
779 int prio,
int selection_index, boost::shared_ptr<ImagePointerHolder> p)
800 "MultiThreadImageReader event : "<<e<<std::endl);
803 if (filename.size()==0)
813 ImageEventTypeMap::iterator i;
820 "Putting image of file '"<<filename<<
"' on pointer"
831 std::string mess=
"ERROR: MultiThreadImageReader: Cannot read image in file ";
835 ImageEventTypeMap::iterator i;
848 std::string mess=
"Unloaded image in file ";
852 ImageEventTypeMap::iterator i;
873 #if defined(USE_GDCM)
878 std::vector<GDCM_NAME_SPACE::FileHelper *> filesH;
879 std::vector<std::string> suid;
880 std::map<std::string, std::string> msuid;
881 std::string tempuid = GDCM_NAME_SPACE::Util::CreateUniqueUID();
883 std::vector<std::string>::iterator it = i_filenames.begin();
884 for(; it != i_filenames.end(); it++)
887 GDCM_NAME_SPACE::File *file;
888 file = GDCM_NAME_SPACE::File::New( );
889 file->SetLoadMode( GDCM_NAME_SPACE::LD_ALL );
890 file->SetFileName( (*it).c_str() );
894 std::cerr <<
"Sorry, " << (*it).c_str() <<
" not a gdcm-readable "
895 <<
"DICOM / ACR File" <<std::endl;
899 std::cout <<
" ... is readable " << std::endl;
902 GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(file);
904 uint8_t *imageData = fh->GetImageData();
907 file->AddAnonymizeElement(0x0008, 0x0080,
"*");
909 file->AddAnonymizeElement(0x0010, 0x0010,
"*");
911 file->AddAnonymizeElement( 0x0010, 0x0020,
"1515" );
913 file->AddAnonymizeElement(0x0020, 0x000d, tempuid );
915 file->AddAnonymizeElement(0x0010, 0x2154,
"3615" );
921 file->AnonymizeFile();
925 fh->SetContentType(GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE);
927 fh->WriteDcmExplVR(file->GetFileName() +
".ano1" );
928 std::cout << i <<
" End Anonymize" << std::cout;
929 file->ClearAnonymizeList();
935 #if defined(USE_GDCM2)