Marine systems simulation
CCrowfootMath.h
1#ifndef C_CROWFOOT_MATH_H
2#define C_CROWFOOT_MATH_H
3
26#include <Eigen/Dense>
27#include <vector>
28#ifdef FH_VISUALIZATION
29#pragma warning(push)
30#pragma warning( disable : 4251)
31#include <Ogre.h>
32#pragma warning(pop)
33# include "cable/subroutines/CInternalCable.h"
34#endif
35
36//#define CROWFOOTMATH_DEBUG_RENDERING
37
39{
40public:
41
43 struct LineDef
44 {
45 Eigen::Vector3d fasteningPos;
46 double length;
47 };
48
49 struct VisualSpec{
50 int numFaces;
51 int numElements;
52 double drawDiameter;
53 std::string materialName;
54 VisualSpec(){
55 numFaces = 5;
56 numElements = 1;
57 drawDiameter = 0.1;
58 materialName = "Trawl/SteelWire";
59 }
60
61 };
62
64 //CCrowfootMath(double m_maxLineForce = 1.0e7);
65
67 CCrowfootMath(double maxLineForce = 1.0e7, const VisualSpec& visualSpec = VisualSpec());
68
79 int AddLine(double length, const double * const fasteningpos);
80
88 void Update(const double * const F, double * const posOut);
89
99 void CalcIterativePos(const double * const F, double * const posOut, int maxNumIter = 500, double expectedLengthToGo = 3.0,
100 double tolerance = 0.00001);
101
108 void GetLineForce(double* F, int lineIndex);
109
115 double GetLineTension(int lineIndex);
116
123 void UpdateLineLength(double length, int lineIndex);
124
131 void UpdateLineFasteningPos(const double * const fasteningpos, int lineIndex);
132
136 int NumLines();
137
138
139#ifdef FH_VISUALIZATION
140 // Initial specification of the simObject geometry for rendering.
141 virtual void RenderInit(Ogre::Root* const pOgreRoot, Ogre::SceneManager* m_pSceneMgr, std::string m_SimObjectName);
142
143 // Updating the simObject for rendering the next frame.
144 virtual void RenderUpdate(std::vector<const double*>& aadPos, const double adPosCollectingPoint[3]);
145#endif
146
147protected:
149 void CalcForOneLine(const Eigen::Vector3d& Force, const Eigen::Vector3d& ForceDir, double * const posOut);
150
152 void CalcForTwoLines(const Eigen::Vector3d& Force, const Eigen::Vector3d& ForceDir, double * const posOut);
153
155 void CalcForThreeLines(const Eigen::Vector3d&, const Eigen::Vector3d& ForceDir, double * const posOut);
156
158 Eigen::Vector3d CalcPosForOneStretched(int index, const Eigen::Vector3d& ForceDir);
159
161 Eigen::Vector3d CalcPosForTwoStretched( int index1, int index2, const Eigen::Vector3d &ForceDir);
162
164 void CalcForOneActive(int index, const Eigen::Vector3d&, const Eigen::Vector3d& pos,double * const posOut);
165
167 void CalcForTwoActive(int index1, int index2, const Eigen::Vector3d& Force, Eigen::Vector3d pos, double * const posOut);
168
170 void SetPosition( double * const posOut, const Eigen::Vector3d &pos );
171
173 bool EnsureLineIndexOk(int lineIndex);
174
176 bool PointIsWithinLineReach(int index, const Eigen::Vector3d& connPos);
177
178 std::vector<LineDef> m_lines;
179 std::vector<Eigen::Vector3d> m_lineForces;
180 //Eigen::Vector3d m_lineTensions;
181 double m_maxLineForce;
182 VisualSpec m_visualSpec;
183
184 // DEBUGGING
185# ifdef CROWFOOTMATH_DEBUG_RENDERING
186 Eigen::Vector3f DEBUG_poss0;
187 Eigen::Vector3f DEBUG_poss1;
188 Eigen::Vector3f DEBUG_ForceDir;
189# endif
190
191# ifdef FH_VISUALIZATION
192 std::vector<SCableRenderSpec*> m_RenderSpecs;
193 std::vector<Ogre::ManualObject*> m_RenderObjects;
194 double m_dDrawDiam;
195 Ogre::SceneNode* m_lineSceneNode;
196
197 // DEBUGGING
198# ifdef CROWFOOTMATH_DEBUG_RENDERING
199 Ogre::Entity* m_pRenderSphere[2];
200 Ogre::SceneNode* m_pRenderNodeSphere[2];
201 CDynamicLines* m_pLines;
202 Ogre::SceneNode* m_debugLineSceneNode;
203# endif
204# endif
205};
206
207
208#endif
Definition: CCrowfootMath.h:39
void SetPosition(double *const posOut, const Eigen::Vector3d &pos)
Sets the position of the output array.
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 Update(const double *const F, double *const posOut)
Calculates the position of the collecting point and the forces in each attached line....
bool PointIsWithinLineReach(int index, const Eigen::Vector3d &connPos)
Tests if a position is within the reach of a specified line.
bool EnsureLineIndexOk(int lineIndex)
Checks if a line index is ok. Prints a warning if not.
CCrowfootMath(double maxLineForce=1.0e7, const VisualSpec &visualSpec=VisualSpec())
The default constructor does nothing.
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...
int NumLines()
Gets the number of lines attached to the collecting point.
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 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...
double GetLineTension(int lineIndex)
Gets the tension in the given line. The line index should be that returned from the AddLine method.
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 UpdateLineLength(double length, int lineIndex)
Updates the length of a given line. The line index should be that returned from the AddLine method.
Eigen::Vector3d CalcPosForTwoStretched(int index1, int index2, const Eigen::Vector3d &ForceDir)
Calculates the collecting position if only two lines are stretched.
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.
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.
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.
Defines a line connected between the collecting point of the crowfoot and a fastening position.
Definition: CCrowfootMath.h:44
Definition: CCrowfootMath.h:49