POV-Ray : Newsgroups : povray.general : question about isosurface from generated saved binary data Server Time
3 Aug 2024 10:17:14 EDT (-0400)
  question about isosurface from generated saved binary data (Message 1 to 4 of 4)  
From: Erik
Subject: question about isosurface from generated saved binary data
Date: 5 Apr 2004 16:11:53
Message: <4071bd89@news.povray.org>
Hi,

I am a very new POV user, so my guess is that my question might be trivial.

Now, I have data 3D data saved to binary files from a C++ program. The data
are 3D matrices of double values, that is the value of a function at a point
in space on a uniform grid. What I would like to use POV for is to read the
data file, and use isosurface to ray-trace the data at the 0
levelset/offset.

How do I read in a large binary file in POV of binary values?

How do I associate the read data with the function argument?


Regards,
Erik


Post a reply to this message

From: Christoph Hormann
Subject: Re: question about isosurface from generated saved binary data
Date: 5 Apr 2004 16:40:02
Message: <c4sg0v$aia$1@chho.imagico.de>
Erik wrote:
> Hi,
> 
> I am a very new POV user, so my guess is that my question might be trivial.
> 
> Now, I have data 3D data saved to binary files from a C++ program. The data
> are 3D matrices of double values, that is the value of a function at a point
> in space on a uniform grid. What I would like to use POV for is to read the
> data file, and use isosurface to ray-trace the data at the 0
> levelset/offset.
> 
> How do I read in a large binary file in POV of binary values?
> 
> How do I associate the read data with the function argument?

Have a look at the density_file pattern:

http://www.povray.org/documentation/view/195/#s06_07_11_11

in POV-Ray 3.6 feature is improved and there is a patch available that 
also allows you to read data from text files and floating point numbers:

http://staff.aist.go.jp/r-suzuki/e/povray/iso/df_body.htm

Christoph

-- 
POV-Ray tutorials, include files, Sim-POV,
HCR-Edit and more: http://www.tu-bs.de/~y0013390/
Last updated 21 Mar. 2004 _____./\/^>_*_<^\/\.______


Post a reply to this message

From: Mike Williams
Subject: Re: question about isosurface from generated saved binary data
Date: 5 Apr 2004 20:06:26
Message: <s5LXgAAiQfcAFws+@econym.demon.co.uk>
Wasn't it Erik who wrote:
>Hi,
>
>I am a very new POV user, so my guess is that my question might be trivial.
>
>Now, I have data 3D data saved to binary files from a C++ program. The data
>are 3D matrices of double values, that is the value of a function at a point
>in space on a uniform grid. What I would like to use POV for is to read the
>data file, and use isosurface to ray-trace the data at the 0
>levelset/offset.
>
>How do I read in a large binary file in POV of binary values?
>
>How do I associate the read data with the function argument?


You have to turn your 3d numerical data into a density_file (df3).
That's typically not an easy process, and it's not particularly well
described in the documentation. I've never quite managed to do it
successfully.

Once you've got your df3 file you can use the density pattern to
generate an isosurface, as described on the "patterns and noise" page of
my isosurface tutorial
<http://www.econym.demon.co.uk/isotut/patterns.htm#density>

When used as an isosurface, there's a single surface that joins all the
points where the density pattern has a particular value.

Alternatively, once you've got your df3 file you can render it as media.
See the scenes\interior\media\galaxy.pov example file that came with the
POV 3.5 package.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: ingo
Subject: Re: question about isosurface from generated saved binary data
Date: 6 Apr 2004 13:47:43
Message: <Xns94C3C95D1C25Dseed7@news.povray.org>
in news:s5LXgAAiQfcAFws+@econym.demon.co.uk Mike Williams wrote:

> You have to turn your 3d numerical data into a density_file (df3).
> That's typically not an easy process, and it's not particularly well
> described in the documentation. I've never quite managed to do it
> successfully.
> 

Here you can find a QBASIC program by David Sharp that generates the 
data and puts them in a df3-file

From: "david sharp" <dsh### [at] interportnet>
Newsgroups: povray.binaries.utilities
Subject: 'algorithmically generated' density files
Date: Tue, 30 Nov 1999 13:48:39 -0500
Message-ID: <38441d84@news.povray.org>
X-Trace: 30 Nov 1999 13:55:00 -0500, 216.164.253.164


Below, my Python version of it, using the Numeric package for array 
manipulation and it has the option to specify the bitsize of the data.

----%<----%<----
import math, array, Numeric, sys

A=0.5
Api=A*math.pi
def fnDensity(x, y, z):
    return (math.cos(Api*z)*math.cos(Api*y) +
        math.cos(Api*x)*math.cos(Api*z) +
        math.cos(Api*x)*math.cos(Api*y))

Bit=32
if Bit==8:
    TypeCode="B"
elif Bit==16:
    TypeCode="H"
elif Bit==32:
    TypeCode="I"
else:
    Bit=8
    Typecode="B"
Bval=(2**Bit)-1

def fnLimit(Density):
    return long(Bval/MMD*(Density-MinD))

def fnx(ix): return (xMin+xLen*(ix/xRes))
def fny(iy): return (yMin+yLen*(iy/yRes))
def fnz(iz): return (zMin+zLen*(iz/zRes))

#x,y,z resolution.
xRes, yRes, zRes = 100.0, 50.0, 50.0
xyRes=xRes*yRes; yzRes=yRes*zRes; xyzRes=xRes*yRes*zRes

#size of the box
xMin, yMin, zMin=-math.pi,-math.pi,-math.pi
xMax, yMax, zMax= math.pi, math.pi, math.pi
xLen=xMax-xMin; yLen=yMax-yMin; zLen=zMax-zMin

#get 'x-axis points'.
Repx=Numeric.ones(int(xRes))*int(yzRes)
x=Numeric.repeat(map(fnx,range(1, xRes+1)),Repx)

#get 'y-axis points'.
Repy=Numeric.ones(int(yRes))*int(zRes)
y=Numeric.repeat(map(fny,range(1, yRes+1)),Repy)
y=Numeric.resize(y,(int(xyzRes),))

#get 'z-axis points'.
z=map(fnz,range(1, zRes+1))*int(xyRes)

#calculate densities for voxel xyz.
Dens=map(fnDensity, x, y, z)

#find minimum and maximum densities,
#scale them to fit between 0 - Bval
MaxD=max(Dens)
MinD=min(Dens)
MMD=MaxD-MinD
Dens=map(fnLimit,Dens)

#write to file.
FileName= "df3Test"+str(Bit)+".df3"
f=open(FileName, 'wb')
Headarr=array.array('H', [long(xRes),long(yRes),long(zRes)])
Datarr=array.array(TypeCode, Dens)
if sys.byteorder == 'little':       #df3-files are big-endian
    Headarr.byteswap()
    Datarr.byteswap()
Headarr.tofile(f)
Datarr.tofile(f)
f.close()
----%<----%<----


Ingo


Post a reply to this message

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