AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
WireRouteController.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
21
22#include <agx/Referenced.h>
23
25
26namespace agxWire
27{
28 // Forward declarations
29 namespace Composite
30 {
31 class Segment;
32 }
33
38 class AGXPHYSICS_EXPORT WireRouteController : public agx::Referenced
39 {
40 public:
41 WireRouteController();
42
49 virtual bool add( agxWire::Node* node );
50
58 virtual int add( agxWire::WireWinchController* winchController, agx::Real pulledInLength );
59
65 virtual bool remove( agxWire::Node* node );
66
72 virtual bool remove( agxWire::WireWinchController* winchController );
73
81 virtual bool insert( agxWire::Node* node, agx::Real distanceFromStart );
82
89 virtual bool insert( agxWire::Node* node, agxWire::NodeIterator beforeThisNode );
90
94 virtual void updateNodeTransforms();
95
101 virtual bool reverse( bool initialized );
102
108 virtual WireRouteController* cut( agx::Real distanceAlongRoute );
109
119 virtual bool attach( agxWire::Node* node, bool begin );
120
128 virtual bool attach( agxWire::WireWinchController* winchController, bool begin );
129
136 virtual bool detach( bool begin );
137
142 virtual void setResolutionPerUnitLength( agx::Real resolutionPerUnitLength );
143
147 inline agx::Real getResolutionPerUnitLength() const;
148
154 agx::Real getCurrentLength( bool includeConnecting = true ) const;
155
159 virtual void clear();
160
169 agx::Real getCurrentLength( const agxWire::Node* node1, const agxWire::Node* node2 ) const;
170
176 agxWire::Node* getNode( agx::Real distanceFromStart ) const;
177
181 const agxWire::NodeContainer& getNodes() const { return m_nodes; }
182 agxWire::NodeContainer& getNodes() { return m_nodes; }
183
187 const agxWire::WireWinchControllerRefVector& getWinchControllers() const { return m_winchControllers; }
188 agxWire::WireWinchControllerRefVector& getWinchControllers() { return m_winchControllers; }
189
193 inline bool hasNode( const agxWire::Node* node ) const;
194
198 inline agxWire::NodeIterator getEndIterator();
199 inline agxWire::NodeConstIterator getEndIterator() const;
200
205 inline agxWire::NodeIterator getIterator( agxWire::Node* node );
206 inline agxWire::NodeConstIterator getIterator( const agxWire::Node* node ) const;
207
208 protected:
209 virtual ~WireRouteController();
210
211 friend class Wire;
212 friend class Composite::Segment;
213
217 explicit WireRouteController( const agxWire::WireRouteController& other )
218 : agx::Referenced()
219 {
220 *this = other;
221 }
222
223 agxWire::WireRouteController& operator = ( const agxWire::WireRouteController& other );
224
225 inline void setInitialized( bool initialized );
226 inline bool getInitialized() const;
227
234 bool insertAfter( agxWire::Node* node, agxWire::Node* afterThisNode );
235
239 inline void addToList( agxWire::Node* node );
240
244 inline bool removeFromList( agxWire::Node* node );
245
246 protected:
247 NodeContainer m_nodes;
248 NodePtrNodeIterHash m_nodeToIterator;
249 bool m_initialized;
250 agx::Real m_resolutionPerUnitLength;
251 WireWinchControllerRefVector m_winchControllers;
252 };
253
254 typedef agx::ref_ptr< WireRouteController > WireRouteControllerRef;
255
256 // Inline methods ------------------------------------------------------------
257 inline void WireRouteController::setInitialized( bool initialized )
258 {
259 m_initialized = initialized;
260 }
261
262 inline bool WireRouteController::getInitialized() const
263 {
264 return m_initialized;
265 }
266
267 inline bool WireRouteController::hasNode( const Node* node ) const
268 {
269 if ( node )
270 return m_nodeToIterator.contains( const_cast< Node* >( node ) );
271 return false;
272 }
273
274 inline agx::Real WireRouteController::getResolutionPerUnitLength() const
275 {
276 return m_resolutionPerUnitLength;
277 }
278
279 inline void WireRouteController::addToList( Node* node )
280 {
281 m_nodes.push_back( node );
282 m_nodeToIterator.insert( node, --m_nodes.end() );
283 }
284
285 inline bool WireRouteController::removeFromList( Node* node )
286 {
287 // We need the iterator, so instead of hasNode.
288 NodePtrNodeIterHash::iterator nodeToIterIt = m_nodeToIterator.find( node );
289 if ( nodeToIterIt == m_nodeToIterator.end() )
290 return false;
291
292 NodeIterator nodeIt = nodeToIterIt->second;
293 m_nodeToIterator.erase( nodeToIterIt );
294 m_nodes.erase( nodeIt );
295
296 return true;
297 }
298
299 inline NodeIterator WireRouteController::getEndIterator()
300 {
301 return m_nodes.end();
302 }
303
304 inline NodeConstIterator WireRouteController::getEndIterator() const
305 {
306 return m_nodes.end();
307 }
308
309 inline NodeIterator WireRouteController::getIterator( Node* node )
310 {
311 if ( node == nullptr )
312 return m_nodes.end();
313 NodePtrNodeIterHash::iterator i = m_nodeToIterator.find( node );
314 return i != m_nodeToIterator.end() ? i->second : m_nodes.end();
315 }
316
317 inline NodeConstIterator WireRouteController::getIterator( const Node* node ) const
318 {
319 if ( node == nullptr )
320 return m_nodes.end();
321 NodePtrNodeIterHash::const_iterator i = m_nodeToIterator.find( const_cast< Node* >( node ) );
322 return i != m_nodeToIterator.end() ? i->second : m_nodes.end();
323 }
324 // ---------------------------------------------------------------------------
325}
326
328
#define AGXPHYSICS_EXPORT
Class defining a node that is part of a wire.
Winch class for handling in and out hauling of wires.
Base class providing referencing counted objects.
Definition Referenced.h:120
Referenced & operator=(const Referenced &)
Assignment operator. Will increment the number of references to the referenced object.
Smart pointer for handling referenced counted objects.
Definition ref_ptr.h:30
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition macros.h:96
AGXTERRAIN_EXPORT void clear()
Implements a Wire model with adaptive resolution.
Definition MergedBody.h:40
NodeRefListA NodeContainer
NodeContainer::const_iterator NodeConstIterator
const Node * getNode(const IteratorCompatibleContainer &container, agx::Real distanceFromStart)
Finds the wire node given current distance from the start of the wire (wire defined to be iterator co...
Definition WireUtils.h:392
agx::LinearProbingHashTable< Node *, NodeIterator > NodePtrNodeIterHash
agx::Vector< WireWinchControllerRef > WireWinchControllerRefVector
NodeContainer::iterator NodeIterator
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
double Real
Definition Real.h:42