isl-org / isl-org/Open3D

Unable to load UTM based objects correctly

Open
#6,525 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
14k
Forks
2.6k
Avg merge
5d 18h
Merged PRs (30d)
6

Description

### Checklist

- [X] I have searched for [similar issues](https://github.com/isl-org/Open3D/issues).
- [X] For Python issues, I have tested with the [latest development wheel](http://www.open3d.org/docs/latest/getting_started.html#development-version-pip).
- [X] I have checked the [release documentation](http://www.open3d.org/docs/release/) and the [latest documentation](http://www.open3d.org/docs/latest/) (for `master` branch).

### Describe the issue

When loading an OBJ file saved in UTM coordinates the values are too big for the Float32 used by open3d. This manifests as a vague "shimmering" of the mesh when moving the viewport. Even worse is the fact is that translating the mesh to be close to the centre stops the "shimmering" But leaves the mesh distorted. See the images of the same mesh opened by CloudCompare and Open3D. The problems stems from the fact that the translation occurs already after the precision has been lost in the conversion to float32. Since there is no built-in way to handle these translations I pre-compute a translation of the meshes using numpy, which by default uses float64 to represent variables. I am providing a simplified version of what i mean below.
![image](https://github.com/isl-org/Open3D/assets/66642543/c5aa045d-ee42-4fbd-aa9b-8275c7e63ff5)

![image](https://github.com/isl-org/Open3D/assets/66642543/ce5c3ce6-9e5e-4dd1-b19d-8b3eee7ac3cf)

![image](https://github.com/isl-org/Open3D/assets/66642543/22e8614a-fd32-4644-8cf5-97c331ccc0ee)

### Steps to reproduce the bug

```python
import open3d as o3d
import numpy as np

def translate_utm_obj(obj_path, translated_path):
obj_file = open(obj_path,'r')
lines = obj_file.readlines()
num_vertices = len([line for line in lines if line.startswith('v ')])
utm_vertices = np.zeros((num_vertices,3))
local_vertices = np.zeros((num_vertices,3))
i = 0
for line in lines:
split = line.split()
if split == []:
continue
elif split[0]!= 'v':
continue
elif split[0] == 'v':
utm_vertices[i,:] = np.array([float(split[1]),float(split[2]),float(split[3])])
i +=1

local_vertices[:,0] = utm_vertices[:,0] - np.min(utm_vertices[:,0])
local_vertices[:,1] = utm_vertices[:,1] - np.min(utm_vertices[:,1])
local_vertices[:,2] = utm_vertices[:,2] - np.min(utm_vertices[:,2])
i = 0
translated_obj = open(translated_path,'w')
for line in lines:
split = line.split()
if split == []:
continue
elif split[0]!= 'v':
translated_obj.write(line)
elif split[0] == 'v':
translated_obj.write('v '+str(local_vertices[i,0])+' '+str(local_vertices[i,1])+' '+str(local_vertices[i,2])+'\n')
i +=1
translated_obj.close()
obj_file.close()

return True

def open_local_obj(obj_path):
mesh = o3d.io.read_triangle_mesh(obj_path,True)
return mesh

def naive_translate_utm_obj(obj_path):
mesh = o3d.io.read_triangle_mesh(obj_path,True)
mesh.translate(-mesh.get_center())
return mesh

translate_utm_obj(obj_file_path,translated_path)
mesh = open_local_obj(translated_path)
wrong_mesh = naive_translate_utm_obj(obj_file_path)

global_view = o3d.visualization.Visualizer()
global_view.create_window(window_name="Open3D correct translation", visible=True)
global_view.add_geometry(mesh)
while True:
global_view.poll_events()
global_view.update_renderer()
```

### Error message

_No response_

### Expected behavior

There should be a warning about loading entities represented by variables too big to be precisely represented by a float32. A feature request would be an automatic translation step but that might be debatable

### Open3D, Python and System information

```markdown
- Operating system: Ubuntu 20.04
- Python version: Python 3.8
- Open3D version: 0.16
- System architecture: x86
- Is this a remote workstation?: no
- How did you install Open3D?: pip
```

### Additional information

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.