lib3mf

repository·master·Indexed 43 days ago

https://github.com/3mfconsortium/lib3mf

A C++ library providing a robust implementation of the 3D Manufacturing Format (3MF) standard. It enables reading, writing, conversion, and validation of 3MF files across Windows, Linux, and macOS. The library offers header-only C++ bindings (implicit and dynamic loading) and supports multiple language bindings including C, Python, Pascal, C#, Golang, and NodeJS.

Tokens
273.5K
Snippets
850
Records
1.3K
Agent score
55%

What's inside lib3mf

  1. Overview of lib3mf

    master

    lib3mf is a C++ implementation of the 3D Manufacturing Format (3MF) file standard. It is designed to facilitate the adoption of the 3MF standard by providing tools for:

    • Reading and Writing: Full support for 3MF file formats.
    • Conversion: Tools to convert between different data representations.
    • Validation: Tools to validate both input and output data against the 3MF specification.

    The library is cross-platform, running on Windows, Linux, and MacOS, and provides API bindings for various programming languages to minimize integration effort.

  2. LibreSSL API Compatibility with OpenSSL

    master

    LibreSSL is a fork of OpenSSL 1.0.1g.

    • API Support: LibreSSL provides much of the OpenSSL 1.1 API. It does not currently support the OpenSSL 3 API.
    • ABI Compatibility: LibreSSL is not ABI compatible with any release of OpenSSL, nor necessarily with earlier releases of LibreSSL. You must relink your programs when switching to LibreSSL.
  3. Use Lib3MF::CImplicitFunction to build implicit functions

    master

    The Lib3MF::CImplicitFunction class (inheriting from CFunction) is used to construct complex implicit functions by building a directed graph of nodes. You can add various mathematical, geometric, and resource nodes to the function and then connect them using ports to define the functional relationship.

    Key operations include:

    • Adding Nodes: Use specialized Add...Node methods to insert mathematical operations (e.g., AddSinNode, AddAdditionNode), constants (AddConstantNode), or geometric primitives (AddMeshNode).
    • Connecting Nodes: Use AddLink with port objects or AddLinkByNames using the string format nodename.portname to establish connections between nodes.
    • Managing Nodes: You can iterate through nodes using GetNodes(), remove specific nodes with RemoveNode(), or organize the graph using SortNodesTopologically().
    • Identification: Every function has a unique identifier that can be managed via GetIdentifier() and SetIdentifier().
    // Conceptual example of building an implicit function
    Lib3MF::PImplicitFunction func;
    func->SetIdentifier("my_function");
    
    // Add nodes
    auto sinNode = func->AddSinNode("sin1", eImplicitNodeConfiguration::kDefault, "Sine Wave", "tag1");
    auto constNode = func->AddConstantNode("const1", "Constant Value", "tag2");
    
    // Link nodes using name-based syntax: nodename.portname
    func->AddLinkByNames("const1.value", "sin1.input");
    
    // Sort the graph for evaluation
    func->SortNodesTopologically();
  4. Use slice references and CollapseSliceReferences in CSliceStack

    master

    A CSliceStack can contain references to other slice stacks instead of just raw slices.

    • Use AddSliceStackReference(pTheSliceStack) to include an existing slice stack as a reference within the current stack.
    • Use GetSliceStackReference(nSliceRefIndex) to retrieve a specific slice stack reference by its index.
    • Use CollapseSliceReferences() to flatten the hierarchy. This method removes all existing slices and slice-references in the current stack and replaces them with the actual slices contained within the referenced stacks, effectively removing the indirection.
  5. Use Lib3MF::CAttachment to manage 3MF attachments

    master

    The Lib3MF::CAttachment class is used to manage attachments within a 3MF package. Attachments are typically external files or data streams linked to the 3MF package via relationships.

    Key capabilities include:

    • Data I/O: Reading from or writing to files, memory buffers, or custom callbacks.
    • Metadata: Managing the attachment's package path and relationship type.
    • Integration: Accessing the PackagePart that this attachment belongs to.

    Note that GetPath() and SetPath() are deprecated and scheduled for removal in a future release.

    Instances of CAttachment are typically managed via Lib3MF::PAttachment, which is a std::shared_ptr<CAttachment> to facilitate automatic reference counting.

    using Lib3MF::PAttachment;
    using Lib3MF::CAttachment;
    
    // PAttachment is a shared_ptr to CAttachment
    PAttachment attachment = /* obtained from a package part or similar */;
    std::string path = attachment->GetPath();
    attachment->WriteToFile("attachment_data.bin");
  6. Choose between Implicit and Dynamic C++ bindings

    master

    lib3mf provides two ways to integrate the C++ bindings into your host application. Both are header-only, making them easy to include in existing projects.

    Implicit Loading (Load-time)

    Use this method if you want the operating system to handle loading the library when your application starts. You must ensure the shared library file (lib3mf.*) is in a path searched by your OS (e.g., LD_LIBRARY_PATH on Linux, or the application directory on Windows).

    • Header to include: Cpp/lib3mf_implicit.hpp
    • Usage: Call CWrapper::loadLibrary() to get a wrapper object.

    Dynamic Loading (Run-time)

    Use this method if you want to explicitly specify the location of the shared library file at runtime.

    • Header to include: CppDynamic/lib3mf_dynamic.hpp
    • Usage: Call Lib3MF::CWrapper::loadLibrary("path/to/lib3mf") with the explicit path to the library file.
    // Implicit loading example
    Lib3MF::PWrapper wrapper = CWrapper::loadLibrary();
    
    // Dynamic loading example (OS specific paths)
    // Linux:
    Lib3MF::PWrapper wrapper = Lib3MF::CWrapper::loadLibrary("LibraryLocation/lib3mf.so");
    // Mac OSX:
    Lib3MF::PWrapper wrapper = Lib3MF::CWrapper::loadLibrary("LibraryLocation/lib3mf.dylib");
    // Windows:
    Lib3MF::PWrapper wrapper = Lib3MF::CWrapper::loadLibrary("LibraryLocation/lib3mf.dll");
  7. Use Lib3MF::CBase and PBase for object management

    master

    In lib3mf, CBase is the base class for most objects. To manage these objects with automatic reference counting and avoid manual memory management, use the Lib3MF::PBase type, which is a std::shared_ptr<CBase>.

    You can identify the specific type of a CBase object by calling its ClassTypeId() method, which returns a 64-bit integer representing the class type.

    // Example of using PBase for reference counting and ClassTypeId for identification
    Lib3MF::PBase baseObject = std::make_shared<Lib3MF::CBase>();
    
    // Get the unique 64-bit identifier for the class type
    Lib3MF_uint64 typeId = baseObject->ClassTypeId();