VR-Engage  2.2
Loading...
Searching...
No Matches
vortexInterface.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2024 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vortexInterface.h
7//! \brief Provides interface functionality between VR-Forces and the Vortex physics engine
8//! \ingroup vreVrfVortex
9
10#pragma once
11
12#include <vreVrfVortex/export.h>
13
14#include <VxSim/VxSmartInterface.h>
15#include <VxSim/VxVHLInterface.h>
16
17#include <vector>
18
19namespace makVre
20{
22}
23
24class DtInputPortGroup;
25class DtOutputPortGroup;
26class DtSingleConnectionInputPort;
27class DtSingleConnectionOutputPort;
28class DtVrfObjectStateRepository;
29
30namespace VxData
31{
32class FieldBase;
33}
34
35namespace VxSim
36{
37class VxExtension;
38class VxPluginExtension;
39class VxVHLInterface;
40class VxSimulationState;
41} // namespace VxSim
42
43//! \brief Base class for Vortex interface elements
44//!
45//! Provides a common interface for all Vortex interface elements, allowing for
46//! type-agnostic handling of different port types.
48{
49public:
50 //! \brief Default constructor
52
53 //! \brief Virtual destructor
54 //!
55 //! Ensures proper cleanup of derived classes.
57
58 //! \brief Updates the interface element
59 //!
60 //! Pure virtual function that must be implemented by derived classes
61 //! to handle data transfer between ports and Vortex fields.
62 virtual void update() = 0;
63
64 //! \brief Gets the port name
65 //!
66 //! \return The name of the port
67 virtual std::string portName() = 0;
68
69 //! \brief Gets the field name
70 //!
71 //! \return The name of the field
72 virtual std::string getFieldName() = 0;
73
74 //! \brief Sets the Vortex field associated with this element
75 //!
76 //! \param field Pointer to the Vortex field
77 virtual void setField(VxData::FieldBase* field) = 0;
78};
79
80//---------------------------------------------------------------------------------------------------------------------
81
82//! \brief Template class for Vortex interface elements
83//!
84//! Implements the DtVortexInterfaceBaseElement interface for specific port types.
85//! Handles the connection between VR-Forces ports and Vortex fields.
86template <typename T>
88{
89public:
90 //! \brief Constructor
91 //!
92 //! Creates and initializes the port with the specified names.
93 //!
94 //! \param portName Name of the port
95 //! \param vortexName Name of the Vortex field
96 DtVortexInterfaceElement(std::string portName, const std::string& vortexName);
97
98 //! \brief Destructor
99 //!
100 //! Cleans up resources.
101 virtual ~DtVortexInterfaceElement() override;
102
103 //! \brief Updates the interface element
104 //!
105 //! Transfers data between the port and the Vortex field.
106 //! The implementation of this method is specialized for different port types.
107 virtual void update() override;
108
109 //! \brief Gets the port
110 //!
111 //! Provides access to the underlying port object.
112 //!
113 //! \return Pointer to the port
114 T* port() { return myPort; }
115
116 //! \brief Sets the Vortex field
117 //!
118 //! Associates a Vortex field with this interface element.
119 //!
120 //! \param field Pointer to the Vortex field
121 virtual void setField(VxData::FieldBase* field) override;
122
123 //! \brief Gets the Vortex field
124 //!
125 //! \return Pointer to the Vortex field
126 VxData::FieldBase* getField() const;
127
128 //! \brief Gets the port name
129 //!
130 //! \return The name of the port
131 virtual std::string portName() override;
132
133 //! \brief Gets the field name
134 //!
135 //! \return The name of the field
136 virtual std::string getFieldName() override;
137
138protected:
139 T* myPort; //!< Pointer to the port
140 VxData::FieldBase* myVortexField; //!< Pointer to the Vortex field
141 std::string myPortName; //!< Name of the port
142 std::string myFieldName; //!< Name of the field
143};
144
145//! \brief Gets the field name
146//!
147//! \return The name of the field
148template <typename T>
150{
151 return myFieldName;
152}
153
154//! \brief Gets the port name
155//!
156//! \return The name of the port
157template <typename T>
159{
160 return myPortName;
161}
162
163//! \brief Gets the Vortex field
164//!
165//! \return Pointer to the Vortex field
166template <typename T>
168{
169 return myVortexField;
170}
171
172//! \brief Sets the Vortex field
173//!
174//! \param field Pointer to the Vortex field
175template <typename T>
176void DtVortexInterfaceElement<T>::setField(VxData::FieldBase* field)
177{
178 myVortexField = field;
179}
180
181//---------------------------------------------------------------------------------------------------------------------
182
183//! \brief Class for managing Vortex interfaces
184//!
185//! Provides functionality for creating and managing the connection between VR-Forces ports
186//! and Vortex interfaces. Handles both input and output ports.
188{
189public:
190 //! \brief Constructor
191 //!
192 //! Creates ports based on the descriptor and optionally connects them to the Vortex interface.
193 //!
194 //! \param desc Descriptor containing interface configuration
195 //! \param iface Optional Vortex interface to connect to
197 makVre::DtVortexInterfaceDescriptor* desc, const VxSim::VxWeakInterface<VxSim::VxVHLInterface>& iface = nullptr);
198
199 //! \brief Destructor
200 //!
201 //! Cleans up resources.
203
204 //! \brief Gets the input port group
205 //!
206 //! Provides access to all input ports.
207 //!
208 //! \return Pointer to the input port group
209 virtual DtInputPortGroup* inputPortGroup();
210
211 //! \brief Gets the output port group
212 //!
213 //! Provides access to all output ports.
214 //!
215 //! \return Pointer to the output port group
216 virtual DtOutputPortGroup* outputPortGroup();
217
218 //! \brief Updates all input elements
219 //!
220 //! Transfers data from input ports to Vortex fields.
221 virtual void updateInputs();
222
223 //! \brief Updates all output elements
224 //!
225 //! Transfers data from Vortex fields to output ports.
226 virtual void updateOutputs();
227
228 //! \brief Updates the object state repository with output values
229 //!
230 //! Transfers data from output ports to the state repository.
231 //!
232 //! \param esr Pointer to the object state repository
233 virtual void updateOutputStateRepository(DtVrfObjectStateRepository* esr);
234
235 //! \brief Sets the Vortex interface
236 //!
237 //! \param iface Vortex interface to connect to
238 virtual void setInterface(VxSim::VxWeakInterface<VxSim::VxVHLInterface> iface);
239
240 //! \brief Connects ports to the Vortex interface
241 //!
242 //! Associates each port with the corresponding Vortex field.
244
245 //! \brief Gets an input element by name
246 //!
247 //! \param name Name of the input element
248 //! \return Pointer to the input element, or nullptr if not found
249 virtual DtVortexInterfaceBaseElement* getInputElement(const std::string& name);
250
251 //! \brief Gets an output element by name
252 //!
253 //! \param name Name of the output element
254 //! \return Pointer to the output element, or nullptr if not found
255 virtual DtVortexInterfaceBaseElement* getOutputElement(const std::string& name);
256
257 //! \brief Gets the interface name
258 //!
259 //! \return The name of the interface
260 virtual std::string getInterfaceName();
261
262protected:
263 //! \brief Creates ports based on the descriptor
264 //!
265 //! Creates input and output ports of appropriate types according to the descriptor.
266 //!
267 //! \param desc Descriptor containing interface configuration
269
270 VxSim::VxWeakInterface<VxSim::VxVHLInterface> myInterface; //!< Vortex interface
271 std::string myInterfaceName; //!< Interface name
272 DtInputPortGroup* myInputPortGroup; //!< Input port group
273 DtOutputPortGroup* myOutputPortGroup; //!< Output port group
274 std::vector<DtVortexInterfaceBaseElement*> myInputElements; //!< Vector of input elements
275 std::vector<DtVortexInterfaceBaseElement*> myOutputElements; //!< Vector of output elements
276};
Base class for Vortex interface elements.
Definition vortexInterface.h:48
virtual void update()=0
Updates the interface element.
virtual void setField(VxData::FieldBase *field)=0
Sets the Vortex field associated with this element.
virtual std::string portName()=0
Gets the port name.
DtVortexInterfaceBaseElement()
Default constructor.
Definition vortexInterface.h:51
virtual ~DtVortexInterfaceBaseElement()
Virtual destructor.
Definition vortexInterface.h:56
virtual std::string getFieldName()=0
Gets the field name.
virtual ~DtVortexInterfaceElement() override
Destructor.
VxData::FieldBase * myVortexField
Pointer to the Vortex field.
Definition vortexInterface.h:140
VxData::FieldBase * getField() const
Gets the Vortex field.
Definition vortexInterface.h:167
T * myPort
Pointer to the port.
Definition vortexInterface.h:139
virtual std::string getFieldName() override
Gets the field name.
Definition vortexInterface.h:149
std::string myPortName
Name of the port.
Definition vortexInterface.h:141
virtual std::string portName() override
Gets the port name.
Definition vortexInterface.h:158
virtual void setField(VxData::FieldBase *field) override
Sets the Vortex field.
Definition vortexInterface.h:176
virtual void update() override
Updates the interface element.
std::string myFieldName
Name of the field.
Definition vortexInterface.h:142
T * port()
Gets the port.
Definition vortexInterface.h:114
DtVortexInterfaceElement(std::string portName, const std::string &vortexName)
Constructor.
DtOutputPortGroup * myOutputPortGroup
Output port group.
Definition vortexInterface.h:273
std::string myInterfaceName
Interface name.
Definition vortexInterface.h:271
std::vector< DtVortexInterfaceBaseElement * > myOutputElements
Vector of output elements.
Definition vortexInterface.h:275
virtual DtInputPortGroup * inputPortGroup()
Gets the input port group.
virtual void connectPortsToInterface()
Connects ports to the Vortex interface.
virtual void setInterface(VxSim::VxWeakInterface< VxSim::VxVHLInterface > iface)
Sets the Vortex interface.
virtual ~DtVortexInterface()
Destructor.
virtual void createPorts(makVre::DtVortexInterfaceDescriptor *desc)
Creates ports based on the descriptor.
std::vector< DtVortexInterfaceBaseElement * > myInputElements
Vector of input elements.
Definition vortexInterface.h:274
DtInputPortGroup * myInputPortGroup
Input port group.
Definition vortexInterface.h:272
virtual std::string getInterfaceName()
Gets the interface name.
virtual DtVortexInterfaceBaseElement * getOutputElement(const std::string &name)
Gets an output element by name.
virtual void updateOutputs()
Updates all output elements.
DtVortexInterface(makVre::DtVortexInterfaceDescriptor *desc, const VxSim::VxWeakInterface< VxSim::VxVHLInterface > &iface=nullptr)
Constructor.
virtual DtVortexInterfaceBaseElement * getInputElement(const std::string &name)
Gets an input element by name.
virtual void updateOutputStateRepository(DtVrfObjectStateRepository *esr)
Updates the object state repository with output values.
VxSim::VxWeakInterface< VxSim::VxVHLInterface > myInterface
Vortex interface.
Definition vortexInterface.h:270
virtual DtOutputPortGroup * outputPortGroup()
Gets the output port group.
virtual void updateInputs()
Updates all input elements.
Descriptor for Vortex physics engine interfaces.
Definition vortexInterfaceDescriptor.h:27
Export macros for the VR-Forces Vortex extension library.
#define VREVRFVORTEX_DLL
Export macro for non-Windows platforms.
Definition export.h:30
Definition vortexConfiguration.h:24
Definition vortexConfiguration.h:29
Include export definitions for this library.
Definition glsVreMessageUtil.h:49