def read_iges(file_name): iges_reader = IGESControl_Reader() status = iges_reader.ReadFile(file_name) if status == IFSelect_RetDone: failsonly = False iges_reader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity) iges_reader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity) ok = iges_reader.TransferRoots() IgesShape = iges_reader.OneShape() return IgesShape else: print("Error: can't read file.") sys.exit(0)
def load_shape_from_file(self, filename): """ This class method loads a shape from the file `filename`. :param string filename: name of the input file. It should have proper extension (.iges or .igs) :return: shape: loaded shape :rtype: TopoDS_Shape """ self._check_filename_type(filename) self._check_extension(filename) reader = IGESControl_Reader() return_reader = reader.ReadFile(filename) # check status if return_reader == IFSelect_RetDone: return_transfer = reader.TransferRoots() if return_transfer: # load all shapes in one shape = reader.OneShape() return shape
def read(cls, filename): controller = IGESControl_Controller() controller.Init() reader = IGESControl_Reader() reader.ReadFile(filename) reader.TransferRoots() shape = reader.OneShape() n_faces = 0 control_point_position = [0] faces_explorer = TopExp_Explorer(shape, TopAbs_FACE) mesh_points = np.zeros(shape=(0, 3)) while faces_explorer.More(): # performing some conversions to get the right format (BSplineSurface) face = topods_Face(faces_explorer.Current()) nurbs_converter = BRepBuilderAPI_NurbsConvert(face) nurbs_converter.Perform(face) nurbs_face = nurbs_converter.Shape() brep_face = BRep_Tool.Surface(topods_Face(nurbs_face)) bspline_face = geomconvert_SurfaceToBSplineSurface(brep_face) # openCascade object occ_face = bspline_face.GetObject() # extract the Control Points of each face n_poles_u = occ_face.NbUPoles() n_poles_v = occ_face.NbVPoles() control_polygon_coordinates = np.zeros(shape=(n_poles_u * n_poles_v, 3)) # cycle over the poles to get their coordinates i = 0 for pole_u_direction in range(n_poles_u): for pole_v_direction in range(n_poles_v): print(pole_u_direction, pole_v_direction) control_point_coordinates = occ_face.Pole( pole_u_direction + 1, pole_v_direction + 1) control_polygon_coordinates[i, :] = [ control_point_coordinates.X(), control_point_coordinates.Y(), control_point_coordinates.Z() ] i += 1 # pushing the control points coordinates to the mesh_points array # (used for FFD) mesh_points = np.append(mesh_points, control_polygon_coordinates, axis=0) control_point_position.append(control_point_position[-1] + n_poles_u * n_poles_v) n_faces += 1 faces_explorer.Next() return { 'shape': shape, 'points': mesh_points, 'control_point_position': control_point_position }