/* * Copyright (c) ICG. All rights reserved. * * Institute for Computer Graphics and Vision * Graz, University of Technology / Austria * * * This software is distributed WITHOUT ANY WARRANTY; without even * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the above copyright notices for more information. * * * Project : projects * Module : MIPItkProjects - CommonItkUtilities * Class : $RCSfile$ * Language : C++ * Description : * * Author : Martin Urschler * EMail : urschler@icg.tu-graz.ac.at * Date : $Date$ * Version : $Revision$ * Full Id : $Id$ * */ #ifndef _RAWDATABUFFERIMPORTER_TXX_ #define _RAWDATABUFFERIMPORTER_TXX_ #include "itkImportImageFilter.h" template< typename TPixelDataType > typename RawDataBufferImporter::ImportImageTypePointer RawDataBufferImporter::import( TPixelDataType * buffer_ptr, int nb_slices, int nb_rows, int nb_colums, float slice_distance, float inplane_voxelsize_x, float inplane_voxelsize_y ) { // image input, let's convert the input image buffer to an itk image // here the image buffer import filter type is defined typedef itk::ImportImageFilter< TPixelDataType, _DIMENSION_ > ImportFilterType; // an instance of the image buffer import filter is created and assigned // to an ITK smart pointer typename ImportFilterType::Pointer importFilter = ImportFilterType::New(); // the size of the image has to be specified typename ImportFilterType::SizeType size; size[0] = nb_colums; // size along X size[1] = nb_rows; // size along Y size[2] = nb_slices; // size along Z // the starting pixel index of the image has to be specified (0,0,0) typename ImportFilterType::IndexType start; start.Fill( 0 ); // size and starting index are combined to form a region typename ImportFilterType::RegionType region; region.SetIndex( start ); region.SetSize( size ); // the region is assigned to the image filter importFilter->SetRegion( region ); // the origin of the output image has to be specified double origin[ _DIMENSION_ ]; origin[0] = 0.0; // X coordinate origin[1] = 0.0; // Y coordinate origin[2] = 0.0; // Z coordinate importFilter->SetOrigin( origin ); // the spacing of the image has to be specified double spacing[ _DIMENSION_ ]; spacing[0] = inplane_voxelsize_x; // along X direction spacing[1] = inplane_voxelsize_y; // along Y direction spacing[2] = slice_distance; // along Z direction importFilter->SetSpacing( spacing ); // The input image buffer is passed to the ImportImageFilter with the // SetImportPointer() method. Note that the last argument of this method // specifies who will be responsible for deleting the memory block once it // is no longer in use. A false value indicates that the ImportImageFilter // will **NOT** try to delete the buffer when its destructor is called!!! // This is exactly what we want! const bool import_image_filter_will_delete_the_buffer = false; const long number_of_pixels = size[0] * size[1] * size[2]; importFilter->SetImportPointer( buffer_ptr, number_of_pixels, import_image_filter_will_delete_the_buffer ); // now execute the pipeline that only consists of a single ImportImageFilter // element to get the image importFilter->Update(); return importFilter->GetOutput(); } template< typename TPixelDataType > typename RawDataBufferImporter::ImportImageTypePointer RawDataBufferImporter::import( TPixelDataType * buffer_ptr, const ImportImageTypePointer& existing_image ) { typedef itk::ImportImageFilter< TPixelDataType, _DIMENSION_ > ImportFilterType; typename ImportFilterType::Pointer importFilter = ImportFilterType::New(); importFilter->SetRegion( existing_image->GetLargestPossibleRegion() ); importFilter->SetSpacing( existing_image->GetSpacing() ); importFilter->SetOrigin( existing_image->GetOrigin() ); typename ImportFilterType::SizeType size = existing_image->GetLargestPossibleRegion().GetSize(); // The input image buffer is passed to the ImportImageFilter with the // SetImportPointer() method. Note that the last argument of this method // specifies who will be responsible for deleting the memory block once it // is no longer in use. A false value indicates that the ImportImageFilter // will **NOT** try to delete the buffer when its destructor is called!!! // This is exactly what we want! const bool import_image_filter_will_delete_the_buffer = false; const long number_of_pixels = size[0] * size[1] * size[2]; importFilter->SetImportPointer( buffer_ptr,number_of_pixels,import_image_filter_will_delete_the_buffer ); // now execute the pipeline that only consists of a single ImportImageFilter // element to get the image importFilter->Update(); return importFilter->GetOutput(); } #endif // _RAWDATABUFFERIMPORTER_TXX_