示例#1
0
 def create_shape(self):
     d = self.declaration
     args = [coerce_axis(d.axis), d.radius, d.radius2]
     if d.angle2 or d.angle3:
         amin = min(d.angle2, d.angle3)
         amax = max(d.angle2, d.angle3)
         args.append(amin)
         args.append(amax)
     if d.angle:
         args.append(d.angle)
     torus = BRepPrimAPI_MakeTorus(*args)
     self.shape = torus.Shape()
##
##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/>.

import os

from OCCT.BRepPrimAPI import BRepPrimAPI_MakeTorus
from OCC.Extend.DataExchange import write_stl_file

# first, create the shape
my_torus = BRepPrimAPI_MakeTorus(20., 10.).Shape()

# set the directory where to output the
stl_output_dir = os.path.abspath(os.path.join("..", "assets", "models"))

# make sure the path exists otherwise OCE get confused
if not os.path.isdir(stl_output_dir):
    raise AssertionError("wrong path provided")
stl_low_resolution_file = os.path.join(stl_output_dir,
                                       "torus_default_resolution.stl")
write_stl_file(my_torus, stl_low_resolution_file)

# then we change the mesh resolution, and export as binary
stl_high_resolution_file = os.path.join(stl_output_dir,
                                        "torus_high_resolution.stl")
# we set the format to binary
示例#3
0
from __future__ import print_function

import random

from OCC.Display.WebGl import threejs_renderer
from OCCT.BRepPrimAPI import BRepPrimAPI_MakeTorus
from OCCT.gp import gp_Vec

from OCC.Extend.ShapeFactory import translate_shp, rotate_shp_3_axis

my_ren = threejs_renderer.ThreejsRenderer()
n_toruses = 100

idx = 0
for i in range(n_toruses):
    torus_shp = BRepPrimAPI_MakeTorus(10 + random.random() * 10,
                                      random.random() * 10).Shape()
    # random position and orientation and color
    angle_x = random.random() * 360
    angle_y = random.random() * 360
    angle_z = random.random() * 360
    rotated_torus = rotate_shp_3_axis(torus_shp, angle_x, angle_y, angle_z,
                                      'deg')
    tr_x = random.uniform(-70, 50)
    tr_y = random.uniform(-70, 50)
    tr_z = random.uniform(-50, 50)
    trans_torus = translate_shp(rotated_torus, gp_Vec(tr_x, tr_y, tr_z))
    rnd_color = (random.random(), random.random(), random.random())
    my_ren.DisplayShape(trans_torus,
                        export_edges=True,
                        color=rnd_color,
                        transparency=random.random())
示例#4
0
        print("Shape selected: ", shape)
    print(kwargs)


def compute_bbox(shp, *kwargs):
    print("Compute bbox for %s " % shp)
    for shape in shp:
        bbox = Bnd_Box()
        brepbndlib_Add(shape, bbox)
        xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
        dx = xmax - xmin
        dy = ymax - ymin
        dz = zmax - zmin
        print("Selected shape bounding box : dx=%f, dy=%f, dz=%f." %
              (dx, dy, dz))
        print("               bounding box center: x=%f, y=%f, z=%f" %
              (xmin + dx / 2., ymin + dy / 2., zmin + dz / 2.))


display, start_display, add_menu, add_function_to_menu = init_display()
# register callbacks
display.register_select_callback(print_xy_click)
display.register_select_callback(compute_bbox)
# creating geometry
my_torus = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()
my_box = BRepPrimAPI_MakeTorus(30., 5.).Shape()
# and finally display geometry
display.DisplayShape(my_torus)
display.DisplayShape(my_box, update=True)
start_display()
#!/usr/bin/env python

##Copyright 2009-2016 Thomas Paviot ([email protected])
##
##This file is part of pythonOCC.
##
##pythonOCC 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 3 of the License, or
##(at your option) any later version.
##
##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 OCC.Display.WebGl import threejs_renderer
from OCCT.BRepPrimAPI import BRepPrimAPI_MakeTorus

torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
my_renderer = threejs_renderer.ThreejsRenderer()
my_renderer.DisplayShape(torus_shp)
my_renderer.render()
##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 OCCT.BRepPrimAPI import BRepPrimAPI_MakeTorus
from OCCT.BRepBuilderAPI import BRepBuilderAPI_NurbsConvert
from OCCT.BRepAdaptor import BRepAdaptor_Surface

from OCC.Extend.TopologyUtils import TopologyExplorer
from OCCT.GeomAbs import GeomAbs_BSplineSurface

base_shape = BRepPrimAPI_MakeTorus(30, 10).Shape()

# conversion to a nurbs representation
nurbs_converter = BRepBuilderAPI_NurbsConvert(base_shape, True)
#nurbs_converter.Perform()
converted_shape = nurbs_converter.Shape()

# now, all edges should be BSpline curves and surfaces BSpline surfaces
# see https://www.opencascade.com/doc/occt-7.4.0/refman/html/class_b_rep_builder_a_p_i___nurbs_convert.html#details

expl = TopologyExplorer(converted_shape)

# loop over faces
fc_idx = 1

for face in expl.faces():
示例#7
0
##
##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

from OCC.Display.WebGl import threejs_renderer
from OCCT.BRepPrimAPI import BRepPrimAPI_MakeTorus
from OCCT.gp import gp_Vec

from OCC.Extend.ShapeFactory import translate_shp

my_ren = threejs_renderer.ThreejsRenderer()

idx = 0
torus_shp1 = BRepPrimAPI_MakeTorus(20, 5).Shape()

torus_shp2b = BRepPrimAPI_MakeTorus(20, 5).Shape()
torus_shp2 = translate_shp(torus_shp2b, gp_Vec(60, 0, 0))

torus_shp3b = BRepPrimAPI_MakeTorus(20, 5).Shape()
torus_shp3 = translate_shp(torus_shp3b, gp_Vec(-60, 0, 0))

# default quality
print("Computing RED torus: default quality")
my_ren.DisplayShape(torus_shp1, export_edges=True, color=(1,0,0))  # red

# better mesh quality, i.e. more triangles
print("Computing GREEN torus: better quality, more time to compute")
my_ren.DisplayShape(torus_shp2, export_edges=True, color=(0,1,0),  # green
                    mesh_quality = 0.5)
def boolean_fuse(base):
    ring_radius = 0.25
    torus_radius = 1.0 - ring_radius
    torus = BRepPrimAPI_MakeTorus(torus_radius, ring_radius).Shape()
    fuse = BRepAlgoAPI_Fuse(base, torus).Shape()
    return fuse