![]() |
General Programming »
Algorithms & Recipes »
Algorithms
Intermediate
A C++ implementation of an improved contour plotting algorithmBy Jonathan de HalleuxThis class generates isocurves of a user defined function. Curves are drawn to OpenGL dc or stored in line strips. |
VC6, VC7Win2K, WinXP, MFC, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||

This article presents a contour plot class. It is designed to draw iso-contour of a user-defined function f(x,y). I wrote it to integrate it in a graphic library : Plot Graphic Library
The class is based on the algorithm presented in [1] (Check References section). It is basically an improved version of the Level Curve Tracing Algorithm.
The algorithm uses several tuning parameter that the user must choose in order to have the best quality/performance ratio of the algorithm :
// Setting domain x=[0,1], y=[2,3] double pLimits[4]={0,1,2,3,4}; CContour contour; contour.SetLimits(pLimits);
SetFirGrid, GetColFir, GetRowFir. The parameter influence greatly the quality of the contour.
SetSecGrid, GetColSec, GetRowSec. Main contour class. This class cannot be directly but has to be inherited. The inherited class must implement the ExportLine function. To generate contours, use
void Generate()
Make to have set the field function (f(x,y)) before calling this function. The function will call ExportLine for each new segment.
Use this class to draw contours to an OpenGL device context.
Use this class to generate contour and store them as line strip. The user can retrieve each contour and use it as he wills. This function uses to sub-classes :
CLineStrip, a list < int > containing the index of the points.
CLineStripList, a list <CLineStrip*>. The line strip can be accessed by
CLineStripList* GetList(iPane);
where iPane is the index of the contour.
Suppose that we have inherited a class from CContour and overriden ExportLine function.
class CMyContour : CContour { void ExportLine(...); }
Now, first set the function f(x,y):
double myF(double x, double y) { [...] return ... }; CMyContour contour; // Setting f(x,y)=myF contour.SetFieldFcn(myF);
Then set the iso-contour values, i.e.
int n; CMyContour contour; vector<double> vIso(n); for (int i=0;i<n;i++) { ... } // setting iso-lines contour.SetPlanes(vIso);
The contour is ready to be used.
CGLContour as inherited function of CContour.
CGLContour contour;
// Setting up contour : setting f, domain of x,
// isocurve values
[...]
// generating contour
contour.Generate();
Use CListContour as inherited function of CContour. Only the index of the points with respect to second grid are stored in the list. You can access their real value by using GetXi() and GetYi() functions.
CGLContour contour;
// Setting up contour : setting f,
// domain of x, isocurve values
[...]
// generating contour
contour.Generate();
// Retreiving info
CLineStripList* pStripList;
// getting 0-th iso-curve
pStripList=contour.GetLines(0);
ASSERT(pStripList);
// iterating liststrip vertices
CLineStrip::iterator pos;
for (pos=pStripList->begin();
pos != pStripList->end() ; pos++)
{
pStrip=(*pos);
ASSERT(pStrip);
if (pStrip->empty())
continue;
// using info of strip list
// pStrip contains the succesive index of the points
// See CContourGLDoc.OnDraw for further details
[...]
}
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 30 Jul 2002 Editor: Nishant Sivakumar |
Copyright 2002 by Jonathan de Halleux Everything else Copyright © CodeProject, 1999-2009 Web18 | Advertise on the Code Project |