diff options
author | Karl Berry <karl@freefriends.org> | 2021-02-25 19:22:25 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-02-25 19:22:25 +0000 |
commit | ad547a6b5986815fda458221149728d9d9ab1d87 (patch) | |
tree | 16296910eb3eca724371474ea9aea3994dc69614 /Build/source/utils/asymptote/prc/PRCTools/makePRC.cc | |
parent | 947b43de3dd21d58ccc2ffadefc4441ea1c2a813 (diff) |
restore Build,TODO from r57911
git-svn-id: svn://tug.org/texlive/trunk@57915 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/prc/PRCTools/makePRC.cc')
-rw-r--r-- | Build/source/utils/asymptote/prc/PRCTools/makePRC.cc | 187 |
1 files changed, 187 insertions, 0 deletions
diff --git a/Build/source/utils/asymptote/prc/PRCTools/makePRC.cc b/Build/source/utils/asymptote/prc/PRCTools/makePRC.cc new file mode 100644 index 00000000000..f7573000203 --- /dev/null +++ b/Build/source/utils/asymptote/prc/PRCTools/makePRC.cc @@ -0,0 +1,187 @@ +/************ +* +* This file is part of a tool for producing 3D content in the PRC format. +* Copyright (C) 2008 Orest Shardt <shardtor (at) gmail dot com> +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +*************/ + +#include <iostream> +#include <iomanip> +#include <fstream> +#include <unistd.h> +#include <cstdlib> +#include "../oPRCFile.h" + +using namespace std; + +void readPoints(istream &is, unsigned int n, double p[][3]) +{ + for(unsigned int i = 0; i < n; ++i) + { + is >> p[i][0] >> p[i][1] >> p[i][2]; + } + if(!is) + { + cerr << "Error reading list of points." << endl; + exit(1); + } +} + +void readDoubles(istream &is, unsigned int n, double d[]) +{ + for(unsigned int i = 0; i < n; ++i) + { + is >> d[i]; + } + if(!is) + { + cerr << "Error reading list of doubles." << endl; + exit(1); + } +} + +int main(int argc, char **argv) +{ + const char *oFileName = "output.prc"; + + int c; + opterr = 0; + while ((c = getopt (argc, argv, "o:")) != -1) + switch (c) + { + case 'o': + oFileName = optarg; + break; + case '?': + if (optopt == 'o') + cerr << "Option '-o' requires an argument, the filename." << endl; + else + cerr << "Unrecognized option '-" << (char)optopt << "'." << endl; + exit(1); + break; + default: + exit(1); + } + istream *ins = NULL; + if(optind < argc) + { + ins = new ifstream(argv[optind]); + if(!*ins) + { + cerr << "Error opening input file " << argv[optind] << endl; + exit(1); + } + } + else + { + ins = &cin; + } + + ofstream outf(oFileName); + if(!outf) + { + cerr << "Error opening output file " << oFileName << endl; + exit(1); + } + + oPRCFile oPRC(outf); + + string entityType; + while(*ins) + { + *ins >> entityType; + if(!*ins) break; + if(entityType == "Line") + { + double r,g,b,a; + unsigned int numberOfPoints; + *ins >> r >> g >> b >> a >> numberOfPoints; + if(!*ins) + { + cerr << "Error reading line data." << endl; + exit(1); + } + else + { + double (*points)[3] = new double[numberOfPoints][3]; + readPoints(*ins,numberOfPoints,points); + oPRC.add(new PRCline(&oPRC,numberOfPoints,points, + *new RGBAColour(r,g,b,a))); + } + } + else if(entityType == "Curve") + { + double r,g,b,a; + unsigned int numberOfPoints; + unsigned int degree; + *ins >> r >> g >> b >> a >> degree >> numberOfPoints; + if(!*ins) + { + cerr << "Error reading curve data." << endl; + exit(1); + } + else + { + double (*points)[3] = new double[numberOfPoints][3]; + double *knots = new double[degree+numberOfPoints+1]; + readPoints(*ins,numberOfPoints,points); + readDoubles(*ins,degree+numberOfPoints+1,knots); + oPRC.add(new PRCcurve(&oPRC,degree,numberOfPoints,points, + knots,*new RGBAColour(r,g,b,a))); + } + } + else if(entityType == "Surface") + { + double r,g,b,a; + unsigned int numberOfPointsU,numberOfPointsV; + unsigned int degreeU,degreeV; + *ins >> r >> g >> b >> a >> degreeU >> degreeV >> numberOfPointsU + >> numberOfPointsV; + if(!*ins) + { + cerr << "Error reading surface data." << endl; + exit(1); + } + else + { + double (*points)[3] = new double[numberOfPointsU*numberOfPointsV][3]; + double *knotsU = new double[degreeU+numberOfPointsU+1]; + double *knotsV = new double[degreeV+numberOfPointsV+1]; + readPoints(*ins,numberOfPointsU*numberOfPointsV,points); + readDoubles(*ins,degreeU+numberOfPointsU+1,knotsU); + readDoubles(*ins,degreeV+numberOfPointsV+1,knotsV); + oPRC.add(new PRCsurface(&oPRC,degreeU,degreeV,numberOfPointsU, + numberOfPointsV,points,knotsU,knotsV, + *new RGBAColour(r,g,b,a))); + } + } + else + { + cerr << "Unrecognized entity type " << entityType << endl; + exit(1); + } + } + + if(ins && ins != &cin) + delete ins; + + + oPRC.finish(); + + outf.close(); + + return 0; +} |