FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
CrowfootMath.h
1#pragma once
2
25#include <Eigen/Dense>
26#include <memory>
27#include <string>
28
29#include <vector>
30#ifdef FH_VISUALIZATION
31# pragma warning(push)
32# pragma warning(disable : 4251)
33# include <Ogre.h>
34# pragma warning(pop)
35# include "cable/subroutines/InternalCable.h"
36#endif
37
38// #define CROWFOOTMATH_DEBUG_RENDERING
39
41{
42public:
44 struct LineDef
45 {
46 Eigen::Vector3d fasteningPos;
47 double length;
48 };
49
51 {
52 int numFaces;
53 int numElements;
54 double drawDiameter;
55 std::string materialName;
57 {
58 numFaces = 5;
59 numElements = 1;
60 drawDiameter = 0.1;
61 materialName = "Trawl/SteelWire";
62 }
63 };
64
66 // CrowfootMath(double m_maxLineForce = 1.0e7);
67
69 CrowfootMath(double maxLineForce = 1.0e7, const VisualSpec& visualSpec = VisualSpec());
70
81 int AddLine(double length, const double* const fasteningpos);
82
90 void Update(const double* const F, double* const posOut);
91
101 void CalcIterativePos(const double* const F, double* const posOut, int maxNumIter = 500, double expectedLengthToGo = 3.0,
102 double tolerance = 0.00001);
103
110 void GetLineForce(double* F, int lineIndex);
111
117 double GetLineTension(int lineIndex);
118
125 void UpdateLineLength(double length, int lineIndex);
126
133 void UpdateLineFasteningPos(const double* const fasteningpos, int lineIndex);
134
138 int NumLines();
139
140
141#ifdef FH_VISUALIZATION
142 // Initial specification of the simObject geometry for rendering.
143 virtual void RenderInit(Ogre::Root* const ogreRoot, Ogre::SceneManager* m_sceneMgr, std::string m_simObjectName);
144
145 // Updating the simObject for rendering the next frame.
146 virtual void RenderUpdate(std::vector<const double*>& aadPos, const double adPosCollectingPoint[3]);
147#endif
148
149protected:
151 void CalcForOneLine(const Eigen::Vector3d& Force, const Eigen::Vector3d& ForceDir, double* const posOut);
152
154 void CalcForTwoLines(const Eigen::Vector3d& Force, const Eigen::Vector3d& ForceDir, double* const posOut);
155
157 void CalcForThreeLines(const Eigen::Vector3d&, const Eigen::Vector3d& ForceDir, double* const posOut);
158
160 Eigen::Vector3d CalcPosForOneStretched(int index, const Eigen::Vector3d& ForceDir);
161
163 Eigen::Vector3d CalcPosForTwoStretched(int index1, int index2, const Eigen::Vector3d& ForceDir);
164
166 void CalcForOneActive(int index, const Eigen::Vector3d&, const Eigen::Vector3d& pos, double* const posOut);
167
169 void CalcForTwoActive(int index1, int index2, const Eigen::Vector3d& Force, Eigen::Vector3d pos, double* const posOut);
170
172 void SetPosition(double* const posOut, const Eigen::Vector3d& pos);
173
175 bool EnsureLineIndexOk(int lineIndex);
176
178 bool PointIsWithinLineReach(int index, const Eigen::Vector3d& connPos);
179
180 std::vector<LineDef> m_lines;
181 std::vector<Eigen::Vector3d> m_lineForces;
182 // Eigen::Vector3d m_lineTensions;
183 double m_maxLineForce;
184 VisualSpec m_visualSpec;
185
186 // DEBUGGING
187#ifdef CROWFOOTMATH_DEBUG_RENDERING
188 Eigen::Vector3f DEBUG_poss0;
189 Eigen::Vector3f DEBUG_poss1;
190 Eigen::Vector3f DEBUG_ForceDir;
191#endif
192
193#ifdef FH_VISUALIZATION
194 std::vector<std::unique_ptr<SCableRenderSpec>> m_RenderSpecs;
195 std::vector<Ogre::ManualObject*> m_RenderObjects;
196 double m_drawDiam;
197 Ogre::SceneNode* m_lineSceneNode;
198
199 // DEBUGGING
200# ifdef CROWFOOTMATH_DEBUG_RENDERING
201 Ogre::Entity* m_renderSphere[2];
202 Ogre::SceneNode* m_renderNodeSphere[2];
203 CDynamicLines* m_lines;
204 Ogre::SceneNode* m_debugLineSceneNode;
205# endif
206#endif
207};
Definition CrowfootMath.h:41
bool PointIsWithinLineReach(int index, const Eigen::Vector3d &connPos)
Tests if a position is within the reach of a specified line.
void UpdateLineFasteningPos(const double *const fasteningpos, int lineIndex)
Updates the "other" end position of a given line. The line index should be that returned from the Add...
void CalcForTwoActive(int index1, int index2, const Eigen::Vector3d &Force, Eigen::Vector3d pos, double *const posOut)
Calculates the collecting position and line force if only two lines are stretched.
void CalcForOneLine(const Eigen::Vector3d &Force, const Eigen::Vector3d &ForceDir, double *const posOut)
Calculates the collecting position and line force if the system is comprised of one line.
Eigen::Vector3d CalcPosForOneStretched(int index, const Eigen::Vector3d &ForceDir)
Calculates the collecting position if only one line is stretched.
bool EnsureLineIndexOk(int lineIndex)
Checks if a line index is ok. Prints a warning if not.
void CalcForThreeLines(const Eigen::Vector3d &, const Eigen::Vector3d &ForceDir, double *const posOut)
Calculates the collecting position and line forces if the system is comprised of three lines.
void CalcForTwoLines(const Eigen::Vector3d &Force, const Eigen::Vector3d &ForceDir, double *const posOut)
Calculates the collecting position and line forces if the system is comprised of two lines.
void UpdateLineLength(double length, int lineIndex)
Updates the length of a given line. The line index should be that returned from the AddLine method.
void Update(const double *const F, double *const posOut)
Calculates the position of the collecting point and the forces in each attached line....
void GetLineForce(double *F, int lineIndex)
Gets the force on the fastening point for a given line. The line index should be that returned from t...
void CalcIterativePos(const double *const F, double *const posOut, int maxNumIter=500, double expectedLengthToGo=3.0, double tolerance=0.00001)
Calculates the position of the collecting point using an iterative method This method is for test pur...
void CalcForOneActive(int index, const Eigen::Vector3d &, const Eigen::Vector3d &pos, double *const posOut)
Calculates the collecting position and line force if only one line is stretched.
Eigen::Vector3d CalcPosForTwoStretched(int index1, int index2, const Eigen::Vector3d &ForceDir)
Calculates the collecting position if only two lines are stretched.
int AddLine(double length, const double *const fasteningpos)
Adds a line to the collecting point. A line is added to the collecting point, the position of the oth...
double GetLineTension(int lineIndex)
Gets the tension in the given line. The line index should be that returned from the AddLine method.
int NumLines()
Gets the number of lines attached to the collecting point.
void SetPosition(double *const posOut, const Eigen::Vector3d &pos)
Sets the position of the output array.
CrowfootMath(double maxLineForce=1.0e7, const VisualSpec &visualSpec=VisualSpec())
The default constructor does nothing.
Defines a line connected between the collecting point of the crowfoot and a fastening position.
Definition CrowfootMath.h:45
Definition CrowfootMath.h:51