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

How to implement the xyz to mesh generation to another code for fluid simulation? #309

Open
uljad opened this issue Sep 23, 2020 · 1 comment
Labels

Comments

@uljad
Copy link

uljad commented Sep 23, 2020

I am running a fluidics simulation in a robotics platform and I am currently pausing the simulation every few steps to mesh the fluid particles. Is there a way I could use the xyz to obj capabilities of fluid engine dev so I will not have to run the partciles2obj examples each timestep?

Currently, I use system to run the examples from the terminal. Can I do it without this extra I/O? It would be amazing if there was a way.

@uljad uljad changed the title How to implement the xyz to mesh generation to another codebase? How to implement the xyz to mesh generation to another code for fluid simulation? Sep 23, 2020
@doyubkim
Copy link
Owner

Hi @uljadberdica1000,

If you want to adapt particles2obj in your code, you can copy and modify the functions from particles2obj as shown below:

void triangulateAndSave(const ScalarGrid3& sdf,
                        const std::string& objFilename) {
    TriangleMesh3 mesh;
    marchingCubes(sdf.constDataAccessor(), sdf.gridSpacing(), sdf.dataOrigin(),
                  &mesh, 0.0, kDirectionAll);

    std::ofstream file(objFilename.c_str());
    if (file) {
        printf("Writing %s...\n", objFilename.c_str());
        mesh.writeObj(&file);
        file.close();
    } else {
        printf("Cannot write file %s.\n", objFilename.c_str());
        exit(EXIT_FAILURE);
    }
}

void particlesToObj(const Array1<Vector3D>& positions, const Size3& resolution,
                    const Vector3D& gridSpacing, const Vector3D& origin,
                    double kernelRadius, const std::string& method,
                    const std::string& objFilename) {
    PointsToImplicit3Ptr converter;
    if (method == kSpherical) {
        converter =
            std::make_shared<SphericalPointsToImplicit3>(kernelRadius, false);
    } else if (method == kSph) {
        converter = std::make_shared<SphPointsToImplicit3>(
            kernelRadius, sSphCutOffDensity, false);
    } else if (method == kZhuBridson) {
        converter = std::make_shared<ZhuBridsonPointsToImplicit3>(
            kernelRadius, sZhuBridsonCutOffThreshold, false);
    } else {
        converter = std::make_shared<AnisotropicPointsToImplicit3>(
            kernelRadius, sAnisoCutOffDensity, sAnisoPositionSmoothingFactor,
            sAnisoMinNumNeighbors, false);
    }

    VertexCenteredScalarGrid3 sdf(resolution, gridSpacing, origin);
    printInfo(resolution, sdf.boundingBox(), gridSpacing, positions.size(),
              method);

    converter->convert(positions, &sdf);

    triangulateAndSave(sdf, objFilename);
}

You can call particlesToObj function after every time-step.

Hope this helps!

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

No branches or pull requests

2 participants