#include "BYUToMeta.h" namespace mial{ // Convert BYU surface files to .meta files. Assumes 1 object per file and a 3D triangular mesh. int BYUToMeta( std::string BYUFileName, std::string metaFileName ) { int SUCCESS = 1; int FAILURE = -1; std::ifstream inFile( BYUFileName.c_str() ); if( !inFile.good() ) { std::cerr << "Error opening input file '" << BYUFileName << "'." << std::endl; return FAILURE; } std::ofstream outFile( metaFileName.c_str() ); //std::ofstream outFile( "C:\\Documents and Settings\\arova\\Desktop\\defOrgs_working_copy\\examples\\DefOrgViewer\\Build\\data\\OFTest" ); if( !outFile.good() ) { std::cerr << "Error creating output file '" << metaFileName << "'." << std::endl; return FAILURE; } // BYU format first line is PART_NUM, VERTEX_NUM, POLY_NUM int partNum; inFile >> partNum; // assume PART_NUM will always be 1: if( partNum != 1 ) { std::cerr << "Format error, PART_NUM (the first number in the file) is " << partNum << ". This function expects PART_NUM to be 1." << std::endl; return FAILURE; } int nVertices, nTriangles; inFile >> nVertices >> nTriangles; // write meta header: outFile << "ObjectType = Scene" << std::endl << "NDims = 3" << std::endl << "NObjects = 1" << std::endl << "ObjectType = Mesh" << std::endl << "NDims = 3" << std::endl << "ID = 0" << std::endl << "TransformMatrix = 1 0 0 0 1 0 0 0 1" << std::endl << "Offset = 0 0 0" << std::endl << "CenterOfRotation = 0 0 0" << std::endl << "ElementSpacing = 1 1 1" << std::endl << "PointType = MET_FLOAT" << std::endl << "PointDataType = MET_FLOAT" << std::endl << "CellDataType = MET_FLOAT" << std::endl << "NCellTypes = 1" << std::endl << "PointDim = ID x y ..." << std::endl << "NPoints = " << nVertices << std::endl << "Points = " << std::endl; // read/write vertex data: double vertex; for( int i=0; i> vertex; outFile << vertex << " "; } outFile << std::endl; } // write more info required by meta format: outFile << "CellType = TRI" << std::endl << "NCells = " << nTriangles << std::endl << "Cells = " << std::endl; // read and write corrected triangle data: double tIndex; //for( int i=0; i> tIndex; tIndex -= 1; outFile << tIndex << " "; } inFile >> tIndex; tIndex = abs( tIndex ); tIndex -= 1; outFile << tIndex << std::endl; } // clean up: inFile.close(); outFile.close(); return SUCCESS; } }