nmwsharp / geometry-central

Applied 3D geometry in C++, with a focus on surface meshes.
https://geometry-central.net
MIT License
1.01k stars 141 forks source link

Future functionality for IntrinsicTriangulation IO #166

Open JeffreyLayton opened 7 months ago

JeffreyLayton commented 7 months ago

Hey,

My application requires saving the mesh connectivity, mesh geometry, and mesh data for intrinsic triangulation on top of extrinsic input meshes. I tried using RichSurfaceMeshData and creating the intrinsic geometry elements and properties (ply file format); however, there is no way (at least I can see) of restoring the intrinsic triangulation alongside the extrinsic data without saving the history of how the triangulation was formed. My intent was to save a ply with both the input extrinsic structure and the input triangulation(s). Is there any future work for improving the IO of the GC structures?

Jeffrey Layton

JeffreyLayton commented 7 months ago

I think I almost managed to do the above without any change to the existing code. The only issue is the BaseGeometryInterface has a reference to the intrinsic mesh in IntrinsicTriangulation that fails to be corrected (and I have no way to change without modifying the class(es)). Everything else I was about to restore I believe.

        auto derived_ptr_sp
            = dynamic_cast<geometrycentral::surface::SignpostIntrinsicTriangulation *>(
                globals::generated_triangulation.get()
            );
        auto derived_ptr_ic
            = dynamic_cast<geometrycentral::surface::IntegerCoordinatesIntrinsicTriangulation *>(
                globals::generated_triangulation.get()
            );
        if (derived_ptr_sp != nullptr) { //Sign Post Realization
            auto temp = std::make_unique<geometrycentral::surface::SignpostIntrinsicTriangulation>(
                *globals::mesh_input, *globals::geometry_input
            );
            // Simulate loading Int. Mesh connectivity with a copy
            temp->intrinsicMesh = globals::generated_triangulation->intrinsicMesh->copy(); 
            temp->mesh          = *temp->intrinsicMesh;  // Illegal copy to a reference
            // Edge Length Geometry members
            temp->edgeLengths
                = globals::generated_triangulation->edgeLengths.reinterpretTo(*temp->intrinsicMesh);
            // Intrinsic Triangulation Members
            temp->vertexLocations = globals::generated_triangulation->vertexLocations.reinterpretTo(
                *temp->intrinsicMesh
            );
            // Sign Post Intrinsic Triangulation Members
            temp->signpostAngle = derived_ptr_sp->signpostAngle.reinterpretTo(*temp->intrinsicMesh);
            temp->edgeIsOriginal
                = derived_ptr_sp->edgeIsOriginal.reinterpretTo(*temp->intrinsicMesh);
            // Copy object for use
            globals::generated_triangulation.reset();
            globals::generated_triangulation = std::move(temp);
        }
        else { //Integer Coordinate Realization
            auto temp = std::make_unique<
                geometrycentral::surface::IntegerCoordinatesIntrinsicTriangulation>(
                *globals::mesh_input, *globals::geometry_input
            );
            // Simulate loading Int. Mesh connectivity with a copy
            temp->intrinsicMesh = globals::generated_triangulation->intrinsicMesh->copy();
            temp->mesh          = *temp->intrinsicMesh; // Illegal copy to a reference
            // Edge Length Geometry members
            temp->edgeLengths
                = globals::generated_triangulation->edgeLengths.reinterpretTo(*temp->intrinsicMesh);
            // Intrinsic Triangulation Members
            temp->vertexLocations = globals::generated_triangulation->vertexLocations.reinterpretTo(
                *temp->intrinsicMesh
            );
            // Integer Coordinates Intrinsic Triangulation Members
            new (&temp->normalCoordinates)
                geometrycentral::surface::NormalCoordinates(*temp->intrinsicMesh);
            temp->normalCoordinates.edgeCoords
                = derived_ptr_ic->normalCoordinates.edgeCoords.reinterpretTo(*temp->intrinsicMesh);
            temp->normalCoordinates.roundabouts
                = derived_ptr_ic->normalCoordinates.roundabouts.reinterpretTo(*temp->intrinsicMesh);
            temp->normalCoordinates.roundaboutDegrees
                = derived_ptr_ic->normalCoordinates.roundaboutDegrees.reinterpretTo(
                    *temp->intrinsicMesh
                );
            // Copy object for use
            globals::generated_triangulation.reset();
            globals::generated_triangulation = std::move(temp);
        }