VR-Forces 5.0.2 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
spatialSubdivision.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2004 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
6 #ifndef spatialSubdivision_H_
7 #define spatialSubdivision_H_
8 
9 #include "geometry/point.h"
10 #include "geometry/extent.h"
11 
12 #include <vlutil/vlConfig.h>
13 #include <list>
14 #include <vector>
15 #include <assert.h>
16 
17 #include <vlutil/vlPrint.h>
18 
19 class DtGdbNode;
20 
168 template <typename T>
170 {
171 public:
174  typedef std::list<T> DtSpatialSubCellType;
175  typedef typename DtSpatialSubCellType::iterator DtSpatialSubCellIter;
176  typedef typename DtSpatialSubCellType::const_iterator DtSpatialSubCellConstIter;
178 
181 
184  typedef typename std::vector< DtSpatialSubCellType >::iterator DtSpatialSubIter;
185  typedef typename std::vector< DtSpatialSubCellType >::const_iterator DtSpatialSubConstIter;
187 
188 
192  unsigned int cellCountX,
193  unsigned int cellCountY,
194  unsigned int cellCountZ,
195  double cellDx,
196  double cellDy,
197  double cellDz);
198 
201  explicit DtSpatialSubdivision(DtExtent extent,
202  unsigned int cellCountX,
203  unsigned int cellCountY,
204  unsigned int cellCountZ = 1);
205 
208  explicit DtSpatialSubdivision(DtExtent extent,
209  double cellDx,
210  double cellDy,
211  double cellDz = -1.0);
212 
214  virtual ~DtSpatialSubdivision();
215 
216 public:
217 
221  virtual void setExtent(DtExtent extent);
222 
233  virtual void setResolutions(unsigned int cellCountX, unsigned int cellCountY,
234  unsigned int cellCountZ = 1);
235 
245  virtual void resize(DtExtent extent, unsigned int cellCountX,
246  unsigned int cellCountY, unsigned int cellCountZ);
247 
251  virtual void clear();
252 
257  virtual void clearCell(DtSpatialSubIter& cellIter);
258  virtual void clearCell(DtSpatialSubIter& startIter, DtSpatialSubIter& endIter);
259 
262  virtual bool empty() const;
263 
265  virtual unsigned int size() const;
266 
267  //
268  // Accessors
269  //
271 
272  virtual DtSpatialSubIter begin();
273  virtual DtSpatialSubConstIter begin() const;
274 
275  virtual DtSpatialSubIter end();
276  virtual DtSpatialSubConstIter end() const;
278 
285 
287  virtual const DtSpatialSubCellType& at(DtSpatialSubCellIndex index) const;
288 
291  virtual const DtSpatialSubCellType& at(DtSpatialSubCellIndex xIndex,
292  DtSpatialSubCellIndex yIndex, DtSpatialSubCellIndex zIndex) const;
294 
297 
299  virtual const DtSpatialSubCellType& operator[](DtSpatialSubCellIndex index) const;
301 
302 
307 
308  virtual DtSpatialSubCellType& front();
309  virtual const DtSpatialSubCellType& front() const;
310 
311  virtual DtSpatialSubCellType& back();
312  virtual const DtSpatialSubCellType& back() const;
314 
316 
317  virtual const DtPoint& origin() const;
318  virtual void setOrigin(const DtPoint& newOrigin);
320 
322 
323  virtual unsigned int cellCountX() const;
324  virtual unsigned int cellCountY() const;
325  virtual unsigned int cellCountZ() const;
327 
329 
330  virtual double cellDx() const;
331  virtual double cellDy() const;
332  virtual double cellDz() const;
334 
343 
344  virtual bool cell(double x, double y, double z, DtSpatialSubCellType*& cell);
345  virtual bool cell(double x, double y, double z, const DtSpatialSubCellType*& cell) const;
346 
347  virtual bool cell(const DtPoint& containing, DtSpatialSubCellType*& cell);
348  virtual bool cell(const DtPoint& containing, const DtSpatialSubCellType*& cell) const;
350 
360  virtual void offsetToIndices(const DtPoint& offset, DtSpatialSubCellIndex& xIndex,
361  DtSpatialSubCellIndex& yIndex, DtSpatialSubCellIndex& zIndex) const;
362 
366  virtual bool indexIsValid(DtSpatialSubCellIndex index) const;
367  virtual bool indicesAreValid(DtSpatialSubCellIndex xIndex,
368  DtSpatialSubCellIndex yIndex, DtSpatialSubCellIndex zIndex) const;
369 
370  virtual int sizeInBytes() const;
371 
372 protected:
375  bool testInvariant() const;
376 
377 protected:
382 
383  double inverseCellDx() const;
384  double inverseCellDy() const;
385  double inverseCellDz() const;
387 
394  void calculateMinMaxOffsets();
395 
398  void calculateInverseDeltas();
399 
401 
402  unsigned int myCellCountX;
403  unsigned int myCellCountY;
404  unsigned int myCellCountZ;
405 
406  double myCellDx;
407  double myCellDy;
408  double myCellDz;
409 
411 
416 
421 
422  double myMaxOffsetX;
423  double myMaxOffsetY;
424  double myMaxOffsetZ;
426 
427  double myMinOffsetX;
428  double myMinOffsetY;
429  double myMinOffsetZ;
430 
431  std::vector< DtSpatialSubCellType > myCells;
432 };
433 
434 
435 //------------------------------------------------------
436 // INLINE METHODS
437 //------------------------------------------------------
438 // include the inline code
439 #define SPATIALSUBDIVISION_HEADER
440 #include "geometry/spatialSubdivision.inl"
441 #undef SPATIALSUBDIVISION_HEADER
442 
443 #endif
double inverseCellDx() const
virtual ~DtSpatialSubdivision()
Destructor.
virtual bool indicesAreValid(DtSpatialSubCellIndex xIndex, DtSpatialSubCellIndex yIndex, DtSpatialSubCellIndex zIndex) const
double myMaxOffsetY
These are the maximum sizes, in each dimension, of any offset that is to be translated into and index...
Definition: spatialSubdivision.h:423
unsigned int myCellCountX
Definition: spatialSubdivision.h:402
virtual void offsetToIndices(const DtPoint &offset, DtSpatialSubCellIndex &xIndex, DtSpatialSubCellIndex &yIndex, DtSpatialSubCellIndex &zIndex) const
Given an offset vector (local coordinate - origin), return the cell index values. ...
double myCellDz
Definition: spatialSubdivision.h:408
void calculateInverseDeltas()
Calculates the inverse of the cell deltas in each dimension. Used every time an index is calculated f...
double myInverseCellDx
These are used instead of dividing when calculating indexes from an offset.
Definition: spatialSubdivision.h:412
voidpf uLong int origin
Definition: ioapi.h:42
Definition: gdbNode.h:44
void calculateMinMaxOffsets()
Calculates the minimum and maximum sizes, in each dimension, of any offset that is to be translated i...
virtual DtSpatialSubIter begin()
virtual int sizeInBytes() const
virtual bool empty() const
virtual unsigned int cellCountZ() const
virtual const DtPoint & origin() const
Get/Set the origin of the spatial index (the point of lowest X, Y, Z)
double myMaxOffsetZ
These are the maximum sizes, in each dimension, of any offset that is to be translated into and index...
Definition: spatialSubdivision.h:424
DtSpatialSubdivision(const DtPoint &origin, unsigned int cellCountX, unsigned int cellCountY, unsigned int cellCountZ, double cellDx, double cellDy, double cellDz)
Intended default constructor.
unsigned int myCellCountY
Definition: spatialSubdivision.h:403
The DtExtent represents an axis-aligned 3d bounding box.
Definition: extent.h:43
double myMaxOffsetX
These are the maximum sizes, in each dimension, of any offset that is to be translated into and index...
Definition: spatialSubdivision.h:422
virtual bool indexIsValid(DtSpatialSubCellIndex index) const
Check if the given index values are within the spatial subdivision.
bool testInvariant() const
Tests the class invariant. Called at the beginning of every public member function and at the end of ...
double myCellDy
Definition: spatialSubdivision.h:407
virtual DtSpatialSubCellType & operator[](DtSpatialSubCellIndex index)
std::vector< DtSpatialSubCellType > myCells
Definition: spatialSubdivision.h:431
virtual void resize(DtExtent extent, unsigned int cellCountX, unsigned int cellCountY, unsigned int cellCountZ)
Resizes the spatial subdivision to fit the specified extent. This function clears the contents of the...
double myInverseCellDz
These are used instead of dividing when calculating indexes from an offset.
Definition: spatialSubdivision.h:414
double inverseCellDz() const
virtual void clear()
Empties the entire spatial subdivision, removing all contents.
double inverseCellDy() const
virtual void setResolutions(unsigned int cellCountX, unsigned int cellCountY, unsigned int cellCountZ=1)
Warning: clears all contents! Resets the cell counts of the spatial subdivision to the specified valu...
double myMinOffsetZ
Definition: spatialSubdivision.h:429
virtual double cellDx() const
double myMinOffsetY
Definition: spatialSubdivision.h:428
int DtSpatialSubCellIndex
As this is a 3D grid, cells can be addressed by indices as well.
Definition: spatialSubdivision.h:180
virtual unsigned int cellCountX() const
double myInverseCellDy
These are used instead of dividing when calculating indexes from an offset.
Definition: spatialSubdivision.h:413
virtual double cellDz() const
DtSpatialSubCellType::const_iterator DtSpatialSubCellConstIter
Typedefs for the containers used to hold the contained elements.
Definition: spatialSubdivision.h:176
virtual DtSpatialSubCellType & front()
virtual void setOrigin(const DtPoint &newOrigin)
Get/Set the origin of the spatial index (the point of lowest X, Y, Z)
DtSpatialSubCellType::iterator DtSpatialSubCellIter
Typedefs for the containers used to hold the contained elements.
Definition: spatialSubdivision.h:175
double myCellDx
Definition: spatialSubdivision.h:406
Contains the declaration of the DtExtent class.
virtual unsigned int cellCountY() const
The DtSpatialSubdivision class represents a uniform spatial container. The container is divided up in...
Definition: spatialSubdivision.h:169
virtual void setExtent(DtExtent extent)
Resizes the spatial subdivision to fit the specified extent. This function clears the contents of the...
virtual double cellDy() const
std::vector< DtSpatialSubCellType >::const_iterator DtSpatialSubConstIter
Iterator into the spatial subdivision&#39;s cells.
Definition: spatialSubdivision.h:185
virtual void clearCell(DtSpatialSubIter &cellIter)
Clears the cells referenced by the specified iterators.
virtual unsigned int size() const
voidpf uLong offset
Definition: ioapi.h:42
unsigned int myCellCountZ
Definition: spatialSubdivision.h:404
virtual DtSpatialSubCellType & at(DtSpatialSubCellIndex index)
std::vector< DtSpatialSubCellType >::iterator DtSpatialSubIter
Iterator into the spatial subdivision&#39;s cells.
Definition: spatialSubdivision.h:184
std::list< T > DtSpatialSubCellType
Typedefs for the containers used to hold the contained elements.
Definition: spatialSubdivision.h:174
DtPoint myOrigin
Definition: spatialSubdivision.h:400
virtual DtSpatialSubIter end()
Definition: point.h:34
virtual bool cell(double x, double y, double z, DtSpatialSubCellType *&cell)
Get the cell that contains the given coordinate if the coordinate lies within the spatial subdivision...
double myMinOffsetX
Definition: spatialSubdivision.h:427
virtual DtSpatialSubCellType & back()

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)