Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 15, 2005, 12:17:37 AM (20 years ago)
Author:
patrick
Message:

orxonox/trunk: cleaned out a segfault in the getDimension function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.cc

    r4867 r4868  
    1717
    1818#include "quadtree_node.h"
     19#include "abstract_model.h"
    1920#include "list.h"
    2021#include "vector.h"
     
    2627 *  standard constructor
    2728*/
    28 QuadtreeNode::QuadtreeNode (sTriangleExt** triangles, int numTriangles, Quadtree* quadtree)
     29QuadtreeNode::QuadtreeNode (sTriangleExt** triangles, int numTriangles,
     30                            const float* pVertices, int numVertices, Quadtree* quadtree)
    2931{
    3032  this->pTriangles = triangles;
    3133  this->numTriangles = numTriangles;
     34  this->pVertices = pVertices;
     35  this->numVertices = numVertices;
    3236  this->quadtree = quadtree;
    3337 
     38  this->pDimension = this->getDimension();
    3439  this->init();
    3540}
     
    4752  this->numTriangles = this->pModelInfo->numTriangles;
    4853  this->pVertices = this->pModelInfo->pVertices;
     54  this->numVertices = this->pModelInfo->numVertices;
    4955  for( int i = 0; i < this->pModelInfo->numTriangles; ++i)
    5056    this->pTriangles[i] = &this->pModelInfo->pTriangles[i];
    5157
     58  this->pDimension = this->getDimension(this->pModelInfo);
    5259  this->init();
    5360}
     
    93100  if( treeDepth <= 0)
    94101    return;
     102  PRINTF(0)("separate Node Nr: %i\n", treeDepth);
    95103  this->separateNode();
    96104
     
    126134{
    127135  PRINTF(0)("got command to separate node\n");
    128 
    129   this->pDimension = this->getDimension(this->pModelInfo);
    130136
    131137  tList<sTriangleExt*>*           listA = new tList<sTriangleExt*>();    //!< triangle list of nodeA
     
    227233
    228234  /* now propagate */
    229   this->nodeA = new QuadtreeNode(pTriA, lenA, this->quadtree);
    230   this->nodeB = new QuadtreeNode(pTriB, lenB, this->quadtree);
    231   this->nodeC = new QuadtreeNode(pTriC, lenC, this->quadtree);
    232   this->nodeD = new QuadtreeNode(pTriD, lenD, this->quadtree);
     235  this->nodeA = new QuadtreeNode(pTriA, lenA, this->pVertices, this->numVertices, this->quadtree);
     236  this->nodeB = new QuadtreeNode(pTriB, lenB, this->pVertices, this->numVertices, this->quadtree);
     237  this->nodeC = new QuadtreeNode(pTriC, lenC, this->pVertices, this->numVertices, this->quadtree);
     238  this->nodeD = new QuadtreeNode(pTriD, lenD, this->pVertices, this->numVertices, this->quadtree);
    233239
    234240
     
    299305}
    300306
     307
     308/**
     309   \brief gets the maximal dimension of a model
     310   \return the dimension of the AbstractModel as a Rectangle
     311   
     312   The rectangle is x-z axis aligned. ATTENTION: if there are any vertices in the model, that exceed the
     313   size of 999999.0, there probably will be some errors in the dimensions calculations. Write an email to
     314   patrick@orxonox.ethz.ch if you will ever encounter a model bigger than 999999.0 units, I will realy be
     315   happy to see orxonox used to extensivly :)
     316 */
     317Rectangle* QuadtreeNode::getDimension()
     318{
     319  float            maxX, maxY;                       //!< the maximal coordinates axis
     320  float            minX, minY;                       //!< minimal axis coorindates
     321  const float*     pVertices;                        //!< pointer to the current vertices
     322 
     323  maxX = -999999; maxY = -999999;
     324  minX =  999999; minY =  999999;
     325  /* get maximal/minimal x/y */
     326  for( int i = 0; i < this->numVertices; ++i)
     327  {
     328    pVertices = &pModelInfo->pVertices[i * 3];
     329    if( pVertices[0] > maxX)
     330      maxX = pVertices[0];
     331    if( pVertices[2] > maxY)
     332      maxY = pVertices[2];
     333
     334    if( pVertices[0] < minX)
     335      minX = pVertices[0];
     336    if( pVertices[2] < minY)
     337      minY = pVertices[2];
     338  }
     339
     340  Rectangle* rect = new Rectangle();
     341  rect->setCenter((maxX + minX) / 2.0f, 0.0f, (maxY + minY) / 2.0f); /* this is little strange, since y is in opengl the up vector */
     342  rect->setAxis(fmax(((fabs(maxX) + fabs(minX)) / 2.0f), ((fabs(maxY) + fabs(minY)) / 2.0f)));
     343
     344  PRINTF(0)("Dimension Informationation: X: min/max %f/%f Y: min/max %f/%f\n", minX, maxX, minY, maxY);
     345  PRINTF(0)("Center: %f, %f, %f   Axis: %f\n", rect->getCenter()->x, rect->getCenter()->y, rect->getCenter()->z, rect->getAxis());
     346  return rect;
     347}
     348
Note: See TracChangeset for help on using the changeset viewer.