7 #include "visuVTKAdaptor/SSnapshot.hpp" 9 #include <fwCom/Slots.hxx> 11 #include <fwData/Composite.hpp> 12 #include <fwData/String.hpp> 14 #include <fwDataTools/fieldHelper/Image.hpp> 16 #include <fwServices/macros.hpp> 18 #include <fwVtkIO/vtk.hpp> 20 #include <boost/filesystem/path.hpp> 23 #include <vtkBMPWriter.h> 24 #include <vtkImageData.h> 25 #include <vtkImageWriter.h> 26 #include <vtkJPEGWriter.h> 27 #include <vtkPNGWriter.h> 28 #include <vtkRenderer.h> 29 #include <vtkRenderWindow.h> 30 #include <vtkTIFFWriter.h> 31 #include <vtkWindowToImageFilter.h> 38 const ::fwCom::Slots::SlotKeyType SSnapshot::s_SNAP_SLOT =
"snap";
39 const ::fwCom::Slots::SlotKeyType SSnapshot::s_SNAPTOIMAGE_SLOT =
"snapToImage";
41 SSnapshot::SSnapshot() noexcept
43 newSlot(s_SNAP_SLOT, &SSnapshot::snap,
this);
44 newSlot(s_SNAPTOIMAGE_SLOT, &SSnapshot::snapToImage,
this);
49 SSnapshot::~SSnapshot() noexcept
81 void SSnapshot::snapToImage()
83 if ( !m_imageUid.empty() )
85 ::fwData::Image::sptr imageToSnap = ::fwData::Image::New();
87 vtkWindowToImageFilter* snapper = vtkWindowToImageFilter::New();
88 snapper->SetMagnification( 1 );
89 snapper->SetInput( this->
getRenderer()->GetRenderWindow() );
92 vtkImageData* vtkImage = snapper->GetOutput();
93 ::fwVtkIO::fromVTKImage(vtkImage, imageToSnap);
103 void SSnapshot::snap(std::string filePath)
105 SLM_ASSERT(
"filePath is empty", !filePath.empty());
106 namespace fs = ::boost::filesystem;
107 fs::path pathImageSnap(filePath);
109 std::string ext =
".jpg";
110 ext = pathImageSnap.extension().string();
111 vtkImageWriter* writer = 0;
113 if( ext ==
".jpg" || ext ==
".jpeg" )
115 writer = vtkJPEGWriter::New();
117 else if ( ext ==
".bmp" )
119 writer = vtkBMPWriter::New();
121 else if ( ext ==
".tiff" )
123 writer = vtkTIFFWriter::New();
125 else if ( ext ==
".png" )
127 writer = vtkPNGWriter::New();
131 SLM_FATAL(
"Error: Format is not supported.");
134 vtkWindowToImageFilter* snapper = vtkWindowToImageFilter::New();
135 snapper->SetMagnification( 1 );
136 snapper->SetInput( this->
getRenderer()->GetRenderWindow() );
138 writer->SetInputConnection( snapper->GetOutputPort() );
139 writer->SetFileName( pathImageSnap.string().c_str() );
FWRENDERVTK_API vtkRenderer * getRenderer()
Returns the renderer.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
FWRENDERVTK_API void configureParams()
Parse the xml configuration for renderer, picker and transform.
FWSERVICES_API void setOutput(const ::fwServices::IService::KeyType &key, const ::fwData::Object::sptr &object, size_t index=0)
Register an output object at a given key in the OSR, replacing it if it already exists.
#define SLM_FATAL(message)
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
FWRENDERVTK_API void initialize()
Initialize the adaptor with the associated render service. (must be call in starting).
Base class for VTK adaptors.
This service will snapshot the current generic scene.