Util.pde 1.0 KB

12345678910111213141516171819202122232425262728
  1. // show grids
  2. void showGrids(int block_size) {
  3. ortho(-width, 0, -height, 0);
  4. camera(0, 0, 0, 0, 0, 1, 0, 1, 0);
  5. stroke(0, 0, 255);
  6. for (int i = 0; i < height; i += block_size) {
  7. line(0, i, width, i);
  8. }
  9. for (int i = 0; i < width; i += block_size) {
  10. line(i, 0, i, height);
  11. }
  12. }
  13. // save the point clould information
  14. void savePointCloud(PointCloud point_cloud, String file_name) {
  15. String[] positions = new String[point_cloud.points.size()];
  16. String[] colors = new String[point_cloud.points.size()];
  17. for (int i = 0; i < point_cloud.points.size(); i++) {
  18. PVector point = point_cloud.getPosition(i);
  19. color point_color = point_cloud.getColor(i);
  20. positions[i] = str(point.x) + ' ' + str(point.y) + ' ' + str(point.z);
  21. colors[i] = str(((point_color >> 16) & 0xFF) / 255.0) + ' ' +
  22. str(((point_color >> 8) & 0xFF) / 255.0) + ' ' +
  23. str((point_color & 0xFF) / 255.0);
  24. }
  25. saveStrings(file_name + "_pos.txt", positions);
  26. saveStrings(file_name + "_color.txt", colors);
  27. }