Пример #1
0
 def _get_cylinder(self, start, end, radius):
     texture = vp.Texture(
         vp.Pigment('color', [1 / 255. * e for e in (0, 125, 255)]))
     c1 = vp.Sphere(start, radius, texture)
     c2 = vp.Sphere(end, radius, texture)
     c3 = vp.Cylinder(start, end, radius, texture)
     return vp.Union(c1, c2, c3)
Пример #2
0
 def _get_cylinder(self, start, end, radius):
     color = (40 / 255., 40 / 255., 40 / 255.)
     texture = vp.Texture(vp.Pigment('color', color),
                          vp.Finish("ambient", color, "diffuse",
                                    0.0)
                          )
     c1 = vp.Sphere(start, radius, texture)
     c2 = vp.Sphere(end, radius, texture)
     c3 = vp.Cylinder(start, end, radius, texture)
     return vp.Union(c1, c2, c3)
Пример #3
0
    def __init__(self, filename=None, ratio=2., lift=0, simple=False):
        texture = vp.Texture(
            vp.Pigment('color', [0.1 * e for e in [0.20, 0.20, 0.20]]),
            vp.Finish("ambient", 1.0, "diffuse", 0.0))
        cylinder = vp.Cylinder([0, 0, 0], [0, 2.5, 0], 0.02, texture)
        texture = vp.Texture(
            "" if simple else "uv_mapping",
            vp.Pigment(vp.ImageMap('png', filename, 'once')),
            vp.Finish("ambient", 1.0)) if filename is not None else vp.Texture(
                vp.Pigment('color', [0.9 * e for e in [1.0, 1.00, 1.00]]),
                vp.Finish("ambient", 1.0, "diffuse", 0.0))

        sheet = vp.Polygon(5, [0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0],
                           [0, 0, 0], texture, "scale", [ratio * 0.5, 0.5, 0],
                           "translate", [0, 2, 0]) if simple else Parametric(
                               self._get_parametric_body(), texture, "scale",
                               [ratio *
                                0.5, 0.5, 0], "translate", [0, 2, 0])  #

        self.flag = vp.Union(cylinder, sheet)
        self.flag = self.flag.add_args(
            ["rotate", [0, 90, 0], "translate", [0, lift, 0]])
Пример #4
0
def geometry_to_povray(appearance, geometry, object, transform, properties):
    if get_property_yes(properties, [geometry, object], "hide"):
        return []

    #analyze appearance
    tex = get_property(properties, [geometry, object], 'texture')
    if tex is None:
        tex_params = []
        #pigment
        pigment = get_property(properties, [geometry, object], 'pigment')
        if pigment is None:
            transmit = 1. - appearance.getColor()[3]
            pigment = vp.Pigment(*[
                'color',
                list(appearance.getColor())[0:3], 'transmit',
                get_property(properties, [geometry, object], 'ambient',
                             transmit)
            ])
        tex_params.append(pigment)

        #finish
        finish = get_property(properties, [geometry, object], 'finish')
        if finish is None:
            finish=vp.Finish(*['ambient',get_property(properties,[geometry,object],'ambient',0.2), \
                               'diffuse',get_property(properties,[geometry,object],'diffuse',0.7), \
                               'phong',get_property(properties,[geometry,object],'phong',1.),  \
                               'phong_size',get_property(properties,[geometry,object],'phong_size',50)])
        tex_params.append(finish)

        #normal
        normal = get_property(properties, [geometry, object], 'normal')
        if normal is not None:
            tex_params.append(normal)

        #texture
        tex = vp.Texture(*tex_params)

    #create geometry
    ret = []
    if transform is None:
        transform = geometry.getCurrentTransform()
    else:
        transform = se3.mul(transform, geometry.getCurrentTransform())
    if geometry.type() == "GeometricPrimitive":
        prim = geometry.getGeometricPrimitive()
        if get_property_yes(properties, [prim, geometry, object], "hide"):
            return ret
        if prim.type == "Point":
            rad = get_property(properties, [prim, geometry, object], "radius")
            if rad is not None:
                mesh_param = [se3.apply(transform, prim.properties[0:3]), rad]
                mesh_param.append(tex)
                mesh = vp.Sphere(*mesh_param)
                ret.append(mesh)
        elif prim.type == "Sphere":
            mesh_param = [
                se3.apply(transform, prim.properties[0:3]), prim.properties[3]
            ]
            mesh_param.append(tex)
            mesh = vp.Sphere(*mesh_param)
            ret.append(mesh)
        elif prim.type == "Segment":
            rad = get_property(properties, [prim, geometry, object], "radius")
            if rad is not None:
                mesh_param = [
                    se3.apply(transform, prim.properties[0:3]),
                    se3.apply(transform, prim.properties[3:6]), rad
                ]
                mesh_param.append(tex)
                mesh = vp.Cylinder(*mesh_param)
                ret.append(mesh)
        elif prim.type == "AABB":
            mesh_param = [
                se3.apply(transform, prim.properties[0:3]),
                se3.apply(transform, prim.properties[3:6])
            ]
            mesh_param.append(tex)
            mesh = vp.Box(*mesh_param)
            ret.append(mesh)
    elif geometry.type() == "Group":
        for idElem in range(geometry.numElements()):
            elem = geometry.getElement(idElem)
            elem.getCurrentTransform()
            ret += geometry_to_povray(appearance=appearance,
                                      geometry=elem,
                                      object=object,
                                      transform=transform,
                                      properties=properties)
    elif geometry.type() == "TriangleMesh":
        tm = geometry.getTriangleMesh()

        if get_property_yes(properties, [geometry, object], "smooth"):
            vss = [
                se3.apply(transform, tuple(tm.vertices[i * 3:i * 3 + 3]))
                for i in range(len(tm.vertices) // 3)
            ]
            iss = [
                tuple(tm.indices[i * 3:i * 3 + 3])
                for i in range(len(tm.indices) // 3)
            ]
            mesh_param = [
                vp.VertexVectors(*([len(vss)] + vss)),
                vp.FaceIndices(*([len(iss)] + iss))
            ]
            mesh_param.append(tex)
            mesh = vp.Mesh2(*mesh_param)
        else:
            vss = [
                se3.apply(transform, tuple(tm.vertices[i * 3:i * 3 + 3]))
                for i in range(len(tm.vertices) // 3)
            ]
            iss = [
                tuple(tm.indices[i * 3:i * 3 + 3])
                for i in range(len(tm.indices) // 3)
            ]
            mesh_param = [
                vp.Triangle(vss[it[0]], vss[it[1]], vss[it[2]]) for it in iss
            ]
            mesh_param.append(tex)
            mesh = vp.Mesh(*mesh_param)

        ret.append(mesh)
    elif geometry.type() == "VolumeGrid":
        from skimage import measure
        import numpy as np
        grid = geometry.getVolumeGrid()
        volume = np.reshape(np.array(list(grid.values)), tuple(grid.dims))
        spacing = [
            (b - a) / d
            for a, b, d in zip(grid.bbox[0:3], grid.bbox[3:6], grid.dims[0:3])
        ]
        vss, iss, nss, _ = measure.marching_cubes_lewiner(volume,
                                                          level=0.,
                                                          spacing=spacing)
        vss += np.expand_dims(np.array(grid.bbox[0:3]).T, 0)
        vss = [vss[it, :].tolist() for it in range(vss.shape[0])]
        iss = [iss[it, :].tolist() for it in range(iss.shape[0])]
        nss = [nss[it, :].tolist() for it in range(nss.shape[0])]
        mesh_param = [
            vp.VertexVectors(*([len(vss)] + vss)),
            vp.NormalVectors(*([len(nss)] + nss)),
            vp.FaceIndices(*([len(iss)] + iss))
        ]
        mesh_param.append(tex)
        mesh = vp.Mesh2(*mesh_param)
        ret.append(mesh)
    elif geometry.type() == "PointCloud":
        cloud_param = []
        cloud = geometry.getPointCloud()
        rad = get_property(properties, [cloud, geometry, object], "radius")
        for id in range(len(cloud.vertices) // 3):
            cloud_param.append(
                vp.Sphere(cloud.vertices[id * 3:id * 3 + 3], rad))
        cloud_param.append(tex)
        mesh = vp.Union(*cloud_param)
        ret.append(mesh)
    else:
        print("Geometry (name=%s) type: %s not supported!" %
              (object.getName(), geometry.type()))
    return ret
Пример #5
0
 def _get_cylinder(self, start, end, radius, texture):
     c1 = vp.Sphere(start, radius, texture)
     c2 = vp.Sphere(end, radius, texture)
     c3 = vp.Cylinder(start, end, radius, texture)
     return vp.Union(c1, c2, c3)
Пример #6
0
 def _get_body(self, texture):
     return vp.Cylinder([0, 0, 0], [0, .2, 0], .1, texture, "scale", [1, 2, 2])
Пример #7
0
def trav(start, branch, r, objects, t, iter):
    end = branch[0]
    # print(end[3])
    # print(start, end)
    cylinder = vp.Cone(
        [start[0], start[2], start[1]], end[3], [end[0], end[2], end[1]],
        end[3],
        vp.Texture(vp.Pigment('color',
                              [0.7 / 255. * e for e in [98, 78, 44]])),
        vp.Finish('ambient', [0.7 / 255. * e for e in [98, 78, 44]], "diffuse",
                  0.1))
    top = vp.Sphere(
        [end[0], end[2], end[1]], end[3],
        vp.Texture(vp.Pigment('color', [.7 / 255. * e for e in [98, 78, 44]])),
        vp.Finish('ambient', [0.7 / 255. * e for e in [98, 78, 44]], "diffuse",
                  0.1))
    for i in range(0, int(t * 450)):
        (dx, dy, dz) = Vector3D.fromAngles(
            random.randint(0, 180), random.randint(0, 360),
            t * random.randint(0, 5) / (5. *
                                        (iter + 2) if iter != 0 else 1000))
        # dx = random.randint(-5, 5) / 30.
        # dy = random.randint(-5, 5) / 30.
        # dz = random.randint(-5, 5) / 30.
        dr = random.randint(-5, 5) / 30.
        dg = random.randint(-5, 5) / 30.
        db = random.randint(-5, 5) / 30.
        ddx = random.randint(1, 10) / 10000.
        ddy = random.randint(0, 10) / 10000.
        ddz = random.randint(0, 10) / 10000.
        color = (random.randint(40, 180), random.randint(120, 250),
                 random.randint(0, 50))
        leave = vp.Cylinder(
            [end[0] + dx, end[2] + dy, end[1] + dz],
            [end[0] + dx + ddx, end[2] + dy + ddy, end[1] + dz + ddz],
            .01 + random.randint(0, 10) / 1000.,
            vp.Texture(vp.Pigment('color', [2 / 255. * e for e in color])),
            vp.Finish('phong', 1))
        objects.append(
            leave.add_args(["scale", [2, 2, 2], "translate", [0, 0.58, 0]]))

    for i in range(0, int(random.randint(0, 10) / 5)):
        (dx, dy, dz) = Vector3D.fromAngles(
            random.randint(90, 180), random.randint(0, 360),
            t * random.randint(4, 4) / (5 * (iter + 2) if iter != 0 else 1000))

        color = (random.randint(190, 250), random.randint(40, 80),
                 random.randint(40, 80))
        fruit = vp.Sphere([end[0] + dx, end[2] + dz, end[1] + dy], 0.04,
                          vp.Texture(
                              vp.Pigment('color',
                                         [2 / 255. * e for e in color])))
        #objects.append(fruit.add_args(["scale", [2, 2, 2], "translate", [0, 0.58, 0]]))

    objects.append(
        cylinder.add_args(["scale", [2, 2, 2], "translate", [0, 0.58, 0]]))
    objects.append(
        top.add_args(["scale", [2, 2, 2], "translate", [0, 0.58, 0]]))

    for branch in branch[1:]:
        trav(end, branch, r - (0.005 if r != 0.05 else 0.02), objects, t,
             iter + 1)
Пример #8
0
 def get_rounded_cylinder(self, start, end, radius, texture):
     cylinder = vapory.Cylinder(start, end, radius, texture)
     tip_1 = vapory.Sphere(start, radius, texture)
     tip_2 = vapory.Sphere(end, radius, texture)
     return vapory.Union(cylinder, tip_1, tip_2)
Пример #9
0
 def _get_cylinder(self, start, end, radius):
     c1 = vp.Sphere(start, radius, vp.Texture("Brass_Metal"))
     c2 = vp.Sphere(end, radius, vp.Texture("Brass_Metal"))
     c3 = vp.Cylinder(start, end, radius, vp.Texture("Brass_Metal"))
     return vp.Union(c1, c2, c3)
Пример #10
0
 def _get_cylinder(self, p1, p2, radius, color) -> vp.Cylinder:
     return vp.Cylinder(
         p1, p2, radius,
         vp.Texture(vp.Pigment('color', [1. / 255. * e for e in color])),
         vp.Finish("ambient", 1.0, "diffuse", 0.0))