POV-Ray : Newsgroups : povray.advanced-users : Multi-usage of an object Server Time
31 Oct 2024 14:11:44 EDT (-0400)
  Multi-usage of an object (Message 1 to 8 of 8)  
From: McHannemann
Subject: Multi-usage of an object
Date: 19 May 2006 13:35:00
Message: <web.446e016163aa8a2192b08d80@news.povray.org>
I have the following problem:
I have a list of objects which I want to use several times,
a list with the positions is created and I create the object this way:

#while(counter < Number )
 object{List[position[counter]] transform Transfer[counter]}
 #declare counter = counter + 1;
 #if (mod(counter,10)=0)
  #debug concat(str(counter,0,0),"..")
 #end
 #if (mod(counter,100)=0)
  #debug "n"
 #end
#end

now to my question,
this way I create 50000 pieces of one object
and I get 800MB memory usage,


with nearly no memory consumption..what do I wrong in this case????

Help is very much appreciated,
Regards,

Thor


Post a reply to this message

From: Jim Charter
Subject: Re: Multi-usage of an object
Date: 19 May 2006 14:51:19
Message: <446e13a7$1@news.povray.org>
McHannemann wrote:
> I have the following problem:
> I have a list of objects which I want to use several times,
> a list with the positions is created and I create the object this way:
> 
> #while(counter < Number )
>  object{List[position[counter]] transform Transfer[counter]}
>  #declare counter = counter + 1;
>  #if (mod(counter,10)=0)
>   #debug concat(str(counter,0,0),"..")
>  #end
>  #if (mod(counter,100)=0)
>   #debug "n"
>  #end
> #end
> 
> now to my question,
> this way I create 50000 pieces of one object
> and I get 800MB memory usage,


> with nearly no memory consumption..what do I wrong in this case????
> 
The idea of reusing an object with little additional memory cost relates 
to objects that themselves have components such as the mesh{} object and 
the blob{} object.  But the initial declaration of a mesh{}, say, will 
require lots of memory if it is comprised of many triangles.  However 
once declared, it can be instanced multiple times without additionally 
multiplying the memory needs.
IE.
#declare M =
mesh {
     triangle {...},
     triangle {...},
     ...
     triangle {...}
};

LOOP
     object { M transform {...} }
END LOOP


BUT
This effect cannot be achieved by unioning a group of objects:

#declare U =
union {
     triangle {...},
     triangle {...},
     ...
     triangle {...}
};

LOOP
     object { U transform {...} }
END LOOP
would multiply the memory cost


Post a reply to this message

From: McHannemann
Subject: Re: Multi-usage of an object
Date: 20 May 2006 01:50:01
Message: <web.446eadd0f11d153f92b08d80@news.povray.org>
> The idea of reusing an object with little additional memory cost relates
> to objects that themselves have components such as the mesh{} object and
> the blob{} object.  But the initial declaration of a mesh{}, say, will
> require lots of memory if it is comprised of many triangles.  However
> once declared, it can be instanced multiple times without additionally
> multiplying the memory needs.
> IE.
> #declare M =
> mesh {
>      triangle {...},
>      triangle {...},
>      ...
>      triangle {...}
> };
>
> LOOP
>      object { M transform {...} }
> END LOOP
>
>
> BUT
> This effect cannot be achieved by unioning a group of objects:
>
> #declare U =
> union {
>      triangle {...},
>      triangle {...},
>      ...
>      triangle {...}
> };
>
> LOOP
>      object { U transform {...} }
> END LOOP
> would multiply the memory cost


ok so if I have a object consistent of several parts I do normally union
to move them around, I need to not union them and move them all seperate
right?

REgards,
THor


Post a reply to this message

From: Warp
Subject: Re: Multi-usage of an object
Date: 20 May 2006 04:54:18
Message: <446ed93a@news.povray.org>
McHannemann <nomail@nomail> wrote:
> ok so if I have a object consistent of several parts I do normally union
> to move them around, I need to not union them and move them all seperate
> right?

  To achieve what?

-- 
                                                          - Warp


Post a reply to this message

From: McHannemann
Subject: Re: Multi-usage of an object
Date: 20 May 2006 07:30:00
Message: <web.446efcc8f11d153fd3b238df0@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
> McHannemann <nomail@nomail> wrote:
> > ok so if I have a object consistent of several parts I do normally union
> > to move them around, I need to not union them and move them all seperate
> > right?
>
>   To achieve what?
>
> --
>                                                           - Warp

To use a lot less memory,
I mean 50000 times an small object for 800 MB's or for much much less MB's
makes
a difference for me when I create landscapes with trees, grass and flowers
and so
on...
Regards,
THor


Post a reply to this message

From: Warp
Subject: Re: Multi-usage of an object
Date: 20 May 2006 08:45:06
Message: <446f0f52@news.povray.org>
McHannemann <nomail@nomail> wrote:
> >   To achieve what?

> To use a lot less memory,

  There's no difference between instantiating individual objects and a
union of them. (Well, there might be a small difference, but probably
negligible if any.)

  If you want to create tens of thousands of trees, make a tree mesh
and then instantiate that.

-- 
                                                          - Warp


Post a reply to this message

From: Alain
Subject: Re: Multi-usage of an object
Date: 20 May 2006 11:05:53
Message: <446f3051$1@news.povray.org>
McHannemann nous apporta ses lumieres en ce 20/05/2006 01:49:
>>The idea of reusing an object with little additional memory cost relates
>>to objects that themselves have components such as the mesh{} object and
>>the blob{} object.  But the initial declaration of a mesh{}, say, will
>>require lots of memory if it is comprised of many triangles.  However
>>once declared, it can be instanced multiple times without additionally
>>multiplying the memory needs.
>>IE.
>>#declare M =
>>mesh {
>>     triangle {...},
>>     triangle {...},
>>     ...
>>     triangle {...}
>>};
>>
>>LOOP
>>     object { M transform {...} }
>>END LOOP
>>
>>
>>BUT
>>This effect cannot be achieved by unioning a group of objects:
>>
>>#declare U =
>>union {
>>     triangle {...},
>>     triangle {...},
>>     ...
>>     triangle {...}
>>};
>>
>>LOOP
>>     object { U transform {...} }
>>END LOOP
>>would multiply the memory cost
> 
> 
> 
> ok so if I have a object consistent of several parts I do normally union
> to move them around, I need to not union them and move them all seperate
> right?
> 
> REgards,
> THor
> 
> 
>
You use slightly less memory moving the whole union than each component invidualy.
The saving possible in that case is, mostly, by having your texture applied to the
whole union. You 
don't save if you apply your texture to each individual element.

The real saving is when your objects are mesh objects. The original mash takes a large
amount of 
memory, but each instances only use a referer and a transformation. The sample was
ONLY a 
comparaison between an union of triangles (memory hog) and the same triangles as a
mesh.
You can put several mesh in an union. This won't cause a marked memory increase. The
larger the 
mesh, the greater the gain.

-- 
Alain
-------------------------------------------------


Post a reply to this message

From: Jim Charter
Subject: Re: Multi-usage of an object
Date: 20 May 2006 20:20:52
Message: <446fb264$1@news.povray.org>
McHannemann wrote:

> ok so if I have a object consistent of several parts I do normally union
> to move them around, I need to not union them and move them all seperate
> right?
Others have answered but since it was my answer that may have been 
confusing to you I will try to clarify further.  If your
question is:
Are union{} blocks necessary to transform and texture a group of objects 
as if one? The answer is no, not necessary.  The result can be the same 
if you apply the transform and texture to each of the individual objects 
or to a union{} block which includes them.  The union{} is a convenience 
and can add other benefits too but you can investigate that on your own.

About leveraging  memory usage,... to add detail to what others have 
already said,... whether you create several objects:

box {...transform {...}}
sphere {...transform {...}}
sphere {...transform {...}}
sphere {...transform {...}}

or first define them, then instantiate them:

#local B = box {...}
#local S = sphere {...}
object { B transform {...}}
LOOP 3 TIMES
	object { S transform {...} }
END LOOP

or put them in a union block:

union {
	box {...transform {...}}
	sphere {...transform {...}}
	sphere {...transform {...}}
	sphere {...transform {...}}
	transform {...}
}

or instantiate them in a union block:
#local B = box {...}
#local S = sphere {...}
union {
	object { B transform {...}}
	LOOP 3 TIMES
		object { S transform {...} }
	END LOOP
	transform {...}
}

your memory usage will be directly related to the
number of objects you create.  If a sphere costs
X bytes of memory, 3 spheres is ~ 3*X bytes.

BUT,... there are a couple of special POV-Ray objects
that are in a sense collections of component objects,
specifically the mesh{}, mesh2{}, and blob{} objects.
Mesh takes the standard triangle{} and smooth_triangle{}
as components, blob{} takes special versions of sphere{}
and cylinder{}.  When you define these special objects the
memory cost for that object will be directly related to the number of
components you use in it.  HOWEVER, if you define and
name your mesh{} or blob{} object, then instantiate
your mesh{} or blob{} multiple times, the memory cost does
NOT multiply by the number of *instances*. It remains close
to the original cost of the components. This is the
leveraging of memory that you are seeing all the talk about.  So
you only get benefit if you are reusing that same multi-object, object. 
  The classic example is to model a tree from perhaps tens thousand
triangles places in a single mesh{}.  This definition is then 
instantiated perhaps six different times, rotated and scaled scaled 
differently each time, and placed to look like a grove of trees.  In 
this way you get the "use" of 60 thousand triangles for approximately 
the memory cost of ten thousand.

Using a union{} to try and group the objects for instantiation
does not give this benefit. You might think it would because
it seems that unions can be treated as a single object. But there is
no benefit to that strategy.

This:
#local U =
union {
	sphere{}
	sphere{}
	sphere{}
};
LOOP 3 TIMES
	object{ U transform{}}
END LOOP
creates nine spheres with a memory cost, approximately, of nine spheres.


Naming the objects through an array
structure, thus seeming to "collect" objects in that way, gains nothing 
either.  Arrays are not objects.

It is only the special mesh{}, mesh2{}, and blob{} objects that can be
use to leverage memory costs.


Post a reply to this message

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