danielepanozzo / gp-old

67 stars 13 forks source link

How to store a scalar function of a mesh as an image? #38

Open majia67 opened 6 years ago

majia67 commented 6 years ago

I'm doing the remeshing project, and in this project it requires to store the "control map" as a 2D image and applying error diffusion technique to do the resampling. After that, it requires to read the result image and recover it as a point cloud. I'm wondering is there a corresponding function in libigl or its external libraries?

jiangzhongshi commented 6 years ago

Please correct me if I am wrong. I don't think you actually need a rasterized image (with fixed pixels etc.), instead, you are sampling in a square region, without the need of pixel-level information, then project them back to the surface.

Just FYI, interacting with images can be done through this tutorial http://libigl.github.io/libigl/tutorial/tutorial.html#screencapture

majia67 commented 6 years ago

The paper does the rasterization and use error diffusion to do the re-sampling. Are you suggesting that I could complete this step without using error diffusion? In that case, is there efficient sampling technique for a scalar function defined on a mesh?

jiangzhongshi commented 6 years ago

Sorry I wasn't reading it carefully. In this case, I am not aware of cpu-side rasterization functions in libigl, probably you can implement it. Or you can also consider grabbing the opengl buffer.

majia67 commented 6 years ago

@jiangzhongshi Thank you for your suggestion, but I'm not sure if these could be done in less than two weeks... If there any alternative sampling techniques (preferably can work on the mesh directly)? Basically I just want a sampling algorithm that could distribute the vertices according to the control map (a scalar function defined on the mesh).

jiangzhongshi commented 6 years ago

I see it in the paper, they were using OpenGL. This involves calling the API glReadPixels, I don't have a specific example at hand. Alternatively, you can implement pixel-by-pixel, it is slower, but easy to implement.

danielepanozzo commented 6 years ago

Hi,

you can use libigl for doing the rasterization, take a look at: http://libigl.github.io/libigl/tutorial/607_ScreenCapture/main.cpp . '1' saves the image to a memory buffer, i.e. it rasterizes a triangle mesh into an array of pixels, which is exactly what you need.

For the half-toning, it is not in libigl: you will have to implement that part.

majia67 commented 6 years ago

Thank you for your suggestions!

majia67 commented 6 years ago

@danielepanozzo Hi professor, I tried to use the example you mentioned, and I want to save the buffer into a png file. My program can be built successfully but won't run. It shows the following error message:

The code execution cannot proceed because igl_stb_image.dll was not found. Reinstalling the program may fix this problem.

I did enabled using PNG module in my CMakeLists.txt and add igl::png in target_link_libraries. Is this a bug in libigl or I didn't do the right configuration?

jiangzhongshi commented 6 years ago

Does the tutorial work with a vanilla libigl build? If it doesn't, then it's likely to be a bug in libigl's CMake configurations.

majia67 commented 6 years ago

@jiangzhongshi Same error. It is likely to be a libigl bug now. I will report it in libigl repository.

jiangzhongshi commented 6 years ago

As a temporary workaround, if you are playing around with matrices RGB, you don't need to export it. If you do, maybe you can use this https://github.com/danielepanozzo/cg/blob/master/Assignment_1/src/stb_image_write.h

majia67 commented 6 years ago

Thank you for your suggestion! A fix is also given in https://github.com/libigl/libigl/issues/758