Results 1 to 10 of 10

Thread: Is it possible to use a deque as plot data?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Join Date
    Jun 2011
    Posts
    38
    Thanks
    8
    Thanked 1 Time in 1 Post

    Default Re: Is it possible to use a deque as plot data?

    there was a dangerous bug in PlotDataBuffer.cpp (initializing min and max with 0.0 instead of numerical limits).
    Also I wrote minY_ instead of maxY_ in one getter.

    Unfortuantely I cannot edit it anymore, so here is the new version, just in case that some1 wants to use it:

    PlotDataBuffer.cpp
    Qt Code:
    1. #include "PlotDataBuffer.h"
    2. #include <cmath>
    3. #include <algorithm>
    4. #include <limits>
    5.  
    6. using namespace std;
    7.  
    8. class MinMax
    9. {
    10. public:
    11. MinMax():
    12. minX_(numeric_limits<double>::max()),
    13. maxX_(numeric_limits<double>::min()),
    14. minY_(numeric_limits<double>::max()),
    15. maxY_(numeric_limits<double>::min()),
    16. empty_(true)
    17. {
    18.  
    19. }
    20.  
    21. void operator()(const QPointF& p)
    22. {
    23. empty_ = false;
    24. minX_ = min(minX_, p.x());
    25. maxX_ = max(maxX_, p.x());
    26.  
    27. minY_ = min(minY_, p.y());
    28. maxY_ = max(maxY_, p.y());
    29. }
    30.  
    31. double getMinX() const
    32. {
    33. if(empty_)
    34. {
    35. return 0.0;
    36. }
    37. return minX_;
    38. }
    39.  
    40. double getMaxX() const
    41. {
    42. if(empty_)
    43. {
    44. return 0.0;
    45. }
    46. return maxX_;
    47. }
    48.  
    49. double getMinY() const
    50. {
    51. if(empty_)
    52. {
    53. return 0.0;
    54. }
    55. return minY_;
    56. }
    57.  
    58. double getMaxY() const
    59. {
    60. if(empty_)
    61. {
    62. return 0.0;
    63. }
    64. return maxY_;
    65. }
    66.  
    67. private:
    68. double minX_;
    69. double maxX_;
    70.  
    71. double minY_;
    72. double maxY_;
    73.  
    74. bool empty_;
    75. };
    76.  
    77. PlotDataBuffer::PlotDataBuffer(int windowSize):
    78. minX_(0.0),
    79. maxX_(0.0),
    80. minY_(0.0),
    81. maxY_(0.0),
    82. windowSize_(windowSize),
    83. minMaxValid_(true)
    84. {
    85.  
    86. }
    87.  
    88. void PlotDataBuffer::setWindowSize(int windowSize)
    89. {
    90. if(windowSize == windowSize_)
    91. {
    92. return;
    93. }
    94. windowSize_ = windowSize;
    95. while(deque_.size() > windowSize_)
    96. {
    97. deque_.pop_front();
    98. }
    99. minMaxValid_ = false;
    100. }
    101.  
    102. void PlotDataBuffer::clear()
    103. {
    104. deque_.clear();
    105. }
    106.  
    107. QRectF PlotDataBuffer::boundingRect() const
    108. {
    109. makeMinMaxValid();
    110. return QRectF(minX_, minY_, maxX_ - minX_, maxY_ - minY_);
    111. }
    112.  
    113. void PlotDataBuffer::addData(const QPointF& p)
    114. {
    115. deque_.push_back(p);
    116. while(deque_.size() > windowSize_)
    117. {
    118. deque_.pop_front();
    119. }
    120. minMaxValid_ = false;
    121. }
    122.  
    123. void PlotDataBuffer::makeMinMaxValid() const
    124. {
    125. if(!minMaxValid_)
    126. {
    127. MinMax m = for_each(deque_.begin(), deque_.end(), MinMax());
    128. minX_ = m.getMinX();
    129. maxX_ = m.getMaxX();
    130. minY_ = m.getMinY();
    131. maxY_ = m.getMaxY();
    132. minMaxValid_ = true;
    133. }
    134. }
    135.  
    136. double PlotDataBuffer::getMinX() const
    137. {
    138. makeMinMaxValid();
    139. return minX_;
    140. }
    141.  
    142. double PlotDataBuffer::getMaxX() const
    143. {
    144. makeMinMaxValid();
    145. return maxX_;
    146. }
    147.  
    148. double PlotDataBuffer::getMinY() const
    149. {
    150. makeMinMaxValid();
    151. return minY_;
    152. }
    153.  
    154. double PlotDataBuffer::getMaxY() const
    155. {
    156. makeMinMaxValid();
    157. return maxY_;
    158. }
    To copy to clipboard, switch view to plain text mode 

    Edit: I discovered a serious problem with the QwtSeriesData API. It takes ownership of the data...
    I want to use one of my buffers for more than one plotcurve, which does not work with this ownership problem.
    I'm thinking of employing some kind of smart pointer and share the data of the PlotDataBuffer to work around this problem.

    Edit2: What does happen if first call setData and later call setRawSamples?
    Last edited by P@u1; 26th July 2011 at 13:26.

Similar Threads

  1. Data Plot Question
    By gokceng in forum Newbie
    Replies: 1
    Last Post: 18th July 2011, 16:06
  2. retrieving data from a QWT plot
    By mobucl in forum Qwt
    Replies: 1
    Last Post: 26th May 2011, 13:00
  3. Simple Plot after Inputing some Data
    By thebrute in forum Qwt
    Replies: 0
    Last Post: 18th August 2010, 14:29
  4. 2D array data plot!
    By kahramonj in forum Qwt
    Replies: 3
    Last Post: 21st March 2009, 11:48
  5. plot only subset of the data
    By pospiech in forum Qwt
    Replies: 3
    Last Post: 14th April 2008, 21:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.