Skip to content

Commit

Permalink
[VolumetricRendering] Fix the compilation
Browse files Browse the repository at this point in the history
But scenes crash
  • Loading branch information
alxbilger committed Dec 20, 2023
1 parent 026a501 commit c473a66
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 85 deletions.
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@

#include <sofa/core/ObjectFactory.h>
#include <sofa/gl/GLSLShader.h>
#include <SofaBaseTopology/TetrahedronSetTopologyContainer.h>
#include <sofa/type/BoundingBox.h>
#include <SofaOpenglVisual/OglAttribute.inl>
#include <sofa/gl/component/shader/OglAttribute.inl>

namespace sofa::component::visualmodel
{
Expand Down Expand Up @@ -74,8 +73,8 @@ void OglVolumetricModel::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 @@ -96,7 +95,7 @@ void OglVolumetricModel::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 @@ -118,7 +117,7 @@ void OglVolumetricModel::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 @@ -185,8 +184,8 @@ void OglVolumetricModel::initVisual()
glBindBufferARB(GL_ARRAY_BUFFER, 0);

//Check attributes
sofa::type::vector<sofa::component::visual::OglFloat4Attribute::SPtr > listVec4Attributes;
this->getContext()->core::objectmodel::BaseContext::template get<sofa::component::visual::OglFloat4Attribute, sofa::type::vector<sofa::component::visual::OglFloat4Attribute::SPtr> >
sofa::type::vector<sofa::gl::component::shader::OglFloat4Attribute::SPtr > listVec4Attributes;
this->getContext()->core::objectmodel::BaseContext::template get<sofa::gl::component::shader::OglFloat4Attribute, sofa::type::vector<sofa::gl::component::shader::OglFloat4Attribute::SPtr> >
(&listVec4Attributes, core::objectmodel::BaseContext::Local);
for (unsigned int i = 0; i < listVec4Attributes.size(); i++)
{
Expand All @@ -201,7 +200,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<sofa::component::visual::OglFloat4Attribute>();
m_vertexColors = sofa::core::objectmodel::New<sofa::gl::component::shader::OglFloat4Attribute>();
m_vertexColors->setName("a_vertexColor");
m_vertexColors->setID("a_vertexColor");
m_vertexColors->setIndexShader(0);
Expand Down Expand Up @@ -399,7 +398,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include <VolumetricRendering/initVolumetricRendering.h>
#include <sofa/core/ObjectFactory.h>

#include <VolumetricRendering/config.h>

namespace sofa::component
namespace volumetricrendering
{

//Here are just several convenient functions to help user to know what contains the plugin
Expand All @@ -36,6 +36,11 @@ extern "C" {
SOFA_VOLUMETRICRENDERING_API const char* getModuleComponentList();
}

void init()
{
initExternalModule();
}

void initExternalModule()
{
static bool first = true;
Expand All @@ -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()
Expand All @@ -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
Loading

0 comments on commit c473a66

Please sign in to comment.