From 6b7ccc72c2f9cee3979d9360a55eaa65aeea8a17 Mon Sep 17 00:00:00 2001 From: davila Date: Mon, 20 Oct 2014 15:33:00 +0200 Subject: [PATCH] #2458 creaImageIO Feature New Normal - UnMosaic Images SimpleView Gimick --- src/CMakeLists.txt | 1 + src/creaImageIOSimpleView.cpp | 58 ++++++++++- src/creaImageIOUnMosaicVtkImageData.cpp | 132 ++++++++++++++++++++++++ src/creaImageIOUnMosaicVtkImageData.h | 78 ++++++++++++++ 4 files changed, 265 insertions(+), 4 deletions(-) create mode 100644 src/creaImageIOUnMosaicVtkImageData.cpp create mode 100644 src/creaImageIOUnMosaicVtkImageData.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 90f1cee..c8726b7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -89,6 +89,7 @@ ENDIF() FILE(GLOB SOURCES_CREAIMAGEIO_IMG_READER creaImageIOSimpleView.cpp + creaImageIOUnMosaicVtkImageData.cpp creaImageIOAbstractImageReader.cpp creaImageIOImageReader.cpp creaImageIOUltrasonixImageReader.cpp diff --git a/src/creaImageIOSimpleView.cpp b/src/creaImageIOSimpleView.cpp index 96d0e74..c7a1bd8 100644 --- a/src/creaImageIOSimpleView.cpp +++ b/src/creaImageIOSimpleView.cpp @@ -25,11 +25,12 @@ # ------------------------------------------------------------------------ */ - -#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 i_filenames, // in information names @@ -37,6 +38,21 @@ namespace creaImageIO std::vector > &i_imgAttr, // out information attributes names-values std::vector &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::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 ::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 index 0000000..6160106 --- /dev/null +++ b/src/creaImageIOUnMosaicVtkImageData.cpp @@ -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 + + +namespace creaImageIO +{ + +// ------------------------------------------------------------------------ +creaImageIOUnMosaicVtkImageData::creaImageIOUnMosaicVtkImageData() +{ +} + +// ------------------------------------------------------------------------ +creaImageIOUnMosaicVtkImageData::~creaImageIOUnMosaicVtkImageData() +{ +} + +// ------------------------------------------------------------------------ +std::vector creaImageIOUnMosaicVtkImageData::unMosaicVectorVtkImageData (std::vector imageInput, std::vector NbImagesInMosaicVector) +{ + std::vector 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 imageIn = imageInput; + + std::vector 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=0; i--) + { + debImage=(i/nbImagesPerRow) * lgrImage*nbImagesPerRow + (i%nbImagesPerRow)*dimXImageElem; + for(j=0; 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 index 0000000..bb8e947 --- /dev/null +++ b/src/creaImageIOUnMosaicVtkImageData.h @@ -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 +#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 unMosaicVectorVtkImageData (std::vector bbGetInputIn, std::vector 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 -- 2.44.0