]> Creatis software - creaImageIO.git/commitdiff
#2458 creaImageIO Feature New Normal - UnMosaic Images SimpleView Gimick
authordavila <eduardo.davila@creatis.insa-lyon.fr>
Mon, 20 Oct 2014 13:33:00 +0000 (15:33 +0200)
committerdavila <eduardo.davila@creatis.insa-lyon.fr>
Mon, 20 Oct 2014 13:33:00 +0000 (15:33 +0200)
src/CMakeLists.txt
src/creaImageIOSimpleView.cpp
src/creaImageIOUnMosaicVtkImageData.cpp [new file with mode: 0644]
src/creaImageIOUnMosaicVtkImageData.h [new file with mode: 0644]

index 90f1ceee4aab9c93767b19c71774491f63966256..c8726b77f03f30233a38bde2a5db6178e02c7f8a 100644 (file)
@@ -89,6 +89,7 @@ ENDIF()
 
 FILE(GLOB SOURCES_CREAIMAGEIO_IMG_READER
          creaImageIOSimpleView.cpp
+         creaImageIOUnMosaicVtkImageData.cpp
          creaImageIOAbstractImageReader.cpp
          creaImageIOImageReader.cpp
          creaImageIOUltrasonixImageReader.cpp
index 96d0e7442bda4713e5f973fc01d1cf9c04df0494..c7a1bd8a929903690a1a35517cd2cc736804a336 100644 (file)
 # ------------------------------------------------------------------------
 */
 
-
-#include "creaImageIOSimpleView.h"
 #include "boost/filesystem/operations.hpp"
 #include "boost/filesystem/fstream.hpp"
 
+#include "creaImageIOSimpleView.h"
+#include "creaImageIOUnMosaicVtkImageData.h"
+
 namespace creaImageIO
 {
        bool SimpleView::readFile(      std::vector<std::string> i_filenames,                                                                   // in information names
@@ -37,6 +38,21 @@ namespace creaImageIO
                                                                                std::vector<std::map <std::string , std::string> > &i_imgAttr,  // out information attributes names-values
                                                                                std::vector<vtkImageData *> &i_img)                                                                     // out information vtkImageData
        {
+printf("EED SimpleView::readFile 0\n");
+
+                 //Mosaic Attribute for Simens         
+                       i_attr.push_back("D0019_100a");  // Number of images in mosaic (Simens)
+                       i_attr.push_back("D0018_0088");  // Spacing Between Slices
+               
+
+
+                       creaImageIOUnMosaicVtkImageData Mosaic;
+                       vtkImageData* tmpImg1;
+                       vtkImageData* tmpImg2;
+                       int numberOfImagesInMosaic;
+                       double spc[3];
+                       double spcZ;
+
                        bool bresult, bfinal = true;
                        ImageReader *mReader = new ImageReader();
                        std::vector<std::string>::iterator it = i_filenames.begin();
@@ -49,15 +65,49 @@ namespace creaImageIO
                                        mReader->getAttributes( (*it).c_str() , mapAttr, i_attr ); //  filename, outMapAttr-NameValue, inVectAttributeName
                                        i_imgAttr.push_back( mapAttr );
 
-                                       //UnMosaic step..
+//EED borrame
+//                                     i_img.push_back( mReader->ReadImage( (*it).c_str() ) );
+
+printf("EED SimpleView::readFile 1\n");
+
+                                       // EED 18 octt 2014
+                                       std::map <std::string , std::string>::iterator itMapAttr;
+                                       std::string numberOfImagesInMosaicStr="";
+                                       std::string spaceBetweenSliceStr="";
+
+                                       itMapAttr = mapAttr.find("D0019_100a");
+                                       if ( itMapAttr!=mapAttr.end() ) numberOfImagesInMosaicStr = itMapAttr->second;
+
+//                                     std::string numberOfImagesInMosaicStr = mapAttr.find("D0019_100a")->second;
+printf("EED SimpleView::readFile 1.1\n");
+                                       itMapAttr = mapAttr.find("D0018_0088");
+                                       if ( itMapAttr!=mapAttr.end() ) spaceBetweenSliceStr = itMapAttr->second;
+
+//                                     std::string spaceBetweenSliceStr = mapAttr.find("D0018_0088")->second;
+printf("EED SimpleView::readFile 1.2\n");
+                                       if (numberOfImagesInMosaicStr=="")
+                                       {
+printf("EED SimpleView::readFile 2\n");
+                                               i_img.push_back( mReader->ReadImage( (*it).c_str() ) );
+                                       } else {
+printf("EED SimpleView::readFile 3\n");
+                                               numberOfImagesInMosaic = atoi(numberOfImagesInMosaicStr.c_str());
+                                               spcZ = atoi(spaceBetweenSliceStr.c_str());
+                                               tmpImg1 = mReader->ReadImage( (*it).c_str() ) ;
+                                               tmpImg1->GetSpacing( spc );     
+                                               tmpImg2 = Mosaic.unMosaic( tmpImg1 , numberOfImagesInMosaic );
+                                               tmpImg2->SetSpacing( spc[0], spc[1], spcZ );    
+                                               i_img.push_back( tmpImg2 );
+                                       }// elemet
 
-                                       i_img.push_back( mReader->ReadImage( (*it).c_str() ) );
                                } else {
                                        printf("ERROR. Impossible to read file %s\n", (*it).c_str() );
                                        bfinal = false;
                                } // if
                        } // for
                        delete mReader;
+printf("EED SimpleView::readFile 4\n");
+
                        return bfinal;  
        }
 
diff --git a/src/creaImageIOUnMosaicVtkImageData.cpp b/src/creaImageIOUnMosaicVtkImageData.cpp
new file mode 100644 (file)
index 0000000..6160106
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+# ---------------------------------------------------------------------
+#
+# 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 "creaImageIOUnMosaicVtkImageData.h"
+#include <math.h>
+
+
+namespace creaImageIO
+{
+
+// ------------------------------------------------------------------------
+creaImageIOUnMosaicVtkImageData::creaImageIOUnMosaicVtkImageData()
+{
+}
+
+// ------------------------------------------------------------------------
+creaImageIOUnMosaicVtkImageData::~creaImageIOUnMosaicVtkImageData()
+{
+}
+
+// ------------------------------------------------------------------------
+std::vector<vtkImageData*> creaImageIOUnMosaicVtkImageData::unMosaicVectorVtkImageData (std::vector<vtkImageData*> imageInput, std::vector<int> NbImagesInMosaicVector)
+{
+       std::vector<int> nbImagesInMosaic;
+
+       for(int i = 0; i < NbImagesInMosaicVector.size(); i++)
+       {
+               nbImagesInMosaic.push_back(NbImagesInMosaicVector[i]);
+       }
+
+       if(imageInput.size() != NbImagesInMosaicVector.size())  
+       {
+               for(int j = NbImagesInMosaicVector.size(); j < imageInput.size(); j++)  
+               {       
+                       nbImagesInMosaic.push_back( NbImagesInMosaicVector[NbImagesInMosaicVector.size()-1] );
+               }
+       }
+       
+       if ( nbImagesInMosaic.size()==0 ) 
+   {
+               std::cout << "VtkUnMosaicVectorVtkImageData ERROR: The number of Images by mosaic is not set " << std::endl; 
+       }
+
+       std::vector<vtkImageData*> imageIn = imageInput;
+
+       std::vector<vtkImageData*> mImageOut;
+       for (int i = 0 ; i < (unsigned int)imageIn.size() ; i++) 
+       {
+                       mImageOut.push_back( unMosaic(imageIn[i], nbImagesInMosaic[i]) );
+       }
+
+       return mImageOut;       
+}
+
+
+// ------------------------------------------------------------------------
+vtkImageData * creaImageIOUnMosaicVtkImageData::unMosaic(vtkImageData *imageIn, int numberOfImagesInMosaic)
+{
+       int nbImagesPerRow = ceil( sqrt(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;
+    int i,j;
+    for (i=0; i<numberOfImagesInMosaic; i++)
+//      for (i=numberOfImagesInMosaic-1; i>=0; i--)
+    {
+       debImage=(i/nbImagesPerRow) * lgrImage*nbImagesPerRow + (i%nbImagesPerRow)*dimXImageElem;
+       for(j=0; j<dimYImageElem; j++)
+//       for(int j=dimYImageElem-1; j>=0; j--)
+       {
+          memcpy(dest, input+debImage, dimXImageElem*sizeof(unsigned short));
+          debImage += dimXImageElem*nbImagesPerRow;
+          dest += dimXImageElem;
+       }
+    }
+    return  vtkImageOut;    
+}
+
+
+} // namespace creaImageIO
+
+
diff --git a/src/creaImageIOUnMosaicVtkImageData.h b/src/creaImageIOUnMosaicVtkImageData.h
new file mode 100644 (file)
index 0000000..bb8e947
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+# ---------------------------------------------------------------------
+#
+# 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.
+# ------------------------------------------------------------------------
+*/
+
+#ifndef _CREAVTKUNMOSAICVECTORVTKIMAGEDATA_H_
+#define _CREAVTKUNMOSAICVECTORVTKIMAGEDATA_H_
+#include <vector>
+#include "iostream"
+#include "vtkImageData.h"
+//---------------------------------------------
+// Class Name: creaVtkUnMosaicVectorVtkImageData
+// [classdescription]
+//---------------------------------------------
+
+
+
+namespace creaImageIO
+{
+
+
+       class creaImageIOUnMosaicVtkImageData   
+       {
+
+       //---------------------------------------------
+       //Methods and attributes exposed to other classes
+       //---------------------------------------------
+       public :
+               creaImageIOUnMosaicVtkImageData();
+               ~creaImageIOUnMosaicVtkImageData();
+               std::vector<vtkImageData*> unMosaicVectorVtkImageData (std::vector<vtkImageData*> bbGetInputIn, std::vector<int> NbImagesInMosaicVector);
+               vtkImageData * unMosaic(vtkImageData *imageIn, int numberOfImagesInMosaic);
+
+               //--Method template----------------------------
+               //  void FunctionName(int& parameterA);
+
+
+               //---------------------------------------------
+               //Methods and attributes exposed only to classes
+               //that are derived from this class
+               //---------------------------------------------
+       protected:
+
+       //---------------------------------------------
+       //Methods and attributes only visible by this class
+       //---------------------------------------------
+       private:
+
+       };
+
+
+} //namespace creaImageIO
+
+
+//-end of _CREAVTKUNMOSAICVECTORVTKIMAGEDATA_H_------------------------------------------------------
+#endif