Click here to Skip to main content
15,891,864 members
Articles / Programming Languages / C++

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

Rate me:
Please Sign up or sign in to vote.
4.87/5 (39 votes)
3 Mar 20037 min read 424K   13.9K   126  
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  
{
DECLARE_SERIAL(CViewGL2D);

public:
	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;
#endif
    /// Serialization
    void Serialize( CArchive& archive );

protected:
	/// 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.

License

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


Written By
Engineer
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 (http://research.microsoft.com/pex).

Comments and Discussions