VR-Forces 4.0.4 Class Documentation
include/geometry/chordBundle.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 ** Copyright (c) 2001 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 *********************************************************************/
00005 /*********************************************************************
00006 ** $RCSfile: chordBundle.h,v $ $Revision: 1.5 $ $State: Exp $
00007 *********************************************************************/
00008 #ifndef chordBundle_H_
00009 #define chordBundle_H_
00010 
00011 // \file chordBundle.h 
00012 // \brief Contains the declaration of the DtChordBundle class.
00013 
00014 #include "geometry/geometryDefines.h"
00015 #include <string.h>
00016 #include "geometry/tdbextent.h"
00017 #include "geometry/chord.h"
00018 
00019 
00020 // \brief This class is a container of DtChords, bundled together for efficiency.
00021 //
00022 // Instances of DtChordBundle are collections of similar (nearby and probably
00023 // parallel) DtChords that can be used to search GDB terrain databases more
00024 // efficiently than searching with the DtChords one-by-one. 
00025 // DtChordBundles store a fixed number of chords directly, and if more than
00026 // the limit are added, a child bundle is created and appended on the end.
00027 // In order to make the use of this class as efficient as possible (for
00028 // bundles smaller than BUNDLE_SIZE), most of its functions are inlined.
00029 class DT_DLL_geometry DtChordBundle
00030 {
00031 public:
00032    // The maximum optimal size of a bundle of DtChords.  Larger sizes will be
00033    // handled correctly, but not as efficiently.
00034    enum
00035    {
00036       BUNDLE_SIZE = 10
00037    };
00038 
00039    // default constructor
00040    DtChordBundle();
00041 
00042    // copy constructor
00043    // Note: the copy constructor only copies the bundle, it does not copy the
00044    // DtChords pointed to by the bundle.
00045    DtChordBundle(const DtChordBundle& orig);
00046 
00047    // destructor  Note: it does not delete the DtChords.
00048    virtual ~DtChordBundle();
00049 
00050    // assignment operator
00051    // Note: the assignment operator only copies the DtChord pointers, it does
00052    // not delete its old DtChords, nor does it clone the DtChords being added.
00053    DtChordBundle& operator=(const DtChordBundle& orig);
00054 
00055    // Get a particular DtChord pointer from the list
00056    const DtChord* operator[](unsigned int index) const;
00057 
00058    // addToEnd appends a DtChord pointer to the end of the bundle's chord
00059    // pointer list.
00060    void addToEnd(const DtChord* arg);
00061 
00062    // removeAll empties the list.  Note: it does not delete the DtChords.
00063    virtual void removeAll();
00064    
00065    // Get the total count of DtChords stored in (or below) this bundle.
00066    unsigned int count() const;
00067 
00068    // Get the extents of this bundle.
00069    const DtExtent& extent() const;
00070 
00071 protected:
00072    // This function is similar to operator[], except that it is not inline
00073    const DtChord* item(unsigned int index);
00074 
00075    DtChordBundle* clone();
00076 
00077 protected:
00078    // An array of pointers to the DtChords in this bundle
00079    const DtChord* myChordArray[BUNDLE_SIZE];
00080 
00081    // The total count of DtChords in this and child bundles
00082    unsigned int myCount;
00083 
00084    // A pointer to the first child bundle (only used if more than BUNDLE_SIZE
00085    // chords have been added)
00086    DtChordBundle* myNextBundle;
00087 
00088    // An extents box that contains all the chords added to this bundle
00089    DtExtent myExtent;
00090 };
00091 
00092 //
00093 // Inline functions
00094 //
00095 inline DtChordBundle::DtChordBundle() :
00096    myCount(0),
00097    myNextBundle(0),
00098    myExtent()
00099 {
00100    memset(myChordArray, 0, sizeof(myChordArray));
00101 }
00102 
00103 inline DtChordBundle::DtChordBundle(const DtChordBundle& orig) :
00104    myCount(orig.myCount),
00105    myNextBundle(0),
00106    myExtent(orig.myExtent)
00107 {
00108    memcpy(myChordArray, orig.myChordArray, sizeof(myChordArray));
00109 
00110    if (orig.myNextBundle != 0)
00111    {
00112       myNextBundle = orig.myNextBundle->clone();
00113    }
00114 }
00115 
00116 inline DtChordBundle::~DtChordBundle() 
00117 {
00118    if (myNextBundle != 0)
00119    {
00120       delete myNextBundle;
00121       myNextBundle = 0;
00122    }
00123 }
00124 
00125 inline const DtChord* DtChordBundle::operator[](unsigned int index) const
00126 {
00127    if (index < BUNDLE_SIZE)
00128    {
00129       return myChordArray[index];
00130    }
00131    else if (myNextBundle == 0)
00132    {
00133       return 0;
00134    }
00135    else
00136    {
00137       return myNextBundle->item(index - BUNDLE_SIZE);
00138    }
00139 }
00140 
00141 inline void DtChordBundle::addToEnd(const DtChord* arg)
00142 {
00143    if (arg == 0)
00144    {
00145       return;
00146    }
00147 
00148    myExtent.expandToInclude(arg->extent());
00149 
00150    if (myCount < BUNDLE_SIZE)
00151    {
00152       myChordArray[myCount++] = arg;
00153       return;
00154    }
00155 
00156    if (myCount == BUNDLE_SIZE)
00157    {
00158       myNextBundle = new DtChordBundle();
00159    }
00160 
00161    myNextBundle->addToEnd(arg);
00162 }
00163 
00164 inline unsigned int DtChordBundle::count() const
00165 {
00166    return myCount;
00167 }
00168 
00169 inline const DtExtent& DtChordBundle::extent() const
00170 {
00171    return myExtent;
00172 }
00173 
00174 #endif

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)