Skip to content

Commit

Permalink
WIP: new mrpt-viz library
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Jan 4, 2025
1 parent 2270811 commit 2d823b6
Show file tree
Hide file tree
Showing 111 changed files with 18,018 additions and 236 deletions.
10 changes: 0 additions & 10 deletions libs/opengl/include/mrpt/opengl/CPointCloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ class CPointCloud :
* to have an easy to use name. */
std::vector<mrpt::math::TPoint3Df>& m_points = CRenderizableShaderPoints::m_vertex_buffer_data;

/** Default: false */
bool m_pointSmooth = false;

mutable size_t m_last_rendered_count{0}, m_last_rendered_count_ongoing{0};

/** Do needed internal work if all points are new (octree rebuilt,...) */
Expand Down Expand Up @@ -285,13 +282,6 @@ class CPointCloud :
CRenderizable::notifyChange();
}

void enablePointSmooth(bool enable = true)
{
m_pointSmooth = enable;
CRenderizable::notifyChange();
}
void disablePointSmooth() { m_pointSmooth = false; }
bool isPointSmoothEnabled() const { return m_pointSmooth; }
/** Sets the colors used as extremes when colorFromDepth is enabled. */
void setGradientColors(const mrpt::img::TColorf& colorMin, const mrpt::img::TColorf& colorMax);

Expand Down
17 changes: 0 additions & 17 deletions libs/opengl/include/mrpt/opengl/CRenderizableShaderTriangles.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,6 @@ class CRenderizableShaderTriangles : public virtual CRenderizable
m_vao.destroy();
}

bool isLightEnabled() const { return m_enableLight; }
void enableLight(bool enable = true) { m_enableLight = enable; }

/** Control whether to render the FRONT, BACK, or BOTH (default) set of
* faces. Refer to docs for glCullFace().
* Example: If set to `cullFaces(TCullFace::BACK);`, back faces will not be
* drawn ("culled")
*/
void cullFaces(const TCullFace& cf) { m_cullface = cf; }
TCullFace cullFaces() const { return m_cullface; }

/** @name Raw access to triangle shader buffer data
* @{ */
const auto& shaderTrianglesBuffer() const { return m_triangles; }
Expand All @@ -75,15 +64,9 @@ class CRenderizableShaderTriangles : public virtual CRenderizable
/** Returns the bounding box of m_triangles, or (0,0,0)-(0,0,0) if empty. */
const mrpt::math::TBoundingBoxf trianglesBoundingBox() const;

void params_serialize(mrpt::serialization::CArchive& out) const;
void params_deserialize(mrpt::serialization::CArchive& in);

private:
mutable Buffer m_trianglesBuffer;
mutable VertexArrayObject m_vao;

bool m_enableLight = true;
TCullFace m_cullface = TCullFace::NONE;
};

} // namespace mrpt::opengl
16 changes: 0 additions & 16 deletions libs/opengl/include/mrpt/opengl/CRenderizableShaderWireFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,6 @@ class CRenderizableShaderWireFrame : public virtual CRenderizable
* to be drawn in "m_*_buffer" fields. */
virtual void onUpdateBuffers_Wireframe() = 0;

void setLineWidth(float w)
{
m_lineWidth = w;
CRenderizable::notifyChange();
}
float getLineWidth() const { return m_lineWidth; }
void enableAntiAliasing(bool enable = true)
{
m_antiAliasing = enable;
CRenderizable::notifyChange();
}
bool isAntiAliasingEnabled() const { return m_antiAliasing; }

// See base docs
void freeOpenGLResources() override
{
Expand All @@ -73,9 +60,6 @@ class CRenderizableShaderWireFrame : public virtual CRenderizable
mutable std::vector<mrpt::img::TColor> m_color_buffer_data;
mutable mrpt::containers::NonCopiableData<std::shared_mutex> m_wireframeMtx;

float m_lineWidth = 1.0f;
bool m_antiAliasing = false;

/** Returns the bounding box of m_vertex_buffer_data, or (0,0,0)-(0,0,0) if
* empty. */
const mrpt::math::TBoundingBox wireframeVerticesBoundingBox() const;
Expand Down
2 changes: 0 additions & 2 deletions libs/opengl/src/CPointCloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ void CPointCloud::serializeTo(mrpt::serialization::CSchemeArchiveBase& out) cons
out["colorFromDepth_max"]["R"] = m_colorFromDepth_max.R;
out["colorFromDepth_max"]["G"] = m_colorFromDepth_max.G;
out["colorFromDepth_max"]["B"] = m_colorFromDepth_max.B;
out["pointSmooth"] = m_pointSmooth;
}
void CPointCloud::serializeFrom(mrpt::serialization::CSchemeArchiveBase& in)
{
Expand Down Expand Up @@ -232,7 +231,6 @@ void CPointCloud::serializeFrom(mrpt::serialization::CSchemeArchiveBase& in)
m_colorFromDepth_max.R = static_cast<float>(in["colorFromDepth_max"]["R"]);
m_colorFromDepth_max.G = static_cast<float>(in["colorFromDepth_max"]["G"]);
m_colorFromDepth_max.B = static_cast<float>(in["colorFromDepth_max"]["B"]);
m_pointSmooth = static_cast<bool>(in["pointSmooth"]);
}
break;
default:
Expand Down
15 changes: 0 additions & 15 deletions libs/opengl/src/CRenderizableShaderPoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,3 @@ void CRenderizableShaderPoints::params_deserialize(mrpt::serialization::CArchive
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(version);
};
}

const mrpt::math::TBoundingBoxf CRenderizableShaderPoints::verticesBoundingBox() const
{
std::shared_lock<std::shared_mutex> wfReadLock(CRenderizableShaderPoints::m_pointsMtx.data);

mrpt::math::TBoundingBoxf bb;

if (m_vertex_buffer_data.empty()) return bb;

bb = mrpt::math::TBoundingBoxf::PlusMinusInfinity();

for (const auto& p : m_vertex_buffer_data) bb.updateWithPoint(p);

return bb;
}
148 changes: 0 additions & 148 deletions libs/opengl/src/CRenderizableShaderTexturedTriangles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,74 +185,6 @@ void CRenderizableShaderTexturedTriangles::render(const RenderContext& rc) const
#endif
}

void CRenderizableShaderTexturedTriangles::assignImage(const CImage& img, const CImage& imgAlpha)
{
MRPT_START

CRenderizable::notifyChange();

m_glTexture.unloadTexture();

// Make a copy:
m_textureImage = img;
m_textureImageAlpha = imgAlpha;
m_textureImageAssigned = true;

m_enableTransparency = true;

MRPT_END
}

void CRenderizableShaderTexturedTriangles::assignImage(const CImage& img)
{
MRPT_START

CRenderizable::notifyChange();

m_glTexture.unloadTexture();

// Make a shallow copy:
m_textureImage = img;
m_textureImageAssigned = true;

m_enableTransparency = false;

MRPT_END
}

void CRenderizableShaderTexturedTriangles::assignImage(CImage&& img, CImage&& imgAlpha)
{
MRPT_START

CRenderizable::notifyChange();

m_glTexture.unloadTexture();

m_textureImage = std::move(img);
m_textureImageAlpha = std::move(imgAlpha);
m_textureImageAssigned = true;

m_enableTransparency = true;

MRPT_END
}

void CRenderizableShaderTexturedTriangles::assignImage(CImage&& img)
{
MRPT_START

CRenderizable::notifyChange();

m_glTexture.unloadTexture();

m_textureImage = std::move(img);
m_textureImageAssigned = true;

m_enableTransparency = false;

MRPT_END
}

void CRenderizableShaderTexturedTriangles::initializeTextures() const
{
#if MRPT_HAS_OPENGL_GLUT || MRPT_HAS_EGL
Expand Down Expand Up @@ -298,83 +230,3 @@ CRenderizableShaderTexturedTriangles::~CRenderizableShaderTexturedTriangles()
<< mrpt::exception_to_str(e);
}
}

void CRenderizableShaderTexturedTriangles::writeToStreamTexturedObject(
mrpt::serialization::CArchive& out) const
{
uint8_t ver = 3;

out << ver;
out << m_enableTransparency << m_textureInterpolate << m_textureUseMipMaps;
out << m_textureImage;
if (m_enableTransparency) out << m_textureImageAlpha;
out << m_textureImageAssigned;
out << m_enableLight << static_cast<uint8_t>(m_cullface); // v2
}

void CRenderizableShaderTexturedTriangles::readFromStreamTexturedObject(
mrpt::serialization::CArchive& in)
{
uint8_t version;
in >> version;

switch (version)
{
case 0:
case 1:
case 2:
case 3:
{
in >> m_enableTransparency >> m_textureInterpolate;
if (version >= 3)
{
in >> m_textureUseMipMaps;
}
else
{
m_textureUseMipMaps = true;
}
in >> m_textureImage;
if (m_enableTransparency)
{
in >> m_textureImageAlpha;
assignImage(m_textureImage, m_textureImageAlpha);
}
else
{
assignImage(m_textureImage);
}
if (version >= 1)
in >> m_textureImageAssigned;
else
m_textureImageAssigned = true;

if (version >= 2)
{
in >> m_enableLight;
m_cullface = static_cast<TCullFace>(in.ReadAs<uint8_t>());
}
}
break;
default:
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(version);
};

CRenderizable::notifyChange();
}

const mrpt::math::TBoundingBoxf CRenderizableShaderTexturedTriangles::trianglesBoundingBox() const
{
mrpt::math::TBoundingBoxf bb;

std::shared_lock<std::shared_mutex> readLock(m_trianglesMtx.data);

if (m_triangles.empty()) return bb;

bb = mrpt::math::TBoundingBoxf::PlusMinusInfinity();

for (const auto& t : m_triangles)
for (int i = 0; i < 3; i++) bb.updateWithPoint(t.vertices[i].xyzrgba.pt);

return bb;
}
20 changes: 0 additions & 20 deletions libs/opengl/src/CRenderizableShaderTriangles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,3 @@ const math::TBoundingBoxf CRenderizableShaderTriangles::trianglesBoundingBox() c

return bb;
}

void CRenderizableShaderTriangles::params_serialize(mrpt::serialization::CArchive& out) const
{
out.WriteAs<uint8_t>(0); // serialization version
out << m_enableLight << static_cast<uint8_t>(m_cullface);
}
void CRenderizableShaderTriangles::params_deserialize(mrpt::serialization::CArchive& in)
{
const auto version = in.ReadAs<uint8_t>();

switch (version)
{
case 0:
in >> m_enableLight;
m_cullface = static_cast<TCullFace>(in.ReadAs<uint8_t>());
break;
default:
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(version);
};
}
19 changes: 19 additions & 0 deletions libs/viz/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Lists of directories with source files:
# See "DeclareMRPTLib.cmake" for explanations
# -------------------------------------------------

#---------------------------------------------
# Macro declared in "DeclareMRPTLib.cmake":
#---------------------------------------------
define_mrpt_lib(
# Lib name
viz
# Dependencies:
mrpt-poses
mrpt-img
)

if(NOT BUILD_mrpt-viz)
return()
endif()

Loading

0 comments on commit 2d823b6

Please sign in to comment.