File: Scene.pde

package info (click to toggle)
libvpx 1.15.0-2.1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 27,004 kB
  • sloc: ansic: 252,377; cpp: 115,241; asm: 22,233; sh: 5,289; python: 4,391; perl: 2,010; makefile: 431
file content (59 lines) | stat: -rw-r--r-- 1,826 bytes parent folder | download | duplicates (19)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class Scene {
  PointCloud point_cloud;
  ArrayList<Triangle> mesh;
  BVH bvh;
  MotionField motion_field;
  Camera last_cam;
  Camera current_cam;
  int frame_count;

  Scene(Camera camera, PointCloud point_cloud, MotionField motion_field) {
    this.point_cloud = point_cloud;
    this.motion_field = motion_field;
    mesh = new ArrayList<Triangle>();
    for (int v = 0; v < height - 1; v++)
      for (int u = 0; u < width - 1; u++) {
        PVector p1 = point_cloud.getPosition(v * width + u);
        PVector p2 = point_cloud.getPosition(v * width + u + 1);
        PVector p3 = point_cloud.getPosition((v + 1) * width + u + 1);
        PVector p4 = point_cloud.getPosition((v + 1) * width + u);
        color c1 = point_cloud.getColor(v * width + u);
        color c2 = point_cloud.getColor(v * width + u + 1);
        color c3 = point_cloud.getColor((v + 1) * width + u + 1);
        color c4 = point_cloud.getColor((v + 1) * width + u);
        mesh.add(new Triangle(p1, p2, p3, c1, c2, c3));
        mesh.add(new Triangle(p3, p4, p1, c3, c4, c1));
      }
    bvh = new BVH(mesh);
    last_cam = camera.copy();
    current_cam = camera;
    frame_count = 0;
  }

  void run() {
    last_cam = current_cam.copy();
    current_cam.run();
    motion_field.update(last_cam, current_cam, point_cloud, bvh);
    frame_count += 1;
  }

  void render(boolean show_motion_field) {
    // build mesh
    current_cam.open();
    noStroke();
    for (int i = 0; i < mesh.size(); i++) {
      Triangle t = mesh.get(i);
      t.render();
    }
    if (show_motion_field) {
      current_cam.close();
      motion_field.render();
    }
  }

  void save(String path) { saveFrame(path + "_" + str(frame_count) + ".png"); }

  void saveMotionField(String path) {
    motion_field.save(path + "_" + str(frame_count) + ".txt");
  }
}