我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用ctypes.c_float()。
def simxReadVisionSensor(clientID, sensorHandle, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' detectionState = ct.c_ubyte() auxValues = ct.POINTER(ct.c_float)() auxValuesCount = ct.POINTER(ct.c_int)() ret = c_ReadVisionSensor(clientID, sensorHandle, ct.byref(detectionState), ct.byref(auxValues), ct.byref(auxValuesCount), operationMode) auxValues2 = [] if ret == 0: s = 0 for i in range(auxValuesCount[0]): auxValues2.append(auxValues[s:s+auxValuesCount[i+1]]) s += auxValuesCount[i+1] #free C buffers c_ReleaseBuffer(auxValues) c_ReleaseBuffer(auxValuesCount) return ret, bool(detectionState.value!=0), auxValues2
def simxGetVisionSensorDepthBuffer(clientID, sensorHandle, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' c_buffer = ct.POINTER(ct.c_float)() resolution = (ct.c_int*2)() ret = c_GetVisionSensorDepthBuffer(clientID, sensorHandle, resolution, ct.byref(c_buffer), operationMode) reso = [] buffer = [] if (ret == 0): buffer = [None]*resolution[0]*resolution[1] for i in range(resolution[0] * resolution[1]): buffer[i] = c_buffer[i] for i in range(2): reso.append(resolution[i]) return ret, reso, buffer
def simxReadProximitySensor(clientID, sensorHandle, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' detectionState = ct.c_ubyte() detectedObjectHandle = ct.c_int() detectedPoint = (ct.c_float*3)() detectedSurfaceNormalVector = (ct.c_float*3)() ret = c_ReadProximitySensor(clientID, sensorHandle, ct.byref(detectionState), detectedPoint, ct.byref(detectedObjectHandle), detectedSurfaceNormalVector, operationMode) arr1 = [] for i in range(3): arr1.append(detectedPoint[i]) arr2 = [] for i in range(3): arr2.append(detectedSurfaceNormalVector[i]) return ret, bool(detectionState.value!=0), arr1, detectedObjectHandle.value, arr2
def simxAuxiliaryConsoleOpen(clientID, title, maxLines, mode, position, size, textColor, backgroundColor, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' consoleHandle = ct.c_int() if (sys.version_info[0] == 3) and (type(title) is str): title=title.encode('utf-8') if position != None: c_position = (ct.c_int*2)(*position) else: c_position = None if size != None: c_size = (ct.c_int*2)(*size) else: c_size = None if textColor != None: c_textColor = (ct.c_float*3)(*textColor) else: c_textColor = None if backgroundColor != None: c_backgroundColor = (ct.c_float*3)(*backgroundColor) else: c_backgroundColor = None return c_AuxiliaryConsoleOpen(clientID, title, maxLines, mode, c_position, c_size, c_textColor, c_backgroundColor, ct.byref(consoleHandle), operationMode), consoleHandle.value
def simxDisplayDialog(clientID, titleText, mainText, dialogType, initialText, titleColors, dialogColors, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' if titleColors != None: c_titleColors = (ct.c_float*6)(*titleColors) else: c_titleColors = None if dialogColors != None: c_dialogColors = (ct.c_float*6)(*dialogColors) else: c_dialogColors = None c_dialogHandle = ct.c_int() c_uiHandle = ct.c_int() if sys.version_info[0] == 3: if type(titleText) is str: titleText=titleText.encode('utf-8') if type(mainText) is str: mainText=mainText.encode('utf-8') if type(initialText) is str: initialText=initialText.encode('utf-8') return c_DisplayDialog(clientID, titleText, mainText, dialogType, initialText, c_titleColors, c_dialogColors, ct.byref(c_dialogHandle), ct.byref(c_uiHandle), operationMode), c_dialogHandle.value, c_uiHandle.value
def simxGetFloatSignal(clientID, signalName, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' signalValue = ct.c_float() if (sys.version_info[0] == 3) and (type(signalName) is str): signalName=signalName.encode('utf-8') return c_GetFloatSignal(clientID, signalName, ct.byref(signalValue), operationMode), signalValue.value
def _get_projection_matrix(window_size, view_position, view_zoom, view_aperture, initial_view_aperture_x): """Retrieve the projection matrix.""" scale = 2.0 * view_zoom / initial_view_aperture_x return (ctypes.c_float * 16)( scale, 0.0, 0.0, 0.0, 0.0, scale * window_size.x / window_size.y, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -2.0 * view_position.x / view_aperture.x, -2.0 * view_position.y / view_aperture.y, 0.0, 1.0)
def make_array(shape=(1,), dtype=np.float32, shared=False, fill_val=None): np_type_to_ctype = {np.float32: ctypes.c_float, np.float64: ctypes.c_double, np.bool: ctypes.c_bool, np.uint8: ctypes.c_ubyte, np.uint64: ctypes.c_ulonglong} if not shared: np_arr = np.empty(shape, dtype=dtype) else: numel = np.prod(shape) arr_ctypes = sharedctypes.RawArray(np_type_to_ctype[dtype], numel) np_arr = np.frombuffer(arr_ctypes, dtype=dtype, count=numel) np_arr.shape = shape if not fill_val is None: np_arr[...] = fill_val return np_arr
def simxGetJointPosition(clientID, jointHandle, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' position = ct.c_float() return c_GetJointPosition(clientID, jointHandle, ct.byref(position), operationMode), position.value
def simxGetJointMatrix(clientID, jointHandle, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' matrix = (ct.c_float*12)() ret = c_GetJointMatrix(clientID, jointHandle, matrix, operationMode) arr = [] for i in range(12): arr.append(matrix[i]) return ret, arr
def simxSetSphericalJointMatrix(clientID, jointHandle, matrix, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' matrix = (ct.c_float*12)(*matrix) return c_SetSphericalJointMatrix(clientID, jointHandle, matrix, operationMode)
def simxJointGetForce(clientID, jointHandle, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' force = ct.c_float() return c_GetJointForce(clientID, jointHandle, ct.byref(force), operationMode), force.value
def simxGetJointForce(clientID, jointHandle, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' force = ct.c_float() return c_GetJointForce(clientID, jointHandle, ct.byref(force), operationMode), force.value
def simxGetObjectOrientation(clientID, objectHandle, relativeToObjectHandle, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' eulerAngles = (ct.c_float*3)() ret = c_GetObjectOrientation(clientID, objectHandle, relativeToObjectHandle, eulerAngles, operationMode) arr = [] for i in range(3): arr.append(eulerAngles[i]) return ret, arr
def simxSetObjectOrientation(clientID, objectHandle, relativeToObjectHandle, eulerAngles, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' angles = (ct.c_float*3)(*eulerAngles) return c_SetObjectOrientation(clientID, objectHandle, relativeToObjectHandle, angles, operationMode)
def simxSetObjectPosition(clientID, objectHandle, relativeToObjectHandle, position, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' c_position = (ct.c_float*3)(*position) return c_SetObjectPosition(clientID, objectHandle, relativeToObjectHandle, c_position, operationMode)
def simxGetArrayParameter(clientID, paramIdentifier, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' paramValues = (ct.c_float*3)() ret = c_GetArrayParameter(clientID, paramIdentifier, paramValues, operationMode) arr = [] for i in range(3): arr.append(paramValues[i]) return ret, arr
def simxSetArrayParameter(clientID, paramIdentifier, paramValues, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' c_paramValues = (ct.c_float*3)(*paramValues) return c_SetArrayParameter(clientID, paramIdentifier, c_paramValues, operationMode)
def simxGetFloatingParameter(clientID, paramIdentifier, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' paramValue = ct.c_float() return c_GetFloatingParameter(clientID, paramIdentifier, ct.byref(paramValue), operationMode), paramValue.value
def simxGetObjectFloatParameter(clientID, objectHandle, parameterID, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' parameterValue = ct.c_float() return c_GetObjectFloatParameter(clientID, objectHandle, parameterID, ct.byref(parameterValue), operationMode), parameterValue.value
def simxGetObjectVelocity(clientID, objectHandle, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' linearVel = (ct.c_float*3)() angularVel = (ct.c_float*3)() ret = c_GetObjectVelocity(clientID, objectHandle, linearVel, angularVel, operationMode) arr1 = [] for i in range(3): arr1.append(linearVel[i]) arr2 = [] for i in range(3): arr2.append(angularVel[i]) return ret, arr1, arr2
def uniform_matrixf(self, name, mat): # obtian the uniform location loc = glGetUniformLocation(self.handle, name) # uplaod the 4x4 floating point matrix glUniformMatrix4fv(loc, 1, False, (c_float * 16)(*mat))
def get_speed(self): return self.device.get_property(c_api.ONI_DEVICE_PROPERTY_PLAYBACK_SPEED, ctypes.c_float)
def get_horizontal_fov(self): return self.get_property(c_api.ONI_STREAM_PROPERTY_HORIZONTAL_FOV, ctypes.c_float).value
def get_vertical_fov(self): return self.get_property(c_api.ONI_STREAM_PROPERTY_VERTICAL_FOV, ctypes.c_float).value
def convert_world_to_depth(depthStream, worldX, worldY, worldZ): """const VideoStream& depthStream, float worldX, float worldY, float worldZ""" out_depthX = ctypes.c_float() out_depthY = ctypes.c_float() out_depthZ = ctypes.c_float() c_api.oniCoordinateConverterWorldToDepth(depthStream._handle, worldX, worldY, worldZ, ctypes.byref(out_depthX), ctypes.byref(out_depthY), ctypes.byref(out_depthZ)) return out_depthX.value, out_depthY.value, out_depthZ.value
def convert_depth_to_world(depthStream, depthX, depthY, depthZ): """const VideoStream& depthStream, float depthX, float depthY, float depthZ, float* pWorldX, float* pWorldY, float* pWorldZ""" out_depthX = ctypes.c_float() out_depthY = ctypes.c_float() out_depthZ = ctypes.c_float() c_api.oniCoordinateConverterDepthToWorld(depthStream._handle, depthX, depthY, depthZ, ctypes.byref(out_depthX), ctypes.byref(out_depthY), ctypes.byref(out_depthZ)) return out_depthX.value, out_depthY.value, out_depthZ.value