示例#1
0
    bool isEar(int u, int v, int w, const std::vector<uint32_t>& vertices)
    {
        PointXY p_u = toPointXY(points_.points[vertices[u]]);
        PointXY p_v = toPointXY(points_.points[vertices[v]]);
        PointXY p_w = toPointXY(points_.points[vertices[w]]);

        // Avoid flat triangles.
        // FIXME: what happens if all the triangles are flat in the X-Y axis?
        const float eps = 1e-15;
        PointXY p_uv = difference(p_v, p_u);
        PointXY p_uw = difference(p_w, p_u);
        if (crossProduct(p_uv, p_uw) < eps)
        {
            ntk_dbg(1) << cv::format("FLAT: (%d, %d, %d)", u, v, w);
            return false;
        }

        // Check if any other vertex is inside the triangle.
        for (int k = 0; k < vertices.size(); k++)
        {
            if ((k == u) || (k == v) || (k == w))
                continue;
            PointXY p = toPointXY(points_.points[vertices[k]]);
            if (isInsideTriangle(p_u, p_v, p_w, p))
                return false;
        }
        return true;
    }
void LodOutsideMarker::getVisibleTriangles( const CHVertex* target, CHTrianglePList& visibleTriangles )
{

    CHTriangleList::iterator it = mHull.begin();
    CHTriangleList::iterator itEnd = mHull.end();
    for (; it != itEnd; it++) {
        if (it->removed) {
            continue;
        }
        Real dot1 = it->normal.dotProduct(it->vertex[0]->position);
        Real dot2 = it->normal.dotProduct(target->position);
        if(std::abs(dot2 - dot1) <= mEpsilon) {
            //Special case: The vertex is on the plane of the triangle
            //mVisibleTriangles.push_back(&*it);
            if (isInsideTriangle(target->position, *it)) {
                // Vertex is inside of a convex hull triangle.
                mVisibleTriangles.clear();
                return;
            } else {
                // If the vertex is outside, then we should add it to the hull.
                visibleTriangles.push_back(&*it);
            }
        } else if (dot1 < dot2) {
            visibleTriangles.push_back(&*it);
        }
    }
}
示例#3
0
bool
pcl::EarClipping::isEar (int u, int v, int w, const std::vector<uint32_t>& vertices)
{
  Eigen::Vector2f p_u, p_v, p_w;
  p_u[0] = points_->points[vertices[u]].x;
  p_u[1] = points_->points[vertices[u]].y;
  p_v[0] = points_->points[vertices[v]].x;
  p_v[1] = points_->points[vertices[v]].y;
  p_w[0] = points_->points[vertices[w]].x;
  p_w[1] = points_->points[vertices[w]].y;

  // Avoid flat triangles.
  // FIXME: triangulation would fail if all the triangles are flat in the X-Y axis
  const float eps = 1e-15;
  Eigen::Vector2f p_uv, p_uw;
  p_uv = p_v - p_u;
  p_uw = p_w - p_u;
  if (crossProduct (p_uv, p_uw) < eps)
    return (false);

  Eigen::Vector2f p;
  // Check if any other vertex is inside the triangle.
  for (int k = 0; k < (int)vertices.size (); k++)
  {
    if ((k == u) || (k == v) || (k == w))
      continue;
    p[0] = points_->points[vertices[k]].x;
    p[1] = points_->points[vertices[k]].y;

    if (isInsideTriangle (p_u, p_v, p_w, p))
      return (false);
  }
  return (true);
}
示例#4
0
bool intersectEdgeAndTriangle(const vec3_t& a, const vec3_t& b, const vec3_t& c,
                              const vec3_t& x1, const vec3_t& x2, vec3_t& xi, vec3_t& ri, double tol)
{
  // triangle base
  vec3_t g1 = b - a;
  vec3_t g2 = c - a;
  vec3_t g3 = g1.cross(g2);
  g3.normalise();

  // direction of the edge
  vec3_t v = x2 - x1;

  // parallel?
  if (fabs(g3*v) < 1e-6) {
    return false;
  }

  // compute intersection between straight and triangular plane
  double k = intersection(x1, v, a, g3);
  xi = x1 + k*v;

  // transform xi to triangular base
  mat3_t G;
  G.column(0, g1);
  G.column(1, g2);
  G.column(2, g3);
  
  mat3_t GI = G.inverse();
  ri = xi - a;
  ri = GI*ri;
  /*
  {
    vec3_t b = xi-a;
    linsolve(G, b, ri);
  }
  */

  // intersection outside of edge range?
  if (k < 0 - tol) {
    return false;
  }
  if (k > 1 + tol) {
    return false;
  }
  
  // intersection outside of triangle?
  if (!isInsideTriangle(vec2_t(ri[0],ri[1]),tol)) {
    return false;
  }
  return true;
}
示例#5
0
bool isInside(Point* p, Point* poly, Point* center, int npoints, bool relative)
{
    for (int i=0; i< npoints; i++)
    {
        Point p1, p2;
        int i1 = (i+1) % npoints;
        p1 = poly[i];
        p2 = poly[i1];
        if (relative)
        {
            p1.x = p1.x + center->x;
            p1.y = p1.y + center->y;
            p2.x = p2.x + center->x;
            p2.y = p2.y + center->y;
        }
        if (isInsideTriangle (p, &p1, &p2, center))
            return true;
    }
    return false;
}