gwnavruntime/channel/channelsectionptr.h Source File

channelsectionptr.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 
8 #pragma once
9 
12 
13 
14 namespace Kaim
15 {
16 
17 class PositionOnPath;
18 
19 class ChannelSectionPtr
20 {
21 public:
22 
23  ChannelSectionPtr();
24  ChannelSectionPtr(Ptr<ChannelArray> channelArray, KyUInt32 channelIdx, KyUInt32 sectionIdx);
25  ~ChannelSectionPtr();
26 
27  void Invalidate();
28 
29  KyResult Set(Ptr<ChannelArray> channelArray, KyUInt32 channelIdx, KyUInt32 sectionIdx);
30 
31  KyResult SetFromPositionOnPath(const PositionOnPath& positionOnPath);
32 
37  KyResult Update(const Vec3f& prevPos, const Vec3f& newPos);
38 
43  KyResult Update(const PositionOnPath& positionOnPath, const Vec3f& newPos);
44 
45  bool IsValid() const;
46 
47  bool operator==(const ChannelSectionPtr& other) const;
48  bool operator!=(const ChannelSectionPtr& other) const;
49 
51 
54  bool IsFirstSection() const;
55 
58  bool IsLastSection() const;
59 
62  bool IsTriangularLeftTurn() const;
63 
66  bool IsTriangularRightTurn() const;
67 
70  bool IsPositionInSection(const Vec2f& position, KyUInt32& positionFlags) const;
71 
72  ChannelArray* GetChannelArray() const;
73  KyUInt32 GetChannelIdx() const;
74  KyUInt32 GetSectionIdx() const;
75 
76  const Channel* GetChannel() const; // WARNING : This object must be valid !
77 
78  KyUInt32 GetPathNodeIdxOfSectionStartGate() const;
79  KyUInt32 GetPathNodeIdxOfSectionEndGate() const;
80  KyUInt32 GetPathNodeIdxOfChannelLastGate() const;
81 
82  KyUInt32 GetSectionStartGateIdx() const;
83  KyUInt32 GetSectionEndGateIdx() const;
84  const Gate& GetSectionStartGate() const;
85  const Gate& GetSectionEndGate() const;
86 
87 public: // internal
88  // Beware this set the channel section based on node index and doesn't take care of node position
89  // i.e. Node position could be in the adjacent section
90  KyResult SetFromPathNodeIdx(const Ptr<ChannelArray>& channelArray, KyUInt32 pathNodeIdx);
91 
92 public: // internal
93  Ptr<ChannelArray> m_channelArray;
94  KyUInt32 m_channelIdx; // The index of the Channel in the ChannelArray.
95  KyUInt32 m_sectionIdx; // The index of the section, i.e. the Gate starting the quad or triangle this position stays on.
96 };
97 
98 
99 KY_INLINE bool ChannelSectionPtr::IsValid() const
100 {
101  if (m_channelArray != nullptr && m_channelIdx < m_channelArray->GetChannelCount())
102  {
103  const Channel* channel = m_channelArray->GetChannel(m_channelIdx);
104  return channel != nullptr && m_sectionIdx < channel->GetGateCount() + 1;
105  }
106 
107  return false;
108 }
109 
110 KY_INLINE bool ChannelSectionPtr::IsFirstSection() const { return m_sectionIdx == 0; }
111 KY_INLINE bool ChannelSectionPtr::IsLastSection() const { return m_sectionIdx == GetChannel()->GetGateCount(); }
112 
113 KY_INLINE bool ChannelSectionPtr::IsTriangularRightTurn() const
114 {
115  GateType type = GetSectionStartGate().m_type;
116  return (type == RightTurnStart) || (type == RightTurnIntermediary);
117 }
118 
119 KY_INLINE bool ChannelSectionPtr::IsTriangularLeftTurn() const
120 {
121  GateType type = GetSectionStartGate().m_type;
122  return (type == LeftTurnStart) || (type == LeftTurnIntermediary);
123 }
124 
125 KY_INLINE bool ChannelSectionPtr::IsPositionInSection(const Vec2f& position, KyUInt32& positionFlags) const
126 {
127  return GetChannel()->IsPositionInSection(position, m_sectionIdx, positionFlags);
128 }
129 
130 KY_INLINE ChannelArray* ChannelSectionPtr::GetChannelArray() const { return m_channelArray; }
131 KY_INLINE KyUInt32 ChannelSectionPtr::GetChannelIdx() const { return m_channelIdx; }
132 KY_INLINE KyUInt32 ChannelSectionPtr::GetSectionIdx() const { return m_sectionIdx; }
133 KY_INLINE const Channel* ChannelSectionPtr::GetChannel() const { return m_channelArray->GetChannel(m_channelIdx); }
134 
135 KY_INLINE KyUInt32 ChannelSectionPtr::GetPathNodeIdxOfSectionStartGate() const { return GetChannel()->GetGatePathNodeIdx(GetSectionStartGateIdx()); }
136 KY_INLINE KyUInt32 ChannelSectionPtr::GetPathNodeIdxOfSectionEndGate() const { return GetChannel()->GetGatePathNodeIdx(GetSectionEndGateIdx()); }
137 KY_INLINE KyUInt32 ChannelSectionPtr::GetPathNodeIdxOfChannelLastGate() const { return GetChannel()->GetGatePathNodeIdx(GetChannel()->GetGateCount() -1); }
138 
139 KY_INLINE KyUInt32 ChannelSectionPtr::GetSectionStartGateIdx() const { return GetChannel()->GetSectionStartGateIdx(m_sectionIdx); }
140 KY_INLINE KyUInt32 ChannelSectionPtr::GetSectionEndGateIdx() const { return GetChannel()->GetSectionEndGateIdx(m_sectionIdx); }
141 KY_INLINE const Gate& ChannelSectionPtr::GetSectionStartGate() const { return GetChannel()->GetSectionStartGate(m_sectionIdx); }
142 KY_INLINE const Gate& ChannelSectionPtr::GetSectionEndGate() const { return GetChannel()->GetSectionEndGate(m_sectionIdx); }
143 
144 KY_INLINE bool ChannelSectionPtr::operator!=(const ChannelSectionPtr& other) const { return !(*this==other); }
145 KY_INLINE bool ChannelSectionPtr::operator==(const ChannelSectionPtr& other) const
146 {
147  return m_channelArray == other.m_channelArray && m_channelIdx == other.m_channelIdx && m_sectionIdx == other.m_sectionIdx;
148 }
149 
150 template <class OSTREAM>
151 inline OSTREAM& operator<<(OSTREAM& os, const ChannelSectionPtr& channelSectionPtr)
152 {
153  os << "{" << channelSectionPtr.m_channelIdx << ", " << channelSectionPtr.m_sectionIdx << "}";
154  return os;
155 }
156 
157 } // namespace Kaim
158 
Indicates the Gate is the start of a sampled turn to the left (CCW). The next Gate must have either L...
Definition: channel.h:28
GateType
Enumerates the different kind of Gates.
Definition: channel.h:20
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
Indicates the Gate is a sampled left turn intermediary Gate.
Definition: channel.h:29
Indicates the Gate is the start of a sampled turn to the right (CW). The next Gate must have either R...
Definition: channel.h:33
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
Indicates the Gate is a sampled right turn intermediary Gate.
Definition: channel.h:34