예제 #1
0
/**
 * intersection post processing
 */
void post_intersection( const GeometrySet<2>& input, GeometrySet<2>& output )
{
    //
    // reverse orientation of polygons if needed
    for ( GeometrySet<2>::SurfaceCollection::const_iterator it = input.surfaces().begin();
            it != input.surfaces().end();
            ++it ) {
        const CGAL::Polygon_with_holes_2<Kernel>& p = it->primitive();
        CGAL::Polygon_2<Kernel> outer = p.outer_boundary();

        if ( outer.orientation() == CGAL::CLOCKWISE ) {
            outer.reverse_orientation();
        }

        std::list<CGAL::Polygon_2<Kernel> > rings;

        for ( CGAL::Polygon_with_holes_2<Kernel>::Hole_const_iterator hit = p.holes_begin();
                hit != p.holes_end();
                ++hit ) {
            rings.push_back( *hit );

            if ( hit->orientation() == CGAL::COUNTERCLOCKWISE ) {
                rings.back().reverse_orientation();
            }
        }

        output.surfaces().push_back( CGAL::Polygon_with_holes_2<Kernel>( outer, rings.begin(), rings.end() ) );
    }

    output.points() = input.points();
    output.segments() = input.segments();
    output.volumes() = input.volumes();
}
예제 #2
0
Polygon::Polygon( const CGAL::Polygon_2< Kernel >& other )
{
    _rings.push_back( new LineString() );
    CGAL::Polygon_2<Kernel>::Edge_const_iterator ei;

    for ( ei = other.edges_begin(); ei != other.edges_end(); ++ei ) {
        _rings.back().addPoint( ei->source() );
    }
}
예제 #3
0
void TreeNode::draw_region(cairo_t *cr) const {
  if (region.size() >= 3) {
    if (this->name) {
      Polygon_2::Vertex_circulator vcir, vend;
      vcir = vend = region.vertices_circulator();
      Bbox_2 bbox = region.bbox();

      cairo_pattern_t *fill =
        cairo_pattern_create_linear(bbox.xmin(), bbox.ymin(),
                                    bbox.xmax(), bbox.ymax());
      cairo_pattern_add_color_stop_rgb(fill, 0.0, 1.0, 1.0, 1.0);

      /* L*a*b* 色空間
      {
        double r, g, b;
        cl2pix(&r, &g, &b,
          dsfmt_genrand_open_open(&dsfmt),
          dsfmt_genrand_open_open(&dsfmt));
        cairo_pattern_add_color_stop_rgb(fill, 1.0, r, g, b);
      }
      */
      // 単なるRGB
      cairo_pattern_add_color_stop_rgb(fill, 1.0,
        dsfmt_genrand_open_open(&dsfmt),
        dsfmt_genrand_open_open(&dsfmt),
        dsfmt_genrand_open_open(&dsfmt));

      cairo_move_to(cr, CGAL::to_double(vcir->x()), CGAL::to_double(vcir->y()));
      ++vcir;

      do {
        cairo_line_to(cr, CGAL::to_double(vcir->x()), CGAL::to_double(vcir->y()));
        ++vcir;
      } while (vcir != vend);
      cairo_line_to(cr, CGAL::to_double(vend->x()), CGAL::to_double(vend->y()));
      cairo_set_source(cr, fill);
      cairo_fill_preserve(cr);
      cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
      cairo_stroke(cr);
      cairo_pattern_destroy(fill);
    }
  }

  std::list<TreeNode>::const_iterator tit;
  for (tit = children.begin(); tit != children.end(); ++tit) {
    tit->draw_region(cr);
  }
}
예제 #4
0
void TreeNode::draw() const
{
  std::ofstream ofs(NODE_FILENAME);
  cairo_t *cr;
  cairo_surface_t *surface;
  CGAL::Bbox_2 bbox = region.bbox();

  assert(bbox.xmin() >= 0.0);
  assert(bbox.ymin() >= 0.0);

#ifdef PDF_OUTPUT
  surface = cairo_pdf_surface_create(IMG_FILENAME, bbox.xmax(), bbox.ymax());
#endif
#ifdef PNG_OUTPUT
  surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, bbox.xmax(), bbox.ymax());
#endif
  cr = cairo_create(surface);

  cairo_select_font_face(cr, "serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
  cairo_set_font_size(cr, 10.0);

  draw_region(cr);
  draw_text(cr);
  write_centroid(ofs);

  cairo_show_page(cr);
  cairo_destroy(cr);
#ifdef PNG_OUTPUT
  cairo_surface_write_to_png(surface, IMG_FILENAME);
#endif
  cairo_surface_destroy(surface);
}
예제 #5
0
 std::ostream& print_ostream(std::ostream &os) const {
   if (name) {
     os << "name: " << name << " ";
   } else {
     os << "name: anonymous ";
   }
   os << "p: (" << CGAL::to_double(p.x()) << ", " << CGAL::to_double(p.y()) << ") ";
   os << "adesired: " << adesired << " ";
   os << "area: " << CGAL::to_double(region.area()) << " ";
   os << "childrens: " << children.size() << " ";
   os << "region:";
   Polygon_2::Vertex_iterator pit;
   for (pit = region.vertices_begin();
        pit != region.vertices_end();
        ++pit) {
     os << " (" << CGAL::to_double(pit->x()) << ", " << CGAL::to_double(pit->y()) << ")";
   }
   return os;
 }
예제 #6
0
CGAL::Polygon_with_holes_2<Kernel> Polygon::toPolygon_with_holes_2( bool fixOrientation ) const
{
    std::list<CGAL::Polygon_2<Kernel> > holes;

    for ( size_t i = 0; i < numInteriorRings(); ++i ) {
        // note that the orientation is fixed here to avoid double reverse for interior rings
        CGAL::Polygon_2<Kernel> inner = interiorRingN( i ).toPolygon_2( false );

        if ( fixOrientation && inner.orientation() == CGAL::COUNTERCLOCKWISE ) {
            inner.reverse_orientation();
        }

        holes.push_back( inner );
    }

    CGAL::Polygon_2<Kernel> outer = exteriorRing().toPolygon_2( fixOrientation );
    return CGAL::Polygon_with_holes_2<Kernel>( outer,
            holes.begin(),
            holes.end() );
}
예제 #7
0
Polygon::Polygon( const CGAL::Polygon_with_holes_2< Kernel >& poly )
{
    _rings.push_back( new LineString() );
    CGAL::Polygon_2<Kernel> outer = poly.outer_boundary();
    CGAL::Polygon_2<Kernel>::Edge_const_iterator ei;

    for ( ei = outer.edges_begin(); ei != outer.edges_end(); ++ei ) {
        _rings.back().addPoint( ei->source() );
    }

    _rings.back().addPoint( _rings.back().startPoint() );

    for ( CGAL::Polygon_with_holes_2<Kernel>::Hole_const_iterator hit = poly.holes_begin(); hit != poly.holes_end(); ++hit ) {
        _rings.push_back( new LineString() );
        CGAL::Polygon_2<Kernel>::Edge_const_iterator ei;

        for ( ei = hit->edges_begin(); ei != hit->edges_end(); ++ei ) {
            _rings.back().addPoint( ei->source() );
        }

        _rings.back().addPoint( _rings.back().startPoint() );
    }
}
예제 #8
0
void makeValidOrientation( CGAL::Polygon_2< Kernel >& polygon )
{
    if ( polygon.orientation() != CGAL::COUNTERCLOCKWISE ) {
        polygon.reverse_orientation() ;
    }
}