gwnavruntime/dynamicnavmesh/tagvolumeslicer.h Source File

tagvolumeslicer.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_TAG_VOLUME_SLICER_H
8 #define KAIM_TAG_VOLUME_SLICER_H
9 
10 // primary contact: LASI - secondary contact: NONE
11 
19 #include "../containers/bitfield.h"
20 
21 namespace Kaim
22 {
23 
24 class WorkingMemory;
25 class NavFloor;
26 class Database;
27 class NavFloorBlob;
28 class TagVolume;
29 class ScopedDisplayList;
30 
31 enum TagVolumeSlicerResult
32 {
33  TAG_VOLUME_SLICE_RESULT_SKIPPED,
34  TAG_VOLUME_SLICE_RESULT_SUCCESS,
35  TAG_VOLUME_SLICE_RESULT_FAILURE
36 };
37 
38 
39 class ContourLineEdgePiece
40 {
41  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
42 public:
43  ContourLineEdgePiece() : m_parentEdge(KY_NULL), m_swap(false), m_canceled(false), m_inPolygon(false), m_currentPolygonIdx(0) {}
44 public:
45  EdgePoints m_edgePiece;
46  const ContourLineEdge* m_parentEdge;
47  bool m_swap;
48  bool m_canceled;
49  bool m_inPolygon;
50  KyUInt16 m_currentPolygonIdx;
51 };
52 
53 class TypedIndexedPos
54 {
55 public:
56  enum PointType
57  {
58  TagVolumeEdgeExtremity = /*1 <<*/ 0,
59  LevelLineEdgeExtremity = /*1 <<*/ 1,
60  DiagonalEdgeExtremity = /*1 <<*/ 2,
61  IntersectionWithLevelLineDiagonal = /*1 <<*/ 3,
62  IntersectionWithFloorLink = /*1 <<*/ 4,
63  IntersectionWithBorder = /*1 <<*/ 5,
64 
65  InvalidPointType
66  };
67 
68  TypedIndexedPos() : m_index(KyUInt32MAXVAL), m_pointType(InvalidPointType) {}
69  TypedIndexedPos(const Vec2i& pos, KyUInt32 index, PointType pointType) :
70  m_pos(pos), m_index(index), m_pointType(pointType) {}
71 
72 public:
73  Vec2i m_pos;
74  KyUInt32 m_index;
75  PointType m_pointType;
76 };
77 
78 class TypedIndexedPosSorter
79 {
80 public:
81  bool operator() (const TypedIndexedPos& hotPoint1, const TypedIndexedPos& hotPoint2) const
82  {
83  return hotPoint1.m_pos < hotPoint2.m_pos;
84  }
85 };
86 
87 class UniqueHotPoint
88 {
89 public:
90  UniqueHotPoint() {}
91  UniqueHotPoint(const Vec2i& pos) : m_pos(pos) {}
92 public:
93  Vec2i m_pos;
94 };
95 
96 class TagVolumeSlicer
97 {
98  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
99 
100 public:
101  TagVolumeSlicer(Database* db, NavFloor* navFloor, WorkingMemory* workingMemory) :
102  m_database(db), m_navFloor(navFloor), m_workingMemory(workingMemory), m_slicedTagVolumes(KY_NULL) {}
103 
104 public:
105  TagVolumeSlicerResult SliceTagVolumeAccordingToAltitudes(const TagVolume* tagVolume, KyArray<KyArrayPOD<Vec2i> >& slicedTagVolumes, ScopedDisplayList* displayList);
106 
107 private:
108  enum InternalResult
109  {
110  Stop_Failure,
111  Stop_SkipTagVolume,
112  Stop_KeepTagVolumeContour,
113  KeppGoingOn
114  };
115  void Clear();
116 
117  KyResult ComputeTagVolumeContour(const TagVolume& tagVolume);
118 
119  KyResult ComputeNavFloorData(WorkingMemArray<PixelBox>& trianglePixelBoxArray, WorkingMemArray<Vec3f>& staticFloatVertices,
120  WorkingMemBitField& triangleVsTagVolumeBoxIntersection);
121 
122  KyResult ExtractLevelLines(const WorkingMemBitField& triangleVsTagVolumeBoxIntersection, const WorkingMemArray<Vec3f>& staticFloatVertices);
123 
124  void ComputeTriangleIndexAndVertexStatusOfTagVolumeVertices(const WorkingMemArray<PixelBox>& trianglePixelBoxArray, const WorkingMemArray<Vec3f>& staticFloatVertices);
125 
126  InternalResult IntersectContourLineWithTagVolume();
127 
128  KyResult BuildPolygons(KyArray<KyArrayPOD<Vec2i> >& result);
129  KyResult BuildPolygonFromTagVolume(KyArray<KyArray<Vec2i> >& result);
130 
131  KyResult MarkAsTreatedPairedLevelLineEdges(BitField& levelLinesIsPaired, KyUInt32& firstNonTVEdge);
132  KyFloat32 GetAltitudeOfPointInTriangle(const Vec2i& tVpixelPos, const WorkingMemArray<Vec3f>& staticFloatVertices, NavTriangleIdx triangleIdx);
133  bool ProjectTagVolumePixelPosInStaticFloor(const WorkingMemArray<PixelBox>& trianglePixelBoxArray, const Vec2i& tVpixelPos,
134  NavTriangleIdx& triangleIdx);
135 
136  void AddTagVolumeEdgesToContourLines();
137  KyResult ComputeAllContourEdgeBBox(WorkingMemArray<Box2i>& edgeBoundingBoxes);
138  void AddAllEdgeExtremitiesToHotPoints(WorkingMemArray<TypedIndexedPos>& hotPoints);
139  KyResult ComputeIntersections(const WorkingMemArray<Box2i>& edgeBoundingBoxes, KyArray<KyArrayPOD<KyUInt32> >& cuts,
140  WorkingMemArray<TypedIndexedPos>& hotPoints);
141 
142  TypedIndexedPos::PointType GetIntersectionPointType(ContourLineEdgeType nonTvEdgeType);
143 
144  KyResult RemoveDuplicatedHotPoints(WorkingMemArray<TypedIndexedPos>& hotPoints, WorkingMemArray<UniqueHotPoint>& uniqueHotPoints, KyArray<KyArrayPOD<KyUInt32> >& cuts);
145  void BreakEdgesOnHotPoints(const WorkingMemArray<Box2i>& edgeBoundingBoxes, WorkingMemArray<UniqueHotPoint>& uniqueHotPoints, KyArray<KyArrayPOD<KyUInt32> >& cuts);
146  void SortCuts(const WorkingMemArray<UniqueHotPoint>& uniqueHotPoints, KyArray<KyArrayPOD<KyUInt32> >& cuts);
147  void BuildFinalTagVolumeBrokenContour(const WorkingMemArray<UniqueHotPoint>& uniqueHotPoints, KyArray<KyArrayPOD<KyUInt32> >& cuts);
148  void BuildContourEdgePiece(const WorkingMemArray<UniqueHotPoint>& uniqueHotPoints, KyArray<KyArrayPOD<KyUInt32> >& cuts);
149 
150  KyResult BuildPolygonsStartingFromTagVolumeEdges(KyUInt32 firstNonTVEdge, KyArray<KyArrayPOD<Vec2i> >& result, BitField& treatedEdges);
151  KyResult BuildOtherPolygons(KyUInt32 firstNonTVEdge, KyArray<KyArrayPOD<Vec2i> >& result, BitField& treatedEdges);
152 
153  void RenderLevelLines(ScopedDisplayList* displayList);
154  void RenderBrokenEdges(ScopedDisplayList* displayList);
155  void RenderSlicedTagVolumes(const KyArray<KyArrayPOD<Vec2i> >& result, ScopedDisplayList* displayList);
156 
157  void PrintTagVolumeForDebug(const TagVolume* tagVolume);
158 private:
159  Database* m_database;
160  NavFloor* m_navFloor;
161  WorkingMemory* m_workingMemory;
162 
163  KyFloat32 m_altMin;
164  KyFloat32 m_altMax;
165  PixelBox m_tagVolumePixelBox;
166  PixelBox m_tagVolumePixelBoxEnlargeOf1;
167  // internal
168  KyArrayPOD<Vec2i> m_tagVolumePixelPos;
169  enum TvAltStatus
170  {
171  TVALTSTATUS_INSIDE,
172  TVALTSTATUS_OUTSIDE,
173  TVALTSTATUS_UNSET
174  };
175 
176  KyArrayPOD<TvAltStatus> m_verticesAltStatus;
177 
178  KyArrayPOD<Vec2i> m_brokenTagVolumePixelPos;
179  KyArray<ContourLineEdge> m_contourLineEdges;
180  KyArray<ContourLineEdgePiece> m_contourLineEdgePiece;
181  KyArray<KyArrayPOD<Vec2i> >* m_slicedTagVolumes;
182  KyUInt16 m_polygonCount;
183 };
184 
185 }
186 
187 #endif //KAIM_CONTOUR_LINE_EXTRACTOR_H
KyUInt32 NavTriangleIdx
An index that uniquely identifies a single triangle within the set of triangles owned by a NavFloor...
Definition: navmeshtypes.h:100
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
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned short KyUInt16
Type used internally to represent an unsigned 16-bit integer.
Definition: types.h:40
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
#define KyUInt32MAXVAL
The maximum value that can be stored in the KyUInt32 variable type.
Definition: types.h:226
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43