diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml new file mode 100644 index 00000000000..a1bff8fcec3 --- /dev/null +++ b/.github/workflows/nix.yml @@ -0,0 +1,21 @@ +name: "CI - Nix" + +on: + push: + +jobs: + nix: + runs-on: "${{ matrix.os }}-latest" + if: ${{ github.repository_owner == 'sofa-framework' }} + strategy: + matrix: + os: [ubuntu, macos] + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v27 + # TODO: the "sofa" account on cachix does not exist yet + #- uses: cachix/cachix-action@v15 + #with: + #name: sofa + #authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + - run: nix build -L diff --git a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/ConstraintAnimationLoop.cpp b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/ConstraintAnimationLoop.cpp index b40e59dee91..ac27e748341 100644 --- a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/ConstraintAnimationLoop.cpp +++ b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/ConstraintAnimationLoop.cpp @@ -307,7 +307,7 @@ void ConstraintAnimationLoop::freeMotion(const core::ExecParams* params, simulat if(d_schemeCorrection.getValue()) { sofa::core::ConstraintParams cparams(*params); - sofa::core::MultiVecDerivId f = core::VecDerivId::externalForce(); + sofa::core::MultiVecDerivId f = core::vec_id::write_access::externalForce; for (auto cc : constraintCorrections) { @@ -319,7 +319,7 @@ void ConstraintAnimationLoop::freeMotion(const core::ExecParams* params, simulat { sofa::core::MechanicalParams mparams(*params); - sofa::core::MultiVecCoordId xfree = sofa::core::VecCoordId::freePosition(); + sofa::core::MultiVecCoordId xfree = sofa::core::vec_id::write_access::freePosition; mparams.x() = xfree; MechanicalProjectPositionVisitor(&mparams, 0, xfree ).execute(context); MechanicalPropagateOnlyPositionVisitor(&mparams, 0, xfree ).execute(context); @@ -331,7 +331,7 @@ void ConstraintAnimationLoop::freeMotion(const core::ExecParams* params, simulat ////////propagate acceleration ? ////// //this is done to set dx to zero in subgraph - core::MultiVecDerivId dx_id = core::VecDerivId::dx(); + core::MultiVecDerivId dx_id = core::vec_id::write_access::dx; MechanicalVOpVisitor(params, dx_id, core::ConstVecId::null(), core::ConstVecId::null(), 1.0 ).setMapped(true).execute(context); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -393,19 +393,19 @@ void ConstraintAnimationLoop::setConstraintEquations(const core::ExecParams* par void ConstraintAnimationLoop::writeAndAccumulateAndCountConstraintDirections(const core::ExecParams* params, simulation::Node *context, unsigned int &numConstraints) { core::ConstraintParams cparams = core::ConstraintParams(*params); - cparams.setX(core::ConstVecCoordId::freePosition()); - cparams.setV(core::ConstVecDerivId::freeVelocity()); + cparams.setX(core::vec_id::read_access::freePosition); + cparams.setV(core::vec_id::read_access::freeVelocity); // calling resetConstraint on LMConstraints and MechanicalStates MechanicalResetConstraintVisitor(&cparams).execute(context); // calling applyConstraint on each constraint - MechanicalSetConstraint(&cparams, core::MatrixDerivId::constraintJacobian(), numConstraints).execute(context); + MechanicalSetConstraint(&cparams, core::vec_id::write_access::constraintJacobian, numConstraints).execute(context); sofa::helper::AdvancedTimer::valSet("numConstraints", numConstraints); // calling accumulateConstraint on the mappings - MechanicalAccumulateConstraint2(&cparams, core::MatrixDerivId::constraintJacobian()).execute(context); + MechanicalAccumulateConstraint2(&cparams, core::vec_id::write_access::constraintJacobian).execute(context); getCP()->clear(numConstraints,this->d_tol.getValue()); } @@ -413,8 +413,8 @@ void ConstraintAnimationLoop::writeAndAccumulateAndCountConstraintDirections(con void ConstraintAnimationLoop::getIndividualConstraintViolations(const core::ExecParams* params, simulation::Node *context) { core::ConstraintParams cparams = core::ConstraintParams(*params); - cparams.setX(core::ConstVecCoordId::freePosition()); - cparams.setV(core::ConstVecDerivId::freeVelocity()); + cparams.setX(core::vec_id::read_access::freePosition); + cparams.setV(core::vec_id::read_access::freeVelocity); constraint::lagrangian::solver::MechanicalGetConstraintViolationVisitor(&cparams, getCP()->getDfree()).execute(context); } @@ -423,8 +423,8 @@ void ConstraintAnimationLoop::getIndividualConstraintSolvingProcess(const core:: { /// calling getConstraintResolution: each constraint provides a method that is used to solve it during GS iterations core::ConstraintParams cparams = core::ConstraintParams(*params); - cparams.setX(core::ConstVecCoordId::freePosition()); - cparams.setV(core::ConstVecDerivId::freeVelocity()); + cparams.setX(core::vec_id::read_access::freePosition); + cparams.setV(core::vec_id::read_access::freeVelocity); MechanicalGetConstraintResolutionVisitor(&cparams, getCP()->getConstraintResolutions(), 0).execute(context); } @@ -467,12 +467,12 @@ void ConstraintAnimationLoop::correctiveMotion(const core::ExecParams* params, s simulation::common::MechanicalOperations mop(params, node); - mop.propagateV(core::VecDerivId::velocity()); + mop.propagateV(core::vec_id::write_access::velocity); - mop.propagateDx(core::VecDerivId::dx(), true); + mop.propagateDx(core::vec_id::write_access::dx, true); // "mapped" x = xfree + dx - MechanicalVOpVisitor(params, core::VecCoordId::position(), core::ConstVecCoordId::freePosition(), core::ConstVecDerivId::dx(), 1.0 ).setOnlyMapped(true).execute(node); + MechanicalVOpVisitor(params, core::vec_id::write_access::position, core::vec_id::read_access::freePosition, core::vec_id::read_access::dx, 1.0 ).setOnlyMapped(true).execute(node); if(!d_schemeCorrection.getValue()) { @@ -564,8 +564,8 @@ void ConstraintAnimationLoop::step ( const core::ExecParams* params, SReal dt ) // This solver will work in freePosition and freeVelocity vectors. // We need to initialize them if it's not already done. - MechanicalVInitVisitor(params, core::VecCoordId::freePosition(), core::ConstVecCoordId::position(), true).execute(node); - MechanicalVInitVisitor(params, core::VecDerivId::freeVelocity(), core::ConstVecDerivId::velocity()).execute(node); + MechanicalVInitVisitor(params, core::vec_id::write_access::freePosition, core::vec_id::read_access::position, true).execute(node); + MechanicalVInitVisitor(params, core::vec_id::write_access::freeVelocity, core::vec_id::read_access::velocity).execute(node); if (d_doCollisionsFirst.getValue()) { @@ -622,8 +622,8 @@ void ConstraintAnimationLoop::step ( const core::ExecParams* params, SReal dt ) //////////////// BEFORE APPLYING CONSTRAINT : propagate position through mapping core::MechanicalParams mparams(*params); - MechanicalProjectPositionVisitor(&mparams, 0, core::VecCoordId::position()).execute(node); - MechanicalPropagateOnlyPositionVisitor(&mparams, 0, core::VecCoordId::position()).execute(node); + MechanicalProjectPositionVisitor(&mparams, 0, core::vec_id::write_access::position).execute(node); + MechanicalPropagateOnlyPositionVisitor(&mparams, 0, core::vec_id::write_access::position).execute(node); /// CONSTRAINT SPACE & COMPLIANCE COMPUTATION diff --git a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/FreeMotionAnimationLoop.cpp b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/FreeMotionAnimationLoop.cpp index c9b6066388f..4c4d97b1edb 100644 --- a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/FreeMotionAnimationLoop.cpp +++ b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/FreeMotionAnimationLoop.cpp @@ -91,10 +91,10 @@ void FreeMotionAnimationLoop::init() simulation::common::VectorOperations vop(core::execparams::defaultInstance(), getContext()); - MultiVecDeriv dx(&vop, core::VecDerivId::dx()); + MultiVecDeriv dx(&vop, core::vec_id::write_access::dx); dx.realloc(&vop, !d_threadSafeVisitor.getValue(), true); - MultiVecDeriv df(&vop, core::VecDerivId::dforce()); + MultiVecDeriv df(&vop, core::vec_id::write_access::dforce); df.realloc(&vop, !d_threadSafeVisitor.getValue(), true); if (!l_constraintSolver) @@ -163,10 +163,10 @@ void FreeMotionAnimationLoop::step(const sofa::core::ExecParams* params, SReal d simulation::common::VectorOperations vop(params, node); simulation::common::MechanicalOperations mop(params, getContext()); - MultiVecCoord pos(&vop, core::VecCoordId::position() ); - MultiVecDeriv vel(&vop, core::VecDerivId::velocity() ); - MultiVecCoord freePos(&vop, core::VecCoordId::freePosition() ); - MultiVecDeriv freeVel(&vop, core::VecDerivId::freeVelocity() ); + MultiVecCoord pos(&vop, core::vec_id::write_access::position ); + MultiVecDeriv vel(&vop, core::vec_id::write_access::velocity ); + MultiVecCoord freePos(&vop, core::vec_id::write_access::freePosition ); + MultiVecDeriv freeVel(&vop, core::vec_id::write_access::freeVelocity ); core::ConstraintParams cparams(*params); cparams.setX(freePos); @@ -175,18 +175,18 @@ void FreeMotionAnimationLoop::step(const sofa::core::ExecParams* params, SReal d cparams.setLambda(l_constraintSolver->getLambda()); cparams.setOrder(m_solveVelocityConstraintFirst.getValue() ? core::ConstraintOrder::VEL : core::ConstraintOrder::POS_AND_VEL); - MultiVecDeriv dx(&vop, core::VecDerivId::dx()); + MultiVecDeriv dx(&vop, core::vec_id::write_access::dx); dx.realloc(&vop, !d_threadSafeVisitor.getValue(), true); - MultiVecDeriv df(&vop, core::VecDerivId::dforce()); + MultiVecDeriv df(&vop, core::vec_id::write_access::dforce); df.realloc(&vop, !d_threadSafeVisitor.getValue(), true); // This solver will work in freePosition and freeVelocity vectors. // We need to initialize them if it's not already done. { SCOPED_TIMER("MechanicalVInitVisitor"); - MechanicalVInitVisitor< core::V_COORD >(params, core::VecCoordId::freePosition(), core::ConstVecCoordId::position(), true).execute(node); - MechanicalVInitVisitor< core::V_DERIV >(params, core::VecDerivId::freeVelocity(), core::ConstVecDerivId::velocity(), true).execute(node); + MechanicalVInitVisitor< core::V_COORD >(params, core::vec_id::write_access::freePosition, core::vec_id::read_access::position, true).execute(node); + MechanicalVInitVisitor< core::V_DERIV >(params, core::vec_id::write_access::freeVelocity, core::vec_id::read_access::velocity, true).execute(node); } // This animation loop works with lagrangian constraints. Forces derive from the constraints. @@ -352,7 +352,14 @@ void FreeMotionAnimationLoop::computeFreeMotionAndCollisionDetection(const sofa: preCollisionComputation(params); { - ScopedAdvancedTimer collisionResetTimer("CollisionReset"); + SCOPED_TIMER("ProcessGeometricalData"); + ProcessGeometricalDataVisitor act(params); + act.setTags(this->getTags()); + act.execute(node); + } + + { + SCOPED_TIMER("CollisionReset"); CollisionResetVisitor act(params); act.setTags(this->getTags()); act.execute(node); @@ -362,19 +369,19 @@ void FreeMotionAnimationLoop::computeFreeMotionAndCollisionDetection(const sofa: taskScheduler->addTask(freeMotionTaskStatus, [&]() { computeFreeMotion(params, cparams, dt, pos, freePos, freeVel, mop); }); { - ScopedAdvancedTimer collisionDetectionTimer("CollisionDetection"); + SCOPED_TIMER("CollisionDetection"); CollisionDetectionVisitor act(params); act.setTags(this->getTags()); act.execute(node); } { - ScopedAdvancedTimer waitFreeMotionTimer("WaitFreeMotion"); + SCOPED_TIMER("WaitFreeMotion"); taskScheduler->workUntilDone(&freeMotionTaskStatus); } { - ScopedAdvancedTimer collisionResponseTimer("CollisionResponse"); + SCOPED_TIMER("CollisionResponse"); CollisionResponseVisitor act(params); act.setTags(this->getTags()); act.execute(node); diff --git a/Sofa/Component/Collision/Detection/Intersection/src/sofa/component/collision/detection/intersection/LocalMinDistance.cpp b/Sofa/Component/Collision/Detection/Intersection/src/sofa/component/collision/detection/intersection/LocalMinDistance.cpp index 8c552575f9e..99a020d46d6 100644 --- a/Sofa/Component/Collision/Detection/Intersection/src/sofa/component/collision/detection/intersection/LocalMinDistance.cpp +++ b/Sofa/Component/Collision/Detection/Intersection/src/sofa/component/collision/detection/intersection/LocalMinDistance.cpp @@ -1204,7 +1204,7 @@ bool LocalMinDistance::testValidity(Point &p, const Vec3 &PQ) const return true; BaseMeshTopology* topology = p.getCollisionModel()->getCollisionTopology(); - const auto& x =(p.getCollisionModel()->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue()); + const auto& x =(p.getCollisionModel()->getMechanicalState()->read(core::vec_id::read_access::position)->getValue()); const auto& trianglesAroundVertex = topology->getTrianglesAroundVertex(p.getIndex()); const auto& edgesAroundVertex = topology->getEdgesAroundVertex(p.getIndex()); @@ -1278,7 +1278,7 @@ bool LocalMinDistance::testValidity(Line &l, const Vec3 &PQ) const AB.normalize(); BaseMeshTopology* topology = l.getCollisionModel()->getCollisionTopology(); - const auto& x =(l.getCollisionModel()->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue()); + const auto& x =(l.getCollisionModel()->getMechanicalState()->read(core::vec_id::read_access::position)->getValue()); const auto& trianglesAroundEdge = topology->getTrianglesAroundEdge(l.getIndex()); if ( trianglesAroundEdge.size() == 2) diff --git a/Sofa/Component/Collision/Detection/Intersection/src/sofa/component/collision/detection/intersection/MeshMinProximityIntersection.cpp b/Sofa/Component/Collision/Detection/Intersection/src/sofa/component/collision/detection/intersection/MeshMinProximityIntersection.cpp index 5b93974c424..47ba57e7b28 100644 --- a/Sofa/Component/Collision/Detection/Intersection/src/sofa/component/collision/detection/intersection/MeshMinProximityIntersection.cpp +++ b/Sofa/Component/Collision/Detection/Intersection/src/sofa/component/collision/detection/intersection/MeshMinProximityIntersection.cpp @@ -85,8 +85,8 @@ bool MeshMinProximityIntersection::testIntersection(Line& e1, Line& e2, const co const SReal alarmDist = currentIntersection->getAlarmDistance() + e1.getProximity() + e2.getProximity(); using Real = Line::Coord::value_type; - const auto& positions_e1 = e1.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue(); - const auto& positions_e2 = e2.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue(); + const auto& positions_e1 = e1.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue(); + const auto& positions_e2 = e2.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue(); const auto& e1p1 = positions_e1[e1.i1()]; const auto& e1p2 = positions_e1[e1.i2()]; @@ -129,8 +129,8 @@ int MeshMinProximityIntersection::computeIntersection(Line& e1, Line& e2, Output const SReal alarmDist = currentIntersection->getAlarmDistance() + e1.getProximity() + e2.getProximity(); using Real = Line::Coord::value_type; - const auto& positions_e1 = e1.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue(); - const auto& positions_e2 = e2.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue(); + const auto& positions_e1 = e1.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue(); + const auto& positions_e2 = e2.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue(); const auto& e1p1 = positions_e1[e1.i1()]; const auto& e1p2 = positions_e1[e1.i2()]; @@ -216,8 +216,8 @@ bool MeshMinProximityIntersection::testIntersection(Triangle& e2, Point& e1, con const SReal alarmDist = currentIntersection->getAlarmDistance() + e1.getProximity() + e2.getProximity(); - const auto& positions_e1 = e1.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue(); - const auto& positions_e2 = e2.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue(); + const auto& positions_e1 = e1.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue(); + const auto& positions_e2 = e2.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue(); const auto& e1p1 = positions_e1[e1.getIndex()]; const auto& e2p1 = positions_e2[e2.p1Index()]; @@ -272,8 +272,8 @@ int MeshMinProximityIntersection::computeIntersection(Triangle& e2, Point& e1, O const SReal alarmDist = currentIntersection->getAlarmDistance() + e1.getProximity() + e2.getProximity(); - const auto& positions_e1 = e1.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue(); - const auto& positions_e2 = e2.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue(); + const auto& positions_e1 = e1.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue(); + const auto& positions_e2 = e2.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue(); const auto& e1p1 = positions_e1[e1.getIndex()]; const auto& e2p1 = positions_e2[e2.p1Index()]; @@ -361,8 +361,8 @@ bool MeshMinProximityIntersection::testIntersection(Line& e2, Point& e1, const c const SReal alarmDist = currentIntersection->getAlarmDistance() + e1.getProximity() + e2.getProximity(); using Real = Line::Coord::value_type; - const auto& positions_e1 = e1.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue(); - const auto& positions_e2 = e2.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue(); + const auto& positions_e1 = e1.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue(); + const auto& positions_e2 = e2.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue(); const auto& e1p1 = positions_e1[e1.getIndex()]; const auto& e2p1 = positions_e2[e2.i1()]; @@ -391,8 +391,8 @@ int MeshMinProximityIntersection::computeIntersection(Line& e2, Point& e1, Outpu const SReal alarmDist = currentIntersection->getAlarmDistance() + e1.getProximity() + e2.getProximity(); - const auto& positions_e1 = e1.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue(); - const auto& positions_e2 = e2.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue(); + const auto& positions_e1 = e1.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue(); + const auto& positions_e2 = e2.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue(); const auto& e1p1 = positions_e1[e1.getIndex()]; const auto& e2p1 = positions_e2[e2.i1()]; diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CylinderModel.inl b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CylinderModel.inl index 02ec410f12b..0d704b09a46 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CylinderModel.inl +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CylinderModel.inl @@ -213,7 +213,7 @@ typename CylinderCollisionModel::Real CylinderCollisionModel< DataTyp template const typename CylinderCollisionModel::Coord & CylinderCollisionModel< DataTypes >::center(sofa::Index i)const{ - return DataTypes::getCPos((m_mstate->read(core::ConstVecCoordId::position())->getValue())[i]); + return DataTypes::getCPos((m_mstate->read(core::vec_id::read_access::position)->getValue())[i]); } template @@ -255,7 +255,7 @@ typename TCylinder::Real TCylinder::radius() const template const typename CylinderCollisionModel::Coord & CylinderCollisionModel::velocity(sofa::Index index) const { - return DataTypes::getDPos(((m_mstate->read(core::ConstVecDerivId::velocity())->getValue()))[index]); + return DataTypes::getDPos(((m_mstate->read(core::vec_id::read_access::velocity)->getValue()))[index]); } @@ -264,7 +264,7 @@ const typename TCylinder::Coord & TCylinder::v() const {r template const sofa::type::Quat CylinderCollisionModel::orientation(sofa::Index index)const{ - return m_mstate->read(core::ConstVecCoordId::position())->getValue()[index].getOrientation(); + return m_mstate->read(core::vec_id::read_access::position)->getValue()[index].getOrientation(); } template diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/LineModel.inl b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/LineModel.inl index 313e6916eac..203537248e6 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/LineModel.inl +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/LineModel.inl @@ -474,7 +474,7 @@ void LineCollisionModel::computeBoundingTree(int maxDepth) if (!empty()) { const SReal distance = this->proximity.getValue(); - const auto& positions = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const auto& positions = this->mstate->read(core::vec_id::read_access::position)->getValue(); for (sofa::Size i=0; i::computeBBox(const core::ExecParams* params, Real maxBBox[3] = {min_real,min_real,min_real}; Real minBBox[3] = {max_real,max_real,max_real}; - const auto& positions = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const auto& positions = this->mstate->read(core::vec_id::read_access::position)->getValue(); for (sofa::Size i=0; i inline sofa::Index TLine::i2() const { return this->model->elems[this->index].p[1]; } template -inline const typename DataTypes::Coord& TLine::p1() const { return this->model->mstate->read(core::ConstVecCoordId::position())->getValue()[this->model->elems[this->index].p[0]]; } +inline const typename DataTypes::Coord& TLine::p1() const { return this->model->mstate->read(core::vec_id::read_access::position)->getValue()[this->model->elems[this->index].p[0]]; } template -inline const typename DataTypes::Coord& TLine::p2() const { return this->model->mstate->read(core::ConstVecCoordId::position())->getValue()[this->model->elems[this->index].p[1]]; } +inline const typename DataTypes::Coord& TLine::p2() const { return this->model->mstate->read(core::vec_id::read_access::position)->getValue()[this->model->elems[this->index].p[1]]; } template inline const typename DataTypes::Coord& TLine::p(Index i) const { - return this->model->mstate->read(core::ConstVecCoordId::position())->getValue()[this->model->elems[this->index].p[i]]; + return this->model->mstate->read(core::vec_id::read_access::position)->getValue()[this->model->elems[this->index].p[i]]; } template inline const typename DataTypes::Coord& TLine::p1Free() const { if (hasFreePosition()) - return this->model->mstate->read(core::ConstVecCoordId::freePosition())->getValue()[this->model->elems[this->index].p[0]]; + return this->model->mstate->read(core::vec_id::read_access::freePosition)->getValue()[this->model->elems[this->index].p[0]]; else return p1(); } @@ -626,28 +626,28 @@ template inline const typename DataTypes::Coord& TLine::p2Free() const { if (hasFreePosition()) - return this->model->mstate->read(core::ConstVecCoordId::freePosition())->getValue()[this->model->elems[this->index].p[1]]; + return this->model->mstate->read(core::vec_id::read_access::freePosition)->getValue()[this->model->elems[this->index].p[1]]; else return p2(); } template -inline const typename DataTypes::Deriv& TLine::v1() const { return this->model->mstate->read(core::ConstVecDerivId::velocity())->getValue()[this->model->elems[this->index].p[0]]; } +inline const typename DataTypes::Deriv& TLine::v1() const { return this->model->mstate->read(core::vec_id::read_access::velocity)->getValue()[this->model->elems[this->index].p[0]]; } template -inline const typename DataTypes::Deriv& TLine::v2() const { return this->model->mstate->read(core::ConstVecDerivId::velocity())->getValue()[this->model->elems[this->index].p[1]]; } +inline const typename DataTypes::Deriv& TLine::v2() const { return this->model->mstate->read(core::vec_id::read_access::velocity)->getValue()[this->model->elems[this->index].p[1]]; } template inline typename DataTypes::Deriv TLine::n() const {return (this->model->mpoints->getNormal(this->i1()) + this->model->mpoints->getNormal( this->i2())).normalized();} template -inline typename LineCollisionModel::Deriv LineCollisionModel::velocity(sofa::Index index) const { return (mstate->read(core::ConstVecDerivId::velocity())->getValue()[elems[index].p[0]] + mstate->read(core::ConstVecDerivId::velocity())->getValue()[elems[index].p[1]])/((Real)(2.0)); } +inline typename LineCollisionModel::Deriv LineCollisionModel::velocity(sofa::Index index) const { return (mstate->read(core::vec_id::read_access::velocity)->getValue()[elems[index].p[0]] + mstate->read(core::vec_id::read_access::velocity)->getValue()[elems[index].p[1]])/((Real)(2.0)); } template inline int TLine::flags() const { return this->model->getLineFlags(this->index); } template -inline bool TLine::hasFreePosition() const { return this->model->mstate->read(core::ConstVecCoordId::freePosition())->isSet(); } +inline bool TLine::hasFreePosition() const { return this->model->mstate->read(core::vec_id::read_access::freePosition)->isSet(); } } //namespace sofa::component::collision::geometry diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/PointModel.h b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/PointModel.h index 8e8c89a8be5..84cbf118004 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/PointModel.h +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/PointModel.h @@ -168,28 +168,28 @@ inline TPoint::TPoint(const core::CollisionElementIterator& i) } template -inline const typename DataTypes::Coord& TPoint::p() const { return this->model->mstate->read(core::ConstVecCoordId::position())->getValue()[this->index]; } +inline const typename DataTypes::Coord& TPoint::p() const { return this->model->mstate->read(core::vec_id::read_access::position)->getValue()[this->index]; } template inline const typename DataTypes::Coord& TPoint::pFree() const { if (hasFreePosition()) - return this->model->mstate->read(core::ConstVecCoordId::freePosition())->getValue()[this->index]; + return this->model->mstate->read(core::vec_id::read_access::freePosition)->getValue()[this->index]; else return p(); } template -inline const typename DataTypes::Deriv& TPoint::v() const { return this->model->mstate->read(core::ConstVecDerivId::velocity())->getValue()[this->index]; } +inline const typename DataTypes::Deriv& TPoint::v() const { return this->model->mstate->read(core::vec_id::read_access::velocity)->getValue()[this->index]; } template -inline const typename DataTypes::Deriv& PointCollisionModel::velocity(sofa::Index index) const { return mstate->read(core::ConstVecDerivId::velocity())->getValue()[index]; } +inline const typename DataTypes::Deriv& PointCollisionModel::velocity(sofa::Index index) const { return mstate->read(core::vec_id::read_access::velocity)->getValue()[index]; } template inline typename DataTypes::Deriv TPoint::n() const { return ((unsigned)this->indexmodel->normals.size()) ? this->model->normals[this->index] : Deriv(); } template -inline bool TPoint::hasFreePosition() const { return this->model->mstate->read(core::ConstVecCoordId::freePosition())->isSet(); } +inline bool TPoint::hasFreePosition() const { return this->model->mstate->read(core::vec_id::read_access::freePosition)->isSet(); } #if !defined(SOFA_COMPONENT_COLLISION_POINTCOLLISIONMODEL_CPP) extern template class SOFA_COMPONENT_COLLISION_GEOMETRY_API PointCollisionModel; diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/PointModel.inl b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/PointModel.inl index cd1c3acd4b0..45de29c5fc9 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/PointModel.inl +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/PointModel.inl @@ -134,7 +134,7 @@ void PointCollisionModel::computeBoundingTree(int maxDepth) cubeModel->resize(size); if (!empty()) { - //VecCoord& x =mstate->read(core::ConstVecCoordId::position())->getValue(); + //VecCoord& x =mstate->read(core::vec_id::read_access::position)->getValue(); const SReal distance = this->proximity.getValue(); for (sofa::Size i=0; i::computeContinuousBoundingTree(SReal dt, int cubeModel->resize(size); if (!empty()) { - //VecCoord& x =mstate->read(core::ConstVecCoordId::position())->getValue(); - //VecDeriv& v = mstate->read(core::ConstVecDerivId::velocity())->getValue(); + //VecCoord& x =mstate->read(core::vec_id::read_access::position)->getValue(); + //VecDeriv& v = mstate->read(core::vec_id::read_access::velocity)->getValue(); const SReal distance = (SReal)this->proximity.getValue(); for (sofa::Size i=0; i::computeContinuousBoundingTree(SReal dt, int template void PointCollisionModel::updateNormals() { - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); auto n = x.size(); normals.resize(n); for (sofa::Index i=0; igetMechanicalState()->read(core::ConstVecCoordId::position())->getValue()[index]; + return model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue()[index]; } const type::Vec3& Ray::direction() const @@ -190,10 +190,10 @@ SReal Ray::l() const void Ray::setOrigin(const type::Vec3& newOrigin) { - auto xData = sofa::helper::getWriteAccessor(*model->getMechanicalState()->write(core::VecCoordId::position())); + auto xData = sofa::helper::getWriteAccessor(*model->getMechanicalState()->write(core::vec_id::write_access::position)); xData.wref()[index] = newOrigin; - auto xDataFree = sofa::helper::getWriteAccessor(*model->getMechanicalState()->write(core::VecCoordId::freePosition())); + auto xDataFree = sofa::helper::getWriteAccessor(*model->getMechanicalState()->write(core::vec_id::write_access::freePosition)); auto& freePos = xDataFree.wref(); freePos.resize(model->getMechanicalState()->getSize()); freePos[index] = newOrigin; diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/SphereModel.h b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/SphereModel.h index 260331691c0..ef5b8031204 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/SphereModel.h +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/SphereModel.h @@ -194,28 +194,28 @@ inline TSphere::TSphere(const core::CollisionElementIterator& i) } template -inline const typename TSphere::Coord& TSphere::center() const { return DataTypes::getCPos(this->model->mstate->read(core::ConstVecCoordId::position())->getValue()[this->index]); } +inline const typename TSphere::Coord& TSphere::center() const { return DataTypes::getCPos(this->model->mstate->read(core::vec_id::read_access::position)->getValue()[this->index]); } template -inline const typename DataTypes::Coord & TSphere::rigidCenter() const { return this->model->mstate->read(core::ConstVecCoordId::position())->getValue()[this->index];} +inline const typename DataTypes::Coord & TSphere::rigidCenter() const { return this->model->mstate->read(core::vec_id::read_access::position)->getValue()[this->index];} template -inline const typename TSphere::Coord& TSphere::p() const { return DataTypes::getCPos(this->model->mstate->read(core::ConstVecCoordId::position())->getValue()[this->index]);} +inline const typename TSphere::Coord& TSphere::p() const { return DataTypes::getCPos(this->model->mstate->read(core::vec_id::read_access::position)->getValue()[this->index]);} template -inline const typename TSphere::Coord& TSphere::pFree() const { return (*this->model->mstate->read(core::ConstVecCoordId::freePosition())).getValue()[this->index]; } +inline const typename TSphere::Coord& TSphere::pFree() const { return (*this->model->mstate->read(core::vec_id::read_access::freePosition)).getValue()[this->index]; } template -inline const typename SphereCollisionModel::Coord& SphereCollisionModel::velocity(sofa::Index index) const { return DataTypes::getDPos(mstate->read(core::ConstVecDerivId::velocity())->getValue()[index]);} +inline const typename SphereCollisionModel::Coord& SphereCollisionModel::velocity(sofa::Index index) const { return DataTypes::getDPos(mstate->read(core::vec_id::read_access::velocity)->getValue()[index]);} template -inline const typename TSphere::Coord& TSphere::v() const { return DataTypes::getDPos(this->model->mstate->read(core::ConstVecDerivId::velocity())->getValue()[this->index]); } +inline const typename TSphere::Coord& TSphere::v() const { return DataTypes::getDPos(this->model->mstate->read(core::vec_id::read_access::velocity)->getValue()[this->index]); } template inline typename DataTypes::Real TSphere::r() const { return (Real) this->model->getRadius((unsigned)this->index); } template -inline bool TSphere::hasFreePosition() const { return this->model->mstate->read(core::ConstVecCoordId::freePosition())->isSet(); } +inline bool TSphere::hasFreePosition() const { return this->model->mstate->read(core::vec_id::read_access::freePosition)->isSet(); } using Sphere = TSphere; using RigidSphere = TSphere; diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TetrahedronModel.cpp b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TetrahedronModel.cpp index ee967216ff7..f8533385263 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TetrahedronModel.cpp +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TetrahedronModel.cpp @@ -207,7 +207,7 @@ void TetrahedronCollisionModel::computeBoundingTree(int maxDepth) updateFromTopology(); Vec3 minElem, maxElem; - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); for (std::size_t i=0; i(static_cast(i.getCollisionModel()), i.getIndex()) {} -inline const type::Vec3& Tetrahedron::p1() const { return model->mstate->read(core::ConstVecCoordId::position())->getValue()[(*(model->tetra))[index][0]]; } -inline const type::Vec3& Tetrahedron::p2() const { return model->mstate->read(core::ConstVecCoordId::position())->getValue()[(*(model->tetra))[index][1]]; } -inline const type::Vec3& Tetrahedron::p3() const { return model->mstate->read(core::ConstVecCoordId::position())->getValue()[(*(model->tetra))[index][2]]; } -inline const type::Vec3& Tetrahedron::p4() const { return model->mstate->read(core::ConstVecCoordId::position())->getValue()[(*(model->tetra))[index][3]]; } +inline const type::Vec3& Tetrahedron::p1() const { return model->mstate->read(core::vec_id::read_access::position)->getValue()[(*(model->tetra))[index][0]]; } +inline const type::Vec3& Tetrahedron::p2() const { return model->mstate->read(core::vec_id::read_access::position)->getValue()[(*(model->tetra))[index][1]]; } +inline const type::Vec3& Tetrahedron::p3() const { return model->mstate->read(core::vec_id::read_access::position)->getValue()[(*(model->tetra))[index][2]]; } +inline const type::Vec3& Tetrahedron::p4() const { return model->mstate->read(core::vec_id::read_access::position)->getValue()[(*(model->tetra))[index][3]]; } -inline const type::Vec3& Tetrahedron::p1Free() const { return model->mstate->read(core::ConstVecCoordId::freePosition())->getValue()[(*(model->tetra))[index][0]]; } -inline const type::Vec3& Tetrahedron::p2Free() const { return model->mstate->read(core::ConstVecCoordId::freePosition())->getValue()[(*(model->tetra))[index][1]]; } -inline const type::Vec3& Tetrahedron::p3Free() const { return model->mstate->read(core::ConstVecCoordId::freePosition())->getValue()[(*(model->tetra))[index][2]]; } -inline const type::Vec3& Tetrahedron::p4Free() const { return model->mstate->read(core::ConstVecCoordId::freePosition())->getValue()[(*(model->tetra))[index][3]]; } +inline const type::Vec3& Tetrahedron::p1Free() const { return model->mstate->read(core::vec_id::read_access::freePosition)->getValue()[(*(model->tetra))[index][0]]; } +inline const type::Vec3& Tetrahedron::p2Free() const { return model->mstate->read(core::vec_id::read_access::freePosition)->getValue()[(*(model->tetra))[index][1]]; } +inline const type::Vec3& Tetrahedron::p3Free() const { return model->mstate->read(core::vec_id::read_access::freePosition)->getValue()[(*(model->tetra))[index][2]]; } +inline const type::Vec3& Tetrahedron::p4Free() const { return model->mstate->read(core::vec_id::read_access::freePosition)->getValue()[(*(model->tetra))[index][3]]; } inline int Tetrahedron::p1Index() const { return (*(model->tetra))[index][0]; } inline int Tetrahedron::p2Index() const { return (*(model->tetra))[index][1]; } inline int Tetrahedron::p3Index() const { return (*(model->tetra))[index][2]; } inline int Tetrahedron::p4Index() const { return (*(model->tetra))[index][3]; } -inline const type::Vec3& Tetrahedron::v1() const { return model->mstate->read(core::ConstVecDerivId::velocity())->getValue()[(*(model->tetra))[index][0]]; } -inline const type::Vec3& Tetrahedron::v2() const { return model->mstate->read(core::ConstVecDerivId::velocity())->getValue()[(*(model->tetra))[index][1]]; } -inline const type::Vec3& Tetrahedron::v3() const { return model->mstate->read(core::ConstVecDerivId::velocity())->getValue()[(*(model->tetra))[index][2]]; } -inline const type::Vec3& Tetrahedron::v4() const { return model->mstate->read(core::ConstVecDerivId::velocity())->getValue()[(*(model->tetra))[index][3]]; } +inline const type::Vec3& Tetrahedron::v1() const { return model->mstate->read(core::vec_id::read_access::velocity)->getValue()[(*(model->tetra))[index][0]]; } +inline const type::Vec3& Tetrahedron::v2() const { return model->mstate->read(core::vec_id::read_access::velocity)->getValue()[(*(model->tetra))[index][1]]; } +inline const type::Vec3& Tetrahedron::v3() const { return model->mstate->read(core::vec_id::read_access::velocity)->getValue()[(*(model->tetra))[index][2]]; } +inline const type::Vec3& Tetrahedron::v4() const { return model->mstate->read(core::vec_id::read_access::velocity)->getValue()[(*(model->tetra))[index][3]]; } inline type::Vec3 Tetrahedron::getBary(const type::Vec3& p) const { return model->elems[index].coord2bary*(p-model->elems[index].coord0); } inline type::Vec3 Tetrahedron::getDBary(const type::Vec3& v) const { return model->elems[index].coord2bary*(v); } diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModel.h b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModel.h index a7fdbc1ce51..4671bae100a 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModel.h +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModel.h @@ -189,7 +189,7 @@ class TriangleCollisionModel : public core::CollisionModel core::behavior::MechanicalState* getMechanicalState() { return m_mstate; } const core::behavior::MechanicalState* getMechanicalState() const { return m_mstate; } - const VecCoord& getX() const { return(getMechanicalState()->read(core::ConstVecCoordId::position())->getValue()); } + const VecCoord& getX() const { return(getMechanicalState()->read(core::vec_id::read_access::position)->getValue()); } const sofa::core::topology::BaseMeshTopology::SeqTriangles& getTriangles() const { return *m_triangles; } const VecDeriv& getNormals() const { return m_normals; } int getTriangleFlags(sofa::core::topology::BaseMeshTopology::TriangleID i); diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModel.inl b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModel.inl index 69cb8ec2998..a4fb0bddea0 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModel.inl +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModel.inl @@ -232,7 +232,7 @@ void TriangleCollisionModel::computeBoundingTree(int maxDepth) m_needsUpdate=false; type::Vec3 minElem, maxElem; - const VecCoord& x = this->m_mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->m_mstate->read(core::vec_id::read_access::position)->getValue(); const bool calcNormals = d_computeNormals.getValue(); @@ -388,7 +388,7 @@ void TriangleCollisionModel::computeBBox(const core::ExecParams* para Real maxBBox[3] = {min_real,min_real,min_real}; Real minBBox[3] = {max_real,max_real,max_real}; - const auto& positions = this->m_mstate->read(core::ConstVecCoordId::position())->getValue(); + const auto& positions = this->m_mstate->read(core::vec_id::read_access::position)->getValue(); for (sofa::Size i=0; i::draw(const core::visual::VisualParams* v } template -inline const typename DataTypes::Coord& TTriangle::p1() const { return this->model->m_mstate->read(core::ConstVecCoordId::position())->getValue()[(*(this->model->m_triangles))[this->index][0]]; } +inline const typename DataTypes::Coord& TTriangle::p1() const { return this->model->m_mstate->read(core::vec_id::read_access::position)->getValue()[(*(this->model->m_triangles))[this->index][0]]; } template -inline const typename DataTypes::Coord& TTriangle::p2() const { return this->model->m_mstate->read(core::ConstVecCoordId::position())->getValue()[(*(this->model->m_triangles))[this->index][1]]; } +inline const typename DataTypes::Coord& TTriangle::p2() const { return this->model->m_mstate->read(core::vec_id::read_access::position)->getValue()[(*(this->model->m_triangles))[this->index][1]]; } template -inline const typename DataTypes::Coord& TTriangle::p3() const { return this->model->m_mstate->read(core::ConstVecCoordId::position())->getValue()[(*(this->model->m_triangles))[this->index][2]]; } +inline const typename DataTypes::Coord& TTriangle::p3() const { return this->model->m_mstate->read(core::vec_id::read_access::position)->getValue()[(*(this->model->m_triangles))[this->index][2]]; } template inline const typename DataTypes::Coord& TTriangle::p(Index i) const { - return this->model->m_mstate->read(core::ConstVecCoordId::position())->getValue()[(*(this->model->m_triangles))[this->index][i]]; + return this->model->m_mstate->read(core::vec_id::read_access::position)->getValue()[(*(this->model->m_triangles))[this->index][i]]; } template inline const typename DataTypes::Coord& TTriangle::operator[](Index i) const { - return this->model->m_mstate->read(core::ConstVecCoordId::position())->getValue()[(*(this->model->m_triangles))[this->index][i]]; + return this->model->m_mstate->read(core::vec_id::read_access::position)->getValue()[(*(this->model->m_triangles))[this->index][i]]; } template -inline const typename DataTypes::Coord& TTriangle::p1Free() const { return (this->model->m_mstate->read(sofa::core::ConstVecCoordId::freePosition())->getValue())[(*(this->model->m_triangles))[this->index][0]]; } +inline const typename DataTypes::Coord& TTriangle::p1Free() const { return (this->model->m_mstate->read(sofa::core::vec_id::read_access::freePosition)->getValue())[(*(this->model->m_triangles))[this->index][0]]; } template -inline const typename DataTypes::Coord& TTriangle::p2Free() const { return (this->model->m_mstate->read(sofa::core::ConstVecCoordId::freePosition())->getValue())[((*this->model->m_triangles))[this->index][1]]; } +inline const typename DataTypes::Coord& TTriangle::p2Free() const { return (this->model->m_mstate->read(sofa::core::vec_id::read_access::freePosition)->getValue())[((*this->model->m_triangles))[this->index][1]]; } template -inline const typename DataTypes::Coord& TTriangle::p3Free() const { return (this->model->m_mstate->read(sofa::core::ConstVecCoordId::freePosition())->getValue())[(*(this->model->m_triangles))[this->index][2]]; } +inline const typename DataTypes::Coord& TTriangle::p3Free() const { return (this->model->m_mstate->read(sofa::core::vec_id::read_access::freePosition)->getValue())[(*(this->model->m_triangles))[this->index][2]]; } template inline typename TTriangle::Index TTriangle::p1Index() const { return (*(this->model->m_triangles))[this->index][0]; } @@ -512,13 +512,13 @@ template inline typename TTriangle::Index TTriangle::p3Index() const { return (*(this->model->m_triangles))[this->index][2]; } template -inline const typename DataTypes::Deriv& TTriangle::v1() const { return (this->model->m_mstate->read(core::ConstVecDerivId::velocity())->getValue())[(*(this->model->m_triangles))[this->index][0]]; } +inline const typename DataTypes::Deriv& TTriangle::v1() const { return (this->model->m_mstate->read(core::vec_id::read_access::velocity)->getValue())[(*(this->model->m_triangles))[this->index][0]]; } template -inline const typename DataTypes::Deriv& TTriangle::v2() const { return this->model->m_mstate->read(core::ConstVecDerivId::velocity())->getValue()[(*(this->model->m_triangles))[this->index][1]]; } +inline const typename DataTypes::Deriv& TTriangle::v2() const { return this->model->m_mstate->read(core::vec_id::read_access::velocity)->getValue()[(*(this->model->m_triangles))[this->index][1]]; } template -inline const typename DataTypes::Deriv& TTriangle::v3() const { return this->model->m_mstate->read(core::ConstVecDerivId::velocity())->getValue()[(*(this->model->m_triangles))[this->index][2]]; } +inline const typename DataTypes::Deriv& TTriangle::v3() const { return this->model->m_mstate->read(core::vec_id::read_access::velocity)->getValue()[(*(this->model->m_triangles))[this->index][2]]; } template -inline const typename DataTypes::Deriv& TTriangle::v(Index i) const { return this->model->m_mstate->read(core::ConstVecDerivId::velocity())->getValue()[(*(this->model->m_triangles))[this->index][i]]; } +inline const typename DataTypes::Deriv& TTriangle::v(Index i) const { return this->model->m_mstate->read(core::vec_id::read_access::velocity)->getValue()[(*(this->model->m_triangles))[this->index][i]]; } template inline const typename DataTypes::Deriv& TTriangle::n() const { return this->model->m_normals[this->index]; } @@ -529,11 +529,11 @@ template inline int TTriangle::flags() const { return this->model->getTriangleFlags(this->index); } template -inline bool TTriangle::hasFreePosition() const { return this->model->m_mstate->read(core::ConstVecCoordId::freePosition())->isSet(); } +inline bool TTriangle::hasFreePosition() const { return this->model->m_mstate->read(core::vec_id::read_access::freePosition)->isSet(); } template -inline typename DataTypes::Deriv TriangleCollisionModel::velocity(sofa::Index index) const { return (m_mstate->read(core::ConstVecDerivId::velocity())->getValue()[(*(m_triangles))[index][0]] + m_mstate->read(core::ConstVecDerivId::velocity())->getValue()[(*(m_triangles))[index][1]] + - m_mstate->read(core::ConstVecDerivId::velocity())->getValue()[(*(m_triangles))[index][2]])/((Real)(3.0)); } +inline typename DataTypes::Deriv TriangleCollisionModel::velocity(sofa::Index index) const { return (m_mstate->read(core::vec_id::read_access::velocity)->getValue()[(*(m_triangles))[index][0]] + m_mstate->read(core::vec_id::read_access::velocity)->getValue()[(*(m_triangles))[index][1]] + + m_mstate->read(core::vec_id::read_access::velocity)->getValue()[(*(m_triangles))[index][2]])/((Real)(3.0)); } } //namespace sofa::component::collision::geometry diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModelInRegularGrid.cpp b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModelInRegularGrid.cpp index 288100b0603..631ecc9b353 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModelInRegularGrid.cpp +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModelInRegularGrid.cpp @@ -110,8 +110,8 @@ void TriangleModelInRegularGrid::computeBoundingTree ( int ) m_needsUpdate=false; Vec3 minElem, maxElem; - const VecCoord& xHigh =_higher_mstate->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& x =m_mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& xHigh =_higher_mstate->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& x =m_mstate->read(core::vec_id::read_access::position)->getValue(); // no hierarchy if ( empty() ) diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleOctreeModel.cpp b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleOctreeModel.cpp index 0e86ca75743..7af6462b9aa 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleOctreeModel.cpp +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleOctreeModel.cpp @@ -90,9 +90,9 @@ void TriangleOctreeModel::computeBoundingTree(int maxDepth) pNorms[i]=type::Vec3(0,0,0); } type::Vec3 minElem, maxElem; - maxElem[0]=minElem[0]=m_mstate->read(core::ConstVecCoordId::position())->getValue()[0][0]; - maxElem[1]=minElem[1]=m_mstate->read(core::ConstVecCoordId::position())->getValue()[0][1]; - maxElem[2]=minElem[2]=m_mstate->read(core::ConstVecCoordId::position())->getValue()[0][2]; + maxElem[0]=minElem[0]=m_mstate->read(core::vec_id::read_access::position)->getValue()[0][0]; + maxElem[1]=minElem[1]=m_mstate->read(core::vec_id::read_access::position)->getValue()[0][1]; + maxElem[2]=minElem[2]=m_mstate->read(core::vec_id::read_access::position)->getValue()[0][2]; cubeModel->resize(1); // size = number of triangles for (std::size_t i=1; i::draw(const core::visual::VisualParams using sofa::type::RGBAColor; - const VecCoord& p1 = this->mstate1->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& p2 = this->mstate2->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& p1 = this->mstate1->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& p2 = this->mstate2->read(core::vec_id::read_access::position)->getValue(); const type::vector& cc = contacts.getValue(); std::vector< type::Vec3 > points[4]; @@ -347,7 +347,7 @@ void PenalityContactForceField::grabPoint( if (static_cast< core::objectmodel::BaseObject *>(this->mstate1) == static_cast< const core::objectmodel::BaseObject *>(tool)) { - const auto& mstate2Pos = this->mstate2->read(core::ConstVecCoordId::position())->getValue(); + const auto& mstate2Pos = this->mstate2->read(core::vec_id::read_access::position)->getValue(); for (sofa::Index i=0; i< contactsRef.size(); i++) { @@ -364,7 +364,7 @@ void PenalityContactForceField::grabPoint( } else if (static_cast< core::objectmodel::BaseObject *>(this->mstate2) == static_cast< const core::objectmodel::BaseObject *>(tool)) { - const auto& mstate1Pos = this->mstate1->read(core::ConstVecCoordId::position())->getValue(); + const auto& mstate1Pos = this->mstate1->read(core::vec_id::read_access::position)->getValue(); for (sofa::Index i=0; i< contactsRef.size(); i++) { for (sofa::Index j=0; j::activateMappers( mapper2.updateXfree(); msg_info() << contacts.size() << " StickContactConstraint created"; - msg_info() << "mstate1 size = " << m_constraint->getMState1()->getSize() << " x = " << m_constraint->getMState1()->getSize() << " xfree = " << m_constraint->getMState1()->read(core::ConstVecCoordId::freePosition())->getValue().size(); - msg_info() << "mstate2 size = " << m_constraint->getMState2()->getSize() << " x = " << m_constraint->getMState2()->getSize() << " xfree = " << m_constraint->getMState2()->read(core::ConstVecCoordId::freePosition())->getValue().size(); + msg_info() << "mstate1 size = " << m_constraint->getMState1()->getSize() << " x = " << m_constraint->getMState1()->getSize() << " xfree = " << m_constraint->getMState1()->read(core::vec_id::read_access::freePosition)->getValue().size(); + msg_info() << "mstate2 size = " << m_constraint->getMState2()->getSize() << " x = " << m_constraint->getMState2()->getSize() << " xfree = " << m_constraint->getMState2()->read(core::vec_id::read_access::freePosition)->getValue().size(); } diff --git a/Sofa/Component/Collision/Response/Mapper/src/sofa/component/collision/response/mapper/BarycentricContactMapper.h b/Sofa/Component/Collision/Response/Mapper/src/sofa/component/collision/response/mapper/BarycentricContactMapper.h index ff4ff87f998..89907e5cf8b 100644 --- a/Sofa/Component/Collision/Response/Mapper/src/sofa/component/collision/response/mapper/BarycentricContactMapper.h +++ b/Sofa/Component/Collision/Response/Mapper/src/sofa/component/collision/response/mapper/BarycentricContactMapper.h @@ -84,8 +84,8 @@ class BarycentricContactMapper : public BaseContactMapper if (mapping != nullptr) { core::BaseMapping* map = mapping.get(); - map->apply(core::mechanicalparams::defaultInstance(), core::VecCoordId::position(), core::ConstVecCoordId::position()); - map->applyJ(core::mechanicalparams::defaultInstance(), core::VecDerivId::velocity(), core::ConstVecDerivId::velocity()); + map->apply(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::position, core::vec_id::read_access::position); + map->applyJ(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::velocity, core::vec_id::read_access::velocity); } } @@ -94,8 +94,8 @@ class BarycentricContactMapper : public BaseContactMapper if (mapping != nullptr) { core::BaseMapping* map = mapping.get(); - map->apply(core::mechanicalparams::defaultInstance(), core::VecCoordId::freePosition(), core::ConstVecCoordId::freePosition()); - map->applyJ(core::mechanicalparams::defaultInstance(), core::VecDerivId::freeVelocity(), core::ConstVecDerivId::freeVelocity()); + map->apply(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::freePosition, core::vec_id::read_access::freePosition); + map->applyJ(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::freeVelocity, core::vec_id::read_access::freeVelocity); } } @@ -104,7 +104,7 @@ class BarycentricContactMapper : public BaseContactMapper if (mapping != nullptr) { core::BaseMapping* map = mapping.get(); - map->apply(core::mechanicalparams::defaultInstance(), core::VecCoordId::restPosition(), core::ConstVecCoordId::restPosition()); + map->apply(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::restPosition, core::vec_id::read_access::restPosition); } } }; @@ -119,7 +119,7 @@ class ContactMappermapper->createPointInLine(P, this->model->getElemEdgeIndex(index), &this->model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue()); + return this->mapper->createPointInLine(P, this->model->getElemEdgeIndex(index), &this->model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue()); } sofa::Index addPointB(const Coord& /*P*/, sofa::Index index, Real& /*r*/, const type::Vec3& baryP) { @@ -141,13 +141,13 @@ class ContactMappermodel->getCollisionTopology()->getNbTriangles(); if (index < nbt) - return this->mapper->createPointInTriangle(P, index, &this->model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue()); + return this->mapper->createPointInTriangle(P, index, &this->model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue()); else { sofa::Index qindex = (index - nbt)/2; auto nbq = this->model->getCollisionTopology()->getNbQuads(); if (qindex < nbq) - return this->mapper->createPointInQuad(P, qindex, &this->model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue()); + return this->mapper->createPointInQuad(P, qindex, &this->model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue()); else { msg_error("ContactMapper>") << "Invalid contact element index "<model->getCollisionTopology()->getNbQuads(); if (qindex < nbq) - return this->mapper->createPointInQuad(P, qindex, &this->model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue()); + return this->mapper->createPointInQuad(P, qindex, &this->model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue()); else { msg_error("ContactMapper>") << "Invalid contact element index "< { if (mapping!=nullptr) { - mapping->apply(core::mechanicalparams::defaultInstance(), core::VecCoordId::position(), core::ConstVecCoordId::position()); - mapping->applyJ(core::mechanicalparams::defaultInstance(), core::VecDerivId::velocity(), core::ConstVecDerivId::velocity()); + mapping->apply(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::position, core::vec_id::read_access::position); + mapping->applyJ(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::velocity, core::vec_id::read_access::velocity); } } @@ -85,8 +85,8 @@ class IdentityContactMapper : public BaseContactMapper { if (mapping!=nullptr) { - mapping->apply(core::mechanicalparams::defaultInstance(), core::VecCoordId::freePosition(), core::ConstVecCoordId::freePosition()); - mapping->applyJ(core::mechanicalparams::defaultInstance(), core::VecDerivId::freeVelocity(), core::ConstVecDerivId::freeVelocity()); + mapping->apply(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::freePosition, core::vec_id::read_access::freePosition); + mapping->applyJ(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::freeVelocity, core::vec_id::read_access::freeVelocity); } } @@ -95,7 +95,7 @@ class IdentityContactMapper : public BaseContactMapper { if(mapping!=nullptr) { - mapping->apply(core::mechanicalparams::defaultInstance(), core::VecCoordId::restPosition(), core::ConstVecCoordId::restPosition()); + mapping->apply(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::restPosition, core::vec_id::read_access::restPosition); } } }; diff --git a/Sofa/Component/Collision/Response/Mapper/src/sofa/component/collision/response/mapper/RigidContactMapper.h b/Sofa/Component/Collision/Response/Mapper/src/sofa/component/collision/response/mapper/RigidContactMapper.h index 163b3c87c8e..da9c3c9301a 100644 --- a/Sofa/Component/Collision/Response/Mapper/src/sofa/component/collision/response/mapper/RigidContactMapper.h +++ b/Sofa/Component/Collision/Response/Mapper/src/sofa/component/collision/response/mapper/RigidContactMapper.h @@ -91,7 +91,7 @@ class RigidContactMapper : public BaseContactMapper } else { - helper::WriteAccessor > xData = *outmodel->write(core::VecCoordId::position()); + helper::WriteAccessor > xData = *outmodel->write(core::vec_id::write_access::position); xData.wref()[i] = P; } return i; @@ -102,8 +102,8 @@ class RigidContactMapper : public BaseContactMapper if (mapping != nullptr) { core::BaseMapping* map = mapping.get(); - map->apply(core::mechanicalparams::defaultInstance(), core::VecCoordId::position(), core::ConstVecCoordId::position()); - map->applyJ(core::mechanicalparams::defaultInstance(), core::VecDerivId::velocity(), core::ConstVecDerivId::velocity()); + map->apply(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::position, core::vec_id::read_access::position); + map->applyJ(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::velocity, core::vec_id::read_access::velocity); } } @@ -112,8 +112,8 @@ class RigidContactMapper : public BaseContactMapper if (mapping != nullptr) { core::BaseMapping* map = mapping.get(); - map->apply(core::mechanicalparams::defaultInstance(), core::VecCoordId::freePosition(), core::ConstVecCoordId::freePosition()); - map->applyJ(core::mechanicalparams::defaultInstance(), core::VecDerivId::freeVelocity(), core::ConstVecDerivId::freeVelocity()); + map->apply(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::freePosition, core::vec_id::read_access::freePosition); + map->applyJ(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::freeVelocity, core::vec_id::read_access::freeVelocity); } } }; diff --git a/Sofa/Component/Collision/Response/Mapper/src/sofa/component/collision/response/mapper/SubsetContactMapper.inl b/Sofa/Component/Collision/Response/Mapper/src/sofa/component/collision/response/mapper/SubsetContactMapper.inl index 5a65e4a1e30..1f10739cc07 100644 --- a/Sofa/Component/Collision/Response/Mapper/src/sofa/component/collision/response/mapper/SubsetContactMapper.inl +++ b/Sofa/Component/Collision/Response/Mapper/src/sofa/component/collision/response/mapper/SubsetContactMapper.inl @@ -110,7 +110,7 @@ typename SubsetContactMapper::Index SubsetContactMap } else { - helper::WriteAccessor > d_x = *outmodel->write(core::VecCoordId::position()); + helper::WriteAccessor > d_x = *outmodel->write(core::vec_id::write_access::position); VecCoord& x = d_x.wref(); x[i] = P; } @@ -128,8 +128,8 @@ void SubsetContactMapper::update() needInit = false; } core::BaseMapping* map = mapping.get(); - map->apply(core::mechanicalparams::defaultInstance(), core::VecCoordId::position(), core::ConstVecCoordId::position()); - map->applyJ(core::mechanicalparams::defaultInstance(), core::VecDerivId::velocity(), core::ConstVecDerivId::velocity()); + map->apply(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::position, core::vec_id::read_access::position); + map->applyJ(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::velocity, core::vec_id::read_access::velocity); } } @@ -145,7 +145,7 @@ void SubsetContactMapper::updateXfree() } core::BaseMapping* map = mapping.get(); - map->apply(core::mechanicalparams::defaultInstance(), core::VecCoordId::freePosition(), core::ConstVecCoordId::freePosition()); + map->apply(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::freePosition, core::vec_id::read_access::freePosition); } } diff --git a/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/GenericConstraintCorrection.cpp b/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/GenericConstraintCorrection.cpp index fddcc8fde5c..9250a7f9a21 100644 --- a/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/GenericConstraintCorrection.cpp +++ b/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/GenericConstraintCorrection.cpp @@ -235,7 +235,7 @@ void GenericConstraintCorrection::applyContactForce(const BaseVector *f) computeMotionCorrectionFromLambda(&cparams, cparams.dx(), f); - applyMotionCorrection(&cparams, VecCoordId::position(), VecDerivId::velocity(), cparams.dx(), cparams.lambda()); + applyMotionCorrection(&cparams, core::vec_id::write_access::position, core::vec_id::write_access::velocity, cparams.dx(), cparams.lambda()); } void GenericConstraintCorrection::computeResidual(const ExecParams* params, linearalgebra::BaseVector *lambda) diff --git a/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/LinearSolverConstraintCorrection.inl b/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/LinearSolverConstraintCorrection.inl index c29e6e20a98..098fe526ef0 100644 --- a/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/LinearSolverConstraintCorrection.inl +++ b/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/LinearSolverConstraintCorrection.inl @@ -329,7 +329,7 @@ template void LinearSolverConstraintCorrection::applyContactForce(const linearalgebra::BaseVector *f) { core::VecDerivId forceID(core::VecDerivId::V_FIRST_DYNAMIC_INDEX); - core::VecDerivId dxID = core::VecDerivId::dx(); + core::VecDerivId dxID = core::vec_id::write_access::dx; const unsigned int numDOFs = mstate->getSize(); @@ -349,7 +349,7 @@ void LinearSolverConstraintCorrection::applyContactForce(const linear for (unsigned int i=0; i< numDOFs; i++) force[i] = Deriv(); - const MatrixDeriv& c = mstate->read(core::ConstMatrixDerivId::constraintJacobian())->getValue(); + const MatrixDeriv& c = mstate->read(core::vec_id::read_access::constraintJacobian)->getValue(); MatrixDerivRowConstIterator rowItEnd = c.end(); @@ -379,10 +379,10 @@ void LinearSolverConstraintCorrection::applyContactForce(const linear // use the OdeSolver to get the position integration factor const SReal velocityFactor = l_ODESolver.get()->getVelocityIntegrationFactor(); - Data& xData = *mstate->write(core::VecCoordId::position()); - Data& vData = *mstate->write(core::VecDerivId::velocity()); - const Data & xfreeData = *mstate->read(core::ConstVecCoordId::freePosition()); - const Data & vfreeData = *mstate->read(core::ConstVecDerivId::freeVelocity()); + Data& xData = *mstate->write(core::vec_id::write_access::position); + Data& vData = *mstate->write(core::vec_id::write_access::velocity); + const Data & xfreeData = *mstate->read(core::vec_id::read_access::freePosition); + const Data & vfreeData = *mstate->read(core::vec_id::read_access::freeVelocity); VecCoord& x = *xData.beginEdit(); VecDeriv& v = *vData.beginEdit(); const VecCoord& x_free = xfreeData.getValue(); @@ -414,7 +414,7 @@ void LinearSolverConstraintCorrection::applyContactForce(const linear template void LinearSolverConstraintCorrection::resetContactForce() { - Data& forceData = *mstate->write(core::VecDerivId::force()); + Data& forceData = *mstate->write(core::vec_id::write_access::force); VecDeriv& force = *forceData.beginEdit(); for( unsigned i=0; i::resetContactForce() template bool LinearSolverConstraintCorrection::hasConstraintNumber(int index) { - const MatrixDeriv& c = mstate->read(core::ConstMatrixDerivId::constraintJacobian())->getValue(); + const MatrixDeriv& c = mstate->read(core::vec_id::read_access::constraintJacobian)->getValue(); return c.readLine(index) != c.end(); } @@ -442,7 +442,7 @@ void LinearSolverConstraintCorrection::resetForUnbuiltResolution(SRea { verify_constraints(); - const MatrixDeriv& constraints = mstate->read(core::ConstMatrixDerivId::constraintJacobian())->getValue(); + const MatrixDeriv& constraints = mstate->read(core::vec_id::read_access::constraintJacobian)->getValue(); constraint_force.clear(); constraint_force.resize(mstate->getSize()); @@ -535,7 +535,7 @@ void LinearSolverConstraintCorrection::resetForUnbuiltResolution(SRea /////////////// SET INFO FOR LINEAR SOLVER ///////////// core::VecDerivId forceID(core::VecDerivId::V_FIRST_DYNAMIC_INDEX); - core::VecDerivId dxID = core::VecDerivId::dx(); + core::VecDerivId dxID = core::vec_id::write_access::dx; l_linearSolver->setSystemRHVector(forceID); l_linearSolver->setSystemLHVector(dxID); @@ -583,7 +583,7 @@ void LinearSolverConstraintCorrection::resetForUnbuiltResolution(SRea template void LinearSolverConstraintCorrection::addConstraintDisplacement(SReal*d, int begin, int end) { - const MatrixDeriv& constraints = mstate->read(core::ConstMatrixDerivId::constraintJacobian())->getValue(); + const MatrixDeriv& constraints = mstate->read(core::vec_id::read_access::constraintJacobian)->getValue(); last_disp = begin; @@ -652,7 +652,7 @@ void LinearSolverConstraintCorrection::setConstraintDForce(SReal* df, _new_force = true; constexpr const auto derivDim = Deriv::total_size; - const MatrixDeriv& constraints = mstate->read(core::ConstMatrixDerivId::constraintJacobian())->getValue(); + const MatrixDeriv& constraints = mstate->read(core::vec_id::read_access::constraintJacobian)->getValue(); // TODO => optimisation !!! for (int i = begin; i <= end; i++) @@ -699,7 +699,7 @@ void LinearSolverConstraintCorrection::getBlockDiagonalCompliance(lin const unsigned int numDOFReals = numDOFs * N; // Compute J - const MatrixDeriv& constraints = mstate->read(core::ConstMatrixDerivId::constraintJacobian())->getValue(); + const MatrixDeriv& constraints = mstate->read(core::vec_id::read_access::constraintJacobian)->getValue(); const sofa::SignedIndex totalNumConstraints = W->rowSize(); m_constraintJacobian.resize(totalNumConstraints, numDOFReals); diff --git a/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/PrecomputedConstraintCorrection.cpp b/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/PrecomputedConstraintCorrection.cpp index 9a69337d036..986cefd554e 100644 --- a/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/PrecomputedConstraintCorrection.cpp +++ b/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/PrecomputedConstraintCorrection.cpp @@ -32,9 +32,9 @@ namespace sofa::component::constraint::lagrangian::correction template<> SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_CORRECTION_API void PrecomputedConstraintCorrection< defaulttype::Rigid3Types >::rotateConstraints(bool back) { - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& x0 = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); - helper::WriteAccessor > cData = *this->mstate->write(core::MatrixDerivId::constraintJacobian()); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& x0 = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); + helper::WriteAccessor > cData = *this->mstate->write(core::vec_id::write_access::constraintJacobian); MatrixDeriv& c = cData.wref(); // On fait tourner les normales (en les ramenant dans le "pseudo" repere initial) @@ -84,10 +84,10 @@ SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_CORRECTION_API void PrecomputedConstraintCo template<> SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_CORRECTION_API void PrecomputedConstraintCorrection::rotateResponse() { - helper::WriteAccessor > dxData = *this->mstate->write(core::VecDerivId::dx()); + helper::WriteAccessor > dxData = *this->mstate->write(core::vec_id::write_access::dx); VecDeriv& dx = dxData.wref(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& x0 = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& x0 = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); for(unsigned int j = 0; j < dx.size(); j++) { // on passe les deplacements du repere local (au repos) au repere global diff --git a/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/PrecomputedConstraintCorrection.inl b/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/PrecomputedConstraintCorrection.inl index 5a500629730..252f807c20f 100644 --- a/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/PrecomputedConstraintCorrection.inl +++ b/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/PrecomputedConstraintCorrection.inl @@ -220,7 +220,7 @@ void PrecomputedConstraintCorrection::bwdInit() { Inherit::init(); - const VecDeriv& v0 = this->mstate->read(core::ConstVecDerivId::velocity())->getValue(); + const VecDeriv& v0 = this->mstate->read(core::vec_id::read_access::velocity)->getValue(); nbNodes = v0.size(); @@ -309,14 +309,14 @@ void PrecomputedConstraintCorrection::bwdInit() } - helper::ReadAccessor< Data< VecCoord > > rposData = *this->mstate->read(core::ConstVecCoordId::position()); + helper::ReadAccessor< Data< VecCoord > > rposData = *this->mstate->read(core::vec_id::read_access::position); const VecCoord prev_pos = rposData.ref(); - helper::WriteAccessor< Data< VecDeriv > > velocityData = *this->mstate->write(core::VecDerivId::velocity()); + helper::WriteAccessor< Data< VecDeriv > > velocityData = *this->mstate->write(core::vec_id::write_access::velocity); VecDeriv& velocity = velocityData.wref(); const VecDeriv prev_velocity = velocity; - helper::WriteAccessor< Data< VecDeriv > > forceData = *this->mstate->write(core::VecDerivId::externalForce()); + helper::WriteAccessor< Data< VecDeriv > > forceData = *this->mstate->write(core::vec_id::write_access::externalForce); VecDeriv& force = forceData.wref(); force.clear(); force.resize(nbNodes); @@ -325,7 +325,7 @@ void PrecomputedConstraintCorrection::bwdInit() /// (avoid to have a line of 0 at the top of the matrix) if (eulerSolver) { - eulerSolver->solve(core::execparams::defaultInstance(), dt, core::VecCoordId::position(), core::VecDerivId::velocity()); + eulerSolver->solve(core::execparams::defaultInstance(), dt, core::vec_id::write_access::position, core::vec_id::write_access::velocity); } Deriv unitary_force; @@ -348,7 +348,7 @@ void PrecomputedConstraintCorrection::bwdInit() velocity.resize(nbNodes); // Actualize ref to the position vector ; it seems it is changed at every eulerSolver->solve() - helper::WriteOnlyAccessor< Data< VecCoord > > wposData = *this->mstate->write(core::VecCoordId::position()); + helper::WriteOnlyAccessor< Data< VecCoord > > wposData = *this->mstate->write(core::vec_id::write_access::position); VecCoord& pos = wposData.wref(); for (unsigned int n = 0; n < nbNodes; n++) @@ -360,7 +360,7 @@ void PrecomputedConstraintCorrection::bwdInit() { fact *= eulerSolver->getPositionIntegrationFactor(); // here, we compute a compliance - eulerSolver->solve(core::execparams::defaultInstance(), dt, core::VecCoordId::position(), core::VecDerivId::velocity()); + eulerSolver->solve(core::execparams::defaultInstance(), dt, core::vec_id::write_access::position, core::vec_id::write_access::velocity); if (linearSolver) linearSolver->freezeSystemMatrix(); // do not recompute the matrix for the rest of the precomputation @@ -401,7 +401,7 @@ void PrecomputedConstraintCorrection::bwdInit() for (unsigned int i = 0; i < velocity.size(); i++) velocity[i] = prev_velocity[i]; - helper::WriteOnlyAccessor< Data< VecCoord > > wposData = *this->mstate->write(core::VecCoordId::position()); + helper::WriteOnlyAccessor< Data< VecCoord > > wposData = *this->mstate->write(core::vec_id::write_access::position); VecCoord& pos = wposData.wref(); // Restore position @@ -672,7 +672,7 @@ void PrecomputedConstraintCorrection::applyVelocityCorrection(const s auto dv = sofa::helper::getWriteAccessor(dv_d); VecDeriv& v = *v_d.beginEdit(); - const VecDeriv& dx = this->mstate->read(core::VecDerivId::dx())->getValue(); + const VecDeriv& dx = this->mstate->read(core::vec_id::write_access::dx)->getValue(); const VecDeriv& v_free = cparams->readV(this->mstate)->getValue(); const SReal invDt = 1.0_sreal / this->getContext()->getDt(); @@ -693,18 +693,18 @@ void PrecomputedConstraintCorrection::applyVelocityCorrection(const s template void PrecomputedConstraintCorrection::applyContactForce(const linearalgebra::BaseVector *f) { - helper::WriteAccessor > forceData = *this->mstate->write(core::VecDerivId::force()); - helper::WriteAccessor > dxData = *this->mstate->write(core::VecDerivId::dx()); - helper::WriteAccessor > xData = *this->mstate->write(core::VecCoordId::position()); - helper::WriteAccessor > vData = *this->mstate->write(core::VecDerivId::velocity()); + helper::WriteAccessor > forceData = *this->mstate->write(core::vec_id::write_access::force); + helper::WriteAccessor > dxData = *this->mstate->write(core::vec_id::write_access::dx); + helper::WriteAccessor > xData = *this->mstate->write(core::vec_id::write_access::position); + helper::WriteAccessor > vData = *this->mstate->write(core::vec_id::write_access::velocity); VecDeriv& force = forceData.wref(); VecDeriv& dx = dxData.wref(); VecCoord& x = xData.wref(); VecDeriv& v = vData.wref(); - const VecDeriv& v_free = this->mstate->read(core::ConstVecDerivId::freeVelocity())->getValue(); - const VecCoord& x_free = this->mstate->read(core::ConstVecCoordId::freePosition())->getValue(); - const MatrixDeriv& c = this->mstate->read(core::ConstMatrixDerivId::constraintJacobian())->getValue(); + const VecDeriv& v_free = this->mstate->read(core::vec_id::read_access::freeVelocity)->getValue(); + const VecCoord& x_free = this->mstate->read(core::vec_id::read_access::freePosition)->getValue(); + const MatrixDeriv& c = this->mstate->read(core::vec_id::read_access::constraintJacobian)->getValue(); const SReal dt = this->getContext()->getDt(); @@ -797,7 +797,7 @@ void PrecomputedConstraintCorrection::getComplianceMatrix(linearalgeb template void PrecomputedConstraintCorrection::resetContactForce() { - helper::WriteAccessor > forceData = *this->mstate->write(core::VecDerivId::force()); + helper::WriteAccessor > forceData = *this->mstate->write(core::vec_id::write_access::force); VecDeriv& force = forceData.wref(); for( unsigned i=0; i::draw(const core::visual::Visu } } - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); const auto& rotations = rotationFinder->getRotations(); for (unsigned int i=0; i< x.size(); i++) { @@ -858,7 +858,7 @@ void PrecomputedConstraintCorrection< DataTypes >::rotateConstraints(bool back) { using sofa::core::behavior::RotationFinder; - helper::WriteAccessor > cData = *this->mstate->write(core::MatrixDerivId::constraintJacobian()); + helper::WriteAccessor > cData = *this->mstate->write(core::vec_id::write_access::constraintJacobian); MatrixDeriv& c = cData.wref(); const simulation::Node *node = dynamic_cast< simulation::Node * >(this->getContext()); @@ -934,7 +934,7 @@ void PrecomputedConstraintCorrection::rotateResponse() return; } - helper::WriteAccessor > dxData = *this->mstate->write(core::VecDerivId::dx()); + helper::WriteAccessor > dxData = *this->mstate->write(core::vec_id::write_access::dx); VecDeriv& dx = dxData.wref(); const auto& rotations = rotationFinder->getRotations(); @@ -951,7 +951,7 @@ template void PrecomputedConstraintCorrection::resetForUnbuiltResolution(SReal* f, std::list& /*renumbering*/) { constraint_force = f; - const MatrixDeriv& c = this->mstate->read(core::ConstMatrixDerivId::constraintJacobian())->getValue(); + const MatrixDeriv& c = this->mstate->read(core::vec_id::read_access::constraintJacobian)->getValue(); #ifdef NEW_METHOD_UNBUILT constraint_D.clear(); diff --git a/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/UncoupledConstraintCorrection.inl b/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/UncoupledConstraintCorrection.inl index 698e9883a49..bffe28596b2 100644 --- a/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/UncoupledConstraintCorrection.inl +++ b/Sofa/Component/Constraint/Lagrangian/Correction/src/sofa/component/constraint/lagrangian/correction/UncoupledConstraintCorrection.inl @@ -196,7 +196,7 @@ void UncoupledConstraintCorrection::init() msg_warning() << "Neither the \'defaultCompliance\' nor the \'compliance\' data is set, please set one to define your compliance matrix"; } - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); if (d_compliance.getValue().size() == 1 && d_defaultCompliance.isSet() && d_defaultCompliance.getValue() == d_compliance.getValue()[0]) { @@ -289,7 +289,7 @@ void UncoupledConstraintCorrection::getComplianceWithConstraintMerge( if(!this->isComponentStateValid()) return; - helper::WriteAccessor > constraintsData = *this->mstate->write(core::MatrixDerivId::constraintJacobian()); + helper::WriteAccessor > constraintsData = *this->mstate->write(core::vec_id::write_access::constraintJacobian); MatrixDeriv& constraints = constraintsData.wref(); MatrixDeriv constraintCopy; @@ -622,13 +622,13 @@ void UncoupledConstraintCorrection::applyContactForce(const linearalg if(!this->isComponentStateValid()) return; - helper::WriteAccessor > forceData = *this->mstate->write(core::VecDerivId::externalForce()); + helper::WriteAccessor > forceData = *this->mstate->write(core::vec_id::write_access::externalForce); VecDeriv& force = forceData.wref(); - const MatrixDeriv& constraints = this->mstate->read(core::ConstMatrixDerivId::constraintJacobian())->getValue(); + const MatrixDeriv& constraints = this->mstate->read(core::vec_id::read_access::constraintJacobian)->getValue(); const VecReal& comp = d_compliance.getValue(); const Real comp0 = d_defaultCompliance.getValue(); - force.resize((this->mstate->read(core::ConstVecCoordId::position())->getValue()).size()); + force.resize((this->mstate->read(core::vec_id::read_access::position)->getValue()).size()); MatrixDerivRowConstIterator rowItEnd = constraints.end(); @@ -648,14 +648,14 @@ void UncoupledConstraintCorrection::applyContactForce(const linearalg } - helper::WriteAccessor > dxData = *this->mstate->write(core::VecDerivId::dx()); + helper::WriteAccessor > dxData = *this->mstate->write(core::vec_id::write_access::dx); VecDeriv& dx = dxData.wref(); - helper::WriteAccessor > xData = *this->mstate->write(core::VecCoordId::position()); + helper::WriteAccessor > xData = *this->mstate->write(core::vec_id::write_access::position); VecCoord& x = xData.wref(); - helper::WriteAccessor > vData = *this->mstate->write(core::VecDerivId::velocity()); + helper::WriteAccessor > vData = *this->mstate->write(core::vec_id::write_access::velocity); VecDeriv& v = vData.wref(); - const VecDeriv& v_free = this->mstate->read(core::ConstVecDerivId::freeVelocity())->getValue(); - const VecCoord& x_free = this->mstate->read(core::ConstVecCoordId::freePosition())->getValue(); + const VecDeriv& v_free = this->mstate->read(core::vec_id::read_access::freeVelocity)->getValue(); + const VecCoord& x_free = this->mstate->read(core::vec_id::read_access::freePosition)->getValue(); const bool useOdeIntegrationFactors = d_useOdeSolverIntegrationFactors.getValue(); @@ -683,7 +683,7 @@ void UncoupledConstraintCorrection::applyContactForce(const linearalg template void UncoupledConstraintCorrection::resetContactForce() { - helper::WriteAccessor > forceData = *this->mstate->write(core::VecDerivId::externalForce()); + helper::WriteAccessor > forceData = *this->mstate->write(core::vec_id::write_access::externalForce); VecDeriv& force = forceData.wref(); for (unsigned i = 0; i < force.size(); ++i) @@ -697,7 +697,7 @@ void UncoupledConstraintCorrection::resetContactForce() template bool UncoupledConstraintCorrection::hasConstraintNumber(int index) { - const MatrixDeriv &constraints = this->mstate->read(core::ConstMatrixDerivId::constraintJacobian())->getValue(); + const MatrixDeriv &constraints = this->mstate->read(core::vec_id::read_access::constraintJacobian)->getValue(); return (constraints.readLine(index) != constraints.end()); } @@ -706,7 +706,7 @@ bool UncoupledConstraintCorrection::hasConstraintNumber(int index) template void UncoupledConstraintCorrection::resetForUnbuiltResolution(SReal * f, std::list& /*renumbering*/) { - const MatrixDeriv& constraints = this->mstate->read(core::ConstMatrixDerivId::constraintJacobian())->getValue(); + const MatrixDeriv& constraints = this->mstate->read(core::vec_id::read_access::constraintJacobian)->getValue(); constraint_disp.clear(); constraint_disp.resize(this->mstate->getSize()); @@ -753,7 +753,7 @@ void UncoupledConstraintCorrection::addConstraintDisplacement(SReal * if(!this->isComponentStateValid()) return; - const MatrixDeriv& constraints = this->mstate->read(core::ConstMatrixDerivId::constraintJacobian())->getValue(); + const MatrixDeriv& constraints = this->mstate->read(core::vec_id::read_access::constraintJacobian)->getValue(); for (int id = begin; id <= end; id++) { @@ -783,7 +783,7 @@ void UncoupledConstraintCorrection::setConstraintDForce(SReal * df, i /// if update is true, it computes the displacements due to this delta of force. /// As the contact are uncoupled, a displacement is obtained only on dof involved with the constraints - const MatrixDeriv& constraints = this->mstate->read(core::ConstMatrixDerivId::constraintJacobian())->getValue(); + const MatrixDeriv& constraints = this->mstate->read(core::vec_id::read_access::constraintJacobian)->getValue(); const VecReal& comp = d_compliance.getValue(); const Real comp0 = d_defaultCompliance.getValue(); @@ -820,7 +820,7 @@ void UncoupledConstraintCorrection::setConstraintDForce(SReal * df, i template void UncoupledConstraintCorrection::getBlockDiagonalCompliance(linearalgebra::BaseMatrix* W, int begin, int end) { - const MatrixDeriv& constraints = this->mstate->read(core::ConstMatrixDerivId::constraintJacobian())->getValue(); + const MatrixDeriv& constraints = this->mstate->read(core::vec_id::read_access::constraintJacobian)->getValue(); const VecReal& comp = d_compliance.getValue(); const Real comp0 = d_defaultCompliance.getValue(); diff --git a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BaseContactLagrangianConstraint.inl b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BaseContactLagrangianConstraint.inl index e18da5a21e5..859bd281c5d 100644 --- a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BaseContactLagrangianConstraint.inl +++ b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BaseContactLagrangianConstraint.inl @@ -57,8 +57,8 @@ template void BaseContactLagrangianConstraint::addContact(const ContactParams& parameters, Deriv norm, Coord P, Coord Q, Real contactDistance, int m1, int m2, long id, PersistentID localid) { addContact(parameters, norm, P, Q, contactDistance, m1, m2, - this->getMState2()->read(core::ConstVecCoordId::freePosition())->getValue()[m2], - this->getMState1()->read(core::ConstVecCoordId::freePosition())->getValue()[m1], + this->getMState2()->read(core::vec_id::read_access::freePosition)->getValue()[m2], + this->getMState1()->read(core::vec_id::read_access::freePosition)->getValue()[m1], id, localid); } @@ -66,11 +66,11 @@ template void BaseContactLagrangianConstraint::addContact(const ContactParams& parameters, Deriv norm, Real contactDistance, int m1, int m2, long id, PersistentID localid) { addContact(parameters, norm, - this->getMState2()->read(core::ConstVecCoordId::position())->getValue()[m2], - this->getMState1()->read(core::ConstVecCoordId::position())->getValue()[m1], + this->getMState2()->read(core::vec_id::read_access::position)->getValue()[m2], + this->getMState1()->read(core::vec_id::read_access::position)->getValue()[m1], contactDistance, m1, m2, - this->getMState2()->read(core::ConstVecCoordId::freePosition())->getValue()[m2], - this->getMState1()->read(core::ConstVecCoordId::freePosition())->getValue()[m1], + this->getMState2()->read(core::vec_id::read_access::freePosition)->getValue()[m2], + this->getMState1()->read(core::vec_id::read_access::freePosition)->getValue()[m1], id, localid); } @@ -176,8 +176,8 @@ void BaseContactLagrangianConstraint::buildConstraintM template void BaseContactLagrangianConstraint::getPositionViolation(linearalgebra::BaseVector *v) { - const VecCoord &PfreeVec = this->getMState2()->read(core::ConstVecCoordId::freePosition())->getValue(); - const VecCoord &QfreeVec = this->getMState1()->read(core::ConstVecCoordId::freePosition())->getValue(); + const VecCoord &PfreeVec = this->getMState2()->read(core::vec_id::read_access::freePosition)->getValue(); + const VecCoord &QfreeVec = this->getMState1()->read(core::vec_id::read_access::freePosition)->getValue(); Real dfree = (Real)0.0; Real dfree_t = (Real)0.0; @@ -262,8 +262,8 @@ void BaseContactLagrangianConstraint::getVelocityViola const SReal dt = this->getContext()->getDt(); const SReal invDt = SReal(1.0) / dt; - const VecDeriv &PvfreeVec = this->getMState2()->read(core::ConstVecDerivId::freeVelocity())->getValue(); - const VecDeriv &QvfreeVec = this->getMState1()->read(core::ConstVecDerivId::freeVelocity())->getValue(); + const VecDeriv &PvfreeVec = this->getMState2()->read(core::vec_id::read_access::freeVelocity)->getValue(); + const VecDeriv &QvfreeVec = this->getMState1()->read(core::vec_id::read_access::freeVelocity)->getValue(); const unsigned int cSize = contacts.size(); diff --git a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralLagrangianConstraint.cpp b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralLagrangianConstraint.cpp index e6932abfdae..a1f07d3db8c 100644 --- a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralLagrangianConstraint.cpp +++ b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralLagrangianConstraint.cpp @@ -37,33 +37,37 @@ class BilateralLagrangianConstraintSpecialization { public: + template + using SubsetIndices = typename BilateralLagrangianConstraint::SubsetIndices; + + template static void bwdInit(BilateralLagrangianConstraint& self) { if (!self.d_keepOrientDiff.getValue()) return; - helper::WriteAccessor::VecDeriv > > wrest = self.d_restVector; + auto wrest = sofa::helper::getWriteAccessor(self.d_restVector); - if (wrest.size() > 0) { - msg_warning("BilateralLagrangianConstraintSpecialization") << "keepOrientationDifference is activated, rest_vector will be ignored! " ; + if (!wrest.empty()) { + msg_warning(&self) << "keepOrientationDifference is activated, rest_vector will be ignored! " ; wrest.resize(0); } - const typename BilateralLagrangianConstraint::SubsetIndices& m1Indices = self.d_m1.getValue(); - const typename BilateralLagrangianConstraint::SubsetIndices& m2Indices = self.d_m2.getValue(); + const SubsetIndices& m1Indices = self.d_m1.getValue(); + const SubsetIndices& m2Indices = self.d_m2.getValue(); const unsigned minp = std::min(m1Indices.size(),m2Indices.size()); - const typename BilateralLagrangianConstraint::DataVecCoord &d_x1 = *self.mstate1->read(core::ConstVecCoordId::position()); - const typename BilateralLagrangianConstraint::DataVecCoord &d_x2 = *self.mstate2->read(core::ConstVecCoordId::position()); + const DataVecCoord_t &d_x1 = *self.mstate1->read(core::vec_id::read_access::position); + const DataVecCoord_t &d_x2 = *self.mstate2->read(core::vec_id::read_access::position); - const typename BilateralLagrangianConstraint::VecCoord &x1 = d_x1.getValue(); - const typename BilateralLagrangianConstraint::VecCoord &x2 = d_x2.getValue(); + const VecCoord_t &x1 = d_x1.getValue(); + const VecCoord_t &x2 = d_x2.getValue(); for (unsigned pid=0; pid::Coord P = x1[m1Indices[pid]]; - const typename BilateralLagrangianConstraint::Coord Q = x2[m2Indices[pid]]; + const Coord_t P = x1[m1Indices[pid]]; + const Coord_t Q = x2[m2Indices[pid]]; type::Quat qP, qQ, dQP; qP = P.getOrientation(); @@ -73,7 +77,7 @@ class BilateralLagrangianConstraintSpecialization dQP = qP.quatDiff(qQ, qP); dQP.normalize(); - typename BilateralLagrangianConstraint::Coord df; + Coord_t df; df.getCenter() = Q.getCenter() - P.getCenter(); df.getOrientation() = dQP; self.initialDifference.push_back(df); @@ -86,12 +90,12 @@ class BilateralLagrangianConstraintSpecialization static void getConstraintResolution(BilateralLagrangianConstraint& self, const ConstraintParams* cParams, std::vector& resTab, - unsigned int& offset, double tolerance) + unsigned int& offset, SReal tolerance) { SOFA_UNUSED(cParams); - const unsigned minp=std::min(self.d_m1.getValue().size(), - self.d_m2.getValue().size()); - for (unsigned pid=0; pid template static void buildConstraintMatrix(BilateralLagrangianConstraint& self, const ConstraintParams* cParams, - typename BilateralLagrangianConstraint::DataMatrixDeriv &c1_d, - typename BilateralLagrangianConstraint::DataMatrixDeriv &c2_d, + DataMatrixDeriv_t &c1_d, + DataMatrixDeriv_t &c2_d, unsigned int &constraintId, - const typename BilateralLagrangianConstraint::DataVecCoord &/*x1*/, - const typename BilateralLagrangianConstraint::DataVecCoord &/*x2*/) + const DataVecCoord_t &/*x1*/, + const DataVecCoord_t &/*x2*/) { SOFA_UNUSED(cParams) ; - const typename BilateralLagrangianConstraint::SubsetIndices& m1Indices = self.d_m1.getValue(); - const typename BilateralLagrangianConstraint::SubsetIndices& m2Indices = self.d_m2.getValue(); + const SubsetIndices& m1Indices = self.d_m1.getValue(); + const SubsetIndices& m2Indices = self.d_m2.getValue(); unsigned minp = std::min(m1Indices.size(),m2Indices.size()); self.cid.resize(minp); - typename BilateralLagrangianConstraint::MatrixDeriv &c1 = *c1_d.beginEdit(); - typename BilateralLagrangianConstraint::MatrixDeriv &c2 = *c2_d.beginEdit(); + auto c1 = sofa::helper::getWriteAccessor(c1_d); + auto c2 = sofa::helper::getWriteAccessor(c2_d); - const Vec<3, typename BilateralLagrangianConstraint::Real> cx(1,0,0), cy(0,1,0), cz(0,0,1); - const Vec<3, typename BilateralLagrangianConstraint::Real> vZero(0,0,0); + static constexpr Vec<3, Real_t> cx(1,0,0), cy(0,1,0), cz(0,0,1); + static constexpr Vec<3, Real_t> vZero(0,0,0); - for (unsigned pid=0; pid constraintId += 6; //Apply constraint for position - typename BilateralLagrangianConstraint::MatrixDerivRowIterator c1_it = c1.writeLine(self.cid[pid]); - c1_it.addCol(tm1, typename BilateralLagrangianConstraint::Deriv(-cx, vZero)); + auto c1_it = c1->writeLine(self.cid[pid]); + c1_it.addCol(tm1, Deriv_t(-cx, vZero)); - typename BilateralLagrangianConstraint::MatrixDerivRowIterator c2_it = c2.writeLine(self.cid[pid]); - c2_it.addCol(tm2, typename BilateralLagrangianConstraint::Deriv(cx, vZero)); + auto c2_it = c2->writeLine(self.cid[pid]); + c2_it.addCol(tm2, Deriv_t(cx, vZero)); - c1_it = c1.writeLine(self.cid[pid] + 1); - c1_it.setCol(tm1, typename BilateralLagrangianConstraint::Deriv(-cy, vZero)); + c1_it = c1->writeLine(self.cid[pid] + 1); + c1_it.setCol(tm1, Deriv_t(-cy, vZero)); - c2_it = c2.writeLine(self.cid[pid] + 1); - c2_it.setCol(tm2, typename BilateralLagrangianConstraint::Deriv(cy, vZero)); + c2_it = c2->writeLine(self.cid[pid] + 1); + c2_it.setCol(tm2, Deriv_t(cy, vZero)); - c1_it = c1.writeLine(self.cid[pid] + 2); - c1_it.setCol(tm1, typename BilateralLagrangianConstraint::Deriv(-cz, vZero)); + c1_it = c1->writeLine(self.cid[pid] + 2); + c1_it.setCol(tm1, Deriv_t(-cz, vZero)); - c2_it = c2.writeLine(self.cid[pid] + 2); - c2_it.setCol(tm2, typename BilateralLagrangianConstraint::Deriv(cz, vZero)); + c2_it = c2->writeLine(self.cid[pid] + 2); + c2_it.setCol(tm2, Deriv_t(cz, vZero)); //Apply constraint for orientation - c1_it = c1.writeLine(self.cid[pid] + 3); - c1_it.setCol(tm1, typename BilateralLagrangianConstraint::Deriv(vZero, -cx)); + c1_it = c1->writeLine(self.cid[pid] + 3); + c1_it.setCol(tm1, Deriv_t(vZero, -cx)); - c2_it = c2.writeLine(self.cid[pid] + 3); - c2_it.setCol(tm2, typename BilateralLagrangianConstraint::Deriv(vZero, cx)); + c2_it = c2->writeLine(self.cid[pid] + 3); + c2_it.setCol(tm2, Deriv_t(vZero, cx)); - c1_it = c1.writeLine(self.cid[pid] + 4); - c1_it.setCol(tm1, typename BilateralLagrangianConstraint::Deriv(vZero, -cy)); + c1_it = c1->writeLine(self.cid[pid] + 4); + c1_it.setCol(tm1, Deriv_t(vZero, -cy)); - c2_it = c2.writeLine(self.cid[pid] + 4); - c2_it.setCol(tm2, typename BilateralLagrangianConstraint::Deriv(vZero, cy)); + c2_it = c2->writeLine(self.cid[pid] + 4); + c2_it.setCol(tm2, Deriv_t(vZero, cy)); - c1_it = c1.writeLine(self.cid[pid] + 5); - c1_it.setCol(tm1, typename BilateralLagrangianConstraint::Deriv(vZero, -cz)); + c1_it = c1->writeLine(self.cid[pid] + 5); + c1_it.setCol(tm1, Deriv_t(vZero, -cz)); - c2_it = c2.writeLine(self.cid[pid] + 5); - c2_it.setCol(tm2, typename BilateralLagrangianConstraint::Deriv(vZero, cz)); + c2_it = c2->writeLine(self.cid[pid] + 5); + c2_it.setCol(tm2, Deriv_t(vZero, cz)); } - - c1_d.endEdit(); - c2_d.endEdit(); } @@ -190,41 +191,45 @@ class BilateralLagrangianConstraintSpecialization const typename BilateralLagrangianConstraint::SubsetIndices& m2Indices = self.d_m2.getValue(); unsigned min = std::min(m1Indices.size(), m2Indices.size()); - const typename BilateralLagrangianConstraint::VecDeriv& restVector = self.d_restVector.getValue(); - self.dfree.resize(min); + const VecDeriv_t& restVector = self.d_restVector.getValue(); + self.m_violation.resize(min); - const typename BilateralLagrangianConstraint::VecCoord &x1 = d_x1.getValue(); - const typename BilateralLagrangianConstraint::VecCoord &x2 = d_x2.getValue(); + const VecCoord_t &x1 = d_x1.getValue(); + const VecCoord_t &x2 = d_x2.getValue(); - for (unsigned pid=0; pid::Coord dof1 = x1[m1Indices[pid]]; - //typename BilateralLagrangianConstraint::Coord dof2 = x2[m2Indices[pid]]; - typename BilateralLagrangianConstraint::Coord dof1; + Coord_t dof1; - if (self.d_keepOrientDiff.getValue()) { - const typename BilateralLagrangianConstraint::Coord dof1c = x1[m1Indices[pid]]; + if (self.d_keepOrientDiff.getValue()) + { + const Coord_t dof1c = x1[m1Indices[pid]]; - typename BilateralLagrangianConstraint::Coord corr=self.initialDifference[pid]; - type::Quat df = corr.getOrientation(); - type::Quat o1 = dof1c.getOrientation(); - type::Quat ro1 = o1 * df; + Coord_t corr = self.initialDifference[pid]; + type::Quat> df = corr.getOrientation(); + type::Quat> o1 = dof1c.getOrientation(); + type::Quat> ro1 = o1 * df; - dof1.getCenter() = dof1c.getCenter() + corr.getCenter(); - dof1.getOrientation() = ro1; - } else - dof1 = x1[m1Indices[pid]]; + dof1.getCenter() = dof1c.getCenter() + corr.getCenter(); + dof1.getOrientation() = ro1; + } + else + { + dof1 = x1[m1Indices[pid]]; + } - const typename BilateralLagrangianConstraint::Coord dof2 = x2[m2Indices[pid]]; + const Coord_t dof2 = x2[m2Indices[pid]]; - getVCenter(self.dfree[pid]) = dof2.getCenter() - dof1.getCenter(); - getVOrientation(self.dfree[pid]) = dof1.rotate(self.q.angularDisplacement(dof2.getOrientation() , + getVCenter(self.m_violation[pid]) = dof2.getCenter() - dof1.getCenter(); + getVOrientation(self.m_violation[pid]) = dof1.rotate(self.q.angularDisplacement(dof2.getOrientation() , dof1.getOrientation())); // angularDisplacement compute the rotation vector btw the two quaternions if (pid < restVector.size()) - self.dfree[pid] -= restVector[pid]; + self.m_violation[pid] -= restVector[pid]; - for (unsigned int i=0 ; iset(self.cid[pid]+i, self.dfree[pid][i]); + for (unsigned int i = 0; i < self.m_violation[pid].size(); i++) + { + v->set(self.cid[pid]+i, self.m_violation[pid][i]); + } } } @@ -235,9 +240,9 @@ class BilateralLagrangianConstraintSpecialization typename MyClass::Real /*contactDistance*/, int m1, int m2, typename MyClass::Coord /*Pfree*/, typename MyClass::Coord /*Qfree*/, long /*id*/, typename MyClass::PersistentID /*localid*/) { - helper::WriteAccessor::SubsetIndices > > wm1 = self.d_m1; - helper::WriteAccessor::SubsetIndices > > wm2 = self.d_m2; - helper::WriteAccessor > wrest = self.d_restVector; + sofa::helper::WriteAccessor>> wm1 = self.d_m1; + sofa::helper::WriteAccessor>> wm2 = self.d_m2; + auto wrest = sofa::helper::WriteAccessor(self.d_restVector); wm1.push_back(m1); wm2.push_back(m2); @@ -249,25 +254,30 @@ class BilateralLagrangianConstraintSpecialization }; +using RigidBilateralLagrangianConstraint = BilateralLagrangianConstraintSpecialization; + template<> SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_MODEL_API -void BilateralLagrangianConstraint::init(){ +void BilateralLagrangianConstraint::init() +{ unspecializedInit() ; } template<> SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_MODEL_API -void BilateralLagrangianConstraint::bwdInit() { - BilateralLagrangianConstraintSpecialization::bwdInit(*this); +void BilateralLagrangianConstraint::bwdInit() +{ + RigidBilateralLagrangianConstraint::bwdInit(*this); } template<> SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_MODEL_API -void BilateralLagrangianConstraint::getConstraintResolution(const ConstraintParams* cParams, - std::vector& resTab, - unsigned int& offset) +void BilateralLagrangianConstraint::getConstraintResolution( + const ConstraintParams* cParams, + std::vector& resTab, + unsigned int& offset) { - BilateralLagrangianConstraintSpecialization::getConstraintResolution(*this, - cParams, resTab, offset, - d_numericalTolerance.getValue()) ; + RigidBilateralLagrangianConstraint::getConstraintResolution(*this, + cParams, resTab, offset, + d_numericalTolerance.getValue()); } template <> SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_MODEL_API @@ -277,9 +287,9 @@ void BilateralLagrangianConstraint::buildConstraintMatrix(const Con unsigned int &constraintId, const DataVecCoord &x1, const DataVecCoord &x2) { - BilateralLagrangianConstraintSpecialization::buildConstraintMatrix(*this, - cParams, c1_d, c2_d, constraintId, - x1, x2) ; + RigidBilateralLagrangianConstraint::buildConstraintMatrix(*this, + cParams, c1_d, c2_d, constraintId, + x1, x2); } @@ -289,9 +299,9 @@ void BilateralLagrangianConstraint::getConstraintViolation(const Co const DataVecCoord &d_x1, const DataVecCoord &d_x2, const DataVecDeriv &v1, const DataVecDeriv &v2) { - BilateralLagrangianConstraintSpecialization::getConstraintViolation(*this, - cParams, v, d_x1, d_x2, - v1, v2) ; + RigidBilateralLagrangianConstraint::getConstraintViolation(*this, + cParams, v, d_x1, d_x2, + v1, v2); } @@ -312,9 +322,10 @@ void BilateralLagrangianConstraint::addContact(Deriv n Coord Pfree, Coord Qfree, long id, PersistentID localid) { - BilateralLagrangianConstraintSpecialization::addContact(*this, - norm, P, Q, contactDistance, m1, m2, Pfree, Qfree, - id, localid) ; + RigidBilateralLagrangianConstraint::addContact(*this, + norm, P, Q, contactDistance, + m1, m2, Pfree, Qfree, + id, localid); } void registerBilateralLagrangianConstraint(sofa::core::ObjectFactory* factory) diff --git a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralLagrangianConstraint.h b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralLagrangianConstraint.h index 93a0aeff7c9..abc001ded95 100644 --- a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralLagrangianConstraint.h +++ b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralLagrangianConstraint.h @@ -45,7 +45,6 @@ namespace sofa::component::constraint::lagrangian::model using sofa::core::behavior::BaseConstraint ; using sofa::core::behavior::ConstraintResolution ; using sofa::core::behavior::PairInteractionConstraint ; -using sofa::core::objectmodel::Data ; using sofa::core::ConstraintParams ; using sofa::core::ConstVecCoordId; @@ -93,10 +92,11 @@ class BilateralLagrangianConstraint : public PairInteractionConstraint dfree; + sofa::type::vector m_violation; Quat q; std::vector cid; + SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA_IN_CONSTRAINT_LAGRANGIAN_MODEL() sofa::core::objectmodel::RenamedData > m1; @@ -114,7 +114,7 @@ class BilateralLagrangianConstraint : public PairInteractionConstraint d_restVector; ///< Relative position to maintain between attached points (optional) VecCoord initialDifference; - Data d_numericalTolerance; ///< a real value specifying the tolerance during the constraint solving. (default=0.0001 + Data d_numericalTolerance; ///< a real value specifying the tolerance during the constraint solving. (default=0.0001 Data d_activate; ///< control constraint activation (true by default) Data d_keepOrientDiff; ///< keep the initial difference in orientation (only for rigids) @@ -128,7 +128,8 @@ class BilateralLagrangianConstraint : public PairInteractionConstraint& resTab, - unsigned int& offset) override; + std::vector& resTab, + unsigned int& offset) override; void handleEvent(sofa::core::objectmodel::Event *event) override; @@ -189,6 +190,9 @@ class BilateralLagrangianConstraint : public PairInteractionConstraint SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_MODEL_API +void BilateralLagrangianConstraint::bwdInit(); + #if !defined(SOFA_COMPONENT_CONSTRAINTSET_BILATERALLAGRANGIANCONSTRAINT_CPP) extern template class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_MODEL_API BilateralLagrangianConstraint< Vec3Types >; diff --git a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralLagrangianConstraint.inl b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralLagrangianConstraint.inl index ad18a6ed7f7..28e5ddd9d19 100644 --- a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralLagrangianConstraint.inl +++ b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralLagrangianConstraint.inl @@ -44,8 +44,8 @@ BilateralLagrangianConstraint::BilateralLagrangianConstraint(Mechanic , d_m1(initData(&d_m1, "first_point","index of the constraint on the first model (object1)")) , d_m2(initData(&d_m2, "second_point","index of the constraint on the second model (object2)")) , d_restVector(initData(&d_restVector, "rest_vector","Relative position to maintain between attached points (optional)")) - , d_numericalTolerance(initData(&d_numericalTolerance, 0.0001, "numericalTolerance", - "a real value specifying the tolerance during the constraint solving. (optional, default=0.0001)") ) + , d_numericalTolerance(initData(&d_numericalTolerance, 1e-4_sreal, "numericalTolerance", + "a real value specifying the tolerance during the constraint solving.") ) , d_activate( initData(&d_activate, true, "activate", "control constraint activation (true by default)")) , d_keepOrientDiff(initData(&d_keepOrientDiff, false, "keepOrientationDifference", "keep the initial difference in orientation (only for rigids)")) , l_topology1(initLink("topology1", "link to the first topology container")) @@ -81,6 +81,11 @@ void BilateralLagrangianConstraint::unspecializedInit() assert(this->mstate1); assert(this->mstate2); + if (!this->mstate1 || !this->mstate2) + { + this->d_componentState.setValue(core::objectmodel::ComponentState::Invalid); + } + prevForces.clear(); } @@ -120,8 +125,10 @@ void BilateralLagrangianConstraint::reinit() template -void BilateralLagrangianConstraint::buildConstraintMatrix(const ConstraintParams*, DataMatrixDeriv &c1_d, DataMatrixDeriv &c2_d, unsigned int &constraintId - , const DataVecCoord &/*x1*/, const DataVecCoord &/*x2*/) +void BilateralLagrangianConstraint::buildConstraintMatrix( + const ConstraintParams*, DataMatrixDeriv& c1_d, DataMatrixDeriv& c2_d, + unsigned int& constraintId, + const DataVecCoord&/*x1*/, const DataVecCoord&/*x2*/) { if (!d_activate.getValue()) return; @@ -133,12 +140,12 @@ void BilateralLagrangianConstraint::buildConstraintMatrix(const Const const SubsetIndices& m1Indices = d_m1.getValue(); const SubsetIndices& m2Indices = d_m2.getValue(); - MatrixDeriv &c1 = *c1_d.beginEdit(); - MatrixDeriv &c2 = *c2_d.beginEdit(); + auto c1 = sofa::helper::getWriteAccessor(c1_d); + auto c2 = sofa::helper::getWriteAccessor(c2_d); cid.resize(minp); - for (unsigned pid=0; pid::buildConstraintMatrix(const Const cid[pid] = constraintId; constraintId += 3; - MatrixDerivRowIterator c1_it = c1.writeLine(cid[pid]); + MatrixDerivRowIterator c1_it = c1->writeLine(cid[pid]); c1_it.addCol(tm1, -cx); - MatrixDerivRowIterator c2_it = c2.writeLine(cid[pid]); + MatrixDerivRowIterator c2_it = c2->writeLine(cid[pid]); c2_it.addCol(tm2, cx); - c1_it = c1.writeLine(cid[pid] + 1); + c1_it = c1->writeLine(cid[pid] + 1); c1_it.setCol(tm1, -cy); - c2_it = c2.writeLine(cid[pid] + 1); + c2_it = c2->writeLine(cid[pid] + 1); c2_it.setCol(tm2, cy); - c1_it = c1.writeLine(cid[pid] + 2); + c1_it = c1->writeLine(cid[pid] + 2); c1_it.setCol(tm1, -cz); - c2_it = c2.writeLine(cid[pid] + 2); + c2_it = c2->writeLine(cid[pid] + 2); c2_it.setCol(tm2, cz); } - - c1_d.endEdit(); - c2_d.endEdit(); } template void BilateralLagrangianConstraint::getConstraintViolation(const ConstraintParams* cParams, - BaseVector *v, - const DataVecCoord &d_x1, const DataVecCoord &d_x2 - , const DataVecDeriv & d_v1, const DataVecDeriv & d_v2) + BaseVector* v, + const DataVecCoord& d_x1, const DataVecCoord& d_x2, + const DataVecDeriv& d_v1, const DataVecDeriv& d_v2) { if (!d_activate.getValue()) return; @@ -196,18 +200,20 @@ void BilateralLagrangianConstraint::getConstraintViolation(const Cons const VecCoord &x1 = d_x1.getValue(); const VecCoord &x2 = d_x2.getValue(); - dfree.resize(minp); + m_violation.resize(minp); - for (unsigned pid=0; pidset(cid[pid] , dfree[pid][0]); - v->set(cid[pid]+1, dfree[pid][1]); - v->set(cid[pid]+2, dfree[pid][2]); + v->set(cid[pid] , m_violation[pid][0]); + v->set(cid[pid]+1, m_violation[pid][1]); + v->set(cid[pid]+2, m_violation[pid][2]); } } @@ -235,7 +241,7 @@ void BilateralLagrangianConstraint::getVelocityViolation(BaseVector * auto pos2 = this->getMState2()->readPositions(); const SReal dt = this->getContext()->getDt(); - const SReal invDt = SReal(1.0) / dt; + const SReal invDt = 1_sreal / dt; for (unsigned pid=0; pid::addContact(Deriv norm, Coord P, C long id, PersistentID localid) { addContact(norm, P, Q, contactDistance, m1, m2, - this->getMState2()->read(ConstVecCoordId::freePosition())->getValue()[m2], - this->getMState1()->read(ConstVecCoordId::freePosition())->getValue()[m1], + this->getMState2()->read(core::vec_id::read_access::freePosition)->getValue()[m2], + this->getMState1()->read(core::vec_id::read_access::freePosition)->getValue()[m1], id, localid); } @@ -302,11 +308,11 @@ void BilateralLagrangianConstraint::addContact(Deriv norm, Real conta int m1, int m2, long id, PersistentID localid) { addContact(norm, - this->getMState2()->read(ConstVecCoordId::position())->getValue()[m2], - this->getMState1()->read(ConstVecCoordId::position())->getValue()[m1], + this->getMState2()->read(core::vec_id::read_access::position)->getValue()[m2], + this->getMState1()->read(core::vec_id::read_access::position)->getValue()[m1], contactDistance, m1, m2, - this->getMState2()->read(ConstVecCoordId::freePosition())->getValue()[m2], - this->getMState1()->read(ConstVecCoordId::freePosition())->getValue()[m1], + this->getMState2()->read(core::vec_id::read_access::freePosition)->getValue()[m2], + this->getMState1()->read(core::vec_id::read_access::freePosition)->getValue()[m1], id, localid); } @@ -387,8 +393,8 @@ void BilateralLagrangianConstraint::draw(const core::visual::VisualPa std::vector< sofa::type::Vec3 > vertices; const unsigned minp = std::min(d_m1.getValue().size(), d_m2.getValue().size()); - auto positionsM1 = sofa::helper::getReadAccessor(*this->mstate1->read(ConstVecCoordId::position())); - auto positionsM2 = sofa::helper::getReadAccessor(*this->mstate2->read(ConstVecCoordId::position())); + auto positionsM1 = sofa::helper::getReadAccessor(*this->mstate1->read(core::vec_id::read_access::position)); + auto positionsM2 = sofa::helper::getReadAccessor(*this->mstate2->read(core::vec_id::read_access::position)); const auto indicesM1 = sofa::helper::getReadAccessor(d_m1); const auto indicesM2 = sofa::helper::getReadAccessor(d_m2); diff --git a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/SlidingLagrangianConstraint.h b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/SlidingLagrangianConstraint.h index 2aec761548d..4c9e9aa5c9c 100644 --- a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/SlidingLagrangianConstraint.h +++ b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/SlidingLagrangianConstraint.h @@ -66,7 +66,7 @@ class SlidingLagrangianConstraint : public core::behavior::PairInteractionConstr SlidingLagrangianConstraint(MechanicalState* object); SlidingLagrangianConstraint(MechanicalState* object1, MechanicalState* object2); - virtual ~SlidingLagrangianConstraint(){} + ~SlidingLagrangianConstraint() override {} diff --git a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/SlidingLagrangianConstraint.inl b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/SlidingLagrangianConstraint.inl index 50d02d65705..cf25b9e4292 100644 --- a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/SlidingLagrangianConstraint.inl +++ b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/SlidingLagrangianConstraint.inl @@ -218,14 +218,14 @@ void SlidingLagrangianConstraint::draw(const core::visual::VisualPara color = sofa::type::RGBAColor::magenta(); std::vector vertices; - vertices.push_back(DataTypes::getCPos((this->mstate1->read(core::ConstVecCoordId::position())->getValue())[d_m1.getValue()])); + vertices.push_back(DataTypes::getCPos((this->mstate1->read(core::vec_id::read_access::position)->getValue())[d_m1.getValue()])); vparams->drawTool()->drawPoints(vertices, 10, color); vertices.clear(); color = sofa::type::RGBAColor::blue(); - vertices.push_back(DataTypes::getCPos((this->mstate2->read(core::ConstVecCoordId::position())->getValue())[d_m2a.getValue()])); - vertices.push_back(DataTypes::getCPos((this->mstate2->read(core::ConstVecCoordId::position())->getValue())[d_m2b.getValue()])); + vertices.push_back(DataTypes::getCPos((this->mstate2->read(core::vec_id::read_access::position)->getValue())[d_m2a.getValue()])); + vertices.push_back(DataTypes::getCPos((this->mstate2->read(core::vec_id::read_access::position)->getValue())[d_m2b.getValue()])); vparams->drawTool()->drawLines(vertices, 1, color); diff --git a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/StopperLagrangianConstraint.inl b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/StopperLagrangianConstraint.inl index 1c4dd4629ba..2b67230da86 100644 --- a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/StopperLagrangianConstraint.inl +++ b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/StopperLagrangianConstraint.inl @@ -46,7 +46,7 @@ void StopperLagrangianConstraint::init() this->mstate = dynamic_cast(this->getContext()->getMechanicalState()); assert(this->mstate); - helper::WriteAccessor > xData = *this->mstate->write(core::VecCoordId::position()); + helper::WriteAccessor > xData = *this->mstate->write(core::vec_id::write_access::position); VecCoord& x = xData.wref(); if (x[d_index.getValue()].x() < d_min.getValue()) x[d_index.getValue()].x() = (Real) d_min.getValue(); diff --git a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/ConstraintSolverImpl.cpp b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/ConstraintSolverImpl.cpp index 5278af3faa9..2e9105b45b9 100644 --- a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/ConstraintSolverImpl.cpp +++ b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/ConstraintSolverImpl.cpp @@ -52,7 +52,7 @@ void ConstraintProblem::clear(int nbConstraints) f.resize(nbConstraints); static std::atomic counter = 0; - problemId = counter.fetch_add(1, std::memory_order::memory_order_relaxed); + problemId = counter.fetch_add(1, std::memory_order_relaxed); } unsigned int ConstraintProblem::getProblemId() diff --git a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.cpp b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.cpp index cf3d4e1a770..e33cbaa1b0b 100644 --- a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.cpp +++ b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.cpp @@ -60,8 +60,10 @@ void clearMultiVecId(sofa::core::objectmodel::BaseContext* ctx, const sofa::core } +static constexpr GenericConstraintSolver::ResolutionMethod defaultResolutionMethod("ProjectedGaussSeidel"); + GenericConstraintSolver::GenericConstraintSolver() - : d_resolutionMethod( initData(&d_resolutionMethod, "resolutionMethod", "Method used to solve the constraint problem, among: \"ProjectedGaussSeidel\", \"UnbuiltGaussSeidel\" or \"for NonsmoothNonlinearConjugateGradient\"")) + : d_resolutionMethod( initData(&d_resolutionMethod, defaultResolutionMethod, "resolutionMethod", ("Method used to solve the constraint problem\n" + ResolutionMethod::dataDescription()).c_str())) , d_maxIt(initData(&d_maxIt, 1000, "maxIterations", "maximal number of iterations of the Gauss-Seidel algorithm")) , d_tolerance(initData(&d_tolerance, 0.001_sreal, "tolerance", "residual error threshold for termination of the Gauss-Seidel algorithm")) , d_sor(initData(&d_sor, 1.0_sreal, "sor", "Successive Over Relaxation parameter (0-2)")) @@ -86,10 +88,6 @@ GenericConstraintSolver::GenericConstraintSolver() , current_cp(&m_cpBuffer[0]) , last_cp(nullptr) { - sofa::helper::OptionsGroup m_newoptiongroup{"ProjectedGaussSeidel","UnbuiltGaussSeidel", "NonsmoothNonlinearConjugateGradient"}; - m_newoptiongroup.setSelectedItem("ProjectedGaussSeidel"); - d_resolutionMethod.setValue(m_newoptiongroup); - addAlias(&d_maxIt, "maxIt"); d_graphErrors.setWidget("graph"); @@ -159,7 +157,8 @@ void GenericConstraintSolver::init() if(d_newtonIterations.isSet()) { - if (d_resolutionMethod.getValue().getSelectedId() != 2) + static constexpr ResolutionMethod NonsmoothNonlinearConjugateGradient("NonsmoothNonlinearConjugateGradient"); + if (d_resolutionMethod.getValue() != NonsmoothNonlinearConjugateGradient) { msg_warning() << "data \"newtonIterations\" is not only taken into account when using the NonsmoothNonlinearConjugateGradient solver"; } @@ -225,15 +224,15 @@ bool GenericConstraintSolver::buildSystem(const core::ConstraintParams *cParams, } // Resolution depending on the method selected - switch ( d_resolutionMethod.getValue().getSelectedId() ) + switch ( d_resolutionMethod.getValue() ) { - case 0: // ProjectedGaussSeidel - case 2: // NonsmoothNonlinearConjugateGradient + case ResolutionMethod("ProjectedGaussSeidel"): + case ResolutionMethod("NonsmoothNonlinearConjugateGradient"): { buildSystem_matrixAssembly(cParams); break; } - case 1: // UnbuiltGaussSeidel + case ResolutionMethod("UnbuiltGaussSeidel"): { buildSystem_matrixFree(numConstraints); break; @@ -429,10 +428,9 @@ bool GenericConstraintSolver::solveSystem(const core::ConstraintParams * /*cPara // Resolution depending on the method selected - switch ( d_resolutionMethod.getValue().getSelectedId() ) + switch ( d_resolutionMethod.getValue()) { - // ProjectedGaussSeidel - case 0: { + case ResolutionMethod("ProjectedGaussSeidel"): { if (notMuted()) { std::stringstream tmp; @@ -445,14 +443,12 @@ bool GenericConstraintSolver::solveSystem(const core::ConstraintParams * /*cPara current_cp->gaussSeidel(0, this); break; } - // UnbuiltGaussSeidel - case 1: { + case ResolutionMethod("UnbuiltGaussSeidel"): { SCOPED_TIMER_VARNAME(unbuiltGaussSeidelTimer, "ConstraintsUnbuiltGaussSeidel"); current_cp->unbuiltGaussSeidel(0, this); break; } - // NonsmoothNonlinearConjugateGradient - case 2: { + case ResolutionMethod("NonsmoothNonlinearConjugateGradient"): { current_cp->NNCG(this, d_newtonIterations.getValue()); break; } diff --git a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.h b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.h index 7d752048930..cd3c770fd97 100644 --- a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.h +++ b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.h @@ -33,6 +33,8 @@ #include #include +#include + namespace sofa::component::constraint::lagrangian::solver { @@ -60,7 +62,13 @@ class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API GenericConstraintSolver : ConstraintProblem* getConstraintProblem() override; void lockConstraintProblem(sofa::core::objectmodel::BaseObject* from, ConstraintProblem* p1, ConstraintProblem* p2 = nullptr) override; - Data< sofa::helper::OptionsGroup > d_resolutionMethod; ///< Method used to solve the constraint problem, among: "ProjectedGaussSeidel", "UnbuiltGaussSeidel" or "for NonsmoothNonlinearConjugateGradient" + MAKE_SELECTABLE_ITEMS(ResolutionMethod, + sofa::helper::Item{"ProjectedGaussSeidel", "Projected Gauss-Seidel"}, + sofa::helper::Item{"UnbuiltGaussSeidel", "Gauss-Seidel where the matrix is not assembled"}, + sofa::helper::Item{"NonsmoothNonlinearConjugateGradient", "Non-smooth non-linear conjugate gradient"} + ); + + Data< ResolutionMethod > d_resolutionMethod; ///< Method used to solve the constraint problem, among: "ProjectedGaussSeidel", "UnbuiltGaussSeidel" or "for NonsmoothNonlinearConjugateGradient" SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA_IN_CONSTRAINT_LAGRANGIAN_SOLVER() sofa::core::objectmodel::RenamedData maxIt; diff --git a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/LCPConstraintSolver.cpp b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/LCPConstraintSolver.cpp index 9a938934b73..18dc8b33258 100644 --- a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/LCPConstraintSolver.cpp +++ b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/LCPConstraintSolver.cpp @@ -114,7 +114,7 @@ void LCPConstraintProblem::solveTimed(SReal tolerance, int maxIt, SReal timeout) bool LCPConstraintSolver::prepareStates(const core::ConstraintParams * /*cParams*/, MultiVecId /*res1*/, MultiVecId /*res2*/) { last_cp = current_cp; - MechanicalVOpVisitor(core::execparams::defaultInstance(), (core::VecId)core::VecDerivId::dx()).setMapped(true).execute( getContext()); //dX=0 + MechanicalVOpVisitor(core::execparams::defaultInstance(), (core::VecId)core::vec_id::write_access::dx).setMapped(true).execute( getContext()); //dX=0 msg_info() <<" propagate DXn performed - collision called" ; @@ -142,8 +142,8 @@ void LCPConstraintSolver::buildSystem() { core::ConstraintParams cparams; - cparams.setX(core::ConstVecCoordId::freePosition()); - cparams.setV(core::ConstVecDerivId::freeVelocity()); + cparams.setX(core::vec_id::read_access::freePosition); + cparams.setV(core::vec_id::read_access::freeVelocity); _numConstraints = buildConstraintMatrix(&cparams); sofa::helper::AdvancedTimer::valSet("numConstraints", _numConstraints); diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AffineMovementProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AffineMovementProjectiveConstraint.inl index abfdde06913..329c7cd70e9 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AffineMovementProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AffineMovementProjectiveConstraint.inl @@ -300,7 +300,7 @@ template void AffineMovementProjectiveConstraint::draw(const core::visual::VisualParams* vparams) { const SetIndexArray & indices = d_indices.getValue(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); Vec3 point; if(d_drawConstrainedPoints.getValue()) diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AttachProjectiveConstraint.cpp b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AttachProjectiveConstraint.cpp index 6fa5cd004f7..51a9e7d71d4 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AttachProjectiveConstraint.cpp +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AttachProjectiveConstraint.cpp @@ -43,7 +43,7 @@ template <> SOFA_COMPONENT_CONSTRAINT_PROJECTIVE_API void AttachProjectiveConstraint::calcRestRotations() { const SetIndexArray & indices2 = f_indices2.getValue(); - const VecCoord& x0 = this->mstate2->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& x0 = this->mstate2->read(core::vec_id::read_access::restPosition)->getValue(); restRotations.resize(indices2.size()); for (unsigned int i=0; i::draw(const core::visual::VisualParam const SetIndexArray & indices1 = f_indices1.getValue(); const SetIndexArray & indices2 = f_indices2.getValue(); - const VecCoord& x1 = this->mstate1->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& x2 = this->mstate2->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x1 = this->mstate1->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& x2 = this->mstate2->read(core::vec_id::read_access::position)->getValue(); constexpr sofa::type::RGBAColor color1(1,0.5,0.5,1); std::vector vertices; diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/DirectionProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/DirectionProjectiveConstraint.inl index f9435470265..465fca4cf08 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/DirectionProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/DirectionProjectiveConstraint.inl @@ -165,7 +165,7 @@ void DirectionProjectiveConstraint::reinit() } jacobian.compress(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); const Indices &indices = d_indices.getValue(); for (const auto id : indices) { @@ -245,7 +245,7 @@ void DirectionProjectiveConstraint::draw(const core::visual::VisualPa { if (!vparams->displayFlags().getShowBehaviorModels()) return; if (!this->isActive()) return; - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedPlaneProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedPlaneProjectiveConstraint.inl index 49b29b03583..b6b151f6dd4 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedPlaneProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedPlaneProjectiveConstraint.inl @@ -244,7 +244,7 @@ void FixedPlaneProjectiveConstraint::setDirection(Coord dir) template void FixedPlaneProjectiveConstraint::selectVerticesAlongPlane() { - const VecCoord& x = mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = mstate->read(core::vec_id::read_access::position)->getValue(); for(unsigned int i=0; i void FixedPlaneProjectiveConstraint::draw(const VisualParams* vparams) { if (!vparams->displayFlags().getShowBehaviorModels()) return; - const VecCoord& x = mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = mstate->read(core::vec_id::read_access::position)->getValue(); vparams->drawTool()->disableLighting(); type::vector points; diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedProjectiveConstraint.inl index 7c4cb684473..1d69e6eb236 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedProjectiveConstraint.inl @@ -372,7 +372,7 @@ void FixedProjectiveConstraint::computeBBoxForIndices(const type::vec const auto drawSize = static_cast(d_drawSize.getValue()); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); for (const auto index : indices) { @@ -426,7 +426,7 @@ void FixedProjectiveConstraint::draw(const core::visual::VisualParams const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); const SetIndexArray & indices = d_indices.getValue(); if( d_drawSize.getValue() == 0) // old classical drawing by points diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedRotationProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedRotationProjectiveConstraint.inl index c9d1d036201..426c6af5030 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedRotationProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedRotationProjectiveConstraint.inl @@ -56,7 +56,7 @@ void FixedRotationProjectiveConstraint::init() this->core::behavior::ProjectiveConstraintSet::init(); // Retrieves mechanical state - VecCoord x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + VecCoord x = this->mstate->read(core::vec_id::read_access::position)->getValue(); // Stores initial orientation for each vertex previousOrientation.resize(x.size()); diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedTranslationProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedTranslationProjectiveConstraint.inl index 308aab936b5..aa3de24dc6b 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedTranslationProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedTranslationProjectiveConstraint.inl @@ -173,7 +173,7 @@ void FixedTranslationProjectiveConstraint::draw(const core::visual::V const SetIndexArray & indices = d_indices.getValue(); if (!vparams->displayFlags().getShowBehaviorModels()) return; - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); vparams->drawTool()->disableLighting(); diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LineProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LineProjectiveConstraint.inl index 8ee9480a42b..41f82958062 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LineProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LineProjectiveConstraint.inl @@ -252,7 +252,7 @@ void LineProjectiveConstraint::draw(const core::visual::VisualParams* { if (!vparams->displayFlags().getShowBehaviorModels()) return; if (!this->isActive()) return; - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearMovementProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearMovementProjectiveConstraint.inl index 8171f82a97e..022150d3546 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearMovementProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearMovementProjectiveConstraint.inl @@ -461,7 +461,7 @@ void LinearMovementProjectiveConstraint::draw(const core::visual::Vis } else { - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); sofa::type::vector points; type::Vec3 point; diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialLinearMovementProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialLinearMovementProjectiveConstraint.inl index d42c03b63de..45bbfd8d12b 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialLinearMovementProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialLinearMovementProjectiveConstraint.inl @@ -524,7 +524,7 @@ void PartialLinearMovementProjectiveConstraint::draw(const core::visu } else { - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); type::Vec3 point; const SetIndexArray & indices = d_indices.getValue(); diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PatchTestMovementProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PatchTestMovementProjectiveConstraint.inl index 6ffdcebddbe..d3443c96a0b 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PatchTestMovementProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PatchTestMovementProjectiveConstraint.inl @@ -431,7 +431,7 @@ template void PatchTestMovementProjectiveConstraint::draw(const core::visual::VisualParams* vparams) { const SetIndexArray & indices = d_indices.getValue(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); type::Vec3 point; if(d_drawConstrainedPoints.getValue()) diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PlaneProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PlaneProjectiveConstraint.inl index f2358f5d8b0..2f769c53f58 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PlaneProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PlaneProjectiveConstraint.inl @@ -244,7 +244,7 @@ void PlaneProjectiveConstraint::draw(const core::visual::VisualParams { if (!vparams->displayFlags().getShowBehaviorModels()) return; if (!this->isActive()) return; - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PointProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PointProjectiveConstraint.inl index 05b6aa1820d..b10638a7e99 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PointProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PointProjectiveConstraint.inl @@ -290,7 +290,7 @@ void PointProjectiveConstraint::draw(const core::visual::VisualParams { if (!vparams->displayFlags().getShowBehaviorModels()) return; if (!this->isActive()) return; - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); const SetIndexArray & indices = d_indices.getValue(); const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PositionBasedDynamicsProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PositionBasedDynamicsProjectiveConstraint.inl index 166da7be3e6..68166e5c2b0 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PositionBasedDynamicsProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PositionBasedDynamicsProjectiveConstraint.inl @@ -77,7 +77,7 @@ void PositionBasedDynamicsProjectiveConstraint::reset() std::fill(vel.begin(),vel.end(),Deriv()); helper::WriteAccessor old_pos (d_old_position ); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); old_pos.resize(x.size()); std::copy(x.begin(),x.end(),old_pos.begin()); } diff --git a/Sofa/Component/Constraint/Projective/tests/AffineMovementProjectiveConstraint_test.cpp b/Sofa/Component/Constraint/Projective/tests/AffineMovementProjectiveConstraint_test.cpp index 98be7bad2e5..d32ea2d552f 100644 --- a/Sofa/Component/Constraint/Projective/tests/AffineMovementProjectiveConstraint_test.cpp +++ b/Sofa/Component/Constraint/Projective/tests/AffineMovementProjectiveConstraint_test.cpp @@ -132,7 +132,7 @@ struct AffineMovementProjectiveConstraint_test : public BaseSimulationTest, Nume // Compute the theoretical final positions VecCoord finalPos; - patchStruct.affineConstraint->getFinalPositions( finalPos,*patchStruct.dofs->write(core::VecCoordId::position()) ); + patchStruct.affineConstraint->getFinalPositions( finalPos,*patchStruct.dofs->write(core::vec_id::write_access::position) ); // Initialize diff --git a/Sofa/Component/Constraint/Projective/tests/DirectionProjectiveConstraint_test.cpp b/Sofa/Component/Constraint/Projective/tests/DirectionProjectiveConstraint_test.cpp index e4663da89ac..39e6f6b3ee3 100644 --- a/Sofa/Component/Constraint/Projective/tests/DirectionProjectiveConstraint_test.cpp +++ b/Sofa/Component/Constraint/Projective/tests/DirectionProjectiveConstraint_test.cpp @@ -137,12 +137,12 @@ struct DirectionProjectiveConstraint_test : public BaseSimulationTest, NumericTe xprev[i] = x[i] = CPos(i,0,0); } - projection->projectPosition(core::mechanicalparams::defaultInstance(), *dofs->write(core::VecCoordId::position()) ); + projection->projectPosition(core::mechanicalparams::defaultInstance(), *dofs->write(core::vec_id::write_access::position) ); type::vector m_origin; // particle original position - const VecCoord& xOrigin = projection->getMState()->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& xOrigin = projection->getMState()->read(core::vec_id::read_access::position)->getValue(); for( typename Indices::const_iterator it = indices.begin() ; it != indices.end() ; ++it ) { m_origin.push_back( DataTypes::getCPos(xOrigin[*it]) ); @@ -188,7 +188,7 @@ struct DirectionProjectiveConstraint_test : public BaseSimulationTest, NumericTe vprev[i] = v[i] = CPos(i,0,0); } - projection->projectVelocity(core::mechanicalparams::defaultInstance(), *dofs->write(core::VecDerivId::velocity()) ); + projection->projectVelocity(core::mechanicalparams::defaultInstance(), *dofs->write(core::vec_id::write_access::velocity) ); bool succeed=true; typename Indices::const_iterator it = indices.begin(); // must be sorted diff --git a/Sofa/Component/Constraint/Projective/tests/LineProjectiveConstraint_test.cpp b/Sofa/Component/Constraint/Projective/tests/LineProjectiveConstraint_test.cpp index 61a72af32ff..37f7d55f030 100644 --- a/Sofa/Component/Constraint/Projective/tests/LineProjectiveConstraint_test.cpp +++ b/Sofa/Component/Constraint/Projective/tests/LineProjectiveConstraint_test.cpp @@ -137,7 +137,7 @@ const PointSetTopologyContainer::SPtr topology = core::objectmodel::NewprojectPosition(core::mechanicalparams::defaultInstance(), *dofs->write(core::VecCoordId::position()) ); + projection->projectPosition(core::mechanicalparams::defaultInstance(), *dofs->write(core::vec_id::write_access::position) ); bool succeed=true; typename Indices::const_iterator it = indices.begin(); // must be sorted @@ -174,7 +174,7 @@ const PointSetTopologyContainer::SPtr topology = core::objectmodel::NewprojectVelocity(core::mechanicalparams::defaultInstance(), *dofs->write(core::VecDerivId::velocity()) ); + projection->projectVelocity(core::mechanicalparams::defaultInstance(), *dofs->write(core::vec_id::write_access::velocity) ); bool succeed=true; typename Indices::const_iterator it = indices.begin(); // must be sorted diff --git a/Sofa/Component/Constraint/Projective/tests/PlaneProjectiveConstraint_test.cpp b/Sofa/Component/Constraint/Projective/tests/PlaneProjectiveConstraint_test.cpp index 05be6be816f..cbaef8f4975 100644 --- a/Sofa/Component/Constraint/Projective/tests/PlaneProjectiveConstraint_test.cpp +++ b/Sofa/Component/Constraint/Projective/tests/PlaneProjectiveConstraint_test.cpp @@ -138,7 +138,7 @@ const PointSetTopologyContainer::SPtr topology = core::objectmodel::NewprojectPosition(core::mechanicalparams::defaultInstance(), *dofs->write(core::VecCoordId::position()) ); + projection->projectPosition(core::mechanicalparams::defaultInstance(), *dofs->write(core::vec_id::write_access::position) ); bool succeed=true; typename Indices::const_iterator it = indices.begin(); // must be sorted @@ -174,7 +174,7 @@ const PointSetTopologyContainer::SPtr topology = core::objectmodel::NewprojectVelocity(core::mechanicalparams::defaultInstance(), *dofs->write(core::VecDerivId::velocity()) ); + projection->projectVelocity(core::mechanicalparams::defaultInstance(), *dofs->write(core::vec_id::write_access::velocity) ); bool succeed=true; typename Indices::const_iterator it = indices.begin(); // must be sorted diff --git a/Sofa/Component/Constraint/Projective/tests/PointProjectiveConstraint_test.cpp b/Sofa/Component/Constraint/Projective/tests/PointProjectiveConstraint_test.cpp index 5151e9f7f29..2efc25e1e0b 100644 --- a/Sofa/Component/Constraint/Projective/tests/PointProjectiveConstraint_test.cpp +++ b/Sofa/Component/Constraint/Projective/tests/PointProjectiveConstraint_test.cpp @@ -138,7 +138,7 @@ struct PointProjectiveConstraint_test : public BaseSimulationTest, NumericTestprojectPosition(core::mechanicalparams::defaultInstance(), *dofs->write(core::VecCoordId::position()) ); + projection->projectPosition(core::mechanicalparams::defaultInstance(), *dofs->write(core::vec_id::write_access::position) ); bool succeed=true; typename Indices::const_iterator it = indices.begin(); // must be sorted @@ -177,7 +177,7 @@ struct PointProjectiveConstraint_test : public BaseSimulationTest, NumericTestprojectVelocity(core::mechanicalparams::defaultInstance(), *dofs->write(core::VecDerivId::velocity()) ); + projection->projectVelocity(core::mechanicalparams::defaultInstance(), *dofs->write(core::vec_id::write_access::velocity) ); bool succeed=true; typename Indices::const_iterator it = indices.begin(); // must be sorted diff --git a/Sofa/Component/Controller/src/sofa/component/controller/MechanicalStateController.cpp b/Sofa/Component/Controller/src/sofa/component/controller/MechanicalStateController.cpp index 859519b4baa..756a76e7a5a 100644 --- a/Sofa/Component/Controller/src/sofa/component/controller/MechanicalStateController.cpp +++ b/Sofa/Component/Controller/src/sofa/component/controller/MechanicalStateController.cpp @@ -40,7 +40,7 @@ void MechanicalStateController::applyController() if(mState) { - helper::WriteAccessor > x0 = *mState->write(sofa::core::VecCoordId::restPosition()); + helper::WriteAccessor > x0 = *mState->write(sofa::core::vec_id::write_access::restPosition); if(buttonDevice) { if (x0[0].x() < -0.1) //angle de fermeture max @@ -75,7 +75,7 @@ void MechanicalStateController::applyController() {*/ if (mState) { - helper::WriteAccessor > x0 = *mState->write(sofa::core::VecCoordId::restPosition()); + helper::WriteAccessor > x0 = *mState->write(sofa::core::vec_id::write_access::restPosition); if (mouseMode==BtMiddle) { x0[0].x() = -0.4; diff --git a/Sofa/Component/Controller/src/sofa/component/controller/MechanicalStateController.inl b/Sofa/Component/Controller/src/sofa/component/controller/MechanicalStateController.inl index cba22b74845..ebfea8ee9b9 100644 --- a/Sofa/Component/Controller/src/sofa/component/controller/MechanicalStateController.inl +++ b/Sofa/Component/Controller/src/sofa/component/controller/MechanicalStateController.inl @@ -80,8 +80,8 @@ void MechanicalStateController::applyController() if(mState) { { - helper::WriteAccessor > x = *this->mState->write(core::VecCoordId::position()); - helper::WriteAccessor > xfree = *this->mState->write(core::VecCoordId::freePosition()); + helper::WriteAccessor > x = *this->mState->write(core::vec_id::write_access::position); + helper::WriteAccessor > xfree = *this->mState->write(core::vec_id::write_access::freePosition); xfree[0].getCenter() = position; x[0].getCenter() = position; @@ -101,9 +101,9 @@ void MechanicalStateController::applyController() if (mState) { - helper::WriteAccessor > x = *this->mState->write(core::VecCoordId::position()); - mState->vRealloc( sofa::core::mechanicalparams::defaultInstance(), core::VecCoordId::freePosition() ); // freePosition is not allocated by default - helper::WriteAccessor > xfree = *this->mState->write(core::VecCoordId::freePosition()); + helper::WriteAccessor > x = *this->mState->write(core::vec_id::write_access::position); + mState->vRealloc( sofa::core::mechanicalparams::defaultInstance(), core::vec_id::write_access::freePosition ); // freePosition is not allocated by default + helper::WriteAccessor > xfree = *this->mState->write(core::vec_id::write_access::freePosition); unsigned int i = d_index.getValue(); @@ -144,7 +144,7 @@ void MechanicalStateController::applyController() if (mState) { - helper::WriteAccessor > x = *this->mState->write(core::VecCoordId::position()); + helper::WriteAccessor > x = *this->mState->write(core::vec_id::write_access::position); unsigned int i = d_index.getValue(); diff --git a/Sofa/Component/Diffusion/src/sofa/component/diffusion/TetrahedronDiffusionFEMForceField.inl b/Sofa/Component/Diffusion/src/sofa/component/diffusion/TetrahedronDiffusionFEMForceField.inl index add06886150..341bbb7c0f3 100644 --- a/Sofa/Component/Diffusion/src/sofa/component/diffusion/TetrahedronDiffusionFEMForceField.inl +++ b/Sofa/Component/Diffusion/src/sofa/component/diffusion/TetrahedronDiffusionFEMForceField.inl @@ -53,7 +53,7 @@ void TetrahedronDiffusionFEMForceField::computeEdgeDiffusionCoefficie edgeDiffusionCoefficient[i] = 0; nbTetra = m_topology->getNbTetrahedra(); - const typename TetrahedronDiffusionFEMForceField::MechanicalTypes::VecCoord position = this->mechanicalObject->read(core::ConstVecCoordId::position())->getValue(); + const typename TetrahedronDiffusionFEMForceField::MechanicalTypes::VecCoord position = this->mechanicalObject->read(core::vec_id::read_access::position)->getValue(); typename DataTypes::Real anisotropyRatio = this->d_transverseAnisotropyRatio.getValue(); const bool isotropicDiffusion = (anisotropyRatio == 1.0); @@ -431,7 +431,7 @@ void TetrahedronDiffusionFEMForceField::draw(const core::visual::Visu if (d_drawConduc.getValue()) { const typename TetrahedronDiffusionFEMForceField::MechanicalTypes::VecCoord restPosition = - this->mechanicalObject->read(core::ConstVecCoordId::restPosition())->getValue(); + this->mechanicalObject->read(core::vec_id::read_access::restPosition)->getValue(); vparams->drawTool()->setLightingEnabled(false); const auto nbr = m_topology->getNbTriangles(); diff --git a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/AverageCoord.h b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/AverageCoord.h index 930f5f7852c..a0bdae2ebd7 100644 --- a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/AverageCoord.h +++ b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/AverageCoord.h @@ -60,7 +60,7 @@ class AverageCoord : public core::DataEngine, public core::behavior::SingleState void doUpdate() override; Data d_indices; ///< indices of the coordinates to average - Data d_vecId; ///< index of the vector (default value corresponds to core::VecCoordId::position() ) + Data d_vecId; ///< index of the vector (default value corresponds to core::vec_id::write_access::position ) Data d_average; ///< result void handleEvent(core::objectmodel::Event *event) override; diff --git a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/AverageCoord.inl b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/AverageCoord.inl index 077573f935e..2dda46abdb9 100644 --- a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/AverageCoord.inl +++ b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/AverageCoord.inl @@ -32,7 +32,7 @@ namespace sofa::component::engine::analyze template AverageCoord::AverageCoord() : d_indices( initData (&d_indices, "indices", "indices of the coordinates to average") ) - , d_vecId(initData (&d_vecId, sofa::core::VecCoordId::position().getIndex(), "vecId", "index of the vector (default value corresponds to core::VecCoordId::position() )") ) + , d_vecId(initData (&d_vecId, sofa::core::vec_id::write_access::position.getIndex(), "vecId", "index of the vector (default value corresponds to core::vec_id::write_access::position )") ) , d_average( initData (&d_average, "average", "average of the values with the given indices in the given coordinate vector \n" "(default value corresponds to the average coord of the mechanical context)") ) { diff --git a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/ClusteringEngine.inl b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/ClusteringEngine.inl index 347e2887eb3..acae20f8459 100644 --- a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/ClusteringEngine.inl +++ b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/ClusteringEngine.inl @@ -383,7 +383,7 @@ void ClusteringEngine::draw(const core::visual::VisualParams* vparams const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); - const VecCoord& currentPositions = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& currentPositions = this->mstate->read(core::vec_id::read_access::position)->getValue(); const ReadAccessor< Data< VVI > > clust = this->d_cluster; const unsigned int nbp = currentPositions.size(); diff --git a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/Distances.inl b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/Distances.inl index b0d4ab07903..abdae6d419e 100644 --- a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/Distances.inl +++ b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/Distances.inl @@ -111,8 +111,8 @@ void Distances< DataTypes >::init() unsigned int realSize = 0; const unsigned int step = d_initTargetStep.getValue(); target->resize( size); - helper::WriteAccessor< Data< VecCoord > > xto = *target->write(core::VecCoordId::position()); - helper::WriteAccessor< Data< VecCoord > > xto0 = *target->write(core::VecCoordId::restPosition()); + helper::WriteAccessor< Data< VecCoord > > xto = *target->write(core::vec_id::write_access::position); + helper::WriteAccessor< Data< VecCoord > > xto0 = *target->write(core::vec_id::write_access::restPosition); const Coord& offSet = d_offset.getValue(); const type::Vec3& voxelSize = hexaContainer->d_voxelSize.getValue(); for ( unsigned int i = 0; i < size; i++) diff --git a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/ShapeMatching.inl b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/ShapeMatching.inl index 7927d631fd0..19f9aa5685a 100644 --- a/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/ShapeMatching.inl +++ b/Sofa/Component/Engine/Analyze/src/sofa/component/engine/analyze/ShapeMatching.inl @@ -114,7 +114,7 @@ void ShapeMatching::doUpdate() if (!this->mstate) return; - const auto* restPositionsData = this->mstate->read(core::ConstVecCoordId::restPosition()); + const auto* restPositionsData = this->mstate->read(core::vec_id::read_access::restPosition); if (!restPositionsData) { msg_error() << "Rest position cannot be found in mechanical object '" << this->mstate->getPathName() << "'"; diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/NearestPointROI.inl b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/NearestPointROI.inl index 9f8ab2b0784..295a5ff0cb8 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/NearestPointROI.inl +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/NearestPointROI.inl @@ -104,7 +104,7 @@ void NearestPointROI::doUpdate() { if (this->mstate1 && this->mstate2) { - const auto vecCoordId = d_useRestPosition.getValue() ? core::ConstVecCoordId::restPosition() : core::ConstVecCoordId::position(); + const auto vecCoordId = d_useRestPosition.getValue() ? core::vec_id::read_access::restPosition : core::vec_id::read_access::position; const VecCoord& x1 = this->mstate1->read(vecCoordId)->getValue(); const VecCoord& x2 = this->mstate2->read(vecCoordId)->getValue(); @@ -204,7 +204,7 @@ void NearestPointROI::draw(const core::visual::VisualParams* vparams) const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); - const auto vecCoordId = d_useRestPosition.getValue() ? core::ConstVecCoordId::restPosition() : core::ConstVecCoordId::position(); + const auto vecCoordId = d_useRestPosition.getValue() ? core::vec_id::read_access::restPosition : core::vec_id::read_access::position; const VecCoord& x1 = this->mstate1->read(vecCoordId)->getValue(); const VecCoord& x2 = this->mstate2->read(vecCoordId)->getValue(); std::vector vertices; diff --git a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/Vertex2Frame.inl b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/Vertex2Frame.inl index af00c92cec7..abed2ed8c5b 100644 --- a/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/Vertex2Frame.inl +++ b/Sofa/Component/Engine/Transform/src/sofa/component/engine/transform/Vertex2Frame.inl @@ -28,7 +28,7 @@ namespace sofa::component::engine::transform { template -const typename Vertex2Frame::Real Vertex2Frame::EPSILON = std::numeric_limits::Real>::epsilon(); +const Real_t Vertex2Frame::EPSILON = std::numeric_limits>::epsilon(); template Vertex2Frame::Vertex2Frame(): diff --git a/Sofa/Component/Haptics/src/sofa/component/haptics/LCPForceFeedback.inl b/Sofa/Component/Haptics/src/sofa/component/haptics/LCPForceFeedback.inl index 9752b668cd3..03d2d500373 100644 --- a/Sofa/Component/Haptics/src/sofa/component/haptics/LCPForceFeedback.inl +++ b/Sofa/Component/Haptics/src/sofa/component/haptics/LCPForceFeedback.inl @@ -371,13 +371,13 @@ void LCPForceFeedback::handleEvent(sofa::core::objectmodel::Event *ev mCP[buf_index] = new_cp; // Update Val - val = mState->read(sofa::core::VecCoordId::freePosition())->getValue(); + val = mState->read(sofa::core::vec_id::write_access::freePosition)->getValue(); // Update constraints and id_buf constraints.clear(); // id_buf.clear(); - const MatrixDeriv& c = mState->read(core::ConstMatrixDerivId::constraintJacobian())->getValue() ; + const MatrixDeriv& c = mState->read(core::vec_id::read_access::constraintJacobian)->getValue() ; MatrixDerivRowConstIterator rowItEnd = c.end(); diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.inl b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.inl index 4193ca763fb..2f91eea5b94 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.inl +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.inl @@ -184,7 +184,7 @@ void BlenderExporter::handleEvent(sofa::core::objectmodel::Event* event) pos[2] = (float)x[2]; Deriv v; - if((mmodel->read(core::ConstVecDerivId::velocity())) && ((int) mmodel->readVelocities().size()>i)) + if((mmodel->read(core::vec_id::read_access::velocity)) && ((int) mmodel->readVelocities().size()>i)) { v =mmodel->readVelocities()[i]; vel[0] = (float)v[0]; @@ -193,7 +193,7 @@ void BlenderExporter::handleEvent(sofa::core::objectmodel::Event* event) } Coord x0; - if((mmodel->read(core::ConstVecCoordId::restPosition())) && ( (int)mmodel->readRestPositions().size()>i)) + if((mmodel->read(core::vec_id::read_access::restPosition)) && ( (int)mmodel->readRestPositions().size()>i)) { x0 =mmodel->readRestPositions()[i]; rest[0] = (float)x0[0]; diff --git a/Sofa/Component/LinearSolver/Iterative/CMakeLists.txt b/Sofa/Component/LinearSolver/Iterative/CMakeLists.txt index e94666809ec..50514787466 100644 --- a/Sofa/Component/LinearSolver/Iterative/CMakeLists.txt +++ b/Sofa/Component/LinearSolver/Iterative/CMakeLists.txt @@ -18,6 +18,8 @@ set(HEADER_FILES ${SOFACOMPONENTLINEARSOLVERITERATIVE_SOURCE_DIR}/MinResLinearSolver.inl ${SOFACOMPONENTLINEARSOLVERITERATIVE_SOURCE_DIR}/ShewchukPCGLinearSolver.h ${SOFACOMPONENTLINEARSOLVERITERATIVE_SOURCE_DIR}/ShewchukPCGLinearSolver.inl + ${SOFACOMPONENTLINEARSOLVERITERATIVE_SOURCE_DIR}/PCGLinearSolver.h + ${SOFACOMPONENTLINEARSOLVERITERATIVE_SOURCE_DIR}/PCGLinearSolver.inl ) set(SOURCE_FILES @@ -29,7 +31,7 @@ set(SOURCE_FILES ${SOFACOMPONENTLINEARSOLVERITERATIVE_SOURCE_DIR}/MatrixLinearSolver.cpp ${SOFACOMPONENTLINEARSOLVERITERATIVE_SOURCE_DIR}/MatrixLinearSystem[GraphScattered].cpp ${SOFACOMPONENTLINEARSOLVERITERATIVE_SOURCE_DIR}/MinResLinearSolver.cpp - ${SOFACOMPONENTLINEARSOLVERITERATIVE_SOURCE_DIR}/ShewchukPCGLinearSolver.cpp + ${SOFACOMPONENTLINEARSOLVERITERATIVE_SOURCE_DIR}/PCGLinearSolver.cpp ) sofa_find_package(Sofa.Simulation.Core REQUIRED) diff --git a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/GraphScatteredTypes.cpp b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/GraphScatteredTypes.cpp index 51dacd5f02d..f9aa5f3a656 100644 --- a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/GraphScatteredTypes.cpp +++ b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/GraphScatteredTypes.cpp @@ -34,7 +34,10 @@ void GraphScatteredMatrix::apply(GraphScatteredVector& res, GraphScatteredVector { // matrix-vector product through visitors parent->propagateDxAndResetDf(x,res); - parent->addMBKdx(res,parent->mparams.mFactor(),parent->mparams.bFactor(),parent->mparams.kFactor(), false); // df = (m M + b B + k K) dx + parent->addMBKdx(res, + core::MatricesFactors::M(parent->mparams.mFactor()), + core::MatricesFactors::B(parent->mparams.bFactor()), + core::MatricesFactors::K(parent->mparams.kFactor()), false); // df = (m M + b B + k K) dx // filter the product to take the constraints into account // diff --git a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixLinearSolver.inl b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixLinearSolver.inl index c3429b4b1ae..e1b38680ddb 100644 --- a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixLinearSolver.inl +++ b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixLinearSolver.inl @@ -615,7 +615,7 @@ void MatrixLinearSolver::computeResidual(const core::ExecParams* internalData.projectForceInConstraintSpace(getSystemRHVector(), f); sofa::simulation::common::VectorOperations vop( params, this->getContext() ); - sofa::core::behavior::MultiVecDeriv force(&vop, core::VecDerivId::force() ); + sofa::core::behavior::MultiVecDeriv force(&vop, core::vec_id::write_access::force ); executeVisitor( MechanicalMultiVectorPeqBaseVectorVisitor(core::execparams::defaultInstance(), force, getSystemRHVector(), &(linearSystem.matrixAccessor)) ); } diff --git a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/ShewchukPCGLinearSolver.cpp b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/PCGLinearSolver.cpp similarity index 82% rename from Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/ShewchukPCGLinearSolver.cpp rename to Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/PCGLinearSolver.cpp index 5cd240c90db..72f4df45bed 100644 --- a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/ShewchukPCGLinearSolver.cpp +++ b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/PCGLinearSolver.cpp @@ -19,8 +19,8 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#define SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_SHEWCHUKPCGLINEARSOLVER_CPP -#include +#define SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_PCGLINEARSOLVER_CPP +#include #include #include #include @@ -28,12 +28,12 @@ namespace sofa::component::linearsolver::iterative { -void registerShewchukPCGLinearSolver(sofa::core::ObjectFactory* factory) +void registerPCGLinearSolver(sofa::core::ObjectFactory* factory) { factory->registerObjects(core::ObjectRegistrationData("Linear system solver using the Shewchuk conjugate gradient iterative algorithm.") - .add< ShewchukPCGLinearSolver >()); + .add< PCGLinearSolver >()); } -template class SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API ShewchukPCGLinearSolver; +template class SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API PCGLinearSolver; } // namespace sofa::component::linearsolver::iterative diff --git a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/PCGLinearSolver.h b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/PCGLinearSolver.h new file mode 100644 index 00000000000..1506256becd --- /dev/null +++ b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/PCGLinearSolver.h @@ -0,0 +1,123 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture * +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once +#include + +#include +#include +#include + +#include + +#include + +namespace sofa::component::linearsolver::iterative +{ + +/// Linear system solver using the conjugate gradient iterative algorithm +template +class PCGLinearSolver : public sofa::component::linearsolver::MatrixLinearSolver +{ +public: + SOFA_CLASS(SOFA_TEMPLATE2(PCGLinearSolver,TMatrix,TVector),SOFA_TEMPLATE2(sofa::component::linearsolver::MatrixLinearSolver,TMatrix,TVector)); + + typedef TMatrix Matrix; + typedef TVector Vector; + typedef sofa::component::linearsolver::MatrixLinearSolver Inherit; + + SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA_IN_LINEARSOLVER_ITERATIVE() + sofa::core::objectmodel::RenamedData f_maxIter; + + SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA_IN_LINEARSOLVER_ITERATIVE() + sofa::core::objectmodel::RenamedData f_tolerance; + + SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA_IN_LINEARSOLVER_ITERATIVE() + sofa::core::objectmodel::RenamedData f_use_precond; + + SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA_IN_LINEARSOLVER_ITERATIVE() + sofa::core::objectmodel::RenamedData f_update_step; + + SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA_IN_LINEARSOLVER_ITERATIVE() + sofa::core::objectmodel::RenamedData f_build_precond; + + SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA_IN_LINEARSOLVER_ITERATIVE() + sofa::core::objectmodel::RenamedData > > f_graph; + + + Data d_maxIter; ///< Maximum number of iterations after which the iterative descent of the Conjugate Gradient must stop + Data d_tolerance; ///< Desired accuracy of the Conjugate Gradient solution evaluating: |r|²/|b|² (ratio of current residual norm over initial residual norm) + Data d_use_precond; ///< Use a preconditioner + SingleLink l_preconditioner; ///< Link towards the linear solver used to precondition the conjugate gradient + Data d_update_step; ///< Number of steps before the next refresh of preconditioners + Data d_build_precond; ///< Build the preconditioners, if false build the preconditioner only at the initial step + Data > > d_graph; ///< Graph of residuals at each iteration + +protected: + PCGLinearSolver(); + +public: + void solve (Matrix& M, Vector& x, Vector& b) override; + void init() override; + void setSystemMBKMatrix(const core::MechanicalParams* mparams) override; + +private : + unsigned next_refresh_step; + bool first; + int newton_iter; + +protected: + /// This method is separated from the rest to be able to use custom/optimized versions depending on the types of vectors. + /// It computes: p = p*beta + r + inline void cgstep_beta(Vector& p, Vector& r, double beta); + /// This method is separated from the rest to be able to use custom/optimized versions depending on the types of vectors. + /// It computes: x += p*alpha, r -= q*alpha + inline void cgstep_alpha(Vector& x,Vector& p,double alpha); + + void handleEvent(sofa::core::objectmodel::Event* event) override; + + +}; + +template +inline void PCGLinearSolver::cgstep_beta(Vector& p, Vector& r, double beta) +{ + p *= beta; + p += r; //z; +} + +template +inline void PCGLinearSolver::cgstep_alpha(Vector& x,Vector& p,double alpha) +{ + x.peq(p,alpha); // x = x + alpha p +} + +template<> +inline void PCGLinearSolver::cgstep_beta(Vector& p, Vector& r, double beta); + +template<> +inline void PCGLinearSolver::cgstep_alpha(Vector& x,Vector& p,double alpha); + +#if !defined(SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_PCGLINEARSOLVER_CPP) +template class SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API PCGLinearSolver; +#endif // !defined(SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_PCGLINEARSOLVER_CPP) + +} // namespace sofa::component::linearsolver::iterative diff --git a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/PCGLinearSolver.inl b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/PCGLinearSolver.inl new file mode 100644 index 00000000000..ff9da2bb46e --- /dev/null +++ b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/PCGLinearSolver.inl @@ -0,0 +1,247 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture * +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once +#include + +#include +#include +#include +#include +#include +#include + +#include + +namespace sofa::component::linearsolver::iterative +{ + +template +PCGLinearSolver::PCGLinearSolver() + : d_maxIter(initData(&d_maxIter, (unsigned)25, "iterations", "Maximum number of iterations after which the iterative descent of the Conjugate Gradient must stop") ) + , d_tolerance(initData(&d_tolerance, 1e-5, "tolerance", "Desired accuracy of the Conjugate Gradient solution evaluating: |r|²/|b|² (ratio of current residual norm over initial residual norm)") ) + , d_use_precond(initData(&d_use_precond, true, "use_precond", "Use a preconditioner") ) + , l_preconditioner(initLink("preconditioner", "Link towards the linear solver used to precondition the conjugate gradient")) + , d_update_step(initData(&d_update_step, (unsigned)1, "update_step", "Number of steps before the next refresh of preconditioners") ) + , d_build_precond(initData(&d_build_precond, true, "build_precond", "Build the preconditioners, if false build the preconditioner only at the initial step") ) + , d_graph(initData(&d_graph, "graph", "Graph of residuals at each iteration") ) + , next_refresh_step(0) + , newton_iter(0) +{ + d_graph.setWidget("graph"); + first = true; + this->f_listening.setValue(true); + + f_maxIter.setOriginalData(&d_maxIter); + f_tolerance.setOriginalData(&d_tolerance); + f_use_precond.setOriginalData(&d_use_precond); + f_update_step.setOriginalData(&d_update_step); + f_build_precond.setOriginalData(&d_build_precond); + f_graph.setOriginalData(&d_graph); + +} + +template +void PCGLinearSolver::init() +{ + Inherit1::init(); + + // Find linear solvers + if (l_preconditioner.empty()) + { + msg_info() << "Link \"preconditioner\" to the desired linear solver should be set to precondition the conjugate gradient."; + } + else + { + if (l_preconditioner.get() == nullptr) + { + msg_error() << "No preconditioner found at path: " << l_preconditioner.getLinkedPath(); + sofa::core::objectmodel::BaseObject::d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid); + return; + } + else + { + if (l_preconditioner.get()->getTemplateName() == "GraphScattered") + { + msg_error() << "Can not use the preconditioner " << l_preconditioner.get()->getName() << " because it is templated on GraphScatteredType"; + sofa::core::objectmodel::BaseObject::d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid); + return; + } + else + { + msg_info() << "Preconditioner path used: '" << l_preconditioner.getLinkedPath() << "'"; + } + } + } + + first = true; + sofa::core::objectmodel::BaseObject::d_componentState.setValue(sofa::core::objectmodel::ComponentState::Valid); +} + +template +void PCGLinearSolver::setSystemMBKMatrix(const core::MechanicalParams* mparams) +{ + sofa::helper::AdvancedTimer::valSet("PCG::buildMBK", 1); + + { + SCOPED_TIMER("PCG::setSystemMBKMatrix"); + Inherit::setSystemMBKMatrix(mparams); + } + + if (l_preconditioner.get()==nullptr) return; + + if (first) //We initialize all the preconditioners for the first step + { + l_preconditioner.get()->setSystemMBKMatrix(mparams); + first = false; + next_refresh_step = 1; + } + else if (d_build_precond.getValue()) + { + sofa::helper::AdvancedTimer::valSet("PCG::PrecondBuildMBK", 1); + SCOPED_TIMER_VARNAME(mbkTimer, "PCG::PrecondSetSystemMBKMatrix"); + + if (d_update_step.getValue() > 0) + { + if (next_refresh_step >= d_update_step.getValue()) + { + l_preconditioner.get()->setSystemMBKMatrix(mparams); + next_refresh_step=1; + } + else + { + next_refresh_step++; + } + } + } + + l_preconditioner.get()->updateSystemMatrix(); +} + +template<> +inline void PCGLinearSolver::cgstep_beta(Vector& p, Vector& r, double beta) +{ + p.eq(r,p,beta); // p = p*beta + r +} + +template<> +inline void PCGLinearSolver::cgstep_alpha(Vector& x, Vector& p, double alpha) +{ + x.peq(p,alpha); // x = x + alpha p +} + +template +void PCGLinearSolver::handleEvent(sofa::core::objectmodel::Event* event) { + /// this event shoul be launch before the addKToMatrix + if (sofa::simulation::AnimateBeginEvent::checkEventType(event)) + { + newton_iter = 0; + std::map < std::string, sofa::type::vector >& graph = * d_graph.beginEdit(); + graph.clear(); + } +} + + +template +void PCGLinearSolver::solve (Matrix& M, Vector& x, Vector& b) +{ + SCOPED_TIMER_VARNAME(solveTimer, "PCGLinearSolver::solve"); + + std::map < std::string, sofa::type::vector >& graph = * d_graph.beginEdit(); +// sofa::type::vector& graph_error = graph["Error"]; + + newton_iter++; + char name[256]; + sprintf(name,"Error %d",newton_iter); + sofa::type::vector& graph_error = graph[std::string(name)]; + + const core::ExecParams* params = core::execparams::defaultInstance(); + typename Inherit::TempVectorContainer vtmp(this, params, M, x, b); + Vector& r = *vtmp.createTempVector(); + Vector& w = *vtmp.createTempVector(); + Vector& s = *vtmp.createTempVector(); + + const bool apply_precond = l_preconditioner.get()!=nullptr && d_use_precond.getValue(); + + const double b_norm = b.dot(b); + const double tol = d_tolerance.getValue() * b_norm; + + r = M * x; + cgstep_beta(r,b,-1);// r = -1 * r + b = b - (M * x) + + if (apply_precond) + { + SCOPED_TIMER_VARNAME(applyPrecondTimer, "PCGLinearSolver::apply Precond"); + l_preconditioner.get()->setSystemLHVector(w); + l_preconditioner.get()->setSystemRHVector(r); + l_preconditioner.get()->solveSystem(); + } + else + { + w = r; + } + + double r_norm = r.dot(w); + graph_error.push_back(r_norm/b_norm); + + unsigned iter=1; + while ((iter <= d_maxIter.getValue()) && (r_norm > tol)) + { + s = M * w; + const double dtq = w.dot(s); + double alpha = r_norm / dtq; + + cgstep_alpha(x,w,alpha);//for(int i=0; isetSystemLHVector(s); + l_preconditioner.get()->setSystemRHVector(r); + l_preconditioner.get()->solveSystem(); + } + else + { + s = r; + } + + const double deltaOld = r_norm; + r_norm = r.dot(s); + graph_error.push_back(r_norm/b_norm); + + double beta = r_norm / deltaOld; + + cgstep_beta(w,s,beta);//for (int i=0; i -#include -#include -#include +#include -#include - -#include +SOFA_HEADER_DEPRECATED("v24.12", "v25.12", "sofa/component/linearsolver/iterative/PCGLinearSolver.h") namespace sofa::component::linearsolver::iterative { - -/// Linear system solver using the conjugate gradient iterative algorithm -template -class ShewchukPCGLinearSolver : public sofa::component::linearsolver::MatrixLinearSolver -{ -public: - SOFA_CLASS(SOFA_TEMPLATE2(ShewchukPCGLinearSolver,TMatrix,TVector),SOFA_TEMPLATE2(sofa::component::linearsolver::MatrixLinearSolver,TMatrix,TVector)); - - typedef TMatrix Matrix; - typedef TVector Vector; - typedef sofa::component::linearsolver::MatrixLinearSolver Inherit; - - SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA_IN_LINEARSOLVER_ITERATIVE() - sofa::core::objectmodel::RenamedData f_maxIter; - - SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA_IN_LINEARSOLVER_ITERATIVE() - sofa::core::objectmodel::RenamedData f_tolerance; - - SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA_IN_LINEARSOLVER_ITERATIVE() - sofa::core::objectmodel::RenamedData f_use_precond; - - SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA_IN_LINEARSOLVER_ITERATIVE() - sofa::core::objectmodel::RenamedData f_update_step; - - SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA_IN_LINEARSOLVER_ITERATIVE() - sofa::core::objectmodel::RenamedData f_build_precond; - - SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA_IN_LINEARSOLVER_ITERATIVE() - sofa::core::objectmodel::RenamedData > > f_graph; - - - Data d_maxIter; ///< Maximum number of iterations after which the iterative descent of the Conjugate Gradient must stop - Data d_tolerance; ///< Desired accuracy of the Conjugate Gradient solution evaluating: |r|²/|b|² (ratio of current residual norm over initial residual norm) - Data d_use_precond; ///< Use a preconditioner - SingleLink l_preconditioner; ///< Link towards the linear solver used to precondition the conjugate gradient - Data d_update_step; ///< Number of steps before the next refresh of preconditioners - Data d_build_precond; ///< Build the preconditioners, if false build the preconditioner only at the initial step - Data > > d_graph; ///< Graph of residuals at each iteration - -protected: - ShewchukPCGLinearSolver(); - -public: - void solve (Matrix& M, Vector& x, Vector& b) override; - void init() override; - void setSystemMBKMatrix(const core::MechanicalParams* mparams) override; - -private : - unsigned next_refresh_step; - bool first; - int newton_iter; - -protected: - /// This method is separated from the rest to be able to use custom/optimized versions depending on the types of vectors. - /// It computes: p = p*beta + r - inline void cgstep_beta(Vector& p, Vector& r, double beta); - /// This method is separated from the rest to be able to use custom/optimized versions depending on the types of vectors. - /// It computes: x += p*alpha, r -= q*alpha - inline void cgstep_alpha(Vector& x,Vector& p,double alpha); - - void handleEvent(sofa::core::objectmodel::Event* event) override; - - -}; - -template -inline void ShewchukPCGLinearSolver::cgstep_beta(Vector& p, Vector& r, double beta) -{ - p *= beta; - p += r; //z; -} - template -inline void ShewchukPCGLinearSolver::cgstep_alpha(Vector& x,Vector& p,double alpha) -{ - x.peq(p,alpha); // x = x + alpha p +using ShewchukPCGLinearSolver SOFA_ATTRIBUTE_DEPRECATED("v24.12", "v25.12", "ShewchukPCGLinearSolver has been renamed to PCGLinearSolver") = PCGLinearSolver; } - -template<> -inline void ShewchukPCGLinearSolver::cgstep_beta(Vector& p, Vector& r, double beta); - -template<> -inline void ShewchukPCGLinearSolver::cgstep_alpha(Vector& x,Vector& p,double alpha); - -#if !defined(SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_SHEWCHUKPCGLINEARSOLVER_CPP) -template class SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API ShewchukPCGLinearSolver; -#endif // !defined(SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_SHEWCHUKPCGLINEARSOLVER_CPP) - -} // namespace sofa::component::linearsolver::iterative diff --git a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/ShewchukPCGLinearSolver.inl b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/ShewchukPCGLinearSolver.inl index 68eb09ae9d0..8345764ae6c 100644 --- a/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/ShewchukPCGLinearSolver.inl +++ b/Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/ShewchukPCGLinearSolver.inl @@ -20,228 +20,7 @@ * Contact information: contact@sofa-framework.org * ******************************************************************************/ #pragma once -#include -#include -#include -#include -#include -#include -#include +#include -#include - -namespace sofa::component::linearsolver::iterative -{ - -template -ShewchukPCGLinearSolver::ShewchukPCGLinearSolver() - : d_maxIter(initData(&d_maxIter, (unsigned)25, "iterations", "Maximum number of iterations after which the iterative descent of the Conjugate Gradient must stop") ) - , d_tolerance(initData(&d_tolerance, 1e-5, "tolerance", "Desired accuracy of the Conjugate Gradient solution evaluating: |r|²/|b|² (ratio of current residual norm over initial residual norm)") ) - , d_use_precond(initData(&d_use_precond, true, "use_precond", "Use a preconditioner") ) - , l_preconditioner(initLink("preconditioner", "Link towards the linear solver used to precondition the conjugate gradient")) - , d_update_step(initData(&d_update_step, (unsigned)1, "update_step", "Number of steps before the next refresh of preconditioners") ) - , d_build_precond(initData(&d_build_precond, true, "build_precond", "Build the preconditioners, if false build the preconditioner only at the initial step") ) - , d_graph(initData(&d_graph, "graph", "Graph of residuals at each iteration") ) - , next_refresh_step(0) - , newton_iter(0) -{ - d_graph.setWidget("graph"); - first = true; - this->f_listening.setValue(true); - - f_maxIter.setOriginalData(&d_maxIter); - f_tolerance.setOriginalData(&d_tolerance); - f_use_precond.setOriginalData(&d_use_precond); - f_update_step.setOriginalData(&d_update_step); - f_build_precond.setOriginalData(&d_build_precond); - f_graph.setOriginalData(&d_graph); - -} - -template -void ShewchukPCGLinearSolver::init() -{ - Inherit1::init(); - - // Find linear solvers - if (l_preconditioner.empty()) - { - msg_info() << "Link \"preconditioner\" to the desired linear solver should be set to precondition the conjugate gradient."; - } - else - { - if (l_preconditioner.get() == nullptr) - { - msg_error() << "No preconditioner found at path: " << l_preconditioner.getLinkedPath(); - sofa::core::objectmodel::BaseObject::d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid); - return; - } - else - { - if (l_preconditioner.get()->getTemplateName() == "GraphScattered") - { - msg_error() << "Can not use the preconditioner " << l_preconditioner.get()->getName() << " because it is templated on GraphScatteredType"; - sofa::core::objectmodel::BaseObject::d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid); - return; - } - else - { - msg_info() << "Preconditioner path used: '" << l_preconditioner.getLinkedPath() << "'"; - } - } - } - - first = true; - sofa::core::objectmodel::BaseObject::d_componentState.setValue(sofa::core::objectmodel::ComponentState::Valid); -} - -template -void ShewchukPCGLinearSolver::setSystemMBKMatrix(const core::MechanicalParams* mparams) -{ - sofa::helper::AdvancedTimer::valSet("PCG::buildMBK", 1); - - { - SCOPED_TIMER("PCG::setSystemMBKMatrix"); - Inherit::setSystemMBKMatrix(mparams); - } - - if (l_preconditioner.get()==nullptr) return; - - if (first) //We initialize all the preconditioners for the first step - { - l_preconditioner.get()->setSystemMBKMatrix(mparams); - first = false; - next_refresh_step = 1; - } - else if (d_build_precond.getValue()) - { - sofa::helper::AdvancedTimer::valSet("PCG::PrecondBuildMBK", 1); - SCOPED_TIMER_VARNAME(mbkTimer, "PCG::PrecondSetSystemMBKMatrix"); - - if (d_update_step.getValue() > 0) - { - if (next_refresh_step >= d_update_step.getValue()) - { - l_preconditioner.get()->setSystemMBKMatrix(mparams); - next_refresh_step=1; - } - else - { - next_refresh_step++; - } - } - } - - l_preconditioner.get()->updateSystemMatrix(); -} - -template<> -inline void ShewchukPCGLinearSolver::cgstep_beta(Vector& p, Vector& r, double beta) -{ - p.eq(r,p,beta); // p = p*beta + r -} - -template<> -inline void ShewchukPCGLinearSolver::cgstep_alpha(Vector& x, Vector& p, double alpha) -{ - x.peq(p,alpha); // x = x + alpha p -} - -template -void ShewchukPCGLinearSolver::handleEvent(sofa::core::objectmodel::Event* event) { - /// this event shoul be launch before the addKToMatrix - if (sofa::simulation::AnimateBeginEvent::checkEventType(event)) - { - newton_iter = 0; - std::map < std::string, sofa::type::vector >& graph = * d_graph.beginEdit(); - graph.clear(); - } -} - - -template -void ShewchukPCGLinearSolver::solve (Matrix& M, Vector& x, Vector& b) -{ - SCOPED_TIMER_VARNAME(solveTimer, "PCGLinearSolver::solve"); - - std::map < std::string, sofa::type::vector >& graph = * d_graph.beginEdit(); -// sofa::type::vector& graph_error = graph["Error"]; - - newton_iter++; - char name[256]; - sprintf(name,"Error %d",newton_iter); - sofa::type::vector& graph_error = graph[std::string(name)]; - - const core::ExecParams* params = core::execparams::defaultInstance(); - typename Inherit::TempVectorContainer vtmp(this, params, M, x, b); - Vector& r = *vtmp.createTempVector(); - Vector& w = *vtmp.createTempVector(); - Vector& s = *vtmp.createTempVector(); - - const bool apply_precond = l_preconditioner.get()!=nullptr && d_use_precond.getValue(); - - const double b_norm = b.dot(b); - const double tol = d_tolerance.getValue() * b_norm; - - r = M * x; - cgstep_beta(r,b,-1);// r = -1 * r + b = b - (M * x) - - if (apply_precond) - { - SCOPED_TIMER_VARNAME(applyPrecondTimer, "PCGLinearSolver::apply Precond"); - l_preconditioner.get()->setSystemLHVector(w); - l_preconditioner.get()->setSystemRHVector(r); - l_preconditioner.get()->solveSystem(); - } - else - { - w = r; - } - - double r_norm = r.dot(w); - graph_error.push_back(r_norm/b_norm); - - unsigned iter=1; - while ((iter <= d_maxIter.getValue()) && (r_norm > tol)) - { - s = M * w; - const double dtq = w.dot(s); - double alpha = r_norm / dtq; - - cgstep_alpha(x,w,alpha);//for(int i=0; isetSystemLHVector(s); - l_preconditioner.get()->setSystemRHVector(r); - l_preconditioner.get()->solveSystem(); - } - else - { - s = r; - } - - const double deltaOld = r_norm; - r_norm = r.dot(s); - graph_error.push_back(r_norm/b_norm); - - double beta = r_norm / deltaOld; - - cgstep_beta(w,s,beta);//for (int i=0; i::loadMatrixWithSolver() msg_error() << "PrecomputedContactCorrection must be associated with EulerImplicitSolver+LinearSolver for the precomputation\nNo Precomputation"; return; } - sofa::core::VecDerivId lhId = core::VecDerivId::velocity(); - sofa::core::VecDerivId rhId = core::VecDerivId::force(); + sofa::core::VecDerivId lhId = core::vec_id::write_access::velocity; + sofa::core::VecDerivId rhId = core::vec_id::write_access::force; mstate->vAvail(core::execparams::defaultInstance(), lhId); @@ -347,7 +347,7 @@ void PrecomputedWarpPreconditioner::loadMatrixWithSolver() linearSolver->setSystemMBKMatrix(&mparams); } - helper::WriteAccessor > dataForce = *mstate->write(core::VecDerivId::externalForce()); + helper::WriteAccessor > dataForce = *mstate->write(core::vec_id::write_access::externalForce); VecDeriv& force = dataForce.wref(); force.clear(); @@ -367,11 +367,11 @@ void PrecomputedWarpPreconditioner::loadMatrixWithSolver() } /////////////////////////////////////////////////////////////////////////////////////////////// - helper::WriteAccessor > dataVelocity = *mstate->write(core::VecDerivId::velocity()); + helper::WriteAccessor > dataVelocity = *mstate->write(core::vec_id::write_access::velocity); VecDeriv& velocity = dataVelocity.wref(); VecDeriv velocity0 = velocity; - helper::WriteAccessor > posData = *mstate->write(core::VecCoordId::position()); + helper::WriteAccessor > posData = *mstate->write(core::vec_id::write_access::position); VecCoord& pos = posData.wref(); VecCoord pos0 = pos; @@ -669,7 +669,7 @@ void PrecomputedWarpPreconditioner::draw(const core::visual::VisualP const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); - const VecCoord& x = mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = mstate->read(core::vec_id::read_access::position)->getValue(); const Real& scale = this->d_draw_rotations_scale.getValue(); for (unsigned int i=0; i< nb_dofs; i++) diff --git a/Sofa/Component/LinearSystem/src/sofa/component/linearsystem/MatrixProjectionMethod.inl b/Sofa/Component/LinearSystem/src/sofa/component/linearsystem/MatrixProjectionMethod.inl index a6557e20e0c..64752acc6a3 100644 --- a/Sofa/Component/LinearSystem/src/sofa/component/linearsystem/MatrixProjectionMethod.inl +++ b/Sofa/Component/LinearSystem/src/sofa/component/linearsystem/MatrixProjectionMethod.inl @@ -275,7 +275,7 @@ MappingJacobians MatrixProjectionMethod::computeJacobiansFrom( return jacobians; } - auto mappingJacobianId = sofa::core::MatrixDerivId::mappingJacobian(); + auto mappingJacobianId = sofa::core::vec_id::write_access::mappingJacobian; // this clears the matrix identified by mappingJacobian() among others simulation::mechanicalvisitor::MechanicalResetConstraintVisitor(&cparams).execute(this->getSolveContext()); diff --git a/Sofa/Component/LinearSystem/src/sofa/component/linearsystem/matrixaccumulators/BaseAssemblingMatrixAccumulator.h b/Sofa/Component/LinearSystem/src/sofa/component/linearsystem/matrixaccumulators/BaseAssemblingMatrixAccumulator.h index be731087f49..68aa75f4ae0 100644 --- a/Sofa/Component/LinearSystem/src/sofa/component/linearsystem/matrixaccumulators/BaseAssemblingMatrixAccumulator.h +++ b/Sofa/Component/LinearSystem/src/sofa/component/linearsystem/matrixaccumulators/BaseAssemblingMatrixAccumulator.h @@ -34,7 +34,6 @@ class BaseAssemblingMatrixAccumulator : public sofa::core::get_base_object_stron SOFA_CLASS(SOFA_TEMPLATE(BaseAssemblingMatrixAccumulator, c), sofa::core::get_base_object_strong_type); using ComponentType = typename Inherit1::ComponentType; - using Inherit1::initData; using Inherit1::add; virtual void setMatrixSize(const sofa::type::Vec2u&); diff --git a/Sofa/Component/LinearSystem/tests/MatrixLinearSystem_test.cpp b/Sofa/Component/LinearSystem/tests/MatrixLinearSystem_test.cpp index 4aa38d0fa77..c8163bfdb3d 100644 --- a/Sofa/Component/LinearSystem/tests/MatrixLinearSystem_test.cpp +++ b/Sofa/Component/LinearSystem/tests/MatrixLinearSystem_test.cpp @@ -136,7 +136,7 @@ TEST(LinearSystem, MatrixSystem_springForceField) // Compute the external force. This step is mandatory because most of the time force fields // pre-computes required elements for the matrix assembly in the addForce method - sofa::core::MultiVecDerivId ffId = sofa::core::VecDerivId::externalForce(); + sofa::core::MultiVecDerivId ffId = sofa::core::vec_id::write_access::externalForce; ((sofa::core::behavior::BaseForceField*)spring.get())->addForce(&mparams, ffId); diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMappers/BarycentricMapperHexahedronSetTopology.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMappers/BarycentricMapperHexahedronSetTopology.inl index 409b029bf3f..d62d268efec 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMappers/BarycentricMapperHexahedronSetTopology.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMappers/BarycentricMapperHexahedronSetTopology.inl @@ -197,7 +197,7 @@ void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core:: typedef MechanicalState InMechanicalStateT; InMechanicalStateT* inState; this->m_fromTopology->getContext()->get(inState); - const auto& inRestPos = (inState->read(core::ConstVecCoordId::restPosition())->getValue()); + const auto& inRestPos = (inState->read(core::vec_id::read_access::restPosition)->getValue()); if( this->m_toTopology) { typedef MechanicalState MechanicalStateT; @@ -209,7 +209,7 @@ void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core:: } else { - const typename MechanicalStateT::VecCoord& outXto0 = (mState->read(core::ConstVecCoordId::restPosition())->getValue()); + const typename MechanicalStateT::VecCoord& outXto0 = (mState->read(core::vec_id::read_access::restPosition)->getValue()); const decltype(inRestPos[0])& outRestPos = Out::getCPos(outXto0[j]); //decltype stuff is to force the same type of coordinates between in and out index = sofa::topology::getClosestHexahedronIndex(inRestPos, m_fromTopology->getHexahedra(), outRestPos, coefs, distance); } @@ -256,7 +256,7 @@ void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core:: typedef MechanicalState InMechanicalStateT; InMechanicalStateT* inState; this->m_fromTopology->getContext()->get(inState); - const auto& inRestPos = (inState->read(core::ConstVecCoordId::restPosition())->getValue()); + const auto& inRestPos = (inState->read(core::vec_id::read_access::restPosition)->getValue()); const auto nbHexahedra = this->m_fromTopology->getNbHexahedra(); diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMapping.inl index 014cb8780a0..ef6ae436d07 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMapping.inl @@ -283,9 +283,9 @@ void BarycentricMapping::initMapper() if (d_mapper != nullptr && this->toModel != nullptr && this->fromModel != nullptr) { if (d_useRestPosition.getValue()) - d_mapper->init (((const core::State *)this->toModel)->read(core::ConstVecCoordId::restPosition())->getValue(), ((const core::State *)this->fromModel)->read(core::ConstVecCoordId::restPosition())->getValue() ); + d_mapper->init (((const core::State *)this->toModel)->read(core::vec_id::read_access::restPosition)->getValue(), ((const core::State *)this->fromModel)->read(core::vec_id::read_access::restPosition)->getValue() ); else - d_mapper->init (((const core::State *)this->toModel)->read(core::ConstVecCoordId::position())->getValue(), ((const core::State *)this->fromModel)->read(core::ConstVecCoordId::position())->getValue() ); + d_mapper->init (((const core::State *)this->toModel)->read(core::vec_id::read_access::position)->getValue(), ((const core::State *)this->fromModel)->read(core::vec_id::read_access::position)->getValue() ); } } @@ -352,7 +352,7 @@ void BarycentricMapping::draw(const core::visual::VisualParams* vpara if (this->d_componentState.getValue() != ComponentState::Valid ) return; // Draw model (out) points - const OutVecCoord& out = this->toModel->read(core::ConstVecCoordId::position())->getValue(); + const OutVecCoord& out = this->toModel->read(core::vec_id::read_access::position)->getValue(); std::vector< Vec3 > points; for ( unsigned int i=0; i::draw(const core::visual::VisualParams* vpara vparams->drawTool()->drawPoints ( points, 7, sofa::type::RGBAColor::yellow()); // Draw mapping line between models - const InVecCoord& in = this->fromModel->read(core::ConstVecCoordId::position())->getValue(); + const InVecCoord& in = this->fromModel->read(core::vec_id::read_access::position)->getValue(); if ( d_mapper!=nullptr ) d_mapper->draw(vparams,out,in); @@ -386,8 +386,8 @@ void BarycentricMapping::handleTopologyChange ( core::topology::Topol { //forward topological modifications to the mapper if (this->d_mapper.get()){ - this->d_mapper->processTopologicalChanges(((const core::State *)this->toModel)->read(core::ConstVecCoordId::position())->getValue(), - ((const core::State *)this->fromModel)->read(core::ConstVecCoordId::position())->getValue(), + this->d_mapper->processTopologicalChanges(((const core::State *)this->toModel)->read(core::vec_id::read_access::position)->getValue(), + ((const core::State *)this->fromModel)->read(core::vec_id::read_access::position)->getValue(), t); } } diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMappingRigid.cpp b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMappingRigid.cpp index 8d71d8a7052..b6c8dafbdee 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMappingRigid.cpp +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMappingRigid.cpp @@ -63,7 +63,7 @@ void BarycentricMapperHexahedronSetTopology InMechanicalStateT; InMechanicalStateT* inState; this->m_fromTopology->getContext()->get(inState); - const auto& inRestPos = (inState->read(core::ConstVecCoordId::restPosition())->getValue()); + const auto& inRestPos = (inState->read(core::vec_id::read_access::restPosition)->getValue()); for ( std::list::const_iterator changeIt = itBegin; changeIt != itEnd; ++changeIt ) diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMappingRigid.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMappingRigid.inl index df3125fe8c8..293cc847f61 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMappingRigid.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMappingRigid.inl @@ -276,7 +276,7 @@ void BarycentricMapperTetrahedronSetTopologyRigid::applyJT( typename In: typename core::behavior::MechanicalState* mechanicalObject; this->getContext()->get(mechanicalObject); -// const typename Out::VecCoord& pX =mechanicalObject->read(core::ConstVecCoordId::position())->getValue(); +// const typename Out::VecCoord& pX =mechanicalObject->read(core::vec_id::read_access::position)->getValue(); // TODO: use d_mapOrient //const sofa::type::vector& d_mapOrient = this->d_mapOrient.getValue(); diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BeamLinearMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BeamLinearMapping.inl index 8d55b8eebc3..994ebbf414d 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BeamLinearMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BeamLinearMapping.inl @@ -66,7 +66,7 @@ void BeamLinearMapping::init() const bool local = localCoord.getValue(); if (this->points.empty() && this->toModel!=nullptr) { - const typename In::VecCoord& xfrom = this->fromModel->read(core::ConstVecCoordId::position())->getValue(); + const typename In::VecCoord& xfrom = this->fromModel->read(core::vec_id::read_access::position)->getValue(); beamLength.resize(xfrom.size()); for (unsigned int i=0; i::init() if (xfrom.size()>=2) beamLength[xfrom.size()-1] = beamLength[xfrom.size()-2]; - const VecCoord& x = this->toModel->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->toModel->read(core::vec_id::read_access::position)->getValue(); msg_info() << "BeamLinearMapping: init "<::applyJT(const core::ConstraintParams * /*cpar typename In::MatrixDeriv* out = _out.beginEdit(); const typename Out::MatrixDeriv& in = _in.getValue(); - const typename In::VecCoord& x = this->fromModel->read(core::ConstVecCoordId::position())->getValue(); + const typename In::VecCoord& x = this->fromModel->read(core::vec_id::read_access::position)->getValue(); typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); @@ -265,7 +265,7 @@ void BeamLinearMapping::draw(const core::visual::VisualParams* vparam std::vector< sofa::type::Vec3 > points; sofa::type::Vec3 point; - const typename Out::VecCoord& x = this->toModel->read(core::ConstVecCoordId::position())->getValue(); + const typename Out::VecCoord& x = this->toModel->read(core::vec_id::read_access::position)->getValue(); for (unsigned int i=0; i::draw(const core::visual::VisualParams* vpar const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); - const typename Out::VecCoord &X = this->toModel->read(core::ConstVecCoordId::position())->getValue(); + const typename Out::VecCoord &X = this->toModel->read(core::vec_id::read_access::position)->getValue(); std::vector< sofa::type::Vec3 > points; sofa::type::Vec3 point1,point2; diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/CenterOfMassMulti2Mapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/CenterOfMassMulti2Mapping.inl index f8de8d20f52..164c5d8b7e8 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/CenterOfMassMulti2Mapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/CenterOfMassMulti2Mapping.inl @@ -268,7 +268,7 @@ template void CenterOfMassMulti2Mapping< TIn1, TIn2, TOut >::draw(const core::visual::VisualParams* vparams) { assert( this->toModels.size() == 1 ); - const Data< OutVecCoord > *X = this->getToModels()[0]->read(sofa::core::VecCoordId::position()); + const Data< OutVecCoord > *X = this->getToModels()[0]->read(sofa::core::vec_id::write_access::position); std::vector< sofa::type::Vec3 > points; sofa::type::Vec3 point1,point2; diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/CenterOfMassMultiMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/CenterOfMassMultiMapping.inl index 7dccb9ae686..0ad2447ea9c 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/CenterOfMassMultiMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/CenterOfMassMultiMapping.inl @@ -181,7 +181,7 @@ template void CenterOfMassMultiMapping< TIn, TOut >::draw(const core::visual::VisualParams* vparams) { assert( this->toModels.size() == 1 ); - const sofa::core::objectmodel::Data< OutVecCoord > *X = this->getToModels()[0]->read(sofa::core::VecCoordId::position()); + const sofa::core::objectmodel::Data< OutVecCoord > *X = this->getToModels()[0]->read(sofa::core::vec_id::write_access::position); std::vector< sofa::type::Vec3 > points; sofa::type::Vec3 point1,point2; diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DeformableOnRigidFrameMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DeformableOnRigidFrameMapping.inl index 3c4f2e8a4cb..dd14a870950 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DeformableOnRigidFrameMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DeformableOnRigidFrameMapping.inl @@ -118,7 +118,7 @@ void DeformableOnRigidFrameMapping::setRepartition(sofa::typ template const typename DataTypes::VecCoord& M_getX0(core::behavior::MechanicalState* model) { - return model->read(core::ConstVecCoordId::restPosition())->getValue(); + return model->read(core::vec_id::read_access::restPosition)->getValue(); } template @@ -323,11 +323,11 @@ void DeformableOnRigidFrameMapping::applyJT( typename In::Ve msg_warning()<<" applyJT was called before any apply ("<read(core::ConstVecCoordId::position()); + const InDataVecCoord* xfromData = m_toModel->read(core::vec_id::read_access::position); const InVecCoord xfrom = xfromData->getValue(); - OutDataVecCoord* xtoData = m_toModel->write(core::VecCoordId::position()); + OutDataVecCoord* xtoData = m_toModel->write(core::vec_id::write_access::position); OutVecCoord &xto = *xtoData->beginEdit(); - apply(xto, xfrom, (m_fromRootModel==nullptr ? nullptr : &m_fromRootModel->read(core::ConstVecCoordId::position())->getValue())); + apply(xto, xfrom, (m_fromRootModel==nullptr ? nullptr : &m_fromRootModel->read(core::vec_id::read_access::position)->getValue())); this->f_printLog.setValue(log); xtoData->endEdit(); } @@ -493,9 +493,9 @@ void DeformableOnRigidFrameMapping::handleTopologyChange(cor { case core::topology::TRIANGLESADDED: ///< To notify the end for the current sequence of topological change events { - core::Multi2Mapping::apply(core::mechanicalparams::defaultInstance(), core::VecCoordId::restPosition(), core::ConstVecCoordId::restPosition()); + core::Multi2Mapping::apply(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::restPosition, core::vec_id::read_access::restPosition); if(this->f_applyRestPosition.getValue() ) - core::Multi2Mapping::apply(core::mechanicalparams::defaultInstance(), core::VecCoordId::position(), core::ConstVecCoordId::position()); + core::Multi2Mapping::apply(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::position, core::vec_id::read_access::position); break; } default: @@ -520,7 +520,7 @@ void DeformableOnRigidFrameMapping::draw(const core::visual: std::vector< sofa::type::Vec3 > points; sofa::type::Vec3 point; - const typename Out::VecCoord& x = m_toModel->read(core::ConstVecCoordId::position())->getValue(); + const typename Out::VecCoord& x = m_toModel->read(core::vec_id::read_access::position)->getValue(); for (unsigned int i=0; i typedef typename In::Coord InCoord; typedef typename In::Deriv InDeriv; typedef typename In::MatrixDeriv InMatrixDeriv; + typedef Data InDataVecCoord; + typedef Data InDataVecDeriv; typedef typename Out::VecCoord VecCoord; typedef typename Out::VecDeriv VecDeriv; @@ -61,6 +63,8 @@ class IdentityMapping : public LinearMapping typedef typename OutDataTypes::Real OutReal; typedef typename OutDataTypes::VecCoord OutVecCoord; typedef typename OutDataTypes::VecDeriv OutVecDeriv; + typedef Data OutDataVecCoord; + typedef Data OutDataVecDeriv; enum { diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMultiMapping.h b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMultiMapping.h index 8f5b998cd95..2ebb82cf83b 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMultiMapping.h +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMultiMapping.h @@ -30,7 +30,7 @@ namespace sofa::component::mapping::linear { -/// concatanate several entire mechanical states together +/// Concatenate several mechanical states together template class IdentityMultiMapping : public LinearMultiMapping { diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/LineSetSkinningMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/LineSetSkinningMapping.inl index a9c9d82910b..ef060fb4083 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/LineSetSkinningMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/LineSetSkinningMapping.inl @@ -74,8 +74,8 @@ double LineSetSkinningMapping::convolutionSegment(const type::Vec<3,R template void LineSetSkinningMapping::init() { - const OutVecCoord& xto = this->toModel->read(core::ConstVecCoordId::position())->getValue(); - const InVecCoord& xfrom = this->fromModel->read(core::ConstVecCoordId::position())->getValue(); + const OutVecCoord& xto = this->toModel->read(core::vec_id::read_access::position)->getValue(); + const InVecCoord& xfrom = this->fromModel->read(core::vec_id::read_access::position)->getValue(); m_topology = this->fromModel->getContext()->getMeshTopology(); linesInfluencedByVertice.resize(xto.size()); @@ -199,8 +199,8 @@ void LineSetSkinningMapping::draw(const core::visual::VisualParams* v const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); vparams->drawTool()->disableLighting(); - const OutVecCoord& xto = this->toModel->read(core::ConstVecCoordId::position())->getValue(); - const InVecCoord& xfrom = this->fromModel->read(core::ConstVecCoordId::position())->getValue(); + const OutVecCoord& xto = this->toModel->read(core::vec_id::read_access::position)->getValue(); + const InVecCoord& xfrom = this->fromModel->read(core::vec_id::read_access::position)->getValue(); std::vector colorVector; std::vector vertices; @@ -249,7 +249,7 @@ void LineSetSkinningMapping::applyJ( const sofa::core::MechanicalPara { SOFA_UNUSED(mparams); - const InVecCoord& xfrom = this->fromModel->read(core::ConstVecCoordId::position())->getValue(); + const InVecCoord& xfrom = this->fromModel->read(core::vec_id::read_access::position)->getValue(); OutVecDeriv& out = *outData.beginEdit(); const InVecDeriv& in = inData.getValue(); for (unsigned int verticeIndex=0; verticeIndex::applyJT( const sofa::core::MechanicalPar InVecDeriv& out = *outData.beginEdit(); const OutVecDeriv& in = inData.getValue(); - const InVecCoord& xfrom = this->fromModel->read(core::ConstVecCoordId::position())->getValue(); + const InVecCoord& xfrom = this->fromModel->read(core::vec_id::read_access::position)->getValue(); out.clear(); out.resize(xfrom.size()); @@ -319,7 +319,7 @@ void LineSetSkinningMapping::applyJT( const sofa::core::ConstraintPar InMatrixDeriv& out = *outData.beginEdit(); const OutMatrixDeriv& in = inData.getValue(); - const InVecCoord& xfrom = this->fromModel->read(core::ConstVecCoordId::position())->getValue(); + const InVecCoord& xfrom = this->fromModel->read(core::vec_id::read_access::position)->getValue(); typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SkinningMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SkinningMapping.inl index f7efa3a8b77..c230af9a38b 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SkinningMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SkinningMapping.inl @@ -70,7 +70,7 @@ template void SkinningMapping::init() { unsigned int numChildren = this->toModel->getSize(); - sofa::helper::ReadAccessor > out (*this->toModel->read(core::ConstVecCoordId::position())); + sofa::helper::ReadAccessor > out (*this->toModel->read(core::vec_id::read_access::position)); sofa::helper::WriteAccessor > initPos(this->d_initPos); if(this->d_initPos.getValue().size() != numChildren ) @@ -92,9 +92,9 @@ void SkinningMapping::reinit() { unsigned int nbref = d_nbRef.getValue()[0]; - sofa::helper::ReadAccessor > out (*this->toModel->read(core::ConstVecCoordId::position())); + sofa::helper::ReadAccessor > out (*this->toModel->read(core::vec_id::read_access::position)); sofa::helper::ReadAccessor > xto (this->d_initPos); - sofa::helper::ReadAccessor > xfrom = *this->fromModel->read(core::ConstVecCoordId::restPosition()); + sofa::helper::ReadAccessor > xfrom = *this->fromModel->read(core::vec_id::read_access::restPosition); sofa::helper::WriteAccessor > > > m_weights (d_weight ); const sofa::helper::ReadAccessor > > > index ( this->d_index ); @@ -141,7 +141,7 @@ void SkinningMapping::updateWeights () msg_info() << "UPDATE WEIGHTS"; sofa::helper::ReadAccessor > xto (this->d_initPos); - sofa::helper::ReadAccessor > xfrom = *this->fromModel->read(core::ConstVecCoordId::restPosition()); + sofa::helper::ReadAccessor > xfrom = *this->fromModel->read(core::vec_id::read_access::restPosition); sofa::helper::WriteAccessor > > > m_weights (d_weight ); sofa::helper::WriteAccessor > > > index (d_index ); @@ -350,8 +350,8 @@ const sofa::linearalgebra::BaseMatrix* SkinningMapping::getJ() template void SkinningMapping::draw(const core::visual::VisualParams* vparams) { - const typename Out::VecCoord& xto = this->toModel->read(core::ConstVecCoordId::position())->getValue(); - const typename In::VecCoord& xfrom = this->fromModel->read(core::ConstVecCoordId::position())->getValue(); + const typename Out::VecCoord& xto = this->toModel->read(core::vec_id::read_access::position)->getValue(); + const typename In::VecCoord& xfrom = this->fromModel->read(core::vec_id::read_access::position)->getValue(); unsigned int nbref = this->d_nbRef.getValue()[0]; sofa::helper::ReadAccessor > > > m_weights (d_weight ); diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMapping.inl index 813757c5b47..238bdffeb77 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMapping.inl @@ -99,8 +99,8 @@ void SubsetMapping::init() { // We have to construct the correspondence index - const InVecCoord& in =this->fromModel->read(core::ConstVecCoordId::position())->getValue(); - const OutVecCoord& out =this->toModel->read(core::ConstVecCoordId::position())->getValue(); + const InVecCoord& in =this->fromModel->read(core::vec_id::read_access::position)->getValue(); + const OutVecCoord& out =this->toModel->read(core::vec_id::read_access::position)->getValue(); IndexArray& indices = *d_indices.beginEdit(); indices.resize(out.size()); @@ -200,7 +200,7 @@ void SubsetMapping::apply ( const core::MechanicalParams* /*mparams*/ } const InVecCoord& in = dIn.getValue(); - const OutVecCoord& out0 = this->toModel->read(core::ConstVecCoordId::restPosition())->getValue(); + const OutVecCoord& out0 = this->toModel->read(core::vec_id::read_access::restPosition)->getValue(); OutVecCoord& out = *dOut.beginEdit(); const auto fromSize = in.size(); @@ -298,8 +298,8 @@ const sofa::linearalgebra::BaseMatrix* SubsetMapping::getJ() { if (matrixJ.get() == 0 || updateJ) { - const OutVecCoord& out =this->toModel->read(core::ConstVecCoordId::position())->getValue(); - const InVecCoord& in =this->fromModel->read(core::ConstVecCoordId::position())->getValue(); + const OutVecCoord& out =this->toModel->read(core::vec_id::read_access::position)->getValue(); + const InVecCoord& in =this->fromModel->read(core::vec_id::read_access::position)->getValue(); const IndexArray& indices = d_indices.getValue(); assert(indices.size() == out.size()); const std::size_t fromSize = in.size(); diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMultiMapping.h b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMultiMapping.h index 066888c34e5..75fe2fe440c 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMultiMapping.h +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMultiMapping.h @@ -34,10 +34,6 @@ namespace sofa::component::mapping::linear { -/** - * @class SubsetMapping - * @brief Compute a subset of input points - */ template class SubsetMultiMapping : public LinearMultiMapping { @@ -48,28 +44,6 @@ class SubsetMultiMapping : public LinearMultiMapping typedef TIn In; typedef TOut Out; - typedef typename Out::VecCoord OutVecCoord; - typedef typename Out::VecDeriv OutVecDeriv; - typedef typename Out::Coord OutCoord; - typedef typename Out::Deriv OutDeriv; - typedef typename Out::MatrixDeriv OutMatrixDeriv; - typedef typename In::VecCoord InVecCoord; - typedef typename In::VecDeriv InVecDeriv; - typedef typename In::Coord InCoord; - typedef typename In::Deriv InDeriv; - typedef typename In::MatrixDeriv InMatrixDeriv; - typedef typename InCoord::value_type Real; - typedef typename type::vector vecConstInVecCoord; - typedef typename type::vector vecOutVecCoord; - - typedef Data InDataVecCoord; - typedef Data InDataVecDeriv; - typedef Data InDataMatrixDeriv; - - typedef Data OutDataVecCoord; - typedef Data OutDataVecDeriv; - typedef Data OutDataMatrixDeriv; - /// Correspondence array typedef core::topology::BaseMeshTopology::SetIndex IndexArray; @@ -81,12 +55,12 @@ class SubsetMultiMapping : public LinearMultiMapping void addPoint(int fromModel, int index); // usual Mapping API - void apply(const core::MechanicalParams* mparams, const type::vector& dataVecOutPos, const type::vector& dataVecInPos) override; - void applyJ(const core::MechanicalParams* mparams, const type::vector& dataVecOutVel, const type::vector& dataVecInVel) override; - void applyJT(const core::MechanicalParams* mparams, const type::vector& dataVecOutForce, const type::vector& dataVecInForce) override; + void apply(const core::MechanicalParams* mparams, const type::vector*>& dataVecOutPos, const type::vector*>& dataVecInPos) override; + void applyJ(const core::MechanicalParams* mparams, const type::vector*>& dataVecOutVel, const type::vector*>& dataVecInVel) override; + void applyJT(const core::MechanicalParams* mparams, const type::vector*>& dataVecOutForce, const type::vector*>& dataVecInForce) override; void applyDJT(const core::MechanicalParams* /*mparams*/, core::MultiVecDerivId /*inForce*/, core::ConstMultiVecDerivId /*outForce*/) override {} - void applyJT( const core::ConstraintParams* cparams, const type::vector< InDataMatrixDeriv* >& dataMatOutConst, const type::vector< const OutDataMatrixDeriv* >& dataMatInConst ) override; + void applyJT( const core::ConstraintParams* cparams, const type::vector< DataMatrixDeriv_t* >& dataMatOutConst, const type::vector< const DataMatrixDeriv_t* >& dataMatInConst ) override; /// Experimental API used to handle multimappings in matrix assembly. Returns pointers to matrices associated with parent states, consistently with getFrom(). virtual const type::vector* getJs() override; @@ -99,7 +73,7 @@ class SubsetMultiMapping : public LinearMultiMapping protected : SubsetMultiMapping(); - virtual ~SubsetMultiMapping(); + virtual ~SubsetMultiMapping() override; type::vector baseMatrices; ///< Jacobian of the mapping, in a vector @@ -112,7 +86,6 @@ extern template class SOFA_COMPONENT_MAPPING_LINEAR_API SubsetMultiMapping< defa extern template class SOFA_COMPONENT_MAPPING_LINEAR_API SubsetMultiMapping< defaulttype::Vec1Types, defaulttype::Vec1Types >; extern template class SOFA_COMPONENT_MAPPING_LINEAR_API SubsetMultiMapping< defaulttype::Rigid3Types, defaulttype::Rigid3Types >; extern template class SOFA_COMPONENT_MAPPING_LINEAR_API SubsetMultiMapping< defaulttype::Rigid3Types, defaulttype::Vec3Types >; - #endif } // namespace sofa::component::mapping::linear diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMultiMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMultiMapping.inl index 261b0f853fd..62e1d9dd422 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMultiMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMultiMapping.inl @@ -43,25 +43,29 @@ void SubsetMultiMapping::init() static constexpr auto Nout = TOut::deriv_total_size; - for( unsigned i=0; i Jacobian; baseMatrices.resize( this->getFrom().size() ); type::vector jacobians( this->getFrom().size() ); - for(unsigned i=0; i; jacobians[i]->resize(Nout*indexPairSize,Nin*this->fromModels[i]->getSize() ); // each jacobian has the same number of rows } + const auto& indexPairsValue = d_indexPairs.getValue(); + // fill the Jacobians - for(unsigned i=0; i::init() } } // finalize the Jacobians - for(unsigned i=0; icompress(); + for (linearalgebra::BaseMatrix* baseMat : baseMatrices) + { + baseMat->compress(); + } } template SubsetMultiMapping::SubsetMultiMapping() - : Inherit() - , d_indexPairs(initData(&d_indexPairs, type::vector(), "indexPairs", "list of couples (parent index + index in the parent)")) + : d_indexPairs(initData(&d_indexPairs, type::vector(), "indexPairs", + "list of couples (parent index + index in the parent)")) { - indexPairs.setOriginalData(&d_indexPairs); + indexPairs.setOriginalData(&d_indexPairs); } template SubsetMultiMapping::~SubsetMultiMapping() { - for(unsigned i=0; i* SubsetMultiMapping void SubsetMultiMapping::addPoint( const core::BaseState* from, int index) { - // find the index of the parent state unsigned i; - for(i=0; ifromModels.size(); i++) - if(this->fromModels.get(i)==from ) + for (i = 0; i < this->fromModels.size(); i++) + { + if (this->fromModels.get(i) == from) + { break; - if(i==this->fromModels.size()) + } + } + if (i == this->fromModels.size()) { - msg_error() << "SubsetMultiMapping::addPoint, parent " << from->getName() << " not found !"; + msg_error() << "addPoint, parent " << from->getName() << " not found !"; assert(0); } @@ -119,56 +128,52 @@ template void SubsetMultiMapping::addPoint( int from, int index) { assert((size_t)from < this->fromModels.size()); - type::vector& indexPairsVector = *d_indexPairs.beginEdit(); + auto indexPairsVector = sofa::helper::getWriteAccessor(d_indexPairs); indexPairsVector.push_back(from); indexPairsVector.push_back(index); - d_indexPairs.endEdit(); } - -template -void SubsetMultiMapping::apply(const core::MechanicalParams* mparams, const type::vector& dataVecOutPos, const type::vector& dataVecInPos) +template +void apply_impl( + const type::vector& dataVecOut, + const type::vector& dataVecIn, + const type::vector& indexPairs) { - SOFA_UNUSED(mparams); - - OutVecCoord& out = *(dataVecOutPos[0]->beginEdit()); + auto out = sofa::helper::getWriteOnlyAccessor(*dataVecOut[0]); - for(unsigned i=0; iendEdit(); + const DataVecIn* inPosPtr = dataVecIn[stateId]; + const typename DataVecIn::value_type& inPos = inPosPtr->getValue(); + core::eq( out[i], inPos[coordId] ); + } } template -void SubsetMultiMapping::applyJ(const core::MechanicalParams* mparams, const type::vector& dataVecOutVel, const type::vector& dataVecInVel) +void SubsetMultiMapping::apply(const core::MechanicalParams* mparams, const type::vector*>& dataVecOutPos, const type::vector*>& dataVecInPos) { SOFA_UNUSED(mparams); + apply_impl( dataVecOutPos, dataVecInPos, d_indexPairs.getValue()); +} - OutVecDeriv& out = *(dataVecOutVel[0]->beginEdit()); - - for(unsigned i=0; iendEdit(); +template +void SubsetMultiMapping::applyJ(const core::MechanicalParams* mparams, const type::vector*>& dataVecOutVel, const type::vector*>& dataVecInVel) +{ + SOFA_UNUSED(mparams); + apply_impl( dataVecOutVel, dataVecInVel, d_indexPairs.getValue()); } template -void SubsetMultiMapping::applyJT( const core::ConstraintParams* /*cparams*/, const type::vector< InDataMatrixDeriv* >& dOut, const type::vector< const OutDataMatrixDeriv* >& dIn) +void SubsetMultiMapping::applyJT( const core::ConstraintParams* /*cparams*/, const type::vector< DataMatrixDeriv_t* >& dOut, const type::vector< const DataMatrixDeriv_t* >& dIn) { type::vector indexP = d_indexPairs.getValue(); // hypothesis: one child only: - const OutMatrixDeriv& in = dIn[0]->getValue(); + const MatrixDeriv_t& in = dIn[0]->getValue(); if (dOut.size() != this->fromModels.size()) { @@ -176,13 +181,13 @@ void SubsetMultiMapping::applyJT( const core::ConstraintParams* /*cpa return; } - typename OutMatrixDeriv::RowConstIterator rowItEnd = in.end(); + typename MatrixDeriv_t::RowConstIterator rowItEnd = in.end(); // loop on the constraints defined on the child of the mapping - for (typename OutMatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) + for (typename MatrixDeriv_t::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) { - typename OutMatrixDeriv::ColConstIterator colIt = rowIt.begin(); - typename OutMatrixDeriv::ColConstIterator colItEnd = rowIt.end(); + typename MatrixDeriv_t::ColConstIterator colIt = rowIt.begin(); + typename MatrixDeriv_t::ColConstIterator colItEnd = rowIt.end(); // A constraint can be shared by several nodes, @@ -194,38 +199,40 @@ void SubsetMultiMapping::applyJT( const core::ConstraintParams* /*cpa { unsigned int index_parent = indexP[colIt.index() * 2]; // 0 or 1 (for now...) // writeLine provide an iterator on the line... if this line does not exist, the line is created: - typename InMatrixDeriv::RowIterator o = dOut[index_parent]->beginEdit()->writeLine(rowIt.index()); + typename MatrixDeriv_t::RowIterator o = dOut[index_parent]->beginEdit()->writeLine(rowIt.index()); dOut[index_parent]->endEdit(); // for each col of the constraint direction, it adds a col in the corresponding parent's constraint direction if(d_indexPairs.getValue()[colIt.index() * 2 + 1] < (unsigned int)this->fromModels[index_parent]->getSize()) { - InDeriv tmp; core::eq( tmp, colIt.val() ); + Deriv_t tmp; + core::eq( tmp, colIt.val() ); o.addCol(indexP[colIt.index() * 2 + 1], tmp); } ++colIt; } - - - } } template -void SubsetMultiMapping::applyJT(const core::MechanicalParams* mparams, const type::vector& dataVecOutForce, const type::vector& dataVecInForce) +void SubsetMultiMapping::applyJT(const core::MechanicalParams* mparams, const type::vector*>& dataVecOutForce, const type::vector*>& dataVecInForce) { SOFA_UNUSED(mparams); - const OutDataVecDeriv* cderData = dataVecInForce[0]; - const OutVecDeriv& cder = cderData->getValue(); + const DataVecDeriv_t* cderData = dataVecInForce[0]; + const VecDeriv_t& cder = cderData->getValue(); + + const auto& indexPairsValue = d_indexPairs.getValue(); - for(unsigned i=0; i* inDerivPtr = dataVecOutForce[stateId]; + auto inDeriv = sofa::helper::getWriteAccessor(*inDerivPtr); + core::peq(inDeriv[coordId], cder[i] ); } } diff --git a/Sofa/Component/Mapping/Linear/tests/SubsetMultiMapping_test.cpp b/Sofa/Component/Mapping/Linear/tests/SubsetMultiMapping_test.cpp index b70504770a6..b9fec71addd 100644 --- a/Sofa/Component/Mapping/Linear/tests/SubsetMultiMapping_test.cpp +++ b/Sofa/Component/Mapping/Linear/tests/SubsetMultiMapping_test.cpp @@ -21,75 +21,39 @@ ******************************************************************************/ #include #include -//#include +#include #include #include namespace sofa { -namespace { -using namespace core; -using namespace component; -using type::Vec; -using type::Mat; -using type::vector; +using component::mapping::linear::SubsetMultiMapping; - -/** Test suite for SubsetMultiMapping. - */ +/** + * Test suite for SubsetMultiMapping. + */ template struct SubsetMultiMappingTest : public MultiMapping_test<_SubsetMultiMapping> { + using In = typename _SubsetMultiMapping::In; + using Out = typename _SubsetMultiMapping::Out; - typedef _SubsetMultiMapping SubsetMultiMapping; - - typedef typename SubsetMultiMapping::In InDataTypes; - typedef typename InDataTypes::VecCoord InVecCoord; - typedef typename InDataTypes::VecDeriv InVecDeriv; - typedef typename InDataTypes::Coord InCoord; - typedef typename InDataTypes::Deriv InDeriv; - typedef statecontainer::MechanicalObject InMechanicalObject; - typedef typename InMechanicalObject::ReadVecCoord ReadInVecCoord; - typedef typename InMechanicalObject::WriteVecCoord WriteInVecCoord; - typedef typename InMechanicalObject::WriteVecDeriv WriteInVecDeriv; - typedef typename InDataTypes::Real InReal; - typedef Mat RotationMatrix; - - - typedef typename SubsetMultiMapping::Out OutDataTypes; - typedef typename OutDataTypes::VecCoord OutVecCoord; - typedef typename OutDataTypes::VecDeriv OutVecDeriv; - typedef typename OutDataTypes::Coord OutCoord; - typedef typename OutDataTypes::Deriv OutDeriv; - typedef statecontainer::MechanicalObject OutMechanicalObject; - typedef typename OutMechanicalObject::WriteVecCoord WriteOutVecCoord; - typedef typename OutMechanicalObject::WriteVecDeriv WriteOutVecDeriv; - typedef typename OutMechanicalObject::ReadVecCoord ReadOutVecCoord; - typedef typename OutMechanicalObject::ReadVecDeriv ReadOutVecDeriv; - - void SetUp() override - { - } - - /** @name Test_Cases - For each of these cases, we can test if the mapping work - */ - ///@{ - /** Two parent particles, two children - */ + /** + * Two parent particles, two children + */ bool test_two_parents_one_child() { - const int NP = 2; + static constexpr int NP = 2; this->setupScene(NP); // NP parents, 1 child - SubsetMultiMapping* smm = static_cast( this->mapping ); + _SubsetMultiMapping* smm = static_cast<_SubsetMultiMapping*>( this->mapping ); // parent positions - vector< InVecCoord > incoords(NP); - for( int i=0; i > incoords(NP); + for (int i = 0; i < NP; i++) { incoords[i].resize(1); - InDataTypes::set( incoords[i][0], i+1.,-2., 3. ); + In::set( incoords[i][0], i+1.,-2., 3. ); } // subset @@ -97,34 +61,28 @@ struct SubsetMultiMappingTest : public MultiMapping_test<_SubsetMultiMapping> smm->addPoint(smm->getMechFrom()[1],0); // parent, index in parent // expected child positions - OutVecCoord outcoords(2); - OutDataTypes::set( outcoords[0], 1. , -2., 3. ); - OutDataTypes::set( outcoords[1], 1+1., -2., 3. ); + VecCoord_t outcoords(2); + Out::set( outcoords[0], 1. , -2., 3. ); + Out::set( outcoords[1], 1+1., -2., 3. ); return this->runTest(incoords,outcoords); } - - - ///@} - - }; - -// Define the list of types to instantiate. We do not necessarily need to test all combinations. using ::testing::Types; typedef Types< -mapping::linear::SubsetMultiMapping, -mapping::linear::SubsetMultiMapping -> DataTypes; // the types to instantiate. + SubsetMultiMapping, + SubsetMultiMapping, + SubsetMultiMapping, + SubsetMultiMapping, + SubsetMultiMapping +> DataTypes; -// Test suite for all the instantiations TYPED_TEST_SUITE(SubsetMultiMappingTest, DataTypes); -// first test case + TYPED_TEST( SubsetMultiMappingTest , two_parents_one_child ) { ASSERT_TRUE(this->test_two_parents_one_child()); } -} // namespace } // namespace sofa diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.h b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.h index 316b04215fd..5f61362a380 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.h +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.h @@ -60,6 +60,8 @@ class RigidMapping : public core::Mapping, public NonLinearMappingDat typedef typename Out::VecCoord OutVecCoord; typedef typename Out::VecDeriv OutVecDeriv; typedef typename Out::MatrixDeriv OutMatrixDeriv; + typedef Data OutDataVecCoord; + typedef Data OutDataVecDeriv; typedef typename In::Real InReal; typedef typename In::Coord InCoord; @@ -67,6 +69,8 @@ class RigidMapping : public core::Mapping, public NonLinearMappingDat typedef typename In::VecCoord InVecCoord; typedef typename In::VecDeriv InVecDeriv; typedef typename In::MatrixDeriv InMatrixDeriv; + typedef Data InDataVecCoord; + typedef Data InDataVecDeriv; enum { diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.inl b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.inl index 9db5a35faeb..fa2d0f1911c 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.inl +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.inl @@ -179,7 +179,7 @@ void RigidMapping::reinit() { if (d_points.getValue().empty() && this->toModel != nullptr && !d_useX0.getValue()) { - const OutVecCoord& xTo =this->toModel->read(core::ConstVecCoordId::position())->getValue(); + const OutVecCoord& xTo =this->toModel->read(core::vec_id::read_access::position)->getValue(); helper::WriteOnlyAccessor > points = d_points; sofa::Size toModelSize = xTo.size(); points.resize(toModelSize); @@ -187,7 +187,7 @@ void RigidMapping::reinit() if (d_globalToLocalCoords.getValue()) { unsigned int i = 0; - const InVecCoord& xFrom =this->fromModel->read(core::ConstVecCoordId::position())->getValue(); + const InVecCoord& xFrom =this->fromModel->read(core::vec_id::read_access::position)->getValue(); for (i = 0; i < toModelSize; i++) { @@ -290,7 +290,7 @@ const typename RigidMapping::OutVecCoord & RigidMapping::g { if (d_useX0.getValue()) { - const Data* v = this->toModel.get()->read(core::VecCoordId::restPosition()); + const Data* v = this->toModel.get()->read(core::vec_id::write_access::restPosition); if (v) { return v->getValue(); @@ -511,8 +511,8 @@ void fill_block(Eigen::Matrix& block, const Coord& v) { template const type::vector* RigidMapping::getJs() { - const OutVecCoord& out =this->toModel->read(core::ConstVecCoordId::position())->getValue(); - const InVecCoord& in =this->fromModel->read(core::ConstVecCoordId::position())->getValue(); + const OutVecCoord& out =this->toModel->read(core::vec_id::read_access::position)->getValue(); + const InVecCoord& in =this->fromModel->read(core::vec_id::read_access::position)->getValue(); typename SparseMatrixEigen::CompressedMatrix& J = m_eigenJacobian.compressedMatrix; @@ -700,8 +700,8 @@ void RigidMapping::buildGeometricStiffnessMatrix( template const sofa::linearalgebra::BaseMatrix* RigidMapping::getJ() { - const OutVecCoord& out =this->toModel->read(core::ConstVecCoordId::position())->getValue(); - const InVecCoord& in =this->fromModel->read(core::ConstVecCoordId::position())->getValue(); + const OutVecCoord& out =this->toModel->read(core::vec_id::read_access::position)->getValue(); + const InVecCoord& in =this->fromModel->read(core::vec_id::read_access::position)->getValue(); const OutVecCoord& pts = this->getPoints(); assert(pts.size() == out.size()); @@ -777,7 +777,7 @@ void RigidMapping::draw(const core::visual::VisualParams* vparams) std::vector points; type::Vec3 point; - const OutVecCoord& x =this->toModel->read(core::ConstVecCoordId::position())->getValue(); + const OutVecCoord& x =this->toModel->read(core::vec_id::read_access::position)->getValue(); for (unsigned int i = 0; i < x.size(); i++) { point = Out::getCPos(x[i]); diff --git a/Sofa/Component/Mapping/NonLinear/tests/RigidMapping_test.cpp b/Sofa/Component/Mapping/NonLinear/tests/RigidMapping_test.cpp index 46a53cb53ef..630add17ad0 100644 --- a/Sofa/Component/Mapping/NonLinear/tests/RigidMapping_test.cpp +++ b/Sofa/Component/Mapping/NonLinear/tests/RigidMapping_test.cpp @@ -90,7 +90,7 @@ struct RigidMappingTest : public sofa::mapping_test::Mapping_test<_RigidMapping> if constexpr ( InDataTypes::spatial_dimensions != 3 ) { // RigidMapping::getK is not yet implemented for 2D rigids - this->flags &= ~Inherit::TEST_getK; + this->setTestExecution(Inherit::TEST_getK, false); } } diff --git a/Sofa/Component/Mapping/NonLinear/tests/SquareDistanceMapping_test.cpp b/Sofa/Component/Mapping/NonLinear/tests/SquareDistanceMapping_test.cpp index 833363657c9..a837a54366f 100644 --- a/Sofa/Component/Mapping/NonLinear/tests/SquareDistanceMapping_test.cpp +++ b/Sofa/Component/Mapping/NonLinear/tests/SquareDistanceMapping_test.cpp @@ -212,10 +212,10 @@ struct SquareDistanceMappingCompare_test : NumericTest //position { sofa::type::vector mstatex0(mstate0->getMatrixSize()); - mstate0->copyToBuffer(mstatex0.data(), core::ConstVecCoordId::position(), mstate0->getMatrixSize()); + mstate0->copyToBuffer(mstatex0.data(), core::vec_id::read_access::position, mstate0->getMatrixSize()); sofa::type::vector mstatex1(mstate1->getMatrixSize()); - mstate1->copyToBuffer(mstatex1.data(), core::ConstVecCoordId::position(), mstate1->getMatrixSize()); + mstate1->copyToBuffer(mstatex1.data(), core::vec_id::read_access::position, mstate1->getMatrixSize()); EXPECT_LT(this->vectorMaxDiff(mstatex0, mstatex1), epsilon) << "Time step " << timeStepCount << "\n" << mstatex0 << "\n" << mstatex1; @@ -224,10 +224,10 @@ struct SquareDistanceMappingCompare_test : NumericTest //velocity { sofa::type::vector mstatev0(mstate0->getMatrixSize()); - mstate0->copyToBuffer(mstatev0.data(), core::ConstVecDerivId::velocity(), mstate0->getMatrixSize()); + mstate0->copyToBuffer(mstatev0.data(), core::vec_id::read_access::velocity, mstate0->getMatrixSize()); sofa::type::vector mstatev1(mstate1->getMatrixSize()); - mstate1->copyToBuffer(mstatev1.data(), core::ConstVecDerivId::velocity(), mstate1->getMatrixSize()); + mstate1->copyToBuffer(mstatev1.data(), core::vec_id::read_access::velocity, mstate1->getMatrixSize()); EXPECT_LT(this->vectorMaxDiff(mstatev0, mstatev1), epsilon) << "Time step " << timeStepCount << "\n" << mstatev0 << "\n" << mstatev1; @@ -236,10 +236,10 @@ struct SquareDistanceMappingCompare_test : NumericTest //force { sofa::type::vector mstatef0(mstate0->getMatrixSize()); - mstate0->copyToBuffer(mstatef0.data(), core::ConstVecDerivId::force(), mstate0->getMatrixSize()); + mstate0->copyToBuffer(mstatef0.data(), core::vec_id::read_access::force, mstate0->getMatrixSize()); sofa::type::vector mstatef1(mstate1->getMatrixSize()); - mstate1->copyToBuffer(mstatef1.data(), core::ConstVecDerivId::force(), mstate1->getMatrixSize()); + mstate1->copyToBuffer(mstatef1.data(), core::vec_id::read_access::force, mstate1->getMatrixSize()); EXPECT_LT(this->vectorMaxDiff(mstatef0, mstatef1), epsilon) << "Time step " << timeStepCount << "\n" << mstatef0 << "\n" << mstatef1; diff --git a/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/MappingTestCreation.h b/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/MappingTestCreation.h index 3a430a8deed..63657b8542e 100644 --- a/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/MappingTestCreation.h +++ b/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/MappingTestCreation.h @@ -22,6 +22,7 @@ #pragma once #include +#include #include using sofa::testing::BaseSimulationTest; @@ -30,7 +31,6 @@ using sofa::testing::NumericTest; #include -#include #include #include #include @@ -38,16 +38,17 @@ using sofa::testing::NumericTest; #include -namespace sofa::mapping_test { +namespace sofa::mapping_test +{ /** @brief Base class for the Mapping tests, with helpers to automatically test applyJ, applyJT, applyDJT and getJs using finite differences. Specific test cases can be created using a derived class instantiated on the mapping class to test, - and calling function runTest( const InVecCoord& parentInit, - const OutVecCoord& childInit, - const InVecCoord parentNew, - const OutVecCoord expectedChildNew); + and calling function runTest( const VecCoord_t& parentInit, + const VecCoord_t& childInit, + const VecCoord_t parentNew, + const VecCoord_t expectedChildNew); This function compares the actual output positions with the expected ones, then automatically tests the methods related to @@ -65,41 +66,16 @@ namespace sofa::mapping_test { @author François Faure @date 2013 */ - template< class _Mapping> struct Mapping_test: public BaseSimulationTest, NumericTest { - typedef _Mapping Mapping; - typedef typename Mapping::In In; - typedef component::statecontainer::MechanicalObject InDOFs; - typedef typename InDOFs::Real Real; - typedef typename InDOFs::Coord InCoord; - typedef typename InDOFs::Deriv InDeriv; - typedef typename InDOFs::VecCoord InVecCoord; - typedef typename InDOFs::VecDeriv InVecDeriv; - typedef typename InDOFs::ReadVecCoord ReadInVecCoord; - typedef typename InDOFs::WriteVecCoord WriteInVecCoord; - typedef typename InDOFs::ReadVecDeriv ReadInVecDeriv; - typedef typename InDOFs::WriteVecDeriv WriteInVecDeriv; - typedef typename InDOFs::MatrixDeriv InMatrixDeriv; - typedef Data InDataVecCoord; - typedef Data InDataVecDeriv; - typedef Data InDataMatrixDeriv; - - typedef typename Mapping::Out Out; - typedef component::statecontainer::MechanicalObject OutDOFs; - typedef typename OutDOFs::Coord OutCoord; - typedef typename OutDOFs::Deriv OutDeriv; - typedef typename OutDOFs::VecCoord OutVecCoord; - typedef typename OutDOFs::VecDeriv OutVecDeriv; - typedef typename OutDOFs::ReadVecCoord ReadOutVecCoord; - typedef typename OutDOFs::WriteVecCoord WriteOutVecCoord; - typedef typename OutDOFs::ReadVecDeriv ReadOutVecDeriv; - typedef typename OutDOFs::WriteVecDeriv WriteOutVecDeriv; - typedef typename OutDOFs::MatrixDeriv OutMatrixDeriv; - typedef Data OutDataVecCoord; - typedef Data OutDataVecDeriv; - typedef Data OutDataMatrixDeriv; + using Mapping = _Mapping; + + using In = typename Mapping::In; + using InDOFs = component::statecontainer::MechanicalObject; + + using Out = typename Mapping::Out; + using OutDOFs = component::statecontainer::MechanicalObject; typedef linearalgebra::EigenSparseMatrix EigenSparseMatrix; @@ -107,10 +83,9 @@ struct Mapping_test: public BaseSimulationTest, NumericTest deltaRange; ///< The minimum and maximum magnitudes of the change of each scalar value of the small displacement is perturbation * numeric_limits::epsilon. This epsilon is 1.19209e-07 for float and 2.22045e-16 for double. - Real errorMax; ///< The test is successful if the (infinite norm of the) difference is less than errorMax * numeric_limits::epsilon - Real errorFactorDJ; ///< The test for geometric stiffness is successful if the (infinite norm of the) difference is less than errorFactorDJ * errorMax * numeric_limits::epsilon + std::pair, Real_t> deltaRange; ///< The minimum and maximum magnitudes of the change of each scalar value of the small displacement is perturbation * numeric_limits::epsilon. This epsilon is 1.19209e-07 for float and 2.22045e-16 for double. + Real_t errorMax; ///< The test is successful if the (infinite norm of the) difference is less than errorMax * numeric_limits::epsilon + Real_t errorFactorDJ; ///< The test for geometric stiffness is successful if the (infinite norm of the) difference is less than errorFactorDJ * errorMax * numeric_limits::epsilon static constexpr unsigned char TEST_getJs = 1; ///< testing getJs used in assembly API @@ -122,6 +97,25 @@ struct Mapping_test: public BaseSimulationTest, NumericTestcreateNewGraph("root"); + root = simpleapi::createRootNode(simulation::getSimulation(), "root"); inDofs = core::objectmodel::New(); root->addObject(inDofs); @@ -149,16 +141,15 @@ struct Mapping_test: public BaseSimulationTest, NumericTestcreateNewGraph("root"); + root = simpleapi::createRootNode(simulation::getSimulation(), "root"); root = sofa::simulation::node::load(fileName.c_str(), false); // InDofs @@ -180,34 +171,8 @@ struct Mapping_test: public BaseSimulationTest, NumericTest& parentInit, + const VecCoord_t& childInit, + const VecCoord_t& parentNew, + const VecCoord_t& expectedChildNew) { - if( deltaRange.second / errorMax <= sofa::testing::g_minDeltaErrorRatio ) - ADD_FAILURE() << "The comparison threshold is too large for the finite difference delta"; - - if( !(flags & TEST_getJs) ) msg_warning("MappingTest") << "getJs is not tested"; - if( !(flags & TEST_getK) ) msg_warning("MappingTest") << "getK is not tested"; - if( !(flags & TEST_applyJT_matrix) ) msg_warning("MappingTest") << "applyJT on matrices is not tested"; - if( !(flags & TEST_applyDJT) ) msg_warning("MappingTest") << "applyDJT is not tested"; + checkComparisonThreshold(); + warnMissingTests(); + const auto errorThreshold = this->epsilon() * errorMax; - const Real errorThreshold = this->epsilon()*errorMax; + using EigenSparseMatrix = linearalgebra::EigenSparseMatrix; - typedef linearalgebra::EigenSparseMatrix EigenSparseMatrix; core::MechanicalParams mparams; mparams.setKFactor(1.0); mparams.setSupportOnlySymmetricMatrix(false); - inDofs->resize(parentInit.size()); - WriteInVecCoord xin = inDofs->writePositions(); - sofa::testing::copyToData(xin,parentInit); // xin = parentInit - - outDofs->resize(childInit.size()); - WriteOutVecCoord xout = outDofs->writePositions(); - sofa::testing::copyToData(xout,childInit); - - /// Init based on parentInit - sofa::simulation::node::initRoot(root.get()); - - /// Updated to parentNew - sofa::testing::copyToData(xin,parentNew); - mapping->apply(&mparams, core::VecCoordId::position(), core::VecCoordId::position()); - mapping->applyJ(&mparams, core::VecDerivId::velocity(), core::VecDerivId::velocity()); /// test apply: check if the child positions are the expected ones - bool succeed=true; + bool succeed = testMappingPositionVelocity( + parentInit, childInit, parentNew, expectedChildNew, errorThreshold, + mparams); - if (expectedChildNew.size() != xout.size()) { - ADD_FAILURE() << "Size of output dofs is wrong: " << xout.size() << " expected: " << expectedChildNew.size(); - succeed = false; - } - for( unsigned i=0; iisSmall( difference(xout[i],expectedChildNew[i]).norm(), errorMax ) ) { - ADD_FAILURE() << "Position of mapped particle " << i << " is wrong: \n" << xout[i] <<"\nexpected: \n" << expectedChildNew[i] - << "\ndifference should be less than " << errorThreshold << " (" << difference(xout[i],expectedChildNew[i]).norm() << ")" << std::endl; - succeed = false; - } - } - - /// test applyJ and everything related to Jacobians - size_t Np = inDofs->getSize(), Nc=outDofs->getSize(); - - InVecCoord xp(Np),xp1(Np); - InVecDeriv vp(Np),fp(Np); - InVecDeriv dfp_a(Np); - InVecDeriv dfp_b(Np); - InVecDeriv fp2(Np); - OutVecCoord xc(Nc),xc1(Nc); - OutVecDeriv vc(Nc),fc(Nc); + const std::size_t sizeIn = inDofs->getSize(); + const std::size_t sizeOut = outDofs->getSize(); // get position data - sofa::testing::copyFromData( xp, inDofs->readPositions() ); - sofa::testing::copyFromData( xc, outDofs->readPositions() ); // positions and have already been propagated + VecCoord_t positionOut = outDofs->readPositions().ref(); // set random child forces and propagate them to the parent - for( unsigned i=0; iwriteForces(); - sofa::testing::copyToData( fin, fp2 ); // reset parent forces before accumulating child forces + VecDeriv_t forceOut = generateRandomVecDeriv(sizeOut, 0.1, 1.); - WriteOutVecDeriv fout = outDofs->writeForces(); - sofa::testing::copyToData( fout, fc ); - mapping->applyJT( &mparams, core::VecDerivId::force(), core::VecDerivId::force() ); - sofa::testing::copyFromData( fp, inDofs->readForces() ); + VecDeriv_t forceIn; + computeForceInFromForceOut(mparams, forceIn, forceOut); // set small parent velocities and use them to update the child - for( unsigned i=0; iepsilon() * deltaRange.first, this->epsilon() * deltaRange.second ); - } + const VecDeriv_t velocityIn = generateRandomVecDeriv(sizeIn, + this->epsilon() * deltaRange.first, + this->epsilon() * deltaRange.second); - for( unsigned i=0; i perturbedPositionIn = computePerturbedPositions(sizeIn, velocityIn); - // propagate small velocity - WriteInVecDeriv vin = inDofs->writeVelocities(); - sofa::testing::copyToData( vin, vp ); - mapping->applyJ( &mparams, core::VecDerivId::velocity(), core::VecDerivId::velocity() ); - ReadOutVecDeriv vout = outDofs->readVelocities(); - sofa::testing::copyFromData( vc, vout); + VecDeriv_t velocityOut; + computeVelocityOutFromVelocityIn(mparams, velocityOut, velocityIn); // apply geometric stiffness - inDofs->vRealloc( &mparams, core::VecDerivId::dx() ); // dx is not allocated by default - WriteInVecDeriv dxin = inDofs->writeDx(); - sofa::testing::copyToData( dxin, vp ); - dfp_a.fill( InDeriv() ); - dfp_b.fill( InDeriv() ); - sofa::testing::copyToData( fin, dfp_a ); - sofa::testing::copyToData( fin, dfp_b ); - - //calling applyDJT without updateK before - mapping->applyDJT( &mparams, core::VecDerivId::force(), core::VecDerivId::force() ); - sofa::testing::copyFromData( dfp_a, inDofs->readForces() ); // fp + df due to geometric stiffness - sofa::testing::copyToData( fin, fp2 ); //reset forces - - //calling applyDJT after updateK - mapping->updateK( &mparams, core::ConstVecDerivId::force() ); // updating stiffness matrix for the current state and force - mapping->applyDJT( &mparams, core::VecDerivId::force(), core::VecDerivId::force() ); - sofa::testing::copyFromData( dfp_b, inDofs->readForces() ); // fp + df due to geometric stiffness + inDofs->vRealloc( &mparams, core::vec_id::write_access::dx ); // dx is not allocated by default + inDofs->writeDx().wref() = velocityIn; + + const VecDeriv_t dfp_withoutUpdateK = applyDJT(mparams, false); + const VecDeriv_t dfp_withUpdateK = applyDJT(mparams, true); // Jacobian will be obsolete after applying new positions - if( flags & TEST_getJs ) + if( isTestExecuted(TEST_getJs) ) { EigenSparseMatrix* J = this->getMatrix(mapping->getJs()); - // cout<<"J = "<< endl << *J << endl; - OutVecDeriv Jv(Nc); - J->mult(Jv,vp); - - // ================ test applyJT() - InVecDeriv jfc( (long)Np,InDeriv()); - J->addMultTranspose(jfc,fc); - if( this->vectorMaxDiff(jfc,fp)>errorThreshold ){ - succeed = false; - ADD_FAILURE() << "applyJT test failed, difference should be less than " << errorThreshold << " (" << this->vectorMaxDiff(jfc,fp) << ")" << std::endl - << "jfc = " << jfc << std::endl<<" fp = " << fp << std::endl; - } - // ================ test getJs() - // check that J.vp = vc - if(this->vectorMaxDiff(Jv,vc)>errorThreshold ){ - succeed = false; - std::cout<<"vp = " << vp << std::endl; - std::cout<<"Jvp = " << Jv << std::endl; - std::cout<<"vc = " << vc << std::endl; - ADD_FAILURE() << "getJs() test failed"<vectorMaxAbs(difference(dxc,vc))<<" should be less than " << errorThreshold << std::endl - << "position change = " << dxc << std::endl - << "velocity = " << vc << std::endl; + if( isTestExecuted(TEST_getK)) + { + succeed &= testGetK(sizeIn, velocityIn, forceChange, errorThreshold); } + if( isTestExecuted(TEST_buildGeometricStiffnessMatrix) ) + { + succeed &= testBuildGeometricStiffnessMatrix(sizeIn, velocityIn, forceChange, errorThreshold); + } + if(!succeed) + { + ADD_FAILURE() << "Failed Seed number = " << this->seed << std::endl; + } + return succeed; + } - // update parent force based on the same child forces - fp2.fill( InDeriv() ); - sofa::testing::copyToData( fin, fp2 ); // reset parent forces before accumulating child forces - sofa::testing::copyToData( fout, preTreatment(fc) ); - mapping->applyJT( &mparams, core::VecDerivId::force(), core::VecDerivId::force() ); - sofa::testing::copyFromData( fp2, inDofs->readForces() ); - InVecDeriv fp12(Np); - for(unsigned i=0; i& parent, + const VecCoord_t expectedChild) + { + VecCoord_t childInit( expectedChild.size() ); // start with null child + return runTest( parent, childInit, parent, expectedChild ); + } + + ~Mapping_test() override + { + if (root != nullptr) + { + sofa::simulation::node::unload(root); } + } + +protected: + - // ================ test applyDJT() - if( flags & TEST_applyDJT ) + /** Returns OutCoord substraction a-b */ + virtual Deriv_t difference( const Coord_t& a, const Coord_t& b ) + { + return Out::coordDifference(a,b); + } + + virtual VecDeriv_t difference( const VecDeriv_t& a, const VecDeriv_t& b ) + { + if (a.size() != b.size()) { - //we test the function applyDJT in two different contexts because - //the implementation usually depends on the context - if (this->vectorMaxDiff(dfp_a,fp12) > errorThreshold * errorFactorDJ) - { - succeed = false; - ADD_FAILURE() << "applyDJT (no call to updateK) test failed" << std::endl - << "dfp = " << dfp_a << std::endl - << "fp2-fp = " << fp12 << std::endl - << "error threshold = " << errorThreshold * errorFactorDJ << std::endl; - } - if (this->vectorMaxDiff(dfp_b, fp12) > errorThreshold * errorFactorDJ) - { - succeed = false; - ADD_FAILURE() << "applyDJT (after call to updateK) test failed" << std::endl - << "dfp = " << dfp_b << std::endl - << "fp2-fp = " << fp12 << std::endl - << "error threshold = " << errorThreshold * errorFactorDJ << std::endl; - } + ADD_FAILURE() << "VecDeriv_t have different sizes"; + return {}; } + VecDeriv_t c; + c.reserve(a.size()); + std::transform(a.begin(), a.end(), b.begin(), std::back_inserter(c), std::minus()); + + return c; + } - // ================ test getK() - if( flags & TEST_getK ) + /** Possible child force pre-treatment, does nothing by default + */ + virtual VecDeriv_t preTreatment( const VecDeriv_t& f ) + { + return f; + } + + + void checkComparisonThreshold() + { + if( deltaRange.second / errorMax <= sofa::testing::g_minDeltaErrorRatio ) { - InVecDeriv Kv(Np); + ADD_FAILURE() << "The comparison threshold is too large for the finite difference delta"; + } + } - const linearalgebra::BaseMatrix* bk = mapping->getK(); + void warnMissingTests() const + { + msg_warning_when(!isTestExecuted(TEST_getJs), "MappingTest") << "getJs is not tested"; + msg_warning_when(!isTestExecuted(TEST_getK) , "MappingTest") << "getK is not tested"; + msg_warning_when(!isTestExecuted(TEST_applyJT_matrix) , "MappingTest") << "applyJT on matrices is not tested"; + msg_warning_when(!isTestExecuted(TEST_applyDJT) , "MappingTest") << "applyDJT is not tested"; + msg_warning_when(!isTestExecuted(TEST_buildGeometricStiffnessMatrix) , "MappingTest") << "buildGeometricStiffnessMatrix is not tested"; + } - // K can be null or empty for linear mappings - // still performing the test with a null Kv vector to check if the mapping is really linear + bool testMappingPositionVelocity(const VecCoord_t& parentInit, + const VecCoord_t& childInit, + const VecCoord_t& parentNew, + const VecCoord_t& expectedChildNew, + const Real_t errorThreshold, + core::MechanicalParams mparams) + { + helper::WriteAccessor positionAccessorIn = inDofs->writePositions(); + positionAccessorIn.wref() = parentInit; - if( bk != nullptr ){ + helper::WriteAccessor positionAccessorOut = outDofs->writePositions(); + positionAccessorOut.wref() = childInit; - typedef linearalgebra::EigenSparseMatrix EigenSparseKMatrix; - const EigenSparseKMatrix* K = dynamic_cast(bk); - if( K == nullptr ){ - succeed = false; - ADD_FAILURE() << "getK returns a matrix of non-EigenSparseMatrix type"; - // TODO perform a slow conversion with a big warning rather than a failure? - } + /// Init based on parentInit + sofa::simulation::node::initRoot(root.get()); - if( K->compressedMatrix.nonZeros() ) K->mult(Kv,vp); - } + /// Updated to parentNew + positionAccessorIn.wref() = parentNew; + mapping->apply(&mparams, core::vec_id::write_access::position, core::vec_id::write_access::position); + mapping->applyJ(&mparams, core::vec_id::write_access::velocity, core::vec_id::write_access::velocity); - // check that K.vp = dfp - if(this->vectorMaxDiff(Kv,fp12)>errorThreshold*errorFactorDJ ){ - succeed = false; - ADD_FAILURE() << "K test failed, difference should be less than " << errorThreshold*errorFactorDJ << std::endl - << "Kv = " << Kv << std::endl - << "dfp = " << fp12 << std::endl; - } - } + bool succeed = true; - if( flags & TEST_buildGeometricStiffnessMatrix ) + if (expectedChildNew.size() != positionAccessorOut.size()) { - core::GeometricStiffnessMatrix testGeometricStiffness; - - struct GeometricStiffnessAccumulator : core::MappingMatrixAccumulator - { - void add(sofa::SignedIndex row, sofa::SignedIndex col, float value) override - { - assembledMatrix.add(row, col, value); - } - void add(sofa::SignedIndex row, sofa::SignedIndex col, double value) override - { - assembledMatrix.add(row, col, value); - } - - linearalgebra::EigenSparseMatrix assembledMatrix; - } accumulator; - - testGeometricStiffness.setMatrixAccumulator(&accumulator, mapping->getFromModel(), mapping->getFromModel()); - - accumulator.assembledMatrix.resize(mapping->getFromModel()->getSize() * In::deriv_total_size, mapping->getFromModel()->getSize() * In::deriv_total_size); - mapping->buildGeometricStiffnessMatrix(&testGeometricStiffness); - accumulator.assembledMatrix.compress(); - - InVecDeriv Kv(Np); - if( accumulator.assembledMatrix.compressedMatrix.nonZeros() ) - { - accumulator.assembledMatrix.mult(Kv,vp); - } + ADD_FAILURE() << "Size of output dofs is wrong: " << positionAccessorOut.size() << " expected: " << expectedChildNew.size(); + succeed = false; + } - // check that K.vp = dfp - if (this->vectorMaxDiff(Kv,fp12) > errorThreshold*errorFactorDJ ) + for (unsigned i = 0; i < positionAccessorOut.size(); ++i) + { + if (!this->isSmall(difference(positionAccessorOut[i], expectedChildNew[i]).norm(), errorMax)) { + ADD_FAILURE() << "Position of mapped particle " << i << " is wrong: \n" << positionAccessorOut[i] <<"\nexpected: \n" << expectedChildNew[i] + << "\ndifference should be less than " << errorThreshold << " (" << difference(positionAccessorOut[i],expectedChildNew[i]).norm() << ")" << std::endl; succeed = false; - ADD_FAILURE() << "buildGeometricStiffnessMatrix test failed, difference should be less than " << errorThreshold*errorFactorDJ << std::endl - << "Kv = " << Kv << std::endl - << "dfp = " << fp12 << std::endl; } } - if(!succeed) - { ADD_FAILURE() << "Failed Seed number = " << this->seed << std::endl;} return succeed; } + template + VecDeriv_t generateRandomVecDeriv(const std::size_t size, const Real_t minMagnitude, const Real_t maxMagnitude) + { + VecDeriv_t randomForce; + randomForce.reserve(size); + for (std::size_t i = 0; i < size; i++) + { + randomForce.push_back(DataTypes::randomDeriv(minMagnitude, maxMagnitude)); + } + return randomForce; + } - /** Test the mapping using the given values and small changes. - * Return true in case of success, if all errors are below maxError*epsilon. - * The mapping is initialized using the first parameter, - * @warning this version supposes the mapping initialization does not depend on child positions - * otherwise, use the runTest functions with 4 parameters - * the child position is computed from parent position and compared with the expected one. - * Additionally, the Jacobian-related methods are tested using finite differences. - * - *\param parent parent position - *\param expectedChild expected position of the child corresponding to the parent position - */ - virtual bool runTest( const InVecCoord& parent, - const OutVecCoord expectedChild) + void computeForceInFromForceOut(core::MechanicalParams mparams, VecDeriv_t& forceIn, const VecDeriv_t& forceOut) { - OutVecCoord childInit( expectedChild.size() ); // start with null child - return runTest( parent, childInit, parent, expectedChild ); + inDofs->writeForces()->fill(Deriv_t()); // reset parent forces before accumulating child forces + + outDofs->writeForces().wref() = forceOut; + mapping->applyJT( &mparams, core::vec_id::write_access::force, core::vec_id::write_access::force ); + forceIn = inDofs->readForces().ref(); } - ~Mapping_test() override + void computeVelocityOutFromVelocityIn(core::MechanicalParams mparams, VecDeriv_t& velocityOut, const VecDeriv_t& velocityIn) { - if (root!=nullptr) - sofa::simulation::node::unload(root); + inDofs->writeVelocities().wref() = velocityIn; + mapping->applyJ( &mparams, core::vec_id::write_access::velocity, core::vec_id::write_access::velocity ); + velocityOut = outDofs->readVelocities().ref(); + } + + const VecDeriv_t& applyDJT(core::MechanicalParams mparams, bool updateK) + { + inDofs->writeForces()->fill(Deriv_t()); //reset force + + if (updateK) + { + mapping->updateK( &mparams, core::vec_id::read_access::force ); // updating stiffness matrix for the current state and force + } + mapping->applyDJT( &mparams, core::vec_id::write_access::force, core::vec_id::write_access::force ); + return inDofs->readForces().ref(); + } + + [[nodiscard]] bool checkApplyDJT(const VecDeriv_t& dfp, const VecDeriv_t& fp12, Real_t errorThreshold, bool updateK) + { + if (this->vectorMaxDiff(dfp, fp12) > errorThreshold * errorFactorDJ) + { + const std::string updateKString = updateK ? "after call to updateK" : "no call to updateK"; + ADD_FAILURE() << "applyDJT (" << updateKString << ") test failed" << std::endl + << "dfp = " << dfp << std::endl + << "fp2-fp = " << fp12 << std::endl + << "error threshold = " << errorThreshold * errorFactorDJ << std::endl; + return false; + } + return true; + } + + VecCoord_t computePerturbedPositions(const std::size_t sizeIn, const VecDeriv_t velocityIn) + { + VecCoord_t perturbedPositionIn; + perturbedPositionIn.reserve(sizeIn); + const helper::ReadAccessor positionIn = inDofs->readPositions(); + for (std::size_t i = 0; i < sizeIn; ++i) + { + perturbedPositionIn.push_back(positionIn[i] + velocityIn[i]); + } + return perturbedPositionIn; } -protected: /// Get one EigenSparseMatrix out of a list. Error if not one single matrix in the list. template static EigenSparseMatrixType* getMatrix(const type::vector* matrices) { - if( !matrices ){ + if( !matrices ) + { ADD_FAILURE()<< "Matrix list is nullptr (API for assembly is not implemented)"; } - if( matrices->size() != 1 ){ - ADD_FAILURE()<< "Matrix list should have size == 1 in simple mappings"; + + if( matrices->empty() ) + { + ADD_FAILURE()<< "Matrix list is empty"; + return nullptr; + } + + if( matrices->size() != 1 ) + { + ADD_FAILURE()<< "Matrix list should have size == 1 in simple mappings (current size = " << matrices->size() << ")"; } EigenSparseMatrixType* ei = dynamic_cast((*matrices)[0] ); - if( ei == nullptr ){ + if( ei == nullptr ) + { ADD_FAILURE() << "getJs returns a matrix of non-EigenSparseMatrix type"; // TODO perform a slow conversion with a big warning rather than a failure? } return ei; } + bool checkJacobianMatrixTranspose( + EigenSparseMatrix* jacobianMatrix, + const VecDeriv_t& forceOut, + const VecDeriv_t& expectedForceIn, + Real_t errorThreshold) + { + VecDeriv_t computedForceIn(expectedForceIn.size(), Deriv_t()); + + //computedForceIn += J^T * forceOut + jacobianMatrix->addMultTranspose(computedForceIn, forceOut); + + const auto diff = this->vectorMaxDiff(computedForceIn, expectedForceIn); + if (diff > errorThreshold) + { + ADD_FAILURE() << + "getJs is not consistent with applyJT, difference should be " + "less than " << errorThreshold << " (" << diff << ")" << std::endl + << "computedForceIn = " << computedForceIn << std::endl + << "expectedForceIn = " << expectedForceIn << std::endl; + return false; + } + return true; + } + + bool checkJacobianMatrix( + EigenSparseMatrix* jacobianMatrix, + const VecDeriv_t& velocityIn, + const VecDeriv_t& expectedVelocityOut, + Real_t errorThreshold) + { + VecDeriv_t computedVelocityOut(expectedVelocityOut.size()); + + jacobianMatrix->mult(computedVelocityOut, velocityIn); + + const auto diff = this->vectorMaxDiff(computedVelocityOut, expectedVelocityOut); + if (diff > errorThreshold) + { + ADD_FAILURE() << + "getJs is not consistent with applyJ, difference should be " + "less than " << errorThreshold << " (" << diff << ")" << std::endl + << "velocityIn = " << velocityIn << std::endl + << "computedVelocityOut = " << computedVelocityOut << std::endl + << "expectedVelocityOut = " << expectedVelocityOut << std::endl; + return false; + } + + return true; + } + + bool testApplyJonPosition( + core::MechanicalParams mparams, + const VecCoord_t& positionOut, + const VecDeriv_t& expectedVelocityOut, + Real_t errorThreshold + ) + { + mapping->apply ( &mparams, core::vec_id::write_access::position, core::vec_id::write_access::position ); + const VecCoord_t& positionOut1 = outDofs->readPositions(); + + const auto sizeOut = positionOut.size(); + VecDeriv_t dxOut(sizeOut); + for (unsigned i = 0; i < sizeOut; i++) + { + dxOut[i] = difference(positionOut1[i], positionOut[i]); + } + + const auto diff = this->vectorMaxAbs(difference(dxOut, expectedVelocityOut)); + if (diff > errorThreshold) + { + ADD_FAILURE() << "applyJ test failed: the difference between child " + "position change and child velocity (dt=1) " << diff << + " should be less than " << errorThreshold << std::endl + << "position change = " << dxOut << std::endl + << "expectedVelocityOut = " << expectedVelocityOut << std::endl; + return false; + } + + return true; + } + + VecDeriv_t computeForceChange(core::MechanicalParams mparams, const std::size_t sizeIn, VecDeriv_t forceOut, VecDeriv_t forceIn) + { + VecDeriv_t forceChange; + forceChange.reserve(sizeIn); + + // apply has been called, therefore parent force must be updated + // based on the same child forces + VecDeriv_t forceIn2; + computeForceInFromForceOut(mparams, forceIn2, preTreatment(forceOut)); + + for (unsigned i = 0; i < sizeIn; ++i) + { + forceChange.push_back(forceIn2[i] - forceIn[i]); + } + + return forceChange; + } + + bool testGetK(const std::size_t& sizeIn, + const VecDeriv_t& velocityIn, + const VecDeriv_t& forceChange, + Real_t errorThreshold) + { + VecDeriv_t Kv(sizeIn); + + const linearalgebra::BaseMatrix* bk = mapping->getK(); + + // K can be null or empty for linear mappings + // still performing the test with a null Kv vector to check if the mapping is really linear + + if( bk != nullptr ) + { + typedef linearalgebra::EigenSparseMatrix EigenSparseKMatrix; + const EigenSparseKMatrix* K = dynamic_cast(bk); + if( K == nullptr ) + { + ADD_FAILURE() << "getK returns a matrix of non-EigenSparseMatrix type"; + // TODO perform a slow conversion with a big warning rather than a failure? + return false; + } + + if( K->compressedMatrix.nonZeros() ) + { + K->mult(Kv,velocityIn); + } + } + + // check that K.vp = dfp + if (this->vectorMaxDiff(Kv, forceChange) > errorThreshold * errorFactorDJ) + { + ADD_FAILURE() << "K test failed, difference should be less than " << errorThreshold*errorFactorDJ << std::endl + << "Kv = " << Kv << std::endl + << "dfp = " << forceChange << std::endl; + return false; + } + + return true; + } + + bool testBuildGeometricStiffnessMatrix( + std::size_t sizeIn, + const VecDeriv_t& velocityIn, + const VecDeriv_t& forceChange, + Real_t errorThreshold + ) + { + core::GeometricStiffnessMatrix testGeometricStiffness; + struct GeometricStiffnessAccumulator : core::MappingMatrixAccumulator + { + void add(sofa::SignedIndex row, sofa::SignedIndex col, float value) override + { + assembledMatrix.add(row, col, value); + } + void add(sofa::SignedIndex row, sofa::SignedIndex col, double value) override + { + assembledMatrix.add(row, col, value); + } + + linearalgebra::EigenSparseMatrix assembledMatrix; + } accumulator; + + testGeometricStiffness.setMatrixAccumulator(&accumulator, mapping->getFromModel(), mapping->getFromModel()); + + accumulator.assembledMatrix.resize(mapping->getFromModel()->getSize() * In::deriv_total_size, mapping->getFromModel()->getSize() * In::deriv_total_size); + mapping->buildGeometricStiffnessMatrix(&testGeometricStiffness); + accumulator.assembledMatrix.compress(); + + VecDeriv_t Kv(sizeIn); + if( accumulator.assembledMatrix.compressedMatrix.nonZeros() ) + { + accumulator.assembledMatrix.mult(Kv,velocityIn); + } + + // check that K.vp = dfp + if (this->vectorMaxDiff(Kv,forceChange) > errorThreshold*errorFactorDJ ) + { + ADD_FAILURE() << "buildGeometricStiffnessMatrix test failed, difference should be less than " << errorThreshold*errorFactorDJ << std::endl + << "Kv = " << Kv << std::endl + << "dfp = " << forceChange << std::endl; + return false; + } + + return true; + } }; diff --git a/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/Multi2MappingTestCreation.h b/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/Multi2MappingTestCreation.h index 2b52c3ea1f4..624e83aeb73 100644 --- a/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/Multi2MappingTestCreation.h +++ b/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/Multi2MappingTestCreation.h @@ -207,8 +207,8 @@ struct Multi2Mapping_test : public BaseSimulationTest, NumericTestmapping->apply(&mparams, core::VecCoordId::position(), core::VecCoordId::position()); - this->mapping->applyJ(&mparams, core::VecDerivId::velocity(), core::VecDerivId::velocity() ); + this->mapping->apply(&mparams, core::vec_id::write_access::position, core::vec_id::write_access::position); + this->mapping->applyJ(&mparams, core::vec_id::write_access::velocity, core::vec_id::write_access::velocity ); // ================ test apply : check if the child positions are the expected ones bool succeed = true; ReadOutVecCoord xout = this->outDofs->readPositions(); @@ -256,7 +256,7 @@ struct Multi2Mapping_test : public BaseSimulationTest, NumericTestwriteForces(); sofa::testing::copyToData(fout, fc); - this->mapping->applyJT( &mparams, core::VecDerivId::force(), core::VecDerivId::force() ); + this->mapping->applyJT( &mparams, core::vec_id::write_access::force, core::vec_id::write_access::force ); for (Index i = 0; i < Np1.size(); i++) sofa::testing::copyFromData(fIn1p[i], this->in1Dofs[i]->readForces()); for (Index i = 0; i < Np2.size(); i++) sofa::testing::copyFromData(fIn2p[i], this->in2Dofs[i]->readForces()); @@ -291,7 +291,7 @@ struct Multi2Mapping_test : public BaseSimulationTest, NumericTestin2Dofs[p]->writeVelocities(); sofa::testing::copyToData(vIn2, vIn2p[p]); } - this->mapping->applyJ(&mparams, core::VecDerivId::velocity(), core::VecDerivId::velocity() ); + this->mapping->applyJ(&mparams, core::vec_id::write_access::velocity, core::vec_id::write_access::velocity ); ReadOutVecDeriv vout = this->outDofs->readVelocities(); sofa::testing::copyFromData(vc, vout); @@ -314,7 +314,7 @@ struct Multi2Mapping_test : public BaseSimulationTest, NumericTestin2Dofs[p]->writeForces(); sofa::testing::copyToData( fin2, dfIn2p[p] ); } - mapping->applyDJT( &mparams, core::VecDerivId::force(), core::VecDerivId::force() ); + mapping->applyDJT( &mparams, core::vec_id::write_access::force, core::vec_id::write_access::force ); for( Index p=0; preadForces() ); // fp + df due to geometric stiffness for( Index p=0; preadForces() ); // fp + df due to geometric stiffness @@ -373,7 +373,7 @@ struct Multi2Mapping_test : public BaseSimulationTest, NumericTestmapping->applyJT( &mparams, core::VecDerivId::force(), core::VecDerivId::force() ); + this->mapping->applyJT( &mparams, core::vec_id::write_access::force, core::vec_id::write_access::force ); for (Index i = 0; i < Np1.size(); i++) sofa::testing::copyFromData(fIn1p[i], this->in1Dofs[i]->readForces()); for (Index i = 0; i < Np2.size(); i++) sofa::testing::copyFromData(fIn2p[i], this->in2Dofs[i]->readForces()); @@ -389,7 +389,7 @@ struct Multi2Mapping_test : public BaseSimulationTest, NumericTestwritePositions(); sofa::testing::copyToData(pin2, xIn2p1[p]); } - this->mapping->apply(&mparams, core::VecCoordId::position(), core::VecCoordId::position()); + this->mapping->apply(&mparams, core::vec_id::write_access::position, core::vec_id::write_access::position); WriteOutVecCoord pout = this->outDofs->writePositions(); sofa::testing::copyFromData(xc1, pout); @@ -418,7 +418,7 @@ struct Multi2Mapping_test : public BaseSimulationTest, NumericTestmapping->applyJT( &mparams, core::VecDerivId::force(), core::VecDerivId::force() ); + this->mapping->applyJT( &mparams, core::vec_id::write_access::force, core::vec_id::write_access::force ); vector fIn1p12(Np1.size()); vector fIn2p12(Np2.size()); // ================ test applyDJT() (Case 1) diff --git a/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/MultiMappingTestCreation.h b/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/MultiMappingTestCreation.h index 1b020d4b8ae..3c0e5868a0a 100644 --- a/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/MultiMappingTestCreation.h +++ b/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/MultiMappingTestCreation.h @@ -177,8 +177,8 @@ struct MultiMapping_test : public BaseSimulationTest, NumericTestapply(&mparams, core::VecCoordId::position(), core::VecCoordId::position()); - mapping->applyJ(&mparams, core::VecDerivId::velocity(), core::VecDerivId::velocity()); + mapping->apply(&mparams, core::vec_id::write_access::position, core::vec_id::write_access::position); + mapping->applyJ(&mparams, core::vec_id::write_access::velocity, core::vec_id::write_access::velocity); /// test apply: check if the child positions are the expected ones bool succeed=true; @@ -228,7 +228,7 @@ struct MultiMapping_test : public BaseSimulationTest, NumericTestwriteForces(); sofa::testing::copyToData( fout, fc ); - mapping->applyJT( &mparams, core::VecDerivId::force(), core::VecDerivId::force() ); + mapping->applyJT( &mparams, core::vec_id::write_access::force, core::vec_id::write_access::force ); for(Index i=0; ireadForces() ); // cout<<"parent forces fp = "<writeVelocities(); sofa::testing::copyToData( vin, vp[p] ); } - mparams.setDx(core::ConstVecDerivId::velocity()); - mapping->applyJ( &mparams, core::VecDerivId::velocity(), core::VecDerivId::velocity() ); + mparams.setDx(core::vec_id::read_access::velocity); + mapping->applyJ( &mparams, core::vec_id::write_access::velocity, core::vec_id::write_access::velocity ); ReadOutVecDeriv vout = outDofs->readVelocities(); sofa::testing::copyFromData( vc, vout); // cout<<"child velocity vc = " << vc << endl; @@ -266,8 +266,8 @@ struct MultiMapping_test : public BaseSimulationTest, NumericTestwriteForces(); sofa::testing::copyToData( fin, dfp[p] ); } - mapping->updateK( &mparams, core::ConstVecDerivId::force() ); // updating stiffness matrix for the current state and force - mapping->applyDJT( &mparams, core::VecDerivId::force(), core::VecDerivId::force() ); + mapping->updateK( &mparams, core::vec_id::read_access::force ); // updating stiffness matrix for the current state and force + mapping->applyDJT( &mparams, core::vec_id::write_access::force, core::vec_id::write_access::force ); for( Index p=0; preadForces() ); // fp + df due to geometric stiffness // cout<<"dfp["<< p <<"] = " << dfp[p] << endl; @@ -319,7 +319,7 @@ struct MultiMapping_test : public BaseSimulationTest, NumericTestapplyJT( &mparams, core::VecDerivId::force(), core::VecDerivId::force() ); + mapping->applyJT( &mparams, core::vec_id::write_access::force, core::vec_id::write_access::force ); for( Index p=0; preadForces() ); @@ -334,7 +334,7 @@ struct MultiMapping_test : public BaseSimulationTest, NumericTestmstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); if (x.empty()) return; @@ -176,7 +176,7 @@ void EdgePressureForceField::initEdgeInformation() sofa::type::vector& my_subset = *(d_edgePressureMap).beginEdit(); - const VecCoord& x0 = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& x0 = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); auto getEdgeLength = [](const sofa::topology::Edge& e, const VecCoord& pos) { const auto& n0 = DataTypes::getCPos(pos[e[0]]); @@ -290,7 +290,7 @@ void EdgePressureForceField::updateEdgeInformation() if (!this->mstate.get()) msg_error() << " No mechanical Object linked."; - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); if (x.empty()) { @@ -343,7 +343,7 @@ void EdgePressureForceField::buildDampingMatrix(core::behavior::Dampi template void EdgePressureForceField::selectEdgesAlongPlane() { - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); std::vector vArray; vArray.resize(x.size()); @@ -437,7 +437,7 @@ void EdgePressureForceField::draw(const core::visual::VisualParams* v const SReal aSC = d_arrowSizeCoef.getValue(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); vparams->drawTool()->disableLighting(); constexpr const sofa::type::RGBAColor& color = sofa::type::RGBAColor::yellow(); diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/InteractionEllipsoidForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/InteractionEllipsoidForceField.inl index 1833ca93616..c9af483eb15 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/InteractionEllipsoidForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/InteractionEllipsoidForceField.inl @@ -64,7 +64,7 @@ void InteractionEllipsoidForceField::init() return; } - vars.pos6D = this->mstate2->read(core::VecCoordId::position())->getValue()[object2_dof_index.getValue()]; + vars.pos6D = this->mstate2->read(core::vec_id::write_access::position)->getValue()[object2_dof_index.getValue()]; if(object2_invert.getValue()) vars.pos6D = DataTypes2::inverse(vars.pos6D); initCalcF(); @@ -74,7 +74,7 @@ template void InteractionEllipsoidForceField::reinit() { Inherit1::reinit(); - vars.pos6D = this->mstate2->read(core::VecCoordId::position())->getValue()[object2_dof_index.getValue()]; + vars.pos6D = this->mstate2->read(core::vec_id::write_access::position)->getValue()[object2_dof_index.getValue()]; if(object2_invert.getValue()) vars.pos6D = DataTypes2::inverse(vars.pos6D); initCalcF(); diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/OscillatingTorsionPressureForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/OscillatingTorsionPressureForceField.inl index e803a8115c8..7b8432d94e2 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/OscillatingTorsionPressureForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/OscillatingTorsionPressureForceField.inl @@ -227,7 +227,7 @@ void OscillatingTorsionPressureForceField::buildDampingMatrix(core::b template void OscillatingTorsionPressureForceField::initTriangleInformation() { - const VecCoord& x0 = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& x0 = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); int idx[3]; Real d[10]; @@ -279,7 +279,7 @@ void OscillatingTorsionPressureForceField::initTriangleInformation() template void OscillatingTorsionPressureForceField::selectTrianglesAlongPlane() { - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); std::vector vArray; vArray.resize(x.size()); @@ -342,7 +342,7 @@ void OscillatingTorsionPressureForceField::draw(const core::visual::V if (vparams->displayFlags().getShowWireFrame()) vparams->drawTool()->setPolygonMode(0, true); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); vparams->drawTool()->disableLighting(); const sofa::type::RGBAColor color = sofa::type::RGBAColor::green(); diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/PlaneForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/PlaneForceField.inl index abbd6ec1e03..568531feee8 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/PlaneForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/PlaneForceField.inl @@ -345,7 +345,7 @@ void PlaneForceField::drawPlane(const core::visual::VisualParams* vpa if (size == 0.0f) size = (float)d_drawSize.getValue(); - helper::ReadAccessor p1 = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + helper::ReadAccessor p1 = this->mstate->read(core::vec_id::read_access::position)->getValue(); type::Vec3 normal{type::NOINIT}, v1{ type::NOINIT }, v2{ type::NOINIT }; get3DFrameFromDPosNormal(d_planeNormal.getValue(), v1, v2, normal); diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/QuadPressureForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/QuadPressureForceField.inl index 430e473156c..9b6901a4524 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/QuadPressureForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/QuadPressureForceField.inl @@ -134,7 +134,7 @@ void QuadPressureForceField::initQuadInformation() const sofa::type::vector& my_map = d_quadPressureMap.getMap2Elements(); auto my_subset = sofa::helper::getWriteOnlyAccessor(d_quadPressureMap); - const VecCoord& x0 = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& x0 = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); for (unsigned int i=0; i::updateQuadInformation() template void QuadPressureForceField::selectQuadsAlongPlane() { - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); std::vector vArray; vArray.resize(x.size()); @@ -251,7 +251,7 @@ void QuadPressureForceField::draw(const core::visual::VisualParams* v if (vparams->displayFlags().getShowWireFrame()) vparams->drawTool()->setPolygonMode(0, true); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); vparams->drawTool()->disableLighting(); std::vector vertices; diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SurfacePressureForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SurfacePressureForceField.inl index e815066f879..226f5cb3ca1 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SurfacePressureForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SurfacePressureForceField.inl @@ -554,7 +554,7 @@ void SurfacePressureForceField::draw(const core::visual::VisualParams } - helper::ReadAccessor x = this->mstate->read(core::ConstVecCoordId::position()); + helper::ReadAccessor x = this->mstate->read(core::vec_id::read_access::position); if (d_drawForceScale.getValue() && m_f.size() == x.size()) { std::vector points; diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TaitSurfacePressureForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TaitSurfacePressureForceField.inl index e75e8d0fd27..7bf9e3acd95 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TaitSurfacePressureForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TaitSurfacePressureForceField.inl @@ -140,7 +140,7 @@ void TaitSurfacePressureForceField::init() } updateFromTopology(); - computeMeshVolumeAndArea(*d_currentVolume.beginEdit(), *d_currentSurfaceArea.beginEdit(), this->mstate->read(sofa::core::VecCoordId::position())); + computeMeshVolumeAndArea(*d_currentVolume.beginEdit(), *d_currentSurfaceArea.beginEdit(), this->mstate->read(sofa::core::vec_id::write_access::position)); d_currentVolume.endEdit(); d_currentSurfaceArea.endEdit(); Real currentStiffness = 0; @@ -148,7 +148,7 @@ void TaitSurfacePressureForceField::init() computePressureAndStiffness(currentPressure, currentStiffness, d_currentVolume.getValue(), d_v0.getValue()); d_currentPressure.setValue(currentPressure); d_currentStiffness.setValue(currentStiffness); - computeStatistics(this->mstate->read(sofa::core::VecCoordId::position())); + computeStatistics(this->mstate->read(sofa::core::vec_id::write_access::position)); } template @@ -203,7 +203,7 @@ void TaitSurfacePressureForceField::updateFromTopology() lastTopologyRevision = m_topology->getRevision(); computePressureTriangles(); - computeMeshVolumeAndArea(*d_volumeAfterTC.beginEdit(), *d_surfaceAreaAfterTC.beginEdit(), this->mstate->read(core::ConstVecCoordId::restPosition())); + computeMeshVolumeAndArea(*d_volumeAfterTC.beginEdit(), *d_surfaceAreaAfterTC.beginEdit(), this->mstate->read(core::vec_id::read_access::restPosition)); d_volumeAfterTC.endEdit(); d_surfaceAreaAfterTC.endEdit(); if (lastTopologyRevision == 0) @@ -243,7 +243,7 @@ void TaitSurfacePressureForceField::addForce(const core::MechanicalPa helper::WriteAccessor f = d_f; helper::ReadAccessor x = d_x; //helper::ReadAccessor v = d_v; - //helper::ReadAccessor x0 = this->mstate->read(core::ConstVecCoordId::restPosition()); + //helper::ReadAccessor x0 = this->mstate->read(core::vec_id::read_access::restPosition); const helper::ReadAccessor< Data< SeqTriangles > > pressureTriangles = d_pressureTriangles; computeMeshVolumeAndArea(*d_currentVolume.beginEdit(), *d_currentSurfaceArea.beginEdit(), x); @@ -303,7 +303,7 @@ void TaitSurfacePressureForceField::addDForce(const core::MechanicalP helper::WriteAccessor df = d_df; helper::ReadAccessor dx = d_dx; helper::ReadAccessor x = mparams->readX(this->mstate.get()); - //helper::ReadAccessor x0 = this->mstate->read(core::ConstVecCoordId::restPosition()); + //helper::ReadAccessor x0 = this->mstate->read(core::vec_id::read_access::restPosition); const helper::ReadAccessor< Data< SeqTriangles > > pressureTriangles = d_pressureTriangles; helper::ReadAccessor gradV = this->gradV; @@ -529,7 +529,7 @@ void TaitSurfacePressureForceField::draw(const core::visual::VisualPa if (vparams->displayFlags().getShowWireFrame()) vparams->drawTool()->setPolygonMode(0,vparams->displayFlags().getShowWireFrame()); - helper::ReadAccessor x = this->mstate->read(core::ConstVecCoordId::position()); + helper::ReadAccessor x = this->mstate->read(core::vec_id::read_access::position); const helper::ReadAccessor< Data< SeqTriangles > > pressureTriangles = d_pressureTriangles; diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TrianglePressureForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TrianglePressureForceField.inl index dbb85054555..95b8c82b742 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TrianglePressureForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TrianglePressureForceField.inl @@ -164,7 +164,7 @@ void TrianglePressureForceField::initTriangleInformation() d_trianglePressureMap.setMap2Elements(_triangleList); // Fill pressure data - const VecCoord& x0 = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& x0 = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); const Deriv& my_pressure = pressure.getValue(); for (unsigned int i = 0; i < _triangleList.size(); ++i) @@ -206,7 +206,7 @@ void TrianglePressureForceField::draw(const core::visual::VisualParam if (vparams->displayFlags().getShowWireFrame()) vparams->drawTool()->setPolygonMode(0, true); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); vparams->drawTool()->disableLighting(); diff --git a/Sofa/Component/MechanicalLoad/tests/SkeletalMotionConstraint_test.cpp b/Sofa/Component/MechanicalLoad/tests/SkeletalMotionConstraint_test.cpp index 35e39dff75f..51c8db83051 100644 --- a/Sofa/Component/MechanicalLoad/tests/SkeletalMotionConstraint_test.cpp +++ b/Sofa/Component/MechanicalLoad/tests/SkeletalMotionConstraint_test.cpp @@ -128,7 +128,7 @@ struct SkeletalMotionProjectiveConstraint_test : public BaseSimulationTest, Nume bool test_projectPosition() { - projection->projectPosition(core::mechanicalparams::defaultInstance(), *dofs->write(core::VecCoordId::position())); + projection->projectPosition(core::mechanicalparams::defaultInstance(), *dofs->write(core::vec_id::write_access::position)); typename MechanicalObject::ReadVecCoord x = dofs->readPositions(); Coord target0(CPos(0.5,0.5,0.5), CRot(0, 0.19509, 0, 0.980785)); Coord target1(CPos(0.5,1.5,0.5), CRot(0.69352, 0.13795, -0.13795, 0.69352)); @@ -153,7 +153,7 @@ struct SkeletalMotionProjectiveConstraint_test : public BaseSimulationTest, Nume bool test_projectVelocity() { - projection->projectVelocity(core::mechanicalparams::defaultInstance(), *dofs->write(core::VecDerivId::velocity())); + projection->projectVelocity(core::mechanicalparams::defaultInstance(), *dofs->write(core::vec_id::write_access::velocity)); typename MechanicalObject::ReadVecDeriv x = dofs->readVelocities(); bool succeed = true; Deriv target(CPos(1,1,1), typename Deriv::Rot(0,0.785397,0)); diff --git a/Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/EulerImplicitSolver.cpp b/Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/EulerImplicitSolver.cpp index e89ed41245e..37ed60880bd 100644 --- a/Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/EulerImplicitSolver.cpp +++ b/Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/EulerImplicitSolver.cpp @@ -83,9 +83,9 @@ void EulerImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa:: #endif sofa::simulation::common::VectorOperations vop( params, this->getContext() ); sofa::simulation::common::MechanicalOperations mop( params, this->getContext() ); - MultiVecCoord pos(&vop, core::VecCoordId::position() ); - MultiVecDeriv vel(&vop, core::VecDerivId::velocity() ); - MultiVecDeriv f(&vop, core::VecDerivId::force() ); + MultiVecCoord pos(&vop, core::vec_id::write_access::position ); + MultiVecDeriv vel(&vop, core::vec_id::write_access::velocity ); + MultiVecDeriv f(&vop, core::vec_id::write_access::force ); MultiVecDeriv b(&vop, true, core::VecIdProperties{"RHS", GetClass()->className}); MultiVecCoord newPos(&vop, xResult ); MultiVecDeriv newVel(&vop, vResult ); @@ -95,7 +95,7 @@ void EulerImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa:: mop.cparams.setV(vResult); // dx is no longer allocated by default (but it will be deleted automatically by the mechanical objects) - MultiVecDeriv dx(&vop, core::VecDerivId::dx()); + MultiVecDeriv dx(&vop, core::vec_id::write_access::dx); dx.realloc(&vop, !d_threadSafeVisitor.getValue(), true); x.realloc(&vop, !d_threadSafeVisitor.getValue(), true, core::VecIdProperties{"solution", GetClass()->className}); @@ -145,8 +145,9 @@ void EulerImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa:: msg_info() << "EulerImplicitSolver, f = " << f; // add the change of force due to stiffness + Rayleigh damping - mop.addMBKv(b, -d_rayleighMass.getValue(), 0, - h + d_rayleighStiffness.getValue()); // b = f + ( rm M + (h+rs) K ) v + mop.addMBKv(b, core::MatricesFactors::M(-d_rayleighMass.getValue()), + core::MatricesFactors::B(0), + core::MatricesFactors::K(h + d_rayleighStiffness.getValue())); // b = f + ( rm M + (h+rs) K ) v // integration over a time step b.teq(h * @@ -162,19 +163,10 @@ void EulerImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa:: { SCOPED_TIMER("setSystemMBKMatrix"); - SReal mFact, kFact, bFact; - if (firstOrder) - { - mFact = 1; - bFact = 0; - kFact = -h * tr; - } - else - { - mFact = 1 + tr * h * d_rayleighMass.getValue(); - bFact = -tr * h; - kFact = -tr * h * (h + d_rayleighStiffness.getValue()); - } + const core::MatricesFactors::M mFact (firstOrder ? 1 : 1 + tr * h * d_rayleighMass.getValue()); + const core::MatricesFactors::B bFact (firstOrder ? 0 : -tr * h); + const core::MatricesFactors::K kFact (firstOrder ? -h * tr : -tr * h * (h + d_rayleighStiffness.getValue())); + mop.setSystemMBKMatrix(mFact, bFact, kFact, l_linearSolver.get()); #ifdef SOFA_DUMP_VISITOR_INFO diff --git a/Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/NewmarkImplicitSolver.cpp b/Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/NewmarkImplicitSolver.cpp index 34e6f35298c..e69abebe1e6 100644 --- a/Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/NewmarkImplicitSolver.cpp +++ b/Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/NewmarkImplicitSolver.cpp @@ -61,8 +61,8 @@ void NewmarkImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa { sofa::simulation::common::VectorOperations vop( params, this->getContext() ); sofa::simulation::common::MechanicalOperations mop( params, this->getContext() ); - MultiVecCoord pos(&vop, core::VecCoordId::position() ); - MultiVecDeriv vel(&vop, core::VecDerivId::velocity() ); + MultiVecCoord pos(&vop, core::vec_id::write_access::position ); + MultiVecDeriv vel(&vop, core::vec_id::write_access::velocity ); MultiVecDeriv b(&vop); MultiVecDeriv aResult(&vop); MultiVecCoord newPos(&vop, xResult ); @@ -70,7 +70,7 @@ void NewmarkImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa // dx is no longer allocated by default (but it will be deleted automatically by the mechanical objects) - MultiVecDeriv dx(&vop, core::VecDerivId::dx()); dx.realloc(&vop, !d_threadSafeVisitor.getValue(), true); + MultiVecDeriv dx(&vop, core::vec_id::write_access::dx); dx.realloc(&vop, !d_threadSafeVisitor.getValue(), true); const SReal h = dt; @@ -113,11 +113,15 @@ void NewmarkImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa mop.propagateDx(a); // b += (-h (1-\gamma)(r_M M + r_K K) - h^2/2 (1-2\beta) K ) a - mop.addMBKdx(b, -h*(1-gamma)*rM, h*(1-gamma), h*(1-gamma)*rK + h*h*(1-2*beta)/2.0,true,true); + mop.addMBKdx(b, + core::MatricesFactors::M(-h*(1-gamma)*rM), + core::MatricesFactors::B(h*(1-gamma)), + core::MatricesFactors::K(h*(1-gamma)*rK + h*h*(1-2*beta)/2.0), + true,true); } // b += -h K v - mop.addMBKv(b, -rM, 1,rK+h); + mop.addMBKv(b, core::MatricesFactors::M(-rM), core::MatricesFactors::B(1), core::MatricesFactors::K(rK+h)); msg_info() << "b = " << b; mop.projectResponse(b); // b is projected to the constrained space @@ -126,9 +130,9 @@ void NewmarkImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa // 3. Solve system of equations on a_{t+h} - const SReal mFact = 1 + h * gamma * rM; - const SReal bFact = (-h) * gamma; - const SReal kFact = -h * h * beta - h * rK * gamma; + const core::MatricesFactors::M mFact ( 1 + h * gamma * rM); + const core::MatricesFactors::B bFact ( (-h) * gamma); + const core::MatricesFactors::K kFact ( -h * h * beta - h * rK * gamma); mop.setSystemMBKMatrix(mFact, bFact, kFact, l_linearSolver.get()); l_linearSolver->setSystemLHVector(aResult); diff --git a/Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/StaticSolver.cpp b/Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/StaticSolver.cpp index 48d6750452f..080b2a192ca 100644 --- a/Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/StaticSolver.cpp +++ b/Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/StaticSolver.cpp @@ -45,29 +45,29 @@ StaticSolver::StaticSolver() : d_newton_iterations(initData(&d_newton_iterations, (unsigned) 1, "newton_iterations", - "Number of Netwon iterations between each load increments (normally, one load increment per simulation time-step.")) + "Number of Newton iterations between each load increments (normally, one load increment per simulation time-step.")) , d_absolute_correction_tolerance_threshold(initData(&d_absolute_correction_tolerance_threshold, 1e-5_sreal, "absolute_correction_tolerance_threshold", - "Convergence criterion of the norm |du| under which the Netwon iterations stop")) + "Convergence criterion of the norm |du| under which the Newton iterations stop")) , d_relative_correction_tolerance_threshold(initData(&d_relative_correction_tolerance_threshold, 1e-5_sreal, "relative_correction_tolerance_threshold", - "Convergence criterion regarding the ratio |du| / |U| under which the Netwon iterations stop")) + "Convergence criterion regarding the ratio |du| / |U| under which the Newton iterations stop")) , d_absolute_residual_tolerance_threshold( initData(&d_absolute_residual_tolerance_threshold, 1e-5_sreal, "absolute_residual_tolerance_threshold", - "Convergence criterion of the norm |R| under which the Netwon iterations stop." + "Convergence criterion of the norm |R| under which the Newton iterations stop." "Use a negative value to disable this criterion")) , d_relative_residual_tolerance_threshold( initData(&d_relative_residual_tolerance_threshold, 1e-5_sreal, "relative_residual_tolerance_threshold", - "Convergence criterion regarding the ratio |R|/|R0| under which the Netwon iterations stop." + "Convergence criterion regarding the ratio |R|/|R0| under which the Newton iterations stop." "Use a negative value to disable this criterion")) , d_should_diverge_when_residual_is_growing( initData(&d_should_diverge_when_residual_is_growing, false, "should_diverge_when_residual_is_growing", - "Boolean stopping Netwon iterations when the residual is greater than the one from the previous iteration")) + "Boolean stopping Newton iterations when the residual is greater than the one from the previous iteration")) {} void StaticSolver::solve(const sofa::core::ExecParams* params, SReal dt, sofa::core::MultiVecCoordId xResult, sofa::core::MultiVecDerivId vResult) @@ -92,8 +92,8 @@ void StaticSolver::solve(const sofa::core::ExecParams* params, SReal dt, sofa::c // Initialize the set of multi-vectors used by this solver MultiVecCoord x(&vop, xResult ); - MultiVecDeriv force( &vop, sofa::core::VecDerivId::force() ); - MultiVecDeriv dx( &vop, sofa::core::VecDerivId::dx() ); + MultiVecDeriv force( &vop, sofa::core::vec_id::write_access::force ); + MultiVecDeriv dx( &vop, sofa::core::vec_id::write_access::dx ); dx.realloc( &vop , true, true); U.realloc( &vop ); U.clear(); @@ -212,7 +212,10 @@ void StaticSolver::solve(const sofa::core::ExecParams* params, SReal dt, sofa::c // is called on every BaseProjectiveConstraintSet objects. An example of such constraint set is the // FixedProjectiveConstraint. In this case, it will set to 0 every column (_, i) and row (i, _) of the assembled // matrix for the ith degree of freedom. - mop.setSystemMBKMatrix(0, 0, -1, l_linearSolver.get()); + mop.setSystemMBKMatrix( + core::MatricesFactors::M(0), + core::MatricesFactors::B(0), + core::MatricesFactors::K(-1), l_linearSolver.get()); } // Part II. Solve the unknown increment. diff --git a/Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/VariationalSymplecticSolver.cpp b/Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/VariationalSymplecticSolver.cpp index 173b2523a89..8dfe7ab91d5 100644 --- a/Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/VariationalSymplecticSolver.cpp +++ b/Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/VariationalSymplecticSolver.cpp @@ -83,8 +83,8 @@ void VariationalSymplecticSolver::solve(const core::ExecParams* params, SReal dt sofa::simulation::common::VectorOperations vop( params, this->getContext() ); sofa::simulation::common::MechanicalOperations mop( params, this->getContext() ); - MultiVecCoord pos(&vop, core::VecCoordId::position() ); - MultiVecDeriv f(&vop, core::VecDerivId::force() ); + MultiVecCoord pos(&vop, core::vec_id::write_access::position ); + MultiVecDeriv f(&vop, core::vec_id::write_access::force ); MultiVecCoord oldpos(&vop); MultiVecCoord x_1(&vop, xResult); // vector of final position @@ -93,7 +93,7 @@ void VariationalSymplecticSolver::solve(const core::ExecParams* params, SReal dt MultiVecDeriv vel_1(&vop, vResult); // vector of final velocity MultiVecDeriv p(&vop); // vector of momentum // dx is no longer allocated by default (but it will be deleted automatically by the mechanical objects) - MultiVecDeriv dx(&vop, core::VecDerivId::dx()); dx.realloc(&vop, !d_threadSafeVisitor.getValue(), true); + MultiVecDeriv dx(&vop, core::vec_id::write_access::dx); dx.realloc(&vop, !d_threadSafeVisitor.getValue(), true); const SReal& h = dt; const SReal rM = d_rayleighMass.getValue(); @@ -130,7 +130,7 @@ void VariationalSymplecticSolver::solve(const core::ExecParams* params, SReal dt if (d_explicit.getValue()) { mop->setImplicit(false); // this solver is explicit only - MultiVecDeriv acc(&vop, core::VecDerivId::dx()); acc.realloc(&vop, !d_threadSafeVisitor.getValue(), true); // dx is no longer allocated by default (but it will be deleted automatically by the mechanical objects) + MultiVecDeriv acc(&vop, core::vec_id::write_access::dx); acc.realloc(&vop, !d_threadSafeVisitor.getValue(), true); // dx is no longer allocated by default (but it will be deleted automatically by the mechanical objects) { SCOPED_TIMER("ComputeForce"); @@ -144,7 +144,7 @@ void VariationalSymplecticSolver::solve(const core::ExecParams* params, SReal dt mop.accFromF(acc, f); // acc= 1/m (f(q(k)+p(k)/h)) if (rM>0) { - MultiVecDeriv oldVel(&vop, core::VecDerivId::velocity() ); + MultiVecDeriv oldVel(&vop, core::vec_id::write_access::velocity ); // add rayleigh Mass damping if necessary acc.peq(oldVel,-rM); // equivalent to adding damping force -rM* M*v(k) } @@ -215,7 +215,9 @@ void VariationalSymplecticSolver::solve(const core::ExecParams* params, SReal dt // corresponds to do b+=-K*res, where res=res(i-1)=q(k,i-1)-q(k,0) mop.propagateDx(res); - mop.addMBKdx(b,0,0,-1.0); + mop.addMBKdx(b,core::MatricesFactors::M(0), + core::MatricesFactors::B(0), + core::MatricesFactors::K(-1.0)); mop.projectResponse(b); @@ -224,9 +226,9 @@ void VariationalSymplecticSolver::solve(const core::ExecParams* params, SReal dt // add left term : matrix=-K+4/h^(2)M, but with dampings rK and rM { SCOPED_TIMER("MBKBuild"); - const SReal mFact = 4.0 / (h * h) + 4 * rM / h; - const SReal kFact = -1.0 - 4 * rK / h; - mop.setSystemMBKMatrix(mFact, 0, kFact, l_linearSolver.get()); + const core::MatricesFactors::M mFact ( 4.0 / (h * h) + 4 * rM / h ); + const core::MatricesFactors::K kFact ( -1.0 - 4 * rK / h ); + mop.setSystemMBKMatrix(mFact, core::MatricesFactors::B(0), kFact, l_linearSolver.get()); } { @@ -312,7 +314,7 @@ void VariationalSymplecticSolver::solve(const core::ExecParams* params, SReal dt MultiVecDeriv b(&vop); b.clear(); // Mass matrix - mop.setSystemMBKMatrix(1, 0, 0, l_linearSolver.get()); + mop.setSystemMBKMatrix(core::MatricesFactors::M(1), core::MatricesFactors::B(0), core::MatricesFactors::K(0), l_linearSolver.get()); // resolution of matrix*b=newp l_linearSolver->setSystemLHVector(b); diff --git a/Sofa/Component/ODESolver/Backward/tests/EulerImplicitSolverDynamic_test.cpp b/Sofa/Component/ODESolver/Backward/tests/EulerImplicitSolverDynamic_test.cpp index bec03c1f10f..d0a0fe377ee 100644 --- a/Sofa/Component/ODESolver/Backward/tests/EulerImplicitSolverDynamic_test.cpp +++ b/Sofa/Component/ODESolver/Backward/tests/EulerImplicitSolverDynamic_test.cpp @@ -119,7 +119,7 @@ struct EulerImplicitDynamic_test : public component::odesolver::testing::ODESolv do { // Record the mass position - Coord p0=dofs.get()->read(sofa::core::ConstVecCoordId::position())->getValue()[0]; + Coord p0=dofs.get()->read(sofa::core::vec_id::read_access::position)->getValue()[0]; double absoluteError = fabs(p0[1]-positionsArray[i]); diff --git a/Sofa/Component/ODESolver/Backward/tests/EulerImplicitSolver_withDamping_test.cpp b/Sofa/Component/ODESolver/Backward/tests/EulerImplicitSolver_withDamping_test.cpp index 26e9791231a..dc1089ed0a7 100644 --- a/Sofa/Component/ODESolver/Backward/tests/EulerImplicitSolver_withDamping_test.cpp +++ b/Sofa/Component/ODESolver/Backward/tests/EulerImplicitSolver_withDamping_test.cpp @@ -105,7 +105,7 @@ struct EulerImplicit_with_damping_forcefield : public BaseSimulationTest, Numeri // access the MechanicalObect (access position of the dampedParticule) typename MechanicalObject::SPtr dofs = dampedParticule->get>(root->SearchDown); - sofa::defaulttype::Vec3dTypes::Coord position = dofs.get()->read(sofa::core::ConstVecCoordId::position())->getValue()[0]; + sofa::defaulttype::Vec3dTypes::Coord position = dofs.get()->read(sofa::core::vec_id::read_access::position)->getValue()[0]; // save it as Vec3d for comparison with expected result Vec3d finalPosition(position[0], position[1], position[2]); diff --git a/Sofa/Component/ODESolver/Backward/tests/NewmarkImplicitSolverDynamic_test.cpp b/Sofa/Component/ODESolver/Backward/tests/NewmarkImplicitSolverDynamic_test.cpp index 092a5e781fc..82922f25323 100644 --- a/Sofa/Component/ODESolver/Backward/tests/NewmarkImplicitSolverDynamic_test.cpp +++ b/Sofa/Component/ODESolver/Backward/tests/NewmarkImplicitSolverDynamic_test.cpp @@ -133,7 +133,7 @@ struct NewmarkImplicitDynamic_test : public component::odesolver::testing::ODESo do { // Record the mass position - Coord p0=dofs.get()->read(sofa::core::ConstVecCoordId::position())->getValue()[0]; + Coord p0=dofs.get()->read(sofa::core::vec_id::read_access::position)->getValue()[0]; double absoluteError = fabs(p0[1]-positionsArray[i]); diff --git a/Sofa/Component/ODESolver/Backward/tests/SpringSolverDynamic_test.cpp b/Sofa/Component/ODESolver/Backward/tests/SpringSolverDynamic_test.cpp index ce4ab459c71..1425fb39be1 100644 --- a/Sofa/Component/ODESolver/Backward/tests/SpringSolverDynamic_test.cpp +++ b/Sofa/Component/ODESolver/Backward/tests/SpringSolverDynamic_test.cpp @@ -92,7 +92,7 @@ struct SpringSolverDynamic_test : public NumericTest do { // Record the mass position - Coord p0=dofs.get()->read(sofa::core::ConstVecCoordId::position())->getValue()[0]; + Coord p0=dofs.get()->read(sofa::core::vec_id::read_access::position)->getValue()[0]; // Absolute error double absoluteError = fabs(p0[1]-(cos(w*time))); diff --git a/Sofa/Component/ODESolver/Backward/tests/VariationalSymplecticExplicitSolverDynamic_test.cpp b/Sofa/Component/ODESolver/Backward/tests/VariationalSymplecticExplicitSolverDynamic_test.cpp index 5164f0a4d92..d002cc9af83 100644 --- a/Sofa/Component/ODESolver/Backward/tests/VariationalSymplecticExplicitSolverDynamic_test.cpp +++ b/Sofa/Component/ODESolver/Backward/tests/VariationalSymplecticExplicitSolverDynamic_test.cpp @@ -125,7 +125,7 @@ struct VariationalSymplecticExplicitSolverDynamic_test : public component::odeso do { // Record the mass position - Coord p0=dofs.get()->read(sofa::core::ConstVecCoordId::position())->getValue()[0]; + Coord p0=dofs.get()->read(sofa::core::vec_id::read_access::position)->getValue()[0]; double absoluteError = fabs(p0[1]-positionsArray[i]); diff --git a/Sofa/Component/ODESolver/Backward/tests/VariationalSymplecticImplicitSolverDynamic_test.cpp b/Sofa/Component/ODESolver/Backward/tests/VariationalSymplecticImplicitSolverDynamic_test.cpp index dfed7294f3e..e0c21b0c99b 100644 --- a/Sofa/Component/ODESolver/Backward/tests/VariationalSymplecticImplicitSolverDynamic_test.cpp +++ b/Sofa/Component/ODESolver/Backward/tests/VariationalSymplecticImplicitSolverDynamic_test.cpp @@ -147,7 +147,7 @@ struct VariationalSymplecticImplicitSolverDynamic_test : public component::odeso do { // Record the mass position - Coord p0=dofs.get()->read(sofa::core::ConstVecCoordId::position())->getValue()[0]; + Coord p0=dofs.get()->read(sofa::core::vec_id::read_access::position)->getValue()[0]; double absoluteError = fabs(p0[1]-positionsArray[i]); diff --git a/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/CentralDifferenceSolver.cpp b/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/CentralDifferenceSolver.cpp index 6bd37b851d4..9204dcc8f63 100644 --- a/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/CentralDifferenceSolver.cpp +++ b/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/CentralDifferenceSolver.cpp @@ -79,12 +79,12 @@ void CentralDifferenceSolver::solve(const core::ExecParams* params, SReal dt, so sofa::simulation::common::VectorOperations vop( params, this->getContext() ); sofa::simulation::common::MechanicalOperations mop( params, this->getContext() ); mop->setImplicit(false); // this solver is explicit only - MultiVecCoord pos(&vop, core::VecCoordId::position() ); - MultiVecDeriv vel(&vop, core::VecDerivId::velocity() ); - MultiVecCoord pos2(&vop, xResult /*core::VecCoordId::position()*/ ); - MultiVecDeriv vel2(&vop, vResult /*core::VecDerivId::velocity()*/ ); - MultiVecDeriv dx(&vop, core::VecDerivId::dx()); dx.realloc(&vop, !d_threadSafeVisitor.getValue(), true); - MultiVecDeriv f (&vop, core::VecDerivId::force() ); + MultiVecCoord pos(&vop, core::vec_id::write_access::position ); + MultiVecDeriv vel(&vop, core::vec_id::write_access::velocity ); + MultiVecCoord pos2(&vop, xResult /*core::vec_id::write_access::position*/ ); + MultiVecDeriv vel2(&vop, vResult /*core::vec_id::write_access::velocity*/ ); + MultiVecDeriv dx(&vop, core::vec_id::write_access::dx); dx.realloc(&vop, !d_threadSafeVisitor.getValue(), true); + MultiVecDeriv f (&vop, core::vec_id::write_access::force ); const SReal r = d_rayleighMass.getValue(); diff --git a/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/DampVelocitySolver.cpp b/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/DampVelocitySolver.cpp index c82d4a05790..1590035c551 100644 --- a/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/DampVelocitySolver.cpp +++ b/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/DampVelocitySolver.cpp @@ -47,7 +47,7 @@ DampVelocitySolver::DampVelocitySolver() void DampVelocitySolver::solve(const core::ExecParams* params, SReal dt, sofa::core::MultiVecCoordId /*xResult*/, sofa::core::MultiVecDerivId vResult) { sofa::simulation::common::VectorOperations vop( params, this->getContext() ); - MultiVecDeriv vel(&vop, vResult /*core::VecDerivId::velocity()*/ ); + MultiVecDeriv vel(&vop, vResult /*core::vec_id::write_access::velocity*/ ); msg_info() <<"DampVelocitySolver, dt = "<< dt <<"DampVelocitySolver, initial v = "<< vel ; diff --git a/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/EulerExplicitSolver.cpp b/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/EulerExplicitSolver.cpp index a1a0ecc83b2..ebf86e5ed79 100644 --- a/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/EulerExplicitSolver.cpp +++ b/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/EulerExplicitSolver.cpp @@ -76,8 +76,8 @@ void EulerExplicitSolver::solve(const core::ExecParams* params, mop->setImplicit(false); // Initialize the set of multi-vectors computed by this solver - MultiVecDeriv acc (&vop, core::VecDerivId::dx()); // acceleration to be computed - MultiVecDeriv f (&vop, core::VecDerivId::force() ); // force to be computed + MultiVecDeriv acc (&vop, core::vec_id::write_access::dx); // acceleration to be computed + MultiVecDeriv f (&vop, core::vec_id::write_access::force ); // force to be computed acc.realloc(&vop, !d_threadSafeVisitor.getValue(), true); @@ -140,8 +140,8 @@ void EulerExplicitSolver::updateState(sofa::simulation::common::VectorOperations MultiVecDeriv newVel(vop, vResult); // position to be computed // Initialize the set of multi-vectors used to compute the new velocity and position - MultiVecCoord pos(vop, core::VecCoordId::position() ); //current position - MultiVecDeriv vel(vop, core::VecDerivId::velocity() ); //current velocity + MultiVecCoord pos(vop, core::vec_id::write_access::position ); //current position + MultiVecDeriv vel(vop, core::vec_id::write_access::velocity ); //current velocity #ifdef SOFA_NO_VMULTIOP // unoptimized version if (d_symplectic.getValue()) @@ -328,7 +328,10 @@ void EulerExplicitSolver::assembleSystemMatrix(sofa::simulation::common::Mechani // is called on every BaseProjectiveConstraintSet objects. An example of such constraint set is the // FixedProjectiveConstraint. In this case, it will set to 0 every column (_, i) and row (i, _) of the assembled // matrix for the ith degree of freedom. - mop->setSystemMBKMatrix(1, 0, 0, l_linearSolver.get()); + mop->setSystemMBKMatrix( + core::MatricesFactors::M(1), + core::MatricesFactors::B(0), + core::MatricesFactors::K(0), l_linearSolver.get()); } void EulerExplicitSolver::solveSystem(core::MultiVecDerivId solution, core::MultiVecDerivId rhs) const diff --git a/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/RungeKutta2Solver.cpp b/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/RungeKutta2Solver.cpp index c395c262151..7eefc5dc953 100644 --- a/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/RungeKutta2Solver.cpp +++ b/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/RungeKutta2Solver.cpp @@ -46,10 +46,10 @@ void RungeKutta2Solver::solve(const core::ExecParams* params, SReal dt, sofa::co sofa::simulation::common::MechanicalOperations mop( params, this->getContext() ); mop->setImplicit(false); // this solver is explicit only // Get the Ids of the state vectors - MultiVecCoord pos(&vop, core::VecCoordId::position() ); - MultiVecDeriv vel(&vop, core::VecDerivId::velocity() ); - MultiVecCoord pos2(&vop, xResult /*core::VecCoordId::position()*/ ); - MultiVecDeriv vel2(&vop, vResult /*core::VecDerivId::velocity()*/ ); + MultiVecCoord pos(&vop, core::vec_id::write_access::position ); + MultiVecDeriv vel(&vop, core::vec_id::write_access::velocity ); + MultiVecCoord pos2(&vop, xResult /*core::vec_id::write_access::position*/ ); + MultiVecDeriv vel2(&vop, vResult /*core::vec_id::write_access::velocity*/ ); // Allocate auxiliary vectors MultiVecDeriv acc(&vop); diff --git a/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/RungeKutta4Solver.cpp b/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/RungeKutta4Solver.cpp index 02fb117ec02..2d643eda0d4 100644 --- a/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/RungeKutta4Solver.cpp +++ b/Sofa/Component/ODESolver/Forward/src/sofa/component/odesolver/forward/RungeKutta4Solver.cpp @@ -47,10 +47,10 @@ void RungeKutta4Solver::solve(const core::ExecParams* params, SReal dt, sofa::co sofa::simulation::common::MechanicalOperations mop( params, this->getContext() ); mop->setImplicit(false); // this solver is explicit only // Get the Ids of the state vectors - MultiVecCoord pos(&vop, core::VecCoordId::position() ); - MultiVecDeriv vel(&vop, core::VecDerivId::velocity() ); - MultiVecCoord pos2(&vop, xResult /*core::VecCoordId::position()*/ ); - MultiVecDeriv vel2(&vop, vResult /*core::VecDerivId::velocity()*/ ); + MultiVecCoord pos(&vop, core::vec_id::write_access::position ); + MultiVecDeriv vel(&vop, core::vec_id::write_access::velocity ); + MultiVecCoord pos2(&vop, xResult /*core::vec_id::write_access::position*/ ); + MultiVecDeriv vel2(&vop, vResult /*core::vec_id::write_access::velocity*/ ); // Allocate auxiliary vectors MultiVecDeriv k1a(&vop); diff --git a/Sofa/Component/ODESolver/Forward/tests/CentralDifferenceExplicitSolverDynamic_test.cpp b/Sofa/Component/ODESolver/Forward/tests/CentralDifferenceExplicitSolverDynamic_test.cpp index 54728aa702e..d285140199c 100644 --- a/Sofa/Component/ODESolver/Forward/tests/CentralDifferenceExplicitSolverDynamic_test.cpp +++ b/Sofa/Component/ODESolver/Forward/tests/CentralDifferenceExplicitSolverDynamic_test.cpp @@ -151,7 +151,7 @@ struct CentralDifferenceExplicitSolverDynamic_test : public component::odesolver do { // Record the mass position - Coord p0=dofs.get()->read(sofa::core::ConstVecCoordId::position())->getValue()[0]; + Coord p0=dofs.get()->read(sofa::core::vec_id::read_access::position)->getValue()[0]; double absoluteError = fabs(p0[1]-positionsArray[i]); diff --git a/Sofa/Component/ODESolver/Forward/tests/EulerExplicitSolverDynamic_test.cpp b/Sofa/Component/ODESolver/Forward/tests/EulerExplicitSolverDynamic_test.cpp index 13b9996e99f..f6a13eb435f 100644 --- a/Sofa/Component/ODESolver/Forward/tests/EulerExplicitSolverDynamic_test.cpp +++ b/Sofa/Component/ODESolver/Forward/tests/EulerExplicitSolverDynamic_test.cpp @@ -118,7 +118,7 @@ struct EulerExplicitDynamic_test : public component::odesolver::testing::ODESolv do { // Record the mass position - Coord p0=dofs.get()->read(sofa::core::ConstVecCoordId::position())->getValue()[0]; + Coord p0=dofs.get()->read(sofa::core::vec_id::read_access::position)->getValue()[0]; double absoluteError = fabs(p0[1]-positionsArray[i]); diff --git a/Sofa/Component/ODESolver/Forward/tests/RungeKutta2ExplicitSolverDynamic_test.cpp b/Sofa/Component/ODESolver/Forward/tests/RungeKutta2ExplicitSolverDynamic_test.cpp index a14d872f70c..683e546b8fa 100644 --- a/Sofa/Component/ODESolver/Forward/tests/RungeKutta2ExplicitSolverDynamic_test.cpp +++ b/Sofa/Component/ODESolver/Forward/tests/RungeKutta2ExplicitSolverDynamic_test.cpp @@ -133,7 +133,7 @@ struct RungeKutta2ExplicitSolverDynamic_test : public component::odesolver::test do { // Record the mass position - Coord p0=dofs.get()->read(sofa::core::ConstVecCoordId::position())->getValue()[0]; + Coord p0=dofs.get()->read(sofa::core::vec_id::read_access::position)->getValue()[0]; double absoluteError = fabs(p0[1]-positionsArray[i]); diff --git a/Sofa/Component/ODESolver/Forward/tests/RungeKutta4ExplicitSolverDynamic_test.cpp b/Sofa/Component/ODESolver/Forward/tests/RungeKutta4ExplicitSolverDynamic_test.cpp index 6324580e9b5..eddbfaa0338 100644 --- a/Sofa/Component/ODESolver/Forward/tests/RungeKutta4ExplicitSolverDynamic_test.cpp +++ b/Sofa/Component/ODESolver/Forward/tests/RungeKutta4ExplicitSolverDynamic_test.cpp @@ -169,7 +169,7 @@ struct RungeKutta4ExplicitSolverDynamic_test : public component::odesolver::test do { // Record the mass position - Coord p0=dofs.get()->read(sofa::core::ConstVecCoordId::position())->getValue()[0]; + Coord p0=dofs.get()->read(sofa::core::vec_id::read_access::position)->getValue()[0]; double absoluteError = fabs(p0[1]-positionsArray[i]); diff --git a/Sofa/Component/Playback/src/sofa/component/playback/CompareState.cpp b/Sofa/Component/Playback/src/sofa/component/playback/CompareState.cpp index 124d86d4d21..fab90dd10cf 100644 --- a/Sofa/Component/Playback/src/sofa/component/playback/CompareState.cpp +++ b/Sofa/Component/Playback/src/sofa/component/playback/CompareState.cpp @@ -216,7 +216,7 @@ void CompareState::draw(const core::visual::VisualParams* vparams) str >> cmd; mmodel->readVec(refX, str); - const core::objectmodel::BaseData* dataX = mmodel->baseRead(core::VecCoordId::position()); + const core::objectmodel::BaseData* dataX = mmodel->baseRead(core::vec_id::write_access::position); const core::objectmodel::BaseData* dataRefX = mmodel->baseRead(refX); if (dataX && dataRefX) { diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/BeamFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/BeamFEMForceField.inl index e0082b1c3b6..d7aa2c49ebc 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/BeamFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/BeamFEMForceField.inl @@ -150,7 +150,7 @@ void BeamFEMForceField::reinitBeam(Index i) SReal stiffness, length, radius, poisson, radiusInner; const auto& [a, b] = (*m_indexedElements)[i].array(); - const VecCoord& x0 = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& x0 = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); stiffness = this->getYoungModulusInElement(i); length = (x0[a].getCenter()-x0[b].getCenter()).norm() ; @@ -340,7 +340,7 @@ inline type::Quat qDiff(type::Quat a, const type::Quat& b) template void BeamFEMForceField::initLarge(int i, Index a, Index b) { - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); type::Quat quatA, quatB, dQ; Vec3 dW; @@ -379,7 +379,7 @@ void BeamFEMForceField::initLarge(int i, Index a, Index b) template void BeamFEMForceField::accumulateForceLarge( VecDeriv& f, const VecCoord & x, int i, Index a, Index b ) { - const VecCoord& x0 = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& x0 = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); beamQuat(i)= x[a].getOrientation(); beamQuat(i).normalize(); @@ -706,7 +706,7 @@ void BeamFEMForceField::draw(const core::visual::VisualParams* vparam const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); std::vector< type::Vec3 > points[3]; @@ -742,7 +742,7 @@ void BeamFEMForceField::computeBBox(const core::ExecParams* params, b const size_t npoints = this->mstate->getSize(); - const VecCoord& p = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& p = this->mstate->read(core::vec_id::read_access::position)->getValue(); for (size_t i=0; i::createTetrahedronRestInfo typename DataTypes::Real volume,val; typename DataTypes::Coord point[4]; //shapeVector[4]; - const typename DataTypes::VecCoord restPosition=this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const typename DataTypes::VecCoord restPosition=this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); ///describe the indices of the 4 tetrahedron vertices const Tetrahedron &t= tetrahedronArray[tetrahedronIndex]; @@ -215,7 +215,7 @@ void FastTetrahedralCorotationalForceField::init() if (_initialPoints.size() == 0) { // get restPosition - const VecCoord& p = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& p = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); _initialPoints=p; } @@ -677,7 +677,7 @@ void FastTetrahedralCorotationalForceField::draw(const core::visual:: const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); if (vparams->displayFlags().getShowWireFrame()) vparams->drawTool()->setPolygonMode(0, true); diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceField.inl index 004643416b1..bd2e5cf3d83 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceField.inl @@ -386,7 +386,7 @@ void HexahedralFEMForceField::initLarge(const int i) // second vector in the plane of the two first edges // third vector orthogonal to first and second - const VecCoord& X0=this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& X0=this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); type::Vec<8,Coord> nodes; for(int w=0; w<8; ++w) @@ -486,7 +486,7 @@ void HexahedralFEMForceField::accumulateForceLarge( WDataRefVecDeriv& template void HexahedralFEMForceField::initPolar(const int i) { - const VecCoord& X0=this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& X0=this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); type::Vec<8,Coord> nodes; for(int j=0; j<8; ++j) @@ -668,7 +668,7 @@ void HexahedralFEMForceField::draw(const core::visual::VisualParams* std::vector colorVector; std::vector vertices; - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); if (vparams->displayFlags().getShowWireFrame()) { diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceFieldAndMass.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceFieldAndMass.inl index f516deee8dc..a1caaa2e893 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceFieldAndMass.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceFieldAndMass.inl @@ -135,7 +135,7 @@ void HexahedralFEMForceFieldAndMass::computeLumpedMasses( ) template void HexahedralFEMForceFieldAndMass::computeElementMasses( ) { - const VecCoord& initialPoints = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& initialPoints = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); const VecElement& hexahedra = this->l_topology->getHexahedra(); @@ -457,7 +457,7 @@ void HexahedralFEMForceFieldAndMass::draw(const core::visual::VisualP if (!vparams->displayFlags().getShowBehaviorModels()) return; - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); std::vector pos; pos.reserve(x.size()); diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.inl index 5c1f4fe5d05..4fc06689e2c 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.inl @@ -139,7 +139,7 @@ void HexahedronFEMForceField::init() template void HexahedronFEMForceField::reinit() { - const VecCoord& p = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& p = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); d_initialPoints.setValue(p); _materialsStiffnesses.resize(this->getIndexedElements()->size() ); @@ -1197,7 +1197,7 @@ void HexahedronFEMForceField::computeBBox(const core::ExecParams* par if( !onlyVisible ) return; - helper::ReadAccessor x = this->mstate->read(core::VecCoordId::position()); + helper::ReadAccessor x = this->mstate->read(core::vec_id::write_access::position); static const Real max_real = std::numeric_limits::max(); static const Real min_real = std::numeric_limits::lowest(); @@ -1227,7 +1227,7 @@ void HexahedronFEMForceField::draw(const core::visual::VisualParams* const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); vparams->drawTool()->setLightingEnabled(false); diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceFieldAndMass.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceFieldAndMass.inl index 59010e9d900..a06b21128b0 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceFieldAndMass.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceFieldAndMass.inl @@ -350,7 +350,7 @@ void HexahedronFEMForceFieldAndMass::draw(const core::visual::VisualP if (!vparams->displayFlags().getShowBehaviorModels()) return; - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); // since drawTool requires a std::vector we have to convert x in an ugly way std::vector pos; pos.resize(x.size()); diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/QuadBendingFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/QuadBendingFEMForceField.inl index add56877b76..2439b38ea7e 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/QuadBendingFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/QuadBendingFEMForceField.inl @@ -149,7 +149,7 @@ void QuadBendingFEMForceField::initSmall(int i, Index&a, Index&b, Ind Coord IntlengthElement; Coord IntheightElement; - const VecCoord& initialPoints = (this->mstate->read(core::ConstVecCoordId::restPosition())->getValue()); + const VecCoord& initialPoints = (this->mstate->read(core::vec_id::read_access::restPosition)->getValue()); qinfo->IntlengthElement = (initialPoints)[b] - (initialPoints)[a]; qinfo->IntheightElement = (initialPoints)[d] - (initialPoints)[a]; qinfo->Intcentroid = ((initialPoints)[a] + (initialPoints)[c]) / 2; @@ -441,7 +441,7 @@ template void QuadBendingFEMForceField::computeElementStiffness( Stiffness &K, Index elementIndex) { type::vector& quadInf = *(d_quadInfo.beginEdit()); - const VecCoord& p = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& p = this->mstate->read(core::vec_id::read_access::position)->getValue(); //QuadInformation *qinfo = &quadInf[elementIndex]; Index idx0 = m_topology->getQuad(elementIndex)[0]; diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedralCorotationalFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedralCorotationalFEMForceField.inl index 7ae0a6e3ce4..0952d6c8f91 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedralCorotationalFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedralCorotationalFEMForceField.inl @@ -402,7 +402,7 @@ void TetrahedralCorotationalFEMForceField::computeMaterialStiffness(i materialMatrix *= (youngModulus*(1-poissonRatio))/((1+poissonRatio)*(1-2*poissonRatio)); // divide by 36 times volumes of the element - const VecCoord X0=this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord X0=this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); Coord A = (X0)[b] - (X0)[a]; Coord B = (X0)[c] - (X0)[a]; @@ -627,7 +627,7 @@ inline void TetrahedralCorotationalFEMForceField::computeForce( Displ template void TetrahedralCorotationalFEMForceField::initSmall(int i, Index&a, Index&b, Index&c, Index&d) { - const VecCoord X0=this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord X0=this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); type::vector::TetrahedronInformation>& tetrahedronInf = *(d_tetrahedronInfo.beginEdit()); @@ -643,7 +643,7 @@ void TetrahedralCorotationalFEMForceField::accumulateForceSmall( Vect { const core::topology::BaseMeshTopology::Tetrahedron t=this->l_topology->getTetrahedron(elementIndex); - const VecCoord& X0=this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& X0=this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); const auto& [a, b, c, d] = t.array(); @@ -867,7 +867,7 @@ void TetrahedralCorotationalFEMForceField::initLarge(int i, Index&a, // first vector on first edge // second vector in the plane of the two first edges // third vector orthogonal to first and second - const VecCoord& X0=this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& X0=this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); Transformation R_0_1; computeRotationLarge( R_0_1, (X0), a, b, c); @@ -1069,7 +1069,7 @@ void TetrahedralCorotationalFEMForceField::applyStiffnessLarge( Vecto template void TetrahedralCorotationalFEMForceField::initPolar(int i, Index& a, Index&b, Index&c, Index&d) { - const VecCoord X0=this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord X0=this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); type::vector::TetrahedronInformation>& tetrahedronInf = *(d_tetrahedronInfo.beginEdit()); @@ -1204,7 +1204,7 @@ void TetrahedralCorotationalFEMForceField::computeBBox(const core::Ex if( !onlyVisible ) return; - helper::ReadAccessor x = this->mstate->read(core::VecCoordId::position()); + helper::ReadAccessor x = this->mstate->read(core::vec_id::write_access::position); static const Real max_real = std::numeric_limits::max(); static const Real min_real = std::numeric_limits::lowest(); @@ -1338,7 +1338,7 @@ void TetrahedralCorotationalFEMForceField::draw(const core::visual::V const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); if (vparams->displayFlags().getShowWireFrame()) vparams->drawTool()->setPolygonMode(0,true); diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.inl index 4a5ce9bfb61..9e3543655af 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.inl @@ -1441,7 +1441,7 @@ inline void TetrahedronFEMForceField::reinit() } setMethod(d_method.getValue() ); - const VecCoord& p = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& p = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); d_initialPoints.setValue(p); strainDisplacements.resize( _indexedElements->size() ); materialsStiffnesses.resize(_indexedElements->size() ); @@ -1678,7 +1678,7 @@ void TetrahedronFEMForceField::computeBBox(const core::ExecParams*, b if( !onlyVisible ) return; if (!this->mstate) return; - helper::ReadAccessor x = this->mstate->read(core::VecCoordId::position()); + helper::ReadAccessor x = this->mstate->read(core::vec_id::write_access::position); static const Real max_real = std::numeric_limits::max(); static const Real min_real = std::numeric_limits::lowest(); @@ -1860,7 +1860,7 @@ void TetrahedronFEMForceField::draw(const core::visual::VisualParams* vparams->drawTool()->disableLighting(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); const VecReal& youngModulus = this->d_youngModulus.getValue(); const bool heterogeneous = [this, drawVonMisesStress]() @@ -1925,7 +1925,7 @@ void TetrahedronFEMForceField::draw(const core::visual::VisualParams* ////////////// DRAW ROTATIONS ////////////// if (vparams->displayFlags().getShowNormals()) { - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); std::vector< type::Vec3 > points[3]; for(unsigned ii = 0; ii< x.size() ; ii++) { @@ -2250,7 +2250,7 @@ void TetrahedronFEMForceField::computeVonMisesStress() typename core::behavior::MechanicalState* mechanicalObject; this->getContext()->get(mechanicalObject); - const VecCoord& X = mechanicalObject->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& X = mechanicalObject->read(core::vec_id::read_access::position)->getValue(); helper::ReadAccessor > X0 = d_initialPoints; @@ -2397,7 +2397,7 @@ void TetrahedronFEMForceField::computeVonMisesStress() vME[el] = 0.0; } - const VecCoord& dofs = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& dofs = this->mstate->read(core::vec_id::read_access::position)->getValue(); helper::WriteAccessor > > vMN = d_vonMisesPerNode; /// compute the values of vonMises stress in nodes diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangleFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangleFEMForceField.inl index a05b2ba75a0..13ec574a40d 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangleFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangleFEMForceField.inl @@ -95,7 +95,7 @@ void TriangleFEMForceField::init() if (d_initialPoints.getValue().size() == 0) { - const VecCoord& p = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& p = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); d_initialPoints.setValue(p); } @@ -558,7 +558,7 @@ void TriangleFEMForceField::draw(const core::visual::VisualParams* vp std::vector colorVector; std::vector vertices; - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); typename VecElement::const_iterator it; for (it = _indexedElements->begin(); it != _indexedElements->end(); ++it) diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularAnisotropicFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularAnisotropicFEMForceField.inl index a7ff547c05f..9357c4fe811 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularAnisotropicFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularAnisotropicFEMForceField.inl @@ -141,7 +141,7 @@ void TriangularAnisotropicFEMForceField::getFiberDir(int element, Der if ((unsigned)element < lfd.size()) { const Deriv& ref = lfd[element]; - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); core::topology::BaseMeshTopology::Triangle t = this->l_topology->getTriangle(element); dir = (x[t[1]]-x[t[0]])*ref[0] + (x[t[2]]-x[t[0]])*ref[1]; } @@ -155,7 +155,7 @@ void TriangularAnisotropicFEMForceField::getFiberDir(int element, Der template void TriangularAnisotropicFEMForceField::computeMaterialStiffness(int i, Index& v1, Index& v2, Index& v3) { - const VecCoord& initialPoints = (this->mstate->read(core::ConstVecCoordId::restPosition())->getValue()); + const VecCoord& initialPoints = (this->mstate->read(core::vec_id::read_access::restPosition)->getValue()); Real Q11, Q12, Q22, Q66; Coord fiberDirGlobal; // orientation of the fiber in the global frame of reference @@ -314,7 +314,7 @@ void TriangularAnisotropicFEMForceField::draw(const core::visual::Vis constexpr sofa::type::RGBAColor color = sofa::type::RGBAColor::black(); std::vector vertices; - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); const int nbTriangles=this->l_topology->getNbTriangles(); for(int i=0; i::initSmall(int i, Index& a, Index& b, In tinfo->rotatedInitialElements = d_rotatedInitialElements.getValue()[i]; else { - const VecCoord& initialPoints = (this->mstate->read(core::ConstVecCoordId::restPosition())->getValue()); + const VecCoord& initialPoints = (this->mstate->read(core::vec_id::read_access::restPosition)->getValue()); const Coord& pA = initialPoints[a]; const Coord& pB = initialPoints[b]; const Coord& pC = initialPoints[c]; @@ -211,7 +211,7 @@ void TriangularFEMForceField::initLarge(int i, Index& a, Index& b, In } else { - const VecCoord& initialPoints = (this->mstate->read(core::ConstVecCoordId::restPosition())->getValue()); + const VecCoord& initialPoints = (this->mstate->read(core::vec_id::read_access::restPosition)->getValue()); tinfo->rotation = tinfo->initialTransformation; if (a >= (initialPoints).size() || b >= (initialPoints).size() || c >= (initialPoints).size()) { @@ -757,7 +757,7 @@ void TriangularFEMForceField::computeStress(type::Vec<3, Real>& stres StrainDisplacement J; type::Vec<3, Real> strain; Transformation R_0_2, R_2_0; - const VecCoord& p = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& p = this->mstate->read(core::vec_id::read_access::position)->getValue(); const Triangle& tri = this->l_topology->getTriangle(elementIndex); const auto& [a, b, c] = tri.array(); @@ -879,7 +879,7 @@ void TriangularFEMForceField::computeStressAcrossDirection(Real& stre { const Triangle& tri = this->l_topology->getTriangle(elementIndex); const auto& [a, b, c] = tri.array(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); Coord n = cross(x[b] - x[a], x[c] - x[a]); Coord dir_t = cross(dir, n); this->computeStressAlongDirection(stress_across_dir, elementIndex, dir_t, stress); @@ -890,7 +890,7 @@ void TriangularFEMForceField::computeStressAcrossDirection(Real& stre { const Triangle& tri = this->l_topology->getTriangle(elementIndex); const auto& [a, b, c] = tri.array(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); Coord n = cross(x[b] - x[a], x[c] - x[a]); Coord dir_t = cross(dir, n); this->computeStressAlongDirection(stress_across_dir, elementIndex, dir_t); @@ -1242,7 +1242,7 @@ void TriangularFEMForceField::draw(const core::visual::VisualParams* vparams->drawTool()->disableLighting(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); const type::vector& triangleInf = d_triangleInfo.getValue(); const auto& triangles = this->l_topology->getTriangles(); const Size nbTriangles = triangles.size(); diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularFEMForceFieldOptim.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularFEMForceFieldOptim.inl index 3259d22b7dd..7a20cbfd300 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularFEMForceFieldOptim.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularFEMForceFieldOptim.inl @@ -180,13 +180,13 @@ void TriangularFEMForceFieldOptim::initTriangleState(Index i, Triangl template< class DataTypes> void TriangularFEMForceFieldOptim::createTriangleInfo(Index triangleIndex, TriangleInfo& ti, const Triangle& t, const sofa::type::vector&, const sofa::type::vector&) { - initTriangleInfo(triangleIndex, ti, t, this->mstate->read(core::ConstVecCoordId::restPosition())->getValue()); + initTriangleInfo(triangleIndex, ti, t, this->mstate->read(core::vec_id::read_access::restPosition)->getValue()); } template< class DataTypes> void TriangularFEMForceFieldOptim::createTriangleState(Index triangleIndex, TriangleState& ti, const Triangle& t, const sofa::type::vector&, const sofa::type::vector&) { - initTriangleState(triangleIndex, ti, t, this->mstate->read(core::ConstVecCoordId::position())->getValue()); + initTriangleState(triangleIndex, ti, t, this->mstate->read(core::vec_id::read_access::position)->getValue()); } // -------------------------------------------------------------------------------------- @@ -198,8 +198,8 @@ void TriangularFEMForceFieldOptim::reinit() /// prepare to store info in the triangle array const unsigned int nbTriangles = this->l_topology->getNbTriangles(); const VecElement& triangles = this->l_topology->getTriangles(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& x0 = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& x0 = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); VecTriangleInfo& triangleInf = *(d_triangleInfo.beginEdit()); VecTriangleState& triangleSta = *(d_triangleState.beginEdit()); triangleInf.resize(nbTriangles); @@ -770,7 +770,7 @@ void TriangularFEMForceFieldOptim::draw(const core::visual::VisualPar using type::Vec3i; using type::Vec4f; - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); unsigned int nbTriangles=this->l_topology->getNbTriangles(); const VecElement& triangles = this->l_topology->getTriangles(); const Real& stressThresold = d_showStressThreshold.getValue(); diff --git a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/StandardTetrahedralFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/StandardTetrahedralFEMForceField.inl index c7ce2017fa6..ed8d2eaafd7 100644 --- a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/StandardTetrahedralFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/StandardTetrahedralFEMForceField.inl @@ -169,7 +169,7 @@ template void StandardTetrahedralFEMForceField::ini if (_initialPoints.size() == 0) { - const VecCoord& p = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& p = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); _initialPoints=p; } @@ -209,7 +209,7 @@ void StandardTetrahedralFEMForceField::createTetrahedronRestInformati unsigned int j; typename DataTypes::Real volume; typename DataTypes::Coord point[4]; - const typename DataTypes::VecCoord restPosition = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const typename DataTypes::VecCoord restPosition = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); ///describe the indices of the 4 tetrahedron vertices const core::topology::BaseMeshTopology::Tetrahedron& t = tetrahedronArray[tetrahedronIndex]; @@ -607,7 +607,7 @@ void StandardTetrahedralFEMForceField::draw(const core::visual::Visua const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); if (vparams->displayFlags().getShowWireFrame()) vparams->drawTool()->setPolygonMode(0,true); @@ -625,7 +625,7 @@ void StandardTetrahedralFEMForceField::testDerivatives() { DataVecCoord d_pos; VecCoord &pos = *d_pos.beginEdit(); - pos = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + pos = this->mstate->read(core::vec_id::read_access::position)->getValue(); // perturb original state: srand( 0 ); @@ -748,7 +748,7 @@ void StandardTetrahedralFEMForceField::testDerivatives() template void StandardTetrahedralFEMForceField::saveMesh( const char *filename ) { - VecCoord pos( this->mstate->read(core::ConstVecCoordId::position())->getValue() ); + VecCoord pos( this->mstate->read(core::vec_id::read_access::position)->getValue() ); const core::topology::BaseMeshTopology::SeqTriangles triangles = m_topology->getTriangles(); FILE *file = fopen( filename, "wb" ); if (!file) return; diff --git a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/TetrahedronHyperelasticityFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/TetrahedronHyperelasticityFEMForceField.inl index adc26351f83..34a5f4b2a51 100644 --- a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/TetrahedronHyperelasticityFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/TetrahedronHyperelasticityFEMForceField.inl @@ -183,7 +183,7 @@ template void TetrahedronHyperelasticityFEMForceFieldmstate->read(core::ConstVecCoordId::restPosition())->getValue(); + m_initialPoints = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); } /// initialize the data structure associated with each tetrahedron @@ -243,7 +243,7 @@ void TetrahedronHyperelasticityFEMForceField::createTetrahedronRestIn typename DataTypes::Real volume; typename DataTypes::Coord point[4]; - const VecCoord& restPosition = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& restPosition = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); ///describe the indices of the 4 tetrahedron vertices const Tetrahedron& t = tetrahedronArray[tetrahedronIndex]; @@ -599,7 +599,7 @@ void TetrahedronHyperelasticityFEMForceField::testDerivatives() { DataVecCoord d_pos; VecCoord &pos = *d_pos.beginEdit(); - pos = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + pos = this->mstate->read(core::vec_id::read_access::position)->getValue(); // perturb original state: srand( 0 ); @@ -752,7 +752,7 @@ void TetrahedronHyperelasticityFEMForceField::draw(const core::visual const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); if (vparams->displayFlags().getShowWireFrame()) vparams->drawTool()->setPolygonMode(0,true); diff --git a/Sofa/Component/SolidMechanics/FEM/NonUniform/src/sofa/component/solidmechanics/fem/nonuniform/HexahedronCompositeFEMForceFieldAndMass.inl b/Sofa/Component/SolidMechanics/FEM/NonUniform/src/sofa/component/solidmechanics/fem/nonuniform/HexahedronCompositeFEMForceFieldAndMass.inl index f4040250526..15d578c5cc6 100644 --- a/Sofa/Component/SolidMechanics/FEM/NonUniform/src/sofa/component/solidmechanics/fem/nonuniform/HexahedronCompositeFEMForceFieldAndMass.inl +++ b/Sofa/Component/SolidMechanics/FEM/NonUniform/src/sofa/component/solidmechanics/fem/nonuniform/HexahedronCompositeFEMForceFieldAndMass.inl @@ -1558,7 +1558,7 @@ void HexahedronCompositeFEMForceFieldAndMass::draw(const core::visual::Visual const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); sofa::type::RGBAColor colour; diff --git a/Sofa/Component/SolidMechanics/FEM/NonUniform/src/sofa/component/solidmechanics/fem/nonuniform/HexahedronCompositeFEMMapping.inl b/Sofa/Component/SolidMechanics/FEM/NonUniform/src/sofa/component/solidmechanics/fem/nonuniform/HexahedronCompositeFEMMapping.inl index 9f2c1dc90e5..ef8a4492aae 100644 --- a/Sofa/Component/SolidMechanics/FEM/NonUniform/src/sofa/component/solidmechanics/fem/nonuniform/HexahedronCompositeFEMMapping.inl +++ b/Sofa/Component/SolidMechanics/FEM/NonUniform/src/sofa/component/solidmechanics/fem/nonuniform/HexahedronCompositeFEMMapping.inl @@ -61,12 +61,12 @@ void HexahedronCompositeFEMMapping::init() for(unsigned i=0; i<(unsigned)this->toModel->getSize(); ++i) - _p0.push_back( this->toModel->read(core::ConstVecCoordId::position())->getValue()[i] ); + _p0.push_back( this->toModel->read(core::vec_id::read_access::position)->getValue()[i] ); for(unsigned i=0; i<(unsigned)this->fromModel->getSize(); ++i) // par construction de la sparse grid, pas de rotation initiale - _qCoarse0.push_back( this->fromModel->read(core::ConstVecCoordId::position())->getValue()[i] ); + _qCoarse0.push_back( this->fromModel->read(core::vec_id::read_access::position)->getValue()[i] ); - InCoord translation0 = this->fromModel->read(core::ConstVecCoordId::position())->getValue()[0] - _sparseGrid->getPointPos(0); + InCoord translation0 = this->fromModel->read(core::vec_id::read_access::position)->getValue()[0] - _sparseGrid->getPointPos(0); for(Size i=0; i<_finestSparseGrid->getNbPoints(); ++i) _qFine0.push_back( _finestSparseGrid->getPointPos(i)+translation0 ); diff --git a/Sofa/Component/SolidMechanics/FEM/NonUniform/src/sofa/component/solidmechanics/fem/nonuniform/NonUniformHexahedralFEMForceFieldAndMass.inl b/Sofa/Component/SolidMechanics/FEM/NonUniform/src/sofa/component/solidmechanics/fem/nonuniform/NonUniformHexahedralFEMForceFieldAndMass.inl index ea63fcf6c52..ac9b2e4e4e3 100644 --- a/Sofa/Component/SolidMechanics/FEM/NonUniform/src/sofa/component/solidmechanics/fem/nonuniform/NonUniformHexahedralFEMForceFieldAndMass.inl +++ b/Sofa/Component/SolidMechanics/FEM/NonUniform/src/sofa/component/solidmechanics/fem/nonuniform/NonUniformHexahedralFEMForceFieldAndMass.inl @@ -91,7 +91,7 @@ void NonUniformHexahedralFEMForceFieldAndMass::reinit() return; } - const VecCoord& X0=this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& X0=this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); type::Vec<8,Coord> nodesCoarse; for(int w=0; w<8; ++w) nodesCoarse[w] = (X0)[this->l_topology->getHexahedron(0)[w]]; @@ -428,7 +428,7 @@ template void NonUniformHexahedralFEMForceFieldAndMass::initLarge( const int i) { - const VecCoord& X0=this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& X0=this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); type::Vec<8,Coord> nodes; for(int w=0; w<8; ++w) @@ -463,7 +463,7 @@ template void NonUniformHexahedralFEMForceFieldAndMass::initPolar( const int i) { - const VecCoord& X0=this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& X0=this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); type::Vec<8,Coord> nodes; for(int j=0; j<8; ++j) diff --git a/Sofa/Component/SolidMechanics/FEM/NonUniform/src/sofa/component/solidmechanics/fem/nonuniform/NonUniformHexahedronFEMForceFieldAndMass.inl b/Sofa/Component/SolidMechanics/FEM/NonUniform/src/sofa/component/solidmechanics/fem/nonuniform/NonUniformHexahedronFEMForceFieldAndMass.inl index bbd77b34732..16bb1be8da9 100644 --- a/Sofa/Component/SolidMechanics/FEM/NonUniform/src/sofa/component/solidmechanics/fem/nonuniform/NonUniformHexahedronFEMForceFieldAndMass.inl +++ b/Sofa/Component/SolidMechanics/FEM/NonUniform/src/sofa/component/solidmechanics/fem/nonuniform/NonUniformHexahedronFEMForceFieldAndMass.inl @@ -67,7 +67,7 @@ void NonUniformHexahedronFEMForceFieldAndMass::init() if (this->d_initialPoints.getValue().size() == 0) { - const VecCoord& p = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& p = this->mstate->read(core::vec_id::read_access::position)->getValue(); this->d_initialPoints.setValue(p); } diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/AngularSpringForceField.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/AngularSpringForceField.inl index 6b6879c0fd2..44250d1a445 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/AngularSpringForceField.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/AngularSpringForceField.inl @@ -213,7 +213,7 @@ void AngularSpringForceField::draw(const core::visual::VisualParams* const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); vparams->drawTool()->setLightingEnabled(false); - sofa::helper::ReadAccessor< DataVecCoord > p = this->mstate->read(core::VecCoordId::position()); + sofa::helper::ReadAccessor< DataVecCoord > p = this->mstate->read(core::vec_id::write_access::position); sofa::type::vector< type::Vec3 > vertices; for (sofa::Index i=0; i < d_indices.getValue().size(); i++) diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FastTriangularBendingSprings.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FastTriangularBendingSprings.inl index 5532d529d59..5ccd4f0d392 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FastTriangularBendingSprings.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FastTriangularBendingSprings.inl @@ -473,7 +473,7 @@ void FastTriangularBendingSprings::draw(const core::visual::VisualPar const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); vparams->drawTool()->disableLighting(); diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FrameSpringForceField.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FrameSpringForceField.inl index 0907c65f3fc..8b9e2678e75 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FrameSpringForceField.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FrameSpringForceField.inl @@ -183,8 +183,8 @@ template void FrameSpringForceField::draw(const core::visual::VisualParams* vparams) { if ( ! ( ( this->mstate1 == this->mstate2 ) ?vparams->displayFlags().getShowForceFields() :vparams->displayFlags().getShowInteractionForceFields() ) ) return; - const VecCoord& p1 =this->mstate1->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& p2 =this->mstate2->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& p1 =this->mstate1->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& p2 =this->mstate2->read(core::vec_id::read_access::position)->getValue(); const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); vparams->drawTool()->disableLighting(); diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/GearSpringForceField.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/GearSpringForceField.inl index d48737db38e..86d8bbced6c 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/GearSpringForceField.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/GearSpringForceField.inl @@ -120,8 +120,8 @@ void GearSpringForceField::init() template void GearSpringForceField::reinit() { - const VecCoord& x1=this->mstate1->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& x2=this->mstate2->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x1=this->mstate1->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& x2=this->mstate2->read(core::vec_id::read_access::position)->getValue(); sofa::type::vector &springsVector=*(d_springs.beginEdit()); for (unsigned int i=0; i < d_springs.getValue().size(); ++i) { @@ -333,8 +333,8 @@ void GearSpringForceField::draw(const core::visual::VisualParams* vpa const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); - const VecCoord& p1 =this->mstate1->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& p2 =this->mstate2->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& p1 =this->mstate1->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& p2 =this->mstate2->read(core::vec_id::read_access::position)->getValue(); vparams->drawTool()->disableLighting(); constexpr const sofa::type::RGBAColor& color = sofa::type::RGBAColor::yellow(); diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/JointSpringForceField.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/JointSpringForceField.inl index 1b6992c2fd6..b3d745d79fc 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/JointSpringForceField.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/JointSpringForceField.inl @@ -103,9 +103,9 @@ template void JointSpringForceField::bwdInit() { - const VecCoord& x1= this->mstate1->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x1= this->mstate1->read(core::vec_id::read_access::position)->getValue(); - const VecCoord& x2= this->mstate2->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x2= this->mstate2->read(core::vec_id::read_access::position)->getValue(); type::vector &springsVector=*(d_springs.beginEdit()); for (sofa::Index i=0; i void JointSpringForceField::draw(const core::visual::VisualParams* vparams) { if (!((this->mstate1 == this->mstate2)?vparams->displayFlags().getShowForceFields():vparams->displayFlags().getShowInteractionForceFields())) return; - const VecCoord& p1 = this->mstate1->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& p2 = this->mstate2->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& p1 = this->mstate1->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& p2 = this->mstate2->read(core::vec_id::read_access::position)->getValue(); const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); vparams->drawTool()->setLightingEnabled(true); @@ -470,8 +470,8 @@ void JointSpringForceField::computeBBox(const core::ExecParams* para Real maxBBox[3] = { min_real,min_real,min_real }; Real minBBox[3] = { max_real,max_real,max_real }; - const VecCoord& p1 = this->mstate1->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& p2 = this->mstate2->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& p1 = this->mstate1->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& p2 = this->mstate2->read(core::vec_id::read_access::position)->getValue(); const type::vector& springs = d_springs.getValue(); @@ -515,8 +515,8 @@ void JointSpringForceField::addSpring(sofa::Index m1, sofa::Index m2, { Spring s(m1,m2,softKst,hardKst,softKsr,hardKsr, blocKsr, axmin, axmax, aymin, aymax, azmin, azmax, kd); - const VecCoord& x1= this->mstate1->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& x2= this->mstate2->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x1= this->mstate1->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& x2= this->mstate2->read(core::vec_id::read_access::position)->getValue(); s.initTrans = x2[m2].getCenter() - x1[m1].getCenter(); s.initRot = x2[m2].getOrientation()*x1[m1].getOrientation().inverse(); diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/MeshSpringForceField.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/MeshSpringForceField.inl index b36565e01c9..fc872ab8089 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/MeshSpringForceField.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/MeshSpringForceField.inl @@ -88,7 +88,7 @@ void MeshSpringForceField::addSpring(std::set0) return; sset.insert(std::make_pair(m2,m1)); } - const Real l = ((mstate2->read(core::ConstVecCoordId::restPosition())->getValue())[m2] - (mstate1->read(core::ConstVecCoordId::restPosition())->getValue())[m1]).norm(); + const Real l = ((mstate2->read(core::vec_id::read_access::restPosition)->getValue())[m2] - (mstate1->read(core::vec_id::read_access::restPosition)->getValue())[m1]).norm(); if (l > std::numeric_limits::epsilon()) { sofa::helper::getWriteAccessor(d_springs)->emplace_back(m1, m2, stiffness / l, damping / l, l, d_noCompression.getValue()); @@ -223,8 +223,8 @@ void MeshSpringForceField::draw(const core::visual::VisualParams* vpa typedef typename Inherit1::Spring Spring; const sofa::type::vector &ss = d_springs.getValue(); - const VecCoord& p1 = mstate1->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& p2 = mstate2->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& p1 = mstate1->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& p2 = mstate2->read(core::vec_id::read_access::position)->getValue(); Real minElongation = std::numeric_limits::max(); Real maxElongation = 0.; diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialRestShapeSpringsForceField.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialRestShapeSpringsForceField.inl index 1cabdaea4b2..a4677d14f7d 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialRestShapeSpringsForceField.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialRestShapeSpringsForceField.inl @@ -210,14 +210,14 @@ const typename PolynomialRestShapeSpringsForceField::DataVecCoord* Po { if (d_restMState) { - return d_restMState->read(core::VecCoordId::position()); + return d_restMState->read(core::vec_id::write_access::position); } } else { if (this->mstate) { - return this->mstate->read(core::VecCoordId::restPosition()); + return this->mstate->read(core::vec_id::write_access::restPosition); } } return nullptr; @@ -412,7 +412,7 @@ void PolynomialRestShapeSpringsForceField::draw(const core::visual::V } helper::ReadAccessor< DataVecCoord > p0 = *extPosition; - helper::ReadAccessor< DataVecCoord > p = this->mstate->read(core::VecCoordId::position()); + helper::ReadAccessor< DataVecCoord > p = this->mstate->read(core::vec_id::write_access::position); const VecIndex& indices = m_indices; const VecIndex& ext_indices = (m_useRestMState ? m_ext_indices : m_indices); diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialSpringsForceField.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialSpringsForceField.inl index 0e4031c1dce..c7c49613af1 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialSpringsForceField.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialSpringsForceField.inl @@ -339,8 +339,8 @@ void PolynomialSpringsForceField::draw(const core::visual::VisualPara const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); - const VecCoord& p1 =this->mstate1->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& p2 =this->mstate2->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& p1 =this->mstate1->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& p2 =this->mstate2->read(core::vec_id::read_access::position)->getValue(); const VecIndex& firstObjectIndices = d_firstObjectPoints.getValue(); const VecIndex& secondObjectIndices = d_secondObjectPoints.getValue(); diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/QuadBendingSprings.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/QuadBendingSprings.inl index 58681013c2c..17496c167b8 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/QuadBendingSprings.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/QuadBendingSprings.inl @@ -58,7 +58,7 @@ void QuadBendingSprings::addSpring( unsigned a, unsigned b, std::set< const IndexPair ab(amstate1->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x =this->mstate1->read(core::vec_id::read_access::position)->getValue(); Real s = (Real)this->d_ks.getValue()[0]; Real d = (Real)this->d_kd.getValue()[0]; Real l = (x[a]-x[b]).norm(); diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/QuadularBendingSprings.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/QuadularBendingSprings.inl index 2f67a89af23..f15d473cb32 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/QuadularBendingSprings.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/QuadularBendingSprings.inl @@ -60,7 +60,7 @@ void QuadularBendingSprings::applyQuadCreation(const sofa::type::vect SReal m_ks=getKs(); SReal m_kd=getKd(); - const typename DataTypes::VecCoord& restPosition=this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const typename DataTypes::VecCoord& restPosition=this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); helper::WriteOnlyAccessor< Data< type::vector > > edgeData = edgeInfo; @@ -143,7 +143,7 @@ void QuadularBendingSprings::applyQuadDestruction(const sofa::type::v SReal m_ks=getKs(); SReal m_kd=getKd(); - const typename DataTypes::VecCoord& restPosition= this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const typename DataTypes::VecCoord& restPosition= this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); helper::WriteOnlyAccessor< Data< type::vector > > edgeData = edgeInfo; for (unsigned int i=0; i::draw(const core::visual::VisualParams* v if (vparams->displayFlags().getShowWireFrame()) vparams->drawTool()->setPolygonMode(0, true); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); vparams->drawTool()->disableLighting(); diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/RegularGridSpringForceField.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/RegularGridSpringForceField.inl index a38c03a8bde..c9e7d31d26e 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/RegularGridSpringForceField.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/RegularGridSpringForceField.inl @@ -445,8 +445,8 @@ void RegularGridSpringForceField::draw(const core::visual::VisualPara // Draw any custom springs this->SpringForceField::draw(vparams); // Compute topological springs - const VecCoord& p1 =this->mstate1->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& p2 =this->mstate2->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& p1 =this->mstate1->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& p2 =this->mstate2->read(core::vec_id::read_access::position)->getValue(); std::vector< Vec3 > points; Vec3 point1,point2; diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/RestShapeSpringsForceField.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/RestShapeSpringsForceField.inl index 557ee0b39d7..8f34f71e51d 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/RestShapeSpringsForceField.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/RestShapeSpringsForceField.inl @@ -316,14 +316,14 @@ const typename RestShapeSpringsForceField::DataVecCoord* RestShapeSpr { if (l_restMState) { - return l_restMState->read(VecCoordId::position()); + return l_restMState->read(core::vec_id::write_access::position); } } else { if (this->mstate) { - return this->mstate->read(VecCoordId::restPosition()); + return this->mstate->read(core::vec_id::write_access::restPosition); } } return nullptr; @@ -513,7 +513,7 @@ void RestShapeSpringsForceField::draw(const VisualParams *vparams) } ReadAccessor< DataVecCoord > p0 = *extPosition; - ReadAccessor< DataVecCoord > p = this->mstate->read(VecCoordId::position()); + ReadAccessor< DataVecCoord > p = this->mstate->read(sofa::core::vec_id::write_access::position); const VecIndex& indices = m_indices; const VecIndex& ext_indices = (useRestMState ? m_ext_indices : m_indices); diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/SpringForceField.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/SpringForceField.inl index 3d188ddb981..7f4b01a67cc 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/SpringForceField.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/SpringForceField.inl @@ -808,8 +808,8 @@ void SpringForceField::draw(const core::visual::VisualParams* vparams using namespace sofa::type; if (!((this->mstate1 == this->mstate2) ? vparams->displayFlags().getShowForceFields() : vparams->displayFlags().getShowInteractionForceFields())) return; - const VecCoord& p1 = this->mstate1->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& p2 = this->mstate2->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& p1 = this->mstate1->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& p2 = this->mstate2->read(core::vec_id::read_access::position)->getValue(); const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); @@ -915,8 +915,8 @@ void SpringForceField::computeBBox(const core::ExecParams* params, bo return; } - const VecCoord& p1 = this->mstate1->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& p2 = this->mstate2->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& p1 = this->mstate1->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& p2 = this->mstate2->read(core::vec_id::read_access::position)->getValue(); constexpr Real max_real = std::numeric_limits::max(); constexpr Real min_real = std::numeric_limits::lowest(); diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangleBendingSprings.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangleBendingSprings.inl index b934632f885..d14e449ee18 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangleBendingSprings.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangleBendingSprings.inl @@ -45,7 +45,7 @@ TriangleBendingSprings::~TriangleBendingSprings() template void TriangleBendingSprings::addSpring( unsigned a, unsigned b ) { - const VecCoord& x =this->mstate1->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x =this->mstate1->read(core::vec_id::read_access::position)->getValue(); Real s = (Real)this->d_ks.getValue()[0]; Real d = (Real)this->d_kd.getValue()[0]; Real l = (x[a]-x[b]).norm(); diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBendingSprings.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBendingSprings.inl index 914f36426fe..c1433fd080e 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBendingSprings.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBendingSprings.inl @@ -58,7 +58,7 @@ void TriangularBendingSprings::applyTriangleCreation(const sofa::type Real m_ks=getKs(); Real m_kd=getKd(); - const typename DataTypes::VecCoord& restPosition = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const typename DataTypes::VecCoord& restPosition = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); sofa::helper::WriteOnlyAccessor< core::objectmodel::Data< type::vector > > edgeData = d_edgeInfo; for (unsigned int i=0; i::applyTriangleDestruction(const sofa::t Real m_ks=getKs(); Real m_kd=getKd(); - const typename DataTypes::VecCoord& restPosition = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const typename DataTypes::VecCoord& restPosition = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); sofa::helper::WriteOnlyAccessor< core::objectmodel::Data< type::vector > > edgeData = d_edgeInfo; for (unsigned int i=0; i::draw(const core::visual::VisualParams* vparams->drawTool()->setPolygonMode(0, true); } - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); std::vector vertices; std::vector colors; diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBiquadraticSpringsForceField.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBiquadraticSpringsForceField.inl index ee84f3f88a5..13ae5ad30d9 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBiquadraticSpringsForceField.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBiquadraticSpringsForceField.inl @@ -47,7 +47,7 @@ void TriangularBiquadraticSpringsForceField::applyTriangleCreation(In typename DataTypes::Real area,restSquareLength[3],cotangent[3]; typename DataTypes::Real lambda=getLambda(); typename DataTypes::Real mu=getMu(); - const typename DataTypes::VecCoord restPosition=this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const typename DataTypes::VecCoord restPosition=this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); helper::WriteOnlyAccessor< Data< type::vector > > edgeInf = d_edgeInfo; ///describe the indices of the 3 triangle vertices @@ -115,7 +115,7 @@ void TriangularBiquadraticSpringsForceField::applyEdgeCreation(Index { // store the rest length of the edge created - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); const auto& e = this->m_topology->getEdge(edgeIndex); const auto& n0 = DataTypes::getCPos(x[e[0]]); @@ -195,7 +195,7 @@ template void TriangularBiquadraticSpringsForceFieldmstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& p = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); d_initialPoints.setValue(p); } unsigned int i; @@ -556,7 +556,7 @@ void TriangularBiquadraticSpringsForceField::draw(const core::visual: if (vparams->displayFlags().getShowWireFrame()) vparams->drawTool()->setPolygonMode(0, true); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); const size_t nbTriangles=m_topology->getNbTriangles(); std::vector vertices; diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularQuadraticSpringsForceField.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularQuadraticSpringsForceField.inl index b7451d9cd2d..1e2c3113357 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularQuadraticSpringsForceField.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularQuadraticSpringsForceField.inl @@ -34,7 +34,7 @@ template< class DataTypes> void TriangularQuadraticSpringsForceField::applyEdgeCreation(Index edgeIndex, EdgeRestInformation &ei, const core::topology::Edge &, const sofa::type::vector &, const sofa::type::vector &) { // store the rest length of the edge created - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); const auto& e = this->m_topology->getEdge(edgeIndex); const auto& n0 = DataTypes::getCPos(x[e[0]]); @@ -178,7 +178,7 @@ template void TriangularQuadraticSpringsForceField: if (d_initialPoints.getValue().size() == 0) { // get restPosition - const VecCoord& p = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& p = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); d_initialPoints.setValue(p); } unsigned int i; @@ -303,7 +303,7 @@ void TriangularQuadraticSpringsForceField::addDForce(const core::Mech type::vector::EdgeRestInformation>& edgeInf = *(d_edgeInfo.beginEdit()); assert(this->mstate); - const VecDeriv& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecDeriv& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); Deriv deltax,res; @@ -435,7 +435,7 @@ void TriangularQuadraticSpringsForceField::draw(const core::visual::V if (vparams->displayFlags().getShowWireFrame()) vparams->drawTool()->setPolygonMode(0, true); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); const size_t nbTriangles=m_topology->getNbTriangles(); std::vector vertices; std::vector colors; diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/VectorSpringForceField.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/VectorSpringForceField.inl index 83dced16b03..be2238b13e6 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/VectorSpringForceField.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/VectorSpringForceField.inl @@ -36,7 +36,7 @@ void VectorSpringForceField::createEdgeInformation(Index, Spring &t, const sofa::type::vector & ancestors, const sofa::type::vector & coefs) { - const typename DataTypes::VecCoord& x0 = this->getObject1()->read(core::ConstVecCoordId::restPosition())->getValue(); + const typename DataTypes::VecCoord& x0 = this->getObject1()->read(core::vec_id::read_access::restPosition)->getValue(); t.restVector = x0[e[1]] - x0[e[0]]; if (ancestors.size()>0) { @@ -232,7 +232,7 @@ void VectorSpringForceField::createDefaultSprings() type::vector& springArrayData = *(d_springArray.beginEdit()); springArrayData.resize(m_topology->getNbEdges()); - const VecCoord& x0 = this->mstate1->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& x0 = this->mstate1->read(core::vec_id::read_access::restPosition)->getValue(); unsigned int i; for (i=0; igetNbEdges(); ++i) { @@ -368,9 +368,9 @@ void VectorSpringForceField::draw(const core::visual::VisualParams* v if (!((this->mstate1 == this->mstate2)?vparams->displayFlags().getShowForceFields():vparams->displayFlags().getShowInteractionForceFields())) return; - //const VecCoord& p = this->mstate->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& x1 =this->mstate1->read(core::ConstVecCoordId::position())->getValue(); - const VecCoord& x2 =this->mstate2->read(core::ConstVecCoordId::position())->getValue(); + //const VecCoord& p = this->mstate->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& x1 =this->mstate1->read(core::vec_id::read_access::position)->getValue(); + const VecCoord& x2 =this->mstate2->read(core::vec_id::read_access::position)->getValue(); std::vector< Vec3 > points; diff --git a/Sofa/Component/SolidMechanics/Spring/tests/SpringForceField_test.cpp b/Sofa/Component/SolidMechanics/Spring/tests/SpringForceField_test.cpp index 9a557f49a77..797bafce838 100644 --- a/Sofa/Component/SolidMechanics/Spring/tests/SpringForceField_test.cpp +++ b/Sofa/Component/SolidMechanics/Spring/tests/SpringForceField_test.cpp @@ -179,7 +179,7 @@ struct SpringForceField_test : public ForceField_test<_SpringForceField> sofa::simulation::node::initRoot(this->node.get()); core::MechanicalParams mparams; mparams.setKFactor(1.0); - MechanicalComputeForceVisitor computeForce( &mparams, core::VecDerivId::force() ); + MechanicalComputeForceVisitor computeForce( &mparams, core::vec_id::write_access::force ); this->node->execute(computeForce); // check force diff --git a/Sofa/Component/SolidMechanics/TensorMass/src/sofa/component/solidmechanics/tensormass/TetrahedralTensorMassForceField.inl b/Sofa/Component/SolidMechanics/TensorMass/src/sofa/component/solidmechanics/tensormass/TetrahedralTensorMassForceField.inl index 114f51f905b..e3bec0e9b24 100644 --- a/Sofa/Component/SolidMechanics/TensorMass/src/sofa/component/solidmechanics/tensormass/TetrahedralTensorMassForceField.inl +++ b/Sofa/Component/SolidMechanics/TensorMass/src/sofa/component/solidmechanics/tensormass/TetrahedralTensorMassForceField.inl @@ -71,7 +71,7 @@ void TetrahedralTensorMassForceField::applyTetrahedronCreation(const typename DataTypes::Real lambdastar, mustar; typename DataTypes::Coord point[4],shapeVector[4]; - const auto& restPosition=this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const auto& restPosition=this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); edgeRestInfoVector& edgeData = *(d_edgeInfo.beginEdit()); const auto& tetraArray = m_topology->getTetrahedra(); @@ -153,7 +153,7 @@ void TetrahedralTensorMassForceField::applyTetrahedronDestruction(con typename DataTypes::Real lambdastar, mustar; typename DataTypes::Coord point[4],shapeVector[4]; - const typename DataTypes::VecCoord restPosition=this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const typename DataTypes::VecCoord restPosition=this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); edgeRestInfoVector& edgeData = *(d_edgeInfo.beginEdit()); @@ -287,7 +287,7 @@ TetrahedralTensorMassForceField::init() if (_initialPoints.size() == 0) { // get restPosition - const VecCoord& p = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& p = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); _initialPoints=p; } @@ -346,7 +346,7 @@ SReal TetrahedralTensorMassForceField::getPotentialEnergy(const core { SCOPED_TIMER("getPotentialEnergy"); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); SReal energy=0; @@ -507,7 +507,7 @@ void TetrahedralTensorMassForceField::draw(const core::visual::Visual constexpr sofa::type::RGBAColor color = sofa::type::RGBAColor::green(); std::vector vertices; - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); const int nbTriangles=m_topology->getNbTriangles(); for(int i=0;i::applyTriangleCreation(const sofa typename DataTypes::Coord point[3],dpk,dpl; helper::WriteOnlyAccessor< Data< type::vector > > edgeData = d_edgeInfo; - const typename DataTypes::VecCoord& restPosition= this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const typename DataTypes::VecCoord& restPosition= this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); for (i=0; i::applyTriangleDestruction(const s typename DataTypes::Coord point[3],dpk,dpl; helper::WriteOnlyAccessor< Data< type::vector > > edgeData = d_edgeInfo; - const typename DataTypes::VecCoord& restPosition= this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const typename DataTypes::VecCoord& restPosition= this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); for (i=0; i void TriangularTensorMassForceField::init( if (_initialPoints.size() == 0) { // get restPosition - const VecCoord& p = this->mstate->read(core::ConstVecCoordId::restPosition())->getValue(); + const VecCoord& p = this->mstate->read(core::vec_id::read_access::restPosition)->getValue(); _initialPoints=p; } @@ -414,7 +414,7 @@ void TriangularTensorMassForceField::draw(const core::visual::VisualP if (vparams->displayFlags().getShowWireFrame()) vparams->drawTool()->setPolygonMode(0, true); - const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); const size_t nbTriangles=m_topology->getNbTriangles(); std::vector vertices; diff --git a/Sofa/Component/SolidMechanics/Testing/src/sofa/component/solidmechanics/testing/ForceFieldTestCreation.h b/Sofa/Component/SolidMechanics/Testing/src/sofa/component/solidmechanics/testing/ForceFieldTestCreation.h index afd471b510b..62211304cef 100644 --- a/Sofa/Component/SolidMechanics/Testing/src/sofa/component/solidmechanics/testing/ForceFieldTestCreation.h +++ b/Sofa/Component/SolidMechanics/Testing/src/sofa/component/solidmechanics/testing/ForceFieldTestCreation.h @@ -182,9 +182,9 @@ struct ForceField_test : public BaseSimulationTest, NumericTestexecute(resetForce); - MechanicalComputeForceVisitor computeForce( &mparams, core::VecDerivId::force() ); + MechanicalComputeForceVisitor computeForce( &mparams, core::vec_id::write_access::force ); this->node->execute(computeForce); // check force @@ -253,10 +253,10 @@ struct ForceField_test : public BaseSimulationTest, NumericTestexecute(resetForce); - dof->vRealloc( &mparams, core::VecDerivId::dx()); // dx is not allocated by default + dof->vRealloc( &mparams, core::vec_id::write_access::dx); // dx is not allocated by default typename DOF::WriteVecDeriv wdx = dof->writeDx(); sofa::testing::copyToData ( wdx, dX ); - MechanicalComputeDfVisitor computeDf( &mparams, core::VecDerivId::force() ); + MechanicalComputeDfVisitor computeDf( &mparams, core::vec_id::write_access::force ); node->execute(computeDf); VecDeriv dF; sofa::testing::copyFromData( dF, dof->readForces() ); diff --git a/Sofa/Component/SolidMechanics/simutests/AffinePatch_test.cpp b/Sofa/Component/SolidMechanics/simutests/AffinePatch_test.cpp index fb4a9ad7286..270088dbaca 100644 --- a/Sofa/Component/SolidMechanics/simutests/AffinePatch_test.cpp +++ b/Sofa/Component/SolidMechanics/simutests/AffinePatch_test.cpp @@ -208,7 +208,7 @@ struct AffinePatch_sofa_test : public sofa::testing::BaseSimulationTest, sofa::t // Compute the theoretical final positions VecCoord finalPos; - patchStruct.affineConstraint->getFinalPositions( finalPos,*patchStruct.dofs->write(core::VecCoordId::position()) ); + patchStruct.affineConstraint->getFinalPositions( finalPos,*patchStruct.dofs->write(core::vec_id::write_access::position) ); // Initialize diff --git a/Sofa/Component/SolidMechanics/simutests/LinearElasticity_test.cpp b/Sofa/Component/SolidMechanics/simutests/LinearElasticity_test.cpp index cfe9e1d3e23..6202204e7e1 100644 --- a/Sofa/Component/SolidMechanics/simutests/LinearElasticity_test.cpp +++ b/Sofa/Component/SolidMechanics/simutests/LinearElasticity_test.cpp @@ -248,13 +248,13 @@ struct LinearElasticity_test : public sofa::testing::BaseSimulationTest, sofa::t sofa::simulation::node::reset(tractionStruct.root.get()); // record the initial point of a given vertex - Coord p0=tractionStruct.dofs.get()->read(sofa::core::ConstVecCoordId::position())->getValue()[vIndex]; + Coord p0=tractionStruct.dofs.get()->read(sofa::core::vec_id::read_access::position)->getValue()[vIndex]; // do one step of the static solver sofa::simulation::node::animate(tractionStruct.root.get(), 0.5_sreal); // Get the simulated final position of that vertex - Coord p1=tractionStruct.dofs.get()->read(sofa::core::ConstVecCoordId::position())->getValue()[vIndex]; + Coord p1=tractionStruct.dofs.get()->read(sofa::core::vec_id::read_access::position)->getValue()[vIndex]; // test the young modulus Real longitudinalDeformation=(p1[2]-p0[2])/p0[2]; if (fabs(longitudinalDeformation-pressure/youngModulus)>1e-4) { diff --git a/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MappedObject.h b/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MappedObject.h index 6993dbf0f23..1d96f21d115 100644 --- a/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MappedObject.h +++ b/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MappedObject.h @@ -88,7 +88,7 @@ class MappedObject : public core::State Data< VecCoord >* write(core::VecCoordId v) override { - if(v == core::VecCoordId::position()) + if(v == core::vec_id::write_access::position) return &d_X; return nullptr; @@ -96,7 +96,7 @@ class MappedObject : public core::State const Data< VecCoord >* read(core::ConstVecCoordId v) const override { - if(v == core::ConstVecCoordId::position()) + if(v == core::vec_id::read_access::position) return &d_X; else return nullptr; @@ -104,7 +104,7 @@ class MappedObject : public core::State Data< VecDeriv >* write(core::VecDerivId v) override { - if(v == core::VecDerivId::velocity()) + if(v == core::vec_id::write_access::velocity) return &d_V; else return nullptr; @@ -112,7 +112,7 @@ class MappedObject : public core::State const Data< VecDeriv >* read(core::ConstVecDerivId v) const override { - if(v == core::ConstVecDerivId::velocity()) + if(v == core::vec_id::read_access::velocity) return &d_V; else return nullptr; diff --git a/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.cpp b/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.cpp index 8de57022975..d877d9f975b 100644 --- a/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.cpp +++ b/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.cpp @@ -55,7 +55,7 @@ void registerMechanicalObject(sofa::core::ObjectFactory* factory) template<> void MechanicalObject::applyRotation (const type::Quat q) { - helper::WriteAccessor< Data > x = *this->write(core::VecCoordId::position()); + helper::WriteAccessor< Data > x = *this->write(core::vec_id::write_access::position); for (RigidCoord<3, SReal>& xi : x) { @@ -199,7 +199,7 @@ void MechanicalObject::draw(const core::visual::Visual if (showObject.getValue()) { const float scale = showObjectScale.getValue(); - const helper::ReadAccessor > x = *this->read(core::VecCoordId::position()); + const helper::ReadAccessor > x = *this->read(core::vec_id::write_access::position); const size_t vsize = d_size.getValue(); for (size_t i = 0; i < vsize; ++i) { diff --git a/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.h b/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.h index e1327eaee63..3c90f0dd40b 100644 --- a/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.h +++ b/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.h @@ -150,13 +150,13 @@ class MechanicalObject : public sofa::core::behavior::MechanicalState Size getSize() const override { return d_size.getValue(); } - SReal getPX(sofa::Index i) const override { Real x=0.0,y=0.0,z=0.0; DataTypes::get(x,y,z,(read(core::ConstVecCoordId::position())->getValue())[i]); return (SReal)x; } - SReal getPY(sofa::Index i) const override { Real x=0.0,y=0.0,z=0.0; DataTypes::get(x,y,z,(read(core::ConstVecCoordId::position())->getValue())[i]); return (SReal)y; } - SReal getPZ(sofa::Index i) const override { Real x=0.0,y=0.0,z=0.0; DataTypes::get(x,y,z,(read(core::ConstVecCoordId::position())->getValue())[i]); return (SReal)z; } + SReal getPX(sofa::Index i) const override { Real x=0.0,y=0.0,z=0.0; DataTypes::get(x,y,z,(read(core::vec_id::read_access::position)->getValue())[i]); return (SReal)x; } + SReal getPY(sofa::Index i) const override { Real x=0.0,y=0.0,z=0.0; DataTypes::get(x,y,z,(read(core::vec_id::read_access::position)->getValue())[i]); return (SReal)y; } + SReal getPZ(sofa::Index i) const override { Real x=0.0,y=0.0,z=0.0; DataTypes::get(x,y,z,(read(core::vec_id::read_access::position)->getValue())[i]); return (SReal)z; } - SReal getVX(sofa::Index i) const { Real x=0.0,y=0.0,z=0.0; DataTypes::get(x,y,z, read(core::ConstVecDerivId::velocity())->getValue()[i]); return (SReal)x; } - SReal getVY(sofa::Index i) const { Real x=0.0,y=0.0,z=0.0; DataTypes::get(x,y,z, read(core::ConstVecDerivId::velocity())->getValue()[i]); return (SReal)y; } - SReal getVZ(sofa::Index i) const { Real x=0.0,y=0.0,z=0.0; DataTypes::get(x,y,z, read(core::ConstVecDerivId::velocity())->getValue()[i]); return (SReal)z; } + SReal getVX(sofa::Index i) const { Real x=0.0,y=0.0,z=0.0; DataTypes::get(x,y,z, read(core::vec_id::read_access::velocity)->getValue()[i]); return (SReal)x; } + SReal getVY(sofa::Index i) const { Real x=0.0,y=0.0,z=0.0; DataTypes::get(x,y,z, read(core::vec_id::read_access::velocity)->getValue()[i]); return (SReal)y; } + SReal getVZ(sofa::Index i) const { Real x=0.0,y=0.0,z=0.0; DataTypes::get(x,y,z, read(core::vec_id::read_access::velocity)->getValue()[i]); return (SReal)z; } /** \brief Overwrite values at index outputIndex by the ones at inputIndex. @@ -263,7 +263,7 @@ class MechanicalObject : public sofa::core::behavior::MechanicalState void endIntegration(const core::ExecParams* params, SReal dt) override; - void accumulateForce(const core::ExecParams* params, core::VecDerivId f = core::VecDerivId::force()) override; // see BaseMechanicalState::accumulateForce(const ExecParams*, VecId) override + void accumulateForce(const core::ExecParams* params, core::VecDerivId f = core::vec_id::write_access::force) override; // see BaseMechanicalState::accumulateForce(const ExecParams*, VecId) override /// Increment the index of the given VecCoordId, so that all 'allocated' vectors in this state have a lower index void vAvail(const core::ExecParams* params, core::VecCoordId& v) override; @@ -315,9 +315,9 @@ class MechanicalObject : public sofa::core::behavior::MechanicalState Size vSize( const core::ExecParams* params, core::ConstVecId v ) override; - void resetForce(const core::ExecParams* params, core::VecDerivId f = core::VecDerivId::force()) override; + void resetForce(const core::ExecParams* params, core::VecDerivId f = core::vec_id::write_access::force) override; - void resetAcc(const core::ExecParams* params, core::VecDerivId a = core::VecDerivId::dx()) override; + void resetAcc(const core::ExecParams* params, core::VecDerivId a = core::vec_id::write_access::dx) override; void resetConstraint(const core::ConstraintParams* cparams) override; diff --git a/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.inl b/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.inl index c31a21c7c1e..919a37297e2 100644 --- a/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.inl +++ b/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.inl @@ -190,18 +190,18 @@ MechanicalObject::MechanicalObject() rotation2 .setGroup("Transformation"); scale .setGroup("Transformation"); - setVecCoord(core::VecCoordId::position(), &x); - setVecCoord(core::VecCoordId::freePosition(), &xfree); - setVecCoord(core::VecCoordId::restPosition(), &x0); - setVecCoord(core::VecCoordId::resetPosition(), &reset_position); - setVecDeriv(core::VecDerivId::velocity(), &v); - setVecDeriv(core::VecDerivId::force(), &f); - setVecDeriv(core::VecDerivId::externalForce(), &externalForces); - setVecDeriv(core::VecDerivId::dx(), &dx); - setVecDeriv(core::VecDerivId::freeVelocity(), &vfree); - setVecDeriv(core::VecDerivId::resetVelocity(), &reset_velocity); - setVecMatrixDeriv(core::MatrixDerivId::constraintJacobian(), &c); - setVecMatrixDeriv(core::MatrixDerivId::mappingJacobian(), &m); + setVecCoord(core::vec_id::write_access::position, &x); + setVecCoord(core::vec_id::write_access::freePosition, &xfree); + setVecCoord(core::vec_id::write_access::restPosition, &x0); + setVecCoord(core::vec_id::write_access::resetPosition, &reset_position); + setVecDeriv(core::vec_id::write_access::velocity, &v); + setVecDeriv(core::vec_id::write_access::force, &f); + setVecDeriv(core::vec_id::write_access::externalForce, &externalForces); + setVecDeriv(core::vec_id::write_access::dx, &dx); + setVecDeriv(core::vec_id::write_access::freeVelocity, &vfree); + setVecDeriv(core::vec_id::write_access::resetVelocity, &reset_velocity); + setVecMatrixDeriv(core::vec_id::write_access::constraintJacobian, &c); + setVecMatrixDeriv(core::vec_id::write_access::mappingJacobian, &m); // These vectors are set as modified as they are mandatory in the MechanicalObject. x .forceSet(); @@ -217,7 +217,7 @@ MechanicalObject::MechanicalObject() // freeVelocity.setDisplayed( false ); // do not forget to delete these in the destructor - // write(VecDerivId::dforce())->forceSet(); + // write(vec_id::write_access::dforce)->forceSet(); // What is exactly the need for allocating null vectors? // if sofa crashes because of a wrong access to the null vector @@ -248,8 +248,8 @@ MechanicalObject::~MechanicalObject() if( vectorsDeriv[i] != nullptr ) { delete vectorsDeriv[i]; vectorsDeriv[i]=nullptr; } if( vectorsDeriv[core::VecDerivId::null().getIndex()] != nullptr ) { delete vectorsDeriv[core::VecDerivId::null().getIndex()]; vectorsDeriv[core::VecDerivId::null().getIndex()] = nullptr; } - if( core::VecDerivId::dforce().getIndex()::exportGnuplot(SReal time) { if( m_gnuplotFileX!=nullptr ) { - (*m_gnuplotFileX) << time <<"\t"<< read(core::ConstVecCoordId::position())->getValue() << std::endl; + (*m_gnuplotFileX) << time <<"\t"<< read(core::vec_id::read_access::position)->getValue() << std::endl; } if( m_gnuplotFileV!=nullptr ) { - (*m_gnuplotFileV) << time <<"\t"<< read(core::ConstVecDerivId::velocity())->getValue() << std::endl; + (*m_gnuplotFileV) << time <<"\t"<< read(core::vec_id::read_access::velocity)->getValue() << std::endl; } } @@ -448,7 +448,7 @@ void MechanicalObject::handleStateChange() if (vecCoord.size() != 0) { - coordVecs.push_back(k); + coordVecs.emplace_back(k); } } } @@ -461,7 +461,7 @@ void MechanicalObject::handleStateChange() if (vecDeriv.size() != 0) { - derivVecs.push_back(k); + derivVecs.emplace_back(k); } } } @@ -673,7 +673,7 @@ void MechanicalObject::reserve(const Size size) template void MechanicalObject::applyTranslation (const SReal dx, const SReal dy, const SReal dz) { - helper::WriteAccessor< Data > x_wA = *this->write(core::VecCoordId::position()); + helper::WriteAccessor< Data > x_wA = *this->write(core::vec_id::write_access::position); for (unsigned int i = 0; i < x_wA.size(); i++) { @@ -693,7 +693,7 @@ void MechanicalObject::applyRotation (const SReal rx, const SReal ry, template void MechanicalObject::applyRotation (const type::Quat q) { - helper::WriteAccessor< Data > x_wA = *this->write(core::VecCoordId::position()); + helper::WriteAccessor< Data > x_wA = *this->write(core::vec_id::write_access::position); for (unsigned int i = 0; i < x_wA.size(); i++) { @@ -1024,13 +1024,13 @@ void MechanicalObject::init() } } - Data* x_wAData = this->write(sofa::core::VecCoordId::position()); - Data* v_wAData = this->write(sofa::core::VecDerivId::velocity()); + Data* x_wAData = this->write(sofa::core::vec_id::write_access::position); + Data* v_wAData = this->write(sofa::core::vec_id::write_access::velocity); VecCoord& x_wA = *x_wAData->beginEdit(); VecDeriv& v_wA = *v_wAData->beginEdit(); //case if X0 has been set but not X - if (read(core::ConstVecCoordId::restPosition())->getValue().size() > x_wA.size()) + if (read(core::vec_id::read_access::restPosition)->getValue().size() > x_wA.size()) { vOp(core::execparams::defaultInstance(), core::VecId::position(), core::VecId::restPosition()); } @@ -1093,7 +1093,7 @@ void MechanicalObject::init() reinit(); // storing X0 must be done after reinit() that possibly applies transformations - if( read(core::ConstVecCoordId::restPosition())->getValue().size()!=x_wA.size() ) + if( read(core::vec_id::read_access::restPosition)->getValue().size()!=x_wA.size() ) { // storing X0 from X if( restScale.getValue()!=1 ) @@ -1137,7 +1137,7 @@ void MechanicalObject::storeResetState() vOp(core::execparams::defaultInstance(), core::VecId::resetPosition(), core::VecId::position()); // we only store a resetVelocity if the velocity is not zero - helper::ReadAccessor< Data > v = *this->read(core::VecDerivId::velocity()); + helper::ReadAccessor< Data > v = *this->read(core::vec_id::write_access::velocity); bool zero = true; for (unsigned int i=0; i::accumulateForce(const core::ExecParams* params { SOFA_UNUSED(params); - helper::ReadAccessor< Data > extForces_rA( *this->read(core::ConstVecDerivId::externalForce()) ); + helper::ReadAccessor< Data > extForces_rA( *this->read(core::vec_id::read_access::externalForce) ); if (!extForces_rA.empty()) { @@ -2305,7 +2305,7 @@ void MechanicalObject::resetConstraint(const core::ConstraintParams* sofa::helper::getWriteOnlyAccessor(c_data)->clear(); //reset the mapping jacobian matrix - Data& m_data = *this->write(core::MatrixDerivId::mappingJacobian()); + Data& m_data = *this->write(core::vec_id::write_access::mappingJacobian); sofa::helper::getWriteOnlyAccessor(m_data)->clear(); } @@ -2488,7 +2488,7 @@ template inline void MechanicalObject::drawVectors(const core::visual::VisualParams* vparams) { float scale = showVectorsScale.getValue(); - sofa::helper::ReadAccessor< Data > v_rA = *this->read(core::ConstVecDerivId::velocity()); + sofa::helper::ReadAccessor< Data > v_rA = *this->read(core::vec_id::read_access::velocity); type::vector points; points.resize(2); for(Size i=0; i::pickParticles(const core::ExecParams* /* param // TODO: this verification is awful and should be done by template specialization { // seems to be valid DOFs - const VecCoord& x =this->read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x =this->read(core::vec_id::read_access::position)->getValue(); type::Vec<3,Real> origin((Real)rayOx, (Real)rayOy, (Real)rayOz); type::Vec<3,Real> direction((Real)rayDx, (Real)rayDy, (Real)rayDz); @@ -2620,7 +2620,7 @@ bool MechanicalObject::addBBox(SReal* minBBox, SReal* maxBBox) static const unsigned spatial_dimensions = std::min( (unsigned)DataTypes::spatial_dimensions, 3u ); - const VecCoord& x = read(core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = read(core::vec_id::read_access::position)->getValue(); for(Size i=0; i p; diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/EdgeSetGeometryAlgorithms.inl b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/EdgeSetGeometryAlgorithms.inl index bce8156f4d9..73a4475a475 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/EdgeSetGeometryAlgorithms.inl +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/EdgeSetGeometryAlgorithms.inl @@ -251,7 +251,7 @@ template< class DataTypes> typename DataTypes::Real EdgeSetGeometryAlgorithms< DataTypes >::computeEdgeLength( const EdgeID i) const { const Edge &e = this->m_topology->getEdge(i); - const VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); const Real length = (DataTypes::getCPos(p[e[0]])-DataTypes::getCPos(p[e[1]])).norm(); return length; } @@ -263,7 +263,7 @@ template< class DataTypes> typename DataTypes::Real EdgeSetGeometryAlgorithms< DataTypes >::computeRestEdgeLength( const EdgeID i) const { const Edge &e = this->m_topology->getEdge(i); - const VecCoord& p = (this->object->read(core::ConstVecCoordId::restPosition())->getValue()); + const VecCoord& p = (this->object->read(core::vec_id::read_access::restPosition)->getValue()); const Real length = (DataTypes::getCPos(p[e[0]])-DataTypes::getCPos(p[e[1]])).norm(); return length; } @@ -272,7 +272,7 @@ template< class DataTypes> typename DataTypes::Real EdgeSetGeometryAlgorithms< DataTypes >::computeRestSquareEdgeLength( const EdgeID i) const { const Edge &e = this->m_topology->getEdge(i); - const VecCoord& p = (this->object->read(core::ConstVecCoordId::restPosition())->getValue()); + const VecCoord& p = (this->object->read(core::vec_id::read_access::restPosition)->getValue()); const Real length = (DataTypes::getCPos(p[e[0]])-DataTypes::getCPos(p[e[1]])).norm2(); return length; } @@ -282,7 +282,7 @@ template void EdgeSetGeometryAlgorithms::computeEdgeLength( BasicArrayInterface &ai) const { const sofa::type::vector &ea = this->m_topology->getEdges(); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); for (Index i=0; i void EdgeSetGeometryAlgorithms::computeEdgeAABB(const EdgeID i, CPos& minCoord, CPos& maxCoord) const { const Edge &e = this->m_topology->getEdge(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); const CPos& a = DataTypes::getCPos(p[e[0]]); const CPos& b = DataTypes::getCPos(p[e[1]]); for (int c=0; c void EdgeSetGeometryAlgorithms::getEdgeVertexCoordinates(const EdgeID i, Coord pnt[2]) const { const Edge &e = this->m_topology->getEdge(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); pnt[0] = p[e[0]]; pnt[1] = p[e[1]]; @@ -317,7 +317,7 @@ template void EdgeSetGeometryAlgorithms::getRestEdgeVertexCoordinates(const EdgeID i, Coord pnt[2]) const { const Edge &e = this->m_topology->getEdge(i); - const typename DataTypes::VecCoord& p = (this->object->read(core::ConstVecCoordId::restPosition())->getValue()); + const typename DataTypes::VecCoord& p = (this->object->read(core::vec_id::read_access::restPosition)->getValue()); pnt[0] = p[e[0]]; pnt[1] = p[e[1]]; @@ -327,7 +327,7 @@ template typename DataTypes::Coord EdgeSetGeometryAlgorithms::computeEdgeCenter(const EdgeID i) const { const Edge &e = this->m_topology->getEdge(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); return (p[e[0]] + p[e[1]]) * (Real) 0.5; } @@ -336,7 +336,7 @@ template typename DataTypes::Coord EdgeSetGeometryAlgorithms::computeEdgeDirection(const EdgeID i) const { const Edge &e = this->m_topology->getEdge(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); return (p[e[1]] - p[e[0]]); } @@ -344,7 +344,7 @@ template typename DataTypes::Coord EdgeSetGeometryAlgorithms::computeRestEdgeDirection(const EdgeID i) const { const Edge &e = this->m_topology->getEdge(i); - const typename DataTypes::VecCoord& p = (this->object->read(core::ConstVecCoordId::restPosition())->getValue()); + const typename DataTypes::VecCoord& p = (this->object->read(core::vec_id::read_access::restPosition)->getValue()); return (p[e[1]] - p[e[0]]); } @@ -368,7 +368,7 @@ auto EdgeSetGeometryAlgorithms::computeEdgeBarycentricCoordinates( const sofa::type::Vec<3, Real> &p, PointID ind_p1, PointID ind_p2, bool useRestPosition) const -> sofa::type::vector< SReal > { - sofa::core::ConstVecCoordId::MyVecId _vecId = useRestPosition ? core::ConstVecCoordId::restPosition() : core::ConstVecCoordId::position(); + sofa::core::ConstVecCoordId::MyVecId _vecId = useRestPosition ? core::vec_id::read_access::restPosition : core::vec_id::read_access::position; const typename DataTypes::VecCoord& vect_c = (this->object->read(_vecId)->getValue()); const typename DataTypes::Coord& c0 = vect_c[ind_p1]; @@ -440,7 +440,7 @@ template bool EdgeSetGeometryAlgorithms::computeEdgePlaneIntersection (EdgeID edgeID, sofa::type::Vec<3,Real> pointOnPlane, sofa::type::Vec<3,Real> normalOfPlane, sofa::type::Vec<3,Real>& intersection) { const Edge &e = this->m_topology->getEdge(edgeID); - const VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); sofa::type::Vec<3,Real> p1,p2; p1[0]=p[e[0]][0]; p1[1]=p[e[0]][1]; p1[2]=p[e[0]][2]; @@ -465,7 +465,7 @@ template bool EdgeSetGeometryAlgorithms::computeRestEdgePlaneIntersection (EdgeID edgeID, sofa::type::Vec<3,Real> pointOnPlane, sofa::type::Vec<3,Real> normalOfPlane, sofa::type::Vec<3,Real>& intersection) { const Edge &e = this->m_topology->getEdge(edgeID); - const VecCoord& p = (this->object->read(core::ConstVecCoordId::restPosition())->getValue()); + const VecCoord& p = (this->object->read(core::vec_id::read_access::restPosition)->getValue()); sofa::type::Vec<3,Real> p1,p2; p1[0]=p[e[0]][0]; p1[1]=p[e[0]][1]; p1[2]=p[e[0]][2]; @@ -509,7 +509,7 @@ template typename DataTypes::Coord EdgeSetGeometryAlgorithms::computeEdgeSegmentIntersection(const EdgeID edgeID, const type::Vec3& a, const type::Vec3& b, bool& intersected) { const Edge& theEdge = this->m_topology->getEdge(edgeID); - const VecCoord& pos = (this->object->read(core::ConstVecCoordId::position())->getValue()); + const VecCoord& pos = (this->object->read(core::vec_id::read_access::position)->getValue()); const typename DataTypes::Coord& e0 = pos[theEdge[0]]; const typename DataTypes::Coord& e1 = pos[theEdge[1]]; @@ -537,7 +537,7 @@ void EdgeSetGeometryAlgorithms::draw(const core::visual::VisualParams // Draw Edges indices if (showEdgeIndices.getValue() && this->m_topology->getNbEdges() != 0) { - const VecCoord& coords =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const VecCoord& coords =(this->object->read(core::vec_id::read_access::position)->getValue()); float scale = this->getIndicesScale(); //for edges: @@ -566,7 +566,7 @@ void EdgeSetGeometryAlgorithms::draw(const core::visual::VisualParams { const sofa::type::vector &edgeArray = this->m_topology->getEdges(); - const VecCoord& coords =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const VecCoord& coords =(this->object->read(core::vec_id::read_access::position)->getValue()); std::vector positions; positions.reserve(edgeArray.size()*2u); @@ -588,7 +588,7 @@ void EdgeSetGeometryAlgorithms::draw(const core::visual::VisualParams template< class DataTypes> void EdgeSetGeometryAlgorithms< DataTypes >::computeLocalFrameEdgeWeights( type::vector& numEdges, type::vector& vertexEdges, type::vector& weights ) const { - const VecCoord& pos =(this->object->read(core::ConstVecCoordId::position())->getValue()); // point positions + const VecCoord& pos =(this->object->read(core::vec_id::read_access::position)->getValue()); // point positions sofa::type::vector > edgeVec; // 3D edges @@ -739,7 +739,7 @@ bool EdgeSetGeometryAlgorithms::computeEdgeSegmentIntersection(EdgeID Real &baryCoef) { const Edge& theEdge = this->m_topology->getEdge(edgeID); - const VecCoord& pos = (this->object->read(core::ConstVecCoordId::position())->getValue()); + const VecCoord& pos = (this->object->read(core::vec_id::read_access::position)->getValue()); const typename DataTypes::Coord& e0 = pos[theEdge[0]]; const typename DataTypes::Coord& e1 = pos[theEdge[1]]; diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/HexahedronSetGeometryAlgorithms.inl b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/HexahedronSetGeometryAlgorithms.inl index 4213579e525..1c0a280aa4c 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/HexahedronSetGeometryAlgorithms.inl +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/HexahedronSetGeometryAlgorithms.inl @@ -378,7 +378,7 @@ template< class DataTypes> void HexahedronSetGeometryAlgorithms< DataTypes >::computeHexahedronAABB(const HexaID h, Coord& minCoord, Coord& maxCoord) const { const Hexahedron &t = this->m_topology->getHexahedron(h); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); for(unsigned int i=0; i<3; ++i) { @@ -394,7 +394,7 @@ template< class DataTypes> void HexahedronSetGeometryAlgorithms< DataTypes >::computeHexahedronRestAABB(const HexaID h, Coord& minCoord, Coord& maxCoord) const { const Hexahedron &t = this->m_topology->getHexahedron(h); - const typename DataTypes::VecCoord& p = (this->object->read(core::ConstVecCoordId::restPosition())->getValue()); + const typename DataTypes::VecCoord& p = (this->object->read(core::vec_id::read_access::restPosition)->getValue()); for(unsigned int i=0; i<3; ++i) { @@ -410,7 +410,7 @@ template typename DataTypes::Coord HexahedronSetGeometryAlgorithms::computeHexahedronCenter(const HexaID h) const { const Hexahedron &t = this->m_topology->getHexahedron(h); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); return (p[t[0]] + p[t[1]] + p[t[2]] + p[t[3]] + p[t[4]] + p[t[5]] + p[t[6]] + p[t[7]]) * (Real) 0.125; } @@ -419,7 +419,7 @@ template typename DataTypes::Coord HexahedronSetGeometryAlgorithms::computeHexahedronRestCenter(const HexaID h) const { const Hexahedron &t = this->m_topology->getHexahedron(h); - const typename DataTypes::VecCoord& p = (this->object->read(core::ConstVecCoordId::restPosition())->getValue()); + const typename DataTypes::VecCoord& p = (this->object->read(core::vec_id::read_access::restPosition)->getValue()); return (p[t[0]] + p[t[1]] + p[t[2]] + p[t[3]] + p[t[4]] + p[t[5]] + p[t[6]] + p[t[7]]) * (Real) 0.125; } @@ -428,7 +428,7 @@ template< class DataTypes> void HexahedronSetGeometryAlgorithms< DataTypes >::getHexahedronVertexCoordinates(const HexaID h, Coord pnt[8]) const { const Hexahedron &t = this->m_topology->getHexahedron(h); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); for(unsigned int i=0; i<8; ++i) { @@ -440,7 +440,7 @@ template< class DataTypes> void HexahedronSetGeometryAlgorithms< DataTypes >::getRestHexahedronVertexCoordinates(const HexaID h, Coord pnt[8]) const { const Hexahedron &t = this->m_topology->getHexahedron(h); - const typename DataTypes::VecCoord& p = (this->object->read(core::ConstVecCoordId::restPosition())->getValue()); + const typename DataTypes::VecCoord& p = (this->object->read(core::vec_id::read_access::restPosition)->getValue()); for(unsigned int i=0; i<8; ++i) { @@ -707,7 +707,7 @@ template< class DataTypes> typename DataTypes::Real HexahedronSetGeometryAlgorithms< DataTypes >::computeHexahedronVolume( const HexaID hexa) const { const Hexahedron &h = this->m_topology->getHexahedron(hexa); - const VecCoord& p = (this->object->read(core::ConstVecCoordId::position())->getValue()); + const VecCoord& p = (this->object->read(core::vec_id::read_access::position)->getValue()); Coord dp[3]; unsigned char i,j,k,ind[3]; Real volume; @@ -740,7 +740,7 @@ template< class DataTypes> typename DataTypes::Real HexahedronSetGeometryAlgorithms< DataTypes >::computeRestHexahedronVolume( const HexaID hexa) const { const Hexahedron &h = this->m_topology->getHexahedron(hexa); - const VecCoord& p = (this->object->read(core::ConstVecCoordId::restPosition())->getValue()); + const VecCoord& p = (this->object->read(core::vec_id::read_access::restPosition)->getValue()); Coord dp[3]; size_t i,j,k,ind[3]; Real volume; @@ -773,7 +773,7 @@ template void HexahedronSetGeometryAlgorithms::computeHexahedronVolume( BasicArrayInterface &ai) const { //const sofa::type::vector &ta=this->m_topology->getHexahedra(); - //const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + //const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); for(sofa::Index i=0; im_topology->getNbHexahedra(); ++i) { //const Hexahedron &t=this->m_topology->getHexahedron(i); //ta[i]; @@ -793,7 +793,7 @@ void HexahedronSetGeometryAlgorithms::draw(const core::visual::Visual // Draw Hexa indices if (d_showHexaIndices.getValue() && this->m_topology->getNbHexahedra() != 0) { - const VecCoord& coords =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const VecCoord& coords =(this->object->read(core::vec_id::read_access::position)->getValue()); float scale = this->getIndicesScale(); //for hexa: @@ -830,7 +830,7 @@ void HexahedronSetGeometryAlgorithms::draw(const core::visual::Visual const sofa::type::vector &hexaArray = this->m_topology->getHexahedra(); - const VecCoord& coords =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const VecCoord& coords =(this->object->read(core::vec_id::read_access::position)->getValue()); sofa::type::vector hexaCoords; for (size_t i = 0; i::getPointSetCent { typename DataTypes::Coord center; // get current positions - const typename DataTypes::VecCoord& p =(object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(object->read(core::vec_id::read_access::position)->getValue()); const int numVertices = this->m_topology->getNbPoints(); for(int i=0; i::getEnclosingSphere(typename DataTyp typename DataTypes::Real &radius) const { // get current positions - const typename DataTypes::VecCoord& p =(object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(object->read(core::vec_id::read_access::position)->getValue()); const unsigned int numVertices = this->m_topology->getNbPoints(); for(unsigned int i=0; i void PointSetGeometryAlgorithms::getAABB(CPos& minCoord, CPos& maxCoord) const { // get current positions - const VecCoord& p =(object->read(core::ConstVecCoordId::position())->getValue()); + const VecCoord& p =(object->read(core::vec_id::read_access::position)->getValue()); minCoord = DataTypes::getCPos(p[0]); maxCoord = minCoord; @@ -172,7 +172,7 @@ template const typename DataTypes::Coord& PointSetGeometryAlgorithms::getPointPosition(const PointID pointId) const { // get current positions - const typename DataTypes::VecCoord& p =(object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(object->read(core::vec_id::read_access::position)->getValue()); return p[pointId]; } @@ -181,7 +181,7 @@ template const typename DataTypes::Coord& PointSetGeometryAlgorithms::getPointRestPosition(const PointID pointId) const { // get rest positions - const typename DataTypes::VecCoord& p = (object->read(core::ConstVecCoordId::restPosition())->getValue()); + const typename DataTypes::VecCoord& p = (object->read(core::vec_id::read_access::restPosition)->getValue()); return p[pointId]; } @@ -191,7 +191,7 @@ typename PointSetGeometryAlgorithms::Angle PointSetGeometryAlgorithms::computeAngle(PointID ind_p0, PointID ind_p1, PointID ind_p2) const { const double ZERO = 1e-10; - const typename DataTypes::VecCoord& p =(object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(object->read(core::vec_id::read_access::position)->getValue()); Coord p0 = p[ind_p0]; Coord p1 = p[ind_p1]; Coord p2 = p[ind_p2]; @@ -276,7 +276,7 @@ void PointSetGeometryAlgorithms::draw(const core::visual::VisualParam if (d_showPointIndices.getValue()) { - const VecCoord& coords =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const VecCoord& coords =(this->object->read(core::vec_id::read_access::position)->getValue()); constexpr auto color4 = sofa::type::RGBAColor::white(); const float scale = getIndicesScale(); diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/QuadSetGeometryAlgorithms.inl b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/QuadSetGeometryAlgorithms.inl index 4c47a01e23a..373f9d6d6f7 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/QuadSetGeometryAlgorithms.inl +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/QuadSetGeometryAlgorithms.inl @@ -32,7 +32,7 @@ template< class DataTypes> void QuadSetGeometryAlgorithms< DataTypes >::computeQuadAABB(const QuadID i, Coord& minCoord, Coord& maxCoord) const { const Quad &t = this->m_topology->getQuad(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); for(unsigned int i=0; i<3; ++i) { @@ -45,7 +45,7 @@ template typename DataTypes::Coord QuadSetGeometryAlgorithms::computeQuadCenter(const QuadID i) const { const Quad &t = this->m_topology->getQuad(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); return (p[t[0]] + p[t[1]] + p[t[2]] + p[t[3]]) * (Real) 0.25; } @@ -54,7 +54,7 @@ template< class DataTypes> void QuadSetGeometryAlgorithms< DataTypes >::getQuadVertexCoordinates(const QuadID i, Coord pnt[4]) const { const Quad &t = this->m_topology->getQuad(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); for(unsigned int i=0; i<4; ++i) { @@ -66,7 +66,7 @@ template< class DataTypes> void QuadSetGeometryAlgorithms< DataTypes >::getRestQuadVertexCoordinates(const QuadID i, Coord pnt[4]) const { const Quad &t = this->m_topology->getQuad(i); - const typename DataTypes::VecCoord& p = (this->object->read(core::ConstVecCoordId::restPosition())->getValue()); + const typename DataTypes::VecCoord& p = (this->object->read(core::vec_id::read_access::restPosition)->getValue()); for(unsigned int i=0; i<4; ++i) { @@ -78,7 +78,7 @@ template< class DataTypes> typename DataTypes::Real QuadSetGeometryAlgorithms< DataTypes >::computeQuadArea( const QuadID i) const { const Quad &t = this->m_topology->getQuad(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); Real area = (Real)((areaProduct(p[t[1]]-p[t[0]],p[t[2]]-p[t[0]]) + areaProduct(p[t[3]]-p[t[2]],p[t[0]]-p[t[2]])) * (Real) 0.5); return area; @@ -88,7 +88,7 @@ template< class DataTypes> typename DataTypes::Real QuadSetGeometryAlgorithms< DataTypes >::computeRestQuadArea( const QuadID i) const { const Quad &t = this->m_topology->getQuad(i); - const typename DataTypes::VecCoord& p = (this->object->read(core::ConstVecCoordId::restPosition())->getValue()); + const typename DataTypes::VecCoord& p = (this->object->read(core::vec_id::read_access::restPosition)->getValue()); Real area = (Real)((areaProduct(p[t[1]]-p[t[0]],p[t[2]]-p[t[0]]) + areaProduct(p[t[3]]-p[t[2]],p[t[0]]-p[t[2]])) * (Real) 0.5); return area; @@ -99,7 +99,7 @@ void QuadSetGeometryAlgorithms::computeQuadArea( BasicArrayInterface< { //const sofa::type::vector &ta=this->m_topology->getQuads(); const size_t nb_quads = this->m_topology->getNbQuads(); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); for(sofa::Index i=0; i QuadSetGeometryAlgorithms< DataTypes >::computeQuadNor // HYP : The quad indexed by ind_q is planar const Quad &q = this->m_topology->getQuad(ind_q); - const typename DataTypes::VecCoord& vect_c =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c =(this->object->read(core::vec_id::read_access::position)->getValue()); const typename DataTypes::Coord& c0=vect_c[q[0]]; const typename DataTypes::Coord& c1=vect_c[q[1]]; @@ -149,7 +149,7 @@ bool QuadSetGeometryAlgorithms< DataTypes >::isQuadInPlane(const QuadID ind_q, // HYP : ind_p==q[0] or ind_q==t[1] or ind_q==t[2] or ind_q==q[3] - const typename DataTypes::VecCoord& vect_c =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c =(this->object->read(core::vec_id::read_access::position)->getValue()); PointID ind_1; PointID ind_2; @@ -203,7 +203,7 @@ bool QuadSetGeometryAlgorithms< DataTypes >::isPointInQuad(const QuadID ind_q, c { const double ZERO = 1e-6; const Quad &q = this->m_topology->getQuad(ind_q); - const typename DataTypes::VecCoord& vect_c =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c =(this->object->read(core::vec_id::read_access::position)->getValue()); sofa::type::Vec<3,Real> ptest = p; sofa::type::Vec<3,Real> p0(vect_c[q[0]][0], vect_c[q[0]][1], vect_c[q[0]][2]); @@ -315,7 +315,7 @@ void QuadSetGeometryAlgorithms::draw(const core::visual::VisualParams // Draw Quads indices if (showQuadIndices.getValue() && this->m_topology->getNbQuads() != 0) { - const VecCoord& coords =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const VecCoord& coords =(this->object->read(core::vec_id::read_access::position)->getValue()); sofa::type::RGBAColor color = _drawColor.getValue(); color[0] -= 0.2f; color[1] -= 0.2f; @@ -355,7 +355,7 @@ void QuadSetGeometryAlgorithms::draw(const core::visual::VisualParams const sofa::type::vector& quadArray = this->m_topology->getQuads(); // Draw Quad surfaces - const VecCoord& coords =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const VecCoord& coords =(this->object->read(core::vec_id::read_access::position)->getValue()); { // drawing quads std::vector pos; pos.reserve(quadArray.size()*4u); diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TetrahedronSetGeometryAlgorithms.inl b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TetrahedronSetGeometryAlgorithms.inl index 95c11dd76af..6b15e47aeac 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TetrahedronSetGeometryAlgorithms.inl +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TetrahedronSetGeometryAlgorithms.inl @@ -399,7 +399,7 @@ template< class DataTypes> void TetrahedronSetGeometryAlgorithms< DataTypes >::computeTetrahedronAABB(const TetraID i, Coord& minCoord, Coord& maxCoord) const { const Tetrahedron t = this->m_topology->getTetrahedron(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); for(unsigned int i=0; i<3; ++i) { @@ -412,7 +412,7 @@ template typename DataTypes::Coord TetrahedronSetGeometryAlgorithms::computeTetrahedronCenter(const TetraID i) const { const Tetrahedron t = this->m_topology->getTetrahedron(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); return (p[t[0]] + p[t[1]] + p[t[2]] + p[t[3]]) * (Real) 0.25; } @@ -421,7 +421,7 @@ template typename DataTypes::Coord TetrahedronSetGeometryAlgorithms::computeTetrahedronCircumcenter(const TetraID i) const { const Tetrahedron t = this->m_topology->getTetrahedron(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); Coord center = p[t[0]]; Coord t1 = p[t[1]] - p[t[0]]; @@ -449,7 +449,7 @@ bool TetrahedronSetGeometryAlgorithms< DataTypes >::isPointInTetrahedron(const T const Real ZERO = 1e-15; const Tetrahedron t = this->m_topology->getTetrahedron(ind_t); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); const sofa::type::Vec<3,Real> t0(p[t[0]][0], p[t[0]][1], p[t[0]][2]); const sofa::type::Vec<3,Real> t1(p[t[1]][0], p[t[1]][1], p[t[1]][2]); @@ -475,7 +475,7 @@ bool TetrahedronSetGeometryAlgorithms< DataTypes >::isPointInTetrahedron(const T const Real ZERO = 1e-15; const Tetrahedron t = this->m_topology->getTetrahedron(ind_t); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); const sofa::type::Vec<3,Real> t0(p[t[0]][0], p[t[0]][1], p[t[0]][2]); const sofa::type::Vec<3,Real> t1(p[t[1]][0], p[t[1]][1], p[t[1]][2]); @@ -511,7 +511,7 @@ template< class DataTypes> void TetrahedronSetGeometryAlgorithms< DataTypes >::getTetrahedronVertexCoordinates(const TetraID i, Coord pnt[4]) const { const Tetrahedron t = this->m_topology->getTetrahedron(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); for(unsigned int i=0; i<4; ++i) { @@ -523,7 +523,7 @@ template< class DataTypes> void TetrahedronSetGeometryAlgorithms< DataTypes >::getRestTetrahedronVertexCoordinates(const TetraID i, Coord pnt[4]) const { const Tetrahedron t = this->m_topology->getTetrahedron(i); - const typename DataTypes::VecCoord& p = (this->object->read(core::ConstVecCoordId::restPosition())->getValue()); + const typename DataTypes::VecCoord& p = (this->object->read(core::vec_id::read_access::restPosition)->getValue()); for(unsigned int i=0; i<4; ++i) { @@ -535,7 +535,7 @@ template< class DataTypes> typename DataTypes::Real TetrahedronSetGeometryAlgorithms< DataTypes >::computeTetrahedronVolume( const TetraID i) const { const Tetrahedron t = this->m_topology->getTetrahedron(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); Real volume = (Real)(tripleProduct(p[t[1]]-p[t[0]],p[t[2]]-p[t[0]],p[t[3]]-p[t[0]])/6.0); if(volume<0) volume=-volume; @@ -551,7 +551,7 @@ typename DataTypes::Real TetrahedronSetGeometryAlgorithms< DataTypes >::computeR template< class DataTypes> typename DataTypes::Real TetrahedronSetGeometryAlgorithms< DataTypes >::computeRestTetrahedronVolume( const Tetrahedron& t) const { - const typename DataTypes::VecCoord& p = (this->object->read(core::ConstVecCoordId::restPosition())->getValue()); + const typename DataTypes::VecCoord& p = (this->object->read(core::vec_id::read_access::restPosition)->getValue()); Real volume = (Real)(tripleProduct(p[t[1]]-p[t[0]],p[t[2]]-p[t[0]],p[t[3]]-p[t[0]])/6.0); if(volume<0) volume=-volume; @@ -563,7 +563,7 @@ template void TetrahedronSetGeometryAlgorithms::computeTetrahedronVolume( BasicArrayInterface &ai) const { const sofa::type::vector &ta = this->m_topology->getTetrahedra(); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); for (unsigned int i=0; i typename DataTypes::Real TetrahedronSetGeometryAlgorithms::computeDihedralAngle(const TetraID tetraId, const EdgeID edgeId) const { Real angle = 0.0; - const typename DataTypes::VecCoord& positions = (this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& positions = (this->object->read(core::vec_id::read_access::position)->getValue()); const Tetrahedron& tetra = this->m_topology->getTetrahedron(tetraId); const EdgesInTetrahedron& edgeIds = this->m_topology->getEdgesInTetrahedron(tetraId); const Edge& edge = this->m_topology->getEdge(edgeIds[edgeId]); @@ -620,7 +620,7 @@ template void TetrahedronSetGeometryAlgorithms< DataTypes >::getTetraInBall(const TetraID ind_ta, const TetraID ind_tb, sofa::type::vector &indices) const { - const typename DataTypes::VecCoord& vect_c =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c =(this->object->read(core::vec_id::read_access::position)->getValue()); const Tetrahedron ta=this->m_topology->getTetrahedron(ind_ta); const Tetrahedron tb=this->m_topology->getTetrahedron(ind_tb); @@ -646,7 +646,7 @@ void TetrahedronSetGeometryAlgorithms< DataTypes >::getTetraInBall(const TetraID { Real d = r; const Tetrahedron ta=this->m_topology->getTetrahedron(ind_ta); - const typename DataTypes::VecCoord& vect_c =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c =(this->object->read(core::vec_id::read_access::position)->getValue()); const typename DataTypes::Coord& ca=(vect_c[ta[0]]+vect_c[ta[1]]+vect_c[ta[2]]+vect_c[ta[3]])*0.25; sofa::type::Vec<3,Real> pa; @@ -745,7 +745,7 @@ void TetrahedronSetGeometryAlgorithms< DataTypes >::getTetraInBall(const Coord& msg_error() << "getTetraInBall, Can't find the seed."; Real d = r; // const Tetrahedron &ta=this->m_topology->getTetrahedron(ind_ta); - const typename DataTypes::VecCoord& vect_c =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c =(this->object->read(core::vec_id::read_access::position)->getValue()); TetrahedronID t_test=ind_ta; indices.push_back(t_test); @@ -822,7 +822,7 @@ template void TetrahedronSetGeometryAlgorithms::getIntersectionPointWithPlane(const TetraID ind_ta, const sofa::type::Vec<3,Real>& planP0, const sofa::type::Vec<3,Real>& normal, sofa::type::vector< sofa::type::Vec<3,Real> >& intersectedPoint, SeqEdges& intersectedEdge) { - const typename DataTypes::VecCoord& vect_c = (this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c = (this->object->read(core::vec_id::read_access::position)->getValue()); const EdgesInTetrahedron& edgesInTetra = this->m_topology->getEdgesInTetrahedron(ind_ta); const SeqEdges& edges = this->m_topology->getEdges(); @@ -876,7 +876,7 @@ bool TetrahedronSetGeometryAlgorithms< DataTypes >::checkNodeSequence(const Tetr template bool TetrahedronSetGeometryAlgorithms::checkNodeSequence(const Tetrahedron& tetra) const { - const typename DataTypes::VecCoord& vect_c = (this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c = (this->object->read(core::vec_id::read_access::position)->getValue()); sofa::type::Vec<3,Real> vec[3]; for(int i=1; i<4; i++) { @@ -894,7 +894,7 @@ bool TetrahedronSetGeometryAlgorithms::checkNodeSequence(const Tetrah template< class DataTypes> bool TetrahedronSetGeometryAlgorithms< DataTypes >::isTetrahedronElongated(const TetraID tetraId, SReal factorLength) const { - const typename DataTypes::VecCoord& coords = (this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& coords = (this->object->read(core::vec_id::read_access::position)->getValue()); const Tetrahedron& tetra = this->m_topology->getTetrahedron(tetraId); typename DataTypes::VecCoord points; @@ -3212,7 +3212,7 @@ void TetrahedronSetGeometryAlgorithms::draw(const core::visual::Visua const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); vparams->drawTool()->disableLighting(); - const VecCoord& coords =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const VecCoord& coords =(this->object->read(core::vec_id::read_access::position)->getValue()); //Draw tetra indices if (d_showTetrahedraIndices.getValue() && this->m_topology->getNbTetrahedra() != 0) { diff --git a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.inl b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.inl index 3aa76248417..5f10984e323 100644 --- a/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.inl +++ b/Sofa/Component/Topology/Container/Dynamic/src/sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.inl @@ -289,7 +289,7 @@ template< class DataTypes> void TriangleSetGeometryAlgorithms< DataTypes >::computeTriangleAABB(const TriangleID i, Coord& minCoord, Coord& maxCoord) const { const Triangle &t = this->m_topology->getTriangle(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); for(PointID i=0; i<3; ++i) { @@ -302,7 +302,7 @@ template typename DataTypes::Coord TriangleSetGeometryAlgorithms::computeTriangleCenter(const TriangleID i) const { const Triangle &t = this->m_topology->getTriangle(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); return (p[t[0]] + p[t[1]] + p[t[2]]) / (Real) 3.0; } @@ -311,7 +311,7 @@ template typename DataTypes::Coord TriangleSetGeometryAlgorithms::computeRestTriangleCenter(const TriangleID i) const { const Triangle &t = this->m_topology->getTriangle(i); - const typename DataTypes::VecCoord& p = (this->object->read(core::ConstVecCoordId::restPosition())->getValue()); + const typename DataTypes::VecCoord& p = (this->object->read(core::vec_id::read_access::restPosition)->getValue()); return (p[t[0]] + p[t[1]] + p[t[2]]) / (Real) 3.0; } @@ -321,7 +321,7 @@ void TriangleSetGeometryAlgorithms::computeTriangleCircumcenterBaryCo const TriangleID i) const { const Triangle &t = this->m_topology->getTriangle(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); Real a2, b2, c2; // square lengths of the 3 edges a2 = (p[t[1]]-p[t[0]]).norm2(); b2 = (p[t[2]]-p[t[1]]).norm2(); @@ -341,7 +341,7 @@ template typename DataTypes::Coord TriangleSetGeometryAlgorithms::computeTriangleCircumcenter(const TriangleID i) const { const Triangle &t = this->m_topology->getTriangle(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); sofa::type::Vec<3,Real> barycentricCoords; computeTriangleCircumcenterBaryCoefs(barycentricCoords, i); @@ -353,7 +353,7 @@ template< class DataTypes> void TriangleSetGeometryAlgorithms< DataTypes >::getTriangleVertexCoordinates(const TriangleID i, Coord pnt[3]) const { const Triangle &t = this->m_topology->getTriangle(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); for(PointID i=0; i<3; ++i) { @@ -365,7 +365,7 @@ template< class DataTypes> void TriangleSetGeometryAlgorithms< DataTypes >::getRestTriangleVertexCoordinates(const TriangleID i, Coord pnt[3]) const { const Triangle &t = this->m_topology->getTriangle(i); - const typename DataTypes::VecCoord& p = (this->object->read(core::ConstVecCoordId::restPosition())->getValue()); + const typename DataTypes::VecCoord& p = (this->object->read(core::vec_id::read_access::restPosition)->getValue()); for(PointID i=0; i<3; ++i) { @@ -377,7 +377,7 @@ template< class DataTypes> typename DataTypes::Real TriangleSetGeometryAlgorithms< DataTypes >::computeTriangleArea( const TriangleID i) const { const Triangle &t = this->m_topology->getTriangle(i); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); Real area = (Real)(areaProduct(p[t[1]]-p[t[0]], p[t[2]]-p[t[0]]) * 0.5); return area; } @@ -386,7 +386,7 @@ template< class DataTypes> typename DataTypes::Real TriangleSetGeometryAlgorithms< DataTypes >::computeRestTriangleArea( const TriangleID i) const { const Triangle &t = this->m_topology->getTriangle(i); - const typename DataTypes::VecCoord& p = (this->object->read(core::ConstVecCoordId::restPosition())->getValue()); + const typename DataTypes::VecCoord& p = (this->object->read(core::vec_id::read_access::restPosition)->getValue()); Real area = (Real) (areaProduct(p[t[1]]-p[t[0]],p[t[2]]-p[t[0]]) * 0.5); return area; } @@ -396,7 +396,7 @@ template void TriangleSetGeometryAlgorithms::computeTriangleArea( BasicArrayInterface &ai) const { const sofa::type::vector &ta = this->m_topology->getTriangles(); - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& p =(this->object->read(core::vec_id::read_access::position)->getValue()); for (size_t i=0; i::computeTriangleArea( BasicArrayIn template auto TriangleSetGeometryAlgorithms< DataTypes >::computeBaryEdgePoint(PointID p0, PointID p1, Real coord_p) const -> sofa::type::Vec<3, Real> { - const typename DataTypes::VecCoord& vect_c =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c =(this->object->read(core::vec_id::read_access::position)->getValue()); sofa::type::Vec<3,Real> c0; c0 = vect_c[p0]; sofa::type::Vec<3,Real> c1; c1 = vect_c[p1]; @@ -421,7 +421,7 @@ auto TriangleSetGeometryAlgorithms< DataTypes >::computeBaryEdgePoint(PointID p0 template auto TriangleSetGeometryAlgorithms< DataTypes >::computeBaryTrianglePoint(PointID p0, PointID p1, PointID p2, sofa::type::Vec<3,Real>& coord_p) const -> sofa::type::Vec<3, Real> { - const typename DataTypes::VecCoord& vect_c =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c =(this->object->read(core::vec_id::read_access::position)->getValue()); sofa::type::Vec<3,Real> c0; c0 = vect_c[p0]; sofa::type::Vec<3,Real> c1; c1 = vect_c[p1]; @@ -436,7 +436,7 @@ auto TriangleSetGeometryAlgorithms< DataTypes >::getOppositePoint(PointID ind_p, const Edge& indices, Real coord_p) const -> sofa::type::Vec<3, Real> { - const typename DataTypes::VecCoord& vect_c =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c =(this->object->read(core::vec_id::read_access::position)->getValue()); const typename DataTypes::Coord& c1 = vect_c[indices[0]]; const typename DataTypes::Coord& c2 = vect_c[indices[1]]; @@ -466,7 +466,7 @@ template auto TriangleSetGeometryAlgorithms< DataTypes >::computeTriangleNormal(const TriangleID ind_t) const -> sofa::type::Vec<3, Real> { const Triangle &t = this->m_topology->getTriangle(ind_t); - const typename DataTypes::VecCoord& vect_c =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c =(this->object->read(core::vec_id::read_access::position)->getValue()); sofa::type::Vec<3, Real> p0; DataTypes::get(p0[0], p0[1], p0[2], vect_c[t[0]]); sofa::type::Vec<3, Real> p1; DataTypes::get(p1[0], p1[1], p1[2], vect_c[t[1]]); @@ -507,7 +507,7 @@ auto TriangleSetGeometryAlgorithms< DataTypes >::compute3PointsBarycoefs( const Real ZERO = 1e-12; sofa::type::vector< SReal > baryCoefs; - const typename DataTypes::VecCoord& vect_c = (bRest ? (this->object->read(core::ConstVecCoordId::restPosition())->getValue()) : (this->object->read(core::ConstVecCoordId::position())->getValue())); + const typename DataTypes::VecCoord& vect_c = (bRest ? (this->object->read(core::vec_id::read_access::restPosition)->getValue()) : (this->object->read(core::vec_id::read_access::position)->getValue())); const typename DataTypes::Coord& c0 = vect_c[ind_p1]; const typename DataTypes::Coord& c1 = vect_c[ind_p2]; @@ -560,7 +560,7 @@ template void TriangleSetGeometryAlgorithms< DataTypes >::computeClosestIndexPair(const TriangleID ind_ta, const TriangleID ind_tb, PointID &ind1, PointID &ind2) const { - const typename DataTypes::VecCoord& vect_c =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c =(this->object->read(core::vec_id::read_access::position)->getValue()); const Triangle &ta=this->m_topology->getTriangle(ind_ta); const Triangle &tb=this->m_topology->getTriangle(ind_tb); @@ -617,8 +617,8 @@ bool TriangleSetGeometryAlgorithms< DataTypes >::isPointInsideTriangle(const Tri { const Real ZERO = -1e-12; const typename DataTypes::VecCoord& vect_c = bRest - ? (this->object->read(core::ConstVecCoordId::restPosition())->getValue()) - :(this->object->read(core::ConstVecCoordId::position())->getValue()); + ? (this->object->read(core::vec_id::read_access::restPosition)->getValue()) + :(this->object->read(core::vec_id::read_access::position)->getValue()); const Triangle &t=this->m_topology->getTriangle(ind_t); const typename DataTypes::Coord& c0=vect_c[t[0]]; @@ -755,7 +755,7 @@ bool TriangleSetGeometryAlgorithms< DataTypes >::isPointInTriangle(const Triangl TriangleID &ind_t_test) const { const Real ZERO = 1e-12; - const typename DataTypes::VecCoord& vect_c =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c =(this->object->read(core::vec_id::read_access::position)->getValue()); const Triangle &t=this->m_topology->getTriangle(ind_t); const typename DataTypes::Coord& c0=vect_c[t[0]]; @@ -900,7 +900,7 @@ bool TriangleSetGeometryAlgorithms< DataTypes >::isQuadDeulaunayOriented(const t { sofa::type::vector< Real > baryCoefs; - const typename DataTypes::VecCoord& vect_c =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c =(this->object->read(core::vec_id::read_access::position)->getValue()); const typename DataTypes::Coord& c3 = vect_c[ind_q3]; const typename DataTypes::Coord& c4 = vect_c[ind_q4]; @@ -1024,7 +1024,7 @@ bool TriangleSetGeometryAlgorithms< DataTypes >::isTriangleInPlane(const Triangl // HYP : ind_p==t[0] or ind_p==t[1] or ind_p==t[2] - const typename DataTypes::VecCoord& vect_c =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c =(this->object->read(core::vec_id::read_access::position)->getValue()); PointID ind_1; PointID ind_2; @@ -1082,7 +1082,7 @@ void TriangleSetGeometryAlgorithms< DataTypes >::prepareVertexDuplication(const { //HYP : if coord_from or coord_to == 0.0 or 1.0, ind_p is distinct from ind_from and from ind_to - const typename DataTypes::VecCoord& vect_c =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c =(this->object->read(core::vec_id::read_access::position)->getValue()); const typename DataTypes::Coord& c_p = vect_c[ind_p]; sofa::type::Vec<3,Real> point_p; @@ -1325,7 +1325,7 @@ bool TriangleSetGeometryAlgorithms< DataTypes >::computeSegmentTriangleIntersect bool is_intersected = false; const Triangle &t=this->m_topology->getTriangle(ind_t); - const typename DataTypes::VecCoord& vect_c =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c =(this->object->read(core::vec_id::read_access::position)->getValue()); bool is_full_01=(is_entered && ((t[0] == ind_first && t[1] == ind_second) || (t[1] == ind_first && t[0] == ind_second))); bool is_full_12=(is_entered && ((t[1] == ind_first && t[2] == ind_second) || (t[2] == ind_first && t[1] == ind_second))); @@ -1605,7 +1605,7 @@ bool TriangleSetGeometryAlgorithms< DataTypes >::computeIntersectionsLineTriangl bool is_validated = false; const Triangle& t = this->m_topology->getTriangle(ind_t); - const typename DataTypes::VecCoord& vect_c = (this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c = (this->object->read(core::vec_id::read_access::position)->getValue()); bool is_full_01 = (is_entered && ((t[0] == ind_first && t[1] == ind_second) || (t[1] == ind_first && t[0] == ind_second))); bool is_full_12 = (is_entered && ((t[1] == ind_first && t[2] == ind_second) || (t[2] == ind_first && t[1] == ind_second))); @@ -1958,7 +1958,7 @@ bool TriangleSetGeometryAlgorithms< DataTypes >::computeIntersectedPointsList(co else coords_list.push_back(1.0-coord_t); - const typename DataTypes::VecCoord& vect_c =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c =(this->object->read(core::vec_id::read_access::position)->getValue()); sofa::type::Vec<3,Real> c_t_current; // WARNING : conversion from 'Real' to 'float', possible loss of data ! // typename DataTypes::Coord c_t_current[0]=(Real) ((1.0-coord_t)*((Real) (vect_c[indices[0]][0]))+coord_t*((Real) (vect_c[indices[1]][0]))); @@ -2225,7 +2225,7 @@ bool TriangleSetGeometryAlgorithms::computeIntersectedObjectsList (co { intersected_topoElements.push_back (sofa::geometry::ElementType::POINT); intersected_indices.push_back (last_point); - const typename DataTypes::VecCoord& realC =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& realC =(this->object->read(core::vec_id::read_access::position)->getValue()); for (unsigned int i = 0; i<3; i++) baryCoords[i]=realC[last_point][i]; } @@ -2284,7 +2284,7 @@ bool TriangleSetGeometryAlgorithms::computeIntersectedObjectsList (co template int TriangleSetGeometryAlgorithms::getTriangleInDirection(PointID p, const sofa::type::Vec<3,Real>& dir) const { - const typename DataTypes::VecCoord& vect_c =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& vect_c =(this->object->read(core::vec_id::read_access::position)->getValue()); const sofa::type::vector &shell=this->m_topology->getTrianglesAroundVertex(p); sofa::type::Vec<3,Real> dtest = dir; for (size_t i=0; i::Suture2Points(TriangleID ind_ta auto* state = this->getDOF(); - sofa::helper::WriteAccessor< Data > x_wA = *state->write(core::VecCoordId::position()); - sofa::helper::WriteAccessor< Data > v_wA = *state->write(core::VecDerivId::velocity()); + sofa::helper::WriteAccessor< Data > x_wA = *state->write(core::vec_id::write_access::position); + sofa::helper::WriteAccessor< Data > v_wA = *state->write(core::vec_id::write_access::velocity); DataTypes::set(x_wA[ind1], x_created[0], x_created[1], x_created[2]); DataTypes::set(v_wA[ind1], (Real) 0.0, (Real) 0.0, (Real) 0.0); @@ -3842,7 +3842,7 @@ int TriangleSetGeometryAlgorithms::SplitAlongPath(PointID ind_A, Coor new_triangles_id.push_back(next_triangle++); // Triangularize the remaining quad according to the delaunay criteria - const typename DataTypes::VecCoord& coords = (this->getDOF()->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& coords = (this->getDOF()->read(core::vec_id::read_access::position)->getValue()); for (unsigned int j = 0; j < 2; j++) { //Vec<3,Real> pos[4]; @@ -4125,7 +4125,7 @@ void TriangleSetGeometryAlgorithms::SnapAlongPath(sofa::type::vector< return; } - const typename DataTypes::VecCoord& coords = (this->getDOF()->read(core::ConstVecCoordId::position())->getValue()); + const typename DataTypes::VecCoord& coords = (this->getDOF()->read(core::vec_id::read_access::position)->getValue()); //// STEP 3 - Second loop necessary to find object on the neighborhood of a snapped point @@ -4732,7 +4732,7 @@ void TriangleSetGeometryAlgorithms::draw(const core::visual::VisualPa // Draw Triangles indices if (showTriangleIndices.getValue() && this->m_topology->getNbTriangles() != 0) { - const VecCoord& coords =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const VecCoord& coords =(this->object->read(core::vec_id::read_access::position)->getValue()); float scale = this->getIndicesScale(); //for triangles: @@ -4766,7 +4766,7 @@ void TriangleSetGeometryAlgorithms::draw(const core::visual::VisualPa const sofa::type::vector &triangleArray = this->m_topology->getTriangles(); // Draw triangle surfaces - const VecCoord& coords =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const VecCoord& coords =(this->object->read(core::vec_id::read_access::position)->getValue()); {// Draw Triangles std::vector pos; @@ -4830,7 +4830,7 @@ void TriangleSetGeometryAlgorithms::draw(const core::visual::VisualPa if (_drawNormals.getValue() && this->m_topology->getNbTriangles() != 0) { - const VecCoord& coords =(this->object->read(core::ConstVecCoordId::position())->getValue()); + const VecCoord& coords =(this->object->read(core::vec_id::read_access::position)->getValue()); const sofa::type::vector &triangleArray = this->m_topology->getTriangles(); const size_t nbrTtri = triangleArray.size(); diff --git a/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SparseGridTopology.cpp b/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SparseGridTopology.cpp index 69e575383c9..a52bcce657e 100644 --- a/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SparseGridTopology.cpp +++ b/Sofa/Component/Topology/Container/Grid/src/sofa/component/topology/container/grid/SparseGridTopology.cpp @@ -616,7 +616,7 @@ void SparseGridTopology::updateMesh() if (mecha_temp != nullptr && mecha_temp->getSize() < 2) //a triangle mesh has minimum 3elements { list_mesh.push_back(collisionTopology); - list_X.push_back(mecha_temp->write(core::VecCoordId::position())); + list_X.push_back(mecha_temp->write(core::vec_id::write_access::position)); } } diff --git a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Edge2QuadTopologicalMapping.cpp b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Edge2QuadTopologicalMapping.cpp index 4b46f4c3194..44436cb7187 100644 --- a/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Edge2QuadTopologicalMapping.cpp +++ b/Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Edge2QuadTopologicalMapping.cpp @@ -181,10 +181,10 @@ void Edge2QuadTopologicalMapping::init() const unsigned int p0=i; Mat3x3 rotation; - (from_mstate->read(core::ConstVecCoordId::position())->getValue())[p0].writeRotationMatrix(rotation); + (from_mstate->read(core::vec_id::read_access::position)->getValue())[p0].writeRotationMatrix(rotation); Vec3 t; - t=(from_mstate->read(core::ConstVecCoordId::position())->getValue())[p0].getCenter(); + t=(from_mstate->read(core::vec_id::read_access::position)->getValue())[p0].getCenter(); Vec3 Y; Vec3 Z; @@ -192,7 +192,7 @@ void Edge2QuadTopologicalMapping::init() Y = rotation * Y0; Z = rotation * Z0; - helper::WriteAccessor< Data< Vec3Types::VecCoord > > to_x = *to_mstate->write(core::VecCoordId::position()); + helper::WriteAccessor< Data< Vec3Types::VecCoord > > to_x = *to_mstate->write(core::vec_id::write_access::position); for(unsigned int j=0; j * mstate = m_topology->getContext()->get< core::behavior::MechanicalState > (); //get the coordinates of the mechanical state - const auto &v_coords = mstate->read(core::ConstVecCoordId::position())->getValue(); + const auto &v_coords = mstate->read(core::vec_id::read_access::position)->getValue(); a = v_coords[a_last]; } @@ -1289,7 +1289,7 @@ void TopologicalChangeProcessor::inciseWithSavedIndices() { const core::behavior::MechanicalState* mstate = m_topology->getContext()->get >(); //get the coordinates of the mechanical state - const auto &v_coords = mstate->read(core::ConstVecCoordId::position())->getValue(); + const auto &v_coords = mstate->read(core::vec_id::read_access::position)->getValue(); a = v_coords[a_last]; } diff --git a/Sofa/Component/Visual/src/sofa/component/visual/VisualModelImpl.cpp b/Sofa/Component/Visual/src/sofa/component/visual/VisualModelImpl.cpp index eecafd203b8..93fcee2b451 100644 --- a/Sofa/Component/Visual/src/sofa/component/visual/VisualModelImpl.cpp +++ b/Sofa/Component/Visual/src/sofa/component/visual/VisualModelImpl.cpp @@ -641,7 +641,7 @@ void VisualModelImpl::applyTranslation(const SReal dx, const SReal dy, const SRe { const Coord d((Real)dx,(Real)dy,(Real)dz); - Data< VecCoord >* d_x = this->write(core::VecCoordId::position()); + Data< VecCoord >* d_x = this->write(core::vec_id::write_access::position); VecCoord &x = *d_x->beginEdit(); for (std::size_t i = 0; i < x.size(); i++) @@ -674,7 +674,7 @@ void VisualModelImpl::applyRotation(const SReal rx, const SReal ry, const SReal void VisualModelImpl::applyRotation(const Quat q) { - Data< VecCoord >* d_x = this->write(core::VecCoordId::position()); + Data< VecCoord >* d_x = this->write(core::vec_id::write_access::position); VecCoord &x = *d_x->beginEdit(); for (std::size_t i = 0; i < x.size(); i++) @@ -701,7 +701,7 @@ void VisualModelImpl::applyRotation(const Quat q) void VisualModelImpl::applyScale(const SReal sx, const SReal sy, const SReal sz) { - Data< VecCoord >* d_x = this->write(core::VecCoordId::position()); + Data< VecCoord >* d_x = this->write(core::vec_id::write_access::position); VecCoord &x = *d_x->beginEdit(); for (std::size_t i = 0; i < x.size(); i++) diff --git a/Sofa/GL/Component/Rendering2D/src/sofa/gl/component/rendering2d/OglColorMap.cpp b/Sofa/GL/Component/Rendering2D/src/sofa/gl/component/rendering2d/OglColorMap.cpp index fa4c6a1f262..91ba9cc396f 100644 --- a/Sofa/GL/Component/Rendering2D/src/sofa/gl/component/rendering2d/OglColorMap.cpp +++ b/Sofa/GL/Component/Rendering2D/src/sofa/gl/component/rendering2d/OglColorMap.cpp @@ -43,8 +43,8 @@ OglColorMap::OglColorMap() , d_colorScheme(initData(&d_colorScheme, "colorScheme", "Color scheme to use")) , d_showLegend(initData(&d_showLegend, false, "showLegend", "Activate rendering of color scale legend on the side")) , d_legendOffset(initData(&d_legendOffset, type::Vec2f(10.0f,5.0f),"legendOffset", "Draw the legend on screen with an x,y offset")) -, d_legendTitle(initData(&d_legendTitle,"legendTitle", "Font size of the legend (if any)")) -, d_legendSize(initData(&d_legendSize, 11u, "legendSize", "Add a title to the legend")) +, d_legendTitle(initData(&d_legendTitle,"legendTitle", "Add a title to the legend")) +, d_legendSize(initData(&d_legendSize, 11u, "legendSize", "Font size of the legend (if any)")) , d_min(initData(&d_min,0.0f,"min","min value for drawing the legend without the need to actually use the range with getEvaluator method which sets the min")) , d_max(initData(&d_max,0.0f,"max","max value for drawing the legend without the need to actually use the range with getEvaluator method which sets the max")) , d_legendRangeScale(initData(&d_legendRangeScale,1.f,"legendRangeScale","to change the unit of the min/max value of the legend")) diff --git a/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/DataDisplay.cpp b/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/DataDisplay.cpp index 2249b18d5e1..6a86c95dc95 100644 --- a/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/DataDisplay.cpp +++ b/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/DataDisplay.cpp @@ -56,8 +56,8 @@ DataDisplay::DataDisplay() , state(nullptr) , m_topology(nullptr) , l_topology(initLink("topology", "link to the topology container")) - , oldMin(0) - , oldMax(0) + , m_oldMin(std::numeric_limits::max()) + , m_oldMax(std::numeric_limits::lowest()) { this->addAlias(&f_triangleData,"cellData"); // backward compatibility d_currentMin.setReadOnly(true); @@ -93,7 +93,7 @@ void DataDisplay::doUpdateVisual(const core::visual::VisualParams*) void DataDisplay::doDrawVisual(const core::visual::VisualParams* vparams) { - const VecCoord& x = this->read(sofa::core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->read(sofa::core::vec_id::read_access::position)->getValue(); const VecPointData &ptData = f_pointData.getValue(); const VecCellData &triData = f_triangleData.getValue(); const VecCellData &quadData = f_quadData.getValue(); @@ -141,9 +141,8 @@ void DataDisplay::doDrawVisual(const core::visual::VisualParams* vparams) } // Range for points - Real min ; - Real max ; - min = max = 0; + Real min = std::numeric_limits::max(); + Real max = std::numeric_limits::lowest(); if (bDrawPointData) { VecPointData::const_iterator i = ptData.begin(); min = *i; @@ -212,12 +211,12 @@ void DataDisplay::doDrawVisual(const core::visual::VisualParams* vparams) } - if (max > oldMax) oldMax = max; - if (min < oldMin) oldMin = min; + if (max > m_oldMax) m_oldMax = max; + if (min < m_oldMin) m_oldMin = min; if (f_maximalRange.getValue()) { - max = oldMax; - min = oldMin; + max = m_oldMax; + min = m_oldMin; } d_currentMin.setValue(min); d_currentMax.setValue(max); @@ -446,7 +445,7 @@ void DataDisplay::doDrawVisual(const core::visual::VisualParams* vparams) void DataDisplay::computeNormals() { if( !m_topology ) return; - const VecCoord& x = this->read(sofa::core::ConstVecCoordId::position())->getValue(); + const VecCoord& x = this->read(sofa::core::vec_id::read_access::position)->getValue(); m_normals.resize(x.size(),Vec3f(0,0,0)); diff --git a/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/DataDisplay.h b/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/DataDisplay.h index 91491ef5d43..91bb25b1acb 100644 --- a/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/DataDisplay.h +++ b/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/DataDisplay.h @@ -66,8 +66,6 @@ class SOFA_GL_COMPONENT_RENDERING3D_API DataDisplay : public core::visual::Visua /// Link to be set to the topology container in the component graph. SingleLink l_topology; - Real oldMin, oldMax; - void init() override; void doDrawVisual(const core::visual::VisualParams* vparams) override; void doUpdateVisual(const core::visual::VisualParams* vparams) override; @@ -80,6 +78,9 @@ class SOFA_GL_COMPONENT_RENDERING3D_API DataDisplay : public core::visual::Visua type::vector m_normals; DataDisplay(); + + Real m_oldMin, m_oldMax; + }; } // namespace sofa::gl::component::rendering3d diff --git a/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglCylinderModel.cpp b/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglCylinderModel.cpp index e1da5f23bc1..8042ea05b97 100644 --- a/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglCylinderModel.cpp +++ b/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglCylinderModel.cpp @@ -59,7 +59,7 @@ void OglCylinderModel::init() void OglCylinderModel::doDrawVisual(const core::visual::VisualParams* vparams) { - const VecCoord& pos = this->read( core::ConstVecCoordId::position() )->getValue(); + const VecCoord& pos = this->read( core::vec_id::read_access::position )->getValue(); vparams->drawTool()->setLightingEnabled(true); const float _radius = radius.getValue(); @@ -140,7 +140,7 @@ void OglCylinderModel::setColor(std::string color) void OglCylinderModel::exportOBJ(std::string name, std::ostream* out, std::ostream* /*mtl*/, Index& vindex, Index& /*nindex*/, Index& /*tindex*/, int& /*count*/) { - const VecCoord& x = this->read( core::ConstVecCoordId::position() )->getValue(); + const VecCoord& x = this->read( core::vec_id::read_access::position )->getValue(); const SeqEdges& edges = d_edges.getValue(); const int nbv = int(x.size()); diff --git a/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglSceneFrame.cpp b/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglSceneFrame.cpp index 41d46622f1a..f2bba6ceb04 100644 --- a/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglSceneFrame.cpp +++ b/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglSceneFrame.cpp @@ -32,20 +32,15 @@ int OglSceneFrameClass = core::RegisterObject("Display a frame at the corner of using namespace sofa::defaulttype; +static constexpr OglSceneFrame::Alignment defaultAlignment("BottomRight"); +static constexpr OglSceneFrame::Style defaultStyle("Cylinders"); + OglSceneFrame::OglSceneFrame() : d_drawFrame(initData(&d_drawFrame, true, "draw", "Display the frame or not")) - , d_style(initData(&d_style, "style", "Style of the frame")) - , d_alignment(initData(&d_alignment, "alignment", "Alignment of the frame in the view")) + , d_style(initData(&d_style, defaultStyle, "style", ("Style of the frame\n" + Style::dataDescription()).c_str())) + , d_alignment(initData(&d_alignment, defaultAlignment, "alignment", ("Alignment of the frame in the view\n" + Alignment::dataDescription()).c_str())) , d_viewportSize(initData(&d_viewportSize, 150, "viewportSize", "Size of the viewport where the frame is rendered")) -{ - sofa::helper::OptionsGroup styleOptions{"Arrows", "Cylinders", "CubeCones"}; - styleOptions.setSelectedItem(1); - d_style.setValue(styleOptions); - - sofa::helper::OptionsGroup alignmentOptions{"BottomLeft", "BottomRight", "TopRight", "TopLeft"}; - alignmentOptions.setSelectedItem(1); - d_alignment.setValue(alignmentOptions); -} +{} void OglSceneFrame::drawArrows(const core::visual::VisualParams* vparams) { @@ -112,22 +107,22 @@ void OglSceneFrame::doDrawVisual(const core::visual::VisualParams* vparams) const auto viewportSize = d_viewportSize.getValue(); - switch(d_alignment.getValue().getSelectedId()) + switch(d_alignment.getValue()) { - case 0: //BottomLeft + case Alignment("BottomLeft"): default: glViewport(0,0,viewportSize,viewportSize); glScissor(0,0,viewportSize,viewportSize); break; - case 1: //BottomRight + case Alignment("BottomRight"): glViewport(viewport[2]-viewportSize,0,viewportSize,viewportSize); glScissor(viewport[2]-viewportSize,0,viewportSize,viewportSize); break; - case 2: //TopRight + case Alignment("TopRight"): glViewport(viewport[2]-viewportSize,viewport[3]-viewportSize,viewportSize,viewportSize); glScissor(viewport[2]-viewportSize,viewport[3]-viewportSize,viewportSize,viewportSize); break; - case 3: //TopLeft + case Alignment("TopLeft"): glViewport(0,viewport[3]-viewportSize,viewportSize,viewportSize); glScissor(0,viewport[3]-viewportSize,viewportSize,viewportSize); break; @@ -157,18 +152,18 @@ void OglSceneFrame::doDrawVisual(const core::visual::VisualParams* vparams) vparams->drawTool()->disableLighting(); - switch (d_style.getValue().getSelectedId()) + switch (d_style.getValue()) { - case 0: + case Style("Arrows"): default: drawArrows(vparams); break; - case 1: + case Style("Cylinders"): drawCylinders(vparams); break; - case 2: + case Style("CubeCones"): drawCubeCones(vparams); break; } diff --git a/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglSceneFrame.h b/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglSceneFrame.h index c6cdd2288bb..d834c9584d1 100644 --- a/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglSceneFrame.h +++ b/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglSceneFrame.h @@ -25,6 +25,8 @@ #include #include #include +#include + namespace sofa::gl::component::rendering3d { @@ -38,8 +40,23 @@ class SOFA_GL_COMPONENT_RENDERING3D_API OglSceneFrame : public core::visual::Vis typedef core::visual::VisualParams::Viewport Viewport; Data d_drawFrame; ///< Display the frame or not - Data d_style; ///< Style of the frame - Data d_alignment; ///< Alignment of the frame in the view + + MAKE_SELECTABLE_ITEMS(Style, + sofa::helper::Item{"Arrows", "The frame is composed of arrows"}, + sofa::helper::Item{"Cylinders", "The frame is composed of cylinders"}, + sofa::helper::Item{"CubeCones", "The frame is composed of cubes and cones"}, + ); + + Data