POV-Ray : Newsgroups : povray.advanced-users : Inline calculation for df3/media entries Server Time
31 Oct 2024 14:10:19 EDT (-0400)
  Inline calculation for df3/media entries (Message 1 to 3 of 3)  
From: Antonio Ferrari
Subject: Inline calculation for df3/media entries
Date: 3 Nov 2005 11:05:01
Message: <web.436a344f57e54c73c93aff1a0@news.povray.org>
ops, I'm sorry but I sent my message without the subject...
I repost it correctly.

I'd like to apply media to a generic object, so that media
"intensity" is a function of the distance from the external
surface (for example decrease/increase linearly/exponentially
when distance grow up).

I don't know if this is a feature of Povray media. Is it
possible?

It seemed simple for spheres of cubes but I don't know if
it's the same thing for generic objects. For generic objects
df3 files can be used, but they must be generated ad hoc
for the media of the specific object.

First I thought to write a macro that calculate and generate
df3 entries, without using external generators or editors.

Follows the pseudo-code for my idea...

INPUT: object O, parameter E (I'll explain it later)
OUTPUT: container L (array, list, etc.)

01: calculate bounding box lengths (X,Y,Z) for axes x,y,z
02: i=0
03: while i<X begin
04:  j=0
05:  while j<Y begin
06:   k=0
07:   while k<Z begin
08:    if point <x,y,z> is internal to O, the add it to L
09:    k=k+E
10:   end
11:   j=j+E
12:  end
13:  i=i+E
14: end

After executing this procedure, L must contain all points
internal to O whose minum distance from each other is E,
that is a sort of grid of internal points. All the points
in L, placed in a 3D plane, approximate the object O.

The littler E is, the better the approximation will be.

Obviously value for E and intitial values (instead of 0)
for i,j,k can be optimized in order to better approximate
the object.

I know that 10^6 checks for internal points must be
performed when subdividing each axis in 100 parts, but
this is necessary in order to implement my idea...

Follows a 2D example, where X will be the points contained
in L:


 +-------------------+
 |XXXXXXXXXXXXXXXXXXX|
 |XXXXXXXXXXXXXXXXXXX|
 |XXXXXXXXXXXXXXXXXXX|
 |XXXXXXXXXXXXXXXXXXX|
 |XXXXXXXXXXXXXXXXXXX.------.
 |XXXXXXXXXXXXXXXXXXXXXXXXXXX`--.
 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX`.
 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 +----------XXXXXXXXXXXXXXXXXXXXXXXX
           ;XXXXXXXXXXXXXXXXXXXXXXXXX:
           |XXXXXXXXXXXXXXXXXXXXXXXXX|
           :XXXXXXXXXXXXXXXXXXXXXXXXX;
            XXXXXXXXXXXXXXXXXXXXXXX/
             XXXXXXXXXXXXXXXXXXXXX/
              `.XXXXXXXXXXXXXXXXX,'
                '--.XXXXXXXXX_.-'
                    `------''


Simple algorithms exist in literature to calculate external
points for a set of points.

After having found external points, a constant intensity can
be assigned to them and such intensities can become entried
for a df3 file.

Example for exaternal points of level 1:


  1111111111111111111
  1                 1
  1                 1
  1                 1
  1                 1
  1                 111111111
  1                          1111
  1111111111                     11
            1                      1
            1                       1
            1                       1
            1                       1
             1                     1
              11                 11
                1111         1111
                    111111111


External points can be removed from L, obtaining a new container
L'. External points for L' constitutes the second level.

The process is reiterated for the next levels.


  1111111111111111111
  1222222222222222221
  1233333333333333321
  1234444444444444321
  1234444444555554321
  123333333345665432111111111
  1222222222345665432222222221111
  111111111123456654333333333222211
            123456654444444443333221
            1234566655555555544443321
            1234555566666666655554321
            1233444455555555544443321
             12233334444444443333221
              112222333333333222211
                11112222222221111
                    111111111



Then... Do you think is it possible to write a macro that
generate df3 entries according to the described rules?

If not yet implemented, do you think that a functionality that
generates df3 entries inline as described (intensity as function
of the distance) could be added to Povray, without including
df3 file every time?

Thanks.

Antonio


Post a reply to this message

From: Christoph Hormann
Subject: Re: Inline calculation for df3/media entries
Date: 3 Nov 2005 11:34:52
Message: <dkde5u$qu4$1@chho.imagico.de>
Antonio Ferrari wrote:
> ops, I'm sorry but I sent my message without the subject...
> I repost it correctly.
> 
> I'd like to apply media to a generic object, so that media
> "intensity" is a function of the distance from the external
> surface (for example decrease/increase linearly/exponentially
> when distance grow up).
> 
> I don't know if this is a feature of Povray media. Is it
> possible?

No.  For some shapes (most notable spline based like prism and lathe) it 
is not possible to analytically calculate the distance to the surface. 
For others (like meshes) this can be extremely slow.

The IsoCSG library provides functions representing the distance from the 
surface of some basic shapes (plane, sphere, torus, box, cone/cylinder 
and triangle to be precise):

http://www.imagico.de/pov/ic/index.html

Functions for other shapes do not return the distance from the surface 
(although they might be sufficiently close to be used anyway).

> 
> Then... Do you think is it possible to write a macro that
> generate df3 entries according to the described rules?

Sure - writing a df3 using SDL file writing functions isn't possible 
though, you will need to do some external conversion.  And it will be 
quite slow.

Note Gilles Tran's makeclouds uses a similar technique but not with a 
macro but using 'slice' renders of the object:

http://www.oyonale.com/ressources/english/sources13.htm

Christoph

-- 
POV-Ray tutorials, include files, Landscape of the week:
http://www.imagico.de/ (Last updated 31 Oct. 2005)
MegaPOV with mechanics simulation: http://megapov.inetart.net/


Post a reply to this message

From: Lonnie
Subject: Re: Inline calculation for df3/media entries
Date: 6 Nov 2005 23:25:00
Message: <web.436ed59bf6741f3fd5d3b08c0@news.povray.org>
There just is no way to write a df3: file directly from POV :( - they must
be written in binary format.  Fortunately, there's plenty of free software
that will do the job.  Python works, and I have had success using
JustBASIC.  The idea is, with POV, take slices of your object using the CSG
intersect function, then scan them using the trace() function.  Output the
result to a text file, for instance a series of 0s and 1s for
outside/inside the object.  Then read the data into a 3D array in a
language capable of binary output and do your edge detection/density
calculations.  I had been toying with this same idea for several weeks and
I'll try to get an implementation  posted in the next week - just too many
projects and I'm in middle of two day render (see my latest posting in
images forum.)  For the moment, check out this JustBASIC code.  It produces
a 100x100x100 df3: filled with random clouds, which are denser in the
center than at the edges.  I use arrays to hold the "seed" values the
clouds are built around, then write the df3: directly by calculating the
distance from each point in the cube to each of the seeds.

open "clouds.df3" for binary as #myfile
print #myfile, chr$(0)
print #myfile, chr$(100)
print #myfile, chr$(0)
print #myfile, chr$(40)
print #myfile, chr$(0)
print #myfile, chr$(100)

randomize 0.5
dim myx(30)
dim myy(30)
dim myz(30)
for p=0 to 29
  myx(p)=rnd(1)*80+10
  myy(p)=rnd(1)*20+10
  myz(p)=rnd(1)*80+10
  print myx(p),
  print myy(p),
  print myz(p)
next

for x=0 to 99
  for y=0 to 39
    for z=0 to 99
      v=0
      for  p=0 to 29
        d=255-sqr(sqr(abs(myx(p)-x)^2+abs(myy(p)-y)^2)^2+abs(myz(p)-z)^2)*20
        if d>v then v=d
      next
      if v<0 then v=0
      if v>255 then v=255
      print x,y,z,v
      print #myfile, chr$(int(v))
    next
  next
next

close #myfile
print "complete"
end


Post a reply to this message

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