Skip to content

memory grows when using flip geodesics shortening the same paths #230

@snhwv

Description

@snhwv

When I follow the official documentation to call the flip geodesics algorithm multiple times on the same dataset, the memory usage keeps growing.
Shortening many paths,doc: https://geometry-central.net/surface/algorithms/flip_geodesics/
I'm a C++ beginner, and with the help of the documentation and ChatGPT, I wrote the following program:

#include <fstream>
#include <vector>

#include <chrono>
#include "geometrycentral/surface/flip_geodesics.h"
#include "geometrycentral/surface/vertex_position_geometry.h"
#include "geometrycentral/surface/meshio.h"
#include "geometrycentral/surface/mesh_graph_algorithms.h"

#include <mach/mach.h>
#include <iostream>
#include <mach/task.h>
#include <mach/mach_init.h>
#include <libproc.h>      // for proc_pidinfo() on some macOS versions
#include <sys/types.h>    // for pid_t
#include <unistd.h>       // for getpid() and getrusage()
#include <sys/resource.h> // for getrusage()

using namespace geometrycentral;
using namespace geometrycentral::surface;

int computeFlipGeodesicPath(
    std::unique_ptr<FlipEdgeNetwork> &edgeNetwork,
    int vertex0,
    int vertex1)
{
    Vertex startVert = edgeNetwork->tri->intrinsicMesh->vertex(vertex0); // populate these somehow
    Vertex endVert = edgeNetwork->tri->intrinsicMesh->vertex(vertex1);

    // Get an initial dijkstra path
    // (surface/mesh_graph_algorithms.h)
    std::vector<Halfedge> dijkstraPath = shortestEdgePath(*edgeNetwork->tri, startVert, endVert);

    // Reinitialize the ede network to contain this path
    edgeNetwork->reinitializePath({dijkstraPath});

    // Straighten the path to geodesic
    edgeNetwork->iterativeShorten();

    // Extract the path and store it in the vector
    // std::vector<Vector3> path3D = edgeNetwork->getPathPolyline3D().front();

    // Be kind, rewind
    edgeNetwork->rewind();
    return 1;
}

int main()
{
    using namespace std::chrono;

    std::unique_ptr<ManifoldSurfaceMesh> mesh;
    std::unique_ptr<VertexPositionGeometry> geom;
    std::tie(mesh, geom) = readManifoldSurfaceMesh("/Downloads/test.obj");

    std::unique_ptr<FlipEdgeNetwork> edgeNetwork(new FlipEdgeNetwork(*mesh, *geom, {}));
    edgeNetwork->supportRewinding = true;
    edgeNetwork->posGeom = geom.get();

    struct task_basic_info t_info;
    mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;

    // 1
    computeFlipGeodesicPath(edgeNetwork, 36841, 29806);

    if (KERN_SUCCESS != task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count))
    {
        std::cerr << "task_info() failed" << std::endl;
        return 1;
    }

    std::cout << "Resident Memory Size: " << t_info.resident_size / 1024 / 1024 << " MB" << std::endl;

    // 2
    computeFlipGeodesicPath(edgeNetwork, 36841, 29806);
    if (KERN_SUCCESS != task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count))
    {
        std::cerr << "task_info() failed" << std::endl;
        return 1;
    }
    std::cout << "Resident Memory Size: " << t_info.resident_size / 1024 / 1024 << " MB" << std::endl;

    // 3
    computeFlipGeodesicPath(edgeNetwork, 36841, 29806);
    if (KERN_SUCCESS != task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count))
    {
        std::cerr << "task_info() failed" << std::endl;
        return 1;
    }
    std::cout << "Resident Memory Size: " << t_info.resident_size / 1024 / 1024 << " MB" << std::endl;

    return 0;
}

result:

Image

obj file:
test.obj.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions