FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
CrowfootMath.h
1#pragma once
2
25#include <Eigen/Dense>
26#include <string>
27
28#include <vector>
29#ifdef FH_VISUALIZATION
30# pragma warning(push)
31# pragma warning(disable : 4251)
32# include <Ogre.h>
33# pragma warning(pop)
34# include "cable/subroutines/InternalCable.h"
35#endif
36
37// #define CROWFOOTMATH_DEBUG_RENDERING
38
40{
41public:
43 struct LineDef
44 {
45 Eigen::Vector3d fasteningPos;
46 double length;
47 };
48
50 {
51 int numFaces;
52 int numElements;
53 double drawDiameter;
54 std::string materialName;
56 {
57 numFaces = 5;
58 numElements = 1;
59 drawDiameter = 0.1;
60 materialName = "Trawl/SteelWire";
61 }
62 };
63
65 // CrowfootMath(double m_maxLineForce = 1.0e7);
66
68 CrowfootMath(double maxLineForce = 1.0e7, const VisualSpec& visualSpec = VisualSpec());
69
80 int AddLine(double length, const double* const fasteningpos);
81
89 void Update(const double* const F, double* const posOut);
90
100 void CalcIterativePos(const double* const F, double* const posOut, int maxNumIter = 500, double expectedLengthToGo = 3.0,
101 double tolerance = 0.00001);
102
109 void GetLineForce(double* F, int lineIndex);
110
116 double GetLineTension(int lineIndex);
117
124 void UpdateLineLength(double length, int lineIndex);
125
132 void UpdateLineFasteningPos(const double* const fasteningpos, int lineIndex);
133
137 int NumLines();
138
139
140#ifdef FH_VISUALIZATION
141 // Initial specification of the simObject geometry for rendering.
142 virtual void RenderInit(Ogre::Root* const ogreRoot, Ogre::SceneManager* m_sceneMgr, std::string m_simObjectName);
143
144 // Updating the simObject for rendering the next frame.
145 virtual void RenderUpdate(std::vector<const double*>& aadPos, const double adPosCollectingPoint[3]);
146#endif
147
148protected:
150 void CalcForOneLine(const Eigen::Vector3d& Force, const Eigen::Vector3d& ForceDir, double* const posOut);
151
153 void CalcForTwoLines(const Eigen::Vector3d& Force, const Eigen::Vector3d& ForceDir, double* const posOut);
154
156 void CalcForThreeLines(const Eigen::Vector3d&, const Eigen::Vector3d& ForceDir, double* const posOut);
157
159 Eigen::Vector3d CalcPosForOneStretched(int index, const Eigen::Vector3d& ForceDir);
160
162 Eigen::Vector3d CalcPosForTwoStretched(int index1, int index2, const Eigen::Vector3d& ForceDir);
163
165 void CalcForOneActive(int index, const Eigen::Vector3d&, const Eigen::Vector3d& pos, double* const posOut);
166
168 void CalcForTwoActive(int index1, int index2, const Eigen::Vector3d& Force, Eigen::Vector3d pos, double* const posOut);
169
171 void SetPosition(double* const posOut, const Eigen::Vector3d& pos);
172
174 bool EnsureLineIndexOk(int lineIndex);
175
177 bool PointIsWithinLineReach(int index, const Eigen::Vector3d& connPos);
178
179 std::vector<LineDef> m_lines;
180 std::vector<Eigen::Vector3d> m_lineForces;
181 // Eigen::Vector3d m_lineTensions;
182 double m_maxLineForce;
183 VisualSpec m_visualSpec;
184
185 // DEBUGGING
186#ifdef CROWFOOTMATH_DEBUG_RENDERING
187 Eigen::Vector3f DEBUG_poss0;
188 Eigen::Vector3f DEBUG_poss1;
189 Eigen::Vector3f DEBUG_ForceDir;
190#endif
191
192#ifdef FH_VISUALIZATION
193 std::vector<SCableRenderSpec*> m_RenderSpecs;
194 std::vector<Ogre::ManualObject*> m_RenderObjects;
195 double m_drawDiam;
196 Ogre::SceneNode* m_lineSceneNode;
197
198 // DEBUGGING
199# ifdef CROWFOOTMATH_DEBUG_RENDERING
200 Ogre::Entity* m_renderSphere[2];
201 Ogre::SceneNode* m_renderNodeSphere[2];
202 CDynamicLines* m_lines;
203 Ogre::SceneNode* m_debugLineSceneNode;
204# endif
205#endif
206};
Definition CrowfootMath.h:40
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:44
Definition CrowfootMath.h:50