Fixed a couple of memory leak...
This commit is contained in:
parent
0d7e92e11f
commit
783d125b71
|
@ -174,7 +174,8 @@ float Cluster(MyMesh &mesh, unsigned int target_faces) {
|
||||||
unsigned int nseeds = target_faces/2;
|
unsigned int nseeds = target_faces/2;
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if(nseeds >= mesh.vert.size()) {
|
if(nseeds >= mesh.vert.size()) {
|
||||||
cerr << "Strange! nseeds > vert.size(): " << nseeds << " >= "<< mesh.vert.size() << endl;
|
cerr << "Strange! nseeds > vert.size(): " << nseeds
|
||||||
|
<< " >= "<< mesh.vert.size() << endl;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.7 2004/12/03 01:20:56 ponchio
|
||||||
|
Debug
|
||||||
|
|
||||||
Revision 1.6 2004/12/02 20:22:42 ponchio
|
Revision 1.6 2004/12/02 20:22:42 ponchio
|
||||||
Level 5;
|
Level 5;
|
||||||
|
|
||||||
|
@ -396,10 +399,6 @@ void FourthStep(const string &crudefile, const string &output,
|
||||||
}
|
}
|
||||||
Report report(nexus.index.size());
|
Report report(nexus.index.size());
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
map<unsigned int, set<unsigned int> > reciprocal;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for(int start = 0; start < nexus.index.size(); start++) {
|
for(int start = 0; start < nexus.index.size(); start++) {
|
||||||
report.Step(start);
|
report.Step(start);
|
||||||
Nexus::PatchInfo &s_entry = nexus.index[start];
|
Nexus::PatchInfo &s_entry = nexus.index[start];
|
||||||
|
@ -418,19 +417,9 @@ void FourthStep(const string &crudefile, const string &output,
|
||||||
Nexus::PatchInfo &e_entry = nexus.index[end];
|
Nexus::PatchInfo &e_entry = nexus.index[end];
|
||||||
float dist = Distance(s_entry.sphere, e_entry.sphere);
|
float dist = Distance(s_entry.sphere, e_entry.sphere);
|
||||||
|
|
||||||
if(dist > (s_entry.sphere.Radius() + e_entry.sphere.Radius()) * 0.01) {
|
if(dist > s_entry.sphere.Radius() + e_entry.sphere.Radius()) {
|
||||||
#ifndef NDEBUG
|
|
||||||
if(start > end)
|
|
||||||
assert(!reciprocal[end].count(start));
|
|
||||||
#endif
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#ifndef NDEBUG
|
|
||||||
if(start > end)
|
|
||||||
assert(reciprocal[end].count(start));
|
|
||||||
else
|
|
||||||
reciprocal[start].insert(end);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for(unsigned int i = 0; i < vert_index[end].size; i++) {
|
for(unsigned int i = 0; i < vert_index[end].size; i++) {
|
||||||
unsigned int global = vert_remap[vert_index[end].offset + i];
|
unsigned int global = vert_remap[vert_index[end].offset + i];
|
||||||
|
@ -510,7 +499,7 @@ void FifthStep(const string &crudefile, const string &output,
|
||||||
report.Step(fcount++);
|
report.Step(fcount++);
|
||||||
|
|
||||||
Fragment *fragin = new Fragment;
|
Fragment *fragin = new Fragment;
|
||||||
BuildFragment(nexus, vchain[level+1],
|
BuildFragment(nexus, *vchain[level+1],
|
||||||
(*fragment).second, *fragin);
|
(*fragment).second, *fragin);
|
||||||
|
|
||||||
dispatcher.SendFragment(fragin);
|
dispatcher.SendFragment(fragin);
|
||||||
|
|
|
@ -15,18 +15,18 @@ void SaveFragment(Nexus &nexus, VChain &chain,
|
||||||
|
|
||||||
|
|
||||||
void Opener::execute() {
|
void Opener::execute() {
|
||||||
cerr << "Trying to connect to: " << server->get_host() << endl;
|
// cerr << "Trying to connect to: " << server->get_host() << endl;
|
||||||
server->reading.lock();
|
server->reading.lock();
|
||||||
server->writing.lock();
|
server->writing.lock();
|
||||||
while(1) {
|
while(1) {
|
||||||
if(get_signaled())
|
if(get_signaled())
|
||||||
return;
|
return;
|
||||||
cerr << "Trying to connect to: " << server->get_host() << endl;
|
// cerr << "Trying to connect to: " << server->get_host() << endl;
|
||||||
try {
|
try {
|
||||||
server->open();
|
server->open();
|
||||||
server->connected = true;
|
server->connected = true;
|
||||||
server->queue = 0;
|
server->queue = 0;
|
||||||
cerr << "Connected to: " << server->get_host() << endl;
|
// cerr << "Connected to: " << server->get_host() << endl;
|
||||||
break;
|
break;
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,24 +45,24 @@ void nxs::Remap(VChain &chain,
|
||||||
float scaling,
|
float scaling,
|
||||||
int steps) {
|
int steps) {
|
||||||
|
|
||||||
chain.push_back(VPartition());
|
VPartition *finepart = new VPartition;
|
||||||
BuildPartition(chain.back(), points, target_size, min_size, max_size, steps);
|
// finepart.Init();
|
||||||
|
chain.push_back(finepart);
|
||||||
|
BuildPartition(*finepart, points, target_size, min_size, max_size, steps);
|
||||||
|
|
||||||
|
|
||||||
|
VPartition *coarsepart = new VPartition;
|
||||||
chain.push_back(VPartition());
|
// coarsepart.Init();
|
||||||
BuildPartition(chain.back(), points,
|
chain.push_back(coarsepart);
|
||||||
|
BuildPartition(*coarsepart, points,
|
||||||
(int)(target_size/scaling), min_size, max_size, steps);
|
(int)(target_size/scaling), min_size, max_size, steps);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
VPartition &finepart = chain[0];
|
|
||||||
finepart.Init();
|
|
||||||
cerr << "Fine size: " << finepart.size() << endl;
|
|
||||||
|
|
||||||
VPartition &coarsepart = chain[1];
|
|
||||||
coarsepart.Init();
|
cerr << "Fine size: " << finepart->size() << endl;
|
||||||
cerr << "Coarse size: " << coarsepart.size() << endl;
|
cerr << "Coarse size: " << coarsepart->size() << endl;
|
||||||
|
|
||||||
typedef map<pair<unsigned int, unsigned int>, unsigned int> FragIndex;
|
typedef map<pair<unsigned int, unsigned int>, unsigned int> FragIndex;
|
||||||
|
|
||||||
|
@ -75,8 +75,8 @@ void nxs::Remap(VChain &chain,
|
||||||
for(unsigned int i = 0; i < points.Size(); i++) {
|
for(unsigned int i = 0; i < points.Size(); i++) {
|
||||||
bari = points[i];
|
bari = points[i];
|
||||||
|
|
||||||
unsigned int fine = finepart.Locate(bari);
|
unsigned int fine = finepart->Locate(bari);
|
||||||
unsigned int coarse = coarsepart.Locate(bari);
|
unsigned int coarse = coarsepart->Locate(bari);
|
||||||
|
|
||||||
unsigned int patch;
|
unsigned int patch;
|
||||||
|
|
||||||
|
@ -240,10 +240,11 @@ void nxs::BuildLevel(VChain &chain,
|
||||||
totvert += nexus.index[idx].nvert;
|
totvert += nexus.index[idx].nvert;
|
||||||
}
|
}
|
||||||
|
|
||||||
chain.push_back(VPartition());
|
VPartition *fine = chain[chain.size()-1];
|
||||||
VPartition &coarse = chain[chain.size()-1];
|
fine->Init();
|
||||||
VPartition &fine = chain[chain.size()-2];
|
|
||||||
fine.Init();
|
VPartition *coarse = new VPartition;
|
||||||
|
chain.push_back(coarse);
|
||||||
|
|
||||||
//unsigned int ncells = (unsigned int)(fine.size() * scaling);
|
//unsigned int ncells = (unsigned int)(fine.size() * scaling);
|
||||||
unsigned int ncells = (unsigned int)(scaling * totface/target_size);
|
unsigned int ncells = (unsigned int)(scaling * totface/target_size);
|
||||||
|
@ -256,21 +257,21 @@ void nxs::BuildLevel(VChain &chain,
|
||||||
if(cratio > 1) {
|
if(cratio > 1) {
|
||||||
Patch patch = nexus.GetPatch(idx);
|
Patch patch = nexus.GetPatch(idx);
|
||||||
Point3f &v = patch.Vert(0);
|
Point3f &v = patch.Vert(0);
|
||||||
coarse.push_back(v);
|
coarse->push_back(v);
|
||||||
cratio -= 1;
|
cratio -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(coarse.size() == 0) {
|
if(coarse->size() == 0) {
|
||||||
Patch patch = nexus.GetPatch(0);
|
Patch patch = nexus.GetPatch(0);
|
||||||
coarse.push_back(patch.Vert(0));
|
coarse->push_back(patch.Vert(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
float coarse_vmean = totface/(float)coarse.size();
|
float coarse_vmean = totface/(float)coarse->size();
|
||||||
|
|
||||||
coarse.Init();
|
coarse->Init();
|
||||||
cerr << "Ncells: " << ncells << endl;
|
cerr << "Ncells: " << ncells << endl;
|
||||||
cerr << "Coarse size: " << coarse.size() << endl;
|
cerr << "Coarse size: " << coarse->size() << endl;
|
||||||
cerr << "Coarse mean: " << coarse_vmean << " mean_size: " << target_size << endl;
|
cerr << "Coarse mean: " << coarse_vmean << " mean_size: " << target_size << endl;
|
||||||
|
|
||||||
//here goes some optimization pass.
|
//here goes some optimization pass.
|
||||||
|
@ -282,8 +283,8 @@ void nxs::BuildLevel(VChain &chain,
|
||||||
cerr << "Optimization step: " << step+1 << "/" << steps << endl;
|
cerr << "Optimization step: " << step+1 << "/" << steps << endl;
|
||||||
centroids.clear();
|
centroids.clear();
|
||||||
counts.clear();
|
counts.clear();
|
||||||
centroids.resize(coarse.size(), Point3f(0, 0, 0));
|
centroids.resize(coarse->size(), Point3f(0, 0, 0));
|
||||||
counts.resize(coarse.size(), 0);
|
counts.resize(coarse->size(), 0);
|
||||||
|
|
||||||
Report report(nexus.index.size());
|
Report report(nexus.index.size());
|
||||||
for(unsigned int idx = offset; idx < nexus.index.size(); idx++) {
|
for(unsigned int idx = offset; idx < nexus.index.size(); idx++) {
|
||||||
|
@ -295,8 +296,8 @@ void nxs::BuildLevel(VChain &chain,
|
||||||
patch.Vert(face[1]) +
|
patch.Vert(face[1]) +
|
||||||
patch.Vert(face[2]))/3;
|
patch.Vert(face[2]))/3;
|
||||||
|
|
||||||
unsigned int target = coarse.Locate(bari);
|
unsigned int target = coarse->Locate(bari);
|
||||||
assert(target < coarse.size());
|
assert(target < coarse->size());
|
||||||
centroids[target] += bari;
|
centroids[target] += bari;
|
||||||
counts[target]++;
|
counts[target]++;
|
||||||
}
|
}
|
||||||
|
@ -307,11 +308,11 @@ void nxs::BuildLevel(VChain &chain,
|
||||||
centroids[v]/= counts[v];
|
centroids[v]/= counts[v];
|
||||||
|
|
||||||
if(step == steps-1) {
|
if(step == steps-1) {
|
||||||
if(!Optimize(coarse, (int)coarse_vmean, min_size, max_size,
|
if(!Optimize(*coarse, (int)coarse_vmean, min_size, max_size,
|
||||||
centroids, counts, false))
|
centroids, counts, false))
|
||||||
step--;
|
step--;
|
||||||
} else
|
} else
|
||||||
Optimize(coarse, (int)coarse_vmean, min_size, max_size,
|
Optimize(*coarse, (int)coarse_vmean, min_size, max_size,
|
||||||
centroids, counts, true);
|
centroids, counts, true);
|
||||||
}
|
}
|
||||||
chain.newfragments.clear();
|
chain.newfragments.clear();
|
||||||
|
|
|
@ -6,6 +6,11 @@ using namespace std;
|
||||||
using namespace vcg;
|
using namespace vcg;
|
||||||
using namespace nxs;
|
using namespace nxs;
|
||||||
|
|
||||||
|
VChain::~VChain() {
|
||||||
|
for(iterator i = begin(); i != end(); i++)
|
||||||
|
delete *i;
|
||||||
|
}
|
||||||
|
|
||||||
bool VChain::Save(const string &file) {
|
bool VChain::Save(const string &file) {
|
||||||
FILE *fp = fopen(file.c_str(), "wb+");
|
FILE *fp = fopen(file.c_str(), "wb+");
|
||||||
if(!fp) {
|
if(!fp) {
|
||||||
|
@ -16,7 +21,7 @@ bool VChain::Save(const string &file) {
|
||||||
unsigned int nlevels = size();
|
unsigned int nlevels = size();
|
||||||
fwrite(&nlevels, sizeof(unsigned int), 1, fp);
|
fwrite(&nlevels, sizeof(unsigned int), 1, fp);
|
||||||
for(unsigned int i = 0; i < nlevels; i++) {
|
for(unsigned int i = 0; i < nlevels; i++) {
|
||||||
VPartition &level = operator[](i);
|
VPartition &level = *operator[](i);
|
||||||
unsigned int npoints = level.size();
|
unsigned int npoints = level.size();
|
||||||
fwrite(&npoints, sizeof(unsigned int), 1, fp);
|
fwrite(&npoints, sizeof(unsigned int), 1, fp);
|
||||||
fwrite(&(level[0]), sizeof(Point3f), npoints, fp);
|
fwrite(&(level[0]), sizeof(Point3f), npoints, fp);
|
||||||
|
@ -59,8 +64,8 @@ bool VChain::Load(const string &file) {
|
||||||
unsigned int nlevels;
|
unsigned int nlevels;
|
||||||
fread(&nlevels, sizeof(unsigned int), 1, fp);
|
fread(&nlevels, sizeof(unsigned int), 1, fp);
|
||||||
for(unsigned int i = 0; i < nlevels; i++) {
|
for(unsigned int i = 0; i < nlevels; i++) {
|
||||||
push_back(VPartition());
|
push_back(new VPartition());
|
||||||
VPartition &level = back();
|
VPartition &level = *back();
|
||||||
|
|
||||||
unsigned int npoints;
|
unsigned int npoints;
|
||||||
fread(&npoints, sizeof(unsigned int), 1, fp);
|
fread(&npoints, sizeof(unsigned int), 1, fp);
|
||||||
|
|
|
@ -8,8 +8,9 @@
|
||||||
|
|
||||||
namespace nxs {
|
namespace nxs {
|
||||||
|
|
||||||
class VChain: public std::vector<VPartition> {
|
class VChain: public std::vector<VPartition *> {
|
||||||
public:
|
public:
|
||||||
|
~VChain();
|
||||||
bool Save(const std::string &file);
|
bool Save(const std::string &file);
|
||||||
bool Load(const std::string &file);
|
bool Load(const std::string &file);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue