Skip to content

Commit 31b9a98

Browse files
authored
Merge branch 'SofaDefrost:main' into transfert-vers-shelladapt
2 parents ebaafd6 + 2b03750 commit 31b9a98

63 files changed

Lines changed: 19902 additions & 13 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ cmake_minimum_required(VERSION 3.12)
22
project(Shell VERSION 1.0 LANGUAGES CXX)
33

44
# Find and load CMake configuration of packages containing this plugin's dependencies
5-
find_package(Sofa.Component.Controller REQUIRED)
5+
find_package(Sofa.Config REQUIRED)
6+
sofa_find_package(Sofa.Component.Controller REQUIRED)
7+
sofa_find_package(Sofa.Component.Topology.Container.Dynamic REQUIRED)
68
sofa_find_package(Sofa.Component.StateContainer REQUIRED)
9+
sofa_find_package(Sofa.Component.Mapping.Linear REQUIRED)
10+
sofa_find_package(Sofa.GL REQUIRED)
711

12+
set(README_FILE README.md)
813

914
# List all files
1015
set(SHELL_SRC_DIR src/Shell)
@@ -13,32 +18,68 @@ set(HEADER_FILES
1318
${SHELL_SRC_DIR}/controller/MeshChangedEvent.h
1419
${SHELL_SRC_DIR}/controller/MeshInterpolator.h
1520
${SHELL_SRC_DIR}/controller/MeshInterpolator.inl
21+
${SHELL_SRC_DIR}/controller/TriangleSwitchExample.h
22+
${SHELL_SRC_DIR}/controller/TriangleSwitchExample.inl
1623
${SHELL_SRC_DIR}/engine/JoinMeshPoints.h
1724
${SHELL_SRC_DIR}/engine/JoinMeshPoints.inl
25+
${SHELL_SRC_DIR}/engine/FindClosePoints.h
26+
${SHELL_SRC_DIR}/engine/FindClosePoints.inl
27+
${SHELL_SRC_DIR}/forcefield/BezierTriangularBendingFEMForceField.h
28+
${SHELL_SRC_DIR}/forcefield/BezierTriangularBendingFEMForceField.inl
29+
${SHELL_SRC_DIR}/forcefield/CstFEMForceField.h
30+
${SHELL_SRC_DIR}/forcefield/CstFEMForceField.inl
1831
${SHELL_SRC_DIR}/forcefield/TriangularBendingFEMForceField.h
1932
${SHELL_SRC_DIR}/forcefield/TriangularBendingFEMForceField.inl
33+
${SHELL_SRC_DIR}/forcefield/TriangularShellForceField.h
34+
${SHELL_SRC_DIR}/forcefield/TriangularShellForceField.inl
35+
${SHELL_SRC_DIR}/mapping/BendingPlateMechanicalMapping.h
36+
${SHELL_SRC_DIR}/mapping/BendingPlateMechanicalMapping.inl
37+
${SHELL_SRC_DIR}/mapping/BezierTriangleMechanicalMapping.h
38+
${SHELL_SRC_DIR}/mapping/BezierTriangleMechanicalMapping.inl
39+
${SHELL_SRC_DIR}/misc/PointProjection.h
40+
${SHELL_SRC_DIR}/misc/PointProjection.inl
41+
${SHELL_SRC_DIR}/shells2/fem/BezierShellInterpolation.h
42+
${SHELL_SRC_DIR}/shells2/fem/BezierShellInterpolation.inl
43+
${SHELL_SRC_DIR}/shells2/fem/BezierShellInterpolationM.h
44+
${SHELL_SRC_DIR}/shells2/fem/BezierShellInterpolationM.inl
45+
${SHELL_SRC_DIR}/shells2/forcefield/BezierShellForceField.h
46+
${SHELL_SRC_DIR}/shells2/forcefield/BezierShellForceField.inl
47+
${SHELL_SRC_DIR}/shells2/mapping/BezierShellMechanicalMapping.h
48+
${SHELL_SRC_DIR}/shells2/mapping/BezierShellMechanicalMapping.inl
2049
)
50+
2151
set(SOURCE_FILES
2252
${SHELL_SRC_DIR}/initShell.cpp
2353
${SHELL_SRC_DIR}/controller/MeshChangedEvent.cpp
2454
${SHELL_SRC_DIR}/controller/MeshInterpolator.cpp
55+
${SHELL_SRC_DIR}/controller/TriangleSwitchExample.cpp
2556
${SHELL_SRC_DIR}/engine/JoinMeshPoints.cpp
57+
${SHELL_SRC_DIR}/engine/FindClosePoints.cpp
58+
${SHELL_SRC_DIR}/forcefield/BezierTriangularBendingFEMForceField.cpp
59+
${SHELL_SRC_DIR}/forcefield/CstFEMForceField.cpp
2660
${SHELL_SRC_DIR}/forcefield/TriangularBendingFEMForceField.cpp
27-
)
28-
set(README_FILES
29-
README.md
61+
${SHELL_SRC_DIR}/forcefield/TriangularShellForceField.cpp
62+
${SHELL_SRC_DIR}/mapping/BendingPlateMechanicalMapping.cpp
63+
${SHELL_SRC_DIR}/mapping/BezierTriangleMechanicalMapping.cpp
64+
${SHELL_SRC_DIR}/misc/PointProjection.cpp
65+
${SHELL_SRC_DIR}/shells2/fem/BezierShellInterpolation.cpp
66+
${SHELL_SRC_DIR}/shells2/fem/BezierShellInterpolationM.cpp
67+
${SHELL_SRC_DIR}/shells2/forcefield/BezierShellForceField.cpp
68+
${SHELL_SRC_DIR}/shells2/mapping/BezierShellMechanicalMapping.cpp
3069
)
3170

32-
# Create the plugin library.
71+
# Create the plugin library
3372
add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${README_FILES})
3473

3574
# Link the plugin library to its dependency(ies).
36-
target_link_libraries(${PROJECT_NAME} Sofa.Component.Controller Sofa.Component.StateContainer)
75+
target_link_libraries(${PROJECT_NAME}
76+
Sofa.Component.Controller
77+
Sofa.Component.Topology.Container.Dynamic
78+
Sofa.Component.StateContainer
79+
Sofa.Component.Mapping.Linear
80+
Sofa.GL
81+
)
3782

38-
# Create package Config, Version & Target files.
39-
# Deploy the headers, resources, scenes & examples.
40-
# Set the plugin 'relocatable' if built within SOFA.
41-
# --> see SofaMacros.cmake
4283
sofa_create_package_with_targets(
4384
PACKAGE_NAME ${PROJECT_NAME}
4485
PACKAGE_VERSION ${PROJECT_VERSION}
@@ -47,3 +88,5 @@ sofa_create_package_with_targets(
4788
INCLUDE_INSTALL_DIR ${PROJECT_NAME}
4889
RELOCATABLE "plugins"
4990
)
91+
92+
sofa_add_subdirectory(plugin extensions/Shell.Adaptivity Shell.Adaptivity)
Binary file not shown.

examples/xml/ShellTest.scn

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727
<SparseLDLSolver template="CompressedRowSparseMatrixMat3x3d"/>
2828
<MeshOBJLoader name="loader" filename="mesh/square1.obj"/>
2929
<MeshTopology name="topology" src="@loader"/>
30-
<MechanicalObject template="Rigid3"/>
30+
<MechanicalObject template="Rigid3d"/>
3131
<UniformMass totalMass="0.005"/>
3232
<BoxROI name="box" box="0 0.9 -0.1 1 1 0.1" drawBoxes="1"/>
33-
<FixedConstraint indices="@box.indices"/>
33+
<FixedProjectiveConstraint indices="@box.indices"/>
3434
<TriangularBendingFEMForceField youngModulus="1.7e3" poissonRatio="0.3" thickness="0.01"/>
35+
3536

3637
<Node name="Visu">
3738

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# CMakeLists.txt for Shell.Adaptivity plugin
2+
cmake_minimum_required(VERSION 3.12)
3+
project(Shell.Adaptivity VERSION 1.0 LANGUAGES CXX)
4+
5+
find_package(Sofa.Config REQUIRED)
6+
sofa_find_package(Shell REQUIRED)
7+
sofa_find_package(Sofa.GUI.Component REQUIRED)
8+
sofa_find_package(Sofa.GUI.Common REQUIRED)
9+
10+
set(HEADER_FILES
11+
src/Shell/Adaptivity/config.h.in
12+
src/Shell/Adaptivity/init.h
13+
14+
src/Shell/Adaptivity/controller/AdaptiveCuttingController.h
15+
src/Shell/Adaptivity/controller/AdaptiveCuttingController.inl
16+
src/Shell/Adaptivity/controller/Test2DAdapter.h
17+
src/Shell/Adaptivity/controller/Test2DAdapter.inl
18+
19+
src/Shell/Adaptivity/cutting/AdaptiveCutting.h
20+
21+
src/Shell/Adaptivity/misc/Optimize2DSurface.h
22+
src/Shell/Adaptivity/misc/Optimize2DSurface.inl
23+
src/Shell/Adaptivity/misc/SurfaceParametrization.h
24+
src/Shell/Adaptivity/misc/SurfaceParametrization.inl
25+
)
26+
27+
set(SOURCE_FILES
28+
src/Shell/Adaptivity/init.cpp
29+
30+
src/Shell/Adaptivity/controller/AdaptiveCuttingController.cpp
31+
src/Shell/Adaptivity/controller/Test2DAdapter.cpp
32+
33+
src/Shell/Adaptivity/cutting/AdaptiveCutting.cpp
34+
35+
src/Shell/Adaptivity/misc/Optimize2DSurface.cpp
36+
src/Shell/Adaptivity/misc/SurfaceParametrization.cpp
37+
)
38+
39+
add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
40+
target_link_libraries(${PROJECT_NAME} PUBLIC Shell Sofa.GUI.Component Sofa.GUI.Common)
41+
42+
sofa_create_package_with_targets(
43+
PACKAGE_NAME ${PROJECT_NAME}
44+
PACKAGE_VERSION ${PROJECT_VERSION}
45+
TARGETS ${PROJECT_NAME} AUTO_SET_TARGET_PROPERTIES
46+
INCLUDE_SOURCE_DIR "src"
47+
INCLUDE_INSTALL_DIR ${PROJECT_NAME}
48+
RELOCATABLE "plugins"
49+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# CMake package configuration file for the plugin @PROJECT_NAME@
2+
3+
@PACKAGE_GUARD@
4+
@PACKAGE_INIT@
5+
6+
find_package(Shell QUIET REQUIRED)
7+
8+
if(NOT TARGET @PROJECT_NAME@)
9+
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
10+
endif()
11+
12+
check_required_components(Shell.Adaptivity)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
#include <sofa/config.h>
3+
4+
#ifdef SOFA_BUILD_SHELL_ADAPTIVITY
5+
# define SOFA_TARGET @PROJECT_NAME@
6+
# define SHELL_ADAPTIVITY_API SOFA_EXPORT_DYNAMIC_LIBRARY
7+
#else
8+
# define SHELL_ADAPTIVITY_API SOFA_IMPORT_DYNAMIC_LIBRARY
9+
#endif
10+
11+
namespace shelladaptivity
12+
{
13+
constexpr const char* MODULE_NAME = "@PROJECT_NAME@";
14+
constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@";
15+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <Shell/Adaptivity/config.h>
2+
#include <Shell/Adaptivity/controller/AdaptiveCuttingController.inl>
3+
#include <sofa/core/ObjectFactory.h>
4+
5+
6+
namespace sofa
7+
{
8+
9+
namespace component
10+
{
11+
12+
namespace controller
13+
{
14+
15+
using namespace sofa::defaulttype;
16+
17+
SOFA_DECL_CLASS(AdaptiveCuttingController)
18+
19+
// Register in the Factory
20+
int AdaptiveCuttingControllerClass = core::RegisterObject(
21+
"Controller that handles the cutting method based on mesh adaptivity.")
22+
#ifdef SOFA_FLOAT
23+
.add< AdaptiveCuttingController<defaulttype::Vec3fTypes> >(true) // default template
24+
#else
25+
.add< AdaptiveCuttingController<defaulttype::Vec3dTypes> >(true) // default template
26+
# ifndef SOFA_DOUBLE
27+
.add< AdaptiveCuttingController<defaulttype::Vec3fTypes> >()
28+
# endif
29+
#endif
30+
;
31+
32+
#ifndef SOFA_FLOAT
33+
template class SHELL_ADAPTIVITY_API AdaptiveCuttingController<defaulttype::Vec3dTypes>;
34+
#endif //SOFA_FLOAT
35+
#ifndef SOFA_DOUBLE
36+
template class SHELL_ADAPTIVITY_API AdaptiveCuttingController<defaulttype::Vec3fTypes>;
37+
#endif //SOFA_DOUBLE
38+
39+
} // namespace controller
40+
41+
} // namespace component
42+
43+
} // namespace sofa
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
#ifndef SOFA_COMPONENT_CONTROLLER_ADAPTIVECUTTINGCONTROLLER_H
2+
#define SOFA_COMPONENT_CONTROLLER_ADAPTIVECUTTINGCONTROLLER_H
3+
4+
#include <sofa/component/controller/Controller.h>
5+
6+
#include <sofa/defaulttype/VecTypes.h>
7+
#include <sofa/type/Vec.h>
8+
9+
#include <sofa/core/behavior/MechanicalState.h>
10+
#include <sofa/core/topology/BaseMeshTopology.h>
11+
#include <sofa/gui/component/performer/MouseInteractor.h>
12+
#include <sofa/component/topology/container/dynamic/TriangleSetTopologyContainer.h>
13+
#include <sofa/component/topology/container/dynamic/TriangleSetTopologyModifier.h>
14+
#include <sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.h>
15+
#include <sofa/core/topology/TopologyData.h>
16+
17+
#include <sofa/helper/map.h>
18+
#include <sofa/type/vector.h>
19+
20+
#include <Shell/Adaptivity/controller/Test2DAdapter.h>
21+
22+
namespace sofa
23+
{
24+
25+
namespace component
26+
{
27+
28+
namespace controller
29+
{
30+
31+
/// Class to shield the data type
32+
class CuttingAdapter
33+
{
34+
public:
35+
virtual void setTrackedPoint(const sofa::gui::component::performer::BodyPicked &picked) = 0;
36+
virtual void freeTrackedPoint() = 0;
37+
virtual void addCuttingPoint() = 0;
38+
};
39+
40+
template<class DataTypes>
41+
class AdaptiveCuttingController : public Controller, public CuttingAdapter
42+
{
43+
public:
44+
SOFA_CLASS(SOFA_TEMPLATE(AdaptiveCuttingController,DataTypes),Controller);
45+
46+
typedef typename DataTypes::Coord Coord;
47+
typedef typename DataTypes::VecCoord VecCoord;
48+
//typedef typename DataTypes::Deriv Deriv;
49+
//typedef typename DataTypes::VecDeriv VecDeriv;
50+
typedef typename Coord::value_type Real;
51+
52+
typedef sofa::type::Vec<2, Real> Vec2;
53+
typedef sofa::type::Vec<3, Real> Vec3;
54+
//typedef sofa::type::Mat<2,2,Real> Mat22;
55+
//typedef sofa::type::Mat<3,3,Real> Mat33;
56+
//typedef type::vector<Vec2> VecVec2;
57+
//typedef type::vector<Vec3> VecVec3;
58+
59+
60+
typedef sofa::core::topology::BaseMeshTopology::Edge Edge;
61+
typedef sofa::core::topology::BaseMeshTopology::EdgesAroundVertex EdgesAroundVertex;
62+
typedef sofa::component::topology::container::dynamic::TriangleSetTopologyContainer::TriangleID Index;
63+
typedef sofa::component::topology::container::dynamic::TriangleSetTopologyContainer::Triangle Triangle;
64+
typedef sofa::component::topology::container::dynamic::TriangleSetTopologyContainer::TrianglesAroundVertex TrianglesAroundVertex;
65+
typedef sofa::component::topology::container::dynamic::TriangleSetTopologyContainer::TrianglesAroundEdge TrianglesAroundEdge;
66+
typedef sofa::component::topology::container::dynamic::TriangleSetTopologyContainer::EdgesInTriangle EdgesInTriangle;
67+
typedef sofa::type::vector<Index> VecIndex;
68+
69+
enum { InvalidID = sofa::core::topology::Topology::InvalidID };
70+
71+
/// @brief If geometric functinal drops below this value the attached node
72+
/// is dropped.
73+
Data<Real> m_affinity;
74+
75+
virtual void init();
76+
virtual void reinit();
77+
78+
void onEndAnimationStep(const double dt);
79+
//void onKeyPressedEvent(core::objectmodel::KeypressedEvent *key);
80+
81+
void draw(const core::visual::VisualParams* vparams);
82+
83+
84+
void setTrackedPoint(const sofa::gui::component::performer::BodyPicked &picked);
85+
void freeTrackedPoint() {
86+
// Detach the point
87+
m_pointId = InvalidID;
88+
// Stop cutting
89+
m_cutPoints = 0;
90+
m_cutEdge = InvalidID;
91+
}
92+
void addCuttingPoint();
93+
94+
/// Whether the cutting is in progress or not.
95+
bool cutting() { return m_cutPoints > 0; }
96+
97+
protected:
98+
99+
AdaptiveCuttingController();
100+
101+
102+
private:
103+
104+
Test2DAdapter<DataTypes>* m_adapter;
105+
sofa::component::topology::container::dynamic::TriangleSetTopologyContainer* m_container;
106+
sofa::component::topology::container::dynamic::TriangleSetGeometryAlgorithms<DataTypes> *m_algoGeom;
107+
sofa::core::behavior::MechanicalState<DataTypes>* m_state;
108+
109+
// TODO: This should go to cutting config (maybe?)
110+
bool autoCutting;
111+
112+
113+
/// Closest point in the mstate.
114+
Index m_pointId;
115+
/// A point on a surface to attract to (valid only if m_pointId != InvalidID).
116+
Vec3 m_point;
117+
/// Position of m_point projected into rest shape.
118+
Vec3 m_pointRest;
119+
/// @brief Triangle ID inside which m_point is located (valid only if
120+
///m_pointId != InvalidID).
121+
Index m_pointTriId;
122+
/// @brief Number of iterations during which the attached node will not be
123+
/// reattached.
124+
unsigned int m_gracePeriod;
125+
126+
/// @brief Stored index of the first edge to cut when the first cut has
127+
/// been delayed.
128+
Index m_cutEdge;
129+
/// Last cutting point.
130+
Index m_cutLastPoint;
131+
/// Cutting operation to perform in this step.
132+
VecIndex m_cutList;
133+
/// Number of cut points defined.
134+
int m_cutPoints;
135+
136+
void switchPoint(const Vec3 &newPoint, const Index newPointTri,
137+
const Index newID, const Index newCutEdge);
138+
139+
/**
140+
* Set edge planned for the next cut.
141+
*
142+
* @param newCutEdge Index of new edge to use.
143+
* @param bKeepProtection Whether to keep edge protection for previous
144+
* edge.
145+
*/
146+
void setCutEdge(const Index newCutEdge, const bool bKeepProtection=false);
147+
148+
};
149+
150+
151+
} // namespace controller
152+
153+
} // namespace component
154+
155+
} // namespace sofa
156+
157+
#endif // #ifndef SOFA_COMPONENT_CONTROLLER_ADAPTIVECUTTINGCONTROLLER_H

0 commit comments

Comments
 (0)