Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
// tregion.h: interface for the TRegion class.
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
#if !defined(TREGION_H)
Toshihiro Shimizu 890ddd
#define TREGION_H
Toshihiro Shimizu 890ddd
Shinya Kitaoka 262a92
#include <memory></memory>
Shinya Kitaoka 262a92
Toshihiro Shimizu 890ddd
#if _MSC_VER > 1000
Toshihiro Shimizu 890ddd
#pragma once
Toshihiro Shimizu 890ddd
#endif // _MSC_VER > 1000
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tgeometry.h"
Toshihiro Shimizu 890ddd
//#include "tsmartpointer.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TVECTORIMAGE_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//forward declarations
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TStroke;
Toshihiro Shimizu 890ddd
//class  TVectorRenderData;
Toshihiro Shimizu 890ddd
class TRegion;
Toshihiro Shimizu 890ddd
class TRegionProp;
Toshihiro Shimizu 890ddd
//class TVectorPalette;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TRegionId
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	int m_strokeId;
Toshihiro Shimizu 890ddd
	float m_midW;
Toshihiro Shimizu 890ddd
	bool m_direction;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRegionId(int strokeId, float midW, bool direction)
Toshihiro Shimizu 890ddd
		: m_strokeId(strokeId), m_midW(midW), m_direction(direction)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TFilledRegionInf
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TRegionId m_regionId;
Toshihiro Shimizu 890ddd
	int m_styleId;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFilledRegionInf(int strokeId, float midW, bool direction, int styleId)
Toshihiro Shimizu 890ddd
		: m_regionId(strokeId, midW, direction), m_styleId(styleId)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFilledRegionInf(TRegionId regionId, int styleId)
Toshihiro Shimizu 890ddd
		: m_regionId(regionId), m_styleId(styleId)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TGeneralEdge
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	enum Type {
Toshihiro Shimizu 890ddd
		eNormal,
Toshihiro Shimizu 890ddd
		eAutoclose
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	Type m_type;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TGeneralEdge(Type type) : m_type(type) {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TEdge : public TGeneralEdge
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TStroke *m_s;
Toshihiro Shimizu 890ddd
	double m_w0, m_w1;
Toshihiro Shimizu 890ddd
	int m_index;
Toshihiro Shimizu 890ddd
	TRegion *m_r;
Toshihiro Shimizu 890ddd
	int m_styleId;
Toshihiro Shimizu 890ddd
	bool m_toBeDeleted;
Toshihiro Shimizu 890ddd
	//bool m_forward;
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TEdge()
Toshihiro Shimizu 890ddd
		: TGeneralEdge(eNormal), m_s(0), m_w0(-1), m_w1(-1), m_index(-1), m_r(0), m_styleId(0), m_toBeDeleted(false)
Toshihiro Shimizu 890ddd
	//, m_forward(true)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TEdge(TStroke *ref, UINT index, double w0, double w1, bool toBeDeletedWithStroke, int styleId)
Toshihiro Shimizu 890ddd
		: TGeneralEdge(eNormal), m_s(ref), m_w0(w0), m_w1(w1), m_index(index), m_r(0), m_styleId(styleId), m_toBeDeleted(toBeDeletedWithStroke)
Toshihiro Shimizu 890ddd
	//, m_forward(forward)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/* TEdge(TStroke* ref, bool toBeDeletedWithStroke)
Toshihiro Shimizu 890ddd
      : m_s (ref)
Toshihiro Shimizu 890ddd
      , m_w0  (-1)
Toshihiro Shimizu 890ddd
      , m_w1  (-1) 
Toshihiro Shimizu 890ddd
      , m_r(0)
Toshihiro Shimizu 890ddd
      , m_styleId(0) 
Toshihiro Shimizu 890ddd
			, m_toBeDeleted(toBeDeletedWithStroke)
Toshihiro Shimizu 890ddd
      {}*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TEdge(const TEdge &e, bool toBeDeletedWithStroke)
Toshihiro Shimizu 890ddd
		: TGeneralEdge(eNormal), m_s(e.m_s), m_w0(e.m_w0), m_w1(e.m_w1), m_index(e.m_index), m_r(e.m_r), m_styleId(e.m_styleId), m_toBeDeleted(toBeDeletedWithStroke)
Toshihiro Shimizu 890ddd
	//, m_forward(e.m_forward)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TEdge &operator=(const TEdge &e)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_s = e.m_s;
Toshihiro Shimizu 890ddd
		m_w0 = e.m_w0;
Toshihiro Shimizu 890ddd
		m_w1 = e.m_w1;
Toshihiro Shimizu 890ddd
		m_index = e.m_index;
Toshihiro Shimizu 890ddd
		m_r = e.m_r;
Toshihiro Shimizu 890ddd
		m_styleId = e.m_styleId;
Toshihiro Shimizu 890ddd
		m_toBeDeleted = e.m_toBeDeleted;
Toshihiro Shimizu 890ddd
		//m_forward = e.m_forward;
Toshihiro Shimizu 890ddd
		return *this;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	TEdge(const TEdge &e) : TGeneralEdge(eNormal), m_s(e.m_s), m_w0(e.m_w0), m_w1(e.m_w1), m_index(e.m_index), m_r(e.m_r), m_styleId(e.m_styleId), m_toBeDeleted(e.m_toBeDeleted) /*, m_forward(e.m_forward)*/ {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool operator<(const TEdge &e) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return (e.m_s == m_s) ? ((e.m_w0 == m_w0) ? e.m_w1 < m_w1 : e.m_w0 < m_w0) : e.m_s < m_s;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	inline int getStyle() const { return m_styleId; }
Toshihiro Shimizu 890ddd
	inline void setStyle(int styleId) { m_styleId = styleId; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	inline bool operator==(const TEdge &b) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_s == b.m_s && ((m_w0 == b.m_w0 && m_w1 == b.m_w1) || (m_w0 == b.m_w1 && m_w1 == b.m_w0));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	TEdge(TStroke *ref);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
template class DVAPI TSmartPointerT<tedge>; </tedge>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef TSmartPointerT<tedge> TEdgeP;</tedge>
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//void addRegion(vector<tregion*>& regionArray, TRegion *region);</tregion*>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TRegion
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	class Imp;
Shinya Kitaoka 262a92
	std::unique_ptr<imp> m_imp;</imp>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TRegion();
Toshihiro Shimizu 890ddd
	~TRegion();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRectD getBBox() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool contains(const TPointD &p) const;
Toshihiro Shimizu 890ddd
	bool contains(const TRegion &r) const;
Toshihiro Shimizu 890ddd
	bool contains(const TStroke &s, bool mayIntersect = false) const;
Toshihiro Shimizu 890ddd
	bool contains(const TEdge &e) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! returns the region equivalent to r, 0 if does not exists.
Toshihiro Shimizu 890ddd
	TRegion *findRegion(const TRegion &r) const;
Toshihiro Shimizu 890ddd
	TRegion *getSubregion(UINT index) const;
Toshihiro Shimizu 890ddd
	UINT getSubregionCount() const;
Toshihiro Shimizu 890ddd
	void deleteSubregion(UINT index);
Toshihiro Shimizu 890ddd
	void addSubregion(TRegion *region);
Toshihiro Shimizu 890ddd
	TEdge *getEdge(UINT index) const;
Toshihiro Shimizu 890ddd
	TEdge *getLastEdge() const;
Toshihiro Shimizu 890ddd
	UINT getEdgeCount() const;
Toshihiro Shimizu 890ddd
	void addEdge(TEdge *e, bool minimizeEdges);
Toshihiro Shimizu 890ddd
	TEdge *popFrontEdge();
Toshihiro Shimizu 890ddd
	TEdge *popBackEdge();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void moveSubregionsTo(TRegion *r);
Toshihiro Shimizu 890ddd
	//it returns the  style of the region before filling or -1 if not filled.
Toshihiro Shimizu 890ddd
	int fill(const TPointD &p, int styleId);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool selectFill(const TRectD &selectArea, int styleId);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! returns the smallest subregions (including this) containing p
Toshihiro Shimizu 890ddd
	TRegion *getRegion(const TPointD &p);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getStyle() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setStyle(int styleId);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void autoFill(int styleId, bool oddLevel);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool isSubRegionOf(const TRegion &r) const;
Toshihiro Shimizu 890ddd
	bool getInternalPoint(TPointD &p);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRegionProp *getProp();
Toshihiro Shimizu 890ddd
	void setProp(TRegionProp *prop);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRegionId getId();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void invalidateProp();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void invalidateBBox();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void print();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//friend void addRegion(vector<tregion*>& regionArray, TRegion *region);</tregion*>
Shinya Kitaoka 3bfa54
	void computeScanlineIntersections(double y, std::vector<double> &intersections) const;</double>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int scanlineIntersectionsBefore(double x, double y, bool horiz) const;
Toshihiro Shimizu 890ddd
	int leftScanlineIntersections(double x, double y) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return scanlineIntersectionsBefore(x, y, true);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef _DEBUG
Toshihiro Shimizu 890ddd
	void checkRegion();
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*Spostata in tregion.cpp
Toshihiro Shimizu 890ddd
inline int TRegion::getStyle() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
int ret = 0;
Toshihiro Shimizu 890ddd
  UINT i=0, j, n=getEdgeCount();
Toshihiro Shimizu 890ddd
  for (; i
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
	  int styleId = getEdge(i)->getStyle();
Toshihiro Shimizu 890ddd
      if(styleId != 0 && ret==0) 
Toshihiro Shimizu 890ddd
			  {
Toshihiro Shimizu 890ddd
				//assert(styleId<100);
Toshihiro Shimizu 890ddd
				ret =  styleId;
Toshihiro Shimizu 890ddd
				if (i>0) for (j=0;j<i;j++) getedge(i)-="">setStyle(ret);</i;j++)>
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			else if (styleId!=ret)
Toshihiro Shimizu 890ddd
			  getEdge(i)->setStyle(ret);
Toshihiro Shimizu 890ddd
  }
Toshihiro Shimizu 890ddd
  return ret;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TRegionFeatureFormula
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	virtual void update(const TPointD &p1, const TPointD &p2) = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//permette di calcolare varie grandesse sul poligono della regione,
Toshihiro Shimizu 890ddd
//come l'area, il baricentro, il perimetro...
Toshihiro Shimizu 890ddd
//per usarla si deve sottoclassare la classe virtuale TRegionFeatureFormula
Toshihiro Shimizu 890ddd
//specificando la formual della grandezza da calcolare.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DVAPI computeRegionFeature(const TRegion &r, TRegionFeatureFormula &formula);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif // !defined(TREGION_H)
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//  End Of File
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------