From bdb503ef17eb0a3e9a08cae53a07b959ad7c5e0e Mon Sep 17 00:00:00 2001 From: ponchio Date: Sun, 12 Dec 2004 20:50:07 +0000 Subject: [PATCH] Created --- apps/nexus/nxstest.cpp | 128 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 apps/nexus/nxstest.cpp diff --git a/apps/nexus/nxstest.cpp b/apps/nexus/nxstest.cpp new file mode 100644 index 00000000..0f693709 --- /dev/null +++ b/apps/nexus/nxstest.cpp @@ -0,0 +1,128 @@ +#include + +#include "nexus.h" +#include "watch.h" + +using namespace vcg; +using namespace std; +using namespace nxs; + +int main(int argc, char *argv[]) { + if(argc != 2) { + cerr << "Usage: " << argv[0] << " \n"; + return -1; + } + Nexus nexus; + if(!nexus.Load(argv[1], true)) { + cerr << "Could not open file: " << argv[1] << endl; + return -1; + } + Report report(nexus.index.size()); + for(unsigned int patchid = 0; patchid < nexus.index.size(); patchid++) { + report.Step(patchid); + Nexus::PatchInfo &info = nexus.index[patchid]; + Patch &patch = nexus.GetPatch(patchid); + for(int f = 0; f < patch.nf; f++) { + unsigned short *face = patch.Face(f); + for(int k = 0; k < 3; k++) { + if(face[k] > patch.nv) { + cerr << "Invalid face number: " << face[k] << " > " << patch.nv << endl; + cerr << "At patch: " << patchid << endl; + //exit(0); + } + } + } + Sphere3f &sphere = info.sphere; + for(int v = 0; v < patch.nv; v++) { + Point3f &p = patch.Vert(v); + float dist = Distance(sphere, p); + if(dist > 0.001) { + //if(!info.sphere.IsIn(p)) { + cerr << "Vertex outside bound: (" << p[0] << " " << p[1] << " " << p[2] << ")\n"; + Point3f &c = sphere.Center(); + cerr << "Sphere: (" << c[0] << " " << c[1] << " " << c[2] << ") R: " << sphere.Radius() << endl;; + cerr << "Distance: " << dist << endl; + cerr << "At patch: " << patchid << endl; + + } + } + } + report.Finish(); + + cerr << "Testing borders\n"; + + for(unsigned int patchid = 0; patchid < nexus.index.size(); patchid++) { + Nexus::PatchInfo &info = nexus.index[patchid]; + Border border = nexus.GetBorder(patchid); + for(unsigned int i = 0; i < border.Size(); i++) { + Link &link = border[i]; + if(link.start_vert == 0 && link.end_vert == 0 && link.end_patch == 0) { + cerr << "patch: " << patchid << " corrupted memory?" << endl; + } + if(link.IsNull()) { + cerr << "Null link: " << i << " at patch: " << patchid << endl; + exit(0); + } + if(link.end_patch < 0 || link.end_patch >= nexus.index.size()) { + cerr << "Invalid link end patch: " << link.end_patch << " at patch: " << patchid << endl; + exit(0); + } + if(link.start_vert > info.nvert) { + cerr << "Invalid link start_vert: " << link.start_vert << " at patch: " << patchid << endl; + exit(0); + } + if(link.end_vert > nexus.index[link.end_patch].nvert) { + cerr << "Invalid link end vert: " << link.end_vert << " at patch: " << patchid << endl; + exit(0); + } + } + } + + cerr << "Reciprocity borders test\n"; + for(unsigned int patchid = 0; patchid < nexus.index.size(); patchid++) { + Nexus::PatchInfo &info = nexus.index[patchid]; + Border border = nexus.GetBorder(patchid); + vector links; + links.resize(border.Size()); + memcpy(&*links.begin(),&(border[0]),links.size() * sizeof(Link)); + for(unsigned int i = 0; i < links.size(); i++) { + Link &link = links[i]; + Border rborder = nexus.GetBorder(link.end_patch); + + bool found = false; + for(unsigned int k = 0; k < rborder.Size(); k++) { + Link rlink = rborder[k]; + if(rlink.end_patch == patchid) { + + if(rlink.end_vert == link.start_vert) { + if(rlink.start_vert != link.end_vert) { + cerr << "Something wrong with links!\n"; + exit(0); + } + found = true; + break; + } + if(rlink.start_vert == link.end_vert) { + if(rlink.end_vert != link.start_vert) { + cerr << "Something wrong with links!\n"; + exit(0); + } + found = true; + break; + } + } + } + if(!found) { + cerr << "A link is one way from patch: " << patchid << " vert: " << link.start_vert + << " to patch: " << link.end_patch << " vert: " << link.end_vert << endl; + for(unsigned int t = 0; t < rborder.Size(); t++) { + Link &rlink = rborder[t]; + cerr << rlink.start_vert << " -> p: " << rlink.end_patch << " v: " << rlink.end_vert << endl; + } + exit(0); + } + } + } + + return 0; +} \ No newline at end of file