def test_iter(self): """ Test __iter__ method. """ s1 = TopoDS_Shape() s2 = TopoDS_Shape() s3 = TopoDS_Shape() shape_list = TopoDS_ListOfShape() shape_list.Append(s1) shape_list.Append(s2) shape_list.Append(s3) self.assertEqual(shape_list.Size(), 3) for s in shape_list: self.assertIsInstance(s, TopoDS_Shape)
def load_brep(filename): """ Load a brep model """ shape = TopoDS_Shape() builder = BRep_Builder() BRepTools.Read_(shape, filename, builder, None) # TODO: Load colors return [TopoShape(shape=shape)]
def read_brep(fn): """ Read a BREP file and return as a single shape. :param str fn: Filename. :return: The shape. :rtype: OCCT.TopoDS.TopoDS_Shape """ shape = TopoDS_Shape() builder = BRep_Builder() BRepTools.Read_(shape, fn, builder) return shape
def read_brep(fn): """ Read a BREP file and return the shape. :param str fn: The filename. :return: The shape. :rtype: afem.topology.entities.Shape """ shape = TopoDS_Shape() builder = BRep_Builder() BRepTools.Read_(shape, fn, builder) return Shape.wrap(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 OCCT.BRep import BRep_Builder from OCCT.TopoDS import TopoDS_Shape from OCCT.BRepTools import breptools_Read # loads brep shape cylinder_head = TopoDS_Shape() builder = BRep_Builder() breptools_Read(cylinder_head, '../assets/models/cylinder_head.brep', builder) # render cylinder head in x3dom my_renderer = x3dom_renderer.X3DomRenderer() my_renderer.DisplayShape(cylinder_head) my_renderer.render()
##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 OCC.Display.SimpleGui import init_display from OCCT.Graphic3d import Graphic3d_RenderingParams from OCCT.BRepTools import breptools_Read from OCCT.TopoDS import TopoDS_Shape from OCCT.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()
import os from OCCT.BRep import BRep_Builder from OCCT.BRepTools import breptools from OCCT.BRepAdaptor import BRepAdaptor_CompCurve, BRepAdaptor_HCompCurve from OCCT.ShapeAnalysis import ShapeAnalysis_Curve from OCCT.TopoDS import TopoDS_Shape, topods from OCCT.gp import gp_Pnt from OCCT.Approx import Approx_Curve3d from OCCT.GeomAbs import GeomAbs_C2 from OCCT.GeomAPI import GeomAPI_ProjectPointOnCurve # Read wire wire_filename = os.path.join('..', 'assets', 'models', 'wire.brep') shp = TopoDS_Shape() aBuilder = BRep_Builder() breptools.Read(shp, wire_filename, aBuilder) wire = topods.Wire(shp) if wire.IsNull(): raise AssertionError("Wire is Null") # discretize the wire and interpolate using a C2 wireAdaptor = BRepAdaptor_CompCurve(wire) curve = BRepAdaptor_HCompCurve(wireAdaptor) tol = 1e-7 max_segments = 200 max_degrees = 12 approx = Approx_Curve3d(curve, tol, GeomAbs_C2, max_segments, max_degrees) if (approx.IsDone() and approx.HasResult()): an_approximated_curve = approx.Curve()
def load_brep(self, path): """ Load a brep model """ shape = TopoDS_Shape() builder = BRep_Builder() BRepTools.Read_(shape, path, builder, None) return [TopoShape(shape=shape)]
def get_brep(): cylinder_head = TopoDS_Shape() builder = BRep_Builder() breptools_Read(cylinder_head, '../assets/models/cylinder_head.brep', builder) return cylinder_head