Comments (11)
I see why that happens. Would this be an acceptable solution?
settings.force_single_precision_points = False
a = vedo.Mesh([np.array([[1.5146416416146161461, 2.464164164164161461254, 3.145315134513465161441]], dtype=np.float64), [], []])
print(a.vertices.dtype)
# float64
(just pushed a version on master)
from vedo.
Yep, that's perfect! Thanks!
from vedo.
Hi, actually i'm not completely sure that that is the case.. e.g.
from vedo import *
Sphere().vertices.dtype
dtype('float32')
from vedo.
It doesn't occur with the bunny.obj dummy example but it does occur for high fidelity meshes. For example: https://www.artec3d.com/3d-models/buggy.
import vedo
import numpy as np
path = "Buggy.ply"
mesh = vedo.Mesh(path)
a = mesh.center_of_mass()
b = mesh.vertices.copy()
b.mean(axis=0)
c = b.astype(np.float64)
c.mean(axis=0)
# PLY: (Same for STL)
# A: array([-160.66834098, 23.57756032, -87.22478219])
# B: array([-160.66664 , 23.578615, -87.15967 ], dtype=float32)
# C: array([-160.66834098, 23.57756032, -87.22478219])
# Difference between B and A/C is floating point precision.
Note that vedo's definition of center of mass is actually just the mean for x, y and z (another topic).
As you can see from the above, computations are done in float64 in VTK but the data type outputted is float32. Therefore, any usage of numpy without explicitly setting the data type may result in this issue.
from vedo.
I don't fully understand though what is the issue here if I run
import vedo
mesh = vedo.Mesh("Buggy.ply")
a = mesh.center_of_mass()
print(a.dtype)
b = mesh.vertices#.copy()
print(b.dtype)
I get
float64
float32
but why do you say that this would cause problems?
from vedo.
There are several areas within the codebase where numpy is used within functions, with np.array(x) or np.array().float(), without specifying the data type. I've had to accommodate for this difference in a few areas. There are a few spots in my codebase where I round to 6 dp for comparisons and recently realised it's due to this issue.
For instance:
Line 791 in db0c0bf
- Vertices being converted to float32 here:
Line 1435 in db0c0bf
- Possibly here too
Line 203 in db0c0bf
from vedo.
Hi, the vtk2numpy()
function is not overriding the input type so it looks to me it's doing the right thing(?)
The other ones in file_io and backends are rather innocuous.
Note that you should not compare floats to floats and doubles to doubles directly without declaring a tolerance.
from vedo.
Fair. It isn't explicitly mentioned for users developing with vedo that VTK uses doubles by default. Could maybe throw something into the getting started section of the documents but regardless, will close this issue.
from vedo.
This is still causing me problems. Here's a useful example:
a = vedo.Mesh([np.array([[1.5146416416146161461, 2.464164164164161461254, 3145315134513465161441]], dtype=np.float64), [], []])
print(a.vertices)
# array([[1.5146416e+00, 2.4641643e+00, 3.1453151e+21]], dtype=float32)
from vedo.
Hi @marcomusy, currently running into a problem with this solution:
from vedo import Axes, Box, show
settings.force_single_precision_points = False
box = Box(pos=(1,2,3), length=8, width=9, height=7).alpha(0.1)
axs = Axes(box, c='k')
Running this gives: "TypeError: Could not find a suitable VTK type for float16". From what I can tell it looks like a problem with the Axes -- specifically it seems that the mesh for the fonts has its vertices in Float16 which now don't get converted into Float32 anymore.
from vedo.
Thanks for spotting the bug, This should now be fixed in master.
from vedo.
Related Issues (20)
- Arrow object's top point HOT 2
- Group objects HOT 1
- Help ! Legosurface Error HOT 2
- version 2024.5.2 `show()` function returns error HOT 4
- quality and resolution of the video HOT 3
- Make load functions compatible with pathlib.Path HOT 1
- Creating a plot with objects out of scene, seems to break calls to render HOT 1
- Mesh.volume() and Mesh.is_closed() don't work with Boxes and Cylinders HOT 1
- compute_normals() unexpectedly changes the appearance of a Mesh HOT 2
- Cut volume with volume HOT 1
- seg fault on vertex normal and texture indices in obj format to off conversion HOT 2
- Issues with boolean operation HOT 4
- Touching objects handling in isosurface_discrete HOT 10
- Problems with boolean operations on concave polyhedrons HOT 4
- Problem with mesh formation
- mesh.cells datatype HOT 2
- Axes order of numpy array HOT 2
- computing volume of intersecting concave polyhedra HOT 1
- 2D images become non-pickable after changing cmap HOT 2
- Docs cannot be accessed due to certificate expiration HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vedo.