FreeCAD Logo FreeCAD 1.0
  • English Afrikaans Arabo Bielorusso Catalano Czech German Greek Spanish Spanish Basco Finnish Filippino Français Galiziano Croatian Hungarian Indonesiano Italiano Japanese Kabyle Coreano Lituano Dutch Norvegese Bokmal Polish Portuguese Portuguese Romanian Russian Slovak Slovenian Serbo Swedish Turkish Ukrainian Valenziano Vietnamita Cinese Cinese
  • Funzioni
  • Download
  • Blog
  • Documentazione
    Indice di documentazione Per iniziare Documentazione utenti Il manuale FreeCAD Documentazione degli ambienti di lavoro Documentazione di scripting Python Documentazione codice C++ Tutorial Domande frequenti Politica sulla Privacy Informazioni Su FreeCAD
  • Contribuire
    Come aiutare Sponsor Segnala un bug Fai una richiesta Opportunità di lavoro e ricompense Linee guida per contribuire Manuale degli sviluppatori Traduzioni
  • Comunità
    Codice di condotta Forum The FPA GitHub GitLab Codeberg Mastodon Matrix IRC IRC via Webchat Gitter Discord Reddit Twitter Facebook LinkedIn Calendario
  • ♥ Donate

Donate

$
Informazioni SEPA
Si prega di intestare il bonifico SEPA a:
Beneficiary: The FreeCAD project association
IBAN: BE04 0019 2896 4531
BIC/SWIFT: GEBABEBBXXX
Agenzia bancaria: BNP Paribas Fortis
Indirizzo: Rue de la Station 64, 1360 Perwez, Belgium

While Stripe doesn't support monthly donations, you can still become a sponsor! Simply make a one-time donation equivalent to 12 months of support, and you'll gain access to the corresponding sponsoring tier. It's an easy and flexible way to contribute.

If you are not sure or not able to commit to a regular donation, but still want to help the project, you can do a one-time donation, of any amount.

Choose freely the amount you wish to donate one time only.

You can support FreeCAD by sponsoring it as an individual or organization through various platforms. Sponsorship provides a steady income for developers, allowing the FPA to plan ahead and enabling greater investment in FreeCAD. To encourage sponsorship, we offer different tiers, and unless you choose to remain anonymous, your name or company logo will be featured on our website accordingly.

from 1 USD / 1 EUR per month. You will not have your name displayed here, but you will have helped the project a lot anyway. Together, normal sponsors maintain the project on its feet as much as the bigger sponsors.

from 25 USD / 25 EUR per month. Your name or company name is displayed on this page.

from 100 USD / 100 EUR per month. Your name or company name is displayed on this page, with a link to your website, and a one-line description text.

from 200 USD / 200 EUR per month. Your name or company name and logo displayed on this page, with a link to your website and a custom description text. Companies that have helped FreeCAD early on also appear under Gold sponsors.

Instead of donating each month, you might find it more comfortable to make a one-time donation that, when divided by twelve, would give you right to enter a sponsoring tier. Don't hesitate to do so!

Choose freely the amount you wish to donate each month.

Please inform your forum name or twitter handle as a notein your transfer, or reach to us, so we can give you proper credits!

Icona macro generica. Crea la tua icona personale con lo stesso nome della macro BSurf_from_grid

Descrizione
Crea una superficie B-spline attraverso una griglia di punti.

Versione macro: 0.1
Ultima modifica: 2022-07-31
Autore: heda
Autore
heda
Download
None
Link
Raccolta di macro
Come installare le macro
Personalizzare la toolbar
Versione macro
0.1
Data ultima modifica
2022-07-31
Versioni di FreeCAD
None
Scorciatoia
Nessuna
Vedere anche
Nessuno

Descrizione

Crea una superficie B-spline attraverso una griglia di punti. Opzioni per la creazione di sole curve Wire o B-spline.

Macro BSurf from grid

Installazione

Disponibile dal Addon manager.

Opzioni

Vedere le docstring.

Utilizzo

Vedere le docstring.

Script

Macro_BSurf_from_grid.FCMacro


# -*- coding: utf-8 -*-

# ***************************************************************************
# *                                                                         *
# *   Copyright (c) 2022 - heda <heda@fc-forum>                             *
# *                                                                         *
# *   This program is free software; you can redistribute it and/or modify  *
# *   it under the terms of the GNU Lesser General Public License (LGPL)    *
# *   as published by the Free Software Foundation; either version 2 of     *
# *   the License, or (at your option) any later version.                   *
# *   for detail see the LICENCE text file.                                 *
# *                                                                         *
# *   This program is distributed in the hope that it will be useful,       *
# *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
# *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
# *   GNU Library General Public License for more details.                  *
# *                                                                         *
# *   You should have received a copy of the GNU Library General Public     *
# *   License along with this program; if not, write to the Free Software   *
# *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
# *   USA                                                                   *
# *                                                                         *
# ***************************************************************************

__Name__ = 'BSurf_from_grid'
__Comment__ = 'Makes a BSpline surface through a grid of points.'
__Author__ = 'heda'
__Version__ = '0.1'
__Date__ = '2022-07-31'
__License__ = 'LGPL-2.0-or-later'
__Web__ = ''
__Wiki__ = 'https://wiki.freecad.org/Macro_Grid_2_BSurf'
__Icon__ = ''
__Help__ = 'Select structured point-cloud, set options, run macro'
__Status__ = 'functional'
__Requires__ = ''
__Communication__ = ''
__Files__ = ''

"""
inspired by:
https://forum.freecad.org/viewtopic.php?f=22&t=69941&start=10
cred to snow54

it is assumed that the cloud is:
    - structured
    - aligned with xy grid,
i.e. a constant y divides 2 horizontal rows of points,
analogue for x and vertical columns of points


usage:
select a pointcloud and run macro    

options:
wires: convert boundary wires to spline (draft wb),
       in surf wb, use boundry edges and verts on wires as vertex-constraints

splines: in surf wb, use outer contour as boundry edges,
         inner edges can be used as edge constraints

bsurf: surface directly created with poles/knots from interpolated spline

mkwframe: in case of bsurf, symbolic wireframe of splines (draft wb)
"""

import numpy as np
from scipy import interpolate

import FreeCAD as App
import FreeCADGui as Gui
import Draft, Part

Vector = App.Vector

doc = App.ActiveDocument

try:
    cloud, = Gui.Selection.getSelection()
except ValueError as e:
    raise RuntimeWarning('a point cloud needs to be selected.')

points = cloud.Points.Points
bb = cloud.Points.BoundBox

options = o = dict(MakeWires=False,
                   MakeBSplines=False,
                   MakeBSurf=True,
                   MakeWFrame=True)

## a bit of options logic...
if o['MakeWires']: o['MakeBSplines'] = False
if o['MakeBSplines']: o['MakeBSurf'] = o['MakeWires'] = False
if o['MakeBSurf'] and o['MakeWFrame']:
    o['MakeBSplines'] = True; o['MakeWires'] = False
if not o['MakeBSurf']: o['MakeWFrame'] = False


def RGB(*args):
    return tuple((float(i/255) for i in args))


hstep = min((p.y for p in points))
vstep = min((p.x for p in points))

wiregroup = doc.addObject('App::DocumentObjectGroup', 'Wires')
hwires = doc.addObject('App::DocumentObjectGroup', 'HWires')
vwires = doc.addObject('App::DocumentObjectGroup', 'VWires')
wiregroup.addObjects([hwires, vwires])

for wg, step, getter in ((hwires, hstep, 'y'),
                         (vwires, vstep, 'x')):
    wires = list()
    empty = False
    cc = bb.YMin if getter == 'y' else bb.XMin
    cc -= step/2
    while not empty:
        polypoints = list()
        for pt in points:
            value = getattr(pt, getter)
            if cc < value < cc + step:
                polypoints.append(pt)
        if polypoints:
            if o['MakeWires'] or (o['MakeBSurf'] and not o['MakeWFrame']):
                maker = Draft.make_wire
            elif o['MakeBSplines']:
                maker = Draft.make_bspline
            wires.append(maker(polypoints, closed=False))
            cc += step
        else:
            empty = True

    wg.addObjects(wires)

Gui.Selection.clearSelection()

if o['MakeBSurf']:
    degree_u = degree_v = 3
    periodic = False

    lowerx, lowery = hwires.Group[0], vwires.Group[0]
    x = np.array([pt.x for pt in lowerx.Points])
    y = np.array([pt.y for pt in lowery.Points])
    Z = np.array([[pt.z for pt in hw.Points] for hw in hwires.Group])

    ## Create spline surface
    g = interpolate.RectBivariateSpline(x, y, Z.T)
    coefgs = g.get_coeffs()
    coefgs = np.reshape(coefgs, Z.T.shape).T
    knots = g.get_knots()
    # Convert knot vector format
    knot_u, mult_u = np.unique(knots[1], return_counts=True)
    knot_v, mult_v = np.unique(knots[0], return_counts=True)
    # Normalize knot vectors
    knot_u = (knot_u - knot_u.min()) / (knot_u.max() - knot_u.min())
    knot_v = (knot_v - knot_v.min()) / (knot_v.max() - knot_v.min())
    
    # Calculate spline coefficients for x and y
    gx = interpolate.make_interp_spline(x, x)
    coefgx = gx.tck[1]
    gy = interpolate.make_interp_spline(y, y)
    coefgy = gy.tck[1]

    getVector = lambda iz, jz: Vector(coefgx[jz],
                                      coefgy[iz],
                                      coefgs[iz, jz])

    # Create control point vectors
    ctrl = [[getVector(iZ, jZ) for jZ, lc in enumerate(lr)]
            for iZ, lr in enumerate(coefgs)]
    
    # Create spline surface in FreeCAD
    bs = Part.BSplineSurface()
    bs.buildFromPolesMultsKnots(ctrl, mult_u, mult_v, knot_u, knot_v,
                                periodic, periodic, degree_u, degree_v)
    
    surf = Part.show(bs.toShape(), 'BSplineSurf')
    surf.Label2 = 'spline surface through points'
    surf.ViewObject.ShapeColor = RGB(0, 170, 255)

    if not o['MakeWFrame']:
        for obj in hwires.Group + vwires.Group + [hwires, vwires, wiregroup]:
            doc.removeObject(obj.Name)


doc.recompute()

av = Gui.ActiveDocument.ActiveView
av.viewIsometric()
av.fitAll()

Questa pagina è recuperata da https://wiki.freecad.org/Macro_BSurf_from_grid

Tieniti aggiornato!
Forum GitHub Mastodon Matrix IRC Gitter.im Discord Reddit Twitter Facebook LinkedIn

© The FreeCAD Team. Homepage image credits (top to bottom): ppemawm, r-frank, epileftric, regis, rider_mortagnais, bejant.

Questo progetto è supportato da: , KiCad Services Corp. e altri sponsor

GitHubMigliora questa pagina su GitHub