Trying to fix big patches.
This commit is contained in:
parent
2a8d132abd
commit
f9dd9b0416
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.7 2004/10/30 20:17:03 ponchio
|
||||||
|
Fixed big patches problem.
|
||||||
|
|
||||||
Revision 1.6 2004/10/15 11:41:03 ponchio
|
Revision 1.6 2004/10/15 11:41:03 ponchio
|
||||||
Tests and small changes.
|
Tests and small changes.
|
||||||
|
|
||||||
|
@ -52,15 +55,17 @@ Created
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <iostream>
|
|
||||||
#include "pvoronoi.h"
|
#include "pvoronoi.h"
|
||||||
#include <ANN/ANN.h>
|
#include <ANN/ANN.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace vcg;
|
using namespace vcg;
|
||||||
using namespace nxs;
|
using namespace nxs;
|
||||||
|
|
||||||
void VoronoiPartition::Init() {
|
void VoronoiPartition::Init() {
|
||||||
if(bd) delete bd;
|
if(bd) delete bd;
|
||||||
buffer.resize(size() * 3);
|
buffer.resize(size() * 3);
|
||||||
for(unsigned int i = 0; i < size(); i++) {
|
for(unsigned int i = 0; i < size(); i++) {
|
||||||
|
@ -71,29 +76,39 @@ void VoronoiPartition::Init() {
|
||||||
for(unsigned int i = 0; i < size(); i++) {
|
for(unsigned int i = 0; i < size(); i++) {
|
||||||
points[i] = &buffer[i*3];
|
points[i] = &buffer[i*3];
|
||||||
}
|
}
|
||||||
|
/*FILE *ft = fopen("points.txt", "wb+");
|
||||||
|
if(!ft) {
|
||||||
|
std::cerr <<" AHOI!" << endl;
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
for(unsigned int i = 0; i < size(); i++) {
|
||||||
|
fprintf(ft, "%f\t%f\t%f\n", operator[](i)[0], operator[](i)[1], operator[](i)[2]);
|
||||||
|
}
|
||||||
|
fclose(ft);*/
|
||||||
|
std::cerr << "Building kd!\n";
|
||||||
bd = new ANNkd_tree(&*points.begin(), size(), 3);
|
bd = new ANNkd_tree(&*points.begin(), size(), 3);
|
||||||
|
std::cerr << "Done!\n";
|
||||||
}
|
}
|
||||||
void VoronoiPartition::Closest(const vcg::Point3f &p, unsigned int nsize,
|
void VoronoiPartition::Closest(const vcg::Point3f &p, unsigned int nsize,
|
||||||
vector<int> &near,
|
vector<int> &nears,
|
||||||
vector<float> &dist) {
|
vector<float> &dist) {
|
||||||
double point[3];
|
double point[3];
|
||||||
point[0] = p[0];
|
point[0] = p[0];
|
||||||
point[1] = p[1];
|
point[1] = p[1];
|
||||||
point[2] = p[2];
|
point[2] = p[2];
|
||||||
|
|
||||||
near.resize(nsize);
|
nears.resize(nsize);
|
||||||
dist.resize(nsize);
|
dist.resize(nsize);
|
||||||
vector<double> dists;
|
vector<double> dists;
|
||||||
dists.resize(nsize);
|
dists.resize(nsize);
|
||||||
bd->annkSearch(&point[0], nsize, &*near.begin(), &*dists.begin());
|
bd->annkSearch(&point[0], nsize, &*nears.begin(), &*dists.begin());
|
||||||
for(unsigned int i = 0; i < nsize; i++)
|
for(unsigned int i = 0; i < nsize; i++)
|
||||||
dist[i] = (float)dists[i];
|
dist[i] = (float)dists[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoronoiPartition::Closest(const vcg::Point3f &p,
|
void VoronoiPartition::Closest(const vcg::Point3f &p,
|
||||||
int &target, float &dist) {
|
int &target, float &dist) {
|
||||||
double point[3];
|
double point[3];
|
||||||
point[0] = p[0];
|
point[0] = p[0];
|
||||||
point[1] = p[1];
|
point[1] = p[1];
|
||||||
point[2] = p[2];
|
point[2] = p[2];
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.9 2004/10/30 20:17:03 ponchio
|
||||||
|
Fixed big patches problem.
|
||||||
|
|
||||||
Revision 1.8 2004/10/15 11:41:03 ponchio
|
Revision 1.8 2004/10/15 11:41:03 ponchio
|
||||||
Tests and small changes.
|
Tests and small changes.
|
||||||
|
|
||||||
|
@ -71,7 +74,8 @@ Created
|
||||||
//TODO provide a Sort function, to sort spatially the seeds.
|
//TODO provide a Sort function, to sort spatially the seeds.
|
||||||
|
|
||||||
class ANNkd_tree;
|
class ANNkd_tree;
|
||||||
|
class ANNbd_tree;
|
||||||
|
class ANNbruteForce;
|
||||||
namespace nxs {
|
namespace nxs {
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,7 +85,7 @@ namespace nxs {
|
||||||
VoronoiPartition(): bd(NULL) {}
|
VoronoiPartition(): bd(NULL) {}
|
||||||
void Init();
|
void Init();
|
||||||
void Closest(const vcg::Point3f &p, unsigned int nsize,
|
void Closest(const vcg::Point3f &p, unsigned int nsize,
|
||||||
std::vector<int> &near,
|
std::vector<int> &nears,
|
||||||
std::vector<float> &dist);
|
std::vector<float> &dist);
|
||||||
void Closest(const vcg::Point3f &p,
|
void Closest(const vcg::Point3f &p,
|
||||||
int &target, float &dist);
|
int &target, float &dist);
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.18 2004/10/30 20:17:03 ponchio
|
||||||
|
Fixed big patches problem.
|
||||||
|
|
||||||
Revision 1.17 2004/10/29 16:33:29 ponchio
|
Revision 1.17 2004/10/29 16:33:29 ponchio
|
||||||
Trying to fix big patches.
|
Trying to fix big patches.
|
||||||
|
|
||||||
|
@ -92,36 +95,47 @@ void print(Point3f p) {
|
||||||
cerr << p[0] << " " << p[1] << " " << p[2] << endl;
|
cerr << p[0] << " " << p[1] << " " << p[2] << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//return first non zero distance point.
|
||||||
float getClosest(const Point3f &seed, VoronoiPartition &part) {
|
float getClosest(const Point3f &seed, VoronoiPartition &part) {
|
||||||
vector<int> near;
|
vector<int> nears;
|
||||||
vector<float> dist;
|
vector<float> dists;
|
||||||
part.Closest(seed, 2, near, dist);
|
float dist = 0;
|
||||||
for(int k = 0; k < 2; k++) {
|
int count = 1;
|
||||||
int c = near[k];
|
while(dist == 0) {
|
||||||
assert(c >= 0);
|
if(count > part.size()) {
|
||||||
assert(c < part.size());
|
cerr << "This should never happen!!!!\n";
|
||||||
if(part[c] == seed) continue;
|
exit(0);
|
||||||
return Distance(seed, part[c]);
|
}
|
||||||
|
part.Closest(seed, count, nears, dists);
|
||||||
|
for(int k = 0; k < count; k++) {
|
||||||
|
int c = nears[k];
|
||||||
|
assert(c >= 0);
|
||||||
|
assert(c < part.size());
|
||||||
|
if(dists[k] > 0 && (dist == 0 || dists[k] < dist)) {
|
||||||
|
dist = dists[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
return -1;
|
return sqrt(dist);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getBest(const Point3f &seed, VoronoiPartition &part,
|
int getBest(const Point3f &seed, VoronoiPartition &part,
|
||||||
vector<bool> &mark,
|
vector<bool> &mark,
|
||||||
vector<unsigned int> &counts) {
|
vector<unsigned int> &counts) {
|
||||||
|
|
||||||
vector<int> near;
|
vector<int> nears;
|
||||||
vector<float> dist;
|
vector<float> dist;
|
||||||
int nnear = 7;
|
int nnear = 7;
|
||||||
if(part.size() < 7) nnear = part.size()/2;
|
if(part.size() < 7) nnear = part.size()/2;
|
||||||
if(!nnear) return -1;
|
if(!nnear) return -1;
|
||||||
|
|
||||||
part.Closest(seed, nnear, near, dist);
|
part.Closest(seed, nnear, nears, dist);
|
||||||
int best = -1;
|
int best = -1;
|
||||||
int bestcount = -1;
|
int bestcount = -1;
|
||||||
int bestdist = -1;
|
int bestdist = -1;
|
||||||
for(int k = 0; k < nnear; k++) {
|
for(int k = 0; k < nnear; k++) {
|
||||||
int c = near[k];
|
int c = nears[k];
|
||||||
assert(c >= 0);
|
assert(c >= 0);
|
||||||
assert(c < part.size()); if(mark[c]) continue;
|
assert(c < part.size()); if(mark[c]) continue;
|
||||||
if(part[c] == seed) continue;
|
if(part[c] == seed) continue;
|
||||||
|
@ -154,38 +168,57 @@ bool VoronoiChain::Optimize(int mean, VoronoiPartition &part,
|
||||||
//first pass we check only big ones
|
//first pass we check only big ones
|
||||||
for(unsigned int i = 0; i < part.size(); i++) {
|
for(unsigned int i = 0; i < part.size(); i++) {
|
||||||
if(counts[i] > max_size || counts[i] > 2 * mean) {
|
if(counts[i] > max_size || counts[i] > 2 * mean) {
|
||||||
failed++;
|
failed++;
|
||||||
cerr << "Failed> " << counts[i] << endl;
|
cerr << "Failed> " << counts[i] << endl;
|
||||||
float radius= getClosest(part[i], part);
|
float radius= getClosest(part[i], part);
|
||||||
radius /= 3;
|
cerr << "RADIUS: " << radius << endl;
|
||||||
if(radius < 0) continue;
|
if(radius == 0) {
|
||||||
seeds.push_back(part[i] + Point3f(1, 0, 0) * radius);
|
cerr << "Radius zero???\n";
|
||||||
seeds.push_back(part[i] + Point3f(0, 1, 0) * radius);
|
exit(0);
|
||||||
seeds.push_back(part[i] + Point3f(0, 0, 1) * radius);
|
}
|
||||||
|
radius /= 3;
|
||||||
seeds.push_back(part[i] - Point3f(1, 0, 0) * radius);
|
if(radius < 0) continue;
|
||||||
seeds.push_back(part[i] - Point3f(0, 1, 0) * radius);
|
seeds.push_back(part[i] + Point3f(1, 0, 0) * radius);
|
||||||
seeds.push_back(part[i] - Point3f(0, 0, 1) * radius);
|
seeds.push_back(part[i] + Point3f(0, 1, 0) * radius);
|
||||||
mark[i];
|
seeds.push_back(part[i] + Point3f(0, 0, 1) * radius);
|
||||||
|
|
||||||
|
seeds.push_back(part[i] - Point3f(1, 0, 0) * radius);
|
||||||
|
seeds.push_back(part[i] - Point3f(0, 1, 0) * radius);
|
||||||
|
seeds.push_back(part[i] - Point3f(0, 0, 1) * radius);
|
||||||
|
mark[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cerr << "Join now!" << endl;
|
||||||
for(unsigned int i = 0; i < part.size(); i++) {
|
for(unsigned int i = 0; i < part.size(); i++) {
|
||||||
if(mark[i]) continue;
|
if(mark[i]) continue;
|
||||||
if(join && counts[i] < min_size) {
|
if(join && counts[i] < min_size) {
|
||||||
failed++;
|
failed++;
|
||||||
int best = getBest(part[i], part, mark, counts);
|
int best = getBest(part[i], part, mark, counts);
|
||||||
if(best < 0) continue;
|
if(best < 0) {
|
||||||
assert(mark[best] == false);
|
cerr << "Best not found! how strange!\n";
|
||||||
mark[best] = true;
|
continue;
|
||||||
mark[i] = true;
|
}
|
||||||
seeds.push_back((part[i] + part[best])/2);
|
if(best >= part.size()) {
|
||||||
|
cerr << "Invalid best!!!\n";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
assert(mark[best] == false);
|
||||||
|
mark[best] = true;
|
||||||
|
mark[i] = true;
|
||||||
|
seeds.push_back((part[i] + part[best])/2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(unsigned int i = 0; i < part.size(); i++) {
|
for(unsigned int i = 0; i < part.size(); i++) {
|
||||||
if(mark[i]) continue;
|
if(mark[i]) continue;
|
||||||
if(join) part[i] = centroids[i]/(float)counts[i];
|
if(join) {
|
||||||
|
if(counts[i] < min_size) {
|
||||||
|
cerr << "Qualche problema serio!\n";
|
||||||
|
} else {
|
||||||
|
part[i] = centroids[i]/(float)counts[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
seeds.push_back(part[i]);
|
seeds.push_back(part[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +227,9 @@ bool VoronoiChain::Optimize(int mean, VoronoiPartition &part,
|
||||||
part.push_back(seeds[i]);
|
part.push_back(seeds[i]);
|
||||||
|
|
||||||
if(part.size() == 0) part.push_back(Point3f(0,0,0));
|
if(part.size() == 0) part.push_back(Point3f(0,0,0));
|
||||||
|
cerr << "Initing!\n";
|
||||||
part.Init();
|
part.Init();
|
||||||
|
cerr << "Inited!\n";
|
||||||
return failed == 0;
|
return failed == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,6 +290,7 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
|
||||||
} else
|
} else
|
||||||
Optimize(fine_vmean, fine, centroids, counts, true);
|
Optimize(fine_vmean, fine, centroids, counts, true);
|
||||||
}
|
}
|
||||||
|
cerr << "Optimized (fine)!\n";
|
||||||
//here goes some optimization pass.
|
//here goes some optimization pass.
|
||||||
//Coarse optimization.
|
//Coarse optimization.
|
||||||
//vector<float> radius;
|
//vector<float> radius;
|
||||||
|
@ -280,10 +316,11 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
|
||||||
}
|
}
|
||||||
if(step == steps-1) {
|
if(step == steps-1) {
|
||||||
if(!Optimize(coarse_vmean, coarse, centroids, counts, false))
|
if(!Optimize(coarse_vmean, coarse, centroids, counts, false))
|
||||||
step --;
|
step --;
|
||||||
} else
|
} else
|
||||||
Optimize(coarse_vmean, coarse, centroids, counts, true);
|
Optimize(coarse_vmean, coarse, centroids, counts, true);
|
||||||
}
|
}
|
||||||
|
cerr << "Optimized coarse!\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int VoronoiChain::Locate(unsigned int level,
|
unsigned int VoronoiChain::Locate(unsigned int level,
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.20 2004/10/30 20:17:03 ponchio
|
||||||
|
Fixed big patches problem.
|
||||||
|
|
||||||
Revision 1.19 2004/10/22 10:37:32 ponchio
|
Revision 1.19 2004/10/22 10:37:32 ponchio
|
||||||
Split is now in fragment.
|
Split is now in fragment.
|
||||||
|
|
||||||
|
@ -91,6 +94,7 @@ First draft.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#include "crude.h"
|
#include "crude.h"
|
||||||
|
@ -485,7 +489,7 @@ void SaveFragment(Nexus &nexus, VoronoiChain &chain,
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReverseHistory(vector<Nexus::Update> &history) {
|
void ReverseHistory(vector<Nexus::Update> &history) {
|
||||||
reverse(history.begin(), history.end());
|
std::reverse(history.begin(), history.end());
|
||||||
vector<Nexus::Update>::iterator i;
|
vector<Nexus::Update>::iterator i;
|
||||||
for(i = history.begin(); i != history.end(); i++)
|
for(i = history.begin(); i != history.end(); i++)
|
||||||
swap((*i).erased, (*i).created);
|
swap((*i).erased, (*i).created);
|
||||||
|
|
Loading…
Reference in New Issue