25 #include <Base/Common/W32Compat.hh>
26 #include <Base/ImageUtils/ImageDraw.hh>
27 #include "GraphPlotter.hh"
47 bAutoDetectBordersX_=
true;
48 bAutoDetectBordersY_=
true;
50 bFixXAxisToBottom_=
true;
51 bFixYAxisToLeft_=
true;
85 bAutoDetectBordersX_=
false;
97 bAutoDetectBordersY_=
false;
134 bFixXAxisToBottom_=fixAxes;
135 bFixYAxisToLeft_=fixAxes;
140 dLineThickness_ = thickness;
145 dTextThickness_ = thickness;
154 xTics_ = yTics_ = 10;
160 bAutoDetectBordersX_=
true;
161 bAutoDetectBordersY_=
true;
163 bFixXAxisToBottom_=
true;
164 bFixYAxisToLeft_=
true;
176 xCoeff_ = width_/(xMax_-xMin_);
177 yCoeff_ = height_/(yMax_-yMin_);
183 xOffset_ = int(-rint(xMin_*xCoeff_))+10;
184 yOffset_ = int(rint(yMin_*yCoeff_))+height_-20;
189 if(!image_.IsEmpty()) image_.Release();
191 image_.Init(width_,height_,3);
192 unsigned char color[] ={255,255,255};
193 image_.FillImageWithConstValue(color);
195 int xAxisInc = abs(
int(rint((xMax_-xMin_)/
double(xTics_))));
196 int yAxisInc = abs(
int(rint((yMax_-yMin_)/
double(yTics_))));
199 unsigned int xTicsPos = 0;
200 if(yOffset_>=10 && yOffset_ < (
int)height_-20)
203 xTicsPos = height_-20;
205 if(bFixXAxisToBottom_)
206 xTicsPos = height_-20;
214 black,dLineThickness_);
222 black,dLineThickness_);
226 if(xMin_>=0) i = int(xMin_);
228 for(; i<=xMax_;i+=xAxisInc){
229 stringstream message; message<<i;
231 Text (image_,message.str(),int(rint(i*xCoeff_))+xOffset_+5,xTicsPos+15,
232 black,CV_FONT_HERSHEY_SIMPLEX,0.5,0.5,0,dTextThickness_);
235 int(rint(i*xCoeff_))+xOffset_,
237 int(rint(i*xCoeff_))+xOffset_,
238 xTicsPos+15,black,dLineThickness_);
243 int(rint(i*xCoeff_))+xOffset_,
245 int(rint(i*xCoeff_))+xOffset_,
252 for(i=0;i>=xMin_;i-=xAxisInc){
253 stringstream message; message<<i;
255 Text (image_,message.str(),int(rint(i*xCoeff_))+xOffset_+5,xTicsPos+15,
256 black,CV_FONT_HERSHEY_SIMPLEX,0.5,0.5,0,dTextThickness_);
259 int(rint(i*xCoeff_))+xOffset_,
261 int(rint(i*xCoeff_))+xOffset_,
262 xTicsPos+15,black,dLineThickness_);
267 int(rint(i*xCoeff_))+xOffset_,
269 int(rint(i*xCoeff_))+xOffset_,
276 Text(image_,xLabel_,width_-250,xTicsPos-15, black,
277 CV_FONT_HERSHEY_SIMPLEX,0.5,0.5,0,dTextThickness_);
281 unsigned int yTicsPos = 0;
282 if(xOffset_>=10 && xOffset_ < (
int)width_-10)
292 height_,black,dLineThickness_);
293 if(yMin_>=0) i = int(yMin_);
296 for(; i<=yMax_;i+=yAxisInc){
297 stringstream message; message<<i;
299 Text (image_,message.str(),
301 yOffset_-int(rint(i*yCoeff_))-5,black,CV_FONT_HERSHEY_SIMPLEX,0.5,0.5,0,dTextThickness_);
305 yOffset_-
int(rint(i*yCoeff_)),
307 yOffset_-
int(rint(i*yCoeff_)), black,dLineThickness_);
313 yOffset_-
int(rint(i*yCoeff_)),
315 yOffset_-
int(rint(i*yCoeff_)), black);
320 for(i=0; i>=yMin_;i-=yAxisInc){
321 stringstream message; message<<i;
323 Text (image_,message.str(),
325 yOffset_-int(rint(i*yCoeff_))-5,black,CV_FONT_HERSHEY_SIMPLEX,0.5,0.5,0,dTextThickness_);
329 yOffset_-
int(rint(i*yCoeff_)),
331 yOffset_-
int(rint(i*yCoeff_)), black,dLineThickness_);
337 yOffset_-
int(rint(i*yCoeff_)),
339 yOffset_-
int(rint(i*yCoeff_)), black);
347 Text(image_,yLabel_,yTicsPos+50,20,black,CV_FONT_HERSHEY_SIMPLEX,0.5,0.5,0,dTextThickness_);
354 Draw(std::vector<double>& xValues,
355 std::vector<double>& yValues,
360 if(bAutoDetectBordersX_){
361 for(
unsigned int i=0;i<xValues.size();i++){
362 if(xValues[i] < xMin_) xMin_ = xValues[i];
363 if(xValues[i] > xMax_) xMax_ = xValues[i];
368 if(bAutoDetectBordersY_){
369 for(
unsigned int i=0;i<yValues.size();i++){
370 if(yValues[i] < yMin_) yMin_ = yValues[i];
371 if(yValues[i] > yMax_) yMax_ = yValues[i];
384 unsigned char tmpColor[3];
385 tmpColor[0] = color[0];
386 tmpColor[1] = color[1];
387 tmpColor[2] = color[2];
388 for(
unsigned i=0;i<xValues.size();i++){
391 int(rint(xValues[i]*xCoeff_))+xOffset_,
392 yOffset_-
int(rint(yValues[i]*yCoeff_)),
401 for(
unsigned i=0;i<xValues.size();i++){
405 int(rint(oldx*xCoeff_))+xOffset_,
406 yOffset_-
int(rint(oldy*yCoeff_)),
407 int(rint(xValues[i]*xCoeff_))+xOffset_,
408 yOffset_-
int(rint(yValues[i]*yCoeff_)),color,dLineThickness_);
425 Draw(std::vector<double>& xValues,
426 std::vector<double>& yValues,
427 std::vector<double>& yStdDeviation,
431 std::vector<string> *labels) {
434 if(bAutoDetectBordersX_){
435 for(
unsigned int i=0;i<xValues.size();i++){
436 if(xValues[i] < xMin_) xMin_ = xValues[i];
437 if(xValues[i] > xMax_) xMax_ = xValues[i];
442 if(bAutoDetectBordersY_){
443 for(
unsigned int i=0;i<yStdDeviation.size();i++){
444 if(-(yStdDeviation[i]+yValues[i]) < yMin_) yMin_ = -(yStdDeviation[i]+yValues[i]);
445 if(yStdDeviation[i]+yValues[i] > yMax_) yMax_ = yStdDeviation[i]+yValues[i];
454 for(
unsigned i=0;i<yStdDeviation.size();i++){
458 int(rint(xValues[i]*xCoeff_))+xOffset_,
459 yOffset_-
int(rint(yValues[i]*yCoeff_))-
460 int(rint(yStdDeviation[i]*yCoeff_)),
461 int(rint(xValues[i]*xCoeff_))+xOffset_,
462 yOffset_-
int(rint(yValues[i]*yCoeff_))+
463 int(rint(yStdDeviation[i]*yCoeff_)),
464 colorSTD,dLineThickness_);
468 int(rint(xValues[i]*xCoeff_))-5+xOffset_,
469 yOffset_-
int(rint(yValues[i]*yCoeff_))-
470 int(rint(yStdDeviation[i]*yCoeff_)),
471 int(rint(xValues[i]*xCoeff_))+5+xOffset_,
472 yOffset_-
int(rint(yValues[i]*yCoeff_))-
473 int(rint(yStdDeviation[i]*yCoeff_)),
474 colorSTD,dLineThickness_);
479 int(rint(xValues[i]*xCoeff_))-5+xOffset_,
480 yOffset_-
int(rint(yValues[i]*yCoeff_))+
481 int(rint(yStdDeviation[i]*yCoeff_)),
482 int(rint(xValues[i]*xCoeff_))+5+xOffset_,
483 yOffset_-
int(rint(yValues[i]*yCoeff_))+
484 int(rint(yStdDeviation[i]*yCoeff_)),
485 colorSTD,dLineThickness_);
486 if (labels != NULL) {
487 if (labels->size() <= i) {
488 BIASWARN(
"label names not complete");
490 BIAS::ImageDraw<unsigned char>::Text(image_, (*labels)[i],
int(rint(xValues[i]*xCoeff_))+5+xOffset_,yOffset_-
int(rint(yValues[i]*yCoeff_))+
int(rint(yStdDeviation[i]*yCoeff_)),colorSTD);
493 Draw(xValues,yValues,color,ds);
499 for(
unsigned i=0;i<labels_.size();i++){
void SetLineThickness(unsigned thickness)
void SetYTics(unsigned ytics)
void SetAxesToYLeftAndXBottom(bool fixAxes)
void SetYLabel(std::string label)
BIAS::Image< unsigned char > * GetImage()
~GraphPlotter()
destructor
void SetYRange(double minY, double maxY)
static int CircleCenterFilled(Image< StorageType > &im, unsigned int CenterX, unsigned int CenterY, unsigned int Radius, const StorageType Value[])
draws a filled circle using Value
void SetImageSize(unsigned width, unsigned height)
void SetDrawGrid(bool drawGrid)
void SetXRange(double minX, double maxX)
BIAS::Image< unsigned char > GetCopyOfImage()
void SetTextThickness(unsigned thickness)
void Draw(std::vector< double > &xValues, std::vector< double > &yValues, BIAS::ColourRGB< unsigned char > color, BIAS::GraphPlotter_DrawStyle=DS_POINT_1)
draws xvalues against yvalues
static int Line(Image< StorageType > &im, const unsigned int start[2], const unsigned int end[2], const StorageType value[])
lines
void SetXTics(unsigned xtics)
GraphPlotter()
constructor
void SetXLabel(std::string label)
static void Text(BIAS::Image< StorageType > &dstImg, const std::string &message, const int &posX=0, const int &posY=20, const ColourRGB< StorageType > &colorRGB=ColourRGB< StorageType >(255, 255, 255), const int fontface=1, const double hscale=1.0, const double vscale=1.0, const double shear=0, const int thickness=1, const int linetype=8)
OpenCV: Draw Text into image.