Ejemplo n.º 1
0
void TilerEngine::remove_duplicated_vertices(WireNetwork& wire_network, Float tol) {
    const size_t num_input_vertices = wire_network.get_num_vertices();

    DuplicatedVertexRemoval remover(wire_network.get_vertices(), wire_network.get_edges());
    remover.run(tol);
    MatrixFr vertices = remover.get_vertices();
    MatrixIr edges = remover.get_faces();
    VectorI index_map = remover.get_index_map();
    assert(num_input_vertices == index_map.size());

    wire_network.set_vertices(vertices);
    wire_network.set_edges(edges);

    const size_t num_output_vertices = wire_network.get_num_vertices();
    std::vector<std::string> attr_names = wire_network.get_attribute_names();
    for (auto itr : attr_names) {
        const std::string& name = itr;
        if (wire_network.is_vertex_attribute(name)) {
            MatrixFr values = wire_network.get_attribute(name);
            MatrixFr updated_values = MatrixFr::Zero(num_output_vertices, values.cols());
            VectorF count = VectorF::Zero(num_output_vertices);
            for (size_t i=0; i<num_input_vertices; i++) {
                size_t j = index_map[i];
                updated_values.row(j) += values.row(i);
                count[j] += 1;
            }

            for (size_t i=0; i<num_output_vertices; i++) {
                assert(count[i] > 0);
                updated_values.row(i) /= count[i];
            }
            wire_network.set_attribute(name, updated_values);
        }
    }
}
Ejemplo n.º 2
0
void TilerEngine::remove_duplicated_edges(WireNetwork& wire_network) {
    const size_t num_edges = wire_network.get_num_edges();

    const MatrixIr& edges = wire_network.get_edges();
    std::vector<bool> mask = create_duplication_mask(edges);

    MatrixIr updated_edges = filter(edges, mask);
    wire_network.set_edges(updated_edges);

    std::vector<std::string> attr_names = wire_network.get_attribute_names();
    for (auto itr : attr_names) {
        const std::string& name = itr;
        if (!wire_network.is_vertex_attribute(name)) {
            MatrixFr values = wire_network.get_attribute(name);
            MatrixFr updated_values = filter(values, mask);
            wire_network.set_attribute(name, updated_values);
        }
    }
}