From ebf6ae99a48fed3133bdaec4d1704ebee97f4936 Mon Sep 17 00:00:00 2001 From: maxcorsini Date: Mon, 19 Dec 2005 11:35:13 +0000 Subject: [PATCH] Add html output support --- apps/trimeshinfo/trimeshinfo.cpp | 141 ++++++++++++++++++++++++++++--- 1 file changed, 130 insertions(+), 11 deletions(-) diff --git a/apps/trimeshinfo/trimeshinfo.cpp b/apps/trimeshinfo/trimeshinfo.cpp index 5d2ccc95..c8437e68 100644 --- a/apps/trimeshinfo/trimeshinfo.cpp +++ b/apps/trimeshinfo/trimeshinfo.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.21 2005/12/16 11:16:36 corsini +Add manifold check to some properties + Revision 1.20 2005/12/15 11:20:00 corsini Add vertex-face topology @@ -109,6 +112,7 @@ Added Standard comments ****************************************************************************/ // Standard headers +#include #include #include #include @@ -178,6 +182,44 @@ struct MeshInfo bool SelfIntersect; }; + +static const int HTML_LINES = 31; +static const char * HTML_TABLE[HTML_LINES]= +{ +"", +" ", +" ", +" description.html", +" ", +" ", +" ", +"

TriMeshInfo V.1.2 - Results

", +"

", +" ", +" ", +" ", +" Name", +" Vertices", +" Faces", +" Edges", +" Holes", +" Connected
Components", +" Isolated
Vertices", +" Duplicated
Vertices", +" Self
Interesection", +" Manifold", +" Orientable/
Oriented", +" Genus", +" ", +" ", +" ", +" ", +"" +}; + + void OpenMesh(const char *filename, CMesh &m) { printf(" Mesh loading..."); @@ -323,26 +365,99 @@ void SaveXMLInfo(MeshInfo &mi) doc.printXMLTree(); } +void SaveMeshInfoHtmlTable(fstream &fout, MeshInfo &mi) +{ + fout << " " << std::endl; + fout << " " << mi.FileName << "" << std::endl; + fout << " " << mi.vn << "" << std::endl; + fout << " " << mi.fn << "" << std::endl; + fout << " " << mi.count_e << "" << std::endl; + fout << " " << mi.numholes << "" << std::endl; + fout << " " << mi.numcomponents << "" << std::endl; + fout << " " << mi.count_uv << "" << std::endl; + fout << " " << mi.dv << "" << std::endl; + + if (mi.SelfIntersect) + fout << " Yes" << std::endl; + else + fout << " No" << std::endl; + + if (mi.Manifold) + fout << " Yes" << std::endl; + else + fout << " No" << std::endl; + + if ((mi.Orientable)&&(mi.Oriented)) + fout << " Yes / Yes" << std::endl; + else if ((mi.Orientable)&&(!mi.Oriented)) + fout << " Yes / No" << std::endl; + else if (!mi.Orientable) + fout << " No / No" << std::endl; + + fout << " " << mi.Genus << "" << std::endl; + + fout << " " << std::endl; +} + void SaveHtmlInfo(MeshInfo &mi) { - ofstream fout; + char buff[1024]; + bool flagInsert = false; + ifstream fin; + fstream fout; - fout.open("result.txt", ios::out); - - if (!fout) + // Try to open + fin.open("result.html"); + long pos; + if (fin.is_open()) { - printf("\n Impossible to create the HTML output file.\n"); + while (!fin.eof()) + { + pos = fin.tellg(); + fin.getline(buff, 1024); + string str(buff); + if (str == " ") + break; + } + flagInsert = true; + } + fin.close(); + + if (flagInsert) + fout.open("result.html", ios::in | ios::out); + else + fout.open("result.html", ios::out); + + if (!fout.is_open()) + { + printf("\n Impossible to write the HTML output file.\n"); } else { - char dquotes = 32; // double quotes + if (flagInsert) + { + // Insert the mesh information into an existing table + fout.seekp(pos, ios::beg); - fout << "" << endl; - fout << "...todo..." << endl; - fout << "<\table>"; + SaveMeshInfoHtmlTable(fout, mi); - fout.close(); + for (int i = HTML_LINES - 4; i < HTML_LINES; i++) + fout << HTML_TABLE[i] << std::endl; + } + else + { + // Create a new table + for (int i = 0; i < HTML_LINES - 4; i++) + fout << HTML_TABLE[i] << std::endl; + + SaveMeshInfoHtmlTable(fout, mi); + + for (int i = HTML_LINES - 4; i < HTML_LINES; i++) + fout << HTML_TABLE[i] << std::endl; + } } + + fout.close(); } int main(int argc, char ** argv) @@ -484,6 +599,9 @@ int main(int argc, char ** argv) mi.Orientable = false; } + // Rebuild Vertex-Face topology + tri::UpdateTopology::VertexFace(m); + // VOLUME (require a closed oriented manifold) if ((mi.Manifold)&&(mi.Oriented)&&(!mi.numholes)) { @@ -510,7 +628,8 @@ int main(int argc, char ** argv) mi.dv = tri::Clean::RemoveDuplicateVertex(m); // SELF INTERSECTION - mi.SelfIntersect = tri::Clean::SelfIntersections(m); + vector intersected; + mi.SelfIntersect = tri::Clean::SelfIntersections(m, intersected); // Mesh Information Output //////////////////////////////////////////