From: ctorres Date: Tue, 26 Nov 2013 14:44:48 +0000 (+0100) Subject: 2187 BBTK Feature New Normal New feature creaVtk X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=c5da7c2dc598a5d8ab3e1945630113a0d3de0968;p=creaVtk.git 2187 BBTK Feature New Normal New feature creaVtk --- diff --git a/lib/creaVtk/creaVtkUnMosaicVectorVtkImageData.cpp b/lib/creaVtk/creaVtkUnMosaicVectorVtkImageData.cpp new file mode 100644 index 0000000..2392af9 --- /dev/null +++ b/lib/creaVtk/creaVtkUnMosaicVectorVtkImageData.cpp @@ -0,0 +1,110 @@ +/* +# --------------------------------------------------------------------- +# +# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image +# pour la Sante) +# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton +# Previous Authors : Laurent Guigues, Jean-Pierre Roux +# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil +# +# This software is governed by the CeCILL-B license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL-B +# license as circulated by CEA, CNRS and INRIA at the following URL +# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +# or in the file LICENSE.txt. +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL-B license and that you accept its terms. +# ------------------------------------------------------------------------ +*/ + +#include "creaVtkUnMosaicVectorVtkImageData.h" + +creaVtkUnMosaicVectorVtkImageData::creaVtkUnMosaicVectorVtkImageData() +{ +} + +creaVtkUnMosaicVectorVtkImageData::~creaVtkUnMosaicVectorVtkImageData() +{ +} + +std::vector creaVtkUnMosaicVectorVtkImageData::unMosaicVectorVtkImageData (int NbImagesPerRow, int NbImagesInMosaic, std::vector bbGetInputIn) +{ + int nbImagesPerRow = NbImagesPerRow; + int nbImagesInMosaic = NbImagesInMosaic; + + if (nbImagesPerRow == 0 || nbImagesInMosaic == 0) { + std::cout << "Not possible" << std::endl; + } + + std::vector imageIn = bbGetInputIn; + + std::vector mImageOut; + for (int i = 0 ; i < (unsigned int)imageIn.size() ; i++) { + mImageOut.push_back( unMosaic(imageIn[i], NbImagesPerRow, NbImagesInMosaic) ); + } + + return mImageOut; +} + +vtkImageData * creaVtkUnMosaicVectorVtkImageData::unMosaic(vtkImageData *imageIn, int nbImagesPerRow, int numberOfImagesInMosaic) +{ + int inputdims[3]; + int outputdims[3]; + imageIn->GetDimensions (inputdims); + unsigned short *input = (unsigned short *)(imageIn->GetScalarPointer()); + imageIn->Update(); + + unsigned int div = (unsigned int)ceil(sqrt( (double)numberOfImagesInMosaic ) ); + outputdims[0] = inputdims[0] / div; + outputdims[1] = inputdims[1] / div; + outputdims[2] = numberOfImagesInMosaic; + + vtkImageData *vtkImageOut; + vtkImageOut = vtkImageData::New(); + vtkImageOut->SetDimensions( outputdims ); + vtkImageOut->SetExtent(0,outputdims[0]-1,0,outputdims[1]-1,0,outputdims[2]-1); + vtkImageOut->SetWholeExtent(0,outputdims[0]-1,0,outputdims[1]-1,0,outputdims[2]-1); + vtkImageOut->SetNumberOfScalarComponents(1); +//vtkImageOut->SetSpacing( blabla ); + vtkImageOut->SetScalarType( VTK_UNSIGNED_SHORT ); + vtkImageOut->AllocateScalars(); + vtkImageOut->Update(); + + unsigned short *output =(unsigned short *)(vtkImageOut->GetScalarPointer()); + + unsigned short *dest = output; + int dimXImageElem = outputdims[0]; + int dimYImageElem = outputdims[1]; + int lgrImage = dimXImageElem*dimYImageElem; + int debImage; + for (int i=0; i