Skip to content

Commit 285eeb1

Browse files
committed
Deprecated visualization Data
1 parent 34a92d2 commit 285eeb1

File tree

3 files changed

+23
-206
lines changed

3 files changed

+23
-206
lines changed

Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.cpp

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -179,71 +179,4 @@ void MechanicalObject<defaulttype::Rigid3Types>::addFromBaseVectorSameSize(core:
179179

180180
}
181181

182-
183-
template<>
184-
void MechanicalObject<defaulttype::Rigid3Types>::draw(const core::visual::VisualParams* vparams)
185-
{
186-
const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle();
187-
vparams->drawTool()->setLightingEnabled(false);
188-
189-
if (showIndices.getValue())
190-
{
191-
drawIndices(vparams);
192-
}
193-
194-
if (showVectors.getValue())
195-
{
196-
drawVectors(vparams);
197-
}
198-
199-
if (showObject.getValue())
200-
{
201-
const float scale = showObjectScale.getValue();
202-
const helper::ReadAccessor<Data<VecCoord> > x = *this->read(core::vec_id::write_access::position);
203-
const size_t vsize = d_size.getValue();
204-
for (size_t i = 0; i < vsize; ++i)
205-
{
206-
vparams->drawTool()->pushMatrix();
207-
float glTransform[16];
208-
///TODO: check if the drawtool use OpenGL-shaped matrix
209-
x[i].writeOpenGlMatrix ( glTransform );
210-
vparams->drawTool()->multMatrix( glTransform );
211-
vparams->drawTool()->scale ( scale );
212-
213-
constexpr type::Vec3f sizes ( 1.f,1.f,1.f );
214-
215-
if (getContext()->isSleeping())
216-
{
217-
vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat<SReal>(), sizes, sofa::type::RGBAColor::gray());
218-
}
219-
else switch( drawMode.getValue() )
220-
{
221-
case 1:
222-
vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat<SReal>(), sizes, sofa::type::RGBAColor::green());
223-
break;
224-
case 2:
225-
vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat<SReal>(), sizes, sofa::type::RGBAColor::red());
226-
break;
227-
case 3:
228-
vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat<SReal>(), sizes, sofa::type::RGBAColor::blue());
229-
break;
230-
case 4:
231-
vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat<SReal>(), sizes, sofa::type::RGBAColor::yellow());
232-
break;
233-
case 5:
234-
vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat<SReal>(), sizes, sofa::type::RGBAColor::magenta());
235-
break;
236-
case 6:
237-
vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat<SReal>(), sizes, sofa::type::RGBAColor::cyan());
238-
break;
239-
default:
240-
vparams->drawTool()->drawFrame ( type::Vec3(), type::Quat<SReal>(), sizes );
241-
}
242-
243-
vparams->drawTool()->popMatrix();
244-
}
245-
}
246-
247-
}
248-
249182
} // namespace sofa::component::statecontainer

Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.h

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,20 @@ class MechanicalObject : public sofa::core::behavior::MechanicalState<DataTypes>
101101

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

104-
Data< bool > showObject; ///< Show objects. (default=false)
105-
Data< float > showObjectScale; ///< Scale for object display. (default=0.1)
106-
Data< bool > showIndices; ///< Show indices. (default=false)
107-
Data< float > showIndicesScale; ///< Scale for indices display. (default=0.02)
108-
Data< bool > showVectors; ///< Show velocity. (default=false)
109-
Data< float > showVectorsScale; ///< Scale for vectors display. (default=0.0001)
110-
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)
111-
Data< type::RGBAColor > d_color; ///< Color for object display. (default=[1 1 1 1])
104+
struct DeprecatedVisualizationData : core::objectmodel::lifecycle::DeprecatedData
105+
{
106+
DeprecatedVisualizationData(core::Base* b, std::string name)
107+
: core::objectmodel::lifecycle::DeprecatedData(b, "v25.12", "v26.06", name, "The visualization features are now available in dedicated components VisualPointCloud and VisualVectorField") {}
108+
};
109+
110+
DeprecatedVisualizationData showObject;
111+
DeprecatedVisualizationData showObjectScale;
112+
DeprecatedVisualizationData showIndices;
113+
DeprecatedVisualizationData showIndicesScale;
114+
DeprecatedVisualizationData showVectors;
115+
DeprecatedVisualizationData showVectorsScale;
116+
DeprecatedVisualizationData drawMode;
117+
DeprecatedVisualizationData d_color;
112118

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

330-
void draw(const core::visual::VisualParams* vparams) override;
331-
332336
/// @}
333337

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

433-
/**
434-
* @brief Internal function : Draw indices in 3d coordinates.
435-
*/
436-
void drawIndices(const core::visual::VisualParams* vparams);
437-
438-
/**
439-
* @brief Internal function : Draw vectors
440-
*/
441-
void drawVectors(const core::visual::VisualParams* vparams);
442-
443437
/// Given the number of a constraint Equation, find the index in the MatrixDeriv C, where the constraint is actually stored
444438
// unsigned int getIdxConstraintFromId(unsigned int id) const;
445439

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

468462

469-
template<> SOFA_COMPONENT_STATECONTAINER_API
470-
void MechanicalObject<defaulttype::Rigid3Types>::draw(const core::visual::VisualParams* vparams);
471-
472-
473-
474-
475463
#if !defined(SOFA_COMPONENT_CONTAINER_MECHANICALOBJECT_CPP)
476464
extern template class SOFA_COMPONENT_STATECONTAINER_API MechanicalObject<defaulttype::Vec3Types>;
477465
extern template class SOFA_COMPONENT_STATECONTAINER_API MechanicalObject<defaulttype::Vec2Types>;

Sofa/Component/StateContainer/src/sofa/component/statecontainer/MechanicalObject.inl

Lines changed: 9 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,14 @@ MechanicalObject<DataTypes>::MechanicalObject()
148148
, reset_velocity(initData(&reset_velocity, "reset_velocity", "reset velocity coordinates of the degrees of freedom"))
149149
, restScale(initData(&restScale, 1.0_sreal, "restScale", "optional scaling of rest position coordinates (to simulated pre-existing internal tension).(default = 1.0)"))
150150
, d_useTopology(initData(&d_useTopology, true, "useTopology", "Shall this object rely on any active topology to initialize its size and positions"))
151-
, showObject(initData(&showObject, (bool) false, "showObject", "Show objects. (default=false)"))
152-
, showObjectScale(initData(&showObjectScale, 0.1f, "showObjectScale", "Scale for object display. (default=0.1)"))
153-
, showIndices(initData(&showIndices, (bool) false, "showIndices", "Show indices. (default=false)"))
154-
, showIndicesScale(initData(&showIndicesScale, 0.02f, "showIndicesScale", "Scale for indices display. (default=0.02)"))
155-
, showVectors(initData(&showVectors, (bool) false, "showVectors", "Show velocity. (default=false)"))
156-
, showVectorsScale(initData(&showVectorsScale, 0.0001f, "showVectorsScale", "Scale for vectors display. (default=0.0001)"))
157-
, 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)"))
158-
, d_color(initData(&d_color, type::RGBAColor::white(), "showColor", "Color for object display. (default=[1 1 1 1])"))
151+
, showObject(this, "showObject")
152+
, showObjectScale(this, "showObjectScale")
153+
, showIndices(this, "showIndices")
154+
, showIndicesScale(this, "showIndicesScale")
155+
, showVectors(this, "showVectors")
156+
, showVectorsScale(this, "showVectorsScale")
157+
, drawMode(this, "drawMode")
158+
, d_color(this, "showColor")
159159
, translation(initData(&translation, type::Vec3(), "translation", "Translation of the DOFs"))
160160
, rotation(initData(&rotation, type::Vec3(), "rotation", "Rotation of the DOFs"))
161161
, 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<DataTypes>::getConstraintJacobianTimesVecDeriv(unsigned i
26272627
return result;
26282628
}
26292629

2630-
template <class DataTypes>
2631-
inline void MechanicalObject<DataTypes>::drawIndices(const core::visual::VisualParams* vparams)
2632-
{
2633-
const float scale = (float)((vparams->sceneBBox().maxBBox() - vparams->sceneBBox().minBBox()).norm() * showIndicesScale.getValue());
2634-
2635-
std::vector<type::Vec3> positions;
2636-
positions.reserve(d_size.getValue());
2637-
for (int i = 0; i <d_size.getValue(); ++i)
2638-
positions.push_back(type::Vec3(getPX(i), getPY(i), getPZ(i)));
2639-
2640-
vparams->drawTool()->draw3DText_Indices(positions, scale, d_color.getValue());
2641-
}
2642-
2643-
template <class DataTypes>
2644-
inline void MechanicalObject<DataTypes>::drawVectors(const core::visual::VisualParams* vparams)
2645-
{
2646-
float scale = showVectorsScale.getValue();
2647-
sofa::helper::ReadAccessor< Data<VecDeriv> > v_rA = *this->read(core::vec_id::read_access::velocity);
2648-
type::vector<type::Vec3> points;
2649-
points.resize(2);
2650-
for(Size i=0; i<v_rA.size(); ++i )
2651-
{
2652-
Real vx=0.0,vy=0.0,vz=0.0;
2653-
DataTypes::get(vx,vy,vz,v_rA[i]);
2654-
type::Vec3 p1 = type::Vec3(getPX(i), getPY(i), getPZ(i));
2655-
type::Vec3 p2 = type::Vec3(getPX(i)+scale*vx, getPY(i)+scale*vy, getPZ(i)+scale*vz);
2656-
2657-
const float rad = (float)( (p1-p2).norm()/20.0 );
2658-
switch (drawMode.getValue())
2659-
{
2660-
case 0:
2661-
points[0] = p1;
2662-
points[1] = p2;
2663-
vparams->drawTool()->drawLines(points, 1, sofa::type::RGBAColor::white());
2664-
break;
2665-
case 1:
2666-
vparams->drawTool()->drawCylinder(p1, p2, rad, sofa::type::RGBAColor::white());
2667-
break;
2668-
case 2:
2669-
vparams->drawTool()->drawArrow(p1, p2, rad, sofa::type::RGBAColor::white());
2670-
break;
2671-
default:
2672-
msg_error() << "No proper drawing mode found!";
2673-
break;
2674-
}
2675-
}
2676-
}
2677-
2678-
template <class DataTypes>
2679-
inline void MechanicalObject<DataTypes>::draw(const core::visual::VisualParams* vparams)
2680-
{
2681-
const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle();
2682-
vparams->drawTool()->setLightingEnabled(false);
2683-
2684-
if (showIndices.getValue())
2685-
{
2686-
drawIndices(vparams);
2687-
}
2688-
2689-
if (showVectors.getValue())
2690-
{
2691-
drawVectors(vparams);
2692-
}
2693-
2694-
if (showObject.getValue())
2695-
{
2696-
const float& scale = showObjectScale.getValue();
2697-
type::vector<type::Vec3> positions(d_size.getValue());
2698-
for (sofa::Index i = 0; i < Size(d_size.getValue()); ++i)
2699-
positions[i] = type::Vec3(getPX(i), getPY(i), getPZ(i));
2700-
2701-
switch (drawMode.getValue())
2702-
{
2703-
case 0:
2704-
vparams->drawTool()->drawPoints(positions,scale, d_color.getValue());
2705-
break;
2706-
case 1:
2707-
vparams->drawTool()->setLightingEnabled(true);
2708-
vparams->drawTool()->drawSpheres(positions,scale, d_color.getValue());
2709-
break;
2710-
case 2:
2711-
vparams->drawTool()->setLightingEnabled(true);
2712-
vparams->drawTool()->drawSpheres(positions,scale, sofa::type::RGBAColor::red());
2713-
break;
2714-
case 3:
2715-
vparams->drawTool()->setLightingEnabled(true);
2716-
vparams->drawTool()->drawSpheres(positions,scale, sofa::type::RGBAColor::green());
2717-
break;
2718-
case 4:
2719-
vparams->drawTool()->setLightingEnabled(true);
2720-
vparams->drawTool()->drawSpheres(positions,scale, sofa::type::RGBAColor::blue());
2721-
break;
2722-
default:
2723-
msg_error() << "No proper drawing mode found!";
2724-
break;
2725-
}
2726-
}
2727-
2728-
}
2729-
2730-
27312630
/// Find mechanical particles hit by the given ray.
27322631
/// A mechanical particle is defined as a 2D or 3D, position or rigid DOF
27332632
/// Returns false if this object does not support picking
@@ -2771,9 +2670,6 @@ bool MechanicalObject<DataTypes>::pickParticles(const core::ExecParams* /* param
27712670
template <class DataTypes>
27722671
bool MechanicalObject<DataTypes>::addBBox(SReal* minBBox, SReal* maxBBox)
27732672
{
2774-
// participating to bbox only if it is drawn
2775-
if( !showObject.getValue() ) return false;
2776-
27772673
static const unsigned spatial_dimensions = std::min( (unsigned)DataTypes::spatial_dimensions, 3u );
27782674

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

0 commit comments

Comments
 (0)