POV-Ray : Newsgroups : povray.advanced-users : Memory handling and cloning of object : Memory handling and cloning of object Server Time
28 Sep 2024 18:55:01 EDT (-0400)
  Memory handling and cloning of object  
From: Techdir
Date: 8 Sep 2010 05:05:01
Message: <web.4c875089bf4745b03b9159050@news.povray.org>
Having been away from POV since version 2-ish, I came back to it recently and
have been tinkering with an image. The image consists of a multi-floored
building with lots of intricate balconys that I was trying to replicate down
both sides of a street. The entire lot was constructed with nested #while loops
and pretty quickly I'd blown the 3GB memory limit on my windows box.

Now I can (and will) reduce the primitve count of the main object that are being
replicated, but that is just delaying the inevitable. If I increased the length
of the street by one or two more copies I'll be right back up against the memory
limitations.

I thought, perhaps somewhat naively, that when you #declare an object and then
use it multiple times that you don't actually recreate the entire set of objects
within for each instance. surely you'd just apply the inverse of the
transformation applied to the instance of the object to the ray and then use the
object declaration for the intersection tests. If this were the case then
cloning a large object heirarchy should just be a case of the memory involved in
storing the inverse transformation, the top level bound-volume in local
coordinates and whatever pointers link the object into the list of objects; in
all significantly less than reproducing a huge object heirarchy repeatedly.


To investigate this I drew up a quick test file:

// ---------------------------------------------------------------
// Persistence Of Vision raytracer version 3.5 sample file.

#include "colors.inc"

#declare UseDeclaration=1;

#declare BallDiameter = 1.0;
#declare BlockSize = 10;
#declare RepeatSize = 5;

// Camera is reasonably irrelevant, we're interested in total memory storage for
the scene.
camera { location <-10,10,-10> direction z look_at <0,0,0> }

// Create a cube of spheres
#macro SphereBlock(SB_BallDiameter,SB_BlockSize)
union
{
#local lx = 0;
#while (lx<SB_BlockSize)
#local ly = 0;
#while (ly<SB_BlockSize)
#local lz = 0;
#while (lz<SB_BlockSize)
sphere { <SB_BallDiameter*lx,SB_BallDiameter*ly,SB_BallDiameter*lz>
SB_BallDiameter/2 }
#local lz = lz+1;
#end // lz
#local ly = ly+1;
#end // ly
#local lx = lx+1;
#end // lx
}
#end // SphereBlock

// Declare a cube of spheres for replication
#declare SphereBlockDec = object { SphereBlock(BallDiameter,BlockSize) };

// Instantiate 25 of the cubes of spheres
object
{
union
{
#declare rx =0;
#while (rx<RepeatSize)
#declare ry =0;
#while (ry<RepeatSize)

#ifdef (UseDeclaration)
    object { SphereBlockDec translate
<BlockSize*BallDiameter*rx,BlockSize*BallDiameter*ry,0> texture { pigment {
colour Red } finish { ambient 0.5 } } }
#else
    object { SphereBlock(BallDiameter,BlockSize) translate
<BlockSize*BallDiameter*rx,BlockSize*BallDiameter*ry,0> texture { pigment {
colour Green } finish { ambient 0.5 } }}
#end

#local ry = ry+1;
#end // ly
#local rx = rx+1;
#end // lx
}
}
// ---------------------------------------------------------------


The UseDeclaration declaration on line6, is intended to control the behaviour of
the system. If enabled it uses a #declare which should instantiat 25 groups of
1000 spheres, otherwise it invokes the macro directly creating all 25,000
spheres individually.

In both cases the finite objects as given as 25,000 and peak memory as 11898018
bytes. Both are fairly coarse measures, but I read this as saying that the
system has done exactly the same thing in both cases, ie. create 25,000 spheres.


My question is: is it possible to "clone" a complex object heirarchy so that
multiple copies can be utilised without significant memory overheads? If so,
how? Trawling through the documentation didn't show up anything obvious.


Thanks

Brian


Post a reply to this message

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