Skip to content

Commit 721e11c

Browse files
committed
totally change name an clean Data
1 parent 7d06417 commit 721e11c

File tree

5 files changed

+45
-145
lines changed

5 files changed

+45
-145
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +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}/CenterLineForceField.h
39-
${INFINYTOOLKIT_SRC_DIR}/CenterLineForceField.inl
38+
${INFINYTOOLKIT_SRC_DIR}/ProximityOscillatorConstraint.h
39+
${INFINYTOOLKIT_SRC_DIR}/ProximityOscillatorConstraint.inl
4040
${INFINYTOOLKIT_SRC_DIR}/Triangle2RefinedTriangleTopologicalMapping.h
4141

4242
## Carving tools sections
@@ -69,7 +69,7 @@ set(SOURCE_FILES
6969
${INFINYTOOLKIT_SRC_DIR}/HapticEmulator.cpp
7070
${INFINYTOOLKIT_SRC_DIR}/NeedleTracker.cpp
7171
${INFINYTOOLKIT_SRC_DIR}/MiddleForceField.cpp
72-
${INFINYTOOLKIT_SRC_DIR}/CenterLineForceField.cpp
72+
${INFINYTOOLKIT_SRC_DIR}/ProximityOscillatorConstraint.cpp
7373
${INFINYTOOLKIT_SRC_DIR}/Triangle2RefinedTriangleTopologicalMapping.cpp
7474

7575
## Carving tools sections

src/InfinyToolkit/CenterLineForceField.cpp renamed to src/InfinyToolkit/ProximityOscillatorConstraint.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@
2222
* Further information: https://infinytech3d.com *
2323
****************************************************************************/
2424

25-
#define SOFA_COMPONENT_FORCEFIELD_CenterLineForceField_CPP
25+
#define SOFA_COMPONENT_FORCEFIELD_ProximityOscillatorConstraint_CPP
2626

2727
#include <sofa/core/ObjectFactory.h>
28-
#include <InfinyToolkit/CenterLineForceField.inl>
28+
#include <InfinyToolkit/ProximityOscillatorConstraint.inl>
2929

3030
namespace sofa::infinytoolkit
3131
{
3232

3333
using namespace sofa::defaulttype;
3434

35-
void registerCenterLineForceField(sofa::core::ObjectFactory* factory)
35+
void registerProximityOscillatorConstraint(sofa::core::ObjectFactory* factory)
3636
{
3737
factory->registerObjects(sofa::core::ObjectRegistrationData("Middle interpolated force applied to given degrees of freedom.")
38-
.add< CenterLineForceField<Vec3Types> >());
38+
.add< ProximityOscillatorConstraint<Vec3Types> >());
3939
}
4040

41-
template class SOFA_INFINYTOOLKIT_API CenterLineForceField<Vec3Types>;
41+
template class SOFA_INFINYTOOLKIT_API ProximityOscillatorConstraint<Vec3Types>;
4242

4343
} // namespace sofa::infinytoolkit

src/InfinyToolkit/CenterLineForceField.h renamed to src/InfinyToolkit/ProximityOscillatorConstraint.h

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ namespace sofa::infinytoolkit
3535
/** Apply forces changing to given degres of freedom. Some keyTimes are given
3636
* and the force to be applied is linearly interpolated between keyTimes. */
3737
template<class DataTypes>
38-
class CenterLineForceField : public DataEngine
38+
class ProximityOscillatorConstraint : public DataEngine
3939
{
4040
public:
41-
SOFA_CLASS(SOFA_TEMPLATE(CenterLineForceField, DataTypes), core::DataEngine);
41+
SOFA_CLASS(SOFA_TEMPLATE(ProximityOscillatorConstraint, DataTypes), core::DataEngine);
4242

4343
using VecCoord = typename DataTypes::VecCoord;
4444
using VecDeriv = typename DataTypes::VecDeriv;
@@ -48,16 +48,13 @@ class CenterLineForceField : public DataEngine
4848
using DataVecCoord = core::objectmodel::Data<VecCoord>;
4949
using DataVecDeriv = core::objectmodel::Data<VecDeriv>;
5050

51-
CenterLineForceField();
51+
ProximityOscillatorConstraint();
5252

5353
void init() override;
5454

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

58-
// ForceField methods
59-
// void addForce(const core::MechanicalParams* mparams, DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v) override;
60-
6158
void draw(const core::visual::VisualParams* vparams) override;
6259

6360
protected:
@@ -69,44 +66,21 @@ class CenterLineForceField : public DataEngine
6966
public:
7067
/// List of coordinates points
7168
Data<VecCoord> d_positions;
72-
Data<VecCoord> d_restPositions;
7369
Data<VecCoord> d_outputPositions;
7470

7571
/// List of coordinates points
7672
Data<VecCoord> d_centers;
7773
VecCoord m_centersOrdered;
7874

79-
/// Applied force to all points to simulate maximum compression.
80-
Data<Real> d_force;
81-
82-
/// If true, will apply the same force at each vertex otherwise will apply force proportional to the distance to the barycenter
83-
Data<bool> d_uniformForce;
84-
8575
/// Time to perform a full Pace (deflate + inflate). Same scale as the simulation time.
8676
Data<Real> d_pace;
8777

88-
/// To recompute barycenter every X pace. 0 by default == no refresh
89-
Data<unsigned int> d_refreshBaryRate;
90-
91-
Data<Real> d_stiffness;
92-
78+
Data<Real> d_amplitude;
9379

9480
/// Parameter to display the force direction
95-
Data<bool> p_showForce;
96-
97-
// Synchronize with real time (instead of simulation time)
98-
Data<bool> d_syncRealTime;
99-
100-
// Frequency at which a full deflate+inflate is done
101-
Data<Real> d_frequency;
81+
Data<bool> p_showMotion;
10282

10383
private :
104-
/// Computed barycenter of the given positions @sa d_positions
105-
Coord m_bary;
106-
107-
/// counter to the last pace the barycenter has been refreshed. To be used with @sa d_refreshBaryRate
108-
unsigned int m_lastBaryRefresh = 0;
109-
11084
// keep trace of the latest time we measured
11185
std::chrono::time_point<std::chrono::system_clock> m_startTime;
11286

@@ -121,12 +95,12 @@ private :
12195
Real length = 4.0_sreal;
12296
//Real current
12397

124-
}; // definition of the CenterLineForceField class
98+
}; // definition of the ProximityOscillatorConstraint class
12599

126100

127101

128-
#if !defined(SOFA_COMPONENT_FORCEFIELD_CenterLineForceField_CPP)
129-
extern template class SOFA_INFINYTOOLKIT_API CenterLineForceField<sofa::defaulttype::Vec3Types>;
130-
#endif // !defined(SOFA_COMPONENT_FORCEFIELD_CenterLineForceField_CPP)
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)
131105

132106
} // namespace sofa::infinytoolkit

src/InfinyToolkit/CenterLineForceField.inl renamed to src/InfinyToolkit/ProximityOscillatorConstraint.inl

Lines changed: 26 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
****************************************************************************/
2424
#pragma once
2525

26-
#include <InfinyToolkit/CenterLineForceField.h>
26+
#include <InfinyToolkit/ProximityOscillatorConstraint.h>
2727
#include <sofa/type/vector.h>
2828
#include <sofa/defaulttype/VecTypes.h>
2929
#include <sofa/defaulttype/RigidTypes.h>
@@ -36,25 +36,15 @@ namespace sofa::infinytoolkit
3636
{
3737

3838
template<class DataTypes>
39-
CenterLineForceField<DataTypes>::CenterLineForceField()
39+
ProximityOscillatorConstraint<DataTypes>::ProximityOscillatorConstraint()
4040
: d_positions(initData(&d_positions, "position", "List of coordinates points"))
41-
, d_restPositions(initData(&d_restPositions, "restPositions", "List of rest coordinates points"))
42-
, d_outputPositions(initData(&d_outputPositions, "outputPositions", "List of output coordinates points"))
41+
, d_outputPositions(initData(&d_outputPositions, "outputPositions", "List of output coordinates points"))
4342
, d_centers(initData(&d_centers, "centers", "List of center coordinates points"))
44-
, d_force(initData(&d_force, 1.0_sreal, "force", "Applied force to all points to simulate maximum compression."))
45-
, d_uniformForce(initData(&d_uniformForce, bool(false), "uniformForce", "If true, will apply the same force at each vertex otherwise will apply force proportional to the distance to the barycenter"))
4643
, d_pace(initData(&d_pace, 1.0_sreal, "pace", "Time to perform a full Pace (deflate + inflate). Same scale as the simulation time."))
47-
48-
, d_stiffness(initData(&d_stiffness, 1000.0_sreal, "stiffness", "Time to perform a full Pace (deflate + inflate). Same scale as the simulation time."))
49-
50-
51-
, d_refreshBaryRate(initData(&d_refreshBaryRate, (unsigned int)(0), "refreshBaryRate", "To recompute barycenter every X pace. 0 by default == no refresh"))
52-
, p_showForce(initData(&p_showForce, bool(false), "showForce", "Parameter to display the force direction"))
53-
, d_syncRealTime(initData(&d_syncRealTime, false, "syncRealTime", "Synchronize with the real time instead of simulation time."))
54-
, d_frequency(initData(&d_frequency, 1.0_sreal, "frequency", "Frequency at which the full deflate+inflate is done, in Hz, i.e x/sec. Used if pace is not set."))
44+
, d_amplitude(initData(&d_amplitude, 0.8_sreal, "amplitude", "Amplitude of the oscillation"))
45+
, p_showMotion(initData(&p_showMotion, bool(false), "showMotion", "Parameter to display the force direction"))
5546
, m_startTime()
5647
{
57-
addInput(&d_restPositions);
5848
addInput(&d_positions);
5949
addInput(&d_centers);
6050

@@ -64,7 +54,7 @@ CenterLineForceField<DataTypes>::CenterLineForceField()
6454

6555

6656
template<class DataTypes>
67-
void CenterLineForceField<DataTypes>::init()
57+
void ProximityOscillatorConstraint<DataTypes>::init()
6858
{
6959
size_t nbPoints = d_positions.getValue().size();
7060
if (nbPoints == 0)
@@ -74,18 +64,13 @@ void CenterLineForceField<DataTypes>::init()
7464
return;
7565
}
7666

77-
if (!d_pace.isSet() && !d_frequency.isSet())
67+
if (!d_pace.isSet())
7868
{
79-
msg_error() << "Neither Pace nor frequency are set. Won't be able to compute pace.";
69+
msg_error() << "Pace is not set. Won't be able to compute pace.";
8070
sofa::core::objectmodel::BaseObject::d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid);
8171
return;
8272
}
8373

84-
if (d_pace.isSet() && d_frequency.isSet())
85-
{
86-
msg_warning() << "Pace and frequency are both set. Will take into account the frequency value.";
87-
}
88-
8974
computeDistribution();
9075

9176
m_startTime = std::chrono::system_clock::now();
@@ -95,40 +80,25 @@ void CenterLineForceField<DataTypes>::init()
9580

9681

9782
template<class DataTypes>
98-
void CenterLineForceField<DataTypes>::computeBarycenter()
99-
{
100-
sofa::helper::ReadAccessor< core::objectmodel::Data< VecCoord > > _x = d_positions;
101-
102-
m_bary = Coord(0.0, 0.0, 0.0);
103-
size_t nbPoints = _x.size();
104-
for (size_t i = 0; i < nbPoints; ++i)
105-
{
106-
m_bary += _x[i];
107-
}
108-
109-
m_bary /= nbPoints;
110-
}
111-
112-
113-
114-
template<class DataTypes>
115-
void CenterLineForceField<DataTypes>::computeDistribution()
83+
void ProximityOscillatorConstraint<DataTypes>::computeDistribution()
11684
{
11785
sofa::helper::ReadAccessor< core::objectmodel::Data< VecCoord > > _x = d_positions;
11886
sofa::helper::ReadAccessor< core::objectmodel::Data< VecCoord > > _centers = d_centers;
119-
//m_centersOrdered.resize(_centers.size());
87+
12088
m_centersOrdered = _centers;
12189
std::sort(m_centersOrdered.begin(), m_centersOrdered.end(),
12290
[](const Coord& a, const Coord& b) {
12391
return a[1] > b[1];
12492
});
12593

126-
for (size_t i = 0; i < _centers.size(); ++i)
94+
if (f_printLog.getValue())
12795
{
128-
std::cout << i << ": " << _centers[i] << " | " << m_centersOrdered[i] << std::endl;
96+
for (size_t i = 0; i < _centers.size(); ++i)
97+
{
98+
std::cout << i << ": " << _centers[i] << " | " << m_centersOrdered[i] << std::endl;
99+
}
129100
}
130101

131-
132102
m_distribution.resize(_x.size());
133103

134104
Coord pt2;
@@ -147,7 +117,7 @@ void CenterLineForceField<DataTypes>::computeDistribution()
147117

148118

149119
template<class DataTypes>
150-
void CenterLineForceField<DataTypes>::doUpdate()
120+
void ProximityOscillatorConstraint<DataTypes>::doUpdate()
151121
{
152122
if (sofa::core::objectmodel::BaseObject::d_componentState.getValue() != sofa::core::objectmodel::ComponentState::Valid)
153123
return;
@@ -157,59 +127,28 @@ void CenterLineForceField<DataTypes>::doUpdate()
157127
sofa::helper::ReadAccessor< core::objectmodel::Data< VecCoord > > _centers = d_centers;
158128

159129
outX.resize(inX.size());
160-
Real pacePercent = 1.0_sreal;
161-
Real time = 1.0_sreal;
162-
163-
const Real pace = (!d_frequency.isSet()) ? d_pace.getValue() : Real(1.0 / d_frequency.getValue());
164-
165-
if (d_syncRealTime.getValue())
166-
{
167-
using namespace std::chrono;
130+
Real time = this->getContext()->getTime();
168131

169-
std::chrono::duration<Real> duration = system_clock::now() - m_startTime;
170-
time = duration.count();
171-
}
172-
else
173-
{
174-
time = this->getContext()->getTime();
175-
}
132+
const Real pace = d_pace.getValue();
176133

177134
// we apply a force proportional to the pace rate. 0 Force at start of pace, 0 at end, F at half pace
178-
pacePercent = std::fmod(time, pace) / pace;
179-
//std::cout << "std::fmod(time, pace): " << std::fmod(time, pace) << std::endl;
180-
//std::cout << "std::fmod(time, pace)/2*pace: " << std::fmod(time, pace)/(2*pace) << std::endl;
181-
//std::cout << "time: " << time << " | pace: " << pace << " | pacePercent: " << pacePercent << std::endl;
182-
135+
const Real pacePercent = std::fmod(time, pace) / pace;
136+
183137
if (time >= nextStart) // at every pace/2 we start moving a new center and stop previous one
184138
{
185139
centerStart++;
186140
centerDone++;
187-
188-
//if (centerCurrent == 4)
189-
{
190-
/* centerDone++;
191-
centerCurrent = 0;*/
192-
std::cout << "Center " << centerDone << " done at time " << time << std::endl;
193-
}
194-
195-
//centerDone++;
196-
std::cout << "Center " << centerStart << " started at time " << time << std::endl;
197-
198141
nextStart += pace / length;
199142
}
200143

201144
// G ---- X -- X0
202145

203-
const Real amplitude = 0.8;
146+
const Real amplitude = d_amplitude.getValue();
204147
const Real frequency = pace;
205148

206-
//std::cout << "oscillation: " << oscillation << std::endl;
207-
//std::cout << "centerStart: " << centerStart << " | " << centerDone << " / " << _centers.size() << " centers done." << std::endl;
208149
for (size_t i = 0; i < inX.size(); ++i)
209150
{
210151
int centerId = m_distribution[i];
211-
212-
213152
if (centerId > centerStart || centerId <= centerDone )
214153
{
215154
outX[i] = inX[i];
@@ -226,35 +165,22 @@ void CenterLineForceField<DataTypes>::doUpdate()
226165
Real oscillation = amplitude * std::cos(pacePercent * 2.0 * M_PI - omega);
227166
oscillation = amplitude - (oscillation + amplitude) / 2.0_sreal; // normalize between 0 and 0.9
228167

229-
// cos: [-1; 1] 1 -1 1
230-
// [0; 2] 2 0 2
231-
// [0; 1] 1 0 1
232-
// [1; 0] 0 1 0
233-
234-
// 0.9 -0.9 0.9
235-
// 1.8 0 1.8
236-
// 0.9 0 0.9
237-
// 0 0.9 0
238-
239168
outX[i] = p0 + dir * oscillation;
240169
}
241-
242-
243170

244171
if (centerDone >= int(m_centersOrdered.size()) && pacePercent >= 0.99)
245172
{
246-
std::cout << "centerDone " << centerDone << " | " << m_centersOrdered.size() << std::endl;
173+
if (f_printLog.getValue())
174+
std::cout << "centerDone " << centerDone << " | " << m_centersOrdered.size() << std::endl;
247175

248176
centerDone = -4;
249177
centerStart = 0;
250178
nextStart = time + pace / length;
251179
}
252-
253-
254180
}
255181

256182
template<class DataTypes>
257-
void CenterLineForceField<DataTypes>::handleEvent(sofa::core::objectmodel::Event* event)
183+
void ProximityOscillatorConstraint<DataTypes>::handleEvent(sofa::core::objectmodel::Event* event)
258184
{
259185
//std::cout << "event" << std::endl;
260186
if (simulation::AnimateBeginEvent::checkEventType(event))
@@ -265,9 +191,9 @@ void CenterLineForceField<DataTypes>::handleEvent(sofa::core::objectmodel::Event
265191

266192

267193
template<class DataTypes>
268-
void CenterLineForceField<DataTypes>::draw(const core::visual::VisualParams* vparams)
194+
void ProximityOscillatorConstraint<DataTypes>::draw(const core::visual::VisualParams* vparams)
269195
{
270-
if (/*!vparams->displayFlags().getShowForceFields() || */!p_showForce.getValue()) {
196+
if (!p_showMotion.getValue()) {
271197
return;
272198
}
273199
const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle();

0 commit comments

Comments
 (0)