Commit 2a646de3 authored by arnaud.charnoz@gmail.com's avatar arnaud.charnoz@gmail.com
Browse files

Add a new reader writer for fxz data to save image in vti image in fxz ( and not vtk iamge)

--HG--
branch : fw4spl_0.6.0
parent f5f9d790
/* ***** BEGIN LICENSE BLOCK *****
* FW4SPL - Copyright (C) IRCAD, 2009-2010.
* Distributed under the terms of the GNU Lesser General Public License (LGPL) as
* published by the Free Software Foundation.
* ****** END LICENSE BLOCK ****** */
#ifndef _VTKIO_VTIIMAGEREADER_HPP_
#define _VTKIO_VTIIMAGEREADER_HPP_
#include <boost/filesystem/path.hpp>
#include <vtkActor.h>
#include <fwDataIO/reader/GenericObjectReader.hpp>
#include <fwData/location/SingleFile.hpp>
#include <fwTools/ProgressAdviser.hpp>
#include <fwData/Image.hpp>
#include "vtkIO/config.hpp"
namespace vtkIO
{
/**
* @brief Read an image.
* @class VtiImageReader.
* @author IRCAD (Research and Development Team).
* @date 2009.
*
* Read a VTK Image using the VTK lib
*/
class VtiImageReader : public ::fwDataIO::reader::GenericObjectReader< ::fwData::Image >,
public ::fwData::location::enableSingleFile< ::fwDataIO::reader::IObjectReader >,
public ::fwTools::ProgressAdviser
{
public :
fwCoreClassDefinitionsWithFactoryMacro( (VtiImageReader)( ::fwDataIO::reader::GenericObjectReader< ::fwData::Image >::Baseclass),
(()),
new VtiImageReader
);
//! @brief Constructor.
VTKIO_API VtiImageReader();
//! @brief Destructor.
VTKIO_API ~VtiImageReader();
//! @brief Reading operator.
VTKIO_API void read();
/// @return ".vtk"
VTKIO_API std::string extension();
};
} // namespace vtkIO
#endif // _VTKIO_VTIIMAGEREADER_HPP_
/* ***** BEGIN LICENSE BLOCK *****
* FW4SPL - Copyright (C) IRCAD, 2009-2010.
* Distributed under the terms of the GNU Lesser General Public License (LGPL) as
* published by the Free Software Foundation.
* ****** END LICENSE BLOCK ****** */
#ifndef _VTKIO_VTIIMAGEWRITER_HPP_
#define _VTKIO_VTIIMAGEWRITER_HPP_
#include <boost/filesystem/path.hpp>
#include <vtkActor.h>
#include <fwDataIO/writer/GenericObjectWriter.hpp>
#include <fwData/location/SingleFile.hpp>
#include <fwTools/ProgressAdviser.hpp>
#include <fwData/Image.hpp>
#include "vtkIO/config.hpp"
namespace vtkIO
{
/**
* @brief Write an image.
* @class VtiImageWriter.
* @author IRCAD (Research and Development Team).
* @date 2009.
*
* Write a VTK Image using the VTK lib
*/
class VtiImageWriter : public ::fwDataIO::writer::GenericObjectWriter< ::fwData::Image >,
public ::fwData::location::enableSingleFile< ::fwDataIO::writer::IObjectWriter >,
public ::fwTools::ProgressAdviser
{
public :
fwCoreClassDefinitionsWithFactoryMacro( (VtiImageWriter)( ::fwDataIO::writer::GenericObjectWriter< ::fwData::Image >::Baseclass),
(()),
new VtiImageWriter
);
//! @brief Constructor.
VTKIO_API VtiImageWriter();
//! @brief Destructor.
VTKIO_API ~VtiImageWriter();
//! @brief Writing operator.
VTKIO_API void write();
/// @return ".vti"
VTKIO_API std::string extension();
};
} // namespace vtkIO
#endif // _VTKIO_VTIIMAGEWRITER_HPP_
/* ***** BEGIN LICENSE BLOCK *****
* FW4SPL - Copyright (C) IRCAD, 2009-2010.
* Distributed under the terms of the GNU Lesser General Public License (LGPL) as
* published by the Free Software Foundation.
* ****** END LICENSE BLOCK ****** */
#include <vtkXMLImageDataReader.h>
#include <vtkImageData.h>
#include <fwTools/ClassRegistrar.hpp>
#include <fwCore/base.hpp>
#include "vtkIO/vtk.hpp"
#include "vtkIO/VtiImageReader.hpp"
REGISTER_BINDING_BYCLASSNAME( ::fwDataIO::reader::IObjectReader , ::vtkIO::VtiImageReader, ::vtkIO::VtiImageReader );
namespace vtkIO
{
//------------------------------------------------------------------------------
VtiImageReader::VtiImageReader()
: ::fwData::location::enableSingleFile< ::fwDataIO::reader::IObjectReader >(this)
{
SLM_TRACE("vtkIO::VtiImageReader::VtiImageReader");
}
//------------------------------------------------------------------------------
VtiImageReader::~VtiImageReader()
{
SLM_TRACE("vtkIO::VtiImageReader::~VtiImageReader");
}
//------------------------------------------------------------------------------
void VtiImageReader::read()
{
assert( m_object.use_count() );
assert( !m_object.expired() );
assert( m_object.lock() );
::fwData::Image::sptr pImage = getConcreteObject();
vtkXMLImageDataReader * reader = vtkXMLImageDataReader::New();
reader->SetFileName(this->getFile().string().c_str());
reader->Update();
vtkDataObject *obj = reader->GetOutput();
vtkImageData* img = vtkImageData::SafeDownCast(obj);
if(img)
{
::vtkIO::fromVTKImage(img, pImage);
}
else
{
std::string errMsg;
errMsg = "VtiImageReader cannot read Vti image file : ";
errMsg.append( this->getFile().string() );
throw( errMsg );
}
reader->Delete();
}
//------------------------------------------------------------------------------
std::string VtiImageReader::extension()
{
return ".vti";
}
} // namespace vtkIO
/* ***** BEGIN LICENSE BLOCK *****
* FW4SPL - Copyright (C) IRCAD, 2009-2010.
* Distributed under the terms of the GNU Lesser General Public License (LGPL) as
* published by the Free Software Foundation.
* ****** END LICENSE BLOCK ****** */
#include <vtkImageData.h>
#include <vtkXMLImageDataWriter.h>
#include <vtkZLibDataCompressor.h>
#include <fwTools/ClassRegistrar.hpp>
#include <fwCore/base.hpp>
#include "vtkIO/vtk.hpp"
#include "vtkIO/VtiImageWriter.hpp"
REGISTER_BINDING_BYCLASSNAME( ::fwDataIO::writer::IObjectWriter , ::vtkIO::VtiImageWriter, ::vtkIO::VtiImageWriter );
namespace vtkIO
{
//------------------------------------------------------------------------------
VtiImageWriter::VtiImageWriter() : ::fwData::location::enableSingleFile< ::fwDataIO::writer::IObjectWriter >(this)
{
SLM_TRACE("vtkIO::VtiImageWriter::VtiImageWriter");
}
//------------------------------------------------------------------------------
VtiImageWriter::~VtiImageWriter()
{
SLM_TRACE("vtkIO::VtiImageWriter::~VtiImageWriter");
}
//------------------------------------------------------------------------------
void VtiImageWriter::write()
{
assert( m_object.use_count() );
assert( !m_object.expired() );
assert( m_object.lock() );
::fwData::Image::sptr pImage = getConcreteObject();
vtkXMLImageDataWriter * writer = vtkXMLImageDataWriter::New();
writer->SetInput( ::vtkIO::toVTKImage( pImage ) );
writer->SetFileName( this->getFile().string().c_str() );
writer->SetDataModeToAppended();
vtkZLibDataCompressor* compressor = vtkZLibDataCompressor::New();
compressor->SetCompressionLevel(1);
writer->SetCompressor( compressor );
writer->EncodeAppendedDataOff();
writer->Write();
compressor->Delete();
writer->Delete();
}
//------------------------------------------------------------------------------
std::string VtiImageWriter::extension()
{
return ".vti";
}
} // namespace vtkIO
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment