CAlgorithmFingerProxy.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2016, CHAI3D.
5  (www.chai3d.org)
6 
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions
11  are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 
16  * Redistributions in binary form must reproduce the above
17  copyright notice, this list of conditions and the following
18  disclaimer in the documentation and/or other materials provided
19  with the distribution.
20 
21  * Neither the name of CHAI3D nor the names of its contributors may
22  be used to endorse or promote products derived from this software
23  without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  POSSIBILITY OF SUCH DAMAGE.
37 
38  \author <http://www.chai3d.org>
39  \author Francois Conti
40  \version 3.2.0 $Rev: 1869 $
41 */
42 //==============================================================================
43 
44 //------------------------------------------------------------------------------
45 #ifndef CAlgorithmFingerProxyH
46 #define CAlgorithmFingerProxyH
47 //------------------------------------------------------------------------------
50 #include "math/CVector3d.h"
51 #include "math/CMatrix3d.h"
52 //------------------------------------------------------------------------------
53 #include <map>
54 //------------------------------------------------------------------------------
55 
56 //------------------------------------------------------------------------------
57 namespace chai3d {
58 //------------------------------------------------------------------------------
59 
60 //------------------------------------------------------------------------------
61 class cWorld;
62 //------------------------------------------------------------------------------
63 
64 //==============================================================================
71 //==============================================================================
72 
73 //==============================================================================
85 //==============================================================================
87 {
88  //--------------------------------------------------------------------------
89  // CONSTRUCTOR & DESTRUCTOR:
90  //--------------------------------------------------------------------------
91 
92 public:
93 
96 
99 
100 
101  //----------------------------------------------------------------------
102  // METHODS - BASIC PROXY:
103  //----------------------------------------------------------------------
104 
106  void initialize(cWorld* a_world, const cVector3d& a_initialGlobalPosition);
107 
109  void reset();
110 
112  virtual cVector3d computeForces(const cVector3d& a_toolPos, const cVector3d& a_toolVel);
113 
114 
115  //----------------------------------------------------------------------
116  // METHODS - GETTER AND SETTER FUNCTIONS:
117  //----------------------------------------------------------------------
118 
120  void setProxyRadius(const double& a_radius) { m_radius = a_radius; m_collisionSettings.m_collisionRadius = m_radius;}
121 
123  inline double getProxyRadius() const { return (m_radius); }
124 
126  inline cVector3d getProxyGlobalPosition() const { return (m_proxyGlobalPos); }
127 
129  inline void setProxyGlobalPosition(const cVector3d& a_position) { m_proxyGlobalPos = a_position; }
130 
133 
135  inline cVector3d getForce() { return (m_lastGlobalForce); }
136 
138  inline cVector3d getNormalForce() { return (m_normalForce); }
139 
142 
143 
144  //----------------------------------------------------------------------
145  // METHODS - COLLISION INFORMATION BETWEEN PROXY AND WORLD
146  //----------------------------------------------------------------------
147 
148 public:
149 
152 
153 
154  //----------------------------------------------------------------------
155  // MEMMBERS - COLLISION INFORMATION BETWEEN PROXY AND WORLD
156  //----------------------------------------------------------------------
157 
158 public:
159 
162 
163 
164  //----------------------------------------------------------------------
165  // MEMBERS - FORCE MODELS
166  //----------------------------------------------------------------------
167 
168 public:
169 
172 
180 
183 
186 
187 
188  //----------------------------------------------------------------------
189  // METHODS - RESOLUTION / ERRORS
190  //----------------------------------------------------------------------
191 
192 public:
193 
195  void setEpsilonBaseValue(double a_value);
196 
199 
200 
201  //--------------------------------------------------------------------------
202  // PROTECTED METHODS - GRAPHICS:
203  //--------------------------------------------------------------------------
204 
205 protected:
206 
208  virtual void render(cRenderOptions& a_options);
209 
210 
211  //--------------------------------------------------------------------------
212  // PROTECTED METHODS - INTERNAL:
213  //--------------------------------------------------------------------------
214 
215 protected:
216 
218  virtual bool goalAchieved(const cVector3d& a_proxy, const cVector3d& a_goal) const;
219 
221  virtual void computeNextBestProxyPosition(const cVector3d& a_goal);
222 
224  virtual void testFrictionAndMoveProxy(const cVector3d& a_goal, const cVector3d& a_proxy, cVector3d& a_normal, cGenericObject* a_parent);
225 
227  virtual void updateForce();
228 
229 
230  //----------------------------------------------------------------------
231  // MEMBERS - PROXY, DEVICE AND FORCE INFORMATION:
232  //----------------------------------------------------------------------
233 
234 protected:
235 
238 
241 
244 
247 
250 
253 
256 
258  unsigned int m_numCollisionEvents;
259 
261  double m_radius;
262 
263 
264  //----------------------------------------------------------------------
265  // PROTECTED MEMBERS - PROXY ALGORITHM
266  //----------------------------------------------------------------------
267 
268 protected:
269 
272 
275 
278 
281 
284 
287 
293  double m_epsilonInitialValue;
295 
297  double m_epsilon;
298 
301 
304 
307 
309  unsigned int m_algoCounter;
310 
311 
312  //----------------------------------------------------------------------
313  // PROTECTED METHODS - PROXY ALGORITHM
314  //----------------------------------------------------------------------
315 
316 protected:
317 
319  void adjustDynamicProxy(const cVector3d& a_goal);
320 
322  bool computeNextProxyPositionWithContraints0(const cVector3d& a_goalGlobalPos);
323 
325  bool computeNextProxyPositionWithContraints1(const cVector3d& a_goalGlobalPos);
326 
328  bool computeNextProxyPositionWithContraints2(const cVector3d& a_goalGlobalPos);
329 
332 
333 
334  //----------------------------------------------------------------------
335  // DEBUG PURPOSES
336  //----------------------------------------------------------------------
337 
338 protected:
339 
342 };
343 
344 //------------------------------------------------------------------------------
345 } // namespace chai3d
346 //------------------------------------------------------------------------------
347 
348 //------------------------------------------------------------------------------
349 #endif
350 //------------------------------------------------------------------------------
351 
This class implements a 3D vector.
Definition: CVector3d.h:88
void setProxyRadius(const double &a_radius)
This method sets the radius of the proxy.
Definition: CAlgorithmFingerProxy.h:120
cCollisionRecorder m_collisionRecorderConstraint2
Collision detection recorder for searching third constraint.
Definition: CAlgorithmFingerProxy.h:277
This structures provide a containers for storing rendering options that are passed through the sceneg...
Definition: CRenderOptions.h:82
bool m_slipping
If true then we are currently in a "slip friction".
Definition: CAlgorithmFingerProxy.h:249
void reset()
This method reset the algorithm and sets the proxy position to the device position.
Definition: CAlgorithmFingerProxy.cpp:159
void setProxyGlobalPosition(const cVector3d &a_position)
This method sets the position of the proxy in world coordinates.
Definition: CAlgorithmFingerProxy.h:129
unsigned int m_numCollisionEvents
Number of collision events between proxy and triangles (0, 1, 2 or 3).
Definition: CAlgorithmFingerProxy.h:258
cVector3d surfaceNormal
Surface normal.
Definition: CAlgorithmFingerProxy.h:341
cCollisionSettings m_collisionSettings
Collision settings.
Definition: CAlgorithmFingerProxy.h:185
bool computeNextProxyPositionWithContraints2(const cVector3d &a_goalGlobalPos)
This method updates the position of the proxy - constraint 2.
Definition: CAlgorithmFingerProxy.cpp:754
double m_forceShadingAngleThreshold
Maximum force shading angle (radians) threshold between normals of triangle.
Definition: CAlgorithmFingerProxy.h:182
void setEpsilonBaseValue(double a_value)
This method sets the epsilon tolerance error base value.
Definition: CAlgorithmFingerProxy.cpp:184
cVector3d m_tangentialForce
Tangential force.
Definition: CAlgorithmFingerProxy.h:255
cCollisionRecorder m_collisionRecorderConstraint1
Collision detection recorder for searching second constraint.
Definition: CAlgorithmFingerProxy.h:274
void adjustDynamicProxy(const cVector3d &a_goal)
This method ajust the position of proxy by taking into account motion of objects in the world...
Definition: CAlgorithmFingerProxy.cpp:329
This structure stores the data related to a collision event.
Definition: CCollisionBasics.h:91
double getEpsilonBaseValue()
This method returns the current epsilon tolerance error base value.
Definition: CAlgorithmFingerProxy.h:198
double m_epsilonBaseValue
Epsilon value - used for handling numerical limits.
Definition: CAlgorithmFingerProxy.h:303
cVector3d getNormalForce()
This method returns the most recently calculated normal force.
Definition: CAlgorithmFingerProxy.h:138
double m_epsilonMinimalValue
Epsilon value - used for handling numerical limits.
Definition: CAlgorithmFingerProxy.h:306
cVector3d computeShadedSurfaceNormal(cCollisionEvent *a_contactPoint)
This method computes the local surface normal from interpolated vertex normals.
Definition: CAlgorithmFingerProxy.cpp:1346
double m_epsilon
Epsilon value - used for handling numerical limits.
Definition: CAlgorithmFingerProxy.h:297
virtual void updateForce()
This method computes the resulting force which will be sent to the haptic device. ...
Definition: CAlgorithmFingerProxy.cpp:1073
This class implements a virtual world.
Definition: CWorld.h:92
double getProxyRadius() const
This method returns the radius of the proxy.
Definition: CAlgorithmFingerProxy.h:123
Implements a base class for programming collision detectors that identify intersections between segme...
cVector3d m_normalForce
Normal force.
Definition: CAlgorithmFingerProxy.h:252
This class implements a base class for all 2D or 3D objects in CHAI3D.
Definition: CGenericObject.h:112
This class implements a collision detection recorder that stores all collision events that are report...
Definition: CCollisionBasics.h:185
bool computeNextProxyPositionWithContraints1(const cVector3d &a_goalGlobalPos)
This method updates the position of the proxy - constraint 1.
Definition: CAlgorithmFingerProxy.cpp:579
This class implements a base class for modeling force rendering algorithms.
Definition: CGenericForceAlgorithm.h:84
This structure stores the collision settings that are passed to a collision detector when querying fo...
Definition: CCollisionBasics.h:242
void initialize(cWorld *a_world, const cVector3d &a_initialGlobalPosition)
This method initialize the algorithm.
Definition: CAlgorithmFingerProxy.cpp:130
int getNumCollisionEvents()
This method return the number of collision events (0, 1, 2 or 3):
Definition: CAlgorithmFingerProxy.h:151
double m_frictionDynHysteresisMultiplier
Definition: CAlgorithmFingerProxy.h:179
Implements a 3D matrix.
cCollisionEvent * m_collisionEvents[3]
Table of collision events (0-3). Call getNumCollisionEvents() to see how many are actually valid...
Definition: CAlgorithmFingerProxy.h:161
bool m_useDynamicProxy
If true the the dynamic proxy is enabled to handle moving objects.
Definition: CAlgorithmFingerProxy.h:171
cVector3d getProxyGlobalPosition() const
This method returns the last computed position of the proxy in world coordinates. ...
Definition: CAlgorithmFingerProxy.h:126
bool computeNextProxyPositionWithContraints0(const cVector3d &a_goalGlobalPos)
This method updates the position of the proxy - constraint 0.
Definition: CAlgorithmFingerProxy.cpp:408
Implements a 3D vector.
virtual cVector3d computeForces(const cVector3d &a_toolPos, const cVector3d &a_toolVel)
This method calculates the interaction forces.
Definition: CAlgorithmFingerProxy.cpp:204
This class implements a finger-proxy force rendering algorithm.
Definition: CAlgorithmFingerProxy.h:86
virtual void testFrictionAndMoveProxy(const cVector3d &a_goal, const cVector3d &a_proxy, cVector3d &a_normal, cGenericObject *a_parent)
This method attempts to move the proxy, subject to friction constraints.
Definition: CAlgorithmFingerProxy.cpp:945
cVector3d m_lastGlobalForce
Last computed force (in global coordinate frame).
Definition: CAlgorithmFingerProxy.h:243
cVector3d getDeviceGlobalPosition() const
This method returns the last specified position of the device in world coordinates.
Definition: CAlgorithmFingerProxy.h:132
double m_epsilonCollisionDetection
Epsilon value - used for handling numerical limits.
Definition: CAlgorithmFingerProxy.h:300
cVector3d m_nextBestProxyGlobalPos
Next best position for the proxy (in global coordinate frame).
Definition: CAlgorithmFingerProxy.h:246
cVector3d m_proxyGlobalPos
Global position of the proxy.
Definition: CAlgorithmFingerProxy.h:237
cVector3d m_contactPointLocalPos1
Local position of contact point first object.
Definition: CAlgorithmFingerProxy.h:283
Definition: CAudioBuffer.cpp:56
virtual void computeNextBestProxyPosition(const cVector3d &a_goal)
This method computes the next goal position of the proxy.
Definition: CAlgorithmFingerProxy.cpp:248
double m_radius
Radius of the proxy.
Definition: CAlgorithmFingerProxy.h:261
unsigned int m_algoCounter
Value of state machine.
Definition: CAlgorithmFingerProxy.h:309
virtual bool goalAchieved(const cVector3d &a_proxy, const cVector3d &a_goal) const
This method tests whether the proxy has reached the goal point.
Definition: CAlgorithmFingerProxy.cpp:927
cCollisionRecorder m_collisionRecorderConstraint0
Collision detection recorder for searching first constraint.
Definition: CAlgorithmFingerProxy.h:271
Implements a base class for force rendering algorithms.
cVector3d m_contactPointLocalPos2
Local position of contact point first object.
Definition: CAlgorithmFingerProxy.h:286
double m_collisionRadius
Collision radius. This value typically corresponds to the radius of the virtual tool or cursor...
Definition: CCollisionBasics.h:275
double m_epsilonInitialValue
Epsilon value - used for handling numerical limits.
Definition: CAlgorithmFingerProxy.h:294
cAlgorithmFingerProxy()
Constructor of cAlgorithmFingerProxy.
Definition: CAlgorithmFingerProxy.cpp:59
cVector3d m_contactPointLocalPos0
Local position of contact point first object.
Definition: CAlgorithmFingerProxy.h:280
virtual void render(cRenderOptions &a_options)
This method renders the force algorithms graphically in OpenGL. (For debug purposes) ...
Definition: CAlgorithmFingerProxy.cpp:1451
cVector3d m_deviceGlobalPos
Global position of device.
Definition: CAlgorithmFingerProxy.h:240
virtual ~cAlgorithmFingerProxy()
Destructor of cAlgorithmFingerProxy.
Definition: CAlgorithmFingerProxy.h:98
cVector3d getForce()
This method returns the last computed force in world coordinates.
Definition: CAlgorithmFingerProxy.h:135
cVector3d getTangentialForce()
This method returns the most recently calculated tangential force.
Definition: CAlgorithmFingerProxy.h:141