def get_brep():
    from OCC.BRep import BRep_Builder
    from OCC.BRepTools import breptools_Read
    from OCC.TopoDS import TopoDS_Shape

    cylinder_head = TopoDS_Shape()
    builder = BRep_Builder()
    breptools_Read(cylinder_head, './models/cylinder_head.brep', builder)
    return cylinder_head
Beispiel #2
0
def get_tess(brep_filename,js_filename):
  from OCC.BRepTools import breptools_Read
  from OCC.TopoDS import TopoDS_Shape
  from OCC.BRep import BRep_Builder
  from OCC.Visualization import Tesselator
  shape = TopoDS_Shape()
  builder = BRep_Builder()
  breptools_Read(shape, brep_filename, builder)
  tess = Tesselator(shape)
  tess.ExportShapeToJSON(js_filename)
Beispiel #3
0
def read_brep(brep_filepath):
    """
    This function writes a 3D model into brep format.
 
    Parameters
    ----------
    brep_filepath : str
        The file path of the brep file. 
        
    Returns
    -------
    occtopology : OCCtopology
        Geometries read from the brep.
        OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex 
    """       
    from OCC.BRepTools import breptools_Read
    from OCC.TopoDS import TopoDS_Shape
    from OCC.BRep import BRep_Builder
    
    shape = TopoDS_Shape()
    builder = BRep_Builder()
    breptools_Read(shape, brep_filepath, builder)
    return shape
Beispiel #4
0
def read_brep(brep_filepath):
    """
    This function writes a 3D model into brep format.
 
    Parameters
    ----------
    brep_filepath : str
        The file path of the brep file. 
        
    Returns
    -------
    occtopology : OCCtopology
        Geometries read from the brep.
        OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex 
    """
    from OCC.BRepTools import breptools_Read
    from OCC.TopoDS import TopoDS_Shape
    from OCC.BRep import BRep_Builder

    shape = TopoDS_Shape()
    builder = BRep_Builder()
    breptools_Read(shape, brep_filepath, builder)
    return shape
Beispiel #5
0
def read_brep(filename):
    """
    Reads in a brep file

    :return: The shape
    """
    if not Path(filename).is_file():
        print("File not found: " + filename)
        raise FileNotFoundError(filename)

    b = BRep_Builder()
    shape = TopoDS_Shape()
    if not breptools_Read(shape, filename, b):
        raise RuntimeError("Cannot read brep file: " + filename)
    return shape
def draw_lineandvertices(event=None):
    Line_1 = TopoDS_Shape()
    Vertex_1 = TopoDS_Shape()
    Vertex_2 = TopoDS_Shape()
    builder = BRep_Builder()
    builder1 = BRep_Builder()
    compound = TopoDS_Compound()
    builder1.MakeCompound(compound)
    breptools_Read(Line_1, 'Line_1.brep', builder)
    breptools_Read(Vertex_1, 'Vertex_1.brep', builder)
    breptools_Read(Vertex_2, 'Vertex_2.brep', builder)
    builder1.Add(compound,Line_1)
    builder1.Add(compound,Vertex_1)
    builder1.Add(compound,Vertex_2)

    #display.DisplayShape({Line_1, Vertex_1, Vertex_2}, update=True)
    #display.DisplayShape(Group_1, update=True)
    display.DisplayShape(compound, update=True)
    breptools_Write(compound, 'compound.brep')

    display.FitAll()
Beispiel #7
0
##Copyright 2010-2014 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.SimpleGui import init_display
from OCC.BRepTools import breptools_Read
from OCC.TopoDS import TopoDS_Shape
from OCC.BRep import BRep_Builder

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

display, start_display, add_menu, add_function_to_menu = init_display()
display.DisplayShape(cylinder_head, update=True)
start_display()
Beispiel #8
0
def __import__brep__(fname):
    s = TopoDS_Shape()
    if breptools_Read(s, fname, BRep_Builder()):
        return s
    else:
        raise IOError("Can't import file "+fname)
Beispiel #9
0
def load_brep(BRepFile):
    BRepShape = TopoDS_Shape()
    builder = BRep_Builder()
    breptools_Read(BRepShape, BRepFile, builder)

    return BRepShape
Beispiel #10
0
 def load_brep(self, path):
     """ Load a brep model """
     shape = TopoDS_Shape()
     builder = BRep_Builder()
     breptools_Read(shape, path, builder)
     return shape
##
##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 x3dom_renderer
from OCC.BRep import BRep_Builder
from OCC.TopoDS import TopoDS_Shape
from OCC.BRepTools import breptools_Read

# loads brep shape
cylinder_head = TopoDS_Shape()
builder = BRep_Builder()
breptools_Read(cylinder_head, './models/cylinder_head.brep', builder)

# render cylinder head in x3dom
my_renderer = x3dom_renderer.X3DomRenderer()
my_renderer.DisplayShape(cylinder_head)
my_renderer.render()
Beispiel #12
0
def get_brep():
    cylinder_head = TopoDS_Shape()
    builder = BRep_Builder()
    breptools_Read(cylinder_head, './models/cylinder_head.brep', builder)
    return cylinder_head
Beispiel #13
0
##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.SimpleGui import init_display
from OCC.BRepTools import breptools_Read
from OCC.TopoDS import TopoDS_Shape
from OCC.BRep import BRep_Builder

Line_1 = TopoDS_Shape()
Vertex_1 = TopoDS_Shape()
Vertex_2 = TopoDS_Shape()
builder = BRep_Builder()
breptools_Read(Line_1, 'Line_1.brep', builder)
breptools_Read(Vertex_1, 'Vertex_1.brep', builder)
breptools_Read(Vertex_2, 'Vertex_2.brep', builder)

display, start_display, add_menu, add_function_to_menu = init_display()
display.DisplayShape(Line_1, update=True)
display.DisplayShape(Vertex_1, update=True)
display.DisplayShape(Vertex_2, update=True)
start_display()
def get_brep():
    cylinder_head = TopoDS_Shape()
    builder = BRep_Builder()
    breptools_Read(cylinder_head, './models/cylinder_head.brep', builder)
    return cylinder_head
Beispiel #15
0
def loadBRep(filename):
    builder = BRep_Builder()
    shape = TopoDS_Shape()
    breptools_Read(shape, filename, builder)
    return shape
Beispiel #16
0
    # Number of points
    n = 100000

    # List for storing TopoDS_Shape instances of vertices if required.
    vertexList = []

    # Set the side length
    side_length = 10.0
    # The side length of the box that contains the shapes that will be tested
    xSideLength = ySideLength = zSideLength = 0.0
    xMin = xMax = yMin = yMax = zMin = zMax = 0.0

    # Read the file to get the shape to be sampled.
    shape = TopoDS_Shape()
    builder = BRep_Builder()
    breptools_Read(shape, "cubeWithHole.brep", builder)

    # Loop over the shape pulled from the input and look for solids.
    solids = []  # A list for storing solids from the file
    i = 0  # A counter for writing vertices/points
    allPointsDataFrame = pd.DataFrame([])  # A dataframe for ALL points
    # OpenCASCADE can only successfully execute point inclusion queries if the
    # shape in question is a full solid, which is defined in their topology as
    # TopAbs_SOLID. Each solid in the file can sampled individually by pulling
    # it from the compound.
    if shape.ShapeType() != TopAbs_SOLID:
        # Create a topology explorer and pull all the solids from the shape
        explorer = TopExp_Explorer(shape, TopAbs_SOLID)
        # Loop over all the solids
        while explorer.More():
            solid = explorer.Current()
Beispiel #17
0
def get_tess(brep_filename,js_filename):
  shape = TopoDS_Shape()
  builder = BRep_Builder()
  breptools_Read(shape, str(brep_filename), builder)
  tess = Tesselator(shape)
  tess.ExportShapeToJSON(str(js_filename))
##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 OCC.Display.SimpleGui import init_display
from OCC.Graphic3d import Graphic3d_RenderingParams
from OCC.BRepTools import breptools_Read
from OCC.TopoDS import TopoDS_Shape
from OCC.BRep import BRep_Builder

display, start_display, add_menu, add_function_to_menu = init_display()

# loads the motor model
motor_c = TopoDS_Shape()
builder = BRep_Builder()
breptools_Read(motor_c, '../assets/models/Motor-c.brep', builder)
display.DisplayShape(motor_c, update=True)

def perspective(event=None):
    display.SetPerspectiveProjection()
    display.FitAll()

def orthographic(event=None):
    display.SetOrthographicProjection()
    display.FitAll()

def anaglyph_red_cyan(event=None):
    display.SetAnaglyphMode(Graphic3d_RenderingParams.Anaglyph_RedCyan_Simple)
    display.FitAll()

def anaglyph_red_cyan_optimized(event=None):