Skip to content
Dmitry V. Sokolov edited this page Nov 28, 2018 · 3 revisions

Welcome to the ENSG wiki!

Detection des horizons:

// this function checks whether the model m contains an edge with extremities v1 and v2
bool is_edge_present(Vec3f v1, Vec3f v2, Model &m) {
    for (int j=0; j<m.nhalfedges(); j++) {
        Vec3f u1 = m.point(m.from(j));
        Vec3f u2 = m.point(m.to  (j));
        float threshold = 1e-3;
        if (((u1-v1).norm()<threshold && (u2-v2).norm()<threshold) || ((u2-v1).norm()<threshold && (u1-v2).norm()<threshold)) {
            return true;
        }
    }
    return false;
}

int main(int argc, char** argv) {
    if (argc<2) {
        std::cerr << "Usage: " << argv[0] << " slice.obj horizon1.obj horizon2.obj horizon3.obj" << std::endl;
        return 1;
    }

    // load all models from command lines parameters into the vector m[]; m[0] is the domain, m[1]-m[n] are the horizons
    std::vector<Model> m;
    for (int i=1; i<argc; i++) {
        m.push_back(Model(argv[i]));
    }

    // fill horizons halfedge attributes, if horizon[hid] equals to -1 for a halfedge hid, then hid is not a horizon; otherwise it is an integer with the horizon id

    std::vector<int> horizon(m[0].nhalfedges(), -1);
    const int nhorizons = m.size()-1;

    for (int i=0; i<m[0].nhalfedges(); i++) {
        Vec3f v[2] = { m[0].point(m[0].from(i)), m[0].point(m[0].to(i)) };

        for (int j=0; j<nhorizons; j++) {
            if (is_edge_present(v[0], v[1], m[j+1])) {
                horizon[i] = j;
                break;
            }
        }
    }
    return 0;
}

Clone this wiki locally