POV-Ray : Newsgroups : povray.general : question about isosurface from generated saved binary data : Re: question about isosurface from generated saved binary data Server Time
3 Aug 2024 08:11:20 EDT (-0400)
  Re: question about isosurface from generated saved binary data  
From: ingo
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.