MinusculeRender/src/triangle.h

43 lines
1.1 KiB
C
Raw Normal View History

2024-03-01 21:31:47 +08:00
// Copyright 2024 Bytedance Inc. All Rights Reserved.
// Author: tianlei.richard@qq.com (tianlei.richard)
#pragma once
2024-03-05 21:43:08 +08:00
#include "common.h"
2024-03-01 21:31:47 +08:00
#include <Eigen/Geometry>
#include <array>
class Triangle {
public:
using AffineTransformType = Eigen::Transform<double, 3, Eigen::Affine>;
using ProjectiveTransformType =
Eigen::Transform<double, 3, Eigen::Projective>;
private:
using HomoPointType = Eigen::Vector4d;
public:
2024-03-05 21:43:08 +08:00
Triangle(const Point3d &a, const Point3d &b, const Point3d &c);
2024-03-01 21:31:47 +08:00
Triangle(const HomoPointType &a, const HomoPointType &b,
const HomoPointType &c);
2024-03-05 21:43:08 +08:00
template <int size>
std::array<Eigen::Vector<double, size>, 3> get_points() const {
return std::array<Eigen::Vector<double, size>, 3>{
(points_[0]).head(size),
(points_[1]).head(size),
(points_[2]).head(size),
};
}
2024-03-01 21:31:47 +08:00
public:
2024-03-05 21:43:08 +08:00
BBox axis_align_bbox() const;
Vector3d normal_vector() const;
2024-03-01 21:31:47 +08:00
void affine_transform(const AffineTransformType &m);
void projective_transform(const ProjectiveTransformType &m);
private:
2024-03-05 21:43:08 +08:00
std::array<Point3d, 3> points_;
2024-03-01 21:31:47 +08:00
};