texture_2d tangent_flow_map(const texture_2d& src, float sigma) { texture_2d tmp0(src.clone_format()); texture_2d tmp1(src.clone_format()); texture_2d dst(src.clone_format()); glsl_program sst("sst_fs.glsl"); sst.use(); sst.bind_sampler("img", src); sst.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height()); sst.draw(&tmp0); glsl_program gauss("gauss_fs.glsl"); gauss.use(); gauss.bind_sampler("img", tmp0); gauss.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height()); gauss.set_uniform_1f("sigma", sigma); gauss.draw(&tmp1); glsl_program tfm("tfm_fs.glsl"); tfm.use(); tfm.bind_sampler("img", tmp1); tfm.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height()); tfm.draw(&dst); return dst; }
static bool Process(ParseParam<Iter>& param) { Group::ptr group = GetGroup(param); Shape::ptr tfm(new Shape(param.currentNode)); group->children.add(tfm); param.currentNode = tfm; return true; }
void GoalCallback(const geometry_msgs::PoseStampedConstPtr &msg) { int i, j, k; double roll, pitch, yaw, tfyaw; tf::Vector3 tfpoint = TransformPoint(msg->pose); gx = (int)(tfpoint.getX()*10); gy = (int)(tfpoint.getY()*10); dgx = msg->pose.position.x; dgy = msg->pose.position.y; tf::Quaternion quat(msg->pose.orientation.x, msg->pose.orientation.y, msg->pose.orientation.z, msg->pose.orientation.w); tf::Matrix3x3 m(quat); m.getRPY(roll, pitch, yaw); dgtheta = yaw; // in real world tf::Quaternion tfquat = _transform * quat; tf::Matrix3x3 tfm(tfquat); tfm.getRPY(roll, pitch, tfyaw); if (tfyaw < 0) {tfyaw+=2*M_PI;} gtheta = (int)(tfyaw/THETA); // in grid cell printf("\n(dgx, dgy, dgtheta) = (%lf, %lf, %lf)\n", dgx, dgy, dgtheta); printf("(gx, gy, gtheta) = (%d, %d, %d)\n", gx, gy, gtheta); /////////for debug///////// //gx = 96; gy = 25; //dgx = 9.62; dgy = 2.557; //dgtheta = 1.512; //gtheta = (int)(dgtheta/THETA); /////////////////////////// /* goal range is about 1m square */ for (i = gy-5; i < gy+5; i++){ for (j = gx-5; j < gx+5; j++){ for (k = 0; k < SIZE_T; k++){ map[i][j][k].goal = true; } } } if (Collide(tfpoint.getX(), tfpoint.getY(), tfyaw)){ std::cout << "INVALID GOAL POINT!" << std::endl; return; } /* Set WaveFront heurisic */ WaveFrontInit(); _goal_set = true; }
/* Cleaning up a list with pending timers. */ void destruction_test(void) { grpc_timer timers[5]; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_timer_list_init(gpr_time_0(GPR_CLOCK_REALTIME)); memset(cb_called, 0, sizeof(cb_called)); grpc_timer_init(&exec_ctx, &timers[0], tfm(100), cb, (void *)(intptr_t)0, gpr_time_0(GPR_CLOCK_REALTIME)); grpc_timer_init(&exec_ctx, &timers[1], tfm(3), cb, (void *)(intptr_t)1, gpr_time_0(GPR_CLOCK_REALTIME)); grpc_timer_init(&exec_ctx, &timers[2], tfm(100), cb, (void *)(intptr_t)2, gpr_time_0(GPR_CLOCK_REALTIME)); grpc_timer_init(&exec_ctx, &timers[3], tfm(3), cb, (void *)(intptr_t)3, gpr_time_0(GPR_CLOCK_REALTIME)); grpc_timer_init(&exec_ctx, &timers[4], tfm(1), cb, (void *)(intptr_t)4, gpr_time_0(GPR_CLOCK_REALTIME)); GPR_ASSERT(1 == grpc_timer_check(&exec_ctx, tfm(2), NULL)); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(1 == cb_called[4][1]); grpc_timer_cancel(&exec_ctx, &timers[0]); grpc_timer_cancel(&exec_ctx, &timers[3]); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(1 == cb_called[0][0]); GPR_ASSERT(1 == cb_called[3][0]); grpc_timer_list_shutdown(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(1 == cb_called[1][0]); GPR_ASSERT(1 == cb_called[2][0]); }
/* Cleaning up a list with pending alarms. */ void destruction_test(void) { grpc_alarm alarms[5]; grpc_alarm_list_init(gpr_time_0(GPR_CLOCK_REALTIME)); memset(cb_called, 0, sizeof(cb_called)); grpc_alarm_init(&alarms[0], tfm(100), cb, (void *)(gpr_intptr)0, gpr_time_0(GPR_CLOCK_REALTIME)); grpc_alarm_init(&alarms[1], tfm(3), cb, (void *)(gpr_intptr)1, gpr_time_0(GPR_CLOCK_REALTIME)); grpc_alarm_init(&alarms[2], tfm(100), cb, (void *)(gpr_intptr)2, gpr_time_0(GPR_CLOCK_REALTIME)); grpc_alarm_init(&alarms[3], tfm(3), cb, (void *)(gpr_intptr)3, gpr_time_0(GPR_CLOCK_REALTIME)); grpc_alarm_init(&alarms[4], tfm(1), cb, (void *)(gpr_intptr)4, gpr_time_0(GPR_CLOCK_REALTIME)); GPR_ASSERT(1 == grpc_alarm_check(NULL, tfm(2), NULL)); GPR_ASSERT(1 == cb_called[4][1]); grpc_alarm_cancel(&alarms[0]); grpc_alarm_cancel(&alarms[3]); GPR_ASSERT(1 == cb_called[0][0]); GPR_ASSERT(1 == cb_called[3][0]); grpc_alarm_list_shutdown(); GPR_ASSERT(1 == cb_called[1][0]); GPR_ASSERT(1 == cb_called[2][0]); }
inline bool const merge_sort(char const *in, char const *out, unsigned const offset, unsigned const max_lines = 1000000) { std::deque<std::string> temporary_files; detail::temporary_file_manager< std::deque<std::string> > tfm(temporary_files); std::ifstream infile(in, std::ios_base::in | std::ios_base::binary); if (!infile.is_open()) { std::ostringstream err; err << "Unable to open file " << in; BOOST_THROW_EXCEPTION(std::runtime_error(err.str())); } while (!infile.eof()) { typedef std::map<boost::shared_ptr<std::string>, unsigned, detail::key_offset_compare> lines_t; detail::key_offset_compare map_comparator(offset); lines_t lines(map_comparator); for (unsigned loop=0; !infile.eof() && loop<max_lines; ++loop) { if (infile.fail() || infile.bad()) BOOST_THROW_EXCEPTION(std::runtime_error("An error occurred reading the input file.")); boost::shared_ptr<std::string> line(new std::string); std::getline(infile, *line); ++lines.insert(std::make_pair(line,0U)).first->second; } std::string const temp_filename(platform::get_temporary_filename()); temporary_files.push_back(temp_filename); std::ofstream file(temp_filename.c_str(), std::ios_base::out | std::ios_base::binary); for (lines_t::const_iterator it=lines.begin(); it!=lines.end(); ++it) { if (file.fail() || file.bad()) BOOST_THROW_EXCEPTION(std::runtime_error("An error occurred writing temporary a file.")); for (unsigned loop=0; loop<it->second; ++loop) file << *(it->first); file << "\n"; } } infile.close(); detail::do_file_merge(temporary_files.begin(), temporary_files.end(), out, offset); return true; }
void Navigation:: parse (::xsd::cxx::xml::dom::parser< char >& p, ::xml_schema::Flags f) { for (; p.more_elements (); p.next_element ()) { const ::xercesc::DOMElement& i (p.cur_element ()); const ::xsd::cxx::xml::qualified_name< char > n ( ::xsd::cxx::xml::dom::name< char > (i)); // event // { ::xsd::cxx::tree::type_factory_map< char >& tfm ( ::xsd::cxx::tree::type_factory_map_instance< 0, char > ()); ::std::auto_ptr< ::xsd::cxx::tree::type > tmp ( tfm.create ( "event", "artofsequence.org/aosl/1.0", &::xsd::cxx::tree::factory_impl< EventType >, true, true, i, n, f, this)); if (tmp.get () != 0) { ::std::auto_ptr< EventType > r ( dynamic_cast< EventType* > (tmp.get ())); if (r.get ()) tmp.release (); else throw ::xsd::cxx::tree::not_derived< char > (); this->event_.push_back (r); continue; } } break; } }
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QStyleOptionViewItem newOption; newOption = option; newOption.state &= ~QStyle::State_HasFocus; newOption.palette.setColor( QPalette::Disabled, QPalette::Text, Qt::black ); QTableWidget* pWidget = static_cast<QTableWidget*>( parent() ); RecentTableWidgetItem* pItem = static_cast<RecentTableWidgetItem*>(pWidget->item(index.row(), index.column())); painter->setFont(fontTitle); QFontMetrics tfm(fontTitle); int fontTitleSize = tfm.height(); QRect titleRect( newOption.rect.x(), newOption.rect.y(), newOption.rect.width(), fontTitleSize ); painter->drawText( titleRect, Qt::TextSingleLine, tfm.elidedText(pItem->title, Qt::ElideRight, newOption.rect.width() )); painter->setFont(fontInfo); QFontMetrics ifm(fontInfo); int fontAuthorSize = ifm.height(); QRect infoRect( newOption.rect.x(), newOption.rect.y() + fontTitleSize, newOption.rect.width(), fontAuthorSize ); int percentWidth = ifm.boundingRect(pItem->percent).width(); infoRect.adjust(0,0,-percentWidth,0); painter->drawText( infoRect, Qt::TextSingleLine, ifm.elidedText(pItem->info, Qt::ElideRight, infoRect.width() ) ); QRect percentRect( infoRect.right(), infoRect.top(), percentWidth, infoRect.height() ); painter->drawText( percentRect, Qt::TextSingleLine, pItem->percent ); if (index.flags() & Qt::ItemIsSelectable) { Qt::GlobalColor lineColor = Qt::black; int lineWidth = newOption.state & QStyle::State_Selected ? 5:0; QPen pen(lineColor, lineWidth, Qt::SolidLine); painter->setPen(pen); painter->drawLine(newOption.rect.left(), newOption.rect.bottom()-lineWidth/2, newOption.rect.right(), newOption.rect.bottom()-lineWidth/2); } }
void StartCallback(const geometry_msgs::PoseWithCovarianceStampedConstPtr &msg) { ros::NodeHandle n; geometry_msgs::PoseStamped posestamped; double roll, pitch, yaw, tfyaw; tf::Vector3 tfpoint = TransformPoint(msg->pose.pose); sx = (int)(tfpoint.getX()*10); sy = (int)(tfpoint.getY()*10); dsx = msg->pose.pose.position.x; dsy = msg->pose.pose.position.y; tf::Quaternion quat(msg->pose.pose.orientation.x, msg->pose.pose.orientation.y, msg->pose.pose.orientation.z, msg->pose.pose.orientation.w); tf::Matrix3x3 m(quat); m.getRPY(roll, pitch, yaw); dstheta = yaw; // in real world tf::Quaternion tfquat = _transform * quat; tf::Matrix3x3 tfm(tfquat); tfm.getRPY(roll, pitch, tfyaw); if (tfyaw < 0) {tfyaw+=2*M_PI;} //make yaw 0~2PI stheta = (int)(tfyaw/THETA); //0~23 (THETA=PI/12) in grid cell printf("\n(dsx, dsy, dstheta) = (%lf, %lf, %lf)\n", dsx, dsy, dstheta); printf("(sx, sy, stheta) = (%d, %d, %d)\n", sx, sy, stheta); ros::Publisher start_pub = n.advertise<geometry_msgs::PoseStamped>("start_pose", 1000, true); /* for start pose visualization */ posestamped.header.frame_id = PATH_FRAME; posestamped.pose.position.x = dsx; posestamped.pose.position.y = dsy; posestamped.pose.position.z = 0.0; posestamped.pose.orientation.x = msg->pose.pose.orientation.x; posestamped.pose.orientation.y = msg->pose.pose.orientation.y; posestamped.pose.orientation.z = msg->pose.pose.orientation.z; posestamped.pose.orientation.w = msg->pose.pose.orientation.w; start_pub.publish(posestamped); /********************************/ /*Collision detection of start point */ if (Collide(tfpoint.getX(), tfpoint.getY(), tfyaw)){ std::cout << "INVALID START POINT!" << std::endl; return; } /* set start point */ map[sy][sx][stheta].status = OPEN; map[sy][sx][stheta].x = dsx; map[sy][sx][stheta].y = dsy; map[sy][sx][stheta].theta = dstheta; map[sy][sx][stheta].gc = 0.0; map[sy][sx][stheta].parent = NULL; /* push start point to openlist */ openlist.push(map[sy][sx][stheta]); /* set start point to current point */ current_x = map[sy][sx][stheta].x; current_y = map[sy][sx][stheta].y; current_theta = map[sy][sx][stheta].theta; _start_set = true; }
RecentBooksDlg::RecentBooksDlg(QWidget *parent, CR3View * docView ) : Dialog(parent) , ui(new Ui::RecentBooksDlg) , docview(docView) { ui->setupUi(this); QFont f(ui->tableWidget->font()); f.setPointSize(docview->getOptions()->getIntDef("cr3.app.ui.recent.font.size", 12)); ui->tableWidget->setFont(f); f = ui->lblPosition->font(); f.setPointSize(f.pointSize()/2); ui->lblPosition->setFont(f); f = ui->lblTitle->font(); f.setBold(true); ui->lblTitle->setFont(f); ui->tableWidget->setColumnCount(1); ui->tableWidget->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); ui->tableWidget->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents); ui->tableWidget->verticalHeader()->setResizeMode(QHeaderView::Custom); bool isVscroll = docview->getOptions()->getIntDef(PROP_APP_UI_RECENT_VSCROLLBAR, 1) != 0; ui->tableWidget->setVerticalScrollBarPolicy(isVscroll? Qt::ScrollBarAsNeeded : Qt::ScrollBarAlwaysOff); bool isHscroll = docview->getOptions()->getIntDef(PROP_APP_UI_RECENT_HSCROLLBAR, 1) != 0; ui->tableWidget->setHorizontalScrollBarPolicy(isHscroll? Qt::ScrollBarAsNeeded : Qt::ScrollBarAlwaysOff); // fill rows QFont fontTitle = ui->tableWidget->font(); fontTitle.setBold(true); QFont fontAuthor = ui->tableWidget->font(); fontAuthor.setItalic(true); QFont fontInfo = ui->tableWidget->font(); fontInfo.setItalic(true); fontInfo.setPointSize(fontInfo.pointSize()*2/3); QFontMetrics tfm(fontTitle); QFontMetrics afm(fontAuthor); int rowHeight = tfm.height() + afm.height(); ui->tableWidget->verticalHeader()->setResizeMode(QHeaderView::Fixed); ui->tableWidget->verticalHeader()->setDefaultSectionSize(rowHeight); ui->tableWidget->setItemDelegate(new RecentBooksListDelegate(ui->tableWidget, fontTitle, fontAuthor)); LVPtrVector<CRFileHistRecord>& files = docview->getDocView()->getHistory()->getRecords(); // remove non-existing entries for( int k=0; k<files.length(); ) { QString fn(cr2qt(files.get(k)->getFilePathName())); if (!QFile::exists(fn)) files.remove(k); else ++k; } ui->tableWidget->setRowCount( files.length() ); // insert items for( int index=0; index<files.length(); ++index ) { CRFileHistRecord* book = files.get(index); RecentTableWidgetItem* titleItem = new RecentTableWidgetItem(); titleItem->title = cr2qt(book->getTitle()); if ( titleItem->title.isEmpty() ) titleItem->title = cr2qt(book->getFileName()); titleItem->info = cr2qt(book->getAuthor()); if ( titleItem->info.isEmpty() ) titleItem->info = "-"; titleItem->percent = " " + crpercent(book->getLastPos()->getPercent()); ui->tableWidget->setItem(index, 0, titleItem); } ui->navBar->setControls(ui->tableWidget, ui->lblPosition, QSize( docview->getOptions()->getIntDef(PROP_APP_UI_SWIPES_X_WEIGHT, 1), docview->getOptions()->getIntDef(PROP_APP_UI_SWIPES_Y_WEIGHT, 1) ) ); ui->tableWidget->setEditFocus(true); ui->tableWidget->setCurrentCell(0,0); QObject::connect( ui->tableWidget, SIGNAL(itemActivated(QTableWidgetItem*)), this, SLOT(onClicked(QTableWidgetItem*)) ); QObject::connect( ui->tableWidget, SIGNAL(itemClicked(QTableWidgetItem*)), this, SLOT(onClicked(QTableWidgetItem*)) ); init(); }