Algorithms for the Vegetation Module

In order to factorize the code the algorithmsvegetation file contains the implementation of some of the functions used in the Vegetation Project. The algorithms are used to process the trees and place them in the scene. The algorithms are implemented using the CGAL library and the Geom library avaible in the project.

using K = CGAL::Exact_predicates_inexact_constructions_kernel;
using Point_3 = K::Point_3;
using Vector_3 = K::Vector_3;
using MeshGeom = Feel::Ktirio::Geom::Mesh;

//! Read cgal mesh from file
inline bool read_soup_cgal(const std::string &file_path,
                           std::vector<Point_3> &points,
                           std::vector<std::array<int, 3>> &faces) {...}

//! Apply a transformation to points
inline void
apply_transformation_cgal(const CGAL::Aff_transformation_3<K> &transformation,
                          std::vector<Point_3> &points) {
    for (auto &p : points) {
        p = transformation.transform(p);
    }
}

The following functions are used in the process of scaling and translating the trees in the scene.

//! Compute the bounding box of points
inline CGAL::Bbox_3 compute_bbox_cgal(const std::vector<Point_3> &points) {
    return CGAL::bbox_3(points.begin(), points.end());
}

//! Scale points
inline void scale_cgal(std::vector<Point_3> &points, K::RT scaling_factor) {
    CGAL::Aff_transformation_3<K> scaling(CGAL::SCALING, scaling_factor);
    apply_transformation_cgal(scaling, points);
}

//! Translate points
inline void translate_cgal(std::vector<Point_3> &points,
                           const Vector_3 &translation_vector) {
    CGAL::Aff_transformation_3<K> translation(CGAL::TRANSLATION,
                                              translation_vector);
    apply_transformation_cgal(translation, points);
}

An importand part is being able to place markers (ie tags) on the part on the mesh such as the leaves and the trunk of the tree. The following functions are used to tag the leaves and the trunk of the tree.

//! Add markers names to leaves
inline void tagLeaves(MeshGeom &mesh) {
    RandomNumber<unsigned int> rnd(0, 3);
    std::vector<std::string> markers = {"tree_leaf_1", "tree_leaf_2",
                                        "tree_leaf_3", "tree_leaf_4"};

    // Add marker names to feelMesh
    for (auto const &tri : mesh.triangles()) {
        auto marker1 = mesh.addMarkerName(2, "tree");
        auto marker2 = mesh.addMarkerName(2, "tree_foliage");
        auto marker3 = mesh.addMarkerName(2, markers[rnd()]);

        tri->addMarkerId(marker1);
        tri->addMarkerId(marker2);
        tri->addMarkerId(marker3);
    }
}

//! Add markers names to trunk
inline void tagTrunk(MeshGeom &mesh) {
    // Add marker names to feelMesh
    for (auto const &tri : mesh.triangles()) {
        auto marker1 = mesh.addMarkerName(2, "tree");
        auto marker2 = mesh.addMarkerName(2, "tree_trunk");
        tri->addMarkerId(marker1);
        tri->addMarkerId(marker2);
    }
}