Skip to content

Commit 4057a76

Browse files
[Type] BoundingBox: Phase out TBoundingBox<Real> (#5676)
* add deprecated attribute for TBoundingBox * rewrite computeBBox where TBoundingBox was used * use dedicated macros * fix compilation with sofacuda (and typo) --------- Co-authored-by: Damien Marchal <damien.marchal@univ-lille1.fr>
1 parent ac24598 commit 4057a76

File tree

24 files changed

+118
-260
lines changed

24 files changed

+118
-260
lines changed

Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/LineModel.inl

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -568,30 +568,20 @@ void LineCollisionModel<DataTypes>::computeBBox(const core::ExecParams* params,
568568
if( onlyVisible && !sofa::core::visual::VisualParams::defaultInstance()->displayFlags().getShowCollisionModels())
569569
return;
570570

571-
static constexpr Real max_real = std::numeric_limits<Real>::max();
572-
static constexpr Real min_real = std::numeric_limits<Real>::lowest();
573-
Real maxBBox[3] = {min_real,min_real,min_real};
574-
Real minBBox[3] = {max_real,max_real,max_real};
575-
576571
const auto& positions = this->mstate->read(core::vec_id::read_access::position)->getValue();
572+
type::BoundingBox bbox;
577573

578574
for (sofa::Size i=0; i<size; i++)
579575
{
580-
Element e(this,i);
576+
const Element e(this,i);
581577
const Coord& pt1 = positions[this->elems[i].p[0]];
582578
const Coord& pt2 = positions[this->elems[i].p[1]];
583579

584-
for (int c=0; c<3; c++)
585-
{
586-
if (pt1[c] > maxBBox[c]) maxBBox[c] = (Real)pt1[c];
587-
else if (pt1[c] < minBBox[c]) minBBox[c] = (Real)pt1[c];
588-
589-
if (pt2[c] > maxBBox[c]) maxBBox[c] = (Real)pt2[c];
590-
else if (pt2[c] < minBBox[c]) minBBox[c] = (Real)pt2[c];
591-
}
580+
bbox.include(pt1);
581+
bbox.include(pt2);
592582
}
593583

594-
this->f_bbox.setValue(sofa::type::TBoundingBox<Real>(minBBox,maxBBox));
584+
this->f_bbox.setValue(bbox);
595585
}
596586

597587
template<class DataTypes>

Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/PointModel.inl

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -300,24 +300,17 @@ void PointCollisionModel<DataTypes>::computeBBox(const core::ExecParams* params,
300300
if (npoints != size)
301301
return;
302302

303-
static constexpr Real max_real = std::numeric_limits<Real>::max();
304-
static constexpr Real min_real = std::numeric_limits<Real>::lowest();
305-
Real maxBBox[3] = {min_real,min_real,min_real};
306-
Real minBBox[3] = {max_real,max_real,max_real};
303+
type::BoundingBox bbox;
307304

308305
for (sofa::Size i=0; i<size; i++)
309306
{
310-
Element e(this,i);
307+
const Element e(this,i);
311308
const Coord& p = e.p();
312309

313-
for (int c=0; c<3; c++)
314-
{
315-
if (p[c] > maxBBox[c]) maxBBox[c] = (Real)p[c];
316-
else if (p[c] < minBBox[c]) minBBox[c] = (Real)p[c];
317-
}
310+
bbox.include(p);
318311
}
319312

320-
this->f_bbox.setValue(sofa::type::TBoundingBox<Real>(minBBox,maxBBox));
313+
this->f_bbox.setValue(bbox);
321314
}
322315

323316

@@ -326,7 +319,6 @@ template<class DataTypes>
326319
void PointCollisionModel<DataTypes>::draw(const core::visual::VisualParams*, sofa::Index index)
327320
{
328321
SOFA_UNUSED(index);
329-
//TODO(fred roy 2018-06-21)...please implement.
330322
}
331323

332324

Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/SphereModel.inl

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -260,26 +260,20 @@ void SphereCollisionModel<DataTypes>::computeBBox(const core::ExecParams* params
260260
if( onlyVisible && !sofa::core::visual::VisualParams::defaultInstance()->displayFlags().getShowCollisionModels())
261261
return;
262262

263-
static constexpr Real max_real = std::numeric_limits<Real>::max();
264-
Real maxBBox[3] = {-max_real,-max_real,-max_real}; //Warning: minimum of float/double is 0, not -inf
265-
Real minBBox[3] = {max_real,max_real,max_real};
266-
267263
const auto npoints = mstate->getSize();
264+
type::BoundingBox bbox;
268265

269266
for(sofa::Size i = 0 ; i < npoints ; ++i )
270267
{
271-
TSphere<DataTypes> t(this,i);
268+
const TSphere<DataTypes> t(this,i);
272269
const Coord& p = t.p();
273-
Real r = t.r();
270+
const Real r = t.r();
274271

275-
for (int c=0; c<3; c++)
276-
{
277-
if (p[c]+r > maxBBox[c]) maxBBox[c] = (Real)p[c]+r;
278-
if (p[c]-r < minBBox[c]) minBBox[c] = (Real)p[c]-r;
279-
}
272+
bbox.include(p + type::Vec3{r,r,r});
273+
bbox.include(p - type::Vec3{r,r,r});
280274
}
281275

282-
this->f_bbox.setValue(sofa::type::TBoundingBox<Real>(minBBox,maxBBox));
276+
this->f_bbox.setValue(bbox);
283277
}
284278

285279
} // namespace sofa::component::collision::geometry

Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModel.inl

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -384,33 +384,18 @@ void TriangleCollisionModel<DataTypes>::computeBBox(const core::ExecParams* para
384384
if (m_topology->getRevision() != m_topologyRevision)
385385
updateFromTopology();
386386

387-
static constexpr Real max_real = std::numeric_limits<Real>::max();
388-
static constexpr Real min_real = std::numeric_limits<Real>::lowest();
389-
Real maxBBox[3] = {min_real,min_real,min_real};
390-
Real minBBox[3] = {max_real,max_real,max_real};
391-
392387
const auto& positions = this->m_mstate->read(core::vec_id::read_access::position)->getValue();
388+
type::BoundingBox bbox;
393389

394-
for (sofa::Size i=0; i<size; i++)
390+
for(const auto& triangle : (*this->m_triangles))
395391
{
396-
const type::Vec3& pt1 = positions[(*this->m_triangles)[i][0]];
397-
const type::Vec3& pt2 = positions[(*this->m_triangles)[i][1]];
398-
const type::Vec3& pt3 = positions[(*this->m_triangles)[i][2]];
399-
400-
for (int c=0; c<3; c++)
392+
for(const auto ptindex : triangle)
401393
{
402-
if (pt1[c] > maxBBox[c]) maxBBox[c] = (Real)pt1[c];
403-
else if (pt1[c] < minBBox[c]) minBBox[c] = (Real)pt1[c];
404-
405-
if (pt2[c] > maxBBox[c]) maxBBox[c] = (Real)pt2[c];
406-
else if (pt2[c] < minBBox[c]) minBBox[c] = (Real)pt2[c];
407-
408-
if (pt3[c] > maxBBox[c]) maxBBox[c] = (Real)pt3[c];
409-
else if (pt3[c] < minBBox[c]) minBBox[c] = (Real)pt3[c];
394+
bbox.include(positions[ptindex]);
410395
}
411396
}
412397

413-
this->f_bbox.setValue(sofa::type::TBoundingBox<Real>(minBBox,maxBBox));
398+
this->f_bbox.setValue(bbox);
414399
}
415400

416401

Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedProjectiveConstraint.inl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -365,26 +365,23 @@ void FixedProjectiveConstraint<DataTypes>::computeBBoxForIndices(const type::vec
365365
{
366366
using Real = typename DataTypes::Real;
367367

368-
constexpr Real max_real = std::numeric_limits<Real>::max();
369-
constexpr Real min_real = std::numeric_limits<Real>::lowest();
370-
Real maxBBox[3] = {min_real,min_real,min_real};
371-
Real minBBox[3] = {max_real,max_real,max_real};
372-
373368
const auto drawSize = static_cast<Real>(d_drawSize.getValue());
374369

375370
const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue();
376371

377-
for (const auto index : indices)
372+
type::BoundingBox bbox;
373+
for (const auto index : indices )
378374
{
379375
const auto x3d = DataTypes::getCPos(x[index]);
380376

381-
for (unsigned int i = 0; i < x3d.size(); ++i)
377+
for (unsigned int i = 0; i < DataTypes::Coord::spatial_dimensions && i<3; ++i)
382378
{
383-
maxBBox[i] = std::max(x3d[i] + drawSize, maxBBox[i]);
384-
minBBox[i] = std::min(x3d[i] - drawSize, minBBox[i]);
379+
bbox.maxBBox()[i] = std::max(static_cast<SReal>(x3d[i] + drawSize), bbox.maxBBox()[i]);
380+
bbox.minBBox()[i] = std::min(static_cast<SReal>(x3d[i] - drawSize), bbox.minBBox()[i]);
385381
}
386382
}
387-
this->f_bbox.setValue(sofa::type::TBoundingBox<Real>(minBBox,maxBBox));
383+
384+
this->f_bbox.setValue(bbox);
388385
}
389386

390387
template <class DataTypes>

Sofa/Component/Engine/Select/src/sofa/component/engine/select/BaseROI.inl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ using core::objectmodel::BaseData ;
3838
using core::objectmodel::Event ;
3939
using core::loader::MeshLoader ;
4040
using core::ExecParams ;
41-
using type::TBoundingBox ;
4241
using type::Vec3 ;
4342
using type::Vec4f ;
4443
using helper::WriteOnlyAccessor ;

Sofa/Component/Engine/Select/src/sofa/component/engine/select/BoxROI.inl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ using core::objectmodel::ComponentState ;
3939
using core::objectmodel::BaseData ;
4040
using core::objectmodel::Event ;
4141
using core::ExecParams ;
42-
using type::TBoundingBox ;
4342
using type::Vec3 ;
4443
using type::Vec4f ;
4544
using helper::WriteOnlyAccessor ;

Sofa/Component/Engine/Select/src/sofa/component/engine/select/SubsetTopology.inl

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -878,22 +878,14 @@ void SubsetTopology<DataTypes>::computeBBox(const core::ExecParams* params , bo
878878
SOFA_UNUSED(onlyVisible);
879879

880880
const type::vector<Vec6>& vb=boxes.getValue();
881-
const Real max_real = std::numeric_limits<Real>::max();
882-
const Real min_real = std::numeric_limits<Real>::lowest();
883-
Real maxBBox[3] = {min_real,min_real,min_real};
884-
Real minBBox[3] = {max_real,max_real,max_real};
885-
886-
for (unsigned int bi=0; bi<vb.size(); ++bi)
881+
type::BoundingBox bbox;
882+
for (const auto& b : vb)
887883
{
888-
const Vec6& b=vb[bi];
889-
if (b[0] < minBBox[0]) minBBox[0] = b[0];
890-
if (b[1] < minBBox[1]) minBBox[1] = b[1];
891-
if (b[2] < minBBox[2]) minBBox[2] = b[2];
892-
if (b[3] > maxBBox[0]) maxBBox[0] = b[3];
893-
if (b[4] > maxBBox[1]) maxBBox[1] = b[4];
894-
if (b[5] > maxBBox[2]) maxBBox[2] = b[5];
884+
bbox.include(type::Vec3{b[0], b[1], b[2]});
885+
bbox.include(type::Vec3{b[3], b[4], b[5]});
895886
}
896-
this->f_bbox.setValue(sofa::type::TBoundingBox<Real>(minBBox,maxBBox));
887+
888+
this->f_bbox.setValue(bbox);
897889
}
898890

899891
} //namespace sofa::component::engine::select

Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/SmoothMeshEngine.inl

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,13 @@ void SmoothMeshEngine<DataTypes>::computeBBox(const core::ExecParams*, bool only
140140

141141
helper::ReadAccessor< Data<VecCoord> > x(input_position);
142142

143-
static const Real max_real = std::numeric_limits<Real>::max();
144-
static const Real min_real = std::numeric_limits<Real>::lowest();
145-
Real maxBBox[3] = {min_real,min_real,min_real};
146-
Real minBBox[3] = {max_real,max_real,max_real};
147-
for (size_t i=0; i<x.size(); i++)
148-
{
149-
for (int c=0; c<3; c++)
150-
{
151-
if (x[i][c] > maxBBox[c]) maxBBox[c] = (Real)x[i][c];
152-
else if (x[i][c] < minBBox[c]) minBBox[c] = (Real)x[i][c];
153-
}
154-
}
155-
156-
this->f_bbox.setValue(sofa::type::TBoundingBox<Real>(minBBox,maxBBox));
143+
type::BoundingBox bbox;
144+
for (const auto& p : x )
145+
{
146+
bbox.include(p);
147+
}
148+
149+
this->f_bbox.setValue(bbox);
157150
}
158151

159152
template <class DataTypes>

Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/PlaneForceField.inl

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -410,32 +410,25 @@ void PlaneForceField<DataTypes>::computeBBox(const core::ExecParams * params, bo
410410
if (onlyVisible && !d_drawIsEnabled.getValue())
411411
return;
412412

413-
constexpr SReal max_real = std::numeric_limits<SReal>::max();
414-
constexpr SReal min_real = std::numeric_limits<SReal>::lowest();
415-
SReal maxBBox[3] = {min_real,min_real,min_real};
416-
SReal minBBox[3] = {max_real,max_real,max_real};
417-
418413
const SReal size = d_drawSize.getValue();
419414

420415
type::Vec3 normal{}, v1{}, v2{};
421416
get3DFrameFromDPosNormal<DataTypes>(d_planeNormal.getValue(), v1, v2, normal);
422417

423418
const type::Vec3& center = normal*d_planeD.getValue();
424-
type::Vec3 corners[4];
419+
std::array<type::Vec3, 4> corners;
425420
corners[0] = center-v1*size-v2*size;
426421
corners[1] = center+v1*size-v2*size;
427422
corners[2] = center+v1*size+v2*size;
428423
corners[3] = center-v1*size+v2*size;
429424

430-
for (unsigned int i=0; i<4; i++)
425+
type::BoundingBox bbox;
426+
for (const auto& c : corners )
431427
{
432-
for (int c=0; c<3; c++)
433-
{
434-
if (corners[i][c] > maxBBox[c]) maxBBox[c] = corners[i][c];
435-
if (corners[i][c] < minBBox[c]) minBBox[c] = corners[i][c];
436-
}
428+
bbox.include(c);
437429
}
438-
this->f_bbox.setValue(sofa::type::TBoundingBox<SReal>(minBBox,maxBBox));
430+
431+
this->f_bbox.setValue(bbox);
439432
}
440433

441434
} // namespace sofa::component::mechanicalload

0 commit comments

Comments
 (0)