Panda3D

pStatStripChart.h

00001 // Filename: pStatStripChart.h
00002 // Created by:  drose (15Jul00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef PSTATSTRIPCHART_H
00016 #define PSTATSTRIPCHART_H
00017 
00018 #include "pandatoolbase.h"
00019 
00020 #include "pStatGraph.h"
00021 #include "pStatMonitor.h"
00022 #include "pStatClientData.h"
00023 
00024 #include "luse.h"
00025 #include "vector_int.h"
00026 
00027 #include "pmap.h"
00028 
00029 class PStatView;
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //       Class : PStatStripChart
00033 // Description : This is an abstract class that presents the interface
00034 //               for drawing a basic strip-chart, showing the relative
00035 //               value over an interval of time for several different
00036 //               collectors, differentiated by bands of color.
00037 //
00038 //               This class just manages all the strip-chart logic;
00039 //               the actual nuts and bolts of drawing pixels is left
00040 //               to a user-derived class.
00041 ////////////////////////////////////////////////////////////////////
00042 class PStatStripChart : public PStatGraph {
00043 public:
00044   PStatStripChart(PStatMonitor *monitor, PStatView &view,
00045                   int thread_index, int collector_index, int xsize, int ysize);
00046   virtual ~PStatStripChart();
00047 
00048   void new_data(int frame_number);
00049   void update();
00050   bool first_data() const;
00051 
00052   INLINE PStatView &get_view() const;
00053   INLINE int get_collector_index() const;
00054   void set_collector_index(int collector_index);
00055 
00056   INLINE void set_horizontal_scale(double time_width);
00057   INLINE double get_horizontal_scale() const;
00058   INLINE void set_vertical_scale(double value_height);
00059   void set_default_vertical_scale();
00060   void set_auto_vertical_scale();
00061   INLINE double get_vertical_scale() const;
00062 
00063   INLINE void set_scroll_mode(bool scroll_mode);
00064   INLINE bool get_scroll_mode() const;
00065 
00066   INLINE void set_average_mode(bool average_mode);
00067   INLINE bool get_average_mode() const;
00068 
00069   int get_collector_under_pixel(int xpoint, int ypoint);
00070   INLINE int timestamp_to_pixel(double time) const;
00071   INLINE double pixel_to_timestamp(int x) const;
00072   INLINE int height_to_pixel(double value) const;
00073   INLINE double pixel_to_height(int y) const;
00074 
00075   string get_title_text();
00076   bool is_title_unknown() const;
00077 
00078 protected:
00079   class ColorData {
00080   public:
00081     unsigned short _collector_index;
00082     unsigned short _i;
00083     double _net_value;
00084   };
00085   typedef pvector<ColorData> FrameData;
00086   typedef pmap<int, FrameData> Data;
00087 
00088   static void accumulate_frame_data(FrameData &fdata,
00089                                     const FrameData &additional, double weight);
00090   static void scale_frame_data(FrameData &fdata, double factor);
00091 
00092   const FrameData &get_frame_data(int frame_number);
00093   void compute_average_pixel_data(PStatStripChart::FrameData &result, 
00094                                   int &then_i, int &now_i, double now);
00095   double get_net_value(int frame_number) const;
00096   double get_average_net_value() const;
00097 
00098   void changed_size(int xsize, int ysize);
00099   void force_redraw();
00100   void force_reset();
00101   virtual void update_labels();
00102   virtual void normal_guide_bars();
00103 
00104   virtual void clear_region();
00105   virtual void copy_region(int start_x, int end_x, int dest_x);
00106   virtual void begin_draw(int from_x, int to_x);
00107   virtual void draw_slice(int x, int w, const FrameData &fdata);
00108   virtual void draw_empty(int x, int w);
00109   virtual void draw_cursor(int x);
00110   virtual void end_draw(int from_x, int to_x);
00111   virtual void idle();
00112 
00113   INLINE bool is_label_used(int collector_index) const;
00114 
00115 private:
00116   void draw_frames(int first_frame, int last_frame);
00117   void draw_pixels(int first_pixel, int last_pixel);
00118 
00119   void clear_label_usage();
00120   void dec_label_usage(const FrameData &fdata);
00121   void inc_label_usage(const FrameData &fdata);
00122 
00123 protected:
00124   int _thread_index;
00125 
00126 private:
00127   PStatView &_view;
00128   int _collector_index;
00129   bool _scroll_mode;
00130   bool _average_mode;
00131 
00132   Data _data;
00133 
00134   int _next_frame;
00135   bool _first_data;
00136   int _cursor_pixel;
00137 
00138   int _level_index;
00139 
00140   double _time_width;
00141   double _start_time;
00142   double _value_height;
00143   bool _title_unknown;
00144 
00145   typedef vector_int LabelUsage;
00146   LabelUsage _label_usage;
00147 };
00148 
00149 #include "pStatStripChart.I"
00150 
00151 #endif
 All Classes Functions Variables Enumerations