Unified · Split
| @@ -76,4 +76,19 @@ class MotionField { · 75 unmodified lines | ||
| 76 | 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 | 5 | MotionField motion_field; |
| 6 | 6 | Camera last_cam; |
| 7 | 7 | Camera current_cam; |
| 8 | + int frame_count; | |
| 8 | 9 | |
| 9 | 10 | Scene(Camera camera, PointCloud point_cloud, MotionField motion_field) { |
| 10 | 11 | this.point_cloud = point_cloud; |
| @@ -26,12 +27,14 @@ class Scene { · 15 unmodified lines | ||
| 26 | 27 | bvh = new BVH(mesh); |
| 27 | 28 | last_cam = camera.copy(); |
| 28 | 29 | current_cam = camera; |
| 30 | + frame_count = 0; | |
| 29 | 31 | } |
| 30 | 32 | |
| 31 | 33 | void run() { |
| 32 | 34 | last_cam = current_cam.copy(); |
| 33 | 35 | current_cam.run(); |
| 34 | 36 | motion_field.update(last_cam, current_cam, point_cloud, bvh); |
| 37 | + frame_count += 1; | |
| 35 | 38 | } |
| 36 | 39 | |
| 37 | 40 | void render(boolean show_motion_field) { |
| @@ -47,4 +50,10 @@ class Scene { · 9 unmodified lines | ||
| 47 | 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 | 10 | // default settings |
| 11 | 11 | int frame_no = 0; // frame number |
| 12 | 12 | float fov = PI / 3; // field of view |
| 13 | − int block_size = 32; // block size | |
| 13 | + int block_size = 8; // block size | |
| 14 | 14 | float normalizer = 5000.0f; // normalizer |
| 15 | 15 | // initialize |
| 16 | 16 | PointCloud point_cloud = new PointCloud(); |
| @@ -62,6 +62,13 @@ void draw() { · 45 unmodified lines | ||
| 62 | 62 | inter = true; |
| 63 | 63 | } |
| 64 | 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 | 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 | } |