From 541c26e6012829b3d5d719ebe030ddcbbc73c3c9 Mon Sep 17 00:00:00 2001 From: cnr-isti-vclab Date: Wed, 28 Sep 2005 10:46:04 +0000 Subject: [PATCH] Added possibility of saving File in OFF format --- apps/trimeshinfo/trimeshinfo.cpp | 80 ++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 14 deletions(-) diff --git a/apps/trimeshinfo/trimeshinfo.cpp b/apps/trimeshinfo/trimeshinfo.cpp index 6bfd2099..0db71262 100644 --- a/apps/trimeshinfo/trimeshinfo.cpp +++ b/apps/trimeshinfo/trimeshinfo.cpp @@ -24,6 +24,10 @@ History $Log: not supported by cvs2svn $ +Revision 1.1 2005/09/20 10:15:27 rita_borgo +Changed file name to uniform with other solution projects, + before was main.cpp + Revision 1.8 2005/02/15 12:26:06 rita_borgo Minor changes to self-intersection @@ -66,8 +70,11 @@ using namespace std; #include #include #include +#include +#include #include "XMLTree.h" +#include // loader @@ -85,6 +92,8 @@ class MyVertex:public Vertex{}; class MyFace :public FaceAFAV{}; class MyMesh: public tri::TriMesh< std::vector, std::vector >{}; +string ans; + void OpenMesh(const char *filename, MyMesh &m) { int err = tri::io::Importer::Open(m,filename); @@ -123,6 +132,7 @@ public: static int DuplicateVertex( MyMesh & m ) // V1.0 { + if(m.vert.size()==0 || m.vn==0) return 0; std::map mp; @@ -148,11 +158,21 @@ static int DuplicateVertex( MyMesh & m ) // V1.0 (! (*perm[j]).IsD()) && (*perm[i]).P() == (*perm[j]).cP() ) { - VertexPointer t = perm[i]; - mp[perm[i]] = perm[j]; - ++i; - (*t).SetD(); - deleted++; + if(deleted ==0) + { + cout<< "\t Found Duplicated Vertices"<< endl; + cout<< "\t do you want to remove them? [y/Y| n/N]\n"; + cin>>ans; + } + if((ans == "s") ||(ans=="S")) + { + VertexPointer t = perm[i]; + mp[perm[i]] = perm[j]; + (*t).SetD(); + m.vn--; + } + ++i; + deleted++;// per evitare che su risposta no rifaccia la domanda ad ogni vertice che incontra; } else { @@ -160,13 +180,15 @@ static int DuplicateVertex( MyMesh & m ) // V1.0 ++i; } } + ans.clear(); return deleted; } void main(int argc,char ** argv){ - char *fmt; + MyMesh m; bool DEBUG = true; + /*------------XML file part ------------------*/ @@ -190,7 +212,7 @@ void main(int argc,char ** argv){ if(DEBUG) - argv[1] = "C:\\sf\\apps\\msvc\\trimeshinfo\\Release\\cube1.stl"; + argv[1] = "C:\\sf\\apps\\msvc\\trimeshinfo\\cube.ply"; else { @@ -206,6 +228,8 @@ void main(int argc,char ** argv){ OpenMesh(argv[1],m); + + doc.initializeMain(XML_SCHEMA_NAME); char* s1 = "http://www.w3.org/2001/XMLSchema-instance"; char* s2 = new(char[50]); @@ -259,6 +283,7 @@ void main(int argc,char ** argv){ sn->addOwnSlot(osn); ng->addNode(osn); + if(m.HasPerFaceColor()||m.HasPerVertexColor()) { @@ -286,7 +311,7 @@ void main(int argc,char ** argv){ vcg::tri::UpdateTopology::FaceFace(m); - + // IS MANIFOLD MyMesh::FaceIterator f; @@ -411,7 +436,6 @@ void main(int argc,char ** argv){ ng->addNode(osn); - // DA QUI IN POI!!! // DEGENERATED FACES @@ -931,7 +955,8 @@ void main(int argc,char ** argv){ osn->setName("Oriented Mesh"); osn->addEntry(*en); sn->addOwnSlot(osn); - ng->addNode(osn); } + ng->addNode(osn); + } else { fprintf(index, "

Oriented Mesh: NO

"); @@ -948,13 +973,14 @@ void main(int argc,char ** argv){ osn->setName("Oriented Mesh"); osn->addEntry(*en); sn->addOwnSlot(osn); - ng->addNode(osn); } + ng->addNode(osn); + } int dv = DuplicateVertex(m); if(dv>0) { fprintf(index, "

Duplicated vertices: %d

", dv); - printf( "\t Duplicated vertices: %d\n",dv); - s = new(char[25]); + printf( "\t Number of duplicated vertices found: %d\n",dv); + s = new(char[25]); vn = new ValueNode; en = new EntryNode; osn = new OwnSlotNode; @@ -988,7 +1014,6 @@ void main(int argc,char ** argv){ ng->addNode(osn); } // SELF INTERSECTION - if (m.fn<300000) { bool SelfInt=false; @@ -1045,6 +1070,33 @@ void main(int argc,char ** argv){ ng->addNode(osn); } } + + + + string fs; + + cout<< "\t To save the file: [s/S]"<< endl; + cin>>ans; + + + if((ans == "S")||(ans == "s")) + cout<< "\t available formats: [ply, off, stl] "<>ans; + cout<<"\t enter filename"<>fs; + const char* filesave = fs.c_str(); + if(ans == "ply") + tri::io::ExporterPLY::Save(m, filesave); + else if(ans == "stl") + tri::io::ExporterSTL::Save(m,filesave); + else if(ans == "dxf") + tri::io::ExporterDXF::Save(m,filesave); + + else if(ans == "off") + tri::io::ExporterOFF::Save(m,filesave); + + doc.addSlots(sn); OwnSlotsNode* ossn = new OwnSlotsNode; ossn->addOwnSlot(ng);