Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

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.
// CViewGL.cpp: implementation of the CViewGL class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ViewGL.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

IMPLEMENT_SERIAL(CViewGL,CObject,1);

#ifdef _DEBUG
void CViewGL::AssertValid() const
{
    // call inherited AssertValid first
    CObject::AssertValid();

    // check CViewGL members...
	m_StateGL.AssertValid();

	ASSERT(m_iTx>=0);
	ASSERT(m_iTy>=0);
	ASSERT(m_iWidth>=0);
	ASSERT(m_iHeight>=0);
}

void CViewGL::Dump( CDumpContext& ch ) const
{
    // call base class function first
    CObject::Dump( ch );

    // now do the stuff for our specific class
	ch<<_T("--- CViewGL Object ---\n");
	ch<<_T("width : ")<<m_iWidth<<_T("  height : ")<<m_iHeight<<_T("  Tx : ")<<m_iTx<<_T("  Ty : ")<<m_iTy<<_T("\n");
	m_StateGL.Dump(ch);
} 
#endif

void CViewGL::Serialize( CArchive& archive )
{
    // call base class function first
    // base class is CObject in this case
    CObject::Serialize( archive );
	
    // now do the stuff for our specific class
    if (archive.IsStoring())
	{
		archive<<m_iTx<<m_iTy<<m_iWidth<<m_iHeight;
	}
    else
	{
		archive>>m_iTx>>m_iTy>>m_iWidth>>m_iHeight;
	}
	// 
	m_StateGL.Serialize(archive);

	// needs viewport info
	PostViewportInfo();
	// we need reshaping...
	m_bPostReshape=TRUE;
}

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

Share

About the Author

Jonathan de Halleux
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).

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