From: jean-pierre roux Date: Thu, 8 Apr 2010 14:39:45 +0000 (+0000) Subject: Concat 2D vtkImageData into a single 3D vtkImageData X-Git-Tag: CREATOOLS.2-0-3~53 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=de73736400ac194137c8dce8fdfb423ca1ad9808;p=bbtk.git Concat 2D vtkImageData into a single 3D vtkImageData --- diff --git a/packages/vtk/src/bbvtkConcatImages.cxx b/packages/vtk/src/bbvtkConcatImages.cxx new file mode 100644 index 0000000..301614f --- /dev/null +++ b/packages/vtk/src/bbvtkConcatImages.cxx @@ -0,0 +1,143 @@ +/*========================================================================= + Program: bbtk + Module: $RCSfile: bbvtkConcatImages.cxx,v $ + Language: C++ + Date: $Date: 2010/04/08 14:39:45 $ + Version: $Revision: 1.1 $ +=========================================================================*/ + +/* --------------------------------------------------------------------- + +* 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 + */ + +#ifdef _USE_VTK_ +#include "bbvtkConcatImages.h" +#include "bbvtkPackage.h" + +namespace bbvtk +{ + BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ConcatImages) + BBTK_BLACK_BOX_IMPLEMENTATION(ConcatImages,bbtk::AtomicBlackBox); + +//--------------------------------------------------------------------- + + void ConcatImages::bbUserSetDefaultValues() + { + //std::cout << "-------- entree ds ConcatImages::bbUserSetDefaultValues()\n" << std::endl; + + // bbSetInputIn(NULL); /// \TODO fix it! IN is a std::vector // JPR + mConcat = NULL; + bbSetOutputOut(NULL); + } + +//--------------------------------------------------------------------- + + void ConcatImages::bbUserInitializeProcessing() + { + //std::cout << "-------- entree ds ConcatImages::bbUserInitalizeProcessing()\n" << std::endl; + //bbUserFinalizeProcessing(); + mConcat = vtkImageData::New(); // Alloc depends on bbGetInputIn().size() + } + +//--------------------------------------------------------------------- + + void ConcatImages::bbUserFinalizeProcessing() + { + //std::cout << "-------- entree ds ConcatImages::bbUserFinalizeProcessing()\n" << std::endl; + // WTF? we never enter here // JPR bbUserFinalizeProcessing() JPR + if (mConcat!=NULL) + { + // mConcat->Delete(); + // mConcat=NULL; + } + bbSetOutputOut(mConcat); + } + +//--------------------------------------------------------------------- + + /// \TODO :clean this dirty stuff : + /// - receives a std::vector + /// - exports a vtkImageData* + /// - 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]; + int nb = (unsigned int)bbGetInputIn().size(); + 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 + // 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]; + + //std::cout << "--------PrintSelf firstImage " << std::endl; + // firstImage->PrintSelf(std::cout, vtkIndent(2)); + + int nbComponents = firstImage->GetNumberOfScalarComponents(); + mConcat->SetNumberOfScalarComponents(nbComponents); + mConcat->SetScalarType(firstImage->GetScalarType( )); + firstImage->GetDimensions(dim); + dim[2]=nb; + mConcat->SetDimensions(dim); + mConcat->SetExtent(0, dim[0]-1, 0, dim[1]-1, 0, dim[2]-1); + mConcat->SetSpacing(firstImage->GetSpacing()); + + mConcat->AllocateScalars(); + mConcat->Update(); + + int index_image, 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)); + } + } + } + } + } + // Devrait etre dans bbUserFinalizeProcessing() ? On n'y entre jamais // JPR + bbSetOutputOut(mConcat); + } + +}//namespace bbtk + +#endif // _USE_VTK_ diff --git a/packages/vtk/src/bbvtkConcatImages.h b/packages/vtk/src/bbvtkConcatImages.h new file mode 100644 index 0000000..6c3d7da --- /dev/null +++ b/packages/vtk/src/bbvtkConcatImages.h @@ -0,0 +1,86 @@ +/*========================================================================= + Program: bbtk + Module: $RCSfile: bbvtkConcatImages.h,v $ + Language: C++ + Date: $Date: 2010/04/08 14:39:46 $ + Version: $Revision: 1.1 $ +=========================================================================*/ + +/* --------------------------------------------------------------------- + +* 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. +* ------------------------------------------------------------------------ */ + +/** + * \brief Short description in one line + * + * Long description which + * can span multiple lines + */ +/** + * \file + * \brief Pattern for the definition of a new type of Node (header) + */ +/** + * \class bbtk::NodePatern + * \brief Pattern for the definition of a new type of Node + */ + +#ifdef _USE_VTK_ + +#ifndef __bbvtkConcatImages_h_INCLUDED__ +#define __bbvtkConcatImages_h_INCLUDED__ +#include "bbvtk_EXPORT.h" + +#include "bbtkAtomicBlackBox.h" + +#include "vtkImageData.h" + +namespace bbvtk +{ + class bbvtk_EXPORT ConcatImages : public bbtk::AtomicBlackBox + { + public: + BBTK_BLACK_BOX_INTERFACE(ConcatImages, bbtk::AtomicBlackBox); + BBTK_DECLARE_INPUT(In, std::vector); + BBTK_DECLARE_OUTPUT(Out, vtkImageData*); + BBTK_PROCESS(Process); + void Process(); + protected: + private: + vtkImageData *mConcat; + }; + + //================================================================= + // UserBlackBox description + BBTK_BEGIN_DESCRIBE_BLACK_BOX(ConcatImages,bbtk::AtomicBlackBox); + BBTK_NAME("ConcatImages"); + BBTK_AUTHOR("jpr@creatis.univ-lyon.fr"); + BBTK_DESCRIPTION("Concatenates all the 'images' held in a std::vector into a single vtkImageData"); + BBTK_CATEGORY("application, image"); + BBTK_INPUT(ConcatImages, In, "Input Vector of Images", std::vector, ""); + BBTK_OUTPUT(ConcatImages, Out, "Concatenation of all Images", vtkImageData *, ""); + BBTK_END_DESCRIBE_BLACK_BOX(ConcatImages); + //================================================================= + +}//namespace bbvtk + +#endif //__bbtvtkConcatImages_h__ +#endif //_USE_VTK_