9 #include "visuVTKAdaptor/SAxis.hpp" 11 #include <fwCom/Slots.hxx> 13 #include <fwServices/macros.hpp> 15 #include <boost/lexical_cast.hpp> 17 #include <vtkCommand.h> 18 #include <vtkPolyDataMapper.h> 19 #include <vtkProp3D.h> 20 #include <vtkProperty.h> 21 #include <vtkRenderer.h> 22 #include <vtkSphereSource.h> 23 #include <vtkTransform.h> 35 SAxis::SAxis() noexcept :
39 m_transformAxis(vtkSmartPointer<vtkTransform>::New()),
40 m_sphereActor(
nullptr),
51 SAxis::~SAxis() noexcept
53 m_axisActor->Delete();
54 m_axisActor =
nullptr;
67 const ConfigType config = this->
getConfigTree().get_child(
"config.<xmlattr>.");
69 m_length = config.get<
double>(
"length", 1.0);
71 const std::string label = config.get<std::string>(
"label",
"yes");
72 SLM_ASSERT(
"value for 'label' must be 'yes' or 'no'", label ==
"yes" || label ==
"no");
73 m_labelOn = ( label ==
"yes" );
75 m_xLabel = config.get<std::string>(
"xLabel",
"x");
76 m_yLabel = config.get<std::string>(
"yLabel",
"y");
77 m_zLabel = config.get<std::string>(
"zLabel",
"z");
79 const std::string marker = config.get<std::string>(
"marker",
"no");
80 SLM_ASSERT(
"value for 'marker' must be 'yes' or 'no'", marker ==
"yes" || marker ==
"no");
83 const std::string markerColor = config.get<std::string>(
"markerColor",
"#FFFFFF");
84 m_color = ::fwData::Color::New();
85 m_color->setRGBA(markerColor);
94 this->buildPipeline();
124 void SAxis::buildPipeline()
126 vtkTransform* transform = m_renderService.lock()->getOrAddVtkTransform(m_transformId);
127 m_axisActor->SetTotalLength( m_length, m_length, m_length );
128 m_axisActor->SetShaftTypeToCylinder();
129 m_axisActor->SetTipTypeToCone();
130 m_axisActor->SetXAxisLabelText(
m_xLabel.c_str() );
131 m_axisActor->SetYAxisLabelText( m_yLabel.c_str() );
132 m_axisActor->SetZAxisLabelText( m_zLabel.c_str() );
136 m_axisActor->AxisLabelsOff();
142 const double sizeRatio = 4.0;
143 auto sphereSource = vtkSmartPointer<vtkSphereSource>::New();
144 sphereSource->SetRadius(m_length/sizeRatio);
145 auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
146 mapper->SetInputConnection(sphereSource->GetOutputPort());
155 m_axisActor->SetUserTransform(transform);
164 m_axisActor->SetVisibility(_isVisible);
The fwVtkAxesActor class is a specific and movable vtkAxesActor.
static VISUVTKADAPTOR_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_VISIBILITY_SLOT
Slot: update axes visibility (true = visible)
FWRENDERVTK_API void addToRenderer(vtkProp *prop)
Adds the vtkProp to the renderer.
VISUVTKADAPTOR_API void updateVisibility(bool isVisible)
Slot: update axes visibility (true = visible)
FWRENDERVTK_API vtkRenderer * getRenderer()
Returns the renderer.
bool m_sphereOn
boolean to show the sphere marker
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
Render axis in the generic scene.
FWRENDERVTK_API void configureParams()
Parse the xml configuration for renderer, picker and transform.
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a 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 removeAllPropFromRenderer()
Removes all the vtkProp from the renderer.
::fwData::Color::sptr m_color
color of the sphere marker
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
vtkSmartPointer< vtkActor > m_sphereActor
actor for the sphere marker
FWRENDERVTK_API void initialize()
Initialize the adaptor with the associated render service. (must be call in starting).
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
std::string m_xLabel
X,Y and Z Labels.
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
Base class for VTK adaptors.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.