X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=bbtk%2Fsrc%2FbbcreaImageIOItkImagesChooserDialogBox.cxx;fp=bbtk%2Fsrc%2FbbcreaImageIOItkImagesChooserDialogBox.cxx;h=e0c2a1ed29402d0924a5aa4bde2a34aaa86c874b;hb=b52bf19755b9e9f7d4a40abb2c8e881b56d49577;hp=b3b8552023d5bb8675eeb0fff46694bfb0ab26a4;hpb=688c28613d4d3f54fb74d55adb653a4a26cebf13;p=creaImageIO.git diff --git a/bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.cxx b/bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.cxx index b3b8552..e0c2a1e 100644 --- a/bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.cxx +++ b/bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.cxx @@ -1,28 +1,28 @@ /* - # --------------------------------------------------------------------- - # - # 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. - # ------------------------------------------------------------------------ + # --------------------------------------------------------------------- + # + # 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. + # ------------------------------------------------------------------------ */ //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) @@ -31,6 +31,32 @@ #include "bbcreaImageIOItkImagesChooserDialogBox.h" #include "bbcreaImageIOPackage.h" +#include "itkImage.h" +#include "itkImportImageFilter.h" + +/* +// ------------------------------------------------------------------------- +// LFV: avoid itk::Concept check on 4d or superior images +#define BBCREAIMAGEIO_ChooserDlg_Template( t, ty, di ) \ + if( t == typeid( itk::Image< ty, di >* ) ) \ + { \ + this->Export< itk::Image< ty, di > >( ); \ + this->ExportVTK< itk::Image< ty, di > >( ); \ + } +*/ + +// ------------------------------------------------------------------------- +// LFV: avoid itk::Concept check on 4d or superior images +#define BBCREAIMAGEIO_ChooserDlg_Template( t, ty, di ) \ + if( t == typeid( itk::Image< ty, di >* ) ) \ + { \ + this->Export< ty , di >( ); \ + this->ExportVTK< itk::Image< ty, di > >( ); \ + } + + +// ------------------------------------------------------------------------- + namespace bbcreaImageIO { @@ -46,47 +72,115 @@ void ItkImagesChooserDialogBox::Process() dlg->ShowModal(); bbtk::TypeInfo typ = bbitk::GetITKImagePtrTypeInfoFromPixelTypeInfoAndDimension(*dlg->getTypes().front(), dlg->getDims().front()); - BBTK_TEMPLATE_ITK_IMAGE_SWITCH(typ, Export); - BBTK_TEMPLATE_ITK_IMAGE_SWITCH(typ, ExportVTK); + + BBCREAIMAGEIO_ChooserDlg_Template( typ, char, 1 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, short, 1 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, int, 1 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, long, 1 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, float, 1 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, double, 1 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, unsigned char, 1 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, unsigned short, 1 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, unsigned int, 1 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, unsigned long, 1 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, char, 2 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, short, 2 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, int, 2 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, long, 2 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, float, 2 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, double, 2 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, unsigned char, 2 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, unsigned short, 2 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, unsigned int, 2 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, unsigned long, 2 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, char, 3 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, short, 3 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, int, 3 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, long, 3 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, float, 3 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, double, 3 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, unsigned char, 3 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, unsigned short, 3 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, unsigned int, 3 ) + else BBCREAIMAGEIO_ChooserDlg_Template( typ, unsigned long, 3 ); + + + /* Deprecated + BBTK_TEMPLATE_ITK_IMAGE_SWITCH(typ, Export); + BBTK_TEMPLATE_ITK_IMAGE_SWITCH(typ, ExportVTK); + */ delete dlg; } -template + +//template +template void ItkImagesChooserDialogBox::Export() { - if (dlg->getImagesSelected().size() == 1) - { + typedef itk::Image TImage; + if (dlg->getImagesSelected().size() == 1) + { bbSetOutputOut( dlg->getTemplatedImagesSelected().front().GetPointer() ); - } - else if (dlg->getImagesSelected().size() > 1) - { - OutputImagesITKType outVect; - - typename std::vector tempImgs= dlg->getTemplatedImagesSelected(); - typename std::vector::iterator it = tempImgs.begin(); - for(;it != tempImgs.end(); ++it) - { - outVect.push_back( (*it).GetPointer() ); - } - bbSetOutputOutIImages( outVect); - } - else - { + } else if (dlg->getImagesSelected().size() > 1){ + OutputImagesITKType outVect; + typename std::vector tempImgs= dlg->getTemplatedImagesSelected(); + typename std::vector::iterator it = tempImgs.begin(); + for(;it != tempImgs.end(); ++it) + { + outVect.push_back( (*it).GetPointer() ); + } // for + bbSetOutputOutIImages( outVect); + + typedef ty RGBPixelType; + typedef itk::ImportImageFilter< ty , di > ImportFilterType; + typename ImportFilterType::Pointer importFilter = ImportFilterType::New(); + + typename TImage::SizeType imsize; + imsize[0] = tempImgs[0].GetPointer()->GetLargestPossibleRegion().GetSize()[0]; + imsize[1] = tempImgs[0].GetPointer()->GetLargestPossibleRegion().GetSize()[1]; + imsize[2] = tempImgs.size(); + + typename ImportFilterType::IndexType start; + start.Fill( 0 ); + typename ImportFilterType::RegionType region; + region.SetIndex( start ); + region.SetSize( imsize ); + importFilter->SetRegion( region ); + + const itk::SpacePrecisionType origin[ 3 ] = { 0.0, 0.0, 0.0 }; + importFilter->SetOrigin( origin ); + + const itk::SpacePrecisionType spacing[ 3 ] = { 1.0, 1.0, 1.0 }; + importFilter->SetSpacing( spacing ); + const unsigned long int numberOfPixels2D = imsize[0]*imsize[1]; + const unsigned long int numberOfPixels2DInBytes = imsize[0]*imsize[1]*sizeof(ty); + const unsigned long int numberOfPixels3D = imsize[0]*imsize[1]*imsize[2]*sizeof(ty); + + RGBPixelType * localBuffer = new RGBPixelType[ numberOfPixels3D ]; + RGBPixelType * tmpLocalBuffer = localBuffer; + + it = tempImgs.begin(); + for(;it != tempImgs.end(); ++it) + { + memcpy(tmpLocalBuffer, (*it).GetPointer()->GetBufferPointer(), numberOfPixels2DInBytes); + tmpLocalBuffer = tmpLocalBuffer + numberOfPixels2D; + } // for + + const bool importImageFilterWillOwnTheBuffer = true; + importFilter->SetImportPointer( localBuffer , numberOfPixels3D , importImageFilterWillOwnTheBuffer ); + importFilter->Update(); + importFilter->Register(); + bbSetOutputOut( importFilter->GetOutput() ); + + } else { // warning: passing NULL to non-pointer //bbSetOutputOut( NULL); bbSetOutputOut(0); // JPR } - // FCY To test the Output - //typedef itk::Image ImageType; - //typedef itk::ImageFileReader< ImageType > itkReaderType; - // typename itkReaderType::Pointer reader = itkReaderType::New(); - // - // reader->SetFileName("d:\test.hdr"); - // reader->Update(); - //reader->GetOutput()->Register(); - // this->bbSetOutputOut(reader->GetOutput()); } + + template void ItkImagesChooserDialogBox::ExportVTK() { @@ -100,40 +194,34 @@ void ItkImagesChooserDialogBox::ExportVTK() dlg->split3Din3Dvtk( (*it) ); } bbSetOutputOutVImages( dlg->getVtkImagesSelected() ); - } - else if (dlg->getDims().front() == 4) - { + } else if (dlg->getDims().front() == 4) { // To Test // dlg->split4Din3Dvtk("d:/temp2"); // bbSetOutputOutVImages( dlg->getVtkImagesSelected()); - } - else - { - // NOT IMPLEMENTED YET FOR DIMENSIONS > 4 - - } - + } else { + // NOT IMPLEMENTED YET FOR DIMENSIONS > 4 + } // if dlg } + //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== void ItkImagesChooserDialogBox::bbUserSetDefaultValues() -{ - +{ } + //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== void ItkImagesChooserDialogBox::bbUserInitializeProcessing() { - } + //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== void ItkImagesChooserDialogBox::bbUserFinalizeProcessing() { - } -} -// EO namespace bbcreaImageIO + +} // EO namespace bbcreaImageIO