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