Some controls added.
This commit is contained in:
parent
29b2d65bb3
commit
6bea51d502
|
@ -19,8 +19,8 @@ void nxs::RemapVertices(Crude &crude,
|
||||||
set<unsigned int> pp;
|
set<unsigned int> pp;
|
||||||
vert_remap.GetValues(face[k], pp);
|
vert_remap.GetValues(face[k], pp);
|
||||||
if(!pp.count(patch)) {
|
if(!pp.count(patch)) {
|
||||||
vert_remap.Insert(face[k], patch);
|
vert_remap.Insert(face[k], patch);
|
||||||
patch_verts[patch]++;
|
patch_verts[patch]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ void nxs::NexusAllocate(Crude &crude,
|
||||||
|
|
||||||
// unsigned int totchunks = 0;
|
// unsigned int totchunks = 0;
|
||||||
//now that we know various sizes, lets allocate space
|
//now that we know various sizes, lets allocate space
|
||||||
|
cerr << "Fixing entries\n";
|
||||||
for(unsigned int i = 0; i < nexus.index.size(); i++) {
|
for(unsigned int i = 0; i < nexus.index.size(); i++) {
|
||||||
Nexus::PatchInfo &entry = nexus.index[i];
|
Nexus::PatchInfo &entry = nexus.index[i];
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ void nxs::NexusAllocate(Crude &crude,
|
||||||
|
|
||||||
entry.nvert = patch_verts[i];
|
entry.nvert = patch_verts[i];
|
||||||
entry.nface = patch_faces[i];
|
entry.nface = patch_faces[i];
|
||||||
entry.error = 0;
|
entry.error = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
patch_faces.clear();
|
patch_faces.clear();
|
||||||
|
@ -55,12 +56,18 @@ void nxs::NexusAllocate(Crude &crude,
|
||||||
|
|
||||||
//now we sort the faces into the patches (but still using absolute indexing
|
//now we sort the faces into the patches (but still using absolute indexing
|
||||||
//instead of relative indexing
|
//instead of relative indexing
|
||||||
|
cerr << "Moving faces into patches\n";
|
||||||
|
|
||||||
for(unsigned int i = 0; i < crude.face.Size(); i++) {
|
for(unsigned int i = 0; i < crude.face.Size(); i++) {
|
||||||
Crude::Face &face = crude.face[i];
|
Crude::Face &face = crude.face[i];
|
||||||
unsigned int npatch = face_remap[i];
|
unsigned int npatch = face_remap[i];
|
||||||
|
#ifdef CONTROLS
|
||||||
Nexus::PatchInfo &entry = nexus.index[npatch];
|
if(npatch > nexus.index.size()) {
|
||||||
// cerr << "Entrynf: " << entry.nface << endl;
|
cerr << "INvalid index\n";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
Nexus::PatchInfo &entry = nexus.index[npatch];
|
||||||
//TODO this is slow because we have to initialize patch.
|
//TODO this is slow because we have to initialize patch.
|
||||||
//just get patch.start.
|
//just get patch.start.
|
||||||
Patch patch = nexus.GetPatch(npatch);
|
Patch patch = nexus.GetPatch(npatch);
|
||||||
|
@ -72,8 +79,17 @@ void nxs::NexusAllocate(Crude &crude,
|
||||||
cerr << "Found degenerate.\n";
|
cerr << "Found degenerate.\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
#ifdef CONTROLS
|
||||||
|
if(patch_faces[npatch] > entry.nface) {
|
||||||
|
cerr << "patch_faces[npatch]: " << patch_faces[npatch]
|
||||||
|
<< " should be <= " << entry.nface << endl;
|
||||||
|
cerr << "something not workin here!\n";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
faces[patch_faces[npatch]++] = face;
|
faces[patch_faces[npatch]++] = face;
|
||||||
}
|
}
|
||||||
|
cerr << "Fixing entry faces\n";
|
||||||
for(unsigned int i = 0; i < nexus.index.size(); i++) {
|
for(unsigned int i = 0; i < nexus.index.size(); i++) {
|
||||||
Nexus::PatchInfo &entry = nexus.index[i];
|
Nexus::PatchInfo &entry = nexus.index[i];
|
||||||
entry.nface = patch_faces[i];
|
entry.nface = patch_faces[i];
|
||||||
|
|
|
@ -99,6 +99,12 @@ Patch &PatchServer::GetPatch(unsigned int idx,
|
||||||
PTime nptime(idx);
|
PTime nptime(idx);
|
||||||
|
|
||||||
char *ram = new char[entry.ram_size * chunk_size];
|
char *ram = new char[entry.ram_size * chunk_size];
|
||||||
|
#ifdef CONTROLS
|
||||||
|
if(!ram) {
|
||||||
|
cerr << "COuld not allocate ram!\n";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
nptime.patch = new Patch(signature, ram, nvert, nface);
|
nptime.patch = new Patch(signature, ram, nvert, nface);
|
||||||
|
|
||||||
if(entry.patch_start != 0xffffffff) { //was allocated.
|
if(entry.patch_start != 0xffffffff) { //was allocated.
|
||||||
|
@ -107,15 +113,15 @@ Patch &PatchServer::GetPatch(unsigned int idx,
|
||||||
SetPosition(entry.patch_start * chunk_size);
|
SetPosition(entry.patch_start * chunk_size);
|
||||||
|
|
||||||
if((signature & NXS_COMPRESSED) == 0) { //not compressed
|
if((signature & NXS_COMPRESSED) == 0) { //not compressed
|
||||||
ReadBuffer(ram, entry.disk_size * chunk_size);
|
ReadBuffer(ram, entry.disk_size * chunk_size);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
unsigned char *disk = new unsigned char[entry.disk_size * chunk_size];
|
unsigned char *disk = new unsigned char[entry.disk_size * chunk_size];
|
||||||
ReadBuffer(disk, entry.disk_size * chunk_size);
|
ReadBuffer(disk, entry.disk_size * chunk_size);
|
||||||
|
|
||||||
nptime.patch->Decompress(entry.ram_size * chunk_size,
|
nptime.patch->Decompress(entry.ram_size * chunk_size,
|
||||||
disk, entry.disk_size * chunk_size);
|
disk, entry.disk_size * chunk_size);
|
||||||
delete []disk;
|
delete []disk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.15 2004/10/21 12:22:21 ponchio
|
||||||
|
Small changes.
|
||||||
|
|
||||||
Revision 1.14 2004/10/19 04:23:29 ponchio
|
Revision 1.14 2004/10/19 04:23:29 ponchio
|
||||||
*** empty log message ***
|
*** empty log message ***
|
||||||
|
|
||||||
|
@ -276,16 +279,13 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
|
||||||
unsigned int VoronoiChain::Locate(unsigned int level,
|
unsigned int VoronoiChain::Locate(unsigned int level,
|
||||||
const vcg::Point3f &p) {
|
const vcg::Point3f &p) {
|
||||||
return levels[level].Locate(p);
|
return levels[level].Locate(p);
|
||||||
/* assert(levels.size() > level+1);
|
|
||||||
unsigned int fine = levels[level].Locate(p);
|
|
||||||
unsigned int coarse = levels[level+1].Locate(p);
|
|
||||||
return fine + coarse * levels[level].size();*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO move this to nxsbuild
|
//TODO move this to nxsbuild
|
||||||
void VoronoiChain::RemapFaces(Crude &crude, VFile<unsigned int> &face_remap,
|
void VoronoiChain::RemapFaces(Crude &crude,
|
||||||
vector<unsigned int> &patch_faces,
|
VFile<unsigned int> &face_remap,
|
||||||
float scaling, int steps) {
|
vector<unsigned int> &patch_faces,
|
||||||
|
float scaling, int steps) {
|
||||||
|
|
||||||
Init(crude, scaling, steps);
|
Init(crude, scaling, steps);
|
||||||
|
|
||||||
|
@ -300,7 +300,7 @@ void VoronoiChain::RemapFaces(Crude &crude, VFile<unsigned int> &face_r
|
||||||
Point3f bari;
|
Point3f bari;
|
||||||
for(unsigned int i = 0; i < crude.Faces(); i++) {
|
for(unsigned int i = 0; i < crude.Faces(); i++) {
|
||||||
bari = crude.GetBari(i);
|
bari = crude.GetBari(i);
|
||||||
// unsigned int patch = Locate(0, bari);
|
|
||||||
unsigned int fine = Locate(0, bari);
|
unsigned int fine = Locate(0, bari);
|
||||||
unsigned int coarse = Locate(1, bari);
|
unsigned int coarse = Locate(1, bari);
|
||||||
|
|
||||||
|
@ -315,14 +315,13 @@ void VoronoiChain::RemapFaces(Crude &crude, VFile<unsigned int> &face_r
|
||||||
face_remap[i] = patch;
|
face_remap[i] = patch;
|
||||||
//face_remap[i] = fine;
|
//face_remap[i] = fine;
|
||||||
|
|
||||||
if(patch_faces.size() <= patch)
|
while(patch_faces.size() <= patch)
|
||||||
patch_faces.resize(patch+1, 0);
|
patch_faces.push_back(0);
|
||||||
patch_faces[patch]++;
|
patch_faces[patch]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//prune faces (now only 0 faces);
|
//prune faces (now only 0 faces);
|
||||||
|
//TODO prune really small faces
|
||||||
unsigned int tot_patches = 0;
|
unsigned int tot_patches = 0;
|
||||||
vector<int> patch_remap;
|
vector<int> patch_remap;
|
||||||
for(unsigned int i = 0; i < patch_faces.size(); i++) {
|
for(unsigned int i = 0; i < patch_faces.size(); i++) {
|
||||||
|
@ -331,6 +330,12 @@ void VoronoiChain::RemapFaces(Crude &crude, VFile<unsigned int> &face_r
|
||||||
patch_remap.push_back(-1);
|
patch_remap.push_back(-1);
|
||||||
else
|
else
|
||||||
patch_remap.push_back(tot_patches++);
|
patch_remap.push_back(tot_patches++);
|
||||||
|
|
||||||
|
if(patch_faces[i] > 32000) {
|
||||||
|
//TODO do something to reduce patch size... :P
|
||||||
|
cerr << "Found a patch too big... sorry\n";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -344,23 +349,26 @@ void VoronoiChain::RemapFaces(Crude &crude, VFile<unsigned int> &face_r
|
||||||
}
|
}
|
||||||
|
|
||||||
//remapping faces
|
//remapping faces
|
||||||
|
patch_faces.clear();
|
||||||
|
patch_faces.resize(totpatches, 0);
|
||||||
for(unsigned int i = 0; i < face_remap.Size(); i++) {
|
for(unsigned int i = 0; i < face_remap.Size(); i++) {
|
||||||
unsigned int patch = face_remap[i];
|
unsigned int patch = face_remap[i];
|
||||||
assert(patch != 0xffffffff);
|
#ifdef CONTROLS
|
||||||
assert(patch_remap[patch] != -1);
|
if(patch == 0xffffffff) {
|
||||||
face_remap[i] = patch_remap[patch];
|
cerr << "RESIGH\n";
|
||||||
}
|
exit(0);
|
||||||
|
|
||||||
//remapping patch_faces
|
|
||||||
for(unsigned int i = 0; i < patch_faces.size(); i++) {
|
|
||||||
assert(patch_remap[i] <= (int)i);
|
|
||||||
if(patch_remap[i] != -1) {
|
|
||||||
assert(patch_faces[i] > 0);
|
|
||||||
patch_faces[patch_remap[i]] = patch_faces[i];
|
|
||||||
}
|
}
|
||||||
|
if(patch_remap[patch] == -1) {
|
||||||
|
cerr << "SIGH!\n";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
unsigned int newpatch = patch_remap[patch];
|
||||||
|
face_remap[i] = newpatch;
|
||||||
|
patch_faces[newpatch]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
patch_faces.resize(tot_patches);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoronoiChain::BuildLevel(Nexus &nexus, unsigned int offset,
|
void VoronoiChain::BuildLevel(Nexus &nexus, unsigned int offset,
|
||||||
|
@ -425,12 +433,12 @@ void VoronoiChain::BuildLevel(Nexus &nexus, unsigned int offset,
|
||||||
Patch patch = nexus.GetPatch(idx);
|
Patch patch = nexus.GetPatch(idx);
|
||||||
for(unsigned int i = 0; i < patch.nv; i++) {
|
for(unsigned int i = 0; i < patch.nv; i++) {
|
||||||
|
|
||||||
unsigned int ctarget = 0xffffffff;
|
unsigned int ctarget = 0xffffffff;
|
||||||
float dist = coarse.Closest(patch.Vert(i), ctarget);
|
float dist = coarse.Closest(patch.Vert(i), ctarget);
|
||||||
assert(ctarget != 0xffffffff);
|
assert(ctarget != 0xffffffff);
|
||||||
ccentroids[ctarget] += patch.Vert(i);
|
ccentroids[ctarget] += patch.Vert(i);
|
||||||
ccount[ctarget]++;
|
ccount[ctarget]++;
|
||||||
if(dist > radius[ctarget]) radius[ctarget] = dist;
|
if(dist > radius[ctarget]) radius[ctarget] = dist;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(unsigned int v = 0; v < coarse.size(); v++) {
|
for(unsigned int v = 0; v < coarse.size(); v++) {
|
||||||
|
@ -457,71 +465,6 @@ void VoronoiChain::BuildLevel(Nexus &nexus, unsigned int offset,
|
||||||
|
|
||||||
if(coarse.size() == 0) coarse.push_back(Point3f(0,0,0));
|
if(coarse.size() == 0) coarse.push_back(Point3f(0,0,0));
|
||||||
coarse.Init();
|
coarse.Init();
|
||||||
|
|
||||||
//Coarse optimization
|
|
||||||
/* vector< map<unsigned int, Point3f> > ccentroids;
|
|
||||||
vector< map<unsigned int, unsigned int> > ccount;
|
|
||||||
|
|
||||||
for(unsigned int step = 0; step < steps; step++) {
|
|
||||||
cerr << "Optimization step " << levels.size()-1 << ":"
|
|
||||||
<< step << "/" << steps << endl;
|
|
||||||
ccentroids.clear();
|
|
||||||
ccount.clear();
|
|
||||||
ccentroids.resize(coarse.size());
|
|
||||||
ccount.resize(coarse.size());
|
|
||||||
|
|
||||||
for(unsigned int idx = offset; idx < nexus.index.size(); idx++) {
|
|
||||||
Patch patch = nexus.GetPatch(idx);
|
|
||||||
|
|
||||||
for(unsigned int i = 0; i < patch.nv; i++) {
|
|
||||||
Point3f &v = patch.Vert(i);
|
|
||||||
unsigned int ftarget;
|
|
||||||
float dist = fine.Closest(v, ftarget);
|
|
||||||
|
|
||||||
dist = fine.Closest(v, ftarget);
|
|
||||||
assert(ftarget != -1);
|
|
||||||
|
|
||||||
unsigned int ctarget;
|
|
||||||
dist = coarse.Closest(v, ctarget);
|
|
||||||
assert(ctarget != -1);
|
|
||||||
|
|
||||||
map<unsigned int, Point3f> ¢roids = ccentroids[ctarget];
|
|
||||||
map<unsigned int, unsigned int> &count = ccount[ctarget];
|
|
||||||
|
|
||||||
if(!centroids.count(ftarget))
|
|
||||||
centroids[ftarget]= Point3f(0, 0, 0);
|
|
||||||
|
|
||||||
if(!count.count(ftarget))
|
|
||||||
count[ftarget] = 0;
|
|
||||||
|
|
||||||
centroids[ftarget] += v;
|
|
||||||
count[ftarget]++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cerr << "recentring" << endl;
|
|
||||||
for(unsigned int v = 0; v < coarse.size(); v++) {
|
|
||||||
|
|
||||||
map<unsigned int, Point3f> ¢roids = ccentroids[v];
|
|
||||||
map<unsigned int, unsigned int> &count = ccount[v];
|
|
||||||
|
|
||||||
coarse[v].p = Point3f(0, 0, 0);
|
|
||||||
float weight = 0;
|
|
||||||
unsigned int tot_size =0;
|
|
||||||
map<unsigned int, Point3f>::iterator k;
|
|
||||||
for(k = centroids.begin();k != centroids.end(); k++) {
|
|
||||||
unsigned int size = count[(*k).first];
|
|
||||||
tot_size += size;
|
|
||||||
coarse[v].p += (*k).second / size;
|
|
||||||
weight += 1;
|
|
||||||
}
|
|
||||||
assert(weight > 0);
|
|
||||||
coarse[v].p /= weight;
|
|
||||||
//TODO find a solution!
|
|
||||||
// coarse[v].weight = pow(tot_size/coarse_vmean, 0.25f);
|
|
||||||
}
|
|
||||||
coarse.Init();
|
|
||||||
}*/
|
|
||||||
newfragments.clear();
|
newfragments.clear();
|
||||||
//TODO add some optimization
|
//TODO add some optimization
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue