sonus::SvgLoader Class Reference

#include <SvgLoader.h>

List of all members.

Public Member Functions

 SvgLoader ()
 ~SvgLoader ()
Level2DloadLevel (const char *fileName, int interpolationSteps=4, bool debug=false)
int calcResultSize (int interpolationSteps)
int calcResultSize (Body2D< Element2D > *source, int interpolationSteps)
void interpolateBezierBody (Body2D< Element2D > *source, Body2D< Vector2D > *target, int interpolationSteps=4)
Vector2DinterpolateBezierBody (Body2D< Element2D > *source, int interpolationSteps=4)
int interpolateBezier (Bezier2D *b, Vector2D *v, int interpolationSteps=4)
void parseSvg (const char *pFilename)
char * addDivisor (const char *source, char insertBefore, char insertSign)
double * tokenizeSvgCommandInputs (const char *command, int amountCoordinates)
void executeSvgCommandString (const char *sourceString, Body2D< Element2D > *targetBody)


Detailed Description

sonus::SvgLoader

Loads a SVG ("Scalable Vector Graphics") file containing the game level and formats it to make it accessible for other modules.

filename: SvgLoader.h

Date:
Jan 04 2008 15:05
Author:
Raphael Estrada
Version:
0.5
Note:
Every Bezier2D has 4 Points, which means there are always two vectors in the middle with the same coordinates. Whoever wants to draw from one vector to the next must check for identical coordinates and skip them (for now...)
Todo:
Maybe the SvgLoader can create an interpolated Vector-Array with only relative coordinates, if any module should need that. In that function, the SvgLoader could filter out any double vectors (see note above)

The (private) variables SvgLoader::worldBezier and SvgLoader::worldVector could possibly be left out and the data could be directly saved into the corresponding worldBezier2D and worldVector2D objects of the appropriate Level2D object.

Make the SvgLoader more compatible to slight differences in the SVG XML code. It is not very flexible/usable for example when using other programs to generate the SVGs. It should at least be able to take Inkscape (free tool) SVG files.

Bug:
Crashes when a path does not have a fill color. Catch that exception and end in a controlled way.

Constructor & Destructor Documentation

sonus::SvgLoader::SvgLoader (  ) 

Default constructor

sonus::SvgLoader::~SvgLoader (  ) 

Destructor


Member Function Documentation

Level2D* sonus::SvgLoader::loadLevel ( const char *  fileName,
int  interpolationSteps = 4,
bool  debug = false 
)

Creates a Level2D object from an SVG file and returns a pointer to it. Interpolation steps is set to 4 by default when no explicit number of steps is given.

Parameters:
fileName A string name of the SVG file that is to be loaded.
interpolationSteps The number of recursive interpolation steps.
Returns:
The generated level as a Level2D object.
Warning:
Number of Vector2D object grows exponentially with the size of interpolationSteps!
See also:
SvgLoader::calcResultSize() for details about the exponential growth

int sonus::SvgLoader::calcResultSize ( int  interpolationSteps  ) 

Calculate how many Vectors would result from interpolating a single Bezier2D depending on the amount of interpolation steps.

Parameters:
interpolationSteps The number of interpolation steps as a base for the calculation.
Returns:
The number of Vector2D objects that would result from interpolation a single Bezier2D.
Note:
1 step => ( (2^(1-1)) * 8 ) = 8 Vector2D points for a single Bezier2D

int sonus::SvgLoader::calcResultSize ( Body2D< Element2D > *  source,
int  interpolationSteps 
)

Calculate how many elements would result from interpolating every Bezier2D in a specific Body2D.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
source Pointer to a Body2D object that contains all the Bezier2D objects to be counted.
interpolationSteps The number of interpolation steps as a base for the calculation.
Returns:
The amount of Vector2D elements that would result from interpolating the body.
Note:
1 step => ( (2^(1-1)) * 8 ) = 8 Vector2Ds for a single Bezier

void sonus::SvgLoader::interpolateBezierBody ( Body2D< Element2D > *  source,
Body2D< Vector2D > *  target,
int  interpolationSteps = 4 
)

Transforms all of a Body2D objects Bezier2Ds into Vector2Ds. Size of resulting Array depends on the given amount of interpolationSteps. Adds every resulting Vector2D into target.

Parameters:
source Pointer to a Body2D object that contains all the Bezier2D objects to be interpolated.
target Pointer to a Body2D object in which the Vector2D objects are to be saved in during the interpolation process.
interpolationSteps The amount of times the Beziers are to be interpolated.
Warning:
Number of Vector2D object grows exponentially with the size of interpolationSteps!

Vector2D* sonus::SvgLoader::interpolateBezierBody ( Body2D< Element2D > *  source,
int  interpolationSteps = 4 
)

Takes a Body2D and transforms all of it's Bezier2Ds into Vector2Ds. Size of returned array depends on the given amount of interpolationSteps.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
source Pointer to a Body2D object that contains all the Bezier2D objects to be interpolated.
interpolationSteps The amount of times the Bezier2D objects are to be interpolated.
Returns:
A pointer to an array of Vector2D objects being the result of the interpolation.
Warning:
size grows exponentially with the number of interpolationSteps given!
See also:
SvgLoader::calcResultSize() for details about the exponential growth.

int sonus::SvgLoader::interpolateBezier ( Bezier2D b,
Vector2D v,
int  interpolationSteps = 4 
)

Recursive. Takes a Bezier2D and splits it into Vector2Ds as many times as requested. Returns the size of the Array that is added into the given position. This is only the size that results from splitting the single given Bezier2D.

Parameters:
b Pointer to a single Bezier2D object that is to be interpolated.
v Address of the position in a Vector2D array where the generated Vector2D objects (which are also stored in an array) are to be added in.
interpolationSteps The amount of times the Bezier2D is to be interpolated.
Returns:
The size of the generated array of Vector2D objects being the result that will be written into the address at the parameter v.

void sonus::SvgLoader::parseSvg ( const char *  pFilename  ) 

Parses an SVG at fileName, reads it's commands and executes them. Adds all paths to the object at SvgLoader::level

Parameters:
pFilename A string containing the name of the SVG file that will be parsed.

char* sonus::SvgLoader::addDivisor ( const char *  source,
char  insertBefore,
char  insertSign 
)

Takes a string and adds a certain char insertSign before the given char insertBefore. Returns a new, extended string

Parameters:
source The string that is to be processed.
insertBefore The character this function will look out for and add insertSign before each time.
insertSign The character to be added before every character defined in insertBefore.
Returns:
A new string containing the result being the new extended version of source.

double* sonus::SvgLoader::tokenizeSvgCommandInputs ( const char *  command,
int  amountCoordinates 
)

Returns an array with the input values for each SVG command. In that array are all coordinates as doubles for the first command starting at the pointer command.

Parameters:
command The string containing the command from the SVG file containing all the data to be processed.
amountCoordinates The amount of coordinates will define the size of the returned array.
Returns:
A double array with the input values for each SVG command.

void sonus::SvgLoader::executeSvgCommandString ( const char *  sourceString,
Body2D< Element2D > *  targetBody 
)

Executes the SVG-Path-Commands contained in sourceString, using a BodyBuilder on targetBody.

Parameters:
sourceString The string containing the command from the SVG file containing all the data to be processed.
targetBody A Body2D container that will receive either Bezier2D or Vector2D objects, depending on the commands within the string sourceString.


The documentation for this class was generated from the following file:
Generated on Tue Aug 26 12:26:54 2008 for sonus by  doxygen 1.5.4