Visual Computing Library
Loading...
Searching...
No Matches
triangle_wrapper.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_SPACE_CORE_TRIANGLE_WRAPPER_H
24#define VCL_SPACE_CORE_TRIANGLE_WRAPPER_H
25
26#include "triangle.h"
27
28namespace vcl {
29
52template<PointConcept PointT>
54{
55 const PointT& mPoint0;
56 const PointT& mPoint1;
57 const PointT& mPoint2;
58
59public:
60 using ScalarType = PointT::ScalarType;
61 using PointType = PointT;
62
66 static const uint DIM = PointT::DIM;
67
78 TriangleWrapper(const PointT& p0, const PointT& p1, const PointT& p2) :
79 mPoint0(p0), mPoint1(p1), mPoint2(p2)
80 {
81 }
82
86 constexpr uint size() const { return 3; }
87
91 const PointT& point(uint i) const
92 {
93 switch (i) {
94 case 0: return mPoint0;
95 case 1: return mPoint1;
96 case 2: return mPoint2;
97 default:
98 throw std::out_of_range(
99 "TriangleWrapper::point: index out of range");
100 }
101 }
102
106 const PointT& point0() const { return mPoint0; }
107
111 const PointT& point1() const { return mPoint1; }
112
116 const PointT& point2() const { return mPoint2; }
117
121 ScalarType sideLength(uint i) const
122 {
123 return Triangle<PointT>::sideLength(mPoint0, mPoint1, mPoint2, i);
124 }
125
129 ScalarType sideLength0() const { return mPoint0.dist(mPoint1); }
130
134 ScalarType sideLength1() const { return mPoint1.dist(mPoint2); }
135
139 ScalarType sideLength2() const { return mPoint2.dist(mPoint0); }
140
144 PointT normal() const requires (PointT::DIM == 3)
145 {
146 return Triangle<PointT>::normal(mPoint0, mPoint1, mPoint2);
147 }
148
152 PointT barycenter() const
153 {
154 return Triangle<PointT>::barycenter(mPoint0, mPoint1, mPoint2);
155 }
156
160 PointT weightedBarycenter(ScalarType w0, ScalarType w1, ScalarType w2) const
161 {
163 mPoint0, mPoint1, mPoint2, w0, w1, w2);
164 }
165
170 {
172 mPoint0, mPoint1, mPoint2, w(0), w(1), w(2));
173 }
174
179 ScalarType b0,
180 ScalarType b1,
181 ScalarType b2) const
182 {
184 mPoint0, mPoint1, mPoint2, b0, b1, b2);
185 }
186
191 {
193 mPoint0, mPoint1, mPoint2, b(0), b(1), b(2));
194 }
195
199 PointT circumcenter() const
200 {
201 return Triangle<PointT>::circumcenter(mPoint0, mPoint1, mPoint2);
202 }
203
207 ScalarType perimeter() const
208 {
209 return Triangle<PointT>::perimeter(mPoint0, mPoint1, mPoint2);
210 }
211
215 ScalarType area() const
216 {
217 return Triangle<PointT>::area(mPoint0, mPoint1, mPoint2);
218 }
219
223 ScalarType quality() const
224 {
225 return Triangle<PointT>::quality(mPoint0, mPoint1, mPoint2);
226 }
227
231 ScalarType qualityRadii() const
232 {
233 return Triangle<PointT>::qualityRadii(mPoint0, mPoint1, mPoint2);
234 }
235
239 ScalarType qualityMeanRatio() const
240 {
241 return Triangle<PointT>::qualityMeanRatio(mPoint0, mPoint1, mPoint2);
242 }
243};
244
245/* Specialization Aliases */
246
247template<typename Scalar>
248using TriangleWrapper2 = TriangleWrapper<Point2<Scalar>>;
249
250using TriangleWrapper2f = TriangleWrapper<Point2f>;
251using TriangleWrapper2d = TriangleWrapper<Point2d>;
252
253template<typename Scalar>
254using TriangleWrapper3 = TriangleWrapper<Point3<Scalar>>;
255
256using TriangleWrapper3f = TriangleWrapper<Point3f>;
257using TriangleWrapper3d = TriangleWrapper<Point3d>;
258
259} // namespace vcl
260
261#endif // VCL_SPACE_CORE_TRIANGLE_WRAPPER_H
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
The TriangleWrapper class is a wrapper around a N-Dimensional triangle.
Definition triangle_wrapper.h:54
PointT weightedBarycenter(ScalarType w0, ScalarType w1, ScalarType w2) const
Computes the weighted barycenter of the triangle.
Definition triangle_wrapper.h:160
static const uint DIM
Dimension of the triangle.
Definition triangle_wrapper.h:66
ScalarType sideLength0() const
Returns the length of the first side of the triangle.
Definition triangle_wrapper.h:129
ScalarType perimeter() const
Computes the perimeter of the triangle.
Definition triangle_wrapper.h:207
TriangleWrapper(const PointT &p0, const PointT &p1, const PointT &p2)
Constructs a triangle wrapper around the three input points.
Definition triangle_wrapper.h:78
const PointT & point(uint i) const
Definition triangle_wrapper.h:91
ScalarType area() const
Computes the area of the triangle.
Definition triangle_wrapper.h:215
const PointT & point0() const
Definition triangle_wrapper.h:106
PointT normal() const
Returns the normal of the triangle.
Definition triangle_wrapper.h:144
PointT barycenter() const
Computes the barycenter of the triangle.
Definition triangle_wrapper.h:152
const PointT & point1() const
Definition triangle_wrapper.h:111
ScalarType qualityMeanRatio() const
Compute the mean ratio of the triangle shape quality measure.
Definition triangle_wrapper.h:239
PointT barycentricCoordinatePoint(const Point3< ScalarType > &b) const
Definition triangle_wrapper.h:190
ScalarType qualityRadii() const
Compute a shape quality measure of the triangle.
Definition triangle_wrapper.h:231
ScalarType sideLength1() const
Returns the length of the second side of the triangle.
Definition triangle_wrapper.h:134
const PointT & point2() const
Definition triangle_wrapper.h:116
ScalarType sideLength2() const
Returns the length of the third side of the triangle.
Definition triangle_wrapper.h:139
PointT barycentricCoordinatePoint(ScalarType b0, ScalarType b1, ScalarType b2) const
Definition triangle_wrapper.h:178
ScalarType sideLength(uint i) const
Returns the length of the i-th side of the triangle.
Definition triangle_wrapper.h:121
constexpr uint size() const
Returns the number of points of the triangle.
Definition triangle_wrapper.h:86
PointT circumcenter() const
Compute the circumcenter of the triangle.
Definition triangle_wrapper.h:199
ScalarType quality() const
Calculates the quality measure of the triangle.
Definition triangle_wrapper.h:223
PointT weightedBarycenter(const Point3< ScalarType > &w) const
Computes the weighted barycenter of the triangle.
Definition triangle_wrapper.h:169
Definition triangle.h:34
ScalarType area() const
Computes the area of the triangle.
Definition triangle.h:219
ScalarType quality() const
Calculates the quality measure of the triangle.
Definition triangle.h:234
ScalarType qualityMeanRatio() const
Compute the mean ratio of the triangle shape quality measure.
Definition triangle.h:271
ScalarType perimeter() const
Computes the perimeter of the triangle.
Definition triangle.h:209
PointT weightedBarycenter(ScalarType w0, ScalarType w1, ScalarType w2) const
Computes the weighted barycenter of the triangle.
Definition triangle.h:138
PointT barycenter() const
Computes the barycenter of the triangle.
Definition triangle.h:122
PointT normal() const
Returns the normal of the triangle.
Definition triangle.h:112
ScalarType sideLength(uint i) const
Returns the length of the i-th side of the triangle.
Definition triangle.h:83
PointT circumcenter() const
Compute the circumcenter of the triangle.
Definition triangle.h:199
ScalarType qualityRadii() const
Compute a shape quality measure of the triangle.
Definition triangle.h:251