OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

octree< Type > Class Template Reference

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

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 > &)

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

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 122 of file octree.H.


Member Enumeration Documentation

enum volumeType

volume types

Enumerator:
UNKNOWN 
MIXED 
INSIDE 
OUTSIDE 

Definition at line 181 of file octree.H.


Constructor & Destructor Documentation

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

Construct from components.

Definition at line 85 of file octree.C.

~octree (  )  [inline]

Definition at line 226 of file octree.C.


Member Function Documentation

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

for debugging:return printable representation of volumeType

Definition at line 32 of file octree.C.

References Foam::abort(), Foam::FatalError, FatalErrorIn, octree< Type >::INSIDE, octree< Type >::MIXED, octree< Type >::OUTSIDE, and octree< Type >::UNKNOWN.

Here is the call graph for this function:

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

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

to point outside.

Definition at line 63 of file octree.C.

const Type& shapes (  )  const [inline]

Definition at line 227 of file octree.H.

Referenced by surfaceFeatures::nearestEdges().

Here is the caller graph for this function:

const treeBoundBox& octreeBb (  )  const [inline]

Definition at line 232 of file octree.H.

scalar maxShapeRatio (  )  const [inline]

Definition at line 237 of file octree.H.

scalar maxLeafRatio (  )  const [inline]

Definition at line 242 of file octree.H.

label minNLevels (  )  const [inline]

Definition at line 247 of file octree.H.

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

Definition at line 254 of file octree.H.

label deepestLevel (  )  const [inline]

Definition at line 259 of file octree.H.

label nEntries (  )  const [inline]

Definition at line 264 of file octree.H.

label nNodes (  )  const [inline]

Definition at line 269 of file octree.H.

label nLeaves (  )  const [inline]

Definition at line 274 of file octree.H.

void setEntries ( const label  n  )  [inline]

Definition at line 279 of file octree.H.

void setNodes ( const label  n  )  [inline]

Definition at line 284 of file octree.H.

void setLeaves ( const label  n  )  [inline]

Definition at line 289 of file octree.H.

Foam::label getSampleType ( const point &  sample  )  const [inline]

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 235 of file octree.C.

Foam::label find ( const point &  sample  )  const [inline]

Find shape containing point in tree.

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

Definition at line 242 of file octree.C.

bool findTightest ( const point &  sample,
treeBoundBox &  tightest 
) const [inline]

Calculate tightest fitting bounding box. Uses.

Type::findTightest.

Definition at line 250 of file octree.C.

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

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

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

Definition at line 266 of file octree.C.

Referenced by boundaryMesh::getNearest(), and surfaceFeatures::nearestEdges().

Here is the caller graph for this function:

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

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 306 of file octree.C.

Foam::labelList findBox ( const boundBox &  bb  )  const [inline]

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

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

Definition at line 333 of file octree.C.

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

Find intersected shape along line. pointIndexHit contains index.

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

Definition at line 346 of file octree.C.

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

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

returns first intersection found, not nessecarily nearest.

Definition at line 427 of file octree.C.

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

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

treeLeaf.

Definition at line 497 of file octree.C.

void writeOBJ ( Ostream &  os,
label &  vertNo 
) const [inline]

Dump graphical representation in .obj format.

Definition at line 560 of file octree.C.

void printStats ( Ostream &  os  )  const [inline]

Print some stats on octree.

Definition at line 608 of file octree.C.

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

iterator set to the begining of the octree

Definition at line 736 of file octree.C.

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

iterator set to beyond the end of the octree

Definition at line 744 of file octree.C.

References octree< Type >::iterator.

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

const_iterator set to the begining of the octree

Definition at line 868 of file octree.C.

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

Definition at line 876 of file octree.C.

References octree< Type >::const_iterator.

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

const_iterator set to beyond the end of the octree

Definition at line 884 of file octree.C.

References octree< Type >::const_iterator.

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

Definition at line 892 of file octree.C.


Friends And Related Function Documentation

friend class iterator [friend]

Definition at line 395 of file octree.H.

Referenced by octree< Type >::end().

friend class const_iterator [friend]

Definition at line 443 of file octree.H.

Referenced by octree< Type >::cbegin(), and octree< Type >::end().

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


The documentation for this class was generated from the following files:
Copyright © 2000-2009 OpenCFD Ltd