Changeset 2618


Ignore:
Timestamp:
01/20/08 01:17:49 (16 years ago)
Author:
bittner
Message:

skip cast line segment for consequent line segments with oposite dirs

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r2615 r2618  
    762762} 
    763763 
    764 int KdTree::CastLineSegment(const Vector3 &origin, 
     764int KdTree::CastLineSegment2(const Vector3 &origin, 
    765765                            const Vector3 &termination, 
    766766                            ViewCellContainer &viewcells) 
     
    850850      if (tStack.empty()) 
    851851        break; 
     852       
     853      entp = extp; 
     854      mint = maxt; 
     855       
     856      RayTraversalData &s  = tStack.top(); 
     857      node = s.mNode; 
     858      extp = s.mExitPoint; 
     859      maxt = s.mMaxT; 
     860      tStack.pop(); 
     861    } 
     862  } 
     863  return hits; 
     864} 
     865 
     866int KdTree::CastLineSegment(const Vector3 &origin, 
     867                            const Vector3 &termination, 
     868                            ViewCellContainer &viewcells) 
     869{ 
     870  int hits = 0; 
     871 
     872  float mint = 0.0f, maxt = 1.0f; 
     873  const Vector3 dir = termination - origin; 
     874   
     875  stack<RayTraversalData> tStack; 
     876   
     877  Intersectable::NewMail(); 
     878   
     879  //maxt += Limits::Threshold; 
     880   
     881  Vector3 entp = origin; 
     882  Vector3 extp = termination; 
     883   
     884  KdNode *node = mRoot; 
     885  KdNode *farChild; 
     886   
     887  float position; 
     888  float tdist; 
     889 
     890  while (1) 
     891  { 
     892    if (!node->IsLeaf()) 
     893    { 
     894      KdInterior *in = static_cast<KdInterior *>(node); 
     895      position = in->mPosition; 
     896      switch (in->mAxis) { 
     897          case 0: 
     898                if (entp.x <= position) 
     899                  { 
     900                        if (extp.x <= position) 
     901                          { 
     902                                node = in->mBack; 
     903                                // cases N1,N2,N3,P5,Z2,Z3 
     904                                continue; 
     905                          }  
     906                        else 
     907                          { 
     908                                // case N4 
     909                                node = in->mBack; 
     910                                farChild = in->mFront; 
     911                          } 
     912                  } 
     913                else 
     914                  { 
     915                        if (position <= extp.x) 
     916                          { 
     917                                node = in->mFront; 
     918                                // cases P1,P2,P3,N5,Z1 
     919                                continue; 
     920                          } 
     921                        else 
     922                          { 
     923                                node = in->mFront; 
     924                                farChild = in->mBack; 
     925                                // case P4 
     926                          } 
     927                  } 
     928                 
     929                // $$ modification 3.5.2004 - hints from Kamil Ghais 
     930                // case N4 or P4 
     931                tdist = (position - origin.x) / dir.x; 
     932                //tStack.push(RayTraversalData(farChild, extp, maxt)); //TODO 
     933                extp = origin + dir * tdist; 
     934                maxt = tdist; 
     935           
     936          break; 
     937        case 1: 
     938         
     939                if (entp.y <= position) 
     940                  { 
     941                        if (extp.y <= position) 
     942                          { 
     943                                node = in->mBack; 
     944                                // cases N1,N2,N3,P5,Z2,Z3 
     945                                continue; 
     946                          }  
     947                        else 
     948                          { 
     949                                // case N4 
     950                                node = in->mBack; 
     951                                farChild = in->mFront; 
     952                          } 
     953                  } 
     954                else 
     955                  { 
     956                        if (position <= extp.y) 
     957                          { 
     958                                node = in->mFront; 
     959                                // cases P1,P2,P3,N5,Z1 
     960                                continue; 
     961                          } 
     962                        else 
     963                          { 
     964                                node = in->mFront; 
     965                                farChild = in->mBack; 
     966                                // case P4 
     967                          } 
     968                  } 
     969                 
     970                // $$ modification 3.5.2004 - hints from Kamil Ghais 
     971                // case N4 or P4 
     972                tdist = (position - origin.y) / dir.y; 
     973                //tStack.push(RayTraversalData(farChild, extp, maxt)); //TODO 
     974                extp = origin + dir * tdist; 
     975                maxt = tdist; 
     976                 
     977                break; 
     978          case 2:  
     979                if (entp.z <= position) 
     980                  { 
     981                        if (extp.z <= position) 
     982                          { 
     983                                node = in->mBack; 
     984                                // cases N1,N2,N3,P5,Z2,Z3 
     985                                continue; 
     986                          }  
     987                        else 
     988                          { 
     989                                // case N4 
     990                                node = in->mBack; 
     991                                farChild = in->mFront; 
     992                          } 
     993                  } 
     994                else 
     995                  { 
     996                        if (position <= extp.z) 
     997                          { 
     998                                node = in->mFront; 
     999                                // cases P1,P2,P3,N5,Z1 
     1000                                continue; 
     1001                          } 
     1002                        else 
     1003                          { 
     1004                                node = in->mFront; 
     1005                                farChild = in->mBack; 
     1006                                // case P4 
     1007                          } 
     1008                  } 
     1009                 
     1010                // $$ modification 3.5.2004 - hints from Kamil Ghais 
     1011                // case N4 or P4 
     1012                tdist = (position - origin.z) / dir.z; 
     1013                //tStack.push(RayTraversalData(farChild, extp, maxt)); //TODO 
     1014                extp = origin + dir * tdist; 
     1015                maxt = tdist; 
     1016           
     1017          break; 
     1018           
     1019          } 
     1020           
     1021        } 
     1022    else 
     1023          { 
     1024      // compute intersection with all objects in this leaf 
     1025      KdLeaf *leaf = static_cast<KdLeaf *>(node); 
     1026       
     1027      // add view cell to intersections 
     1028      ViewCell *vc = leaf->mViewCell; 
     1029       
     1030      if (!vc->Mailed()) 
     1031      { 
     1032        vc->Mail(); 
     1033        viewcells.push_back(vc); 
     1034        ++ hits; 
     1035      } 
     1036       
     1037      // get the next node from the stack 
     1038      if (tStack.empty()) 
     1039                break; 
    8521040       
    8531041      entp = extp; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h

    r2606 r2618  
    332332                      vector<ViewCell *> &viewcells); 
    333333 
     334  // old version 
     335  int CastLineSegment2(const Vector3 &origin, 
     336                                           const Vector3 &termination, 
     337                                           vector<ViewCell *> &viewcells); 
    334338 
    335339  const KdTreeStatistics &GetStatistics() const { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r2617 r2618  
    25872587        ViewCell::NewMail(); 
    25882588 
    2589 #ifdef USE_PERFTIMER   
    2590         viewCellCastTimer.Entry(); 
    2591 #endif 
    25922589        static ViewCellContainer viewCells; 
    25932590        static VssRay *lastVssRay = NULL; 
    25942591 
    25952592        // check if last ray was not same ray with reverse direction 
    2596         if (1)  
     2593        //      if (1)  
    25972594                // tmp matt: don't use when origin objects are not accounted for, currently the second ray is lost!! 
    25982595          // $$JB: reenabled again - should use the same viewcells for the next ray ray if 
    25992596          // it goes in the oposite direction 
    2600 //      if (!lastVssRay || 
    2601 //              !(ray.mOrigin == lastVssRay->mTermination) || 
    2602 //              !(ray.mTermination == lastVssRay->mOrigin))  
     2597        if (!lastVssRay || 
     2598                !(ray.mOrigin == lastVssRay->mTermination) || 
     2599                !(ray.mTermination == lastVssRay->mOrigin))  
    26032600          { 
     2601#ifdef USE_PERFTIMER   
     2602                viewCellCastTimer.Entry(); 
     2603#endif 
    26042604                viewCells.clear(); 
    2605  
     2605                 
    26062606                // traverse the view space subdivision 
    26072607                CastLineSegment(origin, termination, viewCells); 
    26082608                lastVssRay = &ray; 
    2609           }  
    2610  
    26112609#ifdef USE_PERFTIMER   
    2612         viewCellCastTimer.Exit(); 
     2610                viewCellCastTimer.Exit(); 
    26132611#endif 
    2614  
     2612          } 
     2613         
    26152614        mSamplesStat.mViewCells += (int)viewCells.size(); 
    26162615 
Note: See TracChangeset for help on using the changeset viewer.