2016-05-17 03:04:11 +12:00
|
|
|
#pragma once
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
#ifndef T_CENTERLINE_VECTORIZER_PRIVATE
|
|
|
|
#define T_CENTERLINE_VECTORIZER_PRIVATE
|
|
|
|
|
|
|
|
#include "toonz/tcenterlinevectorizer.h"
|
|
|
|
|
|
|
|
// TnzCore includes
|
|
|
|
#include "tpalette.h"
|
|
|
|
#include "tcolorstyles.h"
|
|
|
|
|
|
|
|
#include "trastercm.h"
|
|
|
|
#include "ttoonzimage.h"
|
|
|
|
#include "trasterimage.h"
|
|
|
|
#include "tvectorimage.h"
|
|
|
|
|
|
|
|
#include "tgeometry.h"
|
|
|
|
#include "tstroke.h"
|
|
|
|
|
|
|
|
// STD includes
|
|
|
|
#include <vector>
|
|
|
|
#include <list>
|
|
|
|
#include <queue>
|
|
|
|
#include <map>
|
|
|
|
#include <functional>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
//--------------------------------------
|
|
|
|
// Preliminary geometric helpers
|
|
|
|
//--------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
inline TPointD planeProjection(const T3DPointD &p) { return TPointD(p.x, p.y); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//! Returns distance of \p P from line of direction \p v that touches \p B
|
2016-06-15 18:43:10 +12:00
|
|
|
inline double tdistance2(const T3DPointD &P, const T3DPointD &v,
|
|
|
|
const T3DPointD &B) {
|
|
|
|
double t = P * v - B * v;
|
|
|
|
T3DPointD Q = B + t * v - P;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
return Q * Q;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
inline double tdistance(TPointD P, TPointD v, TPointD B) {
|
|
|
|
return fabs(cross(P - B, normalize(v)));
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
inline double tdistance(T3DPointD P, T3DPointD v, T3DPointD B) {
|
|
|
|
double vv = norm2(v);
|
|
|
|
if (vv < 0.01) return -1;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
double t = (P * v - B * v) / vv;
|
|
|
|
T3DPointD Q = B + t * v - P;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
return norm(Q);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
inline double planeDistance(const T3DPointD &P, const T3DPointD &Q) {
|
|
|
|
return sqrt((P.x - Q.x) * (P.x - Q.x) + (P.y - Q.y) * (P.y - Q.y));
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
inline double crossZ(const T3DPointD &p, const T3DPointD &q) {
|
|
|
|
return p.x * q.y - p.y * q.x;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
// a, b assumed normalized
|
2016-06-15 18:43:10 +12:00
|
|
|
inline bool angleLess(const TPointD &a, const TPointD &b) {
|
|
|
|
return a.y >= 0 ? b.y >= 0 ? a.x > b.x : 1 : b.y < 0 ? a.x < b.x : 0;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
// a, b, ref assumed normalized
|
2016-06-15 18:43:10 +12:00
|
|
|
inline bool angleLess(const TPointD &a, const TPointD &b, const TPointD &ref) {
|
|
|
|
return angleLess(a, ref) ? angleLess(b, ref) ? angleLess(a, b) : 0
|
|
|
|
: angleLess(b, ref) ? 1 : angleLess(a, b);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//------------------------
|
|
|
|
// STL auxiliaries
|
|
|
|
//------------------------
|
|
|
|
|
|
|
|
// Container append (needs reverse iterators)
|
|
|
|
// NOTE: Merge could be used... but it requires operator< and we don't...
|
|
|
|
|
2019-09-02 20:49:49 +12:00
|
|
|
//! warning: must be I == T::Reverse_iterator; explicitly because on Mac it was
|
2016-06-15 18:43:10 +12:00
|
|
|
//! not compiling!
|
2016-03-19 06:57:51 +13:00
|
|
|
template <class T, class I>
|
2016-06-15 18:43:10 +12:00
|
|
|
void append(T &cont1, T &cont2) {
|
|
|
|
I i, j;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
cont1.resize(cont1.size() + cont2.size());
|
|
|
|
for (i = cont2.rbegin(), j = cont1.rbegin(); i != cont2.rend(); ++i, ++j)
|
|
|
|
*j = *i;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//*********************************
|
|
|
|
// Traversable Graphs
|
|
|
|
//*********************************
|
|
|
|
|
|
|
|
typedef unsigned int UINT;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Graph class used by the centerline vectorization process.
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
\details Introducing a directed graph structure that allows local access:
|
|
|
|
main feature is that a graph edge
|
|
|
|
physically belongs to the node that emitted it, by storing it in a
|
|
|
|
'link vector' inside the node.
|
|
|
|
No full-scale edge search method is therefore needed to find node
|
|
|
|
neighbours.
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
No specific iterator class is needed, just use unsigned ints to
|
|
|
|
perform random access to nodes and
|
2016-03-19 06:57:51 +13:00
|
|
|
links vectors.
|
|
|
|
*/
|
|
|
|
template <typename NodeContentType, typename ArcType>
|
2016-06-15 18:43:10 +12:00
|
|
|
class Graph {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
class Link {
|
|
|
|
UINT m_next; //!< Index of the node pointed by this link.
|
|
|
|
ArcType m_arc; //!< Edge data associated to this link.
|
|
|
|
int m_access; //!< Whether access to a node is allowed
|
|
|
|
//! through this link.
|
|
|
|
public:
|
|
|
|
Link() : m_access(1) {}
|
|
|
|
Link(UINT _next) : m_next(_next), m_access(1) {}
|
|
|
|
Link(UINT _next, ArcType _arc) : m_next(_next), m_arc(_arc), m_access(1) {}
|
|
|
|
~Link() {}
|
|
|
|
|
|
|
|
ArcType &operator*() { return m_arc; }
|
|
|
|
const ArcType &operator*() const { return m_arc; }
|
|
|
|
|
|
|
|
ArcType *operator->() { return &m_arc; }
|
|
|
|
const ArcType *operator->() const { return &m_arc; }
|
|
|
|
|
|
|
|
UINT getNext() const { return m_next; }
|
|
|
|
void setNext(UINT _next) { m_next = _next; }
|
|
|
|
|
|
|
|
int getAccess() const { return m_access; }
|
|
|
|
void setAccess(int acc) { m_access = acc; }
|
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class Node {
|
|
|
|
friend class Graph; // Grant Graph access to m_links
|
|
|
|
|
|
|
|
std::vector<Link> m_links; //!< Links to neighbouring nodes.
|
|
|
|
NodeContentType m_content; //!< The node's content.
|
|
|
|
int m_attributes; //!< Node attributes.
|
|
|
|
|
|
|
|
public:
|
|
|
|
Node() : m_attributes(0) {}
|
|
|
|
Node(const NodeContentType &_cont) : m_content(_cont), m_attributes(0) {}
|
|
|
|
~Node() {}
|
|
|
|
|
|
|
|
Link &link(UINT i) { return m_links[i]; }
|
|
|
|
const Link &getLink(UINT i) const { return m_links[i]; }
|
|
|
|
UINT getLinksCount() const { return m_links.size(); }
|
|
|
|
|
|
|
|
NodeContentType &operator*() { return m_content; }
|
|
|
|
const NodeContentType &operator*() const { return m_content; }
|
|
|
|
|
|
|
|
NodeContentType *operator->() { return &m_content; }
|
|
|
|
const NodeContentType *operator->() const { return &m_content; }
|
|
|
|
|
|
|
|
// Attributes
|
|
|
|
int hasAttribute(int attr) const { return m_attributes & attr; }
|
|
|
|
void setAttribute(int attr) { m_attributes |= attr; }
|
|
|
|
void clearAttribute(int attr) { m_attributes &= ~attr; }
|
|
|
|
|
|
|
|
// Others
|
|
|
|
int degree() const { return int(m_links.size()); }
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\warning If more links can be set between the same nodes, the
|
|
|
|
returned link index will be ambiguous.
|
|
|
|
*/
|
|
|
|
UINT linkOfNode(UINT next) const {
|
|
|
|
UINT i = 0;
|
|
|
|
for (; i < m_links.size() && m_links[i].getNext() != next; ++i)
|
|
|
|
;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
};
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
std::vector<Node> m_nodes; //!< Nodes container.
|
|
|
|
UINT m_linksCount; //!< Links counter.
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
Graph() : m_linksCount(0) {}
|
|
|
|
virtual ~Graph() {}
|
|
|
|
|
|
|
|
Node &node(UINT i) { return m_nodes[i]; }
|
|
|
|
const Node &getNode(UINT i) const { return m_nodes[i]; }
|
|
|
|
|
|
|
|
UINT getNodesCount() const { return m_nodes.size(); }
|
|
|
|
UINT getLinksCount() const { return m_linksCount; }
|
|
|
|
|
|
|
|
// Nodes/Links insertions
|
|
|
|
UINT newNode() {
|
|
|
|
m_nodes.push_back(Node());
|
|
|
|
return m_nodes.size() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT newNode(const NodeContentType &content) {
|
|
|
|
m_nodes.push_back(Node(content));
|
|
|
|
return m_nodes.size() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT newLink(UINT first, UINT last) {
|
|
|
|
assert(first < m_nodes.size() && last < m_nodes.size());
|
|
|
|
m_nodes[first].m_links.push_back(Link(last));
|
|
|
|
++m_linksCount;
|
|
|
|
return m_nodes[first].m_links.size() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT newLink(UINT first, UINT last, const ArcType &arc) {
|
|
|
|
assert(first < m_nodes.size() && last < m_nodes.size());
|
|
|
|
m_nodes[first].m_links.push_back(Link(last, arc));
|
|
|
|
++m_linksCount;
|
|
|
|
return m_nodes[first].m_links.size() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void insert(UINT inserted, UINT afterNode, UINT onLink) {
|
|
|
|
newLink(inserted, getNode(afterNode).getLink(onLink).getNext());
|
|
|
|
node(afterNode).link(onLink).setNext(inserted);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
//********************************
|
|
|
|
//* Polygonization classes *
|
|
|
|
//********************************
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Of course we don't want RawBorders to be entirely copied whenever STL
|
|
|
|
// requires to resize a BorderFamily...
|
|
|
|
class RawBorder;
|
|
|
|
|
|
|
|
typedef std::vector<RawBorder *> BorderFamily;
|
|
|
|
typedef std::vector<BorderFamily> BorderList;
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
// Output Polygon Classes
|
|
|
|
//--------------------------------
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class ContourEdge;
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// NOTE: The following class is mainly used in the later 'straight skeleton
|
|
|
|
// computation'
|
2016-03-19 06:57:51 +13:00
|
|
|
// - for polygonization purposes, consider it like a TPointD class.
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
class ContourNode {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
enum Attributes //! Node attributes
|
|
|
|
{ HEAD = 0x1, //!< Node is the 'first' of a nodes ring.
|
|
|
|
ELIMINATED = 0x4, //!< Node was eliminated by the SS process.
|
|
|
|
SK_NODE_DROPPED = 0x8,
|
|
|
|
AMBIGUOUS_LEFT = 0x10, //!< Node represents an ambiguous \a left turn in
|
|
|
|
//! the original image.
|
|
|
|
AMBIGUOUS_RIGHT = 0x20, //!< Node represents an ambiguous \a right turn in
|
|
|
|
//! the original image.
|
|
|
|
JR_RESERVED = 0x40, //!< Reserved for joints recovery.
|
|
|
|
LINEAR_ADDED = 0x80 //!< Node was added by the linear skeleton technique.
|
|
|
|
};
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
// Node kinematics infos
|
|
|
|
T3DPointD m_position, //!< Node's position.
|
|
|
|
m_direction, //!< Node's direction.
|
|
|
|
m_AngularMomentum, //!< Angular momentum with the next node's edge.
|
|
|
|
m_AuxiliaryMomentum1, // Used only when this vertex is convex
|
|
|
|
m_AuxiliaryMomentum2; // Used only when this vertex is convex
|
|
|
|
|
|
|
|
// Further node properties
|
|
|
|
bool m_concave; //!< Whether the node represents a concave angle.
|
|
|
|
unsigned int m_attributes, //!< Bitwise signatures of this node
|
2019-09-02 20:49:49 +12:00
|
|
|
m_updateTime, //!< \a Algorithmic time in which the node was updated.
|
2016-06-15 18:43:10 +12:00
|
|
|
m_ancestor, //!< Index of the original node from which this one evolved.
|
|
|
|
m_ancestorContour; //!< Contour index of the original node from which
|
2016-06-20 14:23:05 +12:00
|
|
|
//! this one evolved.
|
2016-06-15 18:43:10 +12:00
|
|
|
std::vector<ContourEdge *> m_notOpposites; //!< List of edges \a not to be
|
2016-06-20 14:23:05 +12:00
|
|
|
//! used as possible opposites.
|
2016-06-15 18:43:10 +12:00
|
|
|
int m_outputNode; //!< Skeleton node produced by this ContourNode.
|
|
|
|
|
|
|
|
// Connective data
|
|
|
|
ContourEdge *m_edge; //!< Edge departing from this, keeping adjacent black
|
|
|
|
//! region on the right
|
|
|
|
// Node neighbours
|
|
|
|
ContourNode *m_next; //!< Next node on the contour.
|
|
|
|
ContourNode *m_prev; //!< Previous node on the contour.
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
ContourNode() : m_attributes(0) {}
|
|
|
|
ContourNode(double x, double y) : m_position(x, y, 0), m_attributes(0) {}
|
|
|
|
ContourNode(const TPointD &P) : m_position(P.x, P.y, 0), m_attributes(0) {}
|
|
|
|
ContourNode(double x, double y, unsigned short attrib)
|
|
|
|
: m_position(x, y, 0), m_attributes(attrib) {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int hasAttribute(int attr) const { return m_attributes & attr; }
|
|
|
|
void setAttribute(int attr) { m_attributes |= attr; }
|
|
|
|
void clearAttribute(int attr) { m_attributes &= ~attr; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
// Private Node Methods
|
|
|
|
inline void buildNodeInfos(bool forceConvex = false);
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
typedef std::vector<ContourNode> Contour;
|
|
|
|
typedef std::vector<Contour> ContourFamily;
|
|
|
|
typedef std::vector<ContourFamily> Contours;
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
//-----------------------------------
|
|
|
|
// Straight Skeleton Classes
|
|
|
|
//-----------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
class SkeletonArc {
|
|
|
|
double m_slope;
|
|
|
|
unsigned int m_leftGeneratingNode, m_leftContour, m_rightGeneratingNode,
|
|
|
|
m_rightContour;
|
|
|
|
int m_attributes;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// NOTE: Typically an arc is generated by a couple of *edges* of the original
|
|
|
|
// contours; but we store instead the *nodes* which address those
|
|
|
|
// edges.
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
SkeletonArc() : m_attributes(0) {}
|
|
|
|
SkeletonArc(ContourNode *node)
|
|
|
|
: m_slope(node->m_direction.z)
|
|
|
|
, m_leftGeneratingNode(node->m_ancestor)
|
|
|
|
, m_leftContour(node->m_ancestorContour)
|
|
|
|
, m_rightGeneratingNode(node->m_prev->m_ancestor)
|
|
|
|
, m_rightContour(node->m_prev->m_ancestorContour)
|
|
|
|
, m_attributes(0) {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
enum { ROAD = 0x1 };
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
double getSlope() const { return m_slope; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
unsigned int getLeftGenerator() const { return m_leftGeneratingNode; }
|
|
|
|
unsigned int getRightGenerator() const { return m_rightGeneratingNode; }
|
|
|
|
unsigned int getLeftContour() const { return m_leftContour; }
|
|
|
|
unsigned int getRightContour() const { return m_rightContour; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
enum { SS_OUTLINE = 0x10, SS_OUTLINE_REVERSED = 0x20 };
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int hasAttribute(int attr) const { return m_attributes & attr; }
|
|
|
|
void setAttribute(int attr) { m_attributes |= attr; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void turn() {
|
|
|
|
m_slope = -m_slope;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
std::swap(m_leftGeneratingNode, m_rightGeneratingNode);
|
|
|
|
std::swap(m_leftContour, m_rightContour);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
typedef Graph<T3DPointD, SkeletonArc> SkeletonGraph;
|
|
|
|
typedef std::vector<SkeletonGraph *> SkeletonList;
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
// Joints and Sequences definition
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
class Sequence {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
UINT m_head;
|
|
|
|
UINT m_headLink;
|
|
|
|
UINT m_tail;
|
|
|
|
UINT m_tailLink;
|
|
|
|
SkeletonGraph *m_graphHolder;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// Stroke color-sensible data
|
|
|
|
int m_color;
|
|
|
|
int m_strokeIndex;
|
|
|
|
int m_strokeHeight;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
Sequence() : m_graphHolder(0) {}
|
|
|
|
~Sequence() {}
|
|
|
|
|
2019-09-02 20:49:49 +12:00
|
|
|
// Impose a property dependent only on the extremity we consider first
|
2016-06-15 18:43:10 +12:00
|
|
|
// - so that the same sequence is not considered twice when head and tail
|
|
|
|
// are exchanged
|
|
|
|
bool isForward() const {
|
|
|
|
return (m_head < m_tail) || (m_head == m_tail && m_headLink < m_tailLink);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Advances a couple (old, current) of sequence nodes
|
|
|
|
void advance(UINT &old, UINT ¤t) const {
|
|
|
|
UINT temp = current;
|
|
|
|
current = m_graphHolder->getNode(current).getLink(0).getNext() == old
|
|
|
|
? m_graphHolder->getNode(current).getLink(1).getNext()
|
|
|
|
: m_graphHolder->getNode(current).getLink(0).getNext();
|
|
|
|
old = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Advances a couple (current, link) of a sequence node plus its link
|
|
|
|
// direction
|
|
|
|
void next(UINT ¤t, UINT &link) const {
|
|
|
|
UINT temp = current;
|
|
|
|
current = m_graphHolder->getNode(current).getLink(link).getNext();
|
|
|
|
link = m_graphHolder->getNode(current).getLink(0).getNext() == temp ? 1 : 0;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class JointSequenceGraph final : public Graph<UINT, Sequence> {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
JointSequenceGraph() {}
|
|
|
|
~JointSequenceGraph() {}
|
|
|
|
|
|
|
|
enum { REACHED = 0x1, ELIMINATED = 0x2 };
|
|
|
|
|
|
|
|
// Extracts JSG tail link of input node-link
|
|
|
|
inline UINT tailLinkOf(UINT node, UINT link) {
|
|
|
|
UINT i, next = getNode(node).getLink(link).getNext();
|
|
|
|
|
|
|
|
for (i = 0; getNode(next).getLink(i)->m_tail !=
|
|
|
|
getNode(node).getLink(link)->m_head ||
|
|
|
|
getNode(next).getLink(i)->m_tailLink !=
|
|
|
|
getNode(node).getLink(link)->m_headLink;
|
|
|
|
++i)
|
|
|
|
;
|
|
|
|
return i;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<JointSequenceGraph> JointSequenceGraphList;
|
|
|
|
|
|
|
|
typedef std::vector<Sequence> SequenceList;
|
|
|
|
typedef std::vector<T3DPointD> PointList;
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//----------------
|
|
|
|
// Globals
|
|
|
|
//----------------
|
|
|
|
|
|
|
|
//!\b FOR \b INTERNAL \b USE \b ONLY!
|
2016-06-15 18:43:10 +12:00
|
|
|
//! EXPLANATION: Some variables are used widely used and shared by all the
|
|
|
|
//! "tcenterline*.cpp"
|
|
|
|
// sources. Instead than passing each variable repeatedly, it is easier to
|
|
|
|
// define a Global
|
2019-09-02 20:49:49 +12:00
|
|
|
// class passed to each file, which gets immediately pointed in an anonymous
|
2016-06-15 18:43:10 +12:00
|
|
|
// namespace.
|
|
|
|
|
|
|
|
class VectorizerCoreGlobals {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
const CenterlineConfiguration *currConfig;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
JointSequenceGraphList organizedGraphs;
|
|
|
|
SequenceList singleSequences;
|
|
|
|
PointList singlePoints;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
VectorizerCoreGlobals() {}
|
|
|
|
~VectorizerCoreGlobals() {}
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
namespace {
|
|
|
|
// SkeletonGraph nodes global signatures - used for various purposes
|
|
|
|
enum {
|
|
|
|
ORGANIZEGRAPHS_SIGN = 0x10,
|
|
|
|
SAMPLECOLOR_SIGN = 0x20,
|
|
|
|
COLORORDERING_SIGN = 0x40
|
|
|
|
};
|
|
|
|
const int infinity = 1000000; // just a great enough number
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//===============================
|
|
|
|
// Function prototypes
|
|
|
|
//===============================
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void polygonize(const TRasterP &ras, Contours &polygons,
|
|
|
|
VectorizerCoreGlobals &g);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
SkeletonList *skeletonize(Contours &contours, VectorizerCore *thisVectorizer,
|
2016-06-15 18:43:10 +12:00
|
|
|
VectorizerCoreGlobals &g);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
void organizeGraphs(SkeletonList *skeleton, VectorizerCoreGlobals &g);
|
|
|
|
|
|
|
|
void junctionRecovery(Contours *polygons, VectorizerCoreGlobals &g);
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void conversionToStrokes(std::vector<TStroke *> &strokes,
|
|
|
|
VectorizerCoreGlobals &g);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
void calculateSequenceColors(const TRasterP &ras, VectorizerCoreGlobals &g);
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void applyStrokeColors(std::vector<TStroke *> &strokes, const TRasterP &ras,
|
|
|
|
TPalette *palette, VectorizerCoreGlobals &g);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
#endif // T_CENTERLINE_VECTORIZER_PRIVATE
|