示例#1
0
 def create_shape(self):
     d = self.declaration
     u = min(2 * pi, max(0, d.angle))
     vmin = max(-pi / 2, min(d.angle2, d.angle3))
     vmax = min(pi / 2, max(d.angle2, d.angle3))
     sphere = BRepPrimAPI_MakeSphere(coerce_axis(d.axis), d.radius, vmin,
                                     vmax, u)
     self.shape = sphere.Shape()
示例#2
0
 def test_creat_face(self):
     # create a box
     my_face = Face(BRepPrimAPI_MakeSphere(1., 1.).Face())
     assert not my_face.IsNull()
     assert my_face.tolerance == 1e-06
     assert not my_face.is_planar()
     assert my_face.is_trimmed()
def generate_shape():
    """Create a sphere with faces top and bottom"""
    sphere_radius = 1.0
    sphere_angle = atan(0.5)
    sphere_origin = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))
    sphere = BRepPrimAPI_MakeSphere(sphere_origin, sphere_radius,
                                    -sphere_angle, sphere_angle).Shape()
    return sphere
示例#4
0
class SphereByRadius(object):
    """
    Create a sphere by a center and radius.

    :param point_like origin: The origin.
    :param float radius: The radius.
    """
    def __init__(self, origin=(0., 0., 0.), radius=1.):
        origin = CheckGeom.to_point(origin)

        self._builder = BRepPrimAPI_MakeSphere(origin, radius)

    @property
    def face(self):
        """
        :return: The sphere as a face.
        :rtype: afem.topology.entities.Face
        """
        return Face(self._builder.Face())

    @property
    def shell(self):
        """
        :return: The sphere as a shell.
        :rtype: afem.topology.entities.Shell
        """
        return Shell(self._builder.Shell())

    @property
    def solid(self):
        """
        :return: The sphere as a solid.
        :rtype: afem.topology.entities.Face
        """
        return Solid(self._builder.Solid())

    @property
    def sphere(self):
        """
        :return: The sphere primitive.
        :rtype: OCCT.BRepPrim.BRepPrim_Sphere
        """
        return self._builder.Sphere()
def simple_mesh():
    #
    # Create the shape
    #
    theBox = BRepPrimAPI_MakeBox(200, 60, 60).Shape()
    theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100, 20, 20), 80).Shape()
    shape = BRepAlgoAPI_Fuse(theSphere, theBox).Shape()
    #
    # Mesh the shape
    #
    BRepMesh_IncrementalMesh(shape, 0.8)
    builder = BRep_Builder()
    comp = TopoDS_Compound()
    builder.MakeCompound(comp)

    bt = BRep_Tool()
    ex = TopExp_Explorer(shape, TopAbs_FACE)
    while ex.More():
        face = topods_Face(ex.Current())
        location = TopLoc_Location()
        facing = (bt.Triangulation(face, location))
        tab = facing.Nodes()
        tri = facing.Triangles()
        for i in range(1, facing.NbTriangles() + 1):
            trian = tri.Value(i)
            index1, index2, index3 = trian.Get()
            for j in range(1, 4):
                if j == 1:
                    m = index1
                    n = index2
                elif j == 2:
                    n = index3
                elif j == 3:
                    m = index2
                me = BRepBuilderAPI_MakeEdge(tab.Value(m), tab.Value(n))
                if me.IsDone():
                    builder.Add(comp, me.Edge())
        ex.Next()
    display.EraseAll()
    display.DisplayShape(shape)
    display.DisplayShape(comp, update=True)
示例#6
0
    def iso_curve(self, u_or_v, param):
        """
        get the iso curve from a u,v + parameter
        :param u_or_v:
        :param param:
        :return:
        """
        uv = 0 if u_or_v == 'u' else 1
        iso = Adaptor3d_IsoCurve(self.adaptor_handle.GetHandle(), uv, param)
        return iso

    def edges(self):
        return [
            Edge(i)
            for i in WireExplorer(next(self.topo.wires())).ordered_edges()
        ]

    def __repr__(self):
        return self.name

    def __str__(self):
        return self.__repr__()

if __name__ == "__main__":
    from OCCT.BRepPrimAPI import BRepPrimAPI_MakeSphere
    sph = BRepPrimAPI_MakeSphere(1, 1).Face()
    fc = Face(sph)
    print(fc.is_trimmed())
    print(fc.is_planar())
from OCCT.StdMeshers import (StdMeshers_Arithmetic1D,
                             StdMeshers_QuadranglePreference,
                             StdMeshers_Regular_1D, StdMeshers_Prism_3D,
                             StdMeshers_CompositeHexa_3D,
                             StdMeshers_Quadrangle_2D)
from OCCT.MeshVS import (MeshVS_Mesh, MeshVS_BP_Mesh, MeshVS_MeshPrsBuilder,
                         MeshVS_DMF_NodalColorDataPrs)
from OCCT.SMDSAbs import SMDSAbs_Face

from OCC.Display.SimpleGui import init_display
display, start_display, add_menu, add_function_to_menu = init_display()

# First create a 'complex' shape (actually a boolean op between a box and a cylinder)
print('Creating geometry ...', end='')
box = BRepPrimAPI_MakeBox(200, 30, 30).Shape()
sphere = BRepPrimAPI_MakeSphere(gp_Pnt(150, 20, 20), 80).Shape()
aShape = BRepAlgoAPI_Cut(box, sphere).Shape()
print('Done.')

# Create the Mesh
print('Creating mesh ...', end='')
aMeshGen = SMESH_Gen()
aMesh = aMeshGen.CreateMesh(0, True)
print('Done.')

print('Adding hypothesis and algorithms ...', end='')
# 1D
an1DHypothesis = StdMeshers_Arithmetic1D(0, 0,
                                         aMeshGen)  #discretization of the wire
an1DHypothesis.SetLength(5., False)  #the smallest distance between 2 points
an1DHypothesis.SetLength(10., True)  # the longest distance between 2 points
示例#8
0
    def __init__(self, origin=(0., 0., 0.), radius=1.):
        origin = CheckGeom.to_point(origin)

        self._builder = BRepPrimAPI_MakeSphere(origin, radius)
##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 OCCT.gp import gp_Pnt, gp_XYZ, gp_Mat, gp_GTrsf
from OCCT.BRepPrimAPI import BRepPrimAPI_MakeSphere, BRepPrimAPI_MakeBox
from OCCT.BRepBuilderAPI import BRepBuilderAPI_GTransform
from OCCT.BRepAlgoAPI import BRepAlgoAPI_Common

from OCCT.Visualization import BasicViewer

display, start_display, add_menu, add_function_to_menu = init_display()
orig = gp_Pnt(0., 0., 0.)
sphere = BRepPrimAPI_MakeSphere(orig, 50.).Solid()

# be careful that the following scale numbers are "not too big",
# otherwise boolean operations can be buggy
# see isue
a1 = 17.1
a2 = 17.1
a3 = 3.5
gTrsf = gp_GTrsf(gp_Mat(a1, 0, 0, 0, a2, 0, 0, 0, a3), gp_XYZ(0., 112.2, 0.))
ellipsoid = BRepBuilderAPI_GTransform(sphere, gTrsf).Shape()

# then perform a boolean intersection with a box
box = BRepPrimAPI_MakeBox(gp_Pnt(-1000, -1000, -1000),
                          gp_Pnt(1000, 112.2, 1000)).Shape()
common = BRepAlgoAPI_Common(box, ellipsoid).Shape()
if common.IsNull():
示例#10
0
def get_test_sphere_shape():
    return BRepPrimAPI_MakeSphere(10.).Shape()
示例#11
0
##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 OCCT.AIS import AIS_Shape
from OCCT.BRepPrimAPI import BRepPrimAPI_MakeSphere
from OCCT.Graphic3d import (Graphic3d_ShaderProgram, Graphic3d_TOS_VERTEX,
                            Graphic3d_TOS_FRAGMENT, Graphic3d_ShaderObject)
from OCCT.TCollection import TCollection_AsciiString
from OCC.Display.SimpleGui import init_display

display, start_display, add_menu, add_function_to_menu = init_display()

shape = BRepPrimAPI_MakeSphere(100).Shape()
anIO = AIS_Shape(shape)
display.Context.Display(anIO, True)

# gragment shader
fs = """
void main(void)
{
    gl_FragColor=vec4(0.0, 1.0, 0, 1.0);
}
"""

# vertex shader
vs = """
void main()
{
示例#12
0
def also_on_select(shapes):
    for shape in shapes:
        if shape.ShapeType() == TopAbs_SOLID:
            print("solid selected")
        if shape.ShapeType() == TopAbs_EDGE:
            print("edge selected")
        if shape.ShapeType() == TopAbs_FACE:
            print("face selected")


def location_from_vector(x, y, z):
    trsf = gp_Trsf()
    trsf.SetTranslation(gp_Vec(x, y, z))
    loc = TopLoc_Location(trsf)
    return loc


cube = BRepPrimAPI_MakeBox(100, 100, 100).Shape()
sphere = BRepPrimAPI_MakeSphere(100).Shape()
sphere.Move(location_from_vector(500, 0, 0))

display.DisplayShape(cube)
display.DisplayShape(sphere)

viewer = get_occ_viewer()
viewer.sig_topods_selected.connect(on_select)
viewer.sig_topods_selected.connect(also_on_select)

display.FitAll()
start_display()