Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. diff --git a/tutorials/Tutorial_303_Viewer_Qt/main_window.cpp b/tutorials/Tutorial_303_Viewer_Qt/main_window.cpp
  2. index d262149..d6c010f 100644
  3. --- a/tutorials/Tutorial_303_Viewer_Qt/main_window.cpp
  4. +++ b/tutorials/Tutorial_303_Viewer_Qt/main_window.cpp
  5. @@ -198,6 +198,38 @@ Model* MainWindow::open(const std::string& file_name) {
  6.              std::cout << "mesh loaded. num faces: " << mesh->n_faces() << "; "
  7.                  << "num vertices: " << mesh->n_vertices() << "; "
  8.                  << "num edges: " << mesh->n_edges() << std::endl;
  9. +#if 1
  10. +            // Now let's create the drawable for the bounding box of the model.
  11. +            // We also attached it to the model.
  12. +            auto vertices = mesh->get_vertex_property<vec3>("v:point");
  13. +            const auto& points = vertices.vector();
  14. +            LinesDrawable* bbox_drawable = mesh->add_lines_drawable("bbox");
  15. +            Box3 box;
  16. +            // Compute the bounding box.
  17. +            for (const auto& p : points)
  18. +                box.add_point(p);
  19. +            float xmin = box.min(0);   float xmax = box.max(0);
  20. +            float ymin = box.min(1);   float ymax = box.max(1);
  21. +            float zmin = box.min(2);   float zmax = box.max(2);
  22. +            // The eight vertices of the bounding box.
  23. +            const std::vector<vec3> bbox_points = {
  24. +                vec3(xmin, ymin, zmax), vec3(xmax, ymin, zmax),
  25. +                vec3(xmin, ymax, zmax),        vec3(xmax, ymax, zmax),
  26. +                vec3(xmin, ymin, zmin),        vec3(xmax, ymin, zmin),
  27. +                vec3(xmin, ymax, zmin),        vec3(xmax, ymax, zmin)
  28. +            };
  29. +            const std::vector<unsigned int> bbox_indices = {
  30. +                0, 1, 2, 3, 4, 5, 6, 7,
  31. +                0, 2, 4, 6, 1, 3, 5, 7,
  32. +                0, 4, 2, 6, 1, 5, 3, 7
  33. +            };
  34. +
  35. +            // Upload the vertex positions of the bounding box to the GPU.
  36. +            bbox_drawable->update_vertex_buffer(bbox_points);
  37. +            // Upload the vertex indices of the bounding box to the GPU.
  38. +            bbox_drawable->update_index_buffer(bbox_indices);
  39. +            bbox_drawable->set_default_color(vec3(1.0f, 0.0f, 0.0f));  // red color
  40. +#endif
  41.          }
  42.      }
  43.      else { // point cloud
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement