Example #1
0
void raw_print_tiles_impl(std::ostream& out, Point_iter points_begin, Point_iter points_end, double z_scale, bool color)
{
    static log4cplus::Logger logger = log4cplus::Logger::getInstance("raw_print_tiles_impl");

    // out << std::setprecision(12);

    typedef typename iterator_traits<Point_iter>::value_type Point_type;
    typedef boost::unordered_map<Point_type, size_t> Vertex_map;

    Vertex_map vertices;
    size_t next_idx = 0;
    size_t num_points = 0;
    stringstream ss;
    // ss << std::setprecision(24);
    for (Point_iter it = points_begin; it != points_end; ++it)
    {
        const Point_type& t = *it;
        if (vertices.find(t) == vertices.end())
        {
            // // debug
            // if (abs(it->x() - 5.2767) < 0.0001) {
            //   LOG4CPLUS_WARN(logger, "looking for this? " << it->x() <<
            //                  " " << it->y() << " " << (it->z()+0.5) * z_scale <<
            //                  " " << it->point().id());
            // }
            // // /debug

            Color c = get_color(t);
            vertices[t] = next_idx++;
            ss << t.x() << " " << t.y() << " " << (t.z()+0.5) * z_scale;
            if (color)
                ss << " " << c.r() << " " << c.g() << " " << c.b();
            ss << endl;
        }
        ++num_points;
    }
    size_t num_verts = vertices.size();
    num_points /= 3;

    out << num_verts << " " << num_points << endl;
    out << ss.str();

    size_t n = 0;
    for (Point_iter it = points_begin; it != points_end; ++it)
    {
        out << vertices[*it] << " ";
        if ((++n) % 3 == 0)
            out << endl;
    }
}
void Vertex_visibility_graph_2<Traits>::handle(Tree_iterator p, 
                                        Tree_iterator q, 
                                        const Polygon& polygon,
                                        Vertex_map& vertex_map)
{
#ifdef CGAL_VISIBILITY_GRAPH_DEBUG
      std::cout << "Handling edge from " << (*p).x() << " " << (*p).y() 
                << " to " << (*q).x() << " " << (*q).y() << std::endl;
#endif
   Vertex_map_iterator p_it = vertex_map.find(*p);
   Vertex_map_iterator q_it = vertex_map.find(*q);
   CGAL_assertion (p_it != vertex_map.end());
   CGAL_assertion (q_it != vertex_map.end());
#ifdef CGAL_VISIBILITY_GRAPH_DEBUG
   std::cout << "p currently sees : ";
   if ((*p_it).second.second != polygon.end())
      std::cout << *((*p_it).second.second) << endl;
   else
      std::cout << " NADA" << endl;
#endif

   // if p and q are adjacent
   if (are_adjacent(polygon, (*p_it).second.first, (*q_it).second.first))
   {
#ifdef CGAL_VISIBILITY_GRAPH_DEBUG
      cout << "are adjacent" << endl;
#endif
      insert_edge(Point_pair(*p,*q));
      update_visibility(p_it, q_it, polygon, 1);
   }
   else 
   {
      bool interior_at_p = diagonal_in_interior(polygon, (*p_it).second.first,
                                                (*q_it).second.first);
      bool interior_at_q = diagonal_in_interior(polygon, (*q_it).second.first,
                                                (*p_it).second.first);
      // line of site is through the interior of the polygon
      if (interior_at_p && interior_at_q)
      {
#ifdef CGAL_VISIBILITY_GRAPH_DEBUG
         cout << "both interior" << endl;
#endif
         // if p sees something and q is visible only through collinear
         // points then update p's visibility if one of the points adjacent
         // to q is above the line unless p's current visibility point 
         // obscures the view.
         if ((*p_it).second.second != polygon.end() &&
             are_strictly_ordered_along_line_2((*p_it).first,
                                             *(*p_it).second.second,
                                                (*q_it).first))
         {
            update_collinear_visibility(p_it, q_it, polygon);
         }
         // p current sees nothing or q is visible to p
         else if ((*p_it).second.second == polygon.end() ||
                  point_is_visible(polygon, (*q_it).second.first, p_it))
         {
            insert_edge(Point_pair(*p,*q));
            update_visibility(p_it, q_it, polygon, 0);
         }
      }
      else if (!interior_at_p && !interior_at_q) // both points exterior
      {
#ifdef CGAL_VISIBILITY_GRAPH_DEBUG
            cout << "both exterior" << endl;
#endif
         // p currently sees nothing or q is visible to p
         if ((*p_it).second.second == polygon.end() ||
             point_is_visible(polygon, (*q_it).second.first, p_it))
         {
            (*p_it).second.second = (*q_it).second.first;
         }
      }
   }
#ifdef CGAL_VISIBILITY_GRAPH_DEBUG
   std::cout << "p now sees : ";
   if ((*p_it).second.second != polygon.end())
      std::cout << *((*p_it).second.second) << endl;
   else
      std::cout << " NADA" << endl;
#endif
}