Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » Geom/PlotterCtrl fixed plot
Geom/PlotterCtrl fixed plot [message #10483] Wed, 11 July 2007 18:32 Go to next message
pap2k is currently offline  pap2k
Messages: 8
Registered: June 2007
Promising Member
Hi,

PloterCtrl is a very impressive way to plot in a floting point draw.

UpClassing Geom/Plotter i do not understant how fix the coordinate of the draw windwows...
For exemple, if i resize the windows, the floating point zone increase !
How to fix it ?

In MyPlot::Plot(Plotter plotter) implementation i've try to set my plotter whitout succes.
Is it the only way ?
Re: Geom/PlotterCtrl fixed plot [message #10489 is a reply to message #10483] Thu, 12 July 2007 07:58 Go to previous messageGo to next message
rylek is currently offline  rylek
Messages: 79
Registered: November 2005
Member
Hello!

It should be possible to reprogram the Plotter's transform matrix within the Plot method, however under normal circumstances this is usually not desirable as it makes the drawing out of sync with logical scaling information stored in the PlotterCtrl object. Normally PlotterCtrl doesn't change the scale when window size changes, it merely repositions the origin in order to re-align the plot according to user-set alignment parameters. It is, however, possible, and in your case perhaps the most logical, to override the Layout method and use one of the Zoom family of methods to recalculate the view parameters according to current view size.

Also please remember that PlotterCtrl can work either isotropically, when AspectRatio is set to some non-zero value and the scaling factors for both coordinate axes are kept in sync, or anisotropically (AspectRatio = 0), when the axes are completely independent. The former case is handy e.g. for drawing maps or other birds eye views where you don't want to deform drawing proportions (a square always looks like a square), whereas the latter is natural e.g. for charts or diagrams with different units of abscissa and ordinata where the fixed aspect ratio doesn't make much sense (and so deforming a square to a parallelogram is no problem).

When reprogramming Plotter manually, please remember to use one of the Set methods (or the constructors). It is possible to rewrite the transform matrix by hand but it is a dangerous technique as certain derived values are calculated using Set (most notably, there is an optimization which checks for tilt / rotation in the transform matrix and when the matrix describes just a 'straight' rescale operation, a faster version of the transform methods is activated).

Regards

Tomas
Re: Geom/PlotterCtrl fixed plot [message #10490 is a reply to message #10489] Thu, 12 July 2007 08:13 Go to previous messageGo to next message
pap2k is currently offline  pap2k
Messages: 8
Registered: June 2007
Promising Member
Thank's for your quick answer, i'm trying to solve my problem using zoom view.

Regards
Re: Geom/PlotterCtrl fixed plot [message #10492 is a reply to message #10490] Thu, 12 July 2007 10:29 Go to previous message
pap2k is currently offline  pap2k
Messages: 8
Registered: June 2007
Promising Member
Here it is a simple math draw sample :
#ifndef _Math_Math_h
#define _Math_Math_h

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

#define LAYOUTFILE <Math/Math.lay>
#include <CtrlCore/lay.h>


#include <CtrlLib/CtrlLib.h>
#include <Geom/Ctrl/GeomCtrl.h>
#include <sstream>

struct MahtPlot : public PlotterCtrl
{

struct draw_point_pos
{
draw_point_pos( Plotter* _plotter) : plotter_(_plotter) {}
void operator()(const Pointf& _p)
{
//std::ostringstream msg;
//msg << "(" << _p.x <<"; "<< _p.y << ")";
//plotter_->GetDraw().DrawText( plotter_->LtoP(_p).x, plotter_->LtoP(_p).y, msg.str().c_str());
plotter_->GetDraw().DrawEllipse(plotter_->LtoP(_p).x, plotter_->LtoP(_p).y, 2,2);

}
Plotter* plotter_;
};

void Plot(Plotter& plotter)
{
plotter.GetDraw().DrawRect(
Rect(plotter.LtoP(Pointf(left_, top_)),plotter.LtoP(Pointf(rigth_, bottom_))), Yellow());

draw_point_pos point_plot(&plotter);
for(double x = left_; x <= rigth_; x += x_step_)
point_plot(Pointf(x, MathFunc(x)));
}

double MathFunc(const double& _x)
{
return _x*_x;
}

MahtPlot(const double& _left = -10.0,
const double& _top = 10.0,
const double& _rigth = 10.0,
const double& _bottom = -10.0,
const double& _x_step = 0.1) :
left_(_left), top_ (_top), rigth_(_rigth), bottom_(_bottom), x_step_(_x_step)
{
buffer_paint = true;
ShowScroll(false);
Rectf bonding_box(Pointf(left_, top_),Pointf(rigth_, bottom_));
SetExtent(bonding_box);
UserZoom(bonding_box, false);
}

double left_;
double top_ ;
double rigth_;
double bottom_;
double x_step_;
};



class MathGraph : public WithMathGraphLayout<TopWindow> {
public:
typedef MathGraph CLASSNAME;
MathGraph()
{
CtrlLayout(*this, "Window title");
AddFrame(status_);
this->Sizeable();
Add(plot_.SizePos());
}
StatusBar status_;
MahtPlot plot_;
};

#endif

What's wrong whith this simple code ?
(-> why there is no Yellow rectangle on sreen ?)
(-> why the userzoom isn't realy set to -10 -> 10 ?)


Is there somewhere sample of use of PlotterCtrl ?

Thank's in advance.

Previous Topic: How to read from and write to a table in a file (CSV)?
Next Topic: Cross Compile UPP for armv5l arch
Goto Forum:
  


Current Time: Fri Mar 29 15:03:55 CET 2024

Total time taken to generate the page: 0.01275 seconds