Skip to content

Commit 16dcf2a

Browse files
authored
[src] Add new engine ProximityOscillatorConstraint that compute oscillation motion of points between rest_position and closest target (#38)
* backup work on center motion * backup work * Fix behavior with totally new mechanism * totally change name an clean Data * fix typo * Add basic example
1 parent c922578 commit 16dcf2a

File tree

7 files changed

+453
-0
lines changed

7 files changed

+453
-0
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ set(HEADER_FILES
3535
${INFINYTOOLKIT_SRC_DIR}/NeedleTracker.h
3636
${INFINYTOOLKIT_SRC_DIR}/MiddleForceField.h
3737
${INFINYTOOLKIT_SRC_DIR}/MiddleForceField.inl
38+
${INFINYTOOLKIT_SRC_DIR}/ProximityOscillatorConstraint.h
39+
${INFINYTOOLKIT_SRC_DIR}/ProximityOscillatorConstraint.inl
3840
${INFINYTOOLKIT_SRC_DIR}/Triangle2RefinedTriangleTopologicalMapping.h
3941

4042
## Carving tools sections
@@ -67,6 +69,7 @@ set(SOURCE_FILES
6769
${INFINYTOOLKIT_SRC_DIR}/HapticEmulator.cpp
6870
${INFINYTOOLKIT_SRC_DIR}/NeedleTracker.cpp
6971
${INFINYTOOLKIT_SRC_DIR}/MiddleForceField.cpp
72+
${INFINYTOOLKIT_SRC_DIR}/ProximityOscillatorConstraint.cpp
7073
${INFINYTOOLKIT_SRC_DIR}/Triangle2RefinedTriangleTopologicalMapping.cpp
7174

7275
## Carving tools sections
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" ?>
2+
<Node name="root" dt="0.03" showBoundingTree="0" gravity="0 -0.9 0">
3+
<Node name="RequiredPlugins">
4+
<RequiredPlugin name="Sofa.Component.Collision.Detection.Algorithm"/> <!-- Needed to use components [BVHNarrowPhase, BruteForceBroadPhase, CollisionPipeline] -->
5+
<RequiredPlugin name="Sofa.Component.Collision.Detection.Intersection"/> <!-- Needed to use components [MinProximityIntersection] -->
6+
<RequiredPlugin name="Sofa.Component.Collision.Geometry"/> <!-- Needed to use components [TriangleCollisionModel] -->
7+
<RequiredPlugin name="Sofa.Component.Collision.Response.Contact"/> <!-- Needed to use components [DefaultContactManager] -->
8+
<RequiredPlugin name="Sofa.Component.Constraint.Projective"/> <!-- Needed to use components [FixedConstraint] -->
9+
<RequiredPlugin name="Sofa.Component.Engine.Select"/> <!-- Needed to use components [BoxROI] -->
10+
<RequiredPlugin name="Sofa.Component.IO.Mesh"/> <!-- Needed to use components [MeshGmshLoader] -->
11+
<RequiredPlugin name="Sofa.Component.LinearSolver.Iterative"/> <!-- Needed to use components [CGLinearSolver] -->
12+
<RequiredPlugin name="Sofa.Component.Mapping.Linear"/> <!-- Needed to use components [IdentityMapping] -->
13+
<RequiredPlugin name="Sofa.Component.Mass"/> <!-- Needed to use components [DiagonalMass] -->
14+
<RequiredPlugin name="Sofa.Component.ODESolver.Backward"/> <!-- Needed to use components [EulerImplicitSolver] -->
15+
<RequiredPlugin name="Sofa.Component.SceneUtility"/> <!-- Needed to use components [InfoComponent] -->
16+
<RequiredPlugin name="Sofa.Component.SolidMechanics.FEM.Elastic"/> <!-- Needed to use components [TetrahedralCorotationalFEMForceField] -->
17+
<RequiredPlugin name="Sofa.Component.StateContainer"/> <!-- Needed to use components [MechanicalObject] -->
18+
<RequiredPlugin name="Sofa.Component.Topology.Container.Dynamic"/> <!-- Needed to use components [TetrahedronSetGeometryAlgorithms, TetrahedronSetTopologyContainer, TetrahedronSetTopologyModifier, TriangleSetGeometryAlgorithms, TriangleSetTopologyContainer, TriangleSetTopologyModifier] -->
19+
<RequiredPlugin name="Sofa.Component.Topology.Mapping"/> <!-- Needed to use components [Tetra2TriangleTopologicalMapping] -->
20+
<RequiredPlugin name="Sofa.Component.Visual"/> <!-- Needed to use components [VisualStyle] -->
21+
<RequiredPlugin name="Sofa.GL.Component.Rendering3D"/> <!-- Needed to use components [OglModel] -->
22+
<RequiredPlugin name="InfinyToolkit" />
23+
</Node>
24+
25+
<VisualStyle displayFlags="showVisual hideCollisionModels showForceFields showBehaviorModels" />
26+
27+
<DefaultAnimationLoop />
28+
<DefaultVisualManagerLoop />
29+
<CollisionPipeline verbose="0" />
30+
<BruteForceBroadPhase/>
31+
<BVHNarrowPhase/>
32+
<CollisionResponse response="PenalityContactForceField" />
33+
<MinProximityIntersection name="Proximity" alarmDistance="1.0" contactDistance="0.1"/>
34+
35+
36+
<Node name="SurfaceGrid">
37+
<RegularGridTopology name="grid" nx="20" ny="20" nz="3" xmin="0" xmax="20" ymin="0" ymax="20" zmin="0" zmax="2" drawEdges="0"/>
38+
</Node>
39+
40+
<Node name="WaveMotion">
41+
<RegularGridTopology name="centers" nx="20" ny="20" nz="1" xmin="0" xmax="20" ymin="0" ymax="20" zmin="-6" zmax="-6" drawEdges="0"/>
42+
<ProximityOscillatorConstraint name="center" amplitude="1.0" pace="10.5" showMotion="1" position="@../SurfaceGrid/grid.position" centers="@centers.position"/>
43+
<MechanicalObject name='dofs' position="@center.outputPositions" showObject="0"/>
44+
</Node>
45+
46+
<Node name="DeformableGrid">
47+
<EulerImplicitSolver name="cg_odesolver" rayleighStiffness="0.1" rayleighMass="0.1" />
48+
<CGLinearSolver iterations="15" name="linear solver" tolerance="1.0e-4" threshold="1.0e-4" />
49+
50+
<MechanicalObject position="@SurfaceGrid/grid.position" name="dofs" />
51+
52+
<HexahedronSetTopologyContainer name='Container' src="@../SurfaceGrid/grid"/>
53+
<HexahedronSetTopologyModifier name='Modifier'/>
54+
<HexahedronSetGeometryAlgorithms name='GeomAlgo' template='Vec3d'/>
55+
56+
<DiagonalMass totalMass="1.0" />
57+
58+
<HexahedronFEMForceField
59+
name='FEM'
60+
youngModulus='1000'
61+
poissonRatio='0.3'
62+
method='large'
63+
/>
64+
65+
<RestShapeSpringsForceField external_rest_shape="@WaveMotion/dofs"
66+
stiffness="200" angularStiffness="1000" />
67+
</Node>
68+
</Node>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Camera version="1.0">
3+
<!--Vector of 3 reals (x, y, z)-->
4+
<position value="24.3902 10.2953 7.4892"/>
5+
<!--Quaternion (x, y, z, w)-->
6+
<orientation value="0.356487 0.486826 0.666412 0.437964"/>
7+
<!--Real-->
8+
<fieldOfView value="45"/>
9+
<!--Real-->
10+
<distance value="0"/>
11+
<!--Real-->
12+
<zNear value="0.75"/>
13+
<!--Real-->
14+
<zFar value="45.7499"/>
15+
<!--Int (0 -> Perspective, 1 -> Orthographic)-->
16+
<projectionType value="Perspective"/>
17+
</Camera>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*****************************************************************************
2+
* - Copyright (C) - 2020 - InfinyTech3D - *
3+
* *
4+
* This file is part of the InfinyToolkit plugin for the SOFA framework *
5+
* *
6+
* Commercial License Usage: *
7+
* Licensees holding valid commercial license from InfinyTech3D may use this *
8+
* file in accordance with the commercial license agreement provided with *
9+
* the Software or, alternatively, in accordance with the terms contained in *
10+
* a written agreement between you and InfinyTech3D. For further information *
11+
* on the licensing terms and conditions, contact: [email protected] *
12+
* *
13+
* GNU General Public License Usage: *
14+
* Alternatively, this file may be used under the terms of the GNU General *
15+
* Public License version 3. The licenses are as published by the Free *
16+
* Software Foundation and appearing in the file LICENSE.GPL3 included in *
17+
* the packaging of this file. Please review the following information to *
18+
* ensure the GNU General Public License requirements will be met: *
19+
* https://www.gnu.org/licenses/gpl-3.0.html. *
20+
* *
21+
* Authors: see Authors.txt *
22+
* Further information: https://infinytech3d.com *
23+
****************************************************************************/
24+
25+
#define SOFA_COMPONENT_FORCEFIELD_ProximityOscillatorConstraint_CPP
26+
27+
#include <sofa/core/ObjectFactory.h>
28+
#include <InfinyToolkit/ProximityOscillatorConstraint.inl>
29+
30+
namespace sofa::infinytoolkit
31+
{
32+
33+
using namespace sofa::defaulttype;
34+
35+
void registerProximityOscillatorConstraint(sofa::core::ObjectFactory* factory)
36+
{
37+
factory->registerObjects(sofa::core::ObjectRegistrationData("Middle interpolated force applied to given degrees of freedom.")
38+
.add< ProximityOscillatorConstraint<Vec3Types> >());
39+
}
40+
41+
template class SOFA_INFINYTOOLKIT_API ProximityOscillatorConstraint<Vec3Types>;
42+
43+
} // namespace sofa::infinytoolkit
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*****************************************************************************
2+
* - Copyright (C) - 2020 - InfinyTech3D - *
3+
* *
4+
* This file is part of the InfinyToolkit plugin for the SOFA framework *
5+
* *
6+
* Commercial License Usage: *
7+
* Licensees holding valid commercial license from InfinyTech3D may use this *
8+
* file in accordance with the commercial license agreement provided with *
9+
* the Software or, alternatively, in accordance with the terms contained in *
10+
* a written agreement between you and InfinyTech3D. For further information *
11+
* on the licensing terms and conditions, contact: [email protected] *
12+
* *
13+
* GNU General Public License Usage: *
14+
* Alternatively, this file may be used under the terms of the GNU General *
15+
* Public License version 3. The licenses are as published by the Free *
16+
* Software Foundation and appearing in the file LICENSE.GPL3 included in *
17+
* the packaging of this file. Please review the following information to *
18+
* ensure the GNU General Public License requirements will be met: *
19+
* https://www.gnu.org/licenses/gpl-3.0.html. *
20+
* *
21+
* Authors: see Authors.txt *
22+
* Further information: https://infinytech3d.com *
23+
****************************************************************************/
24+
#pragma once
25+
26+
#include <InfinyToolkit/config.h>
27+
#include <sofa/core/DataEngine.h>
28+
29+
#include <chrono>
30+
31+
namespace sofa::infinytoolkit
32+
{
33+
using sofa::core::DataEngine;
34+
35+
/** Apply forces changing to given degres of freedom. Some keyTimes are given
36+
* and the force to be applied is linearly interpolated between keyTimes. */
37+
template<class DataTypes>
38+
class ProximityOscillatorConstraint : public DataEngine
39+
{
40+
public:
41+
SOFA_CLASS(SOFA_TEMPLATE(ProximityOscillatorConstraint, DataTypes), core::DataEngine);
42+
43+
using VecCoord = typename DataTypes::VecCoord;
44+
using VecDeriv = typename DataTypes::VecDeriv;
45+
using Coord = typename DataTypes::Coord;
46+
using Deriv = typename DataTypes::Deriv;
47+
using Real = typename Coord::value_type;
48+
using DataVecCoord = core::objectmodel::Data<VecCoord>;
49+
using DataVecDeriv = core::objectmodel::Data<VecDeriv>;
50+
51+
ProximityOscillatorConstraint();
52+
53+
void init() override;
54+
55+
void doUpdate() override;
56+
void handleEvent(sofa::core::objectmodel::Event* event) override;
57+
58+
void draw(const core::visual::VisualParams* vparams) override;
59+
60+
protected:
61+
/// Will compute the barycenter of the given set of coordinates.
62+
void computeBarycenter();
63+
64+
void computeDistribution();
65+
66+
public:
67+
/// List of coordinates points
68+
Data<VecCoord> d_positions;
69+
Data<VecCoord> d_outputPositions;
70+
71+
/// List of coordinates points
72+
Data<VecCoord> d_centers;
73+
VecCoord m_centersOrdered;
74+
75+
/// Time to perform a full Pace (deflate + inflate). Same scale as the simulation time.
76+
Data<Real> d_pace;
77+
78+
Data<Real> d_amplitude;
79+
80+
/// Parameter to display the force direction
81+
Data<bool> p_showMotion;
82+
83+
private :
84+
// keep trace of the latest time we measured
85+
std::chrono::time_point<std::chrono::system_clock> m_startTime;
86+
87+
std::vector<int> m_distribution;
88+
89+
Real m_startTimeWave = 1.0;
90+
int centerDone = -4;
91+
int centerStart = 0;
92+
int centerCurrent = 0;
93+
Real nextStart = 0.0;
94+
95+
Real length = 4.0_sreal;
96+
//Real current
97+
98+
}; // definition of the ProximityOscillatorConstraint class
99+
100+
101+
102+
#if !defined(SOFA_COMPONENT_FORCEFIELD_ProximityOscillatorConstraint_CPP)
103+
extern template class SOFA_INFINYTOOLKIT_API ProximityOscillatorConstraint<sofa::defaulttype::Vec3Types>;
104+
#endif // !defined(SOFA_COMPONENT_FORCEFIELD_ProximityOscillatorConstraint_CPP)
105+
106+
} // namespace sofa::infinytoolkit

0 commit comments

Comments
 (0)