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

This class represents 3 dimensional prism with a polygon base face. More...

#include <Prism.h>

Inheritance diagram for inet::Prism:
inet::ShapeBase

Public Types

typedef std::vector< PolygonFaces
 
typedef std::vector< CoordPoints
 

Public Member Functions

 Prism ()
 
 Prism (double height, const Polygon &base)
 
double getHeight () const
 
void setHeight (double height)
 
const PolygongetBase () const
 
void setBase (const Polygon &base)
 
const FacesgetFaces () const
 
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...
 
void computeVisibleFaces (std::vector< std::vector< Coord >> &faces, const RotationMatrix &rotation, const RotationMatrix &viewRotation) const
 
- Public Member Functions inherited from inet::ShapeBase
 ShapeBase ()
 
virtual ~ShapeBase ()
 

Protected Member Functions

void genereateFaces ()
 
Coord computeOutwardNormalVector (unsigned int faceId) const
 
void computeOutwardNormalVectors ()
 
bool isVisibleFromPoint (unsigned int faceId, const Coord &point, const RotationMatrix &rotation) const
 
bool isVisibleFromView (unsigned int faceId, const RotationMatrix &viewRotation, const RotationMatrix &rotation) const
 

Protected Attributes

double height
 
Polygon base
 
std::vector< Polygonfaces
 
std::vector< CoordnormalVectorsForFaces
 

Detailed Description

This class represents 3 dimensional prism with a polygon base face.

Member Typedef Documentation

◆ Faces

typedef std::vector<Polygon> inet::Prism::Faces

◆ Points

typedef std::vector<Coord> inet::Prism::Points

Constructor & Destructor Documentation

◆ Prism() [1/2]

inet::Prism::Prism ( )
inline
40 : height(0) {}

◆ Prism() [2/2]

inet::Prism::Prism ( double  height,
const Polygon base 
)
12  :
13  height(height),
14  base(base)
15 {
16  if (height > 0) {
17  if (base.getPoints().size() >= 3) {
20  }
21  else
22  throw cRuntimeError("We need at least three points to construct a prism");
23  }
24  else
25  throw cRuntimeError("A prism has a positive height");
26 }

Member Function Documentation

◆ computeBoundingBoxSize()

Coord inet::Prism::computeBoundingBoxSize ( ) const
overridevirtual

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

Implements inet::ShapeBase.

29 {
30  Coord min = base.getPoints()[0];
31  Coord max = min;
32  for (const auto& elem : base.getPoints()) {
33  min = min.min(elem);
34  max = max.max(elem);
35  }
36  return max - min + Coord(0, 0, height);
37 }

◆ computeIntersection()

bool inet::Prism::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.

106 {
107  // Note: based on http://geomalgorithms.com/a13-_intersect-4.html
108  const auto& p0 = lineSegment.getPoint1();
109  const auto& p1 = lineSegment.getPoint2();
110  if (p0 == p1) {
111  normal1 = normal2 = Coord::NIL;
112  return false;
113  }
114  Coord segmentDirection = p1 - p0;
115  double tE = 0;
116  double tL = 1;
117  for (unsigned int i = 0; i < faces.size(); i++) {
118  const auto& face = faces[i];
119  const auto& normalVec = normalVectorsForFaces[i];
120  const std::vector<Coord>& pointList = face.getPoints();
121  const auto& f0 = pointList[0];
122  double N = (f0 - p0) * normalVec;
123  double D = segmentDirection * normalVec;
124  if (D < 0) {
125  double t = N / D;
126  if (t > tE) {
127  tE = t;
128  normal1 = normalVec;
129  if (tE > tL)
130  return false;
131  }
132  }
133  else if (D > 0) {
134  double t = N / D;
135  if (t < tL) {
136  tL = t;
137  normal2 = normalVec;
138  if (tL < tE)
139  return false;
140  }
141  }
142  else {
143  if (N < 0)
144  return false;
145  }
146  }
147  if (tE == 0)
148  normal1 = Coord::NIL;
149  if (tL == 1)
150  normal2 = Coord::NIL;
151  intersection1 = p0 + segmentDirection * tE;
152  intersection2 = p0 + segmentDirection * tL;
153  if (intersection1 == intersection2) {
154  normal1 = normal2 = Coord::NIL;
155  return false;
156  }
157  return true;
158 }

◆ computeOutwardNormalVector()

Coord inet::Prism::computeOutwardNormalVector ( unsigned int  faceId) const
protected
66 {
67  Polygon face = faces[faceId];
68  Polygon testFace = faces[(faceId + 1) % faces.size()];
69  const std::vector<Coord>& testPoints = testFace.getPoints();
70  // This is a good test point: for convex polygons, the centroid is always an interior point.
71  Coord testCentroid;
72  for (auto& testPoint : testPoints)
73  testCentroid += testPoint;
74  testCentroid /= testPoints.size();
75  Coord facePoint = face.getPoints()[0];
76  Coord faceNormal = face.getNormalVector();
77  if ((testCentroid - facePoint) * faceNormal > 0)
78  return faceNormal * (-1);
79  return faceNormal;
80 }

Referenced by computeOutwardNormalVectors().

◆ computeOutwardNormalVectors()

void inet::Prism::computeOutwardNormalVectors ( )
protected
99 {
100  normalVectorsForFaces.clear();
101  for (unsigned int i = 0; i < faces.size(); i++)
103 }

Referenced by Prism(), setBase(), and setHeight().

◆ computeVisibleFaces()

void inet::Prism::computeVisibleFaces ( std::vector< std::vector< Coord >> &  faces,
const RotationMatrix rotation,
const RotationMatrix viewRotation 
) const
187 {
188  for (unsigned int i = 0; i < this->faces.size(); i++) {
189  const Polygon& face = this->faces.at(i);
190  if (isVisibleFromView(i, viewRotation, rotation)) {
191  const std::vector<Coord>& facePoints = face.getPoints();
192  std::vector<Coord> points;
193  for (const auto& facePoint : facePoints)
194  points.push_back(facePoint);
195  faces.push_back(points);
196  }
197  }
198 }

Referenced by inet::Cuboid::computeVisibleFaces(), and inet::visualizer::PhysicalEnvironmentCanvasVisualizer::refreshDisplay().

◆ genereateFaces()

void inet::Prism::genereateFaces ( )
protected
40 {
41  faces.clear();
42  faces.push_back(base);
43  // TODO Coord baseNormalUnitVector = base.getNormalUnitVector();
44  const std::vector<Coord>& basePoints = base.getPoints();
45  std::vector<Coord> translatedCopyPoints;
46  for (auto& basePoint : basePoints) {
47  Coord point = basePoint;
48  point.z += height;
49  translatedCopyPoints.push_back(point);
50  }
51  Polygon translatedCopy(translatedCopyPoints);
52  faces.push_back(translatedCopy);
53  unsigned int basePointsSize = basePoints.size();
54  for (unsigned int i = 0; i < basePointsSize; i++) {
55  std::vector<Coord> facePoints;
56  facePoints.push_back(basePoints[i]);
57  facePoints.push_back(translatedCopyPoints[i]);
58  facePoints.push_back(translatedCopyPoints[(i + 1) % basePointsSize]);
59  facePoints.push_back(basePoints[(i + 1) % basePointsSize]);
60  Polygon face(facePoints);
61  faces.push_back(face);
62  }
63 }

Referenced by Prism(), setBase(), and setHeight().

◆ getBase()

const Polygon& inet::Prism::getBase ( ) const
inline

◆ getFaces()

const Faces& inet::Prism::getFaces ( ) const
inline

◆ getHeight()

double inet::Prism::getHeight ( ) const
inline

◆ isVisibleFromPoint()

bool inet::Prism::isVisibleFromPoint ( unsigned int  faceId,
const Coord point,
const RotationMatrix rotation 
) const
protected
83 {
84  const std::vector<Coord>& polygonPoints = faces.at(faceId).getPoints();
85  Coord facePoint = polygonPoints.at(0);
86  Coord facePointPoint = point - facePoint;
87  Coord rotatedFaceNormal = rotation.rotateVector(normalVectorsForFaces.at(faceId));
88  return facePointPoint * rotatedFaceNormal > 0;
89 }

◆ isVisibleFromView()

bool inet::Prism::isVisibleFromView ( unsigned int  faceId,
const RotationMatrix viewRotation,
const RotationMatrix rotation 
) const
protected
92 {
93  Coord zNormal(0, 0, 1);
94  Coord rotatedFaceNormal = viewRotation.rotateVector(rotation.rotateVector(normalVectorsForFaces.at(faceId)));
95  return rotatedFaceNormal * zNormal > 0;
96 }

Referenced by computeVisibleFaces().

◆ setBase()

void inet::Prism::setBase ( const Polygon base)
174 {
175  if (base.getPoints() != this->base.getPoints()) {
176  if (base.getPoints().size() >= 3) {
177  this->base = base;
178  genereateFaces();
180  }
181  else
182  throw cRuntimeError("We need at least three points to construct a prism");
183  }
184 }

◆ setHeight()

void inet::Prism::setHeight ( double  height)
161 {
162  if (height != this->height) {
163  if (height > 0) {
164  this->height = height;
165  genereateFaces();
167  }
168  else
169  throw cRuntimeError("A prism has a positive height");
170  }
171 }

Member Data Documentation

◆ base

Polygon inet::Prism::base
protected

◆ faces

◆ height

double inet::Prism::height
protected

◆ normalVectorsForFaces

std::vector<Coord> inet::Prism::normalVectorsForFaces
protected

The documentation for this class was generated from the following files:
inet::Prism::height
double height
Definition: Prism.h:27
inet::Prism::base
Polygon base
Definition: Prism.h:28
inet::sctp::min
double min(const double a, const double b)
Returns the minimum of a and b.
Definition: SctpAssociation.h:261
inet::units::units::N
compose< m, compose< kg, pow< s, -2 > > > N
Definition: Units.h:936
inet::Polygon::getPoints
const std::vector< Coord > & getPoints() const
Definition: Polygon.h:32
inet::Prism::computeOutwardNormalVector
Coord computeOutwardNormalVector(unsigned int faceId) const
Definition: Prism.cc:65
inet::Prism::isVisibleFromView
bool isVisibleFromView(unsigned int faceId, const RotationMatrix &viewRotation, const RotationMatrix &rotation) const
Definition: Prism.cc:91
inet::sctp::max
double max(const double a, const double b)
Returns the maximum of a and b.
Definition: SctpAssociation.h:266
inet::Prism::normalVectorsForFaces
std::vector< Coord > normalVectorsForFaces
Definition: Prism.h:30
inet::Prism::faces
std::vector< Polygon > faces
Definition: Prism.h:29
inet::Coord::NIL
static const Coord NIL
Constant with all values set to 0.
Definition: Coord.h:26
inet::Prism::computeOutwardNormalVectors
void computeOutwardNormalVectors()
Definition: Prism.cc:98
inet::Prism::genereateFaces
void genereateFaces()
Definition: Prism.cc:39