当前位置: 首页>>代码示例>>C++>>正文


C++ TStack::init方法代码示例

本文整理汇总了C++中TStack::init方法的典型用法代码示例。如果您正苦于以下问题:C++ TStack::init方法的具体用法?C++ TStack::init怎么用?C++ TStack::init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TStack的用法示例。


在下文中一共展示了TStack::init方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: findFirstIntersection

// Traverses ray through KDTree and intersects ray with all of the objects along
// the way. Returns the first intersecting object
// if there is one.
// Entry:
//   ray     - the ray being traced
//   KDTree - the KD tree enclosing the entire environment
// Exit:
//   obj      - the first object that intersects the ray
bool KDTree::findFirstIntersection( const TRay &ray, const float maxDist2,
				    TObject *&obj ) const {
  TStack *stack;
  BinNode *currentNode, 
    *nearChild, *farChild;
  float dist, _min, _max;
  TPoint3 p;

#ifdef __DEBUG__
  ray.origin.print("ray origin");
  ray.direction.print("ray direction");
  ray.reverseDirection.print("ray reverse direction");
#endif

  // test if the whole KD tree is missed by the input ray
  if ( !rayBoxIntersect(ray, min, max, _min, _max ) )
#ifdef __DEBUG__
    {
      printf("whole KD tree is missed by ray\n");
#endif
      return false;
#ifdef __DEBUG__
    }
#endif


#ifdef __DEBUG__
  printf("rayBoxIntersect: %5.5f   %5.5f\n", _min, _max );
#endif

  stack = new TStack;
  stack->init();

  currentNode = root;

  while ( currentNode != NULL ) {

    while ( !currentNode->leaf() ) {
#ifdef __DEBUG__
      currentNode->min.print("current node min"); currentNode->max.print("current node max");
      printf("is leaf: %d\n", currentNode->leaf() );
      currentNode->child[0]->max.print("cut plane");
#endif

      dist = currentNode->distanceToDivisionPlane( currentNode->child[0]->max, ray );
      currentNode->getChildren( currentNode, ray.origin, nearChild, farChild );

#ifdef __DEBUG__
      printf("distance to plane: %5.5f\n", dist );
      
      nearChild->min.print("near min"); nearChild->max.print("near max");
      printf("is near leaf: %d\n", nearChild->leaf() );
      farChild->min.print("far min"); farChild->max.print("far max");
      printf("is far leaf: %d\n", farChild->leaf() );
#endif

      if ( ( dist > _max ) || ( dist < 0 ) ) {
#ifdef __DEBUG__
	printf("using near child\n");
#endif
	currentNode = nearChild;
      }
      else if ( dist < _min ) {
#ifdef __DEBUG__
	printf("using far child\n");
#endif
	currentNode = farChild;
      }
      else {
	stack->push( farChild, dist, _max );
#ifdef __DEBUG__
	printf("-->PUSH far  keep near\n");
#endif
	currentNode = nearChild;
	_max = dist;
      }
    }

#ifdef __DEBUG__
    printf("rayObjIntersect:\n");
    currentNode->min.print("currentNode min");
    currentNode->max.print("currentNode max");
#endif
    if ( rayObjIntersect( ray, currentNode->members, maxDist2, obj ) )
      return true;
    stack->pop( currentNode, _min,_max );
#ifdef __DEBUG__
    printf("-->POP\n");
    if ( currentNode ) {
      currentNode->min.print("currentNode min"); currentNode->max.print("currentNode max");
      printf("is leaf: %d\n", currentNode->leaf() );
    }
//.........这里部分代码省略.........
开发者ID:SinaC,项目名称:OldRaytrace,代码行数:101,代码来源:kdtree.cpp


注:本文中的TStack::init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。