Files
ViewDesignEngine/tests/core/test_topology_compression.cpp
T
茂之钳 4eb4f00c57
Build & Test / build-and-test (push) Has been cancelled
VDE Build & Test / build-and-test (push) Has been cancelled
Build & Test / python-bindings (push) Has been cancelled
test: max coverage — 10 new + 11 expanded test files, 140+ cases
New tests: plane/line/topology_compression/serializer/memory_pool/
  interval/format_utils/sat/ray_intersect/tri_intersect
Expanded: quality_feedback/gdt/validate/interference/motion/
  explode/convex_hull/distance/polygon/transaction/sdf

Total test files: 162 → 172 (+10)
2026-08-02 16:32:36 +08:00

127 lines
4.5 KiB
C++

#include <gtest/gtest.h>
#include "vde/core/topology_compression.h"
#include "vde/brep/modeling.h"
#include "vde/mesh/halfedge_mesh.h"
#include <cmath>
using namespace vde::core;
using namespace vde::brep;
using namespace vde::mesh;
// ═══════════════════════════════════════════════════════════
// B-Rep Topology Compression
// ═══════════════════════════════════════════════════════════
TEST(TopologyCompressionTest, CompressBox) {
auto box = make_box(2, 3, 4);
auto comp = compress_brep(box);
EXPECT_GT(comp.data.size(), 0u);
EXPECT_GT(comp.body_count, 0u);
EXPECT_GT(comp.face_count, 0u);
EXPECT_GT(comp.edge_count, 0u);
EXPECT_GT(comp.vertex_count, 0u);
EXPECT_GT(comp.original_bytes, 0u);
EXPECT_GE(comp.compression_ratio, 0.0);
EXPECT_LE(comp.compression_ratio, 2.0);
}
TEST(TopologyCompressionTest, CompressDecompressRoundtrip) {
auto box = make_box(2, 3, 4);
auto comp = compress_brep(box);
auto restored = decompress_brep(comp);
EXPECT_GT(restored.num_faces(), 0u);
EXPECT_GT(restored.num_edges(), 0u);
}
TEST(TopologyCompressionTest, CompressSphere) {
auto sphere = make_sphere(2.0);
auto comp = compress_brep(sphere);
EXPECT_GT(comp.data.size(), 0u);
EXPECT_GT(comp.face_count, 0u);
}
// ═══════════════════════════════════════════════════════════
// Edgebreaker Compression
// ═══════════════════════════════════════════════════════════
TEST(TopologyCompressionTest, EdgebreakerCompress) {
HalfedgeMesh mesh;
// Create a simple tetrahedron mesh
mesh.add_vertex({0, 0, 0});
mesh.add_vertex({1, 0, 0});
mesh.add_vertex({0, 1, 0});
mesh.add_vertex({0, 0, 1});
mesh.add_face({0, 1, 2});
mesh.add_face({0, 2, 3});
mesh.add_face({0, 3, 1});
mesh.add_face({1, 3, 2});
auto result = edgebreaker_compress(mesh);
EXPECT_GT(result.face_count, 0u);
EXPECT_GT(result.vertex_count, 0u);
EXPECT_GT(result.clers.size(), 0u);
}
TEST(TopologyCompressionTest, EdgebreakerDecompress) {
HalfedgeMesh mesh;
mesh.add_vertex({0, 0, 0});
mesh.add_vertex({1, 0, 0});
mesh.add_vertex({0, 1, 0});
mesh.add_vertex({0, 0, 1});
mesh.add_face({0, 1, 2});
mesh.add_face({0, 2, 3});
mesh.add_face({0, 3, 1});
mesh.add_face({1, 3, 2});
auto result = edgebreaker_compress(mesh);
auto restored = edgebreaker_decompress(result);
EXPECT_GT(restored.num_faces(), 0u);
EXPECT_GT(restored.num_vertices(), 0u);
}
// ═══════════════════════════════════════════════════════════
// Vertex Quantization
// ═══════════════════════════════════════════════════════════
TEST(TopologyCompressionTest, QuantizeVertices_Uniform16) {
std::vector<Point3D> verts = {
{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1},
{10, 10, 10}, {-5, -5, -5}
};
auto result = quantize_vertices(verts, QuantMode::Uniform16);
EXPECT_GT(result.data.size(), 0u);
EXPECT_EQ(result.vertex_count, 6u);
EXPECT_GE(result.max_error, 0.0);
EXPECT_GE(result.avg_error, 0.0);
}
TEST(TopologyCompressionTest, QuantizeDequantizeRoundtrip) {
std::vector<Point3D> verts = {
{0, 0, 0}, {1, 0, 0}, {0.5, 0.5, 0}
};
auto result = quantize_vertices(verts, QuantMode::Uniform32);
auto restored = dequantize_vertices(result);
EXPECT_EQ(restored.size(), 3u);
EXPECT_NEAR(restored[0].x(), 0.0, 1e-5);
EXPECT_NEAR(restored[1].x(), 1.0, 1e-5);
EXPECT_NEAR(restored[2].y(), 0.5, 1e-5);
}
TEST(TopologyCompressionTest, QuantizeModes) {
std::vector<Point3D> verts = {{0, 0, 0}, {1, 1, 1}};
auto r8 = quantize_vertices(verts, QuantMode::Uniform8);
auto r16 = quantize_vertices(verts, QuantMode::Uniform16);
auto r32 = quantize_vertices(verts, QuantMode::Uniform32);
EXPECT_GT(r16.data.size(), r8.data.size());
EXPECT_GT(r32.data.size(), r16.data.size());
}