Version: 6.3.1
Data Structures | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes

SMESH_Octree Class Reference

#include <SMESH_Octree.hxx>

Inheritance diagram for SMESH_Octree:
Inheritance graph
[legend]

Data Structures

struct  Limit

Public Member Functions

 SMESH_Octree (Limit *limit=0)
 Constructor.
virtual ~SMESH_Octree ()
 SMESH_Octree Destructor.
void compute ()
 Compute the Octree.
bool isLeaf () const
 Tell if Octree is a leaf or not An inheriting class can influence it via myIsLeaf protected field.
int level () const
const Bnd_B3d & getBox () const
double maxSize () const
 Compute the bigger dimension of my box.
int getChildIndex (double x, double y, double z, const gp_XYZ &boxMiddle) const
 Return index of a child the given point is in.

Protected Member Functions

virtual Bnd_B3d * buildRootBox ()=0
virtual SMESH_OctreeallocateOctreeChild () const =0
virtual void buildChildrenData ()=0

Protected Attributes

SMESH_Octree ** myChildren
SMESH_OctreemyFather
bool myIsLeaf
const LimitmyLimit

Private Member Functions

void buildChildren ()
 Build the 8 children boxes and call buildChildrenData()

Private Attributes

int myLevel
Bnd_B3d * myBox

Detailed Description

Definition at line 34 of file SMESH_Octree.hxx.


Constructor & Destructor Documentation

SMESH_Octree::SMESH_Octree ( SMESH_Octree::Limit limit = 0)

Constructor.

limit must be provided at tree root construction. limit will be deleted by SMESH_Octree.

Definition at line 38 of file SMESH_Octree.cxx.

                                                   :
  myChildren(NULL),
  myFather(NULL),
  myIsLeaf( false ),
  myLimit( limit ),
  myLevel(0),
  myBox(NULL)
{
}
SMESH_Octree::~SMESH_Octree ( ) [virtual]

SMESH_Octree Destructor.

Definition at line 72 of file SMESH_Octree.cxx.

References isLeaf(), level(), myBox, myChildren, and myLimit.

{
  if(myChildren != NULL)
  {
    if(!isLeaf())
    {
      for(int i = 0; i<8; i++)
        delete myChildren[i];
      delete[] myChildren;
      myChildren = 0;
    }
  }
  if ( myBox )
    delete myBox;
  myBox = 0;
  if ( level() == 0 )
    delete myLimit;
  myLimit = 0;
}

Member Function Documentation

virtual SMESH_Octree* SMESH_Octree.allocateOctreeChild ( ) const [protected, pure virtual]

Implemented in SMESH_OctreeNode.

Referenced by buildChildren().

void SMESH_Octree::buildChildren ( ) [private]

Build the 8 children boxes and call buildChildrenData()

Definition at line 98 of file SMESH_Octree.cxx.

References allocateOctreeChild(), buildChildrenData(), isLeaf(), maxSize(), myBox, myChildren, myFather, myIsLeaf, myLevel, myLimit, and SMESH_Octree.Limit.myMinBoxSize.

Referenced by compute().

{
  if ( isLeaf() ) return;

  myChildren = new SMESH_Octree*[8];

  gp_XYZ min = myBox->CornerMin();
  gp_XYZ max = myBox->CornerMax();
  gp_XYZ HSize = (max - min)/2.;
  gp_XYZ mid = min + HSize;
  gp_XYZ childHsize = HSize/2.;

  // get the whole model size
  double rootSize = 0;
  {
    SMESH_Octree* root = this;
    while ( root->myLevel > 0 )
      root = root->myFather;
    rootSize = root->maxSize();
  }
  Standard_Real XminChild, YminChild, ZminChild;
  gp_XYZ minChild;
  for (int i = 0; i < 8; i++)
  {
    // We build the eight boxes, we need 2 points to do that:
    // Min and Mid
    // In binary, we can write i from 0 to 7
    // For instance :
    // 5 is 101, it corresponds here in coordinates to ZYX
    // If coordinate is 0 in Y-> box from Ymin to Ymid
    // If coordinate is 1 in Y-> box from Ymid to Ymax
    // Same scheme for X and Z
    // I need the minChild to build the Bnd_B3d box.

    XminChild = (i%2==0)?min.X():mid.X();
    YminChild = ((i%4)/2==0)?min.Y():mid.Y();
    ZminChild = (i<4)?min.Z():mid.Z();
    minChild.SetCoord(XminChild, YminChild, ZminChild);

    // The child is of the same type than its father (For instance, a SMESH_OctreeNode)
    // We allocate the memory we need for the child
    myChildren[i] = allocateOctreeChild();
    // and we assign to him its box.
    myChildren[i]->myFather = this;
    myChildren[i]->myLimit = myLimit;
    myChildren[i]->myLevel = myLevel + 1;
    myChildren[i]->myBox = new Bnd_B3d(minChild+childHsize,childHsize);
    myChildren[i]->myBox->Enlarge( rootSize * 1e-10 );
    if ( myLimit->myMinBoxSize > 0. && myChildren[i]->maxSize() <= myLimit->myMinBoxSize )
      myChildren[i]->myIsLeaf = true;
  }

  // After building the 8 boxes, we put the data into the children.
  buildChildrenData();

  //After we pass to the next level of the Octree
  for (int i = 0; i<8; i++)
    myChildren[i]->buildChildren();
}
virtual void SMESH_Octree.buildChildrenData ( ) [protected, pure virtual]

Implemented in SMESH_OctreeNode.

Referenced by buildChildren().

virtual Bnd_B3d* SMESH_Octree.buildRootBox ( ) [protected, pure virtual]

Implemented in SMESH_OctreeNode.

Referenced by compute().

void SMESH_Octree::compute ( )

Compute the Octree.

Definition at line 54 of file SMESH_Octree.cxx.

References buildChildren(), buildRootBox(), maxSize(), myBox, myIsLeaf, myLevel, myLimit, and SMESH_Octree.Limit.myMinBoxSize.

Referenced by SMESH_OctreeNode.SMESH_OctreeNode().

{
  if ( myLevel==0 )
  {
    myBox = buildRootBox();
    if ( myLimit->myMinBoxSize > 0. && maxSize() <= myLimit->myMinBoxSize )
      myIsLeaf = true;
    else
      buildChildren();
  }
}
const Bnd_B3d& SMESH_Octree.getBox ( ) const
int SMESH_Octree::getChildIndex ( double  x,
double  y,
double  z,
const gp_XYZ &  boxMiddle 
) const

Return index of a child the given point is in.

Definition at line 118 of file SMESH_Octree.hxx.

Referenced by SMESH_OctreeNode.buildChildrenData(), SMESH_OctreeNode.NodesAround(), and SMESH_OctreeNode.UpdateByMoveNode().

{
  return (x > mid.X()) + ( y > mid.Y())*2 + (z > mid.Z())*4;
}
bool SMESH_Octree::isLeaf ( ) const
int SMESH_Octree.level ( ) const

Definition at line 67 of file SMESH_Octree.hxx.

References myLevel.

Referenced by isLeaf(), and ~SMESH_Octree().

{ return myLevel; }
double SMESH_Octree::maxSize ( ) const

Compute the bigger dimension of my box.

Definition at line 176 of file SMESH_Octree.cxx.

References myBox.

Referenced by buildChildren(), compute(), SMESH_ElementSearcherImpl.getTolerance(), SMESH_OctreeNode.NodesAround(), and SMESH_NodeSearcherImpl.SMESH_NodeSearcherImpl().

{
  if ( myBox )
  {
    gp_XYZ min = myBox->CornerMin();
    gp_XYZ max = myBox->CornerMax();
    gp_XYZ Size = (max - min);
    double returnVal = (Size.X()>Size.Y())?Size.X():Size.Y();
    return (returnVal>Size.Z())?returnVal:Size.Z();
  }
  return 0.;
}

Field Documentation

Bnd_B3d* SMESH_Octree.myBox [private]

Definition at line 109 of file SMESH_Octree.hxx.

Referenced by buildChildren(), compute(), getBox(), maxSize(), and ~SMESH_Octree().

Definition at line 94 of file SMESH_Octree.hxx.

Referenced by buildChildren().

Definition at line 107 of file SMESH_Octree.hxx.

Referenced by buildChildren(), compute(), and level().

const Limit* SMESH_Octree.myLimit [protected]

Definition at line 100 of file SMESH_Octree.hxx.

Referenced by buildChildren(), compute(), isLeaf(), and ~SMESH_Octree().

Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS