From afb627cf979a3cd7b939035b3e138af8e60463c0 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Thu, 14 Nov 2024 14:58:14 +0100 Subject: [PATCH] [Engine.Select] Automatically find topology in MeshBoundaryROI --- .../sofa/component/engine/select/BaseROI.h | 8 ++--- .../engine/select/MeshBoundaryROI.cpp | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/BaseROI.h b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/BaseROI.h index c9c84070c0f..08f5ae34079 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/BaseROI.h +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/BaseROI.h @@ -68,10 +68,10 @@ class BaseROI : public core::DataEngine void draw(const core::visual::VisualParams* vparams) final; void computeBBox(const core::ExecParams* params, bool onlyVisible) final; - virtual void roiInit() {}; - virtual bool roiDoUpdate() { return true; }; - virtual void roiDraw(const core::visual::VisualParams*) {}; - virtual void roiComputeBBox(const core::ExecParams*, type::BoundingBox&) {}; + virtual void roiInit() {} + virtual bool roiDoUpdate() { return true; } + virtual void roiDraw(const core::visual::VisualParams*) {} + virtual void roiComputeBBox(const core::ExecParams*, type::BoundingBox&) {} public: //Input diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshBoundaryROI.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshBoundaryROI.cpp index e866d610604..6cc1947422f 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshBoundaryROI.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshBoundaryROI.cpp @@ -46,6 +46,35 @@ MeshBoundaryROI::MeshBoundaryROI(): Inherit1() void MeshBoundaryROI::init() { + Inherit1::init(); + + if (!d_triangles.isSet() || !d_quads.isSet() ) + { + msg_info(this) << "No topology given. Searching for a BaseMeshTopology in the current context.\n"; + core::topology::BaseMeshTopology* topology = nullptr; + this->getContext()->get(topology, core::objectmodel::BaseContext::Local); + + if (topology) + { + if (!d_triangles.isSet()) + { + if (core::BaseData* tparent = topology->findData("triangles")) + { + d_triangles.setParent(tparent); + d_triangles.setReadOnly(true); + } + } + if (!d_quads.isSet()) + { + if (core::BaseData* tparent = topology->findData("quads")) + { + d_quads.setParent(tparent); + d_quads.setReadOnly(true); + } + } + } + } + setDirtyValue(); }