ParaViewWeb Visualizer

python

(Barak) #1

Hello,
I Created project with visualizer to show vtk file.
I want show also some points on the screen, I want the round and focus of vtk will be effect also the points.
What the best way to do it?
Thanks,
O.Barak


(Sebastien Jourdain) #2

Is your Visualizer working?

What kind of points, round and focus are you talking about?


(Barak) #3

Yes, my visualizer working.
The points will be shown on the drawing, but the point data is x,y,z format and the drawing data is vtk file.
Thanks


(Sebastien Jourdain) #4

Create a vtkPolyData from those x,y,z and use the trivial producer to bring it into the ParaView pipeline.


(Barak) #5

How to to bring it into the ParaView pipeline?


(Sebastien Jourdain) #6
from vtkmodules.vtkCommonDataModel import vtkPolyData, vtkCellArray
from vtkmodules.vtkCommonCore import vtkPoints, vtkFloatArray

from paraview import simple

polyData = vtkPolyData()
polyData.SetPoints(vtkPoints())

polyData.SetLines(vtkCellArray())

points = polyData.GetPoints()
lines = polyData.GetLines()

points.InsertNextPoint(0, 1, 0) # id: 0
points.InsertNextPoint(0, 2, 0) # id: 1
points.InsertNextPoint(0, 3, 0) # id: 2
points.InsertNextPoint(0, 4, 0) # id: 3
points.InsertNextPoint(0, 5, 0) # id: 4

lines.InsertNextCell(points.GetNumberOfPoints())
lines.InsertCellPoint(0)
lines.InsertCellPoint(1)
lines.InsertCellPoint(2)
lines.InsertCellPoint(3)
lines.InsertCellPoint(4)


trivialProducer = simple.TrivialProducer()
trivialProducer.GetClientSideObject().SetOutput(polyData)

simple.Show(trivialProducer)
simple.Render()

(Igor) #7

Hello,

Thank you very much for this example. It’s very usefull.
Do you may to provide similar example, but with spheres. (With radius 1)
Thank you very much and best regards, Igor.


(Sebastien Jourdain) #8
from paraview import simple

sphere = simple.Sphere()
sphere.Radius = 1

simple.Show()
simple.Render()

(Igor) #9

Thank you very much!


(Igor) #10

Hello Sebastien,

Thank you very much about your previous answer.
I’m newest in ParaView/Web applications.
Provided examples demonstrate how to create models in python.
But not understandable how(or where) I load to Visualizer this code.
In my task I need:

  1. Load vtk file
  2. Load txt file with spheres position information
  3. Add spheres (by code) to loaded vtk model
  4. Display to user result scene

Is possible to provide more detailed information (step by step) for this task?
Positions of new files. How to attach and call these files to html page?
Thank you Very much.


(Sebastien Jourdain) #11

I’m not sure it is a Visualizer question. It seems that you are trying to build a custom application based on the ParaViewWeb framework. ParaView Visualizer, ParaView Lite, ParaView Divvy are good examples on how to use such framework to do different things.

For custom development or guidance, Kitware offer support contract which allow us to take the time to explain or develop custom code for you.


(Ravid) #12

Hi @jourdain,
I success to show a sphere with your code,
But when I add it, the sphere fills the whole screen.
How can I fire ResetCamera() function from my .py file?

Thanks in advance.


(Sebastien Jourdain) #13
simple.ResetCamera()

(Ravid) #14

It does not work.

And also -
How can I define a color to each sphere?
I think it called DiffuseColor.

Thanks in advance.


(Sebastien Jourdain) #15

It does work for everyone else. So maybe it is something that you are telling us?

To have unique color per sphere, assuming you have one representation per sphere you can set the representation.DiffuseColor = [0.5, 1, 0.2] on their representations.


(Ravid) #16

This is my code:

for item in array:
sphere = simple.Sphere()
sphere.Radius = 1
sphere.Center = [float(item[0]), float(item[1]), float(item[2])]

How can I add one representation per sphere?


(Sebastien Jourdain) #17

This is a bad idea and you should use Glyph filter or better the Glyph mapper.

But since you ask, here is an answer.

spheres = []
reps = []
for item in array:
  sphere = simple.Sphere(Radius=1, Center=[float(item[0]), float(item[1]), float(item[2])])
  rep = simple.Show(sphere)
  spheres.append(sphere)
  reps.append(rep)

simple.Render()

(Cory Quammen (Kitware)) #18

Seconded. You will be outraged at how slow this will be. Objects in ParaView are heavy weight, and creating more than a couple dozen will result in unhappy results.


(Ravid) #19

Now it works, thanks!
I have another question - it seems that some of the points are displayed below the vtk object.
Can I give the sphere a ‘Z-Index’ property?


(Sebastien Jourdain) #20

I don’t understand what you mean.