7 #include "ioVTK/SImageReader.hpp" 9 #include <fwCom/HasSignals.hpp> 10 #include <fwCom/Signal.hpp> 11 #include <fwCom/Signal.hxx> 13 #include <fwCore/base.hpp> 15 #include <fwData/Image.hpp> 16 #include <fwData/location/Folder.hpp> 17 #include <fwData/mt/ObjectWriteLock.hpp> 19 #include <fwDataIO/reader/IObjectReader.hpp> 21 #include <fwGui/Cursor.hpp> 22 #include <fwGui/dialog/LocationDialog.hpp> 23 #include <fwGui/dialog/MessageDialog.hpp> 25 #include <fwIO/IReader.hpp> 27 #include <fwJobs/Aggregator.hpp> 28 #include <fwJobs/IJob.hpp> 29 #include <fwJobs/Job.hpp> 31 #include <fwServices/macros.hpp> 32 #include <fwServices/registry/ActiveWorkers.hpp> 34 #include <fwVtkIO/BitmapImageReader.hpp> 35 #include <fwVtkIO/ImageReader.hpp> 36 #include <fwVtkIO/MetaImageReader.hpp> 37 #include <fwVtkIO/VtiImageReader.hpp> 39 #include <boost/algorithm/string.hpp> 40 #include <boost/filesystem/operations.hpp> 41 #include <boost/filesystem/path.hpp> 55 static const ::fwCom::Signals::SignalKeyType JOB_CREATED_SIGNAL =
"jobCreated";
68 static ::boost::filesystem::path _sDefaultPath;
71 std::vector<std::string> ext;
73 std::string availableExtensions =
"";
77 availableExtensions =
"*" + ext.at(0);
78 for(
int i = 1; i < ext.size(); i++)
80 availableExtensions = availableExtensions +
" *" + ext.at(i);
89 dialogFile.
addFilter(
"MetaImage",
"*.mhd");
90 dialogFile.
addFilter(
"Bitmap image", availableExtensions);
91 dialogFile.
setOption(::fwGui::dialog::ILocationDialog::READ);
92 dialogFile.
setOption(::fwGui::dialog::ILocationDialog::FILE_MUST_EXIST);
94 ::fwData::location::SingleFile::sptr result;
95 result = ::fwData::location::SingleFile::dynamicCast( dialogFile.
show() );
98 _sDefaultPath = result->getPath().parent_path();
100 this->
setFile(result->getPath());
112 m_sigJobCreated = newSignal< JobCreatedSignalType >( JOB_CREATED_SIGNAL );
138 _sstream <<
"SImageReader::info";
147 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(::fwIO::s_DATA_KEY);
153 image = this->getObject< ::fwData::Image >();
162 cursor.
setCursor(::fwGui::ICursor::BUSY);
178 FW_RAISE_EXCEPTION(e);
187 template<
typename READER >
typename READER::sptr configureReader(const ::boost::filesystem::path& imgFile )
189 typename READER::sptr reader = READER::New();
190 reader->setFile(imgFile);
197 const ::fwData::Image::sptr& img,
202 std::string ext = ::boost::filesystem::extension(imgFile);
203 ::boost::algorithm::to_lower(ext);
205 ::fwDataIO::reader::IObjectReader::sptr imageReader;
208 imageReader = configureReader< ::fwVtkIO::ImageReader >( imgFile );
210 else if(ext ==
".vti")
212 imageReader = configureReader< ::fwVtkIO::VtiImageReader >( imgFile );
214 else if(ext ==
".mhd")
216 imageReader = configureReader< ::fwVtkIO::MetaImageReader >( imgFile );
221 std::vector<std::string> availableExtensions;
226 for(; i < availableExtensions.size(); i++)
228 if(availableExtensions.at(i) == ext)
230 imageReader = configureReader< ::fwVtkIO::BitmapImageReader >( imgFile );
236 if(i == availableExtensions.size())
239 std::string bitmapExtensions =
"";
240 for(; i < availableExtensions.size(); i++)
242 bitmapExtensions = bitmapExtensions + availableExtensions.at(i) +
", ";
244 FW_RAISE_EXCEPTION(::
fwTools::Failed(
"Only " + bitmapExtensions +
".vtk, .vti and .mhd are supported."));
250 imageReader->setObject(img);
252 sigJobCreated->emit(imageReader->getJob());
260 std::stringstream ss;
261 ss <<
"Warning during loading : " << e.what();
266 ::fwGui::dialog::IMessageDialog::WARNING);
269 FW_RAISE_EXCEPTION(e);
271 catch (
const std::exception& e)
273 std::stringstream ss;
274 ss <<
"Warning during loading : " << e.what();
279 ::fwGui::dialog::IMessageDialog::WARNING);
286 "Warning during loading.",
287 ::fwGui::dialog::IMessageDialog::WARNING);
#define FW_DEPRECATED_KEY(newKey, access, version)
Use this macro when deprecating a service key to warn the developer.
virtual FWGUI_API void setCursor(::fwGui::ICursor::CursorType cursor) override
Set the cursor.
static FWVTKIO_API void getAvailableExtensions(std::vector< std::string > &ext)
Service reading a VTK Image using the fwVtkIO lib.
std::string m_windowTitle
Title of the window that will open when the configureWithIHM slot is called.
Class allowing to block a Connection.
FWIO_API bool hasLocationDefined() const
Returns if a location has been defined ( by the configuration process or directly by user ) ...
virtual FWIO_API void configuring() override
This method proposes to parse xml configuration to retrieve file/files/folder paths.
static FWGUI_API IMessageDialog::Buttons showMessageDialog(const std::string &title, const std::string &message,::fwGui::dialog::IMessageDialog::Icons icon=INFO)
virtual IOVTK_API void configuring() override
Method called when the service is stopped, does nothing.
static IOVTK_API bool loadImage(const ::boost::filesystem::path &vtkFile, const std::shared_ptr< ::fwData::Image > &image, const std::shared_ptr< JobCreatedSignalType > &sigJobCreated)
This method is used to load an vtk image using a file path.
virtual FWGUI_API void setDefaultLocation(::fwData::location::ILocation::sptr loc) override
Set the initial location for the dialog.
virtual IOVTK_API void starting() override
Method called when the service is started, does nothing.
FWGUI_API::fwGui::dialog::ILocationDialog & setOption(::fwGui::dialog::ILocationDialog::Options option) override
allow to set option to the file dialog mode=READ/WRITE, check=FILE_MUST_EXIST
FWGUI_API::fwData::location::ILocation::sptr show() override
Display the dialog.
virtual IOVTK_API::fwIO::IOPathType getIOPathType() const override
This method must be implemented by concrete service readers that use path file system to read data...
A helper to lock object on exclusive mode.
#define OSLM_TRACE(message)
FWGUI_API void addFilter(const std::string &filterName, const std::string &wildcardList) override
specify some filtering when browsing files:
FWIO_APIconst::boost::filesystem::path & getFile() const
Returns the file path set by the user or set during service configuration.
UpdateSlotType::sptr m_slotUpdate
Slot to call update method.
virtual IOVTK_API void configureWithIHM() override
Configure the image path with a dialogBox.
FWIO_API void setFile(const ::boost::filesystem::path &file)
Sets file path.
Reader service API. It manages extension points definition and extension configuration.
IOVTK_API SImageReader() noexcept
Constructor. Do nothing.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
virtual IOVTK_API void stopping() override
Method called when the service is stopped, does nothing.
IOVTK_API void info(std::ostream &_sstream) override
Info method gives some informations on service.
IOPathType
IOPathType defines different type of paths used by service readers/writers.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
FWGUI_API void setTitle(const std::string &title) override
Set the title for the dialog.
Defines the generic file/folder selector dialog for IHM.
Defines the generic cursor for IHM. Use the Delegate design pattern.
This class defines an image.
FWIO_API void clearLocations()
Clear any location set by the setFile/setFiles/setFolder setter.
FWGUI_API void saveDefaultLocation(::fwData::location::ILocation::sptr loc) override
Save the specified default location for the dialog in preferences (if available)
The namespace ioVTK contains reader, writer and helper using the fwVtkIO lib for output and input act...
virtual FWGUI_API void setDefaultCursor() override
Set the default cursor.
IOVTK_API void updating() override
Updating method execute the read process.