Unified · Split
| @@ -76,4 +76,19 @@ class MotionField { · 75 unmodified lines | |||
| 76 | line(ox, oy, ox + mv.x, oy + mv.y); | 76 | line(ox, oy, ox + mv.x, oy + mv.y); |
| 77 | } | 77 | } |
| 78 | } | 78 | } |
| 79 | |||
| 80 | void save(String path) { | ||
| 81 | int r_num = height / block_size; | ||
| 82 | int c_num = width / block_size; | ||
| 83 | String[] mvs = new String[r_num]; | ||
| 84 | for (int i = 0; i < r_num; i++) { | ||
| 85 | mvs[i] = ""; | ||
| 86 | for (int j = 0; j < c_num; j++) { | ||
| 87 | PVector mv = motion_field.get(i * c_num + j); | ||
| 88 | mvs[i] += str(mv.x) + "," + str(mv.y); | ||
| 89 | if (j != c_num - 1) mvs[i] += ";"; | ||
| 90 | } | ||
| 91 | } | ||
| 92 | saveStrings(path, mvs); | ||
| 93 | } | ||
| 79 | } | 94 | } |
| @@ -5,6 +5,7 @@ class Scene { · 4 unmodified lines | |||
| 5 | MotionField motion_field; | 5 | MotionField motion_field; |
| 6 | Camera last_cam; | 6 | Camera last_cam; |
| 7 | Camera current_cam; | 7 | Camera current_cam; |
| 8 | int frame_count; | ||
| 8 | 9 | ||
| 9 | Scene(Camera camera, PointCloud point_cloud, MotionField motion_field) { | 10 | Scene(Camera camera, PointCloud point_cloud, MotionField motion_field) { |
| 10 | this.point_cloud = point_cloud; | 11 | this.point_cloud = point_cloud; |
| @@ -26,12 +27,14 @@ class Scene { · 15 unmodified lines | |||
| 26 | bvh = new BVH(mesh); | 27 | bvh = new BVH(mesh); |
| 27 | last_cam = camera.copy(); | 28 | last_cam = camera.copy(); |
| 28 | current_cam = camera; | 29 | current_cam = camera; |
| 30 | frame_count = 0; | ||
| 29 | } | 31 | } |
| 30 | 32 | ||
| 31 | void run() { | 33 | void run() { |
| 32 | last_cam = current_cam.copy(); | 34 | last_cam = current_cam.copy(); |
| 33 | current_cam.run(); | 35 | current_cam.run(); |
| 34 | motion_field.update(last_cam, current_cam, point_cloud, bvh); | 36 | motion_field.update(last_cam, current_cam, point_cloud, bvh); |
| 37 | frame_count += 1; | ||
| 35 | } | 38 | } |
| 36 | 39 | ||
| 37 | void render(boolean show_motion_field) { | 40 | void render(boolean show_motion_field) { |
| @@ -47,4 +50,10 @@ class Scene { · 9 unmodified lines | |||
| 47 | motion_field.render(); | 50 | motion_field.render(); |
| 48 | } | 51 | } |
| 49 | } | 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 | } | ||
| 50 | } | 59 | } |
| @@ -10,7 +10,7 @@ void setup() { · 9 unmodified lines | |||
| 10 | // default settings | 10 | // default settings |
| 11 | int frame_no = 0; // frame number | 11 | int frame_no = 0; // frame number |
| 12 | float fov = PI / 3; // field of view | 12 | float fov = PI / 3; // field of view |
| 13 | int block_size = 32; // block size | 13 | int block_size = 8; // block size |
| 14 | float normalizer = 5000.0f; // normalizer | 14 | float normalizer = 5000.0f; // normalizer |
| 15 | // initialize | 15 | // initialize |
| 16 | PointCloud point_cloud = new PointCloud(); | 16 | PointCloud point_cloud = new PointCloud(); |
| @@ -62,6 +62,13 @@ void draw() { · 45 unmodified lines | |||
| 62 | inter = true; | 62 | inter = true; |
| 63 | } | 63 | } |
| 64 | scene.render( | 64 | scene.render( |
| 65 | true); // true: turn on motion field; false: turn off motion field | 65 | false); // true: turn on motion field; false: turn off motion field |
| 66 | // save frame with no motion field | ||
| 67 | scene.save("../data/frame/raw"); | ||
| 68 | background(0); | ||
| 69 | scene.render(true); | ||
| 66 | showGrids(scene.motion_field.block_size); | 70 | showGrids(scene.motion_field.block_size); |
| 71 | // save frame with motion field | ||
| 72 | scene.save("../data/frame/raw_mv"); | ||
| 73 | scene.saveMotionField("../data/frame/mv"); | ||
| 67 | } | 74 | } |