- Timestamp:
- 03/09/06 04:27:07 (19 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.cpp
r648 r683 167 167 168 168 if (side > 0) 169 { 169 170 onFrontSide = true; 171 } 170 172 else if (side < 0) 173 { 171 174 onBackSide = true; 172 175 } 176 173 177 //TODO: check if split goes through vertex 174 178 if (onFrontSide && onBackSide) // split … … 413 417 const float epsilon) 414 418 { 415 PolygonContainer::const_iterator it;416 417 419 bool onFrontSide = false; 418 420 bool onBackSide = false; 419 421 PolygonContainer::const_iterator it; 422 420 423 // find intersections 421 424 for (it = polys.begin(); it != polys.end(); ++ it) -
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 = -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r682 r683 218 218 Debug << "\nView cells after initial sampling:\n" << mCurrentViewCellsStats << endl; 219 219 220 if ( 0) // export initial view cells220 if (1) // export initial view cells 221 221 { 222 222 cout << "exporting initial view cells (=leaves) ... "; … … 3486 3486 mVspBspTree->ConstructGeometry(leaf, geom); 3487 3487 3488 const int cf = Polygon3::ClassifyPlane(geom.GetPolys(), *clipPlane, 0.000 5);3489 3490 if (cf == Polygon3::BACK_SIDE)3488 const int cf = Polygon3::ClassifyPlane(geom.GetPolys(), *clipPlane, 0.00000001f); 3489 3490 /*if (cf == Polygon3::BACK_SIDE) 3491 3491 { 3492 3492 exporter->ExportPolygons(geom.GetPolys()); 3493 3493 } 3494 3494 else if (cf == Polygon3::SPLIT) 3495 { 3495 {*/ 3496 3496 geom.SplitGeometry(front, 3497 3497 back, 3498 3498 *clipPlane, 3499 3499 mViewSpaceBox, 3500 0.0001f); 3501 3502 if (back.Size() >= 3) 3500 0.00000001f); 3501 3502 Debug << "here geo size: " << geom.Size() << endl; 3503 Debug << "here size b: " << back.Size() << " f: " << front.Size() << endl; 3504 if (back.Valid()) 3505 { 3506 Debug << "here3 size: " << back.Size() << endl; 3503 3507 exporter->ExportPolygons(back.GetPolys()); 3504 } 3508 } 3509 else 3510 Debug << "here2 size: " << back.Size() << endl; 3511 //} 3505 3512 } 3506 3513 } -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r682 r683 2511 2511 Plane3 halfSpace = dynamic_cast<BspInterior *>(interior)->GetPlane(); 2512 2512 2513 if (interior->Get Front() != lastNode)2513 if (interior->GetBack() != lastNode) 2514 2514 halfSpace.ReverseOrientation(); 2515 2515 … … 2530 2530 vector<Plane3> candidatePlanes; 2531 2531 2532 // bounded planes are added to the polygons (reverse polygons 2533 // as they have to be outfacing) 2532 // bounded planes are added to the polygons 2534 2533 for (int i = 0; i < (int)halfSpaces.size(); ++ i) 2535 2534 { … … 2538 2537 if (p->Valid(mEpsilon)) 2539 2538 { 2540 candidatePolys.push_back(p->CreateReversePolygon()); 2541 // Why? 2542 Plane3 candidatePlane = p->GetSupportingPlane(); //halfSpaces[i]; 2543 //candidatePlane.ReverseOrientation(); 2544 candidatePlanes.push_back(candidatePlane); 2545 2546 DEL_PTR(p); 2539 candidatePolys.push_back(p); 2540 candidatePlanes.push_back(halfSpaces[i]); 2547 2541 } 2548 2542 } … … 2590 2584 DEL_PTR(candidatePolys[i]); 2591 2585 2592 if ( frontPoly->Valid(mEpsilon))2593 candidatePolys[i] = frontPoly;2586 if (backPoly->Valid(mEpsilon)) 2587 candidatePolys[i] = backPoly; 2594 2588 else 2595 DEL_PTR(frontPoly); 2596 2597 DEL_PTR(backPoly); 2589 DEL_PTR(backPoly); 2590 2591 // outside, don't need this 2592 DEL_PTR(frontPoly); 2598 2593 break; 2599 2600 case Polygon3:: BACK_SIDE:2594 // polygon outside of halfspace 2595 case Polygon3::FRONT_SIDE: 2601 2596 DEL_PTR(candidatePolys[i]); 2602 2597 break; 2603 2598 // just take polygon as it is 2604 case Polygon3:: FRONT_SIDE:2599 case Polygon3::BACK_SIDE: 2605 2600 case Polygon3::COINCIDENT: 2606 2601 default: … … 2685 2680 mEpsilon); 2686 2681 2687 if (cf == Polygon3:: BACK_SIDE)2682 if (cf == Polygon3::FRONT_SIDE) 2688 2683 { 2689 2684 isAdjacent = false; … … 2704 2699 mEpsilon); 2705 2700 2706 if (cf == Polygon3:: BACK_SIDE)2701 if (cf == Polygon3::FRONT_SIDE) 2707 2702 { 2708 2703 isAdjacent = false; … … 2738 2733 mEpsilon); 2739 2734 2740 if (cf == Polygon3:: FRONT_SIDE)2741 { 2742 nodeStack.push(bspNodePair(interior->Get Front(), fGeom));2743 DEL_PTR( bGeom);2735 if (cf == Polygon3::BACK_SIDE) 2736 { 2737 nodeStack.push(bspNodePair(interior->GetBack(), bGeom)); 2738 DEL_PTR(fGeom); 2744 2739 } 2745 2740 else 2746 2741 { 2747 if (cf == Polygon3:: BACK_SIDE)2742 if (cf == Polygon3::FRONT_SIDE) 2748 2743 { 2749 nodeStack.push(bspNodePair(interior->Get Back(), bGeom));2750 DEL_PTR( fGeom);2744 nodeStack.push(bspNodePair(interior->GetFront(), fGeom)); 2745 DEL_PTR(bGeom); 2751 2746 } 2752 2747 else … … 2830 2825 mEpsilon); 2831 2826 2832 if (cf == Polygon3:: FRONT_SIDE)2833 { 2834 nodeStack.push(bspNodePair(interior->Get Front(), fGeom));2835 DEL_PTR( bGeom);2827 if (cf == Polygon3::BACK_SIDE) 2828 { 2829 nodeStack.push(bspNodePair(interior->GetBack(), bGeom)); 2830 DEL_PTR(fGeom); 2836 2831 } 2837 2832 else 2838 2833 { 2839 if (cf == Polygon3:: BACK_SIDE)2834 if (cf == Polygon3::FRONT_SIDE) 2840 2835 { 2841 nodeStack.push(bspNodePair(interior->Get Back(), bGeom));2842 DEL_PTR( fGeom);2836 nodeStack.push(bspNodePair(interior->GetFront(), fGeom)); 2837 DEL_PTR(bGeom); 2843 2838 } 2844 2839 else … … 3044 3039 3045 3040 float t; 3046 const float thresh = 1 ? 1e-6f : 0.0f; 3041 //const float thresh = 1 ? 1e-6f : 0.0f; 3042 const float thresh = 0.01f; 3047 3043 3048 3044 while (1)
Note: See TracChangeset
for help on using the changeset viewer.