Skip to main content
Email Password   helpLost your password?

Sample Image - contour.jpg

Introduction

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.

Understanding the algorithm

The algorithm uses several tuning parameter that the user must choose in order to have the best quality/performance ratio of the algorithm :

Classes

CContour

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.

CGLContour

Use this class to draw contours to an OpenGL device context.

CListContour

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 :

The line strip can be accessed by

CLineStripList* GetList(iPane);

where iPane is the index of the contour.

How to...

Set up a contour object

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.

Draw contours using OpenGL

Use CGLContour as inherited function of CContour.

    CGLContour contour;
    // Setting up contour : setting f, domain of x, 

    // isocurve values

    [...]
    // generating contour

    contour.Generate();

Retrieve contours in line strip

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

        [...]       
    }

Updates

References

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
QuestionWhy I can not download the demo? Pin
bigsun6909
17:21 10 Jan '08  
GeneralHi,I have a contour ocx here.Would you want to try it?Thank you. Pin
snowedforest
20:49 3 Feb '07  
GeneralBitmap Pin
Sangeetha_J
21:04 25 Jan '07  
GeneralRe: Bitmap Pin
Sangeetha_J
21:09 25 Jan '07  
GeneralImprovement Pin
laurent garnier
0:37 8 Feb '05  
GeneralDemo program crashes on redraw Pin
Ben Discoe
10:56 18 Aug '04  
Generalplotting Contour In an image Pin
Jobaida Begum
8:45 6 Apr '04  
Generalfeature line extraction from contours Pin
sanjayrana
6:21 10 Jun '03  
GeneralImage Processing Pin
Prit
9:50 13 Apr '03  
GeneralRe: Image Processing Pin
Chris Losinger
10:11 13 Apr '03  
GeneralRe: Image Processing Pin
Jonathan de Halleux
22:12 13 Apr '03  
GeneralHelp! Pin
Wang_lei
23:10 5 Sep '02  
GeneralNope Pin
Jonathan de Halleux
22:15 15 Oct '02  
QuestionRe: Nope Pin
bigsun6909
17:19 10 Jan '08  
GeneralRe: Help! Pin
Tigga_1
2:12 23 Feb '07  
GeneralImprovement Pin
C. G. Zhou
21:24 22 Jul '02  
GeneralDid you do it ? Pin
peliikhan
4:20 23 Jul '02  
GeneralRe: Did you do it ? Pin
C.G. Zhou
9:29 25 Jul '02  
GeneralUpdated Pin
Jonathan de Halleux
2:10 31 Jul '02  
GeneralHow to fill the contour with color? Pin
wangchi
21:04 17 Jul '02  
GeneralRe: How to fill the contour with color? Pin
Jonathan de Halleux
23:13 17 Jul '02  
GeneralHow to fill the contour with color? Pin
Anonymous
21:04 17 Jul '02  
GeneralRe: How to fill the contour with color? Pin
Chris Maunder
16:15 31 Jul '02  
GeneralGreat stuff Pin
Jonathan de Halleux
23:06 31 Jul '02  
GeneralRe: Great stuff Pin
Chris Maunder
23:28 31 Jul '02  


Last Updated 30 Jul 2002 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009