Qt 4.8
Public Functions | Private Functions | Properties | List of all members
QTriangulator< T >::MonotoneToTriangles Class Reference

Public Functions

void decompose ()
 
 MonotoneToTriangles (QTriangulator< T > *parent)
 

Private Functions

indices (int index) const
 
bool leftOfEdge (int i, int j, int k) const
 
bool less (int i, int j) const
 
int next (int index) const
 
int previous (int index) const
 

Properties

int m_first
 
int m_length
 
QTriangulator< T > * m_parent
 

Detailed Description

template<typename T>
class QTriangulator< T >::MonotoneToTriangles

Definition at line 1495 of file qtriangulator.cpp.

Constructors and Destructors

◆ MonotoneToTriangles()

template<typename T>
QTriangulator< T >::MonotoneToTriangles::MonotoneToTriangles ( QTriangulator< T > *  parent)
inline

Definition at line 1498 of file qtriangulator.cpp.

1498 : m_parent(parent) { }

Functions

◆ decompose()

template<typename T >
void QTriangulator< T >::MonotoneToTriangles::decompose ( )

Definition at line 2921 of file qtriangulator.cpp.

Referenced by QTriangulator< T >::triangulate().

2922 {
2923  QVector<T> result;
2924  QDataBuffer<int> stack(m_parent->m_indices.size());
2925  m_first = 0;
2926  // Require at least three more indices.
2927  while (m_first + 3 <= m_parent->m_indices.size()) {
2928  m_length = 0;
2929  while (m_parent->m_indices.at(m_first + m_length) != T(-1)) { // Q_TRIANGULATE_END_OF_POLYGON
2930  ++m_length;
2931  Q_ASSERT(m_first + m_length < m_parent->m_indices.size());
2932  }
2933  if (m_length < 3) {
2934  m_first += m_length + 1;
2935  continue;
2936  }
2937 
2938  int minimum = 0;
2939  while (less(next(minimum), minimum))
2940  minimum = next(minimum);
2941  while (less(previous(minimum), minimum))
2942  minimum = previous(minimum);
2943 
2944  stack.reset();
2945  stack.add(minimum);
2946  int left = previous(minimum);
2947  int right = next(minimum);
2948  bool stackIsOnLeftSide;
2949  bool clockwiseOrder = leftOfEdge(minimum, left, right);
2950 
2951  if (less(left, right)) {
2952  stack.add(left);
2953  left = previous(left);
2954  stackIsOnLeftSide = true;
2955  } else {
2956  stack.add(right);
2957  right = next(right);
2958  stackIsOnLeftSide = false;
2959  }
2960 
2961  for (int count = 0; count + 2 < m_length; ++count)
2962  {
2963  Q_ASSERT(stack.size() >= 2);
2964  if (less(left, right)) {
2965  if (stackIsOnLeftSide == false) {
2966  for (int i = 0; i + 1 < stack.size(); ++i) {
2967  result.push_back(indices(stack.at(i + 1)));
2968  result.push_back(indices(left));
2969  result.push_back(indices(stack.at(i)));
2970  }
2971  stack.first() = stack.last();
2972  stack.resize(1);
2973  } else {
2974  while (stack.size() >= 2 && (clockwiseOrder ^ !leftOfEdge(left, stack.at(stack.size() - 2), stack.last()))) {
2975  result.push_back(indices(stack.at(stack.size() - 2)));
2976  result.push_back(indices(left));
2977  result.push_back(indices(stack.last()));
2978  stack.pop_back();
2979  }
2980  }
2981  stack.add(left);
2982  left = previous(left);
2983  stackIsOnLeftSide = true;
2984  } else {
2985  if (stackIsOnLeftSide == true) {
2986  for (int i = 0; i + 1 < stack.size(); ++i) {
2987  result.push_back(indices(stack.at(i)));
2988  result.push_back(indices(right));
2989  result.push_back(indices(stack.at(i + 1)));
2990  }
2991  stack.first() = stack.last();
2992  stack.resize(1);
2993  } else {
2994  while (stack.size() >= 2 && (clockwiseOrder ^ !leftOfEdge(right, stack.last(), stack.at(stack.size() - 2)))) {
2995  result.push_back(indices(stack.last()));
2996  result.push_back(indices(right));
2997  result.push_back(indices(stack.at(stack.size() - 2)));
2998  stack.pop_back();
2999  }
3000  }
3001  stack.add(right);
3002  right = next(right);
3003  stackIsOnLeftSide = false;
3004  }
3005  }
3006 
3007  m_first += m_length + 1;
3008  }
3009  m_parent->m_indices = result;
3010 }
bool leftOfEdge(int i, int j, int k) const
QVector< T > m_indices
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
void push_back(const T &t)
This function is provided for STL compatibility.
Definition: qvector.h:281
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ indices()

template<typename T>
T QTriangulator< T >::MonotoneToTriangles::indices ( int  index) const
inlineprivate

Definition at line 1501 of file qtriangulator.cpp.

1501 {return m_parent->m_indices.at(index + m_first);}
quint16 index

◆ leftOfEdge()

template<typename T>
bool QTriangulator< T >::MonotoneToTriangles::leftOfEdge ( int  i,
int  j,
int  k 
) const
inlineprivate

Definition at line 1505 of file qtriangulator.cpp.

1506  {
1507  return qPointIsLeftOfLine(m_parent->m_vertices.at((qint32)indices(i)),
1508  m_parent->m_vertices.at((qint32)indices(j)), m_parent->m_vertices.at((qint32)indices(k)));
1509  }
int qint32
Definition: qglobal.h:937
static bool qPointIsLeftOfLine(const QPodPoint &p, const QPodPoint &v1, const QPodPoint &v2)

◆ less()

template<typename T>
bool QTriangulator< T >::MonotoneToTriangles::less ( int  i,
int  j 
) const
inlineprivate

Definition at line 1504 of file qtriangulator.cpp.

1504 {return m_parent->m_vertices.at((qint32)indices(i)) < m_parent->m_vertices.at(indices(j));}
int qint32
Definition: qglobal.h:937

◆ next()

template<typename T>
int QTriangulator< T >::MonotoneToTriangles::next ( int  index) const
inlineprivate

Definition at line 1502 of file qtriangulator.cpp.

1502 {return (index + 1) % m_length;}
quint16 index

◆ previous()

template<typename T>
int QTriangulator< T >::MonotoneToTriangles::previous ( int  index) const
inlineprivate

Definition at line 1503 of file qtriangulator.cpp.

1503 {return (index + m_length - 1) % m_length;}
quint16 index

Properties

◆ m_first

template<typename T>
int QTriangulator< T >::MonotoneToTriangles::m_first
private

Definition at line 1512 of file qtriangulator.cpp.

◆ m_length

template<typename T>
int QTriangulator< T >::MonotoneToTriangles::m_length
private

Definition at line 1513 of file qtriangulator.cpp.

◆ m_parent

template<typename T>
QTriangulator<T>* QTriangulator< T >::MonotoneToTriangles::m_parent
private

Definition at line 1511 of file qtriangulator.cpp.


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