当前位置: 首页>>代码示例>>C++>>正文


C++ PCLVisualizer::addModelFromPolyData方法代码示例

本文整理汇总了C++中PCLVisualizer::addModelFromPolyData方法的典型用法代码示例。如果您正苦于以下问题:C++ PCLVisualizer::addModelFromPolyData方法的具体用法?C++ PCLVisualizer::addModelFromPolyData怎么用?C++ PCLVisualizer::addModelFromPolyData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PCLVisualizer的用法示例。


在下文中一共展示了PCLVisualizer::addModelFromPolyData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

void
visualize (const ModelLibrary::HashTable* hash_table)
{
  const ModelLibrary::HashTableCell* cells = hash_table->getVoxels ();
  size_t max_num_entries = 0;
  int id3[3], num_cells = hash_table->getNumberOfVoxels ();
  double cell_center[3];

  vtkPoints* sphere_centers = vtkPoints::New (VTK_DOUBLE);
  vtkDoubleArray* scale = vtkDoubleArray::New ();
  scale->SetNumberOfComponents(1);

  // Get the positions of the spheres (one sphere per full cell)
  for (int i = 0 ; i < num_cells ; ++i, ++cells)
  {
    // Does the cell have any entries?
    if (cells->size ())
    {
      // Insert the center of the current voxel in the point set
      hash_table->compute3dId (i, id3);
      hash_table->computeVoxelCenter (id3, cell_center);
      sphere_centers->InsertNextPoint (cell_center);

      // Save the number of entries
      scale->InsertNextValue (static_cast<double> (cells->size ()));

      // Get the max
      if (cells->size () > max_num_entries)
        max_num_entries = cells->size ();
    }
  }

  PCLVisualizer vis;
  vis.setBackgroundColor (0.1, 0.1, 0.1);

  // Is there something to visualize?
  if (max_num_entries)
  {
    // Compute the factor which maps all the scale values in (0, 1]
    double factor = 1.0/static_cast<double> (max_num_entries);
    // Set the true scale
    for (vtkIdType i = 0 ; i < scale->GetNumberOfTuples () ; ++i)
      scale->SetValue(i, factor*scale->GetValue (i));

    // Input for the glyph object: the centers + scale
    vtkPolyData *positions = vtkPolyData::New ();
    positions->SetPoints (sphere_centers);
    positions->GetPointData ()->SetScalars (scale);
    // The spheres
    vtkSphereSource* sphere_src = vtkSphereSource::New ();
    sphere_src->SetPhiResolution(8);
    sphere_src->SetThetaResolution(8);
    sphere_src->SetRadius(0.5*hash_table->getVoxelSpacing ()[0]);

    // Now that we have the points and the corresponding scalars, build the glyph object
    vtkGlyph3D *glyph = vtkGlyph3D::New ();
    glyph->SetScaleModeToScaleByScalar ();
    glyph->SetColorModeToColorByScalar ();
    glyph->SetInput (positions);
    glyph->SetSource (sphere_src->GetOutput ());
    glyph->Update ();

    vtkSmartPointer<vtkPolyData> glyph_output (glyph->GetOutput ());
    vis.addModelFromPolyData(glyph_output);

    // Cleanup
    glyph->Delete ();
    positions->Delete ();
    sphere_src->Delete ();
  }

  vis.spin();

  // Cleanup
  sphere_centers->Delete();
  scale->Delete();
}
开发者ID:Bardo91,项目名称:pcl,代码行数:77,代码来源:visualize_obj_rec_ransac_hash_table.cpp


注:本文中的PCLVisualizer::addModelFromPolyData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。