VR-Forces 4.1.1 Class Documentation
chordBundle.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 2001 MAK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************/
5 /*********************************************************************
6 ** $RCSfile: chordBundle.h,v $ $Revision: 1.5 $ $State: Exp $
7 *********************************************************************/
8 #ifndef chordBundle_H_
9 #define chordBundle_H_
10 
11 // \file chordBundle.h
12 // \brief Contains the declaration of the DtChordBundle class.
13 
15 #include <string.h>
16 #include "geometry/tdbextent.h"
17 #include "geometry/chord.h"
18 
19 
20 // \brief This class is a container of DtChords, bundled together for efficiency.
21 //
22 // Instances of DtChordBundle are collections of similar (nearby and probably
23 // parallel) DtChords that can be used to search GDB terrain databases more
24 // efficiently than searching with the DtChords one-by-one.
25 // DtChordBundles store a fixed number of chords directly, and if more than
26 // the limit are added, a child bundle is created and appended on the end.
27 // In order to make the use of this class as efficient as possible (for
28 // bundles smaller than BUNDLE_SIZE), most of its functions are inlined.
30 {
31 public:
32  // The maximum optimal size of a bundle of DtChords. Larger sizes will be
33  // handled correctly, but not as efficiently.
34  enum
35  {
36  BUNDLE_SIZE = 10
37  };
38 
39  // default constructor
40  DtChordBundle();
41 
42  // copy constructor
43  // Note: the copy constructor only copies the bundle, it does not copy the
44  // DtChords pointed to by the bundle.
45  DtChordBundle(const DtChordBundle& orig);
46 
47  // destructor Note: it does not delete the DtChords.
48  virtual ~DtChordBundle();
49 
50  // assignment operator
51  // Note: the assignment operator only copies the DtChord pointers, it does
52  // not delete its old DtChords, nor does it clone the DtChords being added.
53  DtChordBundle& operator=(const DtChordBundle& orig);
54 
55  // Get a particular DtChord pointer from the list
56  const DtChord* operator[](unsigned int index) const;
57 
58  // addToEnd appends a DtChord pointer to the end of the bundle's chord
59  // pointer list.
60  void addToEnd(const DtChord* arg);
61 
62  // removeAll empties the list. Note: it does not delete the DtChords.
63  virtual void removeAll();
64 
65  // Get the total count of DtChords stored in (or below) this bundle.
66  unsigned int count() const;
67 
68  // Get the extents of this bundle.
69  const DtExtent& extent() const;
70 
71 protected:
72  // This function is similar to operator[], except that it is not inline
73  const DtChord* item(unsigned int index);
74 
75  DtChordBundle* clone();
76 
77 protected:
78  // An array of pointers to the DtChords in this bundle
79  const DtChord* myChordArray[BUNDLE_SIZE];
80 
81  // The total count of DtChords in this and child bundles
82  unsigned int myCount;
83 
84  // A pointer to the first child bundle (only used if more than BUNDLE_SIZE
85  // chords have been added)
87 
88  // An extents box that contains all the chords added to this bundle
90 };
91 
92 //
93 // Inline functions
94 //
96  myCount(0),
97  myNextBundle(0),
98  myExtent()
99 {
100  memset(myChordArray, 0, sizeof(myChordArray));
101 }
102 
104  myCount(orig.myCount),
105  myNextBundle(0),
106  myExtent(orig.myExtent)
107 {
108  memcpy(myChordArray, orig.myChordArray, sizeof(myChordArray));
109 
110  if (orig.myNextBundle != 0)
111  {
112  myNextBundle = orig.myNextBundle->clone();
113  }
114 }
115 
117 {
118  if (myNextBundle != 0)
119  {
120  delete myNextBundle;
121  myNextBundle = 0;
122  }
123 }
124 
125 inline const DtChord* DtChordBundle::operator[](unsigned int index) const
126 {
127  if (index < BUNDLE_SIZE)
128  {
129  return myChordArray[index];
130  }
131  else if (myNextBundle == 0)
132  {
133  return 0;
134  }
135  else
136  {
137  return myNextBundle->item(index - BUNDLE_SIZE);
138  }
139 }
140 
141 inline void DtChordBundle::addToEnd(const DtChord* arg)
142 {
143  if (arg == 0)
144  {
145  return;
146  }
147 
149 
150  if (myCount < BUNDLE_SIZE)
151  {
152  myChordArray[myCount++] = arg;
153  return;
154  }
155 
156  if (myCount == BUNDLE_SIZE)
157  {
158  myNextBundle = new DtChordBundle();
159  }
160 
161  myNextBundle->addToEnd(arg);
162 }
163 
164 inline unsigned int DtChordBundle::count() const
165 {
166  return myCount;
167 }
168 
169 inline const DtExtent& DtChordBundle::extent() const
170 {
171  return myExtent;
172 }
173 
174 #endif

Document ID: Generated on Mon Apr 8 19:24:01 EDT 2013 from SVN revision 125877
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)