gwnavruntime/dynamicnavmesh/edgeintersector.h Source File

edgeintersector.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 KAIM_EDGE_INTERSECTOR_H
8 #define KAIM_EDGE_INTERSECTOR_H
9 
10 // primary contact: LASI - secondary contact: NONE
11 
18 
19 
20 
21 namespace Kaim
22 {
23 // For Debug render
24 class ScopedDisplayList;
25 class VisualColor;
26 class WorkingMemory;
27 class WorkingMemBitField;
28 template <class T>
29 class WorkingMemArray;
30 
31 //----------------------------------------------------------------------
32 // Compute all the intersections between all the edges passed as input.
33 // The intersection points will be snapped to an integer grid and injected as "Cuts" on the original edges supplied.
34 // The snapping is done in a way that prevents spurious intersections that normally result from such process.
35 // This approach is similar to:
36 //----------------------------------------------------------------
37 // Hobby, J. - 1993
38 // Practical segment intersection with finite precision output.
39 // Technical Report 93/2-27, Bell Laboratories (Lucent Technologies)
40 //------------------------------------------------------------------
41 
42 class EdgeIntersector
43 {
44  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
45 public:
46  EdgeIntersector() : m_debugDisplayListBeforeSnap(KY_NULL), m_debugDisplayListAfterSnap(KY_NULL){}
47 public:
48  KyResult ComputeIntersections(WorkingMemory* workingMemory);
49 
50  static bool Intersects_grid_rounded(const Vec2i& hotPoint, const Vec2i& start, const Vec2i& end);
51 private:
52  KyResult ComputeIntersections_Pass1(WorkingMemory* workingMemory, const WorkingMemArray<InputEdge>& rawEdges,
53  const WorkingMemArray<Box2i>& edgeBoundingBoxes, WorkingMemArray<Vec2i>& points);
54 
55  void ComputeIntersections_Pass2(const WorkingMemArray<InputEdge>& rawEdges,
56  const WorkingMemArray<Box2i>& edgeBoundingBoxes, const WorkingMemArray<Vec2i>& points);
57 
58  void ComputeIntersectionsOuputEdgePieces(const WorkingMemArray<InputEdge>& rawEdges,
59  const WorkingMemArray<Vec2i>& points, KyArray<InputEdgePiece>& intersectedEdges);
60 
61  void InitEdges(const KyArray<InputEdge>& rawEdges);
62 
63  void ComputeBoundingBoxesOfInputEdges(const WorkingMemArray<InputEdge>& rawEdges, WorkingMemArray<Box2i>& edgeBoundingBoxes);
64 
65  void ComputeBoundingBoxesIntersection(const WorkingMemArray<InputEdge>& rawEdges, const WorkingMemArray<Box2i>& edgeBoundingBoxes,
66  WorkingMemBitField& boxIntersect);
67 
68  KyResult SortHotPointAndRemoveDuplicate(WorkingMemory* workingMemory, const WorkingMemArray<InputEdge>& rawEdges,
69  WorkingMemArray<IndexedPos>& hotPoints, WorkingMemArray<Vec2i>& uniqueHotPoints);
70 
71  void SortCutList(const WorkingMemArray<InputEdge>& rawEdges, const WorkingMemArray<Vec2i>& points);
72 
73  KyArray<KyArray<KyUInt32> > m_cuts; // an array of hotPoint Idx
74 
75 public: // debug check and render
76  void IntersectionsToDisplayList(const WorkingMemArray<InputEdge>& rawEdges, const WorkingMemArray<Vec2i>& hotPoints,
77  ScopedDisplayList& displayList, VisualColor color = VisualColor::White);
78 
79  // DEBUG Render using ScopedDisplayList
80  KyResult CheckResult(const WorkingMemArray<InputEdge>& rawEdges, const WorkingMemArray<Vec2i>& hotPoints, ScopedDisplayList* displayList);
81  // DEBUG display settings
82  // displayListBeforeSnap and displayListAfterSnap pointers are use to distinguish what we want to display
83  void SetDebugDisplayLists(KyFloat32 rasterPrecision,const Vec2i& cellOffset, ScopedDisplayList* displayListBeforeSnap, ScopedDisplayList* displayListAfterSnap);
84 
85  ScopedDisplayList* m_debugDisplayListBeforeSnap;
86  ScopedDisplayList* m_debugDisplayListAfterSnap;
87  KyFloat32 m_rasterPrecision;
88  Vec2i m_cellOffset;
89 
90 };
91 
92 } // namespace Kaim
93 
94 
95 
96 #endif // KAIM_EDGE_INTERSECTOR_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
#define KY_NULL
Null value.
Definition: types.h:247
Definition: gamekitcrowddispersion.h:20
static const VisualColor White
Represents the color with RGBA values (255, 255, 255, 255).  
Definition: visualcolor.h:234
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43