Skip to content

File bench_edge_face_intersections.cpp

File List > benchmark > metrics > implementations > bench_edge_face_intersections.cpp

Go to the documentation of this file

#include "bench_edge_face_intersections.h"

#include <chrono>
#include <iostream>
#include <ostream>

#include "structure/AABBTree.h"
#include "structure/Edge.h"

void EdgeFaceIntersection::compute(const Mesh &mesh, const Mesh &reconstruct,
                                   benchmark::State &state) const {

    if (mesh.isEmpty()) {
        // sans mesh original (cloud point en entrée)
        std::cout << "EdgeFaceIntersection -> impossible d'utiliser ce benchmark sans mesh en entrée." << std::endl;

        state.counters[getName()] = benchmark::Counter(-1.0);

        return;
    }

    int nbIntersections = 0;
    std::vector<Vector3D<double>> verticesReconst = reconstruct.getVertices();


    // Récupère toutes les arêtes du mesh reconstruit de façon unique
    std::vector<Edge> edges = Edge::getUniquesEdges(reconstruct);


    // Division en triangles et optimisation
    AABBTree tree(mesh);

    // Parcours des arêtes et detection intersection
    for (auto edge : edges) {
        const Vector3D<double>& v1 = verticesReconst[edge.getV1()];
        const Vector3D<double>& v2 = verticesReconst[edge.getV2()];

        // Detection si l'arête traverse n'importe quelle face (triangles) du mesh original
        nbIntersections += tree.getNbIntersections(v1, v2);
    }

    state.counters[getName()] = benchmark::Counter(nbIntersections);
}