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 Rotation &rotation, const Rotation &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 Rotation &rotation) const
 
bool isVisibleFromView (unsigned int faceId, const Rotation &viewRotation, const Rotation &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

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

Constructor & Destructor Documentation

inet::Prism::Prism ( )
inline
50 : height(0) {}
double height
Definition: Prism.h:37
inet::Prism::Prism ( double  height,
const Polygon base 
)
22  :
23  height(height),
24  base(base)
25 {
26  if (height > 0)
27  {
28  if (base.getPoints().size() >= 3)
29  {
32  }
33  else
34  throw cRuntimeError("We need at least three points to construct a prism");
35  }
36  else
37  throw cRuntimeError("A prism has a positive height");
38 }
double height
Definition: Prism.h:37
void computeOutwardNormalVectors()
Definition: Prism.cc:112
Polygon base
Definition: Prism.h:38
void genereateFaces()
Definition: Prism.cc:51
const std::vector< Coord > & getPoints() const
Definition: Polygon.h:42

Member Function Documentation

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

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

Implements inet::ShapeBase.

41 {
42  Coord min = base.getPoints()[0];
43  Coord max = min;
44  for (const auto & elem : base.getPoints()) {
45  min = min.min(elem);
46  max = max.max(elem);
47  }
48  return max - min + Coord(0, 0, height);
49 }
double height
Definition: Prism.h:37
double min(const double a, const double b)
Returns the minimum of a and b.
Definition: SCTPAssociation.h:270
double max(double a, double b)
Returns the greater of the given parameters.
Definition: INETMath.h:161
Polygon base
Definition: Prism.h:38
const std::vector< Coord > & getPoints() const
Definition: Polygon.h:42
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.

120 {
121  // Note: based on http://geomalgorithms.com/a13-_intersect-4.html
122  Coord p0 = lineSegment.getPoint1();
123  Coord p1 = lineSegment.getPoint2();
124  if (p0 == p1)
125  {
126  normal1 = normal2 = Coord::NIL;
127  return false;
128  }
129  Coord segmentDirection = p1 - p0;
130  double tE = 0;
131  double tL = 1;
132  for (unsigned int i = 0; i < faces.size(); i++)
133  {
134  Polygon face = faces[i];
135  Coord normalVec = normalVectorsForFaces[i];
136  const std::vector<Coord>& pointList = face.getPoints();
137  Coord f0 = pointList[0];
138  double N = (f0 - p0) * normalVec;
139  double D = segmentDirection * normalVec;
140  if (D < 0)
141  {
142  double t = N / D;
143  if (t > tE)
144  {
145  tE = t;
146  normal1 = normalVec;
147  if (tE > tL)
148  return false;
149  }
150  }
151  else if (D > 0)
152  {
153  double t = N / D;
154  if (t < tL)
155  {
156  tL = t;
157  normal2 = normalVec;
158  if (tL < tE)
159  return false;
160  }
161  }
162  else
163  {
164  if (N < 0)
165  return false;
166  }
167  }
168  if (tE == 0)
169  normal1 = Coord::NIL;
170  if (tL == 1)
171  normal2 = Coord::NIL;
172  intersection1 = p0 + segmentDirection * tE;
173  intersection2 = p0 + segmentDirection * tL;
174  if (intersection1 == intersection2)
175  {
176  normal1 = normal2 = Coord::NIL;
177  return false;
178  }
179  return true;
180 }
static const Coord NIL
Constant with all values set to 0.
Definition: Coord.h:40
std::vector< Coord > normalVectorsForFaces
Definition: Prism.h:40
std::vector< Polygon > faces
Definition: Prism.h:39
compose< m, compose< kg, pow< s,-2 > > > N
Definition: Units.h:767
Coord inet::Prism::computeOutwardNormalVector ( unsigned int  faceId) const
protected

Referenced by computeOutwardNormalVectors().

80 {
81  Polygon face = faces[faceId];
82  Polygon testFace = faces[(faceId + 1) % faces.size()];
83  const std::vector<Coord>& testPoints = testFace.getPoints();
84  // This is a good test point: for convex polygons, the centroid is always an interior point.
85  Coord testCentroid;
86  for (auto & testPoint : testPoints)
87  testCentroid += testPoint;
88  testCentroid /= testPoints.size();
89  Coord facePoint = face.getPoints()[0];
90  Coord faceNormal = face.getNormalVector();
91  if ((testCentroid - facePoint) * faceNormal > 0)
92  return faceNormal * (-1);
93  return faceNormal;
94 }
std::vector< Polygon > faces
Definition: Prism.h:39
void inet::Prism::computeOutwardNormalVectors ( )
protected

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

113 {
114  normalVectorsForFaces.clear();
115  for (unsigned int i = 0; i < faces.size(); i++)
117 }
Coord computeOutwardNormalVector(unsigned int faceId) const
Definition: Prism.cc:79
std::vector< Coord > normalVectorsForFaces
Definition: Prism.h:40
std::vector< Polygon > faces
Definition: Prism.h:39
void inet::Prism::computeVisibleFaces ( std::vector< std::vector< Coord > > &  faces,
const Rotation rotation,
const Rotation viewRotation 
) const

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

213 {
214  for (unsigned int i = 0; i < this->faces.size(); i++)
215  {
216  const Polygon& face = this->faces.at(i);
217  if (isVisibleFromView(i, viewRotation, rotation))
218  {
219  const std::vector<Coord>& facePoints = face.getPoints();
220  std::vector<Coord> points;
221  for (const auto & facePoint : facePoints)
222  points.push_back(facePoint);
223  faces.push_back(points);
224  }
225  }
226 }
std::vector< Polygon > faces
Definition: Prism.h:39
bool isVisibleFromView(unsigned int faceId, const Rotation &viewRotation, const Rotation &rotation) const
Definition: Prism.cc:105
void inet::Prism::genereateFaces ( )
protected

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

52 {
53  faces.clear();
54  faces.push_back(base);
55  Coord baseNormalUnitVector = base.getNormalUnitVector();
56  const std::vector<Coord>& basePoints = base.getPoints();
57  std::vector<Coord> translatedCopyPoints;
58  for (auto & basePoint : basePoints)
59  {
60  Coord point = basePoint;
61  point.z += height;
62  translatedCopyPoints.push_back(point);
63  }
64  Polygon translatedCopy(translatedCopyPoints);
65  faces.push_back(translatedCopy);
66  unsigned int basePointsSize = basePoints.size();
67  for (unsigned int i = 0; i < basePointsSize; i++)
68  {
69  std::vector<Coord> facePoints;
70  facePoints.push_back(basePoints[i]);
71  facePoints.push_back(translatedCopyPoints[i]);
72  facePoints.push_back(translatedCopyPoints[(i+1) % basePointsSize]);
73  facePoints.push_back(basePoints[(i+1) % basePointsSize]);
74  Polygon face(facePoints);
75  faces.push_back(face);
76  }
77 }
double height
Definition: Prism.h:37
Polygon base
Definition: Prism.h:38
std::vector< Polygon > faces
Definition: Prism.h:39
Coord getNormalUnitVector() const
Definition: Polygon.cc:40
const std::vector< Coord > & getPoints() const
Definition: Polygon.h:42
const Polygon& inet::Prism::getBase ( ) const
inline
56 { return base; }
Polygon base
Definition: Prism.h:38
const Faces& inet::Prism::getFaces ( ) const
inline
59 { return faces; }
std::vector< Polygon > faces
Definition: Prism.h:39
double inet::Prism::getHeight ( ) const
inline
53 { return height; }
double height
Definition: Prism.h:37
bool inet::Prism::isVisibleFromPoint ( unsigned int  faceId,
const Coord point,
const Rotation rotation 
) const
protected
97 {
98  const std::vector<Coord>& polygonPoints = faces.at(faceId).getPoints();
99  Coord facePoint = polygonPoints.at(0);
100  Coord facePointPoint = point - facePoint;
101  Coord rotatedFaceNormal = rotation.rotateVectorClockwise(normalVectorsForFaces.at(faceId));
102  return facePointPoint * rotatedFaceNormal > 0;
103 }
std::vector< Coord > normalVectorsForFaces
Definition: Prism.h:40
std::vector< Polygon > faces
Definition: Prism.h:39
bool inet::Prism::isVisibleFromView ( unsigned int  faceId,
const Rotation viewRotation,
const Rotation rotation 
) const
protected

Referenced by computeVisibleFaces().

106 {
107  Coord zNormal(0,0,1);
108  Coord rotatedFaceNormal = viewRotation.rotateVectorClockwise(rotation.rotateVectorClockwise(normalVectorsForFaces.at(faceId)));
109  return rotatedFaceNormal * zNormal > 0;
110 }
std::vector< Coord > normalVectorsForFaces
Definition: Prism.h:40
void inet::Prism::setBase ( const Polygon base)
198 {
199  if (base.getPoints() != this->base.getPoints())
200  {
201  if (base.getPoints().size() >= 3)
202  {
203  this->base = base;
204  genereateFaces();
206  }
207  else
208  throw cRuntimeError("We need at least three points to construct a prism");
209  }
210 }
void computeOutwardNormalVectors()
Definition: Prism.cc:112
Polygon base
Definition: Prism.h:38
void genereateFaces()
Definition: Prism.cc:51
const std::vector< Coord > & getPoints() const
Definition: Polygon.h:42
void inet::Prism::setHeight ( double  height)
183 {
184  if (height != this->height)
185  {
186  if (height > 0)
187  {
188  this->height = height;
189  genereateFaces();
191  }
192  else
193  throw cRuntimeError("A prism has a positive height");
194  }
195 }
double height
Definition: Prism.h:37
void computeOutwardNormalVectors()
Definition: Prism.cc:112
void genereateFaces()
Definition: Prism.cc:51

Member Data Documentation

Polygon inet::Prism::base
protected
double inet::Prism::height
protected
std::vector<Coord> inet::Prism::normalVectorsForFaces
protected

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