Implementation:CARLA simulator Carla MarchingCube
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Geometry, Mesh Generation |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
Cube.h defines the Cube class and supporting data structures for the Marching Cubes algorithm, responsible for evaluating signed distance function values at cube vertices and computing surface intersection points.
Description
This file (~180 lines) within the MeshReconstruction namespace provides:
- IntersectInfo struct: stores the sign configuration (0-255) and edge-vertex intersection positions for a single cube
- Cube class: represents a single cube in the marching cubes grid, holding 8 vertex positions and their SDF values
- Edge struct and signConfigToIntersectedEdges lookup table: maps the 256 sign configurations to a 12-bit bitstring indicating which of the cube's 12 edges are intersected by the isosurface
- LerpVertex: linearly interpolates vertex positions along intersected edges
- SignConfig: computes the 8-bit sign configuration from SDF values at cube vertices
Usage
This is an internal component of the Marching Cubes mesh reconstruction pipeline. It is used by MeshReconstruction.h to create cubes from spatial regions, compute intersections, and then pass results to the Triangulation step.
Code Reference
Source Location
- Repository: CARLA
- File:
LibCarla/source/third-party/marchingcube/Cube.h
Signature
namespace MeshReconstruction
{
struct IntersectInfo {
int signConfig; // 0 - 255
std::array<Vec3, 12> edgeVertIndices; // vertex on each edge
};
class Cube {
Vec3 pos[8];
double sdf[8];
Vec3 LerpVertex(double isoLevel, int i1, int i2) const;
int SignConfig(double isoLevel) const;
public:
Cube(Rect3 const &space, Fun3s const &sdf);
IntersectInfo Intersect(double isoLevel = 0) const;
};
}
Import
#include "third-party/marchingcube/Cube.h"
I/O Contract
| Method | Input | Output | Description |
|---|---|---|---|
Cube(space, sdf) |
Rect3 bounding box, SDF function | Cube instance | Constructs a cube by sampling the SDF at 8 corners |
Intersect(isoLevel) |
Iso-level value (default 0) | IntersectInfo |
Computes sign configuration and intersection vertices |
Usage Examples
#include "third-party/marchingcube/Cube.h"
MeshReconstruction::Rect3 space{{0, 0, 0}, {1, 1, 1}};
auto sdf = [](MeshReconstruction::Vec3 const &p) {
return p.x * p.x + p.y * p.y + p.z * p.z - 1.0; // sphere
};
MeshReconstruction::Cube cube(space, sdf);
auto intersect = cube.Intersect(0.0);
// intersect.signConfig indicates which edges are crossed
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment