Order of connecting points in paraview under table to structured grids - paraview

I'm a beginner in Paraview. I have a question about displaying CSV file in Paraview. If my data file looked like this
x coord, y coord, z coord, scalar
0, 0, 0, 1
1, 0, 0, 2
0, 1, 0, 3
1, 1, 0, 4
0, 0, 1, 5
1, 0, 1, 6
0, 1, 1, 7
1, 1, 1, 8
It will create a cubic grid. But if I switch the order of points like
x coord, y coord, z coord, scalar
0, 0, 0, 1
1, 0, 0, 2
1, 0, 1, 6
0, 1, 0, 3
1, 1, 1, 8
1, 1, 0, 4
0, 0, 1, 5
0, 1, 1, 7
It will give me a really messy connected wireframe. I want to know what's the order of connection? How does Paraview form those grids?

In ParaView (and indeed in the underlying VTK library it uses), structured grid points are ordered such that the index of the x dimension varies fastest, the index of the y dimension varies second-fastest, and the index of the z dimension varies slowest. Hence, your first example gives the expected result while the second example does not.

Related

Visualization failed when display two polygon in the same time

I want to display two polygons in one renderer. And the result is:
The green and red color indicates two polygons.
However, when I rotate it, some part of green color disappear:
My environment is:
win 10
python 3.7.13
vtk: 9.2.4
I can 100% reproduce this phenomenon, and the code to reproduce my problem is:
import vtkmodules.all as vtk
def buildPolygon(points):
polydata = vtk.vtkPolyData()
vps = vtk.vtkPoints()
polygon = vtk.vtkPolygon()
polygon.GetPointIds().SetNumberOfIds(len(points))
for i in range(len(points)):
vps.InsertNextPoint(points[i][0], points[i][1], points[i][2])
polygon.GetPointIds().SetId(i, i)
polygons = vtk.vtkCellArray()
polygons.InsertNextCell(polygon)
polydata.SetPoints(vps)
polydata.SetPolys(polygons)
return polydata
polydata1 = buildPolygon([
[0, 0, 0],
[10, 0, 0],
[10, 10, 0],
[0, 10, 0]
])
map1 = vtk.vtkPolyDataMapper()
map1.SetInputData(polydata1)
actor1 = vtk.vtkActor()
actor1.SetMapper(map1)
actor1.GetProperty().SetColor(1, 0, 0)
polydata2 = buildPolygon([
[0, 0, 0],
[5, 0, 0],
[5, 5, 0],
[0, 5, 0]
])
map2 = vtk.vtkPolyDataMapper()
map2.SetInputData(polydata2)
actor2 = vtk.vtkActor()
actor2.SetMapper(map2)
actor2.GetProperty().SetColor(0, 1, 0)
render = vtk.vtkRenderer()
render.AddActor(actor1)
render.AddActor(actor2)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(render)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
iren.Initialize()
iren.Start()
As they lie exactly on the same plane z=0 there is no way to know which should be drawn on top of the other. Just add a small tolerance:
polydata2 = buildPolygon([
[0, 0, 0.001],
[5, 0, 0.001],
[5, 5, 0.001],
[0, 5, 0.001]
])

How do I fill Matrix4 with translation, skew and scale values in flutter?

Suppose, I have these values for a container of height 200 and width 300:
scaleX = 0.9198
scaleY = 0.9198
skewX = -0.3923
skewY = 0.3923
translateX = 150
translateY = 150
Now, how do I fill this values in Matrix4 correctly?
I tried doing this:
Matrix4(
0.9198, 0, 0, 0, //
0, 0.9198, 0, 0, //
0, 0, 1, 0, //
150, 150, 0, 1,
)
which is,
Matrix4(
scaleX, 0, 0, 0, //
0, scaleY, 0, 0, //
0, 0, 1, 0, //
translateX, translateY, 0, 1,
)
But I am not sure where to put skewX and skewY values in this matrix. Please help me with this.
Skew Values
This is a bit of a nuanced topic, as it could be interpreted in a couple of different ways. There are specific cells of a matrix that are associated with specific names, as identified in your question, translate x, translate y, scale x, and scale y. In this context, you most likely mean the values from a matrix that are called skew x and skew y (also sometimes known as shear x and shear y), which refers to indices 4 and 1 (zero-based, column-major order). They're called these names because when put into an identity matrix by themselves, they do that operation (translate, scale, or skew), but it gets more complicated when there are multiple values.
On the other hand, this could also be interpreted as a series of operations (e.g. scale by (0.9198, 0.9198, 1), then skew by (-0.3923, 0.3923), then translate by (150, 150, 0)), and then it's a series of matrix multiplications that would ultimately result in a similar-looking, but numerically different matrix. I'll assume you don't mean this for this question. You can read more about it here though.
You can consult the Flutter Matrix4 documentation, which also provides implementation notes for Matrix4.skewX and Matrix4.skewY. The skews are stored in (zero-based) indices 4, and 1, as the tangent of the skewed angle.
Matrix4(
scaleX, skewY, 0, 0, // skewY could also be tan(ySkewAngle)
skewX, scaleY, 0, 0, // skewX could also be tan(xSkewAngle)
0, 0, 1, 0, //
translateX, translateY, 0, 1,
)
Note to those that aren't familiar with Flutter's data structures that values are stored in column-major order which means that each row in the above code is actually a column, so if you were to represent the matrix as a normal transformation matrix, it's transposed.
More information:
Transformation Matrices: https://en.wikipedia.org/wiki/Transformation_matrix
How matrices are used with CSS Transforms: How do I use the matrix transform and other transform CSS properties?

How to minimise computation time for a matrix diagonalisation plotting script in matlab?

I am fairly new to matlab and was hoping for some assistance regarding the speeding up of computation and plotting of eigenvalues. I have a 'pentadiagonal' 40x40 matrix, with symbolic k entries.
I wish to compute all of the eigenvalues and plot these as a function of k. So I call eig(H), then I set up a loop which replaces the symbolic k entries with a numerical value. I then simply plot this array, which I have called 'list'.
This routine takes a long time to evaluate, and I do need all of the eigenvalues rather than just the n largest. Does anybody have any advice as to how I can speed up this calculation?
Things I have tried:
1) Preallocating my array. This didn't appear to speed it up much. I believe at this stage, the code still holds the eigenvalues as Root[#1^2+cos(1.0*3)...] objects, and the list is relatively small.
2) Rescaling the arguments of the trig functions cos((sqrt(3)/2)*k) -> cos(k). This also doesn't appear to speed it up a huge amount.
I would be very grateful for any further advice.
a=0.5;
b=0.5;
dq=0.01;
d=0.5;
syms k
H= [(-2)*a - b*d*sin(sqrt(3)*k), 2*a*cos((sqrt(3)/2)*k), b*d*sin((sqrt(3)/2)*k), 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; 2*a*cos((sqrt(3)/2)*k), -1, ...]
list = [];
for s=0:dq:3
list=[list,subs(energies,k,s)];
end
q=0:dq:3;
plot(q,transpose(list),'red')

Program for specific sequence of Integers

I am solving steady state heat equation with the boundary condition varying like this 10,0,0,10,0,0,10,0,0,10,0,0,10.... and so on depending upon number of points i select.
I want to construct a matrix for these boundary conditions but unable to specify the logic for the sequence in terms of ith element for a matrix.
i am using mathematica for this however i need the formula only like for odd we can specify 2n+1 and for even 2n , something like this for the sequence 10,0,0,10,0,0,10,0,0,10,....
In MATLAB, it would be
M = zeros(1000, 1);
M(1:3:1000) = 10;
to make a 1000 long vector with such structure. 1:3:1000 is 1,4,7,....
Since you specifically want a mathematical formula let me suggest a method:
seq = PadRight[{}, 30, {10, 0, 0}];
func = FindSequenceFunction[seq]
10/3 (1 + Cos[2/3 \[Pi] (-1 + #1)] + Cos[4/3 \[Pi] (-1 + #1)]) &
Test it:
Array[func, 10]
{10, 0, 0, 10, 0, 0, 10, 0, 0, 10}
There are surely simpler programs to generate this sequence, such as:
Array[10 Boole[1 == Mod[#, 3]] &, 10]
{10, 0, 0, 10, 0, 0, 10, 0, 0, 10}
A way to do this in Mathematica:
Take[Flatten[ConstantArray[{10, 0, 0}, Ceiling[1000/3] ], 1],1000]
Another way
Table[Boole[Mod[i,3]==1]*10, {i,1,1000}]

Correct format for loading vertex arrays from file

I've been banging my head on my keyboard for the past couple of weeks over this. What I'm trying to do is load an array of floats (GLfloat) and an array of unsigned shorts (GLushort) from a text file into equivalent arrays in objective-c so that I can render the contained objects. I've got my arrays loaded into vector objects as
vector<float> vertices;
and
vector<GLushort> indices;
But for some reason I can't figure out why I can't get these to render. Here is my code for rendering the above:
glVertexPointer(3, GL_FLOAT, sizeof(vertices[0])*6, &vertices[0]);
glNormalPoitner(GL_FLOAT, sizeof(vertices[0])*6, &vertices[3]);
glDrawElements(GL_TRIANGLES, sizeof(indices)/sizeof(indices[0]), GL_UNSIGNED_SHORT, indices);
Sample arrays are below:
vertices: (Vx, Vy, Vz, Nx, Ny, Nz)
{10, 10, 0, 0, 0, 1,
-10, 10, 0, 0, 0, 1,
-10, -10, 0, 0, 0, 1,
10, -10, 0, 0, 0, 1};
indices: (v1, v2, v3)
{0, 1, 2,
0, 2, 3};
The text file I want to load these arrays from for rendering looks like this:
4 //Number of Vertices
###Vertices###
v 10 10 0 0 0 1
v -10 10 0 0 0 1
v -10 -10 0 0 0 1
v 10 -10 0 0 0 1
###Object1###
2 //Number of faces
f 0 1 2
f 3 4 5
Are vector objects the best approach to take? If not, what is? And what am I doing wrong that these won't render? Thanks.
You use GL_TRIANGLES to specify the vertices format.
See the graph about GL_TRIANGLES, your format is wrong.
And, I prefer to use GL_TRIANGLE_STRIP format. It needs few vertices.