Paraview bug when displaying vtkUniformGrid? - vtk

I am displaying a vtkUNiformGrid in Paraview, which contains (besides other things) 3-component flow vector in each point. When I display the dataset with volume rendering, it displays just fines. However, when I add Arrow glyph to the very same data, they do show the same data but elsewhere, smaller and in multiple copies (9 in number). Perhaps an images shows better what I mean:
I am a bit at loss as to where to look. Did I screw something up? Other ideas?

To help you debug, open a 2nd layout window and select Spreadsheet View, and look at the source on which you are applying the glyph filter. Is the vector data that you're trying to plot under PointData? Then check in the glyph filter properties that the Vectors drop down box indicates the array that you're trying to plot.

Just for the record, the cause was actually writing data into the vtkDoubleArray in a wrong way -- the array has 3 components and the indices were actually 1/3 of what they should have been, with x/y/z values interspersed (that gives the 3x3 pattern in the lower third, as I realized); I was assuming the components were stored contiguously, which is apparently not the case.
The old code was something like this:
auto flow=vtkSmartPointer<vtkDoubleArray>::New();
flow->SetNumberOfComponents(3);
auto grid=vtkSmartPointer<vtkUniformGrid>::New();
grid->SetDimensions(...);
grid->GetPointData()->AddArray(flow);
for(int i:{0,1,2}) flow->FillComponent(i,0);
for(ijk: ... /* traverses the grid, each point potentially more than once */ ){
vtkIdType dataId=grid->ComputePointId(ijk);
// XXX: this is what caused troubles:
double* f0=flow->GetPointer(dataId);
f[0]+=dx;
f[1]+=dy;
f[2]+=dz;
}
The correct version of the loop body is:
double f[3];
flow->GetTupleValue(dataId,f); // copy the data
f[0]+=dx;
f[1]+=dy;
f[2]+=dz;
flow->SetTupleValue(dataId,f);
Both scalar and vector datasets are now matching:

Related

How to get global world coordinates of bone in Godot GDscript

I'm writing a program in Godot with GDscript that aims to change the position of multiple bones in an armature. The bone gets translated by a value calculated by the point I want the bone to move to minus the current position of the bone. translateValue = endPoint - currentPoint However, all values must be in world coordinates or global position for the code to work. Godot has various methods to retrieve the bone Transform in order to access the position such as : skeleton.get_bone_pose() , skeleton.get_bone_global_pose , skeleton.get_bone_rest . I tried using skeleton.get_bone_global_pose but it didn't give the global position and seemed to still be relative to something. There's also the to_global() method, but i'm not entirely sure what it does. Could someone explain the differences between these methods and how to get global position? Thanks!
I'll start with these methods:
get_bone_rest
get_bone_custom_pose
get_bone_pose
First of all, get_bone_rest gives you the default transform of the bone, relative to its parent bone. Then the other transform are stacked, in the above order.
Then we have:
get_bone_global_pose
This method gives you the final transform of the bone. And it is relative to the Skeleton. That is, this transform already includes the previously mentioned transforms, combined from parent to child bone.
Thus, converting its result to world space is a matter of composing the transform of the Skeleton:
$Skeleton.global_transform * $Skeleton.get_bone_global_pose(bone_index)
And we have:
get_bone_global_pose_no_override
As the name suggest get_bone_global_pose_no_override ignores any global pose override. That's right, you you can override the global pose. To do that, use set_bone_global_pose_override. See also clear_bones_global_pose_override. These are all, of course, relative to the Skeleton.
The method Spatial.to_global(vector3) is unrelated to the Skeleton. It transforms a vector from the local space of the node on which you call it, to world space. Which might also be useful:
$Skeleton.to_global($Skeleton.get_bone_global_pose(bone_index).origin)

Separating real and imaginary components of rectangular coordinates - matlab

I have a rectangular Coordinate in Matlab that looks like the following:
0.0240 - 0.1680i
I'd like to split the double into it real and imaginary parts, those parts being 0.0240 and -0.1680 (Don't need the i here)
I've converted the double into a string using the following:
I=0.0240 - 0.1680*i
I_1=num2str(I)
Im not sure how to proceed here to get what i want. strsplit() just gives back the string in the form it already is. Id like to somehow split it to give me the two numbers separately. I'm not too experienced with data manipulation in Matlab so any help is appreciated.
num2str converts number to string. It is not for separating real and imaginary parts.
You can use:
I=0.0240 - 0.1680*i;
real_part=real (I)
imaginary_part=imag(I)

What is the difference between M11 and M21 cells in a transformation Matrix?

I need to interpret an SVG input data and identify the displayed points.
In the SVG format, any point may be part of a group ( element ) to which transformations (translate/rotate/scale) may be applied. For every point, I need to bubble up and apply transformation of every ancestor, in order to find the position that the point has in the rendering. After reading some web pages on the subject (and trying to remember from school), I understand that the usual way to do this in .NET is to use 3x3 mathematical matrices, so I try to figure out the System.Windows.Media.Matrix class.
It's been a while since I took Math, and I can't recall this one particular detail.
I typed up the following code in LINQPad:
var matrix = new Matrix(1,1,1,6,0,0);
var matrix2 = new Matrix(2,1,0,6,0,0);
var matrix3 = new Matrix(0,1,2,6,0,0);
var pts = new[]{
new System.Windows.Point(0,0),
new System.Windows.Point(1,1),
new System.Windows.Point(2,2),
new System.Windows.Point(3,3),
new System.Windows.Point(4,4),
new System.Windows.Point(5,5)
}.ToArray();
pts.Select(org=>new{org,changed=matrix.Transform(org),changed2=matrix2.Transform(org),changed3=matrix3.Transform(org)}).Dump("Transformation Samples");
... and trying out different values in the Matrix constructor.
However it seems that these values have no impact on the final result.
new Matrix(1,1,1,6,0,0);
new Matrix(2,1,0,6,0,0);
new Matrix(0,1,2,6,0,0);
(same is true for arguments 2 and 4)
The only thing that seems to matter is the sum of the two (which in this case is 2). I assume that this is due to my limited input data and that given other input data, some difference could be seen that would make sense in some visual tranformation.
Can anybody help me out here?
Perhaps the section in the SVG spec about how transform matrixes work will be of use to you?
http://www.w3.org/TR/SVG/coords.html#TransformMatrixDefined

Placing "markers" in MathJax math expressions

Suppose I have some equation, say:
$$\underbrace{ \frac{a}{b} }_{c}$$
And, I want to get the location of the $c$ in the HTML/CSS/SVG output of MathJax.
Is there a way to do this? I.e. I'd like to do something like:
$$\underbrace{ \frac{a}{b} }_{c\invisiblemarkerXYZ}$$
then be able to do a query to get the DOM element corresponding with invisiblemarkerXYZ
Thanks!
EDIT this is what I want to do:
Equation 1 = $$\underbrace{\frac{a}{b}}{A}$$
Equation 2 = $$A = \sum_{i=1}^n i$$
Now, I want to draw a line (via SVG) of the two A's. Thus, I need some way to obtain the location of the MathJax elements.
You can use \cssId{XYZ}{c} to set the id="XYZ" on the element used for the c, and can then use document.getElementById("XYZ") to obtain that DOM element. But the output from MathJax's HTML-CSS and SVG processors is not designed to be manipulated after the fact. For example, in general you will not be able to get the dimensions of the element from the HTML-CSS output as the offsetHeight and offsetWidth may not be what you expect them to be. (The height is frequently set to 0, for example.)
Can you say something more about what you are trying to accomplish?

How to number floats in LaTeX consistently?

I have a LaTeX document where I'd like the numbering of floats (tables and figures) to be in one numeric sequence from 1 to x rather than two sequences according to their type. I'm not using lists of figures or tables either and do not need to.
My documentclass is report and typically my floats have captions like this:
\caption{Breakdown of visualisations created.}
\label{tab:Visualisation_By_Types}
A quick way to do it is to put \addtocounter{table}{1} after each figure, and \addtocounter{figure}{1} after each table.
It's not pretty, and on a longer document you'd probably want to either include that in your style sheet or template, or go with cristobalito's solution of linking the counters.
The differences between the figure and table environments are very minor -- little more than them using different counters, and being maintained in separate sequences.
That is, there's nothing stopping you putting your {tabular} environments in a {figure}, or your graphics in a {table}, which would mean that they'd end up in the same sequence. The problem with this case (as Joseph Wright notes) is that you'd have to adjust the \caption, so that doesn't work perfectly.
Try the following, in the preamble:
\makeatletter
\newcounter{unisequence}
\def\ucaption{%
\ifx\#captype\#undefined
\#latex#error{\noexpand\ucaption outside float}\#ehd
\expandafter\#gobble
\else
\refstepcounter{unisequence}% <-- the only change from default \caption
\expandafter\#firstofone
\fi
{\#dblarg{\#caption\#captype}}%
}
\def\thetable{\#arabic\c#unisequence}
\def\thefigure{\#arabic\c#unisequence}
\makeatother
Then use \ucaption in your tables and figures, instead of \caption (change the name ad lib). If you want to use this same sequence in other environments (say, listings?), then define \the<foo> the same way.
My earlier attempt at this is in fact completely broken, as the OP spotted: the getting-the-lof-wrong is, instead of being trivial and only fiddly to fix, absolutely fundamental (ho, hum).
(For the afficionados, it comes about because \advance commands are processed in TeX's gut, but the content of the .lof, .lot, and .aux files is fixed in TeX's mouth, at expansion time, thus what was written to the files was whatever random value \#tempcnta had at the point \caption was called, ignoring the \advance calculations, which were then dutifully written to the file, and then ignored. Doh: how long have I know this but never internalised it!?)
Dutiful retention of earlier attempt (on the grounds that it may be instructively wrong):
No problem: try putting the following in the preamble:
\makeatletter
\def\tableandfigurenum{\#tempcnta=0
\advance\#tempcnta\c#figure
\advance\#tempcnta\c#table
\#arabic\#tempcnta}
\let\thetable\tableandfigurenum
\let\thefigure\tableandfigurenum
\makeatother
...and then use the {table} and {figure} environments as normal. The captions will have the correct 'Table/Figure' text, but they'll share a single numbering sequence.
Note that this example gets the numbers wrong in the listoffigures/listoftables, but (a) you say you don't care about that, (b) it's fixable, though probably mildly fiddly, and (c) life is hard!
I can't remember the syntax, but you're essentially looking for counters. Have a look here, under the custom floats section. Assign the counters for both tables and figures to the same thing and it should work.
I'd just use one type of float (let's say 'figure'), then use the caption package to remove the automatically added "Figure" text from the caption and deal with it by hand.

Resources