Exemple #1
0
////////////////////////////////HistVizualizer Functions//////////////////////////////////////
bool
pcl::visualization::PCLPlotter::addFeatureHistogram (
    const sensor_msgs::PointCloud2 &cloud, const std::string &field_name, 
    const std::string &id, int win_width, int win_height)
{
  // Get the field
  int field_idx = pcl::getFieldIndex (cloud, field_name);
  if (field_idx == -1)
  {
    PCL_ERROR ("[addFeatureHistogram] Invalid field (%s) given!", field_name.c_str ());
    return (false);
  }

  int hsize = cloud.fields[field_idx].count;
  std::vector<double> array_x (hsize), array_y (hsize);
  
  // Parse the cloud data and store it in the array
  for (int i = 0; i < hsize; ++i)
  {
    array_x[i] = i;
    float data;
    // TODO: replace float with the real data type
    memcpy (&data, &cloud.data[cloud.fields[field_idx].offset + i * sizeof (float)], sizeof (float));
    array_y[i] = data;
  }
  
  this->addPlotData(array_x, array_y, id.c_str(), vtkChart::LINE);
  setWindowSize (win_width, win_height);
  return (true);
}
Exemple #2
0
int main() {

  const float a = 100.0f;
  float host_x[N];
  float host_y[N];

  // initialize the input data
  std::default_random_engine random_gen;
  std::uniform_real_distribution<float> distribution(-N, N);
  std::generate_n(host_x, N, [&]() { return distribution(random_gen); });
  std::generate_n(host_y, N, [&]() { return distribution(random_gen); });

  // CPU implementation of saxpy
  float host_result_y[N];
  for (int i = 0; i < N; i++) {
    host_result_y[i] = a * host_x[i] + host_y[i]; 
  }

  // allocate data buffers on the accelerator and copy the data over
  hc::array<float, 1> array_x(N);
  hc::completion_future future_x = hc::copy_async(host_x, host_x + N, array_x);

  hc::array<float, 1> array_y(N);
  hc::completion_future future_y = hc::copy_async(host_y, host_y + N, array_y);

  // wait for the copy operations to complete
  future_x.wait();
  future_y.wait();

  // launch a GPU kernel to compute the saxpy in parallel
  hc::completion_future future_pfe;
  future_pfe = hc::parallel_for_each(hc::extent<1>(N)
                      , [&](hc::index<1> i) [[hc]] {
    array_y[i] = a * array_x[i] + array_y[i];
  });

  // wait for the kernel to complete before copying results back
  // to the host
  future_pfe.wait();
  future_y = hc::copy_async(array_y, host_y);
  future_y.wait();

  // verify the results
  int errors = 0;
  for (int i = 0; i < N; i++) {
    if (fabs(host_y[i] - host_result_y[i]) > fabs(host_result_y[i] * 0.0001f))
      errors++;
  }
  std::cout << errors << " errors" << std::endl;

  return errors;
}
Exemple #3
0
template <typename PointT> bool
pcl::visualization::PCLPlotter::addFeatureHistogram (
    const pcl::PointCloud<PointT> &cloud, int hsize, 
    const std::string &id, int win_width, int win_height)
{
  std::vector<double> array_x(hsize), array_y(hsize);
  
  // Parse the cloud data and store it in the array
  for (int i = 0; i < hsize; ++i)
  {
    array_x[i] = i;
    array_y[i] = cloud.points[0].histogram[i];
  }
  
  this->addPlotData(array_x, array_y, id.c_str(), vtkChart::LINE);
  setWindowSize (win_width, win_height);
  return true;
}
Exemple #4
0
bool
pcl::visualization::PCLPlotter::addFeatureHistogram (
    const sensor_msgs::PointCloud2 &cloud, 
    const std::string &field_name, 
    const int index,
    const std::string &id, int win_width, int win_height)
{
  if (index < 0 || index >= static_cast<int> (cloud.width * cloud.height))
  {
    PCL_ERROR ("[addFeatureHistogram] Invalid point index (%d) given!\n", index);
    return (false);
  }
  
  // Get the field
  int field_idx = pcl::getFieldIndex (cloud, field_name);
  if (field_idx == -1)
  {
    PCL_ERROR ("[addFeatureHistogram] Invalid field (%s) given!", field_name.c_str ());
    return (false);
  }

  // Compute the total size of the fields
  unsigned int fsize = 0;
  for (size_t i = 0; i < cloud.fields.size (); ++i)
    fsize += cloud.fields[i].count * pcl::getFieldSize (cloud.fields[i].datatype);
  
  int hsize = cloud.fields[field_idx].count;
  std::vector<double> array_x (hsize), array_y (hsize);
  
  // Parse the cloud data and store it in the array
  for (int i = 0; i < hsize; ++i)
  {
    array_x[i] = i;
    float data;
    // TODO: replace float with the real data type
    memcpy (&data, &cloud.data[index * fsize + cloud.fields[field_idx].offset + i * sizeof (float)], sizeof (float));
    array_y[i] = data;
  }
  
  this->addPlotData(array_x, array_y, id.c_str(), vtkChart::LINE);
  setWindowSize (win_width, win_height);
  return (true);
}
Exemple #5
0
void
pcl::visualization::PCLPlotter::addPlotData (
    PolynomialFunction const & p_function,
    double x_min, double y_min,
    char const *name,
    int num_points,
    std::vector<char> const &color)
{
  std::vector<double> array_x(num_points), array_y(num_points);
  double incr = (y_min - x_min)/num_points;
  
  for (int i = 0; i < num_points; i++)
  {
    double xval = i*incr + x_min;
    array_x[i] = xval;
    array_y[i] = compute(p_function, xval);
  }
  
  this->addPlotData (array_x, array_y, name, vtkChart::LINE, color);
}
Exemple #6
0
// an SAXPY example which uses hc::array
int main() {

  const float a = 100.0f;
  float x[N];
  float y[N];

  // initialize the input data
  std::default_random_engine random_gen;
  std::uniform_real_distribution<float> distribution(-N, N);
  std::generate_n(x, N, [&]() { return distribution(random_gen); });
  std::generate_n(y, N, [&]() { return distribution(random_gen); });

  // make a copy of for the GPU implementation 
  float y_gpu[N];
  std::copy_n(y, N, y_gpu);

  // CPU implementation of saxpy
  for (int i = 0; i < N; i++) {
    y[i] = a * x[i] + y[i]; 
  }

  try {
    hc::array<float, 1> array_x(N);
    hc::completion_future future_x = hc::copy_async(x, x + N, array_x);

    hc::array<float, 1> array_y(N);
    hc::completion_future future_y = hc::copy_async(y_gpu, y_gpu + N, array_y);

    future_x.wait();
    future_y.wait();

    // launch a GPU kernel to compute the saxpy in parallel 
    hc::completion_future future_kernel = hc::parallel_for_each(hc::extent<1>(N)
                        , [&](hc::index<1> i) __attribute((hc)) {
      array_y[i] = a * array_x[i] + array_y[i];
    });

    future_kernel.wait();

    hc::copy_async(array_y, y_gpu).wait();
  } catch (std::exception& e) {
Exemple #7
0
template <typename PointT> bool
pcl::visualization::PCLPlotter::addFeatureHistogram (
    const pcl::PointCloud<PointT> &cloud, 
    const std::string &field_name,
    const int index, 
    const std::string &id, int win_width, int win_height)
{
  if (index < 0 || index >= cloud.points.size ())
  {
    PCL_ERROR ("[addFeatureHistogram] Invalid point index (%d) given!\n", index);
    return (false);
  }

  // Get the fields present in this cloud
  std::vector<sensor_msgs::PointField> fields;
  // Check if our field exists
  int field_idx = pcl::getFieldIndex<PointT> (cloud, field_name, fields);
  if (field_idx == -1)
  {
    PCL_ERROR ("[addFeatureHistogram] The specified field <%s> does not exist!\n", field_name.c_str ());
    return (false);
  }

  int hsize = fields[field_idx].count;
  std::vector<double> array_x (hsize), array_y (hsize);
  
  for (int i = 0; i < hsize; ++i)
  {
    array_x[i] = i;
    float data;
    // TODO: replace float with the real data type
    memcpy (&data, reinterpret_cast<const char*> (&cloud.points[index]) + fields[field_idx].offset + i * sizeof (float), sizeof (float));
    array_y[i] = data;
  }
  
  this->addPlotData(array_x, array_y, id.c_str(), vtkChart::LINE);
  setWindowSize (win_width, win_height);
  return (true);
}