[vtkusers] PCA visualizer app
Rahul Chander
rahulch at interchange.ubc.ca
Sun Jul 18 18:01:57 EDT 2004
Hi,
I am currently building a PCA visualizer application using VTK. This
application has inputs the eigenvectors of a PCA analysis. With the
help of slider(s) in the GUI, a user can manipulate the coeff. for
the basis vectors and the resulting superposition of all components
is visualized on the screen.
Now the issue:
Currently, I let the user input the coeff thru a slider in the GUI
and then I do this calculation:
[x,y,z]=[coeff1*eig1+coeff2*eig2+coeff3*eig3 .....and so on]
Then, I add the [x,y,z] from above into a vtkPointSource variable
using the InsertNextPoint() method.
I have to repeat this everytime a coeff value changes, so the points
are re-entered and then rendered using the surface generation for a
datacloud. The result is slow. It takes too long for the slider
interaction.
I think the situation can be improved by using pipeline mechanism and
using the methods VTK provides to do this calculation.
[x,y,z]=[coeff1*eig1+coeff2*eig2+coeff3*eig3 .....and so on]
The problem is, I do not know which method in VTK supports a vector
addition so that I dont have to reinitialize using the PointSource
mechanism. Most methods are supported for only 3 dim unlike ITK
which is supported for N-Dim. Even though each basis vector has
only 3 components, the #basis components more than 3.
I was wondering if a Transform method could be used for the matrix
multiplication part, but again the issue of N-Dims . The number of
points remain the same, only their position gets recalculated.
Here is some portion of the Python code:
eig_x is the x component of all the eigenvectors
eig_y is the y component of all .....
eig_z is the z ....
pointSource is the set of points which gets rendered. type is
vtkPolyData. It is essentially a datacloud and a surface is
generated.
Dot() is a function I wrote that takes the dot-product of two vectors
over N-dim
def readPoints():
global coeff_t,eig_x,eig_y,eig_z,pointSource
output = pointSource.GetPolyDataOutput()
points = vtk.vtkPoints()
output.SetPoints(points)
for i in range(0, LENGTH):
x = Dot(coeff_t[0],eig_x[i])
y = Dot(coeff_t[1],eig_y[i])
z = Dot(coeff_t[2],eig_z[i])
points.InsertNextPoint(x,y,z)
Does anyone have any suggestions to improve the above function?
Thanks
Rahul
--
Rahul Chander, BASc (Electrical Eng.)
War is much too serious a matter to be entrusted to the military.
-- Clemenceau
More information about the vtkusers
mailing list