Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4868 in orxonox.OLD for orxonox/trunk/src/lib


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

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

Location:
orxonox/trunk/src/lib/graphics/spatial_separation
Files:
5 edited

Legend:

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

    r4852 r4868  
    5555
    5656/**
     57 *  gives the signal to separate the model into a quadtree
     58 */
     59void Quadtree::separate(int treeDepth)
     60{
     61  this->rootNode->separateNode(treeDepth);
     62}
     63
     64
     65/**
     66 *  gives the signal to separate the model into a quadtree
     67 */
     68void Quadtree::separate(float minLength)
     69{
     70  this->rootNode->separateNode(minLength);
     71}
     72
     73
     74/**
    5775 *  draws the debug quadtree boxes around the model
    5876 */
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.h

    r4845 r4868  
    2222
    2323  void separate();
     24  void separate(int treeDepth);
     25  void separate(float minLength);
    2426
    2527  void drawTree(int depth, int drawMode) const;
  • 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
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.h

    r4867 r4868  
    1414// FORWARD DEFINITION
    1515class Quadtree;
    16 class QuadtreeNode;
     16
    1717
    1818//! A class for a Quadtree Node representation
     
    2020
    2121  public:
    22     QuadtreeNode(sTriangleExt** triangles, int numTriangles, Quadtree* quadtree);
     22    QuadtreeNode(sTriangleExt** triangles, int numTriangles,
     23                 const float* pVertices, int numVertices, Quadtree* quadtree);
    2324    QuadtreeNode(modelInfo* pModelInfo);
    2425    virtual ~QuadtreeNode();
     
    3435    void init();
    3536    Rectangle* getDimension(modelInfo* pModelInfo);
     37    Rectangle* getDimension();
    3638
    3739  private:
     
    4547    const float*                    pVertices;          //!< reference to vertices data
    4648    unsigned int                    numTriangles;       //!< number of triangles of the Node
     49    unsigned int                    numVertices;        //!< number of vertices of the node
    4750    modelInfo*                      pModelInfo;         //!< reference to the modelInfo of the object
    4851    Rectangle*                      pDimension;         //!< pointer to the local rectangle properties
  • orxonox/trunk/src/lib/graphics/spatial_separation/spatial_separation.cc

    r4855 r4868  
    9797{
    9898  this->quadtree = new Quadtree(model->getModelInfo());
    99   this->quadtree->separate();
     99  this->quadtree->separate(4);
    100100
    101101  return this->quadtree;
Note: See TracChangeset for help on using the changeset viewer.