Click here to Skip to main content
13,054,779 members (71,357 online)
Click here to Skip to main content


124 bookmarked
Posted 3 Jan 2002

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.
// viewGL.h: interface for the CViewGL class.

#if !defined(AFX_VIEWCLASS_H__338966C8_1C93_11D4_8D89_00409503B978__INCLUDED_)
#define AFX_VIEWCLASS_H__338966C8_1C93_11D4_8D89_00409503B978__INCLUDED_

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

#include "StateGL.h"
/**An abstratc class that defines a view.
This class is used as a base to build 2D and 3D views. These
views will be used with OpenGL to render the channels.
@see CTimer
class CViewGL : public CObject


	/// default constructor
	{	m_iTx=m_iTy=m_iWidth=m_iHeight=0; m_bPostReshape=TRUE; m_bViewportInfo=TRUE;};
	/// copy construtor
	CViewGL(const CViewGL& v)
	{	m_iTx=v.m_iTx; m_iTy=v.m_iTy; m_iWidth=v.m_iWidth; m_iHeight=v.m_iHeight;m_bPostReshape=TRUE; 
	/// assignement constructor
	CViewGL& operator=(const CViewGL& v)
		if (&v!=this)
		{ m_iTx=v.m_iTx; m_iTy=v.m_iTy; m_iWidth=v.m_iWidth; m_iHeight=v.m_iHeight;m_bPostReshape=TRUE;
		return *this;
	/// destructor
	virtual ~CViewGL() {};
	/// initialize OpenGL states (virtual function to override in children classes).
	virtual void InitGLState()
	{	m_StateGL.SetStateGL();};
	/// resizing view (virtual function to override in children classes).
	virtual void Reshape()
	{	// view is reshaped...

	/// returns m_iHeight of the viewport
	GLsizei GetHeight() const
	{ return m_iHeight;};
	/// returns m_iWidth of the viewport
	GLsizei GetWidth() const
	{ return m_iWidth;};
	/// returns starting pixel of the viewport in x direction
	GLint GetTx() const
	{ return m_iTx;};
	/// returns starting pixel of the viewport in xy direction
	GLint GetTy() const
	{ return m_iTy;};

	CStateGL* GetState()
	{	return &m_StateGL;};
	void SetState(const CStateGL& _sgl)
	{	m_StateGL=_sgl;};

	/** Sets the viewport charateristics\\
	    {\bf Parameters :}
			\item[\_Tx] starting x pixel of the viewport (must be >=0)
			\item[\_Ty] starting y pixel of the viewport (must be >=0)
			\item[\_width] width (in pixels) of the viewport (must be >=0)
			\item[\_height] height (in pixels) of the viewport (must be >=0)
	void SetViewport(GLint _Tx, GLint _Ty, GLsizei _width, GLsizei _height)
		m_iTx=_Tx; m_iTy=_Ty; m_iWidth=_width; m_iHeight=_height;

		// Viewport updated

		// Needs redrawing...
	void PostViewportInfo()
	{	m_bViewportInfo=TRUE;};
	BOOL NeedViewportInfo()
	{	return m_bViewportInfo;};

	/// Tells the view it needs to be reshape at the next draw...
	void PostReshape()
	{	m_bPostReshape=TRUE; };
	/// returns TRUE if the view needs reshape, FALSE otherwize.
	BOOL NeedReshape()
	{	return m_bPostReshape;};

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

	/// the starting x pixel of the viewport
	GLint m_iTx;
	/// the starting y pixel of the viewport
	GLint m_iTy;
	/// m_iWidth of the viewport (in pixels)
	GLsizei m_iWidth;
	/// m_iHeight of the viewport (in pixels)
	GLsizei m_iHeight;
	/// the OpenGL state
	CStateGL m_StateGL;
	/// TRUE if view needs viewport informations
	BOOL m_bViewportInfo;
	/// TRUE if view needs reshaping... FALSE otherwise
	BOOL m_bPostReshape;

#endif // !defined(AFX_VIEWCLASS_H__338966C8_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...

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