From ffddff707679c4558e3f86b44aea6b43167e4d02 Mon Sep 17 00:00:00 2001 From: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Date: Wed, 29 Jan 2025 19:48:23 +0100 Subject: [PATCH 1/4] [CMake] Add possibility to remove auto installing of resource files (#5230) Add possibility to remove auto installing of ressource files --- .../Config/cmake/SofaMacrosInstall.cmake | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Sofa/framework/Config/cmake/SofaMacrosInstall.cmake b/Sofa/framework/Config/cmake/SofaMacrosInstall.cmake index 096546f9d10..f4f348099fe 100644 --- a/Sofa/framework/Config/cmake/SofaMacrosInstall.cmake +++ b/Sofa/framework/Config/cmake/SofaMacrosInstall.cmake @@ -31,7 +31,7 @@ include(CMakeParseLibraryList) macro(sofa_create_package_with_targets) set(oneValueArgs PACKAGE_NAME PACKAGE_VERSION INCLUDE_ROOT_DIR INCLUDE_INSTALL_DIR INCLUDE_SOURCE_DIR EXAMPLE_INSTALL_DIR RELOCATABLE) set(multiValueArgs TARGETS) - set(optionalArgs AUTO_SET_TARGET_PROPERTIES) + set(optionalArgs AUTO_SET_TARGET_PROPERTIES NO_AUTO_RESOURCES_INSTALL) cmake_parse_arguments("ARG" "${optionalArgs}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) # Required arguments foreach(arg ARG_PACKAGE_NAME ARG_PACKAGE_VERSION ARG_TARGETS) @@ -226,7 +226,7 @@ endmacro() macro(sofa_add_targets_to_package) set(oneValueArgs PACKAGE_NAME PACKAGE_VERSION INCLUDE_ROOT_DIR INCLUDE_INSTALL_DIR INCLUDE_SOURCE_DIR EXAMPLE_INSTALL_DIR RELOCATABLE OPTIMIZE_BUILD_DIR) set(multiValueArgs TARGETS) - set(optionalArgs AUTO_SET_TARGET_PROPERTIES) + set(optionalArgs AUTO_SET_TARGET_PROPERTIES NO_AUTO_RESOURCES_INSTALL) cmake_parse_arguments("ARG" "${optionalArgs}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) # Required arguments foreach(arg ARG_PACKAGE_NAME ARG_TARGETS) @@ -600,7 +600,7 @@ endmacro() macro(sofa_install_targets_in_package) set(oneValueArgs PACKAGE_NAME PACKAGE_VERSION INCLUDE_ROOT_DIR INCLUDE_INSTALL_DIR INCLUDE_SOURCE_DIR EXAMPLE_INSTALL_DIR RELOCATABLE OPTIMIZE_BUILD_DIR) set(multiValueArgs TARGETS) - set(optionalArgs AUTO_SET_TARGET_PROPERTIES) + set(optionalArgs AUTO_SET_TARGET_PROPERTIES NO_AUTO_RESOURCES_INSTALL) cmake_parse_arguments("ARG" "${optionalArgs}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) # Required arguments foreach(arg ARG_PACKAGE_NAME ARG_TARGETS ARG_INCLUDE_INSTALL_DIR) @@ -700,16 +700,18 @@ macro(sofa_install_targets_in_package) endforeach() endforeach() - # Install examples and scenes - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/examples") - install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/examples/" - DESTINATION "${example_install_dir}" - COMPONENT resources) - endif() - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/scenes") - install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/scenes/" - DESTINATION "${example_install_dir}" - COMPONENT resources) + if(NOT ARG_NO_AUTO_RESOURCES_INSTALL) + # Install examples and scenes + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/examples") + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/examples/" + DESTINATION "${example_install_dir}" + COMPONENT resources) + endif() + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/scenes") + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/scenes/" + DESTINATION "${example_install_dir}" + COMPONENT resources) + endif() endif() # Install info files (README, license, etc.) From 38c295dcb7fffee64cbb7bf538fc6c60a61f2273 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Wed, 29 Jan 2025 19:54:39 +0100 Subject: [PATCH 2/4] [Playback] Remove deprecated macro (#5231) --- .../src/sofa/component/playback/CompareState.cpp | 4 ++-- .../src/sofa/component/playback/CompareTopology.cpp | 4 ++-- .../Playback/src/sofa/component/playback/config.h.in | 9 --------- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/Sofa/Component/Playback/src/sofa/component/playback/CompareState.cpp b/Sofa/Component/Playback/src/sofa/component/playback/CompareState.cpp index ead0a2e58aa..989ea02d5bb 100644 --- a/Sofa/Component/Playback/src/sofa/component/playback/CompareState.cpp +++ b/Sofa/Component/Playback/src/sofa/component/playback/CompareState.cpp @@ -263,7 +263,7 @@ void CompareState::draw(const core::visual::VisualParams* vparams) CompareStateCreator::CompareStateCreator(const core::ExecParams* params) : Visitor(params) , sceneName("") -#if SOFAGENERALLOADER_HAVE_ZLIB +#if SOFA_COMPONENT_PLAYBACK_HAVE_ZLIB , extension(".txt.gz") #else , extension(".txt") @@ -277,7 +277,7 @@ CompareStateCreator::CompareStateCreator(const core::ExecParams* params) CompareStateCreator::CompareStateCreator(const std::string &n, const core::ExecParams* params, bool i, int c) : Visitor(params) , sceneName(n) -#if SOFAGENERALLOADER_HAVE_ZLIB +#if SOFA_COMPONENT_PLAYBACK_HAVE_ZLIB , extension(".txt.gz") #else , extension(".txt") diff --git a/Sofa/Component/Playback/src/sofa/component/playback/CompareTopology.cpp b/Sofa/Component/Playback/src/sofa/component/playback/CompareTopology.cpp index b6a20b6fe7f..10b0a1bde72 100644 --- a/Sofa/Component/Playback/src/sofa/component/playback/CompareTopology.cpp +++ b/Sofa/Component/Playback/src/sofa/component/playback/CompareTopology.cpp @@ -298,7 +298,7 @@ void CompareTopology::processCompareTopology() CompareTopologyCreator::CompareTopologyCreator(const core::ExecParams* params) :Visitor(params) , sceneName("") -#if SOFAGENERALLOADER_HAVE_ZLIB +#if SOFA_COMPONENT_PLAYBACK_HAVE_ZLIB , extension(".txt.gz") #else , extension(".txt") @@ -312,7 +312,7 @@ CompareTopologyCreator::CompareTopologyCreator(const core::ExecParams* params) CompareTopologyCreator::CompareTopologyCreator(const std::string &n, const core::ExecParams* params, bool i, int c) :Visitor(params) , sceneName(n) -#if SOFAGENERALLOADER_HAVE_ZLIB +#if SOFA_COMPONENT_PLAYBACK_HAVE_ZLIB , extension(".txt.gz") #else , extension(".txt") diff --git a/Sofa/Component/Playback/src/sofa/component/playback/config.h.in b/Sofa/Component/Playback/src/sofa/component/playback/config.h.in index cdd661afb43..588d17cb0ed 100644 --- a/Sofa/Component/Playback/src/sofa/component/playback/config.h.in +++ b/Sofa/Component/Playback/src/sofa/component/playback/config.h.in @@ -39,15 +39,6 @@ namespace sofa::component::playback constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@"; } // namespace sofa::component::playback -// Keep the previous macros -// This backward compatibility will be removed at v23.06 -#ifndef SOFAGENERALLOADER_HAVE_ZLIB -#define SOFAGENERALLOADER_HAVE_ZLIB SOFA_COMPONENT_PLAYBACK_HAVE_ZLIB -#endif -#ifndef SOFAEXPORTER_HAVE_ZLIB -#define SOFAEXPORTER_HAVE_ZLIB SOFA_COMPONENT_PLAYBACK_HAVE_ZLIB -#endif - #ifdef SOFA_BUILD_SOFA_COMPONENT_PLAYBACK #define SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA_IN_PLAYBACK() #else From 989a885269ec2e97491de89264861c35c8ab36d2 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Wed, 29 Jan 2025 21:03:59 +0100 Subject: [PATCH 3/4] [StateContainer] Extensive tests of MechanicalObject::vOp (#5233) * [StateContainer] Extensive tests of MechanicalObject::vOp * fix wrong name * fix test * Use variable for the coefficients * missing test * remove duplicated test --- .../StateContainer/tests/CMakeLists.txt | 1 + .../tests/MechanicalObjectVOp_test.cpp | 810 ++++++++++++++++++ 2 files changed, 811 insertions(+) create mode 100644 Sofa/Component/StateContainer/tests/MechanicalObjectVOp_test.cpp diff --git a/Sofa/Component/StateContainer/tests/CMakeLists.txt b/Sofa/Component/StateContainer/tests/CMakeLists.txt index 14059938bf1..970fa4e6382 100644 --- a/Sofa/Component/StateContainer/tests/CMakeLists.txt +++ b/Sofa/Component/StateContainer/tests/CMakeLists.txt @@ -4,6 +4,7 @@ project(Sofa.Component.StateContainer_test) set(SOURCE_FILES MechanicalObject_test.cpp + MechanicalObjectVOp_test.cpp ) add_executable(${PROJECT_NAME} ${SOURCE_FILES}) diff --git a/Sofa/Component/StateContainer/tests/MechanicalObjectVOp_test.cpp b/Sofa/Component/StateContainer/tests/MechanicalObjectVOp_test.cpp new file mode 100644 index 00000000000..b1ca88edc2a --- /dev/null +++ b/Sofa/Component/StateContainer/tests/MechanicalObjectVOp_test.cpp @@ -0,0 +1,810 @@ +/****************************************************************************** +* 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 * +******************************************************************************/ +#include +#include + +namespace sofa +{ + +template +struct MechanicalObjectVOpTest : public testing::BaseTest +{ + using MO = component::statecontainer::MechanicalObject; + + static constexpr Real_t positionCoefficient = 19; + static constexpr Real_t restPositionCoefficient = 20; + static constexpr Real_t freePositionCoefficient = 5; + static constexpr Real_t velocityCoefficient = 12; + static constexpr Real_t forceCoefficient = 63; + static constexpr Real_t freeVelocityCoefficient = 78; + + void onSetUp() override + { + m_mechanicalObject = core::objectmodel::New(); + + m_mechanicalObject->x0.forceSet(); + m_mechanicalObject->f.forceSet(); + m_mechanicalObject->xfree.forceSet(); + m_mechanicalObject->vfree.forceSet(); + + m_mechanicalObject->resize(10); + + setVecValues(positionCoefficient); + checkVecValues(positionCoefficient); + + setVecValues(restPositionCoefficient); + checkVecValues(restPositionCoefficient); + + setVecValues(freePositionCoefficient); + checkVecValues(freePositionCoefficient); + + setVecValues(velocityCoefficient); + checkVecValues(velocityCoefficient); + + setVecValues(forceCoefficient); + checkVecValues(forceCoefficient); + + setVecValues(freeVelocityCoefficient); + checkVecValues(freeVelocityCoefficient); + } + + template + void setVecValues(Real_t coefficient = 1) const + { + unsigned int index {}; + auto vec = sofa::helper::getWriteOnlyAccessor(*m_mechanicalObject->write(vtype)); + ASSERT_EQ(vec.size(), 10); + for (auto& v : vec) + { + for (std::size_t i = 0; i < v.size(); ++i) + { + v[i] = static_cast>(index) * coefficient; + } + ++index; + } + } + + template + void checkVecValues(Real_t coefficient = 1) const + { + unsigned int index {}; + auto vec = sofa::helper::getReadAccessor(*m_mechanicalObject->read(vtype)); + ASSERT_EQ(vec.size(), 10); + for (auto& v : vec) + { + for (std::size_t i = 0; i < v.size(); ++i) + { + EXPECT_FLOATINGPOINT_EQ(v[i], static_cast>(index) * coefficient); + } + ++index; + } + } + + template + void checkVecSpatialValues(Real_t coefficient = 1) const + { + unsigned int index {}; + auto vec = sofa::helper::getReadAccessor(*m_mechanicalObject->read(vtype)); + ASSERT_EQ(vec.size(), 10); + for (auto& v : vec) + { + for (std::size_t i = 0; i < DataTypes::spatial_dimensions; ++i) + { + EXPECT_FLOATINGPOINT_EQ(v[i], static_cast>(index) * coefficient); + } + ++index; + } + } + + bool v_null() const + { + //check that an error is emitted + { + EXPECT_MSG_EMIT(Error); + m_mechanicalObject->vOp(nullptr, core::VecId::null()); + } + + checkVecValues(positionCoefficient); + checkVecValues(velocityCoefficient); + + return true; + } + + void resetPosition() const + { + //check that an error is not emitted + { + EXPECT_MSG_NOEMIT(Error); + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position); + } + + //position is reset + for (auto& position : m_mechanicalObject->readPositions()) + { + static Coord_t defaulConstructedCoord; + for (std::size_t i = 0; i < position.size(); ++i) + { + EXPECT_FLOATINGPOINT_EQ(position[i], defaulConstructedCoord[i]); + } + } + + checkVecValues(velocityCoefficient); + } + + void resetVelocity() const + { + //check that an error is not emitted + { + EXPECT_MSG_NOEMIT(Error); + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity); + } + + //velocity is reset + for (auto& velocity : m_mechanicalObject->readVelocities()) + { + static Deriv_t defaulConstructedDeriv; + for (std::size_t i = 0; i < velocity.size(); ++i) + { + EXPECT_FLOATINGPOINT_EQ(velocity[i], defaulConstructedDeriv[i]); + } + } + + checkVecValues(positionCoefficient); + } + + void multiplyByScalarPosition() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v *= f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::ConstVecId::null(), core::vec_id::read_access::position, 2._sreal); + } + checkVecSpatialValues(positionCoefficient * 2_sreal); + checkVecValues(velocityCoefficient); + } + + void multiplyByScalarVelocity() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v *= f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::ConstVecId::null(), core::vec_id::read_access::velocity, 2._sreal); + } + checkVecValues(positionCoefficient); + checkVecValues(velocityCoefficient * 2_sreal); + } + + void equalOtherMultiplyByScalarPosition() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v = b*f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::ConstVecId::null(), core::vec_id::read_access::restPosition, 2._sreal); + } + checkVecSpatialValues(restPositionCoefficient * 2); + checkVecValues(velocityCoefficient); + } + + void equalOtherMultiplyByScalarVelocity() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v = b*f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::ConstVecId::null(), core::vec_id::read_access::force, 2._sreal); + } + checkVecValues(positionCoefficient); + checkVecValues(forceCoefficient * 2); + } + + void equalOtherMultiplyByScalarPositionMix() const + { + { + EXPECT_MSG_EMIT(Error); + //v = b*f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::ConstVecId::null(), core::vec_id::read_access::velocity, 2._sreal); + } + checkVecSpatialValues(positionCoefficient); + checkVecValues(velocityCoefficient); + } + + void equalOtherMultiplyByScalarVelocityMix() const + { + { + EXPECT_MSG_EMIT(Error); + //v = b*f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::ConstVecId::null(), core::vec_id::read_access::position, 2._sreal); + } + checkVecSpatialValues(positionCoefficient); + checkVecValues(velocityCoefficient); + } + + void equalOtherPosition() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v = a + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::vec_id::read_access::restPosition, core::ConstVecId::null(), 1._sreal); + } + checkVecValues(restPositionCoefficient); + checkVecValues(velocityCoefficient); + } + + void equalOtherPositionMix() const + { + { + EXPECT_MSG_EMIT(Error); + //v = a + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::vec_id::read_access::velocity, core::ConstVecId::null(), 1._sreal); + } + checkVecValues(positionCoefficient); + checkVecValues(velocityCoefficient); + } + + void equalOtherVelocity() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v = a + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::vec_id::read_access::force, core::ConstVecId::null(), 1._sreal); + } + checkVecValues(positionCoefficient); + checkVecValues(forceCoefficient); + } + + void equalOtherVelocityMix() const + { + { + EXPECT_MSG_EMIT(Error); + //v = a + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::vec_id::read_access::restPosition, core::ConstVecId::null(), 1._sreal); + } + checkVecValues(positionCoefficient); + checkVecValues(velocityCoefficient); + } + + void plusEqualOtherPosition() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v += b + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::vec_id::read_access::position, core::vec_id::read_access::restPosition, 1._sreal); + } + checkVecSpatialValues(positionCoefficient + restPositionCoefficient); + checkVecValues(velocityCoefficient); + } + + void plusEqualOtherPositionMix() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v += b + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::vec_id::read_access::position, core::vec_id::read_access::freeVelocity, 1._sreal); + } + checkVecSpatialValues(positionCoefficient + freeVelocityCoefficient); + checkVecValues(velocityCoefficient); + } + + void plusEqualOtherVelocity() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v += b + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::vec_id::read_access::velocity, core::vec_id::read_access::force, 1._sreal); + } + checkVecValues(positionCoefficient); + checkVecValues(velocityCoefficient + forceCoefficient); + } + + void plusEqualOtherVelocityMix() const + { + { + EXPECT_MSG_EMIT(Error); + //v += b + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::vec_id::read_access::velocity, core::vec_id::read_access::position, 1._sreal); + } + checkVecValues(positionCoefficient); + checkVecValues(velocityCoefficient); + } + + void plusEqualOtherMultipliedByScalarPosition() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v += b*f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::vec_id::read_access::position, core::vec_id::read_access::restPosition, 2._sreal); + } + checkVecSpatialValues(positionCoefficient + restPositionCoefficient * 2); + checkVecValues(velocityCoefficient); + } + + void plusEqualOtherMultipliedByScalarPositionMix() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v += b*f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::vec_id::read_access::position, core::vec_id::read_access::freeVelocity, 2._sreal); + } + checkVecSpatialValues(positionCoefficient + freeVelocityCoefficient * 2); + checkVecValues(velocityCoefficient); + } + + void plusEqualOtherMultipliedByScalarVelocity() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v += b*f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::vec_id::read_access::velocity, core::vec_id::read_access::force, 2._sreal); + } + checkVecValues(positionCoefficient); + checkVecValues(velocityCoefficient + forceCoefficient * 2); + } + + void plusEqualOtherMultipliedByScalarVelocityMix() const + { + { + EXPECT_MSG_EMIT(Error); + //v += b*f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::vec_id::read_access::velocity, core::vec_id::read_access::freePosition, 2._sreal); + } + checkVecValues(positionCoefficient); + checkVecValues(velocityCoefficient); + } + + void plusEqualOtherPosition_2() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v += a + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::vec_id::read_access::restPosition, core::vec_id::read_access::position, 1._sreal); + } + checkVecSpatialValues(positionCoefficient + restPositionCoefficient); + checkVecValues(velocityCoefficient); + } + + void plusEqualOtherPositionMix_2() const + { + { + EXPECT_MSG_EMIT(Error); + //v += a + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::vec_id::read_access::freeVelocity, core::vec_id::read_access::position, 1._sreal); + } + checkVecSpatialValues(positionCoefficient); + checkVecValues(velocityCoefficient); + } + + void plusEqualOtherVelocity_2() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v += a + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::vec_id::read_access::force, core::vec_id::read_access::velocity, 1._sreal); + } + checkVecValues(positionCoefficient); + checkVecValues(velocityCoefficient + forceCoefficient); + } + + void plusEqualOtherVelocityMix_2() const + { + { + EXPECT_MSG_EMIT(Error); + //v += a + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::vec_id::read_access::freePosition, core::vec_id::read_access::velocity, 1._sreal); + } + checkVecValues(positionCoefficient); + checkVecValues(velocityCoefficient); + } + + void multipliedByScalarThenAddOtherPosition() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v = a+v*f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::vec_id::read_access::restPosition, core::vec_id::read_access::position, 3_sreal); + } + checkVecSpatialValues(restPositionCoefficient + positionCoefficient * 3); + checkVecValues(velocityCoefficient); + } + + void multipliedByScalarThenAddOtherPositionMix() const + { + { + EXPECT_MSG_EMIT(Error); + //v = a+v*f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::vec_id::read_access::freeVelocity, core::vec_id::read_access::position, 3_sreal); + } + checkVecSpatialValues(positionCoefficient); + checkVecValues(velocityCoefficient); + } + + void multipliedByScalarThenAddOtherVelocity() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v = a+v*f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::vec_id::read_access::force, core::vec_id::read_access::velocity, 7._sreal); + } + checkVecValues(positionCoefficient); + checkVecValues(velocityCoefficient * 7 + forceCoefficient); + } + + void multipliedByScalarThenAddOtherVelocityMix() const + { + { + EXPECT_MSG_EMIT(Error); + //v = a+v*f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::vec_id::read_access::freePosition, core::vec_id::read_access::velocity, 7._sreal); + } + checkVecValues(positionCoefficient); + checkVecValues(velocityCoefficient); + } + + void equalSumPosition() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v = a+b + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::vec_id::read_access::restPosition, core::vec_id::read_access::freePosition, 1_sreal); + } + checkVecSpatialValues(restPositionCoefficient + freePositionCoefficient); + checkVecValues(velocityCoefficient); + } + + void equalSumPositionMix1() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v = a+b + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::vec_id::read_access::restPosition, core::vec_id::read_access::freeVelocity, 1_sreal); + } + checkVecSpatialValues(restPositionCoefficient+freeVelocityCoefficient); + checkVecValues(velocityCoefficient); + } + + void equalSumPositionMix2() const + { + { + EXPECT_MSG_EMIT(Error); + //v = a+b + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::vec_id::read_access::freeVelocity, core::vec_id::read_access::freePosition, 1_sreal); + } + checkVecSpatialValues(positionCoefficient); + checkVecValues(velocityCoefficient); + } + + void equalSumVelocity() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v = a+b + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::vec_id::read_access::force, core::vec_id::read_access::freeVelocity, 1._sreal); + } + checkVecValues(positionCoefficient); + checkVecValues(forceCoefficient + freeVelocityCoefficient); + } + + void equalSumVelocityMix1() const + { + { + EXPECT_MSG_EMIT(Error); + //v = a+b + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::vec_id::read_access::position, core::vec_id::read_access::freeVelocity, 1._sreal); + } + checkVecValues(positionCoefficient); + checkVecValues(velocityCoefficient); + } + + void equalSumVelocityMix2() const + { + { + EXPECT_MSG_EMIT(Error); + //v = a+b + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::vec_id::read_access::force, core::vec_id::read_access::position, 1._sreal); + } + checkVecValues(positionCoefficient); + checkVecValues(velocityCoefficient); + } + + void equalSumWithScalarPosition() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v = a+b*f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::vec_id::read_access::restPosition, core::vec_id::read_access::freePosition, 12_sreal); + } + checkVecSpatialValues(restPositionCoefficient + freePositionCoefficient * 12); + checkVecValues(velocityCoefficient); + } + + void equalSumWithScalarPositionMix1() const + { + { + EXPECT_MSG_EMIT(Error); + //v = a+b*f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::vec_id::read_access::velocity, core::vec_id::read_access::freePosition, 12_sreal); + } + checkVecSpatialValues(positionCoefficient); + checkVecValues(velocityCoefficient); + } + + void equalSumWithScalarPositionMix2() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v = a+b*f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::position, core::vec_id::read_access::restPosition, core::vec_id::read_access::freeVelocity, 12_sreal); + } + checkVecSpatialValues(restPositionCoefficient + freeVelocityCoefficient * 12); + checkVecValues(velocityCoefficient); + } + + void equalSumWithScalarVelocity() const + { + { + EXPECT_MSG_NOEMIT(Error); + //v = a+b*f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::vec_id::read_access::force, core::vec_id::read_access::freeVelocity, 12_sreal); + } + checkVecSpatialValues(positionCoefficient); + checkVecValues(forceCoefficient + freeVelocityCoefficient * 12); + } + + void equalSumWithScalarVelocityMix1() const + { + { + EXPECT_MSG_EMIT(Error); + //v = a+b*f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::vec_id::read_access::position, core::vec_id::read_access::freeVelocity, 12_sreal); + } + checkVecSpatialValues(positionCoefficient); + checkVecValues(velocityCoefficient); + } + + void equalSumWithScalarVelocityMix2() const + { + { + EXPECT_MSG_EMIT(Error); + //v = a+b*f + m_mechanicalObject->vOp(nullptr, core::vec_id::write_access::velocity, core::vec_id::read_access::force, core::vec_id::read_access::position, 12_sreal); + } + checkVecSpatialValues(positionCoefficient); + checkVecValues(velocityCoefficient); + } + + typename MO::SPtr m_mechanicalObject; +}; + +typedef ::testing::Types< + defaulttype::Vec1Types, + defaulttype::Vec2Types, + defaulttype::Vec3Types, + defaulttype::Rigid2Types, + defaulttype::Rigid3Types +> DataTypesList; + +TYPED_TEST_SUITE(MechanicalObjectVOpTest, DataTypesList); + +TYPED_TEST(MechanicalObjectVOpTest, v_null) +{ + EXPECT_TRUE(this->v_null()); +} + +TYPED_TEST(MechanicalObjectVOpTest, resetPosition) +{ + this->resetPosition(); +} + +TYPED_TEST(MechanicalObjectVOpTest, resetVelocity) +{ + this->resetVelocity(); +} + +TYPED_TEST(MechanicalObjectVOpTest, multiplyByScalarPosition) +{ + this->multiplyByScalarPosition(); +} + +TYPED_TEST(MechanicalObjectVOpTest, multiplyByScalarVelocity) +{ + this->multiplyByScalarVelocity(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalOtherMultiplyByScalarPosition) +{ + this->equalOtherMultiplyByScalarPosition(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalOtherMultiplyByScalarVelocity) +{ + this->equalOtherMultiplyByScalarVelocity(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalOtherMultiplyByScalarPositionMix) +{ + this->equalOtherMultiplyByScalarPositionMix(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalOtherMultiplyByScalarVelocityMix) +{ + this->equalOtherMultiplyByScalarVelocityMix(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalOtherPosition) +{ + this->equalOtherPosition(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalOtherPositionMix) +{ + this->equalOtherPositionMix(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalOtherVelocity) +{ + this->equalOtherVelocity(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalOtherVelocityMix) +{ + this->equalOtherVelocityMix(); +} + +TYPED_TEST(MechanicalObjectVOpTest, plusEqualOtherPosition) +{ + this->plusEqualOtherPosition(); +} + +TYPED_TEST(MechanicalObjectVOpTest, plusEqualOtherPositionMix) +{ + this->plusEqualOtherPositionMix(); +} + +TYPED_TEST(MechanicalObjectVOpTest, plusEqualOtherVelocity) +{ + this->plusEqualOtherVelocity(); +} + +TYPED_TEST(MechanicalObjectVOpTest, plusEqualOtherVelocityMix) +{ + this->plusEqualOtherVelocityMix(); +} + +TYPED_TEST(MechanicalObjectVOpTest, plusEqualOtherMultipliedByScalarPosition) +{ + this->plusEqualOtherMultipliedByScalarPosition(); +} + +TYPED_TEST(MechanicalObjectVOpTest, plusEqualOtherMultipliedByScalarPositionMix) +{ + this->plusEqualOtherMultipliedByScalarPositionMix(); +} + +TYPED_TEST(MechanicalObjectVOpTest, plusEqualOtherMultipliedByScalarVelocity) +{ + this->plusEqualOtherMultipliedByScalarVelocity(); +} + +TYPED_TEST(MechanicalObjectVOpTest, plusEqualOtherMultipliedByScalarVelocityMix) +{ + this->plusEqualOtherMultipliedByScalarVelocityMix(); +} + +TYPED_TEST(MechanicalObjectVOpTest, plusEqualOtherPosition_2) +{ + this->plusEqualOtherPosition_2(); +} + +TYPED_TEST(MechanicalObjectVOpTest, plusEqualOtherPositionMix_2) +{ + this->plusEqualOtherPositionMix_2(); +} + +TYPED_TEST(MechanicalObjectVOpTest, plusEqualOtherVelocity_2) +{ + this->plusEqualOtherVelocity_2(); +} + +TYPED_TEST(MechanicalObjectVOpTest, plusEqualOtherVelocityMix_2) +{ + this->plusEqualOtherVelocityMix_2(); +} + +TYPED_TEST(MechanicalObjectVOpTest, multipliedByScalarThenAddOtherPosition) +{ + this->multipliedByScalarThenAddOtherPosition(); +} + +TYPED_TEST(MechanicalObjectVOpTest, multipliedByScalarThenAddOtherPositionMix) +{ + this->multipliedByScalarThenAddOtherPositionMix(); +} + +TYPED_TEST(MechanicalObjectVOpTest, multipliedByScalarThenAddOtherVelocity) +{ + this->multipliedByScalarThenAddOtherVelocity(); +} + +TYPED_TEST(MechanicalObjectVOpTest, multipliedByScalarThenAddOtherVelocityMix) +{ + this->multipliedByScalarThenAddOtherVelocityMix(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalSumPosition) +{ + this->equalSumPosition(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalSumPositionMix1) +{ + this->equalSumPositionMix1(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalSumPositionMix2) +{ + this->equalSumPositionMix2(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalSumVelocity) +{ + this->equalSumVelocity(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalSumVelocityMix1) +{ + this->equalSumVelocityMix1(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalSumVelocityMix2) +{ + this->equalSumVelocityMix2(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalSumWithScalarPosition) +{ + this->equalSumWithScalarPosition(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalSumWithScalarPositionMix1) +{ + this->equalSumWithScalarPositionMix1(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalSumWithScalarPositionMix2) +{ + this->equalSumWithScalarPositionMix2(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalSumWithScalarVelocity) +{ + this->equalSumWithScalarVelocity(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalSumWithScalarVelocityMix1) +{ + this->equalSumWithScalarVelocityMix1(); +} + +TYPED_TEST(MechanicalObjectVOpTest, equalSumWithScalarVelocityMix2) +{ + this->equalSumWithScalarVelocityMix2(); +} + +} \ No newline at end of file From 365940321143e545a865765cef669cb267f485e8 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Wed, 29 Jan 2025 21:39:51 +0100 Subject: [PATCH 4/4] [Core] Remove some static functions create (#5239) --- .../Core/src/sofa/core/Multi2Mapping.h | 17 ---------------- .../Core/src/sofa/core/MultiMapping.h | 20 ------------------- .../behavior/MixedInteractionConstraint.h | 15 -------------- .../AnimationLoopParallelScheduler.h | 11 ---------- 4 files changed, 63 deletions(-) diff --git a/Sofa/framework/Core/src/sofa/core/Multi2Mapping.h b/Sofa/framework/Core/src/sofa/core/Multi2Mapping.h index 6616b222fa2..c0ead569710 100644 --- a/Sofa/framework/Core/src/sofa/core/Multi2Mapping.h +++ b/Sofa/framework/Core/src/sofa/core/Multi2Mapping.h @@ -229,23 +229,6 @@ class Multi2Mapping : public BaseMapping return !error && BaseMapping::canCreate(obj, context, arg); } - /// Construction method called by ObjectFactory. - /// - /// This implementation read the input and output attributes to - /// find the input and output models of this mapping. - template - static typename T::SPtr create(T*, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg) - { - typename T::SPtr obj = sofa::core::objectmodel::New(); - - if (context) - context->addObject(obj); - - if (arg) - obj->parse(arg); - - return obj; - } protected: void getVecIn1Coord (const MultiVecCoordId id, type::vector< DataVecCoord_t*> &v) const diff --git a/Sofa/framework/Core/src/sofa/core/MultiMapping.h b/Sofa/framework/Core/src/sofa/core/MultiMapping.h index c6ecfe48c78..bc65f24d32f 100644 --- a/Sofa/framework/Core/src/sofa/core/MultiMapping.h +++ b/Sofa/framework/Core/src/sofa/core/MultiMapping.h @@ -231,26 +231,6 @@ class MultiMapping : public BaseMapping return BaseMapping::canCreate(obj, context, arg); } - /// Construction method called by ObjectFactory. - /// - /// This implementation read the input and output attributes to - /// find the input and output models of this mapping. - template - static typename T::SPtr create(T*, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg) - { - typename T::SPtr obj = sofa::core::objectmodel::New(); - - if (context) - context->addObject(obj); - - if (arg) - { - obj->parse(arg); - } - - return obj; - } - protected: void getVecInCoord (const MultiVecCoordId id, type::vector< InDataVecCoord* > &v) const diff --git a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionConstraint.h b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionConstraint.h index d2c82954415..51b2322c62e 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionConstraint.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionConstraint.h @@ -113,21 +113,6 @@ class MixedInteractionConstraint : public BaseInteractionConstraint, public Pair /// This is the method that should be implemented by the component virtual void buildConstraintMatrix(const ConstraintParams* cParams, DataMatrixDeriv1 &c1, DataMatrixDeriv2 &c2, unsigned int &cIndex , const DataVecCoord1 &x1, const DataVecCoord2 &x2) = 0; - - - /// Construction method called by ObjectFactory. - template - static typename T::SPtr create(T* p0, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg) - { - typename T::SPtr obj = core::behavior::BaseInteractionConstraint::create(p0, context, arg); - - if (arg) - { - obj->parse(arg); - } - - return obj; - } }; #if !defined(SOFA_CORE_BEHAVIOR_MIXEDINTERACTIONCONSTRAINT_CPP) diff --git a/applications/plugins/MultiThreading/src/MultiThreading/component/animationloop/AnimationLoopParallelScheduler.h b/applications/plugins/MultiThreading/src/MultiThreading/component/animationloop/AnimationLoopParallelScheduler.h index 18b2d8e9eb8..ecffebb8269 100644 --- a/applications/plugins/MultiThreading/src/MultiThreading/component/animationloop/AnimationLoopParallelScheduler.h +++ b/applications/plugins/MultiThreading/src/MultiThreading/component/animationloop/AnimationLoopParallelScheduler.h @@ -76,17 +76,6 @@ class SOFA_MULTITHREADING_PLUGIN_API AnimationLoopParallelScheduler : void step(const sofa::core::ExecParams* params, SReal dt) override; - /// Construction method called by ObjectFactory. - template - static typename T::SPtr create(T*, sofa::core::objectmodel::BaseContext* context, sofa::core::objectmodel::BaseObjectDescription* arg) - { - sofa::simulation::Node* gnode = dynamic_cast(context); - typename T::SPtr obj = sofa::core::objectmodel::New(gnode); - if (context) context->addObject(obj); - if (arg) obj->parse(arg); - return obj; - } - private : sofa::simulation::Node* gnode;