25 #include "DataPlot.hh"
26 #include <Base/Debug/Exception.hh>
27 #include <Base/ImageUtils/ImageDraw.hh>
35 PlotAreaWidth_ = PlotArea_->
GetWidth();
36 PlotAreaHeight_ = PlotArea_->GetHeight();
43 DrawIda_ = PlotArea_->GetImageDataArray();
85 unsigned int vx1,vy,vx2;
86 WindowToViewport_(MinX_,0,vx1,vy);
87 WindowToViewport_(MaxX_,0,vx2,vy);
88 DrawLine_(vx1,vy,vx2,vy);
96 unsigned int vx,vy1,vy2;
97 WindowToViewport_(0,MinY_,vx,vy1);
98 WindowToViewport_(0,MaxY_,vx,vy2);
99 DrawLine_(vx,vy1,vx,vy2);
107 MaxX_ = float(data.size()-1);
110 MinY_ = numeric_limits<float>::max();
111 MaxY_ = numeric_limits<float>::min();
112 for (
unsigned int i=0;i<data.size();i++){
113 if (data[i]>MaxY_) MaxY_ = data[i];
114 if (data[i]<MinY_) MinY_ = data[i];
117 for (
unsigned int i=0;i<data.size();i++)
118 Plot(
float(i),data[i]);
124 MinX_ = numeric_limits<float>::max();
125 MaxX_ = numeric_limits<float>::min();
126 for (
unsigned int i=0;i<x.size();i++){
127 if (x[i]>MaxX_) MaxX_ = x[i];
128 if (x[i]<MinX_) MinX_ = x[i];
132 MinY_ = numeric_limits<float>::max();
133 MaxY_ = numeric_limits<float>::min();
134 for (
unsigned int i=0;i<y.size();i++){
135 if (y[i]>MaxY_) MaxY_ = y[i];
136 if (y[i]<MinY_) MinY_ = y[i];
139 for (
unsigned int i=0;i<x.size();i++)
146 unsigned int vx=0,vy=0;
147 int res = WindowToViewport_(x,y,vx,vy);
148 if (res<0)
return res;
149 switch (DrawStyle_) {
151 for (
unsigned int c=0;c<ChannelCount_;c++){
153 for (
int dx =-d;dx<d;dx++)
154 for (
int dy =-d;dy<d;dy++){
157 DrawIda_[yy][xx*ChannelCount_+c] = PenColour_[c];
162 if (LastVX_>=0&&LastVY_>=0)
163 DrawLine_(LastVX_,LastVY_,vx,vy);
168 for (
unsigned int c=0;c<ChannelCount_;c++) {
169 for (
int dx =-5;dx<5;dx++) {
171 DrawIda_[vy][xx*ChannelCount_+c] = PenColour_[c];
173 for (
int dy =-5;dy<5;dy++) {
174 int yy = int(vy) + dy;
175 DrawIda_[yy][vx*ChannelCount_+c] = PenColour_[c];
191 for (
unsigned int y=0;y<PlotAreaHeight_;y++)
192 for (
unsigned int x=0;x<PlotAreaWidth_;x++)
193 for (
unsigned int c=0;c<ChannelCount_;c++)
194 DrawIda_[y][x*ChannelCount_+c] = BGColour_[c];
200 float vpw = float(PlotAreaWidth_ - 2*BorderX_);
201 float vph = float(PlotAreaHeight_ - 2*BorderY_);
202 float RangeX = MaxX_ - MinX_;
203 float RangeY = MaxY_ - MinY_;
204 float tx = (wx - MinX_)/RangeX * vpw +
float(BorderX_);
205 float ty = PlotAreaHeight_ - ((wy - MinY_)/RangeY * vph +
float(BorderY_));
206 if (tx <0 || tx > PlotAreaWidth_)
return -1;
207 if (ty <0 || ty > PlotAreaHeight_)
return -2;
void Plot(const std::vector< float > &data)
DataPlot(Image< unsigned char > &PlotArea)
unsigned int GetWidth() const
static int Line(Image< StorageType > &im, const unsigned int start[2], const unsigned int end[2], const StorageType value[])
lines
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
void SetXRange(float min, float max)
void DrawLine_(unsigned int x, unsigned int y, unsigned int x2, unsigned int y2)
void SetYRange(float min, float max)
void SetAutoRange(bool x, bool y)
void SetDrawingStyle(enum DrawingStyle)
int WindowToViewport_(float wx, float wy, unsigned int &vx, unsigned int &vy)