1 /*=========================================================================
3 Module: $RCSfile: bbvtkConcatImages.cxx,v $
5 Date: $Date: 2010/04/28 22:10:07 $
6 Version: $Revision: 1.2 $
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()
92 int nb = (unsigned int)bbGetInputIn().size();
99 bbGetInputIn()[0]->GetDimensions(dim);
100 if (dim[2] > 1 || nb == 1) // dim[2] > 1 : Hopeless for vtk : the first file contains already a 3D object
101 // nb == 1 : only one image, nothing to do.
104 mConcat = bbGetInputIn()[0];
105 //mConcat->PrintSelf(std::cout, vtkIndent(2));
109 // We suppose *all* the images within the directory are consistent (same sizeS, same pixel Type?...)
110 vtkImageData * firstImage = bbGetInputIn()[0];
112 //std::cout << "--------PrintSelf firstImage " << std::endl;
113 // firstImage->PrintSelf(std::cout, vtkIndent(2));
115 nbComponents = firstImage->GetNumberOfScalarComponents();
116 mConcat->SetNumberOfScalarComponents(nbComponents);
118 mConcat->SetScalarType(firstImage->GetScalarType( ));
119 scalarType = firstImage->GetScalarType( );
120 mConcat->SetScalarType(scalarType);
122 mConcat->SetSpacing(firstImage->GetSpacing());
124 firstImage->GetDimensions(dim);
125 // brute way to perform an ultra-mini consistency check :
126 // First image is supposed to be the reference image,
127 // any unconsistent image is just discarted...
128 for(int i=0; i<nb; i++)
130 if ( !CheckConsistency(firstImage, dim, nbComponents, scalarType))
135 mConcat->SetDimensions(dim);
136 mConcat->SetExtent(0, dim[0]-1, 0, dim[1]-1, 0, dim[2]-1);
138 mConcat->AllocateScalars();
141 int index_image, index_lignes, index_colonnes, index_components;
143 for(index_image=0; index_image<nb; index_image++)
145 if (!CheckConsistency(bbGetInputIn()[index_image], dim, nbComponents, scalarType))
146 continue; // discard unconsistent image !
147 for(index_lignes=0; index_lignes<dim[0];index_lignes++)
149 for(index_colonnes=0; index_colonnes<dim[1];index_colonnes++)
151 for(index_components=0; index_components<nbComponents;index_components++)
153 mConcat->SetScalarComponentFromDouble(index_lignes, index_colonnes, index_image, index_components,(bbGetInputIn()[index_image])->GetScalarComponentAsDouble(index_colonnes,index_lignes,0,index_components));
159 // Devrait etre dans bbUserFinalizeProcessing() ? On n'y entre jamais // JPR
160 bbSetOutputOut(mConcat);
163 bool ConcatImages::CheckConsistency( vtkImageData *curImage, int dim[], int nbComponents, int scalarType )
167 if (scalarType != curImage->GetScalarType( ) )
170 if (nbComponents != curImage->GetNumberOfScalarComponents() )
174 curImage->GetDimensions(curDim);
175 if ( (curDim[0] =! dim[0]) || (curDim[1] =! dim[1]) )