CGI/exercise4/include/Triangle.h

45 lines
2 KiB
C
Raw Normal View History

2019-01-24 14:38:18 +00:00
// This source code is property of the Computer Graphics and Visualization
// chair of the TU Dresden. Do not distribute!
2018-09-06 12:35:43 +00:00
// Copyright (C) CGV TU Dresden - All Rights Reserved
#pragma once
#include "Box.h"
#include "util/OpenMeshUtils.h"
/*
a triangle primitive which can be used with the AABBTree and the HashGrid data structure
*/
class Triangle
{
//internal storage of the first vertex position of the triangle
Eigen::Vector3f v0;
//internal storage of the second vertex position of the triangle
Eigen::Vector3f v1;
//internal storage of the third vertex position of the triangle
Eigen::Vector3f v2;
//internal storage of the optional face handle to identify the originating face in a half edge mesh instance
OpenMesh::FaceHandle h;
2019-01-24 14:38:18 +00:00
public:
2018-09-06 12:35:43 +00:00
//default constructor
Triangle();
//constructs a triangle using the vertex positions v0,v1 and v2
2019-01-24 14:38:18 +00:00
Triangle(const Eigen::Vector3f &v0, const Eigen::Vector3f &v1, const Eigen::Vector3f &v2);
2018-09-06 12:35:43 +00:00
//constructs a triangle from the face f of the given halfedge mesh m
2019-01-24 14:38:18 +00:00
Triangle(const HEMesh &m, const OpenMesh::FaceHandle &f);
2018-09-06 12:35:43 +00:00
//returns the axis aligned bounding box of the triangle
Box ComputeBounds() const;
//returns true if the triangle overlaps the given box b
2019-01-24 14:38:18 +00:00
bool Overlaps(const Box &b) const;
2018-09-06 12:35:43 +00:00
//returns the barycentric coordinates of the point with thesmallest distance to point p which lies on the triangle
2019-01-24 14:38:18 +00:00
void ClosestPointBarycentric(const Eigen::Vector3f &p, float &l0, float &l1, float &l2) const;
2018-09-06 12:35:43 +00:00
//returns the point with smallest distance to point p which lies on the triangle
2019-01-24 14:38:18 +00:00
Eigen::Vector3f ClosestPoint(const Eigen::Vector3f &p) const;
2018-09-06 12:35:43 +00:00
//returns the squared distance between point p and the triangle
2019-01-24 14:38:18 +00:00
float SqrDistance(const Eigen::Vector3f &p) const;
2018-09-06 12:35:43 +00:00
//returns the euclidean distance between point p and the triangle
2019-01-24 14:38:18 +00:00
float Distance(const Eigen::Vector3f &p) const;
2018-09-06 12:35:43 +00:00
//returns a reference point which is on the triangle and is used to sort the primitive in the AABB tree construction
Eigen::Vector3f ReferencePoint() const;
};