7 #include "fwVtkIO/BitmapImageReader.hpp" 9 #include "fwVtkIO/helper/vtkLambdaCommand.hpp" 10 #include "fwVtkIO/vtk.hpp" 12 #include <fwDataIO/reader/registry/macros.hpp> 14 #include <fwJobs/IJob.hpp> 15 #include <fwJobs/Observer.hpp> 17 #include <boost/tokenizer.hpp> 19 #include <vtkGenericDataObjectReader.h> 20 #include <vtkImageData.h> 21 #include <vtkImageReader2.h> 22 #include <vtkImageReader2Collection.h> 23 #include <vtkImageReader2Factory.h> 24 #include <vtkSmartPointer.h> 33 ::
fwData::location::enableSingleFile< ::
fwDataIO::reader::IObjectReader >(this),
34 m_job(::
fwJobs::Observer::New(
"Bitmap image reader"))
37 std::vector<std::string> ext;
42 m_availableExtensions = ext.at(0);
43 for(std::vector<std::string>::size_type i = 1; i < ext.size(); i++)
45 m_availableExtensions = m_availableExtensions +
" " + ext.at(i);
67 vtkSmartPointer<vtkImageReader2Factory>
factory =
68 vtkSmartPointer< vtkImageReader2Factory >::New();
69 vtkSmartPointer<vtkImageReader2> reader =
70 factory->CreateImageReader2( this->
getFile().
string().c_str() );
72 FW_RAISE_IF(
"BitmapImageReader cannot read Bitmap image file :" << this->
getFile().
string(), !reader);
74 reader->SetFileName(this->
getFile().
string().c_str());
77 vtkSmartPointer< vtkLambdaCommand > progressCallback;
79 progressCallback = vtkSmartPointer< vtkLambdaCommand >::New();
80 progressCallback->SetCallback(
81 [&](vtkObject* caller,
long unsigned int,
void*)
83 auto filter =
static_cast<vtkGenericDataObjectReader*
>(caller);
84 m_job->doneWork(static_cast<uint64_t>(filter->GetProgress() * 100.0));
87 reader->AddObserver(vtkCommand::ProgressEvent, progressCallback);
89 m_job->addSimpleCancelHook([&] { reader->AbortExecuteOn(); });
93 vtkDataObject* obj = reader->GetOutput();
94 vtkImageData* img = vtkImageData::SafeDownCast(obj);
98 FW_RAISE_IF(
"BitmapImageReader cannot read Bitmap image file :"<<this->
getFile().
string(), !img);
101 ::fwVtkIO::fromVTKImage( img, pImage);
103 catch( std::exception& e)
105 FW_RAISE(
"BitmapImage to fwData::Image failed "<<e.what());
113 return m_availableExtensions;
128 vtkSmartPointer<vtkImageReader2Collection> ir2c = vtkSmartPointer<vtkImageReader2Collection>::New();
129 vtkImageReader2Factory::GetRegisteredReaders(ir2c);
131 const ::boost::char_separator<char> sep(
" ");
134 ir2c->InitTraversal();
135 for(
int i = 0; i < ir2c->GetNumberOfItems(); i++)
137 vtkImageReader2* ir2 = ir2c->GetNextItem();
140 const std::string s = ir2->GetFileExtensions();
141 const ::boost::tokenizer< ::boost::char_separator<char> > tokens {s, sep};
143 for(
const auto& token : tokens)
145 ext.push_back(token);
static FWVTKIO_API void getAvailableExtensions(std::vector< std::string > &ext)
FWVTKIO_API ~BitmapImageReader()
Destructor.
This namespace fwDataIO contains reader and writer for several framework's data.
::fwTools::Object::wptr m_object
Object result of reading process.
FWVTKIO_API BitmapImageReader(::fwDataIO::reader::IObjectReader::Key key)
Constructor.
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.
Contains fwAtomsFilter::factory utilities.
FWVTKIO_API std::shared_ptr< ::fwJobs::IJob > getJob() const override
FWVTKIO_API std::string extension() override
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
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.
FWVTKIO_API void read() override
Reading operator.