gwnavruntime/dynamicnavmesh/contourlineextractor.h Source File

contourlineextractor.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_CONTOUR_LINE_EXTRACTOR_H
8 #define KAIM_CONTOUR_LINE_EXTRACTOR_H
9 
10 // primary contact: LASI - secondary contact: NONE
11 
14 
15 namespace Kaim
16 {
17 
18 class WorkingMemory;
19 class NavFloor;
20 class Database;
21 class NavFloorBlob;
22 class NavHalfEdge;
23 template <class T>
24 class WorkingMemArray;
25 class WorkingMemBitField;
26 
27 
28 enum ContourLineEdgeType
29 {
30  CONTOUR_LINE_TRIANGLE_DIAGONAL,
31  CONTOUR_LINE_FLOOR_OBSTACLE,
32  CONTOUR_LINE_FLOOR_LINK,
33  CONTOUR_LINE_TAGVOLUME,
34 };
35 
36 
37 class ContourLineEdge
38 {
39 public:
40  ContourLineEdge(): m_altStart(KyFloat32MAXVAL), m_altEnd(KyFloat32MAXVAL), m_navHalfEdgeIdx(NavHalfEdgeIdx_Invalid),
41  m_type(CONTOUR_LINE_TRIANGLE_DIAGONAL), m_swap(false) {}
42 
43  ContourLineEdge(const Vec2i& start, const Vec2i& end, KyFloat32 altStart, KyFloat32 altEnd, NavHalfEdgeIdx idx, ContourLineEdgeType type = CONTOUR_LINE_TRIANGLE_DIAGONAL) :
44  m_edgePiece(start, end), m_altStart(altStart), m_altEnd(altEnd), m_navHalfEdgeIdx(idx),
45  m_type(type), m_swap(false) {}
46 public:
47  EdgePoints m_edgePiece;
48  KyFloat32 m_altStart;
49  KyFloat32 m_altEnd;
50  NavHalfEdgeIdx m_navHalfEdgeIdx;
51  ContourLineEdgeType m_type;
52  bool m_swap;
53 };
54 
55 
59 class ContourLineExtractor
60 {
63 private:
64  enum AltVertexStatus
65  {
66  VERTEX_BELOW_RANGE,
67  VERTEX_WITHIN_RANGE,
68  VERTEX_ABOVE_RANGE
69  };
70 
71 public:
72  ContourLineExtractor(Database* db, NavFloor* floor, const WorkingMemArray<Vec3f>& staticFloatVertices,
73  const WorkingMemBitField& triangleVsTagVolumeBoxIntersection, const PixelBox& tvPixelBox, KyFloat32 altMin, KyFloat32 altMax);
74 
75  // Main function
76  KyResult ExtractContourLineInFloor(WorkingMemory* workingMemory, KyArray<ContourLineEdge>& result);
77  static bool IsPointInMiddleOfEdge(const Vec2i& p, const Vec2i& a, const Vec2i& b);
78  static bool IsPointInMiddleOfEdge_NotAlgined(const Vec2i& p, const Vec2i& a, const Vec2i& b);
79  static bool IsPointStrictlyInMiddleOfEdge_NotAlgined(const Vec2i& p, const Vec2i& a, const Vec2i& b);
80 
81 private:
82  KyResult ComputeVertexStatus(KyArrayPOD<KyUInt8>& vertexAltStatus);
83  KyResult ComputeIntersectionOfEdgeWithLevelLines(const KyArrayPOD<KyUInt8>& vertexAltStatus,
84  WorkingMemArray<Vec2i>& halfEdgeIntersectionWithAltMin, WorkingMemArray<Vec2i>& halfEdgeIntersectionWithAltMax, WorkingMemBitField& egdeIntersect);
85 
86  void ComputeEdgePieceForBorderEdge(const NavFloorBlob* floorBlob, NavHalfEdgeIdx halfEdgeIdx, KyFloat32 starAlt, KyFloat32 endAlt, const Vec2i& v0, const Vec2i& v1);
87  void ComputeLevelLineForEdge(const NavFloorBlob* floorBlob, NavHalfEdgeIdx halfEdgeIdx, NavHalfEdgeIdx nextHalfEdgeIdx, KyFloat32 starAlt, KyFloat32 endAlt);
88  void AddTriangleIsoAltitudeDiagonal(const Vec2i& start, const Vec2i& end, KyFloat32 alt, NavHalfEdgeIdx edgeIdx);
89  void AddEdgePiece(const NavFloorBlob* floor, const Vec2i& start, const Vec2i& end, KyFloat32 altStart, KyFloat32 altEnd, NavHalfEdgeIdx edgeIdx);
90 
91  void GetOrComputeIntersections(NavHalfEdgeIdx halfEdgeIdx, NavHalfEdgeIdx pairHalfEdgeIdx, AltVertexStatus startVertexAltStatus,
92  AltVertexStatus endVertexAltStatus, NavVertexIdx startVertexIdx, NavVertexIdx endtVertexIdx);
93 
94  void IntegerIntersectionWithZPlane(const Vec3f& a, const Vec3f& b, KyFloat32 altOfPlane, Vec2i& pos);
95 
96  void BuildContourEdgesFromIntersections(const KyArrayPOD<KyUInt8>& vertexAltStatus);
97 private:
98  Database* m_database;
99  NavFloor* m_navFloor;
100  const WorkingMemBitField& m_triangleVsTagVolumeBoxIntersection;
101  const WorkingMemArray<Vec3f>& m_staticFloatVertices;
102  PixelBox m_enlargeTagVolumePixelBox;
103  KyFloat32 m_altMin;
104  KyFloat32 m_altMax;
105 
106  KyArray<ContourLineEdge>* m_contourLineEdges;
107 
108  WorkingMemArray<Vec2i>* m_halfEdgeIntersectionWithAltMin;
109  WorkingMemArray<Vec2i>* m_halfEdgeIntersectionWithAltMax;
110  WorkingMemBitField* m_halfEdgeIntersect;
111 };
112 
113 }
114 
115 #endif //KAIM_CONTOUR_LINE_EXTRACTOR_H
#define KyFloat32MAXVAL
The maximum value that can be stored in the KyFloat32 variable type.
Definition: types.h:227
This class represents a two-dimensional axis-aligned bounding box whose dimensions are stored using 3...
Definition: box2i.h:119
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
This class is a runtime wrapper of a NavFloorBlob, it gathers all the runtime information associated ...
Definition: navfloor.h:40
The NavFloorBlob contains a connected and not overlapping part of triangle mesh static data within a ...
Definition: navfloorblob.h:42
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:87
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:387
This class is a runtime container for all NavData that represents the world from the point of view of...
Definition: database.h:64
This class defines a two-dimensional vector whose coordinates are stored using 32-bit integers...
Definition: vec2i.h:26
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
This class takes a NavFloor and an altitude range as input and will return an array of edges that for...
Definition: contourlineextractor.h:61
KyUInt32 NavVertexIdx
An index that uniquely identifies a single vertex of a triangle within the set of vertices owned by a...
Definition: navmeshtypes.h:75
static const NavHalfEdgeIdx NavHalfEdgeIdx_Invalid
Represents an invalid NavHalfEdgeIdx.
Definition: navmeshtypes.h:88
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43
This class defines a three-dimensional vector whose coordinates are stored using floating-point numbe...
Definition: vec3f.h:23