Program Listing for File Triangle.hpp

Return to documentation for file (include/lvr2/texture/Triangle.hpp)

#pragma once

// lvr2 includes
#include "lvr2/types/MatrixTypes.hpp"

// Eigen includes
#include <Eigen/Dense>

// std includes
#include <array>

namespace lvr2
{
template <typename Vec = Eigen::Vector3f, typename Scalar = float>
class Triangle
{
public:
using BarycentricCoords = Vector3<Scalar>;

private:
    // Points
    Vec m_a; // Point a
    Vec m_b; // Point b
    Vec m_c; // Point c
    // Vectors
    Vec m_AB; // Vec from a to b
    Vec m_BC; // Vec from b to c
    Vec m_CA; // Vec from c to a

    Scalar m_area; // Area of the triangle
    Scalar m_areaInverse; // 1 / area

    inline void init();

public:
    Triangle(Vec a, Vec b, Vec c);

    Triangle(const std::array<Vec, 3UL>& array);

    Scalar area() const { return m_area; };

    BarycentricCoords barycentric(Vec point) const;

    Vec point(BarycentricCoords barycentric) const;

    std::pair<Vec, Vec> getAABoundingBox() const;

    bool contains(Vec point) const;

    Vec center() const;

    Vec normal() const;

    // Gets the Point of the triangle
    Vec A() const { return m_a; };
    Vec B() const { return m_b; };
    Vec C() const { return m_c; };

    // Gets the Side Vector of the triangle
    Vec AB() const { return m_AB; };
    Vec BC() const { return m_BC; };
    Vec CA() const { return m_CA; };


};

} // namespace lvr2

#include "Triangle.tcc"