7 #include "scene2D/adaptor/SHistogramCursor.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 SHistogramCursor::SHistogramCursor() noexcept :
33 m_borderColor(Qt::gray),
42 SHistogramCursor::~SHistogramCursor() noexcept
52 const ConfigType config = this->
getConfigTree().get_child(
"config.<xmlattr>");
54 if (config.count(
"color"))
59 if (config.count(
"borderColor"))
64 if (config.count(
"pointSize"))
74 m_index =
new QGraphicsEllipseItem();
75 m_index->setBrush(
m_color.color() );
78 m_index->setCacheMode( QGraphicsItem::DeviceCoordinateCache );
82 m_layer =
new QGraphicsItemGroup();
107 ::fwData::Histogram::csptr histogram = this->getInput< ::fwData::Histogram>(s_HISTOGRAM_INPUT);
108 ::fwData::Histogram::fwHistogramValues values = histogram->getValues();
109 const float histogramMinValue = histogram->getMinValue();
110 const float histogramBinsWidth = histogram->getBinsWidth();
115 int histIndex = (int) sceneCoord.getX();
116 int index = (histIndex - histogramMinValue) / histogramBinsWidth;
118 if(index >= 0 && index < (
int)values.size())
120 ::fwRenderQt::data::Viewport::sptr viewport = this->
getScene2DRender()->getViewport();
121 const double viewportHeight = viewport->getHeight();
122 const double viewportWidth = viewport->getWidth();
124 const double viewportSizeRatio = viewportHeight / viewportWidth;
131 double diameterV =
m_pointSize * viewportSizeRatio;
133 diameterV /= viewportRatio;
134 diameterV *= viewInitialSizeRatio;
138 diameterH *= ratio.first;
139 diameterV *= ratio.second;
141 ::fwData::Point::csptr
point = this->getInput< ::fwData::Point>(s_POINT_INPUT);
143 const double x = point->getCoord()[0] - diameterH / 2;
144 const double y = point->getCoord()[1] - diameterV / 2;
146 m_index->setRect( x, y, diameterH, diameterV );
157 if( _event.getType() == ::fwRenderQt::data::Event::MouseMove )
Root class for all scene2d adaptors.
::fwRenderQt::data::Axis::sptr m_xAxis
The x Axis.
SCENE2D_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
This class is a helper to define the connections of a service and its data.
std::pair< float, float > Scene2DRatio
<width, height>
FWRENDERQT_API void initializeViewSize()
Initialize the source values used for computing view's size ratio.
ViewSizeRatio m_viewInitialSize
SCENE2D_API::fwServices::IService::KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated objects signals, this method is used for obj...
FWRENDERQT_API std::shared_ptr< ::fwRenderQt::SRender > getScene2DRender() const
Get the render that manages the IAdaptor.
QPen m_color
Color used for graphic item's inner color.
static FWRENDERQT_API void setPenColor(QPen &_pen, std::string _color)
Set a pen a color.
QPen m_borderColor
Color used for graphic item's border color.
This bundles contains data and services used to display a 2D Qt scene.
QGraphicsItemGroup * m_layer
The layer.
FWRENDERQT_API void initializeViewportSize()
Initialize the source values used for computing viewport's size ratio.
SCENE2D_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
::fwRenderQt::data::Coord m_coord
Coordinates of the current event.
::fwRenderQt::data::Axis::sptr m_yAxis
The y Axis.
float m_pointSize
Point size.
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 configuring() override
Configure the service before starting. Apply the configuration to service.
IAdaptor implementation to show a cursor on histogram pointed by mouse.
This class manage events on the scene 2D (mouse event, keyboard event , ...).
SCENE2D_API void starting() override
Initialize the service activity.
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
SCENE2D_API void processInteraction(::fwRenderQt::data::Event &_event) override
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.