예제 #1
0
        def motion():
            # Create Fixation Dot
            viz.startLayer(viz.POINTS)
            viz.pointSize(self.POINTSIZE)
            viz.vertexColor(viz.GRAY)
            viz.vertex(0, 1.8, 4)
            points = viz.endLayer()
            points.disable(viz.CULLING)
            # Create the circles
            sphere = self.createCircles(26, 1, 30, -26)
            sphere2 = self.createCircles(22, 0.8, 30, -26)
            sphere3 = self.createCircles(18, 0.6, 30, -26)
            sphere4 = self.createCircles(14, 0.4, 30, -26)
            sphere5 = self.createCircles(10, 0.2, 30, -26)
            viz.MainView.move([0, 0, 3])

            def keydown(key):

                if key == 'f':
                    self.response = 'self motion'
                    self.keyPressTime = viz.tick()  # get time for keypress
                    print(self.response, self.keyPressTime)
                    self.STATE = 'State - self Motion'

                if key == 'j':
                    self.response = 'object motion'
                    self.keyPressTime = viz.tick()  # get time for keypress
                    print(self.response, self.keyPressTime)
                    self.STATE = 'State - Object Motion'

            viz.callback(viz.KEYDOWN_EVENT, keydown)
예제 #2
0
def flashingCloud(height, width, depth, offset, number, node):

	positions = np.random.uniform(low = -width/2, high = width/2, size = (number, 3))
	positions[:, 1] = positions[:, 1]/(width/height) 

	# Save the location of each dots into a .csv file
	record = open('Cloud_positions_' + str(number) + '.csv', 'a' ) 	

	for n in range(number):
		record.write(str(positions[n, 0]) + ',' + str(positions[n, 1]) + ',' + str(positions[n, 2]) + '\n')

	positions[:, 2] = positions[:, 2] - (depth/2 - offset) 

	clouds = []
	
	viz.startLayer(viz.POINTS)
	viz.pointSize(2)  # Set the size of the dots on the display

	# Draw each dot
	for i in range(number):
		viz.vertex(positions[i, 0], positions[i, 1], positions[i, 2])

	cloud = viz.endLayer()

	# Set a parent object for the cloud.
	# Therefore, once the location of the parent is determined, the location of the cloud as a whole is also determined.
	cloud.setParent(node) 

	return cloud
예제 #3
0
			def createRod():
				viz.startLayer(viz.POINTS)
				viz.pointSize(4)
				viz.vertex(0,1.65,1)
				viz.vertex(0,1.70,1)
				viz.vertex(0,1.75,1)
				viz.vertex(0,1.80,1)
				viz.vertex(0,1.85,1)
				viz.vertex(0,1.90,1)
				viz.vertex(0,1.95,1)
				line = viz.endLayer()
				line.visible(viz.OFF)
				line.center(0,1.8,1)
				initLinePos = 0 + 20 * random.uniform(-1,1)
				line.setEuler([0,0,initLinePos])
				class LineRotation(viz.EventClass):
					def __init__(self):
						viz.EventClass.__init__(self)

						self.callback(viz.KEYDOWN_EVENT, self.keyboardAction)

					def keyboardAction(self,key):
						currentPosition = line.getEuler()
						currentRoll = currentPosition[2]
						if viz.key.isDown(viz.KEY_LEFT):
							line.setEuler([0,0,currentRoll + 1])
						elif viz.key.isDown(viz.KEY_RIGHT): 
							line.setEuler([0,0,currentRoll -1])
				LineRotation()
				return line, initLinePos
예제 #4
0
def GenerateStarDome(numStars, pointSize, minRadius, maxRadius, scene=1, yCenter=0):
 #Create a star dome of random points
 viz.startLayer(viz.POINTS)
 viz.pointSize(pointSize)
 for i in range(0, numStars):
  x = random() - 0.5
  y = random() - 0.5
  z = random() - 0.5
  length = math.sqrt(x*x + y*y + z*z)
  rad = vizmat.GetRandom(minRadius,maxRadius)
  x = x / length * rad
  y = y / length * rad
  y += yCenter
  z = z / length * rad
  color = vizmat.GetRandom(0.4,1)
  viz.vertexColor([color,color,color-vizmat.GetRandom(0,0.2)])
  viz.vertex([x, y, z])

 stardome = viz.endLayer()
 stardome.setParent(viz.WORLD, scene=scene)
 stardome.texture( viz.addTexture('particle.rgb') )
 stardome.blendFunc(viz.GL_SRC_ALPHA,viz.GL_DST_ALPHA)
 stardome.enable(viz.POINT_SPRITE)
 stardome.disable(viz.DEPTH_TEST)
 stardome.draworder(-100000)
예제 #5
0
 def getViewXYZ(self, dist="far", reFrame=viz.ABS_GLOBAL):
     
     # temporarily add vertex to track parcel pos in abs coords
     viz.startLayer(viz.POINTS)
     viz.vertexColor(1,0,0)
     viz.pointSize(30)
     viz.vertex(0,0,0)
     cV = viz.endLayer()
     cV.setParent(self.bNodeOp)
             
     if dist == "far":
         cV.setPosition(self.viewLocFar, mode=viz.ABS_LOCAL)
         zoneXYZ = cV.getPosition(mode=reFrame)
     elif dist == "near":
         cV.setPosition(self.viewLocNear, mode=viz.ABS_LOCAL)
         zoneXYZ = cV.getPosition(mode=reFrame)
     elif dist == 'center':
         zoneXYZ = self.bNodeOp.getPosition(mode=reFrame)
         
     cV.visible(viz.OFF)        
     cV.remove()
     
     # set y to eye height
     zoneXYZ[1] = ct.EYE_HEIGHT
     
     return zoneXYZ
예제 #6
0
 def getCornerCoords(cNode, quSpace):
 
     nBox = cNode.getBoundingBox(viz.ABS_LOCAL)
     
     cCrns      = [ (nBox.xmin, 0, nBox.zmin), (nBox.xmin, 0, nBox.zmax), (nBox.xmax, 0, nBox.zmax), (nBox.xmax, 0, nBox.zmin) ]
     globalCrns = []
     singleVertChildren = []
     
     for c in cNode.getChildren():
         if c.__class__ == viz.VizPrimitive:
             singleVertChildren.append( c )
     
     #print "nChildren: ", singleVertChildren
     i = 0
     for cC in cCrns:
         
         # add helper vertices if this node does not contain
         # four children -> heuristic
         if not len(singleVertChildren) == 4:
             # create vertex
             viz.startLayer(viz.POINTS)
             viz.vertexColor(1,0,0)
             viz.pointSize(30)
             viz.vertex(0,0,0)
             cV = viz.endLayer()
             
             # set obst as parent
             cV.setParent(cNode)
             
             # move to parent's corner
             x,y,z = cC
             cV.setPosition(x, y, z, viz.ABS_PARENT)
             
         else:
             cV = singleVertChildren[i]
                                    
         # set obst as parent
         cV.setParent(cNode)
         
         # move to parent's corner
         x,y,z = cC
         cV.setPosition(x, y, z, viz.ABS_PARENT)
         
         # get global coords
         x,y,z = cV.getPosition(viz.ABS_GLOBAL)
         
         # flip z axis to get from world to pedSim space
         if quSpace == 'ped':
             z=-z
             
         globalCrns.append( (x,y,z) )
                         
         # remove this vertex
         #cV.remove()
         
         i = i+1
         
     return globalCrns
예제 #7
0
    def __init__(self, x, y):
        self.x = x
        self.y = y

        viz.startLayer(viz.QUADS)
        viz.vertexColor(0, 0, 0)
        viz.pointSize(100)
        viz.vertex(-1, 0)
        viz.vertex(+1, 0)
        viz.vertex(+1, 2)
        viz.vertex(-1, 2)
        viz.endLayer()
예제 #8
0
	def __init__(self, x, y):
		height = 10
		width = 10
		self.x = 0
		self.y = 0
		viz.startLayer(viz.QUADS)
		viz.vertexColor(1,1,0)
		viz.pointSize(1)
		viz.vertex(-5,10)
		viz.vertex(5,10)
		viz.vertex(5,-10)
		viz.vertex(-5,-10)
		viz.endLayer()
예제 #9
0
    def generate_cloud(self, data, color_array_name):
        """
		Render the vtk data as a cloud, centered at origin and return the Vizard object.
		color_array_name defines the name of the CellData array (for example: "equivalent_stress" or "material")
		"""
        # Start creating the model
        viz.startLayer(viz.POINTS)
        viz.pointSize(self.cloud_point_size)
        # Use the range of the complete data set to ensure consitency
        minimum, maximum = self.vtk_data_local.GetCellData().GetArray(
            color_array_name).GetRange()

        # Generate cloud model by iterating over every cell
        num_of_cells = data.GetNumberOfCells()
        for i in range(num_of_cells):
            cell = data.GetCell(i)

            # Calculate the center of the cell
            x = 0.0
            y = 0.0
            z = 0.0
            num_of_points = cell.GetNumberOfPoints()
            for j in range(num_of_points):
                point = cell.GetPoints().GetPoint(j)
                x += point[0]
                y += point[1]
                z += point[2]
            x /= num_of_points
            y /= num_of_points
            z /= num_of_points

            # Get the value of the cell for color calculation
            value = data.GetCellData().GetArray(color_array_name).GetValue(i)
            color = Simulation_Data._get_color(minimum, maximum, value)
            viz.vertexColor(color[0], color[1], color[2])
            # Draw the point
            viz.vertex(x, y, z)

        # Finish the model
        model = viz.endLayer()
        # Set the center of the model to (0, 0, 0)
        model.setPosition(-(self._original_center[0]),
                          -(self._original_center[1]),
                          -(self._original_center[2]))
        # Create group to get a centered model with coordinates (0, 0, 0)
        group = viz.addGroup()
        model.setParent(group)
        return group
예제 #10
0
    def createCircles(self, NUM_DOTS, RADIUS, POINTSIZE, VELOCITYDIRECTION):

        #Build sphere
        viz.startLayer(viz.POINTS)
        viz.vertexColor(viz.WHITE)
        viz.pointSize(self.POINTSIZE)

        for i in range(0, NUM_DOTS):
            x = RADIUS * math.cos((i * 2 * math.pi) / NUM_DOTS)
            y = RADIUS * math.sin((i * 2 * math.pi) / NUM_DOTS)
            viz.vertex([x, y, 0])

        sphere = viz.endLayer()
        sphere.setPosition([0, 1.8, 4])
        sphere.addAction(vizact.spin(0, 0, 1, VELOCITYDIRECTION))
        return sphere
예제 #11
0
def refreshing(clouds):
    index = 0
    while True:
        clouds[index].remove()
        pos = np.random.uniform(low=-6, high=6, size=(cloudFreq / freq, 3))
        pos[:, 1] = pos[:, 1] / 2
        pos[:, 2] = pos[:, 2] - 5
        viz.startLayer(viz.POINTS)
        viz.pointSize(2)
        for n in range(cloudFreq / freq):
            viz.vertex(pos[n, 0], pos[n, 1], pos[n, 2])
        single_cloud = viz.endLayer()
        single_cloud.disable(viz.CULLING)
        single_cloud.setParent(Target)
        clouds.append(single_cloud)
        index += 1
        yield viztask.waitDraw()
예제 #12
0
    def __init__(self, length, colors, x, y):
        self.length = length
        self.colors = colors
        self.x = x
        self.y = y

        viz.startLayer(viz.POLYGON)

        viz.vertexColor(colors[0], colors[1], colors[2])
        viz.pointSize(1)

        viz.vertex(0, 0)
        viz.vertex(length, 0)
        viz.vertex(length, length)

        viz.vertex(0, length)

        viz.endLayer()
예제 #13
0
def setStage():

    global groundplane, groundtexture

    #	###should set this hope so it builds new tiles if you are reaching the boundary.
    #	fName = 'textures\strong_edge.bmp'
    #
    #	# add groundplane (wrap mode)
    #	groundtexture = viz.addTexture(fName)
    #	groundtexture.wrap(viz.WRAP_T, viz.REPEAT)
    #	groundtexture.wrap(viz.WRAP_S, viz.REPEAT)
    #
    #	groundplane = viz.addTexQuad() ##ground for right bends (tight)
    #	tilesize = 5000#300 #F***ING MASSIVE
    #	planesize = tilesize/5
    #	groundplane.setScale(tilesize, tilesize, tilesize)
    #	groundplane.setEuler((0, 90, 0),viz.REL_LOCAL)
    #	#groundplane.setPosition((0,0,1000),viz.REL_LOCAL) #move forward 1km so don't need to render as much.
    #	matrix = vizmat.Transform()
    #	matrix.setScale( planesize, planesize, planesize )
    #	groundplane.texmat( matrix )
    #	groundplane.texture(groundtexture)
    #	groundplane.visible(1)

    gsize = [1000, 1000]  #groundplane size, metres
    groundplane = vizshape.addPlane(size=(gsize[0], gsize[1]),
                                    axis=vizshape.AXIS_Y,
                                    cullFace=True)  ##make groundplane
    groundplane.texture(viz.add('black.bmp'))  #make groundplane black

    #Build dot plane to cover black groundplane
    ndots = 200000  #arbitrarily picked. perhaps we could match dot density to K & W, 2013?
    viz.startlayer(viz.POINTS)
    viz.vertexColor(viz.WHITE)
    viz.pointSize(2)
    for i in range(0, ndots):
        x = (random.random() - .5) * gsize[0]
        z = (random.random() - .5) * gsize[1]
        viz.vertex([x, 0, z])

    dots = viz.endLayer()
    dots.setPosition(0, 0, 0)
    dots.visible(1)
    groundplane.visible(1)
예제 #14
0
    def __init__(self, bldList):
        
        self.info       = PointInfo()
        self.buildings  = bldList
        self.trials     = []        
        self.cTrial     = None
        self.trialCtr   = -1         
        self.trgAngle   = None
        self.hideBuildings()
        self.trialData  = {}

        # add vertex to measure true target angel
        viz.startLayer(viz.POINTS)
        viz.vertexColor(1,0,0)
        viz.pointSize(30)
        viz.vertex(0,0,0)
        self.refVert = viz.endLayer()
        self.refVert.disable(viz.RENDERING)


        # add grid to orient subject during
        # pointing
        viz.startLayer(viz.LINES)
        viz.lineWidth(6)
        viz.vertexColor(0,0.6,0)
        viz.vertex(-100, 0.01,  0)
        viz.vertex( 100, 0.01,  0)
        viz.vertex(  0, 0.01,-100)
        viz.vertex(  0, 0.01, 100)
        self.cross90 = viz.endLayer()         
        self.cross90.visible(viz.OFF)        

        self.grid = vizshape.addGrid(size=[200,200], step=10.0, boldStep=None)
        self.grid.color([0,.6,0])
        self.grid.visible(viz.OFF)

        # add logger
        self.fields2log = {'trialNr' : 'i8', 'srcBuilding' : 'S10', 'trgBuilding' : 'S10', 'refAngle' : 'f4', 'measAngle' : 'f4', 'trueAngle' : 'f4', 'trialOnset' : 'f8', 'tChoiceMade' : 'f8', 'srcXZ' : [('x', 'f4'), ('z', 'f4')], 'trgXZ' : [('x', 'f4'), ('z', 'f4')], 'srcCtxt' : 'S1', 'trgCtxt' :'S1'}
        self.logHdl     = lg.LogData(self.fields2log)

        # handle exit
        vizact.onexit( self.saveOnExit )
예제 #15
0
def flashingCloud(height, width, depth, offset, number, node, frequence):
    positions = np.random.uniform(low=-width / 2,
                                  high=width / 2,
                                  size=(number, 3))
    positions[:, 1] = positions[:, 1] / (width / height) + height / 2
    positions[:, 2] = positions[:, 2] - (depth / 2 - offset)

    clouds = []

    for j in range(frequence):
        viz.startLayer(viz.POINTS)
        viz.pointSize(2)  #Set the size of the points.
        bin = number / frequence
        for i in range(bin):
            viz.vertex(positions[j * bin + i, 0], positions[j * bin + i, 1],
                       positions[j * bin + i, 2])
        single_cloud = viz.endLayer()
        clouds.append(single_cloud)
        clouds[-1].setParent(node)

    return clouds
예제 #16
0
    def set_cloud_point_size(self, point_size=1):
        """
		Sets the current size of the point cloud points.
		This function also updates the point cloud model.
		"""
        self.cloud_point_size = point_size
        # update the models of the different materials
        for key in self.cloud_materials.keys():
            old_model = self.cloud_materials[key].getChildren()[0]
            # Create new model
            viz.startLayer(viz.POINTS)
            viz.pointSize(point_size)
            # Copy the old model with new point_size
            for point_id in range(old_model.getVertexCount()):
                viz.vertexColor(old_model.getVertexColor(point_id))
                viz.vertex(old_model.getVertex(point_id))
            model = viz.endLayer()
            # Replace the old model with the new one
            model.setParent(self.cloud_materials[key])
            model.setPosition(old_model.getPosition())
            model.setScale(old_model.getScale())
            model.setEuler(old_model.getEuler())
            old_model.remove()
    def runtrials(self):
        """Loops through the trial sequence"""

        setStage()
        self.driver = vizdriver.Driver(self.caveview)
        self.SAVEDATA = True  # switch saving data on.

        viz.MainScene.visible(viz.ON, viz.WORLD)

        #add text to denote conditons - COMMENT OUT FOR EXPERIMENT
        # txtCondt = viz.addText("Condition",parent = viz.SCREEN)
        # txtCondt.setPosition(.7,.2)
        # txtCondt.fontSize(36)

        if self.EYETRACKING:
            comms.start_trial()

        for i, trialtype_signed in enumerate(self.TRIALSEQ_signed):

            ### iterates each trial ###

            #import vizjoy
            print("Trial: ", str(i))
            print("TrialType: ", str(trialtype_signed))

            print("gplanez", self.gplane_z_size)
            print("gplane2", self.gplane2)

            trialtype = abs(trialtype_signed)

            trial_heading = self.ConditionList_heading[
                trialtype]  #set heading for that trial
            trial_dots = self.ConditionList_dots[trialtype]

            print(str([trial_heading, trial_dots]))

            ######choose correct road object.######

            # changes message on screen
            # msg = msg = "Heading: " + str(trial_heading) # COMMENT OUT FOR EXPERIMENT

            #update class trial parameters#
            self.Trial_N = i
            self.Trial_heading = trial_heading
            self.Trial_dots = trial_dots
            self.Trial_trialtype_signed = trialtype_signed

            #1) Offset camera and manipulate dot flow
            #FOR EQUAL AND OPPOSITE USE THE LINE BELOW:
            self.Trial_Camera_Offset = trial_heading

            #put a mask on so that the jump isn't so visible
            self.blackscreen.visible(viz.ON)
            yield viztask.waitFrame(
                12)  #wait for six frames (.2 s) originally 6

            viz.startlayer(viz.POINTS)
            viz.vertexColor(viz.WHITE)
            viz.pointSize(2)
            for i in range(0, trial_dots):
                x = (random.random() - .5) * tilesize
                z = (random.random() - .5) * tilesize
                viz.vertex([x, 0, z])

            dots = viz.endLayer()
            dots.setPosition(0, 0, 0)
            dots.visible(1)

            offset = viz.Matrix.euler(self.Trial_Camera_Offset, 0, 0)
            viz.MainWindow.setViewOffset(offset)  # counter rotates camera

            self.blackscreen.visible(viz.OFF)  #turn the mask

            #2) give participant time with new flow field - might be extra important when manipulating flow field
            yield viztask.waitTime(
                2)  #wait for one second after change of camera heading

            # msg = msg + '\n' + 'Offset: ' + str(self.Trial_Camera_Offset) #Save your variables - COMMENT OUT FOR EXPERIMENT
            # txtCondt.message(msg)	# COMMENT OUT FOR EXPERIMENT

            #3) Move straight to desired position
            # Translate straight to driver position.
            driverpos = viz.MainView.getPosition()
            print(driverpos)
            self.Straight.setPosition(driverpos[0], 0, driverpos[2])

            # Match straight orientation to the driver
            driverEuler = viz.MainView.getEuler(
            )  # gets current driver euler (orientation)
            print("driverEuler", driverEuler)  # prints the euler
            self.Straight.setEuler(
                driverEuler, viz.ABS_GLOBAL
            )  # then sets the straight euler as the driver euler in global coordinates.

            # Offset the angle
            offsetEuler = [trial_heading, 0,
                           0]  # this creates the straight offset
            self.Straight.setEuler(offsetEuler, viz.REL_LOCAL)

            #will need to save initial vertex for line origin, and Euler. Is there a nifty way to save the relative position to the road?

            #4) Reset set point and make the straight visible
            self.Trial_setpoint = self.driver.reset_setpoint()
            self.driver.setSWA_invisible()  # sets SWA invisible on screen
            self.Straight.visible(1)

            #5) Wait for the trial time
            yield viztask.waitTime(
                self.VisibleRoadTime
            )  # add the road again. 2.5s to avoid ceiling effects.

            #6) Remove straight
            self.Straight.visible(0)

            #7) remove dot flow - unsure whether this is the correct thing to do - might need standard level of flow that is then manipulated
            dots.remove()

            def checkCentred():

                centred = False
                x = self.driver.getPos()
                if abs(x) < .1:
                    centred = True
                    return (centred)

            ##wait a while
            #print "waiting"
            #TODO: Recentre the wheel on automation.

            #yield viztask.waitTrue(checkCentred)
            #print "waited"

        #loop has finished.
        CloseConnections(self.EYETRACKING)
예제 #18
0
def diskCreator(node):
    disks = viz.addGroup()

    #Generate random values for position and orientation
    disk_rad = 0.5
    space_width = 80
    disk_number = np.int_(
        np.floor(0.2 * (space_width * space_width) / (4 * disk_rad)))
    al_valu = 0.55
    segment_no = 36

    viz.startLayer(viz.POLYGON)
    viz.pointSize(1)
    for i in range(segment_no):
        pt_z = disk_rad * math.cos(2 * math.pi * i / segment_no)
        pt_x = disk_rad * math.sin(2 * math.pi * i / segment_no)
        viz.vertex([pt_x, 0, pt_z])
    disk = viz.endLayer()

    a = np.arange(2 * disk_rad, space_width - 2 * disk_rad, 4 * disk_rad)
    x = np.repeat(a, len(a)) - space_width / 2
    z = np.tile(a, len(a)) - disk_rad
    pool = np.vstack((x, z))
    pool = np.transpose(pool)
    ind = np.random.choice(len(pool), disk_number, replace=False)
    noise = np.random.uniform(-disk_rad, disk_rad, (disk_number, 2))
    positions = pool[ind, :] + noise

    #disk=vizfx.addChild('disk.osgb')

    for i in range(disk_number):
        #Load a disk
        if i < disk_number / 5:
            d = disk.copy()
            d.color(0, 0, 0.5)
            d.alpha(al_valu)  #Blue
        elif disk_number / 5 <= i < 2 * disk_number / 5:
            d = disk.copy()
            d.color(0.55, 0, 0)
            d.alpha(al_valu)  #Red
        elif 2 * disk_number / 5 <= i < 3 * disk_number / 5:
            d = disk.copy()
            d.color(1, 0.84, 0)
            d.alpha(al_valu)  #Yellow
        elif 3 * disk_number / 5 <= i < 4 * disk_number / 5:
            d = disk.copy()
            d.color(0, 0.5, 0)
            d.alpha(al_valu)  #Green
        elif 4 * disk_number / 5 <= i < disk_number:
            d = disk.copy()
            d.color(0.5, 0, 0.5)
            d.alpha(al_valu)  #Purple

        #Set position, orientation, and state
        d.setPosition([positions[i, 0], 0, positions[i, 1]])
        d.zoffset(-1)
        d.setParent(disks)

    disk.remove()

    disks.setParent(node)
    return disks