Skip to content
Open
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
9 changes: 9 additions & 0 deletions src/marching_cubes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,15 @@ Mesh::Mesh(size_t vertexCount, Point* vertices, Point* normals, size_t faceCount
Mesh::Mesh()
{}

Mesh::~Mesh()
{
if (!vertices)
delete[] vertices;
if (!normals)
delete[] normals;
if (!faces)
delete[] faces;
}

template <class T>
Mesh march(const T* volume, size_t xDim, size_t yDim, size_t zDim, T isoLevel)
Expand Down
3 changes: 2 additions & 1 deletion src/marching_cubes.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct Mesh

Mesh(size_t, Point*, Point*, size_t, size_t*);
Mesh();
~Mesh();
};

/**
Expand All @@ -48,4 +49,4 @@ struct Mesh
*/
template<typename T>
Mesh march(const T* volume, size_t xDim, size_t yDim, size_t zDim, T isoLevel);
#endif
#endif
48 changes: 36 additions & 12 deletions src/python_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,42 @@ namespace marching_cubes
throw py::value_error("vertex or face count are zero: terminating marching cubes");
}

std::string vert_format = py::format_descriptor<float>::value;
auto vert_info = py::buffer_info(mesh.vertices, sizeof(float), vert_format, 2, { vc, 3 }, { sizeof(float) * 3, sizeof(float) });
auto vert_array = py::array(vert_info);

std::string norm_format = py::format_descriptor<float>::value;
auto norm_info = py::buffer_info(mesh.normals, sizeof(float), norm_format, 2, { vc, 3 }, { sizeof(float) * 3, sizeof(float) });
auto norm_array = py::array(norm_info);

std::string face_format = py::format_descriptor<unsigned int>::value;
auto face_info = py::buffer_info(mesh.faces, sizeof(size_t), face_format, 2, { fc, 3 }, { sizeof(size_t) * 3, sizeof(size_t) });
auto face_array = py::array(face_info);

//std::string vert_format = py::format_descriptor<float>::value;
//auto vert_info = py::buffer_info(mesh.vertices, sizeof(float), vert_format, 2, { vc, 3 }, { sizeof(float) * 3, sizeof(float) });
//auto vert_array = py::array(vert_info);

//std::string norm_format = py::format_descriptor<float>::value;
//auto norm_info = py::buffer_info(mesh.normals, sizeof(float), norm_format, 2, { vc, 3 }, { sizeof(float) * 3, sizeof(float) });
//auto norm_array = py::array(norm_info);

//std::string face_format = py::format_descriptor<unsigned int>::value;
//auto face_info = py::buffer_info(mesh.faces, sizeof(size_t), face_format, 2, { fc, 3 }, { sizeof(size_t) * 3, sizeof(size_t) });
//auto face_array = py::array(face_info);

py::capsule free_vertices_when_done(mesh.vertices, [](void *f) {
float* foo = reinterpret_cast<float *>(f);
delete[] foo;
});
py::capsule free_normals_when_done(mesh.normals, [](void *f) {
float* foo = reinterpret_cast<float *>(f);
delete[] foo;
});
py::capsule free_faces_when_done(mesh.faces, [](void *f) {
size_t* foo = reinterpret_cast<size_t *>(f);
delete[] foo;
});
auto vert_array = py::array_t<float>({vc,3},
{sizeof(float)*3,sizeof(float)},
(float*)mesh.vertices,
free_vertices_when_done);
auto norm_array = py::array_t<float>({vc,3},
{sizeof(float)*3,sizeof(float)},
(float*)mesh.normals,
free_normals_when_done);
auto face_array = py::array_t<size_t>({fc,3},
{sizeof(size_t)*3,sizeof(size_t)},
(size_t*)mesh.faces,
free_faces_when_done);
return std::make_tuple(vert_array, norm_array, face_array);

}
Expand Down