7 #include "visuVTKAdaptor/SImage.hpp" 9 #include <fwCom/Slot.hpp> 10 #include <fwCom/Slot.hxx> 11 #include <fwCom/Slots.hpp> 12 #include <fwCom/Slots.hxx> 14 #include <fwData/Boolean.hpp> 15 #include <fwData/Image.hpp> 16 #include <fwData/TransferFunction.hpp> 18 #include <fwDataTools/fieldHelper/Image.hpp> 19 #include <fwDataTools/fieldHelper/MedicalImageHelpers.hpp> 21 #include <fwRenderVTK/vtk/fwVtkWindowLevelLookupTable.hpp> 23 #include <fwServices/macros.hpp> 25 #include <fwVtkIO/helper/TransferFunction.hpp> 26 #include <fwVtkIO/vtk.hpp> 28 #include <vtkImageBlend.h> 29 #include <vtkImageCheckerboard.h> 30 #include <vtkImageData.h> 31 #include <vtkImageMapToColors.h> 38 static const ::fwCom::Slots::SlotKeyType s_UPDATE_IMAGE_OPACITY_SLOT =
"updateImageOpacity";
40 const ::fwServices::IService::KeyType SImage::s_IMAGE_INOUT =
"image";
41 const ::fwServices::IService::KeyType SImage::s_TF_INOUT =
"tf";
45 SImage::SImage() noexcept :
46 m_imageRegister(
nullptr),
49 m_allowAlphaInTF(false),
51 m_map2colors(vtkSmartPointer<vtkImageMapToColors>::New()),
52 m_imageData(vtkSmartPointer<vtkImageData>::New())
60 SImage::~SImage() noexcept
70 ::fwData::TransferFunction::sptr tf = this->getInOut< ::fwData::TransferFunction >(s_TF_INOUT);
71 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
84 this->destroyPipeline();
91 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
98 this->updateImage(image);
99 this->buildPipeline();
100 this->updateImageTransferFunction();
111 if (key == s_TF_INOUT)
113 ::fwData::TransferFunction::sptr tf = this->getInOut< ::fwData::TransferFunction >(s_TF_INOUT);
114 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
126 this->updateImageTransferFunction();
134 ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
137 m_lut->SetWindow(window);
138 m_lut->SetLevel(level);
150 const ConfigType config = this->
getConfigTree().get_child(
"config.<xmlattr>");
152 this->setVtkImageRegisterId( config.get<std::string>(
"vtkimageregister",
""));
154 m_imageOpacity = config.get<
double>(
"opacity", 0.);
156 const std::string tfalpha = config.get<std::string>(
"tfalpha",
"no");
157 SLM_ASSERT(
"'tfalpha' value must be 'yes' or 'no', actual: " + tfalpha, tfalpha ==
"yes" || tfalpha ==
"no");
158 this->setAllowAlphaInTF(tfalpha ==
"yes");
163 void SImage::updateImage( ::fwData::Image::sptr image )
165 ::fwVtkIO::toVTKImage(image, m_imageData);
173 void SImage::updateImageTransferFunction()
179 m_lut->SetClamping( !tf->getIsClamped() );
180 m_lut->SetWindow(tf->getWindow());
181 m_lut->SetLevel(tf->getLevel());
190 if (m_imagePortId >= 0)
192 ::fwData::Image::sptr img = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
195 if(img->getField(
"TRANSPARENCY" ) )
197 ::fwData::Integer::sptr transparency = img->getField<
::fwData::Integer >(
"TRANSPARENCY" );
198 m_imageOpacity = (100 - (*transparency) ) / 100.0;
200 if(img->getField(
"VISIBILITY" ) )
202 ::fwData::Boolean::sptr visible = img->getField<
::fwData::Boolean >(
"VISIBILITY" );
203 m_imageOpacity = (*visible) ? m_imageOpacity : 0.0;
206 vtkImageBlend* imageBlend = vtkImageBlend::SafeDownCast(m_imageRegister);
207 if(
nullptr != imageBlend )
209 imageBlend->SetOpacity(m_imagePortId, m_imageOpacity);
211 "vtkImageBlend " << this->m_imageRegisterId <<
" opacity :" << m_imagePortId <<
"," << m_imageOpacity );
221 void SImage::buildPipeline( )
223 m_map2colors->SetInputData(m_imageData);
224 m_map2colors->SetLookupTable(m_lut);
225 m_map2colors->SetOutputFormatToRGBA();
227 if (!m_imageRegisterId.empty())
229 m_imageRegister = this->
getVtkObject(m_imageRegisterId);
232 vtkImageAlgorithm* algorithm = vtkImageAlgorithm::SafeDownCast(m_imageRegister);
233 vtkImageData* imageData = vtkImageData::SafeDownCast(m_imageRegister);
234 vtkImageBlend* imageBlend = vtkImageBlend::SafeDownCast(m_imageRegister);
235 vtkImageCheckerboard* imageChecker = vtkImageCheckerboard::SafeDownCast(m_imageRegister);
237 SLM_ASSERT(
"Invalid vtk image register", algorithm||imageData||imageBlend||imageChecker );
240 SLM_TRACE(
"Register is a vtkImageBlend");
241 if (m_imagePortId < 0)
243 m_imagePortId = imageBlend->GetNumberOfInputConnections(0);
244 imageBlend->AddInputConnection(m_map2colors->GetOutputPort());
245 OSLM_TRACE(this->
getID() <<
": Added image " << m_imagePortId <<
" on vtkImageBlend");
248 else if (imageChecker)
250 SLM_TRACE(
"Register is a vtkImageCheckerboard");
251 if (m_imagePortId < 0)
253 m_imagePortId = imageChecker->GetNumberOfInputConnections(0);
254 imageChecker->SetInputConnection(m_imagePortId, m_map2colors->GetOutputPort());
255 OSLM_TRACE(this->
getID() <<
": Added image " << m_imagePortId <<
" on vtkImageCheckerboard");
260 SLM_TRACE(
"Register is a vtkImageAlgorithm");
261 algorithm->SetInputConnection(m_map2colors->GetOutputPort());
266 m_map2colors->SetOutput(imageData);
267 m_map2colors->Update();
275 void SImage::destroyPipeline( )
277 vtkImageAlgorithm* algorithm = vtkImageAlgorithm::SafeDownCast(m_imageRegister);
278 vtkImageData* imageData = vtkImageData::SafeDownCast(m_imageRegister);
279 vtkImageBlend* imageBlend = vtkImageBlend::SafeDownCast(m_imageRegister);
280 vtkImageCheckerboard* imageChecker = vtkImageCheckerboard::SafeDownCast(m_imageRegister);
284 if (m_imagePortId >= 0)
287 imageBlend->RemoveInputConnection(0, m_map2colors->GetOutputPort());
291 else if(imageChecker)
293 if (m_imagePortId >= 0)
296 imageChecker->RemoveInputConnection(0, m_map2colors->GetOutputPort());
302 algorithm->RemoveInputConnection(0, m_map2colors->GetOutputPort());
306 m_map2colors->SetOutput(0);
Render an image on the generic scene.
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_TRANSPARENCY_MODIFIED_SIG
Type of signal when image's buffer is added.
This class is a helper to define the connections of a service and its data.
FWRENDERVTK_API vtkObject * getVtkObject(const SRender::VtkObjectIdType &objectId) const
Returns the vtk object defined by 'objectId' in the vtk scene.
virtual VISUVTKADAPTOR_API void updateTFPoints() override
Slot: update the displayed lookup table.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
static FWVTKIO_API void toVtkLookupTable(fwData::TransferFunction::csptr tf, vtkSmartPointer< vtkLookupTable > lt, bool allowTransparency=false, unsigned int size=256)
Convert a fwData::TransferFunction to a vtkLookupTable.
This class contains an integer value. Integer object is essentially used as a field in other objects...
FWRENDERVTK_API void configureParams()
Parse the xml configuration for renderer, picker and transform.
FWRENDERVTK_API void requestRender()
notify a render request iff vtkPipeline is modified
virtual void swapping()
Swap the service from associated object to another object.
FWRENDERVTK_API void setVtkPipelineModified()
End-user have to call this method when a vtk structure has been modified, thus a render request will ...
#define OSLM_TRACE(message)
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
virtual VISUVTKADAPTOR_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_VISIBILITY_MODIFIED_SIG
Type of signal when image's buffer is added.
void updateImageOpacity()
Slot: Update image opacity and visibility.
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_BUFFER_MODIFIED_SIG
Type of signal when image's buffer is added.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
#define SLM_TRACE(message)
FWRENDERVTK_API void initialize()
Initialize the adaptor with the associated render service. (must be call in starting).
Reinplementation of vtkWindowLevelLookupTable : add specific out-of-bounds colors.
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
Base class for VTK adaptors.
This class contains a boolean value.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.
virtual VISUVTKADAPTOR_API void updateTFWindowing(double window, double level) override
Slot: update the windowing of the displayed lookup table.