Click here to Skip to main content
12,624,603 members (37,123 online)
Click here to Skip to main content


123 bookmarked

A C++ implementation of Douglas-Peucker Line Approximation Algorithm

, 3 Mar 2003
DP Line approximation algorithm is a well-known method to approximate 2D lines. It is quite fast, O(nlog_2(n)) for a n-points line and can drastically compress a data curve. Here, a fully OOP implementation is given.
// viewGL2D.h: interface for the CViewGL2D class.

#if !defined(AFX_VIEW2DCLASS1_H__338966CB_1C93_11D4_8D89_00409503B978__INCLUDED_)
#define AFX_VIEW2DCLASS1_H__338966CB_1C93_11D4_8D89_00409503B978__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "viewGL.h"

/**A 2D view
This type of view is used for 2D graphs or drawings. It is 
written for maximum performance.
class CViewGL2D : public CViewGL  

	void DrawGrids(CWGL* pWGL);

	CViewGL2D(GLdouble _left=0.0,GLdouble _right=1.0,GLdouble _top=1.0,GLdouble _bottom=0.0);
	CViewGL2D& operator = (const CViewGL2D& v2D);
	CViewGL2D(const CViewGL2D& v2D);
	virtual ~CViewGL2D()

	/// rebuilding reshape matrices...
	void Reshape();

	void GetLimits(GLdouble dLimits[])
	{	dLimits[0]=m_dLeft; dLimits[1]=m_dRight; dLimits[2]=m_dBottom; dLimits[3]=m_dTop;};
	void SetLimits(GLdouble dLimits[])
	{	m_dLeft=dLimits[0]; m_dRight=dLimits[1]; m_dBottom=dLimits[2]; m_dTop=dLimits[3];};
	/// initialize the grid list (lists are used in openGL for performance matters)
	void InitGLState();

	/// Debugging stuff
#ifdef _DEBUG
    virtual void AssertValid() const;    // Override
    virtual void Dump( CDumpContext& dc ) const;
    /// Serialization
    void Serialize( CArchive& archive );

	/// left limit of the viewport
	GLdouble m_dLeft;
	/// right limit of the viewport
	GLdouble m_dRight;
	/// top limit of the viewport
	GLdouble m_dTop;
	/// bottom limit of the viewport
	GLdouble m_dBottom;

#endif // !defined(AFX_VIEW2DCLASS1_H__338966CB_1C93_11D4_8D89_00409503B978__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Jonathan de Halleux
United States United States
Jonathan de Halleux is Civil Engineer in Applied Mathematics. He finished his PhD in 2004 in the rainy country of Belgium. After 2 years in the Common Language Runtime (i.e. .net), he is now working at Microsoft Research on Pex (

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.161128.1 | Last Updated 4 Mar 2003
Article Copyright 2002 by Jonathan de Halleux
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid