|
|
Woody <nomail@nomail> wrote:
> I'm trying to create a utility that converts a text file (testdata.txt) into a
> df3 file (testdata.df3). It takes a file that might look like
> 3 3 3
> 0 1 2 255
> 0 2 0 128
> (first 3 characters are the dimensions,
> next 3 characters are the index, next character is the value,
> next 3 characters are the index, next character is the value,
> etc.)
> No matter what I try, and no matter what values I use in the input file, when it
> comes time to render I either get an interior of completely filled, or empty.
That might also be because of your scene settings.
Anyways, here's a clean C++ implementation of your task (untested in
povray, but I assume it will work):
#include <iostream>
#include <fstream>
#include <vector>
int main()
{
std::ifstream is("testdata.txt");
if(!is.good()) { std::cerr << "Couldn't open testdata.txt\n"; return 1; }
size_t xSize, ySize, zSize;
is >> xSize >> ySize >> zSize;
std::vector<char> data(xSize*ySize*zSize + 6, 0);
data[0] = xSize/256; data[1] = xSize%256;
data[2] = ySize/256; data[3] = ySize%256;
data[4] = zSize/256; data[5] = zSize%256;
while(true)
{
int x, y, z, value;
is >> x >> y >> z >> value;
if(!is.good()) break;
data.at(x + y*xSize + z*xSize*ySize + 6) = value;
}
std::ofstream os("testdata.df3", std::ios::binary);
os.write(&data[0], data.size());
}
--
- Warp
Post a reply to this message
|
|