7 #include "fwRenderVTK/IAdaptor.hpp" 9 #include "fwRenderVTK/registry/adaptors.hpp" 11 #include <fwData/String.hpp> 13 #include <fwRuntime/EConfigurationElement.hpp> 15 #include <fwServices/macros.hpp> 16 #include <fwServices/registry/ObjectService.hpp> 18 #include <fwTools/fwID.hpp> 20 #include <vtkAbstractPropPicker.h> 21 #include <vtkRenderer.h> 22 #include <vtkRenderWindow.h> 23 #include <vtkRenderWindowInteractor.h> 24 #include <vtkTransform.h> 30 m_vtkPipelineModified(true),
31 m_rendererId("default"),
36 m_propCollection( vtkPropCollection::New() )
42 m_propCollection->Delete();
50 this->
setPickerId(config.get<std::string>(
"config.<xmlattr>.picker",
""));
51 this->
setRendererId(config.get<std::string>(
"config.<xmlattr>.renderer",
""));
52 this->
setTransformId(config.get<std::string>(
"config.<xmlattr>.transform",
""));
59 if(m_renderService.expired())
62 const auto servicesVector = ::fwServices::OSR::getServices(
"::fwRenderVTK::SRender");
64 const auto&
registry = ::fwRenderVTK::registry::getAdaptorRegistry();
66 const std::string adaptorID = this->
getID();
67 SLM_ASSERT(
"The service '" + adaptorID +
"' is not found in the VTK adaptor registry. Make sure the service is " 69 const auto& renderServiceId =
registry.at(adaptorID);
72 std::find_if(servicesVector.begin(), servicesVector.end(),
73 [renderServiceId](const ::fwServices::IService::sptr& srv)
75 return srv->getID() == renderServiceId;
77 SLM_ASSERT(
"Can't find '" + renderServiceId +
"' SRender service.", result != servicesVector.end());
79 ::fwRenderVTK::SRender::sptr renderService = ::fwRenderVTK::SRender::dynamicCast(*result);
80 m_renderService = renderService;
91 m_renderService = service;
112 return (m_renderService.lock()->getRenderMode() == SRender::RenderMode::AUTO);
144 SLM_ASSERT(
"SRender service is not initialized, initialize() method must be called first",
145 !m_renderService.expired());
146 return m_renderService.lock();
153 return m_renderService.lock()->getRenderer(m_rendererId);
174 if (pickerId.empty())
176 pickerId = m_pickerId;
178 return m_renderService.lock()->getPicker(pickerId);
185 m_transformId = newID;
192 return m_transformId;
199 SLM_ASSERT(
"Transform id must be defined", !m_transformId.empty());
200 return m_renderService.lock()->getOrAddVtkTransform(m_transformId);
207 if (!objectId.empty())
209 return m_renderService.lock()->getVtkObject(objectId);
218 return this->
getRenderer()->GetRenderWindow()->GetInteractor();
229 if ( m_propCollection->IsItemPresent(prop) )
231 srv = this->getSptr();
237 for(
auto& service : subServices)
239 auto adaptor = ::fwRenderVTK::IAdaptor::dynamicCast(service.lock());
242 res = adaptor->getAssociatedAdaptor(prop, depth - 1 );
249 srv = ( res && depth == 0 ) ? this->getSptr() : res;
266 int initSize = propc->GetNumberOfItems();
268 prop->GetActors(propc);
269 prop->GetActors2D(propc);
270 prop->GetVolumes(propc);
272 if (initSize == propc->GetNumberOfItems())
274 propc->AddItem(prop);
284 m_propCollection->InitTraversal();
285 while ( (prop = m_propCollection->GetNextProp()) )
293 for(
const auto& service : subServices)
295 auto adaptor = ::fwRenderVTK::IAdaptor::dynamicCast(service.lock());
298 adaptor->getAllSubProps( propc, depth - 1 );
308 m_propCollection->RemoveAllItems();
325 this->
getPicker(pickerId)->AddPickList(prop);
334 this->
getPicker(pickerId)->DeletePickList(prop);
342 vtkPropCollection* propc = m_propCollection;
345 propc->InitTraversal();
346 while ( (prop = propc->GetNextProp()) )
FWRENDERVTK_API vtkRenderWindowInteractor * getInteractor()
Returns the render interactor.
Contains fwAtomsFilter::registry details.
FWRENDERVTK_API void addToRenderer(vtkProp *prop)
Adds the vtkProp to the renderer.
FWRENDERVTK_API vtkObject * getVtkObject(const SRender::VtkObjectIdType &objectId) const
Returns the vtk object defined by 'objectId' in the vtk scene.
FWRENDERVTK_API void addToPicker(vtkProp *prop, std::string pickerId="")
Adds the vtkProp to the picking list.
#define OSLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWRENDERVTK_API vtkRenderer * getRenderer()
Returns the renderer.
FWRENDERVTK_API void setRendererId(SRender::RendererIdType newID)
Sets the renderer identifier.
FWRENDERVTK_API void configureParams()
Parse the xml configuration for renderer, picker and transform.
FWRENDERVTK_API IAdaptor::sptr getAssociatedAdaptor(vtkProp *prop, int depth)
Returns the adaptor associated to the vtkProp.
FWRENDERVTK_API IAdaptor() noexcept
constructor
FWRENDERVTK_API bool getAutoRender() const
Returns true if the service automatically triggers the rendering.
FWRENDERVTK_API vtkAbstractPropPicker * getPicker(std::string pickerId="")
Get the picker.
const ServiceVector & getRegisteredServices() const
Get all subservices linked to this service.
FWRENDERVTK_API void requestRender()
notify a render request iff vtkPipeline is modified
FWRENDERVTK_API void setVtkPipelineModified()
End-user have to call this method when a vtk structure has been modified, thus a render request will ...
FWRENDERVTK_API void setTransformId(SRender::VtkObjectIdType newID)
Sets the identifier of the transform used by this adaptor.
FWRENDERVTK_API SRender::sptr getRenderService() const
Returd the associated render service.
FWRENDERVTK_API SRender::PickerIdType getPickerId() const
Gets the identifier of the picker used by this adaptor.
FWRENDERVTK_API void removeAllPropFromRenderer()
Removes all the vtkProp from the renderer.
FWRENDERVTK_API void setRenderService(SRender::sptr service)
Sets the assiciated render service.
FWRENDERVTK_API vtkTransform * getTransform()
Returns the transform used by this adaptor.
FWRENDERVTK_API void unregisterProps()
Unregisters all the vtkProp.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
bool m_vtkPipelineModified
state of the pipeline
FWRENDERVTK_API void getAllSubProps(vtkPropCollection *propc, int depth=-1)
Gets all the vtkProp associated to this adaptor.
FWRENDERVTK_API SRender::VtkObjectIdType getTransformId() const
Returns the identifier of the transform used by this adaptor.
FWRENDERVTK_API void removeFromPicker(vtkProp *prop, std::string pickerId="")
Removes the vtkProp to the picking list.
FWRENDERVTK_API SRender::RendererIdType getRendererId() const
Returns the renderer identifier.
FWRENDERVTK_API void initialize()
Initialize the adaptor with the associated render service. (must be call in starting).
FWRENDERVTK_API void registerProp(vtkProp *prop)
Registers the vtkProp.
The namespace fwRenderVTK contains classes for rendering with VTK.
FWSERVICES_API GlobalStatus getStatus() const noexcept
Return the global process status.
static FWRENDERVTK_API void getProps(vtkPropCollection *outPropc, vtkProp *inProp)
Get all the vtkProp associated to the inProp (actors, actors2D, volumes)
FWRENDERVTK_API void setPickerId(SRender::PickerIdType newID)
Sets the identifier of the picker used by this adaptor.
virtual FWRENDERVTK_API ~IAdaptor() noexcept
destructor
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.