Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpVwstack.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 "vwstack.c" contient les procedures de gestion
32 * de la pile des points de vue (VieW STACK).
33 *
34 * Authors:
35 * Jean-Luc CORRE
36 */
37
38#include <visp3/core/vpConfig.h>
39
40#ifndef DOXYGEN_SHOULD_SKIP_THIS
41
42#include <cmath> // std::fabs()
43#include <limits>
44#include <stdarg.h>
45#include <stdio.h>
46#include <string.h>
47
48#include "vpArit.h"
49#include "vpMy.h"
50#include "vpView.h"
51#include "vpVwstack.h"
52
53#define STACKSIZE 4
54
56static View_parameters stack[STACKSIZE] = { vpDEFAULT_VIEW };
57static View_parameters *sp = stack;
58
59/*
60 * La procedure "fprintf_vwstack" affiche un parametre du sommet
61 * de la pile des prises de vue.
62 * Entree :
63 * fp Fichier de sortie.
64 * argv Argument a afficher.
65 * Si argv est nul, tous les parametres sont affiches.
66 */
67void fprintf_vwstack(FILE *fp, char *argv)
68{
69 if (argv == NULL || strcmp(argv, "type") == 0) {
70 const char *typetoa;
71
72 switch (sp->type) {
73 case PARALLEL:
74 typetoa = "parallel";
75 break;
76 case PERSPECTIVE:
77 typetoa = "perspective";
78 break;
79 default:
80 typetoa = "unknown";
81 break;
82 }
83 fprintf(fp, "(type\t%s)\n", typetoa);
84 if (argv != NULL)
85 return;
86 }
87 if (argv == NULL || strcmp(argv, "cop") == 0) {
88 fprintf(fp, "(cop\t%.3f\t%.3f\t%.3f)\n", sp->cop.x, sp->cop.y, sp->cop.z);
89 if (argv != NULL)
90 return;
91 }
92 if (argv == NULL || strcmp(argv, "vrp") == 0) {
93 fprintf(fp, "(vrp\t%.3f\t%.3f\t%.3f)\n", sp->vrp.x, sp->vrp.y, sp->vrp.z);
94 if (argv != NULL)
95 return;
96 }
97 if (argv == NULL || strcmp(argv, "vpn") == 0) {
98 fprintf(fp, "(vpn\t%.3f\t%.3f\t%.3f)\n", sp->vpn.x, sp->vpn.y, sp->vpn.z);
99 if (argv != NULL)
100 return;
101 }
102 if (argv == NULL || strcmp(argv, "vup") == 0) {
103 fprintf(fp, "(vup\t%.3f\t%.3f\t%.3f)\n", sp->vup.x, sp->vup.y, sp->vup.z);
104 if (argv != NULL)
105 return;
106 }
107 if (argv == NULL || strcmp(argv, "window") == 0) {
108 fprintf(fp, "(window\t%.3f\t%.3f\t%.3f\t%.3f)\n", sp->vwd.umin, sp->vwd.umax, sp->vwd.vmin, sp->vwd.vmax);
109 if (argv != NULL)
110 return;
111 }
112 if (argv == NULL || strcmp(argv, "depth") == 0) {
113 fprintf(fp, "(depth\t%.3f\t%.3f)\n", sp->depth.front, sp->depth.back);
114 if (argv != NULL)
115 return;
116 }
117 if (argv != NULL) {
118 static char proc_name[] = "fprintf_vwstack";
119 fprintf(stderr, "%s: argument unknown\n", proc_name);
120 }
121}
122
123/*
124 * La procedure "get_vwstack" retourne le point de vue au sommet
125 * de la pile des points de vue.
126 * Sortie :
127 * Pointeur sur le point de vue du sommet de la pile.
128 */
129View_parameters *get_vwstack(void) { return (sp); }
130
131/*
132 * La procedure "load_vwstack" charge un point de vue au sommet
133 * de la pile des points de vue.
134 * Entree :
135 * vp Point de vue a charger.
136 */
137void load_vwstack(View_parameters *vp) { *sp = *vp; }
138
139/*
140 * La procedure "pop_vwstack" depile le point de vue au sommet
141 * de la pile des points de vue.
142 */
143void pop_vwstack(void)
144{
145 if (sp == stack) {
146 static char proc_name[] = "pop_vwstack";
147 fprintf(stderr, "%s: stack underflow\n", proc_name);
148 return;
149 }
150 else
151 sp--;
152}
153
154/*
155 * La procedure "push_vwstack" empile et duplique le point de vue au sommet
156 * de la pile des points de vue.
157 */
158void push_vwstack(void)
159{
160 if (sp == stack + STACKSIZE - 1) {
161 static char proc_name[] = "push_vwstack";
162 fprintf(stderr, "%s: stack overflow\n", proc_name);
163 return;
164 }
165 sp++;
166 *sp = *(sp - 1);
167}
168
169/*
170 * La procedure "swap_vwstack" echange les deux premiers elements
171 * de la pile des points de vue.
172 */
173void swap_vwstack(void)
174{
175 View_parameters *vp, tmp;
176
177 vp = (sp == stack) ? sp + 1 : sp - 1;
178 SWAP(*sp, *vp, tmp);
179}
180
181/*
182 * La procedure "add_vwstack" modifie un agrument du point de vue au sommet
183 * de la pile des points de vue.
184 * Entree :
185 * va_alist Nom de l'argument a modifier suivi de ses parametres.
186 */
187
188void add_vwstack(const char *path, ...)
189// add_vwstack (va_alist)
190// va_dcl
191{
192 va_list ap;
193 char *argv;
194
195 va_start(ap, path);
196 argv = va_arg(ap, char *);
197 if (strcmp(argv, "cop") == 0) {
198 /* initialise le centre de projection */
199 SET_COORD3(sp->cop, static_cast<float>(va_arg(ap, double)), static_cast<float>(va_arg(ap, double)), static_cast<float>(va_arg(ap, double)));
200 }
201 else if (strcmp(argv, "depth") == 0) {
202 /* initialise les distances des plans de decoupage */
203 sp->depth.front = static_cast<float>(va_arg(ap, double));
204 sp->depth.back = static_cast<float>(va_arg(ap, double));
205 }
206 else if (strcmp(argv, "type") == 0) {
207 /* initialise le type de projection */
208 sp->type = (Type)va_arg(ap, int);
209 }
210 else if (strcmp(argv, "vpn") == 0) {
211 /* initialise le vecteur normal au plan */
212 float x = static_cast<float>(va_arg(ap, double));
213 float y = static_cast<float>(va_arg(ap, double));
214 float z = static_cast<float>(va_arg(ap, double));
215
216 // if (x == 0 && y == 0 && z == 0)
217 if (std::fabs(x) <= std::numeric_limits<double>::epsilon() &&
218 std::fabs(y) <= std::numeric_limits<double>::epsilon() &&
219 std::fabs(z) <= std::numeric_limits<double>::epsilon()) {
220 static char proc_name[] = "add_vwstack";
221 fprintf(stderr, "%s: bad vpn\n", proc_name);
222 }
223 else {
224 SET_COORD3(sp->vpn, x, y, z);
225 }
226 }
227 else if (strcmp(argv, "vrp") == 0) {
228 /* initialise le vecteur de reference */
229 SET_COORD3(sp->vrp, static_cast<float>(va_arg(ap, double)), static_cast<float>(va_arg(ap, double)), static_cast<float>(va_arg(ap, double)));
230 }
231 else if (strcmp(argv, "vup") == 0) {
232 /* initialise le vecteur haut du plan */
233 float x = static_cast<float>(va_arg(ap, double));
234 float y = static_cast<float>(va_arg(ap, double));
235 float z = static_cast<float>(va_arg(ap, double));
236
237 // if (x == 0 && y == 0 && z == 0)
238 if (std::fabs(x) <= std::numeric_limits<double>::epsilon() &&
239 std::fabs(y) <= std::numeric_limits<double>::epsilon() &&
240 std::fabs(z) <= std::numeric_limits<double>::epsilon()) {
241 static char proc_name[] = "add_vwstack";
242 fprintf(stderr, "%s: bad vup\n", proc_name);
243 }
244 else {
245 SET_COORD3(sp->vup, x, y, z);
246 }
247 }
248 else if (strcmp(argv, "window") == 0) {
249 /* initialise la fenetre de projection */
250 sp->vwd.umin = static_cast<float>(va_arg(ap, double));
251 sp->vwd.umax = static_cast<float>(va_arg(ap, double));
252 sp->vwd.vmin = static_cast<float>(va_arg(ap, double));
253 sp->vwd.vmax = static_cast<float>(va_arg(ap, double));
254 }
255 else {
256 static char proc_name[] = "add_vwstack";
257 fprintf(stderr, "%s: bad argument\n", proc_name);
258 }
259 va_end(ap);
260}
261END_VISP_NAMESPACE
262#endif