示例#1
0
    def addCSG(self, CSGobj, res, origin, extent, colour=None):
        """
        Visualise a CSG structure in a space subset defined by xmin, xmax, ymin, .... with division factor (i.e. ~ resolution) res
        """

        #INTone = Box(origin = (-1.,-1.,-0.), extent = (1,1,3))
        #INTtwo = Box(origin = (-0.5,-0.5,0), extent = (0.5,0.5,3))
        #INTtwo.append_transform(tf.translation_matrix((0,0.5,0)))
        #INTtwo.append_transform(tf.rotation_matrix(np.pi/4, (0,0,1)))
        #CSGobj = CSGsub(INTone, INTtwo)

        #xmin = -1.
        #xmax = 1.
        #ymin = -1.
        #ymax = 1.
        #zmin = -1.
        #zmax = 3.

        #resolution = 0.05
        #print "Resolution: ", res

        xmin = origin[0]
        xmax = extent[0]
        ymin = origin[1]
        ymax = extent[1]
        zmin = origin[2]
        zmax = extent[2]
        """
        Determine Voxel size from resolution
        """
        voxelextent = (res * (xmax - xmin), res * (ymax - ymin),
                       res * (zmax - zmin))
        pex = voxelextent
        """
        Scan space
        """

        x = xmin
        y = ymin
        z = zmin

        print 'Visualisation of ', CSGobj.reference, ' started...'

        while x < xmax:

            y = ymin
            z = zmin

            while y < ymax:

                z = zmin

                while z < zmax:

                    pt = (x, y, z)

                    if CSGobj.contains(pt):
                        origin = (pt[0] - pex[0] / 2, pt[1] - pex[1] / 2,
                                  pt[2] - pex[2] / 2)
                        extent = (pt[0] + pex[0] / 2, pt[1] + pex[1] / 2,
                                  pt[2] + pex[2] / 2)
                        voxel = geo.Box(origin=origin, extent=extent)
                        self.addCSGvoxel(voxel, colour=colour)

                    z = z + res * (zmax - zmin)

                y = y + res * (ymax - ymin)

            x = x + res * (xmax - xmin)

        print 'Complete.'
示例#2
0
            self.addRay(obj, colour=colour)
        if isinstance(obj, geo.Cylinder):
            self.addCylinder(obj, colour=colour)
        if isinstance(obj, geo.FinitePlane):
            self.addFinitePlane(obj, colour, opacity)
        if isinstance(obj, csg.CSGadd) or isinstance(
                obj, csg.CSGint) or isinstance(obj, csg.CSGsub):
            self.addCSG(obj, res, origin, extent, colour)
        if isinstance(obj, geo.Polygon):
            self.addPolygon(obj, colour=colour)
        if isinstance(obj, geo.Convex):
            self.addConvex(obj, colour=colour)


if False:
    box1 = geo.Box(origin=[0, 0, 0], extent=[2, 2, 2])
    box2 = geo.Box(origin=[2, 2, 2], extent=[2.1, 4, 4])
    ray1 = geo.Ray(position=[-1, -1, -1], direction=[1, 1, 1])
    ray2 = geo.Ray(position=[-1, -1, -1], direction=[1, 0, 0])
    vis = Visualiser()
    vis.addObject(box1)
    import time
    time.sleep(1)
    vis.addObject(ray1)
    time.sleep(1)
    vis.addObject(ray2)
    time.sleep(1)
    vis.addObject(box2)
    time.sleep(1)
    vis.addLine([0, 0, 0], [5, 4, 5])
"""