changed: gcc8 base update
[opensg.git] / Source / System / NodeCores / Drawables / Geometry / Base / OSGGeometryTest.cpp
blob0a661e9359b7bb89539d4b2264631eb42d554f43
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
6 * *
7 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
8 * *
9 \*---------------------------------------------------------------------------*/
10 /*---------------------------------------------------------------------------*\
11 * License *
12 * *
13 * This library is free software; you can redistribute it and/or modify it *
14 * under the terms of the GNU Library General Public License as published *
15 * by the Free Software Foundation, version 2. *
16 * *
17 * This library is distributed in the hope that it will be useful, but *
18 * WITHOUT ANY WARRANTY; without even the implied warranty of *
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
20 * Library General Public License for more details. *
21 * *
22 * You should have received a copy of the GNU Library General Public *
23 * License along with this library; if not, write to the Free Software *
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
25 * *
26 \*---------------------------------------------------------------------------*/
27 /*---------------------------------------------------------------------------*\
28 * Changes *
29 * *
30 * *
31 * *
32 * *
33 * *
34 * *
35 \*---------------------------------------------------------------------------*/
37 #include <UnitTest++.h>
39 // Unit tests for vec classes
41 #include "OSGGeometry.h"
42 #include "OSGGeoVectorProperty.h"
43 #include "OSGGeoProperties.h"
44 #include "OSGFieldContainerFactory.h"
45 #include "OSGTypedGeoVectorProperty.h"
46 #include "OSGSimpleGeometry.h"
47 #include "OSGTransform.h"
49 SUITE(GeometryTests)
52 TEST(CreateGeometry)
54 OSG::GeometryUnrecPtr g = OSG::Geometry::create();
55 CHECK(g != NULL);
58 TEST(TestInitialValues)
60 OSG::GeometryUnrecPtr g = OSG::Geometry::create();
61 CHECK(g != NULL);
63 for(unsigned i=0;i<OSG::Geometry::MaxAttribs;i++)
65 CHECK(g->getProperty(i) == NULL);
66 CHECK(g->getIndex(i) == NULL);
69 CHECK(g->getMaterial() == NULL);
72 // Test using the generic vector interfaces on geometry
73 TEST(TestGenericInterfaces)
75 OSG::GeometryUnrecPtr g = OSG::Geometry::create();
76 CHECK(g != NULL);
78 OSG::GeoPnt3fPropertyUnrecPtr pnts = OSG::GeoPnt3fProperty ::create();
79 pnts->addValue(OSG::Pnt3f(0,0,0));
81 g->setPositions(pnts);
83 OSG::GeoVectorPropertyUnrecPtr pnts_g = g->getPositions();
84 pnts_g->setValue(OSG::Pnt3f(1,1,1), 0);
85 pnts_g->setValue(OSG::Pnt3s(1,1,1), 0);
86 pnts_g->setValue(OSG::Pnt2f(1,1 ), 0);
87 pnts_g->setValue(OSG::Vec3f(1,1,1), 0);
88 pnts_g->setValue(OSG::Vec2f(1,2 ), 0);
89 pnts_g->setValue(OSG::Vec4f(1,2,3,4), 0);
90 pnts_g->setValue(OSG::Color3f(1,2,3), 0);
91 pnts_g->setValue(OSG::Color4f(1,2,3,4), 0);
95 TEST(TestSettingVecAttribs)
97 // Test setting attributes to all possible value types
98 OSG::GeometryUnrecPtr g = OSG::Geometry::create();
99 CHECK(g != NULL);
101 // Copied-and-macroed from OSGTypedGeoVectorPropertyFields
102 const char* allowed_vec_prop_types[] =
104 "GeoVec1ubProperty",
105 "GeoVec2ubProperty",
106 "GeoVec3ubProperty",
107 "GeoVec4ubProperty",
109 "GeoPnt1ubProperty",
110 "GeoPnt2ubProperty",
111 "GeoPnt3ubProperty",
112 "GeoPnt4ubProperty",
114 "GeoVec1NubProperty",
115 "GeoVec2NubProperty",
116 "GeoVec3NubProperty",
117 "GeoVec4NubProperty",
119 "GeoPnt1NubProperty",
120 "GeoPnt2NubProperty",
121 "GeoPnt3NubProperty",
122 "GeoPnt4NubProperty",
125 "GeoVec1bProperty",
126 "GeoVec2bProperty",
127 "GeoVec3bProperty",
128 "GeoVec4bProperty",
130 "GeoPnt1bProperty",
131 "GeoPnt2bProperty",
132 "GeoPnt3bProperty",
133 "GeoPnt4bProperty",
135 "GeoVec1NbProperty",
136 "GeoVec2NbProperty",
137 "GeoVec3NbProperty",
138 "GeoVec4NbProperty",
140 "GeoPnt1NbProperty",
141 "GeoPnt2NbProperty",
142 "GeoPnt3NbProperty",
143 "GeoPnt4NbProperty",
146 "GeoVec1usProperty",
147 "GeoVec2usProperty",
148 "GeoVec3usProperty",
149 "GeoVec4usProperty",
151 "GeoPnt1usProperty",
152 "GeoPnt2usProperty",
153 "GeoPnt3usProperty",
154 "GeoPnt4usProperty",
156 "GeoVec1NusProperty",
157 "GeoVec2NusProperty",
158 "GeoVec3NusProperty",
159 "GeoVec4NusProperty",
161 "GeoPnt1NusProperty",
162 "GeoPnt2NusProperty",
163 "GeoPnt3NusProperty",
164 "GeoPnt4NusProperty",
167 "GeoVec1sProperty",
168 "GeoVec2sProperty",
169 "GeoVec3sProperty",
170 "GeoVec4sProperty",
172 "GeoPnt1sProperty",
173 "GeoPnt2sProperty",
174 "GeoPnt3sProperty",
175 "GeoPnt4sProperty",
177 "GeoVec1NsProperty",
178 "GeoVec2NsProperty",
179 "GeoVec3NsProperty",
180 "GeoVec4NsProperty",
182 "GeoPnt1NsProperty",
183 "GeoPnt2NsProperty",
184 "GeoPnt3NsProperty",
185 "GeoPnt4NsProperty",
187 "GeoVec1fProperty",
188 "GeoVec2fProperty",
189 "GeoVec3fProperty",
190 "GeoVec4fProperty",
192 "GeoPnt1fProperty",
193 "GeoPnt2fProperty",
194 "GeoPnt3fProperty",
195 "GeoPnt4fProperty",
197 "GeoVec1dProperty",
198 "GeoVec2dProperty",
199 "GeoVec3dProperty",
200 "GeoVec4dProperty",
202 "GeoPnt1dProperty",
203 "GeoPnt2dProperty",
204 "GeoPnt3dProperty",
205 "GeoPnt4dProperty",
207 "GeoColor3ubProperty",
208 "GeoColor4ubProperty",
209 "GeoColor3NubProperty",
210 "GeoColor4NubProperty",
212 "GeoColor3fProperty",
213 "GeoColor4fProperty"
216 OSG::GeoVectorPropertyUnrecPtr att;
218 unsigned num_vec_props = sizeof(allowed_vec_prop_types) / sizeof(char*);
220 for(unsigned i = 0; i < num_vec_props;++i)
222 att = OSG::dynamic_pointer_cast<OSG::GeoVectorProperty>(
223 OSG::FieldContainerFactory::the()->createContainer(
224 allowed_vec_prop_types[i]));
225 unsigned prop_index = i % 16;
226 g->setProperty(att,prop_index);
227 CHECK(true);
232 TEST(GeometryAsInnerNodesBoundingVolume)
234 // pNGeo0:[Geometry]
235 // |
236 // +-------------------------------------+
237 // | |
238 // pNTrans1:pTrans1[Transform] pNTran2:pTrans2[Transform]
239 // | |
240 // pNGeo1:[Geometry] pNGeo2:[Geometry]
242 OSG::NodeUnrecPtr pNGeo0 = OSG::makeBox(2.0, 2.0, 4.0, 1, 1, 1);
243 OSG::NodeUnrecPtr pNGeo1 = OSG::makeBox(2.0, 2.0, 2.0, 1, 1, 1);
244 OSG::NodeUnrecPtr pNGeo2 = OSG::makeBox(2.0, 2.0, 2.0, 1, 1, 1);
246 OSG::NodeUnrecPtr pNTrans1 = OSG::Node::create();
247 OSG::TransformUnrecPtr pTrans1 = OSG::Transform::create();
248 OSG::NodeUnrecPtr pNTrans2 = OSG::Node::create();
249 OSG::TransformUnrecPtr pTrans2 = OSG::Transform::create();
251 pNTrans1->setCore (pTrans1);
252 pNTrans1->addChild(pNGeo1 );
253 pNTrans2->setCore (pTrans2);
254 pNTrans2->addChild(pNGeo2 );
256 pNGeo0->addChild(pNTrans1);
257 pNGeo0->addChild(pNTrans2);
259 OSG::Matrix mat1;
260 OSG::Matrix mat2;
262 mat1.setTranslate(OSG::Vec3f( 3.0, 0.0, 0.0));
263 mat2.setTranslate(OSG::Vec3f(- 3.0, 0.0, 0.0));
265 pTrans1->editSFMatrix()->setValue(mat1);
266 pTrans2->editSFMatrix()->setValue(mat2);
268 OSG::commitChanges();
270 OSG::BoxVolume bbox;
271 OSG::Pnt3f min;
272 OSG::Pnt3f max;
274 pNGeo1->getWorldVolume(bbox);
275 bbox.getBounds(min, max);
277 CHECK_CLOSE( 2.0, min[0], 1e-6);
278 CHECK_CLOSE(-1.0, min[1], 1e-6);
279 CHECK_CLOSE(-1.0, min[2], 1e-6);
281 CHECK_CLOSE( 4.0, max[0], 1e-6);
282 CHECK_CLOSE( 1.0, max[1], 1e-6);
283 CHECK_CLOSE( 1.0, max[2], 1e-6);
285 pNGeo2->getWorldVolume(bbox);
286 bbox.getBounds(min, max);
288 CHECK_CLOSE(-4.0, min[0], 1e-6);
289 CHECK_CLOSE(-1.0, min[1], 1e-6);
290 CHECK_CLOSE(-1.0, min[2], 1e-6);
292 CHECK_CLOSE(-2.0, max[0], 1e-6);
293 CHECK_CLOSE( 1.0, max[1], 1e-6);
294 CHECK_CLOSE( 1.0, max[2], 1e-6);
296 pNGeo0->getWorldVolume(bbox);
297 bbox.getBounds(min, max);
299 CHECK_CLOSE(-4.0, min[0], 1e-6);
300 CHECK_CLOSE(-1.0, min[1], 1e-6);
301 CHECK_CLOSE(-2.0, min[2], 1e-6);
303 CHECK_CLOSE( 4.0, max[0], 1e-6);
304 CHECK_CLOSE( 1.0, max[1], 1e-6);
305 CHECK_CLOSE( 2.0, max[2], 1e-6);
308 } // SUITE