INET Framework for OMNeT++/OMNEST
inet::Cuboid Class Reference

This class represents a 3 dimensional shape with 6 pairwise parallel faces. More...

#include <Cuboid.h>

Inheritance diagram for inet::Cuboid:
inet::ShapeBase

Public Member Functions

 Cuboid (const Coord &size)
 
const CoordgetSize () const
 
void setSize (const Coord &size)
 
virtual Coord computeBoundingBoxSize () const override
 Computes the 3 dimensional size of the shapes's bounding box. More...
 
virtual bool computeIntersection (const LineSegment &lineSegment, Coord &intersection1, Coord &intersection2, Coord &normal1, Coord &normal2) const override
 Computes the intersection with the given line segment in the shape's coordinate system. More...
 
virtual void computeVisibleFaces (std::vector< std::vector< Coord > > &faces, const Rotation &rotation, const Rotation &viewRotation) const
 
- Public Member Functions inherited from inet::ShapeBase
 ShapeBase ()
 
virtual ~ShapeBase ()
 

Protected Member Functions

bool isInsideX (const Coord &point) const
 
bool isInsideY (const Coord &point) const
 
bool isInsideZ (const Coord &point) const
 

Protected Attributes

Coord size
 

Detailed Description

This class represents a 3 dimensional shape with 6 pairwise parallel faces.

Constructor & Destructor Documentation

inet::Cuboid::Cuboid ( const Coord size)
25  :
26  size(size)
27 {
28 }
Coord size
Definition: Cuboid.h:32

Member Function Documentation

virtual Coord inet::Cuboid::computeBoundingBoxSize ( ) const
inlineoverridevirtual

Computes the 3 dimensional size of the shapes's bounding box.

Implements inet::ShapeBase.

43 { return size; }
Coord size
Definition: Cuboid.h:32
bool inet::Cuboid::computeIntersection ( const LineSegment lineSegment,
Coord intersection1,
Coord intersection2,
Coord normal1,
Coord normal2 
) const
overridevirtual

Computes the intersection with the given line segment in the shape's coordinate system.

Implements inet::ShapeBase.

Referenced by inet::visualizer::VisualizerBase::getContactPosition(), and inet::BVHTree::intersectWithLineSegment().

31 {
32  // TODO: heavily used function, optimize
33  Coord minPoint = size / -2;
34  Coord maxPoint = size / 2;
35  intersection1 = intersection2 = normal1 = normal2 = Coord::NIL;
36  const Coord& point1 = lineSegment.getPoint1();
37  const Coord& point2 = lineSegment.getPoint2();
38  bool isInside1 = isInsideX(point1) && isInsideY(point1) && isInsideZ(point1);
39  bool isInside2 = isInsideX(point2) && isInsideY(point2) && isInsideZ(point2);
40  if (isInside1)
41  intersection1 = point1;
42  if (isInside2)
43  intersection2 = point2;
44  if (isInside1 && isInside2)
45  return true;
46  // x min
47  Coord xMinNormal(-1, 0, 0);
48  Coord xMinIntersecion = Plane(minPoint, xMinNormal).computeIntersection(lineSegment);
49  if (!xMinIntersecion.isNil() && isInsideY(xMinIntersecion) && isInsideZ(xMinIntersecion)) {
50  if (point1.x < minPoint.x) {
51  intersection1 = xMinIntersecion;
52  normal1 = xMinNormal;
53  }
54  else {
55  intersection2 = xMinIntersecion;
56  normal2 = xMinNormal;
57  }
58  }
59  // x max
60  Coord xMaxNormal(1, 0, 0);
61  Coord xMaxIntersection = Plane(maxPoint, xMaxNormal).computeIntersection(lineSegment);
62  if (!xMaxIntersection.isNil() && isInsideY(xMaxIntersection) && isInsideZ(xMaxIntersection)) {
63  if (point1.x > maxPoint.x) {
64  intersection1 = xMaxIntersection;
65  normal1 = xMaxNormal;
66  }
67  else {
68  intersection2 = xMaxIntersection;
69  normal2 = xMaxNormal;
70  }
71  }
72  // y min
73  Coord yMinNormal(0, -1, 0);
74  Coord yMinIntersection = Plane(minPoint, yMinNormal).computeIntersection(lineSegment);
75  if (!yMinIntersection.isNil() && isInsideX(yMinIntersection) && isInsideZ(yMinIntersection)) {
76  if (point1.y < minPoint.y) {
77  intersection1 = yMinIntersection;
78  normal1 = yMinNormal;
79  }
80  else {
81  intersection2 = yMinIntersection;
82  normal2 = yMinNormal;
83  }
84  }
85  // y max
86  Coord yMaxNormal(0, 1, 0);
87  Coord yMaxIntersection = Plane(maxPoint, yMaxNormal).computeIntersection(lineSegment);
88  if (!yMaxIntersection.isNil() && isInsideX(yMaxIntersection) && isInsideZ(yMaxIntersection)) {
89  if (point1.y > maxPoint.y) {
90  intersection1 = yMaxIntersection;
91  normal1 = yMaxNormal;
92  }
93  else {
94  intersection2 = yMaxIntersection;
95  normal2 = yMaxNormal;
96  }
97  }
98  // z min
99  Coord zMinNormal(0, 0, -1);
100  Coord zMinIntersection = Plane(minPoint, zMinNormal).computeIntersection(lineSegment);
101  if (!zMinIntersection.isNil() && isInsideX(zMinIntersection) && isInsideY(zMinIntersection)) {
102  if (point1.z < minPoint.z) {
103  intersection1 = zMinIntersection;
104  normal1 = zMinNormal;
105  }
106  else {
107  intersection2 = zMinIntersection;
108  normal2 = zMinNormal;
109  }
110  }
111  // z max
112  Coord zMaxNormal(0, 0, 1);
113  Coord zMaxIntersection = Plane(maxPoint, zMaxNormal).computeIntersection(lineSegment);
114  if (!zMaxIntersection.isNil() && isInsideX(zMaxIntersection) && isInsideY(zMaxIntersection)) {
115  if (point1.z > maxPoint.z) {
116  intersection1 = zMaxIntersection;
117  normal1 = zMaxNormal;
118  }
119  else {
120  intersection2 = zMaxIntersection;
121  normal2 = zMaxNormal;
122  }
123  }
124  return !intersection1.isUnspecified() && !intersection2.isUnspecified();
125 }
bool isInsideY(const Coord &point) const
Definition: Cuboid.h:36
Coord size
Definition: Cuboid.h:32
bool isInsideX(const Coord &point) const
Definition: Cuboid.h:35
static const Coord NIL
Constant with all values set to 0.
Definition: Coord.h:40
bool isInsideZ(const Coord &point) const
Definition: Cuboid.h:37
void inet::Cuboid::computeVisibleFaces ( std::vector< std::vector< Coord > > &  faces,
const Rotation rotation,
const Rotation viewRotation 
) const
virtual

Referenced by inet::visualizer::PhysicalEnvironmentCanvasVisualizer::refreshDisplay().

128 {
129  // TODO: specialize
130  std::vector<Coord> polygonPoints;
131  polygonPoints.push_back(Coord(-size.x / 2, -size.y / 2, -size.z / 2));
132  polygonPoints.push_back(Coord(-size.x / 2, size.y / 2, -size.z / 2));
133  polygonPoints.push_back(Coord(size.x / 2, size.y / 2, -size.z / 2));
134  polygonPoints.push_back(Coord(size.x / 2, -size.y / 2, -size.z / 2));
135  Polygon base(polygonPoints);
136  Prism prism(size.z, base);
137  prism.computeVisibleFaces(faces, rotation, viewRotation);
138 }
Coord size
Definition: Cuboid.h:32
double z
Definition: Coord.h:51
double y
Definition: Coord.h:50
double x
Definition: Coord.h:49
const Coord& inet::Cuboid::getSize ( ) const
inline
41 { return size; }
Coord size
Definition: Cuboid.h:32
bool inet::Cuboid::isInsideX ( const Coord point) const
inlineprotected

Referenced by computeIntersection().

35 { return -size.x / 2 <= point.x && point.x <= size.x / 2; }
Coord size
Definition: Cuboid.h:32
double x
Definition: Coord.h:49
bool inet::Cuboid::isInsideY ( const Coord point) const
inlineprotected

Referenced by computeIntersection().

36 { return -size.y / 2 <= point.y && point.y <= size.y / 2; }
Coord size
Definition: Cuboid.h:32
double y
Definition: Coord.h:50
bool inet::Cuboid::isInsideZ ( const Coord point) const
inlineprotected

Referenced by computeIntersection().

37 { return -size.z / 2 <= point.z && point.z <= size.z / 2; }
Coord size
Definition: Cuboid.h:32
double z
Definition: Coord.h:51
void inet::Cuboid::setSize ( const Coord size)
inline
42 { this->size = size; }
Coord size
Definition: Cuboid.h:32

Member Data Documentation

Coord inet::Cuboid::size
protected

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