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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ set(HEADER_FILES
${INFINYTOOLKIT_SRC_DIR}/NeedleTracker.h
${INFINYTOOLKIT_SRC_DIR}/MiddleForceField.h
${INFINYTOOLKIT_SRC_DIR}/MiddleForceField.inl
${INFINYTOOLKIT_SRC_DIR}/ProximityOscillatorConstraint.h
${INFINYTOOLKIT_SRC_DIR}/ProximityOscillatorConstraint.inl
${INFINYTOOLKIT_SRC_DIR}/Triangle2RefinedTriangleTopologicalMapping.h

## Carving tools sections
Expand Down Expand Up @@ -67,6 +69,7 @@ set(SOURCE_FILES
${INFINYTOOLKIT_SRC_DIR}/HapticEmulator.cpp
${INFINYTOOLKIT_SRC_DIR}/NeedleTracker.cpp
${INFINYTOOLKIT_SRC_DIR}/MiddleForceField.cpp
${INFINYTOOLKIT_SRC_DIR}/ProximityOscillatorConstraint.cpp
${INFINYTOOLKIT_SRC_DIR}/Triangle2RefinedTriangleTopologicalMapping.cpp

## Carving tools sections
Expand Down
68 changes: 68 additions & 0 deletions examples/ProximityOscillatorConstraint.scn
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" ?>
<Node name="root" dt="0.03" showBoundingTree="0" gravity="0 -0.9 0">
<Node name="RequiredPlugins">
<RequiredPlugin name="Sofa.Component.Collision.Detection.Algorithm"/> <!-- Needed to use components [BVHNarrowPhase, BruteForceBroadPhase, CollisionPipeline] -->
<RequiredPlugin name="Sofa.Component.Collision.Detection.Intersection"/> <!-- Needed to use components [MinProximityIntersection] -->
<RequiredPlugin name="Sofa.Component.Collision.Geometry"/> <!-- Needed to use components [TriangleCollisionModel] -->
<RequiredPlugin name="Sofa.Component.Collision.Response.Contact"/> <!-- Needed to use components [DefaultContactManager] -->
<RequiredPlugin name="Sofa.Component.Constraint.Projective"/> <!-- Needed to use components [FixedConstraint] -->
<RequiredPlugin name="Sofa.Component.Engine.Select"/> <!-- Needed to use components [BoxROI] -->
<RequiredPlugin name="Sofa.Component.IO.Mesh"/> <!-- Needed to use components [MeshGmshLoader] -->
<RequiredPlugin name="Sofa.Component.LinearSolver.Iterative"/> <!-- Needed to use components [CGLinearSolver] -->
<RequiredPlugin name="Sofa.Component.Mapping.Linear"/> <!-- Needed to use components [IdentityMapping] -->
<RequiredPlugin name="Sofa.Component.Mass"/> <!-- Needed to use components [DiagonalMass] -->
<RequiredPlugin name="Sofa.Component.ODESolver.Backward"/> <!-- Needed to use components [EulerImplicitSolver] -->
<RequiredPlugin name="Sofa.Component.SceneUtility"/> <!-- Needed to use components [InfoComponent] -->
<RequiredPlugin name="Sofa.Component.SolidMechanics.FEM.Elastic"/> <!-- Needed to use components [TetrahedralCorotationalFEMForceField] -->
<RequiredPlugin name="Sofa.Component.StateContainer"/> <!-- Needed to use components [MechanicalObject] -->
<RequiredPlugin name="Sofa.Component.Topology.Container.Dynamic"/> <!-- Needed to use components [TetrahedronSetGeometryAlgorithms, TetrahedronSetTopologyContainer, TetrahedronSetTopologyModifier, TriangleSetGeometryAlgorithms, TriangleSetTopologyContainer, TriangleSetTopologyModifier] -->
<RequiredPlugin name="Sofa.Component.Topology.Mapping"/> <!-- Needed to use components [Tetra2TriangleTopologicalMapping] -->
<RequiredPlugin name="Sofa.Component.Visual"/> <!-- Needed to use components [VisualStyle] -->
<RequiredPlugin name="Sofa.GL.Component.Rendering3D"/> <!-- Needed to use components [OglModel] -->
<RequiredPlugin name="InfinyToolkit" />
</Node>

<VisualStyle displayFlags="showVisual hideCollisionModels showForceFields showBehaviorModels" />

<DefaultAnimationLoop />
<DefaultVisualManagerLoop />
<CollisionPipeline verbose="0" />
<BruteForceBroadPhase/>
<BVHNarrowPhase/>
<CollisionResponse response="PenalityContactForceField" />
<MinProximityIntersection name="Proximity" alarmDistance="1.0" contactDistance="0.1"/>


<Node name="SurfaceGrid">
<RegularGridTopology name="grid" nx="20" ny="20" nz="3" xmin="0" xmax="20" ymin="0" ymax="20" zmin="0" zmax="2" drawEdges="0"/>
</Node>

<Node name="WaveMotion">
<RegularGridTopology name="centers" nx="20" ny="20" nz="1" xmin="0" xmax="20" ymin="0" ymax="20" zmin="-6" zmax="-6" drawEdges="0"/>
<ProximityOscillatorConstraint name="center" amplitude="1.0" pace="10.5" showMotion="1" position="@../SurfaceGrid/grid.position" centers="@centers.position"/>
<MechanicalObject name='dofs' position="@center.outputPositions" showObject="0"/>
</Node>

<Node name="DeformableGrid">
<EulerImplicitSolver name="cg_odesolver" rayleighStiffness="0.1" rayleighMass="0.1" />
<CGLinearSolver iterations="15" name="linear solver" tolerance="1.0e-4" threshold="1.0e-4" />

<MechanicalObject position="@SurfaceGrid/grid.position" name="dofs" />

<HexahedronSetTopologyContainer name='Container' src="@../SurfaceGrid/grid"/>
<HexahedronSetTopologyModifier name='Modifier'/>
<HexahedronSetGeometryAlgorithms name='GeomAlgo' template='Vec3d'/>

<DiagonalMass totalMass="1.0" />

<HexahedronFEMForceField
name='FEM'
youngModulus='1000'
poissonRatio='0.3'
method='large'
/>

<RestShapeSpringsForceField external_rest_shape="@WaveMotion/dofs"
stiffness="200" angularStiffness="1000" />
</Node>
</Node>
17 changes: 17 additions & 0 deletions examples/ProximityOscillatorConstraint.scn.view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<Camera version="1.0">
<!--Vector of 3 reals (x, y, z)-->
<position value="24.3902 10.2953 7.4892"/>
<!--Quaternion (x, y, z, w)-->
<orientation value="0.356487 0.486826 0.666412 0.437964"/>
<!--Real-->
<fieldOfView value="45"/>
<!--Real-->
<distance value="0"/>
<!--Real-->
<zNear value="0.75"/>
<!--Real-->
<zFar value="45.7499"/>
<!--Int (0 -> Perspective, 1 -> Orthographic)-->
<projectionType value="Perspective"/>
</Camera>
43 changes: 43 additions & 0 deletions src/InfinyToolkit/ProximityOscillatorConstraint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*****************************************************************************
* - Copyright (C) - 2020 - InfinyTech3D - *
* *
* This file is part of the InfinyToolkit plugin for the SOFA framework *
* *
* Commercial License Usage: *
* Licensees holding valid commercial license from InfinyTech3D may use this *
* file in accordance with the commercial license agreement provided with *
* the Software or, alternatively, in accordance with the terms contained in *
* a written agreement between you and InfinyTech3D. For further information *
* on the licensing terms and conditions, contact: contact@infinytech3d.com *
* *
* GNU General Public License Usage: *
* Alternatively, this file may be used under the terms of the GNU General *
* Public License version 3. The licenses are as published by the Free *
* Software Foundation and appearing in the file LICENSE.GPL3 included in *
* the packaging of this file. Please review the following information to *
* ensure the GNU General Public License requirements will be met: *
* https://www.gnu.org/licenses/gpl-3.0.html. *
* *
* Authors: see Authors.txt *
* Further information: https://infinytech3d.com *
****************************************************************************/

#define SOFA_COMPONENT_FORCEFIELD_ProximityOscillatorConstraint_CPP

#include <sofa/core/ObjectFactory.h>
#include <InfinyToolkit/ProximityOscillatorConstraint.inl>

namespace sofa::infinytoolkit
{

using namespace sofa::defaulttype;

void registerProximityOscillatorConstraint(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(sofa::core::ObjectRegistrationData("Middle interpolated force applied to given degrees of freedom.")
.add< ProximityOscillatorConstraint<Vec3Types> >());
}

template class SOFA_INFINYTOOLKIT_API ProximityOscillatorConstraint<Vec3Types>;

} // namespace sofa::infinytoolkit
106 changes: 106 additions & 0 deletions src/InfinyToolkit/ProximityOscillatorConstraint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*****************************************************************************
* - Copyright (C) - 2020 - InfinyTech3D - *
* *
* This file is part of the InfinyToolkit plugin for the SOFA framework *
* *
* Commercial License Usage: *
* Licensees holding valid commercial license from InfinyTech3D may use this *
* file in accordance with the commercial license agreement provided with *
* the Software or, alternatively, in accordance with the terms contained in *
* a written agreement between you and InfinyTech3D. For further information *
* on the licensing terms and conditions, contact: contact@infinytech3d.com *
* *
* GNU General Public License Usage: *
* Alternatively, this file may be used under the terms of the GNU General *
* Public License version 3. The licenses are as published by the Free *
* Software Foundation and appearing in the file LICENSE.GPL3 included in *
* the packaging of this file. Please review the following information to *
* ensure the GNU General Public License requirements will be met: *
* https://www.gnu.org/licenses/gpl-3.0.html. *
* *
* Authors: see Authors.txt *
* Further information: https://infinytech3d.com *
****************************************************************************/
#pragma once

#include <InfinyToolkit/config.h>
#include <sofa/core/DataEngine.h>

#include <chrono>

namespace sofa::infinytoolkit
{
using sofa::core::DataEngine;

/** Apply forces changing to given degres of freedom. Some keyTimes are given
* and the force to be applied is linearly interpolated between keyTimes. */
template<class DataTypes>
class ProximityOscillatorConstraint : public DataEngine
{
public:
SOFA_CLASS(SOFA_TEMPLATE(ProximityOscillatorConstraint, DataTypes), core::DataEngine);

using VecCoord = typename DataTypes::VecCoord;
using VecDeriv = typename DataTypes::VecDeriv;
using Coord = typename DataTypes::Coord;
using Deriv = typename DataTypes::Deriv;
using Real = typename Coord::value_type;
using DataVecCoord = core::objectmodel::Data<VecCoord>;
using DataVecDeriv = core::objectmodel::Data<VecDeriv>;

ProximityOscillatorConstraint();

void init() override;

void doUpdate() override;
void handleEvent(sofa::core::objectmodel::Event* event) override;

void draw(const core::visual::VisualParams* vparams) override;

protected:
/// Will compute the barycenter of the given set of coordinates.
void computeBarycenter();

void computeDistribution();

public:
/// List of coordinates points
Data<VecCoord> d_positions;
Data<VecCoord> d_outputPositions;

/// List of coordinates points
Data<VecCoord> d_centers;
VecCoord m_centersOrdered;

/// Time to perform a full Pace (deflate + inflate). Same scale as the simulation time.
Data<Real> d_pace;

Data<Real> d_amplitude;

/// Parameter to display the force direction
Data<bool> p_showMotion;

private :
// keep trace of the latest time we measured
std::chrono::time_point<std::chrono::system_clock> m_startTime;

std::vector<int> m_distribution;

Real m_startTimeWave = 1.0;
int centerDone = -4;
int centerStart = 0;
int centerCurrent = 0;
Real nextStart = 0.0;

Real length = 4.0_sreal;
//Real current

}; // definition of the ProximityOscillatorConstraint class



#if !defined(SOFA_COMPONENT_FORCEFIELD_ProximityOscillatorConstraint_CPP)
extern template class SOFA_INFINYTOOLKIT_API ProximityOscillatorConstraint<sofa::defaulttype::Vec3Types>;
#endif // !defined(SOFA_COMPONENT_FORCEFIELD_ProximityOscillatorConstraint_CPP)

} // namespace sofa::infinytoolkit
Loading
Loading