tahoma2d/toonz/sources/include/tregion.h

286 lines
7.2 KiB
C
Raw Normal View History

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