2005-02-08 13:43:03 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* VCGLib o o *
|
|
|
|
* Visual and Computer Graphics Library o o *
|
|
|
|
* _ O _ *
|
|
|
|
* Copyright(C) 2004 \/)\/ *
|
|
|
|
* Visual Computing Lab /\/| *
|
|
|
|
* ISTI - Italian National Research Council | *
|
|
|
|
* \ *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
|
|
|
* for more details. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
|
|
History
|
|
|
|
|
|
|
|
$Log: not supported by cvs2svn $
|
2005-02-20 01:43:24 +01:00
|
|
|
Revision 1.5 2005/02/08 12:43:03 ponchio
|
|
|
|
Added copyright
|
|
|
|
|
2005-02-08 13:43:03 +01:00
|
|
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
2004-12-12 21:50:07 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#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] << " <nexusfile>\n";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
Nexus nexus;
|
|
|
|
if(!nexus.Load(argv[1], true)) {
|
|
|
|
cerr << "Could not open file: " << argv[1] << endl;
|
|
|
|
return -1;
|
|
|
|
}
|
2005-01-24 16:45:00 +01:00
|
|
|
Report report(nexus.size());
|
|
|
|
for(unsigned int patchid = 0; patchid < nexus.size(); patchid++) {
|
2004-12-12 21:50:07 +01:00
|
|
|
report.Step(patchid);
|
2005-01-24 16:45:00 +01:00
|
|
|
Entry &info = nexus[patchid];
|
2004-12-12 21:50:07 +01:00
|
|
|
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) {
|
2005-02-20 01:43:24 +01:00
|
|
|
cerr << "Invalid face number: " << face[k] << " > "
|
|
|
|
<< patch.nv << endl;
|
2004-12-12 21:50:07 +01:00
|
|
|
cerr << "At patch: " << patchid << endl;
|
2005-02-20 01:43:24 +01:00
|
|
|
cerr << "start: " << info.patch_start << endl;
|
|
|
|
cerr << "nf: " << info.nface << " nv: " << info.nvert << endl;
|
2004-12-12 21:50:07 +01:00
|
|
|
//exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Sphere3f &sphere = info.sphere;
|
|
|
|
for(int v = 0; v < patch.nv; v++) {
|
2005-02-20 01:43:24 +01:00
|
|
|
Point3f &p = patch.Vert3f(v);
|
2004-12-12 21:50:07 +01:00
|
|
|
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";
|
|
|
|
|
2005-01-24 16:45:00 +01:00
|
|
|
for(unsigned int patchid = 0; patchid < nexus.size(); patchid++) {
|
|
|
|
Entry &info = nexus[patchid];
|
2005-01-21 18:09:13 +01:00
|
|
|
Border &border = nexus.GetBorder(patchid);
|
2004-12-12 21:50:07 +01:00
|
|
|
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);
|
|
|
|
}
|
2005-01-24 16:45:00 +01:00
|
|
|
if(link.end_patch < 0 || link.end_patch >= nexus.size()) {
|
2004-12-12 21:50:07 +01:00
|
|
|
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);
|
|
|
|
}
|
2005-01-24 16:45:00 +01:00
|
|
|
if(link.end_vert > nexus[link.end_patch].nvert) {
|
2004-12-12 21:50:07 +01:00
|
|
|
cerr << "Invalid link end vert: " << link.end_vert << " at patch: " << patchid << endl;
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cerr << "Reciprocity borders test\n";
|
2005-01-24 16:45:00 +01:00
|
|
|
for(unsigned int patchid = 0; patchid < nexus.size(); patchid++) {
|
|
|
|
Entry &info = nexus[patchid];
|
2005-01-21 18:09:13 +01:00
|
|
|
Border &border = nexus.GetBorder(patchid);
|
2004-12-12 21:50:07 +01:00
|
|
|
vector<Link> 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];
|
2005-01-21 18:09:13 +01:00
|
|
|
Border &rborder = nexus.GetBorder(link.end_patch, false);
|
2004-12-12 21:50:07 +01:00
|
|
|
|
|
|
|
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;
|
2004-12-13 01:44:48 +01:00
|
|
|
}
|