• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1class Scene {
2  PointCloud point_cloud;
3  ArrayList<Triangle> mesh;
4  BVH bvh;
5  MotionField motion_field;
6  Camera last_cam;
7  Camera current_cam;
8  int frame_count;
9
10  Scene(Camera camera, PointCloud point_cloud, MotionField motion_field) {
11    this.point_cloud = point_cloud;
12    this.motion_field = motion_field;
13    mesh = new ArrayList<Triangle>();
14    for (int v = 0; v < height - 1; v++)
15      for (int u = 0; u < width - 1; u++) {
16        PVector p1 = point_cloud.getPosition(v * width + u);
17        PVector p2 = point_cloud.getPosition(v * width + u + 1);
18        PVector p3 = point_cloud.getPosition((v + 1) * width + u + 1);
19        PVector p4 = point_cloud.getPosition((v + 1) * width + u);
20        color c1 = point_cloud.getColor(v * width + u);
21        color c2 = point_cloud.getColor(v * width + u + 1);
22        color c3 = point_cloud.getColor((v + 1) * width + u + 1);
23        color c4 = point_cloud.getColor((v + 1) * width + u);
24        mesh.add(new Triangle(p1, p2, p3, c1, c2, c3));
25        mesh.add(new Triangle(p3, p4, p1, c3, c4, c1));
26      }
27    bvh = new BVH(mesh);
28    last_cam = camera.copy();
29    current_cam = camera;
30    frame_count = 0;
31  }
32
33  void run() {
34    last_cam = current_cam.copy();
35    current_cam.run();
36    motion_field.update(last_cam, current_cam, point_cloud, bvh);
37    frame_count += 1;
38  }
39
40  void render(boolean show_motion_field) {
41    // build mesh
42    current_cam.open();
43    noStroke();
44    for (int i = 0; i < mesh.size(); i++) {
45      Triangle t = mesh.get(i);
46      t.render();
47    }
48    if (show_motion_field) {
49      current_cam.close();
50      motion_field.render();
51    }
52  }
53
54  void save(String path) { saveFrame(path + "_" + str(frame_count) + ".png"); }
55
56  void saveMotionField(String path) {
57    motion_field.save(path + "_" + str(frame_count) + ".txt");
58  }
59}
60