Skip to content

Commit 99df0a2

Browse files
authored
[Visual] Move, rename and clean OglCylinderModel (#5124)
* move files * depreciation * rename * fix color management * remove string to color conversion and use the one from RGBAColor * remove unused private methods * cleaning * component change * remove Index alias * change the description * cache drawTool * remove calls to removed functions
1 parent 02b3366 commit 99df0a2

File tree

11 files changed

+178
-240
lines changed

11 files changed

+178
-240
lines changed

Sofa/Component/Visual/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set(HEADER_FILES
88
${SOFACOMPONENTVISUAL_SOURCE_DIR}/init.h
99
${SOFACOMPONENTVISUAL_SOURCE_DIR}/BaseCamera.h
1010
${SOFACOMPONENTVISUAL_SOURCE_DIR}/Camera.h
11+
${SOFACOMPONENTVISUAL_SOURCE_DIR}/CylinderVisualModel.h
1112
${SOFACOMPONENTVISUAL_SOURCE_DIR}/InteractiveCamera.h
1213
${SOFACOMPONENTVISUAL_SOURCE_DIR}/LineAxis.h
1314
${SOFACOMPONENTVISUAL_SOURCE_DIR}/RecordedCamera.h
@@ -24,6 +25,7 @@ set(SOURCE_FILES
2425
${SOFACOMPONENTVISUAL_SOURCE_DIR}/init.cpp
2526
${SOFACOMPONENTVISUAL_SOURCE_DIR}/BaseCamera.cpp
2627
${SOFACOMPONENTVISUAL_SOURCE_DIR}/Camera.cpp
28+
${SOFACOMPONENTVISUAL_SOURCE_DIR}/CylinderVisualModel.cpp
2729
${SOFACOMPONENTVISUAL_SOURCE_DIR}/InteractiveCamera.cpp
2830
${SOFACOMPONENTVISUAL_SOURCE_DIR}/LineAxis.cpp
2931
${SOFACOMPONENTVISUAL_SOURCE_DIR}/RecordedCamera.cpp
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/******************************************************************************
2+
* SOFA, Simulation Open-Framework Architecture *
3+
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU Lesser General Public License as published by *
7+
* the Free Software Foundation; either version 2.1 of the License, or (at *
8+
* your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13+
* for more details. *
14+
* *
15+
* You should have received a copy of the GNU Lesser General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Authors: The SOFA Team and external contributors (see Authors.txt) *
19+
* *
20+
* Contact information: [email protected] *
21+
******************************************************************************/
22+
#include <sofa/component/visual/CylinderVisualModel.h>
23+
#include <sofa/core/ObjectFactory.h>
24+
#include <sofa/core/visual/VisualParams.h>
25+
#include <sofa/core/ObjectFactory.h>
26+
27+
namespace sofa::component::visual
28+
{
29+
30+
void registerCylinderVisualModel(sofa::core::ObjectFactory* factory)
31+
{
32+
factory->registerObjects(core::ObjectRegistrationData("Visualize a set of cylinders.")
33+
.add< CylinderVisualModel >());
34+
}
35+
36+
CylinderVisualModel::CylinderVisualModel()
37+
: radius(initData(&radius, 1.0f, "radius", "Radius of the cylinder.")),
38+
color(initData(&color, sofa::type::RGBAColor::white(), "color", "Color of the cylinders."))
39+
, d_edges(initData(&d_edges,"edges","List of edge indices"))
40+
{
41+
}
42+
43+
CylinderVisualModel::~CylinderVisualModel() = default;
44+
45+
void CylinderVisualModel::init()
46+
{
47+
VisualModel::init();
48+
49+
reinit();
50+
}
51+
52+
void CylinderVisualModel::doDrawVisual(const core::visual::VisualParams* vparams)
53+
{
54+
const VecCoord& pos = this->read( core::vec_id::read_access::position )->getValue();
55+
56+
auto* drawTool = vparams->drawTool();
57+
58+
drawTool->setLightingEnabled(true);
59+
60+
const float _radius = radius.getValue();
61+
const sofa::type::RGBAColor& col = color.getValue();
62+
63+
const SeqEdges& edges = d_edges.getValue();
64+
65+
for(const auto& edge : edges)
66+
{
67+
const Coord& p1 = pos[edge[0]];
68+
const Coord& p2 = pos[edge[1]];
69+
70+
drawTool->drawCylinder(p1, p2, _radius, col);
71+
}
72+
}
73+
74+
void CylinderVisualModel::exportOBJ(std::string name, std::ostream* out, std::ostream* /*mtl*/, Index& vindex, Index& /*nindex*/, Index& /*tindex*/, int& /*count*/)
75+
{
76+
const VecCoord& x = this->read( core::vec_id::read_access::position )->getValue();
77+
const SeqEdges& edges = d_edges.getValue();
78+
79+
const int nbv = int(x.size());
80+
81+
*out << "g "<<name<<"\n";
82+
83+
for( int i=0 ; i<nbv; i++ )
84+
*out << "v "<< std::fixed << x[i][0]<<' '<< std::fixed <<x[i][1]<<' '<< std::fixed <<x[i][2]<<'\n';
85+
86+
for( size_t i = 0 ; i < edges.size() ; i++ )
87+
*out << "f " << edges[i][0]+vindex+1 << " " << edges[i][1]+vindex+1 << '\n';
88+
89+
*out << std::endl;
90+
91+
vindex += nbv;
92+
}
93+
94+
} // namespace sofa::component::visual
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/******************************************************************************
2+
* SOFA, Simulation Open-Framework Architecture *
3+
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU Lesser General Public License as published by *
7+
* the Free Software Foundation; either version 2.1 of the License, or (at *
8+
* your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13+
* for more details. *
14+
* *
15+
* You should have received a copy of the GNU Lesser General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Authors: The SOFA Team and external contributors (see Authors.txt) *
19+
* *
20+
* Contact information: [email protected] *
21+
******************************************************************************/
22+
#pragma once
23+
#include <sofa/component/visual/config.h>
24+
25+
#include <sofa/core/visual/VisualModel.h>
26+
#include <sofa/core/visual/VisualState.h>
27+
#include <sofa/type/RGBAColor.h>
28+
29+
namespace sofa::component::visual
30+
{
31+
32+
class SOFA_COMPONENT_VISUAL_API CylinderVisualModel :
33+
public core::visual::VisualModel, public sofa::core::visual::VisualState<defaulttype::Vec3Types>
34+
{
35+
public:
36+
using Vec3State = sofa::core::visual::VisualState<defaulttype::Vec3Types>;
37+
SOFA_CLASS2(CylinderVisualModel,core::visual::VisualModel, Vec3State);
38+
39+
protected:
40+
CylinderVisualModel();
41+
~CylinderVisualModel() override;
42+
public:
43+
void init() override;
44+
45+
void doDrawVisual(const core::visual::VisualParams* vparams) override;
46+
47+
void exportOBJ(std::string /*name*/, std::ostream* /*out*/, std::ostream* /*mtl*/, Index& /*vindex*/, Index& /*nindex*/, Index& /*tindex*/, int& /*count*/) override;
48+
49+
private:
50+
Data<float> radius; ///< Radius of the cylinder.
51+
Data<sofa::type::RGBAColor> color; ///< Color of the cylinders.
52+
53+
typedef sofa::type::vector<core::topology::Edge> SeqEdges;
54+
Data<SeqEdges> d_edges; ///< List of edge indices
55+
56+
public:
57+
bool insertInNode( core::objectmodel::BaseNode* node ) override { Inherit1::insertInNode(node); Inherit2::insertInNode(node); return true; }
58+
bool removeInNode( core::objectmodel::BaseNode* node ) override { Inherit1::removeInNode(node); Inherit2::removeInNode(node); return true; }
59+
};
60+
61+
} // namespace sofa::component::visual

Sofa/Component/Visual/src/sofa/component/visual/init.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace sofa::component::visual
2727
{
2828

2929
extern void registerCamera(sofa::core::ObjectFactory* factory);
30+
extern void registerCylinderVisualModel(sofa::core::ObjectFactory* factory);
3031
extern void registerInteractiveCamera(sofa::core::ObjectFactory* factory);
3132
extern void registerLineAxis(sofa::core::ObjectFactory* factory);
3233
extern void registerRecordedCamera(sofa::core::ObjectFactory* factory);
@@ -63,6 +64,7 @@ void registerObjects(sofa::core::ObjectFactory* factory)
6364
{
6465
registerCamera(factory);
6566
registerInteractiveCamera(factory);
67+
registerCylinderVisualModel(factory);
6668
registerLineAxis(factory);
6769
registerRecordedCamera(factory);
6870
registerTrailRenderer(factory);

Sofa/GL/Component/Rendering3D/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ set(SOURCE_FILES
2121
${SOFAGLCOMPONENTRENDERING3D_SOURCE_DIR}/ClipPlane.cpp
2222
${SOFAGLCOMPONENTRENDERING3D_SOURCE_DIR}/DataDisplay.cpp
2323
${SOFAGLCOMPONENTRENDERING3D_SOURCE_DIR}/MergeVisualModels.cpp
24-
${SOFAGLCOMPONENTRENDERING3D_SOURCE_DIR}/OglCylinderModel.cpp
2524
${SOFAGLCOMPONENTRENDERING3D_SOURCE_DIR}/OglModel.cpp
2625
${SOFAGLCOMPONENTRENDERING3D_SOURCE_DIR}/OglSceneFrame.cpp
2726
${SOFAGLCOMPONENTRENDERING3D_SOURCE_DIR}/PointSplatModel.cpp

Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglCylinderModel.cpp

Lines changed: 0 additions & 163 deletions
This file was deleted.

0 commit comments

Comments
 (0)