قُلْ إِنَّ صَلَاتِي وَنُسُكِي وَمَحْيَايَ وَمَمَاتِي لِلَّـهِ رَبِّ الْعَالَمِينَ - الأنعام: ١٦٢

Showing posts with label Visualization. Show all posts
Showing posts with label Visualization. Show all posts

Thursday, January 14, 2010

My Visualization Package

Al Salam 3alikom w ra7mat Allah w barakatoh :)

yesterday we had our visualization practical exam. I really enjoyed the package we did in that subject. I learned a lot & had fun debugging the colors :D

Here it is...


Visualizing scalar data using the following techniques
-Edge coding
-Face coding
-Line contouring
-Flooded contouring
-Iso surface [marching cubes]

How to Use it?
Getting Started
Open a file [included with the setup file]
File->Open->browse for a file

Apply any of the algorithms
File->Apply->select an algorithm

Select a variable to visualize (if there exist multi variables in the file)
Properties->Visualized Data->select from the combo-box (if there exist other variables for the file)

Mesh visibility
you can choose whether the original mesh is visible or not
Properties->Mesh visibility->Show/Hide

Choose a coloring style
Properties->Color map style->LUT/TF

Mouse Interaction

There is also some friendly interaction with the mesh using the mouse

Zooming
press 'z' to enable/disable zooming
zoom in: double click
zoom out: right click



Translation
press 't' to enable/disable translation
now drag & drop the mesh (it doesn't move while dragging)

Rotation
press 'r' to enable/disable rotation
just like in translation u'll act as if you are dragging the mesh in order to rotate it...also doesn't rotate except when you release the mouse hold.

Here is a sample output
This project is built using C# & OpenGL

Find the project & some sample data files in my shared files =)


Marching Cubes works on some special meshes (3D)
use order1.dat





Despite all the negative energy I had this term :D
This project, this subject & this doctor...really made SC Rocks :D

Related Links:
color map editor: The basic idea of the whole thing
Contouring: I remember when I wrote this post, wasn't actually understanding what I was trying to do :D

Monday, November 2, 2009

Contouring

Al salam 3alikom w ra7mat Allah w'barakatoh

These are my notes about our next assignment in visualization.

(Polygon Filling Algorithm)

1st we'll be using the loader to load the mesh we need to color. This mesh consists of polygons. We'll be coloring these polygons.

We'll make a function with the following specifications
Input:
  • The polygon to be colored
  • The contours that we did last week
Output:
  • An array of lines with their corresponding colors (we'll get them from the color map editor we did 2 weeks ago)
How will we color the regions of the polygon??

using the lines from the array we just got [L1 & L2]. We'll iterate on all the vertices we have in this polygon [V1, V2, V3 & V4] and check if the region we are coloring contains this vertex or not.
If it contains the vertex, then add the vertex to -say- an array of points that defines this region.
After we finish this iteration, we'll be having a set of points that defines the regions to be colored.

in this example we'll have 3 arrays:
[L1, V1] [L1, L2, V2, V4] [L2, V3]
These defines the 3 regions [R1, R2 & R3]
Now What?

can we start coloring?
No, we still need to sort these points, to be able to color the regions.
How will we sort them?
take any vertex as a reference point, then draw the main coordinates (wiz respect to this vertex) & calculate the angles between the main coordinates and the lines.
Sort the angles & start coloring.

Here we took V4 as a reference point.
The Orange lines represent the main axes.
and the angles are (1, 2 & 3)


(Texture Mapping)

This should be faster than the "polygon filling" algorithm and easier to implement.
say we have 8 colors. We'll store them as 8 pixels in the memory.
We should normalize the values, so that they range from 0 to 1.
Also the values of pixels in the polygon, should range from 0 to 1.
Now we'll iterate on the polygon's pixels and get the required pixel (color) directly from the memory.
No distribution is used. We get the color directly from the pixels we stored.


I hope you find this post useful :)
Al Salam 3alikom w ra7mat Allah w'barakatoh

Thursday, October 29, 2009

Color Map Editor

Al Salam 3alikom w ra7mat Allah w barakatoh :)




It's an assignment we took in visualization. The color map editor.


Does this picture look familiar?
I guess most of us has seen similar pics in our geography study @ school

How was this picture drawn??
As u can see, the brown parts represent high areas (like mountains), green parts are just ground & blue will be the see level.
These colors map to specific heights. This is shown in the gradient between colors. like this between beige & brown.
This is color mapping!

Why do we need this?!
We need color mapping because if this data was given in its numerical form, it would be really difficult for ppl to interpret. This visual form makes things easier & more fun.

How do we make this color mapping?
we have 2 main methods to this
  1. using a look-up table
  2. using a transfer function
what are these methods, and which one will we be using?
It depends on the problem we have.
If we have specific discrete values, we can use the look-up table. It will probably do the job required and it is easier to implement.
If we have continuous values (like the gradient mentioned above), we'll need to use the transfer function. Because when we use the transfer function we not only map 2 colors (for example) but we map all the gradients that lies between them, which represents more data.

Now let's talk about the 2 methods we have
Look-up table (LUT)
as mentioned b4, it is suitable when we have specific discrete data.
as you can see here, there are only 6 colors that represent some ranges of data
  • less than 18 --> baby blue
  • 18 - 20 --> light blue
  • 20 - 22 --> off white
  • 22 - 24 --> orange
  • more than 24 --> red
  • if the depth is less than 1000m then it's mapped to white
this can be reflected in a table that contains these colors (array).
when given a value "S", this value is mapped to a color "C".
Index(c)=([(S-Smin)/(Smax-Smin)]*numberOfColors)
if S was the min value, then Index(c) will be equal to 0*numberOfColors = 0 (1st color)
if S was the max value, then Index(c) will be 1*numberOfColors = numberOfColors (last color)
and of course if it was in between them it will give us an index in the array of colors we have.

This is briefly how the LUT works.

Now what about the transfer function?
What's special about it?

Transfer Function
The special part about the transfer function is mapping every gradient between any 2 colors.
as you can see in this picture, every color is a start in a range of values, till another range begins.

How will we get a value to a specific degree of the color?
Using Interpolation.
Let's start with an easy example.
if the first color is red (C1) & the 2nd color is yellow (C2)
C1 represents a value of 100 and C2 represents 200
and we want to know the value of the color corresponding 150
what will we do?
This is a simple case, as we know that the required color (C3) lies exactly in the middle of C1 & C2
so we deduce that C3=0.5*C1 + 0.5*C2

what if it didn't lie exactly @ the middle of 2 colors?
We'll calculate where exactly does it lies. This will be i (index of previous color) + f (fraction). (i+f) will be smaller than (i+1), as it lies between i & (i+1).
i = floor ((S-Smin)/∆S)
f= (S-Smin)/∆S – i
then, C = (1-f)*Ci + f*C(i+1)




i: is the index of a color
f: is the fraction in a given index

This will give us the exact color of any value in our continuous data. Hence, we'll be able to formulate a visualization like the one shown above :)

I hope you find this post interesting & useful :)



Al Salam 3alikom w ra7mat Allah w barakatoh