def display_str_at_pos(stri, col, line): brepstr = text_to_brep(stri, "Arial", Font_FA_Bold, 12., True) # translate the letter to the right brepstr_translated = translate_shp(brepstr, gp_Vec(col * 8, -line * 10, 0)) brepstr_extruded = make_extrusion(brepstr_translated, 2.5) display.DisplayColoredShape(brepstr_extruded, 'WHITE') display.Repaint()
def test_measure_shape_center_of_gravity(self): # we compute the cog of a sphere centered at a point P # then the cog must be P x, y, z = 10.0, 3.0, -2.44 # random values for point P radius = 20.0 vector = gp_Vec(x, y, z) sph = translate_shp(BRepPrimAPI_MakeSphere(radius).Shape(), vector) cog, mass, mass_property = measure_shape_mass_center_of_gravity(sph) self.assertAlmostEqual(cog.X(), x, places=6) self.assertAlmostEqual(cog.Y(), y, places=6) self.assertAlmostEqual(cog.Z(), z, places=6) self.assertAlmostEqual(mass, 4 / 3 * math.pi * radius**3, places=6) self.assertEqual(mass_property, "Volume")
from OCC.Display.WebGl import threejs_renderer from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeTorus from OCC.Core.gp import gp_Vec from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer, NORMAL from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox sys.path.append('..') 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
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()) print("%i%%" % (idx * 100 / n_toruses), end="") idx += 1 my_ren.render()
import sys from OCC.Display.SimpleGui import init_display from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeCone from OCC.Core.Graphic3d import Graphic3d_NOM_PLASTIC, Graphic3d_NOM_ALUMINIUM from OCC.Core.V3d import V3d_SpotLight, V3d_COMPLETE, V3d_XnegYnegZpos from OCC.Core.Quantity import Quantity_NOC_WHITE, Quantity_NOC_CORAL2, Quantity_NOC_BROWN from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut from OCC.Core.gp import gp_Vec from OCC.Extend.ShapeFactory import translate_shp # first create geometry from core_classic_occ_bottle import bottle table = translate_shp(BRepPrimAPI_MakeBox(100, 100, 10).Shape(), gp_Vec(-50, -50, -10)) glass_out = BRepPrimAPI_MakeCone(7, 9, 25).Shape() glass_in = translate_shp(BRepPrimAPI_MakeCone(7, 9, 25).Shape(), gp_Vec(0., 0., 0.2)) glass = BRepAlgoAPI_Cut(glass_out, glass_in).Shape() translated_glass = translate_shp(glass, gp_Vec(-30, -30, 0)) # then inits display display, start_display, add_menu, add_function_to_menu = init_display() # create one spotlight spot_light = V3d_SpotLight(display.Viewer, -100, -100, 100, V3d_XnegYnegZpos, Quantity_NOC_WHITE) ## display the spotlight in rasterized mode spot_light.Display(display.View, V3d_COMPLETE) display.View.SetLightOn()
from __future__ import print_function import random from OCC.Display.WebGl import threejs_renderer from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeTorus from OCC.Core.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
breptools_Write(ventilator_shp, BREP_FILENAME) assert os.path.isfile(BREP_FILENAME) # create the gmesh file gmsh_file_content = """SetFactory("OpenCASCADE"); Mesh.CharacteristicLengthMin = 1; Mesh.CharacteristicLengthMax = 5; 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) display.DisplayShape(translate_shp(ventilator_shp, gp_Vec(-100, 0, 0))) display.DisplayShape(meshed_ventilator_shp) start_display()
##(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.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeSphere from OCC.Display.SimpleGui import init_display from OCC.Core.gp import gp_Vec, gp_Pnt from OCC.Extend.ShapeFactory import translate_shp display, start_display, add_menu, add_function_to_menu = init_display() # Create Box box = BRepPrimAPI_MakeBox(200, 60, 60).Shape() # Create Sphere sphere = BRepPrimAPI_MakeSphere(gp_Pnt(100, 20, 20), 80).Shape() # move the sphere moved_sphere = translate_shp(sphere, gp_Vec(0., -200., 0.)) ais_box = display.DisplayShape(box) display.Context.SetTransparency(ais_box, 0.1) ais_sphere = display.DisplayColoredShape(moved_sphere, color="BLUE") display.Context.SetTransparency(ais_sphere, 0.9) display.FitAll() start_display()
"Hello world": "Arial", # English "Bonjour monde": "Arial", # French "Hallo Welt": "Arial", # German "γειά σου κόσμος": "Calibri", # Greek "Ciao mondo": "Arial", # Italian "こんにちは世界": "Microsoft Yahei", # Japanese "여보세요 세계": "Malgun Gothic", # Korean "Olá mundo": "Arial", # Portuguese "Здравствулте мир": "Microsoft Yahei", # Russian "Hola mundo": "Arial" # Spanish } arialbold_brep_string = text_to_brep("hello from pythonocc !", "Arial", Font_FA_Regular, 12., True) ## Then display the string display.DisplayShape(arialbold_brep_string) for hello_str in hello: rndm_size = random.uniform(10., 16.) font = hello[hello_str] brep_string = text_to_brep(hello_str, font, Font_FA_Regular, rndm_size, True) rndm_extrusion_depth = random.uniform(8., 16.) rndm_extrusion_direction = gp_Vec(random.random(), random.random(), random.random()) extruded_string = make_extrusion(brep_string, rndm_extrusion_depth, rndm_extrusion_direction) rndm_pos = gp_Vec(random.random()*100-50, random.random()*100-50, random.random()*100-50) rndm_color = Quantity_Color(random.random(), random.random(), random.random(), Quantity_TOC_RGB) trs_shp = translate_shp(extruded_string, rndm_pos) display.DisplayColoredShape(trs_shp, rndm_color) display.FitAll() start_display()
import random from OCC.Display.WebGl import x3dom_renderer from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox from OCC.gp import gp_Vec from OCC.Extend.ShapeFactory import translate_shp, rotate_shp_3_axis my_ren = x3dom_renderer.X3DomRenderer() for i in range(100): box_shp = BRepPrimAPI_MakeBox(random.random() * 20, random.random() * 20, random.random() * 20).Shape() # random position and orientation and color angle_x = random.random() * 360 angle_y = random.random() * 360 angle_z = random.random() * 360 rotated_box = rotate_shp_3_axis(box_shp, angle_x, angle_y, angle_z, 'deg') tr_x = random.uniform(-20, 20) tr_y = random.uniform(-20, 20) tr_z = random.uniform(-20, 20) trans_box = translate_shp(rotated_box, gp_Vec(tr_x, tr_y, tr_z)) rnd_color = (random.random(), random.random(), random.random()) my_ren.DisplayShape(trans_box, export_edges=True, color=rnd_color, transparency=random.random()) my_ren.render()
Graphic3d_NOM_SHINY_PLASTIC, Graphic3d_NOM_SATIN, Graphic3d_NOM_METALIZED, Graphic3d_NOM_NEON_GNC, Graphic3d_NOM_CHROME, Graphic3d_NOM_ALUMINIUM, Graphic3d_NOM_OBSIDIAN, Graphic3d_NOM_NEON_PHC, Graphic3d_NOM_JADE, Graphic3d_NOM_CHARCOAL, Graphic3d_NOM_WATER, Graphic3d_NOM_GLASS, Graphic3d_NOM_DIAMOND, Graphic3d_NOM_TRANSPARENT, Graphic3d_NOM_DEFAULT, Graphic3d_NOM_UserDefined] # # Displays a cylinder with a material # radius = 30 s = BRepPrimAPI_MakeCylinder(radius, 200).Shape() delta_x = 0. for mat in available_materials: s2 = translate_shp(s, gp_Vec(delta_x, 0., 0.)) display.DisplayShape(s2, material=mat) delta_x += 2 * radius + 1. display.FitAll() start_display()
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)
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeTorus, BRepPrimAPI_MakeBox, BRepPrimAPI_MakeSphere from OCC.Core.gp import gp_Vec from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer, NORMAL from OCC.Core.GProp import GProp_GProps from OCC.Core.BRepGProp import brepgprop_VolumeProperties 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_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[ ]: