|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//#include "tsystem.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tmachine.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tcurves.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tcommon.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tregion.h"
|
|
Toshihiro Shimizu |
890ddd |
//#include "tregionutil.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tstopwatch.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tstroke.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tstrokeutil.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tvectorimageP.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tdebugmessage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tthreadmessage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tl2lautocloser.h"
|
|
Toshihiro Shimizu |
890ddd |
#include <vector></vector>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tcurveutil.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <algorithm></algorithm>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#if !defined(TNZ_LITTLE_ENDIAN)
|
|
Toshihiro Shimizu |
890ddd |
TNZ_LITTLE_ENDIAN undefined !!
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef IS_DOTNET
|
|
Toshihiro Shimizu |
890ddd |
#define NULL_ITER list<intersectedstroke>::iterator()</intersectedstroke>
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define NULL_ITER 0
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace std;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef TVectorImage::IntersectionBranch IntersectionBranch;
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline double myRound(double x)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return (1.0 / REGION_COMPUTING_PRECISION) * ((TINT32)(x * REGION_COMPUTING_PRECISION));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline TThickPoint myRound(const TThickPoint &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TThickPoint(myRound(p.x), myRound(p.y), p.thick);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void roundStroke(TStroke *s)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int size = s->getControlPointCount();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int j = 0; j < (int)s->getControlPointCount(); j++) {
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint p = s->getControlPoint(j);
|
|
Toshihiro Shimizu |
890ddd |
s->setControlPoint(j, myRound(p));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (size > 3)
|
|
Toshihiro Shimizu |
890ddd |
//! it can happen that a stroke has a first or last quadratic degenerated:(3 equal control points).
|
|
Toshihiro Shimizu |
890ddd |
// in that case, if the stroke has an intersection in an endpoint, the resulting w could not be 0 or 1 as expected.
|
|
Toshihiro Shimizu |
890ddd |
// since the w==0 and w==1 are used in the region computing to determine if the intersection is an endpoint,
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (s->getControlPoint(0) == s->getControlPoint(1) && s->getControlPoint(0) == s->getControlPoint(2)) {
|
|
Toshihiro Shimizu |
890ddd |
s->setControlPoint(2, s->getControlPoint(3));
|
|
Toshihiro Shimizu |
890ddd |
s->setControlPoint(1, s->getControlPoint(3));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (s->getControlPoint(size - 1) == s->getControlPoint(size - 2) && s->getControlPoint(size - 1) == s->getControlPoint(size - 3)) {
|
|
Toshihiro Shimizu |
890ddd |
s->setControlPoint(size - 2, s->getControlPoint(size - 4));
|
|
Toshihiro Shimizu |
890ddd |
s->setControlPoint(size - 3, s->getControlPoint(size - 4));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
class VIListElem
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
VIListElem *m_prev;
|
|
Toshihiro Shimizu |
890ddd |
VIListElem *m_next;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
VIListElem() : m_prev(0), m_next(0) {}
|
|
Toshihiro Shimizu |
890ddd |
inline VIListElem *next() { return m_next; }
|
|
Toshihiro Shimizu |
890ddd |
inline VIListElem *prev() { return m_prev; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
class VIList
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int m_size;
|
|
Toshihiro Shimizu |
890ddd |
T *m_begin, *m_end;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
VIList() : m_begin(0), m_end(0), m_size(0) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline T *first() const { return m_begin; };
|
|
Toshihiro Shimizu |
890ddd |
inline T *last() const { return m_end; };
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void clear();
|
|
Toshihiro Shimizu |
890ddd |
void pushBack(T *elem);
|
|
Toshihiro Shimizu |
890ddd |
void insert(T *before, T *elem);
|
|
Toshihiro Shimizu |
890ddd |
T *erase(T *element);
|
|
Toshihiro Shimizu |
890ddd |
T *getElemAt(int pos);
|
|
Toshihiro Shimizu |
890ddd |
int getPosOf(T *elem);
|
|
Toshihiro Shimizu |
890ddd |
inline int size() { return m_size; }
|
|
Toshihiro Shimizu |
890ddd |
inline bool empty() { return size() == 0; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class Intersection : public VIListElem
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
//Intersection* m_prev, *m_next;
|
|
Toshihiro Shimizu |
890ddd |
TPointD m_intersection;
|
|
Toshihiro Shimizu |
890ddd |
int m_numInter;
|
|
Toshihiro Shimizu |
890ddd |
//bool m_isNotErasable;
|
|
Toshihiro Shimizu |
890ddd |
VIList<intersectedstroke> m_strokeList;</intersectedstroke>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Intersection() : m_numInter(0), m_strokeList() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline Intersection *next() { return (Intersection *)VIListElem::next(); };
|
|
Toshihiro Shimizu |
890ddd |
inline Intersection *prev() { return (Intersection *)VIListElem::prev(); };
|
|
Toshihiro Shimizu |
890ddd |
//inline Intersection* operator++() {return next();}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class IntersectedStrokeEdges
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
int m_index;
|
|
Toshihiro Shimizu |
890ddd |
list<tedge *=""> m_edgeList;</tedge>
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStrokeEdges(int index) : m_index(index), m_edgeList() {}
|
|
Toshihiro Shimizu |
890ddd |
~IntersectedStrokeEdges()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(m_index >= 0); /*clearPointerContainer(m_edgeList);*/
|
|
Toshihiro Shimizu |
890ddd |
m_edgeList.clear();
|
|
Toshihiro Shimizu |
890ddd |
m_index = -1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class IntersectionData
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
UINT maxAutocloseId;
|
|
Toshihiro Shimizu |
890ddd |
VIList<intersection> m_intList;</intersection>
|
|
Toshihiro Shimizu |
890ddd |
map<int, *="" vistroke=""> m_autocloseMap;</int,>
|
|
Toshihiro Shimizu |
890ddd |
vector<intersectedstrokeedges> m_intersectedStrokeArray;</intersectedstrokeedges>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
IntersectionData()
|
|
Toshihiro Shimizu |
890ddd |
: maxAutocloseId(1), m_intList()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
~IntersectionData();
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class IntersectedStroke : public VIListElem
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*double m_w;
|
|
Toshihiro Shimizu |
890ddd |
TStroke *m_s;
|
|
Toshihiro Shimizu |
890ddd |
UINT m_index;*/
|
|
Toshihiro Shimizu |
890ddd |
//IntersectedStroke* m_prev, *m_next;
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TEdge m_edge;
|
|
Toshihiro Shimizu |
890ddd |
Intersection *m_nextIntersection;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *m_nextStroke;
|
|
Toshihiro Shimizu |
890ddd |
bool m_visited, m_gettingOut; //, m_dead;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke()
|
|
Toshihiro Shimizu |
890ddd |
: m_visited(false), m_nextIntersection(0), m_nextStroke(0){};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke(Intersection *nextIntersection,
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *nextStroke)
|
|
Toshihiro Shimizu |
890ddd |
/*: m_w(-1.0)
|
|
Toshihiro Shimizu |
890ddd |
, m_s(NULL)
|
|
Toshihiro Shimizu |
890ddd |
, m_index(0)*/
|
|
Toshihiro Shimizu |
890ddd |
: m_edge(),
|
|
Toshihiro Shimizu |
890ddd |
m_nextIntersection(nextIntersection),
|
|
Toshihiro Shimizu |
890ddd |
m_nextStroke(nextStroke),
|
|
Toshihiro Shimizu |
890ddd |
m_visited(false)
|
|
Toshihiro Shimizu |
890ddd |
//, m_dead(false)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke(const IntersectedStroke &s)
|
|
Toshihiro Shimizu |
890ddd |
: m_edge(s.m_edge, false), m_nextIntersection(s.m_nextIntersection), m_nextStroke(s.m_nextStroke), m_visited(s.m_visited), m_gettingOut(s.m_gettingOut)
|
|
Toshihiro Shimizu |
890ddd |
//, m_dead(s.m_dead)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline IntersectedStroke *next() { return (IntersectedStroke *)VIListElem::next(); };
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
void VIList<t>::clear()</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
while (m_begin) {
|
|
Toshihiro Shimizu |
890ddd |
T *aux = m_begin;
|
|
Toshihiro Shimizu |
890ddd |
m_begin = m_begin->next();
|
|
Toshihiro Shimizu |
890ddd |
delete aux;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_end = 0;
|
|
Toshihiro Shimizu |
890ddd |
m_size = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
void VIList<t>::pushBack(T *elem)</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!m_begin) {
|
|
Toshihiro Shimizu |
890ddd |
assert(!m_end);
|
|
Toshihiro Shimizu |
890ddd |
elem->m_next = elem->m_prev = 0;
|
|
Toshihiro Shimizu |
890ddd |
m_begin = m_end = elem;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
assert(m_end);
|
|
Toshihiro Shimizu |
890ddd |
assert(m_end->m_next == 0);
|
|
Toshihiro Shimizu |
890ddd |
m_end->m_next = elem;
|
|
Toshihiro Shimizu |
890ddd |
elem->m_prev = m_end;
|
|
Toshihiro Shimizu |
890ddd |
elem->m_next = 0;
|
|
Toshihiro Shimizu |
890ddd |
m_end = elem;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_size++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
void VIList<t>::insert(T *before, T *elem)</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(before && elem);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
elem->m_prev = before->m_prev;
|
|
Toshihiro Shimizu |
890ddd |
elem->m_next = before;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!before->m_prev)
|
|
Toshihiro Shimizu |
890ddd |
before->m_prev = m_begin = elem;
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
before->m_prev->m_next = elem;
|
|
Toshihiro Shimizu |
890ddd |
before->m_prev = elem;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_size++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
T *VIList<t>::erase(T *element)</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
T *ret;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(m_size > 0);
|
|
Toshihiro Shimizu |
890ddd |
if (!element->m_prev) {
|
|
Toshihiro Shimizu |
890ddd |
assert(m_begin == element);
|
|
Toshihiro Shimizu |
890ddd |
if (!element->m_next)
|
|
Toshihiro Shimizu |
890ddd |
ret = m_begin = m_end = 0;
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
m_begin = (T *)m_begin->m_next;
|
|
Toshihiro Shimizu |
890ddd |
m_begin->m_prev = 0;
|
|
Toshihiro Shimizu |
890ddd |
ret = m_begin;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else if (!element->m_next) {
|
|
Toshihiro Shimizu |
890ddd |
assert(m_end == element);
|
|
Toshihiro Shimizu |
890ddd |
m_end = (T *)m_end->m_prev;
|
|
Toshihiro Shimizu |
890ddd |
m_end->m_next = 0;
|
|
Toshihiro Shimizu |
890ddd |
ret = 0;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
element->m_prev->m_next = element->m_next;
|
|
Toshihiro Shimizu |
890ddd |
element->m_next->m_prev = element->m_prev;
|
|
Toshihiro Shimizu |
890ddd |
ret = (T *)element->m_next;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_size--;
|
|
Toshihiro Shimizu |
890ddd |
delete element;
|
|
Toshihiro Shimizu |
890ddd |
return ret;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
T *VIList<t>::getElemAt(int pos)</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(pos < m_size);
|
|
Toshihiro Shimizu |
890ddd |
T *p = m_begin;
|
|
Toshihiro Shimizu |
890ddd |
while (pos--)
|
|
Toshihiro Shimizu |
890ddd |
p = p->next();
|
|
Toshihiro Shimizu |
890ddd |
return p;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
int VIList<t>::getPosOf(T *elem)</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int count = 0;
|
|
Toshihiro Shimizu |
890ddd |
T *p = m_begin;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (p && p != elem) {
|
|
Toshihiro Shimizu |
890ddd |
count++;
|
|
Toshihiro Shimizu |
890ddd |
p = p->next();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
assert(p == elem);
|
|
Toshihiro Shimizu |
890ddd |
return count;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef LEVO
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void print(list<intersection> &intersectionList, char *str)</intersection>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
ofstream of(str);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
of << "***************************" << endl;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
list<intersection>::const_iterator it;</intersection>
|
|
Toshihiro Shimizu |
890ddd |
list<intersectedstroke>::const_iterator it1;</intersectedstroke>
|
|
Toshihiro Shimizu |
890ddd |
int i, j;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0, it = intersectionList.begin(); it != intersectionList.end(); it++, i++) {
|
|
Toshihiro Shimizu |
890ddd |
of << "***************************" << endl;
|
|
Toshihiro Shimizu |
890ddd |
of << "Intersection#" << i << ": " << it->m_intersection << "numBranches: " << it->m_numInter << endl;
|
|
Toshihiro Shimizu |
890ddd |
of << endl;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (j = 0, it1 = it->m_strokeList.begin(); it1 != it->m_strokeList.end(); it1++, j++) {
|
|
Toshihiro Shimizu |
890ddd |
of << "----Branch #" << j;
|
|
Toshihiro Shimizu |
890ddd |
if (it1->m_edge.m_index < 0)
|
|
Toshihiro Shimizu |
890ddd |
of << "(AUTOCLOSE)";
|
|
Toshihiro Shimizu |
890ddd |
of << "Intersection at " << it1->m_edge.m_w0 << ": "
|
|
Toshihiro Shimizu |
890ddd |
<< ": " << endl;
|
|
Toshihiro Shimizu |
890ddd |
of << "ColorId: " << it1->m_edge.m_styleId << endl;
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
TColorStyle* fs = it1->m_edge.m_fillStyle;
|
|
Toshihiro Shimizu |
890ddd |
if (fs==0)
|
|
Toshihiro Shimizu |
890ddd |
of<<"NO color: "<< endl;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TFillStyleP fp = fs->getFillStyle();
|
|
Toshihiro Shimizu |
890ddd |
if (fp)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
fp->
|
|
Toshihiro Shimizu |
890ddd |
assert(false) ;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
of<<"Color: ("<< colorStyle->getColor().r<<", "<< colorStyle->getColor().g<<", "<< colorStyle->getColor().b<<")"<
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
of << "----Stroke " << (it1->m_gettingOut ? "OUT" : "IN") << " #" << it1->m_edge.m_index << ": " << endl;
|
|
Toshihiro Shimizu |
890ddd |
//if (it1->m_dead)
|
|
Toshihiro Shimizu |
890ddd |
//of<<"---- DEAD Intersection.";
|
|
Toshihiro Shimizu |
890ddd |
//else
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
of << "---- NEXT Intersection:";
|
|
Toshihiro Shimizu |
890ddd |
if (it1->m_nextIntersection != intersectionList.end()) {
|
|
Toshihiro Shimizu |
890ddd |
int dist = std::distance(intersectionList.begin(), it1->m_nextIntersection);
|
|
Toshihiro Shimizu |
890ddd |
of << dist;
|
|
Toshihiro Shimizu |
890ddd |
list<intersection>::iterator iit = intersectionList.begin();</intersection>
|
|
Toshihiro Shimizu |
890ddd |
std::advance(iit, dist);
|
|
Toshihiro Shimizu |
890ddd |
of << " " << std::distance(iit->m_strokeList.begin(), it1->m_nextStroke);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
of << "NULL!!";
|
|
Toshihiro Shimizu |
890ddd |
of << "---- NEXT Stroke:";
|
|
Toshihiro Shimizu |
890ddd |
if (it1->m_nextIntersection != intersectionList.end())
|
|
Toshihiro Shimizu |
890ddd |
of << it1->m_nextStroke->m_edge.m_index;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
of << "NULL!!";
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
of << endl
|
|
Toshihiro Shimizu |
890ddd |
<< endl;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void findNearestIntersection(list<intersection> &interList,</intersection>
|
|
Toshihiro Shimizu |
890ddd |
const list<intersection>::iterator &i1,</intersection>
|
|
Toshihiro Shimizu |
890ddd |
const list<intersectedstroke>::iterator &i2);</intersectedstroke>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _TOLGO
|
|
Toshihiro Shimizu |
890ddd |
void checkInterList(list<intersection> &intersectionList)</intersection>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
list<intersection>::iterator it;</intersection>
|
|
Toshihiro Shimizu |
890ddd |
list<intersectedstroke>::iterator it1;</intersectedstroke>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (it = intersectionList.begin(); it != intersectionList.end(); it++) {
|
|
Toshihiro Shimizu |
890ddd |
int count = 0;
|
|
Toshihiro Shimizu |
890ddd |
for (it1 = it->m_strokeList.begin(); it1 != it->m_strokeList.end(); it1++) {
|
|
Toshihiro Shimizu |
890ddd |
int val;
|
|
Toshihiro Shimizu |
890ddd |
if (it1->m_nextIntersection != intersectionList.end()) {
|
|
Toshihiro Shimizu |
890ddd |
count++;
|
|
Toshihiro Shimizu |
890ddd |
//assert (it1->m_nextIntersection!=intersectionList.end());
|
|
Toshihiro Shimizu |
890ddd |
assert(it1->m_nextStroke->m_nextIntersection == it);
|
|
Toshihiro Shimizu |
890ddd |
assert(it1->m_nextStroke->m_nextStroke == it1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//int k = it1->m_edge.m_index;
|
|
Toshihiro Shimizu |
890ddd |
val = std::distance(intersectionList.begin(), it1->m_nextIntersection);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//else
|
|
Toshihiro Shimizu |
890ddd |
// assert(it1->m_nextIntersection==intersectionList.end());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
assert(count == it->m_numInter);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define checkInterList
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//void addFakeIntersection(list<intersection>& intersectionList,TStroke* s, UINT ii, double w);</intersection>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void addIntersections(IntersectionData &intersectionData,
|
|
Toshihiro Shimizu |
890ddd |
const vector<vistroke *=""> &s, int ii, int jj, const vector<doublepair> &intersections, int numStrokes, bool isVectorized);</doublepair></vistroke>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void addIntersection(IntersectionData &intData,
|
|
Toshihiro Shimizu |
890ddd |
const vector<vistroke *=""> &s, int ii, int jj,</vistroke>
|
|
Toshihiro Shimizu |
890ddd |
DoublePair intersections, int strokeSize, bool isVectorized);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool sortBBox(const TStroke *s1, const TStroke *s2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return s1->getBBox().x0 < s2->getBBox().x0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void cleanIntersectionMarks(const VIList<intersection> &interList)</intersection>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *q;
|
|
Toshihiro Shimizu |
890ddd |
for (p = interList.first(); p; p = p->next())
|
|
Toshihiro Shimizu |
890ddd |
for (q = p->m_strokeList.first(); q; q = q->next()) {
|
|
Toshihiro Shimizu |
890ddd |
q->m_visited = false; // Ogni ramo della lista viene messo nella condizione
|
|
Toshihiro Shimizu |
890ddd |
// di poter essere visitato
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (q->m_nextIntersection) {
|
|
Toshihiro Shimizu |
890ddd |
q->m_nextIntersection = 0;
|
|
Toshihiro Shimizu |
890ddd |
p->m_numInter--;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void cleanNextIntersection(const VIList<intersection> &interList, TStroke *s)</intersection>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *q;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p = interList.first(); p; p = p->next())
|
|
Toshihiro Shimizu |
890ddd |
for (q = p->m_strokeList.first(); q; q = q->next())
|
|
Toshihiro Shimizu |
890ddd |
if (q->m_edge.m_s == s) {
|
|
Toshihiro Shimizu |
890ddd |
//if (it2->m_nextIntersection==NULL)
|
|
Toshihiro Shimizu |
890ddd |
// return; //gia' ripulita prima
|
|
Toshihiro Shimizu |
890ddd |
if (q->m_nextIntersection) {
|
|
Toshihiro Shimizu |
890ddd |
q->m_nextIntersection = 0;
|
|
Toshihiro Shimizu |
890ddd |
p->m_numInter--;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
q->m_nextStroke = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::Imp::eraseEdgeFromStroke(IntersectedStroke *is)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (is->m_edge.m_index >= 0) //elimino il puntatore all'edge nella lista della VIStroke
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
VIStroke *s;
|
|
Toshihiro Shimizu |
890ddd |
s = m_strokes[is->m_edge.m_index];
|
|
Toshihiro Shimizu |
890ddd |
assert(s->m_s == is->m_edge.m_s);
|
|
Toshihiro Shimizu |
890ddd |
list<tedge *="">::iterator iit = s->m_edgeList.begin(), it_e = s->m_edgeList.end();</tedge>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (; iit != it_e; ++iit)
|
|
Toshihiro Shimizu |
890ddd |
if ((*iit)->m_w0 == is->m_edge.m_w0 && (*iit)->m_w1 == is->m_edge.m_w1) {
|
|
Toshihiro Shimizu |
890ddd |
assert((*iit)->m_toBeDeleted == false);
|
|
Toshihiro Shimizu |
890ddd |
s->m_edgeList.erase(iit);
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *TVectorImage::Imp::eraseBranch(Intersection *in,
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *is)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (is->m_nextIntersection) {
|
|
Toshihiro Shimizu |
890ddd |
Intersection *nextInt = is->m_nextIntersection;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *nextStroke = is->m_nextStroke;
|
|
Toshihiro Shimizu |
890ddd |
assert(nextStroke->m_nextIntersection == in);
|
|
Toshihiro Shimizu |
890ddd |
assert(nextStroke->m_nextStroke == is);
|
|
Toshihiro Shimizu |
890ddd |
assert(nextStroke != is);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//nextStroke->m_nextIntersection = intList.end();
|
|
Toshihiro Shimizu |
890ddd |
//nextStroke->m_nextStroke = nextInt->m_strokeList.end();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (nextStroke->m_nextIntersection) {
|
|
Toshihiro Shimizu |
890ddd |
nextStroke->m_nextIntersection = 0;
|
|
Toshihiro Shimizu |
890ddd |
nextInt->m_numInter--;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//nextInt->m_strokeList.erase(nextStroke);//non posso cancellarla, puo' servire in futuro!
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (is->m_nextIntersection)
|
|
Toshihiro Shimizu |
890ddd |
in->m_numInter--;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
eraseEdgeFromStroke(is);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
is->m_edge.m_w0 = is->m_edge.m_w1 = -3;
|
|
Toshihiro Shimizu |
890ddd |
is->m_edge.m_index = -3;
|
|
Toshihiro Shimizu |
890ddd |
is->m_edge.m_s = 0;
|
|
Toshihiro Shimizu |
890ddd |
is->m_edge.m_styleId = -3;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return in->m_strokeList.erase(is);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::Imp::eraseDeadIntersections()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p = m_intersectionData->m_intList.first();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (p) //la faccio qui, e non nella eraseIntersection. vedi commento li'.
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//Intersection* &intList = m_intersectionData->m_intList;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (p->m_strokeList.size() == 1) {
|
|
Toshihiro Shimizu |
890ddd |
eraseBranch(p, p->m_strokeList.first());
|
|
Toshihiro Shimizu |
890ddd |
assert(p->m_strokeList.size() == 0);
|
|
Toshihiro Shimizu |
890ddd |
p = m_intersectionData->m_intList.erase(p);
|
|
Toshihiro Shimizu |
890ddd |
} else if (p->m_strokeList.size() == 2 &&
|
|
Toshihiro Shimizu |
890ddd |
(p->m_strokeList.first()->m_edge.m_s == p->m_strokeList.last()->m_edge.m_s &&
|
|
Toshihiro Shimizu |
890ddd |
p->m_strokeList.first()->m_edge.m_w0 == p->m_strokeList.last()->m_edge.m_w0)) //intersezione finta
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *it1 = p->m_strokeList.first(), *iit1, *iit2;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *it2 = it1->next();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
eraseEdgeFromStroke(p->m_strokeList.first());
|
|
Toshihiro Shimizu |
890ddd |
eraseEdgeFromStroke(p->m_strokeList.first()->next());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
iit1 = (it1->m_nextIntersection) ? it1->m_nextStroke : 0;
|
|
Toshihiro Shimizu |
890ddd |
iit2 = (it2->m_nextIntersection) ? it2->m_nextStroke : 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (iit1 && iit2) {
|
|
Toshihiro Shimizu |
890ddd |
iit1->m_edge.m_w1 = iit2->m_edge.m_w0;
|
|
Toshihiro Shimizu |
890ddd |
iit2->m_edge.m_w1 = iit1->m_edge.m_w0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (iit1) {
|
|
Toshihiro Shimizu |
890ddd |
iit1->m_nextStroke = iit2;
|
|
Toshihiro Shimizu |
890ddd |
iit1->m_nextIntersection = it2->m_nextIntersection;
|
|
Toshihiro Shimizu |
890ddd |
if (!iit1->m_nextIntersection)
|
|
Toshihiro Shimizu |
890ddd |
it1->m_nextIntersection->m_numInter--;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (iit2) {
|
|
Toshihiro Shimizu |
890ddd |
iit2->m_nextStroke = iit1;
|
|
Toshihiro Shimizu |
890ddd |
iit2->m_nextIntersection = it1->m_nextIntersection;
|
|
Toshihiro Shimizu |
890ddd |
if (!iit2->m_nextIntersection)
|
|
Toshihiro Shimizu |
890ddd |
it2->m_nextIntersection->m_numInter--;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
p->m_strokeList.clear();
|
|
Toshihiro Shimizu |
890ddd |
p->m_numInter = 0;
|
|
Toshihiro Shimizu |
890ddd |
p = m_intersectionData->m_intList.erase(p);
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
p = p->next();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::Imp::doEraseIntersection(int index, vector<int> *toBeDeleted)</int>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1 = m_intersectionData->m_intList.first();
|
|
Toshihiro Shimizu |
890ddd |
TStroke *deleteIt = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (p1) {
|
|
Toshihiro Shimizu |
890ddd |
bool removeAutocloses = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2 = p1->m_strokeList.first();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (p2) {
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke &is = *p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (is.m_edge.m_index == index) {
|
|
Toshihiro Shimizu |
890ddd |
if (is.m_edge.m_index >= 0)
|
|
Toshihiro Shimizu |
890ddd |
//if (!is.m_autoclose && (is.m_edge.m_w0==1 || is.m_edge.m_w0==0))
|
|
Toshihiro Shimizu |
890ddd |
removeAutocloses = true;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
deleteIt = is.m_edge.m_s;
|
|
Toshihiro Shimizu |
890ddd |
p2 = eraseBranch(p1, p2);
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
p2 = p2->next();
|
|
Toshihiro Shimizu |
890ddd |
//checkInterList(interList);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (removeAutocloses) //se ho tolto una stroke dall'inter corrente, tolgo tutti le stroke di autclose che partono da qui
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(toBeDeleted);
|
|
Toshihiro Shimizu |
890ddd |
for (p2 = p1->m_strokeList.first(); p2; p2 = p2->next())
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_index < 0 && (p2->m_edge.m_w0 == 1 || p2->m_edge.m_w0 == 0))
|
|
Toshihiro Shimizu |
890ddd |
toBeDeleted->push_back(p2->m_edge.m_index);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (p1->m_strokeList.empty())
|
|
Toshihiro Shimizu |
890ddd |
p1 = m_intersectionData->m_intList.erase(p1);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
p1 = p1->next();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (deleteIt)
|
|
Toshihiro Shimizu |
890ddd |
delete deleteIt;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UINT TVectorImage::Imp::getFillData(IntersectionBranch *&v)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//print(m_intersectionData->m_intList, "C:\\temp\\intersectionPrimaSave.txt");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Intersection* intList = m_intersectionData->m_intList;
|
|
Toshihiro Shimizu |
890ddd |
if (m_intersectionData->m_intList.empty())
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2;
|
|
Toshihiro Shimizu |
890ddd |
UINT currInt = 0;
|
|
Toshihiro Shimizu |
890ddd |
vector<uint> branchesBefore(m_intersectionData->m_intList.size() + 1);</uint>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
branchesBefore[0] = 0;
|
|
Toshihiro Shimizu |
890ddd |
UINT count = 0, size = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
p1 = m_intersectionData->m_intList.first();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (; p1; p1 = p1->next(), currInt++) {
|
|
Toshihiro Shimizu |
890ddd |
UINT strokeListSize = p1->m_strokeList.size();
|
|
Toshihiro Shimizu |
890ddd |
size += strokeListSize;
|
|
Toshihiro Shimizu |
890ddd |
branchesBefore[currInt + 1] = branchesBefore[currInt] + strokeListSize;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
v = new IntersectionBranch[size];
|
|
Toshihiro Shimizu |
890ddd |
currInt = 0;
|
|
Toshihiro Shimizu |
890ddd |
p1 = m_intersectionData->m_intList.first();
|
|
Toshihiro Shimizu |
890ddd |
for (; p1; p1 = p1->next(), currInt++) {
|
|
Toshihiro Shimizu |
890ddd |
UINT currBranch = 0;
|
|
Toshihiro Shimizu |
890ddd |
for (p2 = p1->m_strokeList.first(); p2; p2 = p2->next(), currBranch++) {
|
|
Toshihiro Shimizu |
890ddd |
IntersectionBranch &b = v[count];
|
|
Toshihiro Shimizu |
890ddd |
b.m_currInter = currInt;
|
|
Toshihiro Shimizu |
890ddd |
b.m_strokeIndex = p2->m_edge.m_index;
|
|
Toshihiro Shimizu |
890ddd |
b.m_w = p2->m_edge.m_w0;
|
|
Toshihiro Shimizu |
890ddd |
b.m_style = p2->m_edge.m_styleId;
|
|
Toshihiro Shimizu |
890ddd |
//assert(b.m_style<100);
|
|
Toshihiro Shimizu |
890ddd |
b.m_gettingOut = p2->m_gettingOut;
|
|
Toshihiro Shimizu |
890ddd |
if (!p2->m_nextIntersection)
|
|
Toshihiro Shimizu |
890ddd |
b.m_nextBranch = count;
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
UINT distInt = m_intersectionData->m_intList.getPosOf(p2->m_nextIntersection);
|
|
Toshihiro Shimizu |
890ddd |
UINT distBranch = p2->m_nextIntersection->m_strokeList.getPosOf(p2->m_nextStroke);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if ((distInt < currInt) ||
|
|
Toshihiro Shimizu |
890ddd |
(distInt == currInt && distBranch < currBranch)) {
|
|
Toshihiro Shimizu |
890ddd |
UINT posNext = branchesBefore[distInt] + distBranch;
|
|
Toshihiro Shimizu |
890ddd |
assert(posNext < count);
|
|
Toshihiro Shimizu |
890ddd |
b.m_nextBranch = posNext;
|
|
Toshihiro Shimizu |
890ddd |
assert(v[posNext].m_nextBranch == (std::numeric_limits<uint>::max)());</uint>
|
|
Toshihiro Shimizu |
890ddd |
v[posNext].m_nextBranch = count;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
b.m_nextBranch = (std::numeric_limits<uint>::max)();</uint>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
count++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//for (UINT i=0; i
|
|
Toshihiro Shimizu |
890ddd |
// assert(v[i].m_nextBranch != std::numeric_limits<uint>::max());</uint>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
/*ofstream of("C:\\temp\\fillDataOut.txt");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (UINT ii=0; ii
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
of<
|
|
Toshihiro Shimizu |
890ddd |
of<<"index:"<
|
|
Toshihiro Shimizu |
890ddd |
of<<"w:"<
|
|
Toshihiro Shimizu |
890ddd |
of<<"curr inter:"<
|
|
Toshihiro Shimizu |
890ddd |
of<<"next inter:"<
|
|
Toshihiro Shimizu |
890ddd |
of<<"gettingOut:"<<((v[ii].m_gettingOut)?"TRUE":"FALSE")<
|
|
Toshihiro Shimizu |
890ddd |
of<<"colorId:"<
|
|
Toshihiro Shimizu |
890ddd |
}*/
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return size;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TStroke *reconstructAutocloseStroke(Intersection *p1,
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
bool found = false;
|
|
Toshihiro Shimizu |
890ddd |
Intersection *pp1 = p1->next();
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *pp2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//vector<tedge*> vapp;</tedge*>
|
|
Toshihiro Shimizu |
890ddd |
for (; !found && pp1; pp1 = pp1->next()) {
|
|
Toshihiro Shimizu |
890ddd |
for (pp2 = pp1->m_strokeList.first(); !found && pp2; pp2 = pp2->next()) {
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_index == pp2->m_edge.m_index) {
|
|
Toshihiro Shimizu |
890ddd |
if ((pp2->m_edge.m_w0 == 1 && p2->m_edge.m_w0 == 0) ||
|
|
Toshihiro Shimizu |
890ddd |
(pp2->m_edge.m_w0 == 0 && p2->m_edge.m_w0 == 1)) {
|
|
Toshihiro Shimizu |
890ddd |
found = true;
|
|
Toshihiro Shimizu |
890ddd |
vector<tpointd> v;</tpointd>
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_w0 == 0) {
|
|
Toshihiro Shimizu |
890ddd |
v.push_back(p1->m_intersection);
|
|
Toshihiro Shimizu |
890ddd |
v.push_back(pp1->m_intersection);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
v.push_back(pp1->m_intersection);
|
|
Toshihiro Shimizu |
890ddd |
v.push_back(p1->m_intersection);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_s = pp2->m_edge.m_s = new TStroke(v);
|
|
Toshihiro Shimizu |
890ddd |
//for (UINT ii=0; ii
|
|
Toshihiro Shimizu |
890ddd |
// vapp[ii]->m_s = it2->m_edge.m_s;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//else if (iit2->m_edge.m_w0!=0 && iit2->m_edge.m_w0!=1)
|
|
Toshihiro Shimizu |
890ddd |
// vapp.push_back(&(iit2->m_edge));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
assert(found);
|
|
Toshihiro Shimizu |
890ddd |
if (!found)
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_s = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return p2->m_edge.m_s;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} //namespace
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::Imp::setFillData(IntersectionBranch *v, UINT branchCount, bool doComputeRegions)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
/*ofstream of("C:\\temp\\fillDataIn.txt");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (UINT ii=0; ii
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
of<
|
|
Toshihiro Shimizu |
890ddd |
of<<"index:"<
|
|
Toshihiro Shimizu |
890ddd |
of<<"w:"<
|
|
Toshihiro Shimizu |
890ddd |
of<<"curr inter:"<
|
|
Toshihiro Shimizu |
890ddd |
of<<"next inter:"<
|
|
Toshihiro Shimizu |
890ddd |
of<<"gettingOut:"<<((v[ii].m_gettingOut)?"TRUE":"FALSE")<
|
|
Toshihiro Shimizu |
890ddd |
of<<"colorId:"<
|
|
Toshihiro Shimizu |
890ddd |
}*/
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (branchCount == 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//{
|
|
Toshihiro Shimizu |
890ddd |
//QMutexLocker sl(m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
VIList<intersection> &intList = m_intersectionData->m_intList;</intersection>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
clearPointerContainer(m_regions);
|
|
Toshihiro Shimizu |
890ddd |
m_regions.clear();
|
|
Toshihiro Shimizu |
890ddd |
intList.clear();
|
|
Toshihiro Shimizu |
890ddd |
Intersection *currInt;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *currBranch;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UINT size = v[branchCount - 1].m_currInter + 1;
|
|
Toshihiro Shimizu |
890ddd |
vector<uint> branchesBefore(size);</uint>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UINT i = 0;
|
|
Toshihiro Shimizu |
890ddd |
for (; i < branchCount; i++) {
|
|
Toshihiro Shimizu |
890ddd |
const IntersectionBranch &b = v[i];
|
|
Toshihiro Shimizu |
890ddd |
if (i == 0 || v[i].m_currInter != v[i - 1].m_currInter) {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (v[i].m_currInter >= size) //pezza per immagine corrotte...evito crash
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
intList.clear();
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
branchesBefore[v[i].m_currInter] = i;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
currInt = new Intersection();
|
|
Toshihiro Shimizu |
890ddd |
intList.pushBack(currInt);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
currBranch = new IntersectedStroke();
|
|
Toshihiro Shimizu |
890ddd |
currInt->m_strokeList.pushBack(currBranch);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
currBranch->m_edge.m_styleId = b.m_style;
|
|
Toshihiro Shimizu |
890ddd |
//assert(b.m_style<100);
|
|
Toshihiro Shimizu |
890ddd |
currBranch->m_edge.m_index = b.m_strokeIndex;
|
|
Toshihiro Shimizu |
890ddd |
if (b.m_strokeIndex >= 0)
|
|
Toshihiro Shimizu |
890ddd |
currBranch->m_edge.m_s = m_strokes[b.m_strokeIndex]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
currBranch->m_edge.m_s = 0;
|
|
Toshihiro Shimizu |
890ddd |
currBranch->m_gettingOut = b.m_gettingOut;
|
|
Toshihiro Shimizu |
890ddd |
currBranch->m_edge.m_w0 = b.m_w;
|
|
Toshihiro Shimizu |
890ddd |
if (b.m_nextBranch < branchCount)
|
|
Toshihiro Shimizu |
890ddd |
currBranch->m_edge.m_w1 = v[b.m_nextBranch].m_w;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
currBranch->m_edge.m_w1 = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
assert(currBranch->m_edge.m_w0 >= -1e-8 && currBranch->m_edge.m_w0 <= 1 + 1e-8);
|
|
Toshihiro Shimizu |
890ddd |
assert(currBranch->m_edge.m_w1 >= -1e-8 && currBranch->m_edge.m_w1 <= 1 + 1e-8);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (b.m_nextBranch < i) {
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2;
|
|
Toshihiro Shimizu |
890ddd |
p1 = intList.getElemAt(v[b.m_nextBranch].m_currInter);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(b.m_nextBranch - branchesBefore[v[b.m_nextBranch].m_currInter] >= 0);
|
|
Toshihiro Shimizu |
890ddd |
p2 = p1->m_strokeList.getElemAt(b.m_nextBranch - branchesBefore[v[b.m_nextBranch].m_currInter]);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
currBranch->m_nextIntersection = p1;
|
|
Toshihiro Shimizu |
890ddd |
currBranch->m_nextStroke = p2;
|
|
Toshihiro Shimizu |
890ddd |
p2->m_nextIntersection = currInt;
|
|
Toshihiro Shimizu |
890ddd |
p2->m_nextStroke = currBranch;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//if (currBranch == currInt->m_strokeList.begin())
|
|
Toshihiro Shimizu |
890ddd |
// currInt->m_intersection = currBranch->m_edge.m_s->getPoint(currBranch->m_edge.m_w0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
currInt->m_numInter++;
|
|
Toshihiro Shimizu |
890ddd |
p1->m_numInter++;
|
|
Toshihiro Shimizu |
890ddd |
} else if (b.m_nextBranch == i)
|
|
Toshihiro Shimizu |
890ddd |
currBranch->m_nextIntersection = 0;
|
|
Toshihiro Shimizu |
890ddd |
else if (b.m_nextBranch == (std::numeric_limits<uint>::max)()) {</uint>
|
|
Toshihiro Shimizu |
890ddd |
currBranch->m_nextIntersection = 0;
|
|
Toshihiro Shimizu |
890ddd |
currBranch->m_nextStroke = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* {
|
|
Toshihiro Shimizu |
890ddd |
assert(b.m_nextBranch
|
|
Toshihiro Shimizu |
890ddd |
assert(v[b.m_nextBranch].m_nextBranch==i);
|
|
Toshihiro Shimizu |
890ddd |
}*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (i == branchCount - 1 || v[i].m_currInter != v[i + 1].m_currInter) {
|
|
Toshihiro Shimizu |
890ddd |
int j = i;
|
|
Toshihiro Shimizu |
890ddd |
while (v[j].m_strokeIndex < 0 && ((j > 0 && v[j].m_currInter == v[j - 1].m_currInter) || j == 0))
|
|
Toshihiro Shimizu |
890ddd |
j--;
|
|
Toshihiro Shimizu |
890ddd |
if (v[j].m_strokeIndex >= 0)
|
|
Toshihiro Shimizu |
890ddd |
currInt->m_intersection = m_strokes[v[j].m_strokeIndex]->m_s->getPoint(v[j].m_w);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < m_strokes.size(); i++)
|
|
Toshihiro Shimizu |
890ddd |
m_strokes[i]->m_isNewForFill = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//computeRegions();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
vector<uint> toBeDeleted;</uint>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p1 = intList.first(); p1; p1 = p1->next())
|
|
Toshihiro Shimizu |
890ddd |
for (p2 = p1->m_strokeList.first(); p2; p2 = p2->next()) {
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_index < 0 && !p2->m_edge.m_s &&
|
|
Toshihiro Shimizu |
890ddd |
(p2->m_edge.m_w0 == 0 || p2->m_edge.m_w0 == 1)) {
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_s = reconstructAutocloseStroke(p1, p2);
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_s)
|
|
Toshihiro Shimizu |
890ddd |
m_intersectionData->m_autocloseMap[p2->m_edge.m_index] = new VIStroke(p2->m_edge.m_s, TGroupId());
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
toBeDeleted.push_back(p2->m_edge.m_index);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p1 = intList.first(); p1; p1 = p1->next())
|
|
Toshihiro Shimizu |
890ddd |
for (p2 = p1->m_strokeList.first(); p2; p2 = p2->next()) {
|
|
Toshihiro Shimizu |
890ddd |
if (!p2->m_edge.m_s && p2->m_edge.m_index < 0) {
|
|
Toshihiro Shimizu |
890ddd |
VIStroke *vs = m_intersectionData->m_autocloseMap[p2->m_edge.m_index];
|
|
Toshihiro Shimizu |
890ddd |
if (vs) {
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_s = m_intersectionData->m_autocloseMap[p2->m_edge.m_index]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//TEdge& e = it2->m_edge;
|
|
Toshihiro Shimizu |
890ddd |
if (!p2->m_edge.m_s)
|
|
Toshihiro Shimizu |
890ddd |
toBeDeleted.push_back(p2->m_edge.m_index);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < toBeDeleted.size(); i++)
|
|
Toshihiro Shimizu |
890ddd |
eraseIntersection(toBeDeleted[i]);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_areValidRegions = false;
|
|
Toshihiro Shimizu |
890ddd |
//}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (doComputeRegions)
|
|
Toshihiro Shimizu |
890ddd |
computeRegions();
|
|
Toshihiro Shimizu |
890ddd |
//print(m_intersectionData->m_intList, "C:\\temp\\intersectionDopoLoad.txt");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::Imp::eraseIntersection(int index)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
vector<int> autocloseStrokes;</int>
|
|
Toshihiro Shimizu |
890ddd |
doEraseIntersection(index, &autocloseStrokes);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i = 0; i < autocloseStrokes.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
doEraseIntersection(autocloseStrokes[i]);
|
|
Toshihiro Shimizu |
890ddd |
assert(autocloseStrokes[i] < 0);
|
|
Toshihiro Shimizu |
890ddd |
m_intersectionData->m_autocloseMap.erase(autocloseStrokes[i]);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void findNearestIntersection(VIList<intersection> &interList)</intersection>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p1 = interList.first(); p1; p1 = p1->next()) {
|
|
Toshihiro Shimizu |
890ddd |
for (p2 = p1->m_strokeList.first(); p2; p2 = p2->next()) {
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_nextIntersection) //already set
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int versus = (p2->m_gettingOut) ? 1 : -1;
|
|
Toshihiro Shimizu |
890ddd |
double minDelta = (std::numeric_limits<double>::max)();</double>
|
|
Toshihiro Shimizu |
890ddd |
Intersection *pp1, *p1Res;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *pp2, *p2Res;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (pp1 = p1; pp1; pp1 = pp1->next()) {
|
|
Toshihiro Shimizu |
890ddd |
if (pp1 == p1)
|
|
Toshihiro Shimizu |
890ddd |
pp2 = p2, pp2 = pp2->next();
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
pp2 = pp1->m_strokeList.first();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (; pp2; pp2 = pp2->next()) {
|
|
Toshihiro Shimizu |
890ddd |
if (pp2->m_edge.m_index == p2->m_edge.m_index &&
|
|
Toshihiro Shimizu |
890ddd |
pp2->m_gettingOut == !p2->m_gettingOut) {
|
|
Toshihiro Shimizu |
890ddd |
double delta = versus * (pp2->m_edge.m_w0 - p2->m_edge.m_w0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (delta > 0 && delta < minDelta) {
|
|
Toshihiro Shimizu |
890ddd |
p1Res = pp1;
|
|
Toshihiro Shimizu |
890ddd |
p2Res = pp2;
|
|
Toshihiro Shimizu |
890ddd |
minDelta = delta;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (minDelta != (std::numeric_limits<double>::max)()) {</double>
|
|
Toshihiro Shimizu |
890ddd |
p2Res->m_nextIntersection = p1;
|
|
Toshihiro Shimizu |
890ddd |
p2Res->m_nextStroke = p2;
|
|
Toshihiro Shimizu |
890ddd |
p2Res->m_edge.m_w1 = p2->m_edge.m_w0;
|
|
Toshihiro Shimizu |
890ddd |
p2->m_nextIntersection = p1Res;
|
|
Toshihiro Shimizu |
890ddd |
p2->m_nextStroke = p2Res;
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_w1 = p2Res->m_edge.m_w0;
|
|
Toshihiro Shimizu |
890ddd |
p1->m_numInter++;
|
|
Toshihiro Shimizu |
890ddd |
p1Res->m_numInter++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
void markDeadIntersections(VIList<intersection> &intList, Intersection *p);</intersection>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//questa funzione "cuscinetto" serve perche crashava il compilatore in release!!!
|
|
Toshihiro Shimizu |
890ddd |
void inline markDeadIntersectionsRic(VIList<intersection> &intList, Intersection *p)</intersection>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
markDeadIntersections(intList, p);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void markDeadIntersections(VIList<intersection> &intList, Intersection *p)</intersection>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p1 = p->m_strokeList.first();
|
|
Toshihiro Shimizu |
890ddd |
if (!p1)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (p->m_numInter == 1) {
|
|
Toshihiro Shimizu |
890ddd |
while (p1 && !!p1->m_nextIntersection)
|
|
Toshihiro Shimizu |
890ddd |
p1 = p1->next();
|
|
Toshihiro Shimizu |
890ddd |
assert(p1);
|
|
Toshihiro Shimizu |
890ddd |
if (!p1)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Intersection *nextInt = p1->m_nextIntersection;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *nextStroke = p1->m_nextStroke;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
p->m_numInter = 0;
|
|
Toshihiro Shimizu |
890ddd |
p1->m_nextIntersection = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (nextInt /*&& !nextStroke->m_dead*/) {
|
|
Toshihiro Shimizu |
890ddd |
nextInt->m_numInter--;
|
|
Toshihiro Shimizu |
890ddd |
nextStroke->m_nextIntersection = 0;
|
|
Toshihiro Shimizu |
890ddd |
markDeadIntersectionsRic(intList, nextInt);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else if (p->m_numInter == 2) //intersezione finta (forse)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
while (p1 && !p1->m_nextIntersection)
|
|
Toshihiro Shimizu |
890ddd |
p1 = p1->next();
|
|
Toshihiro Shimizu |
890ddd |
assert(p1);
|
|
Toshihiro Shimizu |
890ddd |
if (!p1)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2 = p1->next();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (p2 && !p2->m_nextIntersection)
|
|
Toshihiro Shimizu |
890ddd |
p2 = p2->next();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(p2);
|
|
Toshihiro Shimizu |
890ddd |
if (!p2)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (p1->m_edge.m_s == p2->m_edge.m_s && p1->m_edge.m_w0 == p2->m_edge.m_w0) //intersezione finta
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *pp1, *pp2;
|
|
Toshihiro Shimizu |
890ddd |
assert(p1->m_nextIntersection && p2->m_nextIntersection);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
pp1 = p1->m_nextStroke;
|
|
Toshihiro Shimizu |
890ddd |
pp2 = p2->m_nextStroke;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
pp2->m_edge.m_w1 = pp1->m_edge.m_w0;
|
|
Toshihiro Shimizu |
890ddd |
pp1->m_edge.m_w1 = pp2->m_edge.m_w0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//if (iit1!=0)
|
|
Toshihiro Shimizu |
890ddd |
pp1->m_nextStroke = pp2;
|
|
Toshihiro Shimizu |
890ddd |
//if (iit2!=0)
|
|
Toshihiro Shimizu |
890ddd |
pp2->m_nextStroke = pp1;
|
|
Toshihiro Shimizu |
890ddd |
//if (iit1!=0)
|
|
Toshihiro Shimizu |
890ddd |
pp1->m_nextIntersection = p2->m_nextIntersection;
|
|
Toshihiro Shimizu |
890ddd |
//if (iit2!=0)
|
|
Toshihiro Shimizu |
890ddd |
pp2->m_nextIntersection = p1->m_nextIntersection;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
p->m_numInter = 0;
|
|
Toshihiro Shimizu |
890ddd |
p1->m_nextIntersection = p2->m_nextIntersection = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//se cross val era 0, cerco di spostarmi un po' su w per vedere come sono orientate le tangenti agli stroke...
|
|
Toshihiro Shimizu |
890ddd |
double nearCrossVal(TStroke *s0, double w0, TStroke *s1, double w1)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double ltot0 = s0->getLength();
|
|
Toshihiro Shimizu |
890ddd |
double ltot1 = s1->getLength();
|
|
Toshihiro Shimizu |
890ddd |
double dl = tmin(ltot1, ltot0) / 1000;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double crossVal, dl0 = dl, dl1 = dl;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD p0, p1;
|
|
Toshihiro Shimizu |
890ddd |
int count = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (w0 == 1.0)
|
|
Toshihiro Shimizu |
890ddd |
dl0 = -dl0;
|
|
Toshihiro Shimizu |
890ddd |
if (w1 == 1.0)
|
|
Toshihiro Shimizu |
890ddd |
dl1 = -dl1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double l0 = s0->getLength(w0) + dl0;
|
|
Toshihiro Shimizu |
890ddd |
double l1 = s1->getLength(w1) + dl1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
do {
|
|
Toshihiro Shimizu |
890ddd |
p0 = s0->getSpeed(s0->getParameterAtLength(l0));
|
|
Toshihiro Shimizu |
890ddd |
p1 = s1->getSpeed(s1->getParameterAtLength(l1));
|
|
Toshihiro Shimizu |
890ddd |
crossVal = cross(p0, p1);
|
|
Toshihiro Shimizu |
890ddd |
l0 += dl0, l1 += dl1;
|
|
Toshihiro Shimizu |
890ddd |
count++;
|
|
Toshihiro Shimizu |
890ddd |
} while (areAlmostEqual(crossVal, 0.0) &&
|
|
Toshihiro Shimizu |
890ddd |
((dl0 > 0 && l0 < ltot0) || (dl0 < 0 && l0 > 0)) &&
|
|
Toshihiro Shimizu |
890ddd |
((dl1 > 0 && l1 < ltot1) || (dl1 < 0 && l1 > 0)));
|
|
Toshihiro Shimizu |
890ddd |
return crossVal;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline void insertBranch(Intersection &in, IntersectedStroke &item, bool gettingOut)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (item.m_edge.m_w0 != (gettingOut ? 1.0 : 0.0)) {
|
|
Toshihiro Shimizu |
890ddd |
item.m_gettingOut = gettingOut;
|
|
Toshihiro Shimizu |
890ddd |
in.m_strokeList.pushBack(new IntersectedStroke(item));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double getAngle(const TPointD &p0, const TPointD &p1)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double angle1 = 180 * atan2(p0.x, p0.y) / TConsts::pi;
|
|
Toshihiro Shimizu |
890ddd |
double angle2 = 180 * atan2(p1.x, p1.y) / TConsts::pi;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (angle1 < 0)
|
|
Toshihiro Shimizu |
890ddd |
angle1 = 360 + angle1;
|
|
Toshihiro Shimizu |
890ddd |
if (angle2 < 0)
|
|
Toshihiro Shimizu |
890ddd |
angle2 = 360 + angle2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (angle2 - angle1) < 0 ? 360 + angle2 - angle1 : angle2 - angle1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//nel caso l'angolo tra due stroke in un certo w sia nullo,
|
|
Toshihiro Shimizu |
890ddd |
// si va un po' avanti per vedere come sono orientate....
|
|
Toshihiro Shimizu |
890ddd |
double getNearAngle(const TStroke *s1, double w1, bool out1, const TStroke *s2, double w2, bool out2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
bool verse1 = (out1 && w1 < 1) || (!out1 && w1 == 0);
|
|
Toshihiro Shimizu |
890ddd |
bool verse2 = (out2 && w2 < 1) || (!out2 && w2 == 0);
|
|
Toshihiro Shimizu |
890ddd |
double ltot1 = s1->getLength();
|
|
Toshihiro Shimizu |
890ddd |
double ltot2 = s2->getLength();
|
|
Toshihiro Shimizu |
890ddd |
double l1 = s1->getLength(w1);
|
|
Toshihiro Shimizu |
890ddd |
double l2 = s2->getLength(w2);
|
|
Toshihiro Shimizu |
890ddd |
double dl = min(ltot1, ltot2) / 1000;
|
|
Toshihiro Shimizu |
890ddd |
double dl1 = verse1 ? dl : -dl;
|
|
Toshihiro Shimizu |
890ddd |
double dl2 = verse2 ? dl : -dl;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (((verse1 && l1 < ltot1) || (!verse1 && l1 > 0)) && ((verse2 && l2 < ltot2) || (!verse2 && l2 > 0))) {
|
|
Toshihiro Shimizu |
890ddd |
l1 += dl1;
|
|
Toshihiro Shimizu |
890ddd |
l2 += dl2;
|
|
Toshihiro Shimizu |
890ddd |
TPointD p1 = (out1 ? 1 : -1) * s1->getSpeed(s1->getParameterAtLength(l1));
|
|
Toshihiro Shimizu |
890ddd |
TPointD p2 = (out2 ? 1 : -1) * s2->getSpeed(s2->getParameterAtLength(l2));
|
|
Toshihiro Shimizu |
890ddd |
double angle = getAngle(p1, p2);
|
|
Toshihiro Shimizu |
890ddd |
if (!areAlmostEqual(angle, 0, 1e-9))
|
|
Toshihiro Shimizu |
890ddd |
return angle;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool makeEdgeIntersection(Intersection &interList, IntersectedStroke &item1, IntersectedStroke &item2,
|
|
Toshihiro Shimizu |
890ddd |
const TPointD &p1a, const TPointD &p1b, const TPointD &p2a, const TPointD &p2b)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double angle1 = getAngle(p1a, p1b);
|
|
Toshihiro Shimizu |
890ddd |
double angle2 = getAngle(p1a, p2a);
|
|
Toshihiro Shimizu |
890ddd |
double angle3 = getAngle(p1a, p2b);
|
|
Toshihiro Shimizu |
890ddd |
double angle;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool eraseP1b = false, eraseP2a = false, eraseP2b = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(angle1, 0, 1e-9)) {
|
|
Toshihiro Shimizu |
890ddd |
angle1 = getNearAngle(item1.m_edge.m_s, item1.m_edge.m_w0, true, item1.m_edge.m_s, item1.m_edge.m_w0, false);
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(angle1, 1e-9))
|
|
Toshihiro Shimizu |
890ddd |
eraseP1b = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(angle2, 0, 1e-9)) {
|
|
Toshihiro Shimizu |
890ddd |
angle2 = getNearAngle(item1.m_edge.m_s, item1.m_edge.m_w0, true, item2.m_edge.m_s, item2.m_edge.m_w0, true);
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(angle2, 1e-9))
|
|
Toshihiro Shimizu |
890ddd |
eraseP2a = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(angle3, 0, 1e-9)) {
|
|
Toshihiro Shimizu |
890ddd |
angle3 = getNearAngle(item1.m_edge.m_s, item1.m_edge.m_w0, true, item2.m_edge.m_s, item2.m_edge.m_w0, false);
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(angle3, 1e-9))
|
|
Toshihiro Shimizu |
890ddd |
eraseP2b = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(angle1, angle2, 1e-9)) {
|
|
Toshihiro Shimizu |
890ddd |
angle = getNearAngle(item1.m_edge.m_s, item1.m_edge.m_w0, false, item2.m_edge.m_s, item2.m_edge.m_w0, true);
|
|
Toshihiro Shimizu |
890ddd |
if (angle != 0) {
|
|
Toshihiro Shimizu |
890ddd |
angle2 += angle;
|
|
Toshihiro Shimizu |
890ddd |
if (angle2 > 360)
|
|
Toshihiro Shimizu |
890ddd |
angle2 -= 360;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
eraseP2a = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(angle1, angle3, 1e-9)) {
|
|
Toshihiro Shimizu |
890ddd |
angle = getNearAngle(item1.m_edge.m_s, item1.m_edge.m_w0, false, item2.m_edge.m_s, item2.m_edge.m_w0, false);
|
|
Toshihiro Shimizu |
890ddd |
if (angle != 0) {
|
|
Toshihiro Shimizu |
890ddd |
angle3 += angle;
|
|
Toshihiro Shimizu |
890ddd |
if (angle3 > 360)
|
|
Toshihiro Shimizu |
890ddd |
angle3 -= 360;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
eraseP2b = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(angle2, angle3, 1e-9)) {
|
|
Toshihiro Shimizu |
890ddd |
angle = getNearAngle(item1.m_edge.m_s, item1.m_edge.m_w0, false, item2.m_edge.m_s, item2.m_edge.m_w0, true);
|
|
Toshihiro Shimizu |
890ddd |
if (angle != 0) {
|
|
Toshihiro Shimizu |
890ddd |
angle3 += angle;
|
|
Toshihiro Shimizu |
890ddd |
if (angle3 > 360)
|
|
Toshihiro Shimizu |
890ddd |
angle3 -= 360;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
eraseP2b = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int fac = (angle1 < angle2) | ((angle1 < angle3) << 1) | ((angle2 < angle3) << 2);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
switch (fac) {
|
|
Toshihiro Shimizu |
890ddd |
CASE 0 : //p1a p2b p2a p1b
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item1, true);
|
|
Toshihiro Shimizu |
890ddd |
if (!eraseP2b)
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item2, false);
|
|
Toshihiro Shimizu |
890ddd |
if (!eraseP2a)
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item2, true);
|
|
Toshihiro Shimizu |
890ddd |
if (!eraseP1b)
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item1, false);
|
|
Toshihiro Shimizu |
890ddd |
CASE 1 : //p1a p2b p1b p2a
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item1, true);
|
|
Toshihiro Shimizu |
890ddd |
if (!eraseP2b)
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item2, false);
|
|
Toshihiro Shimizu |
890ddd |
if (!eraseP1b)
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item1, false);
|
|
Toshihiro Shimizu |
890ddd |
if (!eraseP2a)
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item2, true);
|
|
Toshihiro Shimizu |
890ddd |
CASE 2 : assert(false);
|
|
Toshihiro Shimizu |
890ddd |
CASE 3 : //p1a p1b p2b p2a
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item1, true);
|
|
Toshihiro Shimizu |
890ddd |
if (!eraseP1b)
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item1, false);
|
|
Toshihiro Shimizu |
890ddd |
if (!eraseP2b)
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item2, false);
|
|
Toshihiro Shimizu |
890ddd |
if (!eraseP2a)
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item2, true);
|
|
Toshihiro Shimizu |
890ddd |
CASE 4 : //p1a p2a p2b p1b
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item1, true);
|
|
Toshihiro Shimizu |
890ddd |
if (!eraseP2a)
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item2, true);
|
|
Toshihiro Shimizu |
890ddd |
if (!eraseP2b)
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item2, false);
|
|
Toshihiro Shimizu |
890ddd |
if (!eraseP1b)
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item1, false);
|
|
Toshihiro Shimizu |
890ddd |
CASE 5 : assert(false);
|
|
Toshihiro Shimizu |
890ddd |
CASE 6 : //p1a p2a p1b p2b
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item1, true);
|
|
Toshihiro Shimizu |
890ddd |
if (!eraseP2a)
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item2, true);
|
|
Toshihiro Shimizu |
890ddd |
if (!eraseP1b)
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item1, false);
|
|
Toshihiro Shimizu |
890ddd |
if (!eraseP2b)
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item2, false);
|
|
Toshihiro Shimizu |
890ddd |
CASE 7 : //p1a p1b p2a p2b
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item1, true);
|
|
Toshihiro Shimizu |
890ddd |
if (!eraseP1b)
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item1, false);
|
|
Toshihiro Shimizu |
890ddd |
if (!eraseP2a)
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item2, true);
|
|
Toshihiro Shimizu |
890ddd |
if (!eraseP2b)
|
|
Toshihiro Shimizu |
890ddd |
insertBranch(interList, item2, false);
|
|
Toshihiro Shimizu |
890ddd |
DEFAULT:
|
|
Toshihiro Shimizu |
890ddd |
assert(false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool makeIntersection(IntersectionData &intData, const vector<vistroke *=""> &s, int ii, int jj,</vistroke>
|
|
Toshihiro Shimizu |
890ddd |
DoublePair inter, int strokeSize, Intersection &interList)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke item1, item2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
interList.m_intersection = s[ii]->m_s->getPoint(inter.first);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
item1.m_edge.m_w0 = inter.first;
|
|
Toshihiro Shimizu |
890ddd |
item2.m_edge.m_w0 = inter.second;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (ii >= 0 && ii < strokeSize) {
|
|
Toshihiro Shimizu |
890ddd |
item1.m_edge.m_s = s[ii]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
item1.m_edge.m_index = ii;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
if (ii < 0) {
|
|
Toshihiro Shimizu |
890ddd |
item1.m_edge.m_s = intData.m_autocloseMap[ii]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
item1.m_edge.m_index = ii;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
item1.m_edge.m_s = s[ii]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
item1.m_edge.m_index = -(ii + intData.maxAutocloseId * 100000);
|
|
Toshihiro Shimizu |
890ddd |
intData.m_autocloseMap[item1.m_edge.m_index] = s[ii];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (jj >= 0 && jj < strokeSize) {
|
|
Toshihiro Shimizu |
890ddd |
item2.m_edge.m_s = s[jj]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
item2.m_edge.m_index = jj;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
if (jj < 0) {
|
|
Toshihiro Shimizu |
890ddd |
item2.m_edge.m_s = intData.m_autocloseMap[jj]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
item2.m_edge.m_index = jj;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
item2.m_edge.m_s = s[jj]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
item2.m_edge.m_index = -(jj + intData.maxAutocloseId * 100000);
|
|
Toshihiro Shimizu |
890ddd |
intData.m_autocloseMap[item2.m_edge.m_index] = s[jj];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool reversed = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD p0, p0b, p1, p1b;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool ret1 = item1.m_edge.m_s->getSpeedTwoValues(item1.m_edge.m_w0, p0, p0b);
|
|
Toshihiro Shimizu |
890ddd |
bool ret2 = item2.m_edge.m_s->getSpeedTwoValues(item2.m_edge.m_w0, p1, p1b);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (ret1 || ret2) //punto angoloso!!!!
|
|
Toshihiro Shimizu |
890ddd |
return makeEdgeIntersection(interList, item1, item2, p0, p0b, p1, p1b);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double crossVal = cross(p0, p1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//crossVal = cross(p0, p1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(crossVal, 0.0)) {
|
|
Toshihiro Shimizu |
890ddd |
bool endpoint1 = (item1.m_edge.m_w0 == 0.0 || item1.m_edge.m_w0 == 1.0);
|
|
Toshihiro Shimizu |
890ddd |
bool endpoint2 = (item2.m_edge.m_w0 == 0.0 || item2.m_edge.m_w0 == 1.0);
|
|
Toshihiro Shimizu |
890ddd |
if (endpoint1 &&
|
|
Toshihiro Shimizu |
890ddd |
endpoint2 &&
|
|
Toshihiro Shimizu |
890ddd |
((p0.x * p1.x >= 0 && p0.y * p1.y >= 0 && item1.m_edge.m_w0 != item2.m_edge.m_w0) ||
|
|
Toshihiro Shimizu |
890ddd |
(p0.x * p1.x <= 0 && p0.y * p1.y <= 0 && item1.m_edge.m_w0 == item2.m_edge.m_w0)))
|
|
Toshihiro Shimizu |
890ddd |
//due endpoint a 180 gradi;metto
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
item1.m_gettingOut = (item1.m_edge.m_w0 == 0.0);
|
|
Toshihiro Shimizu |
890ddd |
interList.m_strokeList.pushBack(new IntersectedStroke(item1));
|
|
Toshihiro Shimizu |
890ddd |
item2.m_gettingOut = (item2.m_edge.m_w0 == 0.0);
|
|
Toshihiro Shimizu |
890ddd |
interList.m_strokeList.pushBack(new IntersectedStroke(item2));
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//crossVal = nearCrossVal(item1.m_edge.m_s, item1.m_edge.m_w0, item2.m_edge.m_s, item2.m_edge.m_w0);
|
|
Toshihiro Shimizu |
890ddd |
//if (areAlmostEqual(crossVal, 0.0))
|
|
Toshihiro Shimizu |
890ddd |
// return false;
|
|
Toshihiro Shimizu |
890ddd |
return makeEdgeIntersection(interList, item1, item2, p0, p0b, p1, p1b);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (crossVal > 0)
|
|
Toshihiro Shimizu |
890ddd |
reversed = true; //std::reverse(interList.m_strokeList.begin(), interList.m_strokeList.end());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (item1.m_edge.m_w0 != 1.0) {
|
|
Toshihiro Shimizu |
890ddd |
item1.m_gettingOut = true;
|
|
Toshihiro Shimizu |
890ddd |
interList.m_strokeList.pushBack(new IntersectedStroke(item1));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (item2.m_edge.m_w0 != (reversed ? 0.0 : 1.0)) {
|
|
Toshihiro Shimizu |
890ddd |
item2.m_gettingOut = !reversed;
|
|
Toshihiro Shimizu |
890ddd |
interList.m_strokeList.pushBack(new IntersectedStroke(item2));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (item1.m_edge.m_w0 != 0.0) {
|
|
Toshihiro Shimizu |
890ddd |
item1.m_gettingOut = false;
|
|
Toshihiro Shimizu |
890ddd |
interList.m_strokeList.pushBack(new IntersectedStroke(item1));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (item2.m_edge.m_w0 != (reversed ? 1.0 : 0.0)) {
|
|
Toshihiro Shimizu |
890ddd |
item2.m_gettingOut = reversed;
|
|
Toshihiro Shimizu |
890ddd |
interList.m_strokeList.pushBack(new IntersectedStroke(item2));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
void checkAuto(const vector<vistroke*>& s)</vistroke*>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (int i=0; i<(int)s.size(); i++)
|
|
Toshihiro Shimizu |
890ddd |
for (int j=i+1; j<(int)s.size(); j++)
|
|
Toshihiro Shimizu |
890ddd |
if (s[i]->m_s->getChunkCount()==1 && s[j]->m_s->getChunkCount()==1) //se ha una sola quadratica, probabilmente e' un autoclose.
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const TThickQuadratic*q = s[i]->m_s->getChunk(0);
|
|
Toshihiro Shimizu |
890ddd |
const TThickQuadratic*p = s[j]->m_s->getChunk(0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(q->getP0(), p->getP0(), 1e-2) && areAlmostEqual(q->getP2(), p->getP2(), 1e-2))
|
|
Toshihiro Shimizu |
890ddd |
assert(!"eccolo!");
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(q->getP0(), p->getP2(), 1e-2) && areAlmostEqual(q->getP2(), p->getP0(), 1e-2))
|
|
Toshihiro Shimizu |
890ddd |
assert(!"eccolo!");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool addAutocloseIntersection(IntersectionData &intData, vector<vistroke *=""> &s,</vistroke>
|
|
Toshihiro Shimizu |
890ddd |
int ii, int jj, double w0, double w1, int strokeSize, bool isVectorized)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(s[ii]->m_groupId == s[jj]->m_groupId);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Intersection *rp = intData.m_intList.last();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(w0 >= 0.0 && w0 <= 1.0);
|
|
Toshihiro Shimizu |
890ddd |
assert(w1 >= 0.0 && w1 <= 1.0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (; rp; rp = rp->prev()) // evito di fare la connessione, se gia' ce
|
|
Toshihiro Shimizu |
890ddd |
// ne e' una simile tra le stesse due stroke
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (rp->m_strokeList.size() < 2)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *ps = rp->m_strokeList.first();
|
|
Toshihiro Shimizu |
890ddd |
int s0 = ps->m_edge.m_index;
|
|
Toshihiro Shimizu |
890ddd |
if (s0 < 0)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
double ww0 = ps->m_edge.m_w0;
|
|
Toshihiro Shimizu |
890ddd |
ps = ps->next();
|
|
Toshihiro Shimizu |
890ddd |
if (ps->m_edge.m_index == s0 && ps->m_edge.m_w0 == ww0) {
|
|
Toshihiro Shimizu |
890ddd |
ps = ps->next();
|
|
Toshihiro Shimizu |
890ddd |
if (!ps)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
int s1 = ps->m_edge.m_index;
|
|
Toshihiro Shimizu |
890ddd |
if (s1 < 0)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
double ww1 = ps->m_edge.m_w0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!((s0 == ii && s1 == jj) || (s0 == jj && s1 == ii)))
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (s0 == ii && areAlmostEqual(w0, ww0, 0.1) && areAlmostEqual(w1, ww1, 0.1))
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
else if (s1 == ii && areAlmostEqual(w0, ww1, 0.1) && areAlmostEqual(w1, ww0, 0.1))
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
vector<tpointd> v;</tpointd>
|
|
Toshihiro Shimizu |
890ddd |
v.push_back(s[ii]->m_s->getPoint(w0));
|
|
Toshihiro Shimizu |
890ddd |
v.push_back(s[jj]->m_s->getPoint(w1));
|
|
Toshihiro Shimizu |
890ddd |
if (v[0] == v[1]) //le stroke si intersecano , ma la fottuta funzione intersect non ha trovato l'intersezione(tipicamente, questo accade agli estremi)!!!
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
addIntersection(intData, s, ii, jj, DoublePair(w0, w1), strokeSize, isVectorized);
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//se gia e' stato messo questo autoclose, evito
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < (int)s.size(); i++)
|
|
Toshihiro Shimizu |
890ddd |
if (s[i]->m_s->getChunkCount() == 1) //se ha una sola quadratica, probabilmente e' un autoclose.
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const TThickQuadratic *q = s[i]->m_s->getChunk(0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(q->getP0(), v[0], 1e-2) && areAlmostEqual(q->getP2(), v[1], 1e-2) ||
|
|
Toshihiro Shimizu |
890ddd |
areAlmostEqual(q->getP0(), v[1], 1e-2) && areAlmostEqual(q->getP2(), v[0], 1e-2)) {
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
addIntersection(intData, s, i, ii, DoublePair(0.0, w0), strokeSize, isVectorized);
|
|
Toshihiro Shimizu |
890ddd |
addIntersection(intData, s, i, jj, DoublePair(1.0, w1), strokeSize, isVectorized);
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
assert(s[ii]->m_groupId == s[jj]->m_groupId);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
s.push_back(new VIStroke(new TStroke(v), s[ii]->m_groupId));
|
|
Toshihiro Shimizu |
890ddd |
addIntersection(intData, s, s.size() - 1, ii, DoublePair(0.0, w0), strokeSize, isVectorized);
|
|
Toshihiro Shimizu |
890ddd |
addIntersection(intData, s, s.size() - 1, jj, DoublePair(1.0, w1), strokeSize, isVectorized);
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//double g_autocloseTolerance = c_newAutocloseTolerance;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isCloseEnoughP2P(double facMin, double facMax, TStroke *s1, double w0, TStroke *s2, double w1)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double autoDistMin, autoDistMax;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint p0 = s1->getThickPoint(w0);
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint p1 = s2->getThickPoint(w1);
|
|
Toshihiro Shimizu |
890ddd |
double dist2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
dist2 = tdistance2(p0, p1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!when closing beetween a normal stroke and a 0-thickness stroke (very typical) the thin one is assumed to have same thickness of the other*/
|
|
Toshihiro Shimizu |
890ddd |
if (p0.thick == 0)
|
|
Toshihiro Shimizu |
890ddd |
p0.thick = p1.thick;
|
|
Toshihiro Shimizu |
890ddd |
else if (p1.thick == 0)
|
|
Toshihiro Shimizu |
890ddd |
p1.thick = p0.thick;
|
|
Toshihiro Shimizu |
890ddd |
if (facMin == 0) {
|
|
Toshihiro Shimizu |
890ddd |
autoDistMin = 0;
|
|
Toshihiro Shimizu |
890ddd |
autoDistMax = tmax(-2.0, facMax * (p0.thick + p1.thick) * (p0.thick + p1.thick));
|
|
Toshihiro Shimizu |
890ddd |
if (autoDistMax < 0.0000001) //! for strokes without thickness, I connect for distances less than min between 2.5 and half of the length of the stroke)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double len1 = s1->getLength();
|
|
Toshihiro Shimizu |
890ddd |
double len2 = s2->getLength();
|
|
Toshihiro Shimizu |
890ddd |
autoDistMax = facMax * tmin(2.5, len1 * len1 / (2 * 2), len2 * len2 / (2 * 2), 100.0 /*dummyVal*/);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
autoDistMin = tmax(-2.0, facMin * (p0.thick + p1.thick) * (p0.thick + p1.thick));
|
|
Toshihiro Shimizu |
890ddd |
if (autoDistMin < 0.0000001) //! for strokes without thickness, I connect for distances less than min between 2.5 and half of the length of the stroke)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double len1 = s1->getLength();
|
|
Toshihiro Shimizu |
890ddd |
double len2 = s2->getLength();
|
|
Toshihiro Shimizu |
890ddd |
autoDistMin = facMax * tmin(2.5, len1 * len1 / (2 * 2), len2 * len2 / (2 * 2), 100.0 /*dummyVal*/);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
autoDistMax = autoDistMin + (facMax - facMin) * (facMax - facMin);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (dist2 < autoDistMin || dist2 > autoDistMax)
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//if (dist2<=tmax(2.0, g_autocloseTolerance*(p0.thick+p1.thick)*(p0.thick+p1.thick))) //0.01 tiene conto di quando thick==0
|
|
Toshihiro Shimizu |
890ddd |
if (s1 == s2) {
|
|
Toshihiro Shimizu |
890ddd |
TRectD r = s1->getBBox(); //se e' un autoclose su una stroke piccolissima, creerebbe uan area trascurabile, ignoro
|
|
Toshihiro Shimizu |
890ddd |
if (fabs(r.x1 - r.x0) < 2 && fabs(r.y1 - r.y0) < 2)
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
bool makePoint2PointConnections(double factor, vector<vistroke*>& s, </vistroke*>
|
|
Toshihiro Shimizu |
890ddd |
int ii, bool isIStartPoint,
|
|
Toshihiro Shimizu |
890ddd |
int jj, bool isJStartPoint, IntersectionData& intData,
|
|
Toshihiro Shimizu |
890ddd |
int strokeSize)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double w0 = (isIStartPoint?0.0:1.0);
|
|
Toshihiro Shimizu |
890ddd |
double w1 = (isJStartPoint?0.0:1.0);
|
|
Toshihiro Shimizu |
890ddd |
if (isCloseEnoughP2P(factor, s[ii]->m_s, w0, s[jj]->m_s, w1))
|
|
Toshihiro Shimizu |
890ddd |
return addAutocloseIntersection(intData, s, ii, jj, w0, w1, strokeSize);
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double getCurlW(TStroke *s, bool isBegin) //trova il punto di split su una stroke, in prossimita di un ricciolo;
|
|
Toshihiro Shimizu |
890ddd |
// un ricciolo c'e' se la curva ha un min o max relativo su x seguito da uno su y, o viceversa.
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int numChunks = s->getChunkCount();
|
|
Toshihiro Shimizu |
890ddd |
double dx2, dx1 = 0, dy2, dy1 = 0;
|
|
Toshihiro Shimizu |
890ddd |
int i = 0;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < numChunks; i++) {
|
|
Toshihiro Shimizu |
890ddd |
const TQuadratic *q = s->getChunk(isBegin ? i : numChunks - 1 - i);
|
|
Toshihiro Shimizu |
890ddd |
dy2 = q->getP1().y - q->getP0().y;
|
|
Toshihiro Shimizu |
890ddd |
if (dy1 * dy2 < 0)
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
dy1 = dy2;
|
|
Toshihiro Shimizu |
890ddd |
dy2 = q->getP2().y - q->getP1().y;
|
|
Toshihiro Shimizu |
890ddd |
if (dy1 * dy2 < 0)
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
dy1 = dy2;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (i == numChunks)
|
|
Toshihiro Shimizu |
890ddd |
return -1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int maxMin0 = isBegin ? i : numChunks - 1 - i;
|
|
Toshihiro Shimizu |
890ddd |
int j = 0;
|
|
Toshihiro Shimizu |
890ddd |
for (j = 0; j < numChunks; j++) {
|
|
Toshihiro Shimizu |
890ddd |
const TQuadratic *q = s->getChunk(isBegin ? j : numChunks - 1 - j);
|
|
Toshihiro Shimizu |
890ddd |
dx2 = q->getP1().x - q->getP0().x;
|
|
Toshihiro Shimizu |
890ddd |
if (dx1 * dx2 < 0)
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
dx1 = dx2;
|
|
Toshihiro Shimizu |
890ddd |
dx2 = q->getP2().x - q->getP1().x;
|
|
Toshihiro Shimizu |
890ddd |
if (dx1 * dx2 < 0)
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
dx1 = dx2;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (j == numChunks)
|
|
Toshihiro Shimizu |
890ddd |
return -1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int maxMin1 = isBegin ? j : numChunks - 1 - j;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return getWfromChunkAndT(s, isBegin ? tmax(maxMin0, maxMin1) : tmin(maxMin0, maxMin1), isBegin ? 1.0 : 0.0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef Levo
|
|
Toshihiro Shimizu |
890ddd |
bool lastIsX = false, lastIsY = false;
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < numChunks; i++) {
|
|
Toshihiro Shimizu |
890ddd |
const TThickQuadratic *q = s->getChunk(isBegin ? i : numChunks - 1 - i);
|
|
Toshihiro Shimizu |
890ddd |
if ((q->getP0().y < q->getP1().y && q->getP2().y < q->getP1().y) || //la quadratica ha un minimo o massimo relativo
|
|
Toshihiro Shimizu |
890ddd |
(q->getP0().y > q->getP1().y && q->getP2().y > q->getP1().y)) {
|
|
Toshihiro Shimizu |
890ddd |
double w = getWfromChunkAndT(s, isBegin ? i : numChunks - 1 - i, isBegin ? 1.0 : 0.0);
|
|
Toshihiro Shimizu |
890ddd |
if (lastIsX) //e' il secondo min o max relativo
|
|
Toshihiro Shimizu |
890ddd |
return w;
|
|
Toshihiro Shimizu |
890ddd |
lastIsX = false;
|
|
Toshihiro Shimizu |
890ddd |
lastIsY = true;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} else if ((q->getP0().x < q->getP1().x && q->getP2().x < q->getP1().x) || //la quadratica ha un minimo o massimo relativo
|
|
Toshihiro Shimizu |
890ddd |
(q->getP0().x > q->getP1().x && q->getP2().x > q->getP1().x)) {
|
|
Toshihiro Shimizu |
890ddd |
double w = getWfromChunkAndT(s, isBegin ? i : numChunks - 1 - i, isBegin ? 1.0 : 0.0);
|
|
Toshihiro Shimizu |
890ddd |
if (lastIsY) //e' il secondo min o max relativo
|
|
Toshihiro Shimizu |
890ddd |
return w;
|
|
Toshihiro Shimizu |
890ddd |
lastIsX = true;
|
|
Toshihiro Shimizu |
890ddd |
lastIsY = false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return -1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isCloseEnoughP2L(double facMin, double facMax, TStroke *s1, double w1, TStroke *s2, double &w)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (s1->isSelfLoop())
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint p0 = s1->getThickPoint(w1);
|
|
Toshihiro Shimizu |
890ddd |
double t, dist2;
|
|
Toshihiro Shimizu |
890ddd |
int index;
|
|
Toshihiro Shimizu |
890ddd |
TStroke sAux, *sComp;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (s1 == s2) //per trovare le intersezioni con una stroke e se stessa, si toglie il
|
|
Toshihiro Shimizu |
890ddd |
//pezzo di stroke di cui si cercano vicinanze fino alla prima curva
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double w = getCurlW(s1, w1 == 0.0);
|
|
Toshihiro Shimizu |
890ddd |
if (w == -1)
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
split<tstroke>(*s1, tmin(1 - w1, w), tmax(1 - w1, w), sAux);</tstroke>
|
|
Toshihiro Shimizu |
890ddd |
sComp = &sAux;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
sComp = s2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (sComp->getNearestChunk(p0, t, index, dist2) && dist2 > 0) {
|
|
Toshihiro Shimizu |
890ddd |
if (s1 == s2) {
|
|
Toshihiro Shimizu |
890ddd |
double dummy;
|
|
Toshihiro Shimizu |
890ddd |
s2->getNearestChunk(sComp->getChunk(index)->getPoint(t), t, index, dummy);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//if (areAlmostEqual(w, 0.0, 0.05) || areAlmostEqual(w, 1.0, 0.05))
|
|
Toshihiro Shimizu |
890ddd |
// return; //se w e' vicino ad un estremo, rientra nell'autoclose point to point
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//if (s[jj]->m_s->getLength(w)<=s[jj]->m_s->getThickPoint(0).thick ||
|
|
Toshihiro Shimizu |
890ddd |
// s[jj]->m_s->getLength(w, 1)<=s[jj]->m_s->getThickPoint(1).thick)
|
|
Toshihiro Shimizu |
890ddd |
// return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint p1 = s2->getChunk(index)->getThickPoint(t);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!when closing beetween a normal stroke and a 0-thickness stroke (very typical) the thin one is assumed to have same thickness of the other*/
|
|
Toshihiro Shimizu |
890ddd |
if (p0.thick == 0)
|
|
Toshihiro Shimizu |
890ddd |
p0.thick = p1.thick;
|
|
Toshihiro Shimizu |
890ddd |
else if (p1.thick == 0)
|
|
Toshihiro Shimizu |
890ddd |
p1.thick = p0.thick;
|
|
Toshihiro Shimizu |
890ddd |
double autoDistMin, autoDistMax;
|
|
Toshihiro Shimizu |
890ddd |
if (facMin == 0) {
|
|
Toshihiro Shimizu |
890ddd |
autoDistMin = 0;
|
|
Toshihiro Shimizu |
890ddd |
autoDistMax = tmax(-2.0, (facMax + 0.7) * (p0.thick + p1.thick) * (p0.thick + p1.thick));
|
|
Toshihiro Shimizu |
890ddd |
if (autoDistMax < 0.0000001) //! for strokes without thickness, I connect for distances less than min between 2.5 and half of the length of the pointing stroke)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double len1 = s1->getLength();
|
|
Toshihiro Shimizu |
890ddd |
autoDistMax = facMax * tmin(2.5, len1 * len1 / (2 * 2));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
autoDistMin = tmax(-2.0, (facMin + 0.7) * (p0.thick + p1.thick) * (p0.thick + p1.thick));
|
|
Toshihiro Shimizu |
890ddd |
if (autoDistMin < 0.0000001) //! for strokes without thickness, I connect for distances less than min between 2.5 and half of the length of the pointing stroke)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double len1 = s1->getLength();
|
|
Toshihiro Shimizu |
890ddd |
autoDistMin = facMax * tmin(2.5, len1 * len1 / (2 * 2));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
autoDistMax = autoDistMin + (facMax - facMin + 0.7) * (facMax - facMin + 0.7);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//double autoDistMin = tmax(-2.0, facMin==0?0:(facMin+0.7)*(p0.thick+p1.thick)*(p0.thick+p1.thick));
|
|
Toshihiro Shimizu |
890ddd |
//double autoDistMax = tmax(-2.0, (facMax+0.7)*(p0.thick+p1.thick)*(p0.thick+p1.thick));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (dist2 < autoDistMin || dist2 > autoDistMax)
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//if (dist2<=(tmax(2.0, (g_autocloseTolerance+0.7)*(p0.thick+p1.thick)*(p0.thick+p1.thick)))) //0.01 tiene conto di quando thick==0
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
w = getWfromChunkAndT(s2, index, t);
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
void makePoint2LineConnection(double factor, vector<vistroke*>& s, int ii, int jj, bool isBegin, IntersectionData& intData, </vistroke*>
|
|
Toshihiro Shimizu |
890ddd |
int strokeSize)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double w1 = isBegin?0.0: 1.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TStroke* s1 = s[ii]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
TStroke* s2 = s[jj]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
double w;
|
|
Toshihiro Shimizu |
890ddd |
if (isCloseEnoughP2L(factor, s1, w1, s2, w))
|
|
Toshihiro Shimizu |
890ddd |
addAutocloseIntersection(intData, s, ii, jj, w1, w, strokeSize);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline bool isSegment(const TStroke &s)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
vector<tthickpoint> v;</tthickpoint>
|
|
Toshihiro Shimizu |
890ddd |
s.getControlPoints(v);
|
|
Toshihiro Shimizu |
890ddd |
UINT n = v.size();
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(v[n - 1].x, v[0].x, 1e-4)) {
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i = 1; i < n - 1; i++)
|
|
Toshihiro Shimizu |
890ddd |
if (!areAlmostEqual(v[i].x, v[0].x, 1e-4))
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
} else if (areAlmostEqual(v[n - 1].y, v[0].y, 1e-4)) {
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i = 1; i < n - 1; i++)
|
|
Toshihiro Shimizu |
890ddd |
if (!areAlmostEqual(v[i].y, v[0].y, 1e-4))
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
double fac = (v[n - 1].y - v[0].y) / (v[n - 1].x - v[0].x);
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i = 1; i < n - 1; i++)
|
|
Toshihiro Shimizu |
890ddd |
if (!areAlmostEqual((v[i].y - v[0].y) / (v[i].x - v[0].x), fac, 1e-4))
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
bool segmentAlreadyExist(const TVectorImageP& vi, const TPointD& p1, const TPointD& p2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i=0; i<vi->getStrokeCount(); i++)</vi->
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TStroke*s = vi->getStroke(i);
|
|
Toshihiro Shimizu |
890ddd |
if (!s->getBBox().contains(p1) || !s->getBBox().contains(p2))
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
if (((areAlmostEqual(s->getPoint(0.0), p1, 1e-4) && areAlmostEqual(s->getPoint(1.0), p2, 1e-4)) ||
|
|
Toshihiro Shimizu |
890ddd |
(areAlmostEqual(s->getPoint(0.0), p2, 1e-4) && areAlmostEqual(s->getPoint(1.0), p1, 1e-4))) &&
|
|
Toshihiro Shimizu |
890ddd |
isSegment(*s))
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool segmentAlreadyPresent(const TVectorImageP &vi, const TPointD &p1, const TPointD &p2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i = 0; i < vi->getStrokeCount(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s = vi->getStroke(i);
|
|
Toshihiro Shimizu |
890ddd |
if (((areAlmostEqual(s->getPoint(0.0), p1, 1e-4) && areAlmostEqual(s->getPoint(1.0), p2, 1e-4)) ||
|
|
Toshihiro Shimizu |
890ddd |
(areAlmostEqual(s->getPoint(0.0), p2, 1e-4) && areAlmostEqual(s->getPoint(1.0), p1, 1e-4))) &&
|
|
Toshihiro Shimizu |
890ddd |
isSegment(*s))
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i=0; i<vi->getStrokeCount(); i++)</vi->
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TStroke* s = vi->getStroke(i);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (s->getChunkCount()!=1)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual((TPointD)s->getControlPoint(0), p1, 1e-2) &&
|
|
Toshihiro Shimizu |
890ddd |
areAlmostEqual((TPointD)s->getControlPoint(s->getControlPointCount()-1), p2, 1e-2))
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void getClosingSegments(TL2LAutocloser &l2lautocloser, double facMin, double facMax, TStroke *s1, TStroke *s2,
|
|
Toshihiro Shimizu |
890ddd |
vector<doublepair> *intersections, vector<std::pair<double, double="">> &segments)</std::pair<double,></doublepair>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
bool ret1 = false, ret2 = false, ret3 = false, ret4 = false;
|
|
Toshihiro Shimizu |
890ddd |
#define L2LAUTOCLOSE
|
|
Toshihiro Shimizu |
890ddd |
#ifdef L2LAUTOCLOSE
|
|
Toshihiro Shimizu |
890ddd |
double thickmax2 = s1->getMaxThickness() + s2->getMaxThickness();
|
|
Toshihiro Shimizu |
890ddd |
thickmax2 *= thickmax2;
|
|
Toshihiro Shimizu |
890ddd |
if (facMin == 0)
|
|
Toshihiro Shimizu |
890ddd |
l2lautocloser.setMaxDistance2((facMax + 0.7) * thickmax2);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
l2lautocloser.setMaxDistance2((facMax + 0.7) * thickmax2 + (facMax - facMin + 0.7) * (facMax - facMin + 0.7));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::vector<tl2lautocloser::segment> l2lSegments;</tl2lautocloser::segment>
|
|
Toshihiro Shimizu |
890ddd |
if (intersections)
|
|
Toshihiro Shimizu |
890ddd |
l2lautocloser.search(l2lSegments, s1, s2, *intersections);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
l2lautocloser.search(l2lSegments, s1, s2);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i = 0; i < l2lSegments.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
TL2LAutocloser::Segment &seg = l2lSegments[i];
|
|
Toshihiro Shimizu |
890ddd |
double autoDistMin, autoDistMax;
|
|
Toshihiro Shimizu |
890ddd |
if (facMin == 0) {
|
|
Toshihiro Shimizu |
890ddd |
autoDistMin = 0;
|
|
Toshihiro Shimizu |
890ddd |
autoDistMax = (facMax + 0.7) * (seg.p0.thick + seg.p1.thick) * (seg.p0.thick + seg.p1.thick);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
autoDistMin = (facMin + 0.7) * (seg.p0.thick + seg.p1.thick) * (seg.p0.thick + seg.p1.thick);
|
|
Toshihiro Shimizu |
890ddd |
autoDistMax = autoDistMin + (facMax - facMin + 0.7) * (facMax - facMin + 0.7);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (seg.dist2 > autoDistMin && seg.dist2 < autoDistMax)
|
|
Toshihiro Shimizu |
890ddd |
segments.push_back(std::pair<double, double="">(seg.w0, seg.w1));</double,>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (s1->isSelfLoop() && s2->isSelfLoop())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!s1->isSelfLoop() && !s2->isSelfLoop()) {
|
|
Toshihiro Shimizu |
890ddd |
if (ret1 = isCloseEnoughP2P(facMin, facMax, s1, 0.0, s2, 1.0))
|
|
Toshihiro Shimizu |
890ddd |
segments.push_back(std::pair<double, double="">(0.0, 1.0));</double,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (s1 != s2) {
|
|
Toshihiro Shimizu |
890ddd |
if (ret2 = isCloseEnoughP2P(facMin, facMax, s1, 0.0, s2, 0.0))
|
|
Toshihiro Shimizu |
890ddd |
segments.push_back(std::pair<double, double="">(0.0, 0.0));</double,>
|
|
Toshihiro Shimizu |
890ddd |
if (ret3 = isCloseEnoughP2P(facMin, facMax, s1, 1.0, s2, 0.0))
|
|
Toshihiro Shimizu |
890ddd |
segments.push_back(std::pair<double, double="">(1.0, 0.0));</double,>
|
|
Toshihiro Shimizu |
890ddd |
if (ret4 = isCloseEnoughP2P(facMin, facMax, s1, 1.0, s2, 1.0))
|
|
Toshihiro Shimizu |
890ddd |
segments.push_back(std::pair<double, double="">(1.0, 1.0));</double,>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double w;
|
|
Toshihiro Shimizu |
890ddd |
if (!ret1 && !ret2 && isCloseEnoughP2L(facMin, facMax, s1, 0.0, s2, w))
|
|
Toshihiro Shimizu |
890ddd |
segments.push_back(std::pair<double, double="">(0.0, w));</double,>
|
|
Toshihiro Shimizu |
890ddd |
if (!ret1 && !ret4 && isCloseEnoughP2L(facMin, facMax, s2, 1.0, s1, w))
|
|
Toshihiro Shimizu |
890ddd |
segments.push_back(std::pair<double, double="">(w, 1.0));</double,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (s1 != s2) {
|
|
Toshihiro Shimizu |
890ddd |
if (!ret2 && !ret3 && isCloseEnoughP2L(facMin, facMax, s2, 0.0, s1, w))
|
|
Toshihiro Shimizu |
890ddd |
segments.push_back(std::pair<double, double="">(w, 0.0));</double,>
|
|
Toshihiro Shimizu |
890ddd |
if (!ret3 && !ret4 && isCloseEnoughP2L(facMin, facMax, s1, 1.0, s2, w))
|
|
Toshihiro Shimizu |
890ddd |
segments.push_back(std::pair<double, double="">(1.0, w));</double,>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} //namaspace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void getClosingPoints(const TRectD &rect, double fac, const TVectorImageP &vi,
|
|
Toshihiro Shimizu |
890ddd |
vector<pair<int, double="">> &startPoints, vector<pair<int, double="">> &endPoints)</pair<int,></pair<int,>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
UINT strokeCount = vi->getStrokeCount();
|
|
Toshihiro Shimizu |
890ddd |
TL2LAutocloser l2lautocloser;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i = 0; i < strokeCount; i++) {
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s1 = vi->getStroke(i);
|
|
Toshihiro Shimizu |
890ddd |
if (!rect.overlaps(s1->getBBox()))
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
if (s1->getChunkCount() == 1)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (UINT j = i; j < strokeCount; j++) {
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s2 = vi->getStroke(j);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!rect.overlaps(s1->getBBox()))
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
if (s2->getChunkCount() == 1)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef NEW_REGION_FILL
|
|
Toshihiro Shimizu |
890ddd |
double autoTol = 0;
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
double autoTol = vi->getAutocloseTolerance();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double enlarge1 = (autoTol + 0.7) * (s1->getMaxThickness() > 0 ? s1->getMaxThickness() : 2.5) + fac;
|
|
Toshihiro Shimizu |
890ddd |
double enlarge2 = (autoTol + 0.7) * (s2->getMaxThickness() > 0 ? s2->getMaxThickness() : 2.5) + fac;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (i != j && !s1->getBBox().enlarge(enlarge1).overlaps(s2->getBBox().enlarge(enlarge2)))
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
vector<std::pair<double, double="">> segments;</std::pair<double,>
|
|
Toshihiro Shimizu |
890ddd |
getClosingSegments(l2lautocloser, autoTol, autoTol + fac, s1, s2, 0, segments);
|
|
Toshihiro Shimizu |
890ddd |
for (UINT k = 0; k < segments.size(); k++) {
|
|
Toshihiro Shimizu |
890ddd |
TPointD p1 = s1->getPoint(segments[k].first);
|
|
Toshihiro Shimizu |
890ddd |
TPointD p2 = s2->getPoint(segments[k].second);
|
|
Toshihiro Shimizu |
890ddd |
if (rect.contains(p1) && rect.contains(p2)) {
|
|
Toshihiro Shimizu |
890ddd |
if (segmentAlreadyPresent(vi, p1, p2))
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
startPoints.push_back(pair<int, double="">(i, segments[k].first));</int,>
|
|
Toshihiro Shimizu |
890ddd |
endPoints.push_back(pair<int, double="">(j, segments[k].second));</int,>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void autoclose(double factor, vector<vistroke *=""> &s, int ii, int jj, IntersectionData &IntData,</vistroke>
|
|
Toshihiro Shimizu |
890ddd |
int strokeSize, TL2LAutocloser &l2lautocloser, vector<doublepair> *intersections, bool isVectorized)</doublepair>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
vector<std::pair<double, double="">> segments;</std::pair<double,>
|
|
Toshihiro Shimizu |
890ddd |
getClosingSegments(l2lautocloser, 0, factor, s[ii]->m_s, s[jj]->m_s, intersections, segments);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i = 0; i < segments.size(); i++)
|
|
Toshihiro Shimizu |
890ddd |
addAutocloseIntersection(IntData, s, ii, jj, segments[i].first, segments[i].second, strokeSize, isVectorized);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
#ifdef LEVO
|
|
Toshihiro Shimizu |
890ddd |
void autoclose(double factor, vector<vistroke *=""> &s, int ii, int jj, IntersectionData &IntData,</vistroke>
|
|
Toshihiro Shimizu |
890ddd |
int strokeSize)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
bool ret1 = false, ret2 = false, ret3 = false, ret4 = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (s[ii]->m_s->isSelfLoop() && s[jj]->m_s->isSelfLoop())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!s[ii]->m_s->isSelfLoop() && !s[jj]->m_s->isSelfLoop()) {
|
|
Toshihiro Shimizu |
890ddd |
ret1 = makePoint2PointConnections(factor, s, ii, true, jj, false, IntData, strokeSize);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (ii != jj) {
|
|
Toshihiro Shimizu |
890ddd |
ret2 = makePoint2PointConnections(factor, s, ii, true, jj, true, IntData, strokeSize);
|
|
Toshihiro Shimizu |
890ddd |
ret3 = makePoint2PointConnections(factor, s, ii, false, jj, true, IntData, strokeSize);
|
|
Toshihiro Shimizu |
890ddd |
ret4 = makePoint2PointConnections(factor, s, ii, false, jj, false, IntData, strokeSize);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!ret1 && !ret2)
|
|
Toshihiro Shimizu |
890ddd |
makePoint2LineConnection(factor, s, ii, jj, true, IntData, strokeSize);
|
|
Toshihiro Shimizu |
890ddd |
if (!ret1 && !ret4)
|
|
Toshihiro Shimizu |
890ddd |
makePoint2LineConnection(factor, s, jj, ii, false, IntData, strokeSize);
|
|
Toshihiro Shimizu |
890ddd |
if (ii != jj) {
|
|
Toshihiro Shimizu |
890ddd |
if (!ret2 && !ret3)
|
|
Toshihiro Shimizu |
890ddd |
makePoint2LineConnection(factor, s, jj, ii, true, IntData, strokeSize);
|
|
Toshihiro Shimizu |
890ddd |
if (!ret3 && !ret4)
|
|
Toshihiro Shimizu |
890ddd |
makePoint2LineConnection(factor, s, ii, jj, false, IntData, strokeSize);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD inline getTangent(const IntersectedStroke &item)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return (item.m_gettingOut ? 1 : -1) * item.m_edge.m_s->getSpeed(item.m_edge.m_w0, item.m_gettingOut);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void addBranch(IntersectionData &intData, VIList<intersectedstroke> &strokeList,</intersectedstroke>
|
|
Toshihiro Shimizu |
890ddd |
const vector<vistroke *=""> &s, int ii, double w, int strokeSize, bool gettingOut)</vistroke>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p1, *p2;
|
|
Toshihiro Shimizu |
890ddd |
TPointD tanRef, lastTan;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *item = new IntersectedStroke();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (ii < 0) {
|
|
Toshihiro Shimizu |
890ddd |
item->m_edge.m_s = intData.m_autocloseMap[ii]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
item->m_edge.m_index = ii;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
item->m_edge.m_s = s[ii]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
if (ii < strokeSize)
|
|
Toshihiro Shimizu |
890ddd |
item->m_edge.m_index = ii;
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
item->m_edge.m_index = -(ii + intData.maxAutocloseId * 100000);
|
|
Toshihiro Shimizu |
890ddd |
intData.m_autocloseMap[item->m_edge.m_index] = s[ii];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
item->m_edge.m_w0 = w;
|
|
Toshihiro Shimizu |
890ddd |
item->m_gettingOut = gettingOut;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
if (strokeList.size()==2) //potrebbero essere orientati male; due branch possono stare come vogliono, ma col terzo no.
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TPointD tan2 = getTangent(strokeList.back());
|
|
Toshihiro Shimizu |
890ddd |
TPointD aux= getTangent(*(strokeList.begin()));
|
|
Toshihiro Shimizu |
890ddd |
double crossVal = cross(aux, tan2);
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(aux, tan2, 1e-3))
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (crossVal>0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::reverse(strokeList.begin(), strokeList.end());
|
|
Toshihiro Shimizu |
890ddd |
//tan2 = getTangent(strokeList.back());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(lastCross, 0.0) && tan1.x*tan2.x>=0 && tan1.y*tan2.y>=0) //significa angolo tra tangenti nullo
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
crossVal = nearCrossVal(item.m_edge.m_s, item.m_edge.m_w0, strokeList.back().m_edge.m_s, strokeList.back().m_edge.m_w0);
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(crossVal, 0.0))
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
if (!strokeList.back().m_gettingOut)
|
|
Toshihiro Shimizu |
890ddd |
crossVal = -crossVal;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
tanRef = getTangent(*item);
|
|
Toshihiro Shimizu |
890ddd |
lastTan = getTangent(*strokeList.last());
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
for (it=strokeList.begin(); it!=strokeList.end(); ++it)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TPointD curTan = getTangent(*it);
|
|
Toshihiro Shimizu |
890ddd |
double angle0 = getAngle(lastTan, curTan);
|
|
Toshihiro Shimizu |
890ddd |
double angle1 = getAngle(lastTan, tanRef);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(angle0, angle1, 1e-8))
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double angle = getNearAngle( it->m_edge.m_s, it->m_edge.m_w0, it->m_gettingOut,
|
|
Toshihiro Shimizu |
890ddd |
item.m_edge.m_s, item.m_edge.m_w0, item.m_gettingOut);
|
|
Toshihiro Shimizu |
890ddd |
angle1 += angle; if (angle1>360) angle1-=360;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (angle1
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
strokeList.insert(it, item);
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
lastTan=curTan;
|
|
Toshihiro Shimizu |
890ddd |
}*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
p2 = strokeList.last();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p1 = strokeList.first(); p1; p1 = p1->next()) {
|
|
Toshihiro Shimizu |
890ddd |
TPointD curTan = getTangent(*p1);
|
|
Toshihiro Shimizu |
890ddd |
double angle0 = getAngle(lastTan, curTan);
|
|
Toshihiro Shimizu |
890ddd |
double angle1 = getAngle(lastTan, tanRef);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(angle1, 0, 1e-8)) {
|
|
Toshihiro Shimizu |
890ddd |
double angle = getNearAngle(p2->m_edge.m_s, p2->m_edge.m_w0, p2->m_gettingOut,
|
|
Toshihiro Shimizu |
890ddd |
item->m_edge.m_s, item->m_edge.m_w0, item->m_gettingOut);
|
|
Toshihiro Shimizu |
890ddd |
angle1 += angle;
|
|
Toshihiro Shimizu |
890ddd |
if (angle1 > 360)
|
|
Toshihiro Shimizu |
890ddd |
angle1 -= 360;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(angle0, angle1, 1e-8)) {
|
|
Toshihiro Shimizu |
890ddd |
double angle = getNearAngle(p1->m_edge.m_s, p1->m_edge.m_w0, p1->m_gettingOut,
|
|
Toshihiro Shimizu |
890ddd |
item->m_edge.m_s, item->m_edge.m_w0, item->m_gettingOut);
|
|
Toshihiro Shimizu |
890ddd |
angle1 += angle;
|
|
Toshihiro Shimizu |
890ddd |
if (angle1 > 360)
|
|
Toshihiro Shimizu |
890ddd |
angle1 -= 360;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (angle1 < angle0) {
|
|
Toshihiro Shimizu |
890ddd |
strokeList.insert(p1, item);
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
lastTan = curTan;
|
|
Toshihiro Shimizu |
890ddd |
p2 = p1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//assert(!"add branch: can't find where to insert!");
|
|
Toshihiro Shimizu |
890ddd |
strokeList.pushBack(item);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void addBranches(IntersectionData &intData, Intersection &intersection, const vector<vistroke *=""> &s, int ii, int jj,</vistroke>
|
|
Toshihiro Shimizu |
890ddd |
DoublePair intersectionPair, int strokeSize)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
bool foundS1 = false, foundS2 = false;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(!intersection.m_strokeList.empty());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p = intersection.m_strokeList.first(); p; p = p->next()) {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if ((ii >= 0 && p->m_edge.m_s == s[ii]->m_s && p->m_edge.m_w0 == intersectionPair.first) ||
|
|
Toshihiro Shimizu |
890ddd |
(ii < 0 && p->m_edge.m_index == ii && p->m_edge.m_w0 == intersectionPair.first))
|
|
Toshihiro Shimizu |
890ddd |
foundS1 = true;
|
|
Toshihiro Shimizu |
890ddd |
if ((jj >= 0 && p->m_edge.m_s == s[jj]->m_s && p->m_edge.m_w0 == intersectionPair.second) ||
|
|
Toshihiro Shimizu |
890ddd |
(jj < 0 && p->m_edge.m_index == jj && p->m_edge.m_w0 == intersectionPair.second))
|
|
Toshihiro Shimizu |
890ddd |
foundS2 = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (foundS1 && foundS2) {
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
//errore!(vedi commento sotto) possono essere un sacco di intersezioni coincidenti se passano per l'estremo di una quad
|
|
Toshihiro Shimizu |
890ddd |
//significa che ci sono due intersezioni coincidenti. cioe' due stroke tangenti. quindi devo invertire l'ordine di due branch enlla rosa dei branch.
|
|
Toshihiro Shimizu |
890ddd |
list<intersectedstroke>::iterator it1, it2;</intersectedstroke>
|
|
Toshihiro Shimizu |
890ddd |
it1=intersection.m_strokeList.begin();
|
|
Toshihiro Shimizu |
890ddd |
it2 = it1; it2++;
|
|
Toshihiro Shimizu |
890ddd |
for (; it2!=intersection.m_strokeList.end(); ++it1, ++it2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if ((*it1).m_gettingOut!=(*it2).m_gettingOut &&((*it1).m_edge.m_index==jj && (*it2).m_edge.m_index==ii) ||
|
|
Toshihiro Shimizu |
890ddd |
((*it1).m_edge.m_index==ii && (*it2).m_edge.m_index==jj))
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke& el1 = (*it1);
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke& el2 = (*it2);
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke app;
|
|
Toshihiro Shimizu |
890ddd |
app = el1;
|
|
Toshihiro Shimizu |
890ddd |
el1=el2;
|
|
Toshihiro Shimizu |
890ddd |
el2=app;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!foundS1) {
|
|
Toshihiro Shimizu |
890ddd |
if (intersectionPair.first != 1)
|
|
Toshihiro Shimizu |
890ddd |
addBranch(intData, intersection.m_strokeList, s, ii, intersectionPair.first, strokeSize, true);
|
|
Toshihiro Shimizu |
890ddd |
if (intersectionPair.first != 0)
|
|
Toshihiro Shimizu |
890ddd |
addBranch(intData, intersection.m_strokeList, s, ii, intersectionPair.first, strokeSize, false);
|
|
Toshihiro Shimizu |
890ddd |
//assert(intersection.m_strokeList.size()-size>0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (!foundS2) {
|
|
Toshihiro Shimizu |
890ddd |
if (intersectionPair.second != 1)
|
|
Toshihiro Shimizu |
890ddd |
addBranch(intData, intersection.m_strokeList, s, jj, intersectionPair.second, strokeSize, true);
|
|
Toshihiro Shimizu |
890ddd |
if (intersectionPair.second != 0)
|
|
Toshihiro Shimizu |
890ddd |
addBranch(intData, intersection.m_strokeList, s, jj, intersectionPair.second, strokeSize, false);
|
|
Toshihiro Shimizu |
890ddd |
//intersection.m_numInter+=intersection.m_strokeList.size()-size;
|
|
Toshihiro Shimizu |
890ddd |
//assert(intersection.m_strokeList.size()-size>0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void addIntersections(IntersectionData &intData,
|
|
Toshihiro Shimizu |
890ddd |
const vector<vistroke *=""> &s, int ii, int jj,</vistroke>
|
|
Toshihiro Shimizu |
890ddd |
vector<doublepair> &intersections, int strokeSize, bool isVectorized)</doublepair>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (int k = 0; k < (int)intersections.size(); k++) {
|
|
Toshihiro Shimizu |
890ddd |
if (ii >= strokeSize &&
|
|
Toshihiro Shimizu |
890ddd |
(areAlmostEqual(intersections[k].first, 0.0) || areAlmostEqual(intersections[k].first, 1.0)))
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
if (jj >= strokeSize &&
|
|
Toshihiro Shimizu |
890ddd |
(areAlmostEqual(intersections[k].second, 0.0) || areAlmostEqual(intersections[k].second, 1.0)))
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
addIntersection(intData, s, ii, jj, intersections[k], strokeSize, isVectorized);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline double truncate(double x)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
x += 1.0;
|
|
Toshihiro Shimizu |
890ddd |
TUINT32 *l = (TUINT32 *)&x;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#if TNZ_LITTLE_ENDIAN
|
|
Toshihiro Shimizu |
890ddd |
l[0] &= 0xFFE00000;
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
l[1] &= 0xFFE00000;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return x - 1.0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void addIntersection(IntersectionData &intData,
|
|
Toshihiro Shimizu |
890ddd |
const vector<vistroke *=""> &s, int ii, int jj,</vistroke>
|
|
Toshihiro Shimizu |
890ddd |
DoublePair intersection, int strokeSize, bool isVectorized)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p;
|
|
Toshihiro Shimizu |
890ddd |
TPointD point;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(ii < 0 || jj < 0 || s[ii]->m_groupId == s[jj]->m_groupId);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//UINT iw;
|
|
Toshihiro Shimizu |
890ddd |
//iw = ((UINT)(intersection.first*0x3fffffff));
|
|
Toshihiro Shimizu |
890ddd |
//intersection.first = truncate(intersection.first);
|
|
Toshihiro Shimizu |
890ddd |
//iw = (UINT)(intersection.second*0x3fffffff);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//intersection.second = truncate(intersection.second);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(intersection.first, 0.0, 1e-5))
|
|
Toshihiro Shimizu |
890ddd |
intersection.first = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
else if (areAlmostEqual(intersection.first, 1.0, 1e-5))
|
|
Toshihiro Shimizu |
890ddd |
intersection.first = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(intersection.second, 0.0, 1e-5))
|
|
Toshihiro Shimizu |
890ddd |
intersection.second = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
else if (areAlmostEqual(intersection.second, 1.0, 1e-5))
|
|
Toshihiro Shimizu |
890ddd |
intersection.second = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
point = s[ii]->m_s->getPoint(intersection.first);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p = intData.m_intList.first(); p; p = p->next())
|
|
Toshihiro Shimizu |
890ddd |
if (p->m_intersection == point ||
|
|
Toshihiro Shimizu |
890ddd |
(isVectorized && areAlmostEqual(p->m_intersection, point, 1e-2))) //devono essere rigorosamente uguali, altrimenti
|
|
Toshihiro Shimizu |
890ddd |
// il calcolo dell'ordine dei rami con le tangenti sballa
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
addBranches(intData, *p, s, ii, jj, intersection, strokeSize);
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
intData.m_intList.pushBack(new Intersection);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!makeIntersection(intData, s, ii, jj, intersection, strokeSize, *intData.m_intList.last()))
|
|
Toshihiro Shimizu |
890ddd |
intData.m_intList.erase(intData.m_intList.last());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::Imp::findIntersections()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
vector<vistroke *=""> &strokeArray = m_strokes;</vistroke>
|
|
Toshihiro Shimizu |
890ddd |
IntersectionData &intData = *m_intersectionData;
|
|
Toshihiro Shimizu |
890ddd |
int strokeSize = (int)strokeArray.size();
|
|
Toshihiro Shimizu |
890ddd |
int i, j;
|
|
Toshihiro Shimizu |
890ddd |
bool isVectorized = (m_autocloseTolerance < 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(intData.m_intersectedStrokeArray.empty());
|
|
Toshihiro Shimizu |
890ddd |
#define AUTOCLOSE_ATTIVO
|
|
Toshihiro Shimizu |
890ddd |
#ifdef AUTOCLOSE_ATTIVO
|
|
Toshihiro Shimizu |
890ddd |
intData.maxAutocloseId++;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
map<int, *="" vistroke="">::iterator it, it_b = intData.m_autocloseMap.begin();</int,>
|
|
Toshihiro Shimizu |
890ddd |
map<int, *="" vistroke="">::iterator it_e = intData.m_autocloseMap.end();</int,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//prima cerco le intersezioni tra nuove strokes e vecchi autoclose
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < strokeSize; i++) {
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s1 = strokeArray[i]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
if (!strokeArray[i]->m_isNewForFill || strokeArray[i]->m_isPoint)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRectD bBox = s1->getBBox();
|
|
Toshihiro Shimizu |
890ddd |
double thick2 = s1->getThickPoint(0).thick * 2.1; //2.1 instead of 2.0, for usual problems of approx...
|
|
Toshihiro Shimizu |
890ddd |
if (bBox.getLx() <= thick2 && bBox.getLy() <= thick2) {
|
|
Toshihiro Shimizu |
890ddd |
strokeArray[i]->m_isPoint = true;
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
roundStroke(s1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (it = it_b; it != it_e; ++it) {
|
|
Toshihiro Shimizu |
890ddd |
if (!it->second || it->second->m_groupId != strokeArray[i]->m_groupId)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s2 = it->second->m_s;
|
|
Toshihiro Shimizu |
890ddd |
vector<doublepair> parIntersections;</doublepair>
|
|
Toshihiro Shimizu |
890ddd |
if (intersect(s1, s2, parIntersections, true))
|
|
Toshihiro Shimizu |
890ddd |
addIntersections(intData, strokeArray, i, it->first, parIntersections, strokeSize, isVectorized);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//poi, intersezioni tra stroke, in cui almeno uno dei due deve essere nuovo
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
map<pair<int, int="">, vector<doublepair>> intersectionMap;</doublepair></pair<int,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < strokeSize; i++) {
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s1 = strokeArray[i]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
if (strokeArray[i]->m_isPoint)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
for (j = i; j < strokeSize /*&& (strokeArray[i]->getBBox().x1>= strokeArray[j]->getBBox().x0)*/; j++) {
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s2 = strokeArray[j]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (strokeArray[j]->m_isPoint || !(strokeArray[i]->m_isNewForFill || strokeArray[j]->m_isNewForFill))
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
if (strokeArray[i]->m_groupId != strokeArray[j]->m_groupId)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
vector<doublepair> parIntersections;</doublepair>
|
|
Toshihiro Shimizu |
890ddd |
if (s1->getBBox().overlaps(s2->getBBox())) {
|
|
Toshihiro Shimizu |
890ddd |
UINT size = intData.m_intList.size();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (intersect(s1, s2, parIntersections, false)) {
|
|
Toshihiro Shimizu |
890ddd |
//if (i==0 && j==1) parIntersections.erase(parIntersections.begin());
|
|
Toshihiro Shimizu |
890ddd |
intersectionMap[pair<int, int="">(i, j)] = parIntersections;</int,>
|
|
Toshihiro Shimizu |
890ddd |
addIntersections(intData, strokeArray, i, j, parIntersections, strokeSize, isVectorized);
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
intersectionMap[pair<int, int="">(i, j)] = vector<doublepair>();</doublepair></int,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!strokeArray[i]->m_isNewForFill && size != intData.m_intList.size() && !strokeArray[i]->m_edgeList.empty()) //aggiunte nuove intersezioni
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
intData.m_intersectedStrokeArray.push_back(IntersectedStrokeEdges(i));
|
|
Toshihiro Shimizu |
890ddd |
list<tedge *=""> &_list = intData.m_intersectedStrokeArray.back().m_edgeList;</tedge>
|
|
Toshihiro Shimizu |
890ddd |
list<tedge *="">::const_iterator it;</tedge>
|
|
Toshihiro Shimizu |
890ddd |
for (it = strokeArray[i]->m_edgeList.begin(); it != strokeArray[i]->m_edgeList.end(); ++it)
|
|
Toshihiro Shimizu |
890ddd |
_list.push_back(new TEdge(**it, false));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef AUTOCLOSE_ATTIVO
|
|
Toshihiro Shimizu |
890ddd |
TL2LAutocloser l2lautocloser;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < strokeSize; i++) {
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s1 = strokeArray[i]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
if (strokeArray[i]->m_isPoint)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
for (j = i; j < strokeSize; j++) {
|
|
Toshihiro Shimizu |
890ddd |
if (strokeArray[i]->m_groupId != strokeArray[j]->m_groupId)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s2 = strokeArray[j]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
if (strokeArray[j]->m_isPoint)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
if (!(strokeArray[i]->m_isNewForFill || strokeArray[j]->m_isNewForFill))
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double enlarge1 = (m_autocloseTolerance + 0.7) * (s1->getMaxThickness() > 0 ? s1->getMaxThickness() : 2.5);
|
|
Toshihiro Shimizu |
890ddd |
double enlarge2 = (m_autocloseTolerance + 0.7) * (s2->getMaxThickness() > 0 ? s2->getMaxThickness() : 2.5);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (s1->getBBox().enlarge(enlarge1).overlaps(s2->getBBox().enlarge(enlarge2))) {
|
|
Toshihiro Shimizu |
890ddd |
map<pair<int, int="">, vector<doublepair>>::iterator it = intersectionMap.find(pair<int, int="">(i, j));</int,></doublepair></pair<int,>
|
|
Toshihiro Shimizu |
890ddd |
if (it == intersectionMap.end())
|
|
Toshihiro Shimizu |
890ddd |
autoclose(m_autocloseTolerance, strokeArray, i, j, intData, strokeSize, l2lautocloser, 0, isVectorized);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
autoclose(m_autocloseTolerance, strokeArray, i, j, intData, strokeSize, l2lautocloser, &(it->second), isVectorized);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
strokeArray[i]->m_isNewForFill = false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < strokeSize; i++) {
|
|
Toshihiro Shimizu |
890ddd |
list<tedge *="">::iterator it, it_b = strokeArray[i]->m_edgeList.begin(), it_e = strokeArray[i]->m_edgeList.end();</tedge>
|
|
Toshihiro Shimizu |
890ddd |
for (it = it_b; it != it_e; ++it)
|
|
Toshihiro Shimizu |
890ddd |
if ((*it)->m_toBeDeleted == 1)
|
|
Toshihiro Shimizu |
890ddd |
delete *it;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
strokeArray[i]->m_edgeList.clear();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//si devono cercare le intersezioni con i segmenti aggiunti per l'autoclose
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (i = strokeSize; i < (int)strokeArray.size(); ++i) {
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s1 = strokeArray[i]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (j = i + 1; j < (int)strokeArray.size(); ++j) //intersezione segmento-segmento
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (strokeArray[i]->m_groupId != strokeArray[j]->m_groupId)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s2 = strokeArray[j]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
vector<doublepair> parIntersections;</doublepair>
|
|
Toshihiro Shimizu |
890ddd |
if (intersect(s1, s2, parIntersections, true))
|
|
Toshihiro Shimizu |
890ddd |
addIntersections(intData, strokeArray, i, j, parIntersections, strokeSize, isVectorized);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
for (j = 0; j < strokeSize; ++j) //intersezione segmento-curva
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (strokeArray[j]->m_isPoint)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
if (strokeArray[i]->m_groupId != strokeArray[j]->m_groupId)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s2 = strokeArray[j]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
vector<doublepair> parIntersections;</doublepair>
|
|
Toshihiro Shimizu |
890ddd |
if (intersect(s1, s2, parIntersections, true))
|
|
Toshihiro Shimizu |
890ddd |
addIntersections(intData, strokeArray, i, j, parIntersections, strokeSize, isVectorized);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//la struttura delle intersezioni viene poi visitata per trovare
|
|
Toshihiro Shimizu |
890ddd |
// i link tra un'intersezione e la successiva
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::Imp::deleteRegionsData()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
clearPointerContainer(m_strokes);
|
|
Toshihiro Shimizu |
890ddd |
clearPointerContainer(m_regions);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1;
|
|
Toshihiro Shimizu |
890ddd |
for (p1 = m_intersectionData->m_intList.first(); p1; p1 = p1->next())
|
|
Toshihiro Shimizu |
890ddd |
p1->m_strokeList.clear();
|
|
Toshihiro Shimizu |
890ddd |
m_intersectionData->m_intList.clear();
|
|
Toshihiro Shimizu |
890ddd |
delete m_intersectionData;
|
|
Toshihiro Shimizu |
890ddd |
m_intersectionData = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::Imp::initRegionsData()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_intersectionData = new IntersectionData();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int TVectorImage::Imp::computeIntersections()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1;
|
|
Toshihiro Shimizu |
890ddd |
IntersectionData &intData = *m_intersectionData;
|
|
Toshihiro Shimizu |
890ddd |
int strokeSize = (int)m_strokes.size();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
findIntersections();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
findNearestIntersection(intData.m_intList);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//for (it1=intData.m_intList.begin(); it1!=intData.m_intList.end();) //la faccio qui, e non nella eraseIntersection. vedi commento li'.
|
|
Toshihiro Shimizu |
890ddd |
eraseDeadIntersections();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p1 = intData.m_intList.first(); p1; p1 = p1->next())
|
|
Toshihiro Shimizu |
890ddd |
markDeadIntersections(intData.m_intList, p1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//checkInterList(intData.m_intList);
|
|
Toshihiro Shimizu |
890ddd |
return strokeSize;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
void endPointIntersect(const TStroke* s0, const TStroke* s1, vector<doublepair>& parIntersections)</doublepair>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TPointD p00 = s0->getPoint(0);
|
|
Toshihiro Shimizu |
890ddd |
TPointD p11 = s1->getPoint(1);
|
|
Toshihiro Shimizu |
890ddd |
if (tdistance2(p00, p11)< 2*0.06*0.06)
|
|
Toshihiro Shimizu |
890ddd |
parIntersections.push_back(DoublePair(0, 1));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (s0==s1)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD p01 = s0->getPoint(1);
|
|
Toshihiro Shimizu |
890ddd |
TPointD p10 = s1->getPoint(0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (tdistance2(p00, p10)< 2*0.06*0.06)
|
|
Toshihiro Shimizu |
890ddd |
parIntersections.push_back(DoublePair(0, 0));
|
|
Toshihiro Shimizu |
890ddd |
if (tdistance2(p01, p10)< 2*0.06*0.06)
|
|
Toshihiro Shimizu |
890ddd |
parIntersections.push_back(DoublePair(1, 0));
|
|
Toshihiro Shimizu |
890ddd |
if (tdistance2(p01, p11)< 2*0.06*0.06)
|
|
Toshihiro Shimizu |
890ddd |
parIntersections.push_back(DoublePair(1, 1));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Trova una possibile regione data una lista di punti di intersezione
|
|
Toshihiro Shimizu |
890ddd |
TRegion *findRegion(
|
|
Toshihiro Shimizu |
890ddd |
VIList<intersection> &intList,</intersection>
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1,
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2,
|
|
Toshihiro Shimizu |
890ddd |
bool minimizeEdges)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRegion *r = new TRegion();
|
|
Toshihiro Shimizu |
890ddd |
int currStyle = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *pStart = p2;
|
|
Toshihiro Shimizu |
890ddd |
Intersection *nextp1;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *nextp2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Cicla finche' t2 non punta ad uno stroke gia' visitato
|
|
Toshihiro Shimizu |
890ddd |
while (!p2->m_visited) {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
p2->m_visited = true;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Ciclo finche' lo stroke puntato da it2 non ha un successivo punto di intersezione
|
|
Toshihiro Shimizu |
890ddd |
do {
|
|
Toshihiro Shimizu |
890ddd |
p2 = p2->next();
|
|
Toshihiro Shimizu |
890ddd |
if (!p2) // uso la lista come se fosse circolare
|
|
Toshihiro Shimizu |
890ddd |
p2 = p1->m_strokeList.first();
|
|
Toshihiro Shimizu |
890ddd |
if (!p2) {
|
|
Toshihiro Shimizu |
890ddd |
delete r;
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} while (!p2->m_nextIntersection);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
nextp1 = p2->m_nextIntersection;
|
|
Toshihiro Shimizu |
890ddd |
nextp2 = p2->m_nextStroke;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Viene controllato e sistemato lo stile degli stroke
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_styleId != 0) {
|
|
Toshihiro Shimizu |
890ddd |
if (currStyle == 0)
|
|
Toshihiro Shimizu |
890ddd |
currStyle = p2->m_edge.m_styleId;
|
|
Toshihiro Shimizu |
890ddd |
else if (p2->m_edge.m_styleId != currStyle) {
|
|
Toshihiro Shimizu |
890ddd |
currStyle = p2->m_edge.m_styleId;
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i = 0; i < r->getEdgeCount(); i++)
|
|
Toshihiro Shimizu |
890ddd |
r->getEdge(i)->m_styleId = currStyle;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_styleId = currStyle;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Aggiunge lo stroke puntato da p2 alla regione
|
|
Toshihiro Shimizu |
890ddd |
r->addEdge(&p2->m_edge, minimizeEdges);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (nextp2 == pStart)
|
|
Toshihiro Shimizu |
890ddd |
return r;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
p1 = nextp1;
|
|
Toshihiro Shimizu |
890ddd |
p2 = nextp2;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
delete r;
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
bool areEqualRegions(const TRegion& r1, const TRegion& r2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (r1.getBBox()!=r2.getBBox())
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
if (r1.getEdgeCount()!=r2.getEdgeCount())
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i=0; i
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TEdge *e1 = r1.getEdge(i);
|
|
Toshihiro Shimizu |
890ddd |
for (j=0; j
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TEdge *e2 = r2.getEdge(j);
|
|
Toshihiro Shimizu |
890ddd |
if (e1->m_s==e2->m_s &&
|
|
Toshihiro Shimizu |
890ddd |
tmin(e1->m_w0, e1->m_w1)==tmin(e2->m_w0, e2->m_w1) &&
|
|
Toshihiro Shimizu |
890ddd |
tmax(e1->m_w0, e1->m_w1)==tmax(e2->m_w0, e2->m_w1))
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (e1->m_styleId && !e2->m_styleId)
|
|
Toshihiro Shimizu |
890ddd |
e2->m_styleId=e1->m_styleId;
|
|
Toshihiro Shimizu |
890ddd |
else if (e2->m_styleId && !e1->m_styleId)
|
|
Toshihiro Shimizu |
890ddd |
e1->m_styleId=e2->m_styleId;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (j==r2.getEdgeCount()) //e1 non e' uguale a nessun edge di r2
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
bool isMetaRegion(const TRegion& r1, const TRegion& r2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (areEqualRegions(r1, r2))
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i=0; i
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (isMetaRegion(*r1.getRegion(i), r2))
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isMetaRegion(const vector<tregion*>& m_regions, const TRegion& r)</tregion*>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i=0; i
|
|
Toshihiro Shimizu |
890ddd |
if (isMetaRegion(*(m_regions[i]), r))
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TRegionClockWiseFormula : public TRegionFeatureFormula
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Toshihiro Shimizu |
890ddd |
double m_quasiArea;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TRegionClockWiseFormula() : m_quasiArea(0) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void inline update(const TPointD &p1, const TPointD &p2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_quasiArea += (p2.y + p1.y) * (p1.x - p2.x);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool inline isClockwise() { return m_quasiArea > 0.5; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void computeRegionFeature(const TRegion &r, TRegionFeatureFormula &formula)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TPointD p, pOld /*, pAux*/;
|
|
Toshihiro Shimizu |
890ddd |
int pointAdded = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int size = r.getEdgeCount();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (size == 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//if (size<2)
|
|
Toshihiro Shimizu |
890ddd |
// return !isMetaRegion(regions, r);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int firstControlPoint;
|
|
Toshihiro Shimizu |
890ddd |
int lastControlPoint;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TEdge *e = r.getEdge(size - 1);
|
|
Toshihiro Shimizu |
890ddd |
pOld = e->m_s->getPoint(e->m_w1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < size; i++) {
|
|
Toshihiro Shimizu |
890ddd |
TEdge *e = r.getEdge(i);
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s = e->m_s;
|
|
Toshihiro Shimizu |
890ddd |
firstControlPoint = s->getControlPointIndexAfterParameter(e->m_w0);
|
|
Toshihiro Shimizu |
890ddd |
lastControlPoint = s->getControlPointIndexAfterParameter(e->m_w1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
p = s->getPoint(e->m_w0);
|
|
Toshihiro Shimizu |
890ddd |
formula.update(pOld, p);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
pOld = p;
|
|
Toshihiro Shimizu |
890ddd |
pointAdded++;
|
|
Toshihiro Shimizu |
890ddd |
if (firstControlPoint <= lastControlPoint) {
|
|
Toshihiro Shimizu |
890ddd |
if (firstControlPoint & 0x1)
|
|
Toshihiro Shimizu |
890ddd |
firstControlPoint++;
|
|
Toshihiro Shimizu |
890ddd |
if (lastControlPoint - firstControlPoint <= 2) ///per evitare di avere troppi pochi punti....
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
p = s->getPoint(0.333333 * e->m_w0 + 0.666666 * e->m_w1);
|
|
Toshihiro Shimizu |
890ddd |
formula.update(pOld, p);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
pOld = p;
|
|
Toshihiro Shimizu |
890ddd |
pointAdded++;
|
|
Toshihiro Shimizu |
890ddd |
p = s->getPoint(0.666666 * e->m_w0 + 0.333333 * e->m_w1);
|
|
Toshihiro Shimizu |
890ddd |
formula.update(pOld, p);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
pOld = p;
|
|
Toshihiro Shimizu |
890ddd |
pointAdded++;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
for (int j = firstControlPoint; j < lastControlPoint; j += 2) {
|
|
Toshihiro Shimizu |
890ddd |
p = s->getControlPoint(j);
|
|
Toshihiro Shimizu |
890ddd |
formula.update(pOld, p);
|
|
Toshihiro Shimizu |
890ddd |
pOld = p;
|
|
Toshihiro Shimizu |
890ddd |
pointAdded++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
firstControlPoint--; //this case, getControlPointIndexBEFOREParameter
|
|
Toshihiro Shimizu |
890ddd |
lastControlPoint--;
|
|
Toshihiro Shimizu |
890ddd |
if (firstControlPoint & 0x1)
|
|
Toshihiro Shimizu |
890ddd |
firstControlPoint--;
|
|
Toshihiro Shimizu |
890ddd |
if (firstControlPoint - lastControlPoint <= 2) ///per evitare di avere troppi pochi punti....
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
p = s->getPoint(0.333333 * e->m_w0 + 0.666666 * e->m_w1);
|
|
Toshihiro Shimizu |
890ddd |
formula.update(pOld, p);
|
|
Toshihiro Shimizu |
890ddd |
pOld = p;
|
|
Toshihiro Shimizu |
890ddd |
pointAdded++;
|
|
Toshihiro Shimizu |
890ddd |
p = s->getPoint(0.666666 * e->m_w0 + 0.333333 * e->m_w1);
|
|
Toshihiro Shimizu |
890ddd |
formula.update(pOld, p);
|
|
Toshihiro Shimizu |
890ddd |
pOld = p;
|
|
Toshihiro Shimizu |
890ddd |
pointAdded++;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
for (int j = firstControlPoint; j > lastControlPoint; j -= 2) {
|
|
Toshihiro Shimizu |
890ddd |
p = s->getControlPoint(j);
|
|
Toshihiro Shimizu |
890ddd |
formula.update(pOld, p);
|
|
Toshihiro Shimizu |
890ddd |
pOld = p;
|
|
Toshihiro Shimizu |
890ddd |
pointAdded++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
p = s->getPoint(e->m_w1);
|
|
Toshihiro Shimizu |
890ddd |
formula.update(pOld, p);
|
|
Toshihiro Shimizu |
890ddd |
pOld = p;
|
|
Toshihiro Shimizu |
890ddd |
pointAdded++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
assert(pointAdded >= 4);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isValidArea(const TRegion &r)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRegionClockWiseFormula formula;
|
|
Toshihiro Shimizu |
890ddd |
computeRegionFeature(r, formula);
|
|
Toshihiro Shimizu |
890ddd |
return formula.isClockwise();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef LEVO
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isValidArea(const vector<tregion *=""> ®ions, const TRegion &r)</tregion>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double area = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
TPointD p, pOld /*, pAux*/;
|
|
Toshihiro Shimizu |
890ddd |
int pointAdded = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int size = r.getEdgeCount();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (size == 0)
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//if (size<2)
|
|
Toshihiro Shimizu |
890ddd |
// return !isMetaRegion(regions, r);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int firstControlPoint;
|
|
Toshihiro Shimizu |
890ddd |
int lastControlPoint;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TEdge *e = r.getEdge(size - 1);
|
|
Toshihiro Shimizu |
890ddd |
pOld = e->m_s->getPoint(e->m_w1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < size; i++) {
|
|
Toshihiro Shimizu |
890ddd |
TEdge *e = r.getEdge(i);
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s = e->m_s;
|
|
Toshihiro Shimizu |
890ddd |
firstControlPoint = s->getControlPointIndexAfterParameter(e->m_w0);
|
|
Toshihiro Shimizu |
890ddd |
lastControlPoint = s->getControlPointIndexAfterParameter(e->m_w1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
p = s->getPoint(e->m_w0);
|
|
Toshihiro Shimizu |
890ddd |
area += (p.y + pOld.y) * (pOld.x - p.x);
|
|
Toshihiro Shimizu |
890ddd |
pOld = p;
|
|
Toshihiro Shimizu |
890ddd |
pointAdded++;
|
|
Toshihiro Shimizu |
890ddd |
if (firstControlPoint <= lastControlPoint) {
|
|
Toshihiro Shimizu |
890ddd |
if (firstControlPoint & 0x1)
|
|
Toshihiro Shimizu |
890ddd |
firstControlPoint++;
|
|
Toshihiro Shimizu |
890ddd |
if (lastControlPoint - firstControlPoint <= 2) ///per evitare di avere troppi pochi punti....
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
p = s->getPoint(0.333333 * e->m_w0 + 0.666666 * e->m_w1);
|
|
Toshihiro Shimizu |
890ddd |
area += (p.y + pOld.y) * (pOld.x - p.x);
|
|
Toshihiro Shimizu |
890ddd |
pOld = p;
|
|
Toshihiro Shimizu |
890ddd |
pointAdded++;
|
|
Toshihiro Shimizu |
890ddd |
p = s->getPoint(0.666666 * e->m_w0 + 0.333333 * e->m_w1);
|
|
Toshihiro Shimizu |
890ddd |
area += (p.y + pOld.y) * (pOld.x - p.x);
|
|
Toshihiro Shimizu |
890ddd |
pOld = p;
|
|
Toshihiro Shimizu |
890ddd |
pointAdded++;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
for (int j = firstControlPoint; j < lastControlPoint; j += 2) {
|
|
Toshihiro Shimizu |
890ddd |
p = s->getControlPoint(j);
|
|
Toshihiro Shimizu |
890ddd |
area += (p.y + pOld.y) * (pOld.x - p.x);
|
|
Toshihiro Shimizu |
890ddd |
pOld = p;
|
|
Toshihiro Shimizu |
890ddd |
pointAdded++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
firstControlPoint--; //this case, getControlPointIndexBEFOREParameter
|
|
Toshihiro Shimizu |
890ddd |
lastControlPoint--;
|
|
Toshihiro Shimizu |
890ddd |
if (firstControlPoint & 0x1)
|
|
Toshihiro Shimizu |
890ddd |
firstControlPoint--;
|
|
Toshihiro Shimizu |
890ddd |
if (firstControlPoint - lastControlPoint <= 2) ///per evitare di avere troppi pochi punti....
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
p = s->getPoint(0.333333 * e->m_w0 + 0.666666 * e->m_w1);
|
|
Toshihiro Shimizu |
890ddd |
area += (p.y + pOld.y) * (pOld.x - p.x);
|
|
Toshihiro Shimizu |
890ddd |
pOld = p;
|
|
Toshihiro Shimizu |
890ddd |
pointAdded++;
|
|
Toshihiro Shimizu |
890ddd |
p = s->getPoint(0.666666 * e->m_w0 + 0.333333 * e->m_w1);
|
|
Toshihiro Shimizu |
890ddd |
area += (p.y + pOld.y) * (pOld.x - p.x);
|
|
Toshihiro Shimizu |
890ddd |
pOld = p;
|
|
Toshihiro Shimizu |
890ddd |
pointAdded++;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
for (int j = firstControlPoint; j > lastControlPoint; j -= 2) {
|
|
Toshihiro Shimizu |
890ddd |
p = s->getControlPoint(j);
|
|
Toshihiro Shimizu |
890ddd |
area += (p.y + pOld.y) * (pOld.x - p.x);
|
|
Toshihiro Shimizu |
890ddd |
pOld = p;
|
|
Toshihiro Shimizu |
890ddd |
pointAdded++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
p = s->getPoint(e->m_w1);
|
|
Toshihiro Shimizu |
890ddd |
area += (p.y + pOld.y) * (pOld.x - p.x);
|
|
Toshihiro Shimizu |
890ddd |
pOld = p;
|
|
Toshihiro Shimizu |
890ddd |
pointAdded++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
assert(pointAdded >= 4);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return area > 0.5;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void transferColors(const list<tedge *=""> &oldList, const list<tedge *=""> &newList, bool isStrokeChanged, bool isFlipped, bool overwriteColor);</tedge></tedge>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
void printStrokes1(vector<vistroke *=""> &v, int size)</vistroke>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
UINT i = 0;
|
|
Toshihiro Shimizu |
890ddd |
ofstream of("C:\\temp\\strokes.txt");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < (UINT)size; i++) {
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s = v[i]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
of << "***stroke " << i << endl;
|
|
Toshihiro Shimizu |
890ddd |
for (UINT j = 0; j < (UINT)s->getChunkCount(); j++) {
|
|
Toshihiro Shimizu |
890ddd |
const TThickQuadratic *q = s->getChunk(j);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
of << " s0 " << q->getP0() << endl;
|
|
Toshihiro Shimizu |
890ddd |
of << " s1 " << q->getP1() << endl;
|
|
Toshihiro Shimizu |
890ddd |
of << " s2 " << q->getP2() << endl;
|
|
Toshihiro Shimizu |
890ddd |
of << "****** " << endl;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
of << endl;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
for (i = size; i < v.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s = v[i]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
of << "***Autostroke " << i << endl;
|
|
Toshihiro Shimizu |
890ddd |
of << "s0 " << s->getPoint(0.0) << endl;
|
|
Toshihiro Shimizu |
890ddd |
of << "s1 " << s->getPoint(1.0) << endl;
|
|
Toshihiro Shimizu |
890ddd |
of << endl;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
static void printTime(TStopWatch &sw, string name)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
ostrstream ss;
|
|
Toshihiro Shimizu |
890ddd |
ss << name << " : ";
|
|
Toshihiro Shimizu |
890ddd |
sw.print(ss);
|
|
Toshihiro Shimizu |
890ddd |
ss << '\n' << '\0';
|
|
Toshihiro Shimizu |
890ddd |
string s = ss.str();
|
|
Toshihiro Shimizu |
890ddd |
ss.freeze(false);
|
|
Toshihiro Shimizu |
890ddd |
//TSystem::outputDebug(s);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
void printStrokes1(vector<vistroke *=""> &v, int size);</vistroke>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//void testHistory();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Trova le regioni in una TVectorImage
|
|
Toshihiro Shimizu |
890ddd |
int TVectorImage::Imp::computeRegions()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
#ifdef NEW_REGION_FILL
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#if defined(_DEBUG) && !defined(MACOSX)
|
|
Toshihiro Shimizu |
890ddd |
TStopWatch stopWatch;
|
|
Toshihiro Shimizu |
890ddd |
stopWatch.start(true);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//testHistory();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!m_computeRegions)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QMutexLocker sl(m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*if (m_intersectionData->m_computedAlmostOnce)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
UINT i,n=m_strokes.size();
|
|
Toshihiro Shimizu |
890ddd |
vector<int> vv(n);</int>
|
|
Toshihiro Shimizu |
890ddd |
for( i=0; i
|
|
Toshihiro Shimizu |
890ddd |
m_intersectionData->m_computedAlmostOnce = true;
|
|
Toshihiro Shimizu |
890ddd |
notifyChangedStrokes(vv,vector<tstroke*>(), false);</tstroke*>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//g_autocloseTolerance = m_autocloseTolerance;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Cancella le regioni gia' esistenti per ricalcolarle
|
|
Toshihiro Shimizu |
890ddd |
clearPointerContainer(m_regions);
|
|
Toshihiro Shimizu |
890ddd |
m_regions.clear();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Controlla che ci siano degli stroke
|
|
Toshihiro Shimizu |
890ddd |
if (m_strokes.empty()) {
|
|
Toshihiro Shimizu |
890ddd |
#if defined(_DEBUG) && !defined(MACOSX)
|
|
Toshihiro Shimizu |
890ddd |
stopWatch.stop();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Inizializza la lista di intersezioni intList
|
|
Toshihiro Shimizu |
890ddd |
m_computedAlmostOnce = true;
|
|
Toshihiro Shimizu |
890ddd |
VIList<intersection> &intList = m_intersectionData->m_intList;</intersection>
|
|
Toshihiro Shimizu |
890ddd |
cleanIntersectionMarks(intList);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//calcolo struttura delle intersezioni
|
|
Toshihiro Shimizu |
890ddd |
int added = 0, notAdded = 0;
|
|
Toshihiro Shimizu |
890ddd |
int strokeSize;
|
|
Toshihiro Shimizu |
890ddd |
strokeSize = computeIntersections();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p1 = intList.first(); p1; p1 = p1->next())
|
|
Toshihiro Shimizu |
890ddd |
for (p2 = p1->m_strokeList.first(); p2; p2 = p2->next())
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_r = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p1 = intList.first(); p1; p1 = p1->next()) {
|
|
Toshihiro Shimizu |
890ddd |
// Controlla che il punto in questione non sia isolato
|
|
Toshihiro Shimizu |
890ddd |
if (p1->m_numInter == 0)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p2 = p1->m_strokeList.first(); p2; p2 = p2->next()) {
|
|
Toshihiro Shimizu |
890ddd |
TRegion *region;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// se lo stroke non unisce due punti di intersezione
|
|
Toshihiro Shimizu |
890ddd |
// non lo considero e vado avanti con un altro stroke
|
|
Toshihiro Shimizu |
890ddd |
if (!p2->m_nextIntersection)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Se lo stroke puntato da t2 non e' stato ancora visitato, trova una regione
|
|
Toshihiro Shimizu |
890ddd |
if (!p2->m_visited && (region = ::findRegion(intList, p1, p2, m_minimizeEdges))) {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Se la regione e' valida la aggiunge al vettore delle regioni
|
|
Toshihiro Shimizu |
890ddd |
if (isValidArea(*region)) {
|
|
Toshihiro Shimizu |
890ddd |
added++;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
addRegion(region);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Lega ogni ramo della regione alla regione di appartenenza
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i = 0; i < region->getEdgeCount(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
TEdge *e = region->getEdge(i);
|
|
Toshihiro Shimizu |
890ddd |
e->m_r = region;
|
|
Toshihiro Shimizu |
890ddd |
if (e->m_index >= 0)
|
|
Toshihiro Shimizu |
890ddd |
m_strokes[e->m_index]->addEdge(e);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else // Se la regione non e' valida viene scartata
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
notAdded++;
|
|
Toshihiro Shimizu |
890ddd |
delete region;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!m_notIntersectingStrokes) {
|
|
Toshihiro Shimizu |
890ddd |
UINT i;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < m_intersectionData->m_intersectedStrokeArray.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
if (!m_strokes[m_intersectionData->m_intersectedStrokeArray[i].m_index]->m_edgeList.empty())
|
|
Toshihiro Shimizu |
890ddd |
transferColors(m_intersectionData->m_intersectedStrokeArray[i].m_edgeList,
|
|
Toshihiro Shimizu |
890ddd |
m_strokes[m_intersectionData->m_intersectedStrokeArray[i].m_index]->m_edgeList, false, false, true);
|
|
Toshihiro Shimizu |
890ddd |
clearPointerContainer(m_intersectionData->m_intersectedStrokeArray[i].m_edgeList);
|
|
Toshihiro Shimizu |
890ddd |
m_intersectionData->m_intersectedStrokeArray[i].m_edgeList.clear();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_intersectionData->m_intersectedStrokeArray.clear();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(m_intersectionData->m_intersectedStrokeArray.empty());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//tolgo i segmenti aggiunti con l'autoclose
|
|
Toshihiro Shimizu |
890ddd |
vector<vistroke *="">::iterator it = m_strokes.begin();</vistroke>
|
|
Toshihiro Shimizu |
890ddd |
advance(it, strokeSize);
|
|
Toshihiro Shimizu |
890ddd |
m_strokes.erase(it, m_strokes.end());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_areValidRegions = true;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#if defined(_DEBUG)
|
|
Toshihiro Shimizu |
890ddd |
checkRegions(m_regions);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
class Branch
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TEdge m_edge;
|
|
Toshihiro Shimizu |
890ddd |
bool m_out, m_visited;
|
|
Toshihiro Shimizu |
890ddd |
Branch *m_next;
|
|
Toshihiro Shimizu |
890ddd |
Branch *m_nextBranch;
|
|
Toshihiro Shimizu |
890ddd |
Intersection* m_intersection;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
Branch* next()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(m_intersection);
|
|
Toshihiro Shimizu |
890ddd |
return m_next?m_next:m_intersection->m_branchList;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class Intersection
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Toshihiro Shimizu |
890ddd |
TPointD m_intersectionPoint;
|
|
Toshihiro Shimizu |
890ddd |
int m_intersectionCount;
|
|
Toshihiro Shimizu |
890ddd |
Branch *m_branchList;
|
|
Toshihiro Shimizu |
890ddd |
Intersection* m_next;
|
|
Toshihiro Shimizu |
890ddd |
list<intersectedstroke> m_strokeList;</intersectedstroke>
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
AddIntersection(int index0, int index1, DoublePair intersectionValues);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::Imp::checkRegions(const vector<tregion *=""> ®ions)</tregion>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i = 0; i < regions.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
TRegion *r = regions[i];
|
|
Toshihiro Shimizu |
890ddd |
UINT j = 0;
|
|
Toshihiro Shimizu |
890ddd |
for (j = 0; j < r->getEdgeCount(); j++) {
|
|
Toshihiro Shimizu |
890ddd |
TEdge *e = r->getEdge(j);
|
|
Toshihiro Shimizu |
890ddd |
//assert(areSameGroup(e->m_index, false, ==m_strokes[r->getEdge(0)->m_index]->m_groupId);
|
|
Toshihiro Shimizu |
890ddd |
assert(e->m_r == r);
|
|
Toshihiro Shimizu |
890ddd |
//if (e->m_s->isSelfLoop())
|
|
Toshihiro Shimizu |
890ddd |
// {
|
|
Toshihiro Shimizu |
890ddd |
// assert(r->getEdgeCount()==1);
|
|
Toshihiro Shimizu |
890ddd |
//assert(r->getSubregionCount()==0);
|
|
Toshihiro Shimizu |
890ddd |
// }
|
|
Toshihiro Shimizu |
890ddd |
//if (j>0)
|
|
Toshihiro Shimizu |
890ddd |
// assert(!e->m_s->isSelfLoop());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (r->getSubregionCount() > 0) {
|
|
Toshihiro Shimizu |
890ddd |
vector<tregion *=""> aux(r->getSubregionCount());</tregion>
|
|
Toshihiro Shimizu |
890ddd |
for (j = 0; j < r->getSubregionCount(); j++)
|
|
Toshihiro Shimizu |
890ddd |
aux[j] = r->getSubregion(j);
|
|
Toshihiro Shimizu |
890ddd |
checkRegions(aux);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline TGroupId getGroupId(TRegion *r, const vector<vistroke *=""> &strokes)</vistroke>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i = 0; i < r->getEdgeCount(); i++)
|
|
Toshihiro Shimizu |
890ddd |
if (r->getEdge(i)->m_index >= 0)
|
|
Toshihiro Shimizu |
890ddd |
return strokes[r->getEdge(i)->m_index]->m_groupId;
|
|
Toshihiro Shimizu |
890ddd |
return TGroupId();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRegion *TVectorImage::findRegion(const TRegion ®ion) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRegion *ret = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (vector<tregion *="">::iterator it = m_imp->m_regions.begin(); it != m_imp->m_regions.end(); ++it)</tregion>
|
|
Toshihiro Shimizu |
890ddd |
if ((ret = (*it)->findRegion(region)) != 0)
|
|
Toshihiro Shimizu |
890ddd |
return ret;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::Imp::addRegion(TRegion *region)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (vector<tregion *="">::iterator it = m_regions.begin(); it != m_regions.end(); ++it) {</tregion>
|
|
Toshihiro Shimizu |
890ddd |
if (getGroupId(region, m_strokes) != getGroupId(*it, m_strokes))
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (region->contains(**it)) {
|
|
Toshihiro Shimizu |
890ddd |
//region->addSubregion(*it);
|
|
Toshihiro Shimizu |
890ddd |
region->addSubregion(*it);
|
|
Toshihiro Shimizu |
890ddd |
it = m_regions.erase(it);
|
|
Toshihiro Shimizu |
890ddd |
while (it != m_regions.end()) {
|
|
Toshihiro Shimizu |
890ddd |
if (region->contains(**it)) {
|
|
Toshihiro Shimizu |
890ddd |
region->addSubregion(*it);
|
|
Toshihiro Shimizu |
890ddd |
//region->addSubregion(*it);
|
|
Toshihiro Shimizu |
890ddd |
it = m_regions.erase(it);
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
it++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_regions.push_back(region);
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
} else if ((*it)->contains(*region)) {
|
|
Toshihiro Shimizu |
890ddd |
(*it)->addSubregion(region);
|
|
Toshihiro Shimizu |
890ddd |
//(*it)->addSubregion(region);
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_regions.push_back(region);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::replaceStroke(int index, TStroke *newStroke)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if ((int)m_imp->m_strokes.size() <= index)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
delete m_imp->m_strokes[index]->m_s;
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_strokes[index]->m_s = newStroke;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p1 = m_imp->m_intersectionData->m_intList.first(); p1; p1 = p1->next())
|
|
Toshihiro Shimizu |
890ddd |
for (p2 = (*p1).m_strokeList.first(); p2; p2 = p2->next())
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_index == index)
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_s = newStroke;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::Imp::moveStroke(int fromIndex, int moveBefore)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert((int)m_strokes.size() > fromIndex);
|
|
Toshihiro Shimizu |
890ddd |
assert((int)m_strokes.size() >= moveBefore);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
checkIntersections();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
VIStroke *vi = m_strokes[fromIndex];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_strokes.erase(m_strokes.begin() + fromIndex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
vector<vistroke *="">::iterator it = m_strokes.begin();</vistroke>
|
|
Toshihiro Shimizu |
890ddd |
if (fromIndex < moveBefore)
|
|
Toshihiro Shimizu |
890ddd |
advance(it, moveBefore - 1);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
advance(it, moveBefore);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_strokes.insert(it, vi);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p1 = m_intersectionData->m_intList.first(); p1; p1 = p1->next())
|
|
Toshihiro Shimizu |
890ddd |
for (p2 = p1->m_strokeList.first(); p2; p2 = p2->next()) {
|
|
Toshihiro Shimizu |
890ddd |
if (fromIndex < moveBefore) {
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_index == fromIndex)
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_index = moveBefore - 1;
|
|
Toshihiro Shimizu |
890ddd |
else if (p2->m_edge.m_index > fromIndex && p2->m_edge.m_index < moveBefore)
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_index--;
|
|
Toshihiro Shimizu |
890ddd |
} else //(fromIndex>moveBefore)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_index == fromIndex)
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_index = moveBefore;
|
|
Toshihiro Shimizu |
890ddd |
else if (p2->m_edge.m_index >= moveBefore && p2->m_edge.m_index < fromIndex)
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_index++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
checkIntersections();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::Imp::reindexEdges(UINT strokeIndex)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p1 = m_intersectionData->m_intList.first(); p1; p1 = p1->next())
|
|
Toshihiro Shimizu |
890ddd |
for (p2 = (*p1).m_strokeList.first(); p2; p2 = p2->next()) {
|
|
Toshihiro Shimizu |
890ddd |
assert(p2->m_edge.m_index != (int)strokeIndex || p2->m_edge.m_index < 0);
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_index > (int)strokeIndex)
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_index--;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::Imp::reindexEdges(const vector<int> &indexes, bool areAdded)</int>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
int size = indexes.size();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (size == 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < size; i++)
|
|
Toshihiro Shimizu |
890ddd |
assert(i == 0 || indexes[i - 1] < indexes[i]);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int min = (int)indexes[0];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p1 = m_intersectionData->m_intList.first(); p1; p1 = p1->next())
|
|
Toshihiro Shimizu |
890ddd |
for (p2 = p1->m_strokeList.first(); p2; p2 = p2->next()) {
|
|
Toshihiro Shimizu |
890ddd |
if (areAdded) {
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_index < min)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
for (i = size - 1; i >= 0; i--)
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_index >= (int)indexes[i] - i) {
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_index += i + 1;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_index < min)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
for (i = size - 1; i >= 0; i--)
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_index > (int)indexes[i]) {
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_index -= i + 1;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//assert(it2->m_edge.m_index!=1369);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::Imp::insertStrokeAt(VIStroke *vs, int strokeIndex, bool recomputeRegions)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
list<tedge *=""> oldEdgeList, emptyList;</tedge>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_computedAlmostOnce && recomputeRegions) {
|
|
Toshihiro Shimizu |
890ddd |
oldEdgeList = vs->m_edgeList;
|
|
Toshihiro Shimizu |
890ddd |
vs->m_edgeList.clear();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(strokeIndex >= 0 && strokeIndex <= (int)m_strokes.size());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
vector<vistroke *="">::iterator it = m_strokes.begin();</vistroke>
|
|
Toshihiro Shimizu |
890ddd |
advance(it, strokeIndex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
vs->m_isNewForFill = true;
|
|
Toshihiro Shimizu |
890ddd |
m_strokes.insert(it, vs);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!m_computedAlmostOnce)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p1 = m_intersectionData->m_intList.first(); p1; p1 = p1->next())
|
|
Toshihiro Shimizu |
890ddd |
for (p2 = (*p1).m_strokeList.first(); p2; p2 = p2->next())
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_index >= (int)strokeIndex)
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_index++;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!recomputeRegions)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
computeRegions();
|
|
Toshihiro Shimizu |
890ddd |
transferColors(oldEdgeList, m_strokes[strokeIndex]->m_edgeList, true, false, true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
checkIntersections();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void invalidateRegionPropAndBBox(TRegion *reg)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (UINT regId = 0; regId != reg->getSubregionCount(); regId++) {
|
|
Toshihiro Shimizu |
890ddd |
invalidateRegionPropAndBBox(reg->getSubregion(regId));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
reg->invalidateProp();
|
|
Toshihiro Shimizu |
890ddd |
reg->invalidateBBox();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::transform(const TAffine &aff, bool doChangeThickness)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
UINT i;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < m_imp->m_strokes.size(); ++i)
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_strokes[i]->m_s->transform(aff, doChangeThickness);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
map<int, *="" vistroke="">::iterator it = m_imp->m_intersectionData->m_autocloseMap.begin();</int,>
|
|
Toshihiro Shimizu |
890ddd |
for (; it != m_imp->m_intersectionData->m_autocloseMap.end(); ++it)
|
|
Toshihiro Shimizu |
890ddd |
it->second->m_s->transform(aff, false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < m_imp->m_regions.size(); ++i)
|
|
Toshihiro Shimizu |
890ddd |
invalidateRegionPropAndBBox(m_imp->m_regions[i]);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
#include "tvectorrenderdata.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tgl.h"
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::drawAutocloses(const TVectorRenderData &rd) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
float width;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glPushMatrix();
|
|
Toshihiro Shimizu |
890ddd |
tglMultMatrix(rd.m_aff);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glGetFloatv(GL_LINE_WIDTH, &width);
|
|
Toshihiro Shimizu |
890ddd |
tglColor(TPixel(0, 255, 0, 255));
|
|
Toshihiro Shimizu |
890ddd |
glLineWidth(1.5);
|
|
Toshihiro Shimizu |
890ddd |
glBegin(GL_LINES);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p1 = m_imp->m_intersectionData->m_intList.first(); p1; p1 = p1->next())
|
|
Toshihiro Shimizu |
890ddd |
for (p2 = (*p1).m_strokeList.first(); p2; p2 = p2->next()) {
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_index < 0 && p2->m_edge.m_w0 == 0.0) {
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s = p2->m_edge.m_s;
|
|
Toshihiro Shimizu |
890ddd |
TPointD p0 = s->getPoint(0.0);
|
|
Toshihiro Shimizu |
890ddd |
TPointD p1 = s->getPoint(1.0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glVertex2d(p0.x, p0.y);
|
|
Toshihiro Shimizu |
890ddd |
glVertex2d(p1.x, p1.y);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
glEnd();
|
|
Toshihiro Shimizu |
890ddd |
glLineWidth(width);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glPopMatrix();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::reassignStyles(map<int, int=""> &table)</int,>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
UINT i;
|
|
Toshihiro Shimizu |
890ddd |
UINT strokeCount = getStrokeCount();
|
|
Toshihiro Shimizu |
890ddd |
//UINT regionCount = getRegionCount();
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < strokeCount; ++i) {
|
|
Toshihiro Shimizu |
890ddd |
TStroke *stroke = getStroke(i);
|
|
Toshihiro Shimizu |
890ddd |
int styleId = stroke->getStyle();
|
|
Toshihiro Shimizu |
890ddd |
if (styleId != 0) {
|
|
Toshihiro Shimizu |
890ddd |
map<int, int="">::iterator it = table.find(styleId);</int,>
|
|
Toshihiro Shimizu |
890ddd |
if (it != table.end())
|
|
Toshihiro Shimizu |
890ddd |
stroke->setStyle(it->second);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p1 = m_imp->m_intersectionData->m_intList.first(); p1; p1 = p1->next())
|
|
Toshihiro Shimizu |
890ddd |
for (p2 = (*p1).m_strokeList.first(); p2; p2 = p2->next())
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_styleId != 0) {
|
|
Toshihiro Shimizu |
890ddd |
map<int, int="">::iterator it = table.find(p2->m_edge.m_styleId);</int,>
|
|
Toshihiro Shimizu |
890ddd |
if (it != table.end())
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_styleId = it->second;
|
|
Toshihiro Shimizu |
890ddd |
//assert(it->second<100);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
struct TDeleteMapFunctor {
|
|
Toshihiro Shimizu |
890ddd |
void operator()(pair<int, *="" vistroke=""> ptr)</int,>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
delete ptr.second;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
IntersectionData::~IntersectionData()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::for_each(m_autocloseMap.begin(), m_autocloseMap.end(), TDeleteMapFunctor());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::Imp::checkIntersections()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//return;
|
|
Toshihiro Shimizu |
890ddd |
UINT i, j;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0, p1 = m_intersectionData->m_intList.first(); p1; p1 = p1->next(), i++)
|
|
Toshihiro Shimizu |
890ddd |
for (j = 0, p2 = (*p1).m_strokeList.first(); p2; p2 = p2->next(), j++) {
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke &is = *p2;
|
|
Toshihiro Shimizu |
890ddd |
assert(is.m_edge.m_styleId >= 0 && is.m_edge.m_styleId <= 1000);
|
|
Toshihiro Shimizu |
890ddd |
assert(is.m_edge.m_w0 >= 0 && is.m_edge.m_w0 <= 1);
|
|
Toshihiro Shimizu |
890ddd |
assert(is.m_edge.m_index < (int)m_strokes.size());
|
|
Toshihiro Shimizu |
890ddd |
if (is.m_edge.m_index >= 0) {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(is.m_edge.m_s->getChunkCount() >= 0 && is.m_edge.m_s->getChunkCount() <= 10000);
|
|
Toshihiro Shimizu |
890ddd |
assert(m_strokes[is.m_edge.m_index]->m_s == is.m_edge.m_s);
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
assert(m_intersectionData->m_autocloseMap[is.m_edge.m_index]);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_nextIntersection) {
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *nextStroke = p2->m_nextStroke;
|
|
Toshihiro Shimizu |
890ddd |
assert(nextStroke->m_nextIntersection == p1);
|
|
Toshihiro Shimizu |
890ddd |
assert(nextStroke->m_nextStroke == p2);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < m_strokes.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
VIStroke *vs = m_strokes[i];
|
|
Toshihiro Shimizu |
890ddd |
list<tedge *="">::const_iterator it = vs->m_edgeList.begin(), it_e = vs->m_edgeList.end();</tedge>
|
|
Toshihiro Shimizu |
890ddd |
for (; it != it_e; ++it) {
|
|
Toshihiro Shimizu |
890ddd |
TEdge *e = *it;
|
|
Toshihiro Shimizu |
890ddd |
assert(e->getStyle() >= 0 && e->getStyle() <= 1000);
|
|
Toshihiro Shimizu |
890ddd |
assert(e->m_w0 >= 0 && e->m_w1 <= 1);
|
|
Toshihiro Shimizu |
890ddd |
assert(e->m_s == vs->m_s);
|
|
Toshihiro Shimizu |
890ddd |
assert(e->m_s->getChunkCount() >= 0 && e->m_s->getChunkCount() <= 10000);
|
|
Toshihiro Shimizu |
890ddd |
//assert(e->m_index<(int)m_strokes.size()); l'indice nella stroke potrebbe essere non valido, non importa.
|
|
Toshihiro Shimizu |
890ddd |
//assert(m_strokes[e->m_index]->m_s==e->m_s); deve essere buono nella intersectionData
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < m_regions.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
m_regions[i]->checkRegion();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TStroke *TVectorImage::Imp::removeEndpoints(int strokeIndex)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
checkIntersections();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
VIStroke *vs = m_strokes[strokeIndex];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (vs->m_s->isSelfLoop())
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
if (vs->m_edgeList.empty())
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
list<tedge *="">::iterator it = vs->m_edgeList.begin();</tedge>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double minW = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
double maxW = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
for (; it != vs->m_edgeList.end(); ++it) {
|
|
Toshihiro Shimizu |
890ddd |
minW = tmin(minW - 0.00002, (*it)->m_w0, (*it)->m_w1);
|
|
Toshihiro Shimizu |
890ddd |
maxW = tmax(maxW + 0.00002, (*it)->m_w0, (*it)->m_w1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(minW, 0.0, 0.001) && areAlmostEqual(maxW, 1.0, 0.001))
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TStroke *oldS = vs->m_s;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s = new TStroke(*(vs->m_s));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double offs = s->getLength(minW);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TStroke s0, s1, final;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!areAlmostEqual(maxW, 1.0, 0.001)) {
|
|
Toshihiro Shimizu |
890ddd |
s->split(maxW, s0, s1);
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
s0 = *s;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!areAlmostEqual(minW, 0.0, 0.001)) {
|
|
Toshihiro Shimizu |
890ddd |
double newW = (maxW == 1.0) ? minW : s0.getParameterAtLength(offs);
|
|
Toshihiro Shimizu |
890ddd |
s0.split(newW, s1, final);
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
final = s0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
vs->m_s = new TStroke(final);
|
|
Toshihiro Shimizu |
890ddd |
vs->m_s->setStyle(oldS->getStyle());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (it = vs->m_edgeList.begin(); it != vs->m_edgeList.end(); ++it) {
|
|
Toshihiro Shimizu |
890ddd |
(*it)->m_w0 = vs->m_s->getParameterAtLength(s->getLength((*it)->m_w0) - offs);
|
|
Toshihiro Shimizu |
890ddd |
(*it)->m_w1 = vs->m_s->getParameterAtLength(s->getLength((*it)->m_w1) - offs);
|
|
Toshihiro Shimizu |
890ddd |
(*it)->m_s = vs->m_s;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p1 = m_intersectionData->m_intList.first(); p1; p1 = p1->next())
|
|
Toshihiro Shimizu |
890ddd |
for (p2 = (*p1).m_strokeList.first(); p2; p2 = p2->next()) {
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_s == oldS) {
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_w0 = vs->m_s->getParameterAtLength(s->getLength(p2->m_edge.m_w0) - offs);
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_w1 = vs->m_s->getParameterAtLength(s->getLength(p2->m_edge.m_w1) - offs);
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_s = vs->m_s;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
checkIntersections();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return oldS;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TVectorImage::Imp::restoreEndpoints(int index, TStroke *oldStroke)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
checkIntersections();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
VIStroke *vs = m_strokes[index];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TStroke *s = vs->m_s;
|
|
Toshihiro Shimizu |
890ddd |
TPointD p = s->getPoint(0.0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double offs = oldStroke->getLength(oldStroke->getW(p));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
vs->m_s = oldStroke;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
list<tedge *="">::iterator it = vs->m_edgeList.begin();</tedge>
|
|
Toshihiro Shimizu |
890ddd |
for (; it != vs->m_edgeList.end(); ++it) {
|
|
Toshihiro Shimizu |
890ddd |
(*it)->m_w0 = vs->m_s->getParameterAtLength(s->getLength((*it)->m_w0) + offs);
|
|
Toshihiro Shimizu |
890ddd |
(*it)->m_w1 = vs->m_s->getParameterAtLength(s->getLength((*it)->m_w1) + offs);
|
|
Toshihiro Shimizu |
890ddd |
(*it)->m_s = vs->m_s;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Intersection *p1;
|
|
Toshihiro Shimizu |
890ddd |
IntersectedStroke *p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (p1 = m_intersectionData->m_intList.first(); p1; p1 = p1->next())
|
|
Toshihiro Shimizu |
890ddd |
for (p2 = (*p1).m_strokeList.first(); p2; p2 = p2->next()) {
|
|
Toshihiro Shimizu |
890ddd |
if (p2->m_edge.m_s == s) {
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_w0 = vs->m_s->getParameterAtLength(s->getLength(p2->m_edge.m_w0) + offs);
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_w1 = vs->m_s->getParameterAtLength(s->getLength(p2->m_edge.m_w1) + offs);
|
|
Toshihiro Shimizu |
890ddd |
p2->m_edge.m_s = vs->m_s;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
delete s;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
checkIntersections();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|