Noise Modeler Library  0.1
Library for procedurally generating noise-based terrains and other content
 All Classes Files Functions Variables Enumerations Enumerator Groups Pages

Graph representation of a procedural generator. More...


file  model.hpp
 The model module.


class  nm::Graph
 A graph of Modules. More...
class  nm::InputLink
 Describes which output of which node a ModuleInput of a specific Module is connected to. More...
class  nm::Module
 An instantiated ModuleType. A node in a function graph. More...
class  nm::ModuleInput
 Describes one of a ModuleType's inputs (name, SignalType, default value). More...
class  nm::ModuleOutput
 Describes one of a ModuleType's outputs (name, SignalType) More...
class  nm::ModuleType
 Describes a recipe for a module and its inputs and outputs. More...
class  nm::OutputLink
 an output of a Module More...
class  nm::SignalType
 Describes a the dimensionality of a signal Can be extended to include other type information such as distinctions between doubles, flots and ints as well. More...
class  nm::SignalValue
 A vector of floats that can be set as the unlinked value of InputLinks. More...
class  nm::TypeManager
 The top-level entity of a noise model. Encapsulates several user types as well as built-in types. More...

Detailed Description

Graph representation of a procedural generator.

The model contains classes for representing module types and graphs of modules.

The top-level entity, is the TypeManager, which may contain several ModuleTypes. A ModuleType represents a mathematical function or algorithm. It is either a primitive type defined by the library, or a composite type described as a Graph of Modules.

When a ModuleType is described by a Graph of Modules, it is called a composite type.

A Graph is a directed acyclic graph of function calls (Modules). It is a similar concept to what is commonly known as an expression tree.

Each node in the Graph, is called a Module. A module represents a function call, and has a corresponding ModuleType, and information about the inputs and outputs of the function call. A Module has several InputLinks that may be connected to OutputLinks of other Modules.

Here is an example of how the expression abs(0.25+fbm(x,y)) may be created using the model:

//A type manager holds information about module types
TypeManager typeManager;
//Initialize common module types, such as add, abs, and fbm2d
//create a module type representing our terrain function
ModuleType *terrainType = typeManager.createModuleType("terrain")
//Add inputs and outputs to the module type
//create a 2D input, "pos"
terrainType->addInput("pos", SignalType{2})
//create a 1D output, "height"
terrainType->addOutput("position", SignalType{2})
//get a handle for the graph of the module type
Graph *graph = terrainType.getGraph();
Module *inputs = graph->getModule("inputs");
Module *outputs = graph->getModule("outputs");
//create modules for the fbm (2d), add (1d), abs (1d)
Module* fbmModule = graph->createModule(*typeManager.getBuiltinType("fbm2"));
Module* addModule = graph->createModule(*typeManager.getBuiltinType("add1"));
Module* absModule = graph->createModule(*typeManager.getBuiltinType("abs"));
//connect fbm to position
//connect add input to fbm output
//set the right hand side to 0.25
//set abs source to add output
//connect abs output to module type output
//we now have a complete model for a heightmap generating
//module type: terrainType
//use the terrainType to evaluate some terrain, or serialize it to disk