本文整理汇总了C++中boost::circular_buffer::size方法的典型用法代码示例。如果您正苦于以下问题:C++ circular_buffer::size方法的具体用法?C++ circular_buffer::size怎么用?C++ circular_buffer::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::circular_buffer
的用法示例。
在下文中一共展示了circular_buffer::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calculate_heading
bool calculate_heading(double& heading)
{
bool ret = false;
if(gps_points_buffer.capacity() == gps_points_buffer.size())
{
gps_points_t p_comp = gps_points_buffer[0];
for(size_t i=1; i < gps_points_buffer.size();i++)
{
gps_points_t p_cur = gps_points_buffer[i];
double dist = sqrt(pow(p_comp.x - p_cur.x,2) + pow(p_comp.y - p_cur.y,2));
if(dist > heading_threshold)
{
heading = atan2(p_comp.y - p_cur.y,p_comp.x - p_cur.x);
ret = true;
break;
}
}
}
return ret;
}
示例2: reserve_read
/** Reserve some part of the pipe for reading
\param[in] s is the number of element to reserve
\param[out] rid is an iterator to a description of the
reservation that has been done if successful
\param[in] blocking specify if the call wait for the operation
to succeed
\return true if the reservation was successful
*/
bool reserve_read(std::size_t s,
rid_iterator &rid,
bool blocking = false) {
// Lock the pipe to avoid being disturbed
std::unique_lock<std::mutex> ul { cb_mutex };
TRISYCL_DUMP_T("Before read reservation cb.size() = " << cb.size()
<< " size() = " << size());
if (s == 0)
// Empty reservation requested, so nothing to do
return false;
if (blocking)
/* If in blocking mode, wait for enough elements to read in the
pipe for the reservation. This condition can change when a
write is done */
write_done.wait(ul, [&] { return s <= size(); });
else if (s > size())
// Not enough elements to read in the pipe for the reservation
return false;
// Compute the location of the first element of the reservation
auto first = cb.begin() + read_reserved_frozen;
// Increment the number of frozen elements
read_reserved_frozen += s;
/* Add a description of the reservation at the end of the
reservation queue */
r_rid_q.emplace_back(first, s);
// Return the iterator to the last reservation descriptor
rid = r_rid_q.end() - 1;
TRISYCL_DUMP_T("After reservation cb.size() = " << cb.size()
<< " size() = " << size());
return true;
}
示例3: render
void render(sf::RenderTarget& target)
{
float dx = 1.0f/static_cast<float>(line_data_.capacity());
float x = static_cast<float>(line_data_.capacity()-line_data_.size())*dx;
line_data_.push_back(std::make_pair(tick_data_, tick_tag_));
tick_tag_ = false;
glBegin(GL_LINE_STRIP);
auto c = color(color_);
glColor4f(std::get<0>(c), std::get<1>(c), std::get<2>(c), 0.8f);
for(size_t n = 0; n < line_data_.size(); ++n)
if(line_data_[n].first > -0.5)
glVertex3d(x+n*dx, std::max(0.05, std::min(0.95, (1.0f-line_data_[n].first)*0.8 + 0.1f)), 0.0);
glEnd();
glEnable(GL_LINE_STIPPLE);
glLineStipple(3, 0xAAAA);
for(size_t n = 0; n < line_data_.size(); ++n)
{
if(line_data_[n].second)
{
glBegin(GL_LINE_STRIP);
glVertex3f(x+n*dx, 0.0f, 0.0f);
glVertex3f(x+n*dx, 1.0f, 0.0f);
glEnd();
}
}
glDisable(GL_LINE_STIPPLE);
}
示例4: image_obj_ranged_callback
void image_obj_ranged_callback(const cv_tracker::image_obj_ranged::ConstPtr& image_obj_ranged_msg) {
pthread_mutex_lock(&mutex);
image_obj_ranged_ringbuf.push_front(*image_obj_ranged_msg);
//image_raw is empty
if (image_raw_ringbuf.begin() == image_raw_ringbuf.end()) {
pthread_mutex_unlock(&mutex);
ROS_INFO("image_raw ring buffer is empty");
return;
}
buf_flag = true;
// image_obj_ranged > image_raw
if (get_time(&(image_obj_ranged_ringbuf.front().header)) >= get_time(&(image_raw_ringbuf.front().header))) {
image_raw_buf = image_raw_ringbuf.front();
boost::circular_buffer<cv_tracker::image_obj_ranged>::iterator it = image_obj_ranged_ringbuf.begin();
if (image_obj_ranged_ringbuf.size() == 1) {
image_obj_ranged_buf = *it;
pthread_mutex_unlock(&mutex);
return;
} else {
for (it++; it != image_obj_ranged_ringbuf.end(); it++) {
if (fabs_time_diff(&(image_raw_ringbuf.front().header), &((it-1)->header))
< fabs_time_diff(&(image_raw_ringbuf.front().header), &(it->header))) {
image_obj_ranged_buf = *(it-1);
break;
}
}
if (it == image_obj_ranged_ringbuf.end()) {
image_obj_ranged_buf = image_obj_ranged_ringbuf.back();
}
}
} else {
image_obj_ranged_buf = image_obj_ranged_ringbuf.front();
boost::circular_buffer<sensor_msgs::Image>::iterator it = image_raw_ringbuf.begin();
if (image_raw_ringbuf.size() == 1) {
image_raw_buf = *it;
pthread_mutex_unlock(&mutex);
return;
}
for (it++; it != image_raw_ringbuf.end(); it++) {
if (fabs_time_diff(&(image_obj_ranged_ringbuf.front().header), &((it-1)->header))
< fabs_time_diff(&(image_obj_ranged_ringbuf.front().header), &(it->header))) {
image_raw_buf = *(it-1);
break;
}
}
if (it == image_raw_ringbuf.end()) {
image_raw_buf = image_raw_ringbuf.back();
}
}
pthread_mutex_unlock(&mutex);
}
示例5: image_obj_callback
void image_obj_callback(const autoware_msgs::image_obj::ConstPtr& image_obj_msg) {
pthread_mutex_lock(&mutex);
image_obj_ringbuf.push_front(*image_obj_msg);
//vscan_image is empty
if (vscan_image_ringbuf.begin() == vscan_image_ringbuf.end()) {
pthread_mutex_unlock(&mutex);
ROS_INFO("vscan_image ring buffer is empty");
return;
}
buf_flag = true;
// image_obj > vscan_image
if (get_time(&(image_obj_ringbuf.front().header)) >= get_time(&(vscan_image_ringbuf.front().header))) {
vscan_image_buf = vscan_image_ringbuf.front();
boost::circular_buffer<autoware_msgs::image_obj>::iterator it = image_obj_ringbuf.begin();
if (image_obj_ringbuf.size() == 1) {
image_obj_buf = *it;
pthread_mutex_unlock(&mutex);
return;
} else {
for (it++; it != image_obj_ringbuf.end(); it++) {
if (fabs_time_diff(&(vscan_image_ringbuf.front().header), &((it-1)->header))
< fabs_time_diff(&(vscan_image_ringbuf.front().header), &(it->header))) {
image_obj_buf = *(it-1);
break;
}
}
if (it == image_obj_ringbuf.end()) {
image_obj_buf = image_obj_ringbuf.back();
}
}
} else {
image_obj_buf = image_obj_ringbuf.front();
boost::circular_buffer<autoware_msgs::PointsImage>::iterator it = vscan_image_ringbuf.begin();
if (vscan_image_ringbuf.size() == 1) {
vscan_image_buf = *it;
pthread_mutex_unlock(&mutex);
return;
}
for (it++; it != vscan_image_ringbuf.end(); it++) {
if (fabs_time_diff(&(image_obj_ringbuf.front().header), &((it-1)->header))
< fabs_time_diff(&(image_obj_ringbuf.front().header), &(it->header))) {
vscan_image_buf = *(it-1);
break;
}
}
if (it == vscan_image_ringbuf.end()) {
vscan_image_buf = vscan_image_ringbuf.back();
}
}
pthread_mutex_unlock(&mutex);
}
示例6: emit_block
void emit_block(size_t line_number, std::function<void (const std::string &, int, size_t)> fun) {
std::string content;
for (auto x : buffer) {
content += x;
}
fun(content, line_number - buffer.size(), buffer.size());
}
示例7: size
/** Get the current number of elements in the pipe that can be read
This is obviously a volatile value which is constrained by the
theory of restricted relativity.
Note that on some devices it may be costly to implement (for
example on FPGA).
*/
std::size_t size() const {
TRISYCL_DUMP_T("size() cb.size() = " << cb.size()
<< " cb.end() = " << (void *)&*cb.end()
<< " reserved_for_reading() = " << reserved_for_reading()
<< " reserved_for_writing() = " << reserved_for_writing());
/* The actual number of available elements depends from the
elements blocked by some reservations.
This prevents a consumer to read into reserved area. */
return cb.size() - reserved_for_reading() - reserved_for_writing();
}
示例8: write
/** Try to write a value to the pipe
\param[in] value is what we want to write
\param[in] blocking specify if the call wait for the operation
to succeed
\return true on success
\todo provide a && version
*/
bool write(const T &value, bool blocking = false) {
// Lock the pipe to avoid being disturbed
std::unique_lock<std::mutex> ul { cb_mutex };
TRISYCL_DUMP_T("Write pipe full = " << full()
<< " value = " << value);
if (blocking)
/* If in blocking mode, wait for the not full condition, that
may be changed when a read is done */
read_done.wait(ul, [&] { return !full(); });
else if (full())
return false;
cb.push_back(value);
TRISYCL_DUMP_T("Write pipe front = " << cb.front()
<< " back = " << cb.back()
<< " cb.begin() = " << (void *)&*cb.begin()
<< " cb.size() = " << cb.size()
<< " cb.end() = " << (void *)&*cb.end()
<< " reserved_for_reading() = " << reserved_for_reading()
<< " reserved_for_writing() = " << reserved_for_writing());
// Notify the clients waiting to read something from the pipe
write_done.notify_all();
return true;
}
示例9: createVelocityMarker
void WaypointVelocityVisualizer::createVelocityMarker(const boost::circular_buffer<geometry_msgs::PoseStamped>& poses,
const boost::circular_buffer<geometry_msgs::TwistStamped>& twists,
const std::string& ns, const std_msgs::ColorRGBA& color,
visualization_msgs::MarkerArray& markers)
{
assert(poses.size() == twists.size());
std::vector<nav_msgs::Odometry> waypoints;
for (unsigned int i = 0; i < poses.size(); ++i)
{
nav_msgs::Odometry odom;
odom.pose.pose = poses[i].pose;
odom.twist.twist = twists[i].twist;
waypoints.push_back(odom);
}
createVelocityMarker(waypoints, ns, color, markers);
}
示例10: controlCallback
void WaypointVelocityVisualizer::controlCallback(const geometry_msgs::PoseStamped::ConstPtr& current_pose_msg,
const geometry_msgs::TwistStamped::ConstPtr& current_twist_msg,
const geometry_msgs::TwistStamped::ConstPtr& command_twist_msg)
{
// buffers are reset when time goes back, e.g. playback rosbag
ros::Time current_time = ros::Time::now();
if (previous_time_ > current_time)
{
ROS_WARN("Detected jump back in time of %.3fs. Clearing markers and buffers.",
(previous_time_ - current_time).toSec());
deleteMarkers(); // call 'DELETEALL'
resetBuffers(); // clear circular buffers
}
previous_time_ = current_time;
// if plot_metric_interval <= 0, velocity is plotted by each callback.
if (plot_metric_interval_ > 0 && current_pose_buf_.size() > 0)
{
tf::Vector3 p1, p2;
tf::pointMsgToTF(current_pose_buf_.back().pose.position, p1);
tf::pointMsgToTF(current_pose_msg->pose.position, p2);
if (!(p1.distance(p2) > plot_metric_interval_))
return; // skipping plot
}
current_pose_buf_.push_back(*current_pose_msg);
current_twist_buf_.push_back(*current_twist_msg);
command_twist_buf_.push_back(*command_twist_msg);
current_twist_marker_array_.markers.clear();
command_twist_marker_array_.markers.clear();
createVelocityMarker(current_pose_buf_, current_twist_buf_, "current_velocity", current_twist_color_,
current_twist_marker_array_);
createVelocityMarker(current_pose_buf_, command_twist_buf_, "twist_cmd", command_twist_color_,
command_twist_marker_array_);
publishVelocityMarker();
}
示例11: readOneImpl
int readOneImpl()
{
if (!m_bReady)
return -1; // delimiter has been matched --> read fails
int nCurSize = m_cbuf.size();
if (m_bEOF) {
// EOF has been encountered --> returns the cbuf content
if (nCurSize>0) {
unsigned char val = m_cbuf.front();
m_cbuf.pop_front();
return val;
}
// EOF reached and cbuf is empty
return -1; // failed!!
}
if (nCurSize<m_nCbufLen) {
if (!fillCbuf())
return -1; // failed!!
}
unsigned char val = m_cbuf.front();
m_cbuf.pop_front();
fillOne();
return val;
}
示例12: while
boost::shared_ptr< const MapsBuffer::MapsRgb >
MapsBuffer::getFront(bool print)
{
boost::shared_ptr< const MapsBuffer::MapsRgb > depth_rgb;
{
boost::mutex::scoped_lock buff_lock (bmutex_);
while (buffer_.empty ())
{
if (is_done)
break;
{
boost::mutex::scoped_lock io_lock (io_mutex);
//std::cout << "No data in buffer_ yet or buffer is empty." << std::endl;
}
buff_empty_.wait (buff_lock);
}
depth_rgb = buffer_.front ();
buffer_.pop_front ();
}
if(print)
PCL_INFO("%d maps left in the buffer...\n", buffer_.size ());
return (depth_rgb);
}
示例13: countThreshold
GestureType::Type GestureClassifierByHistogram::classifyClass3Gesture(const boost::circular_buffer<size_t> &matchedHistogramIndexes) const
{
#if 0
const size_t &matchedIdx = matchHistogramByGestureIdPattern(matchedHistogramIndexes, gestureIdPatternHistogramsForThirdClassGesture_, params_.histDistThresholdForGestureIdPattern);
switch (matchedIdx)
{
case :
return GestureType::GT_INFINITY;
case :
return GestureType::GT_TRIANGLE;
}
#else
// TODO [adjust] >> design parameter
const size_t countThreshold(matchedHistogramIndexes.size() / 2);
//const size_t countThreshold(params_.matchedIndexCountThresholdForClass3Gesture);
const size_t &matchedIdx = matchHistogramByFrequency(matchedHistogramIndexes, countThreshold);
switch (matchedIdx)
{
/*
case :
return GestureType::GT_LEFT_FAST_MOVE;
case :
return GestureType::GT_RIGHT_FAST_MOVE;
*/
case 0:
return GestureType::GT_INFINITY;
case 1:
return GestureType::GT_TRIANGLE;
}
#endif
return GestureType::GT_UNDEFINED;
}
示例14: nClick
/*! @brief Returns true if an n click has occured in the given times and durations
@param n the number of 'quick' consecutive clicks
@param times a circular buffer of the click times
@param durations a circular buffer of the click durations (needed to throw out long clicks)
@param previoustime the previous time that this event has occured
*/
bool BehaviourProvider::nClick(unsigned int n, const boost::circular_buffer<float>& times, const boost::circular_buffer<float>& durations, float& previoustime)
{
size_t buffersize = times.size();
if (buffersize < n) // if there aren't enough values in the buffer return false
return false;
else if (previoustime == times.back()) // if previous time has not changed return false
return false;
else if (m_current_time - times.back() < 500) // need to wait 500 ms for a potential next click
return false;
else
{
// n click if the last n presses are each less than 400ms apart
for (size_t i = buffersize-1; i > buffersize-n; i--)
{
if (times[i] - times[i-1] > 500 || durations[i] > 800)
return false;
}
// check the n+1 click was longer than 400ms
if (buffersize-n > 0)
{
if (times[buffersize-n] - times[buffersize-n-1] < 500 || durations[buffersize-n] > 800)
return false;
}
previoustime = times.back();
return true;
}
}
示例15: drawMatchedIdPatternHistogram
void GestureClassifierByHistogram::drawMatchedIdPatternHistogram(const boost::circular_buffer<size_t> &matchedHistogramIndexes, const std::string &windowName) const
{
// calculate matched index histogram
cv::MatND hist;
#if defined(__GNUC__)
{
cv::Mat tmpmat(std::vector<unsigned char>(matchedHistogramIndexes.begin(), matchedHistogramIndexes.end()));
cv::calcHist(&tmpmat, 1, local::indexHistChannels, cv::Mat(), hist, local::histDims, local::indexHistSize, local::indexHistRanges, true, false);
}
#else
cv::calcHist(&cv::Mat(std::vector<unsigned char>(matchedHistogramIndexes.begin(), matchedHistogramIndexes.end())), 1, local::indexHistChannels, cv::Mat(), hist, local::histDims, local::indexHistSize, local::indexHistRanges, true, false);
#endif
// normalize histogram
//HistogramUtil::normalizeHistogram(hist, params_.maxMatchedHistogramNum);
// draw matched index histogram
cv::Mat histImg(cv::Mat::zeros(local::indexHistMaxHeight, local::indexHistBins*local::indexHistBinWidth, CV_8UC3));
HistogramUtil::drawHistogram1D(hist, local::indexHistBins, params_.maxMatchedHistogramNum, local::indexHistBinWidth, local::indexHistMaxHeight, histImg);
std::ostringstream sstream;
sstream << "count: " << matchedHistogramIndexes.size();
cv::putText(histImg, sstream.str(), cv::Point(10, 15), cv::FONT_HERSHEY_COMPLEX, 0.5, CV_RGB(255, 0, 255), 1, 8, false);
cv::imshow(windowName, histImg);
}