14 #include "MatrixAlg.h"
16 #include "WhiteNoise.h"
20 namespace Architecture
82 CDebugInfo() : filename(
""), line(-1), column(-1) {}
97 virtual DebugAction debug(
const char* filename,
int line,
int column,
CEvaluator* evaluator) = 0;
279 CRule&
var(String identifier, String value,
bool constant);
281 CRule&
snap(String dir, String
id, String radius);
287 CRule&
move(String x, String y, String z);
318 CRule&
loft_box(String positions, String widths, String depths);
323 CRule&
module(String name, String generations =
"-1");
352 CRule&
repeat_x(String length, String module, String flex =
"flex", String snap =
"");
354 CRule&
repeat_y(String length, String module, String flex =
"flex", String snap =
"");
356 CRule&
repeat_z(String length, String module, String flex =
"flex", String snap =
"");
359 CRule&
parameter(String name, String value, String module, String flex =
"flex");
404 void loadFromFile(
const char* filename,
char* debugfile = NULL);
446 String material) = 0;
479 int maxgeneration = -1);
496 CNode* startNode = NULL);
511 TVector<float>& points);
538 DebugAction debugAction;
String widths
Contains the list of widths for the loft.
CRule & center_xy()
Moves the scope's pivot to the scope's geometric center along the XY plane.
float dx
Scope translation along X axis.
TMap< String, String > variables
Variables defined for the node and children.
float dy
Scope translation along Y axis.
CreateInstance * instancer
Pointer to the create instance callback.
String positions
A list of positions for the loft.
float y
Scope origin along Y axis.
CRule & if_occluded_rule(String scope, String volumeId, String margin)
Adds occlusion test.
void findSnapPoints(String &id, Algebra::Vector segments[4][2], TVector< float > &points)
Given four segments in a scope, this function return the intersection points between the segments and...
Algebra::Matrix cachedMatrix
To speed up processing, the transformation matrix can be cached at some point.
CRule & align(String dir)
Aligns the scope along the specified axis.
CRule & var(String identifier, String value, bool constant)
Defines a variable.
Defines a box loft primitive.
CRule & loft_ngon(String sides, String positions, String radii)
Defines a ngon loft primitive.
TMap< String, String > attributes
A list of parameters for the action.
CRule & subdivide_prism(String position, String center, String top, String left, String right)
Divide a prism scope.
CRule & snap(String dir, String id, String radius)
Defines a snap plane.
int sides
Number of sides in the ngon loft.
CBoxLoftVolume boxLoft
Box loft primitive for the node.
Contains all classes and functions for the VoxelFarm engine.
String radii
A list of radii for the loft.
CRule & ngon(String sides)
Defines a ngon primitive.
CGrammar * currentGrammar
Current grammar being evaluated.
Defines a node in the program tree.
bool isOccluded(CNode *node, String volumeId, bool partial)
Tests whether the provided node is occluded.
bool active
Flags whether the primitive is active or not.
CModule * currentModule
Current module being evaluated.
CDebugInfo debugInfo
Debug information for the action.
This object can be used to evaluate a grammar.
CRule & rotate_x(String angle)
Defines a rotation over the X axis.
virtual void createInstance(String id, Algebra::Matrix &matrix, Algebra::Vector &size, ScopeType scopeType, String material)=0
Requests the creation of an instance. The IInstanceCreator interface provides an alternative to this ...
CNode * parent
Pointer to parent node.
String depths
Contains the list of depths for the loft.
float pz
Scope pivot along Z axis.
void saveToFile(const char *filename)
Saves the program to a file name.
TMap< String, TVector< CRule > > rules
Maps rules to identifiers. A single identifier can be shared by many rules.
TVector< String > conditionals
List of conditional statements for the rule.
int generation
Counts the tree generation for the node.
CNGonVolume ngon
Ngon primitive for the node.
TVector< CNode * > children
List of children nodes.
CRule & material(String id)
Set the node's material.
TVector< String > occlusionMargins
List of occluding margins for occlusion tests.
void recurse(String rule)
Evaluates the specified rule and then any other rules it may spawn.
String baseAxiom
Stores the base axiom.
CRule & repeat_z(String length, String module, String flex="flex", String snap="")
Repeat module along Z axis.
NodeType
Enumerates node types for a grammar program.
CRule & begin(String name)
Starts the definition of a new rule object.
TVector< std::pair< CNode *, String > > recursePending
List of child nodes that still require processing.
CRule & center_z()
Moves the scope's pivot to the scope's geometric center along the Y axis.
bool yaligned
Flags whether the scope is aligned along the Y axis.
CRule & move(String x, String y, String z)
Defines a translation statement.
CNode root
Root node for the evaluation tree.
TMap< String, TVector< SnapPlane > > snapPlanes
Stores snap planes according to their IDs.
void CreateInstance(String id, Algebra::Matrix &matrix, Algebra::Vector &size, ScopeType scopeType, String material)
A callback to request the creation of an instance. The IInstanceCreator interface provides an alterna...
float z
Scope origin along Z axis.
bool evaluatePending(CNode *node, int maxgeneration=-1)
Evaluate any pending rules.
int type
Node type (see ActionType)
float sy
Scope size along Y axis.
CRule & rotate_y(String angle)
Defines a rotation over the Y axis.
CRule & occludes(String volumeid)
Declares the current scope may occlude other scopes.
float sx
Scope size along X axis.
CRule & select(String stype, String module)
Select a primitive feature and invoke module within it.
Defines a ngon loft primitive.
CRule & instance(String geometry)
Instances a geometry mesh.
CNode * context
Pointer to the node where the rule is being exectuted.
IInstanceCreator * instanceCreator
Pointer to the create instance interface.
TMap< String, float > parameters
A set of parameters supplied to the evaluator.
bool xaligned
Flags whether the scope is aligned along the X axis.
bool active
Flags whether the primitive is active or not.
bool matrixCacheValid
Indicates whether the cache transformation maxtrix is still valid.
CModule & axiom(String name)
Declares the starting rule object.
ActionType
Enumerates instructions for the grammar virtual machine.
IDebugger * debugger
Interface to a debugger.
CRule & rotate_z(String angle)
Defines a rotation over the Z axis.
TVector< std::pair< CNode *, String > > deferred
List of child nodes that requested deferred processing.
Contains four co-planar 3D points that define a snap plane.
String material
Stores the material ID set for the node.
CModule & define(String name)
Starts the definition of a program.
CRule & push()
Pushes the current state into the stack.
ActionType type
Action type.
TMap< String, CModule > modules
A grammar contains several module programs. Each program is identified by a String.
ScopeType type
Scope type (whether it is a box or a prism, etc)
CRule & center_yz()
Moves the scope's pivot to the scope's geometric center along the YZ plane.
float ax
Scope rotation angle over X axis.
RTree< CNode *, float, 3, float, 20 > OccluderIndex
RTree to accelerate occlussion test.
bool evaluateDeferred(CNode *node, int maxgeneration=-1)
Evaluate any rules that may have been deferred.
void defer(CNode *child, String module)
Defers a new execution subtree generation from this child, applying the specified grammar module...
CModule & end()
Used for fluent inteface decalaration. Ends a series of rule declarations and returns a reference to ...
void newGeneration(CNode *child, String module)
Starts a new execution subtree generation from this child, applying the specified grammar module...
CRule & center()
Moves the scope's pivot to the scope's geometric center.
int sides
Sides in the ngon.
TVector< String > occlusionScopes
List of occluding modes for occlusion tests (partial, full, front, back)
String module
Stores the ID of the grammar module that originated the node.
TVector< String > occlusionVolumeIds
List of occluding IDs for occlusion tests.
CRule & repeat_x(String length, String module, String flex="flex", String snap="")
Repeat module along X axis.
A Matrix for 3D operations.
bool active
Flags whether the primitive is active or not.
Encapsulates a series of actions to be performed over a node. This is equivalent to a "module" statem...
float px
Scope pivot along X axis.
CRule & subdivide_z(String pattern, String modules)
Divide the current scope along the Z axis.
CRule & subdivide_x(String pattern, String modules)
Divide the current scope along the X axis.
CRule & parameter(String name, String value, String module, String flex="flex")
Defines a parameter.
This interfaces allows the grammar evaluator to delegate creation of instances.
CRule & loft_box(String positions, String widths, String depths)
Defines a box loft primitive.
bool occludes
Indicate whether this module may occlude other modules.
CRule & center_xz()
Moves the scope's pivot to the scope's geometric center along the XZ plane.
TMap< String, String > localNames
Contain a list of aliases for occlusion and snap identifiers so they can be local to a portion of the...
void run(CGrammar &grammar, String module, CreateInstance *instancer, int maxgeneration=-1)
Runs a grammar program.
bool zaligned
Flags whether the scope is aligned along the Z axis.
TVector< CAction > actions
List of actions to be performed by the node.
float az
Scope rotation angle over Z axis.
CRule & module(String name, String generations="-1")
Invokes a module.
CBoxVolume box
Box primitive for the node.
CRule & pop()
Pops the current state into the stack.
CRule & local(String volumeid)
Creates an alias for the specified Id so queries can be localized from this point on...
Defines a ngon primitive.
float eval(String exp, float total=-1.0f, CNode *startNode=NULL)
Evaluates an expresion.
CRule & subdivide_y(String pattern, String modules)
Divide the current scope along the Y axis.
A grammar is a collection of programs.
CRule & box()
Defines a box primitive.
CRule & center_y()
Moves the scope's pivot to the scope's geometric center along the Y axis.
CRule & prism(String type)
Defines a prism primitive.
float dz
Scope translation along Z axis.
CNode * currentNode
Current evaluation node.
double rootOffsetX
Position of the root node in world coordinates. It is used for the rnd command.
ScopeType
Enumerates possible scope types.
CModule & add(CRule &rule)
Adds a rule.
float ay
Scope rotation angle over Y axis.
CRule & condition(String exp)
Defines a conditional.
void loadFromFile(const char *filename, char *debugfile=NULL)
Loads a program from a file name.
int guid
Keeps an ever-incrementing counter used to generate unique aliases for local features.
TMap< String, OccluderIndex * > occluders
Store occludes according to their IDs.
float sz
Scope size along Z axis.
CRule & scale(String x, String y, String z)
Defines a scale statement.
CNGonLoftVolume ngonLoft
Ngon loft primitive for the node.
CScope scope
Scope for the node.
CRule & defer(String name)
Deferred invocation for a module.
TVector< CAction > actions
List of actions for the rule.
float x
Scope origin along X axis.
String positions
Contains the list of positions for the loft.
CModule * parent
Pointer to the module that owns the rule.
CRule & center_x()
Moves the scope's pivot to the scope's geometric center along the X axis.
bool hasLocalNames
Indicates whether the node has local aliases.
bool active
Flags whether the primitive is active or not.
float py
Scope pivot along Y axis.
CRule & repeat_y(String length, String module, String flex="flex", String snap="")
Repeat module along Y axis.
Defines a single action and its parameters.