HyperspaceExplorer 0.7.1
Public Member Functions | Protected Member Functions | Protected Attributes

A four-dimensional Menger Sponge. More...

#include <Sponge.h>

Inheritance diagram for Sponge:
Inheritance graph
[legend]
Collaboration diagram for Sponge:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Sponge (unsigned _level=1, unsigned _distance=2, double _rad=0.8, VecMath::Vector< 4 > _center=VecMath::Vector< 4 >(0., 0., 0., 0.))
 Sponge constructor.
virtual ~Sponge ()
 Sponge destructor.
virtual std::string getFunctionName () const
virtual void Transform (const VecMath::Rotation< 4 > &R, const VecMath::Vector< 4 > &T, const VecMath::Vector< 4 > &scale)
 Transforms a Sponge.
virtual void Project (double ScrW, double CamW, bool DepthCue4D)
 Projects a Sponge into three-space.
virtual void Draw (UI::View *view)
 Draw the projected Sponge (onto screen or into GL list, as it is)
virtual void SetParameters (const ParameterMap &parms)
 Set parameters to the Displayable.
virtual void ReInit (double, double, double, double, double, double, double, double, double)
 Rebuild the Sponge if the parameters have changed.
virtual std::string description ()

Protected Member Functions

virtual void Initialize ()
 This function actually creates the hypersponge.
virtual unsigned long MemRequired (unsigned)
 return the approximate amount of memory needed to display a sponge of current level and given distance

Protected Attributes

unsigned Level
 Level of the hypersponge.
std::vector< Hypercube * > List
 List of sub-sponges (see Initialize())
int distance
 max. distance (see Initialize())
double rad
 radius, more correctly size, of the sponge
VecMath::Vector< 4 > center
 center of the sponge

Detailed Description

A four-dimensional Menger Sponge.

A Menger Sponge in three dimensions is a fractal produced by subdividing a cube and taking away parts of the cube which get subsequentally smaller. The level parameter controls how often this process is repeated, i.e. how many holes there are in the final object.

A four-dimensional Menger Sponge is created analogously from a hypercube.

The fractal can be further controlled by the distance parameter:


Constructor & Destructor Documentation

Sponge::Sponge ( unsigned  _level = 1,
unsigned  _distance = 2,
double  _rad = 0.8,
VecMath::Vector< 4 >  _center = VecMath::Vector<4>(0., 0.,0., 0.) 
)

Sponge constructor.

Construct a Hypersponge of level level.

Parameters:
_levelhypersponge level
_distancedistance of subcubes to center to be counted as part of the fractal
  • = 0: solid hypercube
  • = 1: foam
  • = 2: sponge
  • = 3: dust
  • >= 4: nothing
_radside_length/2
_centercenter
_levelLevel of recursion used in creating the Sponge
_distancesee Initialize()
_radSize of the Sponge - _rad is half the side length
_centerCenter point of the Sponge

References Displayable::declareParameter(), and Initialize().

Here is the call graph for this function:


Member Function Documentation

virtual std::string Sponge::description ( ) [inline, virtual]
Returns:
A string with a description of the Hypersponge object

Reimplemented from Hypercube.

References std::ends(), and Level.

Here is the call graph for this function:

void Sponge::Draw ( UI::View view) [virtual]

Draw the projected Sponge (onto screen or into GL list, as it is)

Draws all sub-sponges, recursively.

Reimplemented from Hypercube.

References UI::View::commitDraw(), Level, List, and std::vector< _Tp, _Alloc >::size().

Here is the call graph for this function:

virtual std::string Sponge::getFunctionName ( ) const [inline, virtual]
Returns:
The name of the Displayable in cleartext

Reimplemented from Hypercube.

void Sponge::Initialize ( void  ) [protected, virtual]

This function actually creates the hypersponge.

It views it as an assembly of $ 3^4 $ smaller sponges, slicing the sponge in three sub-sponges in every one of the four dimensions, and then taking away some of the resulting 81 smaller sub-sponges.

  • if the parameter distance is zero, it only removes the sub-sponge with distance 0 from the center, i.e. the one at the center.
  • if the parameter distance is one, it only removes the sub-sponges with distance <= 1, amounting to nine removed sub-sponges. The three- dimensional surface of the hypercube enveloping the sponge is not breached, because the surface of a hypercube is two units away from the center, instead of one unit, as in 3D.
  • if distance = 2, the holes reach the hypercubes surface, giving an object analogous to the three-dimensional Menger Sponge.
  • if distance = 3, only the 16 corners of the hypercube remain, giving four-dimensional fractal dust.

If the level of the sponge is 1, the sub-sponges are hypercubes. Otherwise, they are Hypersponges with a level reduced by 1.

Reimplemented from Hypercube.

References abs(), center, std::cerr, distance, std::endl(), Loki::SingletonHolder< T, CreationPolicy >::Instance(), Level, List, Displayable::MemRequired(), std::vector< _Tp, _Alloc >::push_back(), and rad.

Referenced by Sponge().

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned long Sponge::MemRequired ( unsigned  distance) [protected, virtual]

return the approximate amount of memory needed to display a sponge of current level and given distance

Todo:
uses hardcoded and experimentally found value for memory per hypercube
Parameters:
distancesee Initialize()
Returns:
approx. mem required

References Level, and pow().

Here is the call graph for this function:

void Sponge::Project ( double  scr_w,
double  cam_w,
bool  depthcue4d 
) [virtual]

Projects a Sponge into three-space.

The projection is achieved by projecting all constituting sub-sponges.

Parameters:
scr_ww coordinate of screen
cam_ww coordinate of camera
depthcue4dwheter to use hyperfog/dc

Reimplemented from VertexHolder< 4, 1, double >.

References List, and std::vector< _Tp, _Alloc >::size().

Here is the call graph for this function:

virtual void Sponge::SetParameters ( const ParameterMap ) [inline, virtual]

Set parameters to the Displayable.

Todo:
This function is only there to provide an interface, and it's not abstract so that Displayable s which don't have Parameters don't need to reimplement an unneeded method. But the present implementation does not make sense.

Reimplemented from Hypercube.

References std::map< _Key, _Tp, _Compare, _Alloc >::begin(), std::cerr, distance, std::map< _Key, _Tp, _Compare, _Alloc >::end(), Level, rad, Displayable::setParameter(), and ParameterMap::toString().

Here is the call graph for this function:

void Sponge::Transform ( const VecMath::Rotation< 4 > &  R,
const VecMath::Vector< 4 > &  T,
const VecMath::Vector< 4 > &  scale 
) [virtual]

Transforms a Sponge.

The transformation is achieved by transforming all constituting sub-sponges.

Parameters:
Rrotation
Ttranslation

References List, and std::vector< _Tp, _Alloc >::size().

Here is the call graph for this function:


Member Data Documentation

List of sub-sponges (see Initialize())

Todo:
Use smart pointers instead of a simple pointer-to-object

Referenced by Draw(), Initialize(), Project(), ReInit(), Transform(), and ~Sponge().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends

Generated on Mon Apr 9 2012 20:25:18 for HyperspaceExplorer 0.7.1 by doxygen 1.7.4  -  Hosted bySourceForge.net Logo