MinusculeRender/src/triangle.h

41 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
#include <Eigen/Dense>
#include <Eigen/Geometry>
#include <array>
#include <opencv2/core/core.hpp>
class Triangle {
public:
using AffineTransformType = Eigen::Transform<double, 3, Eigen::Affine>;
using ProjectiveTransformType =
Eigen::Transform<double, 3, Eigen::Projective>;
using PointType = Eigen::Vector3d;
using BBoxType = cv::Rect2i;
private:
using HomoPointType = Eigen::Vector4d;
public:
Triangle(const PointType &a, const PointType &b, const PointType &c);
Triangle(const HomoPointType &a, const HomoPointType &b,
const HomoPointType &c);
public:
BBoxType axis_align_bbox() const;
void affine_transform(const AffineTransformType &m);
void projective_transform(const ProjectiveTransformType &m);
private:
static BBoxType calculate_aabb(const HomoPointType &a, const HomoPointType &b,
const HomoPointType &c);
private:
std::array<HomoPointType, 3> points_;
BBoxType aabb_;
};