Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RHistDrawable.hxx
Go to the documentation of this file.
1/// \file ROOT/RHistDrawable.hxx
2/// \ingroup HistDraw ROOT7
3/// \author Axel Naumann <axel@cern.ch>
4/// \date 2015-07-09
5/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6/// is welcome!
7
8/*************************************************************************
9 * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
10 * All rights reserved. *
11 * *
12 * For the licensing terms see $ROOTSYS/LICENSE. *
13 * For the list of contributors see $ROOTSYS/README/CREDITS. *
14 *************************************************************************/
15
16#ifndef ROOT7_RHistDrawable
17#define ROOT7_RHistDrawable
18
19#include <ROOT/RDrawable.hxx>
20#include <ROOT/RAttrLine.hxx>
21#include <ROOT/RAttrText.hxx>
22#include <ROOT/RAttrMarker.hxx>
23#include <ROOT/RAttrFill.hxx>
24#include <ROOT/RAttrValue.hxx>
25#include <ROOT/RHist.hxx>
26#include <ROOT/RHistImpl.hxx>
27
28// TODO: move to separate file
30#include <ROOT/RDisplayItem.hxx>
31
32#include <memory>
33
34namespace ROOT {
35namespace Experimental {
36
38 RAttrValue<std::string> fKind{this, "kind", ""}; ///<! hist draw kind
39 RAttrValue<int> fSub{this, "sub", -1}; ///<! hist draw sub kind
40 RAttrLine fAttrLine{this, "line"}; ///<! hist line attributes
41 RAttrFill fAttrFill{this, "fill"}; ///<! hist fill attributes
42 RAttrText fAttrText{this, "text"}; ///<! hist text attributes
43 RAttrMarker fMarkerAttr{this, "marker"}; ///<! hist marker attributes
44 RAttrValue<bool> fOptimize{this, "optimize", false}; ///<! optimize drawing
45
46protected:
47
48 bool IsFrameRequired() const final { return true; }
49
50 void PopulateMenu(RMenuItems &) override { }
51
52 void SetDrawKind(const std::string &kind, int sub = -1)
53 {
54 fKind = kind;
55 if (sub >= 0)
56 fSub = sub;
57 else
58 fSub.Clear();
59 }
60
61 std::string GetDrawKind() const { return fKind; }
62
63 virtual std::unique_ptr<RDisplayItem> CreateHistDisplay(const RDisplayContext &) = 0;
64
65 virtual bool Is3D() const { return false; }
66
67 std::unique_ptr<RDisplayItem> Display(const RDisplayContext &ctxt) override
68 {
69 if (fOptimize)
70 return CreateHistDisplay(ctxt);
71
72 return RDrawable::Display(ctxt);
73 }
74
75public:
76
77 class RReply : public RDrawableReply {
78 public:
79 std::unique_ptr<RDisplayItem> item;
80 };
81
82 class RRequest : public RDrawableRequest {
83 std::unique_ptr<RDrawableReply> Process() override
84 {
85 auto hdraw = dynamic_cast<RHistDrawableBase *>(GetContext().GetDrawable());
86
87 auto reply = std::make_unique<RReply>();
88 if (hdraw)
89 reply->item = hdraw->CreateHistDisplay(GetContext());
90 return reply;
91 }
92 };
93
94 friend class RRequest;
95
97
98 const RAttrLine &GetAttrLine() const { return fAttrLine; }
99 RHistDrawableBase &SetAttrLine(const RAttrLine &attr) { fAttrLine = attr; return *this; }
101
102 const RAttrFill &GetAttrFill() const { return fAttrFill; }
103 RHistDrawableBase &SetAttrFill(const RAttrFill &fill) { fAttrFill = fill; return *this; }
105
106 const RAttrText &GetAttrText() const { return fAttrText; }
107 RHistDrawableBase &SetAttrText(const RAttrText &attr) { fAttrText = attr; return *this; }
109
110 const RAttrMarker &GetAttrMarker() const { return fMarkerAttr; }
111 RHistDrawableBase &SetAttrMarker(const RAttrMarker &attr) { fMarkerAttr = attr; return *this; }
113
114 RHistDrawableBase &Optimize(bool on = true) { fOptimize = on; return *this; }
115};
116
117
118template <int DIMENSIONS>
120public:
122
123protected:
124
125 Internal::RIOShared<HistImpl_t> fHistImpl; ///< I/O capable reference on histogram
126
127 void CollectShared(Internal::RIOSharedVector_t &vect) override { vect.emplace_back(&fHistImpl); }
128
129public:
130 RHistDrawable() = default;
131 virtual ~RHistDrawable() = default;
132
133 template <class HIST>
134 RHistDrawable(const std::shared_ptr<HIST> &hist) : RHistDrawableBase()
135 {
136 fHistImpl = std::shared_ptr<HistImpl_t>(hist, hist->GetImpl());
137 }
138
139 std::shared_ptr<HistImpl_t> GetHist() const { return fHistImpl.get_shared(); }
140};
141
142
143class RHist1Drawable final : public RHistDrawable<1> {
144 RAttrValue<double> fBarOffset{this, "bar_offset", 0.}; ///<! bar offset
145 RAttrValue<double> fBarWidth{this, "bar_width", 1.}; ///<! bar width
146 RAttrValue<bool> fText{this, "text", false}; ///<! draw text
147
148protected:
149 std::unique_ptr<RDisplayItem> CreateHistDisplay(const RDisplayContext &) override;
150
151 bool Is3D() const final { return GetDrawKind() == "lego"; }
152
153public:
154 RHist1Drawable() = default;
155
156 template <class HIST>
157 RHist1Drawable(const std::shared_ptr<HIST> &hist) : RHistDrawable<1>(hist) {}
158
159 RHist1Drawable &Bar() { SetDrawKind("bar", 0); fBarOffset.Clear(); fBarWidth.Clear(); return *this; }
160 RHist1Drawable &Bar(double offset, double width, bool mode3d = false) { SetDrawKind("bar", mode3d ? 1 : 0); fBarOffset = offset; fBarWidth = width; return *this; }
161 RHist1Drawable &Error(int kind = 0) { SetDrawKind("err", kind); return *this; }
162 RHist1Drawable &Marker() { SetDrawKind("p"); return *this; }
164 RHist1Drawable &Hist() { SetDrawKind("hist"); return *this; }
165 RHist1Drawable &Line() { SetDrawKind("l"); return *this; }
166 RHist1Drawable &Lego(int kind = 0) { SetDrawKind("lego", kind); return *this; }
167 RHist1Drawable &Text(bool on = true) { fText = on; return *this; }
168
169 double GetBarOffset() const { return fBarOffset; }
170 double GetBarWidth() const { return fBarWidth; }
171};
172
173
174class RHist2Drawable final : public RHistDrawable<2> {
175 RAttrValue<bool> fText{this, "text", false}; ///<! draw text
176
177protected:
178
179 std::unique_ptr<RDisplayItem> CreateHistDisplay(const RDisplayContext &) override;
180
181 bool Is3D() const final { return (GetDrawKind() == "lego") || (GetDrawKind() == "surf") || (GetDrawKind() == "err"); }
182
183public:
184 RHist2Drawable() = default;
185
186 template <class HIST>
187 RHist2Drawable(const std::shared_ptr<HIST> &hist) : RHistDrawable<2>(hist) {}
188
189 RHist2Drawable &Color() { SetDrawKind("col"); return *this; }
190 RHist2Drawable &Box(int kind = 0) { SetDrawKind("box", kind); return *this; }
191 RHist2Drawable &Lego(int kind = 0) { SetDrawKind("lego", kind); return *this; }
192 RHist2Drawable &Surf(int kind = 0) { SetDrawKind("surf", kind); return *this; }
193 RHist2Drawable &Error() { SetDrawKind("err"); return *this; }
194 RHist2Drawable &Contour(int kind = 0) { SetDrawKind("cont", kind); return *this; }
195 RHist2Drawable &Scatter() { SetDrawKind("scat"); return *this; }
196 RHist2Drawable &Arrow() { SetDrawKind("arr"); return *this; }
197 RHist2Drawable &Text(bool on = true) { fText = on; return *this; }
198};
199
200
201class RHist3Drawable final : public RHistDrawable<3> {
202protected:
203 std::unique_ptr<RDisplayItem> CreateHistDisplay(const RDisplayContext &) override;
204
205 bool Is3D() const final { return true; }
206
207public:
208 RHist3Drawable() = default;
209
210 template <class HIST>
211 RHist3Drawable(const std::shared_ptr<HIST> &hist) : RHistDrawable<3>(hist) {}
212
213 RHist3Drawable &Color() { SetDrawKind("col"); return *this; }
214 RHist3Drawable &Box(int kind = 0) { SetDrawKind("box", kind); return *this; }
215 RHist3Drawable &Sphere(int kind = 0) { SetDrawKind("sphere", kind); return *this; }
216 RHist3Drawable &Scatter() { SetDrawKind("scat"); return *this; }
217};
218
219
220inline auto GetDrawable(const std::shared_ptr<RH1D> &histimpl)
221{
222 return std::make_shared<RHist1Drawable>(histimpl);
223}
224
225inline auto GetDrawable(const std::shared_ptr<RH1I> &histimpl)
226{
227 return std::make_shared<RHist1Drawable>(histimpl);
228}
229
230inline auto GetDrawable(const std::shared_ptr<RH1C> &histimpl)
231{
232 return std::make_shared<RHist1Drawable>(histimpl);
233}
234
235inline auto GetDrawable(const std::shared_ptr<RH1F> &histimpl)
236{
237 return std::make_shared<RHist1Drawable>(histimpl);
238}
239
240inline auto GetDrawable(const std::shared_ptr<RH2D> &histimpl)
241{
242 return std::make_shared<RHist2Drawable>(histimpl);
243}
244
245inline auto GetDrawable(const std::shared_ptr<RH2I> &histimpl)
246{
247 return std::make_shared<RHist2Drawable>(histimpl);
248}
249
250inline auto GetDrawable(const std::shared_ptr<RH2C> &histimpl)
251{
252 return std::make_shared<RHist2Drawable>(histimpl);
253}
254
255inline auto GetDrawable(const std::shared_ptr<RH2F> &histimpl)
256{
257 return std::make_shared<RHist2Drawable>(histimpl);
258}
259
260inline auto GetDrawable(const std::shared_ptr<RH3D> &histimpl)
261{
262 return std::make_shared<RHist3Drawable>(histimpl);
263}
264
265inline auto GetDrawable(const std::shared_ptr<RH3I> &histimpl)
266{
267 return std::make_shared<RHist3Drawable>(histimpl);
268}
269
270inline auto GetDrawable(const std::shared_ptr<RH3C> &histimpl)
271{
272 return std::make_shared<RHist3Drawable>(histimpl);
273}
274
275inline auto GetDrawable(const std::shared_ptr<RH3F> &histimpl)
276{
277 return std::make_shared<RHist3Drawable>(histimpl);
278}
279
280} // namespace Experimental
281} // namespace ROOT
282
283#endif
include TDocParser_001 C image html pict1_TDocParser_001 png width
Base class for RHistImplBase that abstracts out the histogram's PRECISION.
Definition RHistImpl.hxx:72
Drawing fill attributes for different objects.
Definition RAttrFill.hxx:27
Drawing line attributes for different objects.
Definition RAttrLine.hxx:27
RAttrMarker & SetStyle(int style)
The style of the marker.
Template class to access single value from drawable or other attributes.
Base class for replies on RDrawableRequest.
Base class for requests which can be submitted from the clients.
const RDrawable::RDisplayContext & GetContext() const
Base class for drawable entities: objects that can be painted on a RPad.
virtual std::unique_ptr< RDisplayItem > Display(const RDisplayContext &)
Creates display item for drawable By default item contains drawable data itself.
Definition RDrawable.cxx:68
RAttrValue< bool > fText
! draw text
std::unique_ptr< RDisplayItem > CreateHistDisplay(const RDisplayContext &) override
RHist1Drawable & Lego(int kind=0)
RHist1Drawable(const std::shared_ptr< HIST > &hist)
RHist1Drawable & Bar(double offset, double width, bool mode3d=false)
RAttrValue< double > fBarOffset
! bar offset
RHist1Drawable & Text(bool on=true)
RAttrValue< double > fBarWidth
! bar width
RHist1Drawable & Error(int kind=0)
RHist2Drawable & Surf(int kind=0)
RHist2Drawable & Contour(int kind=0)
RHist2Drawable & Box(int kind=0)
RHist2Drawable & Lego(int kind=0)
RHist2Drawable(const std::shared_ptr< HIST > &hist)
RAttrValue< bool > fText
! draw text
RHist2Drawable & Text(bool on=true)
std::unique_ptr< RDisplayItem > CreateHistDisplay(const RDisplayContext &) override
std::unique_ptr< RDisplayItem > CreateHistDisplay(const RDisplayContext &) override
RHist3Drawable & Box(int kind=0)
RHist3Drawable(const std::shared_ptr< HIST > &hist)
RHist3Drawable & Sphere(int kind=0)
std::unique_ptr< RDrawableReply > Process() override
const RAttrMarker & GetAttrMarker() const
RAttrText fAttrText
! hist text attributes
std::unique_ptr< RDisplayItem > Display(const RDisplayContext &ctxt) override
Creates display item for drawable By default item contains drawable data itself.
RHistDrawableBase & SetAttrLine(const RAttrLine &attr)
virtual std::unique_ptr< RDisplayItem > CreateHistDisplay(const RDisplayContext &)=0
const RAttrText & GetAttrText() const
RHistDrawableBase & Optimize(bool on=true)
RHistDrawableBase & SetAttrFill(const RAttrFill &fill)
const RAttrLine & GetAttrLine() const
RHistDrawableBase & SetAttrText(const RAttrText &attr)
RAttrFill fAttrFill
! hist fill attributes
void PopulateMenu(RMenuItems &) override
void SetDrawKind(const std::string &kind, int sub=-1)
const RAttrFill & GetAttrFill() const
RHistDrawableBase & SetAttrMarker(const RAttrMarker &attr)
RAttrLine fAttrLine
! hist line attributes
RAttrValue< std::string > fKind
! hist draw kind
RAttrValue< bool > fOptimize
! optimize drawing
RAttrMarker fMarkerAttr
! hist marker attributes
RAttrValue< int > fSub
! hist draw sub kind
Internal::RIOShared< HistImpl_t > fHistImpl
I/O capable reference on histogram.
std::shared_ptr< HistImpl_t > GetHist() const
void CollectShared(Internal::RIOSharedVector_t &vect) override
RHistDrawable(const std::shared_ptr< HIST > &hist)
List of items for object context menu.
std::vector< RIOSharedBase * > RIOSharedVector_t
Definition RDrawable.hxx:52
auto GetDrawable(const std::shared_ptr< DRAWABLE > &drawable)
Central method to insert drawable in list of pad primitives By default drawable placed as is.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...