FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

octree< Type > Class Template Reference

Octree, templated on type of shapes it refers to. More...

#include <meshTools/octree.H>


Detailed Description

template<class Type>
class Foam::octree< Type >

Octree, templated on type of shapes it refers to.

Uses the octreeData class, which is a list of 1D, 2D or 3D shapes. Various implementations of octreeData which know about cell&meshes, patches&meshes and points.

The octree can be used to

  • find the "nearest" shape to a point
  • find the shape which contains a point (only sensible for 3D shapes)
  • find intersections of line with shapes

The tree consists of

  • treeNode : holds sub-treeNodes or treeLeaves
  • treeLeaf : is the one that actually holds data

The data is stored purely as a list of indices into octreeData.

The construction on the depth of the tree is:

  • one can specify a minimum depth (though the tree will never be refined if all leaves contain <=1 shapes)
  • after the minimum depth two statistics are used to decide further refinement:

average number of entries per leaf (leafRatio). Since inside a leaf most algorithms are n or n^2 this value has to be small.

  • average number of leaves a shape is in. Because of bounding boxes, a single shape can be in multiple leaves. If the bbs are large compared to the leaf size this multiplicity can become extremely large and will become larger with more levels.

Note: the octree gets constructed with an overall bounding box. If your mesh is regular it is a good idea to make this overall bb a bit wider than the bb of the shapes itself. Otherwise lots of shapes end up exactly on the edge of a bb and hence go into more than one subcube.

E.g. octree of face centres of lid driven cavity.

  1. bb exact -> total 1457 leaves (every point in 7.1 leaves)
  2. bb.max incremented by 1% -> total 80 leaves (every point in exactly 1 leaf)
Ideas for parallel implementation:

The data inserted into the octree (the 'octreeData') has to be local to the processor. The data to be looked for (usually a sample point) can be global to the domain. The algorithm:

  • search for all my points
  • collect results which have to do with a processor patch
  • global sum all these. If 0 exit.
  • exchange data on all processor patches
  • start again

So data transfers one processor per iteration. One could think of having an extra search mechanism one level above which does an initial search knowing the average shape of a processor distribution (square/cube for most decomposition methods) and can assign sample points to the (almost) correct processor at once.

Source files

Definition at line 127 of file octree.H.

Collaboration diagram for octree< Type >:

List of all members.

Classes

class  const_iterator
 An STL const_iterator for octree. More...
class  iterator
 An STL iterator for octree. More...

Public Types

enum  volumeType { UNKNOWN, MIXED, INSIDE, OUTSIDE }
 

volume types

More...

Public Member Functions

 octree (const treeBoundBox &octreeBb, const Type &shapes, const label minNLevels, const scalar maxLeafRatio, const scalar maxShapeRatio)
 Construct from components.
 ~octree ()
const Type &  shapes () const
const treeBoundBox &  octreeBb () const
scalar  maxShapeRatio () const
scalar  maxLeafRatio () const
label  minNLevels () const
treeNode< Type > *  topNode () const
label  deepestLevel () const
label  nEntries () const
label  nNodes () const
label  nLeaves () const
void  setEntries (const label n)
void  setNodes (const label n)
void  setLeaves (const label n)
label  getSampleType (const point &sample) const
 Returns type of sample with respect to nearest shape.
label  find (const point &sample) const
 Find shape containing point in tree.
bool  findTightest (const point &sample, treeBoundBox &tightest) const
 Calculate tightest fitting bounding box. Uses.
label  findNearest (const point &sample, treeBoundBox &tightest, scalar &tightestDist) const
 Find nearest shape. Returns index of shape or -1 if not found.
label  findNearest (const linePointRef &ln, treeBoundBox &tightest, point &linePoint, point &shapePoint) const
 Find nearest to line. Returns -1 or index of shape and.
labelList  findBox (const boundBox &bb) const
 Find (in no particular order) indices of all shapes inside or.
pointIndexHit  findLine (const point &start, const point &end) const
 Find intersected shape along line. pointIndexHit contains index.
pointIndexHit  findLineAny (const point &start, const point &end) const
 Like above but just tests whether line hits anything. So.
const treeLeaf< Type > *  findLeafLine (const point &start, const point &end, point &leafIntPoint) const
 Find leaf along line. Set leafIntPoint to leave point of.
void  writeOBJ (Ostream &os, label &vertNo) const
 Dump graphical representation in .obj format.
void  printStats (Ostream &os) const
 Print some stats on octree.
iterator  begin ()
 iterator set to the begining of the octree
const iterator &  end ()
 iterator set to beyond the end of the octree
const_iterator  begin () const
 const_iterator set to the begining of the octree
const_iterator  cbegin () const
const const_iterator &  end () const
 const_iterator set to beyond the end of the octree
const const_iterator &  cend () const

Static Public Member Functions

static string  volType (const label)
 for debugging:return printable representation of volumeType
static label  getVolType (const vector &geomNormal, const vector &vec)
 Code the vector with respect to the geometry. geomNormal guaranteed.

Friends

class  iterator
class  const_iterator
Ostream &  operator (Ostream &, const octree< Type > &)

Member Enumeration Documentation

enum volumeType

volume types

Enumerator:
UNKNOWN 
MIXED 
INSIDE 
OUTSIDE 

Definition at line 180 of file octree.H.


Constructor & Destructor Documentation

octree ( const treeBoundBox &   octreeBb,
const Type &   shapes,
const label   minNLevels,
const scalar   maxLeafRatio,
const scalar   maxShapeRatio  
)

Construct from components.

Definition at line 92 of file octree.C.

References cpuTime::cpuTimeIncrement(), Foam::endl(), and Foam::Pout.

~octree (  )

Definition at line 235 of file octree.C.


Member Function Documentation

Foam::string volType ( const label   type  ) [static]

for debugging:return printable representation of volumeType

Definition at line 39 of file octree.C.

References Foam::abort(), Foam::FatalError, and FatalErrorIn.

Referenced by treeNode< Type >::getSampleType(), treeNode< Type >::printNode(), and treeNode< Type >::setSubNodeType().

Foam::label getVolType ( const vector &   geomNormal,
const vector &   vec  
) [static]

Code the vector with respect to the geometry. geomNormal guaranteed.

to point outside.

Definition at line 70 of file octree.C.

References sign().

Referenced by octreeDataTriSurface::getSampleType(), octreeDataFace::getSampleType(), and octreeDataFaceList::getSampleType().

const Type& shapes (  ) const [inline]

Definition at line 224 of file octree.H.

Referenced by surfaceFeatures::nearestEdges().

const treeBoundBox& octreeBb (  ) const [inline]

Definition at line 229 of file octree.H.

Referenced by surfaceFeatures::nearestSamples().

scalar maxShapeRatio (  ) const [inline]

Definition at line 234 of file octree.H.

scalar maxLeafRatio (  ) const [inline]

Definition at line 239 of file octree.H.

Referenced by treeLeaf< Type >::redistribute().

label minNLevels (  ) const [inline]

Definition at line 244 of file octree.H.

treeNode<Type>* topNode (  ) const [inline]

Definition at line 251 of file octree.H.

label deepestLevel (  ) const [inline]

Definition at line 256 of file octree.H.

label nEntries (  ) const [inline]

Definition at line 261 of file octree.H.

Referenced by treeNode< Type >::distribute(), and treeNode< Type >::redistribute().

label nNodes (  ) const [inline]

Definition at line 266 of file octree.H.

Referenced by treeLeaf< Type >::redistribute().

label nLeaves (  ) const [inline]
void setEntries ( const label   n  ) [inline]

Definition at line 276 of file octree.H.

Referenced by treeNode< Type >::distribute(), and treeNode< Type >::redistribute().

void setNodes ( const label   n  ) [inline]

Definition at line 281 of file octree.H.

Referenced by treeLeaf< Type >::redistribute().

void setLeaves ( const label   n  ) [inline]

Definition at line 286 of file octree.H.

Referenced by treeNode< Type >::distribute(), and treeNode< Type >::redistribute().

Foam::label getSampleType ( const point &   sample  ) const

Returns type of sample with respect to nearest shape.

Meaning of type is determined by shapes.getSampleType(). Normally based on outwards pointing normal. For e.g. octreeDataFace returns one of inside : on other side of normal on nearest face outside : on same side as normal on nearest face unknown : not above nearest face; surface probably not closed. mixed : should never happen

Definition at line 244 of file octree.C.

Foam::label find ( const point &   sample  ) const

Find shape containing point in tree.

Returns -1 if not in found. Uses Type::contains.

Definition at line 251 of file octree.C.

bool findTightest ( const point &   sample,
treeBoundBox &   tightest  
) const

Calculate tightest fitting bounding box. Uses.

Type::findTightest.

Definition at line 259 of file octree.C.

Foam::label findNearest ( const point &   sample,
treeBoundBox &   tightest,
scalar &   tightestDist  
) const

Find nearest shape. Returns index of shape or -1 if not found.

tightestDist is both input and output. Uses Type::calcNearest.

Definition at line 275 of file octree.C.

References Foam::endl(), and Foam::Pout.

Referenced by boundaryMesh::getNearest(), octreeDataTriSurface::getSampleType(), octreeDataFace::getSampleType(), octreeDataFaceList::getSampleType(), surfaceFeatures::nearestEdges(), surfaceFeatures::nearestSamples(), and surfaceFeatures::nearestSurfEdge().

Foam::label findNearest ( const linePointRef &   ln,
treeBoundBox &   tightest,
point &   linePoint,
point &   shapePoint  
) const

Find nearest to line. Returns -1 or index of shape and.

sets:

  • tightest (is both input and output).
  • linePoint : point on line (-GREAT,-GREAT,-GREAT if not found)
  • shapePoint : point on shape (GREAT, GREAT, GREAT if not found) Uses Type::calcNearest.

Definition at line 315 of file octree.C.

Foam::labelList findBox ( const boundBox &   bb  ) const

Find (in no particular order) indices of all shapes inside or.

overlapping bounding box (i.e. all shapes not outside box)

Definition at line 342 of file octree.C.

References HashTable< T, Key, Hash >::toc().

Foam::pointIndexHit findLine ( const point &   start,
const point &   end  
) const

Find intersected shape along line. pointIndexHit contains index.

of nearest shape intersected and the intersection point. Uses findLeafLine.

Definition at line 355 of file octree.C.

References forAll, PointIndexHit< Point >::hit(), treeLeaf< Type >::indices(), PointIndexHit< Point >::setHit(), PointIndexHit< Point >::setIndex(), and PointIndexHit< Point >::setPoint().

Foam::pointIndexHit findLineAny ( const point &   start,
const point &   end  
) const

Like above but just tests whether line hits anything. So.

returns first intersection found, not nessecarily nearest.

Definition at line 436 of file octree.C.

References forAll, PointIndexHit< Point >::hit(), treeLeaf< Type >::indices(), p, PointIndexHit< Point >::setHit(), PointIndexHit< Point >::setIndex(), and PointIndexHit< Point >::setPoint().

const Foam::treeLeaf< Type > * findLeafLine ( const point &   start,
const point &   end,
point &   leafIntPoint  
) const

Find leaf along line. Set leafIntPoint to leave point of.

treeLeaf.

Definition at line 506 of file octree.C.

References Foam::endl(), and Foam::Pout.

void writeOBJ ( Ostream &   os,
label &   vertNo  
) const

Dump graphical representation in .obj format.

Definition at line 569 of file octree.C.

References Foam::endl().

void printStats ( Ostream &   os  ) const

Print some stats on octree.

Definition at line 617 of file octree.C.

References Foam::endl(), and Foam::nl.

Foam::octree< Type >::iterator begin (  )

iterator set to the begining of the octree

Definition at line 745 of file octree.C.

const Foam::octree< Type >::iterator & end (  )

iterator set to beyond the end of the octree

Definition at line 753 of file octree.C.

Foam::octree< Type >::const_iterator begin (  ) const [inline]

const_iterator set to the begining of the octree

Definition at line 877 of file octree.C.

Foam::octree< Type >::const_iterator cbegin (  ) const [inline]

Definition at line 885 of file octree.C.

const Foam::octree< Type >::const_iterator & end (  ) const [inline]

const_iterator set to beyond the end of the octree

Definition at line 893 of file octree.C.

const Foam::octree< Type >::const_iterator & cend (  ) const [inline]

Definition at line 901 of file octree.C.


Friends And Related Function Documentation

friend class iterator [friend]

Definition at line 374 of file octree.H.

friend class const_iterator [friend]

Definition at line 422 of file octree.H.

Ostream& operator ( Ostream &   ,
const octree< Type > &    
) [friend]

The documentation for this class was generated from the following files: