]> Creatis software - creaVtk.git/commitdiff
2187 BBTK Feature New Normal New feature creaVtk
authorctorres <carlos.torres@creatis.insa-lyon.fr>
Tue, 26 Nov 2013 14:44:48 +0000 (15:44 +0100)
committerctorres <carlos.torres@creatis.insa-lyon.fr>
Tue, 26 Nov 2013 14:44:48 +0000 (15:44 +0100)
lib/creaVtk/creaVtkUnMosaicVectorVtkImageData.cpp [new file with mode: 0644]

diff --git a/lib/creaVtk/creaVtkUnMosaicVectorVtkImageData.cpp b/lib/creaVtk/creaVtkUnMosaicVectorVtkImageData.cpp
new file mode 100644 (file)
index 0000000..2392af9
--- /dev/null
@@ -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<vtkImageData*> creaVtkUnMosaicVectorVtkImageData::unMosaicVectorVtkImageData (int NbImagesPerRow, int NbImagesInMosaic, std::vector<vtkImageData*> bbGetInputIn)
+{
+       int nbImagesPerRow =   NbImagesPerRow;
+       int nbImagesInMosaic = NbImagesInMosaic;        
+
+  if (nbImagesPerRow == 0 || nbImagesInMosaic == 0) {
+               std::cout << "Not possible" << std::endl; 
+       }
+
+       std::vector<vtkImageData*> imageIn = bbGetInputIn;
+
+       std::vector<vtkImageData*> 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<numberOfImagesInMosaic; i++)
+    {
+       debImage=(i/nbImagesPerRow) * lgrImage*nbImagesPerRow + (i%nbImagesPerRow)*dimXImageElem;
+       for(int j=0; j<dimYImageElem; j++)
+       {
+          memcpy(dest, input+debImage, dimXImageElem*sizeof(unsigned short));
+          debImage += dimXImageElem*nbImagesPerRow;
+          dest += dimXImageElem;
+       }
+    }
+    return  vtkImageOut;    
+}
+
+//---------------------------------------------
+//Method template
+//---------------------------------------------
+/*
+void creaVtkUnMosaicVectorVtkImageData::FunctionName(int& parameterA)
+{
+  parameterA = 2 * parameterA;
+  return;
+}
+*/