Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the intuition behind Voxelizer #32

Open
charlotte12l opened this issue Dec 7, 2020 · 12 comments
Open

the intuition behind Voxelizer #32

charlotte12l opened this issue Dec 7, 2020 · 12 comments

Comments

@charlotte12l
Copy link

Thanks for your package! I find Voxelizer is really helpful, but I can't quite understand the algorithm ... Is there any reference for this method? Thanks!

@archibate
Copy link
Collaborator

Glad it's useful to you! Here's how it work:
Step 1: use B-spline (the same as mpm88 used) to spread particles to 3x3x3 neighbours of the 3D grid.
Step 2: Gaussian blur the 3D grid alone X-axis for radius.
Step 3: Gaussian blur the 3D grid alone Y-axis for radius.
Step 4: Gaussian blur the 3D grid alone Z-axis for radius.
The total effect of step 2+3+4 will spread the 3D grid values further to RxRxR rather than just 3x3x3.
We use three step for XYZ axis separately so that we only need to sample 3*R, otherwise we will sample over an area of R*R*R.

@charlotte12l
Copy link
Author

Thanks for your explanation! I'll cite your package in my course project lol

I'm also curious about the marching cube algorithm. I read some blogs about the marching cube algorithm, and it is originally designed for implicit functions, the vertex is either positive or negative so we can generate mesh based on cube vertex values.
However, I'm wondering in your implementation, do you still check the vertice is positive or negative, or you check it is zero or non-zero? I think because it is voxelizing from particle positions, the vertices will never be negative?

(Sorry for so many questions, I did read your code carefully but I didn't quite understand it because I'm a new beginner .. )

@archibate
Copy link
Collaborator

it is originally designed for implicit functions

By implicit functions you mean f(x, y, z), right?
Then my f(x, y, z) = V[x, y, z], where V is the voxel data.

check the vertice is positive or negative

Their implementation checks f > 0 or f <= 0, my implementation checks f > 1 or f <= 1.

@dodydharma
Copy link

dodydharma commented Dec 17, 2020

Hi @archibate , I tried tp run mciso_mpm3d.py , but i got errors, would u mind helping?

Traceback (most recent call last):
File "mciso_mpm3d.py", line 129, in <module> voxel.voxelize(mciso.m, x) File "/usr/local/lib/python3.6/dist-packages/taichi/lang/kernel.py", line 603, in __call__ return self._primal(self._kernel_owner, *args, **kwargs) File "/usr/local/lib/python3.6/dist-packages/taichi/lang/kernel.py", line 499, in __call__ self.materialize(key=key, args=args, arg_features=arg_features) File "/usr/local/lib/python3.6/dist-packages/taichi/lang/kernel.py", line 368, in materialize taichi_kernel = taichi_kernel.define(taichi_ast_generator) File "/usr/local/lib/python3.6/dist-packages/taichi/lang/kernel.py", line 365, in taichi_ast_generator compiled() File "/usr/local/lib/python3.6/dist-packages/taichi_three/mciso.py", line 251, in voxelize p = (pos[i] - self.pmin) / (self.pmax - self.pmin) File "/usr/local/lib/python3.6/dist-packages/taichi/lang/common_ops.py", line 25, in __sub__ return ti.sub(self, other) File "/usr/local/lib/python3.6/dist-packages/taichi/lang/ops.py", line 74, in wrapped return a.element_wise_binary(imp_foo, b) File "/usr/local/lib/python3.6/dist-packages/taichi_glsl/hack.py", line 30, in _new_element_wise_binary return _old_element_wise_binary(self, foo, other) File "/usr/local/lib/python3.6/dist-packages/taichi/lang/matrix.py", line 132, in element_wise_binary assert self.m == other.m and self.n == other.n, f"Dimension mismatch between shapes ({self.n}, {self.m}), ({other.n}, {other.m})"
AssertionError: Dimension mismatch between shapes (2, 1), (3, 1)

@archibate
Copy link
Collaborator

Hi @archibate , I tried tp run mciso_mpm3d.py , but i got errors, would u mind helping?

Thanks for reporting! This is likely a bug in early version of taichi_glsl. Does pip install -U taichi_glsl taichi_three solve the issue?

@dodydharma
Copy link

dodydharma commented Dec 18, 2020

Thanks @archibate.
Btw, I am using scatter model to render particle without using the marching Cube.
I would like to draw each particle with different color, based on each particle velocity.
But it seems, currently I could only draw one color for all particle using the same material (CMIIW).
Do you have tips, what is the best way to do that with the current library.

@archibate
Copy link
Collaborator

archibate commented Dec 18, 2020

Thanks @archibate.
Btw, I am using scatter model to render particle without using the marching Cube.

Sounds like a good choice! Snows are to be feel like particles rather than stuck together which is the result of mciso.

I would like to draw each particle with different color, based on each particle velocity.
But it seems, currently I could only draw one color for all particle using the same material (CMIIW).
Do you have tips, what is the best way to do that with the current library.

Solutions are:

  1. If you only have finite colors, consider use multiple t3.ScatterModels, each with a different material:
model1 = t3.ScatterModel()
model1.material = t3.Material(t3.CookTorrance(color=t3.Constant(t3.RGB(1, 0, 0))))  # red
scene.add_model(model1)

model2 = t3.ScatterModel()
model2.material = t3.Material(t3.CookTorrance(color=t3.Constant(t3.RGB(0, 1, 0))))  # green
scene.add_model(model2)

...

model1.pos.from_numpy(pos_desired_for_red)
model2.pos.from_numpy(pos_desired_for_green)
...
  1. If you need a different color for each particle, I'd happy to modify the library a little bit to support per-vertex colors :) After that, just clone and install this updated library will work on your end.

@dodydharma
Copy link

dodydharma commented Dec 18, 2020

  1. If you need a different color for each particle, I'd happy to modify the library a little bit to support per-vertex colors :) After that, just clone and install this updated library will work on your end.

Wow :), Thanks alot., that good news, can't wait for that.
I need to draw per-vertex, to draw eachparticle based their own dynamic attribute (velocity, positon, etc... )

@archibate
Copy link
Collaborator

  1. If you need a different color for each particle, I'd happy to modify the library a little bit to support per-vertex colors :) After that, just clone and install this updated library will work on your end.

Wow :), Thanks alot., that good news, can't wait for that.
I need to draw per-vertex, to draw eachparticle based their own dynamic attribute (velocity, positon, etc... )

Hi, I've just pushed commit 0aea61a to master branch, would you clone it to install it locally? The usage example of using vertex colors can be found in examples/ball_simulation.py.

@archibate
Copy link
Collaborator

archibate commented Dec 20, 2020

Hi, I've merged some huge refactors in this project recently and the API has been changed to make it easier to use and maintain.
If you needs the old API, clone from the legacy branch. Otherwise if you'd like try out the new API:

import taichi as ti
import numpy as np
import tina  # previously called taichi_three

ti.init(ti.gpu)

scene = tina.Scene()

pars = tina.SimpleParticles()
material = tina.BlinnPhong()
scene.add_object(pars, material)

gui = ti.GUI('particles')

pos = np.random.rand(1024, 3) * 2 - 1
pars.set_particles(pos)  # you can directly specify particle positions from numpy array with variable length, like gui.circles does
radius = np.random.rand(1024) * 0.1 + 0.1
pars.set_particle_radii(radius)  # radii can still bee customized per-vertex
color = np.random.rand(1024, 3) * 0.8 + 0.2
pars.set_particle_colors(color)  # colors can be customized per-vertex too

while gui.running:
    scene.input(gui)
    scene.render()
    gui.set_image(scene.img)
    gui.show()

Hope it helps. Please let me know if you like this change :)
The new API can be installed with pip install taichi-tina.

@haizi32
Copy link

haizi32 commented Jun 24, 2021

出现这个问题咋办,AttributeError: module 'taichi' has no attribute 'TaichiOperations'

@archibate
Copy link
Collaborator

更新了,最新的master应该没有这个错误
或者把taichi降级到0.7.8,命令:pip install taichi==0.7.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants