void show_octree (ORROctree* octree, PCLVisualizer& viz)
{
  vtkSmartPointer<vtkPolyData> vtk_octree = vtkSmartPointer<vtkPolyData>::New ();
  vtkSmartPointer<vtkAppendPolyData> append = vtkSmartPointer<vtkAppendPolyData>::New ();

  cout << "There are " << octree->getFullLeaves ().size () << " full leaves.\n";

  std::vector<ORROctree::Node*>& full_leaves = octree->getFullLeaves ();
  for (const auto &full_leaf : full_leaves)
    // Add it to the other cubes
    node_to_cube (full_leaf, append);

  // Save the result
  append->Update();
  vtk_octree->DeepCopy (append->GetOutput ());

  // Add to the visualizer
  vtkRenderer *renderer = viz.getRenderWindow ()->GetRenderers ()->GetFirstRenderer ();
  vtkSmartPointer<vtkActor> octree_actor = vtkSmartPointer<vtkActor>::New();
  vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
  mapper->SetInputData (vtk_octree);
  octree_actor->SetMapper(mapper);

  // Set the appearance & add to the renderer
  octree_actor->GetProperty ()->SetColor (1.0, 1.0, 1.0);
  renderer->AddActor(octree_actor);
}
void show_octree_zproj (ORROctreeZProjection* zproj, PCLVisualizer& viz)
{
  cout << "There is (are) " << zproj->getFullPixels ().size () << " full pixel(s).\n";

  vtkSmartPointer<vtkAppendPolyData> upper_bound = vtkSmartPointer<vtkAppendPolyData>::New (), lower_bound = vtkSmartPointer<vtkAppendPolyData>::New ();
  const ORROctreeZProjection::Pixel *pixel;
  const float *b = zproj->getBounds ();
  float x, y, psize = zproj->getPixelSize ();
  int i, j, width, height;

  zproj->getNumberOfPixels (width, height);

  for ( i = 0, x = b[0] ; i < width ; ++i, x += psize )
  {
    for ( j = 0, y = b[2] ; j < height ; ++j, y += psize )
    {
      pixel = zproj->getPixel (i, j);

      if ( !pixel )
        continue;

      rectangle_to_vtk (x, x + psize, y, y + psize, pixel->z1 (), lower_bound);
      rectangle_to_vtk (x, x + psize, y, y + psize, pixel->z2 (), upper_bound);
    }
  }

  // Save the result
  upper_bound->Update();
  lower_bound->Update();

  // Add to the visualizer
  vtkRenderer *renderer = viz.getRenderWindow ()->GetRenderers ()->GetFirstRenderer ();
  vtkSmartPointer<vtkActor> upper_actor = vtkSmartPointer<vtkActor>::New(), lower_actor = vtkSmartPointer<vtkActor>::New();
  vtkSmartPointer<vtkDataSetMapper> upper_mapper = vtkSmartPointer<vtkDataSetMapper>::New (), lower_mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
  upper_mapper->SetInputData (upper_bound->GetOutput ());
  upper_actor->SetMapper(upper_mapper);
  lower_mapper->SetInputData (lower_bound->GetOutput ());
  lower_actor->SetMapper(lower_mapper);

  // Set the appearance & add to the renderer
  upper_actor->GetProperty ()->SetColor (1.0, 0.0, 0.0);
  renderer->AddActor(upper_actor);
  lower_actor->GetProperty ()->SetColor (1.0, 1.0, 0.0);
  renderer->AddActor(lower_actor);
}
Beispiel #3
0
void show_octree (ORROctree* octree, PCLVisualizer& viz, bool show_full_leaves_only)
{
    vtkSmartPointer<vtkPolyData> vtk_octree = vtkSmartPointer<vtkPolyData>::New ();
    vtkSmartPointer<vtkAppendPolyData> append = vtkSmartPointer<vtkAppendPolyData>::New ();

    cout << "There are " << octree->getFullLeaves ().size () << " full leaves.\n";

    if ( show_full_leaves_only )
    {
        std::vector<ORROctree::Node*>& full_leaves = octree->getFullLeaves ();
        for ( std::vector<ORROctree::Node*>::iterator it = full_leaves.begin () ; it != full_leaves.end () ; ++it )
            // Add it to the other cubes
            node_to_cube (*it, append);
    }
    else
    {
        ORROctree::Node* node;

        std::list<ORROctree::Node*> nodes;
        nodes.push_back (octree->getRoot ());

        while ( !nodes.empty () )
        {
            node = nodes.front ();
            nodes.pop_front ();

            // Visualize the node if it has children
            if ( node->getChildren () )
            {
                // Add it to the other cubes
                node_to_cube (node, append);
                // Add all the children to the working list
                for ( int i = 0 ; i < 8 ; ++i )
                    nodes.push_back (node->getChild (i));
            }
            // If we arrived at a leaf -> check if it's full and visualize it
            else if ( node->getData () )
                node_to_cube (node, append);
        }
    }

    // Just print the leaf size
    std::vector<ORROctree::Node*>::iterator first_leaf = octree->getFullLeaves ().begin ();
    if ( first_leaf != octree->getFullLeaves ().end () )
        printf("leaf size = %f\n", (*first_leaf)->getBounds ()[1] - (*first_leaf)->getBounds ()[0]);

    // Save the result
    append->Update();
    vtk_octree->DeepCopy (append->GetOutput ());

    // Add to the visualizer
    vtkRenderer *renderer = viz.getRenderWindow ()->GetRenderers ()->GetFirstRenderer ();
    vtkSmartPointer<vtkActor> octree_actor = vtkSmartPointer<vtkActor>::New();
    vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
    mapper->SetInput(vtk_octree);
    octree_actor->SetMapper(mapper);

    // Set the appearance & add to the renderer
    octree_actor->GetProperty ()->SetColor (1.0, 1.0, 1.0);
    octree_actor->GetProperty ()->SetLineWidth (1);
    octree_actor->GetProperty ()->SetRepresentationToWireframe ();
    renderer->AddActor(octree_actor);
}