Giter Club home page Giter Club logo

Comments (11)

marcomusy avatar marcomusy commented on August 24, 2024 1

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.

JeffreyWardman avatar JeffreyWardman commented on August 24, 2024 1

Yep, that's perfect! Thanks!

from vedo.

marcomusy avatar marcomusy commented on August 24, 2024

Hi, actually i'm not completely sure that that is the case.. e.g.

from vedo import *
Sphere().vertices.dtype
dtype('float32')

from vedo.

JeffreyWardman avatar JeffreyWardman commented on August 24, 2024

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.

marcomusy avatar marcomusy commented on August 24, 2024

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.

JeffreyWardman avatar JeffreyWardman commented on August 24, 2024

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:

from vedo.

marcomusy avatar marcomusy commented on August 24, 2024

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.

JeffreyWardman avatar JeffreyWardman commented on August 24, 2024

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.

JeffreyWardman avatar JeffreyWardman commented on August 24, 2024

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.

sean-d-zydex avatar sean-d-zydex commented on August 24, 2024

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.

marcomusy avatar marcomusy commented on August 24, 2024

Thanks for spotting the bug, This should now be fixed in master.

from vedo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.