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