POV-Ray : Newsgroups : povray.advanced-users : DF3 density file generation for a generic 3D object ? Server Time
31 Oct 2024 08:18:54 EDT (-0400)
  DF3 density file generation for a generic 3D object ? (Message 1 to 7 of 7)  
From: Antonio Ferrari
Subject: DF3 density file generation for a generic 3D object ?
Date: 1 Oct 2007 11:10:00
Message: <web.47010cde36c235964e64f15d0@news.povray.org>
Prerequisites:

1) Having a generic closed object O;
2) Being able to apply inside(O,V) operator for a generic vector V
3) Being able to write DF3 files using povray language, maybe applying the
patch "Extended Density File"

What I'm looking for:

I'm looking for a macro for generating a DF3 file in output for the interior
of the object O passed to the macro. I'd like that the density is a function
of the minimal distance of V from the external surface of O: for V internal,
density[V] = density_function(minimal_distance(O,V)). In particular I'd like
a function the make the density greater when moving toward the interior of
O, where the increment could be linear, exponential, logarithmic, etc.

Is there a function for calculating the minimal distance of an internal
point V from the contour of O?

Have you any idea?

Do you think that only a patch could give me the expected result?

Some time ago I had the following idea: calculating the dimensions X, Y and
Z of the box containing O. Subdivide both X, Y and Z into n segments. Use
of 3 innested loops for x, y and z axis in order to cycle the segments and
see if the are or are not part of the interior of O. This is a sort of
sampling method. The greater n is, the more accurate the samples are.

Then I needed an algorithm for finding interior points at first level,
second level, third level, etc. The greater the level, the higher the
density, for example.

Oh these are just ideas. I don't know if I'm on the right way.

Bye,
A.


Post a reply to this message

From: Alain
Subject: Re: DF3 density file generation for a generic 3D object ?
Date: 1 Oct 2007 15:36:59
Message: <47014c5b$1@news.povray.org>
Antonio Ferrari nous apporta ses lumieres en ce 2007/10/01 11:06:

Normaly, you use some external application to generate the DF3 file.

> Prerequisites:
> 
> 1) Having a generic closed object O;
> 2) Being able to apply inside(O,V) operator for a generic vector V
> 3) Being able to write DF3 files using povray language, maybe applying the
> patch "Extended Density File"
You will have problem writing any non-ASCII characters to the file, POV-Ray only 
write text files (ASCII encoded) and image files.
> 
> What I'm looking for:
> 
> I'm looking for a macro for generating a DF3 file in output for the interior
> of the object O passed to the macro. I'd like that the density is a function
> of the minimal distance of V from the external surface of O: for V internal,
> density[V] = density_function(minimal_distance(O,V)). In particular I'd like
> a function the make the density greater when moving toward the interior of
> O, where the increment could be linear, exponential, logarithmic, etc.
> 
> Is there a function for calculating the minimal distance of an internal
> point V from the contour of O?
User deffined function.
> 
> Have you any idea?
> 
> Do you think that only a patch could give me the expected result?
> 
> Some time ago I had the following idea: calculating the dimensions X, Y and
> Z of the box containing O. Subdivide both X, Y and Z into n segments. Use
> of 3 innested loops for x, y and z axis in order to cycle the segments and
> see if the are or are not part of the interior of O. This is a sort of
> sampling method. The greater n is, the more accurate the samples are.
> 
> Then I needed an algorithm for finding interior points at first level,
> second level, third level, etc. The greater the level, the higher the
> density, for example.
> 
> Oh these are just ideas. I don't know if I'm on the right way.
> 
> Bye,
> A.
> 
> 
Aparently, you already have a function to eveluate the density. Taking that in 
acount, it would be easier, and probably faster, to directly use that function 
as density for a media.
interior{media{emission 1 density Your_Function}}
To increase the quality, you increase the samples value (default of 3). Don't 
touch to intervals, inefficient and very slow.

-- 
Alain
-------------------------------------------------
Just remember - if the world didn't suck, we would all fall off.


Post a reply to this message

From: Tim Attwood
Subject: Re: DF3 density file generation for a generic 3D object ?
Date: 1 Oct 2007 16:39:31
Message: <47015b03$1@news.povray.org>
> Prerequisites:
>
> 1) Having a generic closed object O;
> 2) Being able to apply inside(O,V) operator for a generic vector V
> 3) Being able to write DF3 files using povray language, maybe applying the
> patch "Extended Density File"
>
> What I'm looking for:
>
> I'm looking for a macro for generating a DF3 file in output for the 
> interior
> of the object O passed to the macro. I'd like that the density is a 
> function
> of the minimal distance of V from the external surface of O: for V 
> internal,
> density[V] = density_function(minimal_distance(O,V)). In particular I'd 
> like
> a function the make the density greater when moving toward the interior of
> O, where the increment could be linear, exponential, logarithmic, etc.
>
> Is there a function for calculating the minimal distance of an internal
> point V from the contour of O?

There isn't a built in function for this, because there isn't a single 
answer
to how far a minimal distance point is from the surface. You can use
trace to collect a sample of distances from the surface in random
directions to appoximate the minimal distance of a voxel from the
surface.

#include "rand.inc"
#macro distToSurface(Obj, vec, samp, rsd)
   #local dist = 1000000;
   #local c=0;
   #while (c<samp)
      #local rdir = VRand_On_Sphere(rsd);
      #declare Norm = <0, 0, 0>;
      #local hit = trace(Obj, vec, rdir, Norm);
      #if (vlength(Norm) != 0)
         #local dist = min(dist, vlength(hit - vec));
      #end
      #local c=c+1;
   #end
#end

> Have you any idea?
>
> Do you think that only a patch could give me the expected result?

This can be done with macros I think, though it would be slow to
calculate the distance data. You could calculate your three dimensional
array of distances on the first frame, scale the data, then write it to file
to reload for the remaining frames.  A slice of voxels could then be
generated from the data with the greyscale voxel colors determined
from the array data.

> Some time ago I had the following idea: calculating the dimensions X, Y 
> and
> Z of the box containing O. Subdivide both X, Y and Z into n segments. Use
> of 3 innested loops for x, y and z axis in order to cycle the segments and
> see if the are or are not part of the interior of O. This is a sort of
> sampling method. The greater n is, the more accurate the samples are.
>
> Then I needed an algorithm for finding interior points at first level,
> second level, third level, etc. The greater the level, the higher the
> density, for example.
>
> Oh these are just ideas. I don't know if I'm on the right way.

This might work for simple objects, but will fail for complex objects.
Think of a hollow pipe A, if you scale it smaller then the new smaller
pipe B fits into the void of the first pipe A; the interior of A doesn't
share any points with the interior of B.


Post a reply to this message

From: Antonio Ferrari
Subject: Re: DF3 density file generation for a generic 3D object ?
Date: 2 Oct 2007 08:05:00
Message: <web.470232d9413da414e64f15d0@news.povray.org>
> Aparently, you already have a function to eveluate the density. Taking that in
> acount, it would be easier, and probably faster, to directly use that function
> as density for a media.
> interior{media{emission 1 density Your_Function}}
> To increase the quality, you increase the samples value (default of 3). Don't
> touch to intervals, inefficient and very slow.
>
> --
> Alain
> -------------------------------------------------
> Just remember - if the world didn't suck, we would all fall off.

Hi Alain. First of all thank for you reply.

I explain better the problem...

Let suppose that the intersection of the object with a plane is (in 2D) as
follows:

  @@@@@@@@@
 @         @
@           @
@           @
 @         @
  @@@@@@@@@

Let's do our considerations in 2D, but they can be extended in 3D easily.

  @@@@@@@@@
 @111111111@
@12222222221@
@123333333321@
@12222222221@
 @111111111@
  @@@@@@@@@

What I'd want isn't a generic Your_Function with parameters x, y or z. What
I want is a density function with only a parameter d, where d is the
distance of the vector V=<x,y,z> from the contour of the surface, V inside
the object. It's obvious that there are some preconditions to impose...

Look at the 2D section... Let's consider a linear density function.
Your_Function conincide with the distance. So, for point at distance 1,
density is 1; for points at distance 2, density is 2; and so on.

Does the line "interior{media{emission 1 density Your_Function}}" allow me
to do what I'm expecting? Does it allow me to "follow" the contour of the
object?


Post a reply to this message

From: Antonio Ferrari
Subject: Re: DF3 density file generation for a generic 3D object ?
Date: 2 Oct 2007 08:15:00
Message: <web.47023516413da414e64f15d0@news.povray.org>
> There isn't a built in function for this, because there isn't a single
> answer
> to how far a minimal distance point is from the surface. You can use
> trace to collect a sample of distances from the surface in random
> directions to appoximate the minimal distance of a voxel from the
> surface.
>
> #include "rand.inc"
> #macro distToSurface(Obj, vec, samp, rsd)
>    #local dist = 1000000;
>    #local c=0;
>    #while (c<samp)
>       #local rdir = VRand_On_Sphere(rsd);
>       #declare Norm = <0, 0, 0>;
>       #local hit = trace(Obj, vec, rdir, Norm);
>       #if (vlength(Norm) != 0)
>          #local dist = min(dist, vlength(hit - vec));
>       #end
>       #local c=c+1;
>    #end
> #end
>

Hi Tim thank for this macro... It's very useful to me :)

>
> This can be done with macros I think, though it would be slow to
> calculate the distance data. You could calculate your three dimensional
> array of distances on the first frame, scale the data, then write it to file
> to reload for the remaining frames.  A slice of voxels could then be
> generated from the data with the greyscale voxel colors determined
> from the array data.
>

This just what I'd like. I have only to see if there is the possibility to
write a macro for isolating the more external points, the points nearest to
the surface. Let's call A1 the set of these points. These points have
density=my_func(1). Let's remove A1 point from our array. Let's find the
external points of the new array and call them A2. These points have
density=my_func(2). And so on for other distances.

> >
> > Oh these are just ideas. I don't know if I'm on the right way.
>
> This might work for simple objects, but will fail for complex objects.
> Think of a hollow pipe A, if you scale it smaller then the new smaller
> pipe B fits into the void of the first pipe A; the interior of A doesn't
> share any points with the interior of B.

I have to study better these cases...

Bye.


Post a reply to this message

From: Alain
Subject: Re: DF3 density file generation for a generic 3D object ?
Date: 2 Oct 2007 10:18:01
Message: <47025319$1@news.povray.org>
Antonio Ferrari nous apporta ses lumieres en ce 2007/10/02 08:00:
> 
>> Aparently, you already have a function to eveluate the density. Taking that in
>> acount, it would be easier, and probably faster, to directly use that function
>> as density for a media.
>> interior{media{emission 1 density Your_Function}}
>> To increase the quality, you increase the samples value (default of 3). Don't
>> touch to intervals, inefficient and very slow.
>>
>> --
>> Alain
>> -------------------------------------------------
>> Just remember - if the world didn't suck, we would all fall off.
> 
> Hi Alain. First of all thank for you reply.
> 
> I explain better the problem...
> 
> Let suppose that the intersection of the object with a plane is (in 2D) as
> follows:
> 
>   @@@@@@@@@
>  @         @
> @           @
> @           @
>  @         @
>   @@@@@@@@@
> 
> Let's do our considerations in 2D, but they can be extended in 3D easily.
> 
>   @@@@@@@@@
>  @111111111@
> @12222222221@
> @123333333321@
> @12222222221@
>  @111111111@
>   @@@@@@@@@
> 
> What I'd want isn't a generic Your_Function with parameters x, y or z. What
> I want is a density function with only a parameter d, where d is the
> distance of the vector V=<x,y,z> from the contour of the surface, V inside
> the object. It's obvious that there are some preconditions to impose...
> 
> Look at the 2D section... Let's consider a linear density function.
> Your_Function conincide with the distance. So, for point at distance 1,
> density is 1; for points at distance 2, density is 2; and so on.
> 
> Does the line "interior{media{emission 1 density Your_Function}}" allow me
> to do what I'm expecting? Does it allow me to "follow" the contour of the
> object?
> 
> 
> 
If the object is an isosurface with a threshold of 0 and you use the same 
function for the density, the density will start at zero at the surface and go 
up as you move in. By exactly how much depends on the gradient of the 
function,but some scaling can do the trick. If the function is quadratic, taking 
it's square root will return a linear curve.

If you use some primitives, there are some patterns that can help. Those are 
spherical, boxed and planar.

spherical start at 1 at the origin and drop to zero at radius = 1.

boxed start at 1 at the origin and drop to zero when reaching 1 unit distance in 
any ortogonal direction.

planar start at 1 on the x-z plane and drop to zero at 1 unit along the y axis.

Those can be scaled, receive various wave shapes, be multiplied, divided, 
squared,...

-- 
Alain
-------------------------------------------------
You know you've been raytracing too long when you're watching Bay Watch on the 
telly, see Pamela A. walking by and shout out "Great bump mapping!"


Post a reply to this message

From: Antonio Ferrari
Subject: Re: DF3 density file generation for a generic 3D object ?
Date: 3 Oct 2007 05:20:00
Message: <web.47035dca413da414e64f15d0@news.povray.org>
> If the object is an isosurface with a threshold of 0 and you use the same
> function for the density, the density will start at zero at the surface and go
> up as you move in. By exactly how much depends on the gradient of the
> function,but some scaling can do the trick. If the function is quadratic, taking
> it's square root will return a linear curve.
>
> If you use some primitives, there are some patterns that can help. Those are
> spherical, boxed and planar.
>
> spherical start at 1 at the origin and drop to zero at radius = 1.
>
> boxed start at 1 at the origin and drop to zero when reaching 1 unit distance in
> any ortogonal direction.
>
> planar start at 1 on the x-z plane and drop to zero at 1 unit along the y axis.
>
> Those can be scaled, receive various wave shapes, be multiplied, divided,
> squared,...
>
> --
> Alain

Yes. I didn't think to isosurfaces. There many isosurfaces that povray can
handle. The following wonderful tutorial explains them:

http://www.econym.demon.co.uk/isotut/

Furthermore I know that one of Christoph patches can speed up the process
for isosurfaces.

The problem could be for complex CSG objects or if I decide to use meshes,
sor, lathe, etc.

Only one more question: if have two isosurface objects with their own media
and I construct an union, difference or intersection, what happens to
medias? I'll try to esperiments this cases...


Post a reply to this message

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