WebGL Recursion - recursion

I am writing a website that calculates geometry using a recursive algorithm and displays that geometry using WebGL. Can WebGL calculate the geometry using recursion? I know shaders can't be recursive, but I don't know if there is still some recursion supported.
Thanks, Istvan.

You can easily generate geometry using recursive algorithms in JavaScript. You would store the generated geometry in an array buffer, and then pass it into WebGL. WebGL, however, doesn't have any geometry generation capabilities (e.g., geometry shaders, or subdivision surfaces).

With webgl 1.0 you can get output from shader using render target created with help of webgl renderbuffer and then use canvas's getImageData to get buffer with values representing your geometry. It's quite time consuming, but possible. Also, recommend to pay attention to the project.

Calculating the recursion algorithm in JS and passing the result into the variables that are defined in the shaders would work for your problem.

Related

OpenCL region growing

i'm trying to make a region growing segmentation for my project in OpenCL, can anyone please help me writng the code
the algorithm is as follows:
seed the first pixel(seed) manually
get the value of the seed
compare it with its 4-neighbors or 8-neighbors(i dont know which is better)
if the neighbors have the same value then they are in region
compare these neighbors with there other neighbors and so on until it finds a boundary, then stop
thanks a lot
I have implemented an OpenCL version of this algorithm in the FAST framework for 2D and 3D. See here: https://github.com/smistad/FAST/tree/master/source/FAST/Algorithms/SeededRegionGrowing
In our GPU segmentation review article you can find an explanation of the implementation as well as a performance analysis: http://www.medicalimageanalysisjournal.com/article/S1361-8415(14)00181-9/fulltext#s0075

Howto implement the inverse Laplace transform in javascript?

I'm writing an javascript applet make it easy for others to see how a system with and without proportional controller works and what the outputs are.
First a little explanation on the applet (You can skip this if you want, the real question is in the last paragraph.):
I managed to implement a way of input for the system (in the frequency domain), so the applet can do the math and show the users their provided system. At the moment the applet computes the poles and zeros of the system, plots them together with the root-Loci, plot the Nyquist curve of the system and plot the Bode plots of the system.
The next thing I want the applet to do is calculating and plotting the impulse response. To do so I need to perform an inverse Laplace transformation on the transferfunction of the system.
Now the real question:
I have a function (the transferfunction) in the frequency domain. The function is a rational function, stored in the program as two polynomes (numerator and denominator stored by their coefficients). What would be the best way of transforming this function to the time domain? (inverse Laplace). Or is there an open-source library which implements this already. I've searched for it already but only found some math libraries for with more simple mathematics.
Thanks in advance
This is a fairly complex and interesting problem. A couple of ideas.
(1) If the solution must be strictly JS: the inverse LT of some rational functions can be found via partial fraction decomposition. You have numerical coefficients for the polynomials, right? You can try implementing a partial fraction decomposition in JS or maybe find one. The difficulty here is that it is not guaranteed that you can find the inverse LT via partial fractions.
(2) Use JS as glue code and send the rational function to another process (running e.g. Sympy or Maxima) to compute the inverse LT. That way you can take advantage of all the functions available, but it will take some work to connect to the other process and parse the result. For Maxima at least, there have been many projects which use Maxima as the computational back-end; see: http://maxima.sourceforge.net/relatedprojects.html
Problem is solved now. After checking out some numerical methods I went for the partial fraction decomposition by using the poles of the system and the least square method to calculate the coeficients. After this the inverse LT wasn't that hard to find.
Thx for your suggestions ;)
Ask me if you want to look at the code.

OpenGL Matrices VS DirectX Matrices

I have only handled DirectX matrices
I have read articles that say you cannot use DirectX matrix math libraries for openGL matrices.
but i have also read that if your math is consistent you can get similar to same results. That just confuses me even more.
Can anyone enlighten me? or If you cannot use DirectX math on openGL matrices. Does anyone know a good openGL matrix library?
any help in understand the differences and math knowledge of them would be grateful.
I have read articles that say you cannot use DirectX matrix math libraries for openGL matrices.
This is wrong.
but i have also read that if your math is consistent you can get similar to same results.
The only difference is about the default assumptions OpenGL and DirectX make about their Normalized Device Coordinate space. They use slightly different ranges and signs. However this only translates into a transformation stack with an additional "adaptor" matrix premultiplied on it, and you're done with.
Also important may be the index ordering, but modern OpenGL allows you to choose which order is used by a parameter to glUniformMatrix of the name "transpose"
I'd like to add to datenwolf's great answer by making it clearer that the key perceived difference between OpenGL's matrices and DirectX's matrices is that they are in column-major and row-major formats, respectively. (Column- and row-major refers to how you would write them out in a 4x4 format. If the translations appear in the fourth column, that is column-major, vice versa for row-major.)
Mathematicians would tell you that column-major is the proper way to represent a matrix, primarily because it makes operations on them, visually (on paper), easier.
When it comes to OpenGL, however, the entire matrix is laid out contiguously in memory in a 16-element array, with the translation occupying the 13th, 14th, and 15th elements, according to the specifications. Thus, it's easy to adapt the data to either matrix format.

Qt: what class should I use for matrices instead of QMatrix?

The documentation for QMatrix says it's obsolete and is strongly unadvised to use. Ok, but what should I use instead to store a matrix?
I have even posted a bug report on the Qt Documentation Bug tracker but they didn't respond.
It depends on what you want to do. The replacement for QMatrix is QTransform, so you should use that if it will accomplish what you want. It's worth noting that neither QMatrix nor QTransform are really matrices in the mathematical sense.
If you're talking about ordinary mathematical matrices, you should look to any of the existing C++ matrix libraries (a quick Google search turns up a number of results), or write your own matrix class. I was recently working on a project where I needed to do multiplication of small (2x2) matrices, so I just designed the class myself. It was quite easy.
EDIT: By the way, that's not a bug, so you should try to remove the report, if it's possible.
QMatrix was specifically for 2D transformations and QTransform replaces it for that purpose. If you're looking for regular matrix classes for 3D work or linear algebra, then Qt has QMatrix4x4 and QGenericMatrix.

OpenCL FFT lib for GPUs?

Is there any general FFT lib available for running on the GPU using OpenCL? As far as my knowledge goes, Apple sample code for power-of-two OpenCL FFT is the only such code available?
Does any such library exist for non-power-of-two transform sizes? If not, how easy or difficult is it to modify the Apple OpenCL sample?
I am looking at image processing applications, with non-power-of-two transform sizes, and I will have to do a whole bunch of FFTs, a batched FFT.
Try clFFT developed by AMD. It is aimed at AMD graphic cards, but should work on nVidia GPU's too. It can transform arrays with a radix of 2, 3 and 5 (and combinations there off).
https://github.com/clMathLibraries/clFFT
There are python bindings available
https://github.com/geggo/gpyfft
I know of an OpenCL FFT library that is currently under development,
but they don't plan on having non-power-of-two transform sizes in the first release.
Can you provide any information about your application? It might help to get the priority for that feature raised if it's something a lot of people can use.
You can download some OpenCL code samples including FFT from the SHOC benchmark suite.
Null-padding can be used to make arbitrary-length data fit for a power-of-two FFT algorithm. Consider if that would suit your application.
Increasing the number of samples decreases the "step size" in the output domain, which means higher output resolution.
OpenMM (https://simtk.org/home/openmm) contains a 3D FFT for OpenCL. It may not work for you directly, since it's designed for a specific case: 3D FFTs where each dimension is small enough to be stored in local memory (e.g. a 100x100x100 grid). But it does support non-power-of-two sizes (radix 2, 3, 4, and 5), so you might be able to adapt it.
VexCL provides an implementation of FFT for OpenCL that accepts arbitrary vector expressions as input, allows one to perform multidimensional transforms (of any number of dimensions), and supports arbitrary sized vectors. Here is a link to the relevant part of its README.
Have a look at APPML-FFT library. Though its still for power of two transforms.

Resources