WSF
WsfZoneDefinition.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFZONEDEFINITION_HPP
13#define WSFZONEDEFINITION_HPP
14
15#include "wsf_export.h"
16
17#include <vector>
18
19class UtEntity;
20class UtInput;
21class UtInputBlock;
22#include "UtVec2.hpp"
23#include "UtVec3.hpp"
24class WsfDraw;
25class WsfGeoPoint;
26class WsfPlatform;
27#include "WsfZone.hpp"
28
30
32{
33public:
37 ~WsfZoneDefinition() override = default;
38
39 WsfZone* Clone() const override;
40
41 bool PointIsInside(WsfSimulation* aSimulationPtr,
42 const double aViewedPointWCS[3],
43 const double aEyePointWCS[3],
44 const double aLookHeading,
45 const double aDeltaDownRange = 0.0) override;
46
47 double CheckIntersections(const double aLLA1[3], const double aLLA2[3]) override;
48
49 void Initialize(const WsfScenario& aScenario) override;
50
51 bool ProcessInput(UtInput& aInput) override;
52
58
67
69 void UpdateReference(const WsfSimulation& aSimulation);
70
72 void SetReference(UtEntity& aReference);
73
75 void SetReference(const WsfGeoPoint& aReference, double aReferenceHeading);
76
78 void SetReference(double aReferenceWCS[3], double aReferenceHeading);
79
81 void SetReference(double aReferenceLat, double aReferenceLon, double aReferenceHeading);
82
83 WsfGeoPoint Reference() override;
84
85 void SetShapeType(ShapeType aType);
86 void SetRelativeType(RelativeToType aType);
87
88 void SetAltBounds(double aMinAlt, double aMaxAlt);
89
90 void SetRadialBounds(double aMinRadius, double aMaxRadius);
91
92 void SetAngleBounds(double aStartAngle, double aStopAngle);
93
94 void SetEllipticalAxes(double aLatAxisLen, double aLonAxisLen);
95
96 void SetPolyPoints(const std::vector<WsfGeoPoint>& aPoints);
97 void SetPolyPointsRelative(const std::vector<UtVec3d>& aPoints);
98
99 const std::vector<WsfZone::Point>& GetPoints() const { return mPoints; }
100 void GetPoints(std::vector<WsfGeoPoint>& aPoints) const;
101
102 ut::optional<UtColor> GetFillColor() const override;
103 ut::optional<UtColor> GetLineColor() const override;
104
105 ShapeType GetShapeType() const { return mShapeType; }
106 RelativeToType GetRelativeType() const { return mRelativeTo; }
107 WsfStringId GetReferencePlatformName() const { return mReferencePlatformNameId; }
108 double GetReferenceLat() const { return mReferenceLat; }
109 double GetReferenceLon() const { return mReferenceLon; }
110
112 bool IsNegative() const { return mNegative; }
113
114 bool HasAbsoluteLatLon() const { return mHasAbsoluteLatLon; }
115
116 void SetPointsAreLatLon(bool aValue) { mPointsAreLatLon = aValue; }
117 bool PointsAreLatLon() { return mPointsAreLatLon; }
118
119 bool GetLatLonExtrema(double& aSouthernLat, double& aWesternLon, double& aNorthernLat, double& aEasternLon) const override;
120
121 // For circular zones only.
122 double GetRadius() const;
123 double GetMinRadius() const;
124
125 // For elliptical zones
126 double GetReferenceHeading() const;
127 double GetLatAxisLength() const;
128 double GetLonAxisLength() const;
129 void GetAngleBounds(double& aStartAngle, double& aStopAngle) const;
130 void GetAltBounds(double& aMinAlt, double& aMaxAlt) const;
131
132 WsfPlatform* GetReferencePlatform(WsfSimulation* aSimulationPtr) const;
133
134 void VerticesIn(double aMinX, double aMinY, double aMaxX, double aMaxY, std::vector<Point>& aPointsVector) const;
135
136 void Draw(WsfDraw& aDraw) override;
137 void DrawRelative(WsfDraw& aDraw, const double aEyePointWCS[3], const double aLookHeading) override;
138 void DrawCentroid(WsfDraw& aDraw) override;
139 void DrawBounds(WsfDraw& aDraw) override;
140
141 void DebugDrawZone(WsfDraw& aDraw) override;
142 void DebugDrawZoneRelative(WsfDraw& aDraw, const double aEyePointWCS[3], const double aLookHeading) override;
143 void DebugDrawCentroid(WsfDraw& aDraw) override;
144 void DebugDrawBounds(WsfDraw& aDraw) override;
145
146 bool WithinPolygonSides(const double aXorLatValue, const double aYorLonValue) const;
147
148protected:
149 // void ProcessUnitTestBlock(UtInputBlock& aInputBlock);
150
151 void AddPoint(const Point& aPoint);
152
153private:
154 void CalculateArea();
155 void CalculateCentroid();
156
157 void ConvertWCSToLocalFrame(const double aWCSLocation[3],
158 const double aEyePointWCS[3],
159 const double aLookHeading,
160 double aPointInMyFrame[3]) const;
161
162 bool PointIsInsidePrivate(const double aViewedPointWCS[3],
163 const double aEyePointWCS[3],
164 const double aLookHeading,
165 const double aDeltaDownRange) const;
166
167 void SetReference(double aReferenceLat, double aReferenceLon, double aReferenceHeading, double aReferenceWCS[3]);
168
169 // These methods carve the larger Zone test into smaller sub-pieces
170 // for efficiency of execution. (Although some are valid only in
171 // the context of a local frame.) The following four should be done
172 // (more or less) in order, as appropriate.
173 bool WithinAltitudeBounds(const double aViewedPointWCS[3],
174 const double aEyePointWCS[3],
175 double& aViewedLat,
176 double& aViewedLon,
177 double& aViewedAlt,
178 bool& aLLAValid) const;
179
180 bool WithinAngleBounds(const double aPointInMyFrame[3], double& aViewedAngle) const;
181
182 bool WithinRadialBounds(const double aPointInMyFrame[3],
183 const double aViewedPointWCS[3],
184 const double aEyePointWCS[3],
185 double& aViewedRadiusSquared) const;
186
187 // Prevent use of operator= by declaring, but not defining.
188 WsfZone& operator=(const WsfZone& aRhs) = delete;
189
190 bool WithinAltitudeBounds(const double aViewedAlt) const;
191 bool WithinGrossXYBounds(const double aXorLatValue, const double aYorLonValue) const;
192
193 double ExtrudedZonePenetrationDistance(const double aLLA1[3], const double aLLA2[3]);
194
195 double SphericalZonePenetrationDistance(const double aLLA1[3], const double aLLA2[3]);
196
197 bool Penetration2D(const UtVec2d& aP0, const UtVec2d& aP1, UtVec2d& aI1, UtVec2d& aI2);
198
199 bool PenetrationIntoPolygon(const UtVec2d& aP0, const UtVec2d& aP1, UtVec2d& aI1, UtVec2d& aI2);
200
201 bool PenetrationIntoCircle(const UtVec2d& aP0, const UtVec2d& aP1, UtVec2d& aI1, UtVec2d& aI2);
202
203 bool PenetrationIntoEllipse(const UtVec2d& aP0, const UtVec2d& aP1, UtVec2d& aI1, UtVec2d& aI2);
204
205 // if mReferenceType == cSTATIONARY, mPoints are (lat,lon)
206 // pairs, else they are local-frame (x,y) points.
207 std::vector<Point> mPoints;
208
209 // The first defined attributes are only in the context of a local frame:
210 ShapeType mShapeType;
211 double mMinRadiusSq;
212 double mMaxRadiusSq;
213 double mLongitudinalAxis;
214 double mLateralAxis;
215 double mStartAngle;
216 double mStopAngle;
217 bool mPointsAreLatLon;
218 bool mPointsInputIsMGRS;
219 bool mPointsInputIsPolar;
220 bool mNegative;
221
222 // The latter defined attributes place the Zone in some larger context,
223 // and define the transforms needed. The most "minimal" attribute set
224 // would include only a Latitude, Longitude, Heading. But to permit
225 // use of UtEntity class for transformations, a full WCS location is
226 // specified below. But we will discard consideration of viewer altitude,
227 // pitch, and roll angles. The viewed entity or point may not fall
228 // within the Zone because it is outside of allowed altitudes. (The
229 // class must encapsulate the WCS location to assure that it does indeed
230 // lie at Mean Sea Level altitude.)
231 RelativeToType mRelativeTo;
232 double mReferenceWCS[3];
233 double mReferenceLat;
234 double mReferenceLon;
235 double mReferenceHeading;
236 bool mHasAbsoluteLatLon;
237 WsfStringId mReferencePlatformNameId;
238 size_t mReferencePlatformIndex;
239
241 WsfZoneDefinition* mRefZonePtr;
242 int mZoneIndex;
243
245 bool mDebugEnabled;
246};
247
248#endif
UtStringId WsfStringId
WsfStringId – the same thing as UtStringId.
Definition WsfStringId.hpp:23
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
Provides the capability to draw shapes into the WSF replay file.
Definition WsfDraw.hpp:35
Definition WsfGeoPoint.hpp:29
Platforms represent a entity within the simulation.
Definition WsfPlatform.hpp:115
Contains the data required to create a simulation, and acts as the entry point for input file process...
Definition WsfScenario.hpp:111
The main controller for a simulation.
Definition WsfSimulation.hpp:109
A class for defining a zone.
Definition WsfZoneDefinition.hpp:32
void SetPointsAreLatLon(bool aValue)
Definition WsfZoneDefinition.hpp:116
WsfStringId GetReferencePlatformName() const
Definition WsfZoneDefinition.hpp:107
RelativeToType
Definition WsfZoneDefinition.hpp:54
@ cOBSERVER
The Zone is relative to the observer (movable to fit the current context).
Definition WsfZoneDefinition.hpp:55
@ cINTERNAL
The Zone is fixed at some location or relative to a reference platform.
Definition WsfZoneDefinition.hpp:56
bool HasAbsoluteLatLon() const
Definition WsfZoneDefinition.hpp:114
WsfZoneDefinition()
Definition WsfZoneDefinition.cpp:64
~WsfZoneDefinition() override=default
const std::vector< WsfZone::Point > & GetPoints() const
Definition WsfZoneDefinition.hpp:99
double GetReferenceLon() const
Definition WsfZoneDefinition.hpp:109
double GetReferenceLat() const
Definition WsfZoneDefinition.hpp:108
ShapeType
Definition WsfZoneDefinition.hpp:60
@ cCIRCULAR
The shape of this Zone is a vertical cylinder.
Definition WsfZoneDefinition.hpp:62
@ cELLIPTICAL
The shape of this Zone is a vertical extruded ellipse.
Definition WsfZoneDefinition.hpp:63
@ cSPHERICAL
The shape of this Zone is a 3-dimensional sphere.
Definition WsfZoneDefinition.hpp:65
@ cNO_SHAPE
The shape of this Zone has not yet been determined.
Definition WsfZoneDefinition.hpp:61
@ cPOLYGONAL
The shape of this Zone is a vertical extruded polygon.
Definition WsfZoneDefinition.hpp:64
WsfZoneDefinition & operator=(const WsfZoneDefinition &)=delete
bool PointsAreLatLon()
Definition WsfZoneDefinition.hpp:117
ShapeType GetShapeType() const
Definition WsfZoneDefinition.hpp:105
bool IsNegative() const
Returns true the zone is a 'negative' zone and returns the opposite value for PointIsInside().
Definition WsfZoneDefinition.hpp:112
RelativeToType GetRelativeType() const
Definition WsfZoneDefinition.hpp:106
Definition WsfZone.hpp:63
virtual bool GetLatLonExtrema(double &aSouthernLat, double &aWesternLon, double &aNorthernLat, double &aEasternLon) const
Definition WsfZone.cpp:132
virtual void DebugDrawBounds(WsfDraw &aDraw)
Definition WsfZone.hpp:139
bool Initialize(double aSimTime) override
Definition WsfZone.cpp:123
virtual double CheckIntersections(const double aLLA1[3], const double aLLA2[3])
Definition WsfZone.hpp:114
virtual ut::optional< UtColor > GetFillColor() const
Definition WsfZone.hpp:157
virtual void DebugDrawZone(WsfDraw &aDraw)
Definition WsfZone.hpp:141
virtual void DrawCentroid(WsfDraw &aDraw)
Definition WsfZone.hpp:135
WsfZone()
Definition WsfZone.cpp:21
virtual WsfGeoPoint Reference()=0
virtual ut::optional< UtColor > GetLineColor() const
Definition WsfZone.hpp:158
WsfZone * Clone() const override=0
The standard Clone() method (virtual copy constructor).
WsfZone & operator=(const WsfZone &)=delete
virtual bool PointIsInside(WsfSimulation *aSimulationPtr, const double aViewedPointWCS[3], const double aEyePointWCS[3], const double aLookHeading, const double aDeltaDownRange=0.0)
Definition WsfZone.cpp:160
virtual void Draw(WsfDraw &aDraw)
Definition WsfZone.hpp:136
virtual void DebugDrawZoneRelative(WsfDraw &aDraw, const double aEyePointWCS[3], const double aLookHeading)
Definition WsfZone.hpp:142
virtual void DebugDrawCentroid(WsfDraw &aDraw)
Definition WsfZone.hpp:140
virtual void DrawRelative(WsfDraw &aDraw, const double aEyePointWCS[3], const double aLookHeading)
Definition WsfZone.hpp:137
bool ProcessInput(UtInput &aInput) override
Definition WsfZone.cpp:78
virtual void DrawBounds(WsfDraw &aDraw)
Definition WsfZone.hpp:134
Copyrights Multiple, All Rights Reserved