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: bbvtkUnMosaic.cxx,v $
32 Date: $Date: 2012/11/16 08:51:58 $
33 Version: $Revision: 1.4 $
34 =========================================================================*/
42 #include "bbvtkUnMosaic.h"
43 #include "bbvtkPackage.h"
48 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,UnMosaic)
49 BBTK_BLACK_BOX_IMPLEMENTATION(UnMosaic,bbtk::AtomicBlackBox);
51 //---------------------------------------------------------------------
53 void UnMosaic::bbUserSetDefaultValues()
55 //std::cout << "-------- entree ds UnMosaic::bbUserSetDefaultValues()\n" << std::endl;
57 // bbSetInputIn(NULL); /// \TODO fix it! IN is a std::vector<vtkImageData> // JPR
62 //---------------------------------------------------------------------
64 void UnMosaic::bbUserInitializeProcessing()
66 //std::cout << "-------- entree ds UnMosaic::bbUserInitalizeProcessing()\n" << std::endl;
67 //bbUserFinalizeProcessing();
68 mImageOut = vtkImageData::New(); // Alloc depends on bbGetInputIn().size()
71 //---------------------------------------------------------------------
73 void UnMosaic::bbUserFinalizeProcessing()
75 //std::cout << "-------- entree ds UnMosaic::bbUserFinalizeProcessing()\n" << std::endl;
76 // WTF? we never enter here // JPR bbUserFinalizeProcessing() JPR
79 // mImageOut->Delete();
82 bbSetOutputOut(mImageOut);
85 //---------------------------------------------------------------------
88 /// - receives a vtkImageData*imageIn, int nbImagesPerRow, int numberOfImagesInMosaic
89 /// - exports a vtkImageData* as a3D image
90 /// - supposes the input image is a 2D Siemens Mosaic
92 void UnMosaic::Process()
94 int nbImagesPerRow = (unsigned int)bbGetInputNbImagesPerRow();
95 int nbImagesInMosaic = (unsigned int)bbGetInputNbImagesInMosaic();
97 if (nbImagesPerRow == 0 || nbImagesInMosaic == 0) {
98 std::cout << "Go away!" << std::endl; // ??? JPR
102 vtkImageData* imageIn = bbGetInputIn();
104 vtkImageData * mImageOut = unMosaic(imageIn, nbImagesPerRow, nbImagesInMosaic);
106 // Devrait etre dans bbUserFinalizeProcessing() ? // JPR
107 bbSetOutputOut(mImageOut);
111 vtkImageData * UnMosaic::unMosaic(vtkImageData *imageIn, int nbImagesPerRow, int numberOfImagesInMosaic)
115 imageIn->GetDimensions (inputdims);
116 unsigned short *input = (unsigned short *)(imageIn->GetScalarPointer());
118 //EED 2017-01-01 Migration VTK7
119 #if VTK_MAJOR_VERSION <= 5
125 unsigned int div = (unsigned int)ceil(sqrt( (double)numberOfImagesInMosaic ) );
126 outputdims[0] = inputdims[0] / div;
127 outputdims[1] = inputdims[1] / div;
128 outputdims[2] = numberOfImagesInMosaic;
130 vtkImageData *vtkImageOut;
131 vtkImageOut = vtkImageData::New();
132 vtkImageOut->SetDimensions( outputdims );
133 vtkImageOut->SetExtent(0,outputdims[0]-1,0,outputdims[1]-1,0,outputdims[2]-1);
135 //EED 2017-01-01 Migration VTK7
136 #if VTK_MAJOR_VERSION <= 5
137 vtkImageOut->SetWholeExtent(0,outputdims[0]-1,0,outputdims[1]-1,0,outputdims[2]-1);
138 vtkImageOut->SetNumberOfScalarComponents(1);
139 //vtkImageOut->SetSpacing( blabla );
140 vtkImageOut->SetScalarType( VTK_UNSIGNED_SHORT );
141 vtkImageOut->AllocateScalars();
142 vtkImageOut->Update();
144 vtkImageOut->AllocateScalars(VTK_UNSIGNED_SHORT,1);
150 unsigned short *output =(unsigned short *)(vtkImageOut->GetScalarPointer());
152 unsigned short *dest = output;
153 int dimXImageElem = outputdims[0];
154 int dimYImageElem = outputdims[1];
155 int lgrImage = dimXImageElem*dimYImageElem;
157 for (int i=0; i<numberOfImagesInMosaic; i++)
159 debImage=(i/nbImagesPerRow) * lgrImage*nbImagesPerRow + (i%nbImagesPerRow)*dimXImageElem;
160 for(int j=0; j<dimYImageElem; j++)
162 memcpy(dest, input+debImage, dimXImageElem*sizeof(unsigned short));
163 debImage += dimXImageElem*nbImagesPerRow;
164 dest += dimXImageElem;