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

Voxelization #1209

Merged
merged 48 commits into from
Dec 4, 2017
Merged

Voxelization #1209

merged 48 commits into from
Dec 4, 2017

Conversation

hadjiszs
Copy link
Member

@hadjiszs hadjiszs commented Sep 30, 2016

PR Description

Algorithm

I traverse all voxels V of triangle bounding box and insert in digital set if V overlaps current triangle.
I use intersection target (samuli laine) to know if a voxel overlaps a triangle.

6-separated

6-separated

foreach triangle ABC
    foreach blue segment S of intersection target set
        2D projection of ABC on the plane of normal N(x,y,z)
        corresponding to S, just by ignoring coordinate

        foreach voxel V of ABC bounding box
            2D projection of V
            if 2D V is inside 2D triangle ABC
                insert V in digitalSet

26-separated

26-separated

It's the same algorithm but I do differently of 6-separated way for projections.

foreach triangle ABC
    foreach blue segment S of intersection target set
        compute e1 and e2 to have a base with each normal N(x,y,z)
        corresponding to S, so
            e1 = (-y, x, 0)
            e2 = (-xz, -yz, x^2)

        2D projection of A B and C on plane (0, e1, e2)
        foreach voxel V of ABC bounding box
            2D projection of V on plane (0, e1, e2)
            if 2D V is inside 2D triangle ABC
                insert V in digitalSet

Checklist

  • Unit-test of your feature with Catch.
  • Doxygen documentation of the code completed (classes, methods, types, members...)
  • Documentation module page added or updated.
  • New entry in the ChangeLog.md added.
  • No warning raised in Debug cmake mode (otherwise, Travis C.I. will fail).
  • All continuous integration tests pass (Travis & appveyor)

@kerautret
Copy link
Member

Thanks! and also to the tools I look it this week end!

@copyme
Copy link
Member

copyme commented Sep 30, 2016

Can you provide information about the implemented algorithm?

@dcoeurjo
Copy link
Member

dcoeurjo commented Sep 30, 2016

@kerautret and @copyme please hold on. @hadjiszs is an intern I have at Lyon and the code is not ready for review.

I asked @hadjiszs to PR to be able to discuss on his code.

@kerautret
Copy link
Member

ok let me know when ready but that nice idea ;)

@dcoeurjo
Copy link
Member

dcoeurjo commented Oct 3, 2016

@hadjiszs have you checked the « allow edits from maintainers » when you've created your Pull-Request ?

@hadjiszs
Copy link
Member Author

hadjiszs commented Oct 3, 2016

@dcoeurjo sorry I didn't know this option, but it seems checked

screenshot:
screenshot

@dcoeurjo
Copy link
Member

@hadjiszs : since we do not optimize the intersection tests for adjacent triangles, I suggest to remove the mesh from the constructor and add a "voxelise(Mesh)" method.
You could thus voxelise different meshes and get a unique digital set at the end. What do you think?

@hadjiszs
Copy link
Member Author

hadjiszs commented Oct 16, 2016

@dcoeurjo yes I think it's ok, maybe with a "add(Mesh)" method, and a voxelize() method?

to be able to do something like that:

MeshVoxelizer mv(...);

Mesh3 aMesh1(...);
Mesh3 aMesh2(...);
Mesh3 aMesh3(...);

mv.add(aMesh1);
mv.add(aMesh2);
mv.add(aMesh3);

mv.voxelize(); // to be able to have a parallelization on list of mesh in voxelize() method

by the way, I try to fix last build fail of travis, but I really don't understand error about DGtal::HDF5Reader https://travis-ci.org/DGtal-team/DGtal/jobs/167108444#L1111

@dcoeurjo
Copy link
Member

Even simpler:

MeshVoxeliser mv(domain);

mv.voxelise (aMesh1);
mv.voxelise(aMesh2);

Point a(...),b(...),c(...);

//add a unique triangle
mv.voxelise(a,b,c);

..

no need to keep the meshes (or a ref to) as members.

@dcoeurjo
Copy link
Member

Don't bother with the HDF5 issue, I'll have a look.

thx

@hadjiszs
Copy link
Member Author

sorry I haven't explained my example,
it was to have a parallel processing on list of meshes within voxelize method

something like that (in voxelize method)

#omp parallel for // just for example with openmp syntax
foreach mesh M
    // .. voxelization of M into digitalSet

To let programmer add/remove meshes in MeshVoxelizer, and he chooses when he wants to run parallel voxelization of all current list of meshes he established. With that, he can have a parallel voxelization of a set of meshes

but, there is no parallelism in MeshVoxelizer yet, so my proposition is useless for now and I think it would be eventually for later, and I will do like you said as of now

@dcoeurjo
Copy link
Member

I've updated the interface. Your tool may be deprecated now.

@dcoeurjo
Copy link
Member

can someone review this dude too ?

@kerautret kerautret self-requested a review November 18, 2017 22:46
Copy link
Member

@kerautret kerautret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first part of the review I will finish it tomorrow ;)


The approach is rather simple: Given a triangulated mesh, the
MeshVoxlizer processes each triangle independently. If the triangle
intersects a given @a template centered ot a given grid point, then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ot a given grid -> at a given grid


\section sectVoxelization2 Basic Usage

Given a Mesh @a aMesh, the MeshVoxelizer class is template by a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is templateD


@snippet examples/shapes/exampleMeshVoxelizer.cpp MeshVoxelizerDig

Once exported
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Once exported with :" ?


we obtain the following voxel set:

@image html resultCube.png "Resulting voxelSet (quad faces triangulated by the viewer)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps could you just use an export in off format and the visualize it with the DGtalTools meshViewer (to avoid to display triangle)..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by the way perhaps having another example with bunny or other will be nice to illustrate such new nice work ;)!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are some examples given from my tests that you can use:
(obtained by using bunny at scale 1 but manually changing scale of bunny (basicEditMesh --scale 300 -I bunny.off -o test.off and by using 6 and 26 template)
capture d ecran 2017-11-19 a 00 45 30
capture d ecran 2017-11-19 a 00 45 05
capture d ecran 2017-11-19 a 00 44 15

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you use an imported mesh in the examples simply use:

#include <DGtal/io/readers/MeshReader.h>
aMesh << "bunny.off";

and then simply output in sdp format and display it with 3dSDPViewer for instance.


We then create a voxelization of a scaled version of the cube onto a
@f$ 128^3@f$ domain:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add the header mention (#include "DGtal/shapes/MeshVoxelizer.h") just before this code ?

Copy link
Member

@kerautret kerautret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, that is nice new features!
Just see some small assert add for the domain and then we can merge.

/**
Description of template class 'IntersectionTarget'

\brief Aim: A class for intersection target used on voxelization
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"used for" ?
and mention MeshVoxelizer in parenthesis @see MeshVoxelizer ?

* @param [out] outputSet the set that collects the voxels.
* @param [in] aMesh the mesh to voxelize (vertex coordinates will
* be casted to @e PointR3 points.
* @param [in] scaleFactor the scale factor to apply to the mesh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this parameter perhaps you have to alter to be careful to not use a value compatible with the domain of the digital set, else we have an error... (or/and detect it explicitly later ?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean ?
That the scale may induce voxels outside the set domain ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry something was auto completed with my editor, or I was very tired ;)
I was thinking that you could add a user warning in the doc to avoid this potential error. But with the last change, we can simply mention that outside domain voxel are ignored ?

* @param [in] a the first point of the triangle
* @param [in] b the second point of the triangle
* @param [in] c the third point of the triangle
* @param [in] scaleFactor the scale factor to apply to the triangle (default=1.0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here


// check if current voxel projection is inside ABC projection
if(pointIsInside2DTriangle(AA, BB, CC, pp) != OUTSIDE)
outputSet.insert(v);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I got an error if the scaleFactor is too large (v is outside the output domain, see previous remarks).

A = a*scaleFactor;
B = b*scaleFactor;
C = c*scaleFactor;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps add an assert to check if the points are in the digital set domain ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I've slightly changed the interface: I first check that the voxel is inside the domain or not before the insert. Hence, no more issue with the domain but if a voxel is outside the set, it is simply skipped.
Fine for you ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes fine

@dcoeurjo
Copy link
Member

Thanks for your comments.

@dcoeurjo
Copy link
Member

Could you please generate the images with the bunny and 2 digitizations using different resolution (I'm not familiar with the mesh viewer) ?
This would be very nice for the module doc.

@kerautret
Copy link
Member

Could you please generate the images with the bunny and 2 digitizations using different resolution (I'm not familiar with the mesh viewer) ?
This would be very nice for the module doc.

yes is what you want ?
bunnys250
bunnys500

@dcoeurjo
Copy link
Member

thx @kerautret

@dcoeurjo
Copy link
Member

I've updated the doc with the bunny images. Would it be fine for you ?

@dcoeurjo
Copy link
Member

dcoeurjo commented Dec 2, 2017

@kerautret is it fine for you?

Copy link
Member

@kerautret kerautret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes nice thanks just a typo, sorry for the delay ;(

@@ -84,6 +84,11 @@ be automatically triangulated using a naive fan approach. Hence, if
the face in not planar and/or convex, the resulting digitization might
be incorrect.

Here you have another example with a more complex mesh (using DGtaltools tools for visualization):

@image html bunnies.png "Voxelization at different resolution of a Stanford Bunny."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

different resolutionS ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

damit ;)

@kerautret
Copy link
Member

thanks looks fine, just waiting for travis and merging....

@dcoeurjo
Copy link
Member

dcoeurjo commented Dec 4, 2017

travis done ;)
merging

@dcoeurjo dcoeurjo merged commit 8c2c800 into DGtal-team:master Dec 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants