MCPcopy Create free account
hub / github.com/BIMCoderLiang/LNLib

github.com/BIMCoderLiang/LNLib @v2.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.1 ↗ · + Follow
1,031 symbols 2,200 edges 136 files 12 documented · 1% updated 8d agov2.1 · 2026-06-23★ 3123 open issues

Browse by type

Functions 895 Types & classes 136
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Introduction

LNLib is a NURBS Algorithms Kernel Library.

These algorithms are primary referenced from The NURBS Book 2nd Edition.

For NURBS Curve | Surface | Volume

Build Project

Project API Language Instruction
LNLib C++ Run build.bat first to construct Native C++ solution by CMake
LNLibjs WebAssembly Run script in emscripten folder
PyLNLib Python3.x Switch ENABLE_PYTHON_API to ON in CMakeLists.txt and run build.bat
LNLibSharp .NET8.0 Switch ENABLE_DOTNET_API to ON in CMakeLists.txt and run build.bat, LNLibSharp depends on CApi.dll generated by CAPI project for P/Invoke

notice: Unit tests now only cover Native C++ APIs on Windows System.

Features

Basic Elements: - UV - UVW - XYZ - XYZW - Matrix4d - LNObject

Algorithms in The NURBS Book: |Chapter|Content| |--|--| |Chapter 1 | Basis Function Computation | |Chapter 1 to 4 | Bezier/B-Spline/NURBS Curve and Surface | |Chapter 5 | Curve and Surface Decomposition

Knot Insertion/Refinement/Removal

Degree Elevation and Reduction | |Chapter 6 | Curve/Surface Point Inversion

Surface Tangent Vector Inversion

Curve/Surface Reparameterization

Curve Transform and Reverse

Surface Swap and Reverse| |Chapter 7 | Create Arc/Conic Curve | |Chapter 8 | Create Bilinear/Cylindrical/Ruled/Revolved/CornerFillet Surface | |Chapter 9 | Global/Local Curve/Surface Interpolation and Approximation | |Chapter 10 | Create Swung/Loft/Sweep/Gordon/Coons Surface | |Chapter 11 | Curve Modification in Control Point Locations or Weight Values | |Chapter 12 | Curve Clamp/UnClamp/IsClamp

KnotVector IsUniform

Curve IsClosed/IsPeriodic|

Additional Algorithms: |Description|Content| |--|--|
|NURBS Curve | Curve Curvature and Normal

Curve Split/Segment/Merge/Offset

Curve IsLinear/IsArc

Curve Approximate Length

Curve Extension (Tangent/Arc/Natural)

Curve Tessellation

Line/Cubic Hermite (as NURBS) Creation| |NURBS Surface | Surface AABB and OBB BoundingBox

Surface Curvature and Normal

Surface Approximate Area

Surface Triangulation | |NURBS Volume | Volume Degree Elevation

Volume Knot Insertion/Refinement

Volume Point Inversion

Volume Split

Extract Surface From Volume

Extract IsoCurve From Volume

Volume Swap and Reverse|

Visualization

LNLibViewer based on VTK

NURBS Fitting by Neural Network

ND-LNLib based on LibTorch (PyTorch C++ version)

Convert to OpenCascade NURBS surface

#include "LNObject.h"
#include "XYZ.h"
#include "XYZW.h"
#include "NurbsSurface.h"
#include "KnotVectorUtils.h"
#include <Geom_BSplineSurface.hxx>

void ConvertToOpenCascadeSurface(const LNLib::LN_NurbsSurface& surface, Handle(Geom_BSplineSurface)& internalSurface)
{
    LNLib::NurbsSurface::Check(surface);

    std::vector<double> knotU = surface.KnotVectorU;
    std::vector<double> knotV = surface.KnotVectorV;

    const int numPolesU = static_cast<int>(surface.ControlPoints.size());
    const int numPolesV = static_cast<int>(surface.ControlPoints[0].size());

    TColgp_Array2OfPnt poles(1, numPolesU, 1, numPolesV);
    TColStd_Array2OfReal weights(1, numPolesU, 1, numPolesV);

    for (int i = 0; i < numPolesU; i++) {
        for (int j = 0; j < numPolesV; j++) {
            const LNLib::XYZW& wcp = surface.ControlPoints[i][j];
            const LNLib::XYZ& cp = wcp.ToXYZ(true);
            poles.SetValue(i+1, j+1, gp_Pnt(cp.GetX(), cp.GetY(), cp.GetZ()));
            weights.SetValue(i+1, j+1, wcp.GetW());
        }
    }

    std::map<double, int> mapU = LNLib::KnotVectorUtils::GetKnotMultiplicityMap(knotU);
    TColStd_Array1OfReal knotsU(1, static_cast<int>(mapU.size()));
    TColStd_Array1OfInteger multsU(1, static_cast<int>(mapU.size()));

    std::vector<double> Ukeys;
    Ukeys.reserve(mapU.size());
    std::vector<int> UMults;
    UMults.reserve(mapU.size());
    for (auto it = mapU.begin(); it != mapU.end(); ++it) {
        Ukeys.emplace_back(it->first);
        UMults.emplace_back(it->second);
    }
    for (int i = 0; i < Ukeys.size(); i++) {
        knotsU.SetValue(i+1, Ukeys[i]);
    }
    for (int i = 0; i < UMults.size(); i++) {
        multsU.SetValue(i+1, UMults[i]);
    }

    std::map<double, int> mapV = LNLib::KnotVectorUtils::GetKnotMultiplicityMap(knotV);
    TColStd_Array1OfReal knotsV(1, static_cast<int>(mapV.size()));
    TColStd_Array1OfInteger multsV(1, static_cast<int>(mapV.size()));

    std::vector<double> Vkeys;
    Vkeys.reserve(mapV.size());
    std::vector<int> VMults;
    VMults.reserve(mapV.size());
    for (auto it = mapV.begin(); it != mapV.end(); ++it) {
        Vkeys.emplace_back(it->first);
        VMults.emplace_back(it->second);
    }
    for (int i = 0; i < Vkeys.size(); i++) {
        knotsV.SetValue(i+1, Vkeys[i]);
    }
    for (int i = 0; i < VMults.size(); i++) {
        multsV.SetValue(i+1, VMults[i]);
    }

    internalSurface = new Geom_BSplineSurface(
        poles, weights, knotsU, knotsV,
        multsU, multsV,
        surface.DegreeU, surface.DegreeV);
}

More Details could be found in LNLibEx Library, which used for export nurbs surfaces to STEP or IGES format file.

Online Document

Welcome to use https://deepwiki.com/BIMCoderLiang/LNLib powered by Devin.

Contributing

Welcome join this project including discussions in Issues and make Pull requests. - Contributors:

Repositories based-on LNLib

  • fplnlib: Pascal Version NURBS Algorithm
  • VL.Nurbsy: Native C# Version of NURBS Algorithm

Contact

LNLib is created by Yuqing Liang (BIMCoder Liang).

  • email: bim.frankliang@foxmail.com
  • Weixin Official Account (微信公众号):BIMCoder

License

The source code is published under LGPL 2.1, the license is available here.

Primary Reference

The NURBS Book 2nd Edition by Les Piegl & Wayne Tiller

Core symbols most depended-on inside this repo

Shape

Method 574
Function 321
Class 120
Enum 16

Languages

C++75%
C#25%

Modules by API surface

src/LNLib/Algorithm/Voronoi.cpp67 symbols
src/LNLib/Geometry/Curve/NurbsCurve.cpp65 symbols
dotnet/PInvoke/src/NurbsCurve.cs61 symbols
dotnet/CAPI/src/NurbsCurve_CAPI.cpp59 symbols
src/LNLib/Geometry/Surface/NurbsSurface.cpp50 symbols
dotnet/PInvoke/src/NurbsSurface.cs39 symbols
dotnet/CAPI/src/NurbsSurface_CAPI.cpp39 symbols
src/LNLib/Mathematics/Math/Matrix4d.cpp30 symbols
src/LNLib/Mathematics/Math/XYZ.cpp29 symbols
src/LNLib/include/Voronoi.h28 symbols
dotnet/PInvoke/src/Matrix4d.cs28 symbols
dotnet/CAPI/src/Matrix4d_CAPI.cpp28 symbols

For agents

$ claude mcp add LNLib \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page