1 /*=========================================================================
3 Module: $RCSfile: bbvtkConcatImages.cxx,v $
5 Date: $Date: 2010/04/08 14:39:45 $
6 Version: $Revision: 1.1 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
37 #include "bbvtkConcatImages.h"
38 #include "bbvtkPackage.h"
42 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ConcatImages)
43 BBTK_BLACK_BOX_IMPLEMENTATION(ConcatImages,bbtk::AtomicBlackBox);
45 //---------------------------------------------------------------------
47 void ConcatImages::bbUserSetDefaultValues()
49 //std::cout << "-------- entree ds ConcatImages::bbUserSetDefaultValues()\n" << std::endl;
51 // bbSetInputIn(NULL); /// \TODO fix it! IN is a std::vector<vtkImageData> // JPR
56 //---------------------------------------------------------------------
58 void ConcatImages::bbUserInitializeProcessing()
60 //std::cout << "-------- entree ds ConcatImages::bbUserInitalizeProcessing()\n" << std::endl;
61 //bbUserFinalizeProcessing();
62 mConcat = vtkImageData::New(); // Alloc depends on bbGetInputIn().size()
65 //---------------------------------------------------------------------
67 void ConcatImages::bbUserFinalizeProcessing()
69 //std::cout << "-------- entree ds ConcatImages::bbUserFinalizeProcessing()\n" << std::endl;
70 // WTF? we never enter here // JPR bbUserFinalizeProcessing() JPR
76 bbSetOutputOut(mConcat);
79 //---------------------------------------------------------------------
81 /// \TODO :clean this dirty stuff :
82 /// - receives a std::vector<vtkImageData*>
83 /// - exports a vtkImageData*
84 /// - supposes *all* the images are consistent (same type, same number of components, same pixel type)
85 /// - if images in the vector are already 3D, exports only the first one. ?!? // JPR
87 void ConcatImages::Process()
90 int nb = (unsigned int)bbGetInputIn().size();
91 if (nb == 0) {} // ??? JPR
93 bbGetInputIn()[0]->GetDimensions(dim);
94 if (dim[2] > 1 || nb == 1) // dim[2] > 1 : Hopeless for vtk : the first file contains already a 3D object
95 // nb == 1 : only one image, nothing to do.
98 mConcat = bbGetInputIn()[0];
99 //mConcat->PrintSelf(std::cout, vtkIndent(2));
103 // We suppose *all* the images within the directory are consistent (same sizeS, same pixel Type?...)
104 vtkImageData * firstImage = bbGetInputIn()[0];
106 //std::cout << "--------PrintSelf firstImage " << std::endl;
107 // firstImage->PrintSelf(std::cout, vtkIndent(2));
109 int nbComponents = firstImage->GetNumberOfScalarComponents();
110 mConcat->SetNumberOfScalarComponents(nbComponents);
111 mConcat->SetScalarType(firstImage->GetScalarType( ));
112 firstImage->GetDimensions(dim);
114 mConcat->SetDimensions(dim);
115 mConcat->SetExtent(0, dim[0]-1, 0, dim[1]-1, 0, dim[2]-1);
116 mConcat->SetSpacing(firstImage->GetSpacing());
118 mConcat->AllocateScalars();
121 int index_image, index_lignes, index_colonnes, index_components;
123 for(index_image=0; index_image<nb; index_image++)
125 for(index_lignes=0; index_lignes<dim[0];index_lignes++)
127 for(index_colonnes=0; index_colonnes<dim[1];index_colonnes++)
129 for(index_components=0; index_components<nbComponents;index_components++)
131 mConcat->SetScalarComponentFromDouble(index_lignes, index_colonnes, index_image, index_components,(bbGetInputIn()[index_image])->GetScalarComponentAsDouble(index_colonnes,index_lignes,0,index_components));
137 // Devrait etre dans bbUserFinalizeProcessing() ? On n'y entre jamais // JPR
138 bbSetOutputOut(mConcat);