Debian Codegraph @

DetourCrowd/Include/DetourObstacleAvoidance.h

raw symbols SCIP
1 //
2 // Copyright (c) 2009-2010 Mikko Mononen [email protected]
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty. In no event will the authors be held liable for any damages
6 // arising from the use of this software.
7 // Permission is granted to anyone to use this software for any purpose,
8 // including commercial applications, and to alter it and redistribute it
9 // freely, subject to the following restrictions:
10 // 1. The origin of this software must not be misrepresented; you must not
11 // claim that you wrote the original software. If you use this software
12 // in a product, an acknowledgment in the product documentation would be
13 // appreciated but is not required.
14 // 2. Altered source versions must be plainly marked as such, and must not be
15 // misrepresented as being the original software.
16 // 3. This notice may not be removed or altered from any source distribution.
17 //
18
19 #ifndef DETOUROBSTACLEAVOIDANCE_H
20 #define DETOUROBSTACLEAVOIDANCE_H
21
22 struct dtObstacleCircle
23 {
24 float p[3]; ///< Position of the obstacle
25 float vel[3]; ///< Velocity of the obstacle
26 float dvel[3]; ///< Velocity of the obstacle
27 float rad; ///< Radius of the obstacle
28 float dp[3], np[3]; ///< Use for side selection during sampling.
29 };
30
31 struct dtObstacleSegment
32 {
33 float p[3], q[3]; ///< End points of the obstacle segment
34 bool touch;
35 };
36
37
38 class dtObstacleAvoidanceDebugData
39 {
40 public:
41 dtObstacleAvoidanceDebugData();
42 ~dtObstacleAvoidanceDebugData();
43
44 bool init(const int maxSamples);
45 void reset();
46 void addSample(const float* vel, const float ssize, const float pen,
47 const float vpen, const float vcpen, const float spen, const float tpen);
48
49 void normalizeSamples();
50
51 inline int getSampleCount() const { return m_nsamples; }
52 inline const float* getSampleVelocity(const int i) const { return &m_vel[i*3]; }
53 inline float getSampleSize(const int i) const { return m_ssize[i]; }
54 inline float getSamplePenalty(const int i) const { return m_pen[i]; }
55 inline float getSampleDesiredVelocityPenalty(const int i) const { return m_vpen[i]; }
56 inline float getSampleCurrentVelocityPenalty(const int i) const { return m_vcpen[i]; }
57 inline float getSamplePreferredSidePenalty(const int i) const { return m_spen[i]; }
58 inline float getSampleCollisionTimePenalty(const int i) const { return m_tpen[i]; }
59
60 private:
61 // Explicitly disabled copy constructor and copy assignment operator.
62 dtObstacleAvoidanceDebugData(const dtObstacleAvoidanceDebugData&);
63 dtObstacleAvoidanceDebugData& operator=(const dtObstacleAvoidanceDebugData&);
64
65 int m_nsamples;
66 int m_maxSamples;
67 float* m_vel;
68 float* m_ssize;
69 float* m_pen;
70 float* m_vpen;
71 float* m_vcpen;
72 float* m_spen;
73 float* m_tpen;
74 };
75
76 dtObstacleAvoidanceDebugData* dtAllocObstacleAvoidanceDebugData();
77 void dtFreeObstacleAvoidanceDebugData(dtObstacleAvoidanceDebugData* ptr);
78
79
80 static const int DT_MAX_PATTERN_DIVS = 32; ///< Max numver of adaptive divs.
81 static const int DT_MAX_PATTERN_RINGS = 4; ///< Max number of adaptive rings.
82
83 struct dtObstacleAvoidanceParams
84 {
85 float velBias;
86 float weightDesVel;
87 float weightCurVel;
88 float weightSide;
89 float weightToi;
90 float horizTime;
91 unsigned char gridSize; ///< grid
92 unsigned char adaptiveDivs; ///< adaptive
93 unsigned char adaptiveRings; ///< adaptive
94 unsigned char adaptiveDepth; ///< adaptive
95 };
96
97 class dtObstacleAvoidanceQuery
98 {
99 public:
100 dtObstacleAvoidanceQuery();
101 ~dtObstacleAvoidanceQuery();
102
103 bool init(const int maxCircles, const int maxSegments);
104
105 void reset();
106
107 void addCircle(const float* pos, const float rad,
108 const float* vel, const float* dvel);
109
110 void addSegment(const float* p, const float* q);
111
112 int sampleVelocityGrid(const float* pos, const float rad, const float vmax,
113 const float* vel, const float* dvel, float* nvel,
114 const dtObstacleAvoidanceParams* params,
115 dtObstacleAvoidanceDebugData* debug = 0);
116
117 int sampleVelocityAdaptive(const float* pos, const float rad, const float vmax,
118 const float* vel, const float* dvel, float* nvel,
119 const dtObstacleAvoidanceParams* params,
120 dtObstacleAvoidanceDebugData* debug = 0);
121
122 inline int getObstacleCircleCount() const { return m_ncircles; }
123 const dtObstacleCircle* getObstacleCircle(const int i) { return &m_circles[i]; }
124
125 inline int getObstacleSegmentCount() const { return m_nsegments; }
126 const dtObstacleSegment* getObstacleSegment(const int i) { return &m_segments[i]; }
127
128 private:
129 // Explicitly disabled copy constructor and copy assignment operator.
130 dtObstacleAvoidanceQuery(const dtObstacleAvoidanceQuery&);
131 dtObstacleAvoidanceQuery& operator=(const dtObstacleAvoidanceQuery&);
132
133 void prepare(const float* pos, const float* dvel);
134
135 float processSample(const float* vcand, const float cs,
136 const float* pos, const float rad,
137 const float* vel, const float* dvel,
138 const float minPenalty,
139 dtObstacleAvoidanceDebugData* debug);
140
141 dtObstacleAvoidanceParams m_params;
142 float m_invHorizTime;
143 float m_vmax;
144 float m_invVmax;
145
146 int m_maxCircles;
147 dtObstacleCircle* m_circles;
148 int m_ncircles;
149
150 int m_maxSegments;
151 dtObstacleSegment* m_segments;
152 int m_nsegments;
153 };
154
155 dtObstacleAvoidanceQuery* dtAllocObstacleAvoidanceQuery();
156 void dtFreeObstacleAvoidanceQuery(dtObstacleAvoidanceQuery* ptr);
157
158
159 #endif // DETOUROBSTACLEAVOIDANCE_H