From 9a107f7f68193a97905c9357e6a5365af2ca201c Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Fri, 5 Jan 2024 11:34:29 +0100 Subject: [PATCH] [VolumetricRendering] Fix the compilation (#4398) * [VolumetricRendering] Fix the compilation But scenes crash * reflect changes from datatype change for vec3state (#6) * fix lots of stuff (#7) --------- Co-authored-by: Frederick Roy Co-authored-by: Hugo --- .../gpu/cuda/CudaTetrahedralVisualModel.inl | 4 +- .../VolumetricRendering/CMakeLists.txt | 17 ++--- .../examples/OglTetrahedralModel.scn | 32 +++++---- .../examples/OglVolumetricModel_hexa.scn | 27 ++++--- .../examples/OglVolumetricModel_hexa_link.scn | 24 +++---- .../examples/share/shaders/tetra.frag | 2 + .../examples/share/shaders/tetra.vert | 2 +- .../share/shaders/tetra_triangles.geo | 2 +- .../VolumetricRendering/OglTetrahedralModel.h | 16 +---- .../OglTetrahedralModel.inl | 20 ++++-- .../OglVolumetricModel.cpp | 71 +++++++++++-------- .../VolumetricRendering/OglVolumetricModel.h | 6 +- .../src/VolumetricRendering/config.h.in | 6 ++ .../initVolumetricRendering.cpp | 21 +++--- .../initVolumetricRendering.h | 29 ++++++++ 15 files changed, 171 insertions(+), 108 deletions(-) create mode 100644 applications/plugins/VolumetricRendering/src/VolumetricRendering/initVolumetricRendering.h diff --git a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaTetrahedralVisualModel.inl b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaTetrahedralVisualModel.inl index e5e866f3b1e..db7a13e0020 100644 --- a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaTetrahedralVisualModel.inl +++ b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaTetrahedralVisualModel.inl @@ -59,13 +59,13 @@ void OglTetrahedralModel< gpu::cuda::CudaVectorTypes >::ini if (!nodes) { - serr << "No mecha." << sendl; + msg_error() << "No mecha."; return; } if (!topo) { - serr << "No topo." << sendl; + msg_error() << "No topo."; return; } diff --git a/applications/plugins/VolumetricRendering/CMakeLists.txt b/applications/plugins/VolumetricRendering/CMakeLists.txt index 0f13f8e0ee6..b02f7146d1f 100644 --- a/applications/plugins/VolumetricRendering/CMakeLists.txt +++ b/applications/plugins/VolumetricRendering/CMakeLists.txt @@ -1,11 +1,12 @@ cmake_minimum_required(VERSION 3.12) -project(VolumetricRendering VERSION 0.1) +project(VolumetricRendering) -find_package(Sofa.Helper REQUIRED) +find_package(Sofa.Config REQUIRED) sofa_find_package(Sofa.GL.Component REQUIRED) set(HEADER_FILES src/VolumetricRendering/config.h.in + src/VolumetricRendering/initVolumetricRendering.cpp src/VolumetricRendering/OglTetrahedralModel.h src/VolumetricRendering/OglTetrahedralModel.inl src/VolumetricRendering/OglVolumetricModel.h @@ -19,17 +20,13 @@ set(SOURCE_FILES add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES}) -target_link_libraries(${PROJECT_NAME} Sofa.Helper Sofa.GL.Component) - -# Add the include DIR from OpenHaptics to target -target_include_directories(${PROJECT_NAME} PUBLIC "$") +target_link_libraries(${PROJECT_NAME} Sofa.GL.Component) # Install rules for the library and the headers; CMake package configurations files sofa_create_package_with_targets( PACKAGE_NAME ${PROJECT_NAME} + PACKAGE_VERSION ${Sofa_VERSION} TARGETS ${PROJECT_NAME} AUTO_SET_TARGET_PROPERTIES - PACKAGE_VERSION ${PROJECT_VERSION} INCLUDE_SOURCE_DIR "src" - INCLUDE_INSTALL_DIR "VolumetricRendering" - RELOCATABLE "plugins" - ) + INCLUDE_INSTALL_DIR "${PROJECT_NAME}" +) diff --git a/applications/plugins/VolumetricRendering/examples/OglTetrahedralModel.scn b/applications/plugins/VolumetricRendering/examples/OglTetrahedralModel.scn index d0e0e6dbe73..2584b9a2401 100644 --- a/applications/plugins/VolumetricRendering/examples/OglTetrahedralModel.scn +++ b/applications/plugins/VolumetricRendering/examples/OglTetrahedralModel.scn @@ -1,16 +1,24 @@ - - - - - - - - - - - + + + + + + - \ No newline at end of file + + + + + + + + + + + + + + diff --git a/applications/plugins/VolumetricRendering/examples/OglVolumetricModel_hexa.scn b/applications/plugins/VolumetricRendering/examples/OglVolumetricModel_hexa.scn index 6947acd4725..7ddea1884d8 100644 --- a/applications/plugins/VolumetricRendering/examples/OglVolumetricModel_hexa.scn +++ b/applications/plugins/VolumetricRendering/examples/OglVolumetricModel_hexa.scn @@ -1,18 +1,23 @@ + + + + - + + - - + + - - - - - - + + + + + + - \ No newline at end of file + diff --git a/applications/plugins/VolumetricRendering/examples/OglVolumetricModel_hexa_link.scn b/applications/plugins/VolumetricRendering/examples/OglVolumetricModel_hexa_link.scn index e6a93625208..34048c30a8b 100644 --- a/applications/plugins/VolumetricRendering/examples/OglVolumetricModel_hexa_link.scn +++ b/applications/plugins/VolumetricRendering/examples/OglVolumetricModel_hexa_link.scn @@ -3,18 +3,18 @@ - + - - - + + + - - - - - - + + + + + + - \ No newline at end of file + diff --git a/applications/plugins/VolumetricRendering/examples/share/shaders/tetra.frag b/applications/plugins/VolumetricRendering/examples/share/shaders/tetra.frag index 8ac26097cb3..c4a64b8d353 100644 --- a/applications/plugins/VolumetricRendering/examples/share/shaders/tetra.frag +++ b/applications/plugins/VolumetricRendering/examples/share/shaders/tetra.frag @@ -1,3 +1,5 @@ +#version 140 + uniform float u_enableLight; //GLSL >= 130 diff --git a/applications/plugins/VolumetricRendering/examples/share/shaders/tetra.vert b/applications/plugins/VolumetricRendering/examples/share/shaders/tetra.vert index f853623ad1d..823e83e4def 100644 --- a/applications/plugins/VolumetricRendering/examples/share/shaders/tetra.vert +++ b/applications/plugins/VolumetricRendering/examples/share/shaders/tetra.vert @@ -1,4 +1,4 @@ -#version 130 +#version 140 // uniform vec4 vertexColor; in vec4 a_vertexColor; diff --git a/applications/plugins/VolumetricRendering/examples/share/shaders/tetra_triangles.geo b/applications/plugins/VolumetricRendering/examples/share/shaders/tetra_triangles.geo index 2d9940dfb09..472c534595a 100644 --- a/applications/plugins/VolumetricRendering/examples/share/shaders/tetra_triangles.geo +++ b/applications/plugins/VolumetricRendering/examples/share/shaders/tetra_triangles.geo @@ -1,4 +1,4 @@ -#version 130 +#version 140 #extension GL_EXT_geometry_shader4: enable //GLSL >= 130 diff --git a/applications/plugins/VolumetricRendering/src/VolumetricRendering/OglTetrahedralModel.h b/applications/plugins/VolumetricRendering/src/VolumetricRendering/OglTetrahedralModel.h index 43b29a359af..0fd1ca8244a 100644 --- a/applications/plugins/VolumetricRendering/src/VolumetricRendering/OglTetrahedralModel.h +++ b/applications/plugins/VolumetricRendering/src/VolumetricRendering/OglTetrahedralModel.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include namespace sofa { @@ -76,8 +76,8 @@ class OglTetrahedralModel : public core::visual::VisualModel void updateVertexBuffer(); //Tables - sofa::component::visual::OglFloatVector4Variable::SPtr m_mappingTableValues; - sofa::component::visual::OglFloatVector4Variable::SPtr m_runSelectTableValues; + sofa::gl::component::shader::OglFloatVector4Variable::SPtr m_mappingTableValues; + sofa::gl::component::shader::OglFloatVector4Variable::SPtr m_runSelectTableValues; protected: OglTetrahedralModel(); @@ -90,16 +90,6 @@ class OglTetrahedralModel : public core::visual::VisualModel void updateVisual() override; virtual void computeMesh(); - - virtual std::string getTemplateName() const - { - return templateName(this); - } - - static std::string templateName(const OglTetrahedralModel* = NULL) - { - return DataTypes::Name(); - } }; #if !defined(SOFA_COMPONENT_VISUALMODEL_OGLTETRAHEDRALMODEL_CPP) diff --git a/applications/plugins/VolumetricRendering/src/VolumetricRendering/OglTetrahedralModel.inl b/applications/plugins/VolumetricRendering/src/VolumetricRendering/OglTetrahedralModel.inl index 6d8f5216bb1..a2c4849bfa0 100644 --- a/applications/plugins/VolumetricRendering/src/VolumetricRendering/OglTetrahedralModel.inl +++ b/applications/plugins/VolumetricRendering/src/VolumetricRendering/OglTetrahedralModel.inl @@ -28,7 +28,6 @@ #include #include #include -#include #include namespace sofa @@ -63,8 +62,8 @@ void OglTetrahedralModel::init() //instanciate the mapping tables //Useful for the PT algorithm only - sofa::type::vector listVec4Variables; - this->getContext()->core::objectmodel::BaseContext::template get > + sofa::type::vector listVec4Variables; + this->getContext()->core::objectmodel::BaseContext::template get > (&listVec4Variables, core::objectmodel::BaseContext::Local); for (unsigned int i = 0; i::init() if (!m_mappingTableValues) { msg_info() << "No MappingTable found, instanciating one"; - m_mappingTableValues = sofa::core::objectmodel::New(); + m_mappingTableValues = sofa::core::objectmodel::New(); m_mappingTableValues->setName("MappingTable"); m_mappingTableValues->setID("MappingTable"); @@ -109,7 +108,7 @@ void OglTetrahedralModel::init() { msg_info() << "No RunSelectTable found, instanciating one"; - m_runSelectTableValues = sofa::core::objectmodel::New(); + m_runSelectTableValues = sofa::core::objectmodel::New(); m_runSelectTableValues->setName("RunSelectTable"); m_runSelectTableValues->setID("RunSelectTable"); @@ -255,7 +254,6 @@ void OglTetrahedralModel::computeMesh() template void OglTetrahedralModel::drawTransparent(const core::visual::VisualParams* vparams) { - using sofa::component::topology::TetrahedronSetTopologyContainer; if (!vparams->displayFlags().getShowVisualModels()) return; if (m_topology == NULL) return; if (m_topology->getNbTetrahedra() < 1) return; @@ -288,7 +286,15 @@ void OglTetrahedralModel::drawTransparent(const core::visual::VisualP glBindBufferARB(GL_ARRAY_BUFFER, m_vbo); - glVertexPointer(3, GL_FLOAT, 0, (char*)NULL + 0); + int gltype = GL_FLOAT; + + if constexpr (std::is_same_v) + { + gltype = GL_DOUBLE; + } + + glVertexPointer(3, gltype, 0, nullptr); + glBindBufferARB(GL_ARRAY_BUFFER, 0); glEnableClientState(GL_VERTEX_ARRAY); diff --git a/applications/plugins/VolumetricRendering/src/VolumetricRendering/OglVolumetricModel.cpp b/applications/plugins/VolumetricRendering/src/VolumetricRendering/OglVolumetricModel.cpp index a966e904856..36605896fa4 100644 --- a/applications/plugins/VolumetricRendering/src/VolumetricRendering/OglVolumetricModel.cpp +++ b/applications/plugins/VolumetricRendering/src/VolumetricRendering/OglVolumetricModel.cpp @@ -28,9 +28,8 @@ #include #include -#include #include -#include +#include namespace sofa::component::visualmodel { @@ -74,8 +73,8 @@ void OglVolumetricModel::init() //instanciate the mapping tables //Useful for the PT algorithm only - sofa::type::vector listVec4Variables; - this->getContext()->core::objectmodel::BaseContext::template get > + sofa::type::vector listVec4Variables; + this->getContext()->core::objectmodel::BaseContext::template get > (&listVec4Variables, core::objectmodel::BaseContext::Local); for (unsigned int i = 0; i(); + m_mappingTableValues = sofa::core::objectmodel::New(); m_mappingTableValues->setName("MappingTable"); m_mappingTableValues->setID("MappingTable"); @@ -118,7 +117,7 @@ void OglVolumetricModel::init() { msg_info() << "No RunSelectTable found, instanciating one"; - m_runSelectTableValues = sofa::core::objectmodel::New(); + m_runSelectTableValues = sofa::core::objectmodel::New(); m_runSelectTableValues->setName("RunSelectTable"); m_runSelectTableValues->setID("RunSelectTable"); @@ -156,7 +155,6 @@ void OglVolumetricModel::init() if (b_useTopology) computeMeshFromTopology(); - updateVisual(); } @@ -185,8 +183,8 @@ void OglVolumetricModel::initVisual() glBindBufferARB(GL_ARRAY_BUFFER, 0); //Check attributes - sofa::type::vector listVec4Attributes; - this->getContext()->core::objectmodel::BaseContext::template get > + sofa::type::vector listVec4Attributes; + this->getContext()->core::objectmodel::BaseContext::template get > (&listVec4Attributes, core::objectmodel::BaseContext::Local); for (unsigned int i = 0; i < listVec4Attributes.size(); i++) { @@ -201,7 +199,7 @@ void OglVolumetricModel::initVisual() if (!m_vertexColors) { msg_error() << "No attributes called a_vertexColor found, instanciating one with a default color"; - m_vertexColors = sofa::core::objectmodel::New(); + m_vertexColors = sofa::core::objectmodel::New(); m_vertexColors->setName("a_vertexColor"); m_vertexColors->setID("a_vertexColor"); m_vertexColors->setIndexShader(0); @@ -222,7 +220,6 @@ void OglVolumetricModel::initVisual() m_vertexColors->init(); m_vertexColors->initVisual(); - } void OglVolumetricModel::updateVisual() @@ -358,27 +355,38 @@ void OglVolumetricModel::computeBarycenters() if (!b_tboCreated) { //Texture buffer objects + if (m_tetraBarycenters.size() > 0) + { + glGenBuffers(1, &m_tetraBarycentersTbo); + glBindBuffer(GL_TEXTURE_BUFFER, m_tetraBarycentersTbo); + glBufferData(GL_TEXTURE_BUFFER, tetraBarycentersBufferSize, &(m_tetraBarycenters[0]), GL_DYNAMIC_COPY); + glGenTextures(1, &m_tetraBarycentersTboTexture); + glBindBuffer(GL_TEXTURE_BUFFER, 0); + b_tboCreated = true; + } + if (m_hexaBarycenters.size() > 0) + { + glGenBuffers(1, &m_hexaBarycentersTbo); + glBindBuffer(GL_TEXTURE_BUFFER, m_hexaBarycentersTbo); + glBufferData(GL_TEXTURE_BUFFER, hexaBarycentersBufferSize, &(m_hexaBarycenters[0]), GL_DYNAMIC_COPY); + glGenTextures(1, &m_hexaBarycentersTboTexture); + glBindBuffer(GL_TEXTURE_BUFFER, 0); + b_tboCreated = true; + } + } - glGenBuffers(1, &m_tetraBarycentersTbo); + if (m_tetraBarycenters.size() > 0) + { glBindBuffer(GL_TEXTURE_BUFFER, m_tetraBarycentersTbo); - glBufferData(GL_TEXTURE_BUFFER, tetraBarycentersBufferSize, &(m_tetraBarycenters[0]), GL_DYNAMIC_COPY); - glGenTextures(1, &m_tetraBarycentersTboTexture); + glBufferSubData(GL_TEXTURE_BUFFER, 0, tetraBarycentersBufferSize, &(m_tetraBarycenters[0])); glBindBuffer(GL_TEXTURE_BUFFER, 0); - - glGenBuffers(1, &m_hexaBarycentersTbo); + } + if (m_hexaBarycenters.size() > 0) + { glBindBuffer(GL_TEXTURE_BUFFER, m_hexaBarycentersTbo); - glBufferData(GL_TEXTURE_BUFFER, hexaBarycentersBufferSize, &(m_hexaBarycenters[0]), GL_DYNAMIC_COPY); - glGenTextures(1, &m_hexaBarycentersTboTexture); + glBufferSubData(GL_TEXTURE_BUFFER, 0, hexaBarycentersBufferSize, &(m_hexaBarycenters[0])); glBindBuffer(GL_TEXTURE_BUFFER, 0); - - b_tboCreated = true; } - - glBindBuffer(GL_TEXTURE_BUFFER, m_tetraBarycentersTbo); - glBufferSubData(GL_TEXTURE_BUFFER, 0, tetraBarycentersBufferSize, &(m_tetraBarycenters[0])); - glBindBuffer(GL_TEXTURE_BUFFER, m_hexaBarycentersTbo); - glBufferSubData(GL_TEXTURE_BUFFER, 0, hexaBarycentersBufferSize, &(m_hexaBarycenters[0])); - glBindBuffer(GL_TEXTURE_BUFFER, 0); } void OglVolumetricModel::handleTopologyChange() @@ -399,7 +407,6 @@ void OglVolumetricModel::handleTopologyChange() void OglVolumetricModel::drawTransparent(const core::visual::VisualParams* vparams) { - using sofa::component::topology::TetrahedronSetTopologyContainer; if (!vparams->displayFlags().getShowVisualModels()) return; glPushAttrib(GL_ALL_ATTRIB_BITS); @@ -426,7 +433,14 @@ void OglVolumetricModel::drawTransparent(const core::visual::VisualParams* vpara #ifdef GL_LINES_ADJACENCY_EXT glBindBufferARB(GL_ARRAY_BUFFER, m_vbo); - glVertexPointer(3, GL_FLOAT, 0, (char*)NULL + 0); + int gltype = GL_FLOAT; + + if constexpr (std::is_same_v) + { + gltype = GL_DOUBLE; + } + + glVertexPointer(3, gltype, 0, nullptr); glBindBufferARB(GL_ARRAY_BUFFER, 0); glEnableClientState(GL_VERTEX_ARRAY); @@ -435,6 +449,7 @@ void OglVolumetricModel::drawTransparent(const core::visual::VisualParams* vpara const type::vector& hexahedra = d_hexahedra.getValue(); //glEnable(GL_CLIP_DISTANCE0); + if (tetrahedra.size() > 0) { glBindTexture(GL_TEXTURE_BUFFER, m_tetraBarycentersTboTexture); diff --git a/applications/plugins/VolumetricRendering/src/VolumetricRendering/OglVolumetricModel.h b/applications/plugins/VolumetricRendering/src/VolumetricRendering/OglVolumetricModel.h index 84f9b2ae64f..7fc4034afad 100644 --- a/applications/plugins/VolumetricRendering/src/VolumetricRendering/OglVolumetricModel.h +++ b/applications/plugins/VolumetricRendering/src/VolumetricRendering/OglVolumetricModel.h @@ -49,7 +49,7 @@ namespace visualmodel class SOFA_VOLUMETRICRENDERING_API OglVolumetricModel : public core::visual::VisualModel, public component::visual::Vec3State { public: - SOFA_CLASS2(OglVolumetricModel, core::visual::VisualModel, Vec3State); + SOFA_CLASS2(OglVolumetricModel, core::visual::VisualModel, component::visual::Vec3State); typedef sofa::core::topology::Tetrahedron Tetrahedron; typedef sofa::core::topology::Hexahedron Hexahedron; @@ -94,8 +94,8 @@ class SOFA_VOLUMETRICRENDERING_API OglVolumetricModel : public core::visual::Vis sofa::type::vector m_hexaToTetrahedra; - sofa::type::vector m_tetraBarycenters; - sofa::type::vector m_hexaBarycenters; + sofa::type::vector m_tetraBarycenters; + sofa::type::vector m_hexaBarycenters; public: void init() override; diff --git a/applications/plugins/VolumetricRendering/src/VolumetricRendering/config.h.in b/applications/plugins/VolumetricRendering/src/VolumetricRendering/config.h.in index 40f6cac6c86..bb9fb08d30a 100644 --- a/applications/plugins/VolumetricRendering/src/VolumetricRendering/config.h.in +++ b/applications/plugins/VolumetricRendering/src/VolumetricRendering/config.h.in @@ -33,4 +33,10 @@ # define SOFA_VOLUMETRICRENDERING_API SOFA_IMPORT_DYNAMIC_LIBRARY #endif +namespace volumetricrendering +{ + constexpr const char* MODULE_NAME = "@PROJECT_NAME@"; + constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@"; +} + #endif diff --git a/applications/plugins/VolumetricRendering/src/VolumetricRendering/initVolumetricRendering.cpp b/applications/plugins/VolumetricRendering/src/VolumetricRendering/initVolumetricRendering.cpp index 3008b366634..de1556a8deb 100644 --- a/applications/plugins/VolumetricRendering/src/VolumetricRendering/initVolumetricRendering.cpp +++ b/applications/plugins/VolumetricRendering/src/VolumetricRendering/initVolumetricRendering.cpp @@ -19,10 +19,10 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ +#include +#include -#include - -namespace sofa::component +namespace volumetricrendering { //Here are just several convenient functions to help user to know what contains the plugin @@ -36,6 +36,11 @@ extern "C" { SOFA_VOLUMETRICRENDERING_API const char* getModuleComponentList(); } +void init() +{ + initExternalModule(); +} + void initExternalModule() { static bool first = true; @@ -47,12 +52,12 @@ void initExternalModule() const char* getModuleName() { - return "VolumetricRendering"; + return volumetricrendering::MODULE_NAME; } const char* getModuleVersion() { - return "0.1"; + return volumetricrendering::MODULE_VERSION; } const char* getModuleLicense() @@ -68,9 +73,9 @@ const char* getModuleDescription() const char* getModuleComponentList() { - return "OglTetrahedralModel"; + static std::string classes = sofa::core::ObjectFactory::getInstance()->listClassesFromTarget(volumetricrendering::MODULE_NAME); + return classes.c_str(); } -} // namespace sofa::component - +} // namespace volumetricrendering diff --git a/applications/plugins/VolumetricRendering/src/VolumetricRendering/initVolumetricRendering.h b/applications/plugins/VolumetricRendering/src/VolumetricRendering/initVolumetricRendering.h new file mode 100644 index 00000000000..fb505e5a842 --- /dev/null +++ b/applications/plugins/VolumetricRendering/src/VolumetricRendering/initVolumetricRendering.h @@ -0,0 +1,29 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +namespace volumetricrendering +{ +SOFA_VOLUMETRICRENDERING_API void init(); +}