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
Original file line number Diff line number Diff line change
Expand Up @@ -179,71 +179,4 @@ void MechanicalObject<defaulttype::Rigid3Types>::addFromBaseVectorSameSize(core:

}


template<>
void MechanicalObject<defaulttype::Rigid3Types>::draw(const core::visual::VisualParams* vparams)
{
const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle();
vparams->drawTool()->setLightingEnabled(false);

if (showIndices.getValue())
{
drawIndices(vparams);
}

if (showVectors.getValue())
{
drawVectors(vparams);
}

if (showObject.getValue())
{
const float scale = showObjectScale.getValue();
const helper::ReadAccessor<Data<VecCoord> > x = *this->read(core::vec_id::write_access::position);
const size_t vsize = d_size.getValue();
for (size_t i = 0; i < vsize; ++i)
{
vparams->drawTool()->pushMatrix();
float glTransform[16];
///TODO: check if the drawtool use OpenGL-shaped matrix
x[i].writeOpenGlMatrix ( glTransform );
vparams->drawTool()->multMatrix( glTransform );
vparams->drawTool()->scale ( scale );

constexpr type::Vec3f sizes ( 1.f,1.f,1.f );

if (getContext()->isSleeping())
{
vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat<SReal>(), sizes, sofa::type::RGBAColor::gray());
}
else switch( drawMode.getValue() )
{
case 1:
vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat<SReal>(), sizes, sofa::type::RGBAColor::green());
break;
case 2:
vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat<SReal>(), sizes, sofa::type::RGBAColor::red());
break;
case 3:
vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat<SReal>(), sizes, sofa::type::RGBAColor::blue());
break;
case 4:
vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat<SReal>(), sizes, sofa::type::RGBAColor::yellow());
break;
case 5:
vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat<SReal>(), sizes, sofa::type::RGBAColor::magenta());
break;
case 6:
vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat<SReal>(), sizes, sofa::type::RGBAColor::cyan());
break;
default:
vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat<SReal>(), sizes );
}

vparams->drawTool()->popMatrix();
}
}

}

} // namespace sofa::component::statecontainer
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,20 @@ class MechanicalObject : public sofa::core::behavior::MechanicalState<DataTypes>

Data< bool > d_useTopology; ///< Shall this object rely on any active topology to initialize its size and positions

Data< bool > showObject; ///< Show objects. (default=false)
Data< float > showObjectScale; ///< Scale for object display. (default=0.1)
Data< bool > showIndices; ///< Show indices. (default=false)
Data< float > showIndicesScale; ///< Scale for indices display. (default=0.02)
Data< bool > showVectors; ///< Show velocity. (default=false)
Data< float > showVectorsScale; ///< Scale for vectors display. (default=0.0001)
Data< int > drawMode; ///< The way vectors will be drawn: - 0: Line - 1:Cylinder - 2: Arrow. The DOFS will be drawn: - 0: point - >1: sphere. (default=0)
Data< type::RGBAColor > d_color; ///< Color for object display. (default=[1 1 1 1])
struct DeprecatedVisualizationData : core::objectmodel::lifecycle::DeprecatedData
{
DeprecatedVisualizationData(core::Base* b, std::string name)
: core::objectmodel::lifecycle::DeprecatedData(b, "v25.12", "v26.06", name, "The visualization features are now available in dedicated components VisualPointCloud and VisualVectorField") {}
};

DeprecatedVisualizationData showObject;
DeprecatedVisualizationData showObjectScale;
DeprecatedVisualizationData showIndices;
DeprecatedVisualizationData showIndicesScale;
DeprecatedVisualizationData showVectors;
DeprecatedVisualizationData showVectorsScale;
DeprecatedVisualizationData drawMode;
DeprecatedVisualizationData d_color;

void init() override;
void reinit() override;
Expand Down Expand Up @@ -327,8 +333,6 @@ class MechanicalObject : public sofa::core::behavior::MechanicalState<DataTypes>
void printDOF(core::ConstVecId, std::ostream& =std::cerr, int firstIndex=0, int range=-1 ) const override;
unsigned printDOFWithElapsedTime(core::ConstVecId, unsigned =0, unsigned =0, std::ostream& =std::cerr ) override;

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

/// @}

// handle state changes
Expand Down Expand Up @@ -430,16 +434,6 @@ protected :
helper::ReadAccessor<core::objectmodel::Data<core::StateVecType_t<DataTypes, vtype> > >
getReadAccessor(core::ConstVecId v);

/**
* @brief Internal function : Draw indices in 3d coordinates.
*/
void drawIndices(const core::visual::VisualParams* vparams);

/**
* @brief Internal function : Draw vectors
*/
void drawVectors(const core::visual::VisualParams* vparams);

/// Given the number of a constraint Equation, find the index in the MatrixDeriv C, where the constraint is actually stored
// unsigned int getIdxConstraintFromId(unsigned int id) const;

Expand All @@ -466,12 +460,6 @@ template<> SOFA_COMPONENT_STATECONTAINER_API
void MechanicalObject<defaulttype::Rigid3Types>::addFromBaseVectorDifferentSize(core::VecId dest, const linearalgebra::BaseVector* src, unsigned int &offset );


template<> SOFA_COMPONENT_STATECONTAINER_API
void MechanicalObject<defaulttype::Rigid3Types>::draw(const core::visual::VisualParams* vparams);




#if !defined(SOFA_COMPONENT_CONTAINER_MECHANICALOBJECT_CPP)
extern template class SOFA_COMPONENT_STATECONTAINER_API MechanicalObject<defaulttype::Vec3Types>;
extern template class SOFA_COMPONENT_STATECONTAINER_API MechanicalObject<defaulttype::Vec2Types>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ MechanicalObject<DataTypes>::MechanicalObject()
, reset_velocity(initData(&reset_velocity, "reset_velocity", "reset velocity coordinates of the degrees of freedom"))
, restScale(initData(&restScale, 1.0_sreal, "restScale", "optional scaling of rest position coordinates (to simulated pre-existing internal tension).(default = 1.0)"))
, d_useTopology(initData(&d_useTopology, true, "useTopology", "Shall this object rely on any active topology to initialize its size and positions"))
, showObject(initData(&showObject, (bool) false, "showObject", "Show objects. (default=false)"))
, showObjectScale(initData(&showObjectScale, 0.1f, "showObjectScale", "Scale for object display. (default=0.1)"))
, showIndices(initData(&showIndices, (bool) false, "showIndices", "Show indices. (default=false)"))
, showIndicesScale(initData(&showIndicesScale, 0.02f, "showIndicesScale", "Scale for indices display. (default=0.02)"))
, showVectors(initData(&showVectors, (bool) false, "showVectors", "Show velocity. (default=false)"))
, showVectorsScale(initData(&showVectorsScale, 0.0001f, "showVectorsScale", "Scale for vectors display. (default=0.0001)"))
, drawMode(initData(&drawMode,0,"drawMode","The way vectors will be drawn:\n- 0: Line\n- 1:Cylinder\n- 2: Arrow.\n\nThe DOFS will be drawn:\n- 0: point\n- >1: sphere. (default=0)"))
, d_color(initData(&d_color, type::RGBAColor::white(), "showColor", "Color for object display. (default=[1 1 1 1])"))
, showObject(this, "showObject")
, showObjectScale(this, "showObjectScale")
, showIndices(this, "showIndices")
, showIndicesScale(this, "showIndicesScale")
, showVectors(this, "showVectors")
, showVectorsScale(this, "showVectorsScale")
, drawMode(this, "drawMode")
, d_color(this, "showColor")
, translation(initData(&translation, type::Vec3(), "translation", "Translation of the DOFs"))
, rotation(initData(&rotation, type::Vec3(), "rotation", "Rotation of the DOFs"))
, scale(initData(&scale, type::Vec3(1_sreal, 1_sreal, 1_sreal), "scale3d", "Scale of the DOFs in 3 dimensions"))
Expand Down Expand Up @@ -2627,107 +2627,6 @@ SReal MechanicalObject<DataTypes>::getConstraintJacobianTimesVecDeriv(unsigned i
return result;
}

template <class DataTypes>
inline void MechanicalObject<DataTypes>::drawIndices(const core::visual::VisualParams* vparams)
{
const float scale = (float)((vparams->sceneBBox().maxBBox() - vparams->sceneBBox().minBBox()).norm() * showIndicesScale.getValue());

std::vector<type::Vec3> positions;
positions.reserve(d_size.getValue());
for (int i = 0; i <d_size.getValue(); ++i)
positions.push_back(type::Vec3(getPX(i), getPY(i), getPZ(i)));

vparams->drawTool()->draw3DText_Indices(positions, scale, d_color.getValue());
}

template <class DataTypes>
inline void MechanicalObject<DataTypes>::drawVectors(const core::visual::VisualParams* vparams)
{
float scale = showVectorsScale.getValue();
sofa::helper::ReadAccessor< Data<VecDeriv> > v_rA = *this->read(core::vec_id::read_access::velocity);
type::vector<type::Vec3> points;
points.resize(2);
for(Size i=0; i<v_rA.size(); ++i )
{
Real vx=0.0,vy=0.0,vz=0.0;
DataTypes::get(vx,vy,vz,v_rA[i]);
type::Vec3 p1 = type::Vec3(getPX(i), getPY(i), getPZ(i));
type::Vec3 p2 = type::Vec3(getPX(i)+scale*vx, getPY(i)+scale*vy, getPZ(i)+scale*vz);

const float rad = (float)( (p1-p2).norm()/20.0 );
switch (drawMode.getValue())
{
case 0:
points[0] = p1;
points[1] = p2;
vparams->drawTool()->drawLines(points, 1, sofa::type::RGBAColor::white());
break;
case 1:
vparams->drawTool()->drawCylinder(p1, p2, rad, sofa::type::RGBAColor::white());
break;
case 2:
vparams->drawTool()->drawArrow(p1, p2, rad, sofa::type::RGBAColor::white());
break;
default:
msg_error() << "No proper drawing mode found!";
break;
}
}
}

template <class DataTypes>
inline void MechanicalObject<DataTypes>::draw(const core::visual::VisualParams* vparams)
{
const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle();
vparams->drawTool()->setLightingEnabled(false);

if (showIndices.getValue())
{
drawIndices(vparams);
}

if (showVectors.getValue())
{
drawVectors(vparams);
}

if (showObject.getValue())
{
const float& scale = showObjectScale.getValue();
type::vector<type::Vec3> positions(d_size.getValue());
for (sofa::Index i = 0; i < Size(d_size.getValue()); ++i)
positions[i] = type::Vec3(getPX(i), getPY(i), getPZ(i));

switch (drawMode.getValue())
{
case 0:
vparams->drawTool()->drawPoints(positions,scale, d_color.getValue());
break;
case 1:
vparams->drawTool()->setLightingEnabled(true);
vparams->drawTool()->drawSpheres(positions,scale, d_color.getValue());
break;
case 2:
vparams->drawTool()->setLightingEnabled(true);
vparams->drawTool()->drawSpheres(positions,scale, sofa::type::RGBAColor::red());
break;
case 3:
vparams->drawTool()->setLightingEnabled(true);
vparams->drawTool()->drawSpheres(positions,scale, sofa::type::RGBAColor::green());
break;
case 4:
vparams->drawTool()->setLightingEnabled(true);
vparams->drawTool()->drawSpheres(positions,scale, sofa::type::RGBAColor::blue());
break;
default:
msg_error() << "No proper drawing mode found!";
break;
}
}

}


/// 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
Expand Down Expand Up @@ -2771,9 +2670,6 @@ bool MechanicalObject<DataTypes>::pickParticles(const core::ExecParams* /* param
template <class DataTypes>
bool MechanicalObject<DataTypes>::addBBox(SReal* minBBox, SReal* maxBBox)
{
// participating to bbox only if it is drawn
if( !showObject.getValue() ) return false;

static const unsigned spatial_dimensions = std::min( (unsigned)DataTypes::spatial_dimensions, 3u );

const VecCoord& x = read(core::vec_id::read_access::position)->getValue();
Expand All @@ -2796,7 +2692,7 @@ template <class DataTypes>
void MechanicalObject<DataTypes>::computeBBox(const core::ExecParams* params, bool onlyVisible)
{
// participating to bbox only if it is drawn
if( onlyVisible && !showObject.getValue() ) return;
if( onlyVisible) return;
Inherited::computeBBox( params );
}

Expand Down
1 change: 0 additions & 1 deletion Sofa/framework/Simulation/Graph/test/Simulation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ struct Scene_test: public NumericTest<SReal>
x[2] = type::Vec3(0,1,0);
x[3] = type::Vec3(0,0,1);
type::Vec3 expectedMin(0,0,0), expectedMax(1,1,1);
DOF->showObject.setValue(true); // bbox is updated only for drawn MO

// end create scene
//*********
Expand Down