Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Plugin/src/SofaPython3/DataHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ BaseData* addData(py::object py_self, const std::string& name, py::object value,
data = PythonFactory::createInstance(type);
if (!data)
{
sofa::helper::vector<std::string> validTypes;
sofa::type::vector<std::string> validTypes;
PythonFactory::uniqueKeys(std::back_inserter(validTypes));
std::string typesString = "[";
for (const auto& i : validTypes)
Expand Down
88 changes: 44 additions & 44 deletions Plugin/src/SofaPython3/PythonFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,25 +449,25 @@ bool PythonFactory::registerDefaultTypes()
PythonFactory::registerType<int>("int");

// vectors
PythonFactory::registerType<sofa::defaulttype::Vec2d>("Vec2d");
PythonFactory::registerType<sofa::defaulttype::Vec3d>("Vec3d");
PythonFactory::registerType<sofa::defaulttype::Vec4d>("Vec4d");
PythonFactory::registerType<sofa::defaulttype::Vec6d>("Vec6d");
PythonFactory::registerType<sofa::defaulttype::Vec2f>("Vec2f");
PythonFactory::registerType<sofa::defaulttype::Vec3f>("Vec3f");
PythonFactory::registerType<sofa::defaulttype::Vec4f>("Vec4f");
PythonFactory::registerType<sofa::defaulttype::Vec6f>("Vec6f");
PythonFactory::registerType<sofa::type::Vec2d>("Vec2d");
PythonFactory::registerType<sofa::type::Vec3d>("Vec3d");
PythonFactory::registerType<sofa::type::Vec4d>("Vec4d");
PythonFactory::registerType<sofa::type::Vec6d>("Vec6d");
PythonFactory::registerType<sofa::type::Vec2f>("Vec2f");
PythonFactory::registerType<sofa::type::Vec3f>("Vec3f");
PythonFactory::registerType<sofa::type::Vec4f>("Vec4f");
PythonFactory::registerType<sofa::type::Vec6f>("Vec6f");

// Matrices
PythonFactory::registerType<sofa::defaulttype::Mat2x2d>("Mat2x2d");
PythonFactory::registerType<sofa::defaulttype::Mat3x3d>("Mat3x3d");
PythonFactory::registerType<sofa::defaulttype::Mat3x4d>("Mat3x4d");
PythonFactory::registerType<sofa::defaulttype::Mat4x4d>("Mat4x4d");
PythonFactory::registerType<sofa::type::Mat2x2d>("Mat2x2d");
PythonFactory::registerType<sofa::type::Mat3x3d>("Mat3x3d");
PythonFactory::registerType<sofa::type::Mat3x4d>("Mat3x4d");
PythonFactory::registerType<sofa::type::Mat4x4d>("Mat4x4d");

PythonFactory::registerType<sofa::defaulttype::Mat2x2f>("Mat2x2f");
PythonFactory::registerType<sofa::defaulttype::Mat3x3f>("Mat3x3f");
PythonFactory::registerType<sofa::defaulttype::Mat3x4f>("Mat3x4f");
PythonFactory::registerType<sofa::defaulttype::Mat4x4f>("Mat4x4f");
PythonFactory::registerType<sofa::type::Mat2x2f>("Mat2x2f");
PythonFactory::registerType<sofa::type::Mat3x3f>("Mat3x3f");
PythonFactory::registerType<sofa::type::Mat3x4f>("Mat3x4f");
PythonFactory::registerType<sofa::type::Mat4x4f>("Mat4x4f");

// Topology
PythonFactory::registerType<sofa::core::topology::Topology::Edge>("Edge");
Expand All @@ -486,47 +486,47 @@ bool PythonFactory::registerDefaultTypes()
for (const auto& container : containers)
{
// Scalars
PythonFactory::registerType<sofa::helper::vector<std::string>>(container + "<string>");
PythonFactory::registerType<sofa::helper::vector<float>>(container + "<float>");
PythonFactory::registerType<sofa::helper::vector<double>>(container + "<double>");
PythonFactory::registerType<sofa::helper::vector<bool>>(container + "<bool>");
PythonFactory::registerType<sofa::helper::vector<int>>(container + "<int>");
PythonFactory::registerType<sofa::type::vector<std::string>>(container + "<string>");
PythonFactory::registerType<sofa::type::vector<float>>(container + "<float>");
PythonFactory::registerType<sofa::type::vector<double>>(container + "<double>");
PythonFactory::registerType<sofa::type::vector<bool>>(container + "<bool>");
PythonFactory::registerType<sofa::type::vector<int>>(container + "<int>");

// vectors
PythonFactory::registerType<sofa::helper::vector<sofa::defaulttype::Vec2d>>(container + "<Vec2d>");
PythonFactory::registerType<sofa::helper::vector<sofa::defaulttype::Vec3d>>(container + "<Vec3d>");
PythonFactory::registerType<sofa::helper::vector<sofa::defaulttype::Vec4d>>(container + "<Vec4d>");
PythonFactory::registerType<sofa::helper::vector<sofa::defaulttype::Vec6d>>(container + "<Vec6d>");
PythonFactory::registerType<sofa::type::vector<sofa::type::Vec2d>>(container + "<Vec2d>");
PythonFactory::registerType<sofa::type::vector<sofa::type::Vec3d>>(container + "<Vec3d>");
PythonFactory::registerType<sofa::type::vector<sofa::type::Vec4d>>(container + "<Vec4d>");
PythonFactory::registerType<sofa::type::vector<sofa::type::Vec6d>>(container + "<Vec6d>");

PythonFactory::registerType<sofa::helper::vector<sofa::defaulttype::Vec2f>>(container + "<Vec2f>");
PythonFactory::registerType<sofa::helper::vector<sofa::defaulttype::Vec3f>>(container + "<Vec3f>");
PythonFactory::registerType<sofa::helper::vector<sofa::defaulttype::Vec4f>>(container + "<Vec4f>");
PythonFactory::registerType<sofa::helper::vector<sofa::defaulttype::Vec6f>>(container + "<Vec6f>");
PythonFactory::registerType<sofa::type::vector<sofa::type::Vec2f>>(container + "<Vec2f>");
PythonFactory::registerType<sofa::type::vector<sofa::type::Vec3f>>(container + "<Vec3f>");
PythonFactory::registerType<sofa::type::vector<sofa::type::Vec4f>>(container + "<Vec4f>");
PythonFactory::registerType<sofa::type::vector<sofa::type::Vec6f>>(container + "<Vec6f>");

// Matrices
PythonFactory::registerType<sofa::helper::vector<sofa::defaulttype::Mat2x2d>>(container + "<Mat2x2d>");
PythonFactory::registerType<sofa::helper::vector<sofa::defaulttype::Mat3x3d>>(container + "<Mat3x3d>");
PythonFactory::registerType<sofa::helper::vector<sofa::defaulttype::Mat3x4d>>(container + "<Mat3x4d>");
PythonFactory::registerType<sofa::helper::vector<sofa::defaulttype::Mat4x4d>>(container + "<Mat4x4d>");
PythonFactory::registerType<sofa::type::vector<sofa::type::Mat2x2d>>(container + "<Mat2x2d>");
PythonFactory::registerType<sofa::type::vector<sofa::type::Mat3x3d>>(container + "<Mat3x3d>");
PythonFactory::registerType<sofa::type::vector<sofa::type::Mat3x4d>>(container + "<Mat3x4d>");
PythonFactory::registerType<sofa::type::vector<sofa::type::Mat4x4d>>(container + "<Mat4x4d>");

PythonFactory::registerType<sofa::helper::vector<sofa::defaulttype::Mat2x2f>>(container + "<Mat2x2f>");
PythonFactory::registerType<sofa::helper::vector<sofa::defaulttype::Mat3x3f>>(container + "<Mat3x3f>");
PythonFactory::registerType<sofa::helper::vector<sofa::defaulttype::Mat3x4f>>(container + "<Mat3x4f>");
PythonFactory::registerType<sofa::helper::vector<sofa::defaulttype::Mat4x4f>>(container + "<Mat4x4f>");
PythonFactory::registerType<sofa::type::vector<sofa::type::Mat2x2f>>(container + "<Mat2x2f>");
PythonFactory::registerType<sofa::type::vector<sofa::type::Mat3x3f>>(container + "<Mat3x3f>");
PythonFactory::registerType<sofa::type::vector<sofa::type::Mat3x4f>>(container + "<Mat3x4f>");
PythonFactory::registerType<sofa::type::vector<sofa::type::Mat4x4f>>(container + "<Mat4x4f>");


// Topology
PythonFactory::registerType<sofa::helper::vector<sofa::core::topology::Topology::Edge>>(container + "<Edge>");
PythonFactory::registerType<sofa::helper::vector<sofa::core::topology::Topology::Triangle>>(container + "<Triangle>");
PythonFactory::registerType<sofa::helper::vector<sofa::core::topology::Topology::Quad>>(container + "<Quad>");
PythonFactory::registerType<sofa::helper::vector<sofa::core::topology::Topology::Tetra>>(container + "<Tetra>");
PythonFactory::registerType<sofa::helper::vector<sofa::core::topology::Topology::Hexa>>(container + "<Hexa>");
PythonFactory::registerType<sofa::helper::vector<sofa::core::topology::Topology::Penta>>(container + "<Penta>");
PythonFactory::registerType<sofa::type::vector<sofa::core::topology::Topology::Edge>>(container + "<Edge>");
PythonFactory::registerType<sofa::type::vector<sofa::core::topology::Topology::Triangle>>(container + "<Triangle>");
PythonFactory::registerType<sofa::type::vector<sofa::core::topology::Topology::Quad>>(container + "<Quad>");
PythonFactory::registerType<sofa::type::vector<sofa::core::topology::Topology::Tetra>>(container + "<Tetra>");
PythonFactory::registerType<sofa::type::vector<sofa::core::topology::Topology::Hexa>>(container + "<Hexa>");
PythonFactory::registerType<sofa::type::vector<sofa::core::topology::Topology::Penta>>(container + "<Penta>");
}
return true;
}

void PythonFactory::uniqueKeys(std::back_insert_iterator<sofa::helper::vector<std::string> > it)
void PythonFactory::uniqueKeys(std::back_insert_iterator<sofa::type::vector<std::string> > it)
{
std::transform(s_dataCreationFct.begin(), s_dataCreationFct.end(),
it, [](const auto& item){ return item.first; });
Expand Down
2 changes: 1 addition & 1 deletion Plugin/src/SofaPython3/PythonFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace sofapython3

static std::map<std::string, componentDowncastingFunction>::iterator searchLowestCastAvailable(const sofa::core::objectmodel::BaseClass* metaclass);

static void uniqueKeys(std::back_insert_iterator<sofa::helper::vector<std::string> > it);
static void uniqueKeys(std::back_insert_iterator<sofa::type::vector<std::string> > it);
private:
static bool registerDefaultEvents();
static bool registerDefaultTypes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void moduleAddSparseGridTopology(pybind11::module& m) {

// findCube (pos)
c.def("findCube", [](SparseGridTopology & self, const py::list & l) {
sofa::defaulttype::Vector3 pos;
sofa::type::Vector3 pos;
pos[0] = l[0].cast<double>();
pos[1] = l[1].cast<double>();
pos[2] = l[2].cast<double>();
Expand Down
52 changes: 26 additions & 26 deletions bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_BaseCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,52 +90,52 @@ void moduleAddBaseCamera(py::module &m)
c.def("getOpenGLModelViewMatrix", getOpenGLModelViewMatrix);

c.def("rotate", [](BaseCamera *self, py::list p){
sofa::defaulttype::Quat vec;
vec = sofa::defaulttype::Quat(py::cast<double>(p[0]),py::cast<double>(p[1]),py::cast<double>(p[2]),py::cast<double>(p[3]));
sofa::type::Quat<SReal> vec;
vec = sofa::type::Quat<SReal>(py::cast<double>(p[0]),py::cast<double>(p[1]),py::cast<double>(p[2]),py::cast<double>(p[3]));
self->rotate(vec);
});

c.def("rotateCameraAroundPoint", [](BaseCamera *self, py::list p1, py::list p2) {
sofa::defaulttype::Quat vec1;
sofa::defaulttype::Vec3 vec2;
vec1 = sofa::defaulttype::Quat(py::cast<double>(p1[0]),py::cast<double>(p1[1]),py::cast<double>(p1[2]),py::cast<double>(p1[3]));
vec2 = sofa::defaulttype::Vec3(py::cast<double>(p2[0]),py::cast<double>(p2[1]),py::cast<double>(p2[2]));
sofa::type::Quat<SReal> vec1;
sofa::type::Vec3 vec2;
vec1 = sofa::type::Quat<SReal>(py::cast<double>(p1[0]),py::cast<double>(p1[1]),py::cast<double>(p1[2]),py::cast<double>(p1[3]));
vec2 = sofa::type::Vec3(py::cast<double>(p2[0]),py::cast<double>(p2[1]),py::cast<double>(p2[2]));
self->rotateCameraAroundPoint(vec1, vec2);
});

c.def("getOrientationFromLookAt", [](BaseCamera *self, py::list p1, py::list p2) {
sofa::defaulttype::Vec3 vec1;
sofa::defaulttype::Vec3 vec2;
vec1 = sofa::defaulttype::Vec3(py::cast<double>(p1[0]),py::cast<double>(p1[1]),py::cast<double>(p1[2]));
vec2 = sofa::defaulttype::Vec3(py::cast<double>(p2[0]),py::cast<double>(p2[1]),py::cast<double>(p2[2]));
sofa::type::Vec3 vec1;
sofa::type::Vec3 vec2;
vec1 = sofa::type::Vec3(py::cast<double>(p1[0]),py::cast<double>(p1[1]),py::cast<double>(p1[2]));
vec2 = sofa::type::Vec3(py::cast<double>(p2[0]),py::cast<double>(p2[1]),py::cast<double>(p2[2]));
return (self->getOrientationFromLookAt(vec1, vec2));
});

c.def("getLookAtFromOrientation", [](BaseCamera *self, py::list pos, double distance, py::list quat) {
sofa::defaulttype::Vec3 position;
sofa::defaulttype::Quat orientation;
position = sofa::defaulttype::Vec3(py::cast<double>(pos[0]),py::cast<double>(pos[1]),py::cast<double>(pos[2]));
orientation = sofa::defaulttype::Quat(py::cast<double>(quat[0]),py::cast<double>(quat[1]),py::cast<double>(quat[2]),py::cast<double>(quat[3]));
sofa::type::Vec3 position;
sofa::type::Quat<SReal> orientation;
position = sofa::type::Vec3(py::cast<double>(pos[0]),py::cast<double>(pos[1]),py::cast<double>(pos[2]));
orientation = sofa::type::Quat<SReal>(py::cast<double>(quat[0]),py::cast<double>(quat[1]),py::cast<double>(quat[2]),py::cast<double>(quat[3]));
return (self->getLookAtFromOrientation(position, distance, orientation));
});

c.def("getPositionFromOrientation", [](BaseCamera *self, py::list p1, py::float_ p2, py::list p3) {
sofa::defaulttype::Vec3 vec1;
sofa::type::Vec3 vec1;
double vec2;
sofa::defaulttype::Quat vec3;
vec1 = sofa::defaulttype::Vec3(py::cast<double>(p1[0]),py::cast<double>(p1[1]),py::cast<double>(p1[2]));
sofa::type::Quat<SReal> vec3;
vec1 = sofa::type::Vec3(py::cast<double>(p1[0]),py::cast<double>(p1[1]),py::cast<double>(p1[2]));
vec2 = py::cast<double>(p2);
vec3 = sofa::defaulttype::Quat(py::cast<double>(p3[0]),py::cast<double>(p3[1]),py::cast<double>(p3[2]),py::cast<double>(p3[3]));
vec3 = sofa::type::Quat<SReal>(py::cast<double>(p3[0]),py::cast<double>(p3[1]),py::cast<double>(p3[2]),py::cast<double>(p3[3]));
return(self->getPositionFromOrientation(vec1, vec2, vec3));
});

c.def("getLookAtFromOrientation", [](BaseCamera *self, py::list p1, py::float_ p2, py::list p3) {
sofa::defaulttype::Vec3 vec1;
sofa::type::Vec3 vec1;
double vec2;
sofa::defaulttype::Quat vec3;
vec1 = sofa::defaulttype::Vec3(py::cast<double>(p1[0]),py::cast<double>(p1[1]),py::cast<double>(p1[2]));
sofa::type::Quat<SReal> vec3;
vec1 = sofa::type::Vec3(py::cast<double>(p1[0]),py::cast<double>(p1[1]),py::cast<double>(p1[2]));
vec2 = py::cast<double>(p2);
vec3 = sofa::defaulttype::Quat(py::cast<double>(p3[0]),py::cast<double>(p3[1]),py::cast<double>(p3[2]),py::cast<double>(p3[3]));
vec3 = sofa::type::Quat<SReal>(py::cast<double>(p3[0]),py::cast<double>(p3[1]),py::cast<double>(p3[2]),py::cast<double>(p3[3]));
return(self->getLookAtFromOrientation(vec1, vec2, vec3));
});

Expand All @@ -152,14 +152,14 @@ void moduleAddBaseCamera(py::module &m)
});

c.def("worldToScreenPoint", [](BaseCamera *self, py::list pos) {
sofa::defaulttype::Vec3 vec1;
vec1 = sofa::defaulttype::Vec3(py::cast<double>(pos[0]), py::cast<double>(pos[1]), py::cast<double>(pos[2]));
sofa::type::Vec3 vec1;
vec1 = sofa::type::Vec3(py::cast<double>(pos[0]), py::cast<double>(pos[1]), py::cast<double>(pos[2]));
return(self->worldToScreenPoint(vec1));
});

c.def("screenToWorldPoint", [](BaseCamera *self, py::list pos) {
sofa::defaulttype::Vec3 vec1;
vec1 = sofa::defaulttype::Vec3(py::cast<double>(pos[0]), py::cast<double>(pos[1]), py::cast<double>(pos[2]));
sofa::type::Vec3 vec1;
vec1 = sofa::type::Vec3(py::cast<double>(pos[0]), py::cast<double>(pos[1]), py::cast<double>(pos[2]));
return(self->screenToWorldPoint(vec1));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ using sofa::core::objectmodel::BaseNode;
#include "Binding_DataContainer.h"
#include "Binding_DataContainer_doc.h"

#include <sofa/defaulttype/BoundingBox.h>
#include <sofa/type/BoundingBox.h>

namespace sofapython3
{
Expand Down
6 changes: 3 additions & 3 deletions bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_Vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "Binding_Vector.h"

#include <sofa/helper/vector.h>
#include <sofa/type/vector.h>
#include <sofa/core/objectmodel/BaseData.h>

#include <pybind11/stl.h>
Expand All @@ -30,7 +30,7 @@ namespace py { using namespace pybind11; }


/**
* To add sofa::helper::vector types, follow the 2 steps below
* To add sofa::type::vector types, follow the 2 steps below
*/

// ------------------------------------
Expand All @@ -51,7 +51,7 @@ void declareVector(py::module &m, const std::string &typestr) {

std::string pyclass_name = std::string("Vector") + typestr;

py::class_<sofa::helper::vector<T>> (m, pyclass_name.c_str(), v);
py::class_<sofa::type::vector<T>> (m, pyclass_name.c_str(), v);
}

namespace sofapython3 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

#include <sofa/core/objectmodel/BaseData.h>
#include <sofa/core/objectmodel/Data.h>
#include <sofa/defaulttype/BoundingBox.h>
#include <sofa/type/BoundingBox.h>
#include <SofaPython3/PythonFactory.h>

using sofa::defaulttype::BoundingBox;
using sofa::type::BoundingBox;
using sofa::core::objectmodel::BaseData;

namespace py { using namespace pybind11; }
Expand Down Expand Up @@ -66,7 +66,7 @@ void moduleAddBoundingBox(py::module& m)
}, "sets the max bbox position from a python list");

bbox.def("getCenter", [](sofa::Data<BoundingBox>& bbox) {
const sofa::defaulttype::Vec3 val = bbox.getValue().maxBBox() - bbox.getValue().maxBBox();
const auto val = bbox.getValue().maxBBox() - bbox.getValue().maxBBox();
py::list list;
list.append(val[0]);
list.append(val[1]);
Expand Down
12 changes: 6 additions & 6 deletions bindings/SofaTypes/src/SofaPython3/SofaTypes/Binding_Mat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define BINDING_MAT_MAKE_NAME(R, C) \
std::string(std::string("Mat") + std::to_string(R) + "x" + std::to_string(C))

using namespace sofa::defaulttype;
using namespace sofa::type;

namespace pyMat {
template <sofa::Size R, sofa::Size C>
Expand Down Expand Up @@ -188,7 +188,7 @@ template <> struct MATRIX<1, 1> {

py::class_<MatClass> p(m, BINDING_MAT_MAKE_NAME(1, 1).c_str());
p.def(py::init([](py::list l) {
MatClass *mat = new MatClass(NOINIT);
MatClass *mat = new MatClass(sofa::type::NOINIT);
if (py::isinstance<py::list>(l[0])) // 2D array
{
for (sofa::Size i = 0; i < MatClass::nbLines; ++i) {
Expand Down Expand Up @@ -217,7 +217,7 @@ template <> struct MATRIX<2, 2> {
py::class_<MatClass> p(m, BINDING_MAT_MAKE_NAME(2, 2).c_str());
p.def(py::init<Row, Row>());
p.def(py::init([](py::list l) {
MatClass *mat = new MatClass(NOINIT);
MatClass *mat = new MatClass(sofa::type::NOINIT);
if (py::isinstance<py::list>(l[0])) // 2D array
{
for (sofa::Size i = 0; i < MatClass::nbLines; ++i) {
Expand Down Expand Up @@ -246,7 +246,7 @@ template <> struct MATRIX<3, 3> {
py::class_<MatClass> p(m, BINDING_MAT_MAKE_NAME(3, 3).c_str());
p.def(py::init<Row, Row, Row>());
p.def(py::init([](py::list l) {
MatClass *mat = new MatClass(NOINIT);
MatClass *mat = new MatClass(sofa::type::NOINIT);
if (py::isinstance<py::list>(l[0])) // 2D array
{
for (sofa::Size i = 0; i < MatClass::nbLines; ++i) {
Expand Down Expand Up @@ -275,7 +275,7 @@ template <> struct MATRIX<4, 4> {
py::class_<MatClass> p(m, BINDING_MAT_MAKE_NAME(4, 4).c_str());
p.def(py::init<Row, Row, Row, Row>());
p.def(py::init([](py::list l) {
MatClass *mat = new MatClass(NOINIT);
MatClass *mat = new MatClass(sofa::type::NOINIT);
if (py::isinstance<py::list>(l[0])) // 2D array
{
for (sofa::Size i = 0; i < MatClass::nbLines; ++i) {
Expand Down Expand Up @@ -304,7 +304,7 @@ template <> struct MATRIX<3, 4> {
py::class_<MatClass> p(m, BINDING_MAT_MAKE_NAME(3, 4).c_str());
p.def(py::init<Row, Row, Row>());
p.def(py::init([](py::list l) {
MatClass *mat = new MatClass(NOINIT);
MatClass *mat = new MatClass(sofa::type::NOINIT);
if (py::isinstance<py::list>(l[0])) // 2D array
{
for (sofa::Size i = 0; i < MatClass::nbLines; ++i) {
Expand Down
Loading