gwnavruntime/dynamicnavmesh/edgeintersector.h Source File

edgeintersector.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 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 #pragma once
8 
15 
16 namespace Kaim
17 {
18 // For Debug render
19 class DisplayList;
20 class Color;
21 class WorkingMemory;
22 class WorkingMemBitField;
23 template <class T>
24 class WorkingMemArray;
25 
26 //----------------------------------------------------------------------
27 // Compute all the intersections between all the edges passed as input.
28 // The intersection points will be snapped to an integer grid and injected as "Cuts" on the original edges supplied.
29 // The snapping is done in a way that prevents spurious intersections that normally result from such process.
30 // This approach is similar to:
31 //----------------------------------------------------------------
32 // Hobby, J. - 1993
33 // Practical segment intersection with finite precision output.
34 // Technical Report 93/2-27, Bell Laboratories (Lucent Technologies)
35 //------------------------------------------------------------------
36 
37 class EdgeIntersector
38 {
39  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
40 
41 public:
42  EdgeIntersector() : m_debugDisplayListBeforeSnap(nullptr), m_debugDisplayListAfterSnap(nullptr), m_rasterPrecision(0.0f) {}
43 
44 public:
45  KyResult ComputeIntersections(WorkingMemory* workingMemory);
46 
47  static bool Intersects_grid_rounded(const Vec2i& hotPoint, const Vec2i& start, const Vec2i& end);
48 
49 private:
50  KyResult ComputeIntersections_Pass1(WorkingMemory* workingMemory, const WorkingMemArray<InputEdge>& rawEdges, const WorkingMemArray<Box2i>& edgeBoundingBoxes,
51  WorkingMemArray<Vec2i>& points);
52 
53  void ComputeIntersections_Pass2(const WorkingMemArray<InputEdge>& rawEdges, const WorkingMemArray<Box2i>& edgeBoundingBoxes, const WorkingMemArray<Vec2i>& points);
54 
55  void ComputeIntersectionsOuputEdgePieces(const WorkingMemArray<InputEdge>& rawEdges, const WorkingMemArray<Vec2i>& points, KyArray<InputEdgePiece>& intersectedEdges);
56 
57  void InitEdges(const KyArray<InputEdge>& rawEdges);
58 
59  void ComputeBoundingBoxesOfInputEdges(const WorkingMemArray<InputEdge>& rawEdges, WorkingMemArray<Box2i>& edgeBoundingBoxes);
60 
61  void ComputeBoundingBoxesIntersection(const WorkingMemArray<InputEdge>& rawEdges, const WorkingMemArray<Box2i>& edgeBoundingBoxes, WorkingMemBitField& boxIntersect);
62 
63  KyResult SortHotPointAndRemoveDuplicate(WorkingMemory* workingMemory, const WorkingMemArray<InputEdge>& rawEdges, WorkingMemArray<IndexedPos>& hotPoints,
64  WorkingMemArray<Vec2i>& uniqueHotPoints);
65 
66  void SortCutList(const WorkingMemArray<InputEdge>& rawEdges, const WorkingMemArray<Vec2i>& points);
67 
68  KyArray<KyArray<KyUInt32> > m_cuts; // an array of hotPoint Idx
69 
70 public:
71  // those functions are empty unless KY_FULL_DEBUG_EdgeIntersector is defined in the edgeintersector.cpp
72  // displayListBeforeSnap and displayListAfterSnap pointers are use to distinguish what we want to display
73  void FullDebugInit(KyFloat32 rasterPrecision, const Vec2i& cellOffset, DisplayList* displayListBeforeSnap, DisplayList* displayListAfterSnap);
74  void FullDebugIntersections(const WorkingMemArray<InputEdge>& rawEdges, const WorkingMemArray<Vec2i>& hotPoints, DisplayList& displayList);
75  KyResult FullDebugCheck(const WorkingMemArray<InputEdge>& rawEdges, const WorkingMemArray<Vec2i>& hotPoints, DisplayList* displayList);
76 
77  DisplayList* m_debugDisplayListBeforeSnap;
78  DisplayList* m_debugDisplayListAfterSnap;
79  KyFloat32 m_rasterPrecision;
80  Vec2i m_cellOffset;
81 };
82 
83 } // namespace Kaim
84 
85 
86 
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
float KyFloat32
float
Definition: types.h:32