int main(int argc, char *argv[]) { vector<string> inputFiles; char *outFile = NULL; RawDataBase outObjects; char *stripPrefix = NULL; int text = 0; int nocompress = 0; for (int i=1; i < argc; i++) { if (!strcmp(argv[i], "-o")) { i++; if (i < argc) { outFile = argv[i]; } } else if (!strcmp(argv[i], "-sp")) { i++; if (i < argc) { stripPrefix = argv[i]; } } else if (!strcmp(argv[i], "-t")) { text = 1; } else if (!strcmp(argv[i], "-nc")) { nocompress = 1; } else if (*argv[i] == '-') { usage(); } else { inputFiles.push_back(argv[i]); } } if (!inputFiles.size() || !outFile) { cout << "no infile or outfile specified.\n" << flush; cout << endl; usage(); } for (size_t i=0; i < inputFiles.size(); i++) { RawDataBaseReader reader; cout << "Reading input file " << inputFiles[i] << "..." << endl; if (!reader.open(inputFiles[i].c_str())) { cerr << "ERROR: unable to read file " << inputFiles[i].c_str() << endl; exit(-1); } else { RawDataBase *inObjects = reader.dataBase(); objectMerge(&outObjects, inObjects, stripPrefix); } } RawDataBaseWriter writer; Writer::FileType type = Writer::CompressedGTO; if (nocompress) type = Writer::BinaryGTO; if (text) type = Writer::TextGTO; if (!writer.write(outFile, outObjects, type)) { cerr << "ERROR: unable to write file " << outFile << endl; exit(-1); } else { cout << "Wrote file " << outFile << endl; } return 0; }
// ***************************************************************************** int inputFromGto( const char *filename, bool ascii, bool verbose ) { using namespace Gto; GU_Detail gdp; RawDataBaseReader reader; if( verbose ) std::cerr << "Loading " << filename << "..." << std::flush; if( ! reader.open( filename ) ) { std::cerr << "Unable to load input geometry" << std::endl; exit(1); } if( verbose ) std::cerr << "Done" << std::endl; if( verbose ) std::cerr << "Building objects..." << std::flush; const RawDataBase *db = reader.dataBase(); for( int oi = 0; oi < db->objects.size(); ++oi ) { const Object *o = db->objects[oi]; if( o->protocol == GTO_PROTOCOL_PARTICLE || o->protocol == "warped particle") { HGto::Particle particle( o->name ); for( int ci = 0; ci < o->components.size(); ++ci ) { const Component *c = o->components[ci]; for( int pi = 0; pi < c->properties.size(); ++pi ) { Property *p = c->properties[pi]; if( c->name == GTO_COMPONENT_OBJECT ) { if( p->name == GTO_PROPERTY_GLOBAL_MATRIX ) { memcpy( &particle.globalMatrix(), p->floatData, p->size * p->width * sizeof(float) ); } } if( c->name == GTO_COMPONENT_POINTS ) { if( p->name == GTO_PROPERTY_POSITION ) { particle.positions().resize( p->size ); memcpy( &particle.positions().front(), p->floatData, p->size * p->width * sizeof(float) ); } else { // For all other properties HGto::GtoAttribute *attr = NULL; if( p->type == Gto::Float && p->width == 1) { attr = new HGto::FloatAttribute(p->name, p->size); HGto::FloatAttribute *fattr = (HGto::FloatAttribute*)attr; memcpy(&fattr->data().front(), p->floatData, sizeof( float ) * p->size); particle.attributes().push_back(attr); } else if( p->type == Gto::Float && p->width == 3) { attr = new HGto::VectorAttribute(p->name, p->size); HGto::VectorAttribute *vattr = (HGto::VectorAttribute*)attr; memcpy(&vattr->data().front(), p->floatData, sizeof( float ) * p->size * 3); particle.attributes().push_back(attr); } else if( p->type == Gto::Int && p->width == 1) { attr = new HGto::IntAttribute(p->name, p->size); HGto::IntAttribute *iattr = (HGto::IntAttribute*)attr; memcpy(&iattr->data().front(), p->int32Data, sizeof( int ) * p->size * 1); particle.attributes().push_back(attr); } } } } } particle.declareHoudini( gdp ); } else if( o->protocol == GTO_PROTOCOL_POLYGON ) { HGto::Poly polyObject( o->name ); for( int ci = 0; ci < o->components.size(); ++ci ) { const Component *c = o->components[ci]; for( int pi = 0; pi < c->properties.size(); ++pi ) { const Property *p = c->properties[pi]; if( c->name == GTO_COMPONENT_OBJECT ) { if( p->name == GTO_PROPERTY_GLOBAL_MATRIX ) { memcpy( &polyObject.globalMatrix(), p->floatData, p->size * p->width * sizeof(float) ); } } if( c->name == GTO_COMPONENT_POINTS ) { if( p->name == GTO_PROPERTY_POSITION ) { polyObject.positions().resize( p->size ); memcpy( &polyObject.positions().front(), p->floatData, p->size * p->width * sizeof(float) ); } } if( c->name == GTO_COMPONENT_ELEMENTS ) { if( p->name == GTO_PROPERTY_TYPE ) { polyObject.elementsType().resize( p->size ); memcpy( &polyObject.elementsType().front(), p->uint8Data, p->size * p->width * sizeof(char) ); } if( p->name == GTO_PROPERTY_SIZE ) { polyObject.elementsSize().resize( p->size ); memcpy( &polyObject.elementsSize().front(), p->uint16Data, p->size * p->width * sizeof(short) ); } } if( c->name == GTO_COMPONENT_INDICES ) { if( p->name == GTO_PROPERTY_VERTEX ) { polyObject.indicesVertex().resize( p->size ); memcpy( &polyObject.indicesVertex().front(), p->int32Data, p->size * p->width * sizeof(int) ); } } if( c->name == GTO_COMPONENT_SMOOTHING ) { if( p->name == GTO_PROPERTY_METHOD ) { polyObject.smoothingMethod() = *(p->int32Data); } } } } polyObject.declareHoudini( gdp ); } } if( verbose ) std::cerr << "Done" << std::endl; if( verbose ) std::cerr << "Writing to stdout..." << std::flush; gdp.save( std::cout, ! ascii ); if( verbose ) std::cerr << "Done" << std::endl; return 0; }
int main(int argc, char *argv[]) { char *inFile = 0; char *outFile = 0; char *includeExpr = 0; char *excludeExpr = 0; for (int i=1; i < argc; i++) { if (!strcmp(argv[i], "-o")) { i++; if (i >= argc) usage(); outFile = argv[i]; } else if (!strcmp(argv[i], "-ie") || !strcmp(argv[i], "--include")) { i++; if (i >= argc) usage(); includeExpr = argv[i]; } else if (!strcmp(argv[i], "-ee") || !strcmp(argv[i], "--exclude")) { i++; if (i >= argc) usage(); excludeExpr = argv[i]; } else if (!strcmp(argv[i], "-v")) { verbose = true; } else if (!strcmp(argv[i], "-nc")) { nocompress = true; } else if (!strcmp(argv[i], "-t")) { text = true; } else if (!strcmp(argv[i], "-glob")) { glob = true; } else if (!strcmp(argv[i], "-regex")) { glob = false; } else if (*argv[i] == '-') { usage(); } else { if (inFile) usage(); inFile = argv[i]; } } if (!inFile || !outFile) { cout << "no infile or outfile specified.\n" << flush; cout << endl; usage(); } if (!glob) { if (excludeExpr) { if (int err = regcomp(&excludeRegex, excludeExpr, REG_NOSUB)) { char temp[256]; regerror(err, &excludeRegex, temp, 256); cerr << "ERROR: " << temp << endl; exit(-1); } } if (includeExpr) { if (int err = regcomp(&includeRegex, includeExpr, REG_NOSUB)) { char temp[256]; regerror(err, &includeRegex, temp, 256); cerr << "ERROR: " << temp << endl; exit(-1); } } } RawDataBaseReader reader; cout << "Reading input file " << inFile << "..." << endl; if (!reader.open(inFile)) { cerr << "ERROR: unable to read file " << inFile << endl; exit(-1); } RawDataBase *db = reader.dataBase(); FullProperties allProperties; gather(db, allProperties); filter(db, allProperties, includeExpr, excludeExpr); if (db->objects.empty()) { cerr << "ERROR: everything was excluded" << endl; exit(-1); } RawDataBaseWriter writer; Writer::FileType type = Writer::CompressedGTO; if (nocompress) type = Writer::BinaryGTO; if (text) type = Writer::TextGTO; if (!writer.write(outFile, *db, type)) { cerr << "ERROR: unable to write file " << outFile << endl; exit(-1); } else { cout << "Wrote file " << outFile << endl; } return 0; }