|
Ankit Kumar Dwivedi |
ba802f |
/* === S Y N F I G ========================================================= */
|
|
Ankit Kumar Dwivedi |
ba802f |
/*! \file template.h
|
|
Ankit Kumar Dwivedi |
ba802f |
** \brief Template Header
|
|
Ankit Kumar Dwivedi |
ba802f |
**
|
|
Ankit Kumar Dwivedi |
ba802f |
** $Id$
|
|
Ankit Kumar Dwivedi |
ba802f |
**
|
|
Ankit Kumar Dwivedi |
ba802f |
** \legal
|
|
Ankit Kumar Dwivedi |
ba802f |
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
|
|
Ankit Kumar Dwivedi |
ba802f |
**
|
|
Ankit Kumar Dwivedi |
ba802f |
** This package is free software; you can redistribute it and/or
|
|
Ankit Kumar Dwivedi |
ba802f |
** modify it under the terms of the GNU General Public License as
|
|
Ankit Kumar Dwivedi |
ba802f |
** published by the Free Software Foundation; either version 2 of
|
|
Ankit Kumar Dwivedi |
ba802f |
** the License, or (at your option) any later version.
|
|
Ankit Kumar Dwivedi |
ba802f |
**
|
|
Ankit Kumar Dwivedi |
ba802f |
** This package is distributed in the hope that it will be useful,
|
|
Ankit Kumar Dwivedi |
ba802f |
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Ankit Kumar Dwivedi |
ba802f |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Ankit Kumar Dwivedi |
ba802f |
** General Public License for more details.
|
|
Ankit Kumar Dwivedi |
ba802f |
** \endlegal
|
|
Ankit Kumar Dwivedi |
ba802f |
*/
|
|
Ankit Kumar Dwivedi |
ba802f |
/* ========================================================================= */
|
|
Ankit Kumar Dwivedi |
ba802f |
|
|
Ankit Kumar Dwivedi |
ba802f |
/* === S T A R T =========================================================== */
|
|
Ankit Kumar Dwivedi |
ba802f |
|
|
|
d20d89 |
#ifndef __SYNFIG_APP_POLYGONIZERCLASSES_H
|
|
|
d20d89 |
#define __SYNFIG_APP_POLYGONIZERCLASSES_H
|
|
Ankit Kumar Dwivedi |
ba802f |
|
|
Ankit Kumar Dwivedi |
ba802f |
/* === H E A D E R S ======================================================= */
|
|
Ankit Kumar Dwivedi |
ba802f |
#include <synfig vector.h=""></synfig>
|
|
Ankit Kumar Dwivedi |
989a09 |
#include "centerlinevectorizer.h"
|
|
Ankit Kumar Dwivedi |
ba802f |
|
|
Ankit Kumar Dwivedi |
ba802f |
/* === M A C R O S ========================================================= */
|
|
Ankit Kumar Dwivedi |
ba802f |
|
|
Ankit Kumar Dwivedi |
ba802f |
/* === T Y P E D E F S ===================================================== */
|
|
Ankit Kumar Dwivedi |
ba802f |
|
|
Ankit Kumar Dwivedi |
ba802f |
/* === C L A S S E S & S T R U C T S ======================================= */
|
|
Ankit Kumar Dwivedi |
ba802f |
|
|
Ankit Kumar Dwivedi |
ba802f |
namespace studio {
|
|
Ankit Kumar Dwivedi |
ba802f |
|
|
Ankit Kumar Dwivedi |
d23826 |
//*********************************
|
|
Ankit Kumar Dwivedi |
d23826 |
// Traversable Graphs
|
|
Ankit Kumar Dwivedi |
d23826 |
//*********************************
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
typedef unsigned int UINT;
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
/*!
|
|
Ankit Kumar Dwivedi |
d23826 |
\brief Graph class used by the centerline vectorization process.
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
\details Introducing a directed graph structure that allows local access:
|
|
Ankit Kumar Dwivedi |
d23826 |
main feature is that a graph edge
|
|
Ankit Kumar Dwivedi |
d23826 |
physically belongs to the node that emitted it, by storing it in a
|
|
Ankit Kumar Dwivedi |
d23826 |
'link vector' inside the node.
|
|
Ankit Kumar Dwivedi |
d23826 |
No full-scale edge search method is therefore needed to find node
|
|
Ankit Kumar Dwivedi |
d23826 |
neighbours.
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
No specific iterator class is needed, just use unsigned ints to
|
|
Ankit Kumar Dwivedi |
d23826 |
perform random access to nodes and
|
|
Ankit Kumar Dwivedi |
d23826 |
links vectors.
|
|
Ankit Kumar Dwivedi |
d23826 |
*/
|
|
Ankit Kumar Dwivedi |
9a885f |
template <class class="" i="" t,=""></class>
|
|
Ankit Kumar Dwivedi |
9a885f |
void append(T &cont1, T &cont2)
|
|
Ankit Kumar Dwivedi |
9a885f |
{
|
|
Ankit Kumar Dwivedi |
9a885f |
I i, j;
|
|
Ankit Kumar Dwivedi |
9a885f |
|
|
Ankit Kumar Dwivedi |
9a885f |
cont1.resize(cont1.size() + cont2.size());
|
|
Ankit Kumar Dwivedi |
9a885f |
for (i = cont2.rbegin(), j = cont1.rbegin(); i != cont2.rend(); ++i, ++j)
|
|
Ankit Kumar Dwivedi |
9a885f |
*j = *i;
|
|
Ankit Kumar Dwivedi |
9a885f |
}
|
|
Ankit Kumar Dwivedi |
9a885f |
|
|
Ankit Kumar Dwivedi |
d23826 |
template <typename arctype="" nodecontenttype,="" typename=""></typename>
|
|
Ankit Kumar Dwivedi |
d23826 |
class Graph {
|
|
Ankit Kumar Dwivedi |
d23826 |
public:
|
|
Ankit Kumar Dwivedi |
d23826 |
class Link {
|
|
Ankit Kumar Dwivedi |
d23826 |
UINT m_next; //!< Index of the node pointed by this link.
|
|
Ankit Kumar Dwivedi |
d23826 |
ArcType m_arc; //!< Edge data associated to this link.
|
|
Ankit Kumar Dwivedi |
d23826 |
int m_access; //!< Whether access to a node is allowed
|
|
Ankit Kumar Dwivedi |
d23826 |
//! through this link.
|
|
Ankit Kumar Dwivedi |
d23826 |
public:
|
|
Ankit Kumar Dwivedi |
d23826 |
Link() : m_access(1) {}
|
|
Ankit Kumar Dwivedi |
d23826 |
Link(UINT _next) : m_next(_next), m_access(1) {}
|
|
Ankit Kumar Dwivedi |
d23826 |
Link(UINT _next, ArcType _arc) : m_next(_next), m_arc(_arc), m_access(1) {}
|
|
Ankit Kumar Dwivedi |
d23826 |
~Link() {}
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
ArcType &operator*() { return m_arc; }
|
|
Ankit Kumar Dwivedi |
d23826 |
const ArcType &operator*() const { return m_arc; }
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
ArcType *operator->() { return &m_arc; }
|
|
Ankit Kumar Dwivedi |
d23826 |
const ArcType *operator->() const { return &m_arc; }
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
UINT getNext() const { return m_next; }
|
|
Ankit Kumar Dwivedi |
d23826 |
void setNext(UINT _next) { m_next = _next; }
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
int getAccess() const { return m_access; }
|
|
Ankit Kumar Dwivedi |
d23826 |
void setAccess(int acc) { m_access = acc; }
|
|
Ankit Kumar Dwivedi |
d23826 |
};
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
//--------------------------------------------------------------------------
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
class Node {
|
|
Ankit Kumar Dwivedi |
d23826 |
friend class Graph; // Grant Graph access to m_links
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
std::vector<link> m_links; //!< Links to neighbouring nodes.
|
|
Ankit Kumar Dwivedi |
d23826 |
NodeContentType m_content; //!< The node's content.
|
|
Ankit Kumar Dwivedi |
d23826 |
int m_attributes; //!< Node attributes.
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
public:
|
|
Ankit Kumar Dwivedi |
d23826 |
Node() : m_attributes(0) {}
|
|
Ankit Kumar Dwivedi |
d23826 |
Node(const NodeContentType &_cont) : m_content(_cont), m_attributes(0) {}
|
|
Ankit Kumar Dwivedi |
d23826 |
~Node() {}
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
Link &link(UINT i) { return m_links[i]; }
|
|
Ankit Kumar Dwivedi |
d23826 |
const Link &getLink(UINT i) const { return m_links[i]; }
|
|
Ankit Kumar Dwivedi |
d23826 |
UINT getLinksCount() const { return m_links.size(); }
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
NodeContentType &operator*() { return m_content; }
|
|
Ankit Kumar Dwivedi |
d23826 |
const NodeContentType &operator*() const { return m_content; }
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
NodeContentType *operator->() { return &m_content; }
|
|
Ankit Kumar Dwivedi |
d23826 |
const NodeContentType *operator->() const { return &m_content; }
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
// Attributes
|
|
Ankit Kumar Dwivedi |
d23826 |
int hasAttribute(int attr) const { return m_attributes & attr; }
|
|
Ankit Kumar Dwivedi |
d23826 |
void setAttribute(int attr) { m_attributes |= attr; }
|
|
Ankit Kumar Dwivedi |
d23826 |
void clearAttribute(int attr) { m_attributes &= ~attr; }
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
// Others
|
|
Ankit Kumar Dwivedi |
d23826 |
int degree() const { return int(m_links.size()); }
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
/*!
|
|
Ankit Kumar Dwivedi |
d23826 |
\warning If more links can be set between the same nodes, the
|
|
Ankit Kumar Dwivedi |
d23826 |
returned link index will be ambiguous.
|
|
Ankit Kumar Dwivedi |
d23826 |
*/
|
|
Ankit Kumar Dwivedi |
d23826 |
UINT linkOfNode(UINT next) const {
|
|
Ankit Kumar Dwivedi |
d23826 |
UINT i = 0;
|
|
Ankit Kumar Dwivedi |
d23826 |
for (; i < m_links.size() && m_links[i].getNext() != next; ++i)
|
|
Ankit Kumar Dwivedi |
d23826 |
;
|
|
Ankit Kumar Dwivedi |
d23826 |
return i;
|
|
Ankit Kumar Dwivedi |
d23826 |
}
|
|
Ankit Kumar Dwivedi |
d23826 |
};
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
public:
|
|
Ankit Kumar Dwivedi |
d23826 |
std::vector<node> m_nodes; //!< Nodes container.</node>
|
|
Ankit Kumar Dwivedi |
d23826 |
UINT m_linksCount; //!< Links counter.
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
public:
|
|
Ankit Kumar Dwivedi |
d23826 |
Graph() : m_linksCount(0) {}
|
|
Ankit Kumar Dwivedi |
d23826 |
virtual ~Graph() {}
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
Node &node(UINT i) { return m_nodes[i]; }
|
|
Ankit Kumar Dwivedi |
d23826 |
const Node &getNode(UINT i) const { return m_nodes[i]; }
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
UINT getNodesCount() const { return m_nodes.size(); }
|
|
Ankit Kumar Dwivedi |
d23826 |
UINT getLinksCount() const { return m_linksCount; }
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
// Nodes/Links insertions
|
|
Ankit Kumar Dwivedi |
d23826 |
UINT newNode() {
|
|
Ankit Kumar Dwivedi |
d23826 |
m_nodes.push_back(Node());
|
|
Ankit Kumar Dwivedi |
d23826 |
return m_nodes.size() - 1;
|
|
Ankit Kumar Dwivedi |
d23826 |
}
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
UINT newNode(const NodeContentType &content) {
|
|
Ankit Kumar Dwivedi |
d23826 |
m_nodes.push_back(Node(content));
|
|
Ankit Kumar Dwivedi |
d23826 |
return m_nodes.size() - 1;
|
|
Ankit Kumar Dwivedi |
d23826 |
}
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
UINT newLink(UINT first, UINT last) {
|
|
Ankit Kumar Dwivedi |
d23826 |
assert(first < m_nodes.size() && last < m_nodes.size());
|
|
Ankit Kumar Dwivedi |
d23826 |
m_nodes[first].m_links.push_back(Link(last));
|
|
Ankit Kumar Dwivedi |
d23826 |
++m_linksCount;
|
|
Ankit Kumar Dwivedi |
d23826 |
return m_nodes[first].m_links.size() - 1;
|
|
Ankit Kumar Dwivedi |
d23826 |
}
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
UINT newLink(UINT first, UINT last, const ArcType &arc) {
|
|
Ankit Kumar Dwivedi |
d23826 |
assert(first < m_nodes.size() && last < m_nodes.size());
|
|
Ankit Kumar Dwivedi |
d23826 |
m_nodes[first].m_links.push_back(Link(last, arc));
|
|
Ankit Kumar Dwivedi |
d23826 |
++m_linksCount;
|
|
Ankit Kumar Dwivedi |
d23826 |
return m_nodes[first].m_links.size() - 1;
|
|
Ankit Kumar Dwivedi |
d23826 |
}
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
void insert(UINT inserted, UINT afterNode, UINT onLink) {
|
|
Ankit Kumar Dwivedi |
d23826 |
newLink(inserted, getNode(afterNode).getLink(onLink).getNext());
|
|
Ankit Kumar Dwivedi |
d23826 |
node(afterNode).link(onLink).setNext(inserted);
|
|
Ankit Kumar Dwivedi |
d23826 |
}
|
|
Ankit Kumar Dwivedi |
d23826 |
};
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
//********************************
|
|
Ankit Kumar Dwivedi |
d23826 |
//* Polygonization classes *
|
|
Ankit Kumar Dwivedi |
d23826 |
//********************************
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
//--------------------------------------------------------------------------
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
// Of course we don't want RawBorders to be entirely copied whenever STL
|
|
Ankit Kumar Dwivedi |
d23826 |
// requires to resize a BorderFamily...
|
|
Ankit Kumar Dwivedi |
d23826 |
class RawBorder;
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
typedef std::vector<rawborder *=""> BorderFamily;</rawborder>
|
|
Ankit Kumar Dwivedi |
d23826 |
typedef std::vector<borderfamily> BorderList;</borderfamily>
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
//--------------------------------------------------------------------------
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
20f538 |
class ContourEdge;
|
|
Ankit Kumar Dwivedi |
20f538 |
|
|
Ankit Kumar Dwivedi |
20f538 |
// NOTE: The following class is mainly used in the later 'straight skeleton
|
|
Ankit Kumar Dwivedi |
20f538 |
// computation'
|
|
Ankit Kumar Dwivedi |
20f538 |
// - for polygonization purposes, consider it like a TPointD class.
|
|
Ankit Kumar Dwivedi |
20f538 |
|
|
Ankit Kumar Dwivedi |
20f538 |
class ContourNode {
|
|
Ankit Kumar Dwivedi |
20f538 |
public:
|
|
Ankit Kumar Dwivedi |
20f538 |
enum Attributes //! Node attributes
|
|
Ankit Kumar Dwivedi |
20f538 |
{ HEAD = 0x1, //!< Node is the 'first' of a nodes ring.
|
|
Ankit Kumar Dwivedi |
20f538 |
ELIMINATED = 0x4, //!< Node was eliminated by the SS process.
|
|
Ankit Kumar Dwivedi |
20f538 |
SK_NODE_DROPPED = 0x8,
|
|
Ankit Kumar Dwivedi |
20f538 |
AMBIGUOUS_LEFT = 0x10, //!< Node represents an ambiguous \a left turn in
|
|
Ankit Kumar Dwivedi |
20f538 |
//! the original image.
|
|
Ankit Kumar Dwivedi |
20f538 |
AMBIGUOUS_RIGHT = 0x20, //!< Node represents an ambiguous \a right turn in
|
|
Ankit Kumar Dwivedi |
20f538 |
//! the original image.
|
|
Ankit Kumar Dwivedi |
20f538 |
JR_RESERVED = 0x40, //!< Reserved for joints recovery.
|
|
Ankit Kumar Dwivedi |
20f538 |
LINEAR_ADDED = 0x80 //!< Node was added by the linear skeleton technique.
|
|
Ankit Kumar Dwivedi |
20f538 |
};
|
|
Ankit Kumar Dwivedi |
20f538 |
|
|
Ankit Kumar Dwivedi |
20f538 |
public:
|
|
Ankit Kumar Dwivedi |
20f538 |
// Node kinematics infos
|
|
Ankit Kumar Dwivedi |
0944d7 |
synfig::Point3 m_position, //!< Node's position.
|
|
Ankit Kumar Dwivedi |
20f538 |
m_direction, //!< Node's direction.
|
|
Ankit Kumar Dwivedi |
20f538 |
m_AngularMomentum, //!< Angular momentum with the next node's edge.
|
|
Ankit Kumar Dwivedi |
20f538 |
m_AuxiliaryMomentum1, // Used only when this vertex is convex
|
|
Ankit Kumar Dwivedi |
20f538 |
m_AuxiliaryMomentum2; // Used only when this vertex is convex
|
|
Ankit Kumar Dwivedi |
20f538 |
|
|
Ankit Kumar Dwivedi |
20f538 |
// Further node properties
|
|
Ankit Kumar Dwivedi |
20f538 |
bool m_concave; //!< Whether the node represents a concave angle.
|
|
Ankit Kumar Dwivedi |
20f538 |
unsigned int m_attributes, //!< Bitwise signatures of this node
|
|
luz.paz |
7040b8 |
m_updateTime, //!< \a Algorithmic time in which the node was updated.
|
|
Ankit Kumar Dwivedi |
20f538 |
m_ancestor, //!< Index of the original node from which this one evolved.
|
|
Ankit Kumar Dwivedi |
20f538 |
m_ancestorContour; //!< Contour index of the original node from which
|
|
Ankit Kumar Dwivedi |
20f538 |
//! this one evolved.
|
|
Ankit Kumar Dwivedi |
20f538 |
std::vector<contouredge *=""> m_notOpposites; //!< List of edges \a not to be</contouredge>
|
|
Ankit Kumar Dwivedi |
20f538 |
//! used as possible opposites.
|
|
Ankit Kumar Dwivedi |
20f538 |
int m_outputNode; //!< Skeleton node produced by this ContourNode.
|
|
Ankit Kumar Dwivedi |
20f538 |
|
|
Ankit Kumar Dwivedi |
20f538 |
// Connective data
|
|
Ankit Kumar Dwivedi |
20f538 |
ContourEdge *m_edge; //!< Edge departing from this, keeping adjacent black
|
|
Ankit Kumar Dwivedi |
20f538 |
//! region on the right
|
|
Ankit Kumar Dwivedi |
20f538 |
// Node neighbours
|
|
Ankit Kumar Dwivedi |
20f538 |
ContourNode *m_next; //!< Next node on the contour.
|
|
Ankit Kumar Dwivedi |
20f538 |
ContourNode *m_prev; //!< Previous node on the contour.
|
|
Ankit Kumar Dwivedi |
20f538 |
|
|
Ankit Kumar Dwivedi |
20f538 |
public:
|
|
Ankit Kumar Dwivedi |
20f538 |
ContourNode() : m_attributes(0) {}
|
|
Ankit Kumar Dwivedi |
20f538 |
ContourNode(double x, double y) : m_position(x, y, 0), m_attributes(0) {}
|
|
Ankit Kumar Dwivedi |
0944d7 |
ContourNode(const synfig::Point &P) : m_position(P[0], P[1], 0), m_attributes(0) {}
|
|
Ankit Kumar Dwivedi |
20f538 |
ContourNode(double x, double y, unsigned short attrib)
|
|
Ankit Kumar Dwivedi |
20f538 |
: m_position(x, y, 0), m_attributes(attrib) {}
|
|
Ankit Kumar Dwivedi |
20f538 |
|
|
Ankit Kumar Dwivedi |
20f538 |
int hasAttribute(int attr) const { return m_attributes & attr; }
|
|
Ankit Kumar Dwivedi |
20f538 |
void setAttribute(int attr) { m_attributes |= attr; }
|
|
Ankit Kumar Dwivedi |
20f538 |
void clearAttribute(int attr) { m_attributes &= ~attr; }
|
|
Ankit Kumar Dwivedi |
20f538 |
|
|
Ankit Kumar Dwivedi |
20f538 |
public:
|
|
Ankit Kumar Dwivedi |
20f538 |
// Private Node Methods
|
|
Ankit Kumar Dwivedi |
20f538 |
inline void buildNodeInfos(bool forceConvex = false);
|
|
Ankit Kumar Dwivedi |
20f538 |
};
|
|
Ankit Kumar Dwivedi |
20f538 |
|
|
Ankit Kumar Dwivedi |
20f538 |
//--------------------------------------------------------------------------
|
|
Ankit Kumar Dwivedi |
20f538 |
// basically creating 1D, 2D and 3D matrix of ContourNode
|
|
Ankit Kumar Dwivedi |
20f538 |
// 1D matrix being called Contour
|
|
Ankit Kumar Dwivedi |
20f538 |
// 2D matrix is ContourFamily and
|
|
Ankit Kumar Dwivedi |
20f538 |
// 3D is Contours
|
|
Ankit Kumar Dwivedi |
20f538 |
typedef std::vector<contournode> Contour;</contournode>
|
|
Ankit Kumar Dwivedi |
20f538 |
typedef std::vector<contour> ContourFamily;</contour>
|
|
Ankit Kumar Dwivedi |
20f538 |
typedef std::vector<contourfamily> Contours;</contourfamily>
|
|
Ankit Kumar Dwivedi |
d23826 |
//-----------------------------------
|
|
Ankit Kumar Dwivedi |
d23826 |
// Straight Skeleton Classes
|
|
Ankit Kumar Dwivedi |
d23826 |
//-----------------------------------
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
class SkeletonArc {
|
|
Ankit Kumar Dwivedi |
d23826 |
double m_slope;
|
|
Ankit Kumar Dwivedi |
d23826 |
unsigned int m_leftGeneratingNode, m_leftContour, m_rightGeneratingNode,
|
|
Ankit Kumar Dwivedi |
d23826 |
m_rightContour;
|
|
Ankit Kumar Dwivedi |
d23826 |
int m_attributes;
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
// NOTE: Typically an arc is generated by a couple of *edges* of the original
|
|
Ankit Kumar Dwivedi |
d23826 |
// contours; but we store instead the *nodes* which address those
|
|
Ankit Kumar Dwivedi |
d23826 |
// edges.
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
public:
|
|
Ankit Kumar Dwivedi |
d23826 |
SkeletonArc() : m_attributes(0) {}
|
|
Ankit Kumar Dwivedi |
d23826 |
SkeletonArc(ContourNode *node)
|
|
Ankit Kumar Dwivedi |
7bae86 |
: m_slope(node->m_direction[2])
|
|
Ankit Kumar Dwivedi |
d23826 |
, m_leftGeneratingNode(node->m_ancestor)
|
|
Ankit Kumar Dwivedi |
d23826 |
, m_leftContour(node->m_ancestorContour)
|
|
Ankit Kumar Dwivedi |
d23826 |
, m_rightGeneratingNode(node->m_prev->m_ancestor)
|
|
Ankit Kumar Dwivedi |
d23826 |
, m_rightContour(node->m_prev->m_ancestorContour)
|
|
Ankit Kumar Dwivedi |
d23826 |
, m_attributes(0) {}
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
enum { ROAD = 0x1 };
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
double getSlope() const { return m_slope; }
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
unsigned int getLeftGenerator() const { return m_leftGeneratingNode; }
|
|
Ankit Kumar Dwivedi |
d23826 |
unsigned int getRightGenerator() const { return m_rightGeneratingNode; }
|
|
Ankit Kumar Dwivedi |
d23826 |
unsigned int getLeftContour() const { return m_leftContour; }
|
|
Ankit Kumar Dwivedi |
d23826 |
unsigned int getRightContour() const { return m_rightContour; }
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
enum { SS_OUTLINE = 0x10, SS_OUTLINE_REVERSED = 0x20 };
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
int hasAttribute(int attr) const { return m_attributes & attr; }
|
|
Ankit Kumar Dwivedi |
d23826 |
void setAttribute(int attr) { m_attributes |= attr; }
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
void turn() {
|
|
Ankit Kumar Dwivedi |
d23826 |
m_slope = -m_slope;
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
std::swap(m_leftGeneratingNode, m_rightGeneratingNode);
|
|
Ankit Kumar Dwivedi |
d23826 |
std::swap(m_leftContour, m_rightContour);
|
|
Ankit Kumar Dwivedi |
d23826 |
}
|
|
Ankit Kumar Dwivedi |
d23826 |
};
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
//--------------------------------------------------------------------------
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
typedef Graph<synfig::point3, skeletonarc=""> SkeletonGraph;</synfig::point3,>
|
|
Ankit Kumar Dwivedi |
d23826 |
typedef std::vector<skeletongraph *=""> SkeletonList;</skeletongraph>
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
d23826 |
//==========================================================================
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
a86e26 |
//----------------------------------------
|
|
Ankit Kumar Dwivedi |
a86e26 |
// Joints and Sequences definition
|
|
Ankit Kumar Dwivedi |
a86e26 |
//----------------------------------------
|
|
Ankit Kumar Dwivedi |
a86e26 |
|
|
Ankit Kumar Dwivedi |
a86e26 |
class Sequence
|
|
Ankit Kumar Dwivedi |
a86e26 |
{
|
|
Ankit Kumar Dwivedi |
a86e26 |
public:
|
|
Ankit Kumar Dwivedi |
a86e26 |
UINT m_head;
|
|
Ankit Kumar Dwivedi |
a86e26 |
UINT m_headLink;
|
|
Ankit Kumar Dwivedi |
a86e26 |
UINT m_tail;
|
|
Ankit Kumar Dwivedi |
a86e26 |
UINT m_tailLink;
|
|
Ankit Kumar Dwivedi |
a86e26 |
SkeletonGraph *m_graphHolder;
|
|
Ankit Kumar Dwivedi |
a86e26 |
|
|
Ankit Kumar Dwivedi |
a86e26 |
// Stroke color-sensible data
|
|
Ankit Kumar Dwivedi |
d93397 |
synfig::Color m_color;
|
|
Ankit Kumar Dwivedi |
a86e26 |
int m_strokeIndex;
|
|
Ankit Kumar Dwivedi |
a86e26 |
int m_strokeHeight;
|
|
Ankit Kumar Dwivedi |
a86e26 |
|
|
Ankit Kumar Dwivedi |
a86e26 |
public:
|
|
Ankit Kumar Dwivedi |
a86e26 |
Sequence() : m_graphHolder(0) {}
|
|
Ankit Kumar Dwivedi |
a86e26 |
~Sequence() {}
|
|
Ankit Kumar Dwivedi |
a86e26 |
|
|
luz.paz |
7040b8 |
// Impose a property dependent only on the extremity we consider first
|
|
Ankit Kumar Dwivedi |
a86e26 |
// - so that the same sequence is not considered twice when head and tail
|
|
Ankit Kumar Dwivedi |
a86e26 |
// are exchanged
|
|
Ankit Kumar Dwivedi |
a86e26 |
bool isForward() const
|
|
Ankit Kumar Dwivedi |
a86e26 |
{
|
|
Ankit Kumar Dwivedi |
a86e26 |
return (m_head < m_tail) || (m_head == m_tail && m_headLink < m_tailLink);
|
|
Ankit Kumar Dwivedi |
a86e26 |
}
|
|
Ankit Kumar Dwivedi |
a86e26 |
|
|
Ankit Kumar Dwivedi |
a86e26 |
// Advances a couple (old, current) of sequence nodes
|
|
Ankit Kumar Dwivedi |
a86e26 |
void advance(UINT &old, UINT ¤t) const
|
|
Ankit Kumar Dwivedi |
a86e26 |
{
|
|
Ankit Kumar Dwivedi |
a86e26 |
UINT temp = current;
|
|
Ankit Kumar Dwivedi |
a86e26 |
current = m_graphHolder->getNode(current).getLink(0).getNext() == old
|
|
Ankit Kumar Dwivedi |
a86e26 |
? m_graphHolder->getNode(current).getLink(1).getNext()
|
|
Ankit Kumar Dwivedi |
a86e26 |
: m_graphHolder->getNode(current).getLink(0).getNext();
|
|
Ankit Kumar Dwivedi |
a86e26 |
old = temp;
|
|
Ankit Kumar Dwivedi |
a86e26 |
}
|
|
Ankit Kumar Dwivedi |
a86e26 |
|
|
Ankit Kumar Dwivedi |
a86e26 |
// Advances a couple (current, link) of a sequence node plus its link
|
|
Ankit Kumar Dwivedi |
a86e26 |
// direction
|
|
Ankit Kumar Dwivedi |
a86e26 |
void next(UINT ¤t, UINT &link) const
|
|
Ankit Kumar Dwivedi |
a86e26 |
{
|
|
Ankit Kumar Dwivedi |
a86e26 |
UINT temp = current;
|
|
Ankit Kumar Dwivedi |
a86e26 |
current = m_graphHolder->getNode(current).getLink(link).getNext();
|
|
Ankit Kumar Dwivedi |
a86e26 |
link = m_graphHolder->getNode(current).getLink(0).getNext() == temp ? 1 : 0;
|
|
Ankit Kumar Dwivedi |
a86e26 |
}
|
|
Ankit Kumar Dwivedi |
a86e26 |
};
|
|
Ankit Kumar Dwivedi |
a86e26 |
|
|
Ankit Kumar Dwivedi |
a86e26 |
//--------------------------------------------------------------------------
|
|
Ankit Kumar Dwivedi |
a86e26 |
|
|
Ankit Kumar Dwivedi |
a86e26 |
class JointSequenceGraph final : public Graph<uint, sequence=""> {</uint,>
|
|
Ankit Kumar Dwivedi |
a86e26 |
public:
|
|
Ankit Kumar Dwivedi |
a86e26 |
JointSequenceGraph() {}
|
|
Ankit Kumar Dwivedi |
a86e26 |
~JointSequenceGraph() {}
|
|
Ankit Kumar Dwivedi |
a86e26 |
|
|
Ankit Kumar Dwivedi |
a86e26 |
enum { REACHED = 0x1, ELIMINATED = 0x2 };
|
|
Ankit Kumar Dwivedi |
a86e26 |
|
|
Ankit Kumar Dwivedi |
a86e26 |
// Extracts JSG tail link of input node-link
|
|
Ankit Kumar Dwivedi |
a86e26 |
inline UINT tailLinkOf(UINT node, UINT link)
|
|
Ankit Kumar Dwivedi |
a86e26 |
{
|
|
Ankit Kumar Dwivedi |
a86e26 |
UINT i, next = getNode(node).getLink(link).getNext();
|
|
Ankit Kumar Dwivedi |
a86e26 |
|
|
Ankit Kumar Dwivedi |
a86e26 |
for (i = 0; getNode(next).getLink(i)->m_tail !=
|
|
Ankit Kumar Dwivedi |
a86e26 |
getNode(node).getLink(link)->m_head ||
|
|
Ankit Kumar Dwivedi |
a86e26 |
getNode(next).getLink(i)->m_tailLink !=
|
|
Ankit Kumar Dwivedi |
a86e26 |
getNode(node).getLink(link)->m_headLink;
|
|
Ankit Kumar Dwivedi |
a86e26 |
++i)
|
|
Ankit Kumar Dwivedi |
a86e26 |
;
|
|
Ankit Kumar Dwivedi |
a86e26 |
return i;
|
|
Ankit Kumar Dwivedi |
a86e26 |
}
|
|
Ankit Kumar Dwivedi |
a86e26 |
};
|
|
Ankit Kumar Dwivedi |
a86e26 |
|
|
Ankit Kumar Dwivedi |
a86e26 |
typedef std::vector<jointsequencegraph> JointSequenceGraphList;</jointsequencegraph>
|
|
Ankit Kumar Dwivedi |
a86e26 |
|
|
Ankit Kumar Dwivedi |
a86e26 |
typedef std::vector<sequence> SequenceList;</sequence>
|
|
Ankit Kumar Dwivedi |
a86e26 |
typedef std::vector<synfig::point3> PointList;</synfig::point3>
|
|
Ankit Kumar Dwivedi |
a86e26 |
|
|
Ankit Kumar Dwivedi |
a86e26 |
|
|
Ankit Kumar Dwivedi |
a86e26 |
//==========================================================================
|
|
Ankit Kumar Dwivedi |
a86e26 |
|
|
Ankit Kumar Dwivedi |
d23826 |
|
|
Ankit Kumar Dwivedi |
ba802f |
|
|
Ankit Kumar Dwivedi |
0944d7 |
class VectorizerCoreGlobals {
|
|
Ankit Kumar Dwivedi |
0944d7 |
public:
|
|
Ankit Kumar Dwivedi |
0944d7 |
const CenterlineConfiguration *currConfig;
|
|
Ankit Kumar Dwivedi |
0944d7 |
|
|
Ankit Kumar Dwivedi |
a86e26 |
JointSequenceGraphList organizedGraphs;
|
|
Ankit Kumar Dwivedi |
a86e26 |
SequenceList singleSequences;
|
|
Ankit Kumar Dwivedi |
a86e26 |
PointList singlePoints;
|
|
Ankit Kumar Dwivedi |
0944d7 |
|
|
Ankit Kumar Dwivedi |
0944d7 |
VectorizerCoreGlobals() {}
|
|
Ankit Kumar Dwivedi |
0944d7 |
~VectorizerCoreGlobals() {}
|
|
Ankit Kumar Dwivedi |
0944d7 |
};
|
|
Ankit Kumar Dwivedi |
0944d7 |
|
|
Ankit Kumar Dwivedi |
0944d7 |
namespace {
|
|
Ankit Kumar Dwivedi |
0944d7 |
// SkeletonGraph nodes global signatures - used for various purposes
|
|
Ankit Kumar Dwivedi |
0944d7 |
enum {
|
|
Ankit Kumar Dwivedi |
0944d7 |
ORGANIZEGRAPHS_SIGN = 0x10,
|
|
Ankit Kumar Dwivedi |
0944d7 |
SAMPLECOLOR_SIGN = 0x20,
|
|
Ankit Kumar Dwivedi |
0944d7 |
COLORORDERING_SIGN = 0x40
|
|
Ankit Kumar Dwivedi |
0944d7 |
};
|
|
Ankit Kumar Dwivedi |
0944d7 |
const int infinity = 1000000; // just a great enough number
|
|
Ankit Kumar Dwivedi |
0944d7 |
};
|
|
Ankit Kumar Dwivedi |
0944d7 |
|
|
Ankit Kumar Dwivedi |
0944d7 |
//--------------------------------------------------------------------------
|
|
Ankit Kumar Dwivedi |
0944d7 |
|
|
Ankit Kumar Dwivedi |
0944d7 |
//===============================
|
|
Ankit Kumar Dwivedi |
0944d7 |
// Function prototypes
|
|
Ankit Kumar Dwivedi |
0944d7 |
//===============================
|
|
Ankit Kumar Dwivedi |
0944d7 |
|
|
Ankit Kumar Dwivedi |
0944d7 |
void polygonize(const etl::handle<synfig::layer_bitmap> &ras, Contours &polygons,VectorizerCoreGlobals &g);</synfig::layer_bitmap>
|
|
Ankit Kumar Dwivedi |
0944d7 |
|
|
ankit-kumar-dwivedi |
490fa8 |
SkeletonList *skeletonize(Contours &contours,const etl::handle<synfigapp::uiinterface> &ui_interface, VectorizerCoreGlobals &g);</synfigapp::uiinterface>
|
|
Ankit Kumar Dwivedi |
0944d7 |
|
|
Ankit Kumar Dwivedi |
d388d7 |
void organizeGraphs(SkeletonList *skeleton, VectorizerCoreGlobals &g);
|
|
Ankit Kumar Dwivedi |
0944d7 |
|
|
Ankit Kumar Dwivedi |
0944d7 |
// void junctionRecovery(Contours *polygons, VectorizerCoreGlobals &g);
|
|
Ankit Kumar Dwivedi |
0944d7 |
|
|
|
1387de |
void conversionToStrokes(std::vector< etl::handle<synfig::layer> > &strokes, VectorizerCoreGlobals &g, const etl::handle<synfig::layer_bitmap> &image) ;</synfig::layer_bitmap></synfig::layer>
|
|
Ankit Kumar Dwivedi |
0944d7 |
|
|
|
a4bbdd |
void calculateSequenceColors(const etl::handle<synfig::layer_bitmap> &ras, VectorizerCoreGlobals &g, const synfig::Gamma &gamma);</synfig::layer_bitmap>
|
|
Ankit Kumar Dwivedi |
0944d7 |
|
|
Ankit Kumar Dwivedi |
0944d7 |
// void applyStrokeColors(std::vector<tstroke *=""> &strokes, const TRasterP &ras,</tstroke>
|
|
Ankit Kumar Dwivedi |
0944d7 |
// TPalette *palette, VectorizerCoreGlobals &g);
|
|
Ankit Kumar Dwivedi |
0944d7 |
|
|
Ankit Kumar Dwivedi |
0944d7 |
|
|
Ankit Kumar Dwivedi |
ba802f |
}; // END of namespace studio
|
|
Ankit Kumar Dwivedi |
ba802f |
|
|
Ankit Kumar Dwivedi |
ba802f |
/* === E N D =============================================================== */
|
|
|
d20d89 |
|
|
|
d20d89 |
#endif
|