void Element::setTick( int t ) { Id clockId( 1 ); if ( t == tick_ ) return; if ( tick_ >= 0 ) { // Drop all messages coming here from clock. dropAllMsgsFromSrc( clockId ); } tick_ = t; if ( t < 0 || t > 31 ) { // Only 32 ticks available. // Don't need to add new ticks. return; } const Finfo* f2 = cinfo()->findFinfo( "init" ); if ( f2 && dynamic_cast< const SharedFinfo* >( f2 ) ) { // Must build init msg too. This comes on the previous tick. assert( t > 0 ); addClockMsg( t-1, id(), f2 ); } f2 = cinfo()->findFinfo( "proc" ); if ( f2 ) { addClockMsg( t, id(), f2 ); } else { cout << "Element::setTick:Warning: Attempt to assign a tick to a '" << cinfo_->name() << "'.\nThis does not support process actions.\n"; tick_ = -1; } }
void RimeWithWeaselHandler::_GetContext(weasel::Context & weasel_context, UINT session_id) { RIME_STRUCT(RimeContext, ctx); if (RimeGetContext(session_id, &ctx)) { if (ctx.composition.length > 0) { weasel_context.preedit.str = utf8towcs(ctx.composition.preedit); if (ctx.composition.sel_start < ctx.composition.sel_end) { weasel::TextAttribute attr; attr.type = weasel::HIGHLIGHTED; attr.range.start = utf8towcslen(ctx.composition.preedit, ctx.composition.sel_start); attr.range.end = utf8towcslen(ctx.composition.preedit, ctx.composition.sel_end); weasel_context.preedit.attributes.push_back(attr); } } if (ctx.menu.num_candidates) { weasel::CandidateInfo &cinfo(weasel_context.cinfo); _GetCandidateInfo(cinfo, ctx); } RimeFreeContext(&ctx); } }
/** Main entry point */ int main(int argc, char **argv) { int height, width, input; std::string dev, frame_id, cinfo_url; sensor_msgs::Image image; sensor_msgs::CameraInfo cam_info; ros::init(argc, argv, "camerav4l2_node"); ros::NodeHandle node; ros::NodeHandle nh("~"); CameraInfoManager cinfo(nh); image_transport::ImageTransport it(nh); image_transport::CameraPublisher image_pub = it.advertiseCamera( "image_raw", 1); nh.param<int>("width", width, 640); nh.param<int>("height", height, 480); nh.param<int>("input", input, 0); nh.param<std::string>("device", dev, "/dev/video0"); nh.param<std::string>("frame_id", frame_id, "camera"); nh.param<std::string>("camera_info_url", cinfo_url, "file:///tmp/calibration_camera.yaml"); cinfo.loadCameraInfo(cinfo_url); ROS_INFO("Opening device : %s", dev.c_str()); Camera cam(dev.c_str(), width, height); cam.setInput(input); image.header.frame_id = frame_id; image.height = cam.height; image.width = cam.width; image.encoding = sensor_msgs::image_encodings::RGB8; while (ros::ok()) { unsigned char* ptr = cam.Update(); image.header.stamp = ros::Time::now(); int image_size = cam.width * cam.height * 3; image.step = cam.width * 3; image.data.resize(image_size); memcpy(&image.data[0], ptr, image_size); cam_info = cinfo.getCameraInfo(); cam_info.header.frame_id = image.header.frame_id; cam_info.header.stamp = image.header.stamp; image_pub.publish(image, cam_info); ros::spinOnce(); } return 0; }
bool Element::validMsg( int msg ) const { const Cinfo* c = cinfo(); if ( msg > 0 && msg < static_cast< int >( c->numSrc() ) ) return 1; if ( msg < 0 && -msg < static_cast< int >( c->numSrc() ) ) return 0; if ( msg < 0 && -msg < static_cast< int >( c->numFinfos() ) ) return 1; return 0; }
btRigidBody::btRigidBody(btScalar mass, btMotionState *motionState, btCollisionShape *collisionShape, const btVector3 &localInertia) { idDebug = 0; for(int i = 0; i < 4;i++){ debugAngularVelocity[i] = btVector3(0,0,0); debugRelVector[i] = btVector3(0,0,0); } debugLinearVelocity = btVector3(0,0,0); btRigidBodyConstructionInfo cinfo(mass,motionState,collisionShape,localInertia); setupRigidBody(cinfo); }
SkBaseDevice* SkImageFilter::DeviceProxy::createDevice(int w, int h) { SkBaseDevice::CreateInfo cinfo(SkImageInfo::MakeN32Premul(w, h), SkBaseDevice::kNever_TileUsage, kUnknown_SkPixelGeometry, true /*forImageFilter*/); SkBaseDevice* dev = fDevice->onCreateDevice(cinfo, nullptr); if (nullptr == dev) { const SkSurfaceProps surfaceProps(fDevice->fSurfaceProps.flags(), kUnknown_SkPixelGeometry); dev = SkBitmapDevice::Create(cinfo.fInfo, surfaceProps); } return dev; }
du_body_id du_create_dynamic_bounding_body(du_shape_id shape, float mass, float *trans, float *quat, float damping, float rotation_damping, float size, float ang_fact_x, float ang_fact_y, float ang_fact_z, float friction, float restitution) { btCollisionShape *bt_shape = reinterpret_cast <btCollisionShape*>(shape); btVector3 loc_iner(0, 0, 0); btTransform transform; transform.setIdentity(); transform.setOrigin(btVector3(trans[0], trans[1], trans[2])); if (quat) transform.setRotation(btQuaternion(quat[0], quat[1], quat[2], quat[3])); if (mass > 0) bt_shape->calculateLocalInertia(mass, loc_iner); btRigidBody::btRigidBodyConstructionInfo cinfo(mass, NULL, bt_shape, loc_iner); btRigidBody* body = new btRigidBody(cinfo); body->setSleepingThresholds(LINEAR_SLEEPING_THRESHOLD, ANGULAR_SLEEPING_THRESHOLD); body->setDamping(damping, rotation_damping); body->setAngularFactor(btVector3(ang_fact_x, ang_fact_y, ang_fact_z)); body->setFriction(friction); body->setRestitution(restitution); // Enable CCD for small objects if (size < CCD_SIZE_THRESHOLD) { body->setCcdMotionThreshold(0.04); body->setCcdSweptSphereRadius(size * 0.5); } body->setWorldTransform(transform); return reinterpret_cast <du_body_id>(body); }
du_body_id du_create_static_mesh_body(int indices_len, int *indices, int positions_len, float *positions, float *trans, float friction, float restitution) { btCollisionShape *shape = create_mesh_shape(indices_len, indices, positions_len, positions); btTransform gtrans; gtrans.setIdentity(); gtrans.setOrigin(btVector3(trans[0], trans[1], trans[2])); // NOTE: no rotation float mass = 0; btVector3 loc_iner(0, 0, 0); btRigidBody::btRigidBodyConstructionInfo cinfo(mass, NULL, shape, loc_iner); btRigidBody* body = new btRigidBody(cinfo); body->setFriction(friction); body->setRestitution(restitution); body->setWorldTransform(gtrans); return reinterpret_cast <du_body_id>(body); }
btRigidBody::btRigidBody(btScalar mass, btMotionState *motionState, btCollisionShape *collisionShape, const btVector3 &localInertia) { btRigidBodyConstructionInfo cinfo(mass,motionState,collisionShape,localInertia); setupRigidBody(cinfo); }
void CameraDriver::ImageCallback(uvc_frame_t *frame) { ros::Time timestamp = ros::Time::now(); boost::recursive_mutex::scoped_lock(mutex_); assert(state_ == kRunning); assert(rgb_frame_); sensor_msgs::Image::Ptr image(new sensor_msgs::Image()); image->width = config_.width; image->height = config_.height; image->step = image->width * 3; image->data.resize(image->step * image->height); if (frame->frame_format == UVC_FRAME_FORMAT_BGR){ image->encoding = "bgr8"; memcpy(&(image->data[0]), frame->data, frame->data_bytes); } else if (frame->frame_format == UVC_FRAME_FORMAT_RGB){ image->encoding = "rgb8"; memcpy(&(image->data[0]), frame->data, frame->data_bytes); } else if (frame->frame_format == UVC_FRAME_FORMAT_UYVY) { image->encoding = "yuv422"; memcpy(&(image->data[0]), frame->data, frame->data_bytes); } else if (frame->frame_format == UVC_FRAME_FORMAT_YUYV) { // FIXME: uvc_any2bgr does not work on "yuyv" format, so use uvc_yuyv2bgr directly. uvc_error_t conv_ret = uvc_yuyv2bgr(frame, rgb_frame_); if (conv_ret != UVC_SUCCESS) { uvc_perror(conv_ret, "Couldn't convert frame to RGB"); return; } image->encoding = "bgr8"; memcpy(&(image->data[0]), rgb_frame_->data, rgb_frame_->data_bytes); #if libuvc_VERSION > 00005 /* version > 0.0.5 */ } else if (frame->frame_format == UVC_FRAME_FORMAT_MJPEG) { // Enable mjpeg support despite uvs_any2bgr shortcoming // https://github.com/ros-drivers/libuvc_ros/commit/7508a09f uvc_error_t conv_ret = uvc_mjpeg2rgb(frame, rgb_frame_); if (conv_ret != UVC_SUCCESS) { uvc_perror(conv_ret, "Couldn't convert frame to RGB"); return; } image->encoding = "rgb8"; memcpy(&(image->data[0]), rgb_frame_->data, rgb_frame_->data_bytes); #endif } else { uvc_error_t conv_ret = uvc_any2bgr(frame, rgb_frame_); if (conv_ret != UVC_SUCCESS) { uvc_perror(conv_ret, "Couldn't convert frame to RGB"); return; } image->encoding = "bgr8"; memcpy(&(image->data[0]), rgb_frame_->data, rgb_frame_->data_bytes); } sensor_msgs::CameraInfo::Ptr cinfo( new sensor_msgs::CameraInfo(cinfo_manager_.getCameraInfo())); image->header.frame_id = config_.frame_id; image->header.stamp = timestamp; cinfo->header.frame_id = config_.frame_id; cinfo->header.stamp = timestamp; cam_pub_.publish(image, cinfo); if (config_changed_) { config_server_.updateConfig(config_); config_changed_ = false; } }
void V4RCamNode::readInitParams() { ROS_INFO("V4RCamNode::readParams()"); n_param_.param<bool>("show_camera_image", show_camera_image_, DEFAULT_SHOW_CAMERA_IMAGE); ROS_INFO("show_camera_image: %s", ((show_camera_image_) ? "true" : "false")); n_param_.param<std::string>("frame_id", cameraInfo_.header.frame_id, DEFAULT_FRAME_ID); ROS_INFO("frame_id: %s", cameraInfo_.header.frame_id.c_str()); n_param_.param<std::string>("video_device", videoDevice_, DEFAULT_VIDEODEVICE); ROS_INFO("video_device: %s", videoDevice_.c_str()); n_param_.param<std::string>("avi_filename", aviFilename_, DEFAULT_AVIFILENAME); ROS_INFO("avi_filename: %s", aviFilename_.c_str()); n_param_.param<std::string>("camera_parameters_file", queueLoadConfiguration_, ""); ROS_INFO("camera_parameters_file: %s", queueLoadConfiguration_.c_str()); n_param_.param<int>("convert_image_first", convert_image_first_, DEFAULT_CONVERT_IMAGE_FIRST); ROS_INFO("convert_image_first: %i", convert_image_first_); std::string camera_info_url; if(n_param_.getParam("camera_info_url", camera_info_url)) { camera_info_manager::CameraInfoManager cinfo(n_param_); if(cinfo.validateURL(camera_info_url)) { cinfo.loadCameraInfo(camera_info_url); cameraInfo_ = cinfo.getCameraInfo(); } else { ROS_FATAL("camera_info_url not valid."); n_param_.shutdown(); return; } } else { XmlRpc::XmlRpcValue double_list; n_param_.getParam("K", double_list); if((double_list.getType() == XmlRpc::XmlRpcValue::TypeArray) && (double_list.size() == 9)) { for(int i = 0; i < 9; i++) { ROS_ASSERT(double_list[0].getType() == XmlRpc::XmlRpcValue::TypeDouble); cameraInfo_.K[i] = double_list[i]; } } n_param_.getParam("D", double_list); if((double_list.getType() == XmlRpc::XmlRpcValue::TypeArray) && (double_list.size() == 5)) { for(int i = 0; i < 5; i++) { ROS_ASSERT(double_list[0].getType() == XmlRpc::XmlRpcValue::TypeDouble); cameraInfo_.D[i] = double_list[i]; } } n_param_.getParam("R", double_list); if((double_list.getType() == XmlRpc::XmlRpcValue::TypeArray) && (double_list.size() == 9)) { for(int i = 0; i < 9; i++) { ROS_ASSERT(double_list[0].getType() == XmlRpc::XmlRpcValue::TypeDouble); cameraInfo_.R[i] = double_list[i]; } } n_param_.getParam("P", double_list); if((double_list.getType() == XmlRpc::XmlRpcValue::TypeArray) && (double_list.size() == 12)) { for(int i = 0; i < 12; i++) { ROS_ASSERT(double_list[0].getType() == XmlRpc::XmlRpcValue::TypeDouble); cameraInfo_.P[i] = double_list[i]; } } } ROS_INFO("tf_camera_id: %s", cameraInfo_.header.frame_id.c_str()); }
static hkpShape* CreateMeshShape(const PINT_MESH_CREATE& create, HavokMeshFormat format) { // ### share meshes? const udword NbVerts = create.mSurface.mNbVerts; const Point* V = create.mSurface.mVerts; const udword NbTris = create.mSurface.mNbFaces; const udword* I = create.mSurface.mDFaces; hkpShape* HavokShape=null; if(format==HAVOK_BV_COMPRESSED_MESH_SHAPE) { // "Since this shape stores all of its primitive geometries internally in a compressed format, it cannot be used to reference external geometry." hkGeometry geom; for(udword i=0;i<NbVerts;i++) { // geom.m_vertices[i] = hkVector4(V[i].x, V[i].y, V[i].z); geom.m_vertices.pushBack(hkVector4(V[i].x, V[i].y, V[i].z)); } for(udword i=0;i<NbTris;i++) { hkGeometry::Triangle T; T.set(I[0], I[1], I[2], -1); I+=3; // geom.m_triangles[i] = T; geom.m_triangles.pushBack(T); } { hkpDefaultBvCompressedMeshShapeCinfo cinfo(&geom); // cinfo.m_maxConvexShapeError = 0.0f; // hkMemoryAllocator::MemoryStatistics Stats; // hkMemorySystem::getInstance().getHeapStatistics(Stats); // hkLong before = Stats.m_inUse; HavokShape = new hkpBvCompressedMeshShape(cinfo); // hkMemorySystem::getInstance().getHeapStatistics(Stats); // hkLong after = Stats.m_inUse; // printf("Mesh size: %d\n", after-before); // hkpBvCompressedMeshShape* tmp = new hkpBvCompressedMeshShape(cinfo); // HavokShape = tmp; // int test = tmp->calcSizeForSpu(CalcSizeForSpuInput(), 1000000000); // hkBool b = tmp->castRay( const hkpShapeRayCastInput& input, hkpShapeRayCastOutput& results ) const; } } else if(format==HAVOK_EXTENDED_MESH_SHAPE) { hkpExtendedMeshShape* m_mesh = new hkpExtendedMeshShape; // hkpBvCompressedMeshShape* m_mesh = new hkpBvCompressedMeshShape; // hkpStorageExtendedMeshShape* m_mesh = new hkpStorageExtendedMeshShape; // it is common to have a landscape with 0 convex radius (for each triangle) // and all moving objects with non zero radius. // m_mesh->setRadius(0.0f); { hkpExtendedMeshShape::TrianglesSubpart part; part.m_vertexBase = &V->x; part.m_vertexStriding = sizeof(Point); part.m_numVertices = NbVerts; part.m_indexBase = I; part.m_indexStriding = sizeof(udword)*3; part.m_numTriangleShapes = NbTris; part.m_stridingType = hkpExtendedMeshShape::INDICES_INT32; m_mesh->addTrianglesSubpart(part); } hkpMoppCompilerInput mci; hkpMoppCode* m_code = hkpMoppUtility::buildCode(m_mesh, mci); HavokShape = new hkpMoppBvTreeShape(m_mesh, m_code); m_code->removeReference(); m_mesh->removeReference(); // ### TODO // hkResult res = m_mesh->computeWeldingInfo(shape, hkpWeldingUtility::WELDING_TYPE_CLOCKWISE); // hkResult res = m_mesh->computeWeldingInfo(shape, hkpWeldingUtility::WELDING_TYPE_ANTICLOCKWISE); } return HavokShape; }
void RimeWithWeaselHandler::_UpdateUI(UINT session_id) { weasel::Status weasel_status; weasel::Context weasel_context; if (session_id == 0) weasel_status.disabled = m_disabled; RimeStatus status = {0}; RIME_STRUCT_INIT(RimeStatus, status); if (RimeGetStatus(session_id, &status)) { weasel_status.schema_name = utf8towcs(status.schema_name); weasel_status.ascii_mode = status.is_ascii_mode; weasel_status.composing = status.is_composing; weasel_status.disabled = status.is_disabled; RimeFreeStatus(&status); } RimeContext ctx = {0}; RIME_STRUCT_INIT(RimeContext, ctx); if (RimeGetContext(session_id, &ctx)) { if (ctx.composition.length > 0) { weasel_context.preedit.str = utf8towcs(ctx.composition.preedit); if (ctx.composition.sel_start < ctx.composition.sel_end) { weasel::TextAttribute attr; attr.type = weasel::HIGHLIGHTED; attr.range.start = utf8towcslen(ctx.composition.preedit, ctx.composition.sel_start); attr.range.end = utf8towcslen(ctx.composition.preedit, ctx.composition.sel_end); weasel_context.preedit.attributes.push_back(attr); } } if (ctx.menu.num_candidates) { weasel::CandidateInfo &cinfo(weasel_context.cinfo); cinfo.candies.resize(ctx.menu.num_candidates); cinfo.comments.resize(ctx.menu.num_candidates); for (int i = 0; i < ctx.menu.num_candidates; ++i) { cinfo.candies[i].str = utf8towcs(ctx.menu.candidates[i].text); if (ctx.menu.candidates[i].comment) { cinfo.comments[i].str = utf8towcs(ctx.menu.candidates[i].comment); } } cinfo.highlighted = ctx.menu.highlighted_candidate_index; cinfo.currentPage = ctx.menu.page_no; cinfo.labels = ctx.menu.select_keys; } RimeFreeContext(&ctx); } if (!m_ui) return; if (RimeGetOption(session_id, "inline_preedit")) m_ui->style().client_caps |= weasel::INLINE_PREEDIT_CAPABLE; else m_ui->style().client_caps &= ~weasel::INLINE_PREEDIT_CAPABLE; if (weasel_status.composing) { m_ui->Update(weasel_context, weasel_status); m_ui->Show(); } else if (!_ShowMessage(weasel_context, weasel_status)) { m_ui->Hide(); m_ui->Update(weasel_context, weasel_status); } m_message_type.clear(); m_message_value.clear(); }
Element* FieldElement::copyElement( Id newParent, Id newId, unsigned int n, bool toGlobal ) const { return new FieldElement( newParent, newId, cinfo(), getName(), fef_ ); }
int docmd(Client *C, char *cmd) { int rc = 1; Proto_Client *client = (Proto_Client *) C->ph; // If this is a connect attempt char input[50]; strcpy(input, cmd); int connectAttempt = check_if_connect(input); if (connectAttempt==1) { // Ok startup our connection to the server if (startConnection(C, globals.host, globals.port, update_event_handler)<0) { fprintf(stderr, "ERROR: startConnection failed\n"); return -1; } else { fprintf(stderr, "Successfully connected to <%s:%d>\n", globals.host, globals.port); proto_client_hello(C->ph); doRPCCmd(C, 'q'); //query for the map return 1; } return 1; } strcpy(input,cmd); if (strcmp(cmd, "disconnect\n")==0) { doRPCCmd(C, 'g'); rc=-1; } else if (strcmp(cmd, "where\n")==0) where(); else if (strcmp(cmd, "numhome 1\n")==0) { doRPCCmd(C, 'q'); // query map if (client->game.map.numHome1!=0) fprintf(stderr, "%d\n", client->game.map.numHome1); } else if (strcmp(cmd, "numhome 2\n")==0) { doRPCCmd(C, 'q'); // query map if (client->game.map.numHome2!=0) fprintf(stderr, "%d\n", client->game.map.numHome2); } else if (strcmp(cmd, "numjail 1\n")==0) { doRPCCmd(C, 'q'); // query map if (client->game.map.numJail1!=0) fprintf(stderr, "%d\n", client->game.map.numJail1); } else if (strcmp(cmd, "numjail 2\n")==0) { doRPCCmd(C, 'q'); // query map if (client->game.map.numHome2!=0) fprintf(stderr, "%d\n", client->game.map.numJail2); } else if (strcmp(cmd, "numwall\n")==0) { doRPCCmd(C, 'q'); // query map if (client->game.map.numFixedWall!=0 && client->game.map.numNonfixedWall!=0) fprintf(stderr, "%d\n", client->game.map.numFixedWall + client->game.map.numNonfixedWall); } else if (strcmp(cmd, "numfloor\n")==0) { doRPCCmd(C, 'q'); // query map if (client->game.map.numFloor1!=0 && client->game.map.numFloor2!=0) fprintf(stderr, "%d\n", client->game.map.numFloor1+client->game.map.numFloor2); } else if (strcmp(cmd, "dim\n")==0) { doRPCCmd(C, 'q'); // query map if (client->game.map.dimension.x!=0 && client->game.map.dimension.y!=0) fprintf(stderr, "%dx%d\n", client->game.map.dimension.x, client->game.map.dimension.y); } else if (strcmp(cmd, "dump\n")==0) { doRPCCmd(C, 'q'); // query map printMap(&client->game.map); if (DISPLAYUI==1) ui_update(ui); } else if (containsString(input, "cinfo")>0) { doRPCCmd(C, 'q'); // query map cinfo(cmd, C); } else if (strcmp(cmd, "start\n")==0) { doRPCCmd(C, 's'); // query map } else if (strcmp(cmd, "test\n")==0) { if (STRESS_TEST == 1) { pid_t myChild; myChild = fork(); if (myChild == 0) { Wander(C, 0); } else{} } } // MOVEMENT else if (strcmp(cmd, "w\n")==0) { Proto_Client *client = C->ph; client->rpc_session.shdr.returnCode = UP; doRPCCmd(C, 'm'); // query map } else if (strcmp(cmd, "a\n")==0) { Proto_Client *client = C->ph; client->rpc_session.shdr.returnCode = LEFT; doRPCCmd(C, 'm'); // query map } else if (strcmp(cmd, "d\n")==0) { Proto_Client *client = C->ph; client->rpc_session.shdr.returnCode = RIGHT; doRPCCmd(C, 'm'); // query map } else if (strcmp(cmd, "s\n")==0) { Proto_Client *client = C->ph; client->rpc_session.shdr.returnCode = DOWN; doRPCCmd(C, 'm'); // query map } // END OF MOVEMENT //PICKUP else if (strcmp(cmd, "f\n")==0){ Proto_Client *client = C->ph; doRPCCmd(C, 'f'); } //END PICKUP else if (strcmp(cmd, "O\n")==0) proto_debug_on(); else if (strcmp(cmd, "o\n")==0) proto_debug_off(); else if (strcmp(cmd, "rh\n")==0) rc = proto_client_hello(C->ph); else if (strcmp(cmd, "q\n")==0) { fprintf(stderr, "Game Over: You Quit\n"); doRPCCmd(C, 'g'); rc=-1; } else if (strcmp(cmd, "quit\n")==0) { doRPCCmd(C, 'g'); fprintf(stderr, "Game Over: You Quit\n"); rc=-1; } else if (strcmp(cmd, "\n")==0) { rc = proto_client_update(C->ph); rc=1; } else { fprintf(stderr, "Unknown command\n"); } return rc; }