gwnavruntime/queries/blobs/querydisplaylistbuilder.h Source File

querydisplaylistbuilder.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 // Utility base class that helps implementing IDisplayListBuilder for Queries in a consistent way by sharing code and conventions
16 template<typename TQuery, typename TOutput, typename TSelf>
17 class QueryDisplayListBuilder : public IDisplayListBuilder
18 {
19 public:
20  QueryDisplayListBuilder() { Clear(); }
21 
22  Color NotProcessedColor() { return Color::Orange; }
23 
24 protected:
25  const TQuery* m_query;
26  TOutput* m_output;
27  DisplayList* m_displayList;
28 
29 protected:
30  // DoXXX are to be implemented in TSelf
31  void PushQueryShape(Color color) { static_cast<TSelf*>(this)->DoPushQueryShape(color); }
32  const Vec3f& GetStartPos() { return static_cast<TSelf*>(this)->DoGetStartPos(); }
33  void PushStartTriangle(Color color) { return static_cast<TSelf*>(this)->DoPushStartTriangle(color); }
34  void PushShapeToArrival(Color color){ return static_cast<TSelf*>(this)->DoPushShapeToArrival(color); }
35 
36  // DoXXX defined here are use by default when DoXXX are not defined in TSelf
37  const Vec3f& DoGetStartPos()
38  {
39  return m_query->m_startPos3f;
40  }
41 
42  void DoPushStartTriangle(Color color)
43  {
44  m_displayList->PushTriangle(m_output->m_startTriangle.m_triangle.OffsetZ(0.1f), color);
45  }
46 
47 
48 
49 
50 protected:
51  void Clear()
52  {
53  m_query = nullptr;
54  m_output = nullptr;
55  m_displayList = nullptr;
56  }
57 
58  bool Init(DisplayList* displayList, char* blob)
59  {
60  m_query = (TQuery*)blob;
61  m_output = (TOutput*)m_query->m_queryOutput.Ptr();
62  m_displayList = displayList;
63  return m_output != nullptr;
64  }
65 
66  void PushStartText(Color color, const char* text)
67  {
68  m_displayList->PushText(GetStartPos().OffsetZ(1.0f), color, text);
69  }
70 
71  void PushDestText(Color color, const char* text)
72  {
73  m_displayList->PushText(m_query->m_destPos3f.OffsetZ(1.0f), color, text);
74  }
75 
76  void PushArrivalTriangle(Color color)
77  {
78  m_displayList->PushTriangle(m_output->m_arrivalTriangle.m_triangle.OffsetZ(0.1f), color);
79  }
80 
81  void PushDestTriangle(Color color)
82  {
83  m_displayList->PushTriangle(m_output->m_destTriangle.m_triangle.OffsetZ(0.1f), color);
84  }
85 
86  void PushCollisionPoint(Color color, const char* text)
87  {
88  m_displayList->PushVerticalTriangleCrossInv(m_output->m_collisionPos3f, 1.0f, 0.25f, color);
89  m_displayList->PushText(m_output->m_collisionPos3f.OffsetZ(1.0f), color, text);
90  }
91 
92  void PushDynamicOutput()
93  {
94  QueryDynamicOutputBlob* dynOutput = m_output->m_queryDynamicOutputBlobRef.Ptr();
95  if (dynOutput != nullptr)
96  QueryDynamicOutputDisplayListBuilder().Build(m_displayList, (char*)dynOutput, 0);
97  }
98 
99  void PushStartError(const char* text)
100  {
101  PushQueryShape(Color::Red);
102  PushStartText(Color::Red, text);
103  }
104 
105  void Push_NOT_PROCESSED()
106  {
107  PushStartText(Color::Orange, "Not processed...");
108  PushQueryShape(Color::Orange);
109  }
110 
111  void Push_PROCESSING(const char* text)
112  {
113  PushStartText(Color::Orange, text);
114  PushQueryShape(Color::Orange);
115  }
116 
117  void Push_START_OUTSIDE()
118  {
119  PushStartText(Color::Red, "Start outside!");
120  PushQueryShape(Color::Red);
121  }
122 
123  void Push_DEST_OUTSIDE()
124  {
125  PushStartText(Color::Red, "Destination outside!");
126  PushQueryShape(Color::Red);
127  }
128 
129  void Push_START_NAVTAG_FORBIDDEN()
130  {
131  PushStartTriangle(Color::Red);
132  PushStartText(Color::Red, "Start NavTag forbidden!");
133  PushQueryShape(Color::Red);
134  }
135 
136  void Push_DEST_NAVTAG_FORBIDDEN()
137  {
138  PushDestTriangle(Color::Red);
139  PushDestText(Color::Red, "Destination NavTag forbidden!");
140  PushQueryShape(Color::Red);
141  }
142 
143  void Push_COLLISION_DETECTED()
144  {
145  PushStartTriangle(Color::Green);
146  PushQueryShape(Color::Red);
147  }
148 
149  void Push_ARRIVAL_WRONG_FLOOR()
150  {
151  PushStartTriangle(Color::Green);
152  PushDestText(Color::Red, "Arrival in wrong floor!");
153  PushQueryShape(Color::Red);
154  }
155 
156  void Push_LACK_OF_WORKING_MEMORY()
157  {
158  PushStartTriangle(Color::Green);
159  PushStartText(Color::Red, "Lack of working memory!");
160  PushQueryShape(Color::Red);
161  }
162 
163  void Push_UNKNOWN_ERROR()
164  {
165  PushStartText(Color::Red, "Unknown error!");
166  PushQueryShape(Color::Red);
167  }
168 
169  void Push_SUCCESS()
170  {
171  PushStartTriangle(Color::Green);
172  PushDestTriangle(Color::Green);
173  PushQueryShape(Color::Green);
174  }
175 
176  void Push_CANNOT_MOVE()
177  {
178  PushStartTriangle(Color::Green);
179  PushCollisionPoint(Color::Orange, "Collision point (cannot move)");
180  PushQueryShape(Color::Orange);
181  }
182 
183  void Push_ARRIVAL_ERROR()
184  {
185  PushStartTriangle(Color::Green);
186  PushCollisionPoint(Color::Red, "Collision point (arrival error)");
187  PushQueryShape(Color::Red);
188  }
189 
190  void Push_MAXDIST_REACHED()
191  {
192  PushStartTriangle(Color::Green);
193  PushArrivalTriangle(Color::Green);
194  PushShapeToArrival(Color::Green);
195  }
196 
197  void Push_COLLISION()
198  {
199  PushStartTriangle(Color::Green);
200  PushArrivalTriangle(Color::Green);
201  PushCollisionPoint(Color::Orange, "Collision");
202  PushShapeToArrival(Color::Green);
203  }
204 };
205 
206 }
207 
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17