]> Creatis software - creaVtk.git/blob - lib/creaVtk/creaVtkUnMosaicVectorVtkImageData.cpp
2217 creaVtk Support New Normal Correction of Heart Angles Box
[creaVtk.git] / lib / creaVtk / creaVtkUnMosaicVectorVtkImageData.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 #                        pour la Sante)
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
9 #
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.
16 #
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
21 #  liability.
22 #
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 # ------------------------------------------------------------------------
26 */
27
28 #include "creaVtkUnMosaicVectorVtkImageData.h"
29
30 creaVtkUnMosaicVectorVtkImageData::creaVtkUnMosaicVectorVtkImageData()
31 {
32 }
33
34 creaVtkUnMosaicVectorVtkImageData::~creaVtkUnMosaicVectorVtkImageData()
35 {
36 }
37
38 std::vector<vtkImageData*> creaVtkUnMosaicVectorVtkImageData::unMosaicVectorVtkImageData (int NbImagesPerRow, int NbImagesInMosaic, std::vector<vtkImageData*> bbGetInputIn)
39 {
40         int nbImagesPerRow =   NbImagesPerRow;
41         int nbImagesInMosaic = NbImagesInMosaic;        
42
43         if (nbImagesPerRow == 0 || nbImagesInMosaic == 0) 
44         {
45                 std::cout << "VtkUnMosaicVectorVtkImageData ERROR: The number of Images by mosaic is not set " << std::endl; 
46         }
47
48         std::vector<vtkImageData*> imageIn = bbGetInputIn;
49
50         std::vector<vtkImageData*> mImageOut;
51         for (int i = 0 ; i < (unsigned int)imageIn.size() ; i++) {
52                         mImageOut.push_back( unMosaic(imageIn[i], NbImagesPerRow, NbImagesInMosaic) );
53         }
54
55         return mImageOut;       
56 }
57
58 vtkImageData * creaVtkUnMosaicVectorVtkImageData::unMosaic(vtkImageData *imageIn, int nbImagesPerRow, int numberOfImagesInMosaic)
59 {   
60    int inputdims[3];
61    int outputdims[3];
62    imageIn->GetDimensions (inputdims);
63    unsigned short *input = (unsigned short *)(imageIn->GetScalarPointer());
64    imageIn->Update();
65      
66    unsigned int div = (unsigned int)ceil(sqrt( (double)numberOfImagesInMosaic ) );
67    outputdims[0] = inputdims[0] / div;
68    outputdims[1] = inputdims[1] / div;
69    outputdims[2] = numberOfImagesInMosaic;
70  
71     vtkImageData *vtkImageOut;
72     vtkImageOut = vtkImageData::New();
73     vtkImageOut->SetDimensions( outputdims );
74     vtkImageOut->SetExtent(0,outputdims[0]-1,0,outputdims[1]-1,0,outputdims[2]-1);
75     vtkImageOut->SetWholeExtent(0,outputdims[0]-1,0,outputdims[1]-1,0,outputdims[2]-1);
76     vtkImageOut->SetNumberOfScalarComponents(1);
77 //vtkImageOut->SetSpacing( blabla );
78     vtkImageOut->SetScalarType( VTK_UNSIGNED_SHORT );
79     vtkImageOut->AllocateScalars();
80     vtkImageOut->Update();
81     
82     unsigned short *output =(unsigned short *)(vtkImageOut->GetScalarPointer());
83
84     unsigned short *dest = output;
85     int dimXImageElem = outputdims[0];
86     int dimYImageElem = outputdims[1];
87     int lgrImage = dimXImageElem*dimYImageElem;
88     int debImage;
89     int i,j;
90 //    for (i=0; i<numberOfImagesInMosaic; i++)
91       for (i=numberOfImagesInMosaic-1; i>=0; i--)
92     {
93        debImage=(i/nbImagesPerRow) * lgrImage*nbImagesPerRow + (i%nbImagesPerRow)*dimXImageElem;
94        for(j=0; j<dimYImageElem; j++)
95 //       for(int j=dimYImageElem-1; j>=0; j--)
96        {
97           memcpy(dest, input+debImage, dimXImageElem*sizeof(unsigned short));
98           debImage += dimXImageElem*nbImagesPerRow;
99           dest += dimXImageElem;
100        }
101     }
102     return  vtkImageOut;    
103 }
104
105 //---------------------------------------------
106 //Method template
107 //---------------------------------------------
108 /*
109 void creaVtkUnMosaicVectorVtkImageData::FunctionName(int& parameterA)
110 {
111   parameterA = 2 * parameterA;
112   return;
113 }
114 */