7 #include "fwVtkIO/VtiImageWriter.hpp" 9 #include "fwVtkIO/helper/vtkLambdaCommand.hpp" 10 #include "fwVtkIO/vtk.hpp" 12 #include <fwCore/base.hpp> 14 #include <fwDataIO/writer/registry/macros.hpp> 16 #include <fwJobs/IJob.hpp> 17 #include <fwJobs/Observer.hpp> 19 #include <vtkImageData.h> 20 #include <vtkSmartPointer.h> 21 #include <vtkXMLImageDataWriter.h> 22 #include <vtkZLibDataCompressor.h> 31 ::
fwData::location::enableSingleFile< ::
fwDataIO::writer::IObjectWriter >(this),
32 m_job(::
fwJobs::Observer::New(
"VTK Image Writer"))
55 vtkSmartPointer< vtkXMLImageDataWriter > writer = vtkSmartPointer< vtkXMLImageDataWriter >::New();
56 vtkSmartPointer< vtkImageData > vtkImage = vtkSmartPointer< vtkImageData >::New();
57 ::fwVtkIO::toVTKImage( pImage, vtkImage );
58 writer->SetInputData( vtkImage );
59 writer->SetFileName( this->
getFile().
string().c_str() );
60 writer->SetDataModeToAppended();
62 vtkSmartPointer< vtkZLibDataCompressor > compressor = vtkSmartPointer< vtkZLibDataCompressor >::New();
63 compressor->SetCompressionLevel(1);
64 writer->SetCompressor( compressor );
65 writer->EncodeAppendedDataOff();
67 vtkSmartPointer<vtkLambdaCommand> progressCallback;
68 progressCallback = vtkSmartPointer<vtkLambdaCommand>::New();
69 progressCallback->SetCallback([
this](vtkObject* caller,
long unsigned int,
void* )
71 auto filter =
static_cast<vtkXMLImageDataWriter*
>(caller);
72 m_job->doneWork( filter->GetProgress()*100 );
75 writer->AddObserver(vtkCommand::ProgressEvent, progressCallback);
76 m_job->addSimpleCancelHook( [&]()
78 writer->AbortExecuteOn();
#define SLM_TRACE_FUNC()
Trace contextual function signature.
FWVTKIO_API void write() override
Writing operator.
This namespace fwDataIO contains reader and writer for several framework's data.
::fwTools::Object::cwptr m_object
Object write on filesystem by the process.
virtual std::shared_ptr< const DataType > getConcreteObject() const
m_object getter.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
std::shared_ptr< ::fwJobs::IJob > sptr
Cancel request callback type.
FWVTKIO_API std::shared_ptr< ::fwJobs::IJob > getJob() const override
FWVTKIO_API ~VtiImageWriter()
Destructor.
FWVTKIO_API VtiImageWriter(::fwDataIO::writer::IObjectWriter::Key key)
Constructor.
ILocation::PathType getFile()
Get file system path.
FWVTKIO_API std::string extension() override
Contains the representation of the data objects used in the framework.
This namespace fwJobs provides jobs management.