|
|
Hi list,
I'm trying to use a density file in povray for the first time and the page is
always blank.
I use an external program to generate a file data.dat which looks like this,
10 10 10
0 0 0 240
1 0 0 240
2 0 0 240
3 0 0 240
4 0 0 240
5 0 0 240
6 0 0 240
7 0 0 240
8 0 0 240
etc ...
where the first line gives the dimensions, the first three columns are xyz
coordinates and last column the density value.
I use the c++ code posted here to create a df3 file. OK so far, I think.
Unfortunately, my basic example shows a blank page with nothing in it. I don't
know if the df3 file is incorrect or if it's a problem with the povray file
below,
background { color rgb <1.0,1.0,1.0> }
global_settings {
ambient_light <0.3,0.3,0.3>
}
#include "colors.inc"
#include "textures.inc"
light_source{<10,10,-10> color White}
#declare dist = 1.5;
camera {location <dist , dist ,dist>
right <0, 4/3, 0>
up <0,0,1>
look_at <0.0 , 0.0 , 0.0>}
#declare theinterior = interior {
media {
density {
density_file df3 "data.df3"
interpolate 1
color_map {
[0.00 rgb <0,0,0>]
[0.2 rgb <0,0,1>]
[0.4 rgb <0,1,0>]
[1.00 rgb <1,0,0>]
}
}
}
}
box {
<0,0,0>, <1,1,1>
pigment { rgbf 1 }
interior { theinterior }
hollow
}
I'll appreciate any advice.
Regards,
baptiste
Warp <war### [at] tagpovrayorg> wrote:
> Woody <nomail@nomail> wrote:
> > If you every have a few moments do you think you could modify the source code
> > you posted at http://news.povray.org/4799ff49%40news.povray.org, so that it can
> > take one or more *.txt files specified in the command line (instead of the
> > testdata.txt) and output them into df3 format with the same name (except for
> > the txt extension).
>
> You mean with the same input file format?
> How about this:
>
>
> #include <iostream>
> #include <fstream>
> #include <vector>
> #include <string>
> #include <cstdio>
>
> int main(int argc, char* argv[])
> {
> // Limit the size of the df3 dimensions (safeguard against invalid input).
> // Maximum df3 size will be SIZE_LIMIT*SIZE_LIMIT*SIZE_LIMIT.
> const size_t SIZE_LIMIT = 256;
>
> if(argc < 2)
> {
> std::cout << "Usage: " << argv[0] << " <files>\n";
> return 0;
> }
>
> for(int i = 1; i < argc; ++i) // for each input file
> {
> std::ifstream is(argv[i]);
> if(!is.good())
> {
> std::cerr << "Couldn't open ";
> std::perror(argv[i]);
> continue;
> }
>
> size_t xSize, ySize, zSize;
> is >> xSize >> ySize >> zSize;
> if(xSize > SIZE_LIMIT || ySize > SIZE_LIMIT || zSize > SIZE_LIMIT)
> {
> std::cout << "Skipping " << argv[i] << " (invalid input)\n";
> continue;
> }
>
> std::vector<char> data(xSize*ySize*zSize + 6, 0);
>
> // Setup df3 header:
> data[0] = xSize/256; data[1] = xSize%256;
> data[2] = ySize/256; data[3] = ySize%256;
> data[4] = zSize/256; data[5] = zSize%256;
>
> // Read input data and create df3 data:
> while(true)
> {
> size_t x, y, z, value;
> is >> x >> y >> z >> value;
> if(!is.good()) break;
> const size_t ind = x + y*xSize + z*xSize*ySize + 6;
> if(ind < data.size())
> data[ind] = char(value);
> }
>
> // Write df3 file:
> std::string filename = argv[i];
> size_t ind = filename.find_last_of('.');
> if(ind != filename.npos) filename.resize(ind);
> filename += ".df3";
> std::ofstream os(filename.c_str(), std::ios::binary);
> os.write(&data[0], data.size());
> std::cout << argv[i] << " -> " << filename << std::endl;
> }
> }
Post a reply to this message
|
|