コード例 #1
0
 def test_tesselate_torus(self):
     """ 2st test : tesselation of a torus """
     a_box = BRepPrimAPI_MakeTorus(10, 4).Shape()
     tess = Tesselator(a_box, atNormal, 1.0, 1, 0.01, 0.1, 0.1, 0.1, 0.1,
                       0.1, 0.1, 0.)
     self.assert_(tess.ObjGetTriangleCount() > 100)
     self.assert_(tess.ObjGetNormalCount() > 100)
コード例 #2
0
 def test_x3dom_render_torus(self):
     '''Test: point from curve'''
     torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
     my_renderer = x3dom_renderer.X3DomRenderer()
     my_renderer.DisplayShape(torus_shp)
     assert os.path.isfile('./shape.x3d')
     assert os.path.isfile('./x3dom_topods_shape.html')
コード例 #3
0
 def test_x3dom_render_torus(self):
     '''Test: point from curve'''
     torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
     my_renderer = x3dom_renderer.X3DomRenderer(path="./test_io")
     x3d_file, html_file = my_renderer.create_files(torus_shp)
     assert os.path.isfile(x3d_file)
     assert os.path.isfile(html_file)
コード例 #4
0
 def test_threejs_render_torus(self):
     '''Test: point from curve'''
     torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
     my_renderer = threejs_renderer.ThreejsRenderer(background_color="#123345")
     my_renderer.DisplayShape(torus_shp)
     assert os.path.isfile('./shape.js')
     assert os.path.isfile('./webgl_topods_shape.html')
コード例 #5
0
 def test_tesselate_torus_with_edges(self):
     """ 2st test : tesselation of a torus """
     a_torus = BRepPrimAPI_MakeTorus(10, 4).Shape()
     tess = Tesselator(a_torus, atNormal, 1.0, 1, 0.01, 0.1, 0.1, 0.1, 0.1,
                       0.1, 0.1, 0.)
     tess.Compute(compute_edges=True)
     self.assert_(tess.ObjGetTriangleCount() > 100)
     self.assert_(tess.ObjGetNormalCount() > 100)
コード例 #6
0
 def test_x3dom_random_mesh_quality(self):
     """ Test: threejs 10 random boxes
     """
     my_x3dom_renderer = x3dom_renderer.X3DomRenderer()
     torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
     my_x3dom_renderer.DisplayShape(torus_shp, mesh_quality=1.0)
     my_x3dom_renderer.DisplayShape(torus_shp, mesh_quality=0.8)
     my_x3dom_renderer.DisplayShape(torus_shp, mesh_quality=2.0)
コード例 #7
0
 def test_threejs_render_torus(self):
     '''Test: point from curve'''
     torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
     my_renderer = threejs_renderer.ThreejsRenderer(
         background_color="#123345")
     js_file, html_file = my_renderer.create_files(torus_shp)
     assert os.path.isfile(js_file)
     assert os.path.isfile(html_file)
コード例 #8
0
 def create_shape(self):
     d = self.declaration
     args = [d.axis, d.radius, d.radius2]
     #: Ugly...
     if d.angle:
         args.append(d.angle)
         if d.angle2:
             args.append(d.angle2)
     self.shape = BRepPrimAPI_MakeTorus(*args)
コード例 #9
0
 def test_tesselate_torus_with_bad_quality(self):
     """ 2st test : tesselation of a torus """
     a_torus = BRepPrimAPI_MakeTorus(10, 4).Shape()
     tess = Tesselator(a_torus, atNormal, 1.0, 1, 0.01, 0.1, 0.1, 0.1, 0.1,
                       0.1, 0.1, 0.)
     tess.Compute(mesh_quality=40.)
     # since mesh quality is much lower, we should count less vertices and
     # triangles
     self.assert_(tess.ObjGetTriangleCount() > 10)
     self.assert_(tess.ObjGetTriangleCount() < 100)
     self.assert_(tess.ObjGetNormalCount() > 10)
     self.assert_(tess.ObjGetNormalCount() < 100)
コード例 #10
0
ファイル: shapes.py プロジェクト: fragmuffin/cadquery
 def makeTorus(cls,
               radius1,
               radius2,
               pnt=None,
               dir=None,
               angleDegrees1=None,
               angleDegrees2=None):
     """
     makeTorus(radius1,radius2,[pnt,dir,angle1,angle2,angle]) --
     Make a torus with agiven radii and angles
     By default pnt=Vector(0,0,0),dir=Vector(0,0,1),angle1=0
     ,angle1=360 and angle=360'
     """
     return cls(
         BRepPrimAPI_MakeTorus(gp_Ax2(pnt.toPnt(), dir.toDir()), radius1,
                               radius2, angleDegrees1 * DEG2RAD,
                               angleDegrees2 * DEG2RAD).Shape())
コード例 #11
0
def section(event=None):
    Torus = BRepPrimAPI_MakeTorus(120, 20).Shape()
    radius = 120.0
    sections = []
    for i in range(-3, 4):
        # Create Sphere
        Sphere = BRepPrimAPI_MakeSphere(gp_Pnt(26 * 3 * i, 0, 0), radius).Shape()
        # Computes Torus/Sphere section
        section = BRepAlgoAPI_Section(Torus, Sphere, False)
        section.ComputePCurveOn1(True)
        section.Approximation(True)
        section.Build()
        sections.append(section)

    display.EraseAll()
    display.DisplayShape(Torus)
    for section in sections:
        display.DisplayShape(section.Shape())
    display.FitAll()
コード例 #12
0
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
コード例 #13
0
    def create_single_assembly(self,
                               tire_radius,
                               wheel_radius,
                               struct_length,
                               scale=1):
        tire_radius = tire_radius
        wheel_radius = wheel_radius
        struct_length = struct_length

        straight_arm_height = tire_radius * 1.5

        ring_radius = wheel_radius
        torus_radius = tire_radius
        torus = BRepPrimAPI_MakeTorus(torus_radius, ring_radius).Shape()

        straight_arm_radius = ring_radius / 2

        straight_arm = BRepPrimAPI_MakeCylinder(straight_arm_radius,
                                                straight_arm_height).Shape()

        angled_arm_radius = straight_arm_radius
        angled_arm_height = tire_radius * 1.5
        angle = -40

        angled_arm = BRepPrimAPI_MakeCylinder(angled_arm_radius,
                                              angled_arm_height).Shape()
        traf = CTiglTransformation()
        traf.add_rotation_x(angle)
        angled_arm = traf.transform(angled_arm)
        traf = CTiglTransformation()
        traf.add_translation(0, angled_arm_height * sin(angle), 0)
        angled_arm = traf.transform(angled_arm)

        traf = CTiglTransformation()
        traf.add_translation(0, angled_arm_height * cos(angle),
                             angled_arm_height * sin(angle))
        straight_arm = traf.transform(straight_arm)
        arm_assembly = BRepAlgoAPI_Fuse(straight_arm, angled_arm).Shape()

        traf = CTiglTransformation()
        traf.add_rotation_x(90)
        torus = traf.transform(torus)

        pin_radius = wheel_radius
        pin_height = tire_radius

        pin = BRepPrimAPI_MakeCylinder(pin_radius, pin_height).Shape()

        traf = CTiglTransformation()
        traf.add_translation(0, 0, -straight_arm_height + torus_radius / 2)
        torus = traf.transform(torus)

        traf = CTiglTransformation()
        traf.add_rotation_x(90)
        pin = traf.transform(pin)

        traf = CTiglTransformation()
        traf.add_translation(0, 0, -straight_arm_height + pin_radius)
        pin = traf.transform(pin)

        traf = CTiglTransformation()
        traf.add_mirroring_at_xzplane()
        mirrored_arm_assembly = traf.transform(arm_assembly)

        traf = CTiglTransformation()
        traf.add_mirroring_at_xzplane()
        mirrored_pin = traf.transform(pin)

        arm_assembly = BRepAlgoAPI_Fuse(mirrored_arm_assembly,
                                        arm_assembly).Shape()

        struct_radius = wheel_radius - 0.5 * wheel_radius
        struct_height = struct_length
        struct = BRepPrimAPI_MakeCylinder(struct_radius, struct_height).Shape()
        traf = CTiglTransformation()
        traf.add_translation(0, 0, torus_radius)
        struct = traf.transform(struct)

        pin = BRepAlgoAPI_Fuse(mirrored_pin, pin).Shape()
        part_1 = BRepAlgoAPI_Fuse(arm_assembly, pin).Shape()
        part_2 = BRepAlgoAPI_Fuse(part_1, struct).Shape()
        part_3 = BRepAlgoAPI_Fuse(part_2, pin).Shape()

        return BRepAlgoAPI_Fuse(part_3, torus).Shape()
コード例 #14
0
from __future__ import print_function

import random

from OCC.Display.WebGl import threejs_renderer
from OCC.BRepPrimAPI import BRepPrimAPI_MakeTorus
from OCC.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())
コード例 #15
0
#!/usr/bin/python
# coding: utf-8
r"""
"""
from OCC.Display.WebGl import threejs_renderer
from OCC.BRepPrimAPI import BRepPrimAPI_MakeTorus

# create box
cube_shp = BRepPrimAPI_MakeTorus(25., 15.).Shape()
# load shaders
vs = open('shaders/pink.vs', 'r').read()
fs = open('shaders/pink.fs', 'r').read()
u = open('shaders/pink.uniforms', 'r').read()
my_renderer = threejs_renderer.ThreejsRenderer(vertex_shader=vs,
                                               fragment_shader=fs,
                                               uniforms=u)
my_renderer.DisplayShape(cube_shp)
コード例 #16
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()
コード例 #17
0
#!/usr/bin/python
# coding: utf-8
r"""
"""

from OCC.Display.WebGl import threejs_renderer
from OCC.BRepPrimAPI import BRepPrimAPI_MakeTorus

torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
my_renderer = threejs_renderer.ThreejsRenderer(background_color="#123345")
my_renderer.DisplayShape(torus_shp)
コード例 #18
0
##along with pythonOCC.  If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function

import random

from OCC.Display.WebGl import threejs_renderer
from OCC.BRepPrimAPI import BRepPrimAPI_MakeTorus
from OCC.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_shp2 = translate_shp(torus_shp1, gp_Vec(60, 0, 0))
torus_shp3 = translate_shp(torus_shp1, 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.2) 

# worse quality, i.e. less triangles
print("Computing BLUE torus: worse quality, faster to compute")
my_ren.DisplayShape(torus_shp3, export_edges=True, color=(0,0,1),  # blue
コード例 #19
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 OCC.Display.SimpleGui import init_display
from OCC.BRepPrimAPI import BRepPrimAPI_MakeTorus
from OCC.Graphic3d import (Graphic3d_EF_PDF, Graphic3d_EF_SVG,
                           Graphic3d_EF_TEX, Graphic3d_EF_PostScript,
                           Graphic3d_EF_EnhPostScript)

display, start_display, add_menu, add_function_to_menu = init_display()
my_box = BRepPrimAPI_MakeTorus(40., 20.).Shape()

display.DisplayShape(my_box, update=True)
f = display.View.View().GetObject()

#-------------------------------------------------------------------------------
# for this example to work, pythonocc / OCE needs to be built with the gl2ps lib
#-------------------------------------------------------------------------------


def export_to_PDF(event=None):
    f.Export('torus_export.pdf', Graphic3d_EF_PDF)


def export_to_SVG(event=None):
    f.Export('torus_export.svg', Graphic3d_EF_SVG)
コード例 #20
0
    def GenerateHTMLFile(self):
        """ Generate the HTML file to be rendered wy the web browser
        """
        with open(self._html_filename, "w") as fp:
            fp.write("<!DOCTYPE HTML>")
            fp.write('<html lang="en">')
            # header
            fp.write(HTMLHeader().get_str())
            # body
            fp.write(HTMLBody(self._x3d_shapes).get_str())
            fp.write("</html>\n")


if __name__ == "__main__":
    from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeTorus
    from OCC.BRepBuilderAPI import BRepBuilderAPI_Transform
    from OCC.gp import gp_Trsf, gp_Vec
    def translate_shp(shp, vec, copy=False):
        trns = gp_Trsf()
        trns.SetTranslation(vec)
        brep_trns = BRepBuilderAPI_Transform(shp, trns, copy)
        brep_trns.Build()
        return brep_trns.Shape()
    box = BRepPrimAPI_MakeBox(100., 200., 300.).Shape()
    torus = BRepPrimAPI_MakeTorus(300., 105).Shape()
    t_torus = translate_shp(torus, gp_Vec(700, 0, 0))
    my_ren = X3DomRenderer()
    my_ren.DisplayShape(box)
    my_ren.DisplayShape(t_torus)
    my_ren.render()
コード例 #21
0
 def test_threejs_render_torus(self):
     """ Render a simple torus in threejs
     """
     torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
     my_threejs_renderer = threejs_renderer.ThreejsRenderer()
     my_threejs_renderer.DisplayShape(torus_shp)
コード例 #22
0
##(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/>.

import os

from OCC.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
assert os.path.isdir(stl_output_dir)
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
write_stl_file(my_torus, stl_low_resolution_file, mode="binary", linear_deflection=0.5, angular_deflection=0.3)
コード例 #23
0
import sys

sys.path.append('../..')

import WebServer.TornadoWeb
import tornado.ioloop

from OCC.BRepPrimAPI import BRepPrimAPI_MakeTorus

renderer = WebServer.TornadoWeb.TornadoWebRenderer()

torus = BRepPrimAPI_MakeTorus(40, 10).Shape()

renderer.DisplayShape(torus)

print(renderer)
if __name__ == "__main__":
    io_loop = tornado.ioloop.IOLoop.current()
    io_loop.start()
コード例 #24
0
 def test_x3dom_render_torus(self):
     """ Render a simple torus using x3dom
     """
     torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
     my_x3dom_renderer = x3dom_renderer.X3DomRenderer()
     my_x3dom_renderer.DisplayShape(torus_shp)