Skip to content

Commit

Permalink
Merge branch 'main' into render-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
malomo committed Jan 27, 2025
2 parents 8dac4dd + 7c1415f commit c402003
Show file tree
Hide file tree
Showing 26 changed files with 1,163 additions and 468 deletions.
33 changes: 33 additions & 0 deletions assets/example_meshes/cube_textured.ply
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
ply
format ascii 1.0
comment TextureFile TextureDouble_A.png
comment TextureFile TextureDouble_B.png
element vertex 8
property float x
property float y
property float z
element face 12
property list uchar int vertex_indices
property list uchar float texcoord
property int texnumber
end_header
0 0 0
1 0 0
0 1 0
1 1 0
0 0 1
1 0 1
0 1 1
1 1 1
3 2 1 0 6 0.5 1 0 0.5 0.5 0.5 1
3 1 2 3 6 0 0.5 0.5 1 0 1 1
3 4 2 0 6 0.5 0 1 0.5 0.5 0.5 1
3 2 4 6 6 1 0.5 0.5 0 1 0 1
3 1 4 0 6 0 0.5 0.5 0 0.5 0.5 1
3 4 1 5 6 0.5 0 0 0.5 0 0 1
3 6 5 7 6 0 0.5 0.5 0 0.5 0.5 0
3 5 6 4 6 0.5 0 0 0.5 0 0 0
3 3 6 7 6 0.5 1 0 0.5 0.5 0.5 0
3 6 3 2 6 0 0.5 0.5 1 0 1 0
3 5 3 7 6 0.5 0 1 0.5 0.5 0.5 0
3 3 5 1 6 1 0.5 0.5 0 1 0 0
2 changes: 1 addition & 1 deletion examples/render/common/default_viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ auto defaultViewer()
#ifdef VCLIB_RENDER_EXAMPLES_WITH_QT
return vcl::qt::MeshViewer();
#elif VCLIB_RENDER_EXAMPLES_WITH_GLFW
return vcl::glfw::ViewerWindow ;
return vcl::glfw::ViewerWindow;
#endif
}

Expand Down
27 changes: 27 additions & 0 deletions tests/core/002-mesh-topology/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,3 +746,30 @@ TEMPLATE_TEST_CASE(
REQUIRE(pm.face(5).adjFace(3) == &pm.face(3));
}
}

TEMPLATE_TEST_CASE(
"Wedge Driven Vertex Duplication",
"",
vcl::TriMesh,
vcl::TriMeshf,
vcl::TriMeshIndexed,
vcl::TriMeshIndexedf)
{
using TriMesh = TestType;

TriMesh tm1 =
vcl::loadPly<TriMesh>(VCLIB_EXAMPLE_MESHES_PATH "/TextureDouble.ply");

THEN("Test the number of vertices to duplicate")
{
REQUIRE(vcl::countVerticesToDuplicateByWedgeTexCoords(tm1) == 0);
}

TriMesh tm2 =
vcl::loadPly<TriMesh>(VCLIB_EXAMPLE_MESHES_PATH "/cube_textured.ply");

THEN("Test the number of vertices to duplicate")
{
REQUIRE(vcl::countVerticesToDuplicateByWedgeTexCoords(tm2) == 8);
}
}
1 change: 1 addition & 0 deletions vclib/core/include/vclib/algorithms/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "core/bounding_box.h"
#include "core/box.h"
#include "core/create.h"
#include "core/distance.h"
#include "core/fitting.h"
#include "core/intersection.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,76 +20,68 @@
* (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
****************************************************************************/

#include <vclib/render/drawable/trackball/trackball_render_data.h>
#ifndef VCL_ALGORITHMS_CORE_CREATE_H
#define VCL_ALGORITHMS_CORE_CREATE_H

#include <vclib/algorithms/core/polygon/create.h>
#include <vclib/math/transform.h>
#include "polygon/create.h"

namespace vcl {

TrackballRenderData::TrackballRenderData(uint pointsPerCircle)
/**
* @brief Returns a pair of vectors containing the vertices and edges of a 3D
* Trackball, composed of three circles in the x, y, and z planes.
*
* @tparam ScalarType: the type of scalar used for the 3D vertices.
* @tparam UintType: the type of integer used for the edge indices.
*
* @param[in] scale: the scale of the trackball.
* @param[in] pointsPerCircle: the number of points per circle.
* @return a pair of vectors containing the vertices and edges of the trackball.
*/
template<typename ScalarType = float, std::integral UintType = uint16_t>
std::pair<std::vector<vcl::Point3<ScalarType>>, std::vector<UintType>>
createTrackBall(ScalarType scale = 1.0, uint pointsPerCircle = 64)
{
vcl::Polygon2f circle =
vcl::createCircle<vcl::Polygon2f>(pointsPerCircle, 1.0f);
using PointType = vcl::Point3<ScalarType>;

mVertices.reserve(pointsPerCircle * 3);
std::vector<PointType> vertices;
std::vector<UintType> edges;

vcl::Polygon2<ScalarType> circle =
vcl::createCircle<vcl::Polygon2<ScalarType>>(pointsPerCircle, 1.0);

vertices.reserve(pointsPerCircle * 3);

// x
uint first = 0;
for (uint i = 0; i < circle.size(); ++i) {
const auto& p = circle.point(i);
mVertices.push_back(vcl::Point3f(0, p.x(), p.y()));
mEdges.push_back(i + first);
mEdges.push_back((i + 1) % circle.size() + first);
vertices.push_back(PointType(0, p.x(), p.y()));
edges.push_back(i + first);
edges.push_back((i + 1) % circle.size() + first);
}

// y
first = circle.size();
for (uint i = 0; i < circle.size(); ++i) {
const auto& p = circle.point(i);
mVertices.push_back(vcl::Point3f(p.x(), 0, p.y()));
mEdges.push_back(i + first);
mEdges.push_back((i + 1) % circle.size() + first);
vertices.push_back(PointType(p.x(), 0, p.y()));
edges.push_back(i + first);
edges.push_back((i + 1) % circle.size() + first);
}

// z
first = 2 * circle.size();
for (uint i = 0; i < circle.size(); ++i) {
const auto& p = circle.point(i);
mVertices.push_back(vcl::Point3f(p.x(), p.y(), 0));
mEdges.push_back(i + first);
mEdges.push_back((i + 1) % circle.size() + first);
vertices.push_back(PointType(p.x(), p.y(), 0));
edges.push_back(i + first);
edges.push_back((i + 1) % circle.size() + first);
}
}

uint TrackballRenderData::vertexNumber() const
{
return mVertices.size();
}

uint TrackballRenderData::edgeNumber() const
{
return mEdges.size();
}

const float* TrackballRenderData::vertexBufferData() const
{
return mVertices.front().data();
}

const uint16_t* TrackballRenderData::edgeBufferData() const
{
return mEdges.data();
}

const float* TrackballRenderData::transformData() const
{
return mTransform.data();
}

void TrackballRenderData::setTransform(const Matrix44f& mtx)
{
mTransform = mtx;
return std::make_pair(std::move(vertices), std::move(edges));
}

} // namespace vcl

#endif // VCL_ALGORITHMS_CORE_CREATE_H
1 change: 1 addition & 0 deletions vclib/core/include/vclib/algorithms/mesh/create.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#ifndef VCL_ALGORITHMS_MESH_CREATE_H
#define VCL_ALGORITHMS_MESH_CREATE_H

#include "create/axis.h"
#include "create/cone.h"
#include "create/dodecahedron.h"
#include "create/hexahedron.h"
Expand Down
127 changes: 127 additions & 0 deletions vclib/core/include/vclib/algorithms/mesh/create/axis.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*****************************************************************************
* VCLib *
* Visual Computing Library *
* *
* Copyright(C) 2021-2025 *
* Visual Computing Lab *
* ISTI - Italian National Research Council *
* *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the Mozilla Public License Version 2.0 as published *
* by the Mozilla Foundation; either version 2 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 *
* Mozilla Public License Version 2.0 *
* (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
****************************************************************************/

#ifndef VCL_ALGORITHMS_MESH_CREATE_AXIS_H
#define VCL_ALGORITHMS_MESH_CREATE_AXIS_H

#include "cone.h"
#include "sphere.h"

namespace vcl {

namespace detail {

template<FaceMeshConcept MeshType>
MeshType createAxisCylinder(double unitLength, bool fromOrigin = false)
{
const double cylLength = fromOrigin ? unitLength : unitLength * 2;
const double cylRadius = cylLength * 0.0025;

const double coneRadius = cylRadius * 10;
const double coneLength = cylLength * 0.1;

const double firstSphereRadius = unitLength * 0.02;
const double commonSphereRadius = unitLength * 0.008;

MeshType cylinder = vcl::createCylinder<MeshType>(cylRadius, cylLength);

if (fromOrigin) {
vcl::translate(cylinder, vcl::Point3d(0, unitLength * 0.5, 0));
}

vcl::updatePerVertexNormals(cylinder);

return cylinder;
}

template<FaceMeshConcept MeshType>
MeshType createAxisConeSpheres(double unitLength, bool fromOrigin = false)
{
const double cylLength = fromOrigin ? unitLength : unitLength * 2;
const double cylRadius = cylLength * 0.0025;

const double coneRadius = cylRadius * 10;
const double coneLength = cylLength * 0.1;

const double firstSphereRadius = unitLength * 0.02;
const double commonSphereRadius = unitLength * 0.008;

MeshType coneSpheres = vcl::createCone<MeshType>(coneRadius, 0, coneLength);
double transl = unitLength + (coneLength * 0.5);
vcl::translate(coneSpheres, vcl::Point3d(0, transl, 0));

if (!fromOrigin) {
vcl::Sphered s(vcl::Point3d(0, -1, 0), firstSphereRadius);
MeshType sp = vcl::createSphere<MeshType>(s);
coneSpheres.append(sp);
}

for (uint i = 0; i < 9; ++i) {
const double step = unitLength * 0.1;
const double x = step + i * step;
vcl::Sphered s(vcl::Point3d(0, x, 0), commonSphereRadius);
MeshType sp = vcl::createSphere<MeshType>(s);
coneSpheres.append(sp);
if (!fromOrigin) {
s.center().y() = -x;
sp = vcl::createSphere<MeshType>(s);
coneSpheres.append(sp);
}
}

const double rad = fromOrigin ? firstSphereRadius : commonSphereRadius;
vcl::Sphered s = vcl::Sphered(vcl::Point3d(0, 0, 0), rad);
MeshType sp = vcl::createSphere<MeshType>(s);
coneSpheres.append(sp);

vcl::updatePerVertexNormals(coneSpheres);

return coneSpheres;
}

} // namespace detail

template<FaceMeshConcept MeshType>
std::pair<MeshType, MeshType> createAxisDisjoint(
double unitLength = 1,
bool fromOrigin = false)
{
return std::make_pair(
detail::createAxisCylinder<MeshType>(unitLength, fromOrigin),
detail::createAxisConeSpheres<MeshType>(unitLength, fromOrigin));
}

template<FaceMeshConcept MeshType>
MeshType createAxis(double unitLength = 1, bool fromOrigin = false)
{
MeshType axis =
detail::createAxisCylinder<MeshType>(unitLength, fromOrigin);

axis.append(
detail::createAxisConeSpheres<MeshType>(unitLength, fromOrigin));

return axis;
}

} // namespace vcl

#endif // VCL_ALGORITHMS_MESH_CREATE_AXIS_H
Loading

0 comments on commit c402003

Please sign in to comment.