Beginner Tutorial Data Objects 2D Curves

Example 1: Drawing curves

Introduction

In this example, you will draw one or more curves into a diagram and define different styles for the curves.

Steps to do

Develop your network

A curve requires x- and y-coordinates to be printed. You can use the CurveCreator module as input for these coordinates. The SoDiagram2D draws the curves into a SoRenderArea. You can also define the style of the curves by using the StylePalette module.

Add the modules to your workspace and connect them as seen below.

Example Network

Example Network

Creating a curve

Click on the output of the CurveCreator and open the Output Inspector.

Empty Output Inspector

Empty Output Inspector

Double-click Left Mouse Button on the CurveCreator module and open the Panel.

CurveCreator Module

CurveCreator Module

You can see a large input field Curve Table. Here you can enter the x and y values of your curve. The values of the first column will become the x-values and the 2nd any further column will become the y-series. Comment lines start with a ‘#’ character.

Enter the following into the Curve Table:

Curve Table

# My first curve
0 0
1 1
2 2
3 3
4 4
5 5
10 10
50 50

Now your Output Inspector shows a yellow line through the previously entered coordinates. Exactly the same curve is shown in the SoRenderArea.

SoRenderArea

SoRenderArea

Creating multiple curves

Now, update the Curve Table so that you are using 3 columns and click Update Left Mouse Button :

Curve Table

# My first curve
0 0 0
1 1 2
2 2 4
3 3 6
4 4 8
5 5 10
10 10 20
50 50 100

You can see 2 curves. The second and third columns are printed as separate curves. Both appear yellow. After checking Split columns into data sets, you will see one yellow and one red curve.

before_split

before_split

after_split

after_split

If the flag Split columns into data sets is set to TRUE, then a table with more than two columns is split into different CurveData objects. This gives the user the possibility to assign a different style and title for each series.

Titles and styles

Let’s do this. Open the panel of the SoDiagram2D module and check Draw legend. Enter “Curve1 Curve2” into the Title(s) text box of the CurveCreator module and click Update Left Mouse Button .

SoRenderArea with Legend

SoRenderArea with Legend

You can also define a different location of the legend and set font sizes.

Now open the panel of the StylePalette module.

StylePalette

StylePalette

The StylePalette allows you to define 12 different styles for curves. Initially without manual changes, the styles are applied one after the other. The first curve gets style 1, the second curve style 2, and so on.

Open the Panel of your CurveCreator again and define Curve Style(s) as “3 6”. Update Left Mouse Button your curves.

StylePalette applied

StylePalette applied

You now applied the style 3 for your first curve and 6 for the second. This is how you can create 12 different curves with unique appearance.

Using multiple tables for curve generation

In addition to adding multiple columns for different y-coordinates, you can also define multiple tables as input, so that you can also have different x-coordinates for multiple curves.

Update the Curve Table as defined below and click Update Left Mouse Button :

Curve Table

# My first curve
0 0 0
1 1 2
2 2 4
3 3 6
4 4 8
5 5 10
10 10 20
50 50 100
---
# My second curve
0 0
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
10 100

Also add another title to your curves and define a third style.

Multiple tables as input

Multiple tables as input

Summary

  • Curves can be created to draw 2-dimensional diagrams
  • The StylePalette allows you to define the appearance of a curve
  • Details of the different curves can be visualized by using the SoDiagram2D module