Exemplo n.º 1
0
def slicer(event=None):
    # Param
    Zmin, Zmax, deltaZ = -100, 100, 5
    # Note: the shape can also come from a shape selected from InteractiveViewer
    #if 'display' in dir():
    #    shape = display.GetSelectedShape()
    #else:
    # Create the shape to slice
    shape = BRepPrimAPI_MakeSphere(60.).Shape()
    # Define the direction
    D = gp_Dir(0., 0., 1.)  # the z direction
    # Perform slice
    sections = []
    #init_time = time.time()  # for total time computation
    for z in range(Zmin, Zmax, deltaZ):
        # Create Plane defined by a point and the perpendicular direction
        P = gp_Pnt(0, 0, z)
        Pln = gp_Pln(P, D)
        face = BRepBuilderAPI_MakeFace(Pln).Shape()
        # Computes Shape/Plane intersection
        section_shp = BRepAlgoAPI_Section(shape, face)
        if section_shp.IsDone():
            sections.append(section_shp)
    #total_time = time.time() - init_time
    #print("%.3fs necessary to perform slice." % total_time)
    
    rnd = JupyterRenderer()
    rnd.DisplayShape(shape)
    rnd.Display()
 def render_pipe(pipe):
     my_renderer = JupyterRenderer(compute_normals_mode=NORMAL.CLIENT_SIDE)
     my_renderer.DisplayShape(pipe,
                              shape_color="blue",
                              topo_level="Face",
                              quality=1.)  # default quality
     print(my_renderer)
Exemplo n.º 3
0
def fuse(event=None):
    box1 = BRepPrimAPI_MakeBox(2, 1, 1).Shape()
    box2 = BRepPrimAPI_MakeBox(2, 1, 1).Shape()
    box1 = translate_topods_from_vector(box1, gp_Vec(.5, .5, 0))
    fusedshp = BRepAlgoAPI_Fuse(box1, box2).Shape()
    
    rnd = JupyterRenderer()
    rnd.DisplayShape(fusedshp, render_edges=True)
    rnd.Display()
Exemplo n.º 4
0
def cut(event=None):
    # Create Box
    Box = BRepPrimAPI_MakeBox(200, 60, 60).Shape()
    # Create Sphere
    Sphere = BRepPrimAPI_MakeSphere(gp_Pnt(100, 20, 20), 80).Shape()
    # Cut: the shere is cut 'by' the box
    Cut = BRepAlgoAPI_Cut(Sphere, Box).Shape()
    
    rnd = JupyterRenderer()
    rnd.DisplayShape(Box, transparency = True, opacity =0.2)
    rnd.DisplayShape(Cut, render_edges=True)
    rnd.Display()
Exemplo n.º 5
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_shp = BRepAlgoAPI_Section(torus, sphere, False)
        section_shp.ComputePCurveOn1(True)
        section_shp.Approximation(True)
        section_shp.Build()
        sections.append(section_shp)

    rnd = JupyterRenderer()
    rnd.DisplayShape(torus)
    rnd.Display()
Exemplo n.º 6
0
def common(event=None):
    # Create Box
    axe = gp_Ax2(gp_Pnt(10, 10, 10), gp_Dir(1, 2, 1))
    Box = BRepPrimAPI_MakeBox(axe, 60, 80, 100).Shape()
    # Create wedge
    Wedge = BRepPrimAPI_MakeWedge(60., 100., 80., 20.).Shape()
    # Common surface
    CommonSurface = BRepAlgoAPI_Common(Box, Wedge).Shape()

    rnd = JupyterRenderer()
    rnd.DisplayShape(Box, transparency = True, opacity =0.2)
    rnd.DisplayShape(Wedge, transparency = True, opacity =0.2)
    rnd.DisplayShape(CommonSurface, render_edges=True)
    rnd.Display()
Exemplo n.º 7
0
# coding: utf-8

# In[ ]:

from OCC.Core.BRepTools import breptools_Read
from OCC.Core.TopoDS import TopoDS_Shape
from OCC.Core.BRep import BRep_Builder

# In[ ]:

from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer

# In[ ]:

cylinder_head = TopoDS_Shape()
builder = BRep_Builder()
assert breptools_Read(cylinder_head, '../assets/models/cylinder_head.brep',
                      builder)

# In[ ]:

my_renderer = JupyterRenderer()

# In[ ]:

my_renderer.DisplayShape(cylinder_head, render_edges=True)

# In[ ]:

my_renderer
Exemplo n.º 8
0
from OCC.Core.Precision import precision_Angular
from OCC.Core.BRep import BRep_Tool_Surface
from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopAbs import TopAbs_FACE
from OCC.Core.Geom import Geom_Plane
from OCC.Core.TopoDS import topods_Face

# In[2]:

from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer

# Creation of the Jupyter Renderer

# In[3]:

my_renderer = JupyterRenderer()

# Generation of a box

# In[4]:

S = BRepPrimAPI_MakeBox(20., 30., 15.).Shape()

# Apply a draft angle.

# In[5]:

adraft = BRepOffsetAPI_DraftAngle(S)
topExp = TopExp_Explorer()
topExp.Init(S, TopAbs_FACE)
while topExp.More():
from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer

# Fuse two boxes.

# In[ ]:

box1 = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()
box2 = BRepPrimAPI_MakeBox(20., 1., 30.).Shape()
fused_shp = BRepAlgoAPI_Fuse(box1, box2).Shape()

# Display the union of two boxes. Edges appears from the input of the initial boxes' boundaries.

# In[ ]:

rnd = JupyterRenderer()
rnd.DisplayShape(fused_shp, render_edges=True, update=True)

# Apply the upgrading tool to unify the faces and edges.

# In[ ]:

shapeUpgrade = ShapeUpgrade_UnifySameDomain(fused_shp, False, True, False)
shapeUpgrade.Build()
fused_shp_upgrade = shapeUpgrade.Shape()

# In[ ]:

rnd_upgrade = JupyterRenderer()
rnd_upgrade.DisplayShape(fused_shp_upgrade, render_edges=True, update=True)
Exemplo n.º 10
0
# In[ ]:

import os

from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer, format_color
import ifcopenshell, ifcopenshell.geom

# In[ ]:

ifc_filename = os.path.join('..', 'assets', 'ifc_models',
                            'AC-11-Smiley-West-04-07-2007.ifc')
assert os.path.isfile(ifc_filename)

# In[ ]:

my_renderer = JupyterRenderer(size=(700, 700))

# In[ ]:

settings = ifcopenshell.geom.settings()
settings.set(settings.USE_PYTHON_OPENCASCADE,
             True)  # tells ifcopenshell to use pythonocc

# In[ ]:

ifc_file = ifcopenshell.open(ifc_filename)

# In[ ]:

products = ifc_file.by_type("IfcProduct")  # traverse all IfcProducts
Exemplo n.º 11
0

# create 3 toruses
# be careful to set copy to True or all the shapes will share the same mesh
torus_shp = BRepPrimAPI_MakeTorus(20, 5).Shape()
box_shp = translate_shp(BRepPrimAPI_MakeBox(10, 20, 3).Shape(), gp_Vec(60, 0, 0))
sphere_shp = translate_shp(BRepPrimAPI_MakeSphere(20.).Shape(), gp_Vec(-60, 0, 0))


# In[ ]:


# use the NORMAL.CLIENT_SIDE in order to clearly see faces
# in case the NORMAL.SERVER_SIDE option is used, vertex normals lead to
# a smooth rendering
my_renderer = JupyterRenderer()


# In[ ]:


def a_callback(shp):
    """ called each time a double click is performed
    """
    my_renderer.html.value = "Callback executed !"
my_renderer.register_select_callback(a_callback)


# In[ ]:

Exemplo n.º 12
0
#!/usr/bin/env python
# coding: utf-8

# In[ ]:

from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeSphere, BRepPrimAPI_MakeCylinder
from OCC.Core.gp import gp_Pnt

# In[ ]:

my_renderer = JupyterRenderer()

# In[ ]:

box_shape = BRepPrimAPI_MakeBox(10, 20, 30).Shape()
cylinder_shape = BRepPrimAPI_MakeCylinder(10, 30).Shape()

# In[ ]:

vertices = [gp_Pnt(5, 10, 40), gp_Pnt(10, -4, -10)]
my_renderer.DisplayShape(vertices)

# In[ ]:

my_renderer.DisplayShape(cylinder_shape,
                         render_edges=True,
                         topo_level="Face",
                         shape_color="#abdda4",
                         update=True)
Exemplo n.º 13
0
#!/usr/bin/env python
# coding: utf-8

# In[1]:

import os

from OCC.Core.gp import gp_Dir
from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer
from OCC.Extend.DataExchange import read_step_file, export_shape_to_svg

# In[2]:

my_renderer = JupyterRenderer()

# In[3]:

robot_shp = read_step_file(
    os.path.join('..', 'assets', 'models', 'KR600_R2830-4.stp'))

# In[5]:

my_renderer.DisplayShapeAsSVG(robot_shp,
                              direction=gp_Dir(1, 1, 0.1),
                              export_hidden_edges=False,
                              line_width=1.5)

# In[ ]:
Exemplo n.º 14
0
from random import randint

# In[ ]:

from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer, format_color
from OCC.Extend.TopologyUtils import TopologyExplorer
from OCC.Extend.DataExchange import read_step_file

# In[ ]:

shp = read_step_file(
    os.path.join('..', 'assets', 'models', 'RC_Buggy_2_front_suspension.stp'))

# In[ ]:

my_renderer = JupyterRenderer(size=(700, 700))

# In[ ]:

# loop over subshapes so that each subshape is meshed/displayed
t = TopologyExplorer(shp)
for solid in t.solids():
    # random colors, just for fun
    random_color = format_color(randint(0, 255), randint(0, 255),
                                randint(0, 255))
    my_renderer.DisplayShape(solid,
                             shape_color=random_color,
                             render_edges=True)

# In[ ]:
Exemplo n.º 15
0
a() = ShapeFromFile('%s');
""" % BREP_BASENAME
GEO_FILENAME = os.path.join(TMP_DIR, "ventilator.geo")
gmsh_file = open(GEO_FILENAME, "w")
gmsh_file.write(gmsh_file_content)
gmsh_file.close()
assert os.path.isfile(GEO_FILENAME)

# call gmsh, generate an STL file
STL_FILENAME = os.path.join(TMP_DIR, "ventilator.stl")
os.system("%s %s -2 -o %s -format stl" %
          (GMSH_BINARY, GEO_FILENAME, STL_FILENAME))
assert os.path.isfile(STL_FILENAME)

# load the stl file
meshed_ventilator_shp = read_stl_file(STL_FILENAME)

# In[ ]:

my_renderer = JupyterRenderer(size=(900, 900))

# In[ ]:

my_renderer.DisplayShape(translate_shp(ventilator_shp, gp_Vec(-100, 0, 0)),
                         render_edges=True,
                         shape_color="cyan")
my_renderer.DisplayShape(meshed_ventilator_shp,
                         render_edges=True,
                         shape_color="cyan",
                         update=True)
Exemplo n.º 16
0
 def DisplayShape(self, product, shp, color):
     for shp, sty in zip(self.subshapes(shp), color):
         Renderer.DisplayShape(self, shp, shape_color=sty[0:3], show=False, render_edges=True)
         self.products.append(product)
Exemplo n.º 17
0
 def __init__(self):
     Renderer.__init__(self)
     self.n = 0
     self.products = []
Exemplo n.º 18
0

# In[ ]:


from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer


# In[ ]:


# Build an helix
aCylinder = Geom_CylindricalSurface(gp_Ax3(gp_XOY()), 6.0)
aLine2d = gp_Lin2d (gp_Pnt2d(0.0, 0.0), gp_Dir2d(1.0, 1.0))
aSegment = GCE2d_MakeSegment(aLine2d, 0.0, pi * 2.0)

helix_edge = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCylinder, 0.0, 6.0 * pi).Edge()


# In[ ]:


my_renderer = JupyterRenderer()


# In[ ]:


my_renderer.DisplayShape(helix_edge, update=True)

Exemplo n.º 19
0
from OCC.Extend.ShapeFactory import translate_shp

# In[ ]:

# create 3 toruses
# be careful to set copy to True or all the shapes will share the same mesh
torus_shp1 = BRepPrimAPI_MakeTorus(20, 5).Shape()
torus_shp2 = translate_shp(torus_shp1, gp_Vec(60, 0, 0), copy=True)
torus_shp3 = translate_shp(torus_shp1, gp_Vec(-60, 0, 0), copy=True)

# In[ ]:

# use the NORMAL.CLIENT_SIDE in order to clearly see faces
# in case the NORMAL.SERVER_SIDE option is used, vertex normals lead to
# a smooth rendering
my_renderer = JupyterRenderer(compute_normals_mode=NORMAL.CLIENT_SIDE)

# In[ ]:

my_renderer.DisplayShape(torus_shp1,
                         shape_color="blue",
                         topo_level="Face",
                         quality=1.)  # default quality
my_renderer.DisplayShape(torus_shp2, shape_color="red",
                         quality=4)  # lower quality
my_renderer.DisplayShape(torus_shp3, shape_color="green",
                         quality=0.5)  # better quality

# In[ ]:

my_renderer
Exemplo n.º 20
0
#!/usr/bin/env python
# coding: utf-8

# In[ ]:

import os.path

# In[ ]:

from IPython.core.display import SVG
from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer
from OCC.Extend.DataExchange import read_step_file, export_shape_to_svg

# In[ ]:

shp = read_step_file(
    os.path.join('..', 'assets', 'models', 'RC_Buggy_2_front_suspension.stp'))

# In[ ]:

my_renderer = JupyterRenderer(size=(800, 700))

# In[ ]:

my_renderer.DisplayShape(shp, render_edges=True)

# In[ ]:

my_renderer.Display()
Exemplo n.º 21
0
    # the 9th line holds the number of points
    number_of_points = int(f.readline().split()[1])
    f.close()
    return number_of_points


# In[ ]:

pcd_file_name = os.path.join('..', 'assets', 'models', 'bunny.pcd')
# compute number of lines
nbr_of_vertices = pcd_get_number_of_vertices(pcd_file_name)
print("Number of vertices :", nbr_of_vertices)
vertices = []
# fedd it with vertices
fp = open(pcd_file_name, 'r')
# read 11 lines to skip header
for i in range(10):
    fp.readline()
for i in range(nbr_of_vertices):
    line = fp.readline()
    x, y, z = map(float, line.split())
    vertices.append(gp_Pnt(x, y, z))

# In[ ]:

my_renderer = JupyterRenderer()

# In[ ]:

my_renderer.DisplayShape(vertices, update=True)
Exemplo n.º 22
0
from OCC.Core.gp import gp_Pnt, gp_Vec
from OCC.Core.GeomAPI import GeomAPI_PointsToBSpline
from OCC.Core.TColgp import TColgp_Array1OfPnt
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakePrism

# In[2]:

# imports from Display and Extend
from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer

# Creation of the Jupyter Renderer

# In[3]:

my_renderer = JupyterRenderer()

# Generation of the bspline profile using an array of 5 points. The spline is interpolated through these points.

# In[4]:

# the bspline profile
array = TColgp_Array1OfPnt(1, 5)
array.SetValue(1, gp_Pnt(0, 0, 0))
array.SetValue(2, gp_Pnt(1, 2, 0))
array.SetValue(3, gp_Pnt(2, 3, 0))
array.SetValue(4, gp_Pnt(4, 3, 0))
array.SetValue(5, gp_Pnt(5, 5, 0))
bspline = GeomAPI_PointsToBSpline(array).Curve()
profile = BRepBuilderAPI_MakeEdge(bspline).Edge()