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 #define _USE_MATH_DEFINES // for C
33 creaVtkUnMosaicVectorVtkImageData::creaVtkUnMosaicVectorVtkImageData()
37 creaVtkUnMosaicVectorVtkImageData::~creaVtkUnMosaicVectorVtkImageData()
41 std::vector<vtkImageData*> creaVtkUnMosaicVectorVtkImageData::unMosaicVectorVtkImageData (std::vector<vtkImageData*> imageInput, std::vector<int> NbImagesInMosaicVector)
43 std::vector<int> nbImagesPerRow;
44 std::vector<int> nbImagesInMosaic;
45 double imagesInMosaic;
47 for(int i = 0; i < NbImagesInMosaicVector.size(); i++)
49 imagesInMosaic = NbImagesInMosaicVector[i];
50 nbImagesPerRow.push_back( ceil(sqrt(imagesInMosaic)) );
51 nbImagesInMosaic.push_back(NbImagesInMosaicVector[i]);
54 if(imageInput.size() != NbImagesInMosaicVector.size())
56 for(int j = NbImagesInMosaicVector.size(); j < imageInput.size(); j++)
58 imagesInMosaic = NbImagesInMosaicVector[NbImagesInMosaicVector.size()-1];
59 nbImagesPerRow.push_back( ceil(sqrt(imagesInMosaic)) );
60 nbImagesInMosaic.push_back( NbImagesInMosaicVector[NbImagesInMosaicVector.size()-1] );
64 if (nbImagesPerRow.size() == 0 || nbImagesInMosaic.size() == 0)
66 std::cout << "VtkUnMosaicVectorVtkImageData ERROR: The number of Images by mosaic is not set " << std::endl;
69 std::vector<vtkImageData*> imageIn = imageInput;
71 std::vector<vtkImageData*> mImageOut;
72 for (int i = 0 ; i < (unsigned int)imageIn.size() ; i++) {
73 mImageOut.push_back( unMosaic(imageIn[i], nbImagesPerRow[i], nbImagesInMosaic[i]) );
79 vtkImageData * creaVtkUnMosaicVectorVtkImageData::unMosaic(vtkImageData *imageIn, int nbImagesPerRow, int numberOfImagesInMosaic)
83 imageIn->GetDimensions (inputdims);
84 unsigned short *input = (unsigned short *)(imageIn->GetScalarPointer());
86 //EED 2017-01-01 Migration VTK7
87 #if VTK_MAJOR_VERSION <= 5
93 unsigned int div = (unsigned int)ceil(sqrt( (double)numberOfImagesInMosaic ) );
94 outputdims[0] = inputdims[0] / div;
95 outputdims[1] = inputdims[1] / div;
96 outputdims[2] = numberOfImagesInMosaic;
98 vtkImageData *vtkImageOut;
99 vtkImageOut = vtkImageData::New();
100 vtkImageOut->SetDimensions( outputdims );
101 vtkImageOut->SetExtent(0,outputdims[0]-1,0,outputdims[1]-1,0,outputdims[2]-1);
103 //EED 2017-01-01 Migration VTK7
104 #if VTK_MAJOR_VERSION <= 5
105 vtkImageOut->SetWholeExtent(0,outputdims[0]-1,0,outputdims[1]-1,0,outputdims[2]-1);
106 vtkImageOut->SetNumberOfScalarComponents(1);
107 //vtkImageOut->SetSpacing( blabla );
108 vtkImageOut->SetScalarType( VTK_UNSIGNED_SHORT );
109 vtkImageOut->AllocateScalars();
110 vtkImageOut->Update();
112 vtkImageOut->AllocateScalars(VTK_UNSIGNED_SHORT,1);
116 unsigned short *output =(unsigned short *)(vtkImageOut->GetScalarPointer());
118 unsigned short *dest = output;
119 int dimXImageElem = outputdims[0];
120 int dimYImageElem = outputdims[1];
121 int lgrImage = dimXImageElem*dimYImageElem;
124 // for (i=0; i<numberOfImagesInMosaic; i++)
125 for (i=numberOfImagesInMosaic-1; i>=0; i--)
127 debImage=(i/nbImagesPerRow) * lgrImage*nbImagesPerRow + (i%nbImagesPerRow)*dimXImageElem;
128 for(j=0; j<dimYImageElem; j++)
129 // for(int j=dimYImageElem-1; j>=0; j--)
131 memcpy(dest, input+debImage, dimXImageElem*sizeof(unsigned short));
132 debImage += dimXImageElem*nbImagesPerRow;
133 dest += dimXImageElem;
139 //---------------------------------------------
141 //---------------------------------------------
143 void creaVtkUnMosaicVectorVtkImageData::FunctionName(int& parameterA)
145 parameterA = 2 * parameterA;