Esempio n. 1
0
int
main (int argc, char** argv)
{
  // Make sure that we have the right number of arguments
  if (argc != 2)
  {
    print_info ("\nVisualizes the hash table after adding the provided mesh to it.\n"
        "usage:\n"
        "./obj_rec_ransac_hash_table <mesh.vtk>\n");
    return (-1);
  }

  ObjRecRANSAC::PointCloudIn points_in;
  ObjRecRANSAC::PointCloudN normals_in;
  double b[6];

  if ( !vtk_to_pointcloud (argv[1], points_in, normals_in, b) )
    return (-1);

  // Compute the bounding box diagonal
  float diag = static_cast<float> (sqrt (my_sqr (b[1]-b[0]) + my_sqr (b[3]-b[2]) + my_sqr (b[5]-b[4])));

  // Create the recognition object (we need it only for its hash table)
  ObjRecRANSAC objrec (diag/8.0f, diag/60.0f);
  objrec.addModel (points_in, normals_in, "test_model");

  // Start visualization (and the main VTK loop)
  visualize (objrec.getHashTable ());

  return (0);
}
int
main (int argc, char** argv)
{
  // Make sure that we have the right number of arguments
  if (argc != 2)
  {
    print_info ("\nVisualizes the hash table after adding the provided mesh to it.\n"
        "usage:\n"
        "./visualize_obj_rec_ransac_hash_table mesh.vtk\n");
    return (-1);
  }

  // Parse the command line arguments for .vtk files
  if ( parse_file_extension_argument (argc, argv, ".vtk").size () != 1 )
  {
    print_error ("We need a .vtk object.\n");
    return (-1);
  }

  // Load the model
  vtkPolyDataReader *vtk_reader = vtkPolyDataReader::New ();
  vtk_reader->SetFileName (argv[1]);
  vtk_reader->Update ();
  vtkPolyData *vtk_mesh = vtk_reader->GetOutput ();
  // Get the bounds of the mesh
  double mb[6];
  vtk_mesh->ComputeBounds ();
  vtk_mesh->GetBounds (mb);

  // Create a point cloud with normals
  ModelLibrary::PointCloudInPtr eigen_points (new ModelLibrary::PointCloudIn ());
  ModelLibrary::PointCloudNPtr eigen_normals (new ModelLibrary::PointCloudN ());
  if ( !get_points_and_normals (vtk_mesh, *eigen_points.get(), *eigen_normals.get()) )
  {
    vtk_reader->Delete ();
    return (-1);
  }

  // Compute the bounding box diagonal
  double diag = sqrt (my_sqr (mb[1]-mb[0]) + my_sqr (mb[3]-mb[2]) + my_sqr (mb[5]-mb[4]));

  // Create the recognition object (we need it only for its hash table)
  ObjRecRANSAC objrec (diag/8.0, diag/20.0);
  printf("Adding the model to the library ... "); fflush (stdout);
  objrec.addModel (eigen_points, eigen_normals, string ("test_model"));
  printf("OK\n");

  // Start visualization (and the main VTK loop)
  visualize (objrec.getHashTable ());

  // Cleanup
  vtk_reader->Delete ();

  return 0;
}