How to visualize superquadric

richti83's picture
Submitted by richti83 on Fri, 12/01/2017 - 12:48

First thanks to all developers for the great new 3.8.0 release.
One simple question: how can one visualize the superquadrics from the given tutorial in examples folder ?
Thanks a lot,
Christian.

medvedeg | Fri, 12/01/2017 - 20:10

Hallo Christian,
superquadric plugin for ParaView will become soon available for public

Alexander Podlozhnyuk

richti83's picture

richti83 | Fri, 12/08/2017 - 20:41

In the meantime I managed to get some cool results using dump custom and my rigid reader in combination with a python programmable filter to map any geometry over the centre points dumped:

from math import sqrt
input1 = self.GetInputDataObject(0, 0)
input2 = self.GetInputDataObject(0, 1)
output = self.GetOutputDataObject(0)
newPoints = vtk.vtkPoints()
newcells = vtk.vtkCellArray()
#
P=input1.GetPointData()
B=input2.GetPointData()
BODIES=input1.GetNumberOfPoints()
EDGES=input2.GetNumberOfPoints()
SURFACES=input2.GetNumberOfCells()
#
outputarrayID = vtk.vtkDoubleArray()
outputarrayID.SetName("ID")
outputarrayID.SetNumberOfTuples(BODIES*SURFACES)
#
outputarrayT = vtk.vtkDoubleArray()
outputarrayT.SetName("type")
outputarrayT.SetNumberOfTuples(BODIES*SURFACES)
#
outputarraySC = vtk.vtkDoubleArray()
outputarraySC.SetName("value")
outputarraySC.SetNumberOfTuples(BODIES*SURFACES)
#
outputarrayF = vtk.vtkDoubleArray()
outputarrayF.SetName("F")
outputarrayF.SetNumberOfTuples(BODIES*SURFACES)
#
outputarray_v = vtk.vtkDoubleArray()
outputarray_v.SetName("v")
outputarray_v.SetNumberOfTuples(BODIES*SURFACES)
k=0
c=0
for body in range(0,BODIES):
r=input1.GetPoint(body)
M=P.GetAbstractArray('M')
T11=M.GetComponent(body,0)
T12=M.GetComponent(body,1)
T13=M.GetComponent(body,2)
T21=M.GetComponent(body,3)
T22=M.GetComponent(body,4)
T23=M.GetComponent(body,5)
T31=M.GetComponent(body,6)
T32=M.GetComponent(body,7)
T33=M.GetComponent(body,8)
type=P.GetArray('type').GetValue(body)-1
CLUMP_ID=P.GetArray("c_id").GetValue(body);
CLUMP_SC=P.GetArray("value").GetValue(body);
CLUMP_FORCEx=P.GetAbstractArray("F").GetComponent(body,0)
CLUMP_FORCEy=P.GetAbstractArray("F").GetComponent(body,1)
CLUMP_FORCEz=P.GetAbstractArray("F").GetComponent(body,2)
CLUMP_FORCE=sqrt(CLUMP_FORCEx*CLUMP_FORCEx+CLUMP_FORCEy*CLUMP_FORCEy+CLUMP_FORCEz*CLUMP_FORCEz)
CLUMP_VELx=P.GetAbstractArray("v").GetComponent(body,0)
CLUMP_VELy=P.GetAbstractArray("v").GetComponent(body,1)
CLUMP_VELz=P.GetAbstractArray("v").GetComponent(body,2)
CLUMP_VEL=sqrt(CLUMP_VELx*CLUMP_VELx+CLUMP_VELy*CLUMP_VELy+CLUMP_VELz*CLUMP_VELz)
for surface in range(0,SURFACES):
outputarrayID.SetValue(k,CLUMP_ID)
outputarrayT.SetValue(k,type)
outputarrayF.SetValue(k,CLUMP_FORCE)
outputarraySC.SetValue(k,CLUMP_SC)
outputarray_v.SetValue(k,CLUMP_VEL)
k+=1
cell = input2.GetCell(surface)
COUNT=cell.GetNumberOfPoints()
for j in range(0,COUNT): #alle punkte der jeweiligen zelle
id=cell.GetPointId(j)
#print id
coord = input2.GetPoint(id)
x, y, z = coord[:3]
#print x,y,z
#print r
xnew=T11*x+T12*y+T13*z+r[0]
ynew=T21*x+T22*y+T23*z+r[1]
znew=T31*x+T32*y+T33*z+r[2]
newPoints.InsertPoint(c, xnew, ynew, znew)
c+=1
newcells.InsertNextCell(4)
newcells.InsertCellPoint(c-1)
newcells.InsertCellPoint(c-2)
newcells.InsertCellPoint(c-3)
newcells.InsertCellPoint(c-4)
output.SetPoints(newPoints)
output.SetCells(5,newcells)
output.GetCellData().AddArray(outputarrayID)
output.GetCellData().AddArray(outputarrayT)
output.GetCellData().AddArray(outputarrayF)
output.GetCellData().AddArray(outputarraySC)
output.GetCellData().AddArray(outputarray_v)

Apped this to the dump AND a source of type box (or any other PV primitive with cell type quad)

I'm not an associate of DCS GmbH and not a core developer of LIGGGHTS®
ResearchGate | Contact

skyopener's picture

skyopener | Sat, 01/20/2018 - 09:20

Dear Christian,

Extremely thanks for your kind information regarding your code for visualization. I have tried my best to understand your code.
It is a little puzzling for me about the code adopted to generate the points, i.e. >>>
xnew=T11*x+T12*y+T13*z+r[0]
ynew=T21*x+T22*y+T23*z+r[1]
znew=T31*x+T32*y+T33*z+r[2]
newPoints.InsertPoint(c, xnew, ynew, znew)
>>>>
I can understand that Tij are the transformation tensor and r is the position of the current superquadric particle.
It is interesting that the surface points can be evaluated based on the code you provided. This inspires me to think about the following question.
Given a specific cylindrical particle (i.e., a specific transformation tensor T), it is easy to obtain the Euler angle from the tensor or quaternion. how can I get the exact angles between the major axis of the cylinder particle with the global coordinate system x-y-z?

Your attention and kind information regarding this is highly appreciated!
Regards,
Kai

skyopener's picture

skyopener | Sat, 01/20/2018 - 09:30

More simple description is: is it possible to get the unit vector of the major axis of a cylinder particle along the length direction in the global coordinate system x-y-z, from the transformation tensor T or quaternion?

Thanks.

richti83's picture

richti83 | Mon, 01/22/2018 - 15:33

I calculate the T matrix as well as roll/pitch/yaw angles directly in the "rigid reader" [1] based on the Quaternions. Of course, you can get every transformation information from the quaternion in field Q1..Q4.

[2] is a good starting point.

Best,
Christian.

[1] https://github.com/richti83/ParaView_Reader_for_LIGGGHTS/blob/master/rea... Line 260ff
[2] http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/

I'm not an associate of DCS GmbH and not a core developer of LIGGGHTS®
ResearchGate | Contact

skyopener's picture

skyopener | Fri, 02/02/2018 - 13:20

Dear Christian,

Extremely appreciate for all your kind information and response regarding this. I have learned a lot from the paraview plugin you kindly released. Meanwhile, the web page you suggested provides full information about the transformation and also the relation between all the materials involved.

Thanks again and best wishes,
K

mschramm | Fri, 02/09/2018 - 22:09

Hello,
Checking if any new information is available?

Christian,
Could you be more specific on where we need to stick the python script?
I have paraview running with your reader but I can only get the python script to work as a macro.
I then set the particles as a 3D Glyph and set the glyph type as a box.

Any help is appreciated.

richti83's picture

richti83 | Mon, 02/12/2018 - 13:51

Hi,
the python code is not meant as a macro. Its a python-programmable filter.
You'll need the dump (rigid style) and a Source-> Superquadric. Than attach the programmable filter to both entries in the pipeline browser.
See this screenshot: https://www.cfdem.com/system/files/settings4pv_sq.png
You can Download the filter as custom xml here: https://www.cfdem.com/system/files/304_transform_sq_with_colors.xml_.txt save this file as xml and use PV Tools->Manage Custom Filter [import].

Good luck :-)

One Note: roundness=2/blockiness and y/z scale is interchanged in Paraview 5.0.0 (seems correct in 5.4.1)

[1] https://www.cfdem.com/forums/tutorial-4-superquadric-angle-repose-repres...

I'm not an associate of DCS GmbH and not a core developer of LIGGGHTS®
ResearchGate | Contact

Schuette | Wed, 03/28/2018 - 16:08

Hey all,
I'm new to Linux ,Liggghts and Paraview but I'm trying to get into superquadric particles. I tried Christians tutorial [1] and I have some problems with the visualisation. I included everything (as far as I know) but if I want to use the custom transform filter I get the following error:

Traceback (most recent call last):
File "<string>", line 24, in <module>
File "<string>", line 38, in RequestData
AttributeError: 'NoneType' object has no attribute 'GetValue'

I hope someone has an idea and can help me.
If you need any further details I try to provide them.

Greetings,
Thomas

[1] https://www.cfdem.com/forums/tutorial-4-superquadric-angle-repose-repres...

richti83's picture

richti83 | Thu, 03/29/2018 - 15:02

Hi Thomas,
could you test if it works when you change

CLUMP_ID=P.GetArray("id").GetValue(body);

to

CLUMP_ID=P.GetArray("c_id").GetValue(body);

I changed the array name in the reader some times ago and forgot to change it in the python programable filter before upload.
Thanks,
Christian.

I'm not an associate of DCS GmbH and not a core developer of LIGGGHTS®
ResearchGate | Contact

jsams | Wed, 04/11/2018 - 07:48

I'm having the exact same issue with the custom filter as Thomas. I get the same error message for the same lines in the script, even though the array name is already set to "c_id". Changing it back to just "id" doesn't do the trick either.

I'm using PV 5.4.1 on Windows with the precompiled rigids reader plugin. Any suggestions as to what might be the culprit?

richti83's picture

richti83 | Thu, 04/12/2018 - 07:44

I can reproduce this issue when the order of input signals is wrong.
To overcome this do the following:
right-click transform_filter->change-Input: Select ONLY rigid*.dump
[OK]
again right-click transform_filter->Change-Input:Select rigid AND Superquadric1 (holding ctrl+click on Superquadric).

This is a strange behaviour of PV which often happens after loading a state file, the input order of filters is not deterministic ...

Note: it's not a good idea to only change the DataObjects for input1 and input2 inside the python code as only the rigids files are time-aware and the first input of a filter controls the VCR.

Indeed in the windows reader the body id is still 'id' no change necessary.

I'm not an associate of DCS GmbH and not a core developer of LIGGGHTS®
ResearchGate | Contact

jsams | Thu, 04/12/2018 - 10:25

Thanks a lot. Your proposed workaround seems to do the trick.

rahul205gupta | Fri, 04/13/2018 - 00:22

Hi richti83.
After the first step I am getting the following error.
Traceback (most recent call last):
File "string", line 21, in module
File "string", line 13, in RequestData
AttributeError: 'vtkCommonDataModelPython.vtkMultiBlockDataSet' object has no attribute 'GetPointData'
Please provide some suggestions, besides I had few questions.
1. When I am opening the rigid file time steps shown is 0. I am using paraview 5.5 . I tried installing rigid reader from your pre compiled file, but it is showing error that cannot open shared file.
2. When I open Source -> Superquadric, It just creates a single particle ehich is different than the one created by rigid file.

jsams | Fri, 04/13/2018 - 04:34

1. Try using the correct Paraview version for the compiled plugin readers, I'm not sure if v5.5 is backward compatible with readers for v5.4.1. There's a reason why there are always new versions of the liggghts readers.
2. The behaviour you observe is totally normal, you will always get just one shape for any created source in Paraview. Only once you apply the superquadrics filter to your input from the rigid reader AND the Superquadric Source your particles will take on the desired shape.

richti83's picture

richti83 | Fri, 04/13/2018 - 07:37

The precompiled readers are linked against the corresponding paraview version, as kitware tags all libs with .PV.XYZ there is no chance to make one reader for all versions - I need to compile Paraview and the Reader for every new PV version which is quite time-consuming.
I guess you has loaded the rigid*.dump with the internal LAMMPS File reader of PV- this doesnt't work as the structure of our local dump is different from the expected input of the lammps reader (as both files uses the same file ending there is no error presented).

I would advice you to use PV 5.4.1 and try again :-).

Best,
Christian.

I'm not an associate of DCS GmbH and not a core developer of LIGGGHTS®
ResearchGate | Contact

rahul205gupta | Fri, 04/13/2018 - 10:52

I was able to run visualize the given tutorial properly. I just wanted to know can I use this same code for other systems with different shapes ( cylinder, ellipse, etc). If yes, do I have to follow any specific restrictions?
If it is not possible, is there any other way or I would have to write a new script.
I want to run various systems, one with cylinders in a hopper, other with cubes, cuboids, ellipsoids.

richti83's picture

richti83 | Fri, 04/13/2018 - 14:18

Hi rahul

great to hear you get it working.
There is one difference between the source types: the VTK Type of the used cell elements. The SQ in PV is made by Triangle-Strips, while a box or a cylinder is made of quats and a sphere or stl file is made of triangles. For this reason you need to adapt the lines to

#for STL-File or sphere
newcells.InsertNextCell(3)
newcells.InsertCellPoint(c-1)
newcells.InsertCellPoint(c-2)
newcells.InsertCellPoint(c-3)
output.SetPoints(newPoints)
output.SetCells(5,newcells)

or

#for vtk quat (cylinder,box)
newcells.InsertNextCell(4)
newcells.InsertCellPoint(c-1)
newcells.InsertCellPoint(c-2)
newcells.InsertCellPoint(c-3)
newcells.InsertCellPoint(c-4)
output.SetPoints(newPoints)
output.SetCells(9,newcells)

This could be indeed more generalistic by my filter :-)

Best,
Christian.

I'm not an associate of DCS GmbH and not a core developer of LIGGGHTS®
ResearchGate | Contact

Dheeraj420 | Fri, 08/07/2020 - 12:05

Hi rahul,
I am facing a issue in visualization of SQ particles in PV.

Error:
AttributeError: 'NoneType' object has no attribute 'GetValue'
Traceback (most recent call last):
File "", line 22, in
File "", line 83, in RequestData
AttributeError: 'NoneType' object has no attribute 'GetValue'

Even i m looking to visualize cylindrical particles in screw feeder.

It will be great if you provide your assistance. you can share your Email id for future assistance.

Thanks

Schuette | Thu, 03/29/2018 - 15:37

Hi Christian,
that worked perfectly! Thanks a lot.

Now i have 2 additional questions. Maybe you can help me with that.
I saw that there is also the Tensor Glyph filter which can visualize superquadric particles. Is there a significant difference or is the Tensor Glyph filter just new?
And the second one is, if i change the blockiness of the superquadric particles, is there an easy way to get the change into the paraview cisualisation? (Haven't seen an option/parameter which manipulates this configuration)

Thank you very much again.
Greetings,
Thomas

richti83's picture

richti83 | Thu, 03/29/2018 - 17:26

I do not use tensor glyph as I have no clue how to do the orientation
about
And the second one is, if i change the blockiness of the superquadric particles, is there an easy way to get the change into the paraview cisualisation?
In the Superquadric source roundness is 2/blockiness in liggghts.
(disable torodial and do not change resolution)
For some reason the y,z size of SQ in PV seems interchanged with ey/ez in liggghts

I'm not an associate of DCS GmbH and not a core developer of LIGGGHTS®
ResearchGate | Contact

Schuette | Mon, 04/16/2018 - 16:20

Hey Christian,
I tried your reader with my own project, but for some reason it gets confused with the particle IDs. For example if I read my inserted atoms it only reads one ID of three.
The dump file contains the following:
ITEM: TIMESTEP
100
ITEM: NUMBER OF ATOMS
3
ITEM: BOX BOUNDS ff ff ff
-0.1 0.6
-0.1 0.6
-0.1 0.5
ITEM: ATOMS id type x y z quat1 quat2 quat3 quat4 vx vy vz fx fy fz blockiness1
2503 2 0.182604 0.0781297 0.276655 1 0 0 0 0 0 -0.75 0 0 0 10
2502 2 0.145887 0.22004 0.344799 1 0 0 0 0 0 -0.75 0 0 0 10
2501 2 0.241264 0.380313 0.358075 1 0 0 0 0 0 -0.75 0 0 0 10
And in Paraview it only contains he ID 2501 ind the c_id-array.

If I work with more particles, they "jump" sometimes in the visualization because IDs are missing or somehow get shuffled (at least it seems like that only examined it in detail with the small numbers).

Hopefully you or someone else has an idea why and how it can be fixed.

Thank you really much for your time.
Greetings,
Thomas

Schuette | Tue, 04/17/2018 - 11:06

Hi Christian,
It seems to work! The only problem I had was that I had to change the "c_ID" in the filter back to "ID".
Thank you very much again!

Greetings

Rachel | Sat, 05/19/2018 - 01:56

Hi all,

I have used the guide above but I finally get donut shape. I cannot figure out why. Could anyone give me a step by step guide about how to visualize the superquadric shape?

Many thanks.
Rachel

jsams | Tue, 05/22/2018 - 04:58

In PV you need to deselect the Toroidal option in the Superquadric Source.