fw4spl
SCurvedHistogram.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __SCENE2D_ADAPTOR_SCURVEDHISTOGRAM_HPP__
8 #define __SCENE2D_ADAPTOR_SCURVEDHISTOGRAM_HPP__
9 
10 #include "scene2D/config.hpp"
11 
12 #include <fwData/Histogram.hpp>
13 #include <fwData/Point.hpp>
14 
15 #include <fwRenderQt/IAdaptor.hpp>
16 
17 namespace scene2D
18 {
19 
20 namespace adaptor
21 {
22 
55 class SCENE2D_CLASS_API SCurvedHistogram : public ::fwRenderQt::IAdaptor
56 {
57 public:
59 
60  typedef ::fwRenderQt::IAdaptor::Point2DType Point;
61  typedef std::vector< Point > Points;
62 
63  SCENE2D_API SCurvedHistogram() noexcept;
64  SCENE2D_API virtual ~SCurvedHistogram() noexcept;
65 
66 protected:
67  SCENE2D_API void configuring() override;
68  SCENE2D_API void starting() override;
69  SCENE2D_API void updating() override;
70  SCENE2D_API void stopping() override;
71 
72  SCENE2D_API void processInteraction( ::fwRenderQt::data::Event& _event ) override;
73 
80  SCENE2D_API ::fwServices::IService::KeyConnectionsMap getAutoConnections() const override;
81 
83  static const float SCALE;
84 
86  static const float NB_POINTS_BEZIER;
87 
88 private:
89 
90  Points getControlPoints(const ::fwData::Histogram::csptr& _histogram ) const;
91 
92  Points getBSplinePoints( const Points& _controlPoints ) const;
93 
94  Points getResampledBSplinePoints( const Points& _bSplinePoints ) const;
95 
96  void buildBSplineFromPoints( Points& _bSplinePoints );
97 
98  void computePointToPathLengthMapFromBSplinePoints( Points& _bSplinePoints );
99 
101  void updateCurrentPoint(const ::fwRenderQt::data::Event& _event, const ::fwData::Point::sptr& point );
102 
104  void addBorderItem( const QPainterPath& _path );
105 
107  void addInnerItem( const QPainterPath& _path );
108 
109  Points linearInterpolation( const Point _p1, const Point _p2 );
110 
111  Points cosinusInterpolation( const Point _p0, const Point _p1 );
112 
113  Points quadraticInterpolation( const Point _p0, const Point _p1, const Point _p2 );
114 
115  Points cubicInterpolation(const Point _p0, const Point _p1, const Point _p2, const Point _p3 );
116 
117  // Map the absciss of the points to the corresponding length within the path.
118  std::map<double, double> m_positionsToPathLength;
119 
121  QPen m_borderColor;
122 
123  // Color used for graphic histogram's inner color. If no value is supplied in the configuration,
124  // item's inner will be transparent
125  QPen m_innerColor;
126 
128  QBrush m_brush;
129 
130  // A Qt painter that is used to build a curve representing the shape of the histogram.
131  // Note that the histogram won't be built thanks to this path because of a lack of performance.
132  // In other words, this painter path won't be used to build a graphic item that will be added to
133  // a Qt graphics scene. The graphic representation of the histogram will composed of multiple items
134  // build thanks to painters like this one, because it improves significantly the rendering performance.
135  // This painter path will be used to provide information about the histogram: for instance, it will help
136  // to retrieve the coordinates of path's points.
137  QPainterPath* m_painterPath;
138 
140  float m_borderWidth;
141 
143  float m_scale;
144 
145  // Graphics items contained into m_items are also added to this group item,
146  // which is then added to the scene.
147  // (This is the only graphic item which has to be added into the scene).
148  QGraphicsItemGroup* m_layer;
149 };
150 
151 } // namespace adaptor
152 
153 } // namespace scene2D
154 
155 #endif // __SCENE2D_ADAPTOR_SCURVEDHISTOGRAM_HPP__
156 
Root class for all scene2d adaptors.
This class is a helper to define the connections of a service and its data.
Definition: IService.hpp:454
STL namespace.
Namespace fwServices is dedicated to (mimic) the dynamic affectation of methods to (pure data) object...
This bundles contains data and services used to display a 2D Qt scene.
IAdaptor implementation for histogram data.
#define fwCoreServiceClassDefinitionsMacro(_classinfo_)
Generate common code for services classes.
Contains the representation of the data objects used in the framework.
The namespace fwRenderQt contains classes for rendering with Qt.
Definition: Axis.hpp:12