gwnavruntime/dynamicnavmesh/navfloorsweepline.h Source File

navfloorsweepline.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 #ifndef Navigation_NavFloorSweepline_H
8 #define Navigation_NavFloorSweepline_H
9 
12 
14 
15 namespace Kaim
16 {
17 class DynamicNavTag;
18 class ScopedDisplayList;
19 
20 // This object is used to sweep a plane containing edges belonging to polygons and determine
21 // what's left and right of each edge in terms of polygons.
22 // This algorithm is based on boost polygon approach (http://www.boost.org/doc/libs/1_47_0/libs/polygon/doc/index.htm)
23 // and vatti clipping algorithm (http://en.wikipedia.org/wiki/Vatti_clipping_algorithm)
24 // In order to work properly this algorithm requires that:
25 // 1) Input edges DO NOT intersect except at their endpoints
26 
27 class NavFloorSweepline
28 {
29  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
30 
31 public:
32  typedef SharedPoolList<ScanDataElement>::Iterator ScanDataIterator;
33  typedef SharedPoolList<SweeplineProperty> PropertyList;
34  typedef Pool<PropertyList>::Key PropertyListKey;
35 
36 public:
37  NavFloorSweepline(KyArray<InputEdgePiece>& input, SweepLineOutput& result);
38  ~NavFloorSweepline();
39 
40  KyResult Scan();
41  void SetDebugDisplayList(KyFloat32 rasterPrecision, const Vec2i& cellOffset, ScopedDisplayList* displayList)
42  {
43  m_rasterPrecision = rasterPrecision;
44  m_cellOriginOffset = Vec3i(cellOffset.x, cellOffset.y, 0);
45  m_displayList = displayList;
46  }
47 
48  void MergePropertyMaps(PropertyList& mp1, const PropertyList& mp2);
49  void UpdatePropertyList(PropertyList& propertyList, SweeplineProperty& prop_data);
50  KyUInt32 ComputeNavTagIndexFromPropertyList(const PropertyList& propertySet);
51  bool AreListsEquals(const PropertyList& list1, const PropertyList& list2);
52  void TransferContent(PropertyList& list1, PropertyList& list2, bool clearList2 = true);
53 
54 private:
55  void EraseEndEvent(SharedPoolList<Vec2i>::Iterator epqi);
56  void RemoveRetiredEdges();
57 
58  void InsertSortedInScandata(const ScanDataElement& elem);
59  void InsertSortedIfUniqueInEndPointQueue(const Vec2i& elem);
60  ScanDataIterator LowerBoundInScandata(const EdgePoints& refElem);
61 
62  void HandleInputEvents(KyUInt32& currentInputIdx);
63  void InsertAllTheEdgesOfInsertionSetInScanDataListAndEndPointQueue();
64  void WriteOutEdge(const InputEdgePiece& he, const PropertyList& pm_left, const PropertyList& pm_right);
65 
66  void VisualDebugWriteOutEdges(const InputEdgePiece &he, const PropertyList &pm_left, const PropertyList &pm_right);
67 
68  void FilterOutlineEdge(const InputEdgePiece& edge, const PropertyList& left, const PropertyList& right);
69  bool IsEdgeFullyInsideHole(const PropertyList& leftSet, const PropertyList& rightSet);
70  bool IsEdgeInsideFloor(const PropertyList& propertySet);
71  bool IsHalfEdgeInHole(const PropertyList& propertySet);
72  void DebugRender_Scan();
73 
74 
75 private:
76  KyArray<InputEdgePiece>* m_input;
77  SweepLineOutput* m_result;
78 
79  Pool<PropertyList> m_propertyListPool;
80  KyArray<PropertyListKey> m_propertyListKeys;
81  PropertyList::NodePool m_propertyListNodePool;
82 
83  SharedPoolList<ScanDataElement> m_scanData;
84  SharedPoolList<ScanDataElement>::NodePool m_scanDataElementPool;
85 
86  KyInt32 m_currentX;
87  KyInt32 m_justBefore;
88 
89  SharedPoolList<Vec2i> m_endpointQueue;
90  SharedPoolList<Vec2i>::NodePool m_endPointPool;
91 
92  SharedPoolList<ScanDataElement> m_insertionSet; //edge to be inserted after current NavFloorSweepline stop
93 
94  KyArray<ScanDataElement> m_insertion_elements; //edge to be inserted after current NavFloorSweepline stop
95 
96  SharedPoolList<EdgePoints> m_removalSet;
97  SharedPoolList<EdgePoints>::NodePool m_removalSetPool;
98 
99  // For debug draw
100  KyFloat32 m_rasterPrecision;
101  Vec3i m_cellOriginOffset; // retrieved from input when Scan() is called. Used for debug Render
102  ScopedDisplayList* m_displayList;
103 };
104 
105 } // namespace Kaim
106 
107 #endif // Navigation_NavFloorSweepline_H
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43