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 "creaImageIOUnMosaicVtkImageData.h"
35 // ------------------------------------------------------------------------
36 creaImageIOUnMosaicVtkImageData::creaImageIOUnMosaicVtkImageData()
40 // ------------------------------------------------------------------------
41 creaImageIOUnMosaicVtkImageData::~creaImageIOUnMosaicVtkImageData()
45 // ------------------------------------------------------------------------
46 std::vector<vtkImageData*> creaImageIOUnMosaicVtkImageData::unMosaicVectorVtkImageData (std::vector<vtkImageData*> imageInput, std::vector<int> NbImagesInMosaicVector)
48 std::vector<int> nbImagesInMosaic;
50 for(int i = 0; i < NbImagesInMosaicVector.size(); i++)
52 nbImagesInMosaic.push_back(NbImagesInMosaicVector[i]);
55 if(imageInput.size() != NbImagesInMosaicVector.size())
57 for(int j = NbImagesInMosaicVector.size(); j < imageInput.size(); j++)
59 nbImagesInMosaic.push_back( NbImagesInMosaicVector[NbImagesInMosaicVector.size()-1] );
63 if ( nbImagesInMosaic.size()==0 )
65 std::cout << "VtkUnMosaicVectorVtkImageData ERROR: The number of Images by mosaic is not set " << std::endl;
68 std::vector<vtkImageData*> imageIn = imageInput;
70 std::vector<vtkImageData*> mImageOut;
71 for (int i = 0 ; i < (unsigned int)imageIn.size() ; i++)
73 mImageOut.push_back( unMosaic(imageIn[i], nbImagesInMosaic[i]) );
80 // ------------------------------------------------------------------------
81 vtkImageData * creaImageIOUnMosaicVtkImageData::unMosaic(vtkImageData *imageIn, int numberOfImagesInMosaic)
83 int nbImagesPerRow = ceil( sqrt( (double)numberOfImagesInMosaic) );
86 imageIn->GetDimensions (inputdims);
87 unsigned short *input = (unsigned short *)(imageIn->GetScalarPointer());
88 //EED 2017-01-01 Migration VTK7
89 #if VTK_MAJOR_VERSION <= 5
96 unsigned int div = (unsigned int)ceil(sqrt( (double)numberOfImagesInMosaic ) );
97 outputdims[0] = inputdims[0] / div;
98 outputdims[1] = inputdims[1] / div;
99 outputdims[2] = numberOfImagesInMosaic;
101 vtkImageData *vtkImageOut;
102 vtkImageOut = vtkImageData::New();
103 vtkImageOut->SetDimensions( outputdims );
104 vtkImageOut->SetExtent(0,outputdims[0]-1,0,outputdims[1]-1,0,outputdims[2]-1);
106 //EED 2017-01-01 Migration VTK7
107 #if VTK_MAJOR_VERSION <= 5
108 vtkImageOut->SetWholeExtent(0,outputdims[0]-1,0,outputdims[1]-1,0,outputdims[2]-1);
109 vtkImageOut->SetNumberOfScalarComponents(1);
110 //vtkImageOut->SetSpacing( blabla );
111 vtkImageOut->SetScalarType( VTK_UNSIGNED_SHORT );
112 vtkImageOut->AllocateScalars();
113 vtkImageOut->Update();
115 vtkImageOut->AllocateScalars(VTK_UNSIGNED_SHORT,1);
118 unsigned short *output =(unsigned short *)(vtkImageOut->GetScalarPointer());
120 unsigned short *dest = output;
121 int dimXImageElem = outputdims[0];
122 int dimYImageElem = outputdims[1];
123 int lgrImage = dimXImageElem*dimYImageElem;
126 for (i=0; i<numberOfImagesInMosaic; i++)
127 // for (i=numberOfImagesInMosaic-1; i>=0; i--)
129 debImage=(i/nbImagesPerRow) * lgrImage*nbImagesPerRow + (i%nbImagesPerRow)*dimXImageElem;
130 for(j=0; j<dimYImageElem; j++)
131 // for(int j=dimYImageElem-1; j>=0; j--)
133 memcpy(dest, input+debImage, dimXImageElem*sizeof(unsigned short));
134 debImage += dimXImageElem*nbImagesPerRow;
135 dest += dimXImageElem;
142 } // namespace creaImageIO