Skip to content

Commit b0886d2

Browse files
fredroyth-skambakpaul
authored
[all] Matrix: replace all calls to [i][j] with a single call (i,j) (#5650)
* replace in animation loop * replace in collision * replace in constraint * debug: add assertion ;; replace in type * replace in helper * replace in linearalgebra * replace in defaulttype * replace in core * compile AnimationLoop * compile Mapping * compile LinearSolver * compile FEM.HyperE * compile FEM.Elastic * compile FEM.NonUni * compile Spring * compile MechaLoad * compile Engine * compile Collision * compile MT * compile full Mat * compile gl * restore operator [] * restore [] for lines * Update Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMappers/BarycentricMapperMeshTopology.inl Co-authored-by: Themis Skamagkis <70031729+th-skam@users.noreply.github.com> * fix typo (from copy paste...) * forgotten case * fix tests compilation * fix bad copy paste Co-authored-by: Paul Baksic <30337881+bakpaul@users.noreply.github.com> --------- Co-authored-by: Themis Skamagkis <70031729+th-skam@users.noreply.github.com> Co-authored-by: Paul Baksic <30337881+bakpaul@users.noreply.github.com>
1 parent 034d3d7 commit b0886d2

File tree

111 files changed

+2703
-2686
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+2703
-2686
lines changed

Sofa/Component/AnimationLoop/src/sofa/component/animationloop/ConstraintAnimationLoop.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void ConstraintProblem::gaussSeidelConstraintTimed(SReal &timeout, int numItMax)
164164
// (b) contribution of forces are added to d
165165
for(int k=0; k<_dim; k++)
166166
for(int l=0; l<nb; l++)
167-
_d[j+l] += _W[j+l][k] * _force[k];
167+
_d[j+l] += _W(j+l,k) * _force[k];
168168

169169

170170

@@ -181,14 +181,14 @@ void ConstraintProblem::gaussSeidelConstraintTimed(SReal &timeout, int numItMax)
181181
SReal terr2 = 0;
182182
for (int m=0; m<nb; m++)
183183
{
184-
terr2 += _W[j+l][j+m] * (_force[j+m] - errF[m]);
184+
terr2 += _W(j+l,j+m) * (_force[j+m] - errF[m]);
185185
}
186186
terr += terr2 * terr2;
187187
}
188188
error += sqrt(terr);
189189
}
190190
else
191-
error += fabs(_W[j][j] * (_force[j] - errF[0]));
191+
error += fabs(_W(j,j) * (_force[j] - errF[0]));
192192

193193
j += nb;
194194
}

Sofa/Component/Collision/Detection/Intersection/src/sofa/component/collision/detection/intersection/LocalMinDistance.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ bool LocalMinDistance::testIntersection(Line& e1, Line& e2, const core::collisio
117117
MatNoInit<2, 2, Line::Coord::value_type> A;
118118
VecNoInit<2, Line::Coord::value_type> b;
119119

120-
A[0][0] = AB*AB;
121-
A[1][1] = CD*CD;
122-
A[0][1] = A[1][0] = -CD*AB;
120+
A(0,0) = AB*AB;
121+
A(1,1) = CD*CD;
122+
A(0,1) = A(1,0) = -CD*AB;
123123
b[0] = AB*AC;
124124
b[1] = -CD*AC;
125125

@@ -130,8 +130,8 @@ bool LocalMinDistance::testIntersection(Line& e1, Line& e2, const core::collisio
130130

131131
if (det < -1.0e-30 || det > 1.0e-30)
132132
{
133-
alpha = (b[0]*A[1][1] - b[1]*A[0][1])/det;
134-
beta = (b[1]*A[0][0] - b[0]*A[1][0])/det;
133+
alpha = (b[0]*A(1,1) - b[1]*A(0,1))/det;
134+
beta = (b[1]*A(0,0) - b[0]*A(1,0))/det;
135135
if (alpha < 1e-15 || alpha > (1.0-1e-15) ||
136136
beta < 1e-15 || beta > (1.0-1e-15) )
137137
return false;
@@ -178,9 +178,9 @@ int LocalMinDistance::computeIntersection(Line& e1, Line& e2, OutputVector* cont
178178
Matrix2 A;
179179
Vec2 b;
180180

181-
A[0][0] = AB*AB;
182-
A[1][1] = CD*CD;
183-
A[0][1] = A[1][0] = -CD*AB;
181+
A(0,0) = AB*AB;
182+
A(1,1) = CD*CD;
183+
A(0,1) = A(1,0) = -CD*AB;
184184
b[0] = AB*AC;
185185
b[1] = -CD*AC;
186186
const double det = type::determinant(A);
@@ -192,8 +192,8 @@ int LocalMinDistance::computeIntersection(Line& e1, Line& e2, OutputVector* cont
192192
if (det < -1.0e-30 || det > 1.0e-30)
193193
{
194194
// compute the parametric coordinates along the line
195-
alpha = (b[0]*A[1][1] - b[1]*A[0][1])/det;
196-
beta = (b[1]*A[0][0] - b[0]*A[1][0])/det;
195+
alpha = (b[0]*A(1,1) - b[1]*A(0,1))/det;
196+
beta = (b[1]*A(0,0) - b[0]*A(1,0))/det;
197197

198198
// if parameters are outside of ]0,1[ then there is no intersection
199199
// the intersection is outside of the edge supporting point.
@@ -299,9 +299,9 @@ bool LocalMinDistance::testIntersection(Triangle& e2, Point& e1, const core::col
299299
// AB.AC*alpha + AC.AC*beta = AP.AC
300300
//
301301
// A . [alpha beta] = b
302-
A[0][0] = AB*AB;
303-
A[1][1] = AC*AC;
304-
A[0][1] = A[1][0] = AB*AC;
302+
A(0,0) = AB*AB;
303+
A(1,1) = AC*AC;
304+
A(0,1) = A(1,0) = AB*AC;
305305
b[0] = AP*AB;
306306
b[1] = AP*AC;
307307
const double det = type::determinant(A);
@@ -310,8 +310,8 @@ bool LocalMinDistance::testIntersection(Triangle& e2, Point& e1, const core::col
310310
double beta = 0.5;
311311

312312

313-
alpha = (b[0]*A[1][1] - b[1]*A[0][1])/det;
314-
beta = (b[1]*A[0][0] - b[0]*A[1][0])/det;
313+
alpha = (b[0]*A(1,1) - b[1]*A(0,1))/det;
314+
beta = (b[1]*A(0,0) - b[0]*A(1,0))/det;
315315
if (alpha < 0.000001 ||
316316
beta < 0.000001 ||
317317
alpha + beta > 0.999999)
@@ -356,16 +356,16 @@ int LocalMinDistance::computeIntersection(Triangle& e2, Point& e1, OutputVector*
356356
MatNoInit<2, 2, Real> A;
357357
VecNoInit<2, Real> b;
358358

359-
A[0][0] = AB*AB;
360-
A[1][1] = AC*AC;
361-
A[0][1] = A[1][0] = AB*AC;
359+
A(0,0) = AB*AB;
360+
A(1,1) = AC*AC;
361+
A(0,1) = A(1,0) = AB*AC;
362362
b[0] = AP*AB;
363363
b[1] = AP*AC;
364364

365365
const Real det = type::determinant(A);
366366

367-
const Real alpha=(b[0]*A[1][1]-b[1]*A[0][1])/det;
368-
const Real beta=(b[1]*A[0][0]-b[0]*A[1][0])/det;
367+
const Real alpha=(b[0]*A(1,1)-b[1]*A(0,1))/det;
368+
const Real beta=(b[1]*A(0,0)-b[0]*A(1,0))/det;
369369

370370
if (alpha < 0.000001 ||
371371
beta < 0.000001 ||
@@ -454,15 +454,15 @@ bool LocalMinDistance::testIntersection(Triangle& e2, Sphere& e1, const core::co
454454
// AB.AC*alpha + AC.AC*beta = AP.AC
455455
//
456456
// A . [alpha beta] = b
457-
A[0][0] = AB*AB;
458-
A[1][1] = AC*AC;
459-
A[0][1] = A[1][0] = AB*AC;
457+
A(0,0) = AB*AB;
458+
A(1,1) = AC*AC;
459+
A(0,1) = A(1,0) = AB*AC;
460460
b[0] = AP*AB;
461461
b[1] = AP*AC;
462462
const Real det = type::determinant(A);
463463

464-
const Real alpha=(b[0]*A[1][1]-b[1]*A[0][1])/det;
465-
const Real beta=(b[1]*A[0][0]-b[0]*A[1][0])/det;
464+
const Real alpha=(b[0]*A(1,1)-b[1]*A(0,1))/det;
465+
const Real beta=(b[1]*A(0,0)-b[0]*A(1,0))/det;
466466
if (alpha < 0.000001 ||
467467
beta < 0.000001 ||
468468
alpha + beta > 0.999999)
@@ -511,16 +511,16 @@ int LocalMinDistance::computeIntersection(Triangle& e2, Sphere& e1, OutputVector
511511
MatNoInit<2, 2, Real> A;
512512
VecNoInit<2, Real> b;
513513

514-
A[0][0] = AB*AB;
515-
A[1][1] = AC*AC;
516-
A[0][1] = A[1][0] = AB*AC;
514+
A(0,0) = AB*AB;
515+
A(1,1) = AC*AC;
516+
A(0,1) = A(1,0) = AB*AC;
517517
b[0] = AP*AB;
518518
b[1] = AP*AC;
519519

520520
const Real det = type::determinant(A);
521521

522-
const Real alpha=(b[0]*A[1][1]-b[1]*A[0][1])/det;
523-
const Real beta=(b[1]*A[0][0]-b[0]*A[1][0])/det;
522+
const Real alpha=(b[0]*A(1,1)-b[1]*A(0,1))/det;
523+
const Real beta=(b[1]*A(0,0)-b[0]*A(1,0))/det;
524524
if (alpha < 0.000001 ||
525525
beta < 0.000001 ||
526526
alpha + beta > 0.999999)

Sofa/Component/Collision/Detection/Intersection/src/sofa/component/collision/detection/intersection/MeshDiscreteIntersection.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ int MeshDiscreteIntersection::computeIntersection(Triangle& e1, Line& e2, Output
6464
Triangle::Coord right(NOINIT);
6565
for (int i=0; i<3; i++)
6666
{
67-
M[i][0] = AB[i];
68-
M[i][1] = AC[i];
69-
M[i][2] = -PQ[i];
67+
M(i,0) = AB[i];
68+
M(i,1) = AC[i];
69+
M(i,2) = -PQ[i];
7070
right[i] = P[i]-A[i];
7171
}
7272
if (!Minv.invert(M))

Sofa/Component/Collision/Detection/Intersection/src/sofa/component/collision/detection/intersection/MeshMinProximityIntersection.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ bool MeshMinProximityIntersection::testIntersection(Line& e1, Line& e2, const co
100100
MatNoInit<2, 2, Real> A;
101101
VecNoInit<2, Real> b;
102102

103-
A[0][0] = AB * AB;
104-
A[1][1] = CD * CD;
105-
A[0][1] = A[1][0] = -CD*AB;
103+
A(0,0) = AB * AB;
104+
A(1,1) = CD * CD;
105+
A(0,1) = A(1,0) = -CD*AB;
106106
b[0] = AB*AC;
107107
b[1] = -CD*AC;
108108

@@ -113,8 +113,8 @@ bool MeshMinProximityIntersection::testIntersection(Line& e1, Line& e2, const co
113113

114114
if (det < -1.0e-18 || det > 1.0e-18)
115115
{
116-
alpha = (b[0]*A[1][1] - b[1]*A[0][1])/det;
117-
beta = (b[1]*A[0][0] - b[0]*A[1][0])/det;
116+
alpha = (b[0]*A(1,1) - b[1]*A(0,1))/det;
117+
beta = (b[1]*A(0,0) - b[0]*A(1,0))/det;
118118
if (alpha < 0.000001 || alpha > 0.999999 ||
119119
beta < 0.000001 || beta > 0.999999 )
120120
return false;
@@ -143,9 +143,9 @@ int MeshMinProximityIntersection::computeIntersection(Line& e1, Line& e2, Output
143143
MatNoInit<2, 2, Real> A;
144144
VecNoInit<2, Real> b;
145145

146-
A[0][0] = AB*AB;
147-
A[1][1] = CD*CD;
148-
A[0][1] = A[1][0] = -CD*AB;
146+
A(0,0) = AB*AB;
147+
A(1,1) = CD*CD;
148+
A(0,1) = A(1,0) = -CD*AB;
149149
b[0] = AB*AC;
150150
b[1] = -CD*AC;
151151
const Real det = type::determinant(A);
@@ -155,8 +155,8 @@ int MeshMinProximityIntersection::computeIntersection(Line& e1, Line& e2, Output
155155

156156
if (det < -1.0e-15 || det > 1.0e-15)
157157
{
158-
alpha = (b[0]*A[1][1] - b[1]*A[0][1])/det;
159-
beta = (b[1]*A[0][0] - b[0]*A[1][0])/det;
158+
alpha = (b[0]*A(1,1) - b[1]*A(0,1))/det;
159+
beta = (b[1]*A(0,0) - b[0]*A(1,0))/det;
160160
if (alpha < 0.000001 || alpha > 0.999999 ||
161161
beta < 0.000001 || beta > 0.999999 )
162162
return 0;
@@ -243,15 +243,15 @@ bool MeshMinProximityIntersection::testIntersection(Triangle& e2, Point& e1, con
243243
// AB.AC*alpha + AC.AC*beta = AP.AC
244244
//
245245
// A . [alpha beta] = b
246-
A[0][0] = AB*AB;
247-
A[1][1] = AC*AC;
248-
A[0][1] = A[1][0] = AB*AC;
246+
A(0,0) = AB*AB;
247+
A(1,1) = AC*AC;
248+
A(0,1) = A(1,0) = AB*AC;
249249
b[0] = AP*AB;
250250
b[1] = AP*AC;
251251
const Real det = type::determinant(A);
252252

253-
const Real alpha=(b[0]*A[1][1]-b[1]*A[0][1])/det;
254-
const Real beta=(b[1]*A[0][0]-b[0]*A[1][0])/det;
253+
const Real alpha=(b[0]*A(1,1)-b[1]*A(0,1))/det;
254+
const Real beta=(b[1]*A(0,0)-b[0]*A(1,0))/det;
255255
if (alpha < 0.000001 ||
256256
beta < 0.000001 ||
257257
alpha + beta > 0.999999)
@@ -287,16 +287,16 @@ int MeshMinProximityIntersection::computeIntersection(Triangle& e2, Point& e1, O
287287
MatNoInit<2, 2, Real> A;
288288
VecNoInit<2, Real> b;
289289

290-
A[0][0] = AB*AB;
291-
A[1][1] = AC*AC;
292-
A[0][1] = A[1][0] = AB*AC;
290+
A(0,0) = AB*AB;
291+
A(1,1) = AC*AC;
292+
A(0,1) = A(1,0) = AB*AC;
293293
b[0] = AP*AB;
294294
b[1] = AP*AC;
295295

296296
const Real det = type::determinant(A);
297297

298-
const Real alpha=(b[0]*A[1][1]-b[1]*A[0][1])/det;
299-
const Real beta=(b[1]*A[0][0]-b[0]*A[1][0])/det;
298+
const Real alpha=(b[0]*A(1,1)-b[1]*A(0,1))/det;
299+
const Real beta=(b[1]*A(0,0)-b[0]*A(1,0))/det;
300300
if (alpha < 0.000001 ||
301301
beta < 0.000001 ||
302302
alpha + beta > 0.999999)

Sofa/Component/Collision/Detection/Intersection/src/sofa/component/collision/detection/intersection/MeshMinProximityIntersection.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ bool MeshMinProximityIntersection::testIntersection(collision::geometry::Triangl
7070
const type::Vec3 x03 = e2.p1()-e1.center();
7171
type::Matrix2 A;
7272
type::Vec2 b;
73-
A[0][0] = x13*x13;
74-
A[1][1] = x23*x23;
75-
A[0][1] = A[1][0] = x13*x23;
73+
A(0,0) = x13*x13;
74+
A(1,1) = x23*x23;
75+
A(0,1) = A(1,0) = x13*x23;
7676
b[0] = x13*x03;
7777
b[1] = x23*x03;
7878
const SReal det = type::determinant(A);
@@ -82,8 +82,8 @@ bool MeshMinProximityIntersection::testIntersection(collision::geometry::Triangl
8282

8383
//if (det < -0.000001 || det > 0.000001)
8484
{
85-
alpha = (b[0]*A[1][1] - b[1]*A[0][1])/det;
86-
beta = (b[1]*A[0][0] - b[0]*A[1][0])/det;
85+
alpha = (b[0]*A(1,1) - b[1]*A(0,1))/det;
86+
beta = (b[1]*A(0,0) - b[0]*A(1,0))/det;
8787
if (alpha < 0.000001 ||
8888
beta < 0.000001 ||
8989
alpha + beta > 0.999999)
@@ -113,9 +113,9 @@ int MeshMinProximityIntersection::computeIntersection(collision::geometry::Trian
113113
const type::Vec3 x03 = e2.p1()-e1.center();
114114
type::Matrix2 A;
115115
type::Vec2 b;
116-
A[0][0] = x13*x13;
117-
A[1][1] = x23*x23;
118-
A[0][1] = A[1][0] = x13*x23;
116+
A(0,0) = x13*x13;
117+
A(1,1) = x23*x23;
118+
A(0,1) = A(1,0) = x13*x23;
119119
b[0] = x13*x03;
120120
b[1] = x23*x03;
121121
const SReal det = type::determinant(A);
@@ -125,8 +125,8 @@ int MeshMinProximityIntersection::computeIntersection(collision::geometry::Trian
125125

126126
//if (det < -0.000001 || det > 0.000001)
127127
{
128-
alpha = (b[0]*A[1][1] - b[1]*A[0][1])/det;
129-
beta = (b[1]*A[0][0] - b[0]*A[1][0])/det;
128+
alpha = (b[0]*A(1,1) - b[1]*A(0,1))/det;
129+
beta = (b[1]*A(0,0) - b[0]*A(1,0))/det;
130130
if (alpha < 0.000001 ||
131131
beta < 0.000001 ||
132132
alpha + beta > 0.999999)

0 commit comments

Comments
 (0)