From 68f9f1bdd7df08d0b88d90da9c6e03219db98643 Mon Sep 17 00:00:00 2001 From: Paul Baksic Date: Wed, 15 Jul 2026 17:01:38 +0200 Subject: [PATCH] Remove plugin from sources and add it to the preset --- CMakePresets.json | 12 +- applications/plugins/CMakeLists.txt | 2 +- .../plugins/SofaImplicitField/CMakeLists.txt | 65 --- .../SofaImplicitField/MarchingCube.cpp | 165 -------- .../plugins/SofaImplicitField/MarchingCube.h | 83 ---- .../plugins/SofaImplicitField/README.md | 4 - .../SofaImplicitFieldConfig.cmake.in | 21 - .../SofaImplicitField_test/CMakeLists.txt | 14 - .../ImplicitShape_test.cpp | 53 --- .../components/engine/FieldToSurfaceMesh.cpp | 174 -------- .../components/engine/FieldToSurfaceMesh.h | 102 ----- .../components/geometry/BottleField.cpp | 171 -------- .../components/geometry/BottleField.h | 84 ---- .../components/geometry/DiscreteGridField.cpp | 376 ------------------ .../components/geometry/DiscreteGridField.h | 99 ----- .../components/geometry/ScalarField.cpp | 291 -------------- .../components/geometry/ScalarField.h | 143 ------- .../components/geometry/SphericalField.cpp | 112 ------ .../components/geometry/SphericalField.h | 83 ---- .../components/geometry/StarShapedField.cpp | 137 ------- .../components/geometry/StarShapedField.h | 79 ---- .../mapping/ImplicitSurfaceMapping.cpp | 41 -- .../mapping/ImplicitSurfaceMapping.h | 164 -------- .../mapping/ImplicitSurfaceMapping.inl | 164 -------- .../plugins/SofaImplicitField/config.h.in | 37 -- .../deprecated/ImplicitSurfaceContainer.h | 50 --- .../deprecated/ImplicitSurfaceMapping.h | 1 - .../deprecated/ImplicitSurfaceMapping.inl | 1 - .../InterpolatedImplicitSurface.cpp | 18 - .../deprecated/InterpolatedImplicitSurface.h | 52 --- .../deprecated/SphereSurface.cpp | 30 -- .../deprecated/SphereSurface.h | 29 -- .../examples/ImplicitSurfaceMapping.scn | 25 -- .../example-mesh-extraction-from-implicit.py | 53 --- .../examples/python/python-scalarfield.py | 50 --- .../examples/python/xshape/__init__.py | 0 .../examples/python/xshape/operators.py | 35 -- .../examples/python/xshape/primitives.py | 34 -- .../examples/python/xshape/transforms.py | 15 - .../initSofaImplicitField.cpp | 115 ------ .../SofaImplicitField/initSofaImplicitField.h | 37 -- .../SofaImplicitField/python/CMakeLists.txt | 26 -- .../python/src/Binding_ScalarField.cpp | 140 ------- .../python/src/Binding_ScalarField.h | 29 -- .../python/src/Module_SofaImplicitField.cpp | 38 -- 45 files changed, 9 insertions(+), 3445 deletions(-) delete mode 100644 applications/plugins/SofaImplicitField/CMakeLists.txt delete mode 100644 applications/plugins/SofaImplicitField/MarchingCube.cpp delete mode 100644 applications/plugins/SofaImplicitField/MarchingCube.h delete mode 100644 applications/plugins/SofaImplicitField/README.md delete mode 100644 applications/plugins/SofaImplicitField/SofaImplicitFieldConfig.cmake.in delete mode 100644 applications/plugins/SofaImplicitField/SofaImplicitField_test/CMakeLists.txt delete mode 100644 applications/plugins/SofaImplicitField/SofaImplicitField_test/ImplicitShape_test.cpp delete mode 100644 applications/plugins/SofaImplicitField/components/engine/FieldToSurfaceMesh.cpp delete mode 100644 applications/plugins/SofaImplicitField/components/engine/FieldToSurfaceMesh.h delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/BottleField.cpp delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/BottleField.h delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/DiscreteGridField.cpp delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/DiscreteGridField.h delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/ScalarField.cpp delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/ScalarField.h delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/SphericalField.cpp delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/SphericalField.h delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/StarShapedField.cpp delete mode 100644 applications/plugins/SofaImplicitField/components/geometry/StarShapedField.h delete mode 100644 applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.cpp delete mode 100644 applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.h delete mode 100644 applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.inl delete mode 100644 applications/plugins/SofaImplicitField/config.h.in delete mode 100644 applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceContainer.h delete mode 100644 applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceMapping.h delete mode 100644 applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceMapping.inl delete mode 100644 applications/plugins/SofaImplicitField/deprecated/InterpolatedImplicitSurface.cpp delete mode 100644 applications/plugins/SofaImplicitField/deprecated/InterpolatedImplicitSurface.h delete mode 100644 applications/plugins/SofaImplicitField/deprecated/SphereSurface.cpp delete mode 100644 applications/plugins/SofaImplicitField/deprecated/SphereSurface.h delete mode 100644 applications/plugins/SofaImplicitField/examples/ImplicitSurfaceMapping.scn delete mode 100644 applications/plugins/SofaImplicitField/examples/python/example-mesh-extraction-from-implicit.py delete mode 100644 applications/plugins/SofaImplicitField/examples/python/python-scalarfield.py delete mode 100644 applications/plugins/SofaImplicitField/examples/python/xshape/__init__.py delete mode 100644 applications/plugins/SofaImplicitField/examples/python/xshape/operators.py delete mode 100644 applications/plugins/SofaImplicitField/examples/python/xshape/primitives.py delete mode 100644 applications/plugins/SofaImplicitField/examples/python/xshape/transforms.py delete mode 100644 applications/plugins/SofaImplicitField/initSofaImplicitField.cpp delete mode 100644 applications/plugins/SofaImplicitField/initSofaImplicitField.h delete mode 100644 applications/plugins/SofaImplicitField/python/CMakeLists.txt delete mode 100644 applications/plugins/SofaImplicitField/python/src/Binding_ScalarField.cpp delete mode 100644 applications/plugins/SofaImplicitField/python/src/Binding_ScalarField.h delete mode 100644 applications/plugins/SofaImplicitField/python/src/Module_SofaImplicitField.cpp diff --git a/CMakePresets.json b/CMakePresets.json index 29dd152ed01..5d8af5429fc 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -214,6 +214,14 @@ "PLUGIN_MODELORDERREDUCTION": { "type": "BOOL", "value": "ON" + }, + "SOFA_FETCH_SOFAIMPLICITFIELD": { + "type": "BOOL", + "value": "ON" + }, + "PLUGIN_SOFAIMPLICITFIELD": { + "type": "BOOL", + "value": "ON" } } }, @@ -256,10 +264,6 @@ "type": "BOOL", "value": "ON" }, - "PLUGIN_SOFAIMPLICITFIELD": { - "type": "BOOL", - "value": "ON" - }, "SOFA_FETCH_SOFASPHFLUID": { "type": "BOOL", "value": "ON" diff --git a/applications/plugins/CMakeLists.txt b/applications/plugins/CMakeLists.txt index 736fbf72423..fcab7fe3da7 100644 --- a/applications/plugins/CMakeLists.txt +++ b/applications/plugins/CMakeLists.txt @@ -73,4 +73,4 @@ else() endif() sofa_add_subdirectory(plugin SofaDistanceGrid SofaDistanceGrid) # Also defines SofaDistanceGrid.CUDA -sofa_add_subdirectory(plugin SofaImplicitField SofaImplicitField) +sofa_add_external(plugin SofaImplicitField GIT_REF master GIT_REPOSITORY https://www.github.com/sofa-framework/SofaImplicitField.git) diff --git a/applications/plugins/SofaImplicitField/CMakeLists.txt b/applications/plugins/SofaImplicitField/CMakeLists.txt deleted file mode 100644 index aca4a06b47b..00000000000 --- a/applications/plugins/SofaImplicitField/CMakeLists.txt +++ /dev/null @@ -1,65 +0,0 @@ -cmake_minimum_required(VERSION 3.22) -project(SofaImplicitField VERSION 1.0) - -sofa_find_package(Sofa.Component.Topology.Container.Constant REQUIRED) - -set(HEADER_FILES - config.h.in - initSofaImplicitField.h - MarchingCube.h - - # This is backward compatibility - deprecated/SphereSurface.h - deprecated/ImplicitSurfaceContainer.h # This is a backward compatibility file toward ScalarField - deprecated/InterpolatedImplicitSurface.h # This is a backward compatibility file toward DiscreteGridField - - components/engine/FieldToSurfaceMesh.h - components/geometry/BottleField.h - components/geometry/DiscreteGridField.h - components/geometry/SphericalField.h - components/geometry/ScalarField.h - components/geometry/StarShapedField.h - components/mapping/ImplicitSurfaceMapping.h - components/mapping/ImplicitSurfaceMapping.inl -) - -set(SOURCE_FILES - initSofaImplicitField.cpp - MarchingCube.cpp - - ## This is a backward compatibility.. - deprecated/SphereSurface.cpp - deprecated/InterpolatedImplicitSurface.cpp - - components/engine/FieldToSurfaceMesh.cpp - components/geometry/BottleField.cpp - components/geometry/ScalarField.cpp - components/geometry/DiscreteGridField.cpp - components/geometry/SphericalField.cpp - components/geometry/StarShapedField.cpp - components/mapping/ImplicitSurfaceMapping.cpp -) - -set(EXTRA_FILES - README.md - ) - -if(SOFA_BUILD_TESTS) - add_subdirectory(SofaImplicitField_test) -endif() - -add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${EXTRA_FILES}) -target_link_libraries(${PROJECT_NAME} PRIVATE Sofa.Component.Topology.Container.Constant) - -find_package(SofaPython3 REQUIRED) -if (SofaPython3_FOUND) - add_subdirectory(python) -endif() - -## Install rules for the library and headers; CMake package configurations files -sofa_create_package_with_targets( - PACKAGE_NAME ${PROJECT_NAME} - PACKAGE_VERSION ${PROJECT_VERSION} - TARGETS ${PROJECT_NAME} AUTO_SET_TARGET_PROPERTIES - RELOCATABLE "plugins" - ) diff --git a/applications/plugins/SofaImplicitField/MarchingCube.cpp b/applications/plugins/SofaImplicitField/MarchingCube.cpp deleted file mode 100644 index 4a7d0098b20..00000000000 --- a/applications/plugins/SofaImplicitField/MarchingCube.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2025 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 -#include -#include -#include -#include - -namespace sofaimplicitfield -{ - -void MarchingCube::generateSurfaceMesh(const double isoval, const double mstep, const double invStep, - const Vec3d& gridmin, const Vec3d& gridmax, - std::function&, std::vector&)> getFieldValueAt, - SeqCoord& tmpPoints, SeqTriangles& tmpTriangles) -{ - int nx = floor((gridmax.x() - gridmin.x()) * invStep) + 1 ; - int ny = floor((gridmax.y() - gridmin.y()) * invStep) + 1 ; - int nz = floor((gridmax.z() - gridmin.z()) * invStep) + 1 ; - - // Marching cubes only works for a grid size larger than two - if( nz < 2 || ny < 2 || nx < 2 ) - return; - - double cx,cy,cz; - int z,mk; - const int *tri; - - // Creates two planes - CubeData c{{-1,-1,-1},0}; - planes.resize(2*nx*ny); - for(size_t i=0;i &positions, std::vector& output, - double mstep, double gridmin_y, double gridmin_x, int ny, int nx, float cz, - std::vector::iterator itDestPlane) - { - for (int i=0, y = 0 ; y < ny ; ++y) - { - double cy = gridmin_y + mstep * y ; - for (int x = 0 ; x < nx ; ++x) - { - double cx = gridmin_x + mstep * x ; - positions[i++].set(cx, cy, cz ); - } - } - getFieldValueAt(positions, output) ; - - for(auto res : output){ - itDestPlane->data = res; - itDestPlane++; - } - }; - - std::vector positions; - std::vector output; - positions.resize(nx*ny); - output.resize(nx*ny); - - fillPlane(positions, output, mstep, gridmin.y(), gridmin.x(), ny, nx, gridmin.z(), P0); - for (z=1; z<=nz; ++z) - { - fillPlane(positions, output, mstep, gridmin.y(), gridmin.x(), ny, nx, gridmin.z() + mstep * z, P1); - - int edgecube[12]; - const int edgepts[12] = {0,1,0,1,0,1,0,1,2,2,2,2}; - typename std::vector::iterator base = planes.begin(); - int ip0 = P0-base; - int ip1 = P1-base; - edgecube[0] = (ip0 -dy); - edgecube[1] = (ip0 ); - edgecube[2] = (ip0 ); - edgecube[3] = (ip0-dx ); - edgecube[4] = (ip1 -dy); - edgecube[5] = (ip1 ); - edgecube[6] = (ip1 ); - edgecube[7] = (ip1-dx ); - edgecube[8] = (ip1-dx-dy); - edgecube[9] = (ip1-dy ); - edgecube[10] = (ip1 ); - edgecube[11] = (ip1-dx ); - - unsigned int di = nx; - for(int y=1; ydata>isoval)^((P1+di-dx)->data>isoval)) - { - (P1+di)->p[0] = addPoint(tmpPoints, 0, pos,gridmin, (P1+di)->data,(P1+di-dx)->data, mstep, isoval); - } - if (((P1+di)->data>isoval)^((P1+di-dy)->data>isoval)) - { - (P1+di)->p[1] = addPoint(tmpPoints, 1, pos,gridmin,(P1+di)->data,(P1+di-dy)->data, mstep, isoval); - } - if (((P1+di)->data>isoval)^((P0+di)->data>isoval)) - { - (P1+di)->p[2] = addPoint(tmpPoints, 2, pos,gridmin,(P1+di)->data,(P0+di)->data, mstep, isoval); - } - - // All points should now be created - if ((P0+di-dx-dy)->data > isoval) mk = 1; - else mk=0; - if ((P0+di -dy)->data > isoval) mk|= 2; - if ((P0+di )->data > isoval) mk|= 4; - if ((P0+di-dx )->data > isoval) mk|= 8; - if ((P1+di-dx-dy)->data > isoval) mk|= 16; - if ((P1+di -dy)->data > isoval) mk|= 32; - if ((P1+di )->data > isoval) mk|= 64; - if ((P1+di-dx )->data > isoval) mk|= 128; - - tri=sofa::helper::MarchingCubeTriTable[mk]; - while (*tri>=0) - { - typename std::vector::iterator b = base+di; - addFace(tmpTriangles, - (b+edgecube[tri[0]])->p[edgepts[tri[0]]], - (b+edgecube[tri[1]])->p[edgepts[tri[1]]], - (b+edgecube[tri[2]])->p[edgepts[tri[2]]], tmpPoints.size()); - tri+=3; - } - ++di; - } - } - std::swap(P0, P1); - } -} - -} diff --git a/applications/plugins/SofaImplicitField/MarchingCube.h b/applications/plugins/SofaImplicitField/MarchingCube.h deleted file mode 100644 index 394a6163b1c..00000000000 --- a/applications/plugins/SofaImplicitField/MarchingCube.h +++ /dev/null @@ -1,83 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2025 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 - -//////////////////////////////////////////////////////////////////////////////////////////////////// -namespace sofaimplicitfield -{ - -typedef sofa::core::topology::BaseMeshTopology::SeqTriangles SeqTriangles; -typedef sofa::core::topology::BaseMeshTopology::Triangle Triangle; -typedef sofa::type::vector SeqCoord; -using sofa::type::Vec3d; - -class MarchingCube -{ -public: - void generateSurfaceMesh(const double isoval, const double mstep, const double invStep, - const Vec3d& gridmin, const Vec3d& gridmax, - std::function &, std::vector &)> field, - SeqCoord& tmpPoints, SeqTriangles& tmpTriangles); - -private: - /// For each cube, store the vertex indices on each 3 first edges, and the data value - struct CubeData - { - int p[3]; - double data; - }; - - sofa::type::vector planes; - typename sofa::type::vector::iterator P0; /// Pointer to first plane - typename sofa::type::vector::iterator P1; /// Pointer to second plane - - int addPoint(SeqCoord& v, int i, Vec3d pos, const Vec3d& gridmin, double v0, double v1, double step, double iso) - { - pos[i] -= (iso-v0)/(v1-v0); - v.push_back( (pos * step)+gridmin ) ; - return v.size()-1; - } - - int addFace(SeqTriangles& triangles, int p1, int p2, int p3, int nbp) - { - if ((unsigned)p1<(unsigned)nbp && - (unsigned)p2<(unsigned)nbp && - (unsigned)p3<(unsigned)nbp) - { - triangles.push_back(Triangle(p1, p3, p2)); - return triangles.size()-1; - } - else - { - return -1; - } - } -}; - - -} - diff --git a/applications/plugins/SofaImplicitField/README.md b/applications/plugins/SofaImplicitField/README.md deleted file mode 100644 index 73b1bda083b..00000000000 --- a/applications/plugins/SofaImplicitField/README.md +++ /dev/null @@ -1,4 +0,0 @@ -= ImplicitField plugin. - - - diff --git a/applications/plugins/SofaImplicitField/SofaImplicitFieldConfig.cmake.in b/applications/plugins/SofaImplicitField/SofaImplicitFieldConfig.cmake.in deleted file mode 100644 index f7535c7e032..00000000000 --- a/applications/plugins/SofaImplicitField/SofaImplicitFieldConfig.cmake.in +++ /dev/null @@ -1,21 +0,0 @@ -# CMake package configuration file for the SofaImplicitField plugin - -@PACKAGE_GUARD@ -@PACKAGE_INIT@ - -set(SOFAIMPLICITFIELD_HAVE_SOFADISTANCEGRID @SOFAIMPLICITFIELD_HAVE_SOFADISTANCEGRID@) - -find_package(Sofa.Framework QUIET REQUIRED) - -if(SOFAIMPLICITFIELD_HAVE_SOFADISTANCEGRID) - find_package(SofaDistanceGrid QUIET REQUIRED) -endif() - -if(NOT TARGET SofaImplicitField) - include("${CMAKE_CURRENT_LIST_DIR}/SofaImplicitFieldTargets.cmake") -endif() - -check_required_components(SofaImplicitField) -set(SofaImplicitField_LIBRARIES SofaImplicitField) -set(SofaImplicitField_INCLUDE_DIRS @PACKAGE_SOFAIMPLICITFIELD_INCLUDE_DIR@ ${SOFAIMPLICITFIELD_INCLUDE_DIR}) - diff --git a/applications/plugins/SofaImplicitField/SofaImplicitField_test/CMakeLists.txt b/applications/plugins/SofaImplicitField/SofaImplicitField_test/CMakeLists.txt deleted file mode 100644 index b4042f0c308..00000000000 --- a/applications/plugins/SofaImplicitField/SofaImplicitField_test/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -project(SofaImplicitField_test) - -set(SOURCE_FILES - ImplicitShape_test.cpp -) - - - -add_executable(${PROJECT_NAME} ${SOURCE_FILES}) -target_link_libraries(${PROJECT_NAME} Sofa.Testing SofaImplicitField) - -add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME}) diff --git a/applications/plugins/SofaImplicitField/SofaImplicitField_test/ImplicitShape_test.cpp b/applications/plugins/SofaImplicitField/SofaImplicitField_test/ImplicitShape_test.cpp deleted file mode 100644 index f48bc8cccfb..00000000000 --- a/applications/plugins/SofaImplicitField/SofaImplicitField_test/ImplicitShape_test.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/****************************************************************************** -* 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 General Public License as published by the Free * -* Software Foundation; either version 2 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 General Public License for * -* more details. * -* * -* You should have received a copy of the GNU 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 -using sofa::type::Vec3d ; - -#include -using sofa::component::geometry::SphericalField ; - -namespace -{ - -class SphericalFieldTest : public sofa::testing::BaseTest -{ -public: - bool checkSphericalField(); - bool checkDiscreteGridField(); -}; - - -bool SphericalFieldTest::checkSphericalField() -{ - SphericalField sphere_test; - Vec3d p(1,1,2); - sphere_test.getValue(p) ; - return true; -} - - -TEST_F(SphericalFieldTest, checkSphericalField) { ASSERT_TRUE( checkSphericalField() ); } - -} diff --git a/applications/plugins/SofaImplicitField/components/engine/FieldToSurfaceMesh.cpp b/applications/plugins/SofaImplicitField/components/engine/FieldToSurfaceMesh.cpp deleted file mode 100644 index e42e18467a9..00000000000 --- a/applications/plugins/SofaImplicitField/components/engine/FieldToSurfaceMesh.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2025 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 -using sofa::core::visual::VisualParams ; - -#include -using sofa::core::RegisterObject ; - -#include - -#include "FieldToSurfaceMesh.h" - -namespace sofaimplicitfield::component::engine -{ - -FieldToSurfaceMesh::FieldToSurfaceMesh() - : l_field(initLink("field", "The scalar field to generate a mesh from.")) - , d_step(initData(&d_step,0.1,"step","Step")) - , d_IsoValue(initData(&d_IsoValue,0.0,"isoValue","Iso Value")) - , d_gridMin(initData(&d_gridMin, Vec3d(-1,-1,-1),"min","Grid Min")) - , d_gridMax(initData(&d_gridMax, Vec3d(1,1,1),"max","Grid Max")) - , d_outPoints(initData(&d_outPoints, "points", "position of the tiangles vertex")) - , d_outTriangles(initData(&d_outTriangles, "triangles", "list of triangles")) - , d_debugDraw(initData(&d_debugDraw,false, "debugDraw","Display the extracted surface")) -{ - addUpdateCallback("updateMesh", {&d_step, &d_IsoValue, &d_gridMin, &d_gridMax}, [this](const sofa::core::DataTracker&) - { - checkInputs(); - updateMeshIfNeeded(); - return core::objectmodel::ComponentState::Valid; - }, {&d_outPoints, &d_outTriangles}); - d_outPoints.setGroup("Output"); - d_outTriangles.setGroup("Output"); -} - -FieldToSurfaceMesh::~FieldToSurfaceMesh() -{ -} - -void FieldToSurfaceMesh::init() -{ - if(!l_field.get()) - { - msg_error() << "Missing field to extract surface from"; - d_componentState = core::objectmodel::ComponentState::Invalid; - } - - d_componentState = core::objectmodel::ComponentState::Valid; -} - -void FieldToSurfaceMesh::computeBBox(const core::ExecParams* /* params */, bool /*onlyVisible*/) -{ - f_bbox.setValue({d_gridMin.getValue(), d_gridMax.getValue()}); -} - -void FieldToSurfaceMesh::checkInputs(){ - - auto length = d_gridMax.getValue()-d_gridMin.getValue() ; - auto step = d_step.getValue(); - - // clamp the mStep value to avoid too large grids - if( step < 0.0001 || (length.x() / step > 256) || length.y() / step > 256 || length.z() / step > 256) - { - d_step.setValue( *std::max_element(length.begin(), length.end()) / 256.0 ); - msg_warning() << "step exceeding grid size, clamped to " << d_step.getValue(); - } -} - -void FieldToSurfaceMesh::updateMeshIfNeeded() -{ - sofa::helper::getWriteOnlyAccessor(d_outPoints).clear(); - sofa::helper::getWriteOnlyAccessor(d_outTriangles).clear(); - - double isoval = d_IsoValue.getValue(); - double mstep = d_step.getValue(); - double invStep = 1.0/d_step.getValue(); - - Vec3d gridmin = d_gridMin.getValue() ; - Vec3d gridmax = d_gridMax.getValue() ; - - auto field = l_field.get(); - - if(!field) - return; - - // Clear the previously used buffer - tmpPoints.clear(); - tmpTriangles.clear(); - - marchingCube.generateSurfaceMesh(isoval, mstep, invStep, gridmin, gridmax, - [field](std::vector& positions, std::vector& res){ - int i=0; - for(auto& position : positions) - { - res[i++]=field->getValue(position); - } - }, - tmpPoints, tmpTriangles); - - /// Copy the surface to Sofa topology - d_outPoints.setValue(tmpPoints); - d_outTriangles.setValue(tmpTriangles); - - tmpPoints.clear(); - tmpTriangles.clear(); - - hasChanged = false; - return; -} - -void FieldToSurfaceMesh::draw(const VisualParams* vparams) -{ - if(isComponentStateInvalid()) - return; - - if(!d_debugDraw.getValue()) - return; - - auto drawTool = vparams->drawTool(); - - sofa::helper::ReadAccessor< Data > x = d_outPoints; - sofa::helper::ReadAccessor< Data > triangles = d_outTriangles; - drawTool->setLightingEnabled(true); - - for(const Triangle& triangle : triangles) - { - int a = triangle[0]; - int b = triangle[1]; - int c = triangle[2]; - Vec3d center = (x[a]+x[b]+x[c])*0.333333; - Vec3d pa = (0.9*x[a]+0.1*center) ; - Vec3d pb = (0.9*x[b]+0.1*center) ; - Vec3d pc = (0.9*x[c]+0.1*center) ; - - vparams->drawTool()->drawTriangles({pb,pa,pc}, - type::RGBAColor(0.0,0.0,1.0,1.0)); - } - - if(x.size()>1000){ - drawTool->drawPoints(x, 1.0, type::RGBAColor(1.0,1.0,0.0,0.2)) ; - }else{ - drawTool->drawSpheres(x, 0.01, type::RGBAColor(1.0,1.0,0.0,0.2)) ; - } -} - -// Register in the Factory -void registerFieldToSurfaceMesh(sofa::core::ObjectFactory* factory) -{ - factory->registerObjects(sofa::core::ObjectRegistrationData("Generates a surface mesh from a field function.") - .add< FieldToSurfaceMesh >()); -} - -} diff --git a/applications/plugins/SofaImplicitField/components/engine/FieldToSurfaceMesh.h b/applications/plugins/SofaImplicitField/components/engine/FieldToSurfaceMesh.h deleted file mode 100644 index e92783b020e..00000000000 --- a/applications/plugins/SofaImplicitField/components/engine/FieldToSurfaceMesh.h +++ /dev/null @@ -1,102 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2025 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 - -//////////////////////////////////////////////////////////////////////////////////////////////////// -namespace sofaimplicitfield::component::engine -{ -using namespace sofa; - -typedef sofa::core::topology::BaseMeshTopology::SeqTriangles SeqTriangles; -typedef sofa::core::topology::BaseMeshTopology::Triangle Triangle; -typedef sofa::type::vector VecCoord; - -using sofa::component::geometry::ScalarField; -using sofa::core::visual::VisualParams ; -using BaseObject [[deprecated("Use sofa::core::objectmodel::BaseObject instead.")]] = sofa::core::objectmodel::BaseObject; -using sofa::type::Vec3d ; - -class FieldToSurfaceMesh : public BaseObject -{ -public: - SOFA_CLASS(FieldToSurfaceMesh, BaseObject); - - virtual void init() override ; - virtual void draw(const VisualParams*params) override ; - - double getStep() const { return d_step.getValue(); } - void setStep(double val) { d_step.setValue(val); } - - double getIsoValue() const { return d_IsoValue.getValue(); } - void setIsoValue(double val) { d_IsoValue.setValue(val); } - - const Vec3d& getGridMin() const { return d_gridMin.getValue(); } - void setGridMin(const Vec3d& val) { d_gridMin.setValue(val); } - void setGridMin(double x, double y, double z) { d_gridMin.setValue( Vec3d(x,y,z)); } - - const Vec3d& getGridMax() const { return d_gridMax.getValue(); } - void setGridMax(const Vec3d& val) { d_gridMax.setValue(val); } - void setGridMax(double x, double y, double z) { d_gridMax.setValue( Vec3d(x,y,z)); } - -protected: - SingleLink l_field ; - - Data d_step; - Data d_IsoValue; - - Data< Vec3d > d_gridMin; - Data< Vec3d > d_gridMax; - - /// Output - Data d_outPoints; - Data d_outTriangles; - Data d_debugDraw; - -protected: - FieldToSurfaceMesh() ; - virtual ~FieldToSurfaceMesh() ; - -private: - void computeBBox(const core::ExecParams* /* params */, bool /*onlyVisible*/=false) override; - - void checkInputs(); - - void generateSurfaceMesh(double isoval, double mstep, double invStep, - Vec3d gridmin, Vec3d gridmax, - sofa::component::geometry::ScalarField*); - void updateMeshIfNeeded(); - - bool hasChanged {true} ; - VecCoord tmpPoints; - SeqTriangles tmpTriangles; - - MarchingCube marchingCube; -}; - -} - diff --git a/applications/plugins/SofaImplicitField/components/geometry/BottleField.cpp b/applications/plugins/SofaImplicitField/components/geometry/BottleField.cpp deleted file mode 100644 index 2ed50eb2837..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/BottleField.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/****************************************************************************** -* 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 -using sofa::core::RegisterObject ; - -#include "BottleField.h" - -namespace sofa::component::geometry::_BottleField_ -{ - -using sofa::type::Vec2; - -BottleField::BottleField() - : d_inside(initData(&d_inside, false, "inside", "If true the field is oriented inside (resp. outside) the bottle-shaped object. (default = false)")) - , d_radiusSphere(initData(&d_radiusSphere, 1.0, "radius", "Radius of Sphere emitting the field. (default = 1)")) - , d_centerSphere(initData(&d_centerSphere, Vec3d(0.0,0.0,0.0), "center", "Position of the Sphere Surface. (default=0 0 0)" )) - , d_shift(initData(&d_shift, 1.0, "shift", "How much the top ellipsoid is shifted from the bottom sphere. (default=1)" )) - , d_ellipsoidRadius(initData(&d_ellipsoidRadius, 1.0, "ellipsoidRadius", "Radius of the ellipsoid whose intersection with the sphere is taken off" )) - , d_excentricity(initData(&d_excentricity, 1.0, "excentricity", "excentricity of ellipsoid" )) -{ - init(); - addUpdateCallback("myUpdateCallback", {&d_inside, &d_radiusSphere, &d_centerSphere, &d_shift, &d_ellipsoidRadius, &d_excentricity}, [this](const core::DataTracker& t) - { - SOFA_UNUSED(t); - this->init(); - return sofa::core::objectmodel::ComponentState::Valid; - }, {}); -} - -void BottleField::init() -{ - m_inside = d_inside.getValue(); - m_center = d_centerSphere.getValue(); - m_radius = d_radiusSphere.getValue(); - m_shift = d_shift.getValue(); - m_ellipsoidRadius = d_ellipsoidRadius.getValue(); - m_excentricity = d_excentricity.getValue(); -} - -void BottleField::reinit() -{ - init(); -} - -double BottleField::outerLength(Vec3d& Pos) -{ - return sqrt((Pos[0] - m_center[0])*(Pos[0] - m_center[0]) + - (Pos[1] - m_center[1])*(Pos[1] - m_center[1]) + - (Pos[2] - m_center[2])*(Pos[2] - m_center[2])); -} - -double BottleField::innerLength(Vec3d& Pos) -{ - return sqrt(m_excentricity*(Pos[0] - m_center[0])*(Pos[0] - m_center[0]) + - (Pos[1] - (m_center[1]+m_shift))*(Pos[1] - (m_center[1]+m_shift)) + - m_excentricity*(Pos[2] - m_center[2])*(Pos[2] - m_center[2])); -} - -double BottleField::getValue(Vec3d& Pos, int& domain) -{ - SOFA_UNUSED(domain) ; - double resultSphereOuter = this->outerLength(Pos) - m_radius ; - double resultEllipsoidInner = this->innerLength(Pos) - m_ellipsoidRadius; - - double result = std::max(resultSphereOuter,-resultEllipsoidInner); - - if(m_inside) - result = -result; - - return result; -} - -Vec3d BottleField::getGradient(Vec3d &Pos, int &domain) -{ - SOFA_UNUSED(domain); - Vec3d g; - - double LsphereOuter = this->outerLength(Pos) ; - double LEllipsoidInner = this->innerLength(Pos) ; - - if (LsphereOuter - m_radius > - (LEllipsoidInner- m_ellipsoidRadius)){ - g[0] = (Pos[0] - m_center[0])/LsphereOuter; - g[1] = (Pos[1] - m_center[1])/LsphereOuter; - g[2] = (Pos[2] - m_center[2])/LsphereOuter; - } - else - { - g[0] = -m_excentricity*(Pos[0] - m_center[0])/LEllipsoidInner; - g[1] = -(Pos[1] - (m_center[1]+m_shift))/LEllipsoidInner; - g[2] = -m_excentricity*(Pos[2] - m_center[2])/LEllipsoidInner; - } - - - if (m_inside) - { - g[0] = -g[0]; - g[1] = -g[1]; - g[2] = -g[2]; - } - - return g; -} - -void BottleField::getHessian(Vec3d &Pos, Mat3x3& h) -{ - double LsphereOuter = this->outerLength(Pos) ; - double LEllipsoidInner = this->innerLength(Pos) ; - - if (LsphereOuter - m_radius > - (LEllipsoidInner- m_ellipsoidRadius)) - { - double LsphereOuterSquare = LsphereOuter*LsphereOuter; - double LsphereOuterCube = LsphereOuter*LsphereOuter*LsphereOuter; - h[0][0] = ( LsphereOuter - (Pos[0] - m_center[0])*(Pos[0] - m_center[0])/LsphereOuter )/LsphereOuterSquare ; - h[1][1] = ( LsphereOuter - (Pos[1] - m_center[1])*(Pos[1] - m_center[1])/LsphereOuter )/LsphereOuterSquare ; - h[2][2] = ( LsphereOuter - (Pos[2] - m_center[2])*(Pos[2] - m_center[2])/LsphereOuter )/LsphereOuterSquare ; - - h[0][1] = h[1][0] = - (Pos[0] - m_center[0])*(Pos[1] - m_center[1]) / LsphereOuterCube; - h[0][2] = h[2][0] = - (Pos[0] - m_center[0])*(Pos[2] - m_center[2]) / LsphereOuterCube; - h[1][2] = h[2][1] = - (Pos[2] - m_center[2])*(Pos[1] - m_center[1]) / LsphereOuterCube; - } - else - { - double LEllipsoidInnerSquare = LEllipsoidInner*LEllipsoidInner; - double LEllipsoidInnerCube = LEllipsoidInner*LEllipsoidInner*LEllipsoidInner; - h[0][0] = -m_excentricity*(LEllipsoidInner - m_excentricity*(Pos[0] - m_center[0])*(Pos[0] - m_center[0])/LEllipsoidInner )/LEllipsoidInnerSquare ; - h[1][1] = -(LEllipsoidInner - (Pos[1] - (m_center[1]+m_shift))*(Pos[1] - (m_center[1]+m_shift))/LEllipsoidInner )/LEllipsoidInnerSquare ; - h[2][2] = -m_excentricity*(LEllipsoidInner - m_excentricity*(Pos[2] - m_center[2])*(Pos[2] - m_center[2])/LEllipsoidInner )/LEllipsoidInnerSquare ; - - h[0][1] = h[1][0] = m_excentricity*(Pos[0] - m_center[0])*(Pos[1] - (m_center[1]+m_shift)) / LEllipsoidInnerCube; - h[0][2] = h[2][0] = m_excentricity*m_excentricity*(Pos[0] - m_center[0])*(Pos[2] - m_center[2]) / LEllipsoidInnerCube; - h[1][2] = h[2][1] = m_excentricity*(Pos[2] - m_center[2])*(Pos[1] - (m_center[1]+m_shift)) / LEllipsoidInnerCube; - } - - if (m_inside) - { - for (unsigned int i=0; i<3; i++) - for (unsigned int j=0; j<3; j++) - h[i][j] = -h[i][j]; - } - - return; -} - -// Register in the Factory -void registerBottleField(sofa::core::ObjectFactory* factory) -{ - factory->registerObjects(sofa::core::ObjectRegistrationData("A bottle implicit field.") - .add< BottleField >()); -} - -} // namespace sofa::component::geometry::_BottleField_ diff --git a/applications/plugins/SofaImplicitField/components/geometry/BottleField.h b/applications/plugins/SofaImplicitField/components/geometry/BottleField.h deleted file mode 100644 index 1f62df0c172..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/BottleField.h +++ /dev/null @@ -1,84 +0,0 @@ -/****************************************************************************** -* 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 "ScalarField.h" -#include -namespace sofa::component::geometry -{ - -namespace _BottleField_ -{ - -using sofa::type::Vec3d; -using sofa::type::Mat3x3; - -/** - * This component emulates an implicit field shaped by a sphere with a hole made by an ellispsoid. The result may look like some kind of bottle or vase. -*/ - -class SOFA_SOFAIMPLICITFIELD_API BottleField : public ScalarField -{ -public: - SOFA_CLASS(BottleField, ScalarField); - -public: - BottleField() ; - ~BottleField() override { } - - /// Inherited from BaseObject - void init() override ; - void reinit() override ; - - /// Inherited from ScalarField. - double getValue(Vec3d& Pos, int &domain) override ; - Vec3d getGradient(Vec3d &Pos, int& domain) override ; - void getHessian(Vec3d &Pos, Mat3x3& h) override; - - double outerLength(Vec3d& Pos); - double innerLength(Vec3d& Pos); - - using ScalarField::getValue ; - using ScalarField::getGradient ; - using ScalarField::getValueAndGradient ; - - Data d_inside; ///< If true the field is oriented inside (resp. outside) the bottle-shaped object. (default = false) - Data d_radiusSphere; ///< Radius of Sphere emitting the field. (default = 1) - Data d_centerSphere; ///< Position of the Sphere Surface. (default=0 0 0) - Data d_shift; ///< How much the top ellipsoid is shifted from the bottom sphere. (default=1) - Data d_ellipsoidRadius; ///< Radius of the ellipsoid whose intersection with the sphere is taken off - Data d_excentricity; ///< excentricity of ellipsoid -protected: - Vec3d m_center; - double m_radius; - bool m_inside; - double m_shift; - double m_ellipsoidRadius; - double m_excentricity; -}; - -} //namespace _BottleField_ - -using sofa::component::geometry::_BottleField_::BottleField; - -} //namespace sofa::component::geometry - diff --git a/applications/plugins/SofaImplicitField/components/geometry/DiscreteGridField.cpp b/applications/plugins/SofaImplicitField/components/geometry/DiscreteGridField.cpp deleted file mode 100644 index fa6949c0928..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/DiscreteGridField.cpp +++ /dev/null @@ -1,376 +0,0 @@ -/****************************************************************************** -* 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 -#include -using sofa::core::RegisterObject ; - -#include "DiscreteGridField.h" - - -namespace sofa::component::geometry::_discretegrid_ -{ - -/** -DiscreteGridField::DiscreteGridField() - : in_filename(initData(&in_filename,"filename","filename")) - , in_nx(initData(&in_nx,0,"nx","in_nx")) - , in_ny(initData(&in_ny,0,"ny","in_ny")) - , in_nz(initData(&in_nz,0,"nz","in_nz")) - , in_scale(initData(&in_scale,0.0,"scale","in_scale")) - , in_sampling(initData(&in_sampling,0.0,"sampling","in_sampling")) -{ -} - - - -void DiscreteGridField::init() -{ - if(in_nx.getValue()==0 && in_nz.getValue()==0 && in_nz.getValue()==0) { - d_componentState.setValue(ComponentState::Invalid); - msg_error() << "uninitialized grid"; - } - else if(in_filename.isSet() == false) { - d_componentState.setValue(ComponentState::Invalid) - msg_error() << "unset filename"; - } - else { - pmin.set(0,0,-5.0); - pmax.set(27,27,5.0); - loadGrid(in_scale.getValue(),in_sampling.getValue(),in_nx.getValue(),in_ny.getValue(),in_nz.getValue(),pmin,pmax); - } - - d_componentState.setValue(ComponentState::Valid) -} -*/ - -DiscreteGridField::DiscreteGridField() - : ScalarField(), - d_distanceMapHeader( initData( &d_distanceMapHeader, "file", "MHD file for the distance map" ) ), - d_maxDomains( initData( &d_maxDomains, 1, "maxDomains", "Number of domains available for caching" ) ), - dx( initData( &dx, 0.0, "dx", "x translation" ) ), - dy( initData( &dy, 0.0, "dy", "y translation" ) ), - dz( initData( &dz, 0.0, "dz", "z translation" ) ) -{ - m_usedDomains = 0; - m_imgData = nullptr; -} - - -DiscreteGridField::~DiscreteGridField() -{ - if (m_imgData) - { - delete[] m_imgData; - m_imgData = nullptr; - } -} - - -///used to set a name in tests -void DiscreteGridField::setFilename(const std::string& name) -{ - d_distanceMapHeader.setValue(name); -} - - -void DiscreteGridField::init() -{ - m_domainCache.resize( d_maxDomains.getValue() ); - bool ok = loadGridFromMHD( d_distanceMapHeader.getFullPath().c_str() ); - if (ok) printf( "Successfully loaded distance map.\n" ); -} - - -bool DiscreteGridField::loadGridFromMHD( const char *filename ) -{ - m_imgMin[0]=m_imgMin[1]=m_imgMin[2] = 0; - m_spacing[0]=m_spacing[1]=m_spacing[2] = 1; - m_imgSize[0]=m_imgSize[1]=m_imgSize[2] = 0; - - char buffer[1024]; - char *value; - bool dataFileSpecified = false; - float f0, f1, f2; - int i0, i1, i2; - char dataFile[1024]; - - // read header file - std::ifstream header( filename ); - if (!header.is_open()) return false; - while (!header.eof()) - { - header.getline( buffer, 1024 ); - if (strncmp( buffer, "ObjectType", 10 ) == 0) - { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - if (strncmp( value, "Image", 5 ) != 0) - { - printf( "ERROR: Object is no image.\n" ); - return false; - } - } - else if (strncmp( buffer, "NDims", 5 ) == 0) - { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - if (*value != '3') - { - printf( "ERROR: Wrong number of dimensions.\n" ); - return false; - } - } - else if (strncmp( buffer, "BinaryData ", 11 ) == 0 || strncmp( buffer, "BinaryData=", 11 ) == 0) - { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - if (strncmp( value, "True", 4 ) != 0) - { - printf( "ERROR: Data is not binary.\n" ); - return false; - } - } - else if (strncmp( buffer, "CompressedData", 14 ) == 0) - { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - if (strncmp( value, "False", 5 ) != 0) - { - printf( "ERROR: Data is compressed.\n" ); - return false; - } - } - else if (strncmp( buffer, "TransformMatrix", 15 ) == 0) - { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - if (strncmp( value, "1 0 0 0 1 0 0 0 1", 17 ) != 0) - { - printf( "ERROR: Unsupported transform matrix.\n" ); - return false; - } - } - else if (strncmp( buffer, "Offset", 6 ) == 0) - { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - sscanf( value, "%f %f %f", &f0, &f1, &f2 ); - m_imgMin[0]=f0; m_imgMin[1]=f1; m_imgMin[2]=f2; - printf( "Image offset = %f %f %f\n", m_imgMin[0], m_imgMin[1], m_imgMin[2] ); - } - else if (strncmp( buffer, "ElementSpacing", 14 ) == 0) - { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - sscanf( value, "%f %f %f", &f0, &f1, &f2 ); - m_spacing[0]=f0; m_spacing[1]=f1; m_spacing[2]=f2; - printf( "Image spacing = %f %f %f\n", m_spacing[0], m_spacing[1], m_spacing[2] ); - } - else if (strncmp( buffer, "DimSize", 7 ) == 0) - { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - sscanf( value, "%d %d %d", &i0, &i1, &i2 ); - m_imgSize[0]=i0; m_imgSize[1]=i1; m_imgSize[2]=i2; - printf( "Image size = %i %i %i\n", m_imgSize[0], m_imgSize[1], m_imgSize[2] ); - } - else if (strncmp( buffer, "ElementType", 11 ) == 0) - { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - if (strncmp( value, "MET_FLOAT", 9) != 0) - { - printf( "ERROR: Datatype is not supported.\n" ); - return false; - } - } - /* Don't allow variable names for problems with correct file paths! - else if (strncmp( buffer, "ElementDataFile", 11 ) == 0) { - value = strchr( buffer, '=' )+1; while (*value==' ') value++; - strncpy( dataFile, value, sizeof(dataFile) - 1 ); - dataFile[sizeof(dataFile) - 1] = '\0'; - dataFileSpecified = true; - }*/ - } - header.close(); - - // init remaining variables - for (int d=0; d<3; d++) - { - m_scale[d] = 1.0/m_spacing[d]; - m_imgMax[d] = m_imgMin[d] + (double)(m_imgSize[d]-1)*m_spacing[d]; - } - m_deltaOfs[0] = 0; - m_deltaOfs[1] = 1; - m_deltaOfs[2] = m_imgSize[0]; - m_deltaOfs[3] = m_imgSize[0]+1; - unsigned int sliceSize = m_imgSize[0]*m_imgSize[1]; - m_deltaOfs[4] = m_deltaOfs[0] + sliceSize; - m_deltaOfs[5] = m_deltaOfs[1] + sliceSize; - m_deltaOfs[6] = m_deltaOfs[2] + sliceSize; - m_deltaOfs[7] = m_deltaOfs[3] + sliceSize; - - // read data file - if (!dataFileSpecified) - { - // change extension to .raw - strncpy( dataFile, filename, sizeof(dataFile) - 1 ); - dataFile[sizeof(dataFile) - 1] = '\0'; - size_t lenWithoutExt = strlen( filename ); - if (lenWithoutExt >= 3) - lenWithoutExt -= 3; - if (lenWithoutExt < sizeof(dataFile) - 4) - { - dataFile[lenWithoutExt] = '\0'; - strncat( dataFile, "raw", sizeof(dataFile) - lenWithoutExt - 1 ); - } - else - { - printf( "Warning: filename too long to replace extension, keeping '%s'\n", dataFile ); - } - } - std::ifstream data( dataFile, std::ios_base::binary|std::ios_base::in ); - if (!data.is_open()) return false; - unsigned int numVoxels = m_imgSize[0]*m_imgSize[1]*m_imgSize[2]; - m_imgData = new float[numVoxels]; - data.read( (char*)m_imgData, numVoxels*sizeof(float) ); - if (data.bad()) return false; - data.close(); - return true; -} - -void DiscreteGridField::updateCache( DomainCache *cache, Vec3d& pos ) -{ - cache->insideImg = true; - for (int d=0; d<3; d++) if (pos[d]=m_imgMax[d]) - { - cache->insideImg = false; - break; - } - if (cache->insideImg) - { - int voxMinPos[3]; - for (int d=0; d<3; d++) - { - voxMinPos[d] = (int)(m_scale[d] * (pos[d]-m_imgMin[d])); - cache->bbMin[d] = m_spacing[d]*(double)voxMinPos[d] + m_imgMin[d]; - cache->bbMax[d] = cache->bbMin[d] + m_spacing[d]; - } - unsigned int ofs = voxMinPos[0] + m_imgSize[0]*(voxMinPos[1] + m_imgSize[1]*voxMinPos[2]); - cache->val[0] = m_imgData[ofs]; - for (int i=1; i<8; i++) cache->val[i] = m_imgData[ofs+m_deltaOfs[i]]; - } - else - { - // init bounding box to be as large as possible to prevent unnecessary cache updates while outside image - const double MIN=-10e6, MAX=10e6; - int voxMappedPos[3]; - for (int d=0; d<3; d++) - { - if (pos[d] < m_imgMin[d]) - { - cache->bbMin[d] = MIN; - cache->bbMax[d] = m_imgMin[d]; - voxMappedPos[d] = 0; - } - else if (pos[d] >= m_imgMax[d]) - { - cache->bbMin[d] = m_imgMax[d]; - cache->bbMax[d] = MAX; - voxMappedPos[d] = m_imgSize[d]-1; - } - else - { - cache->bbMin[d] = MIN; - cache->bbMax[d] = MAX; - voxMappedPos[d] = (int)(m_scale[d] * (pos[d]-m_imgMin[d])); - } - } - unsigned int ofs = voxMappedPos[0] + m_imgSize[0]*(voxMappedPos[1] + m_imgSize[1]*voxMappedPos[2]); - // if cache lies outside image, the returned distance is not updated anymore, instead this boundary value is returned - cache->val[0] = m_imgData[ofs] + m_spacing[0]+m_spacing[1]+m_spacing[2]; - } -} - - -int DiscreteGridField::getNextDomain() -{ - // while we have free domains always return the next one, afterwards always use the last one - if (m_usedDomains < (int)m_domainCache.size()) m_usedDomains++; - return m_usedDomains-1; -} - - -double DiscreteGridField::getValue( Vec3d &transformedPos, int &domain ) -{ - // use translation - Vec3d pos; - pos[0] = transformedPos[0] - dx.getValue(); - pos[1] = transformedPos[1] - dy.getValue(); - pos[2] = transformedPos[2] - dz.getValue(); - // find cache domain and check if it needs an update - DomainCache *cache; - if (domain < 0) - { - domain = getNextDomain(); - cache = &(m_domainCache[domain]); - updateCache( cache, pos ); - } - else - { - cache = &(m_domainCache[domain]); - for (int d=0; d<3; d++) - { - if (pos[d]bbMin[d] || pos[d]>cache->bbMax[d]) - { - updateCache( cache, pos ); - break; - } - } - } - - // if cache lies outside image, the returned distance is not updated anymore, instead this boundary value is returned - if (!cache->insideImg) return cache->val[0]; - - // use trilinear interpolation on cached cube - double weight[3]; - for (int d=0; d<3; d++) - { - weight[d] = m_scale[d] * (pos[d]-cache->bbMin[d]); - } - double d = weight[0]*weight[1]; - double c = weight[1] - d; - double b = weight[0] - d; - double a = (1.0-weight[1]) - b; - double res = ( cache->val[0]*a + cache->val[1]*b + cache->val[2]*c + cache->val[3]*d ) * (1.0-weight[2]) - + ( cache->val[4]*a + cache->val[5]*b + cache->val[6]*c + cache->val[7]*d ) * weight[2]; - - return res; -} - - -double DiscreteGridField::getValue( Vec3d &transformedPos ) -{ - static int domain=-1; - return getValue( transformedPos, domain ); -} - -// Register in the Factory -void registerDiscreteGridField(sofa::core::ObjectFactory* factory) -{ - factory->registerObjects(sofa::core::ObjectRegistrationData("A discrete scalar field from a regular grid storing field value with interpolation.") - .add< DiscreteGridField >()); -} - -} ///namespace sofa::component::geometry::_discretegrid_ diff --git a/applications/plugins/SofaImplicitField/components/geometry/DiscreteGridField.h b/applications/plugins/SofaImplicitField/components/geometry/DiscreteGridField.h deleted file mode 100644 index a98e897d4c3..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/DiscreteGridField.h +++ /dev/null @@ -1,99 +0,0 @@ -/****************************************************************************** -* 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 * -******************************************************************************/ -#ifndef SOFAIMPLICITFIELD_COMPONENT_DISCRETEGRIDFIELD_H -#define SOFAIMPLICITFIELD_COMPONENT_DISCRETEGRIDFIELD_H -#include - -#include -#include - -namespace sofa -{ - -namespace component -{ - -namespace geometry -{ - -namespace _discretegrid_ -{ - -using sofa::type::Vec3d; - -class SOFA_SOFAIMPLICITFIELD_API DomainCache -{ -public: - bool insideImg; // shows if the domain lies inside the valid image region or outside - Vec3d bbMin, bbMax; // bounding box (min and max) of the domain - double val[8]; // corner values of the domain -}; - -class SOFA_SOFAIMPLICITFIELD_API DiscreteGridField : public virtual ScalarField -{ - -public: - SOFA_CLASS(DiscreteGridField, ScalarField); - -public: - DiscreteGridField(); - ~DiscreteGridField() override; - - void init() override; - - virtual double getValue( Vec3d &transformedPos ); - double getValue( Vec3d &transformedPos, int &domain ) override; - int getDomain( Vec3d &pos, int ref_domain ) override { (void)pos; return ref_domain; } - - void setFilename(const std::string& filename) ; - bool loadGridFromMHD( const char *filename ) ; - - void updateCache( DomainCache *cache, Vec3d& pos ); - int getNextDomain(); - - sofa::core::objectmodel::DataFileName d_distanceMapHeader; - Data< int > d_maxDomains; ///< Number of domains available for caching - Data< double > dx; ///< x translation - Data< double > dy; ///< y translation - Data< double > dz; ///< z translation - - int m_usedDomains; // number of domains already given out - unsigned int m_imgSize[3]; // number of voxels - double m_spacing[3]; // physical distance between two neighboring voxels - double m_scale[3]; // (1/spacing) - double m_imgMin[3], m_imgMax[3]; // physical locations of the centers of both corner voxels - float *m_imgData; // raw data - unsigned int m_deltaOfs[8]; // offsets to define 8 corners of cube for interpolation - std::vector m_domainCache; -}; - -} /// namespace _discretegrid_ -using _discretegrid_::DiscreteGridField ; - -} /// namespace geometry - -} /// namespace component - -} /// namespace sofa - -#endif - diff --git a/applications/plugins/SofaImplicitField/components/geometry/ScalarField.cpp b/applications/plugins/SofaImplicitField/components/geometry/ScalarField.cpp deleted file mode 100644 index 9c0323bbfd8..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/ScalarField.cpp +++ /dev/null @@ -1,291 +0,0 @@ -/****************************************************************************** -* 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 * -******************************************************************************/ -/****************************************************************************** -* Contributors: -* - damien.marchal@univ-lille.fr -* - olivier.goury@inria.fr -******************************************************************************/ - - -#include -#include "ScalarField.h" -namespace sofa -{ - -namespace component -{ - -namespace geometry -{ - -namespace _scalarfield_ -{ - -void ScalarField::init() -{ - d_componentState.setValue(core::objectmodel::ComponentState::Valid); -} - -Vec3d ScalarField::getGradientByFinitDifference(Vec3d& pos, int& i) -{ - Vec3d Result; - double epsilon = d_epsilon.getValue(); - pos[0] += epsilon; - Result[0] = getValue(pos, i); - pos[0] -= epsilon; - pos[1] += epsilon; - Result[1] = getValue(pos, i); - pos[1] -= epsilon; - pos[2] += epsilon; - Result[2] = getValue(pos, i); - pos[2] -= epsilon; - - double v = getValue(pos, i); - Result[0] = (Result[0]-v)/epsilon; - Result[1] = (Result[1]-v)/epsilon; - Result[2] = (Result[2]-v)/epsilon; - - return Result; -} - -Vec3d ScalarField::getGradient(Vec3d& pos, int& i) -{ - return getGradientByFinitDifference(pos, i); -} - -void ScalarField::getValueAndGradient(Vec3d& pos, double &value, Vec3d& grad, int& domain) -{ - value = getValue(pos,domain); - grad = getGradient(pos,domain); -} - -void ScalarField::getHessianByCentralFiniteDifference(const Vec3d& x, const double dx, - Mat3x3& hessian) -{ - /// Centrale Finite difference using only function's value - /// implemented from https://v8doc.sas.com/sashtml/ormp/chap5/sect28.htm - /// Second-order derivatives based on function calls only (Abramowitz and Stegun 1972, p. 884): - Vec3d e[3] = {Vec3d{dx,0.0,0.0}, - Vec3d{0.0,dx,0.0}, - Vec3d{0.0,0.0,dx}}; - double invTerm = 1.0 / (4.0 * dx * dx); - Vec3d tmpX; - for(unsigned int i=0;i<3;i++) - { - for(unsigned int j=0;j<3;j++) - { - tmpX = x + e[i] + e[j] ; - double p1 = this->getValue(tmpX); - - tmpX = x + e[i] - e[j]; - double p2 = -this->getValue(tmpX); - - tmpX = x - e[i] + e[j]; - double p3 = - this->getValue(tmpX); - - tmpX = x - e[i] - e[j]; - double p4 = +this->getValue(tmpX); - hessian[i][j] = (p1 + p2 + p3 + p4) * invTerm; - } - } -} - - -void ScalarField::getHessian(Vec3d &Pos, Mat3x3& h) -{ - getHessianByCentralFiniteDifference(Pos, d_epsilon.getValue(), h); -} - -bool ScalarField::computeSegIntersection(Vec3d& posInside, Vec3d& posOutside, Vec3d& intersecPos, int i) -{ - - - double tolerance = 0.00001; // tolerance sur la précision m - - float a = (float)getValue(posInside, i); - float b = (float)getValue(posOutside, i); - - if (a*b>0) - { - msg_warning()<<"les deux points sont du même côté de la surface \n"; - return false; - } - - if(b<0) - { - msg_warning()<<"posOutside is inside"; - return false; - } - - - - Vec3d Seg = posInside-posOutside; - if (Seg.norm() < tolerance) // TODO : macro on the global precision - { - intersecPos = posOutside; - return true; - } - - // we start on posInside and search for the first point outside with a step given by scale // - int count=0; - Vec3d step = Seg; - double val = b; - intersecPos = posOutside; - - double step_incr=0.1; - - while(step.norm()> tolerance && count < 1000) - { - step *= step_incr; - - while (val >= 0 && count < (1/step_incr + 1)) - { - count++; - intersecPos += step; - val = getValue(intersecPos, i); - } - - // we restart with more precision - intersecPos -=step; - - val = getValue(intersecPos, i); - if (val < 0) - msg_warning()<<": val is negative\n" ; - } - - if (count>998) - { - msg_error()<<"in computeSegIntersection: Seg : "<0) - { - posInside = point; - while(value>0 && count < 30) - { - count++; - posInside -= dir * step; - value = getValue(posInside, i); - } - posOutside = point; - } - else - { - posOutside = point; - while(value<0 && count < 30) - { - count++; - posOutside += dir * step; - value = getValue(posOutside, i); - } - posInside = point; - - } - if (count == 30) - { - dmsg_warning() << "no projection found in ImplSurf::projectPointonSurface(Vec3d& point, Vec3d& dir)"; - return false; - } - return computeSegIntersection(posInside, posOutside, point, i); - - -} - - -bool ScalarField::projectPointOutOfSurface(Vec3d& point, int i, Vec3d& dir, double &dist_out) -{ - - - if (projectPointonSurface2(point, i, dir)) - { - Vec3d grad = getGradient(point, i); - grad.normalize(); - point += grad*dist_out; - return true; - } - dmsg_warning() << " problem while computing 'projectPointOutOfSurface" ; - return false; - - -} - -} /// namespace _scalarfield_ - -} /// namespace geometry - -} /// namespace component - -} /// namespace sofa diff --git a/applications/plugins/SofaImplicitField/components/geometry/ScalarField.h b/applications/plugins/SofaImplicitField/components/geometry/ScalarField.h deleted file mode 100644 index d676dd2e8d4..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/ScalarField.h +++ /dev/null @@ -1,143 +0,0 @@ -/****************************************************************************** -* 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 * -******************************************************************************/ -/****************************************************************************** -* Contributors: -* - damien.marchal@univ-lille.fr -* - olivier.goury@inria.fr -******************************************************************************/ - -#ifndef SOFAIMPLICITFIELD_COMPONENT_SCALARFIELD_H -#define SOFAIMPLICITFIELD_COMPONENT_SCALARFIELD_H -#include - -#include -#include - -namespace sofa::component::geometry -{ - -namespace _scalarfield_ -{ - -using BaseObject [[deprecated("Use sofa::core::objectmodel::BaseObject instead.")]] = sofa::core::objectmodel::BaseObject; -using sofa::type::Vec3d ; -using sofa::type::Mat3x3 ; - -////////////////// /////////////// -class SOFA_SOFAIMPLICITFIELD_API ScalarField : public BaseObject -{ -public: - SOFA_CLASS(ScalarField, BaseObject); - -public: - void init() override; - - /// Compute the gradient using a first order finite-difference scheme. - /// This is of lower precision compared to analytical gradient computed by derivating - /// the equations. - Vec3d getGradientByFinitDifference(Vec3d& pos, int& domain) ; - void getHessianByCentralFiniteDifference(const Vec3d& x, const double dx, - Mat3x3& hessian); - virtual int getDomain(Vec3d& pos, int domain) { - SOFA_UNUSED(pos); - SOFA_UNUSED(domain); - return -1; - } - - virtual double getValue(Vec3d& pos, int& domain) = 0; - inline double getValue(Vec3d& pos) { int domain=-1; return getValue(pos,domain); } - - /// By default compute the gradient using a first order finite difference approache - /// If you have analytical derivative don't hesitate to override this function. - virtual Vec3d getGradient(Vec3d& pos, int& domain); - inline Vec3d getGradient(Vec3d& pos) {int domain=-1; return getGradient(pos,domain); } - virtual void getHessian(Vec3d &Pos, Mat3x3& h); - - /// Returns the value and the gradiant by evaluating one after an other. - /// For some computation it is possible to implement more efficiently the computation - /// By factoring the computing of the two...if you can do this please override this function. - virtual void getValueAndGradient(Vec3d& pos, double &value, Vec3d& grad, int& domain) ; - inline void getValueAndGradient(Vec3d& pos, double &value, Vec3d& grad) - { - int domain=-1; - return getValueAndGradient(pos,value,grad,domain); - } - - virtual bool computeSegIntersection(Vec3d& posInside, Vec3d& posOutside, Vec3d& intersecPos, int domain=-1); - bool computeSegIntersection(Vec3d& posInside, double valInside, Vec3d& gradInside, - Vec3d& posOutside, double valOutside, Vec3d& gradOutside, - Vec3d& intersecPos, int domain=-1) - { - (void)valInside; - (void)gradInside; - (void)valOutside; - (void)gradOutside; - return computeSegIntersection(posInside, posOutside, intersecPos, domain); - } - - virtual void projectPointonSurface(Vec3d& point, int i=-1); - void projectPointonSurface(Vec3d& point, double value, Vec3d& grad, int domain=-1) - { - (void)value; - (void)grad; - projectPointonSurface(point, domain); - } - - // TODO mettre les paramètres step=0.1 & countMax=30 en paramètre - virtual bool projectPointonSurface2(Vec3d& point, int i, Vec3d& dir); - bool projectPointonSurface2(Vec3d& point, int domain=-1) - { - Vec3d dir = Vec3d(0,0,0); - return projectPointonSurface2(point, domain, dir); - } - - virtual bool projectPointOutOfSurface(Vec3d& point, int i, Vec3d& dir, double &dist_out); - bool projectPointOutOfSurface(Vec3d& point, int domain=-1) - { - Vec3d dir; - double dist_out = 0.0; - return projectPointOutOfSurface(point, domain, dir, dist_out); - } - - -protected: - Data< double > d_epsilon; ///< Tolerance when evaluating the gradient and/or the hessian of the implicit surface numerically - ScalarField( ) - : d_epsilon(initData(&d_epsilon,0.00001,"epsilon","Tolerance when evaluating the gradient and/or the hessian of the implicit surface numerically")) - { - } - ~ScalarField() override { } - -private: - ScalarField(const ScalarField& n) ; - ScalarField& operator=(const ScalarField& n) ; -}; - - -} /// namespace _scalarfield_ - -using _scalarfield_::ScalarField ; - -} /// namespace sofa::component::geometry - -#endif - diff --git a/applications/plugins/SofaImplicitField/components/geometry/SphericalField.cpp b/applications/plugins/SofaImplicitField/components/geometry/SphericalField.cpp deleted file mode 100644 index 14b0c52c6f0..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/SphericalField.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/****************************************************************************** -* 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 -using sofa::core::RegisterObject ; - -#include "SphericalField.h" - -namespace sofa::component::geometry::_sphericalfield_ -{ - -SphericalField::SphericalField() - : d_inside(initData(&d_inside, false, "inside", "If true the field is oriented inside (resp. outside) the sphere. (default = false)")) - , d_radiusSphere(initData(&d_radiusSphere, 1.0, "radius", "Radius of Sphere emitting the field. (default = 1)")) - , d_centerSphere(initData(&d_centerSphere, Vec3d(0.0,0.0,0.0), "center", "Position of the Sphere Surface. (default=0 0 0)" )) -{init(); - } - -void SphericalField::init() -{ - m_inside = d_inside.getValue(); - m_center = d_centerSphere.getValue(); - m_radius = d_radiusSphere.getValue(); -} - -void SphericalField::reinit() -{ - init(); -} - -double SphericalField::getValue(Vec3d& Pos, int& domain) -{ - SOFA_UNUSED(domain) ; - double result = (Pos[0] - m_center[0])*(Pos[0] - m_center[0]) + - (Pos[1] - m_center[1])*(Pos[1] - m_center[1]) + - (Pos[2] - m_center[2])*(Pos[2] - m_center[2]) - - m_radius * m_radius ; - if(m_inside) - result = -result; - - return result; -} - -Vec3d SphericalField::getGradient(Vec3d &Pos, int &domain) -{ - SOFA_UNUSED(domain); - Vec3d g; - if (m_inside) - { - g[0] = -2* (Pos[0] - m_center[0]); - g[1] = -2* (Pos[1] - m_center[1]); - g[2] = -2* (Pos[2] - m_center[2]); - } - else - { - g[0] = 2* (Pos[0] - m_center[0]); - g[1] = 2* (Pos[1] - m_center[1]); - g[2] = 2* (Pos[2] - m_center[2]); - } - - return g; -} - -void SphericalField::getValueAndGradient(Vec3d& Pos, double &value, Vec3d& /*grad*/, int& domain) -{ - SOFA_UNUSED(domain); - Vec3d g; - g[0] = (Pos[0] - m_center[0]); - g[1] = (Pos[1] - m_center[1]); - g[2] = (Pos[2] - m_center[2]); - if (m_inside) - { - value = m_radius*m_radius - g.norm2(); - g = g * (-2); - } - else - { - value = g.norm2() - m_radius*m_radius; - g = g * 2; - } - - return; -} - - -// Register in the Factory -void registerSphericalField(sofa::core::ObjectFactory* factory) -{ - factory->registerObjects(sofa::core::ObjectRegistrationData("A spherical implicit field.") - .add< SphericalField >()); -} - -} /// sofa::component::geometry::_sphericalfield_ diff --git a/applications/plugins/SofaImplicitField/components/geometry/SphericalField.h b/applications/plugins/SofaImplicitField/components/geometry/SphericalField.h deleted file mode 100644 index 6880a14ec25..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/SphericalField.h +++ /dev/null @@ -1,83 +0,0 @@ -/****************************************************************************** -* 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 * -******************************************************************************/ -#ifndef SOFA_IMPLICIT_SPHERICALFIELD_H -#define SOFA_IMPLICIT_SPHERICALFIELD_H - -#include "ScalarField.h" - -namespace sofa -{ - -namespace component -{ - -namespace geometry -{ - -namespace _sphericalfield_ -{ - -using sofa::type::Vec3d ; - -class SOFA_SOFAIMPLICITFIELD_API SphericalField : public ScalarField -{ -public: - SOFA_CLASS(SphericalField, ScalarField); - -public: - SphericalField() ; - ~SphericalField() override { } - - /// Inherited from BaseObject - void init() override ; - void reinit() override ; - - /// Inherited from ScalarField. - double getValue(Vec3d& Pos, int &domain) override ; - Vec3d getGradient(Vec3d &Pos, int& domain) override ; - void getValueAndGradient(Vec3d& pos, double& val, Vec3d& grad, int& domain) override ; - - using ScalarField::getValue ; - using ScalarField::getGradient ; - using ScalarField::getValueAndGradient ; - - Data d_inside; ///< If true the field is oriented inside (resp. outside) the sphere. (default = false) - Data d_radiusSphere; ///< Radius of Sphere emitting the field. (default = 1) - Data d_centerSphere; ///< Position of the Sphere Surface. (default=0 0 0) - -protected: - Vec3d m_center; - double m_radius; - bool m_inside; -}; - -} /// _sphericalfield_ - -using _sphericalfield_::SphericalField ; - -} /// geometry - -} /// component - -} /// sofa - -#endif diff --git a/applications/plugins/SofaImplicitField/components/geometry/StarShapedField.cpp b/applications/plugins/SofaImplicitField/components/geometry/StarShapedField.cpp deleted file mode 100644 index f41b2d75880..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/StarShapedField.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/****************************************************************************** -* 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 -using sofa::core::RegisterObject ; - -#include "StarShapedField.h" - -namespace sofa::component::geometry::_StarShapedField_ -{ - - -StarShapedField::StarShapedField() - : d_inside(initData(&d_inside, false, "inside", "If true the field is oriented inside (resp. outside) the sphere. (default = false)")) - , d_radiusSphere(initData(&d_radiusSphere, 1.0, "radius", "Radius of Sphere emitting the field. (default = 1)")) - , d_centerSphere(initData(&d_centerSphere, Vec3d(0.0,0.0,0.0), "center", "Position of the Sphere Surface. (default=0 0 0)" )) - , d_branches(initData(&d_branches, 1.0, "branches", "Number of branches of the star. (default=1)" )) - , d_branchesRadius(initData(&d_branchesRadius, 1.0, "branchesRadius", "Size of the branches of the star. (default=1)" )) -{ - init(); - addUpdateCallback("myUpdateCallback", {&d_inside, &d_radiusSphere, &d_centerSphere, &d_branches, &d_branchesRadius}, [this](const core::DataTracker& t) - { - SOFA_UNUSED(t); - this->init(); - return sofa::core::objectmodel::ComponentState::Valid; - }, {}); - -} - -void StarShapedField::init() -{ - m_inside = d_inside.getValue(); - m_center = d_centerSphere.getValue(); - m_radius = d_radiusSphere.getValue(); - m_branches = d_branches.getValue(); - m_branchesRadius = d_branchesRadius.getValue(); -} - -void StarShapedField::reinit() -{ - init(); -} - -double StarShapedField::getValue(Vec3d& Pos, int& domain) -{ - SOFA_UNUSED(domain) ; - double length = sqrt((Pos[0] - m_center[0])*(Pos[0] - m_center[0]) + - (Pos[1] - m_center[1])*(Pos[1] - m_center[1]) + - (Pos[2] - m_center[2])*(Pos[2] - m_center[2])); - double result = length - m_radius ; - - double simpleCos0 = (Pos[0] - m_center[0]); - double simpleCos1 = (Pos[1] - m_center[1]); - double simpleCos2 = (Pos[2] - m_center[2]); - - result += m_branchesRadius * ( cos( m_branches*simpleCos0 ) + cos( m_branches*simpleCos1 ) + cos( m_branches*simpleCos2 ) ); - if(m_inside) - result = -result; - - return result; -} - -Vec3d StarShapedField::getGradient(Vec3d &Pos, int &domain) -{ - SOFA_UNUSED(domain); - Vec3d g; - - double length = sqrt((Pos[0] - m_center[0])*(Pos[0] - m_center[0]) + - (Pos[1] - m_center[1])*(Pos[1] - m_center[1]) + - (Pos[2] - m_center[2])*(Pos[2] - m_center[2])); - double deltaLength0 = (Pos[0] - m_center[0])/length; - double deltaLength1 = (Pos[1] - m_center[1])/length; - double deltaLength2 = (Pos[2] - m_center[2])/length; - - g[0] = deltaLength0 - m_branchesRadius*m_branches*sin(m_branches*(Pos[0] - m_center[0])); - g[1] = deltaLength1 - m_branchesRadius*m_branches*sin(m_branches*(Pos[1] - m_center[1])); - g[2] = deltaLength2 - m_branchesRadius*m_branches*sin(m_branches*(Pos[2] - m_center[2])); - - if (m_inside) - { - g[0] = -g[0]; - g[1] = -g[1]; - g[2] = -g[2]; - } - - return g; -} - -void StarShapedField::getHessian(Vec3d &Pos, Mat3x3& h) -{ - double length = sqrt((Pos[0] - m_center[0])*(Pos[0] - m_center[0]) + - (Pos[1] - m_center[1])*(Pos[1] - m_center[1]) + - (Pos[2] - m_center[2])*(Pos[2] - m_center[2])); - double deltaLength0 = (Pos[0] - m_center[0])/length; - double deltaLength1 = (Pos[1] - m_center[1])/length; - double deltaLength2 = (Pos[2] - m_center[2])/length; - - - h[0][0] = (length - (Pos[0] - m_center[0])*deltaLength0 )/(length*length) - m_branchesRadius*m_branches*m_branches*cos(m_branches*(Pos[0] - m_center[0])); - h[1][1] = (length - (Pos[1] - m_center[1])*deltaLength1 )/(length*length) - m_branchesRadius*m_branches*m_branches*cos(m_branches*(Pos[1] - m_center[1])); - h[2][2] = (length - (Pos[2] - m_center[2])*deltaLength2 )/(length*length) - m_branchesRadius*m_branches*m_branches*cos(m_branches*(Pos[2] - m_center[2])); - - h[0][1] = h[1][0] = - (Pos[0] - m_center[0])*(Pos[1] - m_center[1]) / (length*length*length); - h[0][2] = h[2][0] = - (Pos[0] - m_center[0])*(Pos[2] - m_center[2]) / (length*length*length); - h[1][2] = h[2][1] = - (Pos[2] - m_center[2])*(Pos[1] - m_center[1]) / (length*length*length); - - return; -} - -// Register in the Factory -void registerStarShapedField(sofa::core::ObjectFactory* factory) -{ - factory->registerObjects(sofa::core::ObjectRegistrationData("A star-shape implicit field.") - .add< StarShapedField >()); -} - -} // namespace sofa::component::geometry::_StarShapedField_ - diff --git a/applications/plugins/SofaImplicitField/components/geometry/StarShapedField.h b/applications/plugins/SofaImplicitField/components/geometry/StarShapedField.h deleted file mode 100644 index 1d0aebb33b7..00000000000 --- a/applications/plugins/SofaImplicitField/components/geometry/StarShapedField.h +++ /dev/null @@ -1,79 +0,0 @@ -/****************************************************************************** -* 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 "ScalarField.h" -#include - -namespace sofa::component::geometry -{ - -namespace _StarShapedField_ -{ - -using sofa::type::Vec3d; -using sofa::type::Mat3x3; - -/** - * This component emulates an implicit field that looks like some kind of star. -*/ -class SOFA_SOFAIMPLICITFIELD_API StarShapedField : public ScalarField -{ -public: - SOFA_CLASS(StarShapedField, ScalarField); - -public: - StarShapedField() ; - ~StarShapedField() override { } - - /// Inherited from BaseObject - void init() override ; - void reinit() override ; - - /// Inherited from ScalarField. - double getValue(Vec3d& Pos, int &domain) override ; - Vec3d getGradient(Vec3d &Pos, int& domain) override ; - void getHessian(Vec3d &Pos, Mat3x3& h) override; - - using ScalarField::getValue ; - using ScalarField::getGradient ; - using ScalarField::getValueAndGradient ; - - Data d_inside; ///< If true the field is oriented inside (resp. outside) the sphere. (default = false) - Data d_radiusSphere; ///< Radius of Sphere emitting the field. (default = 1) - Data d_centerSphere; ///< Position of the Sphere Surface. (default=0 0 0) - Data d_branches; ///< Number of branches of the star. (default=1) - Data d_branchesRadius; ///< Size of the branches of the star. (default=1) -protected: - Vec3d m_center; - double m_radius; - bool m_inside; - double m_branches; - double m_branchesRadius; -}; - -} // namespace _StarShapedField_ - -using sofa::component::geometry::_StarShapedField_::StarShapedField; - -} // namespace sofa::component::geometry - diff --git a/applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.cpp b/applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.cpp deleted file mode 100644 index 9609e654e7f..00000000000 --- a/applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/****************************************************************************** -* 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 * -******************************************************************************/ -#define SOFA_COMPONENT_MAPPING_IMPLICITSURFACEMAPPING_CPP -#include -#include -#include "ImplicitSurfaceMapping.inl" - -namespace sofaimplicitfield::mapping -{ - -using namespace sofa::defaulttype; - -// Register in the Factory -void registerImplicitSurfaceMapping(sofa::core::ObjectFactory* factory) -{ - factory->registerObjects(sofa::core::ObjectRegistrationData("Compute an iso-surface from a set of particles.") - .add< ImplicitSurfaceMapping< Vec3dTypes, Vec3dTypes > >()); -} - -template class SOFA_SOFAIMPLICITFIELD_API ImplicitSurfaceMapping< Vec3dTypes, Vec3dTypes >; - -} diff --git a/applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.h b/applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.h deleted file mode 100644 index 6b66ece9bd8..00000000000 --- a/applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.h +++ /dev/null @@ -1,164 +0,0 @@ -/****************************************************************************** -* 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 sofaimplicitfield::mapping -{ - -using namespace sofa; -using sofa::component::topology::container::constant::MeshTopology; - -template -class ImplicitSurfaceMapping : public core::Mapping, public MeshTopology -{ -public: - SOFA_CLASS2(SOFA_TEMPLATE2(ImplicitSurfaceMapping, In, Out), SOFA_TEMPLATE2(core::Mapping, In, Out), MeshTopology); - - typedef core::Mapping Inherit; - typedef typename Out::VecCoord OutVecCoord; - typedef typename Out::VecDeriv OutVecDeriv; - typedef typename Out::Coord OutCoord; - typedef typename Out::Deriv OutDeriv; - typedef typename OutCoord::value_type OutReal; - typedef typename In::VecCoord InVecCoord; - typedef typename In::VecDeriv InVecDeriv; - typedef typename In::Coord InCoord; - typedef typename In::Deriv InDeriv; - typedef typename InCoord::value_type InReal; - - typedef typename In::MatrixDeriv InMatrixDeriv; - typedef typename Out::MatrixDeriv OutMatrixDeriv; - - typedef Data InDataVecCoord; - typedef Data InDataVecDeriv; - typedef Data InDataMatrixDeriv; - - typedef Data OutDataVecCoord; - typedef Data OutDataVecDeriv; - typedef Data OutDataMatrixDeriv; -protected: - ImplicitSurfaceMapping() - : Inherit(), - mStep(initData(&mStep,0.5,"step","Step")), - mRadius(initData(&mRadius,2.0,"radius","Radius")), - mIsoValue(initData(&mIsoValue,0.5,"isoValue","Iso Value")), - mGridMin(initData(&mGridMin,InCoord(-100,-100,-100),"min","Grid Min")), - mGridMax(initData(&mGridMax,InCoord(100,100,100),"max","Grid Max")) - { - } - - ~ImplicitSurfaceMapping() override - { - } -public: - void init() override; - - void parse(core::objectmodel::BaseObjectDescription* arg) override; - - double getStep() const { return mStep.getValue(); } - void setStep(double val) { mStep.setValue(val); } - - double getRadius() const { return mRadius.getValue(); } - void setRadius(double val) { mRadius.setValue(val); } - - double getIsoValue() const { return mIsoValue.getValue(); } - void setIsoValue(double val) { mIsoValue.setValue(val); } - - const InCoord& getGridMin() const { return mGridMin.getValue(); } - void setGridMin(const InCoord& val) { mGridMin.setValue(val); } - void setGridMin(double x, double y, double z) { mGridMin.setValue( InCoord((InReal)x,(InReal)y,(InReal)z)); } - - const InCoord& getGridMax() const { return mGridMax.getValue(); } - void setGridMax(const InCoord& val) { mGridMax.setValue(val); } - void setGridMax(double x, double y, double z) { mGridMax.setValue( InCoord((InReal)x,(InReal)y,(InReal)z)); } - - void apply(const core::MechanicalParams *mparams, Data& out, const Data& in) override; - void applyJ(const core::MechanicalParams *mparams, Data& out, const Data& in) override; - void applyJT( const sofa::core::MechanicalParams* /*mparams*/, InDataVecDeriv& /*out*/, const OutDataVecDeriv& /*in*/) override - { - msg_error() << "applyJT(dx) is not implemented"; - } - - void applyJT( const sofa::core::ConstraintParams* /*cparams*/, InDataMatrixDeriv& /*out*/, const OutDataMatrixDeriv& /*in*/) override - { - msg_error() << "applyJT(constraint) is not implemented"; - } - - void draw(const core::visual::VisualParams* params) override; - -protected: - Data mStep; ///< Step - Data mRadius; ///< Radius - Data mIsoValue; ///< Iso Value - - Data< InCoord > mGridMin; ///< Grid Min - Data< InCoord > mGridMax; ///< Grid Max - - Vec3d mLocalGridMin; ///< Grid Min - Vec3d mLocalGridMax; ///< Grid Max - - - // Marching cube data - - /// For each cube, store the vertex indices on each 3 first edges, and the data value - struct CubeData - { - int p[3]; - OutReal data; - inline friend std::istream& operator >> ( std::istream& in, CubeData& c) - { - in >> c.p[0] >> c.p[1] >> c.p[2] >> c.data; - - return in; - } - - inline friend std::ostream& operator << ( std::ostream& out, const CubeData& c) - { - out << c.p[0] << " " << c.p[1] << " " << c.p[2] << " " << c.data ; - return out; - } - }; - - Data < sofa::type::vector > planes; - typename sofa::type::vector::iterator P0; /// Pointer to first plane - typename sofa::type::vector::iterator P1; /// Pointer to second plane -public: - bool insertInNode( core::objectmodel::BaseNode* node ) override { Inherit1::insertInNode(node); Inherit2::insertInNode(node); return true; } - bool removeInNode( core::objectmodel::BaseNode* node ) override { Inherit1::removeInNode(node); Inherit2::removeInNode(node); return true; } - -private: - MarchingCube marchingCube; -}; - -#if !defined(SOFA_COMPONENT_MAPPING_IMPLICITSURFACEMAPPING_CPP) -extern template class SOFA_SOFAIMPLICITFIELD_API ImplicitSurfaceMapping< defaulttype::Vec3dTypes, defaulttype::Vec3dTypes >; -#endif - -} // namespace - diff --git a/applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.inl b/applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.inl deleted file mode 100644 index 267b73e3fc3..00000000000 --- a/applications/plugins/SofaImplicitField/components/mapping/ImplicitSurfaceMapping.inl +++ /dev/null @@ -1,164 +0,0 @@ -/****************************************************************************** -* 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 "ImplicitSurfaceMapping.h" -#include -#include -#include -#include - -namespace sofaimplicitfield::mapping -{ - -template -void ImplicitSurfaceMapping::init() -{ - core::Mapping::init(); - MeshTopology::init(); -} - -template -void ImplicitSurfaceMapping::parse(core::objectmodel::BaseObjectDescription* arg) -{ - this->Inherit::parse(arg); - if ( arg->getAttribute("minx") || arg->getAttribute("miny") || arg->getAttribute("minz")) - this->setGridMin(arg->getAttributeAsFloat("minx",-100.0), - arg->getAttributeAsFloat("miny",-100.0), - arg->getAttributeAsFloat("minz",-100.0)); - if (arg->getAttribute("maxx") || arg->getAttribute("maxy") || arg->getAttribute("maxz")) - this->setGridMax(arg->getAttributeAsFloat("maxx",100.0), - arg->getAttributeAsFloat("maxy",100.0), - arg->getAttributeAsFloat("maxz",100.0)); -} - -template -Real sqr(Real r) -{ - return r*r; -} - -template -void ImplicitSurfaceMapping::draw(const core::visual::VisualParams* params) -{ - auto dt = params->drawTool(); - - dt->drawBoundingBox(mGridMin.getValue(), mGridMax.getValue()); - dt->drawBoundingBox(mLocalGridMin, mLocalGridMax); -} - -template -void ImplicitSurfaceMapping::apply(const core::MechanicalParams * /*mparams*/, Data& dOut, const Data& dIn) -{ - const InVecCoord& in = dIn.getValue(); - - clear(); - - if (in.size()==0) - { - OutVecCoord &out = *dOut.beginEdit(); - dOut.endEdit(); - return; - } - - auto minGrid = mGridMin.getValue(); - auto maxGrid = mGridMax.getValue(); - - InReal invStep = (InReal)(1/mStep.getValue()); - const InReal r = getRadius(); - - std::unordered_map > sortParticles; - for (unsigned int ip=0; ip maxGrid[0] || - c0[1] < minGrid[1] || c0[1] > maxGrid[1] || - c0[2] < minGrid[2] || c0[2] > maxGrid[2]) - continue; - - InCoord c = c0 ; - int z0 = helper::rfloor((c[2]-r)*invStep); - int z1 = helper::rceil((c[2]+r)*invStep); - for (int z = z0; z <= z1; ++z) - sortParticles[z].push_back(c); - } - - OutReal r2 = (OutReal)sqr(r); - - double rr = getRadius(); - type::BoundingBox box{}; - for(auto& particle : in) - { - box.include(particle); - } - box.include(box.minBBox()+Vec3d{-rr,-rr,-rr}); - box.include(box.maxBBox()+Vec3d{+rr,+rr,+rr}); - - mLocalGridMin = box.minBBox(); - mLocalGridMax = box.maxBBox(); - - type::BoundingBox bigBox {mGridMin.getValue(), mGridMax.getValue()}; - box.intersection(bigBox); - - auto fieldFunction = [&sortParticles, &r, &r2, &invStep]( - std::vector& pos, std::vector& res) -> void { - - auto z = pos[0].z(); - int index = helper::rfloor(z*invStep); - auto particlesIt = sortParticles.find(index); - if(particlesIt==sortParticles.end()) - return; - - int i = 0; - for(auto& position : pos ) - { - double sumd = 0.0; - for(auto& particle : (particlesIt->second)){ - position.z() = z; - double d2 = (position - particle).norm2(); - if(d2 < r2){ - d2 /= r2; - sumd += (1 + (-4*d2*d2*d2 + 17*d2*d2 - 22*d2)/9); - } - } - res[i++] = sumd; - } - return; - }; - - auto triangles = helper::getWriteOnlyAccessor(d_seqTriangles); - auto points = helper::getWriteOnlyAccessor(dOut); - - points.clear(); - triangles.clear(); - marchingCube.generateSurfaceMesh(mIsoValue.getValue(), mStep.getValue(), - invStep, box.minBBox(), box.maxBBox(), - fieldFunction, points.wref(), triangles.wref()); - -} - -template -void ImplicitSurfaceMapping::applyJ(const core::MechanicalParams * /*mparams*/, Data& /*dOut*/, const Data& /*dIn*/) -{ -} - -} diff --git a/applications/plugins/SofaImplicitField/config.h.in b/applications/plugins/SofaImplicitField/config.h.in deleted file mode 100644 index 875a9b62f0d..00000000000 --- a/applications/plugins/SofaImplicitField/config.h.in +++ /dev/null @@ -1,37 +0,0 @@ -/****************************************************************************** -* 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 - -#ifdef SOFA_BUILD_SOFAIMPLICITFIELD -# define SOFA_TARGET SofaImplicitField -# define SOFA_SOFAIMPLICITFIELD_API SOFA_EXPORT_DYNAMIC_LIBRARY -#else -# define SOFA_SOFAIMPLICITFIELD_API SOFA_IMPORT_DYNAMIC_LIBRARY -#endif - -namespace sofaimplicitfield -{ - constexpr const char* MODULE_NAME = "@PROJECT_NAME@"; - constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@"; -} // namespace sofaimplicitfield diff --git a/applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceContainer.h b/applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceContainer.h deleted file mode 100644 index 9858a7ea1ab..00000000000 --- a/applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceContainer.h +++ /dev/null @@ -1,50 +0,0 @@ -/// This file is only forwarding to the new location -#include - -namespace sofa -{ -namespace component -{ -namespace container -{ - -class ImplicitSurfaceContainer : public sofa::component::geometry::DiscreteGridField -{ -public: - bool loadImage( const char *filename ) - { - return loadGridFromMHD(filename) ; - } - - virtual double getDistance(type::Vec3d& pos) - { - int domain=-1; - return getDistance(pos,domain); - } - - virtual double getDistance(type::Vec3d& pos, int& domain) - { - type::Vec3d grad; - double value; - getValueAndGradient(pos,value,grad,domain); - return getDistance(pos,value,grad.norm()); - } - - virtual double getDistance(type::Vec3d& pos, double value, double grad_norm) - { - int domain=-1; - return getDistance(pos, value, grad_norm, domain); - } - - virtual double getDistance(type::Vec3d& /*pos*/, double value, double grad_norm, int &domain) - { - SOFA_UNUSED(domain); - /// use Taubin's distance by default - if (grad_norm < 1e-10) return value < 0 ? double(std::numeric_limits::min()) : double(std::numeric_limits::max()); - return value/grad_norm; - } -}; - -} -} -} diff --git a/applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceMapping.h b/applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceMapping.h deleted file mode 100644 index 9e2d3d4a250..00000000000 --- a/applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceMapping.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceMapping.inl b/applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceMapping.inl deleted file mode 100644 index 3e60617ebde..00000000000 --- a/applications/plugins/SofaImplicitField/deprecated/ImplicitSurfaceMapping.inl +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/applications/plugins/SofaImplicitField/deprecated/InterpolatedImplicitSurface.cpp b/applications/plugins/SofaImplicitField/deprecated/InterpolatedImplicitSurface.cpp deleted file mode 100644 index d02ac4597f8..00000000000 --- a/applications/plugins/SofaImplicitField/deprecated/InterpolatedImplicitSurface.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -using sofa::core::RegisterObject ; - -#include - -namespace sofa::component::container -{ - -// Register in the Factory -void registerInterpolatedImplicitSurface(sofa::core::ObjectFactory* factory) -{ - factory->registerObjects(sofa::core::ObjectRegistrationData("Deprecated. This class is forwarding DiscreteGridField.") - .add< InterpolatedImplicitSurface >() - .addAlias("DistGrid")); -} - -} /// sofa::component::container diff --git a/applications/plugins/SofaImplicitField/deprecated/InterpolatedImplicitSurface.h b/applications/plugins/SofaImplicitField/deprecated/InterpolatedImplicitSurface.h deleted file mode 100644 index 9d83c47f827..00000000000 --- a/applications/plugins/SofaImplicitField/deprecated/InterpolatedImplicitSurface.h +++ /dev/null @@ -1,52 +0,0 @@ -#include - -namespace sofa -{ -namespace component -{ -namespace container -{ - -class InterpolatedImplicitSurface : public sofa::component::geometry::DiscreteGridField -{ -public: - SOFA_CLASS(InterpolatedImplicitSurface, DiscreteGridField) ; - - bool loadImage( const char *filename ) { - return loadGridFromMHD(filename) ; - } - - virtual double getDistance(type::Vec3d& pos) - { - int domain=-1; - return getDistance(pos,domain); - } - - virtual double getDistance(type::Vec3d& pos, int& domain) - { - type::Vec3d grad; - double value; - getValueAndGradient(pos,value,grad,domain); - return getDistance(pos,value,grad.norm()); - } - - virtual double getDistance(type::Vec3d& pos, double value, double grad_norm) - { - int domain=-1; - return getDistance(pos, value, grad_norm, domain); - } - - virtual double getDistance(type::Vec3d& /*pos*/, double value, double grad_norm, int &domain) - { - SOFA_UNUSED(domain); - /// use Taubin's distance by default - if (grad_norm < 1e-10) return value < 0 ? double(std::numeric_limits::min()) : double(std::numeric_limits::max()); - return value/grad_norm; - } - - -}; - -} /// container -} /// component -} /// sofa diff --git a/applications/plugins/SofaImplicitField/deprecated/SphereSurface.cpp b/applications/plugins/SofaImplicitField/deprecated/SphereSurface.cpp deleted file mode 100644 index daa9abd2c96..00000000000 --- a/applications/plugins/SofaImplicitField/deprecated/SphereSurface.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "SphereSurface.h" - -namespace sofa -{ -namespace component -{ -namespace container -{ - -double SphereSurface::getDistance(type::Vec3d& Pos, int& domain) -{ - SOFA_UNUSED(domain) ; - double result = m_radius - sqrt((Pos[0] - m_center[0])*(Pos[0] - m_center[0]) + - (Pos[1] - m_center[1])*(Pos[1] - m_center[1]) + - (Pos[2] - m_center[2])*(Pos[2] - m_center[2])); - return m_inside ? result : -result; -} - -double SphereSurface::getDistance(type::Vec3d& /*Pos*/, double value, double grad_norm, int &domain) -{ - (void)domain; - if (grad_norm < 0) // use value - grad_norm = sqrt(m_inside ? m_radius*m_radius - value : value + m_radius*m_radius); - else grad_norm /= 2; - return m_inside ? m_radius - grad_norm : grad_norm - m_radius; -} - -} -} -} diff --git a/applications/plugins/SofaImplicitField/deprecated/SphereSurface.h b/applications/plugins/SofaImplicitField/deprecated/SphereSurface.h deleted file mode 100644 index ab24ba2cc7e..00000000000 --- a/applications/plugins/SofaImplicitField/deprecated/SphereSurface.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef SOFA_SOFAIMPLICITFIELD_H -#define SOFA_SOFAIMPLICITFIELD_H - -#include - -namespace sofa -{ -namespace component -{ -namespace container -{ - -class SphereSurface : public sofa::component::geometry::SphericalField -{ -public: - SOFA_CLASS(SphereSurface, sofa::component::geometry::SphericalField) ; - - // The following function uses only either value or grad_norm (they are redundant) - // - value is used is grad_norm < 0 - // - else grad_norm is used: for example, in that case dist = _radius - grad_norm/2 (with _inside=true) - virtual double getDistance(sofa::type::Vec3d& pos, int& domain) ; - virtual double getDistance(sofa::type::Vec3d& pos, double value, double grad_norm, int &domain) ; -}; - -} /// container -} /// components -} /// sofa - -#endif /// SOFA_SOFAIMPLICITFIELD_H diff --git a/applications/plugins/SofaImplicitField/examples/ImplicitSurfaceMapping.scn b/applications/plugins/SofaImplicitField/examples/ImplicitSurfaceMapping.scn deleted file mode 100644 index 174e8d159fc..00000000000 --- a/applications/plugins/SofaImplicitField/examples/ImplicitSurfaceMapping.scn +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/applications/plugins/SofaImplicitField/examples/python/example-mesh-extraction-from-implicit.py b/applications/plugins/SofaImplicitField/examples/python/example-mesh-extraction-from-implicit.py deleted file mode 100644 index 4b848a7d86a..00000000000 --- a/applications/plugins/SofaImplicitField/examples/python/example-mesh-extraction-from-implicit.py +++ /dev/null @@ -1,53 +0,0 @@ -import Sofa -from Sofa.Types import RGBAColor -from xshape.primitives import * -from xshape.transforms import * -from xshape.operators import * - -class DrawController(Sofa.Core.Controller): - def __init__(self, *args, **kwargs): - Sofa.Core.Controller.__init__(self, *args, **kwargs) - - def draw(self, visual_context): - dt = visual_context.getDrawTool() - dt.drawText([-1.0, 1.0, 0.5], 0.2, "Union(Sphere, Box)", RGBAColor(1.0,1.0,1.0,1.0)) - dt.drawText([ 1.0, 1.0, 0.5], 0.2, "Difference(Sphere, Box)", RGBAColor(1.0,1.0,1.0,1.0)) - -def createScene(root : Sofa.Core.Node): - """Creates two different mesh from two scalar field. - The scalar fields are 'spherical', one implemented in python, the other in c++ - One of the produced mesh is then connected to a visual model. - """ - root.addObject("RequiredPlugin", pluginName="SofaImplicitField") - - root.addObject(DrawController()) - - ########################### Fields ################## - root.addChild("Fields") - f1 = root.Fields.addObject( - Union(name="field1", - childA=Sphere(name="sphere", center=[0,0,0],radius=0.7), - childB=RoundedBox(center=[0.0,0.0,0.0],dimensions=[0.95,0.5,0.5], rounding_radius=0.1)) - ) - - f2 = root.Fields.addObject( - Difference(name="field2", - childB=Sphere(name="sphere", center=[2,0,0],radius=0.9), - childA=RoundedBox(center=[2.0,0.0,0.0],dimensions=[0.95,0.5,0.5], rounding_radius=0.1)) - ) - - ########################### Meshing ################## - root.addChild("Meshing") - m1 = root.Meshing.addObject("FieldToSurfaceMesh", name="polygonizer1", - field=f1.linkpath, min=[-1,-1,-1], max=[1,1,1], - step=0.1, debugDraw=True) - - m2 = root.Meshing.addObject("FieldToSurfaceMesh", name="polygonizer2", - field=f2.linkpath, min=[1,-1,-1], max=[3,1,1], - step=0.07) - - ########################### Fields ################## - root.addChild("Visual") - root.Visual.addObject("OglModel", name="renderer", - position=root.Meshing.polygonizer2.points.linkpath, - triangles=root.Meshing.polygonizer2.triangles.linkpath) diff --git a/applications/plugins/SofaImplicitField/examples/python/python-scalarfield.py b/applications/plugins/SofaImplicitField/examples/python/python-scalarfield.py deleted file mode 100644 index 9a43da272a9..00000000000 --- a/applications/plugins/SofaImplicitField/examples/python/python-scalarfield.py +++ /dev/null @@ -1,50 +0,0 @@ -import Sofa -from SofaImplicitField import ScalarField -from SofaTypes.SofaTypes import Vec3d, Mat3x3 -import numpy - -class Sphere(ScalarField): - def __init__(self, *args, **kwargs): - ScalarField.__init__(self, *args, **kwargs) - - self.addData("center", type="Vec3d",value=kwargs.get("center", [0.0,0.0,0.0]), default=[0.0,0.0,0.0], help="center of the sphere", group="Geometry") - self.addData("radius", type="double",value=kwargs.get("radius", 1.0), default=1, help="radius of the sphere", group="Geometry") - - def getValue(self, position): - x,y,z = position - return numpy.sqrt( numpy.sum((self.center.value - numpy.array([x,y,z]))**2) ) - self.radius.value - -class SphereWithCustomHessianAndGradient(Sphere): - def __init__(self, *args, **kwargs): - Sphere.__init__(self, *args, **kwargs)# - - def getGradient(self, position): - return Vec3d(3.0,2.0,1.0) - - def getHessian(self, position): - return Mat3x3([[1,1,1],[2,1,1],[3,1,1]]) - -class FieldController(Sofa.Core.Controller): - def __init__(self, *args, **kwargs): - Sofa.Core.Controller.__init__(self, *args, **kwargs) - self.field = kwargs.get("target") - - def onAnimateEndEvent(self, event): - print("Animation end event, ") - print("Field value at 0,0,0 is: ", self.field.getValue(Vec3d(0.0,0.0,0.0)) ) - print("Field value at 1,0,0 is: ", self.field.getValue(Vec3d(1.0,0.0,0.0)) ) - print("Field value at 2,0,0 is: ", self.field.getValue(Vec3d(2.0,0.0,0.0)) ) - - print("Gradient value at 0,0,0 is: ", type(self.field.getGradient(Vec3d(0.0,0.0,0.0)))) - print("Hessian value at 0,0,0 is: ", type(self.field.getHessian(Vec3d(0.0,0.0,0.0)))) - -def createScene(root): - """In this scene we create two scalar field of spherical shape, the two are implemented using - python. The first one is overriding only the getValue, the hessian and gradient is thus computed using - finite difference in the c++ code. The second field is overriding the hessian and gradient function - """ - root.addObject(Sphere("field1")) - root.addObject(FieldController(name="controller1", target=root.field1)) - - root.addObject(SphereWithCustomHessianAndGradient("field2")) - root.addObject(FieldController(name="controller2", target=root.field2)) diff --git a/applications/plugins/SofaImplicitField/examples/python/xshape/__init__.py b/applications/plugins/SofaImplicitField/examples/python/xshape/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/applications/plugins/SofaImplicitField/examples/python/xshape/operators.py b/applications/plugins/SofaImplicitField/examples/python/xshape/operators.py deleted file mode 100644 index 4506c1342a3..00000000000 --- a/applications/plugins/SofaImplicitField/examples/python/xshape/operators.py +++ /dev/null @@ -1,35 +0,0 @@ -from SofaImplicitField import ScalarField -import numpy - -class Union(ScalarField): - """Union of two scalar fields""" - def __init__(self, *args, **kwargs): - ScalarField.__init__(self, *args, **kwargs) - - self.childA = kwargs.get("childA", None) - self.childB = kwargs.get("childB", None) - - def getValue(self, position): - return min(self.childA.getValue(position), self.childB.getValue(position)) - -class Difference(ScalarField): - """Difference of two scalar fields""" - def __init__(self, *args, **kwargs): - ScalarField.__init__(self, *args, **kwargs) - - self.childA = kwargs.get("childA", None) - self.childB = kwargs.get("childB", None) - - def getValue(self, position): - return max(-self.childA.getValue(position), self.childB.getValue(position)) - -class Intersection(ScalarField): - """Intersection of two scalar fields""" - def __init__(self, *args, **kwargs): - ScalarField.__init__(self, *args, **kwargs) - - self.childA = kwargs.get("childA", None) - self.childB = kwargs.get("childB", None) - - def getValue(self, position): - return max(self.childA.getValue(position), self.childB.getValue(position)) \ No newline at end of file diff --git a/applications/plugins/SofaImplicitField/examples/python/xshape/primitives.py b/applications/plugins/SofaImplicitField/examples/python/xshape/primitives.py deleted file mode 100644 index 87f8a34fff2..00000000000 --- a/applications/plugins/SofaImplicitField/examples/python/xshape/primitives.py +++ /dev/null @@ -1,34 +0,0 @@ -"""Distance field function - -Sources: - https://iquilezles.org/articles/distfunctions/ -""" -from SofaImplicitField import ScalarField -import numpy - -class Sphere(ScalarField): - def __init__(self, *args, **kwargs): - ScalarField.__init__(self, *args, **kwargs) - - self.addData("center", type="Vec3d",value=kwargs.get("center", [0.0,0.0,0.0]), default=[0.0,0.0,0.0], help="center of the sphere", group="Geometry") - self.addData("radius", type="double",value=kwargs.get("radius", 1.0), default=1, help="radius of the sphere", group="Geometry") - - def getValue(self, pos): - x,y,z = pos - return numpy.linalg.norm(self.center.value - numpy.array([x,y,z])) - self.radius.value - -class RoundedBox(ScalarField): - def __init__(self, *args, **kwargs): - ScalarField.__init__(self, *args, **kwargs) - - self.addData("center", type="Vec3d",value=kwargs.get("center", [0.0,0.0,0.0]), default=[0.0,0.0,0.0], help="center of the sphere", group="Geometry") - self.addData("dimensions", type="Vec3d",value=kwargs.get("dimensions", [1.0,1.0,1.0]), default=[1.0,1.0,1.0], help="dimmension of the box", group="Geometry") - self.addData("rounding_radius", type="double",value=kwargs.get("rounding_radius", 0.1), default=0.1, help="radius of the sphere", group="Geometry") - - def getValue(self, pos): - x,y,z = pos - b = self.dimensions.value - r = self.rounding_radius.value - q = numpy.abs(self.center.value - numpy.array([x,y,z])) - b + r - res = numpy.linalg.norm(numpy.maximum(q, 0.0)) + min(max(q[0], max(q[1],q[2]) ), 0.0) - r - return res diff --git a/applications/plugins/SofaImplicitField/examples/python/xshape/transforms.py b/applications/plugins/SofaImplicitField/examples/python/xshape/transforms.py deleted file mode 100644 index 778b4f7dd7c..00000000000 --- a/applications/plugins/SofaImplicitField/examples/python/xshape/transforms.py +++ /dev/null @@ -1,15 +0,0 @@ -from SofaImplicitField import ScalarField -import numpy - -class Translate(ScalarField): - """Translate a scalar field given as attribute""" - def __init__(self, *args, **kwargs): - ScalarField.__init__(self, *args, **kwargs) - - self.addData("translate", type="Vec3d",value=kwargs.get("translate", [0.0,0.0,0.0]), default=[0.0,0.0,0.0], help="amount of translation", group="Geometry") - self.child = kwargs.get("child", None) - - def getValue(self, pos): - x,y,z = pos - position = numpy.array([x,y,z])-self.translate.value - return self.child.getValue(position) \ No newline at end of file diff --git a/applications/plugins/SofaImplicitField/initSofaImplicitField.cpp b/applications/plugins/SofaImplicitField/initSofaImplicitField.cpp deleted file mode 100644 index 9e3a2d51e6f..00000000000 --- a/applications/plugins/SofaImplicitField/initSofaImplicitField.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/****************************************************************************** -* 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 - -#include -#include -using sofa::helper::system::PluginManager ; - -namespace sofa::component::geometry::_BottleField_ -{ - extern void registerBottleField(sofa::core::ObjectFactory* factory); -} -namespace sofa::component::geometry::_sphericalfield_ -{ - extern void registerSphericalField(sofa::core::ObjectFactory* factory); -} -namespace sofa::component::geometry::_StarShapedField_ -{ - extern void registerStarShapedField(sofa::core::ObjectFactory* factory); -} -namespace sofaimplicitfield::mapping -{ - extern void registerImplicitSurfaceMapping(sofa::core::ObjectFactory* factory); -} -namespace sofa::component::container -{ - extern void registerInterpolatedImplicitSurface(sofa::core::ObjectFactory* factory); -} -namespace sofa::component::geometry::_discretegrid_ -{ - extern void registerDiscreteGridField(sofa::core::ObjectFactory* factory); -} -namespace sofaimplicitfield::component::engine -{ -extern void registerFieldToSurfaceMesh(sofa::core::ObjectFactory* factory); -} - -namespace sofaimplicitfield -{ - -extern "C" { - SOFA_SOFAIMPLICITFIELD_API void initExternalModule(); - SOFA_SOFAIMPLICITFIELD_API const char* getModuleName(); - SOFA_SOFAIMPLICITFIELD_API const char* getModuleVersion(); - SOFA_SOFAIMPLICITFIELD_API const char* getModuleLicense(); - SOFA_SOFAIMPLICITFIELD_API const char* getModuleDescription(); - SOFA_SOFAIMPLICITFIELD_API void registerObjects(sofa::core::ObjectFactory* factory); -} - -void initExternalModule() -{ - static bool first = true; - if (first) - { - // make sure that this plugin is registered into the PluginManager - sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); - - first = false; - } -} - -const char* getModuleName() -{ - return MODULE_NAME; -} - -const char* getModuleVersion() -{ - return MODULE_VERSION; -} - -const char* getModuleLicense() -{ - return "LGPL"; -} - -const char* getModuleDescription() -{ - return "ImplicitField describe shapes of objects using implicit equation. \n" - "In general of function of a n-dimentional space f(X) returns a scalar value \n" - "The surface is then defined as f(x) = aConstant."; -} - -void registerObjects(sofa::core::ObjectFactory* factory) -{ - sofa::component::geometry::_BottleField_::registerBottleField(factory); - sofa::component::geometry::_sphericalfield_::registerSphericalField(factory); - sofa::component::geometry::_StarShapedField_::registerStarShapedField(factory); - sofaimplicitfield::mapping::registerImplicitSurfaceMapping(factory); - sofa::component::container::registerInterpolatedImplicitSurface(factory); - sofa::component::geometry::_discretegrid_::registerDiscreteGridField(factory); - sofaimplicitfield::component::engine::registerFieldToSurfaceMesh(factory); -} - -} /// sofaimplicitfield diff --git a/applications/plugins/SofaImplicitField/initSofaImplicitField.h b/applications/plugins/SofaImplicitField/initSofaImplicitField.h deleted file mode 100644 index b7c7e37e2fd..00000000000 --- a/applications/plugins/SofaImplicitField/initSofaImplicitField.h +++ /dev/null @@ -1,37 +0,0 @@ -/****************************************************************************** -* 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 * -******************************************************************************/ -#ifndef SOFA_COMPONENT_VOLUMETRIC_DATA_INIT_H -#define SOFA_COMPONENT_VOLUMETRIC_DATA_INIT_H -#include - -namespace sofa -{ - -namespace component -{ - -} // namespace component - -} // namespace sofa - -#endif - diff --git a/applications/plugins/SofaImplicitField/python/CMakeLists.txt b/applications/plugins/SofaImplicitField/python/CMakeLists.txt deleted file mode 100644 index bd66bd9546b..00000000000 --- a/applications/plugins/SofaImplicitField/python/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -project(SofaImplicitField.Python) - -set(SOURCE_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/src/Binding_ScalarField.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/Module_SofaImplicitField.cpp -) - -set(HEADER_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/src/Binding_ScalarField.h -) - -if (NOT TARGET SofaPython3::Plugin) - find_package(SofaPython3 REQUIRED COMPONENTS Plugin Bindings.Sofa.Core) -endif() - -sofa_find_package(SofaImplicitField REQUIRED) - -SP3_add_python_module( - TARGET ${PROJECT_NAME} - PACKAGE SofaImplicitField.Python - MODULE SofaImplicitField - DESTINATION . - SOURCES ${SOURCE_FILES} - HEADERS ${HEADER_FILES} - DEPENDS SofaImplicitField SofaPython3::Plugin SofaPython3::Bindings.Sofa.Core -) diff --git a/applications/plugins/SofaImplicitField/python/src/Binding_ScalarField.cpp b/applications/plugins/SofaImplicitField/python/src/Binding_ScalarField.cpp deleted file mode 100644 index 927a801b7a3..00000000000 --- a/applications/plugins/SofaImplicitField/python/src/Binding_ScalarField.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/****************************************************************************** -* SofaImplicitField plugin * -* (c) 2024 CNRS, University of Lille, INRIA * -* * -* 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 . * -******************************************************************************* -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#include - -#include -#include -#include -#include - -#include "Binding_ScalarField.h" - -/// Makes an alias for the pybind11 namespace to increase readability. -namespace py { using namespace pybind11; } - -namespace sofaimplicitfield { -using namespace sofapython3; -using sofa::component::geometry::ScalarField; -using sofa::core::objectmodel::BaseObject; -using sofa::type::Vec3; -using sofa::type::Mat3x3; - -class ScalarField_Trampoline : public ScalarField { -public: - SOFA_CLASS(ScalarField_Trampoline, ScalarField); - - // Override this function so that it returns the actual python class name instead of - // "ScalarField_Trampoline" which correspond to this utility class. - std::string getClassName() const override - { - PythonEnvironment::gil acquire; - - // Get the actual class name from python. - return py::str(py::cast(this).get_type().attr("__name__")); - } - - double getValue(Vec3& pos, int& domain) override - { - SOFA_UNUSED(domain); - PythonEnvironment::gil acquire; - - PYBIND11_OVERLOAD_PURE(double, ScalarField, getValue, pos); - } - - Vec3 getGradient(Vec3& pos, int& domain) override - { - SOFA_UNUSED(domain); - PythonEnvironment::gil acquire; - - PYBIND11_OVERLOAD(Vec3, ScalarField, getGradient, pos); - } - - void getHessian(Vec3 &pos, Mat3x3& h) override - { - /// The implementation is a bit more complex compared to getGradient. This is because we change de signature between the c++ API and the python one. - PythonEnvironment::gil acquire; - - // Search if there is a python override, - pybind11::function override = pybind11::get_override(static_cast(this),"getHessian"); - if(!override){ - return ScalarField::getHessian(pos, h); - } - // as there is one override, we call it, passing the "pos" argument and storing the return of the - // value in the "o" variable. - auto o = override(pos); - - // then we check that the function correctly returned a Mat3x3 object and copy its value - // in case there is no Mat3x3 returned values, rise an error - if(py::isinstance(o)) - h = py::cast(o); - else - throw py::type_error("The function getHessian must return a Mat3x3"); - return; - } -}; - -void moduleAddScalarField(py::module &m) { - py::class_> f(m, "ScalarField", py::dynamic_attr(), ""); - - f.def(py::init([](py::args &args, py::kwargs &kwargs) { - auto ff = sofa::core::sptr (new ScalarField_Trampoline()); - - ff->f_listening.setValue(true); - - if (args.size() == 1) ff->setName(py::cast(args[0])); - - py::object cc = py::cast(ff); - for (auto kv : kwargs) { - std::string key = py::cast(kv.first); - py::object value = py::reinterpret_borrow(kv.second); - if (key == "name") { - if (args.size() != 0) { - throw py::type_error("The name is set twice as a " - "named argument='" + py::cast(value) + "' and as a" - "positional argument='" + - py::cast(args[0]) + "'."); - } - ff->setName(py::cast(value)); - } - } - return ff; - })); - - f.def("getValue", [](ScalarField* self, Vec3 pos){ - int domain=-1; - // This shouldn't be self->ScalarField::getValue because it is a pure function - // so there is not ScalarField::getValue emitted. - return self->getValue(pos, domain); - }); - - f.def("getGradient", [](ScalarField* self, Vec3 pos){ - int domain=-1; - return self->ScalarField::getGradient(pos, domain); - }); - - f.def("getHessian", [](ScalarField* self, Vec3 pos){ - Mat3x3 result; - self->getHessian(pos, result); - return result; - }); -} - -} diff --git a/applications/plugins/SofaImplicitField/python/src/Binding_ScalarField.h b/applications/plugins/SofaImplicitField/python/src/Binding_ScalarField.h deleted file mode 100644 index 8ab31e32945..00000000000 --- a/applications/plugins/SofaImplicitField/python/src/Binding_ScalarField.h +++ /dev/null @@ -1,29 +0,0 @@ -/****************************************************************************** -* SofaImplicitField plugin * -* (c) 2021 CNRS, University of Lille, INRIA * -* * -* 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 . * -******************************************************************************* -* Contact information: contact@sofa-framework.org * -******************************************************************************/ - -#pragma once - -#include - -namespace sofaimplicitfield { - -void moduleAddScalarField(pybind11::module &m); - -} diff --git a/applications/plugins/SofaImplicitField/python/src/Module_SofaImplicitField.cpp b/applications/plugins/SofaImplicitField/python/src/Module_SofaImplicitField.cpp deleted file mode 100644 index bd7e9480856..00000000000 --- a/applications/plugins/SofaImplicitField/python/src/Module_SofaImplicitField.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/****************************************************************************** -* SofaImplicitField plugin * -* (c) 2024 CNRS, University of Lille, INRIA * -* * -* 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 . * -******************************************************************************* -* Contact information: contact@sofa-framework.org * -******************************************************************************/ - -#include -namespace py = pybind11; - -#include "Binding_ScalarField.h" - -namespace sofaimplicitfield -{ - -PYBIND11_MODULE(SofaImplicitField, m) { - m.doc() = R"doc( - Implement scalar field representation in python - )doc"; - - moduleAddScalarField(m); -} - -} -