POV-Ray : Newsgroups : povray.general : recursively defined objects and memory Server Time
29 Jul 2024 08:17:35 EDT (-0400)
  recursively defined objects and memory (Message 21 to 30 of 43)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: clipka
Subject: Re: recursively defined objects and memory
Date: 18 Aug 2013 17:48:24
Message: <52114128@news.povray.org>
Am 18.08.2013 23:08, schrieb Ger Remmers:

> (*) Povray seems to have a problem with very large arrays. I  can go as
> high as 800K nodes, after that the last position in the array seems to
> get corrupted.

Obviously that shouldn't happen. Can you provide a sample scene to 
reproduce, dissect and debug the problem?


Post a reply to this message

From: Ger Remmers
Subject: Re: recursively defined objects and memory
Date: 18 Aug 2013 18:01:22
Message: <52114432$1@news.povray.org>
On 08/18/2013 04:48 PM, clipka wrote:
> Am 18.08.2013 23:08, schrieb Ger Remmers:
>
>> (*) Povray seems to have a problem with very large arrays. I  can go as
>> high as 800K nodes, after that the last position in the array seems to
>> get corrupted.
>
> Obviously that shouldn't happen. Can you provide a sample scene to
> reproduce, dissect and debug the problem?
>

It messes up in the WriteDataFile() macro

#declare DataFilename = "nodes.inc";

#macro WriteDataFile()

   #fopen DataFile DataFilename write
   #write( DataFile, "#declare NumberOfNodes = 
",str(NumberOfNodes,0,0),";\n")
   #write( DataFile, "#declare Nodes =array [NumberOfNodes]\n")
   #write( DataFile, "{\n")
   #for (NodeCount, 0, NumberOfNodes -2, 1)
       #write ( DataFile, "<",vstr(3, Nodes[NodeCount],",",0,-1),">,\n")
   #end

/*
When including the written data it turns out that the next line is not 
executed
*/
   #write ( DataFile, "<",vstr(3, Nodes[NumberOfNodes-1],",",0,-1),">\n")
   #write (DataFile,"}\n")
   #fclose DataFile

   #debug concat("Done writing data file with ",str(NumberOfNodes,0,0)," 
nodes for frame ",str(frame_number,0,0),"\n")
#end


/*
   Only at the first frame do we need to initialize the nodes on the sphere,
   after that we load the node data from disk.
*/

#if (frame_number = 1)
   #declare NumberOfNodes = 5000000;

/*
With NumberOfNodes < ~800K it works fine
*/
   #declare Nodes =array [NumberOfNodes];
   #declare dlong = pi * (3-sqrt(5));
   #declare dz = 2.0 / NumberOfNodes;
   #declare Longitude = 0;
   #declare Z = 1 - dz / 2;

   #for (NodeCount, 0, NumberOfNodes - 1, 1)
     #declare Radius = sqrt(1 - Z * Z);
     #declare Nodes[NodeCount] = <cos(Longitude)* Radius, sin(Longitude) 
* Radius, Z>;
     #declare Z = Z - dz;
     #declare Longitude = Longitude + dlong;
   #end

   #else
     #include DataFilename
#end

#declare NumberOfItterations = 5;
#declare RandAngle = seed(66);
#if (frame_number > 1)
   #for(Dummy,0, (frame_number - 1) * NumberOfItterations * 4,1)
     #declare PlaneAngle = rand(RandAngle);
   #end
#end
#declare PlaneAngle = rand(RandAngle);
#declare CuttingPlane = plane{y, 0};
//#declare Cutter = box {<-10, 0.0, -10>,<10, -10, 10>};

#macro AdjustNodes(AngleX, AngleY, AngleZ, Displacement)
   #declare Cut = object { CuttingPlane translate y * Displacement 
rotate <AngleX, AngleY, AngleZ> };
   #for (NodeCount, 0, NumberOfNodes - 1, 1)
     #if (inside (Cut, Nodes[NodeCount]))
       #declare Nodes[NodeCount] = Nodes[NodeCount] / 1.001;
     #else
       #declare Nodes[NodeCount] = Nodes[NodeCount] * 1.001;
     #end
   #end
#end

   #for (ItterationCount, 0, NumberOfItterations - 1, 1)
   #declare PlaneAngleX = rand(RandAngle) * 360;
   #declare PlaneAngleY = rand(RandAngle) * 360;
   #declare PlaneAngleZ = rand(RandAngle) * 360;
   #declare Displacement = 0.5 - rand(RandAngle);
//  #local Cut = object { CuttingPlane rotate PlaneAngle };
   AdjustNodes(PlaneAngleX, PlaneAngleY, PlaneAngleZ, Displacement)
//    #debug concat(str(PlaneAngle,0,0),"\n")
#end
WriteDataFile()

-- 
Cheers
Ger


Post a reply to this message

From: Ger Remmers
Subject: Re: recursively defined objects and memory (for Clipka full source)
Date: 18 Aug 2013 18:13:45
Message: <52114719$1@news.povray.org>
/*

Original code from somewhere on the internet.
How to evenly distribute points on a sphere.

dlong := pi*(3-sqrt(5))   ~2.39996323
dz    := 2.0/N
long := 0
z    := 1 - dz/2
for k := 0 .. N-1
     r    := sqrt(1-z*z)
     node[k] := (cos(long)*r, sin(long)*r, z)
     z    := z - dz
     long := long + dlong
*/

#version 3.7;


/*
   Original code transcribed to SDL
   Create an array with NumberOfNodes points
   evenly distributed on the sphere
*/

#declare DataFilename = "nodes.inc";

#macro WriteDataFile()

   #fopen DataFile DataFilename write
   #write( DataFile, "#declare NumberOfNodes = 
",str(NumberOfNodes,0,0),";\n")
   #write( DataFile, "#declare Nodes =array [NumberOfNodes]\n")
   #write( DataFile, "{\n")
   #for (NodeCount, 0, NumberOfNodes -2, 1)
       #write ( DataFile, "<",vstr(3, Nodes[NodeCount],",",0,-1),">,\n")
   #end
   #write ( DataFile, "<",vstr(3, Nodes[NumberOfNodes-2],",",0,-1),">\n")
   #write (DataFile,"}\n")
   #fclose DataFile

   #debug concat("Done writing data file with ",str(NumberOfNodes,0,0)," 
nodes for frame ",str(frame_number,0,0),"\n")
#end


/*
   Only at the first frame do we need to initialize the nodes on the sphere,
   after that we load the node data from disk.
*/

#if (frame_number = 1)
   #declare NumberOfNodes = 5000000;
   #declare Nodes =array [NumberOfNodes];
   #declare dlong = pi * (3-sqrt(5));
   #declare dz = 2.0 / NumberOfNodes;
   #declare Longitude = 0;
   #declare Z = 1 - dz / 2;

   #for (NodeCount, 0, NumberOfNodes - 1, 1)
     #declare Radius = sqrt(1 - Z * Z);
     #declare Nodes[NodeCount] = <cos(Longitude)* Radius, sin(Longitude) 
* Radius, Z>;
     #declare Z = Z - dz;
     #declare Longitude = Longitude + dlong;
   #end

   #else
     #include DataFilename
#end
/*
   Now for the mountainous transformations

   We use a plane (Plane) to cut the sphere into 2 halves,
   every node "inside" the plane will be lowered, every node "outside"
   will be raised.
*/

#declare NumberOfItterations = 5;
#declare RandAngle = seed(66);
#if (frame_number > 1)
   #for(Dummy,0, (frame_number - 1) * NumberOfItterations * 4,1)
     #declare PlaneAngle = rand(RandAngle);
   #end
#end
#declare PlaneAngle = rand(RandAngle);
#declare CuttingPlane = plane{y, 0};


#macro AdjustNodes(AngleX, AngleY, AngleZ, Displacement)

   #declare Cut = object { CuttingPlane translate y * Displacement 
rotate <AngleX, AngleY, AngleZ> };

   #for (NodeCount, 0, NumberOfNodes - 1, 1)
     #if (inside (Cut, Nodes[NodeCount]))
       #declare Nodes[NodeCount] = Nodes[NodeCount] / 1.001;
     #else
       #declare Nodes[NodeCount] = Nodes[NodeCount] * 1.001;
     #end
   #end
#end

   #for (ItterationCount, 0, NumberOfItterations - 1, 1)
   #declare PlaneAngleX = rand(RandAngle) * 360;
   #declare PlaneAngleY = rand(RandAngle) * 360;
   #declare PlaneAngleZ = rand(RandAngle) * 360;
   #declare Displacement = 0.5 - rand(RandAngle);

   AdjustNodes(PlaneAngleX, PlaneAngleY, PlaneAngleZ, Displacement)

#end
WriteDataFile()

/*
   And now to make the whole thing visible
*/

#declare Diameter = 2/sqrt(NumberOfNodes);
#declare MutilatedEarth = union {
#for (NodeCount, 0, NumberOfNodes - 1, 1)
   sphere{Nodes[NodeCount], Diameter}
#end
    pigment{
      onion color_map{
      [0.0  0.6 color <0, 1, 1> color <1, 0, 0>]
      [0.6 0.8 color <1, 0, 0> color <0, 1, 0>]
      [0.80 0.85 color <0, 1, 0> color <0, 0, 0.5>]
      [0.85 0.9 color <0, 0, 0.5> color <0, 0, 1>]
      [0.95 1.0 color <0, 0, 1> color <0, 0, 0>]}
      scale 1
    }
}



#declare LightStrenght = 1;

light_source {< -400, 1000, -500>*10000, color <1.0, 1.0, 1.0> * 
LightStrenght
//	      area_light 10000, 10000, 51, 51 adaptive 0
	      }

light_source {< -400, 1000, 500>*1000, color 0.06125/2 * LightStrenght 
rotate y * 120 shadowless}
light_source {< -400, 1000, 500>*1000, color 0.06125/2 * LightStrenght 
rotate y * -120 shadowless}
light_source {< 0, -100000, 0>, color 0.06125/2 * LightStrenght shadowless}


#declare Blue_Sky3 =
pigment {
     granite
     turbulence 0.4
     color_map {
         [0.6 rgb <0, 0, 0.2> * LightStrenght]
         [1.0 rgb 0.5 * LightStrenght]
     }
}

sky_sphere {pigment {Blue_Sky3 scale < 3, 1, 3>*10}}


global_settings {
     ambient_light 0.0
     adc_bailout 0.09
     max_trace_level 200
     noise_generator 3
     assumed_gamma 1.0
     }

object { MutilatedEarth }


#declare CameraLocation =  <0,0,-3>;
#declare CameraLookat = <0, 0, 0>;


camera {
   location CameraLocation
   look_at CameraLookat
   direction z *   1.0
   right image_width / image_height * x
}


Post a reply to this message

From: clipka
Subject: Re: recursively defined objects and memory
Date: 18 Aug 2013 18:35:14
Message: <52114c22$1@news.povray.org>
Am 19.08.2013 00:01, schrieb Ger Remmers:
> On 08/18/2013 04:48 PM, clipka wrote:
>> Am 18.08.2013 23:08, schrieb Ger Remmers:
>>
>>> (*) Povray seems to have a problem with very large arrays. I  can go as
>>> high as 800K nodes, after that the last position in the array seems to
>>> get corrupted.
>>
>> Obviously that shouldn't happen. Can you provide a sample scene to
>> reproduce, dissect and debug the problem?
>>
>
> It messes up in the WriteDataFile() macro

Thanks, I'll have a closer look at it.


Post a reply to this message

From: scott
Subject: Re: recursively defined objects and memory
Date: 19 Aug 2013 08:55:41
Message: <521215cd$1@news.povray.org>
>    #declare Cut = object { CuttingPlane translate y * Displacement
> rotate <AngleX, AngleY, AngleZ> };

...

>    #declare PlaneAngleX = rand(RandAngle) * 360;
>    #declare PlaneAngleY = rand(RandAngle) * 360;
>    #declare PlaneAngleZ = rand(RandAngle) * 360;

On a separate note, are you sure that method of choosing the plane 
orientation gives a uniform random distribution...?


Post a reply to this message

From: clipka
Subject: Re: recursively defined objects and memory
Date: 19 Aug 2013 10:47:15
Message: <52122ff3@news.povray.org>
Am 19.08.2013 14:55, schrieb scott:
>>    #declare Cut = object { CuttingPlane translate y * Displacement
>> rotate <AngleX, AngleY, AngleZ> };
>
> ....
>
>>    #declare PlaneAngleX = rand(RandAngle) * 360;
>>    #declare PlaneAngleY = rand(RandAngle) * 360;
>>    #declare PlaneAngleZ = rand(RandAngle) * 360;
>
> On a separate note, are you sure that method of choosing the plane
> orientation gives a uniform random distribution...?

#declare Cut = object { CuttingPlane translate 
VRand_On_Sphere(RandAngle) * Displacement };

should do the trick.


Post a reply to this message

From: Ger
Subject: Re: recursively defined objects and memory
Date: 19 Aug 2013 11:34:05
Message: <52123aed$1@news.povray.org>
On 08/19/2013 07:55 AM, scott wrote:
>>    #declare Cut = object { CuttingPlane translate y * Displacement
>> rotate <AngleX, AngleY, AngleZ> };
>
> ....
>
>>    #declare PlaneAngleX = rand(RandAngle) * 360;
>>    #declare PlaneAngleY = rand(RandAngle) * 360;
>>    #declare PlaneAngleZ = rand(RandAngle) * 360;
>
> On a separate note, are you sure that method of choosing the plane
> orientation gives a uniform random distribution...?
>

No, it does not, but doing it this way gives a better result than using 
a single rand() for the plane orientation.

-- 
Cheers
Ger


Post a reply to this message

From: Ger
Subject: Re: recursively defined objects and memory
Date: 19 Aug 2013 11:38:23
Message: <52123bef$1@news.povray.org>
On 08/19/2013 09:47 AM, clipka wrote:
> Am 19.08.2013 14:55, schrieb scott:
>>>    #declare Cut = object { CuttingPlane translate y * Displacement
>>> rotate <AngleX, AngleY, AngleZ> };
>>
>> ....
>>
>>>    #declare PlaneAngleX = rand(RandAngle) * 360;
>>>    #declare PlaneAngleY = rand(RandAngle) * 360;
>>>    #declare PlaneAngleZ = rand(RandAngle) * 360;
>>
>> On a separate note, are you sure that method of choosing the plane
>> orientation gives a uniform random distribution...?
>
> #declare Cut = object { CuttingPlane translate
> VRand_On_Sphere(RandAngle) * Displacement };
>
> should do the trick.
>
Using 3 separate rand()'s gave me a better result than a single rand(), 
but by no means uniform. But then again, that was not the problem I was 
trying to solve :)

-- 
Cheers
Ger


Post a reply to this message

From: Warp
Subject: Re: recursively defined objects and memory
Date: 19 Aug 2013 11:51:52
Message: <52123f18@news.povray.org>
Ger <ger### [at] nospamthankyou> wrote:
> >>    #declare PlaneAngleX = rand(RandAngle) * 360;
> >>    #declare PlaneAngleY = rand(RandAngle) * 360;
> >>    #declare PlaneAngleZ = rand(RandAngle) * 360;
> >
> > On a separate note, are you sure that method of choosing the plane
> > orientation gives a uniform random distribution...?

> No, it does not, but doing it this way gives a better result than using 
> a single rand() for the plane orientation.

Better in what way?

-- 
                                                          - Warp


Post a reply to this message

From: Ger
Subject: Re: recursively defined objects and memory
Date: 19 Aug 2013 12:04:48
Message: <52124220$1@news.povray.org>
On 08/19/2013 10:51 AM, Warp wrote:
> Ger <ger### [at] nospamthankyou> wrote:
>>>>     #declare PlaneAngleX = rand(RandAngle) * 360;
>>>>     #declare PlaneAngleY = rand(RandAngle) * 360;
>>>>     #declare PlaneAngleZ = rand(RandAngle) * 360;
>>>
>>> On a separate note, are you sure that method of choosing the plane
>>> orientation gives a uniform random distribution...?
>
>> No, it does not, but doing it this way gives a better result than using
>> a single rand() for the plane orientation.
>
> Better in what way?
>
More uniform, but in all honesty, that was not the first thing I was 
paying attention to. I'll run a single vs triple rand() test case later.

-- 
Cheers
Ger


Post a reply to this message

<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>

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