Skip to content

Commit 3ebaf13

Browse files
committed
Merge remote-tracking branch 'origin/master' into pr-typehint-example-how-to-fix-definition
2 parents 423ba9e + 9514a08 commit 3ebaf13

15 files changed

Lines changed: 171 additions & 188 deletions

File tree

bindings/Modules/tests/SofaConstraintSolver/matrix_access.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import unittest
22
import Sofa.Core
3-
import Sofa.Components
43
from Sofa import SofaConstraintSolver
54

65
class Test(unittest.TestCase):

bindings/Modules/tests/SofaLinearSolver/matrix_access.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import unittest
22
import Sofa.Core
3-
import Sofa.Components
43
from Sofa import SofaLinearSolver
54

65
class Test(unittest.TestCase):

bindings/Sofa/Bindings.SofaConfig.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ find_package(SofaPython3 QUIET REQUIRED COMPONENTS Plugin)
88
# Required by Bindings.Sofa.Helper, Bindings.Sofa.Types
99
find_package(Sofa.Core QUIET REQUIRED)
1010

11-
# Required by Bindings.Sofa.Core, Bindings.Sofa.Components
11+
# Required by Bindings.Sofa.Core
1212
find_package(Sofa.Simulation.Core QUIET REQUIRED)
1313

1414
# Required by Bindings.Sofa.Core

bindings/Sofa/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
project(Bindings.Sofa)
22

33
set(SOFABINDINGS_MODULE_LIST
4-
Components
54
Core
65
Helper
76
Simulation

bindings/Sofa/package/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@
161161
import Sofa.Core
162162
import Sofa.Simulation
163163
import Sofa.Types
164-
import Sofa.Components
165164
import SofaTypes
166165

167166
from .prefab import *

bindings/Sofa/src/SofaPython3/Sofa/Components/CMakeLists.txt

Lines changed: 0 additions & 21 deletions
This file was deleted.

bindings/Sofa/src/SofaPython3/Sofa/Components/Submodule_Components.cpp

Lines changed: 0 additions & 142 deletions
This file was deleted.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/******************************************************************************
2+
* SOFA, Simulation Open-Framework Architecture *
3+
* (c) 2021 INRIA, USTL, UJF, CNRS, MGH *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU Lesser General Public License as published by *
7+
* the Free Software Foundation; either version 2.1 of the License, or (at *
8+
* your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13+
* for more details. *
14+
* *
15+
* You should have received a copy of the GNU Lesser General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Contact information: contact@sofa-framework.org *
19+
******************************************************************************/
20+
#include <SofaPython3/Sofa/Types/Binding_CompressedRowSparseMatrix.h>
21+
22+
#include <sofa/core/objectmodel/BaseData.h>
23+
#include <sofa/core/objectmodel/Data.h>
24+
#include <sofa/defaulttype/RigidTypes.h>
25+
#include <sofa/linearalgebra/CompressedRowSparseMatrixConstraint.h>
26+
#include <pybind11/eigen.h>
27+
#include <sofa/linearalgebra/CompressedRowSparseMatrixConstraintEigenUtils.h>
28+
#include <sofa/type/trait/is_specialization_of.h>
29+
#include <SofaPython3/PythonFactory.h>
30+
31+
32+
namespace py { using namespace pybind11; }
33+
34+
namespace sofapython3
35+
{
36+
37+
template<class TBlock>
38+
typename sofa::linearalgebra::CompressedRowSparseMatrixToEigenSparseVec<TBlock>::EigenSparseMatrix
39+
toEigen(const sofa::linearalgebra::CompressedRowSparseMatrixConstraint<TBlock>& matrix)
40+
{
41+
static sofa::linearalgebra::CompressedRowSparseMatrixToEigenSparseVec<TBlock> convert;
42+
return convert(matrix);
43+
}
44+
45+
template<class MatrixDeriv>
46+
void bindCompressedRowSparseMatrixConstraint(pybind11::module& m)
47+
{
48+
static_assert(sofa::type::trait::is_specialization_of_v<MatrixDeriv, sofa::linearalgebra::CompressedRowSparseMatrixConstraint>,
49+
"Template argument must be a specialization of CompressedRowSparseMatrixConstraint");
50+
51+
py::class_<sofa::Data<MatrixDeriv>, sofa::core::objectmodel::BaseData,
52+
std::unique_ptr<sofa::Data<MatrixDeriv>, pybind11::nodelete> > crsmc(m, MatrixDeriv::Name() );
53+
54+
crsmc.def_property_readonly("value", [](sofa::Data<MatrixDeriv>& self)
55+
{
56+
sofa::helper::ReadAccessor accessor(self);
57+
return toEigen(accessor.ref());
58+
});
59+
60+
PythonFactory::registerType(MatrixDeriv::Name(), [](sofa::core::BaseData* data) -> py::object {
61+
auto matrix = reinterpret_cast<sofa::Data<MatrixDeriv>*>(data);
62+
return py::cast(matrix);
63+
});
64+
}
65+
66+
/**
67+
* Given a template parameter pack, create the bindings of all the templates in
68+
* the pack, making sure that there are no duplicate types.
69+
*/
70+
template <typename T, typename... Args>
71+
void bindAllCompressedRowSparseMatrixConstraintTypes(pybind11::module& m)
72+
{
73+
static_assert(!(std::is_same_v<T, Args> || ...), "Error: Duplicate types found!");
74+
75+
bindCompressedRowSparseMatrixConstraint<T>(m);
76+
if constexpr (sizeof...(Args) > 0)
77+
{
78+
bindAllCompressedRowSparseMatrixConstraintTypes<Args...>(m);
79+
}
80+
}
81+
82+
void moduleAddCompressedRowSparseMatrix(pybind11::module& m)
83+
{
84+
using namespace sofa::defaulttype;
85+
86+
bindAllCompressedRowSparseMatrixConstraintTypes<
87+
Vec1Types::MatrixDeriv,
88+
Vec2Types::MatrixDeriv,
89+
Vec3Types::MatrixDeriv,
90+
Vec6Types::MatrixDeriv,
91+
Rigid2Types::MatrixDeriv,
92+
Rigid3Types::MatrixDeriv
93+
>(m);
94+
}
95+
96+
}

bindings/Sofa/src/SofaPython3/Sofa/Components/Submodule_Components.h renamed to bindings/Sofa/src/SofaPython3/Sofa/Types/Binding_CompressedRowSparseMatrix.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222

2323
#include <pybind11/pybind11.h>
2424

25-
namespace sofapython3
26-
{
27-
namespace py { using namespace pybind11; }
25+
namespace sofapython3 {
2826

29-
} ///namespace sofapython3
27+
void moduleAddCompressedRowSparseMatrix(pybind11::module& m);
3028

29+
} // namespace sofapython3

bindings/Sofa/src/SofaPython3/Sofa/Types/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ project(Bindings.Sofa.Types)
22

33
set(HEADER_FILES
44
${CMAKE_CURRENT_SOURCE_DIR}/Binding_BoundingBox.h
5+
${CMAKE_CURRENT_SOURCE_DIR}/Binding_CompressedRowSparseMatrix.h
56
)
67

78
set(SOURCE_FILES
89
${CMAKE_CURRENT_SOURCE_DIR}/Submodule_Types.cpp
10+
${CMAKE_CURRENT_SOURCE_DIR}/Binding_CompressedRowSparseMatrix.cpp
911
${CMAKE_CURRENT_SOURCE_DIR}/Binding_BoundingBox.cpp
1012
)
1113

0 commit comments

Comments
 (0)