Skip to content

Commit

Permalink
tweak marching cube code, eliminate some stdouts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Qi Wu committed Aug 16, 2023
1 parent f147784 commit 81584a2
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions core/marching_cube.cu
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ void doComputeVertices(
}

template<typename VolumeInfo>
void doMarchingCubeTemplate(const VolumeInfo& volume_info, CUDABufferTyped<vec3f>& vertices)
double doMarchingCubeTemplate(const VolumeInfo& volume_info, CUDABufferTyped<vec3f>& vertices)
{
vidi::details::HighPerformanceTimer timer;

Expand Down Expand Up @@ -422,12 +422,12 @@ void doMarchingCubeTemplate(const VolumeInfo& volume_info, CUDABufferTyped<vec3f
// Statistics
timer.stop();
const auto totaltime = timer.milliseconds();
std::cout << "Marching Cube Time = "<< totaltime / 1000.0 << "s"<< std::endl;
return totaltime / 1000.0;
}

/* network version */
template<int N_FEATURES_PER_LEVEL>
void doMarchingCubeTemplate__Network(const NeuralVolume& network, vec3i dims, float iso, CUDABufferTyped<vec3f>& vertices)
double doMarchingCubeTemplate__Network(const NeuralVolume& network, vec3i dims, float iso, CUDABufferTyped<vec3f>& vertices)
{
int WIDTH = network.get_network_width();
if (WIDTH == -1) {
Expand Down Expand Up @@ -458,6 +458,8 @@ void vnrMarchingCube(vnrVolume v, float iso, vnr::vec3f** ptr, size_t* size, boo
{
CUDABufferTyped<vec3f> vertices;

double et = 0.0;

if (v->isNetwork()) {
const auto ctx = std::dynamic_pointer_cast<NeuralVolumeContext>(v);
const vec3i dims = ctx->dims;
Expand All @@ -470,17 +472,16 @@ void vnrMarchingCube(vnrVolume v, float iso, vnr::vec3f** ptr, size_t* size, boo
throw std::runtime_error("Incorrect encoding method for in-shader rendering");
}

if (N_FEATURES_PER_LEVEL == 1) doMarchingCubeTemplate__Network<1>(network, dims, iso, vertices);
else if (N_FEATURES_PER_LEVEL == 2) doMarchingCubeTemplate__Network<2>(network, dims, iso, vertices);
else if (N_FEATURES_PER_LEVEL == 4) doMarchingCubeTemplate__Network<4>(network, dims, iso, vertices);
else if (N_FEATURES_PER_LEVEL == 8) doMarchingCubeTemplate__Network<8>(network, dims, iso, vertices);
if (N_FEATURES_PER_LEVEL == 1) et = doMarchingCubeTemplate__Network<1>(network, dims, iso, vertices);
else if (N_FEATURES_PER_LEVEL == 2) et = doMarchingCubeTemplate__Network<2>(network, dims, iso, vertices);
else if (N_FEATURES_PER_LEVEL == 4) et = doMarchingCubeTemplate__Network<4>(network, dims, iso, vertices);
else if (N_FEATURES_PER_LEVEL == 8) et = doMarchingCubeTemplate__Network<8>(network, dims, iso, vertices);
else throw std::runtime_error("expecting a simple volume");
}

else {
const auto ctx = std::dynamic_pointer_cast<SimpleVolumeContext>(v);
const vec3i dims = ctx->dims;
// printf("type = %d, dims = %d, %d, %d\n", (int)ctx->desc.type, dims.x, dims.y, dims.z);

CUDABufferTyped<float> volume_data;
{
Expand All @@ -491,14 +492,20 @@ void vnrMarchingCube(vnrVolume v, float iso, vnr::vec3f** ptr, size_t* size, boo

VolumeDesc<void> volume_info(iso, dims, volume_data.d_pointer());

doMarchingCubeTemplate(volume_info, vertices);
et = doMarchingCubeTemplate(volume_info, vertices);
}

// std::cout << "Marching Cube Time = "<< et << "s"<< std::endl;

*size = vertices.size();
if (vertices.size() == 0) {
std::cerr << "Warning: no vertices generated" << std::endl;
return;
}
// else {
// std::cout << "Generated " << vertices.size() << " vertices" << std::endl;
// }

*size = vertices.size();
if (!cuda) {
*ptr = new vec3f[*size];
vertices.download(*ptr, *size);
Expand Down

0 comments on commit 81584a2

Please sign in to comment.