forked from sofa-framework/sofa
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Visual] Move, rename and clean OglCylinderModel (sofa-framework#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
- Loading branch information
Showing
11 changed files
with
178 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
Sofa/Component/Visual/src/sofa/component/visual/CylinderVisualModel.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/****************************************************************************** | ||
* SOFA, Simulation Open-Framework Architecture * | ||
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * | ||
* * | ||
* This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>. * | ||
******************************************************************************* | ||
* Authors: The SOFA Team and external contributors (see Authors.txt) * | ||
* * | ||
* Contact information: [email protected] * | ||
******************************************************************************/ | ||
#include <sofa/component/visual/CylinderVisualModel.h> | ||
#include <sofa/core/ObjectFactory.h> | ||
#include <sofa/core/visual/VisualParams.h> | ||
#include <sofa/core/ObjectFactory.h> | ||
|
||
namespace sofa::component::visual | ||
{ | ||
|
||
void registerCylinderVisualModel(sofa::core::ObjectFactory* factory) | ||
{ | ||
factory->registerObjects(core::ObjectRegistrationData("Visualize a set of cylinders.") | ||
.add< CylinderVisualModel >()); | ||
} | ||
|
||
CylinderVisualModel::CylinderVisualModel() | ||
: radius(initData(&radius, 1.0f, "radius", "Radius of the cylinder.")), | ||
color(initData(&color, sofa::type::RGBAColor::white(), "color", "Color of the cylinders.")) | ||
, d_edges(initData(&d_edges,"edges","List of edge indices")) | ||
{ | ||
} | ||
|
||
CylinderVisualModel::~CylinderVisualModel() = default; | ||
|
||
void CylinderVisualModel::init() | ||
{ | ||
VisualModel::init(); | ||
|
||
reinit(); | ||
} | ||
|
||
void CylinderVisualModel::doDrawVisual(const core::visual::VisualParams* vparams) | ||
{ | ||
const VecCoord& pos = this->read( core::vec_id::read_access::position )->getValue(); | ||
|
||
auto* drawTool = vparams->drawTool(); | ||
|
||
drawTool->setLightingEnabled(true); | ||
|
||
const float _radius = radius.getValue(); | ||
const sofa::type::RGBAColor& col = color.getValue(); | ||
|
||
const SeqEdges& edges = d_edges.getValue(); | ||
|
||
for(const auto& edge : edges) | ||
{ | ||
const Coord& p1 = pos[edge[0]]; | ||
const Coord& p2 = pos[edge[1]]; | ||
|
||
drawTool->drawCylinder(p1, p2, _radius, col); | ||
} | ||
} | ||
|
||
void CylinderVisualModel::exportOBJ(std::string name, std::ostream* out, std::ostream* /*mtl*/, Index& vindex, Index& /*nindex*/, Index& /*tindex*/, int& /*count*/) | ||
{ | ||
const VecCoord& x = this->read( core::vec_id::read_access::position )->getValue(); | ||
const SeqEdges& edges = d_edges.getValue(); | ||
|
||
const int nbv = int(x.size()); | ||
|
||
*out << "g "<<name<<"\n"; | ||
|
||
for( int i=0 ; i<nbv; i++ ) | ||
*out << "v "<< std::fixed << x[i][0]<<' '<< std::fixed <<x[i][1]<<' '<< std::fixed <<x[i][2]<<'\n'; | ||
|
||
for( size_t i = 0 ; i < edges.size() ; i++ ) | ||
*out << "f " << edges[i][0]+vindex+1 << " " << edges[i][1]+vindex+1 << '\n'; | ||
|
||
*out << std::endl; | ||
|
||
vindex += nbv; | ||
} | ||
|
||
} // namespace sofa::component::visual |
61 changes: 61 additions & 0 deletions
61
Sofa/Component/Visual/src/sofa/component/visual/CylinderVisualModel.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/****************************************************************************** | ||
* SOFA, Simulation Open-Framework Architecture * | ||
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * | ||
* * | ||
* This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>. * | ||
******************************************************************************* | ||
* Authors: The SOFA Team and external contributors (see Authors.txt) * | ||
* * | ||
* Contact information: [email protected] * | ||
******************************************************************************/ | ||
#pragma once | ||
#include <sofa/component/visual/config.h> | ||
|
||
#include <sofa/core/visual/VisualModel.h> | ||
#include <sofa/core/visual/VisualState.h> | ||
#include <sofa/type/RGBAColor.h> | ||
|
||
namespace sofa::component::visual | ||
{ | ||
|
||
class SOFA_COMPONENT_VISUAL_API CylinderVisualModel : | ||
public core::visual::VisualModel, public sofa::core::visual::VisualState<defaulttype::Vec3Types> | ||
{ | ||
public: | ||
using Vec3State = sofa::core::visual::VisualState<defaulttype::Vec3Types>; | ||
SOFA_CLASS2(CylinderVisualModel,core::visual::VisualModel, Vec3State); | ||
|
||
protected: | ||
CylinderVisualModel(); | ||
~CylinderVisualModel() override; | ||
public: | ||
void init() override; | ||
|
||
void doDrawVisual(const core::visual::VisualParams* vparams) override; | ||
|
||
void exportOBJ(std::string /*name*/, std::ostream* /*out*/, std::ostream* /*mtl*/, Index& /*vindex*/, Index& /*nindex*/, Index& /*tindex*/, int& /*count*/) override; | ||
|
||
private: | ||
Data<float> radius; ///< Radius of the cylinder. | ||
Data<sofa::type::RGBAColor> color; ///< Color of the cylinders. | ||
|
||
typedef sofa::type::vector<core::topology::Edge> SeqEdges; | ||
Data<SeqEdges> d_edges; ///< List of edge indices | ||
|
||
public: | ||
bool insertInNode( core::objectmodel::BaseNode* node ) override { Inherit1::insertInNode(node); Inherit2::insertInNode(node); return true; } | ||
bool removeInNode( core::objectmodel::BaseNode* node ) override { Inherit1::removeInNode(node); Inherit2::removeInNode(node); return true; } | ||
}; | ||
|
||
} // namespace sofa::component::visual |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 0 additions & 163 deletions
163
Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglCylinderModel.cpp
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.