/**------------------------------------------------------------------------
 * @file
 *
 * Copyright 2001 by the University of Toronto (UT).
 *
 *                       All Rights Reserved
 * 
 * Permission to copy and modify this software and its documentation 
 * only for internal use in your organization is hereby granted, 
 * provided that this notice is retained thereon and on all copies.  
 * UT makes no representations as to the suitability and operability 
 * of this software for any purpose.  It is provided "as is" without 
 * express or implied warranty.
 *
 * UT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
 * SHALL UT BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
 * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 *
 * No other rights, including for example, the right to redistribute 
 * this software and its documentation or the right to prepare 
 * derivative works, are granted unless specifically provided in a 
 * separate license agreement.
 *
 * Author: Diego Macrini
 * 
 * $Log: ApproxPoly.cpp,v $
 *
 *
 *-----------------------------------------------------------------------*/

#ifndef __SKELETON_H__
#define __SKELETON_H__

#include <fstream>
#include "sg.h"

#include "ApproxPolyTLS.h"

namespace dml {

class BlumSkeleton
{
protected:
	SmartArray<SEGMENTS> m_lineSegments;

public:
	virtual void Read(std::istream& is) = 0;
	virtual void Write(std::ostream& os) = 0;
	virtual ~BlumSkeleton() {}
	virtual void ApproxSkeletonWithLines(double dMinError, double dMinSlope, int nMaxSegments, double dMaxYDiff) = 0;
	virtual SmartArray<SEGMENTS> GerApproximation() const { return m_lineSegments; }
};

class McGillSkeleton : public BlumSkeleton
{
	sg::DDSkeleton* pMAT;

public:
	McGillSkeleton(sg::DDSkeleton* p = NULL) { pMAT = p; }
	//McGillSkeleton(const sg::DDSkeleton& dds) { pMAT = new sg::DDSkeleton(dds); }
	
	~McGillSkeleton() { delete pMAT; }

	sg::DDSkeleton* GetSkeleton() { return pMAT; }
	void SetSkeleton(sg::DDSkeleton* p) { pMAT = p; }

	sg::DDSkeleton* ReadDDSkeleton(std::istream& is);
	void WriteDDSkeleton(std::ostream& os, sg::DDSkeleton& dds);

	void ReadNodesAndEdges(std::istream& is, sg::DDSkeleton& dds);
	void WriteNodesAndEdges(std::ostream& os, sg::DDSkeleton& dds);

	void Read(std::istream& is) { pMAT = ReadDDSkeleton(is); }
	void Write(std::ostream& os) { WriteDDSkeleton(os, *pMAT); }
	
	void ApproxSkeletonWithLines(double dMinError, double dMinSlope, int nMaxSegments, double dMaxYDiff);
};

} // namespace dml

#endif //__SKELETON_H__
