7 #include "fwVtkIO/ImageWriter.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/Observer.hpp> 18 #include <vtkGenericDataObjectWriter.h> 19 #include <vtkImageData.h> 20 #include <vtkSmartPointer.h> 29 ::
fwData::location::enableSingleFile< ::
fwDataIO::writer::IObjectWriter >(this),
30 m_job(::
fwJobs::Observer::New(
"VTK Image Writer"))
53 vtkSmartPointer< vtkGenericDataObjectWriter > writer = vtkSmartPointer< vtkGenericDataObjectWriter >::New();
54 vtkSmartPointer< vtkImageData > vtkImage = vtkSmartPointer< vtkImageData >::New();
55 ::fwVtkIO::toVTKImage( pImage, vtkImage );
56 writer->SetInputData( vtkImage );
57 writer->SetFileName(this->
getFile().
string().c_str());
58 writer->SetFileTypeToBinary();
60 vtkSmartPointer<vtkLambdaCommand> progressCallback;
61 progressCallback = vtkSmartPointer<vtkLambdaCommand>::New();
62 progressCallback->SetCallback([
this](vtkObject* caller,
long unsigned int,
void* )
64 auto filter =
static_cast<vtkGenericDataObjectWriter*
>(caller);
65 m_job->doneWork( filter->GetProgress()*100 );
68 writer->AddObserver(vtkCommand::ProgressEvent, progressCallback);
69 m_job->addSimpleCancelHook( [&]()
71 writer->AbortExecuteOn();
FWVTKIO_API void write() override
Writing operator.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
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.
FWVTKIO_API ~ImageWriter()
Destructor.
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::string extension() override
FWVTKIO_API std::shared_ptr< ::fwJobs::IJob > getJob() const override
ILocation::PathType getFile()
Get file system path.
Contains the representation of the data objects used in the framework.
FWVTKIO_API ImageWriter(::fwDataIO::writer::IObjectWriter::Key key)
Constructor.
This namespace fwJobs provides jobs management.