INET Framework for OMNeT++/OMNEST
inet::SpatialGrid::LineSegmentIterator Class Reference

#include <SpatialGrid.h>

Public Member Functions

 LineSegmentIterator (const SpatialGrid *spatialGrid, const LineSegment &lineSegment, const Triplet< double > &voxelSizes, const Triplet< int > &numVoxels)
 
LineSegmentIteratoroperator++ ()
 
const Triplet< int > & getMatrixIndices () const
 
bool end () const
 

Protected Attributes

Triplet< int > index
 
Triplet< int > endPoint
 
Triplet< int > step
 
Triplet< double > tDelta
 
Triplet< double > tExit
 
bool reachedEnd
 

Constructor & Destructor Documentation

inet::SpatialGrid::LineSegmentIterator::LineSegmentIterator ( const SpatialGrid spatialGrid,
const LineSegment lineSegment,
const Triplet< double > &  voxelSizes,
const Triplet< int > &  numVoxels 
)
199 {
200  reachedEnd = false;
201  Coord p0 = lineSegment.getPoint1();
202  Coord p1 = lineSegment.getPoint2();
203  Coord segmentDirection = p1 - p0;
204  Triplet<double> point0 = Triplet<double>(p0.x - spatialGrid->constraintAreaMin.x, p0.y - spatialGrid->constraintAreaMin.y, p0.z - spatialGrid->constraintAreaMin.z);
205  Triplet<double> direction = Triplet<double>(segmentDirection.x, segmentDirection.y, segmentDirection.z);
206  index = spatialGrid->coordToMatrixIndices(p0);
207  endPoint = spatialGrid->coordToMatrixIndices(p1);
208  for (int i = 0; i < 3; i++)
209  {
210  tDelta[i] = voxelSizes[i] / std::abs(direction[i]);
211  double ithdirection = direction[i];
212  if (ithdirection > 0)
213  step[i] = 1;
214  else if (ithdirection < 0)
215  step[i] = -1;
216  else
217  step[i] = 0;
218  if (ithdirection != 0) {
219  double d = point0[i] - index[i] * voxelSizes[i];
220  if (step[i] > 0)
221  d = voxelSizes[i] - d;
222  ASSERT(d >= 0 && d <= voxelSizes[i]);
223  tExit[i] = d / std::abs(ithdirection);
224  }
225  else
227  }
228 }
Triplet< int > endPoint
Definition: SpatialGrid.h:79
Triplet< int > step
Definition: SpatialGrid.h:80
bool reachedEnd
Definition: SpatialGrid.h:83
Triplet< double > tExit
Definition: SpatialGrid.h:82
double max(double a, double b)
Returns the greater of the given parameters.
Definition: INETMath.h:161
Triplet< double > tDelta
Definition: SpatialGrid.h:81
Triplet< int > index
Definition: SpatialGrid.h:78

Member Function Documentation

bool inet::SpatialGrid::LineSegmentIterator::end ( ) const
inline

Referenced by inet::SpatialGrid::lineSegmentQuery().

88 { return reachedEnd; }
bool reachedEnd
Definition: SpatialGrid.h:83
const Triplet<int>& inet::SpatialGrid::LineSegmentIterator::getMatrixIndices ( ) const
inline
87 { return index; }
Triplet< int > index
Definition: SpatialGrid.h:78
SpatialGrid::LineSegmentIterator & inet::SpatialGrid::LineSegmentIterator::operator++ ( )
231 {
232  if (index.x != endPoint.x || index.y != endPoint.y || index.z != endPoint.z)
233  {
234  int axis = 0;
235  if (tExit.x < tExit.y)
236  {
237  if (tExit.x < tExit.z)
238  axis = 0;
239  else
240  axis = 2;
241  }
242  else if (tExit.y < tExit.z)
243  axis = 1;
244  else
245  axis = 2;
246  index[axis] += step[axis];
247  tExit[axis] += tDelta[axis];
248  }
249  else
250  reachedEnd = true;
251  return *this;
252 }
T z
Definition: SpatialGrid.h:44
Triplet< int > endPoint
Definition: SpatialGrid.h:79
Triplet< int > step
Definition: SpatialGrid.h:80
bool reachedEnd
Definition: SpatialGrid.h:83
Triplet< double > tExit
Definition: SpatialGrid.h:82
T x
Definition: SpatialGrid.h:42
T y
Definition: SpatialGrid.h:43
Triplet< double > tDelta
Definition: SpatialGrid.h:81
Triplet< int > index
Definition: SpatialGrid.h:78

Member Data Documentation

Triplet<int> inet::SpatialGrid::LineSegmentIterator::endPoint
protected
Triplet<int> inet::SpatialGrid::LineSegmentIterator::index
protected
bool inet::SpatialGrid::LineSegmentIterator::reachedEnd
protected
Triplet<int> inet::SpatialGrid::LineSegmentIterator::step
protected
Triplet<double> inet::SpatialGrid::LineSegmentIterator::tDelta
protected
Triplet<double> inet::SpatialGrid::LineSegmentIterator::tExit
protected

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