-
I'm wondering what is the best way to create a Gordon Surface? Here is what I have so far but as you would expect I getting import csv
import numpy as np
from build123d import *
def read_heightmap(filename: str):
with open(filename, 'r') as f:
reader = csv.reader(f)
heightmap = []
for row in reader:
heightmap.append([float(val) for val in row])
return np.array(heightmap)
heightmap = read_heightmap('heightmap.csv')
points = []
for x in range(heightmap.shape[0]):
for y in range(heightmap.shape[1]):
points.append(Vector(x, y, heightmap[x,y]))
x_splines = []
y_splines = []
for x in range(heightmap.shape[0]):
points = [(x, y, heightmap[x,y]) for y in range(heightmap.shape[1])]
x_splines.append(Spline(points))
for y in range(heightmap.shape[1]):
points = [(x, y, heightmap[x,y]) for x in range(heightmap.shape[0])]
y_splines.append(Spline(points))
boundary_wire = Wire.make_wire([x_splines[0], y_splines[0], x_splines[-1], y_splines[-1]])
show_object(Face.make_surface(boundary_wire)) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 16 replies
-
The make_surface_from_array_of_points method might be what you want here. A Gordon Surface isn't currently supported by build123d; however, to create one it looks like GeomFill_AppSurf might be the correct OpenCascade class. Here is a rough (AI generated) template how this might work: #include <GeomFill_AppSurf.hxx>
#include <Geom_BSplineCurve.hxx>
#include <GeomFill_SimpleBound.hxx>
#include <Geom_Surface.hxx>
#include <TopoDS_Face.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
void CreateGordonSurface() {
// Example boundary curves (replace with your actual curves)
Handle(Geom_BSplineCurve) curve1 = ...; // U direction curve 1
Handle(Geom_BSplineCurve) curve2 = ...; // U direction curve 2
Handle(Geom_BSplineCurve) curve3 = ...; // V direction curve 1
Handle(Geom_BSplineCurve) curve4 = ...; // V direction curve 2
// Create bounds for U and V directions
GeomFill_SimpleBound uBound1(curve1, GeomAbs_C0);
GeomFill_SimpleBound uBound2(curve2, GeomAbs_C0);
GeomFill_SimpleBound vBound1(curve3, GeomAbs_C0);
GeomFill_SimpleBound vBound2(curve4, GeomAbs_C0);
// Create the Gordon surface
GeomFill_AppSurf gordonSurface;
gordonSurface.Init(uBound1, uBound2, Standard_True, Standard_True);
gordonSurface.Perform(vBound1, vBound2, Standard_True, Standard_True);
// Retrieve the resulting surface
Handle(Geom_Surface) surface = gordonSurface.Surface();
// Optional: Convert to a TopoDS_Face
TopoDS_Face face = BRepBuilderAPI_MakeFace(surface, Precision::Confusion());
// Use the face in your model
} |
Beta Was this translation helpful? Give feedback.
-
TiGL[1] has an OpenCascade based Gordon surface builder that is very good (c++). Christophe Grellier (@tomate44) ported it to FreeCAD's Curves WB[2] long time ago in Python. It can be used as a reference to port it to build123d. I am in the process of reorganizing the implementation as a standalone python module, but it is WIP and i can't make compromises on that [3] [1] https://dlr-sc.github.io/tigl/ |
Beta Was this translation helpful? Give feedback.
TiGL[1] has an OpenCascade based Gordon surface builder that is very good (c++). Christophe Grellier (@tomate44) ported it to FreeCAD's Curves WB[2] long time ago in Python. It can be used as a reference to port it to build123d. I am in the process of reorganizing the implementation as a standalone python module, but it is WIP and i can't make compromises on that [3]
[1] https://dlr-sc.github.io/tigl/
[2] https://github.com/tomate44/CurvesWB/blob/master/freecad/Curves/gordon.py
[3] https://github.com/mnesarco/MarzWorkbench/blob/master/freecad/marz/curves/gordon.py