SFA Project On-line Documentation: Shape

This file is responsible for creating the actual OpenGL drawing lists that are needed to draw the following shapes :

When SFA is fired up, the SFADraw::SFADraw() function is called and that is where the create_lists_* functions are called. These functions return the number of the first drawing list in the series.


# ifndef _SHAPES_H
# define _SHAPES_H

//
// Shapes.H  : generates procedural shapes for glyph-based visualization 
// Part of my code for CMSC 698
//
// Pradyut Panda

# include 
# include 

# include 
# include 
# include 

# include "Vector_noise.H"


// for the circle
# define SFA_CIRCLE_MIN   3


// for the shape warping 
# define NUM_POINTS     12
# define NUM_QUADS      4
# define NUM_TRIANGLES  8

# define TETRA_TO_CUBE  101
# define TETRA_TO_OCTA  102
# define OCTA_TO_CUBE   103




// for the turbulated cube
# define TURB_CUBE  201
# define TURB_TETRA 202

# define SCALE_DOWN 0.4 

# define TURB_HMIN  0.0
# define TURB_HMAX  1.0
# define TURB_EXP   1.0


// the number of basically diff shapes
# define SFA_DIFF_SHAPES  10

// the functions to create drawing lists
int create_lists_circle( int );
int create_lists_warp( int , int );
int create_lists_turb_cube( int type, int freq, int range );

# endif
    

Refining a 3-d Circle( Cylinder really !)

int create_lists_circle( int range )

This functions creates the drawing lists for the refinement of a circle shape. The function returns the number of starting OpenGL list. If it is not successful in creating the lists it returns 0. The range integer is the number of different shapes t o be created. There are 2 #defines :
SFA_CIRCLE_MIN 3 : the minimum number of line segments
SFA_CIRCLE_RANGE 10: the number of circle shapes ( in sfa_ui.H )
This will create circle with n=3,4 ... 12 .

void generate_circle( const int n, const int index )

This functions computes the actual points of the circle and also creates the OpenGL drawing list needed to create the circle. The circle is created in the 0.01, 0.01, 0.005 cube centered around the origin. The points are generated using the formula x=r*cos theta, y=r*sin theta. Normals are computed appropriately.

Warping between shapes

int create_lists_warp( int type, int range )

This functions creates the drawing lists for the warping between 3 platonic solids. Three basic shapes ( the CUBE, the TETRAHEDRON and the OCTAHEDRON ) are modeled. Vertices, polygons and normals are defined. There are 4 #defines :
NUM_POINTS 12 : Each shape has been defined using 12 points. Some are redundant.
NUM_QUADS 4 : Each shape has 4 quadrilaterals.
NUM_TRIANGLES 8 : Each shape has 8 triangles.
SFA_WARP_RANGE 10 : the number of different shapes. ( in sfa_ui.H )

void interpolate_points( Pvector a, Pvector b, float x, Pvector c)

This function performs a linear interpolation between 2 points a and b and stores the value in point c. The value of x should be between 0.0 and 1.0.

void interpolate_shapes( Pvector *shape1, Pvector *shape2, int n, int index )

This function does a "linear interpolation" between 2 shapes based on the value of x. The value of x should be between 0.0 and 1.0. This done by interpolating between the vertices of the individual shapes.

void generate_list( Pvector *shape, int index )

Given an array of points( shape ) , this function creates an OpenGL drawing list with number equal to "index". The reason why this works for all shapes is that there is a one-to-one correspondence maintained between each point in the different shape s. Thus, normal and polygon information remains the same.

The turbulated cube

int create_lists_turb_cube( int type, int freq, int range )

This functions creates the drawing lists for the turbulated cube. The integer "range" controls the number of turbulated cubes, whereas the integer freq controls the frequency at which the distortion is applied. There are 4 #defines :
TURB_HMIN 0.0 : the minimum value for H.
TURB_HMAX 1.0 : the maximum value for H.
TURB_EXP 1.0 : controls rate of change of H.
SFA_TURB_RANGE 10 : the number of different shapes. ( in sfa_ui.H )

void generate_list( Pvector **points, int size, int index )

This function generates the actual drawing lists based on the array on points. The array of points has dimension : size x size. Index is the number of the drawing list. All cubes will have the same polygons and normals may be computed too. The actua l amount of displacement for individual points will vary.

double get_H_value( double min, double max, int n, int range )

Computes the actual H value for a particular shape. This is a computed by :
y = pow( 1- n/range, TURB_EXP ); based on y, linear interpolation between min and max.

void create_turb_cube( int freq, int range, int index )

Performs the displacement for a single face ( z = 0.01 ). For each point (x,y) the fBm function is called and then the drawing list is created.
Pradyut Panda
Last modified: Mon Mar 30 10:23:40 EST 1998