Voronoi partition changes.
This commit is contained in:
parent
16d1909ad0
commit
57ee6ea2ef
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.4 2004/09/21 00:53:23 ponchio
|
||||||
|
Lotsa changes.
|
||||||
|
|
||||||
Revision 1.3 2004/09/17 15:25:09 ponchio
|
Revision 1.3 2004/09/17 15:25:09 ponchio
|
||||||
First working (hopefully) release.
|
First working (hopefully) release.
|
||||||
|
|
||||||
|
@ -46,10 +49,6 @@ using namespace nxs;
|
||||||
|
|
||||||
|
|
||||||
void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
|
void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
|
||||||
box = crude.GetBox();
|
|
||||||
box.Offset(box.max - box.min);
|
|
||||||
//how many cells do i need?
|
|
||||||
cerr << "scaling: " << scaling << endl;
|
|
||||||
unsigned int f_cells = crude.Faces() / mean_size;
|
unsigned int f_cells = crude.Faces() / mean_size;
|
||||||
unsigned int c_cells = (unsigned int)(scaling * f_cells);
|
unsigned int c_cells = (unsigned int)(scaling * f_cells);
|
||||||
|
|
||||||
|
@ -61,15 +60,11 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
|
||||||
levels.push_back(VoronoiPartition());
|
levels.push_back(VoronoiPartition());
|
||||||
VoronoiPartition &fine = levels[0];
|
VoronoiPartition &fine = levels[0];
|
||||||
VoronoiPartition &coarse = levels[1];
|
VoronoiPartition &coarse = levels[1];
|
||||||
|
fine.SetBox(crude.GetBox());
|
||||||
fine.Init(box);
|
coarse.SetBox(crude.GetBox());
|
||||||
coarse.Init(box);
|
|
||||||
|
|
||||||
srand(0);
|
srand(0);
|
||||||
|
|
||||||
vector<Seed> fine_seeds;
|
|
||||||
vector<Seed> coarse_seeds;
|
|
||||||
|
|
||||||
float fine_vmean = mean_size/2;
|
float fine_vmean = mean_size/2;
|
||||||
float coarse_vmean = (mean_size/scaling)/2;
|
float coarse_vmean = (mean_size/scaling)/2;
|
||||||
for(unsigned int i = 0; i < crude.Vertices(); i++) {
|
for(unsigned int i = 0; i < crude.Vertices(); i++) {
|
||||||
|
@ -77,22 +72,27 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
|
||||||
int c = (int)(coarse_vmean *rand()/(RAND_MAX + 1.0));
|
int c = (int)(coarse_vmean *rand()/(RAND_MAX + 1.0));
|
||||||
if(f == 1) {
|
if(f == 1) {
|
||||||
Point3f &point = crude.GetVertex(i);
|
Point3f &point = crude.GetVertex(i);
|
||||||
fine_seeds.push_back(Seed(point, 1));
|
fine.push_back(Seed(point, 1));
|
||||||
}
|
}
|
||||||
if(c == 1) {
|
if(c == 1) {
|
||||||
Point3f &point = crude.GetVertex(i);
|
Point3f &point = crude.GetVertex(i);
|
||||||
coarse_seeds.push_back(Seed(point, 1));
|
coarse.push_back(Seed(point, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cerr << "fine_seeds.size: " << fine_seeds.size() << endl;
|
//TODO! Check for duplicates (use the closest :P)
|
||||||
cerr << "coarse_seeds.size: " << coarse_seeds.size() << endl;
|
cerr << "fine_seeds.size: " << fine.size() << endl;
|
||||||
fine.all_seeds = fine_seeds;
|
cerr << "coarse_seeds.size: " << coarse.size() << endl;
|
||||||
coarse.all_seeds = coarse_seeds;
|
fine.Init();
|
||||||
fine.reload();
|
coarse.Init();
|
||||||
coarse.reload();
|
|
||||||
|
|
||||||
//here goes some optimization pass.
|
for(int i = 0; i < fine.size(); i ++) {
|
||||||
//Fine optimization.
|
unsigned int target = 0xffffffff;
|
||||||
|
fine.Closest(fine[i].p, target);
|
||||||
|
assert(target == i);
|
||||||
|
|
||||||
|
}
|
||||||
|
//here goes some optimization pass.
|
||||||
|
//Fine optimization.
|
||||||
vector<Point3f> fcentroids;
|
vector<Point3f> fcentroids;
|
||||||
vector<unsigned int> fcount;
|
vector<unsigned int> fcount;
|
||||||
for(unsigned int i = 0; i < steps; i++) {
|
for(unsigned int i = 0; i < steps; i++) {
|
||||||
|
@ -110,19 +110,62 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
|
||||||
fcount[ftarget]++;
|
fcount[ftarget]++;
|
||||||
}
|
}
|
||||||
for(unsigned int v = 0; v < fine.size(); v++) {
|
for(unsigned int v = 0; v < fine.size(); v++) {
|
||||||
|
if(fcount[v] == 0) {
|
||||||
|
unsigned int target;
|
||||||
|
float dist = fine.Closest(fine[v].p, target);
|
||||||
|
}
|
||||||
assert(fcount[v] != 0);
|
assert(fcount[v] != 0);
|
||||||
|
|
||||||
|
|
||||||
fine[v].p = fcentroids[v]/fcount[v];
|
fine[v].p = fcentroids[v]/fcount[v];
|
||||||
//0.3 is related to the fact is doubled the box size.
|
//0.3 is related to the fact is doubled the box size.
|
||||||
fine[v].weight = pow(fcount[v]/fine_vmean, 0.3f);
|
fine[v].weight = pow(fcount[v]/(float)fine_vmean, 0.3f);
|
||||||
// fine.bbox.Add(fine[v].p);
|
// fine.bbox.Add(fine[v].p);
|
||||||
}
|
}
|
||||||
// fine.Init(fine.bbox);
|
// fine.Init(fine.bbox);
|
||||||
fine.reload();
|
fine.Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
//here goes some optimization pass.
|
||||||
|
//Coarse optimization.
|
||||||
|
vector<Point3f> ccentroids;
|
||||||
|
vector<unsigned int> ccount;
|
||||||
|
for(unsigned int i = 0; i < steps; i++) {
|
||||||
|
cerr << "Optimization step 0: " << i << "/" << steps << endl;
|
||||||
|
ccentroids.clear();
|
||||||
|
ccount.clear();
|
||||||
|
ccentroids.resize(fine.size(), Point3f(0, 0, 0));
|
||||||
|
ccount.resize(fine.size(), 0);
|
||||||
|
|
||||||
|
for(unsigned int v = 0; v < crude.Vertices(); v++) {
|
||||||
|
unsigned int ctarget = 0xffffffff;
|
||||||
|
float dist = coarse.Closest(crude.vert[v], ctarget);
|
||||||
|
assert(ctarget != 0xffffffff);
|
||||||
|
ccentroids[ctarget] += crude.vert[v];
|
||||||
|
ccount[ctarget]++;
|
||||||
|
}
|
||||||
|
for(unsigned int v = 0; v < coarse.size(); v++) {
|
||||||
|
if(ccount[v] == 0) {
|
||||||
|
unsigned int target;
|
||||||
|
float dist = coarse.Closest(fine[v].p, target);
|
||||||
|
assert(target == v);
|
||||||
|
}
|
||||||
|
assert(ccount[v] != 0);
|
||||||
|
|
||||||
|
|
||||||
|
coarse[v].p = ccentroids[v]/ccount[v];
|
||||||
|
//0.3 is related to the fact is doubled the box size.
|
||||||
|
coarse[v].weight = pow(ccount[v]/(float)coarse_vmean, 0.3f);
|
||||||
|
// fine.bbox.Add(fine[v].p);
|
||||||
|
}
|
||||||
|
// fine.Init(fine.bbox);
|
||||||
|
coarse.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Coarse optimization
|
//Coarse optimization
|
||||||
vector< map<unsigned int, Point3f> > ccentroids;
|
/* vector< map<unsigned int, Point3f> > ccentroids;
|
||||||
vector< map<unsigned int, unsigned int> > ccount;
|
vector< map<unsigned int, unsigned int> > ccount;
|
||||||
|
|
||||||
for(unsigned int i = 0; i < steps; i++) {
|
for(unsigned int i = 0; i < steps; i++) {
|
||||||
|
@ -180,8 +223,8 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
|
||||||
// coarse[v].weight = pow(tot_size/coarse_vmean, 0.25f);
|
// coarse[v].weight = pow(tot_size/coarse_vmean, 0.25f);
|
||||||
|
|
||||||
}
|
}
|
||||||
coarse.reload();
|
coarse.Init();
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int VoronoiChain::Locate(unsigned int level,
|
unsigned int VoronoiChain::Locate(unsigned int level,
|
||||||
|
@ -286,35 +329,71 @@ void VoronoiChain::BuildLevel(Nexus &nexus, unsigned int offset,
|
||||||
levels.push_back(VoronoiPartition());
|
levels.push_back(VoronoiPartition());
|
||||||
VoronoiPartition &coarse = levels[levels.size()-1];
|
VoronoiPartition &coarse = levels[levels.size()-1];
|
||||||
VoronoiPartition &fine = levels[levels.size()-2];
|
VoronoiPartition &fine = levels[levels.size()-2];
|
||||||
|
coarse.SetBox(fine.box);
|
||||||
coarse.Init(box);
|
|
||||||
|
|
||||||
fine.reload();
|
|
||||||
|
|
||||||
srand(0);
|
srand(0);
|
||||||
float coarse_vmean = (totface/2)/(fine.size() * scaling);
|
float coarse_vmean = (totface/2)/(fine.size() * scaling);
|
||||||
|
|
||||||
cerr << "initing random seeds\n";
|
cerr << "initing random seeds\n";
|
||||||
|
|
||||||
vector<Seed> coarse_seeds;
|
|
||||||
|
|
||||||
for(unsigned int idx = offset; idx < nexus.index.size(); idx++) {
|
for(unsigned int idx = offset; idx < nexus.index.size(); idx++) {
|
||||||
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++) {
|
||||||
int c = (int)(coarse_vmean*rand()/(RAND_MAX + 1.0));
|
int c = (int)(coarse_vmean*rand()/(RAND_MAX + 1.0));
|
||||||
if(c == 1) {
|
if(c == 1) {
|
||||||
Point3f &v = patch.Vert(i);
|
Point3f &v = patch.Vert(i);
|
||||||
coarse_seeds.push_back(v);
|
coarse.push_back(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(coarse_seeds.size() == 0)
|
if(coarse.size() == 0) {
|
||||||
coarse_seeds.push_back(Point3f(0, 0, 0));
|
Patch patch = nexus.GetPatch(0);
|
||||||
coarse.all_seeds = coarse_seeds;
|
coarse.push_back(patch.Vert(0));
|
||||||
coarse.reload();
|
}
|
||||||
|
coarse.Init();
|
||||||
|
cerr << "Coarse size: " << coarse.size() << endl;
|
||||||
|
//here goes some optimization pass.
|
||||||
|
//Coarse optimization.
|
||||||
|
vector<Point3f> ccentroids;
|
||||||
|
vector<unsigned int> ccount;
|
||||||
|
for(unsigned int i = 0; i < steps; i++) {
|
||||||
|
cerr << "Optimization step 0: " << i << "/" << steps << endl;
|
||||||
|
ccentroids.clear();
|
||||||
|
ccount.clear();
|
||||||
|
ccentroids.resize(fine.size(), Point3f(0, 0, 0));
|
||||||
|
ccount.resize(fine.size(), 0);
|
||||||
|
|
||||||
|
for(unsigned int idx = offset; idx < nexus.index.size(); idx++) {
|
||||||
|
Patch patch = nexus.GetPatch(idx);
|
||||||
|
for(unsigned int i = 0; i < patch.nv; i++) {
|
||||||
|
|
||||||
|
unsigned int ctarget = 0xffffffff;
|
||||||
|
float dist = coarse.Closest(patch.Vert(i), ctarget);
|
||||||
|
assert(ctarget != 0xffffffff);
|
||||||
|
ccentroids[ctarget] += patch.Vert(i);
|
||||||
|
ccount[ctarget]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(unsigned int v = 0; v < coarse.size(); v++) {
|
||||||
|
if(ccount[v] == 0) {
|
||||||
|
unsigned int target = 0xffffffff;
|
||||||
|
float dist = coarse.Closest(fine[v].p, target);
|
||||||
|
assert(target == v);
|
||||||
|
}
|
||||||
|
assert(ccount[v] != 0);
|
||||||
|
|
||||||
|
coarse[v].p = ccentroids[v]/ccount[v];
|
||||||
|
//0.3 is related to the fact is doubled the box size.
|
||||||
|
coarse[v].weight = pow(ccount[v]/(float)coarse_vmean, 0.3f);
|
||||||
|
// fine.bbox.Add(fine[v].p);
|
||||||
|
}
|
||||||
|
// fine.Init(fine.bbox);
|
||||||
|
coarse.Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Coarse optimization
|
//Coarse optimization
|
||||||
vector< map<unsigned int, Point3f> > ccentroids;
|
/* vector< map<unsigned int, Point3f> > ccentroids;
|
||||||
vector< map<unsigned int, unsigned int> > ccount;
|
vector< map<unsigned int, unsigned int> > ccount;
|
||||||
|
|
||||||
for(unsigned int step = 0; step < steps; step++) {
|
for(unsigned int step = 0; step < steps; step++) {
|
||||||
|
@ -331,7 +410,7 @@ void VoronoiChain::BuildLevel(Nexus &nexus, unsigned int offset,
|
||||||
for(unsigned int i = 0; i < patch.nv; i++) {
|
for(unsigned int i = 0; i < patch.nv; i++) {
|
||||||
Point3f &v = patch.Vert(i);
|
Point3f &v = patch.Vert(i);
|
||||||
unsigned int ftarget;
|
unsigned int ftarget;
|
||||||
float dist = fine.Closest(Point3f(1,1,1), ftarget);
|
float dist = fine.Closest(v, ftarget);
|
||||||
|
|
||||||
dist = fine.Closest(v, ftarget);
|
dist = fine.Closest(v, ftarget);
|
||||||
assert(ftarget != -1);
|
assert(ftarget != -1);
|
||||||
|
@ -343,7 +422,7 @@ void VoronoiChain::BuildLevel(Nexus &nexus, unsigned int offset,
|
||||||
map<unsigned int, Point3f> ¢roids = ccentroids[ctarget];
|
map<unsigned int, Point3f> ¢roids = ccentroids[ctarget];
|
||||||
map<unsigned int, unsigned int> &count = ccount[ctarget];
|
map<unsigned int, unsigned int> &count = ccount[ctarget];
|
||||||
|
|
||||||
if(!centroids.count(ftarget))
|
if(!centroids.count(ftarget))
|
||||||
centroids[ftarget]= Point3f(0, 0, 0);
|
centroids[ftarget]= Point3f(0, 0, 0);
|
||||||
|
|
||||||
if(!count.count(ftarget))
|
if(!count.count(ftarget))
|
||||||
|
@ -375,8 +454,8 @@ void VoronoiChain::BuildLevel(Nexus &nexus, unsigned int offset,
|
||||||
//TODO find a solution!
|
//TODO find a solution!
|
||||||
// coarse[v].weight = pow(tot_size/coarse_vmean, 0.25f);
|
// coarse[v].weight = pow(tot_size/coarse_vmean, 0.25f);
|
||||||
}
|
}
|
||||||
coarse.reload();
|
coarse.Init();
|
||||||
}
|
}*/
|
||||||
newfragments.clear();
|
newfragments.clear();
|
||||||
//TODO add some optimization
|
//TODO add some optimization
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue