Function-based Shape Modeling and Visualization

Last time updated  1 December, 2022

Procedural shape modelling using explicit, implicit and parametric functions is explored in this research. Two software tools are being developed:

We use mathematical definitions or procedural representation to define geometry, visual appearance and physical properties of virtual objects. We work with FReps, algebraic surfaces, implicit surfaces, CSG solids, volumetric objects, as well as parametric curves, surfaces and solids. We have developed Function-based extestion of VRML and X3D (FVRML/FX3D) which allows for using mathematical formulas and function scripts straight in the codes of VRML and X3D for defining practically any type of geometry, appearance as well as physical properties. We are also developing a multiplatform interactive modelling tool Shape Explorer for teaching and research on function-based computer graphics and visualization.


Shape Explorer

Developed by:
Alexei Sourin
Khiew Jian Bin (FYP project)
Ho Kai Jie, Calvin (FYP project)
Naseer Ahmed Khan (FYP project)
Beh Wei Feng (FYP project)

ShapeExplorer is a new interactive software tool designed to display shapes defined by parametric and implicit function scripts and colors defined by explicit functions. It can run on Windows, MacOS and Linux (Ubuntu) computers. Shape Explorer is just one interactive window where you can type the definitions scripts and other parameters. The definitions can be saved in a proprietary format to be used in FVRML/FX3D and any other procedural modeling software. In contrast to FVRML/FX3D, Shape Explorer supports only one shape visualization at the time. Its purpose is to work as a quick all-in-one multi-platform visualization tool.

The software and its manual can be downloaded from here.

Selected Publications:

1. Alexei Sourin, Making Images with Mathematics, Springer Nature, 2021.
2. Sourin A. Making Shapes with Mathematics. The 2022 International Conference on Cyberworlds, Kanazawa, Japan, 27-29 Sept 2022, IEEE CPS, 175-176, 2022.

Back


FVRML/FX3D: Function-based Extension of VRML and X3D (version 5.0)

Developed by:
Alexei Sourin
Shahzad Rasool (PhD project: 2010 - 2014)
Cui Jian (PhD project: 2013 - 2019)
Lai Danbo (PhD project: 2009 - 2013)

Lei Wei (PhD project: 2006 - 2011)

Qi Liu  (PhD project: 2004 - 2007)
Konstantin Levinski (MSc/PhD project: 2001 - 2007)
Lai Feng Min (MEng project: 2000 - 2002) 

Introduction

Function-based extension of VRML and X3D (FVRML/FX3D) allows for extending VRML and its successor X3D with practically any type of object’s geometry and sophisticated graphics appearances by defining the object’s geometry, appearance (color and 3D texture) and transformations with analytical formulas which are implicit, explicit and parametric representations used concurrently. Static and time-dependent shapes and operations can be defined. In contrast to the polygon-based models of VRML/X3D, function-based nodes greatly reduce the size of the models and provide an unlimited level of detail. Also, these nodes allow for using set-theoretic as well as any analytically-defined geometric operations which can be introduced by the user. FVRML/FX3D allows for its extending with any proprietary function-based models.  The extension is developed for collaborative shape modeling as well as for building shared virtual worlds.

Back


Software Installation

The following plug-ins work with MS Internet Explorer and Mozilla Firefox.

1. Install  BS Contact VRML/X3D (32bit version).

2. Click to install the FVRML/FX3D plug-in (Version 5.3)

Please report bugs to assourin@ntu.edu.sg


FVRML Extension Description and Programming Examples

Function-based extension of VRML—FVRML—allows for extending VRML with practically any type of object’s geometry, sophisticated graphics appearance and transformation by defining them analytically straight in the VRML code. In contrast to the polygon-based models of VRML, function-based nodes allow for a great reduction of the model sizes and provide an unlimited level of detail. Also, these nodes introduce to VRML set-theoretic as well as any other operations analytically-defined by the user.

For defining geometry, appearance and their transformations, three types of functions can be used concurrently. They are implicit, explicit and parametric functions.

Implicit functions are f(x,y,z,t)=0, where x, y, z are Cartesian coordinates and t is the time. The function equals to zero for the points located on the surface of a shape.

Explicit functions are g=f(x,y,z,t). The function value g evaluated at any point of the 3d space can be used either as an argument of other functions (e.g. for defining colors or parameters of transformations) or as an indicator of the sampled point location. Thus, explicit functions can be used for defining bounded solid objects. In this case, the function equals to zero for the points located on the surface of a shape. Positive values indicate points inside the shape and negative values are for the points outside the shape.

Parametric functions define surfaces and solid objects as:

 x= f1(u,v,w,t);  y= f2(u,v,w,t);  z= f3(u,v,w,t)  where x, y, z are Cartesian coordinates of the points, while u, v and w are parametric coordinates, and t is the time. Parametric functions can also define r, g, b values of color or parameters of transformations.

Geometry, 3D texture, and color can be defined by implicit, explicit or parametric functions in their own domains and then merged together into one shape by the predefined mapping functions. When modeling shape, first a geometric texture is mapped onto the original shape’s geometry, and then the color is mapped to the textured shape to form the final shape. This process repeats as many times as needed.

Defining complex shapes, appearances and operations usually assumes using multiple formulas and temporary variables. This requires a script-like mathematical language. To be consistent with VRML, which has a JavaScript (VRMLScript) as a standard feature, and to ease the learning curve, FVRML emulates a subset of JavaScipt. In this JavaScript emulation, all variables, arrays and constants have only one type float. The following mathematical functions are implemented: abs(x), sqrt(x), exp(x), log(x), sin(x), cos(x), tan(x), acos(x), asin(x), atan(x), ceil(x), floor(x), round(x), max(x,y), min(x,y), atan2(y,x), mod(x,y), cosh(x), sinh(x), tanh(x), log10(x). There are also three operators ‘&’, ‘|’ and ‘^’, which denote set-theoretic ‘intersection’, ‘union’, and ‘power’ operations, respectively. Custom functions can be defined in the same way as defining a function in JavaScript. Recursions are allowed. There are also the following flow control operators: for-loops, while-loops, do-while-loops, break, continue, and if-else.

When writing function scripts, implicit and explicit functions have to be named ‘frep’. Parametric functions for shapes and geometric textures have to be named ‘parametric_x’, ‘parametric_y’, and ‘parametric_z’, and for colors—‘parametric_r’, ‘parametric_g’, and ‘parametric_b’. If all these functions exist concurrently, frep function will have priority.

    FVRML offers six additional nodes, which are FShape, FGeometry, FAppearance, FMaterial, FTexture3D and FTransform. These nodes can be used together as well as with the standard VRML nodes. The nodes' prototypes are here.

FShape node is a container similar to the VRML’s Shape node. It contains FGeometry or any standard geometry node, and FAppearance or the standard Appearance node. These nodes define the geometry and the appearance of the shape, respectively. FShape may be called from FTransform node of from the standard Transform node.

FGeometry node is designed to define a geometry using implicit, explicit or parametric functions. It contains either one string, or a script defining a function representing the geometry, or a URL to the function definition.

FAppearance node may contain FMaterial or the standard Material, the standard Texture node, and FTexture3D node. FTexture3D defines geometric textures while the standard Texture node is used for image texture mapping.

FMaterial node defines diffuse, specular, and emissive colors, as well as transparency, ambient intensity, and shininess with parametric and explicit functions. Parametric functions directly define color values r, g, b. When the color is defined with an explicit function, its values are linearly mapped to the r, g, b values of the actual color with a user-defined color interpolation map. The color can be defined at every point of the 3D modeling space and then will be sampled by the geometry of the shape.

FTexture3D node defines 3D geometric textures using explicit and parametric functions. These functions define displacements of the original shape’s geometry defined in FGeometry or in any standard geometry node. The functions are defined either in one string, or in a function script, or via a URL to the function definition.

If the standard Geometry node is used in place of FGeometry node, the standard shapes of VRML will be assigned an appearance defined in FAppearance node. This ability of using the function-based nodes with the standard geometry and appearance nodes of VRML adds many new features to VRML, some of which are illustrated in this chapter.

FTransform node contains function-defined operations. It may contain FShape and other FTransform nodes as its children. FTransform contains either one string, or a script defining a function representing the operation, or a URL to the function definition as well as other fields to preserve the consistency with the standard Transform node. Both, set-theoretic and affine transformations can be defined as functions of time in FTransform node.

FVRML Examples:

In the following examples, different ways of using implicit, explicit and parametric functions for defining the shape's geometry and appearance are used.
For better performance switch the VRML viewer to OpenGL (software) mode.
Click at the images to see the VRML scene. Right click to save the .wrl file.

Time-Dependent FVRML examples:

Parametric Metamorphoses:

Curves:

Parametric solids (beta):

Parameters of the FVRML fields:

definition “f(x,y,z,t)“

or

definition"

frep(x,y,z,t){

function script; return frep(x,y,z,t);}”

or

definition”

x= x(u,v,w,t); y= y(u,v,w,t); z= z(u,v,w,t);”

or

definition”
function parametric_x(u,v,w,t){

function script; return x(u,v,w,t);}

function parametric_y(u,v,w,t){

function script; return y(u,v,w,t);}

function parametric_z(u,v,w,t){

function script; return z(u,v,w,t);}” 

In this field analytical definition of the shape's geometry or geometric texture has to be defined. It can be given either as individual implicit or parametric formulas or as a function script. The names of Cartesian coordinates are
x, y, z, while the names of parametric coordinates are u, v, w. Parameter t is the time. The number of variables is optional. For defining surfaces and solid objects x, y, z variables are to be used. For defining parametric surfaces, two of the parameters coordinates are to be used (e.g., u and v). For defining curves, only one of the parametric coordinates is to be used. New variable names can be introduced in function scripts as it is normally done in JavaScript. The formulae can be also called by a URL.

parameters [p1  p2  p3  p4  p5  p6]

 

Default: parameters [-1 1 -1 -1 1]

It defines parameters' range for u, v, w and continuity of the predefined set-theoretic operations. Default values for u, v, w are -1 1, and the continuity is 0. If the continuity equals to 0, the set-theoretic operations are implemented with min/max functions (as in Chapter 3). If the continuity is greater than 0, they are implemented with the so-called
R-functions.

bboxCenter x  y  z

Default: bboxCenter 0  0  0

It defines the origin of the coordinate system of the implicitly/explicitly defined surface.

bboxSize x  y  z

 Default: bboxSize 10 10 10

It defines the size of the bounding box, and thus the range of variables x, y, z for the implicitly/explicitly defined shape.

resolution [x  y  z]

 Default: resolution [50 50 50]

It defines the rendering resolution. There must be 3 values for solid shapes, 2 values for parametric surfaces, and 1 value for parametric curves.

diffuseColor ”frep(x,y,z,t)”

or

diffuseColor ”

frep(x,y,z,t){

function script; return frep(x,y,z,t);}”

or

diffuseColor ”

r=r(u,v,w,t); g=g(u,v,w,t); b=b(u,v,w,t);”

or

diffuseColor ”

function parametric_r(u,v,w,t){

function script; return r(u,v,w,t);}

function parametric_g(u,v,w,t){

function script; return g(u,v,w,t);}

function parametric_b(u,v,w,t){

function script; return b(u,v,w,t);}” 

In this field the function definition of the shape's diffuse color is to be given. It can be typed either as individual explicit or parametric formulas or as a function script. Cartesian coordinates are x, y, z, while the names of parametric coordinates are u, v, w. Ranges of the variables can be defined in parameters, bboxCenter, and bboxSize fields. Parameter t is the time. The formulae can be also called by a URL. In case if the color is defined by an explicit function, color interpolation will be done using the values defined in fields patternKey and patternColor.

emissiveColor ”frep(t)”

or

emissiveColor ”

frep(t){

function script; return frep(t);}”

or

emissiveColor ”

r=r(t); g=g(t); b=b(t);”

or

emissiveColor ”

function parametric_r(t){

function script; return r(t);}

function parametric_g(t){

function script; return g(t);}

function parametric_b(t){

function script; return b(t);}”  

It defines a time-dependent emissive color by an explicit function or script. In case of color definition by one explicit function, color interpolation will be done by the current pattern. Parameter t is the time. The formulae can be also called by a URL. The emissive color is assigned to the whole shape and cannot vary across it. In case if the color is defined by an explicit function, color interpolation will be done using the values defined in fields patternKey and patternColor.

specularColor ”frep(t)”

or

specularColor ”

frep(t){

function script; return frep(t);}”

or

specularColor ”

r=r(t); g=g(t); b=b(t);”

or

specularColor ”

function parametric_r(t){

function script; return r(t);}

function parametric_g(t){

function script; return g(t);}

function parametric_b(t){

function script; return b(t);}” 

It defines a time-dependent specular color by an explicit function or script. In case of color definition by one explicit function, color interpolation will be done by the current pattern. Parameter t is the time. The formulae can be also called by a URL. The specular color is assigned to the whole shape and cannot vary across it. In case if the color is defined by an explicit function, color interpolation will be done using the values defined in fields patternKey and patternColor.

ambientIntensity “frep(t)

It defines a time-dependent ambient intensity by an explicit function or script. The ambient intensity is assigned to the whole shape and cannot vary across it.

shininess frep(t)

It defines a time-dependent shininess by an explicit function or script. The shininess is assigned to the whole shape and cannot vary across it.

transparency frep(t)

It defines a time-dependent transparency by an explicit function or script. The transparency is assigned to the whole shape and cannot vary across it.

patternKey [a1   a2   a3 …  an]

It defines the values of the explicit diffuseColor, emissiveColor or specularColor function or script which will be used for mapping to patternColor.

patternColor [rgbrgb2 … rgbn]

It defines the colors which will be used for interpolating the color defined by an explicit diffuseColor, emissiveColor or specularColor function or script based on the current patternKey. Linear interpolation of colors will be done.

g=...;
patternValue(g);
The function is used in scripts to generate colors defined by patternKey and patternColor.

translation “x=x(t); y=y(t); z=z(t);”

It defines translation parameters by explicit functions or scripts.

scale “x=x(t); y=y(t); z=z(t);”

It defines scaling parameters by explicit functions or scripts.

rotation “x=x(t); y=y(t); z=z(t); a=a(t);”

It defines rotation parameters by explicit functions or scripts.

center “x=x(t); y=y(t); z=z(t);”

It specifies a function-defined translation offset from the origin of the local coordinate system (0, 0, 0).

scaleOrientation

“x=x(t); y=y(t); z=z(t); a=a(t);”

It specifies a function-defined rotation of the coordinate system before the scale (to specify scales in arbitrary orientations).

operation

 “union | intersection | difference”

or

operation “

frep(f,g,t){

function script; return frep(f,g,t);}”

 

Default: operation “union”

parameters [0]

In this field either a name of the predefined set-theoretic operation or an individual formula or script defining a set-theoretic operation on shapes defined by functions f(x,y,z,t) and g(x,y,z,t) have to be typed. The respective FShapes are to be defined as children of FTransform node. Set-theoretic operations do not apply to parametrically defined shapes.

timeSpan  t1   t2

  

 

Default: timeSpan  0  1

It defines a time interval of variable t when defining a time-dependent process (shape's geometry, color, texture or transformation). Variables t1 and t2 can take any real values including negative.

startTime  t

Default: startTime  0

It defines the values of time to start a time-dependent process.

stopTime  t

Default: stopTime  0

It defines the values of time to stop a time-dependent process.

cycleInterval  t

Default: cycleInterval  1

It defines the duration of the time-dependent process cycle in sec.

frames   n

Default: frames 0

It defines the number of frames to be cached. If 0 is defined, rendering time-dependent processes will be performed on the fly.

loop TRUE|FALSE

Default: loop FALSE

It enables or disables looping of time-dependent processes.

enabled TRUE|FALSE

Default: enabled TRUE

It enables or disables time-dependent processes.

trilinear(x,y,z,size_x,size_y,size_z,’filename’) This function is provided to support 8-bit raw CT/MRI data. Parameter x, y, and z represents the coordinates of the point to be evaluated. Parameter size_x, size_y and size_z indicates the dimension of the CT/MRI data. Parameter filename is a string, representing the volume data file. When the filename is a relative file name, it is a file relative to the C:/Program Files/FuncNodes/Processor directory of the plug-in. When the filename is an absolute file name, it reads the absolute file directly. When the filename is an URL of http, https or ftp, the function reads the file from the network according to the URL.
nurbs

Besides function scripts and analytical formulae, NURBS surface can also be defined in FVRML. When defining NURBS surface, the ‘type’ field in FGeometry should be set as ‘nurbs’. In the ‘definition’ field, write the definition of the NURBS surface. The definition of the NURBS surface is formatted as the follows:

‘uOrder <uOrder>

vOrder <vOrder>

uDimension <n>

vDimension <m>

uKnots [<uKnot1> <uKnot2> .. <uKnot n>]

vKnots [<vKnot1> <vKnot2> .. <vKnot m>]

controlPoint [<Point1_x> <Point1_y> <Point1_z> <Point2_x> <Point2_y> <Point2_z> .. <Point m*n_x> <Point m*n_y> <Point m*n_z>]

weight [<Weight1> <Weight2> .. <Weight m*n>]’

uDimension and vDimension define the number of control points in the u and v dimensions. uOrder and vOrder define the order of surface. uKnots and vKnots define the knot vectors.

controlPoint defines a set of control points of dimension uDimension * vDimension. This set of points defines a mesh similar to the grid of a ElevationGrid whereas the points do not have a uniform spacing. Depending on the weight-values and the order this hull is approximated by the resulting surface. #uDimension points define a polyline in u-direction followed by further u-polylines with the v-parameter in ascending order. The number of control points must be equal or greater than the order. A closed NURBS surface can be specified by repeating the limiting control points.

The control vertex corresponding to the control point P[i, j] on the control grid is :

    P[i,j].x = controlPoints[i + ( j × uDimension)].x

    P[i,j].y = controlPoints[i + ( j × uDimension)].y

    P[i,j].z = controlPoints[i + ( j × uDimension)].z

    P[i,j].w = weight[ i + (j × uDimension)]

    where 0 <= i < uDimension and 0 <= j < vDimension.

Back


FX3D Extension Description and Programming Examples

Preserving backward compatibility with FVRML, in function-based extension of X3D there are six concrete node types FShape, FGeometry, FAppearance, FMaterial, FTexture3D, and FTransform and one abstract node type X3DFunctionChildNode. The existing models designed using FVRML can be upgraded to FX3D with minimum efforts.

FShape node is designed to associate a function-defined geometry and a function-defined appearance, which is quite similar to Shape node. FShape may be used as a child of a function-defined operation, which results in the implementation of X3DFunctionChildNode.

FGeometry node is designed to define a geometry using any type of functions—implicit, explicit or parametric.

FAppearance node represents function-defined material, function-defined 3D geometric texture, and other regular appearance components (2D/3D image texture, texture transformation, etc.).

FMaterial node contains color information of a shape, including the function definitions used to describe the diffuse color.

 FTexture3D stores function definitions of a 3D geometric texture, such as vertex displacements.

FTransform defines affine transformations (i.e. translation, rotation, and scaling) as well as set-theoretic operations on function-defined shapes.

The detailed definitions of the function-based node types can be seen in FX3D.x3d.

FX3D examples:

If BS Contact VRML/X3D is used, make sure to deselect "resolve external XML resources" in Settings/Preferences/General.

For users of Xj3D, download fx3d.jar and copy it to the Xj3D root directory.

Back


Interactive Shape Modeling Tool

This application requires  BS Contact VRML/X3D to be installed. It works only with MS Internet Explorer and Mozilla Firefox. Make sure you have installed the most recent version of the FVRML plug-in.

Release notes:
1. Geometry and appearance are defined in their own coordinate systems and can be mutually interactively relocated to form a final shape.
2. Geometry and appearance can be changed in editing windows which can be displayed by clicking at Edit operation in Geometry and Appearance modes.
Mathematical operations and functions which can be used in formulas:
+,  - ,  *, /, ^, &, |
acos, asin, atan, atan2, cos, cosh, exp, fabs, fmod, log, log10, sin, sinh, tan, tanh, sqrt, ceil, floor, range, min, max
^           Power. E.g.  x^3 stands for x*x*x
&         
Set-theoretic "AND". The continuity of this function can be defined in parameters.
|           
Set-theoretic "OR". The continuity of this function can be defined in parameters.
range    When a>b and a<c, range(a,b,c)=1, otherwise, range(a,b,c)=0. This function is only provided for FRep shapes.
3. In the editing windows, the basic shape and tools definition functions and scripts are kept separated from the coordinate transformations and other parameters.
4. Any part constituting the shape can be edited by selecting it in Show Handle mode.
5. The models can be saved/loaded as well as exported to VRML.

Email problems to: Alexei Sourin


Selected Publications:


Copyright 2001-2022 A. Sourin
This material may not be published, modified or otherwise redistributed in whole or part without prior approval.