7 #include "fwVtkIO/vtk.hpp" 8 #include "fwVtkIO/VtiImageReader.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 <vtkSmartPointer.h> 20 #include <vtkXMLImageDataReader.h> 21 #include <vtkImageData.h> 31 ::
fwData::location::enableSingleFile< ::
fwDataIO::reader::IObjectReader >(this),
32 m_job(::
fwJobs::Observer::New(
"Vti image reader"))
53 vtkSmartPointer< vtkXMLImageDataReader > reader = vtkSmartPointer< vtkXMLImageDataReader >::New();
54 reader->SetFileName(this->
getFile().
string().c_str());
57 vtkSmartPointer< vtkLambdaCommand > progressCallback;
59 progressCallback = vtkSmartPointer< vtkLambdaCommand >::New();
60 progressCallback->SetCallback(
61 [&](vtkObject* caller,
long unsigned int,
void*)
63 auto filter =
static_cast<vtkGenericDataObjectReader*
>(caller);
64 m_job->doneWork(filter->GetProgress() * 100);
67 reader->AddObserver(vtkCommand::ProgressEvent, progressCallback);
69 m_job->addSimpleCancelHook([&] { reader->AbortExecuteOn(); });
72 reader->UpdateInformation();
73 reader->PropagateUpdateExtent();
75 vtkDataObject *obj = reader->GetOutput();
76 vtkImageData* img = vtkImageData::SafeDownCast(obj);
80 FW_RAISE_IF(
"VtiImageReader cannot read Vti image file :"<<this->
getFile().
string(), !img);
83 ::fwVtkIO::fromVTKImage( img, pImage);
85 catch( std::exception &e)
87 FW_RAISE(
"VTIImage to fwData::Image failed "<<e.what());
#define SLM_TRACE_FUNC()
Trace contextual function signature.
FWVTKIO_API ~VtiImageReader()
Destructor.
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.
std::shared_ptr< ::fwJobs::IJob > sptr
Cancel request callback type.
FWVTKIO_API void read() override
Reading operator.
FWVTKIO_API std::shared_ptr< ::fwJobs::IJob > getJob() const override
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.
FWVTKIO_API std::string extension() override
FWVTKIO_API VtiImageReader(::fwDataIO::reader::IObjectReader::Key key)
Constructor.
This namespace fwJobs provides jobs management.