2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbvtkConcatImages.cxx,v $
32 Date: $Date: 2012/11/16 08:51:58 $
33 Version: $Revision: 1.3 $
34 =========================================================================*/
42 #include "bbvtkConcatImages.h"
43 #include "bbvtkPackage.h"
47 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ConcatImages)
48 BBTK_BLACK_BOX_IMPLEMENTATION(ConcatImages,bbtk::AtomicBlackBox);
50 //---------------------------------------------------------------------
52 void ConcatImages::bbUserSetDefaultValues()
54 //std::cout << "-------- entree ds ConcatImages::bbUserSetDefaultValues()\n" << std::endl;
56 // bbSetInputIn(NULL); /// \TODO fix it! IN is a std::vector<vtkImageData> // JPR
61 //---------------------------------------------------------------------
63 void ConcatImages::bbUserInitializeProcessing()
65 //std::cout << "-------- entree ds ConcatImages::bbUserInitalizeProcessing()\n" << std::endl;
66 //bbUserFinalizeProcessing();
67 mConcat = vtkImageData::New(); // Alloc depends on bbGetInputIn().size()
70 //---------------------------------------------------------------------
72 void ConcatImages::bbUserFinalizeProcessing()
74 //std::cout << "-------- entree ds ConcatImages::bbUserFinalizeProcessing()\n" << std::endl;
75 // WTF? we never enter here // JPR bbUserFinalizeProcessing() JPR
81 bbSetOutputOut(mConcat);
84 //---------------------------------------------------------------------
86 /// \TODO :clean this dirty stuff :
87 /// - receives a std::vector<vtkImageData*>
88 /// - exports a vtkImageData*
89 /// - supposes *all* the images are consistent (same type, same number of components, same pixel type)
90 /// - if images in the vector are already 3D, exports only the first one. ?!? // JPR
92 void ConcatImages::Process()
98 int nb = (unsigned int)bbGetInputIn().size();
99 // int consistentNb(nb);
106 bbGetInputIn()[0]->GetDimensions(dim);
107 if ( nb == 1) // dim[2] > 1 : Hopeless for vtk : the first file contains already a 3D object
108 // nb == 1 : only one image, nothing to do.
111 mConcat = bbGetInputIn()[0];
112 //mConcat->PrintSelf(std::cout, vtkIndent(2));
114 // We suppose *all* the images within the directory are consistent (same sizeS, same pixel Type?...)
115 vtkImageData * firstImage = bbGetInputIn()[0];
117 //std::cout << "--------PrintSelf firstImage " << std::endl;
118 // firstImage->PrintSelf(std::cout, vtkIndent(2));
120 nbComponents = firstImage->GetNumberOfScalarComponents();
121 scalarType = firstImage->GetScalarType( );
123 mConcat->SetSpacing(firstImage->GetSpacing());
125 firstImage->GetDimensions(dim);
127 // brute way to perform an ultra-mini consistency check :
128 // First image is supposed to be the reference image,
129 // any unconsistent image is just discarted...
130 for(int i=0; i<nb; i++)
134 //EED if ( !CheckConsistency(firstImage, dim, nbComponents, scalarType))
135 //EED consistentNb--;
137 if ( CheckConsistency(bbGetInputIn()[i], dim, nbComponents, scalarType))
139 bbGetInputIn()[i]->GetDimensions(curDim);
140 newSizeZ = newSizeZ + curDim[2];
148 mConcat->SetDimensions(dim);
149 mConcat->SetExtent(0, dim[0]-1, 0, dim[1]-1, 0, dim[2]-1);
152 //EED 2017-01-01 Migration VTK7
153 #if (VTK_MAJOR_VERSION <= 5)
154 mConcat->SetNumberOfScalarComponents(nbComponents);
155 mConcat->SetScalarType(scalarType);
156 mConcat->AllocateScalars();
159 #if (VTK_MAJOR_VERSION >= 6)
160 mConcat->AllocateScalars(scalarType,nbComponents);
166 int scalarSize=bbGetInputIn()[0]->GetScalarSize();
167 char *pImage = (char*)mConcat->GetScalarPointer();
170 //EED int index_lignes, index_colonnes, index_components;
173 for(index_image=0; index_image<nb; index_image++)
175 if (!CheckConsistency(bbGetInputIn()[index_image], dim, nbComponents, scalarType))
177 continue; // discard unconsistent image !
179 bbGetInputIn()[index_image]->GetDimensions(curDim);
180 blocksize = curDim[0]*curDim[1]*curDim[2]*nbComponents*scalarSize;
181 sourcePointer = (char*)bbGetInputIn()[index_image]->GetScalarPointer();
182 memcpy(pImage, sourcePointer,blocksize);
183 pImage = pImage+blocksize;
186 //EED for(index_lignes=0; index_lignes<dim[0];index_lignes++)
188 //EED for(index_colonnes=0; index_colonnes<dim[1];index_colonnes++)
190 //EED for(index_components=0; index_components<nbComponents;index_components++)
192 //EED mConcat->SetScalarComponentFromDouble(index_lignes, index_colonnes, index_image, index_components,(bbGetInputIn()[index_image])->GetScalarComponentAsDouble(index_colonnes,index_lignes,0,index_components));
193 //EED } // components
198 } // if CheckConsistency
199 } /// for index_image
201 // Devrait etre dans bbUserFinalizeProcessing() ? On n'y entre jamais // JPR
202 bbSetOutputOut(mConcat);
205 //---------------------------------------------------
206 bool ConcatImages::CheckConsistency( vtkImageData *curImage, int dim[], int nbComponents, int scalarType )
210 if (scalarType != curImage->GetScalarType( ) )
215 if (nbComponents != curImage->GetNumberOfScalarComponents() )
221 curImage->GetDimensions(curDim);
222 if ( (curDim[0] =! dim[0]) || (curDim[1] =! dim[1]) )