예제 #1
0
 def make_bounding_box(self):
     '''figures out a bounding box from a set of points.
     this is just to set bottom_left, top_right, bottom_right, top_left
     see Surface.approximate for the real magic.'''
     x_list, y_list, z_list = [], [], []
     #really we just need to figure out two points
     for point in self.points:
         if hasattr(point, "__iter__"):
             #it's a list
             for pnt in point:
                 pnt = make_point(pnt)
                 x, y, z = pnt.Coord()  #Point(BRep_Tool().Pnt(pnt)).Coord()
                 x_list.append(x)
                 y_list.append(y)
                 z_list.append(z)
             break
         point = make_point(point)
         if hasattr(point, "Coord"):
             x, y, z = point.Coord()
             x_list.append(x)
             y_list.append(y)
             z_list.append(z)
     x_min, y_min, z_min = min(x_list), min(y_list), min(z_list)
     x_max, y_max, z_max = max(x_list), max(y_list), max(z_list)
     #we're assuming z=0 for this plane that we're working on.
     #check to make sure the points line up in the z=0 plane
     self.bottom_left = Point(x_min, y_min, 0)
     self.top_right = Point(x_max, y_max, 0)
     self.bottom_right = Point(x_max, y_min, 0)
     self.top_left = Point(x_min, y_max, 0)
예제 #2
0
 def test_extract_shape_vertices(self):
     clear()
     occ_shape = BRepPrimAPI_MakeBox(Point(0, 0, 0), Point(1, 1, 1)).Shape()
     display.DisplayShape(occ_shape)
     temp_points = extract_shape_vertices(occ_shape)
     self.assertTrue(len(temp_points) > 0)
     surf = Surface()
     surf.shape = occ_shape
     surf.points = temp_points
     surf.approximate()
예제 #3
0
def make_point(vertex):
    #print "make_point: vertex=", vertex
    if isinstance(vertex, TopoDS_Vertex):
        #first check to see if it points anywhere
        location = vertex.Location()
        if location.IsDifferent(location.__class__()) == 1:
            print "making a gp_Pnt"
            pnt = BRep_Tool().Pnt(vertex)
            print "making a point"
            return Point(pnt)
        else:
            print "vertex wasn't anything special"
            return Point(0, 0, 0)  #but it might not actually be 0,0,0
    elif isinstance(vertex, Point):
        return vertex
    elif isinstance(vertex, gp_Pnt):
        return Point(vertex)
    else:
        return vertex
예제 #4
0
def process_wire(wire):
    '''takes a wire and extracts points
    returns a list of points'''
    vertices = []
    explorer = BRepTools_WireExplorer(wire)
    while explorer.More():
        vertex = TopoDS().Vertex(explorer.CurrentVertex())
        xyz = Point(BRep_Tool().Pnt(vertex))
        vertices.append(xyz)
        explorer.Next()
    return vertices
예제 #5
0
    def test_stl(self, event=None):
        #you probably dont have these
        #occ_shape = load_stl("~/local/pythonocc-0.3/pythonOCC/src/samples/Level2/DataExchange/sample.stl")
        #occ_shape = load_stl("~/local/legos/diver.stl") #http://adl.serveftp.org/lab/legos/diver.stl
        #occ_shape = load_stl(os.path.join(os.path.curdir, "models/cube.stl"))

        #make a box
        occ_shape = BRepPrimAPI_MakeBox(Point(0, 0, 0), Point(1, 1, 1)).Shape()
        display.DisplayShape(occ_shape)

        shape = Face(occ_shape)
        temp_points = list(set(shape.points))
        #self.assertTrue(len(temp_points)>0)

        #TODO: cluster points and make surfaces. but how do you compute the first parameter to build_plate?
        surf = Surface()
        surf.shape = occ_shape
        surf.points = temp_points
        #surf.approximate() #should be more like test_extract_shape_vertices
        curve1 = GeomAPI_PointsToBSpline(point_list_1(surf.points)).Curve()
        curve1.GetObject()
        e1 = Edge(curve1.GetHandle())
        display.DisplayShape(e1)
예제 #6
0
    def test_approximate(self):
        #my_surface = approximate_surface(pts)
        p1, p2, p3, p4, p5 = Point(0, 0, 0), Point(0, 10, 0), Point(
            0, 10, 10), Point(0, 0, 10), Point(5, 5, 5)
        poly = BRepBuilderAPI_MakePolygon()
        map(poly.Add, [p1, p2, p3, p4, p1])
        poly.Build()

        my_surf = build_plate([poly], [Point(-1, -1, -1)])
        sh = my_surf.Shape()
        display.DisplayShape(sh)
예제 #7
0
def approximate_surface(points=[]):
    #just to be safe, let's convert that list to Point objects
    if points is not []:
        new_points = []
        for point in points:
            if not isinstance(point, Point):
                new_points.append(gp_Pnt(Point(point)._CSFDB_Getgp_Pntcoord()))
            else:
                new_points.append(point)
        points = new_points
    points = point_list_2(points)
    print "approximate_surface: about to call GeomAPI_PointsToBSplineSurface"
    surface = GeomAPI_PointsToBSplineSurface(points)
    print "approximate_surface: about to call surface.Surface"
    surface1 = surface.Surface()
    surface2 = Handle_Geom_Surface(surface1)
    print "approximate_surface: about to call BRepBuilderAPI_MakeFace"
    face = BRepBuilderAPI_MakeFace(surface2)
    #to get a TopoDS_Face, do: face.Face()
    my_shape = face.Shape()
    print "approximate_surface: returning"
    return my_shape
예제 #8
0
def ask_user(event=None):
    global app
    x = raw_input("x?")
    y = raw_input("y?")
    z = raw_input("z?")
    app.points.append(Point(x, y, z))
예제 #9
0
 def __init__(self):
     self.bottom_left, self.bottom_right, self.top_left, self.top_right = Point(
         0, 0, 0), Point(0, 0, 0), Point(0, 0, 0), Point(0, 0, 0)
     self.points = []  #points that we want to approximate
     self.shape = Shape()
     self.polygons = [BRepBuilderAPI_MakePolygon()]
예제 #10
0
    x = raw_input("x?")
    y = raw_input("y?")
    z = raw_input("z?")
    app.points.append(Point(x, y, z))


def exit_app(event=None):
    sys.exit()


add_key("c", clear)
add_key("a", ask_user)
add_key("d", demo)

pts = [
    Point(0, 0, 0),
    Point(0, 0, 1),
    Point(0, 1, 0),
    Point(0, 1, 1),
    Point(1, 0, 0),
    Point(1, 1, 0),
    Point(1, 0, 1),
    Point(1, 1, 1)
]


class TestApproximation(unittest.TestCase):
    def test_point_list(self):
        tcolgp_array = point_list_1(pts)
        self.assertTrue(isinstance(tcolgp_array, TColgp_Array1OfPnt))
        tcolgp_array = point_list_2(pts)