-
Notifications
You must be signed in to change notification settings - Fork 343
[Visual] Move, rename and clean OglCylinderModel #5124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
25233ed
abbed2d
e6333c1
632494c
896ba59
672f48d
bc6a0de
4dbfb5f
be412a9
0e256ea
eb247a1
c8ab58a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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: contact@sofa-framework.org * | ||
| ******************************************************************************/ | ||
| #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 | ||
| 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: contact@sofa-framework.org * | ||
| ******************************************************************************/ | ||
| #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(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we are creating a new object. Maybe we could consider renaming it. I'm not supper fan of XxxxYyyyyModel... because a Model is a vague name.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is already renamed from |
||
| ~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 was deleted.
Uh oh!
There was an error while loading. Please reload this page.