7 #include "scene2D/adaptor/SHistogramValue.hpp" 9 #include <fwData/Histogram.hpp> 10 #include <fwData/Point.hpp> 12 #include <fwRenderQt/data/InitQtPen.hpp> 13 #include <fwRenderQt/Scene2DGraphicsView.hpp> 15 #include <fwServices/macros.hpp> 18 #include <QGraphicsEllipseItem> 27 static const ::fwServices::IService::KeyType s_POINT_INPUT =
"point";
28 static const ::fwServices::IService::KeyType s_HISTOGRAM_INPUT =
"histogram";
29 static const ::fwServices::IService::KeyType s_VIEWPORT_INPUT =
"viewport";
31 SHistogramValue::SHistogramValue() noexcept :
34 m_isInteracting(false),
42 SHistogramValue::~SHistogramValue() noexcept
52 const ConfigType config = this->
getConfigTree().get_child(
"config.<xmlattr>");
54 if (config.count(
"color"))
59 if (config.count(
"fontSize"))
70 m_font.setLetterSpacing( QFont::AbsoluteSpacing, 0.2 );
71 m_font.setKerning(
true );
72 m_font.setFixedPitch(
true );
74 m_text =
new QGraphicsSimpleTextItem();
77 m_text->setCacheMode( QGraphicsItem::DeviceCoordinateCache );
78 m_text->setVisible(
false );
81 m_layer =
new QGraphicsItemGroup();
105 ::fwData::Histogram::csptr histogram = this->getInput< ::fwData::Histogram>(s_HISTOGRAM_INPUT);
106 ::fwData::Histogram::fwHistogramValues values = histogram->getValues();
107 const float histogramMinValue = histogram->getMinValue();
108 const float histogramBinsWidth = histogram->getBinsWidth();
113 int histIndex = (int) sceneCoord.getX();
114 int index = (histIndex - histogramMinValue) / histogramBinsWidth;
118 ::fwRenderQt::data::Viewport::sptr viewport = this->
getScene2DRender()->getViewport();
119 const double viewportHeight = viewport->getHeight();
120 const double viewportWidth = viewport->getWidth();
122 const double viewportSizeRatio = viewportHeight / viewportWidth;
129 double diameterV =
m_fontSize * viewportSizeRatio;
131 diameterV /= viewportWidthRatio;
132 diameterV *= viewInitialSizeRatio;
134 diameterH *= ratio.first;
135 diameterV *= ratio.second;
137 m_text->setText( QString::number( histIndex ) );
140 double scaleY =
m_fontSize * viewportSizeRatio;
142 scaleY /= viewportWidthRatio;
143 scaleY *= viewInitialSizeRatio;
145 scaleX = scaleX * ratio.first;
146 scaleY = scaleY * ratio.second;
148 QTransform transform;
149 transform.scale(scaleX, scaleY);
151 ::fwData::Point::csptr
point = this->getInput< ::fwData::Point>(s_POINT_INPUT);
153 m_text->setTransform( transform );
154 m_text->setPos( point->getCoord()[0] + diameterH * 2, point->getCoord()[1] - diameterV * 2 );
155 m_text->setVisible(
true );
159 m_text->setVisible(
false );
170 if( _event.getType() == ::fwRenderQt::data::Event::MouseMove )
174 else if( _event.getType() == ::fwRenderQt::data::Event::MouseButtonPress )
178 else if( _event.getType() == ::fwRenderQt::data::Event::MouseButtonRelease )
Root class for all scene2d adaptors.
::fwRenderQt::data::Axis::sptr m_xAxis
The x Axis.
This class is a helper to define the connections of a service and its data.
std::pair< float, float > Scene2DRatio
<width, height>
QPen m_color
Color used for graphic item's inner color.
QGraphicsItemGroup * m_layer
The layer.
FWRENDERQT_API void initializeViewSize()
Initialize the source values used for computing view's size ratio.
ViewSizeRatio m_viewInitialSize
bool m_isInteracting
If true, display the currently pointed intensity value.
FWRENDERQT_API std::shared_ptr< ::fwRenderQt::SRender > getScene2DRender() const
Get the render that manages the IAdaptor.
float m_fontSize
Size of the font used for rendering the current value of this tracker.
QGraphicsSimpleTextItem * m_text
An item which display the current values of the associated histogram pointed by this cursor...
static FWRENDERQT_API void setPenColor(QPen &_pen, std::string _color)
Set a pen a color.
This bundles contains data and services used to display a 2D Qt scene.
SCENE2D_API void configuring() override
Configure the service before starting. Apply the configuration to service.
FWRENDERQT_API void initializeViewportSize()
Initialize the source values used for computing viewport's size ratio.
SCENE2D_API::fwServices::IService::KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated objects signals, this method is used for obj...
SCENE2D_API void starting() override
Initialize the service activity.
::fwRenderQt::data::Axis::sptr m_yAxis
The y Axis.
::fwRenderQt::data::Coord m_coord
Coordinates of the current event.
FWRENDERQT_API ViewportSizeRatio getViewportSizeRatio() const
Return the ratio between viewport's initial size and its current size.
FWRENDERQT_API void configureParams()
Parse the xml configuration for Axis, z value and opacity.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
SCENE2D_API void processInteraction(::fwRenderQt::data::Event &_event) override
IAdaptor implementation to show the histogram values clicked by mouse.
SCENE2D_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
This class manage events on the scene 2D (mouse event, keyboard event , ...).
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
SCENE2D_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.