7 #include "ioVTK/SImageWriter.hpp" 9 #include <fwCore/base.hpp> 11 #include <fwData/Image.hpp> 12 #include <fwData/location/Folder.hpp> 13 #include <fwData/location/SingleFile.hpp> 15 #include <fwDataIO/reader/IObjectReader.hpp> 17 #include <fwGui/Cursor.hpp> 18 #include <fwGui/dialog/LocationDialog.hpp> 19 #include <fwGui/dialog/MessageDialog.hpp> 20 #include <fwGui/dialog/ProgressDialog.hpp> 22 #include <fwIO/IWriter.hpp> 24 #include <fwJobs/IJob.hpp> 25 #include <fwJobs/Job.hpp> 27 #include <fwServices/macros.hpp> 29 #include <fwTools/Failed.hpp> 31 #include <fwVtkIO/ImageWriter.hpp> 32 #include <fwVtkIO/MetaImageWriter.hpp> 33 #include <fwVtkIO/VtiImageWriter.hpp> 35 #include <boost/algorithm/string.hpp> 42 static const ::fwCom::Signals::SignalKeyType JOB_CREATED_SIGNAL =
"jobCreated";
48 m_sigJobCreated = newSignal< JobCreatedSignalType >( JOB_CREATED_SIGNAL );
63 static ::boost::filesystem::path _sDefaultPath(
"");
70 dialogFile.
addFilter(
"MetaImage",
"*.mhd");
71 dialogFile.
setOption(::fwGui::dialog::ILocationDialog::WRITE);
73 ::fwData::location::SingleFile::sptr result;
74 result = ::fwData::location::SingleFile::dynamicCast( dialogFile.
show() );
77 _sDefaultPath = result->getPath().parent_path();
79 this->
setFile(result->getPath());
113 _sstream <<
"SImageWriter::info";
125 ::fwDataIO::writer::IObjectWriter::sptr myWriter;
127 std::string ext = ::boost::filesystem::extension(imgFile);
128 ::boost::algorithm::to_lower(ext);
132 ::fwVtkIO::ImageWriter::sptr vtkWriter = ::fwVtkIO::ImageWriter::New();
134 vtkWriter->setFile(imgFile);
135 myWriter = vtkWriter;
137 else if(ext ==
".vti")
139 ::fwVtkIO::VtiImageWriter::sptr vtiWriter = ::fwVtkIO::VtiImageWriter::New();
140 vtiWriter->setFile(imgFile);
141 myWriter = vtiWriter;
143 else if(ext ==
".mhd")
145 ::fwVtkIO::MetaImageWriter::sptr mhdWriter = ::fwVtkIO::MetaImageWriter::New();
146 mhdWriter->setFile(imgFile);
147 myWriter = mhdWriter;
151 FW_RAISE_EXCEPTION(::
fwTools::Failed(
"Only .vtk, .vti and .mhd are supported."));
154 myWriter->setObject(image);
156 sigJobCreated->emit(myWriter->getJob());
163 catch (
const std::exception& e)
165 std::stringstream ss;
166 ss <<
"Warning during saving : " << e.what();
171 ::fwGui::dialog::IMessageDialog::WARNING);
178 "Warning during saving.",
179 ::fwGui::dialog::IMessageDialog::WARNING);
194 ::fwData::Image::csptr pImage = this->getInput< ::fwData::Image >(::fwIO::s_DATA_KEY);
198 pImage = this->getObject< ::fwData::Image >();
203 cursor.
setCursor(::fwGui::ICursor::BUSY);
212 FW_RAISE_EXCEPTION(e);
virtual IOVTK_API void configureWithIHM() override
Configure the image path.
#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.
IOVTK_API void updating() override
Updating method.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
virtual IOVTK_API void configuring() override
Configuring method.
static FWGUI_API IMessageDialog::Buttons showMessageDialog(const std::string &title, const std::string &message,::fwGui::dialog::IMessageDialog::Icons icon=INFO)
virtual FWGUI_API void setDefaultLocation(::fwData::location::ILocation::sptr loc) override
Set the initial location for the dialog.
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.
#define OSLM_TRACE(message)
virtual IOVTK_API void starting() override
Starting method.
FWGUI_API void addFilter(const std::string &filterName, const std::string &wildcardList) override
specify some filtering when browsing files:
Defines the generic progress dialog for IHM. Use the Delegate design pattern. The specific implementa...
FWIO_API void setFile(const ::boost::filesystem::path &file)
Sets file path.
virtual IOVTK_API::fwIO::IOPathType getIOPathType() const override
This method must be implemented by concrete service writers that use path file system to write data...
virtual FWIO_API void configuring() override
This method proposes to parse xml configuration to retrieve file/files/folder paths.
FWIO_APIconst::boost::filesystem::path & getFile() const
Returns the file path set by the user or set during service configuration.
static IOVTK_API bool saveImage(const ::boost::filesystem::path &imgFile, const std::shared_ptr< const ::fwData::Image > &image, const std::shared_ptr< JobCreatedSignalType > &sigJobCreated)
Save a VTK image.
IOVTK_API SImageWriter() noexcept
Constructor. Do nothing.
FWIO_API void clearLocations()
Clear any location set by the setFile/setFiles/setFolder setter.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
IOVTK_API void info(std::ostream &_sstream) override
Info method.
IOPathType
IOPathType defines different type of paths used by service readers/writers.
Writer service API. It manages extension points definition and extension configuration.
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.
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 IOVTK_API void stopping() override
Stopping method.
FWIO_API bool hasLocationDefined() const
Returns if a location has been defined ( by the configuration process or directly by user ) ...
virtual FWGUI_API void setDefaultCursor() override
Set the default cursor.
std::string m_windowTitle
Title of the window that will open when the configureWithIHM slot is called.