@@ -58,7 +58,8 @@ WireRestShape<DataTypes>::WireRestShape()
5858 , l_sectionMaterials(initLink(" wireMaterials" , " link to Wire Section Materials (to be ordered according to the instrument, from handle to tip)" ))
5959 , l_topology(initLink(" topology" , " link to the topology container" ))
6060{
61-
61+ d_density.setReadOnly (true ); // density is supposed to be filled using the section materials
62+ d_keyPoints.setReadOnly (true ); // key points are supposed to be filled using the section materials
6263}
6364
6465
@@ -70,16 +71,15 @@ void WireRestShape<DataTypes>::init()
7071 // ////////////////////////////////////////////
7172 // //////// get and fill local topology ///////
7273 // ////////////////////////////////////////////
73-
74- // Get pointer to given topology using the link. If not found will search in current context.
75- _topology = l_topology.get ();
7674
77- if (!_topology)
78- this ->getContext ()->get (_topology);
75+ if (!l_topology)
76+ {
77+ l_topology.set (this ->getContext ()->getMeshTopologyLink ());
78+ }
7979
80- if (_topology != nullptr )
80+ if (l_topology )
8181 {
82- msg_info () << " found topology named " << _topology ->getName () ;
82+ msg_info () << " Found topology named " << l_topology ->getName () ;
8383 }
8484 else
8585 {
@@ -94,6 +94,16 @@ void WireRestShape<DataTypes>::init()
9494 this ->d_componentState .setValue (sofa::core::objectmodel::ComponentState::Invalid);
9595 return ;
9696 }
97+
98+ // Workaround around the fact that d_density and d_keyPoints are supposed to be output only
99+ if (d_density.isSet ())
100+ {
101+ msg_warning () << " The density field will be ignored (output only Data)." ;
102+ }
103+ if (d_keyPoints.isSet ())
104+ {
105+ msg_warning () << " The keyPoints field will be ignored (output only Data)." ;
106+ }
97107
98108
99109 // //////////////////////////////////////////////////////
@@ -124,7 +134,7 @@ void WireRestShape<DataTypes>::initLengths()
124134 {
125135 auto rodSection = l_sectionMaterials.get (i);
126136 keyPointList[i+1 ] = keyPointList[i] + rodSection->getLength ();
127- densityList[i] = rodSection->getNbCollisionEdges ();
137+ densityList[i] = rodSection->getNbBeams ();
128138 }
129139}
130140
@@ -133,8 +143,8 @@ template <class DataTypes>
133143bool WireRestShape<DataTypes>::initTopology()
134144{
135145 // / fill topology :
136- _topology ->clear ();
137- _topology ->cleanup ();
146+ l_topology ->clear ();
147+ l_topology ->cleanup ();
138148
139149 const type::vector<Real>& keyPts = d_keyPoints.getValue ();
140150 if (l_sectionMaterials.size () != keyPts.size () - 1 )
@@ -155,12 +165,12 @@ bool WireRestShape<DataTypes>::initTopology()
155165
156166 // add points from the material
157167 for (int i = startPtId; i < nbrVisuEdges + 1 ; i++) {
158- _topology ->addPoint (prev_length + i * dx, 0 , 0 );
168+ l_topology ->addPoint (prev_length + i * dx, 0 , 0 );
159169 }
160170
161171 // add segments from the material
162172 for (int i = prev_edges; i < prev_edges + nbrVisuEdges; i++) {
163- _topology ->addEdge (i, i + 1 );
173+ l_topology ->addEdge (i, i + 1 );
164174 }
165175
166176 prev_length = length;
@@ -181,10 +191,51 @@ void WireRestShape<DataTypes>::getSamplingParameters(type::vector<Real>& xP_noti
181191}
182192
183193
194+ template <class DataTypes >
195+ void WireRestShape<DataTypes>::getMechanicalSampling(Real &dx, const Real x_curv)
196+ {
197+ unsigned int numLines = 0 ;
198+ Real x_used = x_curv - EPSILON;
199+
200+ const Real totalLength = this ->getLength ();
201+ x_used = std::clamp (x_used, 0.0 , totalLength);
202+
203+ const type::vector<Real>& keyPts = d_keyPoints.getValue ();
204+
205+ // verify that size of number of materials == size of keyPoints-1
206+ if (l_sectionMaterials.size () != keyPts.size () - 1 )
207+ {
208+ msg_error () << " Problem size of number of materials: " << l_sectionMaterials.size ()
209+ << " != size of keyPoints-1 " << keyPts.size ()-1
210+ << " . Returning default values." ;
211+ numLines = 20 ;
212+ dx = totalLength / numLines;
213+ return ;
214+ }
215+
216+ // Check in which section x_used belongs to and get access to this section material
217+ for (sofa::Size i = 1 ; i< keyPts.size (); ++i)
218+ {
219+ if (x_used <= keyPts[i])
220+ {
221+ numLines = l_sectionMaterials.get (i-1 )->getNbBeams ();
222+
223+ Real length = fabs (keyPts[i] - keyPts[i-1 ]);
224+ dx = length / numLines;
225+ return ;
226+ }
227+ }
228+
229+ // If x_used is out of bounds. Warn user and returns default value.
230+ numLines = 20 ;
231+ dx = totalLength / numLines;
232+ msg_error () << " problem in getMechanicalSampling : x_curv " << x_used << " is not between keyPoints" << d_keyPoints.getValue ();
233+ }
234+
184235template <class DataTypes >
185236void WireRestShape<DataTypes>::getCollisionSampling(Real &dx, const Real x_curv)
186237{
187- unsigned int numLines;
238+ unsigned int numLines = 0 ;
188239 Real x_used = x_curv - EPSILON;
189240
190241 const Real totalLength = this ->getLength ();
@@ -227,6 +278,17 @@ void WireRestShape<DataTypes>::getCollisionSampling(Real &dx, const Real x_curv)
227278 msg_error () << " problem in getCollisionSampling : x_curv " << x_used << " is not between keyPoints" << d_keyPoints.getValue ();
228279}
229280
281+ template <class DataTypes >
282+ void WireRestShape<DataTypes>::getNumberOfCollisionSegment(Real &dx, sofa::Size& numLines)
283+ {
284+ numLines = 0 ;
285+ for (sofa::Size i = 0 ; i < l_sectionMaterials.size (); ++i)
286+ {
287+ numLines += l_sectionMaterials.get (i)->getNbCollisionEdges ();
288+ }
289+ dx = getLength () / numLines;
290+ }
291+
230292
231293template <class DataTypes >
232294void WireRestShape<DataTypes>::getRestTransformOnX(Transform &global_H_local, const Real x)
@@ -319,19 +381,6 @@ typename WireRestShape<DataTypes>::Real WireRestShape<DataTypes>::getLength()
319381 return d_keyPoints.getValue ().back ();
320382}
321383
322-
323- template <class DataTypes >
324- void WireRestShape<DataTypes>::getNumberOfCollisionSegment(Real &dx, sofa::Size& numLines)
325- {
326- numLines = 0 ;
327- for (sofa::Size i = 0 ; i < l_sectionMaterials.size (); ++i)
328- {
329- numLines += l_sectionMaterials.get (i)->getNbCollisionEdges ();
330- }
331- dx = getLength () / numLines;
332- }
333-
334-
335384template <class DataTypes >
336385void WireRestShape<DataTypes>::computeOrientation(const Vec3& AB, const Quat& Q, Quat &result)
337386{
0 commit comments