|
| 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: contact@infinytech3d.com * |
| 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