This file is indexed.

/usr/include/sofa/component/container/MechanicalObject.h is in libsofa1-dev 1.0~beta4-9.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/******************************************************************************
*       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 4      *
*                (c) 2006-2009 MGH, INRIA, USTL, UJF, CNRS                    *
*                                                                             *
* This library is free software; you can redistribute it and/or modify it     *
* under the terms of the GNU Lesser General Public License as published by    *
* the Free Software Foundation; either version 2.1 of the License, or (at     *
* your option) any later version.                                             *
*                                                                             *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details.                                                           *
*                                                                             *
* You should have received a copy of the GNU Lesser General Public License    *
* along with this library; if not, write to the Free Software Foundation,     *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
*******************************************************************************
*                               SOFA :: Modules                               *
*                                                                             *
* Authors: The SOFA Team and external contributors (see Authors.txt)          *
*                                                                             *
* Contact information: contact@sofa-framework.org                             *
******************************************************************************/
#ifndef SOFA_COMPONENT_MECHANICALOBJECT_H
#define SOFA_COMPONENT_MECHANICALOBJECT_H

#include <sofa/core/componentmodel/behavior/MechanicalState.h>
#include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
#include <sofa/core/objectmodel/XDataPtr.h>
#include <sofa/core/objectmodel/VDataPtr.h>
#include <sofa/defaulttype/BaseVector.h>
#include <sofa/defaulttype/Quat.h>
#include <sofa/component/component.h>
#include <sofa/defaulttype/VecTypes.h>
#include <sofa/defaulttype/RigidTypes.h>
#include <sofa/defaulttype/LaparoscopicRigidTypes.h>
#include <sofa/core/objectmodel/DataFileName.h>

#include <vector>
#include <assert.h>
#include <fstream>

namespace sofa
{

namespace component
{


using namespace core::componentmodel::behavior;
using namespace core::objectmodel;
using sofa::defaulttype::Vector3;

/// This class can be overridden if needed for additionnal storage within template specializations.
template<class DataTypes>
class MechanicalObjectInternalData
{
public:
};

template <class DataTypes>
class MechanicalObject : public MechanicalState<DataTypes>
{
public:
    typedef MechanicalState<DataTypes> Inherited;
    typedef typename Inherited::VecId VecId;
    typedef typename Inherited::VMultiOp VMultiOp;
    typedef typename DataTypes::VecCoord VecCoord;
    typedef typename DataTypes::VecDeriv VecDeriv;
    typedef typename DataTypes::Coord Coord;
    typedef typename DataTypes::Deriv Deriv;
    typedef typename DataTypes::Real Real;
    typedef typename DataTypes::SparseVecDeriv SparseVecDeriv;
    typedef typename DataTypes::VecConst VecConst;

protected:
	VecCoord* x;
	VecDeriv* v;
	VecDeriv* f;
	VecDeriv* internalForces;
	VecDeriv* externalForces;
	VecDeriv* dx;
	VecCoord* x0;
	VecCoord* reset_position;

	VecDeriv* v0;
	VecCoord* xfree; // stores the position of the mechanical objet after a free movement (p.e. gravity action)
	VecDeriv* vfree; // stores the velocity of the mechanical objet after a free movement (p.e. gravity action)

	// Constraints stored in the Mechanical State
	// The storage is a SparseMatrix
	// Each constraint (Type TConst) contains the index of the related DOF
	VecConst *c;
	sofa::helper::vector<unsigned int> constraintId;

	bool initialized;
	Data< Vector3 > translation;
	Data< Vector3> rotation;
	Data< SReal > scale;
        sofa::core::objectmodel::DataFileName filename;
  Data< bool> ignoreLoader;

	/// @name Integration-related data
	/// @{

	sofa::helper::vector< VecCoord * > vectorsCoord;
	sofa::helper::vector< VecDeriv * > vectorsDeriv;
	sofa::helper::vector< VecConst * > vectorsConst;
	int vsize; ///< Number of elements to allocate in vectors

	void setVecCoord(unsigned int index, VecCoord* v);
	void setVecDeriv(unsigned int index, VecDeriv* v);
	void setVecConst(unsigned int index, VecConst* v);

	/// @}

	MechanicalObjectInternalData<DataTypes> data;

	friend class MechanicalObjectInternalData<DataTypes>;

        std::ofstream* m_gnuplotFileX;
        std::ofstream* m_gnuplotFileV;

    class Loader;

public:

    MechanicalObject();
    MechanicalObject& operator = ( const MechanicalObject& );

    virtual ~MechanicalObject();

    virtual bool load(const char* filename);

    virtual void parse ( BaseObjectDescription* arg );

	XDataPtr<DataTypes>* const f_X;
	VDataPtr<DataTypes>* const f_V;
	VDataPtr<DataTypes>* const f_F;
	VDataPtr<DataTypes>* const f_externalF;
	VDataPtr<DataTypes>* const f_Dx;
	XDataPtr<DataTypes>* const f_Xfree;
	VDataPtr<DataTypes>* const f_Vfree;

	XDataPtr<DataTypes>* const f_X0;

	Data<SReal> restScale;

	Data<bool> debugViewIndices;
	Data<float> debugViewIndicesScale;

	virtual VecCoord* getX()  { f_X->beginEdit(); return x;  }
	virtual VecDeriv* getV()  { f_V->beginEdit(); return v;  }
	virtual VecDeriv* getF()  { f_F->beginEdit(); return f;  }
	virtual VecDeriv* getExternalForces()  { f_externalF->beginEdit(); return externalForces;  }
	virtual VecDeriv* getDx() { f_Dx->beginEdit(); return dx; }
	virtual VecConst* getC() { return c;}
	virtual VecCoord* getXfree() { f_Xfree->beginEdit(); return xfree; }
	virtual VecDeriv* getVfree() { f_Vfree->beginEdit(); return vfree;  }
	VecCoord* getX0() { f_X0->beginEdit(); return x0;}

	virtual const VecCoord* getX()  const { return x;  }
	virtual const VecCoord* getX0()  const { return x0;  }
	virtual const VecDeriv* getV()  const { return v;  }
	virtual const VecDeriv* getV0()  const { return v0;  }
	virtual const VecDeriv* getF()  const { return f;  }
	virtual const VecDeriv* getExternalForces()  const { return externalForces;  }
	virtual const VecDeriv* getDx() const { return dx; }
	virtual const VecConst* getC() const { return c; }
	virtual const VecCoord* getXfree() const { return xfree; }
	virtual const VecDeriv* getVfree()  const { return vfree;  }

	virtual double getScale() const {return scale.getValue();};

	virtual void init();
	virtual void reinit();

	virtual void storeResetState();

	virtual void reset();

	virtual void writeX(std::ostream& out);
	virtual void readX(std::istream& in);
	virtual double compareX(std::istream& in);
	virtual void writeV(std::ostream& out);
	virtual void readV(std::istream& in);
	virtual double compareV(std::istream& in);
	virtual void writeF(std::ostream& out);
	virtual void writeDx(std::ostream& out);

	virtual void writeState( std::ostream& out );

        virtual void initGnuplot(const std::string path);
        virtual void exportGnuplot(Real time);

    virtual void resize( int vsize);

    virtual bool addBBox(double* minBBox, double* maxBBox);

    int getSize() const {
        return vsize;
    }
    double getPX(int i) const { Real x=0.0,y=0.0,z=0.0; DataTypes::get(x,y,z,(*getX())[i]); return (SReal)x; }
    double getPY(int i) const { Real x=0.0,y=0.0,z=0.0; DataTypes::get(x,y,z,(*getX())[i]); return (SReal)y; }
    double getPZ(int i) const { Real x=0.0,y=0.0,z=0.0; DataTypes::get(x,y,z,(*getX())[i]); return (SReal)z; }

    /** \brief Overwrite values at index outputIndex by the ones at inputIndex.
     *
     */
    void replaceValue (const int inputIndex, const int outputIndex);



    /** \brief Exchange values at indices idx1 and idx2.
     *
     */
    void swapValues (const int idx1, const int idx2);



    /** \brief Reorder values according to parameter.
     *
     * Result of this method is :
     * newValue[ i ] = oldValue[ index[i] ];
     */
    void renumberValues( const sofa::helper::vector<unsigned int> &index );



    /** \brief Replace the value at index by the sum of the ancestors values weithed by the coefs.
     *
     * Sum of the coefs should usually equal to 1.0
     */
    void computeWeightedValue( const unsigned int i, const sofa::helper::vector< unsigned int >& ancestors, const sofa::helper::vector< double >& coefs);

	/** \brief Compute the values attached to a new point.
     *
     */
//	void computeNewPoint( const unsigned int i, const sofa::helper::vector< double >& m_x);

	// Force the position of a point (and force its velocity to zero value)
	void forcePointPosition( const unsigned int i, const sofa::helper::vector< double >& m_x);

	virtual void applyTranslation (const double dx,const double dy,const double dz);

        // rotation using Euler Angles in degree
        virtual void applyRotation (const double rx, const double ry, const double rz);

	virtual void applyRotation (const defaulttype::Quat q);

	virtual void applyScale (const double s);

	/// Get the indices of the particles located in the given bounding box
	void getIndicesInSpace(sofa::helper::vector<unsigned>& indices, Real xmin, Real xmax, Real ymin, Real ymax, Real zmin, Real zmax) const;


	/// @Base Matrices and Vectors Interface
	/// @{

	/// Add the Mechanical State Dimension [DOF number * DOF dimension] to the global matrix dimension
	virtual void contributeToMatrixDimension(unsigned int * const, unsigned int * const);

	/// Load local mechanical data stored in the state in a global BaseVector basically stored in solvers
	virtual void loadInBaseVector(defaulttype::BaseVector *, VecId , unsigned int &);

	/// Add data stored in a BaseVector to a local mechanical vector of the MechanicalState
	virtual void addBaseVectorToState(VecId , defaulttype::BaseVector *, unsigned int &);

	/// Update offset index during the subgraph traversal
	virtual void setOffset(unsigned int &);

	/// @}



        /// Express the constraint J as a dense matrix
	virtual void buildConstraintMatrix(const sofa::helper::vector<unsigned int> &constraintId, const double factor, defaulttype::BaseMatrix& m,unsigned int numConstraint,  unsigned int offset);

	virtual void computeConstraintProjection(const sofa::helper::vector<unsigned int> &constraintId, VecId Id, defaulttype::BaseVector& v, unsigned int offset);

        void setFilename(std::string s){filename.setValue(s);};
        void setTranslation(double dx,double dy,double dz){translation.setValue(Vector3(dx,dy,dz));};
        void setRotation(double rx,double ry,double rz){rotation.setValue(Vector3(rx,ry,rz));};
        void setScale(double s){scale.setValue(s);};

        std::string getFilename(){return filename.getValue();};

	virtual void addDxToCollisionModel(void);

	void setConstraintId(unsigned int);
	sofa::helper::vector<unsigned int>& getConstraintId();


	/// @name Integration related methods
	/// @{

	virtual void beginIntegration(Real dt);

	virtual void endIntegration(Real dt);

	virtual void accumulateForce();

	VecCoord* getVecCoord(unsigned int index);
	const VecCoord* getVecCoord(unsigned int index) const;

	VecDeriv* getVecDeriv(unsigned int index);
	const VecDeriv* getVecDeriv(unsigned int index) const;

	VecConst* getVecConst(unsigned int index);
	const VecConst* getVecConst(unsigned int index) const;

	virtual void vAvail(VecId& v);

	virtual void vAlloc(VecId v);

	virtual void vFree(VecId v);

	virtual void vOp(VecId v, VecId a = VecId::null(), VecId b = VecId::null(), double f=1.0);

	virtual void vMultiOp(const VMultiOp& ops);

        virtual void vThreshold( VecId a, double threshold );

        virtual double vDot(VecId a, VecId b);

	virtual void setX(VecId v);

	virtual void setXfree(VecId v);

	virtual void setVfree(VecId v);

	virtual void setV(VecId v);

	virtual void setF(VecId v);

	virtual void setDx(VecId v);

	virtual void setC(VecId v);

	virtual void resetForce();

	virtual void resetAcc();

	virtual void resetConstraint();


	/// @}

	/// @name Debug
	/// @{
	virtual void printDOF( VecId, std::ostream& =std::cerr );
	virtual unsigned printDOFWithElapsedTime(VecId, unsigned =0, unsigned =0, std::ostream& =std::cerr );
	//
	void draw();
	/// @}

	// handle state changes
	virtual void handleStateChange();

    /// Find mechanical particles hit by the given ray.
    /// A mechanical particle is defined as a 2D or 3D, position or rigid DOF
    /// Returns false if this object does not support picking
    virtual bool pickParticles(double rayOx, double rayOy, double rayOz, double rayDx, double rayDy, double rayDz, double radius0, double dRadius,
			       std::multimap< double, std::pair<sofa::core::componentmodel::behavior::BaseMechanicalState*, int> >& particles);

protected:
	sofa::core::componentmodel::topology::BaseMeshTopology* _topology;


};

#if defined(WIN32) && !defined(SOFA_COMPONENT_CONTAINER_MECHANICALOBJECT_CPP)
#ifndef SOFA_FLOAT
extern template class SOFA_COMPONENT_CONTAINER_API MechanicalObject<defaulttype::Vec3dTypes>;
extern template class SOFA_COMPONENT_CONTAINER_API MechanicalObject<defaulttype::Vec2dTypes>;
extern template class SOFA_COMPONENT_CONTAINER_API MechanicalObject<defaulttype::Vec1dTypes>;
extern template class SOFA_COMPONENT_CONTAINER_API MechanicalObject<defaulttype::Vec6dTypes>;
extern template class SOFA_COMPONENT_CONTAINER_API MechanicalObject<defaulttype::Rigid3dTypes>;
extern template class SOFA_COMPONENT_CONTAINER_API MechanicalObject<defaulttype::Rigid2dTypes>;
#endif
#ifndef SOFA_DOUBLE
extern template class SOFA_COMPONENT_CONTAINER_API MechanicalObject<defaulttype::Vec3fTypes>;
extern template class SOFA_COMPONENT_CONTAINER_API MechanicalObject<defaulttype::Vec2fTypes>;
extern template class SOFA_COMPONENT_CONTAINER_API MechanicalObject<defaulttype::Vec1fTypes>;
extern template class SOFA_COMPONENT_CONTAINER_API MechanicalObject<defaulttype::Vec6fTypes>;
extern template class SOFA_COMPONENT_CONTAINER_API MechanicalObject<defaulttype::Rigid3fTypes>;
extern template class SOFA_COMPONENT_CONTAINER_API MechanicalObject<defaulttype::Rigid2fTypes>;
#endif
extern template class SOFA_COMPONENT_CONTAINER_API MechanicalObject<defaulttype::LaparoscopicRigid3Types>;
#endif

} // namespace component

} // namespace sofa

#endif