How to use _flush method in localstack

Best Python code snippet using localstack_python

surrender_client.py

Source:surrender_client.py Github

copy

Full Screen

...14 params["element_name"] = str(element_name);15 params["texture_name"] = str(texture_name);16 params["texture_unit_id"] = int(texture_unit_id);17 self._stream.writeQVariantHash(params);18 self._flush(True);19 if not self._async:20 ret = self._read_return("attachDynamicTexture");21 def cd(self, path):22 """23 | Change the current resource path.24 | This is similar to the 'cd' command on Linux.25 """26 self._check_connection();27 params = { "" : "cd"};28 params["path"] = str(path);29 self._stream.writeQVariantHash(params);30 self._flush(True);31 if not self._async:32 ret = self._read_return("cd");33 def clearMetadata(self):34 """35 | Resets the metadata table36 """37 self._check_connection();38 params = { "" : "clearMetadata"};39 self._stream.writeQVariantHash(params);40 self._flush(True);41 if not self._async:42 ret = self._read_return("clearMetadata");43 def createBRDF(self, name, filename, parameters):44 """45 | Create a BRDF object which can be referenced with the name 'name'.46 | The BRDF model is loaded from the SuMoL file 'filename' with the parameters in 'parameters'.47 """48 self._check_connection();49 params = { "" : "createBRDF"};50 params["name"] = str(name);51 params["filename"] = str(filename);52 params["parameters"] = parameters;53 self._stream.writeQVariantHash(params);54 self._flush(True);55 if not self._async:56 ret = self._read_return("createBRDF");57 def createBody(self, body_name, shape_name, brdf_name, textures):58 """59 | Create an object with the shape 'shape_name' and BRDF 'brdf_name'.60 | 'textures' contain the textures to be used for (in order):61 | - diffuse map62 | - specular map63 | - emission map64 | - normal map65 """66 self._check_connection();67 params = { "" : "createBody"};68 params["body_name"] = str(body_name);69 params["shape_name"] = str(shape_name);70 params["brdf_name"] = str(brdf_name);71 params["textures"] = textures;72 self._stream.writeQVariantHash(params);73 self._flush(True);74 if not self._async:75 ret = self._read_return("createBody");76 def createDEM(self, object_name, conemap_filename, brdf_name, texture):77 """78 | Create a DEM (Digital Elevation Model) from a '.dem' file. Displacement mapping is done from a plan.79 | The conemap can be built with the build_conemap tool.80 | 'texture' is the texture to be used for the diffuse texture map, empty means default white texture.81 """82 self._check_connection();83 params = { "" : "createDEM"};84 params["object_name"] = str(object_name);85 params["conemap_filename"] = str(conemap_filename);86 params["brdf_name"] = str(brdf_name);87 params["texture"] = str(texture);88 self._stream.writeQVariantHash(params);89 self._flush(True);90 ret = self._read_return("createDEM");91 return ret["info"]92 def createLight(self, light_name, spectrum, cutoff, exponent):93 """94 | Create a spot light.95 | 'spectrum' is the 4D spectrum of the light (in W for each wavelength simulated).96 | 'cutoff' is the maximum angle in degrees from the spot direction where the spot produce light.97 | 'exponent' controls how the power decreases when reaching the cutoff angle. 1 means linear, the higher the flatter it gets.98 """99 self._check_connection();100 params = { "" : "createLight"};101 params["light_name"] = str(light_name);102 params["spectrum"] = self._vec(spectrum);103 params["cutoff"] = float(cutoff);104 params["exponent"] = float(exponent);105 self._stream.writeQVariantHash(params);106 self._flush(True);107 if not self._async:108 ret = self._read_return("createLight");109 def createMesh(self, object_name, model_name, scale):110 """111 | Create a new mesh object in the scene.112 | 'object_name' is the name of the new object in the scene.113 | 'model_name' is the name of the model file.114 | 'scale' is the scaling factor to apply when loading the model (use 1 if the mesh is in meters, 1e-3 is it is in km, ...)115 """116 self._check_connection();117 params = { "" : "createMesh"};118 params["object_name"] = str(object_name);119 params["model_name"] = str(model_name);120 params["scale"] = float(scale);121 self._stream.writeQVariantHash(params);122 self._flush(True);123 if not self._async:124 ret = self._read_return("createMesh");125 def createPerPixelProcess(self, name, filename, parameters):126 """127 | Create a PerPixelProcess object for a SuMoL file and a set of parameters.128 | 'name' is used to reference the created object.129 | 130 """131 self._check_connection();132 params = { "" : "createPerPixelProcess"};133 params["name"] = str(name);134 params["filename"] = str(filename);135 params["parameters"] = parameters;136 self._stream.writeQVariantHash(params);137 self._flush(True);138 if not self._async:139 ret = self._read_return("createPerPixelProcess");140 def createShape(self, name, filename, parameters):141 """142 | Create a Shape object which can be referenced with the name 'name'.143 | The shape model is loaded from the SuMoL file 'filename' with the parameters in 'parameters'.144 """145 self._check_connection();146 params = { "" : "createShape"};147 params["name"] = str(name);148 params["filename"] = str(filename);149 params["parameters"] = parameters;150 self._stream.writeQVariantHash(params);151 self._flush(True);152 if not self._async:153 ret = self._read_return("createShape");154 def createSphericalDEM(self, object_name, conemap_filename, brdf_name, texture):155 """156 | Create a DEM (Digital Elevation Model) from a '.dem' file. Displacement mapping is done from the spherical body described in the DEM/PDS file.157 | The conemap can be built with the build_conemap tool.158 | 'texture' is the texture to be used for the diffuse texture map, empty means default white texture.159 """160 self._check_connection();161 params = { "" : "createSphericalDEM"};162 params["object_name"] = str(object_name);163 params["conemap_filename"] = str(conemap_filename);164 params["brdf_name"] = str(brdf_name);165 params["texture"] = str(texture);166 self._stream.writeQVariantHash(params);167 self._flush(True);168 ret = self._read_return("createSphericalDEM");169 return ret["info"]170 def createUserDataTexture(self, name, width, height, gray):171 """172 | Create a data texture whose content has to be provided by the client.173 | If 'gray' is true, the texture type is Y32F (single channel, float).174 | If 'gray' is false, the texture type is RGBA32F (4 channels, float).175 """176 self._check_connection();177 params = { "" : "createUserDataTexture"};178 params["name"] = str(name);179 params["width"] = int(width);180 params["height"] = int(height);181 params["gray"] = bool(gray);182 self._stream.writeQVariantHash(params);183 self._flush(True);184 if not self._async:185 ret = self._read_return("createUserDataTexture");186 def createVideoTexture(self, name, filename, loop):187 """188 | Create a new dynamic texture from a video.189 | If 'loop' is true, the video loops indefinitely, otherwise it stops at the last frame.190 """191 self._check_connection();192 params = { "" : "createVideoTexture"};193 params["name"] = str(name);194 params["filename"] = str(filename);195 params["loop"] = bool(loop);196 self._stream.writeQVariantHash(params);197 self._flush(True);198 if not self._async:199 ret = self._read_return("createVideoTexture");200 def dumpPhotonMapToFile(self, object_name, filename):201 """202 | Dump the photon map of an object to a PLY file.203 """204 self._check_connection();205 params = { "" : "dumpPhotonMapToFile"};206 params["object_name"] = str(object_name);207 params["filename"] = str(filename);208 self._stream.writeQVariantHash(params);209 self._flush(True);210 if not self._async:211 ret = self._read_return("dumpPhotonMapToFile");212 def enableAutoUpdate(self, enable):213 """214 | Enable (true) or disable (false) automatic update of viewer window after rendering.215 | Default: enabled216 """217 self._check_connection();218 params = { "" : "enableAutoUpdate"};219 params["enable"] = bool(enable);220 self._stream.writeQVariantHash(params);221 self._flush(True);222 if not self._async:223 ret = self._read_return("enableAutoUpdate");224 def enableDoublePrecisionMode(self, *args, **kwargs):225 """226 | This function is deprecated and has been removed!227 | It has been replaced with a stub function to avoid legacy script failures.228 """229 self._check_connection();230 params = { "" : "enableDoublePrecisionMode"};231 self._stream.writeQVariantHash(params);232 self._flush(True);233 self._read_return("enableDoublePrecisionMode");234 return None;235 def enableFastPSFMode(self, *args, **kwargs):236 """237 | This function is deprecated and has been removed!238 | It has been replaced with a stub function to avoid legacy script failures.239 """240 self._check_connection();241 params = { "" : "enableFastPSFMode"};242 self._stream.writeQVariantHash(params);243 self._flush(True);244 self._read_return("enableFastPSFMode");245 return None;246 def enableGlobalDynamicShadowMap(self, enable):247 """248 | If true, create a dynamic shadow map to compute sun visibility when rendering all objects249 | This shadow map is global, ie. adapted to exterior environments such as rover simulations or close range rendez-vous.250 | It overrides per object shadow maps.251 | If false, restore the default behavior with per object shadow maps.252 """253 self._check_connection();254 params = { "" : "enableGlobalDynamicShadowMap"};255 params["enable"] = bool(enable);256 self._stream.writeQVariantHash(params);257 self._flush(True);258 if not self._async:259 ret = self._read_return("enableGlobalDynamicShadowMap");260 def enableIrradianceMode(self, enable):261 """262 | Enable (true) or disable (false) irradiance mode.263 """264 self._check_connection();265 params = { "" : "enableIrradianceMode"};266 params["enable"] = bool(enable);267 self._stream.writeQVariantHash(params);268 self._flush(True);269 if not self._async:270 ret = self._read_return("enableIrradianceMode");271 def enableLOSmapping(self, b_enable):272 """273 | enable or disable LOS mapping274 | If true, LOS map will be allocated on image generation. Otherwise it is destroyed if one was allocated before.275 | LOS mapping only works in raytracing (in OpenGL you can deduce it from the pinhole model)276 """277 self._check_connection();278 params = { "" : "enableLOSmapping"};279 params["b_enable"] = bool(b_enable);280 self._stream.writeQVariantHash(params);281 self._flush(True);282 if not self._async:283 ret = self._read_return("enableLOSmapping");284 def enableMultilateralFiltering(self, *args, **kwargs):285 """286 | This function is deprecated and has been removed!287 | It has been replaced with a stub function to avoid legacy script failures.288 """289 self._check_connection();290 params = { "" : "enableMultilateralFiltering"};291 self._stream.writeQVariantHash(params);292 self._flush(True);293 self._read_return("enableMultilateralFiltering");294 return None;295 def enablePathTracing(self, enable):296 """297 | Enable (true) or disable (false) pathtracing.298 | Pathtracing requires raytracing to be enabled.299 """300 self._check_connection();301 params = { "" : "enablePathTracing"};302 params["enable"] = bool(enable);303 self._stream.writeQVariantHash(params);304 self._flush(True);305 if not self._async:306 ret = self._read_return("enablePathTracing");307 def enablePhotonAccumulation(self, enable):308 """309 | Enable (true) or disable (false) photon accumulation mode (Raytracing only).310 | Objects with the photon_map property set to true will be mapped with the energy received.311 | No image will be renderer in this mode!312 """313 self._check_connection();314 params = { "" : "enablePhotonAccumulation"};315 params["enable"] = bool(enable);316 self._stream.writeQVariantHash(params);317 self._flush(True);318 if not self._async:319 ret = self._read_return("enablePhotonAccumulation");320 def enablePreviewMode(self, enable):321 """322 | Enable (true) or disable (false) preview mode.323 | This mode enables faster OpenGL rendering at the cost of reduced quality.324 """325 self._check_connection();326 params = { "" : "enablePreviewMode"};327 params["enable"] = bool(enable);328 self._stream.writeQVariantHash(params);329 self._flush(True);330 if not self._async:331 ret = self._read_return("enablePreviewMode");332 def enableRaySharing(self, enable):333 """334 | Enable (true) or disable (false) reuse of rays for neighbors pixels (Raytracing only).335 | This optimization assumes pixels are acquired simultaneously.336 | It only works with SuMoL PSF!!337 """338 self._check_connection();339 params = { "" : "enableRaySharing"};340 params["enable"] = bool(enable);341 self._stream.writeQVariantHash(params);342 self._flush(True);343 if not self._async:344 ret = self._read_return("enableRaySharing");345 def enableRaytracing(self, enable):346 """347 | Enable (true) or disable (false) raytracing.348 """349 self._check_connection();350 params = { "" : "enableRaytracing"};351 params["enable"] = bool(enable);352 self._stream.writeQVariantHash(params);353 self._flush(True);354 if not self._async:355 ret = self._read_return("enableRaytracing");356 def enableRegularPSFSampling(self, enable):357 """358 | Enable (true) or disable (false) regular PSF sampling. It implies regular pixel sampling.359 """360 self._check_connection();361 params = { "" : "enableRegularPSFSampling"};362 params["enable"] = bool(enable);363 self._stream.writeQVariantHash(params);364 self._flush(True);365 if not self._async:366 ret = self._read_return("enableRegularPSFSampling");367 def enableRegularPixelSampling(self, enable):368 """369 | Enable (true) or disable (false) regular pixel sampling. It doesn't affect PSF sampling.370 """371 self._check_connection();372 params = { "" : "enableRegularPixelSampling"};373 params["enable"] = bool(enable);374 self._stream.writeQVariantHash(params);375 self._flush(True);376 if not self._async:377 ret = self._read_return("enableRegularPixelSampling");378 def enableScanningDeviceMode(self, enable):379 """380 | Enable (true) or disable (false) scanning device mode (Raytracing only).381 | Scanning device mode disables optimizations which assume a typical image projection.382 | This is useful for scanning LiDARs. It has the following characteristics:383 | - simulate a single detector cell (projection model applied to a 1x1 pixel matrix)384 | - does not support rendering stars385 | - PSF tail optimization (blooming) is disabled386 | - RaySharing is disabled387 """388 self._check_connection();389 params = { "" : "enableScanningDeviceMode"};390 params["enable"] = bool(enable);391 self._stream.writeQVariantHash(params);392 self._flush(True);393 if not self._async:394 ret = self._read_return("enableScanningDeviceMode");395 def enableSkipPixelSampling(self, enable):396 """397 | Enable (true) or disable (false) skipping the pixel surface sampling.398 | Enable only when PSF model is already integrated over the pixel surface otherwise image will be smoother than expected!399 | Default: disabled400 """401 self._check_connection();402 params = { "" : "enableSkipPixelSampling"};403 params["enable"] = bool(enable);404 self._stream.writeQVariantHash(params);405 self._flush(True);406 if not self._async:407 ret = self._read_return("enableSkipPixelSampling");408 def enableSpecularOptimization(self, enable):409 """410 | Enable a dedicated optimization for sampling specular reflections of the Sun (pathtracing only).411 """412 self._check_connection();413 params = { "" : "enableSpecularOptimization"};414 params["enable"] = bool(enable);415 self._stream.writeQVariantHash(params);416 self._flush(True);417 if not self._async:418 ret = self._read_return("enableSpecularOptimization");419 def enableTimeMapping(self, b_enable):420 """421 | enable or disable time mapping422 | If true, time map will be allocated on image generation. Otherwise it is destroyed if one was allocated before.423 | Time mapping only works in raytracing424 """425 self._check_connection();426 params = { "" : "enableTimeMapping"};427 params["b_enable"] = bool(b_enable);428 self._stream.writeQVariantHash(params);429 self._flush(True);430 if not self._async:431 ret = self._read_return("enableTimeMapping");432 def exists(self, object_name):433 """434 | Returns true if an object with the given name already exists.435 | This function checks aliases and builtin objects!436 """437 self._check_connection();438 params = { "" : "exists"};439 params["object_name"] = str(object_name);440 self._stream.writeQVariantHash(params);441 self._flush(True);442 ret = self._read_return("exists");443 return ret["exists"]444 def generateMicroTasks(self):445 """446 | Generate the list of µtasks required to render an image.447 | This is what makes possible to distribute the rendering process of a single image across several machines.448 | 449 | The format of the returned matrix is as follow (everything is encoded as double, types are given as hints):450 | cluster_id(int64), x(int32), y(int32), samples(int32), object_id(int32), start(s), end(s), weight([0-1]), flags(int)451 | 452 | NB: works in raytracing only!453 | WARNING: since cluster_id is stored as double, expect issues with images with width or height above 32.000.000 pixels454 """455 self._check_connection();456 params = { "" : "generateMicroTasks"};457 self._stream.writeQVariantHash(params);458 self._flush(True);459 ret = self._read_return("generateMicroTasks");460 return ret["utasks"]461 def getCameraFOVDeg(self):462 """463 | Return camera field of view in degrees.464 """465 self._check_connection();466 params = { "" : "getCameraFOVDeg"};467 self._stream.writeQVariantHash(params);468 self._flush(True);469 ret = self._read_return("getCameraFOVDeg");470 return ret["fov"]471 def getCameraFOVRad(self):472 """473 | Return camera field of view in radians.474 """475 self._check_connection();476 params = { "" : "getCameraFOVRad"};477 self._stream.writeQVariantHash(params);478 self._flush(True);479 ret = self._read_return("getCameraFOVRad");480 return ret["fov"]481 def getConventions(self):482 """483 | Get the active conventions for quaternions and camera frame definition.484 """485 self._check_connection();486 params = { "" : "getConventions"};487 self._stream.writeQVariantHash(params);488 self._flush(True);489 ret = self._read_return("getConventions");490 return ret["conventions"]491 def getCubeMapSize(self):492 """493 | Return the size of cube maps when creating new meshes.494 """495 self._check_connection();496 params = { "" : "getCubeMapSize"};497 self._stream.writeQVariantHash(params);498 self._flush(True);499 ret = self._read_return("getCubeMapSize");500 return ret["cube_map_size"]501 def getDoublePrecisionMode(self, *args, **kwargs):502 """503 | This function is deprecated and has been removed!504 | It has been replaced with a stub function to avoid legacy script failures.505 """506 self._check_connection();507 params = { "" : "getDoublePrecisionMode"};508 self._stream.writeQVariantHash(params);509 self._flush(True);510 self._read_return("getDoublePrecisionMode");511 return None;512 def getGlobalVariables(self):513 """514 | Return the values of active global SuMoL variables.515 | 516 """517 self._check_connection();518 params = { "" : "getGlobalVariables"};519 self._stream.writeQVariantHash(params);520 self._flush(True);521 ret = self._read_return("getGlobalVariables");522 return ret["names_and_values"]523 def getImageSize(self):524 """525 | Return the size of the image.526 """527 self._check_connection();528 params = { "" : "getImageSize"};529 self._stream.writeQVariantHash(params);530 self._flush(True);531 ret = self._read_return("getImageSize");532 return ret["size"]533 def getIntegrationTime(self):534 """535 | Return integration time in seconds.536 """537 self._check_connection();538 params = { "" : "getIntegrationTime"};539 self._stream.writeQVariantHash(params);540 self._flush(True);541 ret = self._read_return("getIntegrationTime");542 return ret["integration_time"]543 def getIrradianceMode(self):544 """545 | Return true if irradiance mode is enabled, false otherwise.546 """547 self._check_connection();548 params = { "" : "getIrradianceMode"};549 self._stream.writeQVariantHash(params);550 self._flush(True);551 ret = self._read_return("getIrradianceMode");552 return ret["enable"]553 def getLOSmapping(self):554 """555 | return true is LOS mapping is enabled, false otherwise.556 """557 self._check_connection();558 params = { "" : "getLOSmapping"};559 self._stream.writeQVariantHash(params);560 self._flush(True);561 ret = self._read_return("getLOSmapping");562 return ret["b_enable"]563 def getMaxSamplesPerPixel(self):564 """565 | Return the maximum number of samples allowed per pixel.566 """567 self._check_connection();568 params = { "" : "getMaxSamplesPerPixel"};569 self._stream.writeQVariantHash(params);570 self._flush(True);571 ret = self._read_return("getMaxSamplesPerPixel");572 return ret["max_samples"]573 def getMaxSecondaryRays(self):574 """575 | Return the number of secondary rays used for pathtracing.576 """577 self._check_connection();578 params = { "" : "getMaxSecondaryRays"};579 self._stream.writeQVariantHash(params);580 self._flush(True);581 ret = self._read_return("getMaxSecondaryRays");582 return ret["max_secondary_rays"]583 def getMaxShadowRays(self):584 """585 | Get the maximum number of rays used for direct shadows.586 | Default is 4.587 """588 self._check_connection();589 params = { "" : "getMaxShadowRays"};590 self._stream.writeQVariantHash(params);591 self._flush(True);592 ret = self._read_return("getMaxShadowRays");593 return ret["max_shadow_rays"]594 def getMetadata(self):595 """596 | Returns the metadata table597 """598 self._check_connection();599 params = { "" : "getMetadata"};600 self._stream.writeQVariantHash(params);601 self._flush(True);602 ret = self._read_return("getMetadata");603 return ret["metadata"]604 def getNbSamplesPerPixel(self):605 """606 | Return the number of samples per pixel.607 """608 self._check_connection();609 params = { "" : "getNbSamplesPerPixel"};610 self._stream.writeQVariantHash(params);611 self._flush(True);612 ret = self._read_return("getNbSamplesPerPixel");613 return ret["nb_samples"]614 def getObjectAttitude(self, object_name):615 """616 | Return the attitude of object 'object_name'.617 | Use 'camera' as object name to get the attitude of the camera.618 """619 self._check_connection();620 params = { "" : "getObjectAttitude"};621 params["object_name"] = str(object_name);622 self._stream.writeQVariantHash(params);623 self._flush(True);624 ret = self._read_return("getObjectAttitude");625 return ret["attitude"]626 def getObjectDynamicCubeMap(self, object_name):627 """628 | Return true if object 'object_name' has dynamic cube maps, false otherwise.629 | A dynamic cube map is updated at each frame whereas a static one is kept as is.630 | This is an OpenGL only option.631 """632 self._check_connection();633 params = { "" : "getObjectDynamicCubeMap"};634 params["object_name"] = str(object_name);635 self._stream.writeQVariantHash(params);636 self._flush(True);637 ret = self._read_return("getObjectDynamicCubeMap");638 return ret["enable"]639 def getObjectDynamicShadowMap(self, object_name):640 """641 | Return true if object 'object_name' has dynamic shadow maps, false otherwise.642 | A dynamic shadow map is updated at each frame whereas a static one is kept as is.643 | This is an OpenGL only option.644 """645 self._check_connection();646 params = { "" : "getObjectDynamicShadowMap"};647 params["object_name"] = str(object_name);648 self._stream.writeQVariantHash(params);649 self._flush(True);650 ret = self._read_return("getObjectDynamicShadowMap");651 return ret["enable"]652 def getObjectElementProperty(self, name, element_name, property):653 """654 | Return the value of property 'property' for element 'element_name' in object 'name'.655 """656 self._check_connection();657 params = { "" : "getObjectElementProperty"};658 params["name"] = str(name);659 params["element_name"] = str(element_name);660 params["property"] = str(property);661 self._stream.writeQVariantHash(params);662 self._flush(True);663 ret = self._read_return("getObjectElementProperty");664 return ret["value"]665 def getObjectMotion(self, object_name):666 """667 | Return motion parameters for object 'object_name'.668 """669 self._check_connection();670 params = { "" : "getObjectMotion"};671 params["object_name"] = str(object_name);672 self._stream.writeQVariantHash(params);673 self._flush(True);674 ret = self._read_return("getObjectMotion");675 return ret["motion"]676 def getObjectPosition(self, object_name):677 """678 | Return the position of object 'object_name'.679 | Use 'camera' as object name to get the position of the camera.680 """681 self._check_connection();682 params = { "" : "getObjectPosition"};683 params["object_name"] = str(object_name);684 self._stream.writeQVariantHash(params);685 self._flush(True);686 ret = self._read_return("getObjectPosition");687 return ret["pos"]688 def getObjectProperty(self, name, property):689 """690 | Return the value of property 'property' for object 'name'.691 """692 self._check_connection();693 params = { "" : "getObjectProperty"};694 params["name"] = str(name);695 params["property"] = str(property);696 self._stream.writeQVariantHash(params);697 self._flush(True);698 ret = self._read_return("getObjectProperty");699 return ret["value"]700 def getObjectSamples(self, object_name):701 """702 | Return the required number of rays for object 'object_name'.703 """704 self._check_connection();705 params = { "" : "getObjectSamples"};706 params["object_name"] = str(object_name);707 self._stream.writeQVariantHash(params);708 self._flush(True);709 ret = self._read_return("getObjectSamples");710 return ret["nb_samples"]711 def getPhotonMapSamplingStep(self):712 """713 | Return the sampling step for photon maps.714 """715 self._check_connection();716 params = { "" : "getPhotonMapSamplingStep"};717 self._stream.writeQVariantHash(params);718 self._flush(True);719 ret = self._read_return("getPhotonMapSamplingStep");720 return ret["step"]721 def getPreviewMode(self):722 """723 | Return true if preview mode is enabled, false otherwise.724 """725 self._check_connection();726 params = { "" : "getPreviewMode"};727 self._stream.writeQVariantHash(params);728 self._flush(True);729 ret = self._read_return("getPreviewMode");730 return ret["enable"]731 def getRessourcePath(self):732 """733 | Return current path to ressource files.734 """735 self._check_connection();736 params = { "" : "getRessourcePath"};737 self._stream.writeQVariantHash(params);738 self._flush(True);739 ret = self._read_return("getRessourcePath");740 return ret["ressource_path"]741 def getScanningDeviceMode(self):742 """743 | Return the status of scanning device mode.744 """745 self._check_connection();746 params = { "" : "getScanningDeviceMode"};747 self._stream.writeQVariantHash(params);748 self._flush(True);749 ret = self._read_return("getScanningDeviceMode");750 return ret["enable"]751 def getSelfVisibilitySamplingStep(self):752 """753 | Return the sampling step for self visibility maps.754 """755 self._check_connection();756 params = { "" : "getSelfVisibilitySamplingStep"};757 self._stream.writeQVariantHash(params);758 self._flush(True);759 ret = self._read_return("getSelfVisibilitySamplingStep");760 return ret["step"]761 def getShadowMapSize(self):762 """763 | Return the size of shadow maps when creating new meshes.764 """765 self._check_connection();766 params = { "" : "getShadowMapSize"};767 self._stream.writeQVariantHash(params);768 self._flush(True);769 ret = self._read_return("getShadowMapSize");770 return ret["shadow_map_size"]771 def getState(self):772 """773 | Return the state of the scene manager as a string.774 | This state contains position,attitude,motion of all objects in the scene as well as renderer settings.775 """776 self._check_connection();777 params = { "" : "getState"};778 self._stream.writeQVariantHash(params);779 self._flush(True);780 ret = self._read_return("getState");781 return ret["state"]782 def getSunPower(self):783 """784 | Return the power of the sun.785 """786 self._check_connection();787 params = { "" : "getSunPower"};788 self._stream.writeQVariantHash(params);789 self._flush(True);790 ret = self._read_return("getSunPower");791 return ret["sun_power"]792 def getTimeMapping(self):793 """794 | return true is time mapping is enabled, false otherwise.795 """796 self._check_connection();797 params = { "" : "getTimeMapping"};798 self._stream.writeQVariantHash(params);799 self._flush(True);800 ret = self._read_return("getTimeMapping");801 return ret["b_enable"]802 def help(self, function_name):803 """804 | Print the available documentation for function 'function_name'.805 """806 self._check_connection();807 params = { "" : "help"};808 params["function_name"] = str(function_name);809 self._stream.writeQVariantHash(params);810 self._flush(True);811 ret = self._read_return("help");812 print(ret['help']);813 return ret["help"]814 def intersectScene(self, rays):815 """816 | Compute the intersection of a set of rays with the scene817 | Each ray is stored as a (position,direction) pair in a std::vector/list818 | Returns the distance to the hit along each ray.819 """820 self._check_connection();821 params = { "" : "intersectScene"};822 params["rays"] = rays;823 self._stream.writeQVariantHash(params);824 self._flush(True);825 ret = self._read_return("intersectScene");826 return ret["distance_to_hit"]827 def loadAndProjectMultipleMeshes(self, object_name, mesh_names, positions, attitudes, projection_center, offset_ratio):828 """829 | Like loadMultipleMeshes it loads a list of meshes with the given positions and attitudes into a single object.830 | A quaternion on the unit sphere is a simple rotation, otherwise its norm is interpreted as a scaling factor.831 | The difference with loadMultipleMeshes is the projection of the given position onto the scene towards a projection center.832 | This point is defined in homogeneous coordinates and can be set at inifinity by setting its last coordinate to 0.833 | The last parameter is the offset, relative to the radius of each instance's bounding sphere, from the surface to the center of each object.834 | An offset_ratio of 0 means the center is on the surface, 1 means a sphere would be at the limit of penetrating the surface.835 """836 self._check_connection();837 params = { "" : "loadAndProjectMultipleMeshes"};838 params["object_name"] = str(object_name);839 params["mesh_names"] = mesh_names;840 params["positions"] = positions;841 params["attitudes"] = attitudes;842 params["projection_center"] = self._vec(projection_center);843 params["offset_ratio"] = float(offset_ratio);844 self._stream.writeQVariantHash(params);845 self._flush(True);846 if not self._async:847 ret = self._read_return("loadAndProjectMultipleMeshes");848 def loadMotionModel(self, filename, parameters):849 """850 | Load a motion model written in SuMoL from the file 'filename' with the parameters in 'parameters'.851 | A motion model defines the camera motion during image acquisition, it can also define microvibrations.852 """853 self._check_connection();854 params = { "" : "loadMotionModel"};855 params["filename"] = str(filename);856 params["parameters"] = parameters;857 self._stream.writeQVariantHash(params);858 self._flush(True);859 if not self._async:860 ret = self._read_return("loadMotionModel");861 def loadMultipleMeshes(self, object_name, mesh_names, positions, attitudes):862 """863 | Load a list of meshes with the given positions and attitudes into a single object.864 | A quaternion on the unit sphere is a simple rotation, otherwise its norm is interpreted as a scaling factor.865 """866 self._check_connection();867 params = { "" : "loadMultipleMeshes"};868 params["object_name"] = str(object_name);869 params["mesh_names"] = mesh_names;870 params["positions"] = positions;871 params["attitudes"] = attitudes;872 self._stream.writeQVariantHash(params);873 self._flush(True);874 if not self._async:875 ret = self._read_return("loadMultipleMeshes");876 def loadPSFModel(self, filename, parameters):877 """878 | Load a PSF model written in SuMoL from the file 'filename' with the parameters in 'parameters'.879 | A PSF model defines the PSF integral.880 """881 self._check_connection();882 params = { "" : "loadPSFModel"};883 params["filename"] = str(filename);884 params["parameters"] = parameters;885 self._stream.writeQVariantHash(params);886 self._flush(True);887 if not self._async:888 ret = self._read_return("loadPSFModel");889 def loadProjectionModel(self, filename, parameters):890 """891 | Load a projection model written in SuMoL from the file 'filename' with the parameters in 'parameters'.892 | A projection model defines both the projection to image plane and the optical distortion.893 """894 self._check_connection();895 params = { "" : "loadProjectionModel"};896 params["filename"] = str(filename);897 params["parameters"] = parameters;898 self._stream.writeQVariantHash(params);899 self._flush(True);900 if not self._async:901 ret = self._read_return("loadProjectionModel");902 def loadSpectrumModel(self, filename, parameters):903 """904 | Load a Spectrum model written in SuMoL from the file 'filename' with the parameters in 'parameters'.905 | A Spectrum model defines how a 4D color spectrum is converted into a continuous one and how the spectrum is sampled.906 | This is required to simulate achromatism (with a PSF model with a dependency to lambda).907 """908 self._check_connection();909 params = { "" : "loadSpectrumModel"};910 params["filename"] = str(filename);911 params["parameters"] = parameters;912 self._stream.writeQVariantHash(params);913 self._flush(True);914 if not self._async:915 ret = self._read_return("loadSpectrumModel");916 def loadTextureObject(self, name, filename, parameters):917 """918 | Load a texture. It can be any supported type of image format.919 | It can also be a procedural texture model written in SuMoL from the file 'filename' with the parameters in 'parameters' and give it the the name 'name'.920 | A procedural texture model describes a 2D or 3D texture (4D color spectrum) using lookup functions.921 """922 self._check_connection();923 params = { "" : "loadTextureObject"};924 params["name"] = str(name);925 params["filename"] = str(filename);926 params["parameters"] = parameters;927 self._stream.writeQVariantHash(params);928 self._flush(True);929 if not self._async:930 ret = self._read_return("loadTextureObject");931 def loadTimeSamplingModel(self, filename, parameters):932 """933 | Load a sampling model (raytracing) which defines when and for how long pixels gather light.934 | The model is loaded from the SuMoL file 'filename' with the parameters 'parameters'.935 """936 self._check_connection();937 params = { "" : "loadTimeSamplingModel"};938 params["filename"] = str(filename);939 params["parameters"] = parameters;940 self._stream.writeQVariantHash(params);941 self._flush(True);942 if not self._async:943 ret = self._read_return("loadTimeSamplingModel");944 def ls(self):945 """946 | List the content of the current resource path947 | This is similar to the 'ls -lh' command on Linux.948 """949 self._check_connection();950 params = { "" : "ls"};951 self._stream.writeQVariantHash(params);952 self._flush(True);953 ret = self._read_return("ls");954 print(ret['listing']);955 return ret["listing"]956 def printAPI(self):957 """958 | List all the functions of the client API.959 """960 self._check_connection();961 params = { "" : "printAPI"};962 self._stream.writeQVariantHash(params);963 self._flush(True);964 ret = self._read_return("printAPI");965 print(ret['api']);966 return ret["api"]967 def printObjectStructure(self, object_name):968 """969 | Print the structure of object 'object_name'.970 """971 self._check_connection();972 params = { "" : "printObjectStructure"};973 params["object_name"] = str(object_name);974 self._stream.writeQVariantHash(params);975 self._flush(True);976 ret = self._read_return("printObjectStructure");977 print(ret['object_structure']);978 return ret["object_structure"]979 def printState(self, state):980 """981 | Generates a human readable string representation of a saved state.982 """983 self._check_connection();984 params = { "" : "printState"};985 params["state"] = str(state);986 self._stream.writeQVariantHash(params);987 self._flush(True);988 ret = self._read_return("printState");989 print(ret['readable_state']);990 return ret["readable_state"]991 def pwd(self):992 """993 | Return the current resource path.994 | This is similar to the 'pwd' command on Linux.995 """996 self._check_connection();997 params = { "" : "pwd"};998 self._stream.writeQVariantHash(params);999 self._flush(True);1000 ret = self._read_return("pwd");1001 print(ret['path']);1002 return ret["path"]1003 def render(self):1004 """1005 | Render an image with current parameters.1006 """1007 self._check_connection();1008 params = { "" : "render"};1009 self._stream.writeQVariantHash(params);1010 self._flush(True);1011 if not self._async:1012 ret = self._read_return("render");1013 def renderMicroTasks(self, utasks):1014 """1015 | Render an image using a pregenerated list of µtasks1016 | This is what makes possible to distribute the rendering process of a single image across several machines.1017 | Using this function one can generate only a fraction of an image which can be split to be generated on several machines in parallel.1018 | 1019 | NB: works in raytracing only1020 """1021 self._check_connection();1022 params = { "" : "renderMicroTasks"};1023 params["utasks"] = utasks;1024 self._stream.writeQVariantHash(params);1025 self._flush(True);1026 if not self._async:1027 ret = self._read_return("renderMicroTasks");1028 def reset(self):1029 """1030 | Reset the engine.1031 | All ressources are freed, all scene objects/elements are deleted.1032 """1033 self._check_connection();1034 params = { "" : "reset"};1035 self._stream.writeQVariantHash(params);1036 self._flush(True);1037 if not self._async:1038 ret = self._read_return("reset");1039 def runPerPixelProcess(self, output_name, process_name):1040 """1041 | Run a function on each pixel of a texture.1042 | If 'output_name' is empty, it targets the framebuffer (rendered image buffer).1043 | You must create the PerPixelProcess object first with createPerPixelProcess.1044 """1045 self._check_connection();1046 params = { "" : "runPerPixelProcess"};1047 params["output_name"] = str(output_name);1048 params["process_name"] = str(process_name);1049 self._stream.writeQVariantHash(params);1050 self._flush(True);1051 if not self._async:1052 ret = self._read_return("runPerPixelProcess");1053 def saveDepthMap(self, filename):1054 """1055 | Save the depth map in file 'filename'. Only TIF format is supported.1056 """1057 self._check_connection();1058 params = { "" : "saveDepthMap"};1059 params["filename"] = str(filename);1060 self._stream.writeQVariantHash(params);1061 self._flush(True);1062 if not self._async:1063 ret = self._read_return("saveDepthMap");1064 def saveImage(self, filename):1065 """1066 | Save the image in file 'filename'. File format is guessed from extension.1067 | [0-1] range is mapped to 8bits when required.1068 """1069 self._check_connection();1070 params = { "" : "saveImage"};1071 params["filename"] = str(filename);1072 self._stream.writeQVariantHash(params);1073 self._flush(True);1074 if not self._async:1075 ret = self._read_return("saveImage");1076 def saveImageGray32F(self, filename):1077 """1078 | Save the image in file 'filename'. File format is guessed from extension.1079 | The first 3 channels are averaged and the result is stored in float format.1080 """1081 self._check_connection();1082 params = { "" : "saveImageGray32F"};1083 params["filename"] = str(filename);1084 self._stream.writeQVariantHash(params);1085 self._flush(True);1086 if not self._async:1087 ret = self._read_return("saveImageGray32F");1088 def saveImageGray8(self, filename):1089 """1090 | Save the image in file 'filename'. File format is guessed from extension.1091 | [0-1] range is mapped to 8bits and the first 3 channels are averaged.1092 """1093 self._check_connection();1094 params = { "" : "saveImageGray8"};1095 params["filename"] = str(filename);1096 self._stream.writeQVariantHash(params);1097 self._flush(True);1098 if not self._async:1099 ret = self._read_return("saveImageGray8");1100 def saveImageRGB8(self, filename):1101 """1102 | Save the image in file 'filename'. File format is guessed from extension.1103 | [0-1] range is mapped to 8bits and only the first 3 channels are considered.1104 """1105 self._check_connection();1106 params = { "" : "saveImageRGB8"};1107 params["filename"] = str(filename);1108 self._stream.writeQVariantHash(params);1109 self._flush(True);1110 if not self._async:1111 ret = self._read_return("saveImageRGB8");1112 def saveImageSpectrumProjection(self, filename, spectrum):1113 """1114 | Save the image in file 'filename'. File format is guessed from extension.1115 | The 4 channels are weighted according to the 'spectrum' parameter and the result is stored in float format.1116 """1117 self._check_connection();1118 params = { "" : "saveImageSpectrumProjection"};1119 params["filename"] = str(filename);1120 params["spectrum"] = self._vec(spectrum);1121 self._stream.writeQVariantHash(params);1122 self._flush(True);1123 if not self._async:1124 ret = self._read_return("saveImageSpectrumProjection");1125 def saveImageSpectrumProjectionQuantized(self, filename, spectrum, nbits):1126 """1127 | Save the image in file 'filename'. File format is guessed from extension.1128 | The 4 channels are weighted according to the 'spectrum' parameter and the result is stored in integer 8/16bits format after quantization.1129 | This last step is done using 'nbits' to define the valid range. If nbits <= 8, the result is stored in an 8bits image, otherwise it is stored in a 16bits image.1130 """1131 self._check_connection();1132 params = { "" : "saveImageSpectrumProjectionQuantized"};1133 params["filename"] = str(filename);1134 params["spectrum"] = self._vec(spectrum);1135 params["nbits"] = int(nbits);1136 self._stream.writeQVariantHash(params);1137 self._flush(True);1138 if not self._async:1139 ret = self._read_return("saveImageSpectrumProjectionQuantized");1140 def saveObject(self, object_name, filename):1141 """1142 | Save object 'object_name' to file 'filename'.1143 """1144 self._check_connection();1145 params = { "" : "saveObject"};1146 params["object_name"] = str(object_name);1147 params["filename"] = str(filename);1148 self._stream.writeQVariantHash(params);1149 self._flush(True);1150 if not self._async:1151 ret = self._read_return("saveObject");1152 def setAlias(self, object_name, alias):1153 """1154 | Create an alias for an existing object.1155 """1156 self._check_connection();1157 params = { "" : "setAlias"};1158 params["object_name"] = str(object_name);1159 params["alias"] = str(alias);1160 self._stream.writeQVariantHash(params);1161 self._flush(True);1162 if not self._async:1163 ret = self._read_return("setAlias");1164 def setBackground(self, background):1165 """1166 | Set the background to render: either a spherical texture or a star map.1167 """1168 self._check_connection();1169 params = { "" : "setBackground"};1170 params["background"] = str(background);1171 self._stream.writeQVariantHash(params);1172 self._flush(True);1173 if not self._async:1174 ret = self._read_return("setBackground");1175 def setCameraFOVDeg(self, fov_x, fov_y):1176 """1177 | Set camera field of view in degrees.1178 """1179 self._check_connection();1180 params = { "" : "setCameraFOVDeg"};1181 params["fov_x"] = float(fov_x);1182 params["fov_y"] = float(fov_y);1183 self._stream.writeQVariantHash(params);1184 self._flush(True);1185 if not self._async:1186 ret = self._read_return("setCameraFOVDeg");1187 def setCameraFOVRad(self, fov_x, fov_y):1188 """1189 | Set camera field of view in radians.1190 """1191 self._check_connection();1192 params = { "" : "setCameraFOVRad"};1193 params["fov_x"] = float(fov_x);1194 params["fov_y"] = float(fov_y);1195 self._stream.writeQVariantHash(params);1196 self._flush(True);1197 if not self._async:1198 ret = self._read_return("setCameraFOVRad");1199 def setConventions(self, quaternion_convention, camera_convention):1200 """1201 | Set the conventions for quaternions and camera frame definition.1202 """1203 self._check_connection();1204 params = { "" : "setConventions"};1205 params["quaternion_convention"] = int(quaternion_convention);1206 params["camera_convention"] = int(camera_convention);1207 self._stream.writeQVariantHash(params);1208 self._flush(True);1209 if not self._async:1210 ret = self._read_return("setConventions");1211 def setCubeMapSize(self, cube_map_size):1212 """1213 | Set the size of cube maps when creating new meshes.1214 """1215 self._check_connection();1216 params = { "" : "setCubeMapSize"};1217 params["cube_map_size"] = cube_map_size;1218 self._stream.writeQVariantHash(params);1219 self._flush(True);1220 if not self._async:1221 ret = self._read_return("setCubeMapSize");1222 def setCubeMapZNear(self, znear):1223 """1224 | Set the distance (in meters) of the near plane when rendering cubemaps. Default is 10km.1225 """1226 self._check_connection();1227 params = { "" : "setCubeMapZNear"};1228 params["znear"] = float(znear);1229 self._stream.writeQVariantHash(params);1230 self._flush(True);1231 if not self._async:1232 ret = self._read_return("setCubeMapZNear");1233 def setFSAA(self, fsaa):1234 """1235 | Set the super sampling factor in OpenGL mode. 1 means disabled.1236 | The number of samples per pixel is equal to this parameter squared.1237 | Disabled by default.1238 """1239 self._check_connection();1240 params = { "" : "setFSAA"};1241 params["fsaa"] = int(fsaa);1242 self._stream.writeQVariantHash(params);1243 self._flush(True);1244 if not self._async:1245 ret = self._read_return("setFSAA");1246 def setFocus(self, focus_plane_Z, pupil_radius):1247 """1248 | Set parameters for defocus/depth of field simulation.1249 | If focus_plane_Z or pupil_radius is set to 0, defocus/depth of field is not simulated.1250 | 1251 | Default: disabled1252 """1253 self._check_connection();1254 params = { "" : "setFocus"};1255 params["focus_plane_Z"] = float(focus_plane_Z);1256 params["pupil_radius"] = float(pupil_radius);1257 self._stream.writeQVariantHash(params);1258 self._flush(True);1259 if not self._async:1260 ret = self._read_return("setFocus");1261 def setGlobalVariables(self, names_and_values):1262 """1263 | Set the values of a set of global SuMoL variables.1264 | NB: this only affects globals for already loaded SuMoL models. When loading a new model its globals will be kept at their default values!1265 """1266 self._check_connection();1267 params = { "" : "setGlobalVariables"};1268 params["names_and_values"] = names_and_values;1269 self._stream.writeQVariantHash(params);1270 self._flush(True);1271 if not self._async:1272 ret = self._read_return("setGlobalVariables");1273 def setImageSize(self, width, height):1274 """1275 | Set image size.1276 """1277 self._check_connection();1278 params = { "" : "setImageSize"};1279 params["width"] = width;1280 params["height"] = height;1281 self._stream.writeQVariantHash(params);1282 self._flush(True);1283 if not self._async:1284 ret = self._read_return("setImageSize");1285 def setIntegrationTime(self, integration_time):1286 """1287 | Set integration time in seconds.1288 | NB: if using a sensor model, please refer to its API instead of this function.1289 """1290 self._check_connection();1291 params = { "" : "setIntegrationTime"};1292 params["integration_time"] = float(integration_time);1293 self._stream.writeQVariantHash(params);1294 self._flush(True);1295 if not self._async:1296 ret = self._read_return("setIntegrationTime");1297 def setMaxSamplesPerPixel(self, max_samples):1298 """1299 | Set the maximum number of samples per pixel when dynamically increased to reduce noise on edges.1300 """1301 self._check_connection();1302 params = { "" : "setMaxSamplesPerPixel"};1303 params["max_samples"] = int(max_samples);1304 self._stream.writeQVariantHash(params);1305 self._flush(True);1306 if not self._async:1307 ret = self._read_return("setMaxSamplesPerPixel");1308 def setMaxSecondaryRays(self, max_secondary_rays):1309 """1310 | Set the maximum number of secondary rays (default is 4) when pathtracing is enabled.1311 """1312 self._check_connection();1313 params = { "" : "setMaxSecondaryRays"};1314 params["max_secondary_rays"] = int(max_secondary_rays);1315 self._stream.writeQVariantHash(params);1316 self._flush(True);1317 if not self._async:1318 ret = self._read_return("setMaxSecondaryRays");1319 def setMaxShadowRays(self, max_shadow_rays):1320 """1321 | Set the maximum number of rays used for direct shadows.1322 | Default is 4.1323 """1324 self._check_connection();1325 params = { "" : "setMaxShadowRays"};1326 params["max_shadow_rays"] = int(max_shadow_rays);1327 self._stream.writeQVariantHash(params);1328 self._flush(True);1329 if not self._async:1330 ret = self._read_return("setMaxShadowRays");1331 def setMetadata(self, name, value):1332 """1333 | Add, update or remove a metadata1334 | If value is empty, the metadata is removed1335 | Metadata are used when sending images over TCP. This is typically used to store timestamps and image IDs.1336 """1337 self._check_connection();1338 params = { "" : "setMetadata"};1339 params["name"] = str(name);1340 params["value"] = value;1341 self._stream.writeQVariantHash(params);1342 self._flush(True);1343 if not self._async:1344 ret = self._read_return("setMetadata");1345 def setNbSamplesPerPixel(self, nb_samples):1346 """1347 | Set the number of samples per pixel (raytracing).1348 """1349 self._check_connection();1350 params = { "" : "setNbSamplesPerPixel"};1351 params["nb_samples"] = int(nb_samples);1352 self._stream.writeQVariantHash(params);1353 self._flush(True);1354 if not self._async:1355 ret = self._read_return("setNbSamplesPerPixel");1356 def setNearPlane(self, z):1357 """1358 | Set the distance of the near plane (OpenGL only). Objects or parts of objects closer than this distance won't be rendered.1359 """1360 self._check_connection();1361 params = { "" : "setNearPlane"};1362 params["z"] = float(z);1363 self._stream.writeQVariantHash(params);1364 self._flush(True);1365 if not self._async:1366 ret = self._read_return("setNearPlane");1367 def setObjectAttitude(self, object_name, attitude):1368 """1369 | Set the attitude of object 'object_name'.1370 | Use 'camera' as object name to change the attitude of the camera.1371 """1372 self._check_connection();1373 params = { "" : "setObjectAttitude"};1374 params["object_name"] = str(object_name);1375 params["attitude"] = self._vec(attitude);1376 self._stream.writeQVariantHash(params);1377 self._flush(True);1378 if not self._async:1379 ret = self._read_return("setObjectAttitude");1380 def setObjectDynamicCubeMap(self, object_name, enable):1381 """1382 | Enable (true) or disable (false) dynamic cube maps for object 'object_name'.1383 | A dynamic cube map is updated at each frame whereas a static one is kept as is.1384 | This is an OpenGL only option.1385 """1386 self._check_connection();1387 params = { "" : "setObjectDynamicCubeMap"};1388 params["object_name"] = str(object_name);1389 params["enable"] = bool(enable);1390 self._stream.writeQVariantHash(params);1391 self._flush(True);1392 if not self._async:1393 ret = self._read_return("setObjectDynamicCubeMap");1394 def setObjectDynamicShadowMap(self, object_name, enable):1395 """1396 | Enable (true) or disable (false) dynamic shadow maps for object 'object_name'.1397 | A dynamic shadow map is updated at each frame whereas a static one is kept as is.1398 | This is an OpenGL only option.1399 """1400 self._check_connection();1401 params = { "" : "setObjectDynamicShadowMap"};1402 params["object_name"] = str(object_name);1403 params["enable"] = bool(enable);1404 self._stream.writeQVariantHash(params);1405 self._flush(True);1406 if not self._async:1407 ret = self._read_return("setObjectDynamicShadowMap");1408 def setObjectElementBRDF(self, object_name, element_name, brdf):1409 """1410 | Set the BRDF for an element of an object.1411 | If 'object_name' = 'element_name' the BRDF is applied to the whole object.1412 """1413 self._check_connection();1414 params = { "" : "setObjectElementBRDF"};1415 params["object_name"] = str(object_name);1416 params["element_name"] = str(element_name);1417 params["brdf"] = str(brdf);1418 self._stream.writeQVariantHash(params);1419 self._flush(True);1420 if not self._async:1421 ret = self._read_return("setObjectElementBRDF");1422 def setObjectElementProperty(self, name, element_name, property, value):1423 """1424 | Set property 'property' to 'value' for element 'element_name' in object 'name'.1425 | Available properties are:1426 | photon_map_sampling_step Sampling step (distance between samples) for this element in the photon map.1427 | If 0, no samples will be generated for this object.1428 | If < 0.0, density is inherited from parent node.1429 """1430 self._check_connection();1431 params = { "" : "setObjectElementProperty"};1432 params["name"] = str(name);1433 params["element_name"] = str(element_name);1434 params["property"] = str(property);1435 params["value"] = float(value);1436 self._stream.writeQVariantHash(params);1437 self._flush(True);1438 if not self._async:1439 ret = self._read_return("setObjectElementProperty");1440 def setObjectElementTransform(self, object_name, element_name, matrix, relative):1441 """1442 | Set the local (relative = true) or global (relative = false) transformation1443 | of an element of an object. 'matrix' is a 4x4 matrix representing this transformation.1444 """1445 self._check_connection();1446 params = { "" : "setObjectElementTransform"};1447 params["object_name"] = str(object_name);1448 params["element_name"] = str(element_name);1449 params["matrix"] = self._mat44(matrix);1450 params["relative"] = bool(relative);1451 self._stream.writeQVariantHash(params);1452 self._flush(True);1453 if not self._async:1454 ret = self._read_return("setObjectElementTransform");1455 def setObjectMotion(self, object_name, motion):1456 """1457 | Set motion parameters (speed & rotation speed) for object 'object_name'.1458 """1459 self._check_connection();1460 params = { "" : "setObjectMotion"};1461 params["object_name"] = str(object_name);1462 params["motion"] = [ self._vec(motion[0]), self._vec(motion[1]) ];1463 self._stream.writeQVariantHash(params);1464 self._flush(True);1465 if not self._async:1466 ret = self._read_return("setObjectMotion");1467 def setObjectPosition(self, object_name, pos):1468 """1469 | Set the position of object 'object_name'.1470 | Use 'camera' as object name to change the position of the camera.1471 """1472 self._check_connection();1473 params = { "" : "setObjectPosition"};1474 params["object_name"] = str(object_name);1475 params["pos"] = self._vec(pos);1476 self._stream.writeQVariantHash(params);1477 self._flush(True);1478 if not self._async:1479 ret = self._read_return("setObjectPosition");1480 def setObjectProperty(self, name, property, value):1481 """1482 | Set property 'property' to 'value' for object 'name'.1483 | Available properties are:1484 | photon_map (boolean) If true object will have a photon map to accumulate energy received on its surface.1485 | normal_map_object_space (boolean) If true normal maps are read in object frame instead of tangent space.1486 | skip_path_tracing (boolean) If true the object won't be sampled as a secondary light source when pathtracing is enabled.1487 """1488 self._check_connection();1489 params = { "" : "setObjectProperty"};1490 params["name"] = str(name);1491 params["property"] = str(property);1492 params["value"] = float(value);1493 self._stream.writeQVariantHash(params);1494 self._flush(True);1495 if not self._async:1496 ret = self._read_return("setObjectProperty");1497 def setObjectSamples(self, object_name, nb_samples):1498 """1499 | Set a quota of samples to cast over an object.1500 | Surrender will cast at least that many primary rays toward this object.1501 """1502 self._check_connection();1503 params = { "" : "setObjectSamples"};1504 params["object_name"] = str(object_name);1505 params["nb_samples"] = float(nb_samples);1506 self._stream.writeQVariantHash(params);1507 self._flush(True);1508 if not self._async:1509 ret = self._read_return("setObjectSamples");1510 def setPSFSigma(self, sigma):1511 """1512 | Set the sigma parameter of a gaussian PSF in OpenGL mode. 0.0 means disabled.1513 | Disabled by default.1514 """1515 self._check_connection();1516 params = { "" : "setPSFSigma"};1517 params["sigma"] = float(sigma);1518 self._stream.writeQVariantHash(params);1519 self._flush(True);1520 if not self._async:1521 ret = self._read_return("setPSFSigma");1522 def setPhotonMapSamplingStep(self, step):1523 """1524 | Set the sampling step for generating photon maps (for meshes) in pathtracing.1525 | Default value is 1e-1. Reducing this value produces better results but requires more memory and more processing time (more rays).1526 """1527 self._check_connection();1528 params = { "" : "setPhotonMapSamplingStep"};1529 params["step"] = float(step);1530 self._stream.writeQVariantHash(params);1531 self._flush(True);1532 if not self._async:1533 ret = self._read_return("setPhotonMapSamplingStep");1534 def setRessourcePath(self, ressource_path):1535 """1536 | Set the reference path (server side) to access ressources (models, textures, ...).1537 """1538 self._check_connection();1539 params = { "" : "setRessourcePath"};1540 params["ressource_path"] = str(ressource_path);1541 self._stream.writeQVariantHash(params);1542 self._flush(True);1543 if not self._async:1544 ret = self._read_return("setRessourcePath");1545 def setSelfVisibilitySamplingStep(self, step):1546 """1547 | Set the sampling step for generating self visibility maps (for meshes) in pathtracing.1548 | Default value is 1e-1. Reducing this value produces better results but requires more memory and more preprocessing time.1549 """1550 self._check_connection();1551 params = { "" : "setSelfVisibilitySamplingStep"};1552 params["step"] = float(step);1553 self._stream.writeQVariantHash(params);1554 self._flush(True);1555 if not self._async:1556 ret = self._read_return("setSelfVisibilitySamplingStep");1557 def setShadowMapSize(self, shadow_map_size):1558 """1559 | Set the size of shadow maps when creating new meshes.1560 """1561 self._check_connection();1562 params = { "" : "setShadowMapSize"};1563 params["shadow_map_size"] = shadow_map_size;1564 self._stream.writeQVariantHash(params);1565 self._flush(True);1566 if not self._async:1567 ret = self._read_return("setShadowMapSize");1568 def setStarThreshold(self, threshold):1569 """1570 | Set the lowest value (in W/m^2) for a star to be rendered.1571 | If any spectrum component is above this threshold the star will be rendered otherwise it will be ignored.1572 | Default is 0.1573 | 1574 | NB: applies only to raytracing1575 | 1576 """1577 self._check_connection();1578 params = { "" : "setStarThreshold"};1579 params["threshold"] = float(threshold);1580 self._stream.writeQVariantHash(params);1581 self._flush(True);1582 if not self._async:1583 ret = self._read_return("setStarThreshold");1584 def setState(self, state):1585 """1586 | Restores a previously saved state of the scene manager.1587 | This will restore position,attitude,motion of all objects in the scene as well as renderer settings.1588 | Objects are not created, they must exist in the scene before restoring the scene state.1589 """1590 self._check_connection();1591 params = { "" : "setState"};1592 params["state"] = str(state);1593 self._stream.writeQVariantHash(params);1594 self._flush(True);1595 if not self._async:1596 ret = self._read_return("setState");1597 def setSunPower(self, sun_color):1598 """1599 | Set the power emitted by the Sun for each wave length simulated.1600 | This is expressed in W/sr.1601 """1602 self._check_connection();1603 params = { "" : "setSunPower"};1604 params["sun_color"] = self._vec(sun_color);1605 self._stream.writeQVariantHash(params);1606 self._flush(True);1607 if not self._async:1608 ret = self._read_return("setSunPower");1609 def setSunPowerAtDistance(self, sun_color, distance):1610 """1611 | Set the received from the Sun for each wave length simulated at a given distance.1612 | This is expressed in W/m² for the power and in m for the distance.1613 """1614 self._check_connection();1615 params = { "" : "setSunPowerAtDistance"};1616 params["sun_color"] = self._vec(sun_color);1617 params["distance"] = float(distance);1618 self._stream.writeQVariantHash(params);1619 self._flush(True);1620 if not self._async:1621 ret = self._read_return("setSunPowerAtDistance");1622 def updateDisplay(self):1623 """1624 | Update viewer window on the server side.1625 | This is useful after framebuffer has been modified with a PerPixelProcess1626 """1627 self._check_connection();1628 params = { "" : "updateDisplay"};1629 self._stream.writeQVariantHash(params);1630 self._flush(True);1631 if not self._async:1632 ret = self._read_return("updateDisplay");1633 def updateDynamicTexture(self, name):1634 """1635 | Trigger an update of the dynamic texture 'name'.1636 """1637 self._check_connection();1638 params = { "" : "updateDynamicTexture"};1639 params["name"] = str(name);1640 self._stream.writeQVariantHash(params);1641 self._flush(True);1642 if not self._async:1643 ret = self._read_return("updateDynamicTexture");1644 def version(self):1645 """1646 | Returns the server version number and GIT revision if available.1647 """1648 self._check_connection();1649 params = { "" : "version"};1650 self._stream.writeQVariantHash(params);1651 self._flush(True);1652 ret = self._read_return("version");...

Full Screen

Full Screen

FA.py

Source:FA.py Github

copy

Full Screen

...101 msg = '{0}: No return({1})'.format(cmd,loop)102 print(msg)103 loop = loop + 1104 return(r);105 def _flush(self):106 count = self.__ser.in_waiting107 while (count > 0):108 self.__ser.readline().rstrip()109 count = self.__ser.in_waiting110 return;111 def _set_verbose(self, value):112 self.__verbose = value113 return;114 115 116 def GetAPIVersion(self):117 """Retrieves the API version from the robot118 Returns:119 int: The API version in the robot120 """121 self._flush()122 s = 'GetAPIVersion\n'123 self.__ser.write(s.encode())124 r = self._readval("GetAPIVersion", 1)125 return(r);126 127 def ReadSwitch(self, index):128 """Read the switch value129 Args:130 index: 0 (left) or 1 (right)131 Returns:132 int: 0 (false) or 1 (true)133 """134 self._flush()135 s = 'ReadSwitch {0}\n'.format(int(index))136 self.__ser.write(s.encode())137 r = self._readval("ReadSwitch", 1)138 return(r);139 def ReadIR(self, index):140 """Read the IR value141 Args:142 index: IR sensor to query (0 to 7)143 Returns:144 int: Value of IR sensor (0 to 4095)145 """146 self._flush()147 s = 'ReadIR {0}\n'.format(int(index))148 self.__ser.write(s.encode())149 r = self._readval("ReadIR", 1)150 return(r);151 def ReadLine(self, index):152 """Read the line sensor value153 Args:154 index: Line sensor to query (0 to 1)155 Returns:156 int: Value of Line sensor (0 to 4095)157 """158 self._flush()159 s = 'ReadLine {0}\n'.format(int(index))160 self.__ser.write(s.encode())161 r = self._readval("ReadLine", 1)162 return(r);163 def ReadLight(self):164 """Read the light sensor value165 Returns:166 int: Value of light sensor (0 to 4095)167 """168 self._flush()169 s = 'ReadLight\n'170 self.__ser.write(s.encode())171 r = self._readval("ReadLight", 1)172 return(r);173 def ReadMic(self):174 """Read the microphone sensor value175 Returns:176 int: Value of microphone sensor (0 to 4095)177 """178 self._flush()179 s = 'ReadMic\n'180 self.__ser.write(s.encode())181 r = self._readval("ReadMic", 1)182 return(r);183 def ReadAxis(self, index):184 """Read the axis value of the accelerometer185 Args:186 index: Axis to query (0 to 3)187 Returns:188 int: Value of accelerometer axis (-32768 to 32767)189 """190 self._flush()191 s = 'ReadAxis {0}\n'.format(int(index))192 self.__ser.write(s.encode())193 r = self._readval("ReadAxis", 1)194 return(r);195 def SetMotors(self, left, right):196 """Set the motors speed197 Args:198 left: value of left motor (0 to 100)199 right: value of right motor (0 to 100)200 """201 s = 'SetMotors {0} {1}\n'.format(int(left),int(right))202 self.__ser.write(s.encode())203 return;204 def Forwards(self, distance):205 """Set the robot moving forward206 Args:207 distance: distance to move (0 to 1000) in mm208 """209 self._flush()210 s = 'Forwards {0}\n'.format(int(distance))211 self.__ser.write(s.encode())212 timeout = abs(int(distance / 50))213 if (timeout <= 0):214 timeout = 1215 r = self._readval("Forwards", timeout)216 return(r);217 def Backwards(self, distance):218 """Set the robot moving backwards219 Args:220 distance: distance to move (0 to 1000) in mm221 """222 self._flush()223 s = 'Backwards {0}\n'.format(int(distance))224 self.__ser.write(s.encode())225 timeout = abs(int(distance / 50))226 if (timeout <= 0):227 timeout = 1228 r = self._readval("Backwards", timeout)229 return(r);230 def Left(self, angle):231 """Set the robot to turn left232 Args:233 angle: angle to rotate (0 to 360) in degrees234 """235 self._flush()236 s = 'Left {0}\n'.format(int(angle))237 self.__ser.write(s.encode())238 timeout = abs(int(angle / 45))239 if (timeout <= 0):240 timeout = 1241 r = self._readval("Left", timeout)242 return(r);243 def Right(self, angle):244 """Set the robot to turn right245 Args:246 angle: angle to rotate (0 to 360) in degrees247 """248 self._flush()249 s = 'Right {0}\n'.format(int(angle))250 self.__ser.write(s.encode())251 timeout = abs(int(angle / 45))252 if (timeout <= 0):253 timeout = 1254 r = self._readval("Right", timeout)255 return(r);256 257 def LEDWrite(self, value):258 """Set the value of the LEDs259 Args:260 value: Value to set the LEDS (0 to 255)261 """262 s = 'LEDWrite {0}\n'.format(int(value))263 self.__ser.write(s.encode())264 return;265 def LEDOn(self, index):266 """Turn an LED on267 Args:268 index: The LED to turn on (0 to 7)269 """270 s = 'LEDOn {0}\n'.format(int(index))271 self.__ser.write(s.encode())272 return;273 def LEDOff(self, index):274 """Turn an LED off275 Args:276 index: The LED to turn off (0 to 7)277 """278 s = 'LEDOff {0}\n'.format(int(index))279 self.__ser.write(s.encode())280 return;281 def PlayNote(self, note, length):282 """Play a note on the speaker283 Args:284 note: The frequency of the note (1 to 10000) in Hz285 length: The duration of the note (1 to 10000) in ms286 """287 s = 'PlayNote {0} {1}\n'.format(int(note),int(length))288 self.__ser.write(s.encode())289 time.sleep(length/1000)290 return;291 292 def GetBattery():293 s = 'GetBattery\n'294 self.__ser.write(s.encode())295 r = self._readval("Battery", timeout)296 return(r);297 298 def ExpDDR(bitnumber,direction):299 s = 'ExpDDR {0} {1}\n'.format(bitnumber,direction)300 self.__ser.write(s.encode())301 return;302 303 def ExpRead(bitnumber):304 s = 'ExpRead {0}\n'.format(bitnumber)305 self.__ser.write(s.encode())306 r = self._readval("Bit", timeout)307 return(r);308 309 def ExpWrite(bitnumber,value):310 s = 'ExpWrite {0} {1}\n'.format(bitnumber,value)311 self.__ser.write(s.encode())312 return;313 314 def ExpAn(annumber):315 s = 'ExpAn {0}\n'.format(annumber)316 self.__ser.write(s.encode())317 r = self._readval("An", timeout)318 return(r);319## #blocking...320## def PlayNote(self, note, time):321## self._flush()322## s = 'PlayNote {0} {1}\n'.format(int(note),int(time))323## self.__ser.write(s.encode())324## timeout = abs(int(time / 1000))325## if (timeout <= 0):326## timeout = 1327## r = self._readval("PlayNote", timeout)328## return;329 def ServoEnable(self, index):330 """Enable a servo motor331 Args:332 index: The servo to control (0 to 3)333 """334 s = 'ServoEnable {0}\n'.format(int(index))335 self.__ser.write(s.encode())336 return;337 def ServoDisable(self, index):338 """Disable a servo motor339 Args:340 index: The servo to control (0 to 3)341 """342 s = 'ServoDisable {0}\n'.format(int(index))343 self.__ser.write(s.encode())344 return;345 def ServoSetPos(self, index, position):346 """Move a servo immediately to a position347 Args:348 index: The servo to control (0 to 3)349 position: The position of the servo (0 to 255)350 """351 s = 'ServoSetPos {0} {1}\n'.format(int(index),int(position))352 self.__ser.write(s.encode())353 return;354 def ServoAutoMove(self, index, position):355 """Auto-move a servo to a position356 Args:357 index: The servo to control (0 to 3)358 position: The position of the servo (0 to 255)359 """360 s = 'ServoAutoMove {0} {1}\n'.format(int(index),int(position))361 self.__ser.write(s.encode())362 return;363 def ServoMoveSpeed(self, speed):364 """Set the auto-move speed365 Args:366 speed: The servo speed (1 to 50)367 """368 s = 'ServoMoveSpeed {0}\n'.format(int(speed))369 self.__ser.write(s.encode())370 return;371 def LCDClear(self):372 """Clear the LCD373 """374 s = 'LCDClear\n'375 self.__ser.write(s.encode())376 return;377 def LCDPrint(self, x, y, text):378 """Display text on the LCD379 Args:380 x: The x-coordinate (0 to 127)381 y: The y-coordinate (0 to 31)382 text: The text to display383 """384 s = 'LCDPrint {0} {1} {2}\n'.format(int(x),int(y),text)385 self.__ser.write(s.encode())386 return;387 def LCDNumber(self, x, y, value):388 """Display a number on the LCD389 Args:390 x: The x-coordinate (0 to 127)391 y: The y-coordinate (0 to 31)392 value: The number to display (-32768 to 32767)393 """394 s = 'LCDNumber {0} {1} {2}\n'.format(int(x),int(y),int(value))395 self.__ser.write(s.encode())396 return;397 def LCDPixel(self, x, y, state):398 """Display a pixel on the LCD399 Args:400 x: The x-coordinate (0 to 127)401 y: The y-coordinate (0 to 31)402 state: 0 (off) or 1 (on)403 """404 s = 'LCDPixel {0} {1} {2}\n'.format(int(x),int(y),int(state))405 self.__ser.write(s.encode())406 return;407 def LCDLine(self, x1, y1, x2, y2):408 """Display a line on the LCD between points A and B409 Args:410 x1: The x-coordinate of point A (0 to 127)411 y1: The y-coordinate of point A (0 to 31)412 x2: The x-coordinate of point B (0 to 127)413 y2: The y-coordinate of point B (0 to 31)414 """415 s = 'LCDLine {0} {1} {2} {3}\n'.format(int(x1),int(y1),int(x2),int(y2))416 self.__ser.write(s.encode())417 return;418 def LCDRect(self, x1, y1, x2, y2):419 """Display a rectangle on the LCD between points A and B420 Args:421 x1: The x-coordinate of point A (0 to 127)422 y1: The y-coordinate of point A (0 to 31)423 x2: The x-coordinate of point B (0 to 127)424 y2: The y-coordinate of point B (0 to 31)425 """426 s = 'LCDRect {0} {1} {2} {3}\n'.format(int(x1),int(y1),int(x2),int(y2))427 self.__ser.write(s.encode())428 return;429 def LCDBacklight(self, value):430 """Control the backlight of the display431 Args:432 value: The brightness of the backlight (0 to 100)433 """434 s = 'LCDBacklight {0}\n'.format(int(value))435 self.__ser.write(s.encode())436 return;437 def LCDOptions(self, foreground, background, transparent):438 """Set the options for the display439 Args:440 foreground: The foreground colour, 0 (white) or 1 (black)441 background: The background colour, 0 (white) or 1 (black)442 transparent: The transparency, 0 (false) or 1 (true)443 """444 s = 'LCDOptions {0} {1} {2}\n'.format(int(foreground), int(background), int(transparent))445 self.__ser.write(s.encode())446 return;447 def _LCDVerbose(self, value):448 s = 'LCDVerbose {0}\n'.format(int(value))449 self.__ser.write(s.encode())450 return;451 def CardInit(self):452 self._flush()453 s = 'CardInit\n'454 self.__ser.write(s.encode())455 r = self._readval("CardInit", 2)456 return(r);457 def CardCreate(self, filename):458 self._flush()459 s = 'CardCreate {0}\n'.format(filename)460 self.__ser.write(s.encode())461 r = self._readval("CardCreate", 2)462 return(r);463 def CardOpen(self, filename):464 self._flush()465 s = 'CardOpen {0}\n'.format(filename)466 self.__ser.write(s.encode())467 r = self._readval("CardOpen", 2)468 return(r);469 def CardDelete(self, filename):470 self._flush()471 s = 'CardDelete {0}\n'.format(filename)472 self.__ser.write(s.encode())473 r = self._readval("CardDelete", 2)474 return(r);475 def CardWriteByte(self, data):476 #self._flush()477 s = 'CardWriteByte {0}\n'.format(int(data))478 self.__ser.write(s.encode())479 #r = self._readval("CardWriteByte", 2)480 return();481 def CardReadByte(self):482 self._flush()483 s = 'CardReadByte\n'484 self.__ser.write(s.encode())485 r = self._readval("CardReadByte", 2)486 return(r);487 def CardRecordMic(self, bitdepth, samplerate, time, filename):488 self._flush()489 s = 'CardRecordMic {0} {1} {2} {3}\n'.format(int(bitdepth),int(samplerate),int(time),filename)490 self.__ser.write(s.encode())491 r = self._readval("CardRecordMic", time+1)492 return(r);493 def CardPlayback(self, filename):494 self._flush()495 s = 'CardPlayback {0}\n'.format(filename)496 self.__ser.write(s.encode())497 r = self._readval("CardPlayback", 50)498 return(r);499 def CardBitmap(self, x, y, filename):500 self._flush()501 s = 'CardBitmap {0} {1} {2}\n'.format(int(x),int(y),filename)502 self.__ser.write(s.encode())503 r = self._readval("CardBitmap", 5)504 return(r);...

Full Screen

Full Screen

RT_IB.py

Source:RT_IB.py Github

copy

Full Screen

...102 msg = '{0}: No return({1})'.format(cmd,loop)103 print(msg)104 loop = loop + 1105 return(r);106 def _flush(self):107 count = self.__ser.in_waiting108 while (count > 0):109 self.__ser.readline().rstrip()110 count = self.__ser.in_waiting111 return;112 def _set_verbose(self, value):113 self.__verbose = value114 return;115 def ADCSample8(self, channel):116 """Reads an analogue value from a pin as an 8-bit value117 Args:118 channel: The pin to read to (0 to 2)119 Returns:120 The voltage of the pin (0 to 255)121 """122 self._flush()123 values = bytearray([0x9B, channel, 0])124 self.__ser.write(values)125 values = self.__ser.read(3)126 return(values[2]);127 def ADCSample10(self, channel):128 """Reads an analogue value from a pin as a 10-bit value129 Args:130 channel: The pin to read to (0 to 2)131 Returns:132 The voltage of the pin (0 to 1023)133 """134 self._flush()135 values = bytearray([0x9C, channel, 0, 0])136 self.__ser.write(values)137 values = self.__ser.read(4)138 r = (values[2] * 256) + values[3]139 return(r);140 def DACDisable(self):141 """Disables the DAC output142 143 """144 self._flush()145 values = bytearray([0x9E])146 self.__ser.write(values)147 values = self.__ser.read(1)148 return;149 def DACEnable(self):150 """Enables the DAC output151 152 """153 self._flush()154 values = bytearray([0x9D])155 self.__ser.write(values)156 values = self.__ser.read(1)157 return;158 def DACOutput(self, value):159 """Writes a 5-bit value to the DAC output160 161 Args:162 value: The value to write to (0 to 31)163 164 """165 self._flush()166 values = bytearray([0x9F, value])167 self.__ser.write(values)168 values = self.__ser.read(2)169 return;170 def I2CInitialise(self):171 """Enables the I2C interface172 173 """174 self._flush()175 values = bytearray([0x86])176 self.__ser.write(values)177 values = self.__ser.read(1)178 return;179 def I2CReceive(self, last):180 """Reads an byte from the I2C interface181 182 Args:183 last: The last byte to read? (0 to 1)184 Returns:185 The received value (0 to 255)186 """187 self._flush()188 values = bytearray([0x8B, last, 0])189 self.__ser.write(values)190 values = self.__ser.read(3)191 return(values[2]);192 def I2CRestart(self):193 """Restarts the I2C interface194 195 """196 self._flush()197 values = bytearray([0x88])198 self.__ser.write(values)199 values = self.__ser.read(1)200 return;201 def I2CSend(self, data):202 """Sends a byte to the I2C interface203 Args:204 data: The last byte to send (0 to 255)205 Returns:206 The ack value (0 to 1)207 """208 self._flush()209 values = bytearray([0x8A, data, 0])210 self.__ser.write(values)211 values = self.__ser.read(3)212 return(values[2]);213 def I2CStart(self):214 """Starts the I2C interface215 216 """217 self._flush()218 values = bytearray([0x87])219 self.__ser.write(values)220 values = self.__ser.read(1)221 return;222 def I2CStop(self):223 """Stops the I2C interface224 225 """226 self._flush()227 values = bytearray([0x89])228 self.__ser.write(values)229 values = self.__ser.read(1)230 return;231 def IOGetInputPin(self, pin):232 """Reads a value from a pin233 Args:234 pin: The pin to write to (0 to 17)235 Returns:236 The state of the pin (0 to 1)237 """238 self._flush()239 values = bytearray([0x81, pin, 0])240 self.__ser.write(values)241 values = self.__ser.read(3)242 return(values[2]);243 def IOSetOutputPin(self, pin, state):244 """Write a value to a pin245 Args:246 pin: The pin to write to (0 to 17)247 state: The value to output (0 to 1)248 """249 self._flush()250 values = bytearray([0x80, pin, state])251 self.__ser.write(values)252 self.__ser.read(3)253 return; 254 def PWMDisable(self, channel):255 """Disables one of the PWM output channels256 Args:257 channel: The PWM channel to disable (0 to 1)258 """259 self._flush()260 values = bytearray([0x93, channel])261 self.__ser.write(values)262 values = self.__ser.read(2)263 return;264 def PWMEnable(self, channel):265 """Enables one of the PWM output channels266 Args:267 channel: The PWM channel to enable (0 to 1)268 """269 self._flush()270 values = bytearray([0x92, channel])271 self.__ser.write(values)272 values = self.__ser.read(2)273 return;274 def PWMSetDuty8(self, channel, value):275 """Sets the duty one of the PWM output channels as an 8-bit value276 Args:277 channel: The PWM channel to enable (0 to 1)278 value: The duty of the PWM channel (0 to 255)279 """280 self._flush()281 values = bytearray([0x95, channel, value])282 self.__ser.write(values)283 values = self.__ser.read(3)284 return;285 def PWMSetDuty10(self, channel, value):286 """Sets the duty one of the PWM output channels as a 10-bit value287 Args:288 channel: The PWM channel to enable (0 to 1)289 value: The duty of the PWM channel (0 to 1023)290 """291 lsb = value & 255 292 msb = value / 256293 self._flush()294 values = bytearray([0x96, channel, lsb, msb])295 self.__ser.write(values)296 values = self.__ser.read(4)297 return;298 def PWMSetPrescaler(self, scaler):299 """Sets the prescaler of the PWM output channels300 Args:301 scaler: The scaler of the PWM channels (0 to 3) 0=1:1 1=1:4 2=1:16 3=1:64302 """303 self._flush()304 values = bytearray([0x94, scaler])305 self.__ser.write(values)306 values = self.__ser.read(2)307 return;308 def SPIInitialise(self):309 """Enables the SPI interface310 311 """312 self._flush()313 values = bytearray([0x82])314 self.__ser.write(values)315 values = self.__ser.read(1)316 return;317 def SPIPrescaler(self, scaler):318 """Sets the prescaler of the SPI interface319 Args:320 scaler: The scaler of the SPI interface (0 to 2) 0=1:1 1=1:4 2=1:16321 """322 self._flush()323 values = bytearray([0x85, scaler])324 self.__ser.write(values)325 values = self.__ser.read(2)326 return;327 def SPITransfer(self, data):328 """Reads and writes a byte on the SPI interface329 Args:330 data: The data byte to send (0 to 255)331 332 Returns:333 The received value (0 to 255)334 """335 self._flush()336 values = bytearray([0x83, data, 0])337 self.__ser.write(values)338 values = self.__ser.read(3)339 return(values[2]);340 def ServoDisable(self, channel):341 """Disables one of the Servo output channels342 Args:343 channel: The Servo channel to disable (0 to 5)344 """345 self._flush()346 values = bytearray([0x98, channel])347 self.__ser.write(values)348 values = self.__ser.read(2)349 return;350 def ServoEnable(self, channel):351 """Enables one of the Servo output channels352 Args:353 channel: The Servo channel to enable (0 to 5)354 """355 self._flush()356 values = bytearray([0x97, channel])357 self.__ser.write(values)358 values = self.__ser.read(2)359 return;360 def ServoSetPosition8(self, channel, position):361 """Sets the position one of the servo output channels as an 8-bit value362 Args:363 channel: The Servo channel to enable (0 to 1)364 position: The position of the Servo channel (0 to 255)365 """366 self._flush()367 values = bytearray([0x99, channel, position])368 self.__ser.write(values)369 values = self.__ser.read(3)370 return;371 def ServoSetPosition16(self, channel, position):372 """Sets the position one of the servo output channels as an 16-bit value373 Args:374 channel: The Servo channel to enable (0 to 1)375 position: The position of the Servo channel (0 to 65535)376 """377 lsb = position & 255 378 msb = position / 256379 self._flush()380 values = bytearray([0x9A, channel, lsb, msb])381 self.__ser.write(values)382 values = self.__ser.read(4)383 return;384 def UARTBaud(self, rate):385 """Sets the baud rate of the UART interface386 Args:387 rate: The baud rate of the UART interface (0 to 7) 0=1200, 1=2400, 2=4800, 3=9600, 4=19200, 5=38400, 6=57600, 7=115200388 """389 self._flush()390 values = bytearray([0x91, rate])391 self.__ser.write(values)392 values = self.__ser.read(2)393 return;394 def UARTInitialise(self):395 """Enables the UART interface396 397 """398 self._flush()399 values = bytearray([0x8D])400 self.__ser.write(values)401 values = self.__ser.read(1)402 return;403 def UARTReceive(self):404 """Reads a byte from the UART receive buffer405 406 Returns:407 The received value (0 to 255)408 """409 self._flush()410 values = bytearray([0x90, 0])411 self.__ser.write(values)412 values = self.__ser.read(2)413 return(values[1]);414 def UARTReceiveCount(self):415 """Reads the number of bytes stored in the UART receive buffer416 417 Returns:418 The received value (0 to 255)419 """420 self._flush()421 values = bytearray([0x8F, 0])422 self.__ser.write(values)423 values = self.__ser.read(2)424 return(values[1]);425 def UARTTransmit(self, data):426 """writes a byte to the UART interface427 Args:428 data: The data byte to send (0 to 255)429 430 """431 self._flush()432 values = bytearray([0x8E, data])433 self.__ser.write(values)434 values = self.__ser.read(2)...

Full Screen

Full Screen

translator-gulp.js

Source:translator-gulp.js Github

copy

Full Screen

1var File = require('vinyl');2var through = require('through2');3var assert = require('assert');4var Stream = require('stream');5var gulpTranslator = require('../translator-gulp.js');6describe('gulp-translator', function() {7 describe('with null contents', function() {8 it('should let null files pass through', function(done) {9 var translator = gulpTranslator('./test/locales/en.yml');10 var n = 0;11 var _transform = function(file, enc, callback) {12 assert.equal(file.contents, null);13 n++;14 callback();15 };16 var _flush = function(callback) {17 assert.equal(n, 1);18 done();19 callback();20 };21 var t = through.obj(_transform, _flush);22 translator.pipe(t);23 translator.end(new File({24 contents: null25 }));26 });27 });28 describe('with buffer contents', function() {29 it('should interpolate strings from *.yml locale file - ENGLISH', function(done) {30 var translator = gulpTranslator('./test/locales/en.yml');31 var n = 0;32 var content = new Buffer("{{ user.title | translate }} {{title | translate}}");33 var translated = "ENGLISH USER TITLE Title";34 var _transform = function(file, enc, callback) {35 assert.equal(file.contents.toString('utf8'), translated);36 n++;37 callback();38 };39 var _flush = function(callback) {40 assert.equal(n, 1);41 done();42 callback();43 };44 var t = through.obj(_transform, _flush);45 translator.pipe(t);46 translator.end(new File({47 contents: content48 }));49 });50 it('should interpolate strings from *.yml locale file - POLISH', function(done) {51 var translator = gulpTranslator('./test/locales/pl.yml');52 var n = 0;53 var content = new Buffer("{{ user.title | translate }} {{title | translate}}");54 var translated = "POLSKI TYTUL Tytul";55 var _transform = function(file, enc, callback) {56 assert.equal(file.contents.toString('utf8'), translated);57 n++;58 callback();59 };60 var _flush = function(callback) {61 assert.equal(n, 1);62 done();63 callback();64 };65 var t = through.obj(_transform, _flush);66 translator.pipe(t);67 translator.end(new File({68 contents: content69 }));70 });71 it('should interpolate strings from *.json locale file - RUSSIAN', function(done) {72 var translator = gulpTranslator('./test/locales/ru.json');73 var n = 0;74 var content = new Buffer("{{ user.title | translate }} {{title | translate}}");75 var translated = "РУССКИЙ ЗАГОЛОВОК Заголовок";76 var _transform = function(file, enc, callback) {77 assert.equal(file.contents.toString('utf8'), translated);78 n++;79 callback();80 };81 var _flush = function(callback) {82 assert.equal(n, 1);83 done();84 callback();85 };86 var t = through.obj(_transform, _flush);87 translator.pipe(t);88 translator.end(new File({89 contents: content90 }));91 });92 it("should throw error about undefined locale", function(done){93 var translator = gulpTranslator('./test/locales/pl.yml');94 var n = 0;95 var content = new Buffer("{{ unsupported | translate }}");96 var _transform = function(file, enc, callback) {97 n++;98 callback();99 };100 var _flush = function(callback) {101 assert.equal(n, 0);102 callback();103 };104 translator.on('error', function(err){105 assert.equal(err.message,106 'Error: No such content (unsupported) in locale file and is used in /path');107 done();108 });109 var t = through.obj(_transform, _flush);110 translator.pipe(t);111 translator.end(new File({112 path: '/path',113 contents: content114 }));115 });116 describe('filters', function() {117 it("should lowecase translated text", function(done){118 var translator = gulpTranslator('./test/locales/en.yml');119 var n = 0;120 var content = new Buffer("{{ title | translate }} {{title | translate | lowercase}}");121 var translated = "Title title";122 var _transform = function(file, enc, callback) {123 assert.equal(file.contents.toString('utf8'), translated);124 n++;125 callback();126 done();127 };128 var _flush = function(callback) {129 assert.equal(n, 1);130 callback();131 };132 var t = through.obj(_transform, _flush);133 translator.pipe(t);134 translator.end(new File({135 contents: content136 }));137 });138 it("should uppercase translated text", function(done){139 var translator = gulpTranslator('./test/locales/en.yml');140 var n = 0;141 var content = new Buffer("{{ title | translate }} {{title | translate | uppercase}}");142 var translated = "Title TITLE";143 var _transform = function(file, enc, callback) {144 assert.equal(file.contents.toString('utf8'), translated);145 n++;146 callback();147 };148 var _flush = function(callback) {149 assert.equal(n, 1);150 done();151 callback();152 };153 var t = through.obj(_transform, _flush);154 translator.pipe(t);155 translator.end(new File({156 contents: content157 }));158 });159 it("should capitalize translated text", function(done){160 var translator = gulpTranslator('./test/locales/en.yml');161 var n = 0;162 var content = new Buffer("{{ title | translate }} {{user.title | translate | capitalize}}");163 var translated = "Title English user title";164 var _transform = function(file, enc, callback) {165 assert.equal(file.contents.toString('utf8'), translated);166 n++;167 callback();168 done();169 };170 var _flush = function(callback) {171 assert.equal(n, 1);172 callback();173 };174 var t = through.obj(_transform, _flush);175 translator.pipe(t);176 translator.end(new File({177 contents: content178 }));179 });180 it("should capitalize every word in translated text", function(done){181 var translator = gulpTranslator('./test/locales/en.yml');182 var n = 0;183 var content = new Buffer("{{ title | translate }} {{user.title | translate | capitalizeEvery}}");184 var translated = "Title English User Title";185 var _transform = function(file, enc, callback) {186 assert.equal(file.contents.toString('utf8'), translated);187 n++;188 callback();189 done();190 };191 var _flush = function(callback) {192 assert.equal(n, 1);193 callback();194 };195 var t = through.obj(_transform, _flush);196 translator.pipe(t);197 translator.end(new File({198 contents: content199 }));200 });201 it("should reverse translated text", function(done){202 var translator = gulpTranslator('./test/locales/en.yml');203 var n = 0;204 var content = new Buffer("{{ title | translate }} {{user.title | translate | reverse}}");205 var translated = "Title ELTIT RESU HSILGNE";206 var _transform = function(file, enc, callback) {207 assert.equal(file.contents.toString('utf8'), translated);208 n++;209 callback();210 done();211 };212 var _flush = function(callback) {213 assert.equal(n, 1);214 callback();215 };216 var t = through.obj(_transform, _flush);217 translator.pipe(t);218 translator.end(new File({219 contents: content220 }));221 });222 it("should throw error if unsupported filter", function(done){223 var translator = gulpTranslator('./test/locales/en.yml');224 var n = 0;225 var content = new Buffer("{{ title | translate }} {{title | translate | unsupported}}");226 var _transform = function(file, enc, callback) {227 assert.equal(file.contents.toString('utf8'), translated);228 n++;229 callback();230 };231 var _flush = function(callback) {232 assert.equal(n, 0);233 callback();234 };235 translator.on('error', function(err){236 assert.equal(err.message, 'Error: unsupported filter is not supported and is used in /path');237 done();238 });239 var t = through.obj(_transform, _flush);240 translator.pipe(t);241 translator.end(new File({242 path: '/path',243 contents: content244 }));245 });246 });247 });248 describe('with stream contents', function() {249 it('should emit errors', function(done) {250 var translator = gulpTranslator('./test/locales/en.yml');251 var content = Readable("{{ title }} {{title}}");252 var n = 0;253 var _transform = function(file, enc, callback) {254 n++;255 callback();256 };257 var _flush = function(callback) {258 assert.equal(n, 0);259 callback();260 };261 translator.on('error', function(err){262 assert.equal(err.message, "Streaming not supported");263 done();264 });265 var t = through.obj(_transform, _flush);266 translator.pipe(t);267 translator.end(new File({268 contents: content269 }));270 });271 });272});273function Readable(content, cb){274 var readable = new Stream.Readable();275 readable._read = function() {276 this.push(new Buffer(content));277 this.push(null); // no more data278 };279 if (cb) readable.on('end', cb);280 return readable;...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful