Skip to content
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
Binary file removed .github/cppIGL-setting.png
Binary file not shown.
411 changes: 301 additions & 110 deletions .github/workflows/build-release.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ GeoSharPlusCPP/build
bin
_release/releaseRH8
cppPrebuild
igm/obj
14 changes: 10 additions & 4 deletions GeoSharPlusCPP/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
cmake_minimum_required(VERSION 3.15)

cmake_minimum_required(VERSION 3.31)

set(PROJECT_NAME GeoSharPlusCPP)

# Set the Visual Studio toolset to the latest version
if(MSVC)
set(CMAKE_GENERATOR_TOOLSET "v145" CACHE STRING "Visual Studio toolset version" FORCE)
message(STATUS "Using Visual Studio 2026 (Insider) toolset: ${CMAKE_GENERATOR_TOOLSET}")
endif()

# Check for VCPKG_ROOT environment variable
if(DEFINED ENV{VCPKG_ROOT})
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
Expand All @@ -28,13 +33,14 @@ endif()
# Set C++ standard
project(${PROJECT_NAME} LANGUAGES C CXX)

# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
# Set C++ standard to C++20
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "C++ compiler: ${CMAKE_CXX_COMPILER}")
message(STATUS "C++ standard: C++${CMAKE_CXX_STANDARD}")
message(STATUS "Generator: ${CMAKE_GENERATOR}")

# Find dependencies
Expand Down
25 changes: 15 additions & 10 deletions GeoSharPlusCPP/include/GeoSharPlusCPP/Core/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
namespace GeoSharPlusCPP {
struct Polyline {
MatrixX3d vertices;
double length() const;
[[nodiscard]] double length() const;
};

struct Mesh {
Mesh() = default;

// Constructor to initialize mesh with vertices and faces
Mesh(const MatrixX3d& vertices, const Eigen::MatrixXi& faces)
: V(vertices), F(faces) {}
Mesh(const MatrixX3d& vertices, const Eigen::MatrixXi& faces) : V(vertices), F(faces) {}

// Mesh data: V - vertices, F - faces (triangles or quads)
// F is now dynamic width: 3 columns for triangles, 4 columns for quads
Expand All @@ -25,12 +24,18 @@ struct Mesh {
Eigen::VectorXd C;

// Helper methods to identify mesh type
bool isTriangleMesh() const { return F.cols() == 3; }
bool isQuadMesh() const { return F.cols() == 4; }
int faceVertexCount() const { return F.cols(); }

bool validate() const;
Eigen::Vector3d centroid() const;
std::pair<Vector3d, Vector3d> boundingBox() const;
[[nodiscard]] constexpr bool isTriangleMesh() const noexcept {
return F.cols() == 3;
}
[[nodiscard]] constexpr bool isQuadMesh() const noexcept {
return F.cols() == 4;
}
[[nodiscard]] constexpr int faceVertexCount() const noexcept {
return static_cast<int>(F.cols());
}

[[nodiscard]] bool validate() const;
[[nodiscard]] Eigen::Vector3d centroid() const;
[[nodiscard]] std::pair<Vector3d, Vector3d> boundingBox() const;
};
} // namespace GeoSharPlusCPP
14 changes: 14 additions & 0 deletions GeoSharPlusCPP/include/GeoSharPlusCPP/Core/MathTypes.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#pragma once
#include <span>

#include <Eigen/Core>
#include <Eigen/Geometry>

Expand All @@ -17,6 +19,10 @@ using MatrixX4i = Eigen::Matrix<int, Eigen::Dynamic, 4, Eigen::RowMajor>; // Fo
using MatrixXi = Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
using MatrixXd = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;

// C++20 span types for safer buffer handling
using ByteSpan = std::span<const uint8_t>;
using MutableByteSpan = std::span<uint8_t>;

// Geometry primitives
struct Point {
Vector3d position;
Expand All @@ -25,5 +31,13 @@ struct Point {
struct LineSegment {
Vector3d start;
Vector3d end;

[[nodiscard]] double length() const noexcept {
return (end - start).norm();
}

[[nodiscard]] Vector3d midpoint() const noexcept {
return (start + end) * 0.5;
}
};
} // namespace GeoSharPlusCPP
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ bool serializeNumberArray(const NumberContainer& numbers, uint8_t*& resBuffer, i

template <typename NumberContainer>
bool deserializeNumberArray(const uint8_t* data, int size, NumberContainer& numberArray);

// Index array (pairs of integers) serialization/deserialization
template <typename IndexContainer>
bool serializeNumberPairArray(const IndexContainer& indices, uint8_t*& resBuffer, int& resSize);
Expand Down
46 changes: 44 additions & 2 deletions GeoSharPlusCPP/src/API/BridgeAPI.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "GeoSharPlusCPP/API/BridgeAPI.h"

#include <algorithm>
#include <iostream>
#include <memory>
#include <ranges>
#include <unordered_map>

#define _USE_MATH_DEFINES
Expand Down Expand Up @@ -48,12 +50,12 @@ namespace GS = GeoSharPlusCPP::Serialization;
// Helper functions for mesh type handling
namespace {
// Check if mesh requires triangulation for triangle-only functions
bool requiresTriangulation(const GeoSharPlusCPP::Mesh& mesh) {
[[nodiscard]] constexpr bool requiresTriangulation(const GeoSharPlusCPP::Mesh& mesh) noexcept {
return mesh.F.cols() == 4; // Quad mesh needs triangulation
}

// Triangulate a quad mesh by splitting each quad into 2 triangles
GeoSharPlusCPP::Mesh triangulate(const GeoSharPlusCPP::Mesh& mesh) {
[[nodiscard]] GeoSharPlusCPP::Mesh triangulate(const GeoSharPlusCPP::Mesh& mesh) {
if (mesh.F.cols() == 3) {
return mesh; // Already triangulated
}
Expand All @@ -77,6 +79,46 @@ GeoSharPlusCPP::Mesh triangulate(const GeoSharPlusCPP::Mesh& mesh) {

return triMesh;
}

// C++20: Custom deleter for buffer cleanup
struct BufferDeleter {
void operator()(uint8_t* ptr) const noexcept {
if (ptr) {
delete[] ptr;
}
}
};

// C++20: RAII wrapper for output buffers
class OutputBuffer {
public:
OutputBuffer() = default;

[[nodiscard]] uint8_t** data() noexcept {
return &buffer_;
}
[[nodiscard]] int* size() noexcept {
return &size_;
}

void release(uint8_t** outBuffer, int* outSize) noexcept {
*outBuffer = buffer_;
*outSize = size_;
buffer_ = nullptr;
size_ = 0;
}

~OutputBuffer() {
if (buffer_) {
delete[] buffer_;
}
}

private:
uint8_t* buffer_ = nullptr;
int size_ = 0;
};

} // namespace

extern "C" {
Expand Down
6 changes: 5 additions & 1 deletion GeoSharPlusNET/GeoSharPlusNET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand All @@ -18,4 +18,8 @@
</Compile>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GeoSharPlusCPP\build\GeoSharPlusCPP.vcxproj" />
</ItemGroup>

</Project>
Loading
Loading