本文整理汇总了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();
}