Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualizing Descriptors #83

Closed
roaasoloh opened this issue Dec 16, 2019 · 10 comments
Closed

Visualizing Descriptors #83

roaasoloh opened this issue Dec 16, 2019 · 10 comments

Comments

@roaasoloh
Copy link

roaasoloh commented Dec 16, 2019

Hi,

Thanks for this wonderful library!

my problem is as the following, I want to visualize 3D descriptors on the mesh, what I tend to do is like this:

    point_mesh = trimesh.PointCloud(vertices[interest_points])
    vtkmesh = trimesh2vtk(mesh)
    vtk_fourier = vtk.util.numpy_support.numpy_to_vtk(fourier_n)
    vtkmesh.pointColors(vtk_fourier, cmap='jet')
    show(vtkmesh,point_mesh,bg='w', axes=1)

my interest points are 3D coordinates they are the interest points on my mesh, and then I applied extracting descriptors on these points, so the output of fourier_n is summarized by this: [3655.+0.00000000e+00j -43.+1.17658631e+03j -43.+5.87507409e+02j -43.+3.90797931e+02j -43.+2.92180107e+02j -43.+2.32798157e+02j -43.+1.93033293e+02j -43.+1.64477297e+02j -43.+1.42925909e+02j -43.+1.26043295e+02j -43.+1.12427827e+02j -43.+1.01187441e+02j -43.+9.17273171e+01j -43.+8.36355483e+01j -43.+7.66178118e+01j -43.+7.04581695e+01j -43.+6.49945684e+01j -43.+6.01029870e+01j -43.+5.56868665e+01j -43.+5.16698780e+01j -43.+4.79908603e+01j -43.+4.46002021e+01j -43.+4.14572113e+01j -43.+3.85281695e+01j -43.+3.57848725e+01j -43.+3.32035203e+01j -43.+3.07638620e+01j -43.+2.84485311e+01j -43.+2.62425211e+01j -43.+2.41327696e+01j

it's the output of fourier_n = np.fft.fftn(interest_points)

but the problem I faced is this error:
"Complex numpy arrays cannot be converted to vtk arrays."\ AssertionError: Complex numpy arrays cannot be converted to vtk arrays.Use real() or imag() to get a component of the array before passing it to vtk.

Any assist is appreciated please!

@marcomusy
Copy link
Owner

Indeed numpy_to_vtk does not support complex numbers.

But I´m not sure I understand what are you aiming for.. in any case the pointColors() methods can a take a real numpy array as input, so no need of conversion.
So it all depends on what you really wish to visualize.

@roaasoloh
Copy link
Author

Dear Sir,
I'm late to get updated with this, Sorry.
The case is as follows:
I have feature points(interest points, keypoints) whatever you may call them. It's a way to simplify work on a mesh instead of using all vertices.
So for these points that belong to mesh I have scalars(you can say, but the correct is descriptions) descriptors. And I want to visualize them on this mesh
What I tried is like this:
vtkmeshe = trimesh2vtk(mesh.mesh) vtkmeshe.pointColors(mean_curvature,cmap='jet') show(vtkmeshe, bg='w', axes=0)
but it outputs
pointColors Error: nr. of scalars != nr. of points 86 867
As well the output images are:
interest
mean

The first image shows the interest points, and the second shows the mean curvature, although the curvature has the same length as for the number of interest points.
Shouldn't it colorize differently on the values of interest points!
one more thing, how I may visualize more than one mesh on the same window, each with different parameters.
Thank you for your assistance.

@marcomusy
Copy link
Owner

Hi
You are getting that error nr. of scalars != nr. of points because the scalar must be defined for all the mesh points. So you need to interpolate it before assigning it to the mesh.

import numpy as np
from scipy.interpolate import Rbf, NearestNDInterpolator as Near
from vtkplotter import *

mesh = load(datadir+"bunny.obj").normalize()
pts = mesh.points()

# make a test subset of points where descriptor is known
ptsubset = pts[:100]

# assume the descriptor value is some func of the point coord y
x, y, z = ptsubset[:,0], ptsubset[:,1], ptsubset[:,2]
desc = 3*sin(4*y)

# build the interpolator to determine the descriptor value
#  for the rest of mesh vertices:
itr = Rbf(x, y, z, desc)          # Radial Basis Function interpolator
#itr = Near(ptsubset, desc)       # Nearest-neighbour interpolator

# interpolate desciptor values on the set of mesh vertices
xi, yi, zi = pts[:,0], pts[:,1], pts[:,2]
interpolated_desc = itr(xi, yi, zi)

rpts = Points(ptsubset, r=10, c='white')
mesh.pointColors(interpolated_desc, cmap='rainbow').addScalarBar()

show(rpts, mesh, axes=1, bg="w")

image

one more thing, how I may visualize more than one mesh on the same window, each with different parameters.

just create any other Mesh object and add it to the show() command.

@roaasoloh
Copy link
Author

roaasoloh commented Jan 23, 2020

Hello Again :)
Thank you for this,
Still one thing please,

Regarding plotting several meshes!! it didn't work with me, especially that each mesh has it's own title and let's say values, like what follows:

mesh1 = vtkmeshe.pointColors(interpolated_desc_nearmean, cmap='hsv').addScalarBar()
show(rpts,mesh1,title= "Mean Curvature Descriptor", axis = 0)
mesh2 = vtkmeshe.pointColors(interpolated_desc_neargauss, cmap='hsv').addScalarBar()
show(rpts,mesh1,mesh2,title= "Shape Index Descriptor", axis = 0)

I have the same scalar bar since all meshes are normalized to the same range, but different titles as well as different parameters.

The second mesh appears when I close the first window of the first mesh, I have more than two mesh even but I guess rule will validate for many meshes.

@marcomusy
Copy link
Owner

You can plot things in many different ways and combinations... and create copies with mesh.clone() if needed.
Also the keyword option is axes not axis to choose the axes style.
E.g.

mesh1 = vtkmeshe.pointColors(interpolated_desc_nearmean, cmap='hsv').addScalarBar()
# ...
show(rpts,mesh1, at=0, N=2, title= "Mean Curvature Descriptor", axes=0)
show(rpts,mesh2, at=1, interactive=1)

or use newPlotter=True to create a new Plotter window.

@roaasoloh
Copy link
Author

roaasoloh commented Jan 23, 2020

I tried the attached code, but still more thing please, N for how mesh I want correct? I made it like this:

show(rpts,mesh1, at=0, N=3, title= "Mean Curvature Descriptor", axes=0)
show(rpts,mesh2, at=1, interactive=1, title="Shape Index Descriptor", axes=0)
show(rpts,mesh3, at=2, interactive=1, title="Curvature Index Descriptor", axes=0)

even if I put only one time axes for example, the same.
I thought that the title will set a title under each mesh? or there is another parameter for that, where I may check for this!
It shows two windows one after closing the first like this:
mulit-1

multi-2
What I'm doing wrong, please?

@marcomusy
Copy link
Owner

N is the number of subwindows (can also be specified as e.g. shape=(1,3))
You can only have one title per window.
You can still add text comments in each separate window with Text():

show(rpts,mesh1, Text('some comment'), at=0, N=3, title= "window title", axes=0)
show(rpts,mesh2, Text('some other\ncomment'), at=1, interactive=True)

You can find plenty of examples here to explore the possibilities.

@roaasoloh
Copy link
Author

Hello again :)
Please previously I was using trimesh library for loading meshes and performing other things...
but I found your library is well enough to use, instead of loading several libraries, but the issue now
is that when I tried to do this example through-loading mesh using vtkplotter getting the attached photo :(
ant

interest points are not visualized well, may you guess why?
this is my code:

mesh = load("/home/roaa/Desktop/PhD/Models/ant.ply").normalize()
pts = np.array(mesh.points())
faces = np.array(mesh.faces())
neighbors = nb.k_ring_delaunay_adaptive(pts,0.25)
detector_fraction,ptsubset = detector.method_one_fraction(detector.get_candidate(pts,neighbors))
#print(ptsubset)
#print(pts[ptsubset])

in another file importing the previously things:

x, y, z = mm.pts[ptsubset,0], mm.pts[ptsubset,1], mm.pts[ptsubset,2]
xi, yi, zi = pts[:,0], pts[:,1], pts[:,2]
rpts = Points(mm.pts[ptsubset], r=5, c='white')
itr_near = Near(mm.pts[ptsubset], mm.OurDescriptor)
interpolated_desc_near = itr_near(xi,yi,zi)
ourMesh= mm.mesh.pointColors(interpolated_desc_near, cmap='viridis').addScalarBar()
show(rpts,ourMesh)

As well if I use .obj file I get an error in another place in my coding since I'm using code that uses ply files... I don't know why this effect, but trying to figure out why!
if you already faced something like this! getting:

IndexError: index 2502 is out of bounds for axis 0 with size 867

@roaasoloh
Copy link
Author

I was able to solve the last situation for obj files, but the visualizing is the same... getting objects, in the same way, I showed you, not sure what I'm missing!!

@marcomusy
Copy link
Owner

I cannot reproduce your output image...
A small test gives me the expected result:

from vtkplotter import *

mesh = load(datadir+"spider.ply").normalize()
pts = mesh.points()
ptsubset = [i for i in range(0, mesh.N(), 10)]
rpts = Points(pts[ptsubset], r=5, c='white')

show(mesh, rpts)

image

it looks like your are rotating your points... but it seems unrelated to vtkplotter..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants