37 template <
class VertexVector,
class Polygon>
55 template <
class TriangleList>
60 typedef typename VertexVector::value_type Vector;
62 Vector eval_orientation(
const Polygon& poly)
const;
67 const typename VertexVector::value_type& a,
68 const typename VertexVector::value_type& b,
69 const typename VertexVector::value_type& c,
70 const typename VertexVector::value_type& p,
71 bool debug =
false )
const;
74 const VertexVector& m_vv;
75 mutable Vector m_orientation;
78 template <
class VertexVector,
class Polygon>
84 template <
class VertexVector,
class Polygon>
85 template <
class TriangleList>
89 size_t poly_size = poly.size();
98 m_orientation = eval_orientation(poly);
100 typename Polygon::const_iterator pi = poly.begin();
101 typename Polygon::const_iterator pe = poly.end();
111 while ( (p_i != p_e) && (poly_size > 3)) {
112 if (is_ear(p_i, cpoly,
false)) {
114 output.push_back(
typename TriangleList::value_type(**p_i->
succ, **p_i, **p_i->
prev));
126 if ((p_i == p_e) && (poly_size > 3)) {
133 while ( (p_i != p_e) && (poly_size > 3)) {
135 if (is_ear(p_i, cpoly,
true)) {
137 output.push_back(
typename TriangleList::value_type(**p_i->
succ, **p_i, **p_i->
prev));
150 output.push_back(
typename TriangleList::value_type(**p_i->
succ, **p_i, **p_i->
prev));
158 template <
class VertexVector,
class Polygon>
159 typename TPolyTriangulator<VertexVector,Polygon>::Vector
162 typename VertexVector::value_type result(0,0,0);
164 typename Polygon::const_iterator pb = poly.begin();
165 typename Polygon::const_iterator be = poly.end();
167 typename Polygon::const_iterator c1 = pb;
170 typename Polygon::const_iterator c2 = c1;
173 typename VertexVector::value_type a = m_vv[*pb];
175 while (c1 != be && c2 != be) {
176 result += (m_vv[*c1++] - a) ^ (m_vv[*c2++] - a);
182 template <
class VertexVector,
class Polygon>
185 typename VertexVector::value_type a = m_vv[**i->
prev];
186 typename VertexVector::value_type b = m_vv[**i];
187 typename VertexVector::value_type c = m_vv[**i->
succ];
189 typename VertexVector::value_type ab = a - b;
190 typename VertexVector::value_type cb = c - b;
192 typename VertexVector::value_type
cross = ab ^ cb;
194 const bool result =
dot(cross, m_orientation) > 0;
200 template <
class VertexVector,
class Polygon>
203 if (!is_convex(p,debug)) {
204 cvdebug() <<
"corner is concave\n";
208 typename VertexVector::value_type a = m_vv[**p->
prev];
209 typename VertexVector::value_type b = m_vv[**p];
210 typename VertexVector::value_type c = m_vv[**p->
succ];
212 cvdebug() <<
"check triangle" << a << b << c <<
" = (" << **p->
prev <<
"," << **p <<
"," << **p->
succ <<
"\n";
217 while (i != cpoly.
end()) {
218 if (i != p && i != p->
prev && i != p->
succ)
219 if (!is_convex(i, debug) && is_inside(a,b,c,m_vv[**i], debug)) {
220 cvdebug() <<
"point " << **i <<
":" << m_vv[**i] <<
" is concave and inside\n";
230 template <
class VertexVector,
class Polygon>
232 const typename VertexVector::value_type& a,
233 const typename VertexVector::value_type& b,
234 const typename VertexVector::value_type& c,
235 const typename VertexVector::value_type& p,
238 double abc = ((a-b)^(c-b)).norm() * 0.5;
239 double abp = ((a-p)^(b-p)).norm() * 0.5;
240 double acp = ((a-p)^(c-p)).norm() * 0.5;
241 double bcp = ((b-p)^(c-p)).norm() * 0.5;
243 const bool result = (abc >= abp + acp + bcp);
TPolyTriangulator(const VertexVector &vv)
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
T cross(const T2DVector< T > &a, const T2DVector< T > &b)
double EXPORT_GSL dot(const gsl_vector *lhs, const gsl_vector *rhs)
class to make a triangle mesh from a closed polygon
bool triangulate(TriangleList &output, const Polygon &poly) const
#define NS_MIA_END
conveniance define to end the mia namespace