Пример #1
0
 def test_x3dom_render_torus(self):
     """ Render a simple torus using x3dom
     """
     my_x3dom_renderer = x3dom_renderer.X3DomRenderer()
     dict_shape, dict_edge = my_x3dom_renderer.DisplayShape(torus_shp)
     self.assertTrue(dict_shape)
     self.assertTrue(not dict_edge)
 def test_x3dom_random_mesh_quality(self):
     """ Test: threejs 10 random boxes
     """
     my_x3dom_renderer = x3dom_renderer.X3DomRenderer()
     my_x3dom_renderer.DisplayShape(torus_shp, mesh_quality=1.0)
     my_x3dom_renderer.DisplayShape(torus_shp, mesh_quality=0.8)
     my_x3dom_renderer.DisplayShape(torus_shp, mesh_quality=2.0)
Пример #3
0
 def test_x3dom_render_torus(self):
     '''Test: point from curve'''
     torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
     my_renderer = x3dom_renderer.X3DomRenderer(path="./test_io")
     x3d_file, html_file = my_renderer.create_files(torus_shp)
     assert os.path.isfile(x3d_file)
     assert os.path.isfile(html_file)
Пример #4
0
    def render_locally(self,
                       addr="localhost",
                       server_port=8080,
                       open_webbrowser=False,
                       render_engine="threejs",
                       resolution=(1800, 900)):
        from OCC.Display.WebGl.simple_server import start_server

        if render_engine == "xdom":
            from OCC.Display.WebGl import x3dom_renderer

            my_renderer = x3dom_renderer.X3DomRenderer()
            # TODO: Find similarities in build processing as done for THREE.js (tesselate geom etc..).
            # my_renderer.DisplayShape(shape.profile_curve_outer.wire)
            # my_renderer.DisplayShape(shape.sweep_curve.wire)
            # my_renderer.DisplayShape(shape.geom)
            my_renderer.render()
        else:  # Assume THREEJS
            from ipywidgets.embed import embed_minimal_html

            from ada.base.renderer import MyRenderer

            _path = pathlib.Path("temp/index.html").resolve().absolute()

            renderer = MyRenderer(resolution)
            renderer.DisplayObj(self)
            renderer.build_display()

            os.makedirs(_path.parent, exist_ok=True)
            embed_minimal_html(_path,
                               views=renderer._renderer,
                               title="Pythreejs Viewer")
            start_server(addr, server_port, str(_path.parent), open_webbrowser)
Пример #5
0
 def test_x3dom_render_torus(self):
     '''Test: point from curve'''
     torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
     my_renderer = x3dom_renderer.X3DomRenderer()
     my_renderer.DisplayShape(torus_shp)
     assert os.path.isfile('./shape.x3d')
     assert os.path.isfile('./x3dom_topods_shape.html')
Пример #6
0
 def Exchange_stp_3xd(self):
     try:
         for file in self.file_list:
             if "stp" in file or "step" in file or "iges" in file :
                 try:
                     the_shape = read_step_file(file)
                     my_renderer = x3dom_renderer.X3DomRenderer("./")
                     name=file.split(".")
                     my_renderer.DisplayShape(the_shape,export_edges=True,color=(random(), random(), random()),file_name=name[0])
                     
                     #if file=="iseg":
                         #pass
                     #else:
                         #the_shape = read_step_file(file)
                         #ais_shape=AIS_ColoredShape(the_shape)
                         #for e in TopologyExplorer(the_shape).shells():
                             #rnd_color = (random(), random(), random())
                             #ais_shape.SetCustomColor(e, rgb_color(random(), random(), random()))
                             #display.EraseAll()
                             #context.Display(ais_shape,True)
                             #display.FitAll()
                             #path='./'+name[0]+".bmp"
                             #display.View.Dump(path)
                         
                 except:
                     pass             
     except:
         pass
Пример #7
0
 def test_x3d_edge(self):
     """Test: threejs 10 random boxes"""
     my_x3dom_renderer = x3dom_renderer.X3DomRenderer()
     for edg in TopologyExplorer(torus_shp).edges():
         dict_shape, dict_edge = my_x3dom_renderer.DisplayShape(
             edg, mesh_quality=1.0)
         self.assertTrue(not dict_shape)
         self.assertTrue(dict_edge)
 def test_x3dom_random_mesh_quality(self):
     """ Test: threejs 10 random boxes
     """
     my_x3dom_renderer = x3dom_renderer.X3DomRenderer()
     torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
     my_x3dom_renderer.DisplayShape(torus_shp, mesh_quality=1.0)
     my_x3dom_renderer.DisplayShape(torus_shp, mesh_quality=0.8)
     my_x3dom_renderer.DisplayShape(torus_shp, mesh_quality=2.0)
 def test_x3dom_random_boxes(self):
     """ Test: threejs 10 random boxes
     """
     my_x3dom_renderer = x3dom_renderer.X3DomRenderer()
     for i in range(10):
         box_shp = BRepPrimAPI_MakeBox(random.random()*20, random.random()*20, random.random()*20).Shape()
         rnd_color = (random.random(), random.random(), random.random())
         rnd_export_edges = bool(random.random() > 0.5)
         my_x3dom_renderer.DisplayShape(box_shp, export_edges=True, color=rnd_color, transparency=random.random())
Пример #10
0
 def Exchange_stp_3xd(self):
     try:
         for file in self.file_list:
             if "stp" in file or "step" in file or "iges" in file :
                 try:
                     the_shape = read_step_file(file)
                     my_renderer = x3dom_renderer.X3DomRenderer("./")
                     name=file.split(".")
                     my_renderer.DisplayShape(the_shape,export_edges=True,color=(random(), random(), random()),file_name=name[0])
                 except:
                     pass
               
     except:
         pass
Пример #11
0
def Exchange_stp_3xd(file="aaa.stp",path="."):
    pass
    file=file
    global num_click
    num_click+=1
    try:
        os.mkdir(str(num_click))
    except:
        pass
    the_shape = read_step_file(file)
    path=str(num_click)
    my_renderer = x3dom_renderer.X3DomRenderer(path=path)
    my_renderer.DisplayShape(the_shape,export_edges=True,color=(random(), random(), random()))
    my_renderer.run()
    os.path.join(path, "index.html")
    path="."+"\\"+ path +"\\"+"index.html"
    print(path)

    with open(path,"r") as f:
          html=f.read()
          f.close()
    return html
 def test_x3dom_render_torus(self):
     """ Render a simple torus using x3dom
     """
     torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
     my_x3dom_renderer = x3dom_renderer.X3DomRenderer()
     my_x3dom_renderer.DisplayShape(torus_shp)
Пример #13
0
 def test_x3dom_render_torus(self):
     """ Render a simple torus using x3dom
     """
     my_x3dom_renderer = x3dom_renderer.X3DomRenderer()
     my_x3dom_renderer.DisplayShape(torus_shp)
Пример #14
0
from OCC.Core.Bnd import Bnd_Box
from OCC.Core.BRepBndLib import brepbndlib_Add
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeCylinder
from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh
from OCC.Core.Quantity import Quantity_Color
from OCC.Core.Quantity import Quantity_Color, Quantity_TOC_RGB
from OCC.Display.SimpleGui import init_display
from OCC.Display.OCCViewer import Viewer3d
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox

the_shape = read_step_file('SFU01610-4.step')
print(type(the_shape))
# 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(path="d:\\123")
ais_shape = AIS_ColoredShape(the_shape)

#display.DisplayShape(my_box,update=True)
#display.Context.Display(cube,True)
for e in TopologyExplorer(the_shape).shells():
    rnd_color = (random(), random(), random())
    ais_shape.SetCustomColor(e, rgb_color(random(), random(), random()))
    my_renderer.DisplayShape(e,
                             export_edges=True,
                             color=(random(), random(), random()))

my_renderer.render()
Пример #15
0
def test_sweep_curve():
    sweep_curve = [(1, 1, 0), (5, 5.0, 0.0, 1), (10, 1, 0)]
    curve = CurvePoly(points3d=sweep_curve, is_closed=False)
    my_renderer = x3dom_renderer.X3DomRenderer()
    my_renderer.DisplayShape(curve.wire, export_edges=True)
Пример #16
0
 def test_sweep_curve(self):
     curve = CurvePoly(points3d=sweep_curve, is_closed=False)
     my_renderer = x3dom_renderer.X3DomRenderer()
     my_renderer.DisplayShape(curve.wire, export_edges=True)
Пример #17
0
def main():
    # Construct the argument parser
    argp = argparse.ArgumentParser(
        prog='renderOCX',
        usage='%(prog)s [options] OCXfile schema',
        description=
        "Renders the whole OCX model or a part identified by the guid.")
    # Add the arguments to the parser
    argp.add_argument("-file",
                      type=str,
                      help="Your input OCX file.",
                      default='OCX_Models/Submission_V1.xml')
    argp.add_argument("-schema",
                      type=str,
                      help="URI to OCX schema xsd",
                      default='OCX_Models/OCX_Schema.xsd')
    argp.add_argument(
        "-e",
        "--external",
        default=True,
        type=bool,
        help="Render the model from the external geometry. This is the default"
    )
    argp.add_argument(
        "-s",
        "--solid",
        default=False,
        type=bool,
        help=
        "Render a solid model. The default is to render a sheet model. This option is only used if option -external=no"
    )
    argp.add_argument(
        "-l",
        "--log",
        default=True,
        type=bool,
        help="Output logging information. This is useful for debugging")
    #    argp.add_argument("-g", "--guid", default='{0010A20F-0000-0000-453F-D518A55C2204}',type=str, help="The GUIDRef of the shape to be rendered. If empty, the whole model is rendered")
    argp.add_argument(
        "-g",
        "--guid",
        default='none',
        type=str,
        help=
        "The GUIDRef of the shape to be rendered. If empty, the whole model is rendered"
    )
    argp.add_argument("-r",
                      "--render",
                      default=False,
                      type=bool,
                      help="If True, render the model")
    argp.add_argument("-st",
                      "--step",
                      default=True,
                      type=bool,
                      help="Export the OCX model to STEP")
    options = argp.parse_args()
    guid = options.guid
    ext = options.external
    # Verify that the model and schema exist
    # create the model parser
    model = OCXParser.OCXmodel(options.file, options.schema, options.log)
    model.importModel()
    # Create the geometry creator
    geom = OCXGeometry.OCXGeometry(model, model.dict, options.log)
    # Render only one part
    if not guid == 'none':
        if ext == True:
            shapes = geom.externalPartGeometry(guid)
        else:
            shapes = geom.createPartGeometry(guid, options.solid)
    else:
        if ext == True:
            shapes = geom.externalGeometryAssembly()
        else:
            shapes = geom.createGeometry(options.solid)
    if options.render:
        #Render shapes
        my_renderer = x3dom_renderer.X3DomRenderer()
        if isinstance(shapes, list):
            for shape in shapes:
                my_renderer.DisplayShape(shape, export_edges=False)
        elif not shapes == None:
            my_renderer.DisplayShape(shapes, export_edges=False)
        else:
            print('No shapes to render')
        my_renderer.render()
##(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.Extend.DataExchange import read_step_file_with_names_colors
from OCC.Extend.TopologyUtils import TopologyExplorer
from OCC.Display.WebGl import x3dom_renderer

filename = '../assets/models/as1-oc-214.stp'
shapes_labels_colors = read_step_file_with_names_colors(filename)

# create the x3dom renderer
my_renderer = x3dom_renderer.X3DomRenderer()

# traverse shapes, render in "face" mode
for shpt_lbl_color in shapes_labels_colors:
    shape, label, c = shpt_lbl_color
    all_faces = TopologyExplorer(shape).faces()
    for face in all_faces:
        my_renderer.DisplayShape(face,
                                 color=(c.Red(), c.Green(), c.Blue()),
                                 export_edges=True)

my_renderer.render()
Пример #19
0
##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.STEPControl import STEPControl_Reader
from OCC.BRepAlgoAPI import BRepAlgoAPI_Cut
from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.gp import gp_Vec, gp_Trsf
from OCC.BRepBuilderAPI import BRepBuilderAPI_Transform
from OCC.Display.WebGl import x3dom_renderer

# loads file
step_reader = STEPControl_Reader()
step_reader.ReadFile('../_models/cylinder_block_mold_model.stp')
step_reader.TransferRoot()
block_cylinder_shape = step_reader.Shape()

# create box
box = BRepPrimAPI_MakeBox(30, 90, 90).Shape()
trns = gp_Trsf()
trns.SetTranslation(gp_Vec(0, -35, -35))
mold_basis = BRepBuilderAPI_Transform(box, trns).Shape()

# compute mold print
mold = BRepAlgoAPI_Cut(mold_basis, block_cylinder_shape).Shape()

# export to X3D
my_webgl_renderer = x3dom_renderer.X3DomRenderer()
my_webgl_renderer.DisplayShape(mold)