Skip to content
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

[VolumetricRendering] Fix the compilation #4398

Merged
merged 4 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ void OglTetrahedralModel< gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> >::ini

if (!nodes)
{
serr << "No mecha." << sendl;
msg_error() << "No mecha.";
return;
}

if (!topo)
{
serr << "No topo." << sendl;
msg_error() << "No topo.";
return;
}

Expand Down
17 changes: 7 additions & 10 deletions applications/plugins/VolumetricRendering/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 "$<BUILD_INTERFACE:${OPENHAPTICS_INCLUDE_DIR}>")
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}"
)
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
<?xml version="1.0"?>
<Node name="root" dt="0.02">

<MeshVTKLoader name="loader" filename="mesh/raptorTetra_8418.vtu" />
<MechanicalObject src="@loader" template="Vec3d" />
<include href="Objects/TetrahedronSetTopology.xml" src="@loader" />

<Node>
<OglShader geometryVerticesOut="12" geometryInputType="10" geometryOutputType="5" vertFilename="shaders/tetra.vert" geoFilename="shaders/tetra_triangles.geo" fragFilename="shaders/tetra.frag" />
<OglFloat4Variable id="vertexColor" value="1 1 0 1"/>
<OglFloatVariable id="tetraScale" value="0.8"/>
<OglFloatVariable id="u_enableLight" value="2"/>
<OglTetrahedralModel template="Vec3d" />
</Node>
<RequiredPlugin name="Sofa.Component.IO.Mesh"/> <!-- Needed to use components [MeshVTKLoader] -->
<RequiredPlugin name="Sofa.Component.StateContainer"/> <!-- Needed to use components [MechanicalObject] -->
<RequiredPlugin name="Sofa.Component.Topology.Container.Dynamic"/> <!-- Needed to use components [TetrahedronSetGeometryAlgorithms,TetrahedronSetTopologyContainer,TetrahedronSetTopologyModifier] -->
<RequiredPlugin name="Sofa.GL.Component.Shader"/> <!-- Needed to use components [OglFloat4Variable,OglFloatVariable,OglShader] -->
<RequiredPlugin name="SofaCUDA"/>
<RequiredPlugin name="VolumetricRendering"/>

</Node>
<DefaultAnimationLoop/>
<MeshVTKLoader name="loader" filename="mesh/raptorTetra_8418.vtu" />
<MechanicalObject src="@loader" template="Vec3d" />
<include href="Objects/TetrahedronSetTopology.xml" src="@loader" />

<Node>
<OglShader geometryVerticesOut="12" geometryInputType="10" geometryOutputType="5" fileVertexShaders="['shaders/tetra.vert']" fileGeometryShaders="['shaders/tetra_triangles.geo']" fileFragmentShaders="['shaders/tetra.frag']" />
<OglFloat4Variable id="vertexColor" value="1 1 0 1"/>
<OglFloatVariable id="tetraScale" value="0.8"/>
<OglFloatVariable id="u_enableLight" value="2"/>
<OglTetrahedralModel template="Vec3d" />
</Node>

</Node>
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
<?xml version="1.0"?>
<Node name="root" dt="0.02">
<RequiredPlugin name="Sofa.Component.StateContainer"/> <!-- Needed to use components [MechanicalObject] -->
<RequiredPlugin name="Sofa.Component.Topology.Container.Dynamic"/> <!-- Needed to use components [HexahedronSetTopologyContainer] -->
<RequiredPlugin name="Sofa.Component.Topology.Container.Grid"/> <!-- Needed to use components [SparseGridTopology] -->
<RequiredPlugin name="Sofa.GL.Component.Shader"/> <!-- Needed to use components [OglFloatVariable,OglShader] -->
<RequiredPlugin name="VolumetricRendering" />

<SparseGridTopology name="grid" n="51 51 51" fileTopology="mesh/raptor_8kp.obj" />
<DefaultAnimationLoop/>
<SparseGridTopology name="grid" n="51 51 51" fileTopology="mesh/raptor_8kp.obj" />

<MechanicalObject template="Vec3d" />
<HexahedronSetTopologyContainer hexahedra="@grid.hexahedra" />
<MechanicalObject template="Vec3d" />
<HexahedronSetTopologyContainer hexahedra="@grid.hexahedra" />

<Node>
<OglShader geometryVerticesOut="12" geometryInputType="10" geometryOutputType="5"
vertFilename="share/shaders/tetra.vert" geoFilename="share/shaders/tetra_triangles.geo" fragFilename="share/shaders/tetra.frag" />
<OglFloatVariable id="volumeScale" value="0.9"/>
<OglFloatVariable id="u_enableLight" value="1"/>
<OglVolumetricModel printLog="false" color="1 0 1 1" />
</Node>
<Node>
<OglShader geometryVerticesOut="12" geometryInputType="10" geometryOutputType="5"
fileVertexShaders="['share/shaders/tetra.vert']" fileGeometryShaders="['share/shaders/tetra_triangles.geo']" fileFragmentShaders="['share/shaders/tetra.frag']" />
<OglFloatVariable id="volumeScale" value="0.9"/>
<OglFloatVariable id="u_enableLight" value="1"/>
<OglVolumetricModel printLog="false" color="1 0 1 1" />
</Node>

</Node>
</Node>
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
<RequiredPlugin name="VolumetricRendering" />

<Node name="Input">
<SparseGridTopology name="grid" n="51 51 51" fileTopology="mesh/raptor_8kp.obj" />
<SparseGridTopology name="grid" n="51 51 51" fileTopology="mesh/raptor_8kp.obj" />

<MechanicalObject name="dofs" template="Vec3d" />
<HexahedronSetTopologyContainer name="topology" hexahedra="@grid.hexahedra" />
</Node>
<MechanicalObject name="dofs" template="Vec3d" />
<HexahedronSetTopologyContainer name="topology" hexahedra="@grid.hexahedra" />
</Node>

<Node>
<OglShader geometryVerticesOut="12" geometryInputType="10" geometryOutputType="5"
vertFilename="share/shaders/tetra.vert" geoFilename="share/shaders/tetra_triangles.geo" fragFilename="share/shaders/tetra.frag" />
<OglFloatVariable id="volumeScale" value="0.9"/>
<OglFloatVariable id="u_enableLight" value="1"/>
<OglVolumetricModel position="@../Input/dofs.position" hexahedra="@../Input/topology.hexahedra" printLog="false" color="1 0 1 1" />
</Node>
<Node>
<OglShader geometryVerticesOut="12" geometryInputType="10" geometryOutputType="5"
fileVertexShaders="['share/shaders/tetra.vert']" fileGeometryShaders="['share/shaders/tetra_triangles.geo']" fileFragmentShaders="['share/shaders/tetra.frag']" />
<OglFloatVariable id="volumeScale" value="0.9"/>
<OglFloatVariable id="u_enableLight" value="1"/>
<OglVolumetricModel position="@../Input/dofs.position" hexahedra="@../Input/topology.hexahedra" printLog="false" color="1 0 1 1" />
</Node>

</Node>
</Node>
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#version 140

uniform float u_enableLight;

//GLSL >= 130
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 130
#version 140

// uniform vec4 vertexColor;
in vec4 a_vertexColor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 130
#version 140
#extension GL_EXT_geometry_shader4: enable

//GLSL >= 130
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <sofa/defaulttype/VecTypes.h>
#include <sofa/defaulttype/VecTypes.h>
#include <sofa/core/topology/TopologyData.inl>
#include <SofaOpenglVisual/OglVariable.h>
#include <sofa/gl/component/shader/OglVariable.h>

namespace sofa
{
Expand Down Expand Up @@ -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();
Expand All @@ -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<DataTypes>* = NULL)
{
return DataTypes::Name();
}
};

#if !defined(SOFA_COMPONENT_VISUALMODEL_OGLTETRAHEDRALMODEL_CPP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <sofa/gl/GLSLShader.h>
#include <sofa/core/visual/VisualParams.h>
#include <sofa/type/BoundingBox.h>
#include <SofaBaseTopology/TetrahedronSetTopologyContainer.h>
#include <limits>

namespace sofa
Expand Down Expand Up @@ -63,8 +62,8 @@ void OglTetrahedralModel<DataTypes>::init()

//instanciate the mapping tables
//Useful for the PT algorithm only
sofa::type::vector<sofa::component::visual::OglFloatVector4Variable::SPtr > listVec4Variables;
this->getContext()->core::objectmodel::BaseContext::template get<sofa::component::visual::OglFloatVector4Variable, sofa::type::vector<sofa::component::visual::OglFloatVector4Variable::SPtr> >
sofa::type::vector<sofa::gl::component::shader::OglFloatVector4Variable::SPtr > listVec4Variables;
this->getContext()->core::objectmodel::BaseContext::template get<sofa::gl::component::shader::OglFloatVector4Variable, sofa::type::vector<sofa::gl::component::shader::OglFloatVector4Variable::SPtr> >
(&listVec4Variables, core::objectmodel::BaseContext::Local);
for (unsigned int i = 0; i<listVec4Variables.size(); i++)
{
Expand All @@ -85,7 +84,7 @@ void OglTetrahedralModel<DataTypes>::init()
if (!m_mappingTableValues)
{
msg_info() << "No MappingTable found, instanciating one";
m_mappingTableValues = sofa::core::objectmodel::New<sofa::component::visual::OglFloatVector4Variable>();
m_mappingTableValues = sofa::core::objectmodel::New<sofa::gl::component::shader::OglFloatVector4Variable>();
m_mappingTableValues->setName("MappingTable");
m_mappingTableValues->setID("MappingTable");

Expand All @@ -109,7 +108,7 @@ void OglTetrahedralModel<DataTypes>::init()
{
msg_info() << "No RunSelectTable found, instanciating one";

m_runSelectTableValues = sofa::core::objectmodel::New<sofa::component::visual::OglFloatVector4Variable>();
m_runSelectTableValues = sofa::core::objectmodel::New<sofa::gl::component::shader::OglFloatVector4Variable>();
m_runSelectTableValues->setName("RunSelectTable");
m_runSelectTableValues->setID("RunSelectTable");

Expand Down Expand Up @@ -255,7 +254,6 @@ void OglTetrahedralModel<DataTypes>::computeMesh()
template<class DataTypes>
void OglTetrahedralModel<DataTypes>::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;
Expand Down Expand Up @@ -288,7 +286,15 @@ void OglTetrahedralModel<DataTypes>::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<typename Coord::value_type, double>)
{
gltype = GL_DOUBLE;
}

glVertexPointer(3, gltype, 0, nullptr);

glBindBufferARB(GL_ARRAY_BUFFER, 0);

glEnableClientState(GL_VERTEX_ARRAY);
Expand Down
Loading
Loading