Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpCoreDisplay.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 * Le module "display.c" contient les procedures de d'affichage
32 * des scenes de modele geometrique surfacique.
33 *
34 * Authors:
35 * Jean-Luc CORRE
36 */
37
38#include <visp3/core/vpConfig.h>
39#include <visp3/core/vpException.h>
40
41#ifndef DOXYGEN_SHOULD_SKIP_THIS
42#include <stdio.h>
43#include <stdlib.h>
44
45#include "vpCoreDisplay.h"
46#include "vpImstack.h"
47#include "vpMy.h"
48#include "vpRfstack.h"
49#include "vpView.h"
50#include "vpVwstack.h"
51
53/*
54 * POINT2I :
55 * Tableau de points 2D dans l'espace ecran servant a l'affichage fil-de-fer.
56 *
57 * RENAME :
58 * Tableau de renommage des sommets ou tableau de compteurs associes aux
59 * points.
60 */
61 Point2i *point2i = (Point2i *)NULL;
62Point2i *listpoint2i = (Point2i *)NULL;
63static int *rename_jlc = (int *)NULL;
64
65/*
66 * La procedure "open_display" alloue et initialise les variables utilisees
67 * par le mode "display".
68 */
69void open_display(void)
70{
71 if ((point2i = (Point2i *)malloc(POINT_NBR * sizeof(Point2i))) == NULL ||
72 (listpoint2i = (Point2i *)malloc(50 * sizeof(Point2i))) == NULL ||
73 (rename_jlc = (int *)malloc(POINT_NBR * sizeof(int))) == NULL) {
74 static char proc_name[] = "open_display";
75 perror(proc_name);
76 throw vpException(vpException::fatalError, "Error in open_display");
77 }
78}
79
80/*
81 * La procedure "close_display" libere les variables utilisees par le mode
82 * "display".
83 */
84void close_display(void)
85{
86 free((char *)point2i);
87 free((char *)listpoint2i);
88 free((char *)rename_jlc);
89 point2i = (Point2i *)NULL;
90 listpoint2i = (Point2i *)NULL;
91 rename_jlc = (int *)NULL;
92}
93
94/*
95 * La procedure "point_3D_2D" projette les points 3D du volume canonique
96 * dans l'espace image 2D.
97 *
98 * Volume canonique Espace image
99 * ________________ ____________
100 *
101 * - 1 < X < 1 0 < X < xsize
102 * - 1 < Y < 1 0 < Y < ysize
103 * 0 < Z < 1
104 *
105 * Z < 0 X = 0, Y = -1 non significatifs.
106 *
107 * Entree :
108 * p3 Tableau de points 3D a projeter.
109 * size Taille du tableau de points "p3".
110 * xsize, ysize Tailles de l'espace image.
111 * p2 Tableau de points 2D en sortie.
112 */
113// static
114void point_3D_2D(Point3f *p3, Index size, int xsize, int ysize, Point2i *p2)
115{
116 Point3f *pend = p3 + size; /* borne de p3 */
117 float xdiv2 = static_cast<float>(xsize) / 2.0f;
118 float ydiv2 = static_cast<float>(ysize) / 2.0f;
119
120 for (; p3 < pend; p3++, p2++) {
121 p2->x = static_cast<int>((1.0 + p3->x) * xdiv2);
122 p2->y = static_cast<int>((1.0 - p3->y) * ydiv2);
123 }
124}
125
126/*
127 * La procedure "set_Bound_face_display" marque les faces affichables
128 * de la surface "bp".
129 * Soit la face comportant le contour oriente suivant : (...,P2,P0,P1...).
130 * La normale a la face au point P0 est obtenue par le produit vectoriel :
131 *
132 * | x1 - x0 x2 - x0 | | Nx |
133 * N = (P1 - P0) ^ (P2 - P0) = | y1 - y0 y2 - y0 | = | Ny |
134 * | z1 - z0 z2 - z0 | | Nz |
135 *
136 * La face est dans le volume canonique de vision et dans un repere gauche.
137 * L'observateur est situe a l'infini dans la direction [0, 0, -1].
138 * IS_ABOVE <=> Ny < 0, IS_BELOW <=> Ny > 0.
139 * IS_RIGHT <=> Nx < 0, IS_LEFT <=> Nx > 0.
140 * IS_BACK <=> Nz < 0, IS_FRONT <=> Nz > 0.
141 * Entree :
142 * bp Surface a initialiser.
143 * b Drapeaux indiquant les faces non affichables.
144 */
145void set_Bound_face_display(Bound *bp, Byte b)
146{
147 Face *fp = bp->face.ptr;
148 Face *fend = fp + bp->face.nbr;
149 Point3f *pp = bp->point.ptr;
150
151 for (; fp < fend; fp++) {
152 Index *vp;
153 Point3f *p0; /* premier sommet */
154 Point3f *p1; /* second sommet */
155 Point3f *p2; /* dernier sommet */
156
157 fp->is_visible = TRUE;
158 if (b == IS_INSIDE)
159 continue;
160 vp = fp->vertex.ptr;
161 p0 = pp + *vp;
162 p1 = pp + *(vp + 1);
163 p2 = pp + *(vp + fp->vertex.nbr - 1);
164 if (b & IS_ABOVE) {
165 fp->is_visible = ((p1->z - p0->z) * (p2->x - p0->x) >= (p1->x - p0->x) * (p2->z - p0->z));
166 }
167 if (!fp->is_visible)
168 continue;
169 if (b & IS_BELOW) {
170 fp->is_visible = ((p1->z - p0->z) * (p2->x - p0->x) <= (p1->x - p0->x) * (p2->z - p0->z));
171 }
172 if (!fp->is_visible)
173 continue;
174 if (b & IS_RIGHT) {
175 fp->is_visible = ((p1->y - p0->y) * (p2->z - p0->z) >= (p1->z - p0->z) * (p2->y - p0->y));
176 }
177 if (!fp->is_visible)
178 continue;
179 if (b & IS_LEFT) {
180 fp->is_visible = ((p1->y - p0->y) * (p2->z - p0->z) <= (p1->z - p0->z) * (p2->y - p0->y));
181 }
182 if (!fp->is_visible)
183 continue;
184 if (b & IS_BACK) {
185 fp->is_visible = ((p1->x - p0->x) * (p2->y - p0->y) >= (p1->y - p0->y) * (p2->x - p0->x));
186 }
187 if (!fp->is_visible)
188 continue;
189 if (b & IS_FRONT) {
190 fp->is_visible = ((p1->x - p0->x) * (p2->y - p0->y) <= (p1->y - p0->y) * (p2->x - p0->x));
191 }
192 }
193}
194
195/*
196 * La procedure "wireframe_Face" affiche une face "fp" en "fil de fer".
197 * sur la fenetre graphique de "suncgi" sur "SUN".
198 * Les points des sommets de la face sont contenu dans les points "pp"
199 * de la surface contenant la face.
200 * Entree :
201 * fp face a afficher.
202 * pp Points de la surface contenant la face.
203 */
204void wireframe_Face(Face *fp, Point2i *pp)
205{
206 // extern Window id_window;
207
208 Index *vp = fp->vertex.ptr;
209 Index *vend = vp + fp->vertex.nbr;
210 Point2i *cp = listpoint2i;
211
212 if (fp->vertex.nbr < 2)
213 return;
214 if (fp->vertex.nbr > 50) {
215 printf("pb malloc listpoint2i (display.c)\n");
216 return;
217 }
218 for (; vp < vend; vp++, cp++) {
219 SET_COORD2(*cp, pp[*vp].x, pp[*vp].y);
220 }
221}
222END_VISP_NAMESPACE
223#endif
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ fatalError
Fatal error.
Definition vpException.h:72