GNU Radio 3.3.0 C++ API
Waterfall3DDisplayPlot.h
Go to the documentation of this file.
00001 #ifndef WATERFALL_3D_DISPLAY_PLOT_HPP
00002 #define WATERFALL_3D_DISPLAY_PLOT_HPP
00003 
00004 #include <cstdio>
00005 #include <highResTimeFunctions.h>
00006 
00007 #include <waterfallGlobalData.h>
00008 #include <qwt3d_surfaceplot.h>
00009 
00010 #include <qwt3d_color.h>
00011 #include <qwt_color_map.h>
00012 
00013 class Waterfall3DColorMap: public Qwt3D::Color, public QwtLinearColorMap
00014 {
00015 public:
00016   Waterfall3DColorMap();
00017   virtual ~Waterfall3DColorMap();
00018 
00019   virtual Qwt3D::RGBA operator()(double x, double y, double z)const;
00020   virtual Qwt3D::ColorVector& createVector(Qwt3D::ColorVector& vec);
00021 
00022   virtual void SetInterval(const double minValue, const double maxValue);
00023 
00024 protected:
00025   
00026 private:
00027   QwtDoubleInterval _interval;
00028 };
00029 
00030 class Waterfall3DDisplayPlot:public Qwt3D::SurfacePlot{
00031   Q_OBJECT
00032 
00033   protected:
00034   class IntensityScale:public Qwt3D::LinearScale{
00035 
00036   friend class Qwt3D::Axis;
00037   friend class Qwt3D::qwt3d_ptr<Qwt3D::Scale>;
00038 
00039   private:
00040     double _floor;
00041 
00042   public:
00043     explicit IntensityScale(const double newFloor):_floor(newFloor){ }
00044     virtual ~IntensityScale(){}
00045 
00046     virtual QString ticLabel(unsigned int idx) const{
00047       if (idx<majors_p.size())
00048         {
00049           return QString("%1").arg( majors_p[idx] + GetFloorValue(), 0, 'f', 0 );
00050         }
00051       return QString("");
00052     }
00053 
00054     virtual double GetFloorValue()const{ return _floor; }
00055     virtual void SetFloorValue(const double newFloor){ _floor = newFloor; }
00056 
00057     //! Returns a new heap based object utilized from qwt3d_ptr
00058     Scale* clone() const {return new IntensityScale(*this);} 
00059   };
00060   
00061   class TimeScale:public Qwt3D::LinearScale{
00062 
00063     friend class Qwt3D::Axis;
00064     friend class Qwt3D::qwt3d_ptr<Qwt3D::Scale>;
00065     friend class Waterfall3DDisplayPlot;
00066 
00067   private:
00068     Waterfall3DDisplayPlot* _plot;
00069 
00070   public:
00071     TimeScale(Waterfall3DDisplayPlot* plot ):_plot(plot){
00072     }
00073     virtual ~TimeScale(){
00074     }
00075 
00076     virtual QString ticLabel(unsigned int idx) const{
00077       if (idx<majors_p.size())
00078         {
00079           const timespec markerTime = timespec_add(_plot->_dataTimestamp,
00080                                                    -(_plot->_timePerFFT) * majors_p[idx]);
00081           struct tm timeTm;
00082           gmtime_r(&markerTime.tv_sec, &timeTm);
00083           
00084           char* timeBuffer = new char[128];
00085           snprintf(timeBuffer, 128, "%02d:%02d:%02d.%03ld", timeTm.tm_hour,
00086                    timeTm.tm_min, timeTm.tm_sec, (markerTime.tv_nsec / 1000000));
00087           QString returnBuffer(timeBuffer);
00088           delete[] timeBuffer;
00089           return returnBuffer;
00090         }
00091       return QString("");
00092     }
00093 
00094     //! Returns a new heap based object utilized from qwt3d_ptr
00095     Scale* clone() const {return new TimeScale(*this);}
00096   };
00097 
00098   class FrequencyScale: public Qwt3D::LinearScale{
00099 
00100     friend class Qwt3D::Axis;
00101     friend class Qwt3D::qwt3d_ptr<Qwt3D::Scale>;
00102   private:
00103     double _centerFrequency;
00104     bool _useCenterFrequencyFlag;
00105   public:
00106     FrequencyScale(bool useCenterFrequencyFlag, double centerFrequency)
00107       : _centerFrequency(centerFrequency),_useCenterFrequencyFlag(useCenterFrequencyFlag)
00108       {}
00109 
00110     virtual ~FrequencyScale(){}
00111 
00112     virtual QString ticLabel(unsigned int idx) const
00113     {
00114       if (idx<majors_p.size())
00115         {
00116           if(!_useCenterFrequencyFlag){
00117             return QString("%1").arg(  majors_p[idx], 0, 'f', 0 );
00118 
00119           }
00120           else{
00121             return QString("%1").arg(  (majors_p[idx] + _centerFrequency)/1000.0, 0, 'f', 3 );
00122           }
00123         }
00124       return QString("");
00125     }
00126 
00127     //! Returns a new heap based object utilized from qwt3d_ptr
00128     Scale* clone() const {return new FrequencyScale(*this);}
00129   };
00130 
00131 public:
00132   Waterfall3DDisplayPlot(QWidget*);
00133   virtual ~Waterfall3DDisplayPlot();
00134                                                 
00135   void Init();
00136   void Reset();
00137 
00138   bool loadFromData(double** data, unsigned int columns, unsigned int rows
00139                     ,double minx, double maxx, double miny, double maxy);
00140 
00141   void SetFrequencyRange(const double, const double,
00142                          const double, const bool,
00143                          const double units, const std::string &strunits);
00144   double GetStartFrequency()const;
00145   double GetStopFrequency()const;
00146 
00147   void PlotNewData(const double* dataPoints, const int64_t numDataPoints,
00148                    const double timePerFFT, const timespec timestamp,
00149                    const int droppedFrames);
00150 
00151   void SetIntensityRange(const double minIntensity, const double maxIntensity);
00152 
00153   virtual void replot(void);
00154 
00155   int GetIntensityColorMapType()const;
00156   void SetIntensityColorMapType( const int, const QColor,
00157                                  const QColor, const bool forceFlag = false,
00158                                  const bool noReplotFlag = false );
00159   const QColor GetUserDefinedLowIntensityColor()const;
00160   const QColor GetUserDefinedHighIntensityColor()const;
00161 
00162   static const int INTENSITY_COLOR_MAP_TYPE_MULTI_COLOR = 0;
00163   static const int INTENSITY_COLOR_MAP_TYPE_WHITE_HOT = 1;
00164   static const int INTENSITY_COLOR_MAP_TYPE_BLACK_HOT = 2;
00165   static const int INTENSITY_COLOR_MAP_TYPE_INCANDESCENT = 3;
00166   static const int INTENSITY_COLOR_MAP_TYPE_USER_DEFINED = 4;
00167 
00168 public slots:
00169   void resizeSlot( QSize *s );
00170 
00171 
00172 signals:
00173   void UpdatedLowerIntensityLevel(const double);
00174   void UpdatedUpperIntensityLevel(const double);
00175 
00176 protected:
00177 
00178   double _startFrequency;
00179   double _stopFrequency;
00180 
00181   Waterfall3DData* _waterfallData;
00182 
00183   timespec _lastReplot;
00184 
00185   int64_t _numPoints;
00186 
00187   double _displayIntervalTime;
00188 
00189   int _intensityColorMapType;
00190   QColor _userDefinedLowIntensityColor;
00191   QColor _userDefinedHighIntensityColor;
00192 
00193   bool _useCenterFrequencyFlag;
00194   double _centerFrequency;
00195 
00196   timespec _dataTimestamp;
00197   double _timePerFFT;
00198   bool _initialized;
00199 
00200   bool _createCoordinateSystemFlag;
00201 
00202 private:
00203 
00204 };
00205 
00206 #endif /* WATERFALL_3D_DISPLAY_PLOT_HPP */