11,932,402 members (50,599 online)
alternative version

58.1K views
39 bookmarked
Posted

# Scalar Data Visualization Part 2

, 9 Dec 2012 BSD
 Rate this:

## 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:

```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:

```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]);
.
.
.
.
.
}```

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.

```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.

```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())
}
}```

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

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

## Share

 Other 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

## You may also be interested in...

 First Prev Next
 My vote of 5 meetp15-Jul-15 20:45 meetp 15-Jul-15 20:45
 Mesh points implementation Member 86930529-Jul-12 23:55 Member 8693052 9-Jul-12 23:55
 Re: Mesh points implementation I_gO_tO_schoOl_by_scoOter9-Dec-12 1:52 I_gO_tO_schoOl_by_scoOter 9-Dec-12 1:52
 Re: implementation of Kriging Algorithm I_gO_tO_schoOl_by_scoOter24-Aug-09 22:10 I_gO_tO_schoOl_by_scoOter 24-Aug-09 22:10
 Use of point vafa_hhh5-Jul-09 1:46 vafa_hhh 5-Jul-09 1:46
 Re: Use of point I_gO_tO_schoOl_by_scoOter6-Jul-09 4:04 I_gO_tO_schoOl_by_scoOter 6-Jul-09 4:04
 kriging prabhakarsangisetty2-Apr-09 21:18 prabhakarsangisetty 2-Apr-09 21:18
 Re: kriging I_gO_tO_schoOl_by_scoOter3-Apr-09 2:43 I_gO_tO_schoOl_by_scoOter 3-Apr-09 2:43
 Regarding Contour Lines prabhakarsangisetty2-Apr-09 21:17 prabhakarsangisetty 2-Apr-09 21:17
 Re: Regarding Contour Lines I_gO_tO_schoOl_by_scoOter3-Apr-09 2:39 I_gO_tO_schoOl_by_scoOter 3-Apr-09 2:39
 Re: Regarding Contour Lines prabhakarsangisetty6-Apr-09 19:03 prabhakarsangisetty 6-Apr-09 19:03
 Re: Regarding Contour Lines I_gO_tO_schoOl_by_scoOter8-Apr-09 8:05 I_gO_tO_schoOl_by_scoOter 8-Apr-09 8:05
 Re: Regarding Contour Lines agelospanagiotakis26-Oct-11 3:49 agelospanagiotakis 26-Oct-11 3:49
 Rending Issues cyber-drugs6-Jun-07 23:52 cyber-drugs 6-Jun-07 23:52
 Re: Rending Issues I_gO_tO_schoOl_by_scoOter3-Jul-07 17:04 I_gO_tO_schoOl_by_scoOter 3-Jul-07 17:04
 Are you using directx? zhvickie3-Apr-07 4:55 zhvickie 3-Apr-07 4:55
 Re: Are you using directx? I_gO_tO_schoOl_by_scoOter3-Apr-07 5:49 I_gO_tO_schoOl_by_scoOter 3-Apr-07 5:49
 Contour offset of a polygon Member #17451594-Jan-07 21:27 Member #1745159 4-Jan-07 21:27
 Re: Contour offset of a polygon I_gO_tO_schoOl_by_scoOter5-Jan-07 3:48 I_gO_tO_schoOl_by_scoOter 5-Jan-07 3:48
 Re: Contour offset of a polygon DLG0017-Jan-07 17:29 DLG001 7-Jan-07 17:29
 Re: Contour offset of a polygon I_gO_tO_schoOl_by_scoOter8-Jan-07 11:17 I_gO_tO_schoOl_by_scoOter 8-Jan-07 11:17
 Re: Contour offset of a polygon DLG0017-Jan-07 22:00 DLG001 7-Jan-07 22:00
 Contour offset of a polygon Member #17451594-Jan-07 21:26 Member #1745159 4-Jan-07 21:26
 Texture mapping method is more efficient [modified] Frank W. Wu18-Aug-06 11:14 Frank W. Wu 18-Aug-06 11:14
 Re: Texture mapping method is more efficient [modified] I_gO_tO_schoOl_by_scoOter18-Aug-06 11:39 I_gO_tO_schoOl_by_scoOter 18-Aug-06 11:39
 Explanation sahiljain221-Aug-06 7:39 sahiljain22 1-Aug-06 7:39
 Re: Explanation I_gO_tO_schoOl_by_scoOter1-Aug-06 8:55 I_gO_tO_schoOl_by_scoOter 1-Aug-06 8:55
 Re: Explanation Rakeshsharan7-Jan-10 3:46 Rakeshsharan 7-Jan-10 3:46
 Last Visit: 31-Dec-99 19:00     Last Update: 30-Nov-15 11:56 Refresh 1