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

Weird behavior in PoissonDiskSampler #184

Closed
dyollb opened this issue Aug 8, 2024 · 2 comments · Fixed by #186
Closed

Weird behavior in PoissonDiskSampler #184

dyollb opened this issue Aug 8, 2024 · 2 comments · Fixed by #186

Comments

@dyollb
Copy link
Contributor

dyollb commented Aug 8, 2024

I am trying to use the PoissonDiskSampler to sample a triangle mesh with minimum sample distance distance:

    gc::surface::SimplePolygonMesh simpleMesh;
    for (const auto & t : qmesh.get_tris_buffer())
    {
        simpleMesh.polygons.push_back({t.inds[0], t.inds[1], t.inds[2]});
    }
    for (const auto & v : qmesh.get_verts_buffer())
    {
        simpleMesh.vertexCoordinates.push_back({v.x, v.y, v.z});
    }

    std::unique_ptr<gc::surface::ManifoldSurfaceMesh> mesh;
    std::unique_ptr<gc::surface::VertexPositionGeometry> geometry;
    // throws exception if input is non-manifold/invalid
    std::tie(mesh, geometry) = gc::surface::makeManifoldSurfaceMeshAndGeometry(simpleMesh.polygons, simpleMesh.vertexCoordinates);

    geometry->requireEdgeLengths();
    double meanEdgeLength = 0.;
    for (auto e : mesh->edges()) {
      meanEdgeLength += geometry->edgeLengths[e];
    }
    meanEdgeLength /= mesh->nEdges();
    geometry->unrequireEdgeLengths();

    gc::surface::PoissonDiskSampler sampler(*mesh, *geometry);
    auto samples = sampler.sample(distance / meanEdgeLength);

    std::vector<Vec3d> points;
    points.reserve(samples.size());
    for (auto& s: samples)
    {
        auto p = s.interpolate(geometry->vertexPositions);
        points.push_back({p.x, p.y, p.z});
    }

If I sample a (approximate) cube with edge length 40 (two triangles per cube face), I get following behavior:

distance=4 distance=2 distance=1
samples: 3 samples: 22 samples: 6559
image image image

Why is this happening? Am I doing something wrong?

@dyollb
Copy link
Contributor Author

dyollb commented Aug 14, 2024

@nmwsharp Is this a bug or a user error?

Looking at the code I am wondering why the sqrt of the minDist is used to create new samples here:

double dist = std::sqrt(randomReal(rMinDist, 2. * rMinDist));

@nzfeng
Copy link
Collaborator

nzfeng commented Aug 17, 2024

Hey @dyollb, thanks for making a pull request! I've been meaning to correct this issue for a while now. Totally agree it doesn't usually make too much sense for the min distance to be in terms of edge length.

And yeah, line 93 looks like a bug -- thank you for catching it!

I'll get back to you on your PR!

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

Successfully merging a pull request may close this issue.

2 participants