POV-Ray : Newsgroups : povray.advanced-users : DF3 density file generation for a generic 3D object ? : Re: DF3 density file generation for a generic 3D object ? Server Time
8 Jul 2024 19:38:29 EDT (-0400)
  Re: DF3 density file generation for a generic 3D object ?  
From: Tim Attwood
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

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