示例#1
0
void _buildingWall( const Polygon_2& ring, const Kernel::FT& wallHeight, PolyhedralSurface& shell )
{
    size_t npt = ring.size() ;

    for ( size_t i = 0; i < npt; i++ ) {
        const Point_2& a = ring.vertex( i ) ;
        const Point_2& b = ring.vertex( ( i+1 ) % npt ) ;

        LineString wallRing ;
        wallRing.addPoint( new Point( a.x(), a.y(), Kernel::FT( 0 ) ) );
        wallRing.addPoint( new Point( b.x(), b.y(), Kernel::FT( 0 ) ) );
        wallRing.addPoint( new Point( b.x(), b.y(), wallHeight ) );
        wallRing.addPoint( new Point( a.x(), a.y(), wallHeight ) );
        wallRing.addPoint( new Point( a.x(), a.y(), Kernel::FT( 0 ) ) );
        shell.addPolygon( Polygon( wallRing ) );
    }
}
Polygon_2 CollisionDetector::flip(const Polygon_2& robot)
{
	m_translate_helper.resize(0);
	for(int i = 0; i < robot.size(); ++i)
	{
		Vector_2 minus_p = CGAL::ORIGIN - robot.vertex(i);
		m_translate_helper.push_back(Point_2(minus_p.x(),minus_p.y()));
	}
	return Polygon_2(m_translate_helper.begin(), m_translate_helper.end());
}
Pwh_list_2 GDALParceling::splitter(Polygon_2 &rect)
{
	Pwh_list_2 ress;

	Point_2 p1 = rect.vertex(0);
	Point_2 p2 = rect.vertex(1);

	Point_2 p3 = rect.vertex(2);
	Point_2 p4 = rect.vertex(3);

	Vector_2 v1 = (p2-p1)/2;
	Vector_2 v2 = (p3-p2)/2;

	bool v1_bigger = true;
	if (v1.squared_length() < v2.squared_length()) {
		v1_bigger = false;
	}

	//Left
	if (v1_bigger && v1.squared_length() >= this->length*this->length) {
		split_left(p3, ress, p2, p4, p1, v1);
		return ress;
	}
	if (!v1_bigger && v2.squared_length() >= this->length*this->length) {
		split_up(ress, p3, p1, p4, v2, p2);
		return ress;
	}
	if (v1_bigger && v2.squared_length() >= this->width*this->width){
		split_up(ress, p3, p1, p4, v2, p2);
		return ress;
	}

	if (!v1_bigger && v1.squared_length() >= this->width*this->width){
		split_left(p3, ress, p2, p4, p1, v1);
		return ress;
	}
	return ress;
}
示例#4
0
int alpha_shape(vertex_t *vertices, size_t count, double alpha,
                vertex_t **res, size_t *res_count, char **err_msg)
{
    try {
  std::list<Point> points;

  {
    std::vector<Point> pv;

    for (std::size_t j = 0; j < count; ++j) {
        Point p(vertices[j].x, vertices[j].y);
        pv.push_back(p);
    }

    std::sort(pv.begin(), pv.end(),
        [](const Point &e1, const Point &e2)->bool {
        return e2.y() < e1.y();
        });
    std::stable_sort(pv.begin(), pv.end(),
        [](const Point &e1, const Point &e2)->bool {
        return e2.x() < e1.x();
        });
    pv.erase(std::unique(pv.begin(), pv.end()), pv.end());
    if (pv.size() != count &&  pv.size() < 3) {
        *err_msg = strdup("After eliminating duplicated points, less than 3 points remain!!. Alpha shape calculation needs at least 3 vertices.");
        return -1;
    }
    points.insert(points.begin(), pv.begin(), pv.end());
  }

  Alpha_shape_2 A(points.begin(), points.end(),
                  coord_type(10000),
                  Alpha_shape_2::REGULARIZED);
  
  std::vector<Segment> segments;
//  std::vector<Segment> result;

//  Alpha_shape_2::Alpha_shape_vertices_iterator vit;
//  Alpha_shape_2::Vertex_handle vertex;
//  Alpha_shape_2::Alpha_shape_edges_iterator eit;
//  Alpha_shape_2::Edge edge;
//  Alpha_shape_2::Face_iterator fit;
//  Alpha_shape_2::Face_handle face;
  
  if (alpha <= 0.0)
  {
    alpha = *A.find_optimal_alpha(1);
  }
  A.set_alpha(alpha);

  alpha_edges( A, std::back_inserter(segments));

//  Segment s = segments.at(0);
//  find_next_edge(s, segments, result);
  if (segments.empty())
  {
    *res = NULL;
    *res_count = 0;
  }
  else
  {
    std::set<int> unusedIndexes;
    for (unsigned int i = 0; i < segments.size(); i++)
    {
      unusedIndexes.insert(i);
    }
    
    std::vector<Polygon_2> rings;
    Polygon_2 ring;
    ring.push_back(segments.at(0).source());
    rings.push_back(ring);
    unusedIndexes.erase(0);
    find_next_edge(segments.at(0), segments, unusedIndexes, rings);

    size_t result_count = 0;
    for (unsigned int i = 0; i < rings.size(); i++)
    {
      Polygon_2 ring = rings.at(i);
      result_count += ring.size();
    }
    result_count += rings.size() - 1;
    *res = (vertex_t *) malloc(sizeof(vertex_t) * result_count);
    *res_count = result_count;

    int idx = 0;
    for (unsigned int i = 0; i < rings.size(); i++)
    {
      if (i > 0)
      {
        (*res)[idx].x = DBL_MAX;
        (*res)[idx].y = DBL_MAX;
        idx++;
      }
      Polygon_2 ring = rings.at(i);
      for(unsigned int j = 0; j < ring.size(); j++)
      {
        Point point = ring.vertex(j);
        (*res)[idx].x = point.x();
        (*res)[idx].y = point.y();
        idx++;
      }
    }
  }
  *err_msg = NULL;

  return EXIT_SUCCESS;
    } catch ( ... ) {
        *err_msg = strdup("Caught unknown expection!");
    }
        return -1;

}