7 #include "fwVtkIO/vtk.hpp" 8 #include "fwVtkIO/ImageReader.hpp" 9 #include "fwVtkIO/helper/vtkLambdaCommand.hpp" 11 #include <fwCore/base.hpp> 13 #include <fwDataIO/reader/registry/macros.hpp> 15 #include <fwJobs/IJob.hpp> 16 #include <fwJobs/Observer.hpp> 18 #include <vtkGenericDataObjectReader.h> 19 #include <vtkImageData.h> 20 #include <vtkSmartPointer.h> 30 ::
fwData::location::enableSingleFile< ::
fwDataIO::reader::IObjectReader >(this),
31 m_job(::
fwJobs::Observer::New(
"VTK Image reader"))
54 vtkSmartPointer< vtkGenericDataObjectReader > reader = vtkSmartPointer< vtkGenericDataObjectReader >::New();
55 reader->SetFileName(this->
getFile().
string().c_str());
57 vtkSmartPointer<vtkLambdaCommand> progressCallback;
58 progressCallback = vtkSmartPointer<vtkLambdaCommand>::New();
59 progressCallback->SetCallback(
60 [
this](vtkObject* caller,
long unsigned int,
void* )
62 auto filter =
static_cast<vtkGenericDataObjectReader*
>(caller);
63 m_job->doneWork( filter->GetProgress()*100 );
66 reader->AddObserver(vtkCommand::ProgressEvent, progressCallback);
69 m_job->addSimpleCancelHook( [&]()
71 reader->AbortExecuteOn();
75 reader->UpdateInformation();
76 reader->PropagateUpdateExtent();
78 vtkDataObject *obj = reader->GetOutput();
79 vtkImageData* img = vtkImageData::SafeDownCast(obj);
83 FW_RAISE_IF(
"ImageReader cannot read VTK image file :"<<this->
getFile().
string(), !img);
86 ::fwVtkIO::fromVTKImage( img, pImage);
88 catch( std::exception &e)
90 FW_RAISE(
"VTKImage to fwData::Image failed "<<e.what());
FWVTKIO_API std::shared_ptr< ::fwJobs::IJob > getJob() const override
FWVTKIO_API ImageReader(::fwDataIO::reader::IObjectReader::Key key)
Constructor.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
This namespace fwDataIO contains reader and writer for several framework's data.
::fwTools::Object::wptr m_object
Object result of reading process.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
FWVTKIO_API std::string extension() override
std::shared_ptr< ::fwJobs::IJob > sptr
Cancel request callback type.
FWVTKIO_API ~ImageReader()
Destructor.
FWVTKIO_API void read() override
Reading operator.
virtual std::shared_ptr< DataType > getConcreteObject()
m_object getter.
ILocation::PathType getFile()
Get file system path.
Contains the representation of the data objects used in the framework.
This namespace fwJobs provides jobs management.