7 #include "visuVTKAdaptor/STransformFromWheel.hpp" 9 #include <fwCom/Slot.hxx> 10 #include <fwCom/Slots.hxx> 12 #include <fwDataTools/TransformationMatrix3D.hpp> 14 #include <fwRenderVTK/vtk/Helpers.hpp> 16 #include <fwServices/macros.hpp> 18 #include <glm/gtc/matrix_transform.hpp> 19 #include <glm/vec3.hpp> 21 #include <vtkAbstractPropPicker.h> 28 static const ::fwCom::Slots::SlotKeyType s_ROTATE_TRANSFORM_SLOT =
"rotateTransform";
29 static const ::fwCom::Slots::SlotKeyType s_TRANSLATE_TRANSFORM =
"translateTransform";
30 static const ::fwCom::Slots::SlotKeyType s_UPDATE_SLICE_TYPE_SLOT =
"updateSliceType";
32 static const ::fwServices::IService::KeyType s_TRANSFORM_INOUT =
"transform";
36 STransformFromWheel::STransformFromWheel() :
37 m_orientation(::
fwDataTools::helper::MedicalImageAdaptor::Orientation::Z_AXIS),
42 newSlot(s_ROTATE_TRANSFORM_SLOT, &STransformFromWheel::rotateTransform,
this);
43 newSlot(s_TRANSLATE_TRANSFORM, &STransformFromWheel::translateTransform,
this);
44 newSlot(s_UPDATE_SLICE_TYPE_SLOT, &STransformFromWheel::updateSliceOrientation,
this);
49 STransformFromWheel::~STransformFromWheel()
56 void STransformFromWheel::configuring()
58 this->configureParams();
60 const ConfigType config = this->
getConfigTree().get_child(
"config.<xmlattr>");
61 const std::string interactionMode = config.get<std::string>(
"mode",
"2D");
63 if(interactionMode ==
"2d" || interactionMode ==
"2D")
65 m_interactionMode = 2;
67 else if(interactionMode ==
"3d" || interactionMode ==
"3D")
69 m_interactionMode = 3;
73 SLM_WARN(
"Wrong interaction mode specified. Set to 2D.");
76 const std::string orientation = config.get<std::string>(
"orientation",
"");
78 if(orientation ==
"axial")
80 m_orientation = ::fwDataTools::helper::MedicalImageAdaptor::Orientation::Z_AXIS;
82 else if(orientation ==
"sagittal")
84 m_orientation = ::fwDataTools::helper::MedicalImageAdaptor::Orientation::X_AXIS;
86 else if(orientation ==
"frontal")
88 m_orientation = ::fwDataTools::helper::MedicalImageAdaptor::Orientation::Y_AXIS;
92 SLM_FATAL(
"Unknown orientation: '" + orientation +
"'.");
98 void STransformFromWheel::starting()
105 void STransformFromWheel::updating()
112 void STransformFromWheel::stopping()
119 void STransformFromWheel::applyTransformToOutput(
const glm::dmat4& transform)
const 121 ::fwData::TransformationMatrix3D::sptr outTrans =
122 this->getInOut< ::fwData::TransformationMatrix3D >(s_TRANSFORM_INOUT);
124 SLM_ASSERT(
"No 'transform' found.", outTrans);
127 finalTransform = finalTransform * transform;
139 void STransformFromWheel::updateSliceOrientation(
int from,
int to)
141 if( to == static_cast< int > ( m_orientation ) )
145 else if(from == static_cast<int>(m_orientation))
153 void STransformFromWheel::rotateTransform(
double cx,
double cy,
double wheelAngle)
155 const double angle = wheelAngle - m_initAngle;
156 m_initAngle = wheelAngle;
159 vtkAbstractPropPicker* picker = this->getRenderService()->getPicker(m_pickerId);
161 SLM_ASSERT(
"No picker named '" + m_pickerId +
"'.", picker);
163 double displayPosition[3] = { cx, cy, 0. };
164 picker->Pick( displayPosition, this->getRenderer());
167 ::fwRenderVTK::vtk::getNearestPickedPosition(picker, this->getRenderer(), worldPos);
169 ::glm::dvec3 rotAxis;
170 ::glm::dvec3 pos(worldPos[0], worldPos[1], worldPos[2]);
172 rotAxis[m_orientation] = 1.;
174 if(m_interactionMode == 2)
176 switch (m_orientation)
178 case ::fwDataTools::helper::MedicalImageAdaptor::Orientation::Z_AXIS:
break;
179 case ::fwDataTools::helper::MedicalImageAdaptor::Orientation::Y_AXIS:
181 pos = ::glm::dvec3(pos.x, pos.z, pos.y);
183 case ::fwDataTools::helper::MedicalImageAdaptor::Orientation::X_AXIS:
184 pos = ::glm::dvec3(pos.z, pos.x, pos.y);
189 const ::glm::dmat4 invTransMat = ::glm::translate(::glm::dmat4(1.), pos);
190 const ::glm::dmat4 rotMat = ::glm::rotate(invTransMat, angle, rotAxis);
191 const ::glm::dmat4 centeredRot = ::glm::translate(rotMat, -pos);
193 this->applyTransformToOutput(centeredRot);
200 if(info.
m_eventId == ::fwDataTools::PickingInfo::Event::MOUSE_LEFT_DOWN)
206 else if(m_translate && info.
m_eventId == ::fwDataTools::PickingInfo::Event::MOUSE_MOVE)
208 ::glm::dvec3 transVec(m_lastPickedPos[0] - info.
m_worldPos[0],
212 if(m_interactionMode == 2)
214 switch (m_orientation)
216 case ::fwDataTools::helper::MedicalImageAdaptor::Orientation::Z_AXIS:
break;
217 case ::fwDataTools::helper::MedicalImageAdaptor::Orientation::Y_AXIS:
218 transVec = ::glm::dvec3(transVec.x, transVec.z, transVec.y);
220 case ::fwDataTools::helper::MedicalImageAdaptor::Orientation::X_AXIS:
221 transVec = ::glm::dvec3(transVec.z, transVec.x, transVec.y);
226 const ::glm::dmat4 transMat = ::glm::translate(::glm::dmat4(1.), transVec);
228 this->applyTransformToOutput(transMat);
232 else if(info.
m_eventId == ::fwDataTools::PickingInfo::Event::MOUSE_LEFT_UP)
237 this->requestRender();
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
#define SLM_WARN(message)
#define SLM_FATAL(message)
#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.
FWGUI_API void initialize()
Initialize managers.
Base class for VTK adaptors.
virtual FWSERVICES_API void info(std::ostream &_sstream)
Write information in a stream.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.