Changeset 457 for trunk/Source/System/NodeCores/Drawables/Geometry/Util/OSGGeoStatsAttachmentTest.cpp
- Timestamp:
- 12/24/06 07:27:43 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Source/System/NodeCores/Drawables/Geometry/Util/OSGGeoStatsAttachmentTest.cpp
r448 r457 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 \*---------------------------------------------------------------------------*/ 1 36 2 37 #include <UnitTest++.h> … … 18 53 { 19 54 GeoBuilder b; 20 55 21 56 root = makeNodeFor(Group::create()); 22 57 geos0Node = makeNodeFor(Group::create()); 23 58 24 59 root->addChild(geos0Node); 25 60 26 61 // Test geometry 0: a single triangle 27 62 b.begin(GL_TRIANGLES); … … 30 65 b.vertex(Vec3f(0,1,0)); 31 66 b.end(); 32 67 33 68 geos[0] = b.getGeometry(); 34 69 geoVertices[0] = 3; … … 38 73 geoProcessedAttributeBytes[0] = 3*sizeof(Vec3f); 39 74 geoStoredAttributeBytes[0] = 3*sizeof(Vec3f); 40 75 41 76 nodes[0] = makeNodeFor(geos[0]); 42 77 geos0Node->addChild(nodes[0]); // Add a second level 43 78 44 79 // Test geometry 1: a triangle and a quad 45 80 b.reset(); … … 53 88 b.vertex(Vec3f(3,2,0)); 54 89 b.vertex(Vec3f(2,2,0)); 55 90 56 91 b.tri(0); 57 92 b.quad(3); 58 93 59 94 geos[1] = b.getGeometry(); 60 95 geoVertices[1] = 7; … … 64 99 geoProcessedAttributeBytes[1] = 7*sizeof(Vec3f); 65 100 geoStoredAttributeBytes[1] = 7*sizeof(Vec3f); 66 101 67 102 nodes[1] = makeNodeFor(geos[1]); 68 103 root->addChild(nodes[1]); 69 104 70 105 // Test geometry 2: Sharing some vertices 71 106 b.reset(); … … 77 112 b.vertex(Vec3f(2,1,0)); 78 113 b.vertex(Vec3f(3,0,0)); 79 114 80 115 b.tri(0); 81 116 b.quad(1); 82 117 83 118 geos[2] = b.getGeometry(); 84 119 geoVertices[2] = 7; … … 88 123 geoProcessedAttributeBytes[2] = 7*sizeof(Vec3f); 89 124 geoStoredAttributeBytes[2] = 5*sizeof(Vec3f); 90 125 91 126 nodes[2] = makeNodeFor(geos[2]); 92 127 root->addChild(nodes[2]); 93 128 94 129 commitChanges(); 95 96 sumVertices = sumPoints = sumLines = sumTriangles = 130 131 sumVertices = sumPoints = sumLines = sumTriangles = 97 132 sumProcessedAttributeBytes = sumStoredAttributeBytes = 0; 98 133 99 134 for(UInt32 i = 0; i < nGeos; ++i) 100 135 { … … 105 140 sumProcessedAttributeBytes += geoProcessedAttributeBytes[i]; 106 141 sumStoredAttributeBytes += geoStoredAttributeBytes[i]; 107 142 108 143 } 109 144 } 110 145 111 146 ~GSAFixture() 112 147 { 113 148 } 114 149 115 150 // Number of test geometries 116 151 static const int nGeos = 3; 117 152 118 153 // Test Geometries, see above 119 154 RefPtr<GeometryPtr> geos[nGeos]; 120 155 121 156 // Stats Data for test geometries 122 157 UInt32 geoVertices[nGeos]; … … 126 161 UInt32 geoProcessedAttributeBytes[nGeos]; 127 162 UInt32 geoStoredAttributeBytes[nGeos]; 128 163 129 164 // Summed stats data 130 165 UInt32 sumVertices; … … 134 169 UInt32 sumProcessedAttributeBytes; 135 170 UInt32 sumStoredAttributeBytes; 136 171 137 172 // Nodes for tree test 138 173 RefPtr<NodePtr> nodes[nGeos]; … … 148 183 RefPtr<GeoStatsAttachmentPtr> st; 149 184 st = GeoStatsAttachment::calcStatic(g); 150 185 151 186 CHECK_EQUAL(geoVertices[i], st->getVertices()); 152 187 CHECK_EQUAL(geoPoints[i], st->getPoints()); … … 161 196 { 162 197 RefPtr<GeoStatsAttachmentPtr> sum; 163 198 164 199 sum = GeoStatsAttachment::create(); 165 200 166 201 UInt32 v = 0,p = 0,l = 0,t = 0,pb = 0,sb = 0; 167 202 168 203 for(int i = 0; i < nGeos; ++i) 169 204 { … … 173 208 //sum += st; 174 209 sum->operator+=(st); 175 210 176 211 v += st->getVertices(); 177 212 p += st->getPoints(); … … 181 216 sb += st->getStoredAttributeBytes(); 182 217 } 183 218 184 219 CHECK_EQUAL(v, sum->getVertices()); 185 220 CHECK_EQUAL(p, sum->getPoints()); … … 187 222 CHECK_EQUAL(t, sum->getTriangles()); 188 223 CHECK_EQUAL(pb, sum->getProcessedAttributeBytes()); 189 CHECK_EQUAL(sb, sum->getStoredAttributeBytes()); 190 224 CHECK_EQUAL(sb, sum->getStoredAttributeBytes()); 225 191 226 //sum -= sum; 192 227 sum->operator-=(sum); … … 196 231 CHECK_EQUAL(sum->getTriangles(), 0); 197 232 CHECK_EQUAL(sum->getProcessedAttributeBytes(), 0); 198 CHECK_EQUAL(sum->getStoredAttributeBytes(), 0); 199 233 CHECK_EQUAL(sum->getStoredAttributeBytes(), 0); 234 200 235 } 201 236 … … 203 238 { 204 239 GeoStatsAttachment::addTo(geos[0]); 205 206 RefPtr<GeoStatsAttachmentPtr> st; 207 st = GeoStatsAttachment::get(geos[0]); 208 240 241 RefPtr<GeoStatsAttachmentPtr> st; 242 st = GeoStatsAttachment::get(geos[0]); 243 209 244 CHECK(st != NullFC); 210 245 … … 222 257 { 223 258 GeoStatsAttachmentPtr st; 224 259 225 260 st = GeoStatsAttachment::get(geos[0]); 226 261 CHECK(st == NullFC); 227 262 228 263 GeoStatsAttachment::addTo(geos[0]); 229 230 st = GeoStatsAttachment::get(geos[0]); 231 264 265 st = GeoStatsAttachment::get(geos[0]); 266 232 267 CHECK(st != NullFC); 233 268 } … … 236 271 { 237 272 GeoStatsAttachment::addTo(geos[0]); 238 239 RefPtr<GeoStatsAttachmentPtr> st; 240 st = GeoStatsAttachment::get(geos[0]); 241 242 CHECK(st != NullFC); 243 273 274 RefPtr<GeoStatsAttachmentPtr> st; 275 st = GeoStatsAttachment::get(geos[0]); 276 277 CHECK(st != NullFC); 278 244 279 st->attachTo(geos[1]); 245 280 246 281 st = GeoStatsAttachment::get(geos[0]); 247 282 248 CHECK(st == NullFC); // Removed from old one? 283 CHECK(st == NullFC); // Removed from old one? 249 284 250 285 st = GeoStatsAttachment::get(geos[1]); 251 286 252 CHECK(st != NullFC); // Attached to new one? 253 254 CHECK_EQUAL(st->getValid(), false); // Should be invalid now 255 256 st->validate(); 257 258 CHECK_EQUAL(st->getValid(), true); // Should be valid now 287 CHECK(st != NullFC); // Attached to new one? 288 289 CHECK_EQUAL(st->getValid(), false); // Should be invalid now 290 291 st->validate(); 292 293 CHECK_EQUAL(st->getValid(), true); // Should be valid now 259 294 260 295 CHECK_EQUAL(geoVertices[1], st->getVertices()); … … 269 304 { 270 305 GeoStatsAttachment::addTo(nodes[0]); 271 306 272 307 RefPtr<GeoStatsAttachmentPtr> st; 273 308 st = GeoStatsAttachment::get(nodes[0]); … … 287 322 // Add to multiple tree levels 288 323 TEST_FIXTURE(GSAFixture, AddToGroupNodes) 289 { 324 { 290 325 GeoStatsAttachment::addTo(geos0Node); 291 326 GeoStatsAttachment::addTo(nodes[0]); 292 327 293 328 RefPtr<GeoStatsAttachmentPtr> st; 294 329 st = GeoStatsAttachment::get(geos0Node); … … 308 343 // Add to one tree level, should update all lower levels automatically 309 344 TEST_FIXTURE(GSAFixture, AddToGroupNode) 310 { 345 { 311 346 GeoStatsAttachment::addTo(geos0Node); 312 347 313 348 RefPtr<GeoStatsAttachmentPtr> st; 314 349 st = GeoStatsAttachment::get(geos0Node); … … 328 363 // Automatic Invalidation 329 364 TEST_FIXTURE(GSAFixture, AutoInvalidateGeometryOnChange) 330 { 365 { 331 366 GeoStatsAttachment::addTo(geos[0]); 332 333 RefPtr<GeoStatsAttachmentPtr> st; 334 st = GeoStatsAttachment::get(geos[0]); 335 336 CHECK(st != NullFC); 337 338 st->validate(); 339 367 368 RefPtr<GeoStatsAttachmentPtr> st; 369 st = GeoStatsAttachment::get(geos[0]); 370 371 CHECK(st != NullFC); 372 373 st->validate(); 374 340 375 commitChanges(); 341 376 … … 346 381 CHECK_EQUAL(geoProcessedAttributeBytes[0], st->getProcessedAttributeBytes()); 347 382 CHECK_EQUAL(geoStoredAttributeBytes[0], st->getStoredAttributeBytes()); 348 383 349 384 geos[0]->getTypes()->push_back(GL_LINE_STRIP); 350 385 geos[0]->getLengths()->push_back(3); … … 352 387 geos[0]->getIndex(0)->push_back(1); 353 388 geos[0]->getIndex(0)->push_back(2); 354 389 355 390 commitChanges(); 356 391 357 392 CHECK_EQUAL(st->getValid(), false); 358 393 359 394 st->validate(); 360 395 361 396 CHECK_EQUAL(st->getValid(), true); 362 397 363 398 CHECK_EQUAL(geoVertices[0] + 3, st->getVertices()); 364 399 CHECK_EQUAL(geoPoints[0], st->getPoints()); 365 400 CHECK_EQUAL(geoLines[0] + 2, st->getLines()); 366 401 CHECK_EQUAL(geoTriangles[0], st->getTriangles()); 367 CHECK_EQUAL(geoProcessedAttributeBytes[0] + sizeof(Vec3f) * 3, 402 CHECK_EQUAL(geoProcessedAttributeBytes[0] + sizeof(Vec3f) * 3, 368 403 st->getProcessedAttributeBytes()); 369 CHECK_EQUAL(geoStoredAttributeBytes[0], st->getStoredAttributeBytes()); 404 CHECK_EQUAL(geoStoredAttributeBytes[0], st->getStoredAttributeBytes()); 370 405 } 371 406 372 407 // Automatic Invalidation 373 408 TEST_FIXTURE(GSAFixture, AutoInvalidateNodeOnChange) 374 { 409 { 375 410 GeoStatsAttachment::addTo(nodes[0]); 376 411 377 412 RefPtr<GeoStatsAttachmentPtr> st; 378 413 st = GeoStatsAttachment::get(nodes[0]); … … 381 416 382 417 st->validate(); 383 418 384 419 commitChanges(); 385 420 … … 390 425 CHECK_EQUAL(geoProcessedAttributeBytes[0], st->getProcessedAttributeBytes()); 391 426 CHECK_EQUAL(geoStoredAttributeBytes[0], st->getStoredAttributeBytes()); 392 427 393 428 geos[0]->getTypes()->push_back(GL_LINE_STRIP); 394 429 geos[0]->getLengths()->push_back(3); … … 396 431 geos[0]->getIndex(0)->push_back(1); 397 432 geos[0]->getIndex(0)->push_back(2); 398 433 399 434 commitChanges(); 400 435 401 436 CHECK_EQUAL(st->getValid(), false); 402 437 403 438 st->validate(); 404 439 405 440 CHECK_EQUAL(st->getValid(), true); 406 441 407 442 CHECK_EQUAL(geoVertices[0] + 3, st->getVertices()); 408 443 CHECK_EQUAL(geoPoints[0], st->getPoints()); 409 444 CHECK_EQUAL(geoLines[0] + 2, st->getLines()); 410 445 CHECK_EQUAL(geoTriangles[0], st->getTriangles()); 411 CHECK_EQUAL(geoProcessedAttributeBytes[0] + sizeof(Vec3f) * 3, 446 CHECK_EQUAL(geoProcessedAttributeBytes[0] + sizeof(Vec3f) * 3, 412 447 st->getProcessedAttributeBytes()); 413 CHECK_EQUAL(geoStoredAttributeBytes[0], st->getStoredAttributeBytes()); 448 CHECK_EQUAL(geoStoredAttributeBytes[0], st->getStoredAttributeBytes()); 414 449 } 415 450 416 451 // Hierarchical Invalidation 417 452 TEST_FIXTURE(GSAFixture, AutoInvalidateHierarchy) 418 { 453 { 419 454 RefPtr<GeoStatsAttachmentPtr> st; 420 455 st = GeoStatsAttachment::get(root); … … 426 461 427 462 CHECK(st != NullFC); 428 463 429 464 st->validate(); 430 465 … … 435 470 CHECK_EQUAL(sumProcessedAttributeBytes, st->getProcessedAttributeBytes()); 436 471 CHECK_EQUAL(sumStoredAttributeBytes, st->getStoredAttributeBytes()); 437 472 438 473 geos[0]->getTypes()->push_back(GL_LINE_STRIP); 439 474 geos[0]->getLengths()->push_back(3); … … 441 476 geos[0]->getIndex(0)->push_back(1); 442 477 geos[0]->getIndex(0)->push_back(2); 443 478 444 479 commitChanges(); 445 480 446 481 CHECK_EQUAL(false, st->getValid()); 447 482 448 483 st->validate(); 449 484 450 485 CHECK_EQUAL(true, st->getValid()); 451 486 452 487 CHECK_EQUAL(sumVertices + 3, st->getVertices()); 453 488 CHECK_EQUAL(sumPoints, st->getPoints()); 454 489 CHECK_EQUAL(sumLines + 2, st->getLines()); 455 490 CHECK_EQUAL(sumTriangles, st->getTriangles()); 456 CHECK_EQUAL(sumProcessedAttributeBytes + sizeof(Vec3f) * 3, 491 CHECK_EQUAL(sumProcessedAttributeBytes + sizeof(Vec3f) * 3, 457 492 st->getProcessedAttributeBytes()); 458 CHECK_EQUAL(sumStoredAttributeBytes, st->getStoredAttributeBytes()); 459 } 460 461 } 493 CHECK_EQUAL(sumStoredAttributeBytes, st->getStoredAttributeBytes()); 494 } 495 496 } // SUITE
