Qt 4.8
Classes | Public Types | Public Functions | Properties | Friends | List of all members
QTriangulator< T > Class Template Reference

Classes

class  ComplexToSimple
 
class  MonotoneToTriangles
 
class  SimpleToMonotone
 

Public Types

typedef QVarLengthArray< int, 6 > ShortArray
 

Public Functions

void initialize (const qreal *polygon, int count, uint hint, const QTransform &matrix)
 
void initialize (const QVectorPath &path, const QTransform &matrix, qreal lod)
 
void initialize (const QPainterPath &path, const QTransform &matrix, qreal lod)
 
QVertexSet< T > polyline ()
 
 QTriangulator ()
 
QVertexSet< T > triangulate ()
 

Properties

uint m_hint
 
QVector< T > m_indices
 
QDataBuffer< QPodPointm_vertices
 

Friends

class ComplexToSimple
 
class MonotoneToTriangles
 
class SimpleToMonotone
 

Detailed Description

template<typename T>
class QTriangulator< T >

Definition at line 1316 of file qtriangulator.cpp.

Typedefs

◆ ShortArray

template<typename T>
typedef QVarLengthArray<int, 6> QTriangulator< T >::ShortArray

Definition at line 1319 of file qtriangulator.cpp.

Constructors and Destructors

◆ QTriangulator()

template<typename T>
QTriangulator< T >::QTriangulator ( )
inline

Definition at line 1516 of file qtriangulator.cpp.

1516 : m_vertices(0) { }
QDataBuffer< QPodPoint > m_vertices

Functions

◆ initialize() [1/3]

template<typename T >
void QTriangulator< T >::initialize ( const qreal polygon,
int  count,
uint  hint,
const QTransform matrix 
)

Definition at line 1581 of file qtriangulator.cpp.

Referenced by qPolyline(), and qTriangulate().

1582 {
1583  m_hint = hint;
1584  m_vertices.resize(count);
1585  m_indices.resize(count + 1);
1586  for (int i = 0; i < count; ++i) {
1587  qreal x, y;
1588  matrix.map(polygon[2 * i + 0], polygon[2 * i + 1], &x, &y);
1591  m_indices[i] = i;
1592  }
1593  m_indices[count] = T(-1); //Q_TRIANGULATE_END_OF_POLYGON
1594 }
double qreal
Definition: qglobal.h:1193
void resize(int size)
#define Q_FIXED_POINT_SCALE
QVector< T > m_indices
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
Type & at(int i)
Definition: qdatabuffer_p.h:86
QDataBuffer< QPodPoint > m_vertices
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ initialize() [2/3]

template<typename T >
void QTriangulator< T >::initialize ( const QVectorPath path,
const QTransform matrix,
qreal  lod 
)

Definition at line 1597 of file qtriangulator.cpp.

1598 {
1599  m_hint = path.hints();
1600  // Curved paths will be converted to complex polygons.
1601  m_hint &= ~QVectorPath::CurvedShapeMask;
1602 
1603  const qreal *p = path.points();
1604  const QPainterPath::ElementType *e = path.elements();
1605  if (e) {
1606  for (int i = 0; i < path.elementCount(); ++i, ++e, p += 2) {
1607  switch (*e) {
1609  if (!m_indices.isEmpty())
1610  m_indices.push_back(T(-1)); // Q_TRIANGULATE_END_OF_POLYGON
1611  // Fall through.
1613  m_indices.push_back(T(m_vertices.size()));
1615  qreal x, y;
1616  matrix.map(p[0], p[1], &x, &y);
1619  break;
1621  {
1622  qreal pts[8];
1623  for (int i = 0; i < 4; ++i)
1624  matrix.map(p[2 * i - 2], p[2 * i - 1], &pts[2 * i + 0], &pts[2 * i + 1]);
1625  for (int i = 0; i < 8; ++i)
1626  pts[i] *= lod;
1627  QBezier bezier = QBezier::fromPoints(QPointF(pts[0], pts[1]), QPointF(pts[2], pts[3]), QPointF(pts[4], pts[5]), QPointF(pts[6], pts[7]));
1628  QPolygonF poly = bezier.toPolygon();
1629  // Skip first point, it already exists in 'm_vertices'.
1630  for (int j = 1; j < poly.size(); ++j) {
1631  m_indices.push_back(T(m_vertices.size()));
1633  m_vertices.last().x = qRound(poly.at(j).x() * Q_FIXED_POINT_SCALE / lod);
1634  m_vertices.last().y = qRound(poly.at(j).y() * Q_FIXED_POINT_SCALE / lod);
1635  }
1636  }
1637  i += 2;
1638  e += 2;
1639  p += 4;
1640  break;
1641  default:
1642  Q_ASSERT_X(0, "QTriangulator::triangulate", "Unexpected element type.");
1643  break;
1644  }
1645  }
1646  } else {
1647  for (int i = 0; i < path.elementCount(); ++i, p += 2) {
1648  m_indices.push_back(T(m_vertices.size()));
1650  qreal x, y;
1651  matrix.map(p[0], p[1], &x, &y);
1654  }
1655  }
1656  m_indices.push_back(T(-1)); // Q_TRIANGULATE_END_OF_POLYGON
1657 }
ElementType
This enum describes the types of elements used to connect vertices in subpaths.
Definition: qpainterpath.h:70
double qreal
Definition: qglobal.h:1193
int elementCount() const
void resize(int size)
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_FIXED_POINT_SCALE
QVector< T > m_indices
const QPainterPath::ElementType * elements() const
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
static QBezier fromPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
Definition: qbezier.cpp:71
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
uint hints() const
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QPolygonF toPolygon(qreal bezier_flattening_threshold=0.5) const
Definition: qbezier.cpp:89
Type & last()
Definition: qdatabuffer_p.h:88
const qreal * points() const
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QDataBuffer< QPodPoint > m_vertices
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
int size() const
Definition: qdatabuffer_p.h:83

◆ initialize() [3/3]

template<typename T >
void QTriangulator< T >::initialize ( const QPainterPath path,
const QTransform matrix,
qreal  lod 
)

Definition at line 1660 of file qtriangulator.cpp.

1661 {
1662  initialize(qtVectorPathForPath(path), matrix, lod);
1663 }
const QVectorPath & qtVectorPathForPath(const QPainterPath &path)
void initialize(const qreal *polygon, int count, uint hint, const QTransform &matrix)

◆ polyline()

template<typename T >
QVertexSet< T > QTriangulator< T >::polyline ( )

Definition at line 1568 of file qtriangulator.cpp.

Referenced by qPolyline().

1569 {
1570  QVertexSet<T> result;
1571  result.indices = m_indices;
1572  result.vertices.resize(2 * m_vertices.size());
1573  for (int i = 0; i < m_vertices.size(); ++i) {
1574  result.vertices[2 * i + 0] = qreal(m_vertices.at(i).x) / Q_FIXED_POINT_SCALE;
1575  result.vertices[2 * i + 1] = qreal(m_vertices.at(i).y) / Q_FIXED_POINT_SCALE;
1576  }
1577  return result;
1578 }
double qreal
Definition: qglobal.h:1193
QVector< qreal > vertices
#define Q_FIXED_POINT_SCALE
QVector< T > m_indices
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
Type & at(int i)
Definition: qdatabuffer_p.h:86
QDataBuffer< QPodPoint > m_vertices
QVector< T > indices
int size() const
Definition: qdatabuffer_p.h:83

◆ triangulate()

template<typename T >
QVertexSet< T > QTriangulator< T >::triangulate ( )

Definition at line 1538 of file qtriangulator.cpp.

Referenced by qPolyline(), and qTriangulate().

1539 {
1540  for (int i = 0; i < m_vertices.size(); ++i) {
1541  Q_ASSERT(qAbs(m_vertices.at(i).x) < (1 << 21));
1542  Q_ASSERT(qAbs(m_vertices.at(i).y) < (1 << 21));
1543  }
1544 
1547 
1549  ComplexToSimple c2s(this);
1550  c2s.decompose();
1551  SimpleToMonotone s2m(this);
1552  s2m.decompose();
1553  }
1554  MonotoneToTriangles m2t(this);
1555  m2t.decompose();
1556 
1557  QVertexSet<T> result;
1558  result.indices = m_indices;
1559  result.vertices.resize(2 * m_vertices.size());
1560  for (int i = 0; i < m_vertices.size(); ++i) {
1561  result.vertices[2 * i + 0] = qreal(m_vertices.at(i).x) / Q_FIXED_POINT_SCALE;
1562  result.vertices[2 * i + 1] = qreal(m_vertices.at(i).y) / Q_FIXED_POINT_SCALE;
1563  }
1564  return result;
1565 }
double qreal
Definition: qglobal.h:1193
friend class SimpleToMonotone
QVector< qreal > vertices
#define Q_FIXED_POINT_SCALE
QVector< T > m_indices
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
Type & at(int i)
Definition: qdatabuffer_p.h:86
friend class ComplexToSimple
friend class MonotoneToTriangles
QDataBuffer< QPodPoint > m_vertices
QVector< T > indices
int size() const
Definition: qdatabuffer_p.h:83

Friends and Related Functions

◆ ComplexToSimple

template<typename T>
friend class ComplexToSimple
friend

Definition at line 1324 of file qtriangulator.cpp.

◆ MonotoneToTriangles

template<typename T>
friend class MonotoneToTriangles
friend

Definition at line 1494 of file qtriangulator.cpp.

◆ SimpleToMonotone

template<typename T>
friend class SimpleToMonotone
friend

Definition at line 1438 of file qtriangulator.cpp.

Properties

◆ m_hint

template<typename T>
uint QTriangulator< T >::m_hint
private

Definition at line 1530 of file qtriangulator.cpp.

◆ m_indices

template<typename T>
QVector<T> QTriangulator< T >::m_indices
private

Definition at line 1529 of file qtriangulator.cpp.

◆ m_vertices

template<typename T>
QDataBuffer<QPodPoint> QTriangulator< T >::m_vertices
private

Definition at line 1528 of file qtriangulator.cpp.


The documentation for this class was generated from the following file: