gwnavruntime/dynamicnavmesh/contourlineextractor.h Source File

contourlineextractor.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 
11 
12 namespace Kaim
13 {
14 
15 class WorkingMemory;
16 class NavFloor;
17 class Database;
18 class NavFloorBlob;
19 class NavHalfEdge;
20 template <class T>
21 class WorkingMemArray;
22 class WorkingMemBitField;
23 
24 
25 enum ContourLineEdgeType
26 {
27  CONTOUR_LINE_TRIANGLE_DIAGONAL,
28  CONTOUR_LINE_FLOOR_OBSTACLE,
29  CONTOUR_LINE_FLOOR_LINK,
30  CONTOUR_LINE_TAGVOLUME,
31 };
32 
33 
34 class ContourLineEdge
35 {
36 public:
37  ContourLineEdge(): m_altStart(KyFloat32MAXVAL), m_altEnd(KyFloat32MAXVAL), m_navHalfEdgeIdx(NavHalfEdgeIdx_Invalid),
38  m_type(CONTOUR_LINE_TRIANGLE_DIAGONAL), m_swap(false) {}
39 
40  ContourLineEdge(const Vec2i& start, const Vec2i& end, KyFloat32 altStart, KyFloat32 altEnd, NavHalfEdgeIdx idx, ContourLineEdgeType type = CONTOUR_LINE_TRIANGLE_DIAGONAL) :
41  m_edgePiece(start, end), m_altStart(altStart), m_altEnd(altEnd), m_navHalfEdgeIdx(idx),
42  m_type(type), m_swap(false) {}
43 public:
44  EdgePoints m_edgePiece;
45  KyFloat32 m_altStart;
46  KyFloat32 m_altEnd;
47  NavHalfEdgeIdx m_navHalfEdgeIdx;
48  ContourLineEdgeType m_type;
49  bool m_swap;
50 };
51 
52 
57 {
58  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
60 private:
61  enum AltVertexStatus
62  {
63  VERTEX_BELOW_RANGE,
64  VERTEX_WITHIN_RANGE,
65  VERTEX_ABOVE_RANGE
66  };
67 
68 public:
69  ContourLineExtractor(Database* db, NavFloor* floor, const WorkingMemArray<Vec3f>& staticFloatVertices,
70  const WorkingMemBitField& triangleVsTagVolumeBoxIntersection, const PixelBox& tvPixelBox, KyFloat32 altMin, KyFloat32 altMax);
71 
72  // Main function
73  KyResult ExtractContourLineInFloor(WorkingMemory* workingMemory, KyArray<ContourLineEdge>& result);
74  static bool IsPointInMiddleOfEdge(const Vec2i& p, const Vec2i& a, const Vec2i& b);
75  static bool IsPointInMiddleOfEdge_NotAligned(const Vec2i& p, const Vec2i& a, const Vec2i& b);
76  static bool IsPointStrictlyInMiddleOfEdge_NotAligned(const Vec2i& p, const Vec2i& a, const Vec2i& b);
77 
78 private:
79  KyResult ComputeVertexStatus(KyArrayPOD<KyUInt8>& vertexAltStatus);
80  KyResult ComputeIntersectionOfEdgeWithLevelLines(const KyArrayPOD<KyUInt8>& vertexAltStatus,
81  WorkingMemArray<Vec2i>& halfEdgeIntersectionWithAltMin, WorkingMemArray<Vec2i>& halfEdgeIntersectionWithAltMax, WorkingMemBitField& egdeIntersect);
82 
83  void ComputeEdgePieceForBorderEdge(const NavFloorBlob* floorBlob, NavHalfEdgeIdx halfEdgeIdx, KyFloat32 starAlt, KyFloat32 endAlt, const Vec2i& v0, const Vec2i& v1);
84  void ComputeLevelLineForEdge(const NavFloorBlob* floorBlob, NavHalfEdgeIdx halfEdgeIdx, NavHalfEdgeIdx nextHalfEdgeIdx, KyFloat32 starAlt, KyFloat32 endAlt);
85  void AddTriangleIsoAltitudeDiagonal(const Vec2i& start, const Vec2i& end, KyFloat32 alt, NavHalfEdgeIdx edgeIdx);
86  void AddEdgePiece(const NavFloorBlob* floor, const Vec2i& start, const Vec2i& end, KyFloat32 altStart, KyFloat32 altEnd, NavHalfEdgeIdx edgeIdx);
87 
88  void GetOrComputeIntersections(NavHalfEdgeIdx halfEdgeIdx, NavHalfEdgeIdx pairHalfEdgeIdx, AltVertexStatus startVertexAltStatus,
89  AltVertexStatus endVertexAltStatus, NavVertexIdx startVertexIdx, NavVertexIdx endtVertexIdx);
90 
91  void IntegerIntersectionWithZPlane(const Vec3f& a, const Vec3f& b, KyFloat32 altOfPlane, Vec2i& pos);
92 
93  void BuildContourEdgesFromIntersections(const KyArrayPOD<KyUInt8>& vertexAltStatus);
94 private:
95  Database* m_database;
96  NavFloor* m_navFloor;
97  const WorkingMemBitField& m_triangleVsTagVolumeBoxIntersection;
98  const WorkingMemArray<Vec3f>& m_staticFloatVertices;
99  PixelBox m_enlargeTagVolumePixelBox;
100  KyFloat32 m_altMin;
101  KyFloat32 m_altMax;
102 
103  KyArray<ContourLineEdge>* m_contourLineEdges;
104 
105  WorkingMemArray<Vec2i>* m_halfEdgeIntersectionWithAltMin;
106  WorkingMemArray<Vec2i>* m_halfEdgeIntersectionWithAltMax;
107  WorkingMemBitField* m_halfEdgeIntersect;
108 };
109 
110 }
111 
#define KyFloat32MAXVAL
KyFloat32 max value
Definition: types.h:71
2d axis aligned box of 32bits integers. Very Important: CountX() returns m_max.x - m_min...
Definition: box2i.h:17
This class is a runtime wrapper of a NavFloorBlob, it gathers all the runtime information associated ...
Definition: navfloor.h:32
The NavFloorBlob contains a connected and not overlapping part of triangle mesh static data within a ...
Definition: navfloorblob.h:38
KyUInt32 NavHalfEdgeIdx
An index that uniquely identifies a single edge of a triangle within the set of edges owned by a NavF...
Definition: navmeshtypes.h:84
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:196
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
This class is a runtime container for all NavData that represents the world from the point of view of...
Definition: database.h:57
Navigation return code class.
Definition: types.h:108
2d vector using KyInt32
Definition: vec2i.h:18
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
This class takes a NavFloor and an altitude range as input and will return an array of edges that for...
Definition: contourlineextractor.h:56
KyUInt32 NavVertexIdx
An index that uniquely identifies a single vertex of a triangle within the set of vertices owned by a...
Definition: navmeshtypes.h:72
static const NavHalfEdgeIdx NavHalfEdgeIdx_Invalid
Represents an invalid NavHalfEdgeIdx.
Definition: navmeshtypes.h:85
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16