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 #include "creaVtkUnMosaicVectorVtkImageData.h"
30 creaVtkUnMosaicVectorVtkImageData::creaVtkUnMosaicVectorVtkImageData()
34 creaVtkUnMosaicVectorVtkImageData::~creaVtkUnMosaicVectorVtkImageData()
38 std::vector<vtkImageData*> creaVtkUnMosaicVectorVtkImageData::unMosaicVectorVtkImageData (int NbImagesPerRow, int NbImagesInMosaic, std::vector<vtkImageData*> bbGetInputIn)
40 int nbImagesPerRow = NbImagesPerRow;
41 int nbImagesInMosaic = NbImagesInMosaic;
43 if (nbImagesPerRow == 0 || nbImagesInMosaic == 0) {
44 std::cout << "Not possible" << std::endl;
47 std::vector<vtkImageData*> imageIn = bbGetInputIn;
49 std::vector<vtkImageData*> mImageOut;
50 for (int i = 0 ; i < (unsigned int)imageIn.size() ; i++) {
51 mImageOut.push_back( unMosaic(imageIn[i], NbImagesPerRow, NbImagesInMosaic) );
57 vtkImageData * creaVtkUnMosaicVectorVtkImageData::unMosaic(vtkImageData *imageIn, int nbImagesPerRow, int numberOfImagesInMosaic)
61 imageIn->GetDimensions (inputdims);
62 unsigned short *input = (unsigned short *)(imageIn->GetScalarPointer());
65 unsigned int div = (unsigned int)ceil(sqrt( (double)numberOfImagesInMosaic ) );
66 outputdims[0] = inputdims[0] / div;
67 outputdims[1] = inputdims[1] / div;
68 outputdims[2] = numberOfImagesInMosaic;
70 vtkImageData *vtkImageOut;
71 vtkImageOut = vtkImageData::New();
72 vtkImageOut->SetDimensions( outputdims );
73 vtkImageOut->SetExtent(0,outputdims[0]-1,0,outputdims[1]-1,0,outputdims[2]-1);
74 vtkImageOut->SetWholeExtent(0,outputdims[0]-1,0,outputdims[1]-1,0,outputdims[2]-1);
75 vtkImageOut->SetNumberOfScalarComponents(1);
76 //vtkImageOut->SetSpacing( blabla );
77 vtkImageOut->SetScalarType( VTK_UNSIGNED_SHORT );
78 vtkImageOut->AllocateScalars();
79 vtkImageOut->Update();
81 unsigned short *output =(unsigned short *)(vtkImageOut->GetScalarPointer());
83 unsigned short *dest = output;
84 int dimXImageElem = outputdims[0];
85 int dimYImageElem = outputdims[1];
86 int lgrImage = dimXImageElem*dimYImageElem;
88 for (int i=0; i<numberOfImagesInMosaic; i++)
90 debImage=(i/nbImagesPerRow) * lgrImage*nbImagesPerRow + (i%nbImagesPerRow)*dimXImageElem;
91 for(int j=0; j<dimYImageElem; j++)
93 memcpy(dest, input+debImage, dimXImageElem*sizeof(unsigned short));
94 debImage += dimXImageElem*nbImagesPerRow;
95 dest += dimXImageElem;
101 //---------------------------------------------
103 //---------------------------------------------
105 void creaVtkUnMosaicVectorVtkImageData::FunctionName(int& parameterA)
107 parameterA = 2 * parameterA;