static void traceIntersectionGraph(const V2Set &shared_edges, const FLGroupList & /* a_loops_grouped */, const FLGroupList & /* b_loops_grouped */, const carve::csg::detail::LoopEdges &a_edge_map, const carve::csg::detail::LoopEdges &b_edge_map) { carve::csg::detail::VVSMap shared_edge_graph; carve::csg::detail::VSet branch_points; // first, make the intersection graph. for (V2Set::const_iterator i = shared_edges.begin(); i != shared_edges.end(); ++i) { const V2Set::key_type &edge = (*i); carve::csg::detail::VVSMap::mapped_type &out = (shared_edge_graph[edge.first]); out.insert(edge.second); if (out.size() == 3) branch_points.insert(edge.first); #if defined(CARVE_DEBUG) && defined(DEBUG_DRAW_INTERSECTION_LINE) HOOK(drawEdge(edge.first, edge.second, 1, 1, 1, 1, 1, 1, 1, 1, 1.0);); #endif }
void carve::csg::CSG::findSharedEdges(const detail::LoopEdges &edge_map_a, const detail::LoopEdges &edge_map_b, V2Set &shared_edges) { for (detail::LoopEdges::const_iterator i = edge_map_a.begin(), e = edge_map_a.end(); i != e; ++i) { detail::LoopEdges::const_iterator j = edge_map_b.find((*i).first); if (j != edge_map_b.end()) { shared_edges.insert((*i).first); } } #if defined(CARVE_DEBUG) detail::VVSMap edge_graph; for (V2Set::const_iterator i = shared_edges.begin(); i != shared_edges.end(); ++i) { edge_graph[(*i).first].insert((*i).second); edge_graph[(*i).second].insert((*i).first); } std::cerr << "*** testing consistency of edge graph" << std::endl; for (detail::VVSMap::const_iterator i = edge_graph.begin(); i != edge_graph.end(); ++i) { if ((*i).second.size() > 2) { std::cerr << "branch at: " << (*i).first << std::endl; } if ((*i).second.size() == 1) { std::cerr << "endpoint at: " << (*i).first << std::endl; std::cerr << "coordinate: " << (*i).first->v << std::endl; } } { carve::line::PolylineSet intersection_graph; intersection_graph.vertices.resize(edge_graph.size()); std::map<const carve::mesh::MeshSet<3>::vertex_t *, size_t> vmap; size_t j = 0; for (detail::VVSMap::const_iterator i = edge_graph.begin(); i != edge_graph.end(); ++i) { intersection_graph.vertices[j].v = (*i).first->v; vmap[(*i).first] = j++; } while (edge_graph.size()) { detail::VVSMap::iterator prior_i = edge_graph.begin(); carve::mesh::MeshSet<3>::vertex_t *prior = (*prior_i).first; std::vector<size_t> connected; connected.push_back(vmap[prior]); while (prior_i != edge_graph.end() && (*prior_i).second.size()) { carve::mesh::MeshSet<3>::vertex_t *next = *(*prior_i).second.begin(); detail::VVSMap::iterator next_i = edge_graph.find(next); CARVE_ASSERT(next_i != edge_graph.end()); connected.push_back(vmap[next]); (*prior_i).second.erase(next); (*next_i).second.erase(prior); if (!(*prior_i).second.size()) { edge_graph.erase(prior_i); prior_i = edge_graph.end(); } if (!(*next_i).second.size()) { edge_graph.erase(next_i); next_i = edge_graph.end(); } prior_i = next_i; prior = next; } bool closed = connected.front() == connected.back(); for (size_t k = 0; k < connected.size(); ++k) { std::cerr << " " << connected[k]; } std::cerr << std::endl; intersection_graph.addPolyline(closed, connected.begin(), connected.end()); } #if defined(CARVE_DEBUG_WRITE_PLY_DATA) std::string out("/tmp/intersection.ply"); ::writePLY(out, &intersection_graph, true); #endif } std::cerr << "*** edge graph consistency test done" << std::endl; #endif }