コード例 #1
0
ファイル: bop_assys.py プロジェクト: frmdstryr/pyOCCT
from OCCT.BOPAlgo import BOPAlgo_Options
from OCCT.BRepAlgoAPI import BRepAlgoAPI_Fuse
from OCCT.TopTools import TopTools_ListOfShape

from OCCT.Exchange import ExchangeBasic
from OCCT.Visualization import BasicViewer

fn = './models/wing_assy.brep'
wing_assy = ExchangeBasic.read_brep(fn)

fn = './models/fuse_assy.brep'
fuse_assy = ExchangeBasic.read_brep(fn)

BOPAlgo_Options.SetParallelMode_(True)
bop = BRepAlgoAPI_Fuse()
args = TopTools_ListOfShape()
args.Append(wing_assy)
bop.SetArguments(args)
tools = TopTools_ListOfShape()
tools.Append(fuse_assy)
bop.SetTools(tools)
print('Starting fuse...')
start = time.time()
bop.Build()
print('Complete in ', time.time() - start, ' seconds.')

v = BasicViewer()
v.add(bop.Shape())
v.start()
コード例 #2
0
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
import time

from OCCT.BOPAlgo import BOPAlgo_Options
from OCCT.BRepAlgoAPI import BRepAlgoAPI_Common

from OCCT.Exchange import ExchangeBasic
from OCCT.Visualization import BasicViewer

cheese = ExchangeBasic.read_step('./models/cheese.stp')
planes = ExchangeBasic.read_step('./models/planes.stp')

v = BasicViewer()
v.add(cheese, planes)
v.start()
v.clear()

# Basic operation takes about 32 seconds
print('Starting Boolean operation...')
start = time.time()
BRepAlgoAPI_Common(cheese, planes)
print('Complete in ', time.time() - start, ' seconds.')

# Run in parallel. Should take 10 to 11 seconds on 4 cores
BOPAlgo_Options.SetParallelMode_(True)
print('Starting Boolean operation...')
start = time.time()
bop = BRepAlgoAPI_Common(cheese, planes)
コード例 #3
0
ファイル: import_step.py プロジェクト: tnakaicode/PlotGallery
# This file is part of pyOCCT which provides Python bindings to the OpenCASCADE
# geometry kernel.
#
# Copyright (C) 2016-2018  Laughlin Research, LLC ([email protected])
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
from OCCT.Graphic3d import Graphic3d_NOM_ALUMINIUM

from OCCT.Exchange import ExchangeBasic
from OCCT.Visualization import BasicViewer

shape = ExchangeBasic.read_step('./models/compressor.step')

v = BasicViewer()
v.display_shape(shape, rgb=(0.5, 0.5, 0.5), material=Graphic3d_NOM_ALUMINIUM)
v.start()
コード例 #4
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
##
# You should have received a copy of the GNU Lesser General Public License
# along with pythonOCC.  If not, see <http://www.gnu.org/licenses/>.

import sys
from itertools import chain

from OCCT.Visualization import BasicViewer
from OCCT.BRepGProp import BRepGProp_VinertGK, brepgprop_LinearProperties
#from OCCTUtils.Common import points_to_bspline
from OCCTUtils.Construct import gp_Pnt, make_edge, make_n_sided, make_vertex

v = BasicViewer()


def n_sided_patch():

    # left
    pts1 = (gp_Pnt(0, 0, 0.0),
            gp_Pnt(0, 1, 0.3),
            gp_Pnt(0, 2, -0.3),
            gp_Pnt(0, 3, 0.15),
            gp_Pnt(0, 4, 0),
            )
    # front
    pts2 = (gp_Pnt(0, 0, 0.0),
            gp_Pnt(1, 0, -0.3),
            gp_Pnt(2, 0, 0.15),
コード例 #5
0
ファイル: import_vsp.py プロジェクト: tnakaicode/pyOCCT
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
import random
import time

from OCCT.Boolean import FuseShapes
from OCCT.Exchange import ImportVSP
from OCCT.Visualization import BasicViewer

# Select version of OpenVSP used to export the model. Versions greater than
# 3.5.0 seem to decrease OpenCASCADE performance. Surface parameterization was
# changed in OpenVSP, but not entirely sure that is the root cause.
fn = './models/F-16_OpenVSP3.5.0.stp'
# fn = './models/F-16_OpenVSP3.15.0.stp'
vsp = ImportVSP(fn)

v = BasicViewer()
for s in vsp.solids:
    r = random.randint(0, 256)
    g = random.randint(0, 256)
    b = random.randint(0, 256)
    v.display_shape(s, (r, g, b))
v.start()
v.clear()

# Attempt to fuse all the solids together. Pick one solid for the argument and
# the others will be tools (you need at least one of each). Not sure how
# selecting different arguments and tools impacts the results, if at all.
arg = vsp.solids[0]
tools = vsp.solids[1:]

fuse = FuseShapes()
コード例 #6
0
# fn = './models/wingbox.brep'
# fn = './models/fuselage_structure.brep'
fn = './models/wing_body.brep'

shape = ExchangeBasic.read_brep(fn)

gen = SMESH_Gen()

mesh = gen.CreateMesh(0, True)

assert isinstance(mesh, SMESH_Mesh)

mesh.ShapeToMesh(shape)

mg_hyp = BLSURFPlugin_Hypothesis(0, 0, gen, True)
mg_alg = BLSURFPlugin_BLSURF(1, 0, gen, True)
mg_hyp.SetPhySize(4)
mg_hyp.SetQuadAllowed(True)

mesh.AddHypothesis(mesh.GetShapeToMesh(), 0)
mesh.AddHypothesis(mesh.GetShapeToMesh(), 1)

print('Computing mesh...')
start = time.time()
done = gen.Compute(mesh, mesh.GetShapeToMesh())
print('done in ', time.time() - start, ' seconds.')

v = BasicViewer()
v.add(mesh)
v.start()
コード例 #7
0
# pythonOCC 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 Lesser General Public License for more details.
##
# You should have received a copy of the GNU Lesser General Public License
# along with pythonOCC.  If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function

import sys

from OCCT.gp import gp_Pnt, gp_Dir, gp_Ax3

from OCCT.Visualization import BasicViewer
gui = BasicViewer()


def axis():
    p1 = gp_Pnt(2., 3., 4.)
    d = gp_Dir(4., 5., 6.)
    a = gp_Ax3(p1, d)
    a_IsDirect = a.Direct()
    print("a is direct:", a_IsDirect)
    # a_XDirection = a.XDirection()
    # a_YDirection = a.YDirection()
    p2 = gp_Pnt(5., 3., 4.)
    a2 = gp_Ax3(p2, d)
    a2.YReverse()
    # axis3 is now left handed
    a2_IsDirect = a2.Direct()
コード例 #8
0
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
from OCCT.STEPControl import STEPControl_Reader
from OCCT.TopAbs import TopAbs_FACE
from OCCT.TopExp import TopExp_Explorer

from OCCT.Visualization import BasicViewer

# Read the file and get the shape
reader = STEPControl_Reader()
tr = reader.WS().TransferReader()
reader.ReadFile('./models/shape_names.step')
reader.TransferRoots()
shape = reader.OneShape()

gui = BasicViewer()

# Explore the faces of the shape (these are known to be named)
exp = TopExp_Explorer(shape, TopAbs_FACE)
while exp.More():
    rgb = None
    s = exp.Current()
    exp.Next()
    item = tr.EntityFromShapeResult(s, 1)
    name = item.Name().ToCString()
    if name:
        print('Found entity: {}'.format(name))
        rgb = (1, 0, 0)
    gui.add(s, rgb)

gui.start()