7 #include "scene2D/adaptor/SHistogram.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> 17 #include <QGraphicsRectItem> 18 #include <QGraphicsView> 27 static const ::fwServices::IService::KeyType s_POINT_INOUT =
"point";
28 static const ::fwServices::IService::KeyType s_HISTOGRAM_INPUT =
"histogram";
34 SHistogram::SHistogram() noexcept :
44 SHistogram::~SHistogram() noexcept
54 const ConfigType config = this->
getConfigTree().get_child(
"config.<xmlattr>");
58 if (config.count(
"color"))
63 if (config.count(
"opacity"))
65 m_opacity = config.get<
float>(
"opacity");
82 ::fwData::Histogram::csptr histogram = this->getInput< ::fwData::Histogram>(s_HISTOGRAM_INPUT);
83 ::fwData::Histogram::fwHistogramValues values = histogram->getValues();
85 m_layer =
new QGraphicsItemGroup();
90 QColor color = m_color.color();
91 color.setAlphaF( m_opacity );
92 m_color.setColor( color );
94 const float min = histogram->getMinValue();
95 const float binsWidth = histogram->getBinsWidth();
103 QBrush brush = QBrush(m_color.color());
106 const int nbValues = (int)values.size();
107 for(
int i = 1; i < nbValues; ++i)
111 QPainterPath painter( QPointF(startPoint.first, 0) );
112 painter.lineTo( startPoint.first, startPoint.second );
113 painter.lineTo( pair.first, pair.second );
114 painter.lineTo( pair.first, 0 );
116 QGraphicsPathItem* item =
new QGraphicsPathItem( painter );
117 item->setPath( painter );
118 item->setBrush( brush );
119 item->setPen( Qt::NoPen );
120 item->setCacheMode( QGraphicsItem::DeviceCoordinateCache );
122 m_layer->addToGroup( item );
140 ::fwData::Histogram::csptr histogram = this->getInput< ::fwData::Histogram >(s_HISTOGRAM_INPUT);
141 ::fwData::Histogram::fwHistogramValues values = histogram->getValues();
142 const float histogramMinValue = histogram->getMinValue();
143 const float histogramBinsWidth = histogram->getBinsWidth();
148 const int histIndex = (int) sceneCoord.getX();
149 const int index = histIndex - histogramMinValue;
150 const int nbValues = (int)values.size() * histogramBinsWidth;
152 if(index >= 0 && index < nbValues)
154 point->getCoord()[0] = sceneCoord.getX();
155 point->getCoord()[1] = values.at( index / histogramBinsWidth ) * m_scale;
175 bool updatePointedPos =
false;
178 if( _event.getType() == ::fwRenderQt::data::Event::MouseWheelUp )
181 m_layer->setTransform(QTransform::fromScale(1,
SCALE),
true);
186 updatePointedPos =
true;
188 else if( _event.getType() == ::fwRenderQt::data::Event::MouseWheelDown )
191 m_layer->setTransform(QTransform::fromScale(1, 1 /
SCALE),
true);
196 updatePointedPos =
true;
198 else if( _event.getType() == ::fwRenderQt::data::Event::MouseMove )
200 updatePointedPos =
true;
203 ::fwData::Point::sptr point = this->getInOut< ::fwData::Point>(s_POINT_INOUT);
204 if( point && updatePointedPos )
206 this->updateCurrentPoint(_event, point);
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.
SCENE2D_API void configuring() override
Configure the service before starting. Apply the configuration to service.
FWRENDERQT_API Point2DType mapAdaptorToScene(const Point2DType &_xy, const ::fwRenderQt::data::Axis::sptr &_xAxis, const ::fwRenderQt::data::Axis::sptr &_yAxis) const
FWRENDERQT_API std::shared_ptr< ::fwRenderQt::SRender > getScene2DRender() const
Get the render that manages the IAdaptor.
SCENE2D_API void starting() override
Initialize the service activity.
std::pair< double, double > Point2DType
Point2D coordinate <X, Y>
static FWRENDERQT_API void setPenColor(QPen &_pen, std::string _color)
Set a pen a color.
static const float SCALE
Ratio used for vertical scaling (default value: 1.1)
This bundles contains data and services used to display a 2D Qt scene.
IAdaptor implementation for histogram data.
SCENE2D_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
SCENE2D_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
::fwRenderQt::data::Axis::sptr m_yAxis
The y Axis.
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
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::fwServices::IService::KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.