Panda3D
pStatStripChart.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file pStatStripChart.h
10  * @author drose
11  * @date 2000-07-15
12  */
13 
14 #ifndef PSTATSTRIPCHART_H
15 #define PSTATSTRIPCHART_H
16 
17 #include "pandatoolbase.h"
18 
19 #include "pStatGraph.h"
20 #include "pStatMonitor.h"
21 #include "pStatClientData.h"
22 
23 #include "luse.h"
24 #include "vector_int.h"
25 
26 #include "pmap.h"
27 
28 class PStatView;
29 
30 /**
31  * This is an abstract class that presents the interface for drawing a basic
32  * strip-chart, showing the relative value over an interval of time for
33  * several different collectors, differentiated by bands of color.
34  *
35  * This class just manages all the strip-chart logic; the actual nuts and
36  * bolts of drawing pixels is left to a user-derived class.
37  */
38 class PStatStripChart : public PStatGraph {
39 public:
40  PStatStripChart(PStatMonitor *monitor, PStatView &view,
41  int thread_index, int collector_index, int xsize, int ysize);
42  virtual ~PStatStripChart();
43 
44  void new_data(int frame_number);
45  void update();
46  bool first_data() const;
47 
48  INLINE PStatView &get_view() const;
49  INLINE int get_collector_index() const;
50  void set_collector_index(int collector_index);
51 
52  INLINE void set_horizontal_scale(double time_width);
53  INLINE double get_horizontal_scale() const;
54  INLINE void set_vertical_scale(double value_height);
57  INLINE double get_vertical_scale() const;
58 
59  INLINE void set_scroll_mode(bool scroll_mode);
60  INLINE bool get_scroll_mode() const;
61 
62  INLINE void set_average_mode(bool average_mode);
63  INLINE bool get_average_mode() const;
64 
65  int get_collector_under_pixel(int xpoint, int ypoint);
66  INLINE int timestamp_to_pixel(double time) const;
67  INLINE double pixel_to_timestamp(int x) const;
68  INLINE int height_to_pixel(double value) const;
69  INLINE double pixel_to_height(int y) const;
70 
71  std::string get_title_text();
72  bool is_title_unknown() const;
73 
74 protected:
75  class ColorData {
76  public:
77  unsigned short _collector_index;
78  unsigned short _i;
79  double _net_value;
80  };
82  typedef pmap<int, FrameData> Data;
83 
84  static void accumulate_frame_data(FrameData &fdata,
85  const FrameData &additional, double weight);
86  static void scale_frame_data(FrameData &fdata, double factor);
87 
88  const FrameData &get_frame_data(int frame_number);
89  void compute_average_pixel_data(PStatStripChart::FrameData &result,
90  int &then_i, int &now_i, double now);
91  double get_net_value(int frame_number) const;
92  double get_average_net_value() const;
93 
94  void changed_size(int xsize, int ysize);
95  void force_redraw();
96  void force_reset();
97  virtual void update_labels();
98  virtual void normal_guide_bars();
99 
100  virtual void clear_region();
101  virtual void copy_region(int start_x, int end_x, int dest_x);
102  virtual void begin_draw(int from_x, int to_x);
103  virtual void draw_slice(int x, int w, const FrameData &fdata);
104  virtual void draw_empty(int x, int w);
105  virtual void draw_cursor(int x);
106  virtual void end_draw(int from_x, int to_x);
107  virtual void idle();
108 
109  INLINE bool is_label_used(int collector_index) const;
110 
111 private:
112  void draw_frames(int first_frame, int last_frame);
113  void draw_pixels(int first_pixel, int last_pixel);
114 
115  void clear_label_usage();
116  void dec_label_usage(const FrameData &fdata);
117  void inc_label_usage(const FrameData &fdata);
118 
119 protected:
120  int _thread_index;
121 
122 private:
123  PStatView &_view;
124  int _collector_index;
125  bool _scroll_mode;
126  bool _average_mode;
127 
128  Data _data;
129 
130  int _next_frame;
131  bool _first_data;
132  int _cursor_pixel;
133 
134  int _level_index;
135 
136  double _time_width;
137  double _start_time;
138  double _value_height;
139  bool _title_unknown;
140 
141  typedef vector_int LabelUsage;
142  LabelUsage _label_usage;
143 };
144 
145 #include "pStatStripChart.I"
146 
147 #endif
PStatStripChart::pixel_to_height
double pixel_to_height(int y) const
Converts a vertical pixel offset to a value (a "height" in the strip chart).
Definition: pStatStripChart.I:155
pStatClientData.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatStripChart::set_scroll_mode
void set_scroll_mode(bool scroll_mode)
Changes the scroll_mode flag.
Definition: pStatStripChart.I:82
PStatStripChart::get_view
PStatView & get_view() const
Returns the View this chart represents.
Definition: pStatStripChart.I:18
pvector
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
vector_int.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pmap< int, FrameData >
PStatStripChart::get_collector_under_pixel
int get_collector_under_pixel(int xpoint, int ypoint)
Return the collector index associated with the particular band of color at the indicated pixel locati...
Definition: pStatStripChart.cxx:201
PStatStripChart::get_vertical_scale
double get_vertical_scale() const
Returns total value the height of the vertical axis represents.
Definition: pStatStripChart.I:72
PStatStripChart::get_collector_index
int get_collector_index() const
Returns the particular collector whose data this strip chart reflects.
Definition: pStatStripChart.I:26
PStatStripChart
This is an abstract class that presents the interface for drawing a basic strip-chart,...
Definition: pStatStripChart.h:38
PStatStripChart::get_average_mode
bool get_average_mode() const
Returns the current state of the average_mode flag.
Definition: pStatStripChart.I:121
PStatStripChart::get_scroll_mode
bool get_scroll_mode() const
Returns the current state of the scroll_mode flag.
Definition: pStatStripChart.I:96
PStatView
A View boils down the frame data to a linear list of times spent in a number of different Collectors,...
Definition: pStatView.h:31
pmap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatStripChart::first_data
bool first_data() const
Returns true if the chart has seen its first data appear on it, false if it is still a virgin chart.
Definition: pStatStripChart.cxx:127
PStatStripChart::update
void update()
Updates the chart with the latest data.
Definition: pStatStripChart.cxx:84
PStatStripChart::set_average_mode
void set_average_mode(bool average_mode)
Changes the average_mode flag.
Definition: pStatStripChart.I:107
luse.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatStripChart::timestamp_to_pixel
int timestamp_to_pixel(double time) const
Converts a timestamp to a horizontal pixel offset.
Definition: pStatStripChart.I:129
PStatStripChart::set_default_vertical_scale
void set_default_vertical_scale()
Sets the vertical scale according to the suggested scale of the base collector, if any,...
Definition: pStatStripChart.cxx:152
PStatStripChart::height_to_pixel
int height_to_pixel(double value) const
Converts a value (i.e.
Definition: pStatStripChart.I:146
pStatGraph.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatStripChart::is_title_unknown
bool is_title_unknown() const
Returns true if get_title_text() has never yet returned an answer, false if it has.
Definition: pStatStripChart.cxx:291
PStatStripChart::set_vertical_scale
void set_vertical_scale(double value_height)
Changes the value the height of the vertical axis represents.
Definition: pStatStripChart.I:60
PStatGraph
This is an abstract base class for several different kinds of graphs that have a few things in common...
Definition: pStatGraph.h:33
PStatStripChart::get_horizontal_scale
double get_horizontal_scale() const
Returns the amount of total time the width of the horizontal axis represents.
Definition: pStatStripChart.I:51
PStatStripChart::set_auto_vertical_scale
void set_auto_vertical_scale()
Sets the vertical scale to make all the data visible.
Definition: pStatStripChart.cxx:170
pStatMonitor.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandatoolbase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatStripChart::set_collector_index
void set_collector_index(int collector_index)
Changes the collector represented by this strip chart.
Definition: pStatStripChart.cxx:136
PStatMonitor
This is an abstract class that presents the interface to any number of different front-ends for the s...
Definition: pStatMonitor.h:39
PStatStripChart::set_horizontal_scale
void set_horizontal_scale(double time_width)
Changes the amount of time the width of the horizontal axis represents.
Definition: pStatStripChart.I:35
pStatStripChart.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatStripChart::pixel_to_timestamp
double pixel_to_timestamp(int x) const
Converts a horizontal pixel offset to a timestamp.
Definition: pStatStripChart.I:137
PStatStripChart::get_title_text
std::string get_title_text()
Returns the text suitable for the title label on the top line.
Definition: pStatStripChart.cxx:255
PStatStripChart::new_data
void new_data(int frame_number)
Indicates that new data has become available.
Definition: pStatStripChart.cxx:73