|
|
What do I need to do to modify the program code shown below, so that the first
line of the data file, instead of taking 3 parameters (Size of each dimension),
takes 4 arguments (Size of each of the three dimensins + bit resolution type).
Where the bit resolution type is 8, 16 or 32bit.
> 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
|
|