Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 12, 2005, 11:48:39 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: added the rectangle to the vector file, since it is a geometrical body like a plane (the plane without arrows…), moved getDimension function to the QuadtreeNode

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

Legend:

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

    r4836 r4845  
    1717
    1818#include "quadtree.h"
     19#include "quadtree_node.h"
    1920
    2021using namespace std;
     
    2930   this->setClassID(CL_QUADTREE, "Quadtree");
    3031   this->pModelInfo = pModelInfo;
     32
     33   this->rootNode = new QuadtreeNode(this->pModelInfo);
    3134}
    3235
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.h

    r4836 r4845  
    1010
    1111#include "base_object.h"
    12 #include "vector.h"
     12#include "abstract_model.h"
    1313
    1414class QuadtreeNode;
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.cc

    r4836 r4845  
    2727{
    2828   this->setClassID(CL_QUADTREE_NODE, "QuadtreeNode");
     29}
     30
     31
     32/**
     33 *  standard constructor
     34 */
     35QuadtreeNode::QuadtreeNode(modelInfo* pModelInfo)
     36{
     37  this->pModelInfo = pModelInfo;
     38  this->getDimension(this->pModelInfo);
    2939}
    3040
     
    6171void QuadtreeNode::drawTree(int depth, int drawMode) const
    6272{}
     73
     74
     75
     76/**
     77  \brief gets the maximal dimension of a model
     78 * @param playerModel the model that this measurement is based on
     79    \return the dimension of the AbstractModel as a Rectangle
     80
     81    The rectangle is x-z axis aligned. ATTENTION: if there are any vertices in the model, that exceed the
     82    size of 999999.0, there probably will be some errors in the dimensions calculations.
     83 */
     84Rectangle* QuadtreeNode::getDimension(modelInfo* pModelInfo)
     85{
     86  float            maxX, maxY;                       //!< the maximal coordinates axis
     87  float            minX, minY;                       //!< minimal axis coorindates
     88  const float*     pVertices;                        //!< pointer to the current vertices
     89
     90  maxX = -999999; maxY = -999999;
     91  minX =  999999; minY =  999999;
     92  /* get maximal/minimal x/y */
     93  for( int i = 0; i < pModelInfo->numVertices; ++i)
     94  {
     95    pVertices = &pModelInfo->pVertices[i * 3];
     96    if( pVertices[0] > maxX)
     97      maxX = pVertices[0];
     98    if( pVertices[2] > maxY)
     99      maxY = pVertices[2];
     100
     101    if( pVertices[0] < minX)
     102      minX = pVertices[0];
     103    if( pVertices[2] < minY)
     104      minY = pVertices[2];
     105  }
     106
     107  Rectangle* rect = new Rectangle();
     108  rect->setCenter((maxX + minX) / 2.0f, 0.0f, (maxY + minY) / 2.0f); /* this is little strange, since y is in opengl the up vector */
     109  rect->setAxis(fmax(((fabs(maxX) + fabs(minX)) / 2.0f), ((fabs(maxY) + fabs(minY)) / 2.0f)));
     110
     111  PRINTF(0)("Dimension Informationation: X: min/max %f/%f Y: min/max %f/%f\n", minX, maxX, minY, maxY);
     112  return rect;
     113}
     114
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.h

    r4836 r4845  
    11/*!
    22    \file proto_class.h
    3   *  Definition of ...
     3 *  Definition of ...
    44
    5 */
     5 */
    66
    77#ifndef _QUADTREE_NODE_H
     
    1010#include "base_object.h"
    1111#include "vector.h"
     12#include "abstract_model.h"
    1213
    1314// FORWARD DEFINITION
     
    1819class QuadtreeNode : public BaseObject {
    1920
    20  public:
    21   QuadtreeNode(sTriangleExt* triangles, int numTriangles, Quadtree* quadtree);
    22   virtual ~QuadtreeNode();
     21  public:
     22    QuadtreeNode(sTriangleExt* triangles, int numTriangles, Quadtree* quadtree);
     23    QuadtreeNode(modelInfo* pModelInfo);
     24    virtual ~QuadtreeNode();
    2325
    24   void separateNode(int treeDepth);
    25   void separateNode(float minLength);
     26    void separateNode(int treeDepth);
     27    void separateNode(float minLength);
    2628
    27   void drawTree(int depth, int drawMode) const;
     29    void drawTree(int depth, int drawMode) const;
    2830
    2931
    30  private:
    31    Quadtree*                       quadtree;           //!< reference to the quadtree
    32    Vector                          center;             //!< center coordinate of the quadtree node - relative coordinates in model space(!)
    33    float                           axisLength;         //!< axis length of the quadtree
    34    float                           maxHeigth;          //!< max height of the model in the quadtree
     32  private:
     33    Rectangle* getDimension(modelInfo* pModelInfo);
    3534
    36    sTriangleExt*                   triangles;          //!< reference to the triangles of the node
    37    unsigned int                    numTriangles;       //!< number of triangles of the Node
    38    modelInfo*                      pModelInfo;         //!< reference to the modelInfo of the object
     35  private:
     36    Quadtree*                       quadtree;           //!< reference to the quadtree
     37    Vector                          center;             //!< center coordinate of the quadtree node - relative coordinates in model space(!)
     38    float                           axisLength;         //!< axis length of the quadtree
     39    float                           maxHeigth;          //!< max height of the model in the quadtree
    3940
    40    QuadtreeNode*                   nodeA;              //!< reference to the node A
    41    QuadtreeNode*                   nodeB;              //!< reference to the node B
    42    QuadtreeNode*                   nodeC;              //!< reference to the node C
    43    QuadtreeNode*                   nodeD;              //!< reference to the node D
     41    sTriangleExt*                   triangles;          //!< reference to the triangles of the node
     42    unsigned int                    numTriangles;       //!< number of triangles of the Node
     43    modelInfo*                      pModelInfo;         //!< reference to the modelInfo of the object
     44
     45    QuadtreeNode*                   nodeA;              //!< reference to the node A
     46    QuadtreeNode*                   nodeB;              //!< reference to the node B
     47    QuadtreeNode*                   nodeC;              //!< reference to the node C
     48    QuadtreeNode*                   nodeD;              //!< reference to the node D
    4449
    4550};
  • orxonox/trunk/src/lib/graphics/spatial_separation/spatial_separation.cc

    r4844 r4845  
    3434{
    3535   this->setClassID(CL_SPATIAL_SEPARATION, "SpatialSeparation");
    36    this->getDimension(model);
     36   this->createQuadtree(model);
    3737}
    3838
     
    9797  this->quadtree->separate();
    9898
     99
    99100  return this->quadtree;
    100 }
    101 
    102 
    103 /**
    104   \brief gets the maximal dimension of a model
    105 * @param playerModel the model that this measurement is based on
    106   \return the dimension of the AbstractModel as a Rectangle
    107 
    108   The rectangle is x-z axis aligned. ATTENTION: if there are any vertices in the model, that exceed the
    109   size of 999999.0, there probably will be some errors in the dimensions calculations.
    110  */
    111 Rectangle* SpatialSeparation::getDimension(AbstractModel* playerModel)
    112 {
    113   float            maxX, maxY;                       //!< the maximal coordinates axis
    114   float            minX, minY;                       //!< minimal axis coorindates
    115   const float*     pVertices;                        //!< pointer to the current vertices
    116 
    117   maxX = -999999; maxY = -999999;
    118   minX =  999999; minY =  999999;
    119   /* get maximal/minimal x/y */
    120   for( int i = 0; i < playerModel->getModelInfo()->numVertices; ++i)
    121   {
    122     pVertices = &playerModel->getModelInfo()->pVertices[i * 3];
    123     if( pVertices[0] > maxX)
    124       maxX = pVertices[0];
    125     if( pVertices[2] > maxY)
    126       maxY = pVertices[2];
    127 
    128     if( pVertices[0] < minX)
    129       minX = pVertices[0];
    130     if( pVertices[2] < minY)
    131       minY = pVertices[2];
    132   }
    133   Rectangle* rect = new Rectangle();
    134 
    135   rect->setCenter((maxX + minX) / 2.0f, 0.0f, (maxY + minY) / 2.0f);
    136 
    137 
    138   PRINTF(0)("Dimension Informationation: X: min/max %f/%f Y: min/max %f/%f\n", minX, maxX, minY, maxY);
    139101}
    140102
  • orxonox/trunk/src/lib/graphics/spatial_separation/spatial_separation.h

    r4844 r4845  
    1616#define SEC_OFFSET 1.0                       //!< the offset added to the overlapSize to ensure that there are no problems in
    1717
    18 
    19 //! A class that represents a rectangle, this is needed for SpatialSeparation
    20 class Rectangle
    21 {
    22 
    23   public:
    24     Rectangle() {}
    25     virtual ~Rectangle() {}
    26 
    27     /** \brief sets the center of the rectangle to a defined vector @param center the new center */
    28     inline void setCenter(const Vector &center) { this->center = center;}
    29     /** \brief sets the center of the rectangle to a defined vector @param x coord of the center @param y coord of the center @param z coord of the center */
    30     inline void setCenter(float x, float y, float z) { this->center.x = x; this->center.y = y; this->center.z = z; }
    31     /** \brief returns the center of the rectangle to a defined vector @returns center the new center */
    32     inline const Vector* getCenter() const { return &this->center; }
    33 
    34     /** \brief sets both axis of the rectangle to a defined vector @param unityLength the new center */
    35     inline void setAxis(float unityLength) { this->axis[0] = unityLength; this->axis[1] = unityLength; }
    36                /** \brief sets both axis of the rectangle to a defined vector @param v1 the length of the x axis @param v2 the length of the z axis*/
    37     inline void setAxis(float v1, float v2) { this->axis[0] = v1; this->axis[1] = v2; }
    38 
    39   private:
    40     Vector center;
    41     float axis[2];
    42 };
    4318
    4419
     
    6136  private:
    6237    void separateZone();
    63     Rectangle* getDimension(AbstractModel* playerModel);
    6438
    6539
Note: See TracChangeset for help on using the changeset viewer.