Click here to Skip to main content
15,868,014 members
Articles / Programming Languages / C#

Scalar Data Visualization Part 2

Rate me:
Please Sign up or sign in to vote.
4.76/5 (33 votes)
9 Dec 2012BSD2 min read 83.7K   1.4K   40   31
This article will describe the line contouring section in more detail
Sample Image - ScoOterVisualizationPart2.png

Sample screenshot

Introduction

I'm back again but I hope this time is better. In this article, I'll discuss the line contouring part of the application. Contour line is a curve connecting points where the function has the same particular value. You can find more about line contouring in Wikipedia.

Background

A previous knowledge of simple scalar data visualization techniques and DirectX9.

Using the Code

To get a contour line that represents certain values, you need to search between 2 consecutive pairs of points in a given face to see if the value you are looking for lies between them:

C#
private bool ValueWithin(double Val1, double Val2)
{
    return (Value >= Val1 && Value <= Val2) || (Value >= Val2 && Value <= Val1);
}

I used linear interpolation to determine the position of the new point using the following equation:

t = P – P<sub>1</sub> / P<sub>2</sub> – P<sub>1</sub>

Using this equation on the data dimension being visualized to get the "t" and then the "t" is used to get the new x, y, z coordinates of this point.

This function just does this stuff and adds the new point to the list of points in the contourLine class, as they will be needed later for rendering:

C#
private void GetContourPoint(int Vertex1, int Vertex2)
{
    double diff = (Parent.Points[Vertex2].Data[Parent.VariableIndex] - 
		Parent.Points[Vertex1].Data[Parent.VariableIndex]);

    double t = 0.0;
    if(diff != 0)
           t = (Value - Parent.Points[Vertex1].Data[Parent.VariableIndex]) / diff;
    Point p = new Point(13);
    double DeltaX = (Parent.Points[Vertex2].Data[0] - Parent.Points[Vertex1].Data[0]);
. 
.
.
    p.Data.Add(Parent.Points[Vertex1].Data[0] + t * DeltaX);
.
.
    points.Add(p);
}

So, to create a contour line, you need to do the above stuff for each point in each face on the surface. This will get you the contour line over the whole surface.

C#
public bool CreateLine()
{    
    foreach (TriangulatedPolygon t in Parent.Faces)
    {
        if (ValueWithin(Parent.Points[t.Vertex1Index].Data[Parent.VariableIndex],
		Parent.Points[t.Vertex2Index].Data[Parent.VariableIndex]))

            GetContourPoint(t.Vertex1Index, t.Vertex2Index);
       .
       .
       .
   }
    return SetVertexBuffer();
}

Now, we have our contour line ready for rendering. If you are familiar with DirectX, you don't need to bother yourself with this part. For those who don't know about VertexBuffers in DirectX, please check this link first.

I create a vertex buffer of PositionNormalColored vertices, where normal is mainly needed for lighting, and the color is responsible for representing the value the contour line defines.

This is not everything yet. This was just a description of the logic of the ContourLine class. It's mainly controlled by a contour manager – which manages all the contouring stuff, but let's concentrate on line contouring for now. This manager is responsible for holding the list of contour lines, rendering them, defining each line's color and also data value – as they might be input from the user or auto generated according to a given number.

C#
private void CreateLines()
{
    double transtion = (MaxVal - MinVal) / (LinesCount + 1);
    Lines = new List<ContourLine>();
    for (int i = 1; i <= LinesCount; i++)
    {        
        double val = MinVal + i*transtion;
        ContourLine c = new ContourLine(this, ScoOteRColorPalet.GetColor(val), val);
        if(c.CreateLine())
            Lines.Add(c);
    }
}

And finally, this is how the user can deal with line contouring:

Sample screenshot

Now you can proceed to the next part, the flooded contouring technique.  

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Other
Egypt Egypt
Nvidia Registered game developer.
Teaching Assistant,
Faculty of computer and information sciences,
Ain Shams University.
SmartLabZ QT Developer.
Have an experience of more than 2 years in c++(QT/MFC/ATL/Win32),c#, GDI,DirectX

Comments and Discussions

 
GeneralMy vote of 5 Pin
meetp15-Jul-15 19:45
meetp15-Jul-15 19:45 
QuestionMesh points implementation Pin
Sagar319-Jul-12 22:55
Sagar319-Jul-12 22:55 
AnswerRe: Mesh points implementation Pin
I_gO_tO_schoOl_by_scoOter9-Dec-12 0:52
I_gO_tO_schoOl_by_scoOter9-Dec-12 0:52 
Generalimplementation of Kriging Algorithm Pin
dadamamad24-Aug-09 20:35
dadamamad24-Aug-09 20:35 
GeneralRe: implementation of Kriging Algorithm Pin
I_gO_tO_schoOl_by_scoOter24-Aug-09 21:10
I_gO_tO_schoOl_by_scoOter24-Aug-09 21:10 
GeneralUse of point Pin
vafa_hhh5-Jul-09 0:46
vafa_hhh5-Jul-09 0:46 
GeneralRe: Use of point Pin
I_gO_tO_schoOl_by_scoOter6-Jul-09 3:04
I_gO_tO_schoOl_by_scoOter6-Jul-09 3:04 
Generalkriging Pin
prabhakarsangisetty2-Apr-09 20:18
prabhakarsangisetty2-Apr-09 20:18 
GeneralRe: kriging Pin
I_gO_tO_schoOl_by_scoOter3-Apr-09 1:43
I_gO_tO_schoOl_by_scoOter3-Apr-09 1:43 
GeneralRegarding Contour Lines Pin
prabhakarsangisetty2-Apr-09 20:17
prabhakarsangisetty2-Apr-09 20:17 
GeneralRe: Regarding Contour Lines Pin
I_gO_tO_schoOl_by_scoOter3-Apr-09 1:39
I_gO_tO_schoOl_by_scoOter3-Apr-09 1:39 
GeneralRe: Regarding Contour Lines Pin
prabhakarsangisetty6-Apr-09 18:03
prabhakarsangisetty6-Apr-09 18:03 
GeneralRe: Regarding Contour Lines Pin
I_gO_tO_schoOl_by_scoOter8-Apr-09 7:05
I_gO_tO_schoOl_by_scoOter8-Apr-09 7:05 
GeneralRe: Regarding Contour Lines Pin
agelospanagiotakis26-Oct-11 2:49
agelospanagiotakis26-Oct-11 2:49 
GeneralRe: Regarding Contour Lines Pin
Member 123014433-Mar-16 18:29
Member 123014433-Mar-16 18:29 
QuestionRending Issues Pin
cyber-drugs6-Jun-07 22:52
cyber-drugs6-Jun-07 22:52 
AnswerRe: Rending Issues Pin
I_gO_tO_schoOl_by_scoOter3-Jul-07 16:04
I_gO_tO_schoOl_by_scoOter3-Jul-07 16:04 
AnswerRe: Rending Issues Pin
Member 123014433-Mar-16 18:38
Member 123014433-Mar-16 18:38 
QuestionAre you using directx? Pin
zhvickie3-Apr-07 3:55
zhvickie3-Apr-07 3:55 
AnswerRe: Are you using directx? Pin
I_gO_tO_schoOl_by_scoOter3-Apr-07 4:49
I_gO_tO_schoOl_by_scoOter3-Apr-07 4:49 
QuestionContour offset of a polygon Pin
DLG0014-Jan-07 20:27
DLG0014-Jan-07 20:27 
AnswerRe: Contour offset of a polygon Pin
I_gO_tO_schoOl_by_scoOter5-Jan-07 2:48
I_gO_tO_schoOl_by_scoOter5-Jan-07 2:48 
GeneralRe: Contour offset of a polygon Pin
DLG0017-Jan-07 16:29
DLG0017-Jan-07 16:29 
GeneralRe: Contour offset of a polygon Pin
I_gO_tO_schoOl_by_scoOter8-Jan-07 10:17
I_gO_tO_schoOl_by_scoOter8-Jan-07 10:17 
GeneralRe: Contour offset of a polygon Pin
DLG0017-Jan-07 21:00
DLG0017-Jan-07 21:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.