1 /*=========================================================================
3 Module: $RCSfile: bbvtkUnMosaic.cxx,v $
5 Date: $Date: 2011/05/31 09:39:11 $
6 Version: $Revision: 1.3 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
37 #include "bbvtkUnMosaic.h"
38 #include "bbvtkPackage.h"
42 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,UnMosaic)
43 BBTK_BLACK_BOX_IMPLEMENTATION(UnMosaic,bbtk::AtomicBlackBox);
45 //---------------------------------------------------------------------
47 void UnMosaic::bbUserSetDefaultValues()
49 //std::cout << "-------- entree ds UnMosaic::bbUserSetDefaultValues()\n" << std::endl;
51 // bbSetInputIn(NULL); /// \TODO fix it! IN is a std::vector<vtkImageData> // JPR
56 //---------------------------------------------------------------------
58 void UnMosaic::bbUserInitializeProcessing()
60 //std::cout << "-------- entree ds UnMosaic::bbUserInitalizeProcessing()\n" << std::endl;
61 //bbUserFinalizeProcessing();
62 mImageOut = vtkImageData::New(); // Alloc depends on bbGetInputIn().size()
65 //---------------------------------------------------------------------
67 void UnMosaic::bbUserFinalizeProcessing()
69 //std::cout << "-------- entree ds UnMosaic::bbUserFinalizeProcessing()\n" << std::endl;
70 // WTF? we never enter here // JPR bbUserFinalizeProcessing() JPR
73 // mImageOut->Delete();
76 bbSetOutputOut(mImageOut);
79 //---------------------------------------------------------------------
82 /// - receives a vtkImageData*imageIn, int nbImagesPerRow, int numberOfImagesInMosaic
83 /// - exports a vtkImageData* as a3D image
84 /// - supposes the input image is a 2D Siemens Mosaic
86 void UnMosaic::Process()
88 int nbImagesPerRow = (unsigned int)bbGetInputNbImagesPerRow();
89 int nbImagesInMosaic = (unsigned int)bbGetInputNbImagesInMosaic();
91 if (nbImagesPerRow == 0 || nbImagesInMosaic == 0) {
92 std::cout << "Go away!" << std::endl; // ??? JPR
96 vtkImageData* imageIn = bbGetInputIn();
98 vtkImageData * mImageOut = unMosaic(imageIn, nbImagesPerRow, nbImagesInMosaic);
100 // Devrait etre dans bbUserFinalizeProcessing() ? // JPR
101 bbSetOutputOut(mImageOut);
105 vtkImageData * UnMosaic::unMosaic(vtkImageData *imageIn, int nbImagesPerRow, int numberOfImagesInMosaic)
109 imageIn->GetDimensions (inputdims);
110 unsigned short *input = (unsigned short *)(imageIn->GetScalarPointer());
113 unsigned int div = (unsigned int)ceil(sqrt( (double)numberOfImagesInMosaic ) );
114 outputdims[0] = inputdims[0] / div;
115 outputdims[1] = inputdims[1] / div;
116 outputdims[2] = numberOfImagesInMosaic;
118 vtkImageData *vtkImageOut;
119 vtkImageOut = vtkImageData::New();
120 vtkImageOut->SetDimensions( outputdims );
121 vtkImageOut->SetExtent(0,outputdims[0]-1,0,outputdims[1]-1,0,outputdims[2]-1);
122 vtkImageOut->SetWholeExtent(0,outputdims[0]-1,0,outputdims[1]-1,0,outputdims[2]-1);
123 vtkImageOut->SetNumberOfScalarComponents(1);
124 //vtkImageOut->SetSpacing( blabla );
125 vtkImageOut->SetScalarType( VTK_UNSIGNED_SHORT );
126 vtkImageOut->AllocateScalars();
127 vtkImageOut->Update();
129 unsigned short *output =(unsigned short *)(vtkImageOut->GetScalarPointer());
131 unsigned short *dest = output;
132 int dimXImageElem = outputdims[0];
133 int dimYImageElem = outputdims[1];
134 int lgrImage = dimXImageElem*dimYImageElem;
136 for (int i=0; i<numberOfImagesInMosaic; i++)
138 debImage=(i/nbImagesPerRow) * lgrImage*nbImagesPerRow + (i%nbImagesPerRow)*dimXImageElem;
139 for(int j=0; j<dimYImageElem; j++)
141 memcpy(dest, input+debImage, dimXImageElem*sizeof(unsigned short));
142 debImage += dimXImageElem*nbImagesPerRow;
143 dest += dimXImageElem;