7 #include "visuVTKAdaptor/SImageSliceOrientationText.hpp" 9 #include <fwCom/Slot.hpp> 10 #include <fwCom/Slot.hxx> 11 #include <fwCom/Slots.hpp> 12 #include <fwCom/Slots.hxx> 14 #include <fwData/Image.hpp> 16 #include <fwDataTools/fieldHelper/MedicalImageHelpers.hpp> 18 #include <fwServices/macros.hpp> 20 #include <boost/algorithm/string.hpp> 22 #include <vtkActor2D.h> 23 #include <vtkRenderer.h> 24 #include <vtkSmartPointer.h> 25 #include <vtkTextMapper.h> 26 #include <vtkTextProperty.h> 36 typedef vtkSmartPointer<vtkActor2D> TextActorPtr;
37 typedef vtkSmartPointer<vtkTextMapper> TextMapperPtr;
41 void configure(TextActorPtr& actor, TextMapperPtr& mapper)
43 actor = TextActorPtr::New();
44 mapper = TextMapperPtr::New();
46 mapper->GetTextProperty()->SetFontFamilyToCourier();
47 mapper->GetTextProperty()->ShadowOn();
48 mapper->GetTextProperty()->BoldOn();
49 actor->SetMapper(mapper);
50 actor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
51 actor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
56 configure(m_right, m_rightMapper);
57 configure(m_left, m_leftMapper);
58 configure(m_top, m_topMapper);
59 configure(m_bottom, m_bottomMapper);
61 vtkTextProperty* textProp;
63 m_right->SetPosition(0.99, 0.5);
64 m_rightMapper->SetInput(
"");
65 textProp = m_rightMapper->GetTextProperty();
66 textProp->SetJustificationToRight();
67 textProp->SetVerticalJustificationToCentered();
69 m_left->SetPosition(0.01, 0.5);
70 m_leftMapper->SetInput(
"");
71 textProp = m_leftMapper->GetTextProperty();
72 textProp->SetJustificationToLeft();
73 textProp->SetVerticalJustificationToCentered();
75 m_top->SetPosition(0.5, 0.99);
76 m_topMapper->SetInput(
"");
77 textProp = m_topMapper->GetTextProperty();
78 textProp->SetJustificationToCentered();
79 textProp->SetVerticalJustificationToTop();
81 m_bottom->SetPosition(0.5, 0.01);
82 m_bottomMapper->SetInput(
"");
83 textProp = m_bottomMapper->GetTextProperty();
84 textProp->SetJustificationToCentered();
85 textProp->SetVerticalJustificationToBottom();
90 void setText(
const std::string& str)
101 std::vector<std::string> locations;
102 ::boost::algorithm::split( locations, str, ::boost::algorithm::is_any_of(
",") );
103 SLM_ASSERT(
"Six location should be given, got : " << locations.size() <<
":" << str, locations.size());
105 m_rightStr = (locations.size() > 0) ? locations[0] :
"";
106 m_leftStr = (locations.size() > 1) ? locations[1] :
"";
107 m_anteriorStr = (locations.size() > 2) ? locations[2] :
"";
108 m_porteriorStr = (locations.size() > 3) ? locations[3] :
"";
109 m_superiorStr = (locations.size() > 4) ? locations[4] :
"";
110 m_inferiorStr = (locations.size() > 5) ? locations[5] :
"";
121 case ::fwDataTools::helper::MedicalImageAdaptor::X_AXIS:
122 m_rightMapper->SetInput(m_anteriorStr.c_str());
123 m_leftMapper->SetInput(m_porteriorStr.c_str());
124 m_topMapper->SetInput(m_superiorStr.c_str());
125 m_bottomMapper->SetInput(m_inferiorStr.c_str());
127 case ::fwDataTools::helper::MedicalImageAdaptor::Y_AXIS:
128 m_rightMapper->SetInput(m_leftStr.c_str());
129 m_leftMapper->SetInput(m_rightStr.c_str());
130 m_topMapper->SetInput(m_superiorStr.c_str());
131 m_bottomMapper->SetInput(m_inferiorStr.c_str());
133 case ::fwDataTools::helper::MedicalImageAdaptor::Z_AXIS:
134 m_rightMapper->SetInput(m_leftStr.c_str());
135 m_leftMapper->SetInput(m_rightStr.c_str());
136 m_topMapper->SetInput(m_anteriorStr.c_str());
137 m_bottomMapper->SetInput(m_porteriorStr.c_str());
140 m_rightMapper->SetInput(
"");
141 m_leftMapper->SetInput(
"");
142 m_topMapper->SetInput(
"");
143 m_bottomMapper->SetInput(
"");
144 SLM_ASSERT(
"bad orientation : " << orientation, 0);
148 std::string m_rightStr;
149 std::string m_leftStr;
150 std::string m_anteriorStr;
151 std::string m_porteriorStr;
152 std::string m_superiorStr;
153 std::string m_inferiorStr;
155 TextMapperPtr m_rightMapper;
156 TextMapperPtr m_leftMapper;
157 TextMapperPtr m_topMapper;
158 TextMapperPtr m_bottomMapper;
159 TextActorPtr m_right;
162 TextActorPtr m_bottom;
167 static const ::fwCom::Slots::SlotKeyType s_UPDATE_SLICE_TYPE_SLOT =
"updateSliceType";
169 static const ::fwServices::IService::KeyType s_IMAGE_INPUT =
"image";
173 SImageSliceOrientationText::SImageSliceOrientationText() noexcept :
176 newSlot(s_UPDATE_SLICE_TYPE_SLOT, &SImageSliceOrientationText::updateSliceType,
this);
181 SImageSliceOrientationText::~SImageSliceOrientationText() noexcept
191 if(m_initialOrientation ==
"axial")
193 this->setOrientation(Z_AXIS);
195 else if(m_initialOrientation ==
"frontal")
197 this->setOrientation(Y_AXIS);
201 this->setOrientation(X_AXIS);
204 if(!m_locations.empty())
207 this->addToRenderer( m_pimpl->m_right );
208 this->addToRenderer( m_pimpl->m_left );
209 this->addToRenderer( m_pimpl->m_top );
210 this->addToRenderer( m_pimpl->m_bottom );
219 this->removeAllPropFromRenderer();
226 m_pimpl->setText(m_locations);
227 m_pimpl->setOrientation(m_orientation);
229 this->requestRender();
237 m_pimpl->setOrientation(orientation);
242 void SImageSliceOrientationText::updateSliceType(
int from,
int to)
244 if( to == static_cast<int>(m_orientation) )
246 this->setOrientation( static_cast< Orientation >( from ));
248 else if(from == static_cast<int>(m_orientation))
250 this->setOrientation( static_cast< Orientation >( to ));
258 this->configureParams();
260 const ConfigType srvconfig = this->getConfigTree().get_child(
"config");
262 m_locations = srvconfig.get(
"locations",
"");
266 m_locations = (m_locations ==
"default") ?
"R,L,A,P,S,I" : m_locations;
268 m_initialOrientation = srvconfig.get(
"initialOrientation",
"axial");
269 SLM_TRACE(
"initialOrientation " + m_initialOrientation);
Shows image orientation information (right, left, ...) This adaptor show locations labels in the four...
This class is a helper to define the connections of a service and its data.
VISUVTKADAPTOR_API void starting() override
IService API implementation.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
VISUVTKADAPTOR_API void configuring() override
IService API implementation.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
VISUVTKADAPTOR_API void stopping() override
IService API implementation.
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)
VISUVTKADAPTOR_API void setOrientation(Orientation orientation) override
Overides MedicalImageAdaptor's setOrientation.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_SLICE_TYPE_MODIFIED_SIG
Type of signal when image's buffer is added.
virtual VISUVTKADAPTOR_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
VISUVTKADAPTOR_API void updating() override
IService API implementation.
Base class for VTK adaptors.