From 285eeb1c9e7356d5d737aeb9eef600f1de5cdc75 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Thu, 3 Jul 2025 12:00:36 +0200 Subject: [PATCH 1/2] Deprecated visualization Data --- .../statecontainer/MechanicalObject.cpp | 67 ---------- .../statecontainer/MechanicalObject.h | 40 ++---- .../statecontainer/MechanicalObject.inl | 122 ++---------------- 3 files changed, 23 insertions(+), 206 deletions(-) diff --git a/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.cpp b/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.cpp index 9763be97bde..a36ea5ea177 100644 --- a/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.cpp +++ b/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.cpp @@ -179,71 +179,4 @@ void MechanicalObject::addFromBaseVectorSameSize(core: } - -template<> -void MechanicalObject::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 > 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(), sizes, sofa::type::RGBAColor::gray()); - } - else switch( drawMode.getValue() ) - { - case 1: - vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat(), sizes, sofa::type::RGBAColor::green()); - break; - case 2: - vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat(), sizes, sofa::type::RGBAColor::red()); - break; - case 3: - vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat(), sizes, sofa::type::RGBAColor::blue()); - break; - case 4: - vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat(), sizes, sofa::type::RGBAColor::yellow()); - break; - case 5: - vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat(), sizes, sofa::type::RGBAColor::magenta()); - break; - case 6: - vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat(), sizes, sofa::type::RGBAColor::cyan()); - break; - default: - vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat(), sizes ); - } - - vparams->drawTool()->popMatrix(); - } - } - -} - } // namespace sofa::component::statecontainer diff --git a/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.h b/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.h index 7c193cd4407..5c143f6b4b9 100644 --- a/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.h +++ b/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.h @@ -101,14 +101,20 @@ class MechanicalObject : public sofa::core::behavior::MechanicalState 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; @@ -327,8 +333,6 @@ class MechanicalObject : public sofa::core::behavior::MechanicalState 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 @@ -430,16 +434,6 @@ protected : helper::ReadAccessor > > 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; @@ -466,12 +460,6 @@ template<> SOFA_COMPONENT_STATECONTAINER_API void MechanicalObject::addFromBaseVectorDifferentSize(core::VecId dest, const linearalgebra::BaseVector* src, unsigned int &offset ); -template<> SOFA_COMPONENT_STATECONTAINER_API -void MechanicalObject::draw(const core::visual::VisualParams* vparams); - - - - #if !defined(SOFA_COMPONENT_CONTAINER_MECHANICALOBJECT_CPP) extern template class SOFA_COMPONENT_STATECONTAINER_API MechanicalObject; extern template class SOFA_COMPONENT_STATECONTAINER_API MechanicalObject; diff --git a/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.inl b/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.inl index 45f23586500..8e76ac5677f 100644 --- a/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.inl +++ b/Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.inl @@ -148,14 +148,14 @@ MechanicalObject::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")) @@ -2627,107 +2627,6 @@ SReal MechanicalObject::getConstraintJacobianTimesVecDeriv(unsigned i return result; } -template -inline void MechanicalObject::drawIndices(const core::visual::VisualParams* vparams) -{ - const float scale = (float)((vparams->sceneBBox().maxBBox() - vparams->sceneBBox().minBBox()).norm() * showIndicesScale.getValue()); - - std::vector positions; - positions.reserve(d_size.getValue()); - for (int i = 0; i drawTool()->draw3DText_Indices(positions, scale, d_color.getValue()); -} - -template -inline void MechanicalObject::drawVectors(const core::visual::VisualParams* vparams) -{ - float scale = showVectorsScale.getValue(); - sofa::helper::ReadAccessor< Data > v_rA = *this->read(core::vec_id::read_access::velocity); - type::vector points; - points.resize(2); - for(Size i=0; idrawTool()->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 -inline void MechanicalObject::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 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 @@ -2771,9 +2670,6 @@ bool MechanicalObject::pickParticles(const core::ExecParams* /* param template bool MechanicalObject::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(); @@ -2796,7 +2692,7 @@ template void MechanicalObject::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 ); } From 0fe034518b5e35e183496955cdbf502238f6a9e6 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Thu, 31 Jul 2025 11:48:26 +0200 Subject: [PATCH 2/2] fix test --- Sofa/framework/Simulation/Graph/test/Simulation_test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Sofa/framework/Simulation/Graph/test/Simulation_test.cpp b/Sofa/framework/Simulation/Graph/test/Simulation_test.cpp index 8fad0b75081..ff34c9561dd 100644 --- a/Sofa/framework/Simulation/Graph/test/Simulation_test.cpp +++ b/Sofa/framework/Simulation/Graph/test/Simulation_test.cpp @@ -90,7 +90,6 @@ struct Scene_test: public NumericTest 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 //*********