X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=packages%2Fvtk%2Fsrc%2FbbvtkConcatImages.cxx;h=cac0843f01cb91aa90a33871e55978adfb3ec9fc;hb=9bf93d26c92029689cb5da02822edb68d5835864;hp=39bc30555b07bcbbdf829b70eb06a7b375d7e96d;hpb=f346161adcdec4cf3dc3e1b8fac72a7bc43a5f50;p=bbtk.git diff --git a/packages/vtk/src/bbvtkConcatImages.cxx b/packages/vtk/src/bbvtkConcatImages.cxx index 39bc305..cac0843 100644 --- a/packages/vtk/src/bbvtkConcatImages.cxx +++ b/packages/vtk/src/bbvtkConcatImages.cxx @@ -1,33 +1,38 @@ -/*========================================================================= +/* + # --------------------------------------------------------------------- + # + # 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. + # ------------------------------------------------------------------------ */ + + +/*========================================================================= Program: bbtk Module: $RCSfile: bbvtkConcatImages.cxx,v $ Language: C++ - Date: $Date: 2010/04/28 22:10:07 $ - Version: $Revision: 1.2 $ + Date: $Date: 2012/11/16 08:51:58 $ + Version: $Revision: 1.3 $ =========================================================================*/ -/* --------------------------------------------------------------------- - -* Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale) -* Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux -* -* 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. -* ------------------------------------------------------------------------ */ - /** * \file * \brief @@ -84,96 +89,140 @@ namespace bbvtk /// - supposes *all* the images are consistent (same type, same number of components, same pixel type) /// - if images in the vector are already 3D, exports only the first one. ?!? // JPR /// - void ConcatImages::Process() - { - int dim[3]; +void ConcatImages::Process() +{ + int dim[3]; + int curDim[3]; int nbComponents; int scalarType; int nb = (unsigned int)bbGetInputIn().size(); - int consistentNb(nb); +// int consistentNb(nb); + int newSizeZ; - if (nb == 0) { + if (nb == 0) { // ??? JPR } bbGetInputIn()[0]->GetDimensions(dim); - if (dim[2] > 1 || nb == 1) // dim[2] > 1 : Hopeless for vtk : the first file contains already a 3D object + if ( nb == 1) // dim[2] > 1 : Hopeless for vtk : the first file contains already a 3D object // nb == 1 : only one image, nothing to do. { mConcat->Delete(); mConcat = bbGetInputIn()[0]; //mConcat->PrintSelf(std::cout, vtkIndent(2)); - } - else - { - // We suppose *all* the images within the directory are consistent (same sizeS, same pixel Type?...) - vtkImageData * firstImage = bbGetInputIn()[0]; + } else { + // We suppose *all* the images within the directory are consistent (same sizeS, same pixel Type?...) + vtkImageData * firstImage = bbGetInputIn()[0]; - //std::cout << "--------PrintSelf firstImage " << std::endl; - // firstImage->PrintSelf(std::cout, vtkIndent(2)); + //std::cout << "--------PrintSelf firstImage " << std::endl; + // firstImage->PrintSelf(std::cout, vtkIndent(2)); - nbComponents = firstImage->GetNumberOfScalarComponents(); - mConcat->SetNumberOfScalarComponents(nbComponents); + nbComponents = firstImage->GetNumberOfScalarComponents(); + scalarType = firstImage->GetScalarType( ); - mConcat->SetScalarType(firstImage->GetScalarType( )); - scalarType = firstImage->GetScalarType( ); - mConcat->SetScalarType(scalarType); - - mConcat->SetSpacing(firstImage->GetSpacing()); + mConcat->SetSpacing(firstImage->GetSpacing()); - firstImage->GetDimensions(dim); - // brute way to perform an ultra-mini consistency check : - // First image is supposed to be the reference image, - // any unconsistent image is just discarted... - for(int i=0; iGetDimensions(dim); + newSizeZ=0; + // brute way to perform an ultra-mini consistency check : + // First image is supposed to be the reference image, + // any unconsistent image is just discarted... + for(int i=0; iGetDimensions(curDim); + newSizeZ = newSizeZ + curDim[2]; + } // if + + } // for + + dim[2]=newSizeZ; + - dim[2]=consistentNb; mConcat->SetDimensions(dim); mConcat->SetExtent(0, dim[0]-1, 0, dim[1]-1, 0, dim[2]-1); + +//EED 2017-01-01 Migration VTK7 +#if (VTK_MAJOR_VERSION <= 5) + mConcat->SetNumberOfScalarComponents(nbComponents); + mConcat->SetScalarType(scalarType); mConcat->AllocateScalars(); mConcat->Update(); +#endif +#if (VTK_MAJOR_VERSION >= 6) + mConcat->AllocateScalars(scalarType,nbComponents); +#endif - int index_image, index_lignes, index_colonnes, index_components; - + int index_image; + + int blocksize; + int scalarSize=bbGetInputIn()[0]->GetScalarSize(); + char *pImage = (char*)mConcat->GetScalarPointer(); + char *sourcePointer; + +//EED int index_lignes, index_colonnes, index_components; + + for(index_image=0; index_imageSetScalarComponentFromDouble(index_lignes, index_colonnes, index_image, index_components,(bbGetInputIn()[index_image])->GetScalarComponentAsDouble(index_colonnes,index_lignes,0,index_components)); - } - } - } - } - } + { + continue; // discard unconsistent image ! + } + bbGetInputIn()[index_image]->GetDimensions(curDim); + blocksize = curDim[0]*curDim[1]*curDim[2]*nbComponents*scalarSize; + sourcePointer = (char*)bbGetInputIn()[index_image]->GetScalarPointer(); + memcpy(pImage, sourcePointer,blocksize); + pImage = pImage+blocksize; + +//EED 2013 oct 29 +//EED for(index_lignes=0; index_lignesSetScalarComponentFromDouble(index_lignes, index_colonnes, index_image, index_components,(bbGetInputIn()[index_image])->GetScalarComponentAsDouble(index_colonnes,index_lignes,0,index_components)); +//EED } // components +//EED } // colonnes +//EED } // lignes + + + } // if CheckConsistency + } /// for index_image + // Devrait etre dans bbUserFinalizeProcessing() ? On n'y entre jamais // JPR bbSetOutputOut(mConcat); - } +} +//--------------------------------------------------- bool ConcatImages::CheckConsistency( vtkImageData *curImage, int dim[], int nbComponents, int scalarType ) { assert (curImage); if (scalarType != curImage->GetScalarType( ) ) + { return false; - + } + if (nbComponents != curImage->GetNumberOfScalarComponents() ) + { return false; - + } + int curDim[3]; curImage->GetDimensions(curDim); if ( (curDim[0] =! dim[0]) || (curDim[1] =! dim[1]) ) + { return false; + } return true; }