Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpTriangle.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Defines a 2D triangle.
32 */
33
34#include <visp3/core/vpDebug.h>
35#include <visp3/core/vpTriangle.h>
36
45 : goodTriange(true), S1(), uvinv00(0), uvinv01(0), uvinv10(0), uvinv11(0), ptempo0(0), ptempo1(0), area(0), apex1(),
46 apex2(), apex3()
47{
48 init(vpImagePoint(0, 0), vpImagePoint(1, 0), vpImagePoint(0, 1));
49}
50
60 : goodTriange(true), S1(), uvinv00(0), uvinv01(0), uvinv10(0), uvinv11(0), ptempo0(0), ptempo1(0), area(0), apex1(),
61 apex2(), apex3()
62{
63 init(iP1, iP2, iP3);
64}
65
72 : goodTriange(true), S1(), uvinv00(0), uvinv01(0), uvinv10(0), uvinv11(0), ptempo0(0), ptempo1(0), area(0), apex1(),
73 apex2(), apex3()
74{
75 *this = tri;
76}
77
82
87{
88 goodTriange = tri.goodTriange;
89 S1 = tri.S1;
90 uvinv00 = tri.uvinv00;
91 uvinv01 = tri.uvinv01;
92 uvinv10 = tri.uvinv10;
93 uvinv11 = tri.uvinv11;
94 ptempo0 = tri.ptempo0;
95 ptempo1 = tri.ptempo1;
96 area = tri.area;
97 apex1 = tri.apex1;
98 apex2 = tri.apex2;
99 apex3 = tri.apex3;
100 return *this;
101}
102
112{
113 init(iP1, iP2, iP3);
114 return *this;
115}
116
117void vpTriangle::init(const vpImagePoint &iP1, const vpImagePoint &iP2, const vpImagePoint &iP3)
118{
119 ptempo0 = ptempo1 = 0.;
120 apex1 = iP1;
121 apex2 = iP2;
122 apex3 = iP3;
123
124 vpMatrix uv(2, 2);
125 vpMatrix uvinv(2, 2);
126
127 uv[0][0] = iP2.get_i() - iP1.get_i();
128 uv[1][0] = iP3.get_i() - iP1.get_i();
129 uv[0][1] = iP2.get_j() - iP1.get_j();
130 uv[1][1] = iP3.get_j() - iP1.get_j();
131 try {
132 uvinv = uv.inverseByLU();
133 goodTriange = true;
134 }
135 catch (...) {
136 goodTriange = false;
137 std::cout << "Empty triangle" << std::endl;
138 }
139
140 uvinv00 = uvinv[0][0];
141 uvinv01 = uvinv[0][1];
142 uvinv10 = uvinv[1][0];
143 uvinv11 = uvinv[1][1];
144 S1 = iP1;
145 area = 0.5 * fabs(uv.det());
146}
147
159bool vpTriangle::inTriangle(const vpImagePoint &iP, double threshold)
160{
161 if (!goodTriange)
162 return false;
163
164 if (threshold < 0)
165 threshold = 0;
166
167 ptempo0 = iP.get_i() - S1.get_i();
168 ptempo1 = iP.get_j() - S1.get_j();
169
170 double p_ds_uv0 = ptempo0 * uvinv00 + ptempo1 * uvinv10;
171 double p_ds_uv1 = ptempo0 * uvinv01 + ptempo1 * uvinv11;
172
173 return (p_ds_uv0 + p_ds_uv1 < 1. + threshold && p_ds_uv0 > -threshold && p_ds_uv1 > -threshold);
174}
175END_VISP_NAMESPACE
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
double get_j() const
double get_i() const
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
vpTriangle & operator=(const vpTriangle &tri)
vpTriangle & buildFrom(const vpImagePoint &iP1, const vpImagePoint &iP2, const vpImagePoint &iP3)
bool inTriangle(const vpImagePoint &iP, double threshold=0.00001)
virtual ~vpTriangle()