Пример #1
0
    def __init__(self, positions, 
                 radii = None,
                 colors = None,
                 force_centering = False,
                 affine = None,
                 *args, **kwargs):
                   
        """ Draw a set of spheres in 3D """
        super(SphereCloud, self).__init__()

        if affine == None:
            # create a default affine
            self.affine = np.eye(4, dtype = np.float32)
        else:
            self.affine = affine
            
        self._update_glaffine()
        
        self.positions = positions
        n = len(positions)
        if colors == None:
            # default colors
            self.colors = np.array( [[1,1,1,1]], dtype = np.float32).repeat(len(self.positions),axis=0)            
        else:
            self.colors = colors.astype( np.ubyte )

        if radii == None:
            # default colors
            self.radii = np.array( [1.0], dtype = np.float32).repeat(len(self.positions),axis=0)            
        else:
            assert(len(positions) == len(radii))
            self.radii = radii

        # create vertices / faces for the primitive
        # which is a sphere in this actor
        mys = np.load(get_sphere())
        v = mys['vertices'].astype(np.float32)
        f = mys['faces'].astype(np.uint32)
        lv = v.shape[0]
        lf = f.shape[0]
        # allocate memory
        vertices = np.zeros( (lv * n, 3), np.float32 )
        faces =  np.zeros( (lf * n, 3), np.uint32 )
        vertexcolors =  np.zeros( (lv * n, 4), np.float32 )
        for i, n in enumerate(range(n)):
            # scale the unit-sphere by the radius
            vertices[i*lv:((i+1)*lv),:] = v * self.radii[i] + self.positions[i,:]
            # add the number of vertices
            faces[i*lf:((i+1)*lf),:] = f + (i * lv)
            # coloring the vertices
            vertexcolors[i*lv:((i+1)*lv),:] = self.colors[i,:].reshape( (1, 4) ).repeat(lv, axis=0)
            
        self.vertices = vertices
        self.faces = faces.astype(np.uint32)
        self.colors = vertexcolors.astype(np.float32)
        self.show_aabb = True        
        self.make_aabb(margin = 0)
        
        # bind the vertex arrays
        self.vert_ptr = self.vertices.ctypes.data
        self.face_ptr = self.faces.ctypes.data
        self.color_ptr = self.colors.ctypes.data
        self.el_count = len(self.faces) * 3
Пример #2
0
    def __init__(self,
                 positions,
                 radii=None,
                 colors=None,
                 force_centering=False,
                 affine=None,
                 *args,
                 **kwargs):
        """ Draw a set of spheres in 3D """
        super(SphereCloud, self).__init__()

        if affine == None:
            # create a default affine
            self.affine = np.eye(4, dtype=np.float32)
        else:
            self.affine = affine

        self._update_glaffine()

        self.positions = positions
        n = len(positions)
        if colors == None:
            # default colors
            self.colors = np.array([[1, 1, 1, 1]], dtype=np.float32).repeat(
                len(self.positions), axis=0)
        else:
            self.colors = colors.astype(np.ubyte)

        if radii == None:
            # default colors
            self.radii = np.array([1.0],
                                  dtype=np.float32).repeat(len(self.positions),
                                                           axis=0)
        else:
            assert (len(positions) == len(radii))
            self.radii = radii

        # create vertices / faces for the primitive
        # which is a sphere in this actor
        mys = np.load(get_sphere())
        v = mys['vertices'].astype(np.float32)
        f = mys['faces'].astype(np.uint32)
        lv = v.shape[0]
        lf = f.shape[0]
        # allocate memory
        vertices = np.zeros((lv * n, 3), np.float32)
        faces = np.zeros((lf * n, 3), np.uint32)
        vertexcolors = np.zeros((lv * n, 4), np.float32)
        for i, n in enumerate(range(n)):
            # scale the unit-sphere by the radius
            vertices[i * lv:((i + 1) *
                             lv), :] = v * self.radii[i] + self.positions[i, :]
            # add the number of vertices
            faces[i * lf:((i + 1) * lf), :] = f + (i * lv)
            # coloring the vertices
            vertexcolors[i * lv:((i + 1) * lv), :] = self.colors[i, :].reshape(
                (1, 4)).repeat(lv, axis=0)

        self.vertices = vertices
        self.faces = faces.astype(np.uint32)
        self.colors = vertexcolors.astype(np.float32)
        self.show_aabb = True
        self.make_aabb(margin=0)

        # bind the vertex arrays
        self.vert_ptr = self.vertices.ctypes.data
        self.face_ptr = self.faces.ctypes.data
        self.color_ptr = self.colors.ctypes.data
        self.el_count = len(self.faces) * 3
Пример #3
0
import numpy as np
from fos.comp_geom.gen_normals import auto_normals 
from fos.data import get_sphere
from fos.actor.surf import Surface
from fos import Window, WindowManager, World, DefaultCamera
from fos.core.color import red,green,blue,white,black
from fos.core.material import Material
from fos.core.light import Light

eds=np.load(get_sphere())
vertices=eds['vertices']
faces=eds['faces']

vertices=100*vertices.astype(np.float32)
faces=faces.astype(np.uint32)        

print('vertices.shape %s' % vertices.dtype)
print('faces.shape %s' % faces.dtype)

colors=np.random.rand(len(vertices),4)
colors=colors.astype('f4')
colors[:,3]=1
   
normals=auto_normals(vertices,faces)
print('normals.shape %d %d' % normals.shape)
print('colors.shape %d %d' % colors.shape)
print(vertices.dtype,faces.dtype, colors.dtype, normals.dtype)

aff = np.eye(4,dtype='f4')
aff[:3,3] = [0,0,0]
Пример #4
0
import numpy as np
from fos.comp_geom.gen_normals import auto_normals

from fos.data import get_sphere

eds = np.load(get_sphere('symmetric362'))  # problem with 642
vertices = eds['vertices']
faces = eds['faces']

vertices = 50 * vertices.astype('f4')
faces = faces.astype(np.uint32)
colors = np.ones((len(vertices), 4)).astype('f4')
#colors[0]=np.array([1.,0.,0.,1.]).astype('f4')
colors[:, :3] = np.random.rand(len(vertices), 3).astype('f4')

len(vertices)
print 'vertices.shape', vertices.shape, vertices.dtype
print 'faces.shape', faces.shape, faces.dtype

normals = auto_normals(vertices, faces)

print vertices.min(), vertices.max(), vertices.mean()
print normals.min(), normals.max(), normals.mean()

print vertices.dtype, faces.dtype, colors.dtype, normals.dtype

from fos.actor.surf import Surface
from fos import Window, World, DefaultCamera

aff = np.eye(4, dtype=np.float32)
#aff[0,3] = 30
Пример #5
0
import numpy as np
from fos.comp_geom.gen_normals import auto_normals


from fos.data import get_sphere

eds=np.load(get_sphere('symmetric362'))
vertices=eds['vertices']
faces=eds['faces']

vertices=vertices.astype(np.float32)
faces=faces.astype(np.uint32)
colors=np.ones((len(vertices),4))

len(vertices)
print 'vertices.shape', vertices.shape, vertices.dtype
print 'faces.shape', faces.shape,faces.dtype

    
normals=auto_normals(vertices,faces)



print vertices.min(),vertices.max(),vertices.mean()
print normals.min(),normals.max(), normals.mean()

print vertices.dtype,faces.dtype, colors.dtype, normals.dtype

from fos.actor.surf import Surface
from fos import Window, World, DefaultCamera