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"
47 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,UnMosaic)
48 BBTK_BLACK_BOX_IMPLEMENTATION(UnMosaic,bbtk::AtomicBlackBox);
50 //---------------------------------------------------------------------
52 void UnMosaic::bbUserSetDefaultValues()
54 //std::cout << "-------- entree ds UnMosaic::bbUserSetDefaultValues()\n" << std::endl;
56 // bbSetInputIn(NULL); /// \TODO fix it! IN is a std::vector<vtkImageData> // JPR
61 //---------------------------------------------------------------------
63 void UnMosaic::bbUserInitializeProcessing()
65 //std::cout << "-------- entree ds UnMosaic::bbUserInitalizeProcessing()\n" << std::endl;
66 //bbUserFinalizeProcessing();
67 mImageOut = vtkImageData::New(); // Alloc depends on bbGetInputIn().size()
70 //---------------------------------------------------------------------
72 void UnMosaic::bbUserFinalizeProcessing()
74 //std::cout << "-------- entree ds UnMosaic::bbUserFinalizeProcessing()\n" << std::endl;
75 // WTF? we never enter here // JPR bbUserFinalizeProcessing() JPR
78 // mImageOut->Delete();
81 bbSetOutputOut(mImageOut);
84 //---------------------------------------------------------------------
87 /// - receives a vtkImageData*imageIn, int nbImagesPerRow, int numberOfImagesInMosaic
88 /// - exports a vtkImageData* as a3D image
89 /// - supposes the input image is a 2D Siemens Mosaic
91 void UnMosaic::Process()
93 int nbImagesPerRow = (unsigned int)bbGetInputNbImagesPerRow();
94 int nbImagesInMosaic = (unsigned int)bbGetInputNbImagesInMosaic();
96 if (nbImagesPerRow == 0 || nbImagesInMosaic == 0) {
97 std::cout << "Go away!" << std::endl; // ??? JPR
101 vtkImageData* imageIn = bbGetInputIn();
103 vtkImageData * mImageOut = unMosaic(imageIn, nbImagesPerRow, nbImagesInMosaic);
105 // Devrait etre dans bbUserFinalizeProcessing() ? // JPR
106 bbSetOutputOut(mImageOut);
110 vtkImageData * UnMosaic::unMosaic(vtkImageData *imageIn, int nbImagesPerRow, int numberOfImagesInMosaic)
114 imageIn->GetDimensions (inputdims);
115 unsigned short *input = (unsigned short *)(imageIn->GetScalarPointer());
117 //EED 2017-01-01 Migration VTK7
118 #if VTK_MAJOR_VERSION <= 5
124 unsigned int div = (unsigned int)ceil(sqrt( (double)numberOfImagesInMosaic ) );
125 outputdims[0] = inputdims[0] / div;
126 outputdims[1] = inputdims[1] / div;
127 outputdims[2] = numberOfImagesInMosaic;
129 vtkImageData *vtkImageOut;
130 vtkImageOut = vtkImageData::New();
131 vtkImageOut->SetDimensions( outputdims );
132 vtkImageOut->SetExtent(0,outputdims[0]-1,0,outputdims[1]-1,0,outputdims[2]-1);
134 //EED 2017-01-01 Migration VTK7
135 #if VTK_MAJOR_VERSION <= 5
136 vtkImageOut->SetWholeExtent(0,outputdims[0]-1,0,outputdims[1]-1,0,outputdims[2]-1);
137 vtkImageOut->SetNumberOfScalarComponents(1);
138 //vtkImageOut->SetSpacing( blabla );
139 vtkImageOut->SetScalarType( VTK_UNSIGNED_SHORT );
140 vtkImageOut->AllocateScalars();
141 vtkImageOut->Update();
143 vtkImageOut->AllocateScalars(VTK_UNSIGNED_SHORT,1);
149 unsigned short *output =(unsigned short *)(vtkImageOut->GetScalarPointer());
151 unsigned short *dest = output;
152 int dimXImageElem = outputdims[0];
153 int dimYImageElem = outputdims[1];
154 int lgrImage = dimXImageElem*dimYImageElem;
156 for (int i=0; i<numberOfImagesInMosaic; i++)
158 debImage=(i/nbImagesPerRow) * lgrImage*nbImagesPerRow + (i%nbImagesPerRow)*dimXImageElem;
159 for(int j=0; j<dimYImageElem; j++)
161 memcpy(dest, input+debImage, dimXImageElem*sizeof(unsigned short));
162 debImage += dimXImageElem*nbImagesPerRow;
163 dest += dimXImageElem;