Changeset 683 for GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
- Timestamp:
- 03/09/06 04:27:07 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
r682 r683 2317 2317 Plane3 halfSpace = dynamic_cast<BspInterior *>(interior)->GetPlane(); 2318 2318 2319 if (interior->Get Front() != lastNode)2319 if (interior->GetBack() != lastNode) 2320 2320 halfSpace.ReverseOrientation(); 2321 2321 … … 2344 2344 2345 2345 2346 void BspTree::SetViewCellsManager(ViewCellsManager *vcm) 2347 { 2348 mViewCellsManager = vcm; 2349 } 2350 2351 2352 void BspTree::ConstructGeometry(BspNode *n, BspNodeGeometry &geom) const 2346 void BspTree::ConstructGeometry(BspNode *n, 2347 BspNodeGeometry &geom) const 2353 2348 { 2354 2349 vector<Plane3> halfSpaces; 2355 2350 ExtractHalfSpaces(n, halfSpaces); 2356 2351 2357 PolygonContainer candidate s;2352 PolygonContainer candidatePolys; 2358 2353 vector<Plane3> candidatePlanes; 2359 2354 2360 // bounded planes are added to the polygons (reverse polygons 2361 // as they have to be outfacing 2362 // comment: why is this? 2355 // bounded planes are added to the polygons 2363 2356 for (int i = 0; i < (int)halfSpaces.size(); ++ i) 2364 2357 { 2365 2358 Polygon3 *p = GetBoundingBox().CrossSection(halfSpaces[i]); 2366 2359 2367 2360 if (p->Valid(mEpsilon)) 2368 2361 { 2369 candidates.push_back(p->CreateReversePolygon()); 2370 2371 Plane3 candidatePlane = p->GetSupportingPlane();//halfSpaces[i]; 2372 //candidatePlane.ReverseOrientation(); 2373 candidatePlanes.push_back(candidatePlane); 2374 2375 DEL_PTR(p); 2362 candidatePolys.push_back(p); 2363 candidatePlanes.push_back(halfSpaces[i]); 2376 2364 } 2377 2365 } … … 2381 2369 { 2382 2370 VertexContainer vertices; 2383 2371 2384 2372 for (int j = 0; j < 4; ++ j) 2385 2373 vertices.push_back(mBox.GetFace(i).mVertices[j]); 2386 2374 2387 2375 Polygon3 *poly = new Polygon3(vertices); 2388 candidates.push_back(new Polygon3(vertices)); 2376 2377 candidatePolys.push_back(poly); 2389 2378 candidatePlanes.push_back(poly->GetSupportingPlane()); 2390 2379 } 2391 2380 2392 2393 for (int i = 0; i < (int)candidates.size(); ++ i) 2381 for (int i = 0; i < (int)candidatePolys.size(); ++ i) 2394 2382 { 2395 2383 // polygon is split by all other planes 2396 for (int j = 0; (j < (int)halfSpaces.size()) && candidate s[i]; ++ j)2384 for (int j = 0; (j < (int)halfSpaces.size()) && candidatePolys[i]; ++ j) 2397 2385 { 2398 2386 if (i == j) // polygon and plane are coincident … … 2402 2390 Polygon3 *frontPoly, *backPoly; 2403 2391 2404 const int cf = candidates[i]-> 2405 ClassifyPlane(halfSpaces[j], mEpsilon); 2406 2392 const int cf = 2393 candidatePolys[i]->ClassifyPlane(halfSpaces[j], 2394 mEpsilon); 2395 2407 2396 switch (cf) 2408 2397 { … … 2411 2400 backPoly = new Polygon3(); 2412 2401 2413 candidate s[i]->Split(halfSpaces[j],2414 *frontPoly,2415 *backPoly,2416 mEpsilon);2417 2418 DEL_PTR(candidate s[i]);2402 candidatePolys[i]->Split(halfSpaces[j], 2403 *frontPoly, 2404 *backPoly, 2405 mEpsilon); 2406 2407 DEL_PTR(candidatePolys[i]); 2419 2408 2420 2409 if (frontPoly->Valid(mEpsilon)) 2421 candidate s[i] = frontPoly;2410 candidatePolys[i] = frontPoly; 2422 2411 else 2423 2412 DEL_PTR(frontPoly); … … 2425 2414 DEL_PTR(backPoly); 2426 2415 break; 2427 case Polygon3::BACK_SIDE: 2428 DEL_PTR(candidates[i]); 2416 // polygon outside of halfspace 2417 case Polygon3::FRONT_SIDE: 2418 DEL_PTR(candidatePolys[i]); 2429 2419 break; 2430 2420 // just take polygon as it is 2431 case Polygon3:: FRONT_SIDE:2421 case Polygon3::BACK_SIDE: 2432 2422 case Polygon3::COINCIDENT: 2433 2423 default: … … 2435 2425 } 2436 2426 } 2437 2438 if (candidates[i]) 2439 { 2440 geom.Add(candidates[i], candidatePlanes[i]); 2441 // geom.mPolys.push_back(candidates[i]); 2442 } 2443 } 2427 2428 if (candidatePolys[i]) 2429 { 2430 geom.Add(candidatePolys[i], candidatePlanes[i]); 2431 // geom.mPolys.push_back(candidates[i]); 2432 } 2433 } 2434 } 2435 2436 2437 void BspTree::SetViewCellsManager(ViewCellsManager *vcm) 2438 { 2439 mViewCellsManager = vcm; 2444 2440 } 2445 2441 … … 2448 2444 2449 2445 2450 int BspTree::FindNeighbors(BspNode *n, vector<BspLeaf *> &neighbors, 2446 int BspTree::FindNeighbors(BspNode *n, vector<BspLeaf *> 2447 &neighbors, 2451 2448 const bool onlyUnmailed) const 2452 2449 { … … 2494 2491 mEpsilon); 2495 2492 2496 if (cf == Polygon3:: BACK_SIDE)2493 if (cf == Polygon3::FRONT_SIDE) 2497 2494 { 2498 2495 isAdjacent = false; … … 2513 2510 mEpsilon); 2514 2511 2515 if (cf == Polygon3:: BACK_SIDE)2512 if (cf == Polygon3::FRONT_SIDE) 2516 2513 { 2517 2514 isAdjacent = false; … … 2544 2541 interior->GetPlane(), 2545 2542 mBox, 2543 //0.0000001f); 2546 2544 mEpsilon); 2547 2545 2548 if (cf == Polygon3:: FRONT_SIDE)2546 if (cf == Polygon3::BACK_SIDE) 2549 2547 { 2550 nodeStack.push(bspNodePair(interior->Get Front(), fGeom));2551 DEL_PTR( bGeom);2548 nodeStack.push(bspNodePair(interior->GetBack(), bGeom)); 2549 DEL_PTR(fGeom); 2552 2550 } 2553 2551 else 2554 2552 { 2555 if (cf == Polygon3:: BACK_SIDE)2553 if (cf == Polygon3::FRONT_SIDE) 2556 2554 { 2557 nodeStack.push(bspNodePair(interior->Get Back(), bGeom));2558 DEL_PTR( fGeom);2555 nodeStack.push(bspNodePair(interior->GetFront(), fGeom)); 2556 DEL_PTR(bGeom); 2559 2557 } 2560 2558 else … … 2570 2568 2571 2569 return (int)neighbors.size(); 2572 }2573 2574 2575 BspLeaf *BspTree::GetRandomLeaf(const Plane3 &halfspace)2576 {2577 stack<BspNode *> nodeStack;2578 nodeStack.push(mRoot);2579 2580 int mask = rand();2581 2582 while (!nodeStack.empty())2583 {2584 BspNode *node = nodeStack.top();2585 nodeStack.pop();2586 2587 if (node->IsLeaf())2588 {2589 return dynamic_cast<BspLeaf *>(node);2590 }2591 else2592 {2593 BspInterior *interior = dynamic_cast<BspInterior *>(node);2594 BspNode *next;2595 2596 BspNodeGeometry geom;2597 // todo: not very efficient: constructs full cell everytime2598 ConstructGeometry(interior, geom);2599 2600 const int cf = Polygon3::ClassifyPlane(geom.GetPolys(),2601 halfspace,2602 mEpsilon);2603 2604 if (cf == Polygon3::BACK_SIDE)2605 next = interior->GetFront();2606 else2607 if (cf == Polygon3::FRONT_SIDE)2608 next = interior->GetFront();2609 else2610 {2611 // random decision2612 if (mask & 1)2613 next = interior->GetBack();2614 else2615 next = interior->GetFront();2616 mask = mask >> 1;2617 }2618 2619 nodeStack.push(next);2620 }2621 }2622 2623 return NULL;2624 2570 } 2625 2571 … … 3085 3031 splitsGeom = false; 3086 3032 3087 if (DotProd(mPlanes[i].mNormal, 3033 if (DotProd(mPlanes[i].mNormal, splitPlane.mNormal > 0)) 3088 3034 back.Add(new Polygon3(mPolys[i]->mVertices), mPlanes[i]); 3089 3035 else … … 3098 3044 if (planePoly) 3099 3045 { 3100 3046 // add polygon with reverse orientation to front cell 3101 3047 Plane3 reversePlane(splitPlane); 3102 3048 reversePlane.ReverseOrientation(); 3103 3049 3104 //Debug << "poly normal : " << ndummy << " split plane normal " << splitPlane.mNormal << endl;3105 3050 // add polygon with normal pointing into positive half space to back cell 3106 3051 back.Add(planePoly, splitPlane); 3107 3052 //back.mPolys.push_back(planePoly); 3053 3108 3054 Polygon3 *reversePoly = planePoly->CreateReversePolygon(); 3109 3055 front.Add(reversePoly, reversePlane); 3110 3056 Debug << "poly normal : " << reversePoly->GetSupportingPlane().mNormal << " split plane normal " << reversePlane.mNormal << endl; 3111 3057 } 3112 3058 else Debug << "err" << endl; 3113 3059 3114 3060 return splitsGeom; … … 3120 3066 { 3121 3067 if (!planePoly->Valid(epsilon)) 3068 { 3069 Debug << "not valid!!" << endl; 3122 3070 DEL_PTR(planePoly); 3123 3071 } 3124 3072 // polygon is split by all other planes 3125 3073 for (int i = 0; (i < (int)mPolys.size()) && planePoly; ++ i) 3126 3074 { 3127 #if 0 3128 Plane3 plane = mPolys[i]->GetSupportingPlane(); 3129 #else 3075 //Plane3 plane = mPolys[i]->GetSupportingPlane(); 3130 3076 Plane3 plane = mPlanes[i]; 3131 3132 #endif 3077 3078 Debug << "*******************" << endl; 3079 Debug << "support: " << mPolys[i]->GetSupportingPlane() << endl; 3080 Debug << "plane: " << mPlanes[i] << endl; 3081 3133 3082 /// don't use epsilon here to get exact split planes 3134 3083 const int cf =
Note: See TracChangeset
for help on using the changeset viewer.