SINTEF / Splipy

Spline modelling made easy.
GNU General Public License v3.0
100 stars 18 forks source link

Added: Trimmed Surfaces (with g2 readers) #53

Closed VikingScientist closed 6 years ago

VikingScientist commented 6 years ago

Also support for more g2 classes:

Also fixed some numerical precision bugs CurveFactory.fit( )

VikingScientist commented 6 years ago

Not especially nice interface right now, and very limited functionality, but it is a start on which we can build on.

Use cases

Read .g2 files

with G2('g2_files_with_trimmed_surfaces.g2') as myfile:
    my_model = myfile.read()

Constructors requires trimming loops to be specified

trim_loop = [CurveFactory.line([.25,.25], [.75,.25]),                  
             CurveFactory.line([.75,.25], [.75,.75]),                  
             CurveFactory.line([.75,.75], [.25,.75]),                  
             CurveFactory.line([.25,.75], [.25,.25])]                                                                
# defaults basis1=basis2=linear, unit square identity parametrization
s = TrimmedSurface(loops=[trim_loop])                                  

Create physical representation of parametric trimming curves

I kind of like this one

for loop in surface.boundaries:                                                
    for curve in loop:                                                         
        x = lambda t: surface(curve(t)[:,0], curve(t)[:,1], tensor=False)      
        my_crvs.append(CurveFactory.fit(x, curve.start(0), curve.end(0)))      

for all curve pieces, for all closed trimming loops you evaluate the points of that curve, to get the parametric points of the underlying surface. This surface then needs to be sampled to get the final coordinates in physical space. Using a lambda to wrap this "double"-evaluation makes it possible to use CurveFactory.fit( ) which does non-uniform adaptive refinement up to some desired tolerance. Pretty compact, powerful and neat.