Spaces:
Running
on
Zero
Running
on
Zero
namespace py = pybind11; | |
using namespace pybind11::literals; // to bring in the `_a` literal | |
torch::Tensor py_triangulate(const torch::Tensor &points) { | |
TORCH_CHECK(points.dim() == 2 && points.size(1) == 3, "points must have shape [num_points, 3]"); | |
const auto points_ = points.cpu().contiguous(); | |
std::vector<uint4> cells = triangulate( | |
points_.size(0), | |
reinterpret_cast<float3 *>(points_.data_ptr())); | |
if (cells.size() >= (size_t)std::numeric_limits<int>::max) { | |
throw Exception("Too many points!"); | |
} | |
auto cells_out = torch::empty({(long)cells.size(), 4}, torch::dtype(torch::kInt32).device(torch::kCPU)); | |
memcpy( | |
cells_out.data_ptr(), | |
reinterpret_cast<void *>(cells.data()), | |
cells.size() * sizeof(uint4)); | |
return cells_out.to(points.device()); | |
}; | |
PYBIND11_MODULE(tetranerf_cpp_extension, m) { | |
m.def("triangulate", &py_triangulate); | |
} |