POV-Ray : Newsgroups : povray.general : Trouble parsing recursive macro : Trouble parsing recursive macro Server Time
31 Jul 2024 08:27:05 EDT (-0400)
  Trouble parsing recursive macro  
From: barton
Date: 28 Jul 2007 13:30:02
Message: <web.46ab7a3b6b420bc8e071738a0@news.povray.org>
I'm creating a fairly simple recursive macro which creates a 10x10x10 cube,
and based on the level of recursion, breaks down each sub cube into
10x10x10 cubes, which may be in turn broken down into 10x10x10 cubes...

[take a look at
http://loudsl01-253-100-25.iglou.com/~tiger/pov_images/cube1.png]

Here's the source:

// by Barton Chittenden, based on PYRAMID2.POV by Chris Young

// Define the macro.  Parameters are:
//   X:  position of lower/right/forward block
//   Y:  position of lower/right/forward block
//   Z:  position of lower/right/forward block
//   E:  Length of edge of cube
//   L:  level of recursion

#macro Cube(X,Y,Z,E,L)

  #local Side = E * 0.80;
  #if ( L = 0)
        box { <X,Y,Z>, <X+Side,Y+Side,Z+Side>
                //pigment{color <R,G,B> }
        }
  #end // if recusion is false

  #if (L > 0)
    # local New_L = L - 1;
    # local New_E = Side / 10;
    # local i = 0;
    # local j = 0;
    # local k = 0;

    #while(i < 10)
        #while(j < 10)
                #while(k < 10)
                        Cube(
                                X+i*New_E,
                                Y+j*New_E,
                                Z+k*New_E,
                                New_E, New_L
                                )
                        #declare k = k+1;
                #end // Xhile k
                #declare k = 0;
                #declare j = j+1;
        #end // while j
        #declare j = 0;
        #declare i = i+1;
    #end // while i
  #end // if recursion is true
#end // macro Cube


union {
  Cube(-cube_radius,0,-15,10,2)

  pigment { color rgb <1,0,0> }
}

light_source { <2,20,-10> color rgb <1,1,1> }
light_source { <2,10,-20> color rgb <1,1,1> }

background { color rgb <0, 0, 0> }

// Cube is 10 units wide... sub cubes

camera {
        right x
        location <0,3*cube_radius,-25>
        look_at  <0,0,-3.5>
}

The trouble that I'm having is that I'm running out of memory because there
are numerous tokens created for each sub cube. If I use

Cube(-cube_radius,0,-15,10,1)

I'm fine; it creates 1002 objects (one for each sub cube, then two lights).

the render shows:

  0:00:00 Parsing
  0:00:00 Creating bounding slabs
  0:00:00 Creating vista buffer
  0:00:00 Creating light buffers 209K tokens

Indicating roughtly 200 tokens/sub cube

If I increase the recursion level to 2:

Cube(-cube_radius,0,-15,10,2)

I try to render, and it bottoms out at

0:02:12 Parsing 207628K tokens

Now most of the sub cubes are hidden, but because there is some space
between the sub cubes, there are areas where you can see all the way
through the cube. I'm trying to figure out a way of not parsing the sub
cubes that I can't see so that I don't swamp the memory, yet I want to make
sure that the parts of the
structure which are visible actually show correctly.

I'm not stuck on recursion, although that seems to be the simplest way of
generating a structure of this type.

Any thoughts?


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.