9 #include "visuVTKAdaptor/SBoxWidget.hpp" 11 #include <fwData/TransformationMatrix3D.hpp> 13 #include <fwRenderVTK/vtk/fwVtkBoxRepresentation.hpp> 15 #include <fwServices/macros.hpp> 17 #include <vtkBoxRepresentation.h> 18 #include <vtkBoxWidget2.h> 19 #include <vtkCamera.h> 20 #include <vtkCommand.h> 21 #include <vtkMatrix4x4.h> 22 #include <vtkRenderer.h> 23 #include <vtkRenderWindow.h> 24 #include <vtkRenderWindowInteractor.h> 25 #include <vtkTransform.h> 39 cb->m_adaptor = adaptor;
53 virtual void Execute( ::vtkObject*,
unsigned long,
void* )
55 m_adaptor->updateFromVtk();
65 static const ::fwServices::IService::KeyType s_TRANSFORM_INOUT =
"transform";
69 SBoxWidget::SBoxWidget() noexcept :
72 m_vtkBoxWidget(
nullptr),
73 m_boxWidgetCommand(
nullptr),
77 m_boxWidgetCommand = BoxClallback::New(
this);
82 SBoxWidget::~SBoxWidget() noexcept
90 this->configureParams();
92 const ConfigType config = this->getConfigTree().get_child(
"config.<xmlattr>");
94 m_scaleFactor = config.get(
"scaleFactor", 1.);
96 const std::string enableScaling = config.get(
"enableScaling",
"no");
98 SLM_ASSERT(
"Wrong value for 'enableScaling', must be 'yes' or 'no'",
99 enableScaling ==
"yes" || enableScaling ==
"no");
101 m_enableScaling = (enableScaling ==
"yes");
110 SLM_ASSERT(
"vtk transform must be defined.", !this->getTransformId().empty());
111 m_transform = this->getRenderService()->getOrAddVtkTransform(this->getTransformId());
114 boxRep->SetPlaceFactor(m_scaleFactor);
116 double bounds[] = {-1, 1, -1, 1, -1, 1};
117 boxRep->PlaceWidget(bounds);
119 m_vtkBoxWidget = ::vtkBoxWidget2::New();
120 m_vtkBoxWidget->SetRepresentation(boxRep);
121 m_vtkBoxWidget->SetInteractor( this->getInteractor() );
122 if (!m_enableScaling)
124 boxRep->ScalingEnabledOff();
126 m_vtkBoxWidget->On();
128 boxRep->SetTransform(m_transform);
130 m_vtkBoxWidget->AddObserver( ::vtkCommand::InteractionEvent, m_boxWidgetCommand );
139 m_transform->Delete();
141 m_vtkBoxWidget->RemoveObserver( m_boxWidgetCommand );
142 m_vtkBoxWidget->Delete();
144 this->requestRender();
149 void SBoxWidget::updateFromVtk()
151 m_vtkBoxWidget->RemoveObserver( m_boxWidgetCommand );
153 vtkBoxRepresentation* repr = vtkBoxRepresentation::SafeDownCast( m_vtkBoxWidget->GetRepresentation() );
156 repr->GetTransform(m_transform);
157 m_transform->Modified();
160 ::fwData::TransformationMatrix3D::sptr trf = this->getInOut< ::fwData::TransformationMatrix3D >(s_TRANSFORM_INOUT);
161 vtkMatrix4x4* mat = m_transform->GetMatrix();
163 for(
int lt = 0; lt < 4; lt++)
165 for(
int ct = 0; ct < 4; ct++)
167 trf->setCoefficient(static_cast<size_t>(lt), static_cast<size_t>(ct), mat->GetElement(lt, ct));
177 m_vtkBoxWidget->AddObserver( ::vtkCommand::InteractionEvent, m_boxWidgetCommand );
184 m_vtkBoxWidget->RemoveObserver( m_boxWidgetCommand );
185 vtkBoxRepresentation* repr = vtkBoxRepresentation::SafeDownCast( m_vtkBoxWidget->GetRepresentation() );
188 ::fwData::TransformationMatrix3D::sptr transMat =
189 this->getInOut< ::fwData::TransformationMatrix3D >(s_TRANSFORM_INOUT);
191 vtkMatrix4x4* mat = vtkMatrix4x4::New();
193 for(
int lt = 0; lt < 4; lt++)
195 for(
int ct = 0; ct < 4; ct++)
197 mat->SetElement(lt, ct, transMat->getCoefficient(static_cast<size_t>(lt), static_cast<size_t>(ct)));
200 m_transform->SetMatrix(mat);
201 repr->SetTransform(m_transform);
202 this->setVtkPipelineModified();
204 m_vtkBoxWidget->AddObserver( ::vtkCommand::InteractionEvent, m_boxWidgetCommand );
205 this->requestRender();
This class is a helper to define the connections of a service and its data.
Class allowing to block a Connection.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
Base class for VTK adaptors.