00001 #include "BYUToMeta.h"
00002
00003
00004 int BYUToMeta( std::string BYUFileName, std::string metaFileName )
00005 {
00006 int SUCCESS = 1;
00007 int FAILURE = -1;
00008
00009 std::ifstream inFile( BYUFileName.c_str() );
00010 if( !inFile.good() )
00011 {
00012 std::cerr << "Error opening input file '" << BYUFileName << "'." << std::endl;
00013 return FAILURE;
00014 }
00015
00016 std::ofstream outFile( metaFileName.c_str() );
00017
00018 if( !outFile.good() )
00019 {
00020 std::cerr << "Error creating output file '" << metaFileName << "'." << std::endl;
00021 return FAILURE;
00022 }
00023
00024
00025 int partNum;
00026 inFile >> partNum;
00027
00028 if( partNum != 1 )
00029 {
00030 std::cerr << "Format error, PART_NUM (the first number in the file) is " << partNum
00031 << ". This function expects PART_NUM to be 1." << std::endl;
00032 return FAILURE;
00033 }
00034
00035 int nVertices, nTriangles;
00036 inFile >> nVertices >> nTriangles;
00037
00038
00039 outFile << "ObjectType = Scene" << std::endl
00040 << "NDims = 3" << std::endl
00041 << "NObjects = 1" << std::endl
00042 << "ObjectType = Mesh" << std::endl
00043 << "NDims = 3" << std::endl
00044 << "ID = 0" << std::endl
00045 << "TransformMatrix = 1 0 0 0 1 0 0 0 1" << std::endl
00046 << "Offset = 0 0 0" << std::endl
00047 << "CenterOfRotation = 0 0 0" << std::endl
00048 << "ElementSpacing = 1 1 1" << std::endl
00049 << "PointType = MET_FLOAT" << std::endl
00050 << "PointDataType = MET_FLOAT" << std::endl
00051 << "CellDataType = MET_FLOAT" << std::endl
00052 << "NCellTypes = 1" << std::endl
00053 << "PointDim = ID x y ..." << std::endl
00054 << "NPoints = " << nVertices << std::endl
00055 << "Points = " << std::endl;
00056
00057
00058 double vertex;
00059 for( int i=0; i<nVertices; i++ )
00060 {
00061 outFile << i << " ";
00062 for( unsigned int j=0; j<3; j++ )
00063 {
00064 inFile >> vertex;
00065 outFile << vertex << " ";
00066 }
00067 outFile << std::endl;
00068 }
00069
00070
00071 outFile << "CellType = TRI" << std::endl
00072 << "NCells = " << nTriangles << std::endl
00073 << "Cells = " << std::endl;
00074
00075
00076 double tIndex;
00077
00078 int i = -1;
00079 while( inFile.peek() != EOF )
00080 {
00081 i++;
00082 outFile << i << " ";
00083 for( unsigned int j=0; j<2; j++ )
00084 {
00085 inFile >> tIndex;
00086 tIndex -= 1;
00087 outFile << tIndex << " ";
00088 }
00089 inFile >> tIndex;
00090 tIndex = abs( tIndex );
00091 tIndex -= 1;
00092 outFile << tIndex << std::endl;
00093 }
00094
00095
00096 inFile.close();
00097 outFile.close();
00098
00099 return SUCCESS;
00100 }