Debian Codegraph @

test/checklmio.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2004-2013 Gert Wollny <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * As an exception to this license, "NEC C&C Research Labs" may use
19 * this software under the terms of the GNU Lesser General Public License as
20 * published by the Free Software Foundation.
21 *
22 */
23
24 #include "mialm.h"
25 #include <math.h>
26
27 #include <math.h>
28 #include <string.h>
29
30 #ifndef NDEBUG
31 extern void print_vectors_left(void);
32 extern void print_quats_left(void);
33 extern void print_camera_left(void);
34 #endif
35
36 gboolean
37 mia_vector3d_test (void)
38 {
39 gboolean result = FALSE;
40 gfloat f;
41 const float sqrt14 = sqrt(14.0f);
42 MiaVector3d *dup;
43 MiaVector3d *test = mia_vector3d_new (1.0, 2.0, 3.0);
44 MiaVector3d *test2 = mia_vector3d_new (2.0, 5.0, 7.0);
45
46 g_return_val_if_fail (test, FALSE);
47 g_return_val_if_fail (test2, FALSE);
48
49 g_assert(MIA_IS_VECTOR3D (test));
50 g_assert(test->x == 1.0 && test->y == 2.0 && test->z == 3.0);
51
52 dup = mia_vector3d_dup(test);
53 g_assert(MIA_IS_VECTOR3D (dup));
54 g_assert(mia_vector3d_equal(test, dup));
55
56
57
58 mia_vector3d_addup(test, test2);
59 g_assert(test->x == 3.0 && test->y == 7.0 && test->z == 10.0);
60
61 mia_vector3d_scale(test, 0.5);
62 g_assert(test->x == 1.5 && test->y == 3.5 && test->z == 5.0);
63
64 g_assert(mia_vector3d_dot(dup,test2) == 33.0);
65
66 f = mia_vector3d_get_norm (dup);
67
68 g_assert(fabs(f - sqrt(14.0)) < 1e-5);
69
70 mia_vector3d_normalize (dup);
71
72 f = mia_vector3d_get_norm(dup);
73 g_assert( fabs(f - 1.0f) < 1e-5 );
74
75
76 g_assert(fabs (dup->x - (1.0f / sqrt14)) < 1e-5 &&
77 fabs (dup->y - (2.0f / sqrt14)) < 1e-5 &&
78 fabs (dup->z - (3.0f / sqrt14)) < 1e-5 );
79
80
81 mia_vector3d_copy(dup, test2);
82 g_assert(dup->x == 2.0 && dup->y == 5.0 && dup->z == 7.0);
83
84 mia_vector3d_add(test, test2, dup);
85 g_assert(dup->x == 3.5 && dup->y == 8.5 && dup->z == 12.0);
86
87 g_object_unref (G_OBJECT (dup));
88
89 dup = mia_vector3d_add(test, test2, NULL);
90 g_assert(dup->x == 3.5 && dup->y == 8.5 && dup->z == 12.0);
91
92 g_object_unref (G_OBJECT (test));
93 g_object_unref (G_OBJECT (test2));
94 g_object_unref (G_OBJECT (dup));
95 return result;
96 }
97
98
99 MiaCamera *
100 create_camera ()
101 {
102 MiaVector3d *cloc;
103 MiaQuaternion *crot;
104
105 cloc = mia_vector3d_new (10.1, -20.2, 400.1);
106 crot = mia_quaternion_new (12.1,0.543, 13.3, 1.4);
107 return mia_camera_new (cloc, crot, 20.12);
108 }
109
110 MiaLandmark *
111 create_landmark (gchar *name)
112 {
113 MiaCamera *camera = create_camera ();
114 MiaVector3d *loc = mia_vector3d_new (-11.34, 21.12, -50.20);
115
116 return mia_landmark_new (name,loc, 128.7, camera, "picfile.jpg");
117 }
118
119
120
121 gboolean
122 compare_camera (MiaCamera * c1, MiaCamera * c2)
123 {
124 if (!mia_vector3d_equal (mia_camera_get_location (c1),
125 mia_camera_get_location (c2)))
126 return FALSE;
127 if (!mia_quaternion_equal (mia_camera_get_rotation (c1),
128 mia_camera_get_rotation (c2)))
129 return FALSE;
130 return mia_camera_get_zoom (c1) == mia_camera_get_zoom (c2);
131 }
132
133 gboolean
134 compare_landmarks (MiaLandmark * lm1, MiaLandmark * lm2)
135 {
136 if (mia_landmark_get_iso_value (lm1) !=
137 mia_landmark_get_iso_value (lm2))
138 return FALSE;
139
140 if (!mia_vector3d_equal (mia_landmark_get_location (lm1),
141 mia_landmark_get_location (lm2)))
142 return FALSE;
143 if (!compare_camera (mia_landmark_get_camera (lm1),
144 mia_landmark_get_camera (lm2)))
145 return FALSE;
146 if (strcmp (mia_landmark_get_picfile (lm1),
147 mia_landmark_get_picfile (lm2)))
148 return FALSE;
149 return !strcmp (mia_landmark_get_name (lm1),
150 mia_landmark_get_name (lm2));
151 }
152
153 void check_camera(void)
154 {
155 MiaCamera *c = create_camera ();
156 g_object_unref(c);
157 #ifndef NDEBUG
158 print_vectors_left();
159 print_quats_left();
160 print_camera_left();
161 #endif
162 }
163
164 void check_landmark(void)
165 {
166 MiaLandmark *lm = create_landmark("test");
167 g_object_unref(lm);
168 #ifndef NDEBUG
169 print_vectors_left();
170 print_quats_left();
171 print_camera_left();
172 #endif
173 }
174
175
176 void check_landmarklist(void)
177 {
178 MiaLandmark *lm;
179 MiaLandmarklist *lml = mia_landmarklist_new ("P1TEST");
180
181 lm = create_landmark("A");
182 mia_landmarklist_insert(lml, lm);
183 lm = create_landmark("B");
184 mia_landmarklist_insert(lml, lm);
185
186 g_object_unref(lml);
187 #ifndef NDEBUG
188 print_vectors_left();
189 print_quats_left();
190 print_camera_left();
191 #endif
192 }
193
194
195 int
196 main (int UNUSED(argc), char **UNUSED(args))
197 {
198 MiaLandmarklist *lml1;
199 MiaLandmarklist *lml2;
200 MiaLandmark *lm;
201 MiaLandmark *lm2;
202 const gchar *lmname;
203
204 g_type_init ();
205
206 check_camera();
207 check_landmark();
208 check_landmarklist();
209
210 mia_vector3d_test();
211
212 lml1 = mia_landmarklist_new ("P1TEST");
213
214 lm = create_landmark ("Landmark 1");
215 lmname =mia_landmark_get_name(lm);
216
217 mia_landmarklist_insert(lml1, lm);
218
219 g_assert (mia_landmarklist_save (lml1, "lmtest.xml"));
220 lml2 = mia_landmarklist_new_from_file ("lmtest.xml");
221 g_assert (!strcmp (mia_landmarklist_get_name(lml1),
222 mia_landmarklist_get_name(lml2)));
223
224 lm2 = mia_landmarklist_get_landmark(lml2, lmname);
225 g_assert (compare_landmarks (lm, lm2));
226 g_object_unref (lml2);
227 g_object_unref (lml1);
228
229
230 /* be nice to valgrind */
231 xmlCleanupParser ();
232
233 #ifndef NDEBUG
234 print_vectors_left();
235 print_quats_left();
236 print_camera_left();
237 #endif
238
239
240 return 0;
241 }