Open AzamatB opened 7 years ago
That's right. Though the first 4 bytes store the binary encoding of the resolution of the grid (2^d).
-- misha
On July 9, 2017 4:32:23 PM EDT, AzamatB notifications@github.com wrote:
PoissonRecon --in bunny.points.ply --voxel bunny.voxel.ply --depth 10
My understanding that the line above outputs 3D array (voxel grid), where each element is a value of the implicit function.
-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/mkazhdan/PoissonRecon/issues/28
So is there a way to read in this 3D array from bunny.voxel.ply
?
The following code that uses pcl
library gives error
#include <iostream>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
int main (int argc, char** argv) {
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
if (pcl::io::loadPLYFile<pcl::PointXYZ> ("bunny.voxel.ply", *cloud) == -1) //* load the file
{
PCL_ERROR ("Couldn't read file bunny.voxel.ply \n");
return (-1);
}
std::cout << "Loaded "
<< cloud->width * cloud->height
<< " data points from bunny.voxel.ply"
<< std::endl;
return (0);
}
I'm not sure I follow the question here. Are you trying to read the voxel grid as a ply file? That won't work. It's written in raw binary, so that if r=2^d is the resolution, the file will have size (rrr+1)4 bytes. With the first 4 bytes used to store the binary representation of the integer r and the remaining rrr4 bytes storing the binary representation of rr*r single-precision floating point values of the implicit function.
On July 9, 2017 10:17:41 PM EDT, AzamatB notifications@github.com wrote:
#include <iostream> #include <pcl/io/pcd_io.h> #include <pcl/point_types.h> #include <pcl/features/normal_3d.h> #include <pcl/io/ply_io.h> int main (int argc, char** argv) { pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>); if (pcl::io::loadPLYFile<pcl::PointXYZ> ("bunny.voxel.ply", *cloud) == -1) //* load the file { PCL_ERROR ("Couldn't read file test_pcd.pcd \n"); return (-1); } std::cout << "Loaded " << cloud->width * cloud->height << " data points from test_pcd.pcd with the following fields: " << std::endl; return (0); }
-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/mkazhdan/PoissonRecon/issues/28#issuecomment-313985255
Ok, I'll try to explain.
My goal is to get the 3D binary image of the object, i.e. voxelized representation instead of mesh representation.
To do this I was planning to read 3D tensor of single-precision floating point values of the implicit function that as I understand is stored in the bunny.voxel.ply
file produced by
PoissonRecon --in bunny.points.ply --voxel bunny.voxel.ply --depth 10
and then work with it to get the binary 3D tensor from it.
But I cannot retrieve (i.e. read into the memory) the 3D tensor of the implicit function values from bunny.voxel.ply
.
Assume you just want the 3D array of values, you can read it as:
FILE fp = fopen( "bunny.voxel" , "rb" ); int res; fread( &res , 1 , sizeof(int) , fp ); float voxel = new float[resresres]; fread( voxel , resresres , sizeof(float) , fp ); fclose( fp );
On July 9, 2017 11:50:00 PM EDT, AzamatB notifications@github.com wrote:
Ok, I'll try to explain. My goal is to get the 3D binary image of the object, i.e. voxelized representation instead of meshes. To do this I was planning to read 3D tensor of single-precision floating point values of the implicit function that as I understand is stored in the
bunny.voxel.ply
file produced byPoissonRecon --in bunny.points.ply --voxel bunny.voxel.ply --depth 10
and then work with it to get the binary 3D tensor from it. But I cannot retrieve (i.e. read into the memory) the 3D tensor of the implicit function values frombunny.voxel.ply
.-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/mkazhdan/PoissonRecon/issues/28#issuecomment-313995352
Great! Thank you!
One clarification: in this code voxel
seems to be 1D array.
So say if I want to access element, which in voxel grid (3D tensor), has indicies [x][y][z]
, how would I find this element's index in voxel
?
voxel(x,y,z)=voxel[resresz+res*y+x]
On July 10, 2017 3:43:28 PM EDT, AzamatB notifications@github.com wrote:
Great! Thank you! One clarification: in this code
voxel
seems to be 1D array. So say if I want to access element, which in voxel grid (3D tensor), has indicies [x][y][z]. how can I access it fromvoxel
-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/mkazhdan/PoissonRecon/issues/28#issuecomment-314213493
On a related note, does the volume always extend spatially from (0,0,0) to (1,1,1)? This question is related to https://github.com/mkazhdan/PoissonRecon/issues/21.
Yep.
From: Mike Roberts [mailto:notifications@github.com] Sent: Tuesday, August 22, 2017 1:15 AM To: mkazhdan/PoissonRecon PoissonRecon@noreply.github.com Cc: mkazhdan misha@cs.jhu.edu; Comment comment@noreply.github.com Subject: Re: [mkazhdan/PoissonRecon] Not able to read .ply voxel output. (#28)
On a related note, does the volume always extend spatially from (0,0,0) to (1,1,1)? This question is related to #21 https://github.com/mkazhdan/PoissonRecon/issues/21 .
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mkazhdan/PoissonRecon/issues/28#issuecomment-323921236 , or mute the thread https://github.com/notifications/unsubscribe-auth/AKXc5RIWiq6DWU4vZufrdNOmiGjYwl-oks5samPEgaJpZM4OSLTS . https://github.com/notifications/beacon/AKXc5RSPm6zS6k_wf2G5zsh2HLOkoEqGks5samPEgaJpZM4OSLTS.gif
I write a python code to load this voxel: import numpy as np
def load_voxel_grid(file_name):
with open(file_name, 'rb') as f:
res = np.frombuffer(f.read(4), dtype=np.int32)[0]
print(f"Resolution: {res}")
resolution = res ** 3
voxel_values = np.frombuffer(f.read(resolution * 4), dtype=np.float32)
return res, voxel_values
if __name__ == '__main__':
file_name = 'real_mesh.voxel'
resolution, voxel_values = load_voxel_grid(file_name)
print("Voxel Values:", voxel_values[:10])
but the resolution is very large: Resolution: 822752071 any issue?
I'm afraid I don't understand the question or it's relation to the Poisson Reconstruction code.
On October 13, 2024 6:43:20 AM EDT, Miaowei Wang @.***> wrote:
I write a python code to load this voxel: import numpy as np
def load_voxel_grid(file_name): with open(file_name, 'rb') as f: res = np.frombuffer(f.read(4), dtype=np.int32)[0] print(f"Resolution: {res}") resolution = res ** 3 voxel_values = np.frombuffer(f.read(resolution * 4), dtype=np.float32) return res, voxel_values if __name__ == '__main__': file_name = 'real_mesh.voxel' resolution, voxel_values = load_voxel_grid(file_name) print("Voxel Values:", voxel_values[:10])
but the resolution is very large: Resolution: 822752071 any issue?
-- Reply to this email directly or view it on GitHub: https://github.com/mkazhdan/PoissonRecon/issues/28#issuecomment-2408925827 You are receiving this because you commented.
Message ID: @.***>
Apologies. The grid format was changed a while back and the description in the readme was out of sync. I have modified it so that the description of the contents now matches what is output.
yes, there is an updation.
My understanding is that the line above outputs
bunny.voxel.ply
file that contains 3D array (voxel grid), where each element is a value of the implicit function.I tried reading
bunny.voxel.ply
with pcl library, but getting read error... Even though with the same code I am able to read the mesh filebunny.ply
produced bySo my question is how can I read that 3D array from
bunny.voxel.ply
?