gwnavruntime/channel/bubblestringpullerbetweenpivots.h Source File

bubblestringpullerbetweenpivots.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 
10 
11 
12 namespace Kaim
13 {
14 
15 class StringPulledBubbleList;
16 
17 // Internal.
18 // This class computes a string pull on Bubbles that are so that the line
19 class BubbleStringPullerBetweenPivots
20 {
21 private:
22  // A chained-list node identifying a pivot Bubble in both a BubbleArray (globalArrayIdx)
23  // and a local corner index array (localArrayIdx).
24  class Pivot : public ListNode<Pivot>
25  {
26  public:
27  Pivot(KyUInt32 globalArrayIdx, KyUInt32 localArrayIdx)
28  : m_globalArrayIdx(globalArrayIdx)
29  , m_localArrayIdx(localArrayIdx)
30  {}
31 
32  void Set(KyUInt32 globalArrayIdx, KyUInt32 localArrayIdx)
33  {
34  m_globalArrayIdx = globalArrayIdx;
35  m_localArrayIdx = localArrayIdx;
36  }
37 
38  KyUInt32 m_globalArrayIdx;
39  KyUInt32 m_localArrayIdx;
40  };
41 
42 
43  // Defines a sub set for iterative corner index array sort and local
44  // string pull resolution.
45  class BubbleArraySubSet
46  {
47  public:
48  enum SubSetSide
49  {
50  BeforePivot = 0,
51  AfterPivot
52  };
53 
54  BubbleArraySubSet()
55  : m_pivot(nullptr)
56  , m_startGlobalIndex(KyUInt32MAXVAL)
57  , m_endGlobalIndex(KyUInt32MAXVAL)
58  , m_refBubbleGlobalIndex(KyUInt32MAXVAL)
59  , m_startLocalIndex(KyUInt32MAXVAL)
60  , m_endLocalIndex(KyUInt32MAXVAL)
61  , m_subSetSide(BeforePivot)
62  {}
63 
64  BubbleArraySubSet(const KyUInt32 startGlobalIndex, const KyUInt32 endGlobalIndex, KyUInt32 startLocalIndex, KyUInt32 endLocalIndex)
65  : m_pivot(nullptr)
66  , m_startGlobalIndex(startGlobalIndex)
67  , m_endGlobalIndex(endGlobalIndex)
68  , m_refBubbleGlobalIndex(endGlobalIndex)
69  , m_startLocalIndex(startLocalIndex)
70  , m_endLocalIndex(endLocalIndex)
71  , m_subSetSide(BeforePivot)
72  {}
73 
74  BubbleArraySubSet(Pivot* pivot, SubSetSide subSetSide, const KyUInt32 startGlobalIndex, const KyUInt32 endGlobalIndex, KyUInt32 startLocalIndex, KyUInt32 endLocalIndex)
75  : m_pivot(pivot)
76  , m_startGlobalIndex(startGlobalIndex)
77  , m_endGlobalIndex(endGlobalIndex)
78  , m_refBubbleGlobalIndex(endGlobalIndex)
79  , m_startLocalIndex(startLocalIndex)
80  , m_endLocalIndex(endLocalIndex)
81  , m_subSetSide(subSetSide)
82  {}
83 
84  Pivot* m_pivot;
85  KyUInt32 m_startGlobalIndex;
86  KyUInt32 m_endGlobalIndex;
87  KyUInt32 m_refBubbleGlobalIndex;
88  KyUInt32 m_startLocalIndex;
89  KyUInt32 m_endLocalIndex;
90  SubSetSide m_subSetSide;
91  };
92 
93  class IncreasingProjectionDistance2dLessSorter
94  {
95  public:
96  IncreasingProjectionDistance2dLessSorter(
97  const BubbleArray* bubbleArray, const Vec2f& referencePosition,
98  const Vec2f& referenceVector, KyUInt32 referenceEndBubbleIdx)
99  : m_bubbleArray(bubbleArray)
100  , m_referencePosition(referencePosition)
101  , m_referenceVector(referenceVector)
102  , m_referenceEndBubbleIdx(referenceEndBubbleIdx)
103  {}
104 
105  KY_INLINE bool operator() (KyUInt32 firstIdx, KyUInt32 secondIdx) const
106  {
107  // Let m_referenceEndBubbleIdx be sorted in last position
108  if (firstIdx == m_referenceEndBubbleIdx)
109  return false;
110  if (secondIdx == m_referenceEndBubbleIdx)
111  return true;
112 
113  const Bubble& firstBubble = m_bubbleArray->At(firstIdx);
114  const Bubble& secondBubble = m_bubbleArray->At(secondIdx);
115 
116  const Vec2f vecToFirst = firstBubble.GetCenter().Get2d() - m_referencePosition;
117  const Vec2f vecToSecond = secondBubble.GetCenter().Get2d() - m_referencePosition;
118 
119  return (DotProduct(vecToFirst, m_referenceVector) < DotProduct(vecToSecond, m_referenceVector));
120  }
121 
122  private:
123  const BubbleArray* m_bubbleArray;
124  Vec2f m_referencePosition;
125  Vec2f m_referenceVector;
126  KyUInt32 m_referenceEndBubbleIdx;
127  };
128 
129 
130 public:
131  KyResult SolveLocalStringPulledBubbleList(const BubbleArray& bubbleArray, KyArrayPOD<KyUInt32>& cornerIndexArray,
132  KyUInt32 startGlobalIndex, KyUInt32 endGlobalIndex, StringPulledBubbleList& stringPulledBubbleList);
133 
134 private:
135  // This function analyzes a subset of corner index array to detect a intermediary
136  // pivot. It then split the current subset in two subsets around the identified pivot.
137  // Note that in fact the second part of the initial subset is not created, so that the
138  // first identified pivot is used as start bubble for the next main loop.
139  KyResult TreatNextSubStrip(const BubbleArray& bubbleArray, KyArrayPOD<KyUInt32>& funnelCornerIndices,
140  KyArray<BubbleArraySubSet>& subSets, KyArray<Pivot>& pivotArray, List<Pivot>& pivotList);
141 };
142 
143 } // namespace Kaim
144 
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
#define KyUInt32MAXVAL
KyUInt32 max value
Definition: types.h:68