Home › Forum › SOFA › Using SOFA › Create a new component from AttachConstraint
- This topic has 15 replies, 2 voices, and was last updated 5 years, 6 months ago by Hugo.
-
AuthorPosts
-
20 May 2019 at 11:13 #13520amitBlocked
Hi @Hugo
Sorry to trouble you again.
I was trying to make a component using c++ inheriting from attach constraint.
But I am lost in the sense of how to begin?I looked at the link you shared and pluginExample project. But very confused by what modules and namespaces is needed,what header files to include and how to create the cmakeList file. Sorry if this seems too naive but I have not worked in projects of magnitude of sofa and very confused to begin.
Any help will be highly appreciated.
Thank you27 May 2019 at 15:01 #13531HugoKeymasterHi @amit
No problem it’s always a pleasure, but I apologize for my delay.
As you just attended the SOFA training session, I guess you have got the answer.Let me however give you some more input so that others can also benefit from your post.
The first step is to create your own plugin, as explained in the documentation and illustrated in the pluginExample.
Once your plugin created, to create a c++ class inheriting from AttachConstraint, here is an example to start from (TemplateAttachConstraint) I would use:TemplateAttachConstraint.h
/****************************************************************************** * SOFA, Simulation Open-Framework Architecture, development version * * (c) 2006-2017 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 * ******************************************************************************/ #ifndef SOFA_COMPONENT_PROJECTIVECONSTRAINTSET_TEMPLATEATTACHCONSTRAINT_H #define SOFA_COMPONENT_PROJECTIVECONSTRAINTSET_TEMPLATEATTACHCONSTRAINT_H #include "config.h" #include <sofa/component/projectiveconstraintset/AttachConstraint.h> #include <sofa/defaulttype/Vec3Types.h> namespace sofa { namespace component { namespace projectiveconstraintset { template <class DataTypes> class TemplateAttachConstraint : public sofa::component::projectiveconstraintset::AttachConstraint<DataTypes> { public: SOFA_CLASS(SOFA_TEMPLATE(TemplateAttachConstraint,DataTypes),SOFA_TEMPLATE(sofa::core::behavior::AttachConstraint,DataTypes)); typedef typename DataTypes::VecCoord VecCoord; typedef typename DataTypes::VecDeriv VecDeriv; typedef typename DataTypes::Coord Coord; typedef typename DataTypes::Deriv Deriv; typedef typename DataTypes::Real Real; typedef core::objectmodel::Data<VecCoord> DataVecCoord; typedef core::objectmodel::Data<VecDeriv> DataVecDeriv; protected: TemplateAttachConstraint(core::behavior::MechanicalState<DataTypes> *mm1, core::behavior::MechanicalState<DataTypes> *mm2); TemplateAttachConstraint(); virtual ~TemplateAttachConstraint(); public: // -- Constraint interface void init() override {}; void projectJacobianMatrix(const core::MechanicalParams* /*mparams*/ /* PARAMS FIRST */, core::MultiMatrixDerivId /*cId*/) override {}; void projectResponse(const core::MechanicalParams *mparams, DataVecDeriv& dx1, DataVecDeriv& dx2) override {}; void projectVelocity(const core::MechanicalParams *mparams, DataVecDeriv& v1, DataVecDeriv& v2) override {}; void projectPosition(const core::MechanicalParams *mparams, DataVecCoord& x1, DataVecCoord& x2) override {}; /// Project the global Mechanical Matrix to constrained space using offset parameter void applyConstraint(const core::MechanicalParams *mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override {}; /// Project the global Mechanical Vector to constrained space using offset parameter void applyConstraint(const core::MechanicalParams *mparams, defaulttype::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override {}; /// Define your internal functions and data }; #if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_PROJECTIVECONSTRAINTSET_TEMPLATEATTACHCONSTRAINT_CPP) extern template class SOFA_GENERAL_OBJECT_INTERACTION_API TemplateAttachConstraint<defaulttype::Vec3Types>; extern template class SOFA_GENERAL_OBJECT_INTERACTION_API TemplateAttachConstraint<defaulttype::Vec2Types>; extern template class SOFA_GENERAL_OBJECT_INTERACTION_API TemplateAttachConstraint<defaulttype::Vec1Types>; #endif } // namespace projectiveconstraintset } // namespace component } // namespace sofa #endif
TemplateAttachConstraint.inl
/****************************************************************************** * SOFA, Simulation Open-Framework Architecture, development version * * (c) 2006-2017 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 * ******************************************************************************/ #ifndef SOFA_COMPONENT_PROJECTIVECONSTRAINTSET_TEMPLATEATTACHCONSTRAINT_INL #define SOFA_COMPONENT_PROJECTIVECONSTRAINTSET_TEMPLATEATTACHCONSTRAINT_INL #include <SofaGeneralObjectInteraction/TemplateAttachConstraint.h> namespace sofa { namespace component { namespace projectiveconstraintset { template <class DataTypes> AttachConstraint<DataTypes>::AttachConstraint() : // INIT your data here { } template <class DataTypes> AttachConstraint<DataTypes>::AttachConstraint(core::behavior::MechanicalState<DataTypes> *mm1, core::behavior::MechanicalState<DataTypes> *mm2) : core::behavior::PairInteractionProjectiveConstraintSet<DataTypes>(mm1,mm2) , // INIT your data here { } template <class DataTypes> void AttachConstraint<DataTypes>::init() { // To implement } template<class DataTypes> void AttachConstraint<DataTypes>::projectJacobianMatrix(const core::MechanicalParams* /*mparams*/ /* PARAMS FIRST */, core::MultiMatrixDerivId /*cId*/) { // To implement } template <class DataTypes> void AttachConstraint<DataTypes>::projectPosition(const core::MechanicalParams * /*mparams*/, DataVecCoord& res1_d, DataVecCoord& res2_d) { // To implement } template <class DataTypes> void AttachConstraint<DataTypes>::projectVelocity(const core::MechanicalParams * /*mparams*/, DataVecDeriv& res1_d, DataVecDeriv& res2_d) { // To implement } template <class DataTypes> void AttachConstraint<DataTypes>::projectResponse(const core::MechanicalParams * /*mparams*/, DataVecDeriv& res1_d, DataVecDeriv& res2_d) { // To implement } // Matrix Integration interface template <class DataTypes> void AttachConstraint<DataTypes>::applyConstraint(const core::MechanicalParams * /*mparams*/, const sofa::core::behavior::MultiMatrixAccessor* matrix) { // To implement } template <class DataTypes> void AttachConstraint<DataTypes>::applyConstraint(const core::MechanicalParams * /*mparams*/, defaulttype::BaseVector* vect, const sofa::core::behavior::MultiMatrixAccessor* matrix) { // To implement } } } // namespace constraint } // namespace component } // namespace sofa #endif
TemplateAttachConstraint.cpp
/****************************************************************************** * SOFA, Simulation Open-Framework Architecture, development version * * (c) 2006-2017 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 * ******************************************************************************/ #define SOFA_COMPONENT_PROJECTIVECONSTRAINTSET_TEMPLATEATTACHCONSTRAINT_CPP #include "TemplateAttachConstraint.inl" #include <sofa/core/ObjectFactory.h> #include <sofa/defaulttype/VecTypes.h> namespace sofa { namespace component { namespace projectiveconstraintset { using namespace sofa::defaulttype; int TemplateAttachConstraintClass = core::RegisterObject("A specific constraint inheriting from AttachConstraint") .add< TemplateAttachConstraint<Vec3Types> >(); .add< TemplateAttachConstraint<Vec2Types> >(); .add< TemplateAttachConstraint<Vec1Types> >(); template class TemplateAttachConstraint<Vec3Types>; template class TemplateAttachConstraint<Vec2Types>; template class TemplateAttachConstraint<Vec1Types>; } // namespace projectiveconstraintset } // namespace component } // namespace sofa
NB: this kind of dev question is more dedicated on the Dev part of the forum.
Hope this helps, do not hesitate to close the topic if this explanation is fine for you.
Best,Hugo
28 May 2019 at 11:43 #13540amitBlockedHey
Thank you for your help.
However when I try to build sofa using this, I get error “Cannot open include file sofa/component/projectiveconstraintset/AttachConstraint.h”:No such file or directory.
I am trying to build using windows 10 and visual studio 2017.My cmakelists.txt file:
cmake_minimum_required(VERSION 3.1) project(MyPlugin) find_package(SofaFramework REQUIRED) find_package(SofaGeneral REQUIRED) find_package(SofaCommon REQUIRED) set(HEADER_FILES TemplateAttachConstraint.h TemplateAttachConstraint.inl config.h ) set(SOURCE_FILES TemplateAttachConstraint.cpp initPlugin.cpp ) add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES}) target_link_libraries(${PROJECT_NAME} SofaCore SofaGeneralObjectInteraction) include_directories("${CMAKE_CURRENT_SOURCE_DIR}/..") install(TARGETS ${PROJECT_NAME} COMPONENT MyPlugin_libraries EXPORT MyPluginTargets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
28 May 2019 at 15:36 #13545HugoKeymasterDear @amit
Your CMakeList seems perfect! Good work!!
The error is mine.
In the TemplateAttachConstraint.h, you should have#include <SofaGeneralObjectInteraction/AttachConstraint.h>
instead of#include <sofa/component/projectiveconstraintset/AttachConstraint.h>
In the TemplateAttachConstraint.h, you should have
#include "TemplateAttachConstraint.h"
instead of#include <SofaGeneralObjectInteraction/TemplateAttachConstraint.h>
Let me know if this works.
Hugo
30 May 2019 at 12:46 #13556amitBlockedHey @Hugo,
Thank you very much for your help. I was able to build the templateattachconstraint plugin.
Is removing the indices best way to remove an attach constraint at point of contact? I want to create an interaction where based on the contact of the instrument with the attached object, the constraints are removed at the point of contact and the attached objects are gradually separated. Is there any other(hopefully better) way to do this? Will you please give me some guidance regarding this?
Thank you again,
amit4 June 2019 at 15:43 #13565HugoKeymasterHi @amit
Sorry for the delay, I’ve been away for several days.
AttachConstraint is computing/enforcing two objects that are really attach, connected together.If you want to mimic the interaction / collision of two objects, you should better use the collision pipeline for this. See an example in examples/Components/animationloop/FreeAnimationLoop.scn showing different objects interacting. At each collision, it creates a constraint solved using the Lagrange multiplier method.
If you want to model two objects that can be torn apart, using an AttachConstraint which can remove the constraints when the object are detached from another, your approach is a good one.
I hope this helps
Hugo
5 June 2019 at 14:09 #13576amitBlockedHi @hugo,
sorry I dont quite understand what you want me to look at the freeanimationloop.scn.
Let me put my situation more clearly.
I am trying to model fatty tissue that is between two organs, Liver and gallbladder. Here is the xml scene for modelling fatty tissue between liver and gallbladder.<?xml version="1.0" ?> <Node name="root" dt="0.02" showBoundingTree="0"> <VisualStyle displayFlags="showBehaviorModels showVisual" /> <CollisionPipeline verbose="0" /> <BruteForceDetection name="N2" /> <CollisionResponse response="default" /> <MinProximityIntersection name="Proximity" alarmDistance="0.8" contactDistance="0.5" /> <RequiredPlugin pluginName="MyPlugin"/> <CollisionGroup /> <Node name ="Attach"> <EulerImplicit name="cg_odesolverAC" printLog="false" rayleighStiffness="0.1" rayleighMass="0.1" /> <CGLinearSolver iterations="25" name="linear solverAC" tolerance="1.0e-9" threshold="1.0e-9" /> <Node name="Liver"> <EulerImplicit name="cg_odesolver" printLog="false" rayleighStiffness="0.1" rayleighMass="0.1" /> <CGLinearSolver iterations="25" name="linear solver" tolerance="1.0e-9" threshold="1.0e-9" /> <MeshGmshLoader name="loader" filename="./myMesh/liver_only.msh" /> <MechanicalObject src="@loader" name="Volume" scale3d="60 60 60" rotation="140 180 0" translation ="15 100 85"/> <TetrahedronSetTopologyContainer name="Container" position="@Volume.position" src="@loader" tags=" "/> <TetrahedronSetTopologyModifier name="Modifier" /> <TetrahedronSetTopologyAlgorithms name="TopoAlgo" template="Vec3d" /> <TetrahedronSetGeometryAlgorithms name="GeomAlgo" template="Vec3d" showPointIndices="1"/> <DiagonalMass massDensity="1.0" /> <BoxROI template="Vec3d" box="25 98 70 30 100 80" drawBoxes="1" position="@Volume.rest_position" name="FixedROI" /> <FixedConstraint indices="@FixedROI.indices" /> <FastTetrahedralCorotationalForceField name="FEM" youngModulus="13000" poissonRatio="0.3" method="large" /> <Node name="T"> <TriangleSetTopologyContainer name="Container" fileTopology="" tags=" " /> <TriangleSetTopologyModifier name="Modifier" /> <TriangleSetTopologyAlgorithms name="TopoAlgo" template="Vec3d" /> <TriangleSetGeometryAlgorithms name="GeomAlgo" template="Vec3d" /> <Tetra2TriangleTopologicalMapping input="@../Container" output="@Container" /> <TriangularBendingSprings name="FEM-Bend" stiffness="60000" damping="1.0" /> <TriangleSet /> <Node name="VisuLiver"> <OglModel name="Visual" color="blue" /> <IdentityMapping input="@../../Volume" output="@Visual" /> </Node> </Node> </Node> <Node name="Gallbladder"> <EulerImplicit name="cg_odesolver" printLog="false" rayleighStiffness="0.1" rayleighMass="0.1" /> <CGLinearSolver iterations="25" name="linear solver" tolerance="1.0e-9" threshold="1.0e-9" /> <MeshGmshLoader name="loader" filename="./myMesh/gallbladder_only.msh" /> <MechanicalObject src="@loader" name="Volume" scale3d="20 20 20" rotation="140 180 0" translation ="22 106 86"/> <TetrahedronSetTopologyContainer name="Container" position="@Volume.position" src="@loader" tags=" "/> <TetrahedronSetTopologyModifier name="Modifier" /> <TetrahedronSetTopologyAlgorithms name="TopoAlgo" template="Vec3d" /> <TetrahedronSetGeometryAlgorithms name="GeomAlgo" template="Vec3d" showPointIndices="1"/> <DiagonalMass massDensity="1.0" /> <FastTetrahedralCorotationalForceField name="FEM" youngModulus="13000" poissonRatio="0.3" method="large" /> <Node name="T"> <TriangleSetTopologyContainer name="Container" fileTopology="" tags=" " /> <TriangleSetTopologyModifier name="Modifier" /> <TriangleSetTopologyAlgorithms name="TopoAlgo" template="Vec3d" /> <TriangleSetGeometryAlgorithms name="GeomAlgo" template="Vec3d" /> <Tetra2TriangleTopologicalMapping input="@../Container" output="@Container" /> <TriangularBendingSprings name="FEM-Bend" stiffness="60000" damping="1.0" /> <TriangleSet /> <Node name="VisuGallbladder"> <OglModel name="Visual" color="blue" /> <IdentityMapping input="@../../Volume" output="@Visual" /> </Node> </Node> </Node> <Node name="Fat"> <EulerImplicit name="cg_odesolver" printLog="false" rayleighStiffness="0.1" rayleighMass="0.1" /> <CGLinearSolver iterations="25" name="linear solver" tolerance="1.0e-9" threshold="1.0e-9" /> <MeshGmshLoader name="loader" filename="./myMesh/fat_only.msh" /> <MechanicalObject src="@loader" name="Volume" scale3d="2.85 2.85 2.85" rotation="140 180 0" translation ="15 101 85"/> <TetrahedronSetTopologyContainer name="Container" position="@Volume.position" src="@loader" tags=" "/> <TetrahedronSetTopologyModifier name="Modifier" /> <TetrahedronSetTopologyAlgorithms name="TopoAlgo" template="Vec3d" /> <TetrahedronSetGeometryAlgorithms name="GeomAlgo" template="Vec3d" showPointIndices="1"/> <DiagonalMass massDensity="1.0" /> <FastTetrahedralCorotationalForceField name="FEM" youngModulus="13000" poissonRatio="0.3" method="large" /> <Node name="T"> <TriangleSetTopologyContainer name="Container" fileTopology="" tags=" " /> <TriangleSetTopologyModifier name="Modifier" /> <TriangleSetTopologyAlgorithms name="TopoAlgo" template="Vec3d" /> <TriangleSetGeometryAlgorithms name="GeomAlgo" template="Vec3d" /> <Tetra2TriangleTopologicalMapping input="@../Container" output="@Container" /> <TriangularBendingSprings name="FEM-Bend" stiffness="60000" damping="1.0" /> <TriangleSet /> <Node name="VisuFat"> <OglModel name="Visual" color="blue" /> <IdentityMapping input="@../../Volume" output="@Visual" /> </Node> </Node> </Node> <NearestPointROI template="Vec3" name="np1" object1="@./Liver/Volume" object2="@./Fat/Volume" radius="0.5"/> <NearestPointROI template="Vec3" name="np2" object1="@./Fat/Volume" object2="@./Gallbladder/Volume" radius="0.5"/> <TemplateAttachConstraint object1="@Liver" object2="@Fat" name ="AC1" indices1="@np1.indices1" indices2="@np1.indices2" /> <TemplateAttachConstraint object1="@Fat" object2="@Gallbladder" name="AC2" indices1="@np2.indices1" indices2="@np2.indices2"/> </Node> </Node>
The link to the mesh files.Meshes
As you can see, there is templateAttachConstraint used from Myplugin as you suggested earlier. Right now TemplateAttachConstraint is just a child of AttachConstraint,i.e,
it just inherits from attach constraint and I have not implemented any new data attribute or functions.Now I want to add in the TemplateAttachConstraint so that when I interact with the fatty tissue(burn or cut the tissue), the attach constraint are removed procedurally, not all constraints at once but at the point of interaction or contact. How would I approach to do so?
You had also suggested to me to make a new Spring force field component between the organs to attach them and change their stiffness based on their elongation to remove the spring connection. I want to try that approach too but I am not able to compute the indices in the meshes to be end points of the spring. If you can help me to find how do i choose the indices in the meshes that would be really helpful too.
Thank you for your assistance again. Please Help.
7 June 2019 at 13:42 #13589HugoKeymasterHi @amit
Thank you for re-detailing everything. It helps.
You can forget about my remark concerning the FreeAnimationLoop, the AttachConstraint seems to be well respected using the usual DefaultAL.The approach based on AttachConstraint in order to model the fatty tissue linking the two organs can work but I think this won’t look very really realistic. If you decrease/update the radius of the NearestROI you can see that the objects will suddenly detach (I tested changing radius from 0.5 to 0.000005).
Another approach that could look more physically realistic would be to go for springs (not necessarily linear!) linking the two objects. You could implement the stiffness law you wish and when the elongation exceeds a threshold, set the stiffness to zero. This would really give the feeling to tear the fatty tissue and detach the organs step by step.
To do so, you could inherit from SpringForceField, define the law you want and the threshold regarding the elongation as a Data.I hope this helps.
Best wishes,Hugo
10 June 2019 at 06:40 #13618amitBlockedThank you @Hugo.
I am now trying to create a component based on SpringForceField. But what concerns me is I have to provide the indices of the meshes manually to be linked to make the spring. I am currently using unity3D plugin for sofa and I am testing a lot of stuffs and changes are very frequent, also of the meshes. Is there any way I can provide the mesh indices data to be linked for the springs using python or available components in sofa?
Thank you
11 June 2019 at 19:07 #13629HugoKeymasterHey @amit,
To know which are the indices, you can see these point indices in SOFA by setting in the MechanicalObject:
showIndices="1"
andshowIndicesScale="3.0"
(set the scale you want).If you want to automatically select points in a region of interest (ROI), you can still use Box/Sphere/NearestPointROI.
This could help. If this is not what you are looking for, please let me know.
BestHugo
12 June 2019 at 08:11 #13634amitBlockedHey @Hugo,
Thank You I am trying try all the methods you suggested.
How do we show indices in a region? Using showIndices in mechanical object gives unreadable indices so I tried using BoxROI with show indices to only show indices of some region I am interested in but it is not working with message unused attribute showIndices. Anyway we can show only the indices of region in interest?12 June 2019 at 09:55 #13637HugoKeymasterHey @amit,
There is no such option in the BoxROI. However, this could be added in the
draw()
function of the BoxROI class by getting inspired of the draw() in the MechanicalObject.
Let us know if you struggle with this part.Best
Hugo
13 June 2019 at 12:03 #13666amitBlockedHello @hugo,
I just changed drawPoints() function in draw function of BoxROI with draw3DText_Indices(). But i think it is giving me the index of points in roi but not in mesh.
Sorry could not figure out the proper way to follow what you said. Would you mind helping me do this?Also, if I have to check for some event in each frame like checking the elongation of spring or collision, what is the best way to do this?
Thank you19 June 2019 at 19:21 #13792HugoKeymasterHey @amit,
What you can do in the
draw()
function of BoxROI is to use the function:vparams->drawTool()->draw3DText(pv, size, color, indice);
I tried it on my side, it worked. Here is a diff file:
diff --git a/SofaKernel/modules/SofaEngine/BoxROI.h b/SofaKernel/modules/SofaEngine/BoxROI.h index c1896c2..4bad42e 100644 --- a/SofaKernel/modules/SofaEngine/BoxROI.h +++ b/SofaKernel/modules/SofaEngine/BoxROI.h @@ -166,6 +166,7 @@ public: //Parameter Data<bool> d_drawBoxes; ///< Draw Boxes. (default = false) Data<bool> d_drawPoints; ///< Draw Points. (default = false) + Data<bool> d_drawPointIndices; ///< Draw Points indices. (default = false) Data<bool> d_drawEdges; ///< Draw Edges. (default = false) Data<bool> d_drawTriangles; ///< Draw Triangles. (default = false) Data<bool> d_drawTetrahedra; ///< Draw Tetrahedra. (default = false) diff --git a/SofaKernel/modules/SofaEngine/BoxROI.inl b/SofaKernel/modules/SofaEngine/BoxROI.inl index 776307e..43bd206 100644 --- a/SofaKernel/modules/SofaEngine/BoxROI.inl +++ b/SofaKernel/modules/SofaEngine/BoxROI.inl @@ -91,6 +91,7 @@ BoxROI<DataTypes>::BoxROI() , d_nbIndices( initData(&d_nbIndices,"nbIndices", "Number of selected indices") ) , d_drawBoxes( initData(&d_drawBoxes,false,"drawBoxes","Draw Boxes. (default = false)") ) , d_drawPoints( initData(&d_drawPoints,false,"drawPoints","Draw Points. (default = false)") ) + , d_drawPointIndices( initData(&d_drawPointIndices,false,"drawPointIndices","Draw Points indices in ROI. (default = false)") ) , d_drawEdges( initData(&d_drawEdges,false,"drawEdges","Draw Edges. (default = false)") ) , d_drawTriangles( initData(&d_drawTriangles,false,"drawTriangles","Draw Triangles. (default = false)") ) , d_drawTetrahedra( initData(&d_drawTetrahedra,false,"drawTetrahedra","Draw Tetrahedra. (default = false)") ) @@ -810,6 +811,29 @@ void BoxROI<DataTypes>::draw(const core::visual::VisualParams* vparams) vparams->drawTool()->drawLines(vertices, linesWidth, color); } + ///draw points indices in ROI + if( d_drawPointIndices.getValue()) + { + float size = d_drawSize.getValue() ? (float)d_drawSize.getValue() : 1; + vparams->drawTool()->setLightingEnabled(false); + std::vector<Vector3> vertices; + ReadAccessor< Data<VecCoord > > pointsInROI = d_pointsInROI; + ReadAccessor< Data<SetIndex > > indices = d_indices; + + for (unsigned int i=0; i<pointsInROI.size() ; ++i) + { + CPos p = DataTypes::getCPos(pointsInROI[i]); + Vector3 pv; + for( unsigned int j=0 ; j<max_spatial_dimensions ; ++j ) + pv[j] = p[j]; + + std::ostringstream oss; + oss << indices[i]; + const char* indice = oss.str().c_str(); + vparams->drawTool()->draw3DText(pv, size, color, indice); + } + } + ///draw triangles in ROI if( d_drawTriangles.getValue()) {
Events are described here. Using the listening option, you will activate the c++ function handleEvent() handling all SOFA events.
Best,
Hugo
20 June 2019 at 06:49 #13793amitBlockedHello Hugo,
Thank You for your suggestion. I will test it out.
Meanwhile, I worked around it by writing a python script to print out indices from nearestPointROI component to a text file and using indices to link springs from that file.Right now I am struggling with collision detection in sofa. When I set my models for collision(triangle/sphere or any model) the frame rate drops and the simulation becomes unusable. I need real time, fast and robust collision detection between the organs and the tools so they dont penetrate each other and I can set up interaction based on collision of the tools and organs. What is the proper way to set up collision pipeline so that we can have realistic real time collision with suitable frame rates(~ 60 fps). Please help me with this issue.
20 June 2019 at 10:16 #13798HugoKeymasterHi @amit
I forgot to mention, but do not hesitate to pull-request this improvement of BoxROI in SOFA! To do so, the documentation is here.
Right now I am struggling with collision detection in sofa. When I set my models for collision(triangle/sphere or any model) the frame rate drops and the simulation becomes unusable.
Performances will depend on your mesh refinement for the collision model, as well as on the numerical properties. I would advise to first try using a slightly coarser mesh for the collision detection. Do not hesitate to share your scene with me (in private if necessary).
However, once everything is optimized, if the simulation is still not efficient enough there is (always!) solutions. We have independent developers in the community working on a multithreaded and GPU collision detection. I could put you in contact with these guys if you need it.
Best
Hugo
-
AuthorPosts
- You must be logged in to reply to this topic.