2004-10-19 03:19:46 +02:00
|
|
|
#include "fragment.h"
|
|
|
|
#include "border.h"
|
|
|
|
#include "pvoronoi.h"
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace vcg;
|
|
|
|
using namespace nxs;
|
|
|
|
using namespace pt;
|
|
|
|
|
2004-10-22 12:34:13 +02:00
|
|
|
void NxsPatch::Write(outstm *out) {
|
2004-10-19 03:19:46 +02:00
|
|
|
int vsize = vert.size();
|
|
|
|
int fsize = face.size();
|
|
|
|
int bsize = bord.size();
|
|
|
|
|
|
|
|
out->write(&patch, sizeof(unsigned int));
|
|
|
|
out->write(&vsize, sizeof(unsigned int));
|
|
|
|
out->write(&fsize, sizeof(unsigned int));
|
|
|
|
out->write(&bsize, sizeof(unsigned int));
|
|
|
|
|
|
|
|
out->write(&*vert.begin(), vert.size() * sizeof(Point3f));
|
|
|
|
out->write(&*face.begin(), face.size() * sizeof(unsigned short));
|
|
|
|
out->write(&*bord.begin(), bord.size() * sizeof(Link));
|
|
|
|
}
|
|
|
|
|
2004-10-22 12:34:13 +02:00
|
|
|
void NxsPatch::Read(instm *in) {
|
2004-10-19 03:19:46 +02:00
|
|
|
int vsize;
|
|
|
|
int fsize;
|
|
|
|
int bsize;
|
|
|
|
|
|
|
|
in->read(&patch, sizeof(unsigned int));
|
|
|
|
in->read(&vsize, sizeof(unsigned int));
|
|
|
|
in->read(&fsize, sizeof(unsigned int));
|
|
|
|
in->read(&bsize, sizeof(unsigned int));
|
|
|
|
vert.resize(vsize);
|
|
|
|
face.resize(fsize);
|
|
|
|
bord.resize(bsize);
|
|
|
|
in->read(&*vert.begin(), vert.size() * sizeof(Point3f));
|
|
|
|
in->read(&*face.begin(), face.size() * sizeof(unsigned short));
|
|
|
|
in->read(&*bord.begin(), bord.size() * sizeof(Link));
|
|
|
|
}
|
|
|
|
|
2004-11-18 19:30:15 +01:00
|
|
|
bool Fragment::Write(outstm *out) {
|
|
|
|
try {
|
|
|
|
out->write(&id, sizeof(unsigned int));
|
|
|
|
out->write(&error, sizeof(float));
|
|
|
|
unsigned int ssize = seeds.size();
|
|
|
|
out->write(&ssize, sizeof(unsigned int));
|
|
|
|
out->write(&*seeds.begin(), ssize * sizeof(Point3f));
|
|
|
|
out->write(&*seeds_id.begin(), ssize * sizeof(unsigned int));
|
|
|
|
unsigned int psize = pieces.size();
|
|
|
|
out->write(&psize, sizeof(unsigned int));
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < pieces.size(); i++)
|
|
|
|
pieces[i].Write(out);
|
|
|
|
return true;
|
|
|
|
} catch (estream *e) {
|
|
|
|
perr.putf("Error: %s\n", pconst(e->get_message()));
|
|
|
|
delete e;
|
|
|
|
return false;
|
|
|
|
}
|
2004-10-19 03:19:46 +02:00
|
|
|
}
|
|
|
|
|
2004-11-18 19:30:15 +01:00
|
|
|
bool Fragment::Read(instm *in) {
|
|
|
|
try {
|
|
|
|
in->read(&id, sizeof(unsigned int));
|
|
|
|
in->read(&error, sizeof(float));
|
|
|
|
|
|
|
|
//TODO move this control to all read!
|
|
|
|
unsigned int ssize;
|
|
|
|
if(sizeof(int) != in->read(&ssize, sizeof(unsigned int)))
|
|
|
|
return false;
|
|
|
|
seeds.resize(ssize);
|
|
|
|
seeds_id.resize(ssize);
|
|
|
|
in->read(&*seeds.begin(), ssize * sizeof(Point3f));
|
|
|
|
in->read(&*seeds_id.begin(), ssize * sizeof(unsigned int));
|
|
|
|
|
|
|
|
unsigned int psize;
|
|
|
|
in->read(&psize, sizeof(unsigned int));
|
|
|
|
pieces.resize(psize);
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < psize; i++) {
|
|
|
|
pieces[i].Read(in);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} catch (estream *e) {
|
|
|
|
perr.putf("Error: %s\n", pconst(e->get_message()));
|
|
|
|
delete e;
|
|
|
|
return false;
|
|
|
|
}
|
2004-10-19 03:19:46 +02:00
|
|
|
}
|
|
|
|
|
2004-10-22 12:34:13 +02:00
|
|
|
void nxs::Join(Fragment &in,
|
2004-10-19 03:19:46 +02:00
|
|
|
vector<Point3f> &newvert,
|
|
|
|
vector<unsigned int> &newface,
|
2004-10-22 12:34:13 +02:00
|
|
|
vector<BigLink> &newbord) {
|
2004-10-19 03:19:46 +02:00
|
|
|
|
|
|
|
map<unsigned int, unsigned int> patch_remap;
|
|
|
|
vector<unsigned int> offsets;
|
|
|
|
|
|
|
|
unsigned int totvert = 0;
|
|
|
|
for(unsigned int i = 0; i < in.pieces.size(); i++) {
|
|
|
|
offsets.push_back(totvert);
|
|
|
|
patch_remap[in.pieces[i].patch] = i;
|
|
|
|
totvert += in.pieces[i].vert.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<unsigned int> remap;
|
|
|
|
remap.resize(totvert, 0xffffffff);
|
|
|
|
|
2004-10-22 12:34:13 +02:00
|
|
|
//TODO what if totvert > 1<<22?
|
2004-10-19 03:19:46 +02:00
|
|
|
//todo we really need a set?
|
|
|
|
// set<Link> newborders;
|
|
|
|
unsigned int vcount = 0;
|
|
|
|
unsigned int fcount = 0;
|
|
|
|
unsigned int bcount = 0;
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < in.pieces.size(); i++) {
|
|
|
|
unsigned int offset = offsets[i];
|
|
|
|
vector<Point3f> &vert = in.pieces[i].vert;
|
|
|
|
vector<unsigned short> &face = in.pieces[i].face;
|
|
|
|
vector<Link> &bord = in.pieces[i].bord;
|
|
|
|
|
2004-11-28 02:23:26 +01:00
|
|
|
for(unsigned int k = 0; k < face.size(); k+=3) {
|
|
|
|
assert(face[k] != face[k+1]);
|
|
|
|
assert(face[k] != face[k+2]);
|
|
|
|
assert(face[k+1] != face[k+2]);
|
|
|
|
}
|
|
|
|
|
2004-10-19 03:19:46 +02:00
|
|
|
fcount += face.size()/3;
|
|
|
|
|
|
|
|
for(unsigned int k = 0; k < vert.size(); k++) {
|
|
|
|
assert(offset + k < remap.size());
|
|
|
|
if(remap[offset + k] == 0xffffffff)
|
|
|
|
remap[offset + k] = vcount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(unsigned int k = 0; k < bord.size(); k++) {
|
|
|
|
Link link = bord[k];
|
|
|
|
if(link.IsNull()) continue;
|
|
|
|
|
|
|
|
if(patch_remap.count(link.end_patch)) {//internal
|
|
|
|
unsigned int idx = patch_remap[link.end_patch];
|
2004-11-28 02:23:26 +01:00
|
|
|
assert(link.end_patch != in.pieces[i].patch);
|
2004-10-19 03:19:46 +02:00
|
|
|
unsigned int extoffset = offsets[idx];
|
|
|
|
|
|
|
|
assert(extoffset + link.end_vert < remap.size());
|
|
|
|
if(remap[extoffset + link.end_vert] == 0xffffffff) //first time
|
|
|
|
remap[extoffset + link.end_vert] = remap[offset + link.start_vert];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-10-22 12:34:13 +02:00
|
|
|
assert(vcount < (1<<16));
|
2004-10-19 03:19:46 +02:00
|
|
|
|
2004-11-18 19:30:15 +01:00
|
|
|
set<BigLink> newborders;
|
|
|
|
for(unsigned int i = 0; i < in.pieces.size(); i++) {
|
|
|
|
unsigned int offset = offsets[i];
|
|
|
|
vector<Link> &bord = in.pieces[i].bord;
|
|
|
|
for(unsigned int k = 0; k < bord.size(); k++) {
|
|
|
|
Link llink = bord[k];
|
|
|
|
if(llink.IsNull()) continue;
|
|
|
|
if(!patch_remap.count(llink.end_patch)) {//external
|
|
|
|
BigLink link;
|
|
|
|
link.start_vert = remap[offset + llink.start_vert];
|
|
|
|
link.end_patch = in.pieces[i].patch;
|
|
|
|
link.end_vert = llink.start_vert;
|
|
|
|
newborders.insert(link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newvert.resize(vcount);
|
|
|
|
newface.resize(fcount*3);
|
|
|
|
newbord.resize(newborders.size());
|
|
|
|
|
|
|
|
fcount = 0;
|
|
|
|
for(unsigned int i = 0; i < in.pieces.size(); i++) {
|
|
|
|
unsigned int offset = offsets[i];
|
|
|
|
vector<Point3f> &vert = in.pieces[i].vert;
|
|
|
|
vector<unsigned short> &face = in.pieces[i].face;
|
|
|
|
vector<Link> &bord = in.pieces[i].bord;
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < vert.size(); i++) {
|
|
|
|
assert(offset + i < remap.size());
|
|
|
|
assert(remap[offset + i] < vcount);
|
|
|
|
newvert[remap[offset + i]] = vert[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < face.size(); i++) {
|
|
|
|
assert(offset + face[i] < remap.size());
|
|
|
|
assert(remap[offset + face[i]] < newvert.size());
|
|
|
|
assert(fcount < newface.size());
|
|
|
|
newface[fcount++] = remap[offset + face[i]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set<BigLink>::iterator b;
|
2004-11-28 02:23:26 +01:00
|
|
|
for(b = newborders.begin(); b != newborders.end(); b++) {
|
|
|
|
newbord[bcount++] = *b;
|
|
|
|
}
|
2004-11-18 19:30:15 +01:00
|
|
|
|
2004-11-28 02:23:26 +01:00
|
|
|
for(unsigned int i = 0; i < newface.size(); i+= 3) {
|
|
|
|
if(newface[i] == newface[i+1] ||
|
|
|
|
newface[i] == newface[i+2] ||
|
|
|
|
newface[i+1] == newface[i+2]) {
|
|
|
|
cerr << "i: " << i << endl;
|
|
|
|
for(unsigned int k = 0; k < newface.size(); k+=3) {
|
|
|
|
cerr << k << ": " << newface[k] << " "
|
|
|
|
<< newface[k+1] << " "
|
|
|
|
<< newface[k+2] << endl;
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
2004-11-18 19:30:15 +01:00
|
|
|
/* old code (more general.. but not parallelizable)
|
|
|
|
|
|
|
|
|
2004-10-19 03:19:46 +02:00
|
|
|
//L(a, b): Exist link between a, b
|
|
|
|
//An external link L(e, v) where v belongs to the patches (and e not)
|
|
|
|
//is valid only if: for every x in patches L(v, x) => L(e, x)
|
|
|
|
//this means the number of internal links for the same shared
|
|
|
|
//vertex is E = (n * (n-1)) where n is the number of duplicated vertices
|
|
|
|
//and n must be the number of externa links.
|
|
|
|
vector<unsigned int> internal_links;
|
|
|
|
internal_links.resize(vcount, 0);
|
|
|
|
|
2004-10-22 12:34:13 +02:00
|
|
|
map<BigLink, unsigned int> newborders;
|
2004-10-19 03:19:46 +02:00
|
|
|
for(unsigned int i = 0; i < in.pieces.size(); i++) {
|
|
|
|
unsigned int offset = offsets[i];
|
|
|
|
vector<Link> &bord = in.pieces[i].bord;
|
|
|
|
for(unsigned int k = 0; k < bord.size(); k++) {
|
2004-10-22 12:34:13 +02:00
|
|
|
Link llink = bord[k];
|
|
|
|
if(llink.IsNull()) continue;
|
2004-11-18 19:30:15 +01:00
|
|
|
if(!patch_remap.count(llink.end_patch)) {//external...may be erased
|
2004-10-22 12:34:13 +02:00
|
|
|
BigLink link;
|
2004-11-18 19:30:15 +01:00
|
|
|
link.orig_vert = llink.start_vert;
|
|
|
|
link.orig_patch = in.pieces[i].patch;
|
2004-10-22 12:34:13 +02:00
|
|
|
link.start_vert = remap[offset + llink.start_vert];
|
|
|
|
link.end_patch = llink.end_patch;
|
|
|
|
link.end_vert = llink.end_vert;
|
2004-10-19 03:19:46 +02:00
|
|
|
if(!newborders.count(link))
|
|
|
|
newborders[link] = 1;
|
|
|
|
else
|
|
|
|
newborders[link]++;
|
|
|
|
} else { //internal
|
2004-10-22 12:34:13 +02:00
|
|
|
internal_links[remap[offset + llink.start_vert]]++;
|
2004-10-19 03:19:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newvert.resize(vcount);
|
|
|
|
newface.resize(fcount*3);
|
|
|
|
newbord.resize(0);
|
|
|
|
|
|
|
|
fcount = 0;
|
|
|
|
for(unsigned int i = 0; i < in.pieces.size(); i++) {
|
|
|
|
unsigned int offset = offsets[i];
|
|
|
|
vector<Point3f> &vert = in.pieces[i].vert;
|
|
|
|
vector<unsigned short> &face = in.pieces[i].face;
|
|
|
|
vector<Link> &bord = in.pieces[i].bord;
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < vert.size(); i++) {
|
|
|
|
assert(offset + i < remap.size());
|
|
|
|
assert(remap[offset + i] < vcount);
|
|
|
|
newvert[remap[offset + i]] = vert[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < face.size(); i++) {
|
|
|
|
assert(offset + face[i] < remap.size());
|
|
|
|
assert(remap[offset + face[i]] < newvert.size());
|
|
|
|
assert(fcount < newface.size());
|
|
|
|
newface[fcount++] = remap[offset + face[i]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-22 12:34:13 +02:00
|
|
|
map<BigLink, unsigned int>::iterator b;
|
2004-10-19 03:19:46 +02:00
|
|
|
for(b = newborders.begin(); b != newborders.end(); b++) {
|
|
|
|
//test that number of links on this vertex is equal to
|
|
|
|
//number of internal links of the internal vertex
|
2004-10-22 12:34:13 +02:00
|
|
|
const BigLink &link = (*b).first;
|
2004-10-19 03:19:46 +02:00
|
|
|
unsigned int n = (*b).second;
|
|
|
|
if(n * (n-1) == internal_links[link.start_vert])
|
|
|
|
newbord.push_back(link);
|
2004-11-18 19:30:15 +01:00
|
|
|
}*/
|
2004-10-19 03:19:46 +02:00
|
|
|
}
|
|
|
|
|
2004-10-22 12:34:13 +02:00
|
|
|
void nxs::Split(Fragment &out,
|
2004-10-19 03:19:46 +02:00
|
|
|
vector<Point3f> &newvert,
|
|
|
|
vector<unsigned int> &newface,
|
2004-11-18 19:30:15 +01:00
|
|
|
vector<BigLink> &newbord) {
|
2004-10-22 12:34:13 +02:00
|
|
|
|
|
|
|
unsigned int nseeds = out.seeds.size();
|
2004-10-30 22:17:03 +02:00
|
|
|
vector<Point3f> &seeds = out.seeds;
|
2004-10-22 12:34:13 +02:00
|
|
|
vector<unsigned int> &seeds_id = out.seeds_id;
|
|
|
|
//preliminary count
|
|
|
|
vector<unsigned int> count;
|
|
|
|
count.resize(nseeds, 0);
|
|
|
|
for(unsigned int f = 0; f < newface.size(); f += 3) {
|
|
|
|
Point3f bari = (newvert[newface[f]] +
|
|
|
|
newvert[newface[f+1]] +
|
|
|
|
newvert[newface[f+2]])/3;
|
|
|
|
unsigned int seed = out.Locate(bari);
|
|
|
|
assert(seed < nseeds);
|
|
|
|
count[seed]++;
|
|
|
|
}
|
2004-11-18 19:30:15 +01:00
|
|
|
|
2004-10-22 12:34:13 +02:00
|
|
|
//pruning small patches
|
|
|
|
float min_size = (newface.size()/3) / 20.0f;
|
2004-10-30 22:17:03 +02:00
|
|
|
vector<Point3f> newseeds;
|
2004-10-22 12:34:13 +02:00
|
|
|
vector<unsigned int> newseeds_id;
|
2004-11-18 19:30:15 +01:00
|
|
|
|
2004-10-22 12:34:13 +02:00
|
|
|
for(unsigned int seed = 0; seed < nseeds; seed++) {
|
|
|
|
if(count[seed] > min_size) {
|
|
|
|
newseeds.push_back(seeds[seed]);
|
|
|
|
newseeds_id.push_back(seeds_id[seed]);
|
|
|
|
}
|
|
|
|
if(count[seed] > (1<<16)) {
|
|
|
|
cerr << "Ooops a cell came too big... quitting\n";
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
seeds = newseeds;
|
|
|
|
seeds_id = newseeds_id;
|
|
|
|
|
|
|
|
nseeds = seeds.size();
|
|
|
|
|
|
|
|
//if != -1 remap global index to cell index (first arg)
|
|
|
|
vector< vector<int> > vert_remap;
|
|
|
|
vector< vector<int> > face_remap;
|
|
|
|
|
|
|
|
vector<int> vert_count;
|
|
|
|
vector<int> face_count;
|
|
|
|
|
|
|
|
vert_remap.resize(nseeds);
|
|
|
|
face_remap.resize(nseeds);
|
|
|
|
vert_count.resize(nseeds, 0);
|
|
|
|
face_count.resize(nseeds, 0);
|
2004-10-19 03:19:46 +02:00
|
|
|
|
2004-10-22 12:34:13 +02:00
|
|
|
for(unsigned int seed = 0; seed < nseeds; seed++)
|
|
|
|
vert_remap[seed].resize(newvert.size(), -1);
|
|
|
|
|
|
|
|
for(unsigned int f = 0; f < newface.size(); f += 3) {
|
|
|
|
Point3f bari = (newvert[newface[f]] +
|
|
|
|
newvert[newface[f+1]] +
|
|
|
|
newvert[newface[f+2]])/3;
|
|
|
|
|
|
|
|
unsigned int seed = out.Locate(bari);
|
|
|
|
|
|
|
|
vector<int> &f_remap = face_remap[seed];
|
|
|
|
|
|
|
|
f_remap.push_back(newface[f]);
|
|
|
|
f_remap.push_back(newface[f+1]);
|
|
|
|
f_remap.push_back(newface[f+2]);
|
|
|
|
face_count[seed]++;
|
|
|
|
|
|
|
|
|
|
|
|
vector<int> &v_remap = vert_remap[seed];
|
|
|
|
|
|
|
|
for(int i = 0; i < 3; i++)
|
|
|
|
if(v_remap[newface[f+i]] == -1)
|
|
|
|
v_remap[newface[f+i]] = vert_count[seed]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO assure no big ones.
|
|
|
|
|
|
|
|
out.pieces.resize(nseeds);
|
|
|
|
|
|
|
|
for(unsigned int seed = 0; seed != nseeds; seed++) {
|
|
|
|
NxsPatch &patch = out.pieces[seed];
|
|
|
|
patch.patch = seeds_id[seed];
|
|
|
|
|
|
|
|
//vertices first
|
|
|
|
vector<int> &v_remap = vert_remap[seed];
|
|
|
|
|
|
|
|
assert(vert_count[seed] > 0);
|
|
|
|
vector<Point3f> &verts = patch.vert;
|
|
|
|
verts.resize(vert_count[seed]);
|
|
|
|
for(unsigned int i = 0; i < newvert.size(); i++) {
|
|
|
|
if(v_remap[i] != -1)
|
|
|
|
verts[v_remap[i]] = newvert[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
//faces now
|
|
|
|
vector<int> &f_remap = face_remap[seed];
|
|
|
|
|
|
|
|
vector<unsigned short> &faces = patch.face;
|
|
|
|
faces.resize(face_count[seed]*3);
|
|
|
|
for(unsigned int i = 0; i < f_remap.size(); i++) {
|
|
|
|
assert(v_remap[f_remap[i]] != -1);
|
|
|
|
faces[i] = v_remap[f_remap[i]];
|
|
|
|
}
|
|
|
|
|
|
|
|
//borders last
|
|
|
|
vector<Link> &bords = patch.bord;
|
|
|
|
|
2004-11-28 02:23:26 +01:00
|
|
|
//process downward borders
|
2004-10-22 12:34:13 +02:00
|
|
|
for(unsigned int i = 0; i < newbord.size(); i++) {
|
|
|
|
BigLink link = newbord[i];
|
2004-11-28 02:23:26 +01:00
|
|
|
/* cerr << "Newbord: " << link.start_vert << " "
|
|
|
|
<< link.end_patch << " "
|
|
|
|
<< link.end_vert << endl;*/
|
2004-11-18 19:30:15 +01:00
|
|
|
if(v_remap[link.start_vert] == -1) continue;
|
2004-10-22 12:34:13 +02:00
|
|
|
Link llink;
|
2004-11-18 19:30:15 +01:00
|
|
|
llink.start_vert = v_remap[link.start_vert];
|
2004-10-22 12:34:13 +02:00
|
|
|
llink.end_patch = link.end_patch;
|
|
|
|
llink.end_vert = link.end_vert;
|
|
|
|
bords.push_back(llink);
|
|
|
|
}
|
|
|
|
|
2004-11-18 19:30:15 +01:00
|
|
|
//process internal borders;
|
2004-10-22 12:34:13 +02:00
|
|
|
//TODO higly inefficient!!!
|
|
|
|
for(unsigned int rseed = 0; rseed < nseeds; rseed++) {
|
|
|
|
if(seed == rseed) continue;
|
|
|
|
|
|
|
|
vector<int> &vremapclose = vert_remap[rseed];
|
|
|
|
for(unsigned int i = 0; i < newvert.size(); i++) {
|
|
|
|
if(v_remap[i] != -1 && vremapclose[i] != -1) {
|
|
|
|
Link link;
|
|
|
|
link.end_patch = rseed + (1<<31);
|
|
|
|
link.start_vert = v_remap[i];
|
|
|
|
link.end_vert = vremapclose[i];
|
|
|
|
bords.push_back(link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-11-28 02:23:26 +01:00
|
|
|
/* cerr << "patch seed: " << patch.patch << endl;
|
|
|
|
for(unsigned int i = 0; i < bords.size(); i++) {
|
|
|
|
Link &link = bords[i];
|
|
|
|
cerr << "link: " << link.start_vert << " "
|
|
|
|
<< link.end_patch << " " << link.end_vert << endl;
|
|
|
|
}*/
|
2004-10-22 12:34:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int Fragment::Locate(const Point3f &p) {
|
|
|
|
float max_dist = 1e20;
|
|
|
|
unsigned int id = 0xffffffff;
|
|
|
|
for(unsigned int i = 0; i < seeds.size(); i++) {
|
2004-10-30 22:17:03 +02:00
|
|
|
float dist = Distance(seeds[i], p);
|
2004-10-22 12:34:13 +02:00
|
|
|
if(dist < max_dist) {
|
|
|
|
max_dist = dist;
|
|
|
|
id = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(id != 0xffffffff);
|
|
|
|
return id;
|
2004-10-19 03:19:46 +02:00
|
|
|
}
|