Debug, cleaning and optimization.
This commit is contained in:
parent
487f113015
commit
ed2d3c823b
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.6 2005/01/21 17:09:12 ponchio
|
||||
Porting and debug.
|
||||
|
||||
Revision 1.5 2004/10/08 14:46:26 ponchio
|
||||
Working version.
|
||||
|
||||
|
@ -77,7 +80,7 @@ class Border {
|
|||
links(l), used(_used), size(_size), start(0) {}
|
||||
unsigned int Size() { return used; }
|
||||
//TODO rename available to capacity.
|
||||
unsigned int Available() { return size; }
|
||||
unsigned int Capacity() { return size; }
|
||||
Link &operator[](unsigned int i) { return links[i]; }
|
||||
Link *Start() { return links; }
|
||||
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.10 2005/02/08 12:43:03 ponchio
|
||||
Added copyright
|
||||
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -86,6 +89,9 @@ Border &BorderServer::GetBorder(unsigned int border, bool flush) {
|
|||
index[border] = pqueue.begin();
|
||||
} else {
|
||||
while(flush && ram_used > ram_max) {
|
||||
if(!pqueue.size()) {
|
||||
cerr << "Ram used: " << ram_used << " ram max: " << ram_max << endl;
|
||||
}
|
||||
assert(pqueue.size());
|
||||
unsigned int to_flush = pqueue.back();
|
||||
pqueue.pop_back();
|
||||
|
@ -115,6 +121,8 @@ void BorderServer::ResizeBorder(unsigned int border, unsigned int used) {
|
|||
unsigned int newstart = Length()/sizeof(Link);
|
||||
Redim((int64)(newstart + capacity) * (int64)sizeof(Link));
|
||||
Link *newlinks = new Link[capacity];
|
||||
ram_used += (capacity - entry.size);
|
||||
|
||||
if(entry.used > 0) {
|
||||
assert(entry.links);
|
||||
memcpy(newlinks, entry.links, entry.used * sizeof(Link));
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.5 2005/02/08 12:43:03 ponchio
|
||||
Added copyright
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -44,14 +46,6 @@ $Log: not supported by cvs2svn $
|
|||
|
||||
namespace nxs {
|
||||
|
||||
//This should be Border class!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
/*struct BorderEntry {
|
||||
unsigned int start; //granuralita' Link
|
||||
unsigned short size; //in Links //TODO what are this? be clear!
|
||||
unsigned short used; //in Links
|
||||
Link *links;
|
||||
};*/
|
||||
|
||||
class BorderServer: public IndexFile<Border> {
|
||||
public:
|
||||
BorderServer(): ram_max(1000000), ram_used(0) {}
|
||||
|
@ -65,15 +59,9 @@ class BorderServer: public IndexFile<Border> {
|
|||
Border &GetBorder(unsigned int border, bool flush = true);
|
||||
void ResizeBorder(unsigned int border, unsigned int size);
|
||||
|
||||
/*unsigned int BorderSize(unsigned int i) {
|
||||
return operator[](i).used;
|
||||
}
|
||||
unsigned int BorderCapacity(unsigned int i) {
|
||||
return operator[](i).size;
|
||||
} */
|
||||
protected:
|
||||
unsigned int ram_max;
|
||||
unsigned int ram_used;
|
||||
protected:
|
||||
std::list<unsigned int> pqueue;
|
||||
std::map<unsigned int, std::list<unsigned int>::iterator> index;
|
||||
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.3 2004/11/30 22:50:30 ponchio
|
||||
Level 0.
|
||||
|
||||
Revision 1.2 2004/07/02 13:08:11 ponchio
|
||||
Changed extension to .cri, crv, crf
|
||||
|
||||
|
@ -36,6 +39,7 @@ Created
|
|||
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "crude.h"
|
||||
|
||||
using namespace std;
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.5 2004/11/30 22:50:30 ponchio
|
||||
Level 0.
|
||||
|
||||
Revision 1.4 2004/07/05 15:49:38 ponchio
|
||||
Windows (DevCpp, mingw) port.
|
||||
|
||||
|
@ -45,7 +48,7 @@ Created
|
|||
#ifndef NXS_CRUDE_H
|
||||
#define NXS_CRUDE_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <string>
|
||||
#include <vcg/space/point3.h>
|
||||
#include <vcg/space/box3.h>
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.8 2005/02/21 20:49:30 ponchio
|
||||
some culling bug.
|
||||
|
||||
Revision 1.7 2005/02/20 19:49:44 ponchio
|
||||
cleaning (a bit more).
|
||||
|
||||
|
@ -90,7 +93,7 @@ namespace nxs {
|
|||
visible = false;
|
||||
error /= remote;
|
||||
} else if(entry.cone.Backface(sph, frustum.ViewPoint())) {
|
||||
//visible = false;
|
||||
visible = false;
|
||||
}
|
||||
}
|
||||
return error;
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.35 2005/02/20 19:49:44 ponchio
|
||||
cleaning (a bit more).
|
||||
|
||||
Revision 1.34 2005/02/20 18:07:01 ponchio
|
||||
cleaning.
|
||||
|
||||
|
@ -241,8 +244,8 @@ void NexusMt::Draw(unsigned int cell, DrawContest &contest) {
|
|||
|
||||
fstart = NULL;
|
||||
vstart = NULL;
|
||||
cstart = (char *)(64 * (int)patch.vstartc);
|
||||
nstart = (char *)(64 * (int)patch.vstartn);
|
||||
cstart = (char *)(patch.vstartc - patch.vstart);
|
||||
nstart = (char *)(patch.vstartn - patch.vstart);
|
||||
} else {
|
||||
fstart = (char *)patch.FaceBegin();
|
||||
vstart = (char *)patch.Vert3fBegin();
|
||||
|
@ -388,7 +391,7 @@ void NexusMt::LoadVbo(Entry &entry) {
|
|||
vbo_used += size;
|
||||
|
||||
//TODO fix this when we allow data :p
|
||||
size = 64 * (int)patch.vstartd;
|
||||
size = patch.vstartd - patch.vstart;
|
||||
|
||||
glGenBuffersARB(1, &entry.vbo_array);
|
||||
assert(entry.vbo_array);
|
||||
|
@ -410,7 +413,7 @@ void NexusMt::FlushVbo(Entry &entry) {
|
|||
|
||||
Patch &patch = *entry.patch;
|
||||
vbo_used -= patch.nf * sizeof(unsigned short);
|
||||
vbo_used -= sizeof(float) * patch.vstartd;
|
||||
vbo_used -= sizeof(float) * (patch.vstart - patch.vstartd);
|
||||
}
|
||||
|
||||
//Kept for historical reasons.
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.22 2005/02/21 17:55:36 ponchio
|
||||
debug debug debug
|
||||
|
||||
Revision 1.21 2005/02/20 18:07:01 ponchio
|
||||
cleaning.
|
||||
|
||||
|
@ -61,62 +64,185 @@ using namespace std;
|
|||
using namespace nxs;
|
||||
using namespace vcg;
|
||||
|
||||
#include "tristripper/tri_stripper.h"
|
||||
using namespace triangle_stripper;
|
||||
|
||||
void nxs::Connect(Nexus &nexus, std::vector< set<unsigned int> > &close,
|
||||
float threshold) {
|
||||
|
||||
/*void nxs::TightSphere(vcg::Sphere3f &sphere,
|
||||
std::vector<vcg::Point3f> &points) {
|
||||
//test:
|
||||
//assumes radius is ok.... and try to optimize moving center.
|
||||
//TODO using a gradiend descent? really a mess.
|
||||
Point3f center;
|
||||
float radius;
|
||||
Point3f pert[14];
|
||||
while(1) {
|
||||
radius = sphere.Radius();
|
||||
float step = radius/40;
|
||||
pert[0] = Point3f(step, 0, 0);
|
||||
pert[1] = -pert[0];
|
||||
pert[2] = Point3f(0, step, 0);
|
||||
pert[3] = -pert[2];
|
||||
pert[4] = Point3f(0, 0, step);
|
||||
pert[5] = -pert[4];
|
||||
pert[6] = Point3f(step, step, step);
|
||||
pert[7] = Point3f(step, step, -step);
|
||||
pert[8] = Point3f(step, -step, step);
|
||||
pert[9] = Point3f(step, -step, -step);
|
||||
pert[10] = Point3f(-step, step, step);
|
||||
pert[11] = Point3f(-step, step, -step);
|
||||
pert[12] = Point3f(-step, -step, step);
|
||||
pert[13] = Point3f(-step, -step, -step);
|
||||
VPartition grid;
|
||||
float max_radius = 0;
|
||||
|
||||
unsigned int best = 14;
|
||||
float best_radius = sphere.Radius();
|
||||
|
||||
for(unsigned int k = 0; k < 14; k++) {
|
||||
center = sphere.Center() + pert[k];
|
||||
radius = 0;
|
||||
for(unsigned int i = 0; i < points.size(); i++) {
|
||||
float r = 1.01 * Distance(center, points[i]);
|
||||
if(r > radius)
|
||||
radius = r;
|
||||
for(unsigned int patch = 0; patch < nexus.size(); patch++) {
|
||||
Sphere3f &sphere = nexus[patch].sphere;
|
||||
grid.push_back(sphere.Center());
|
||||
float r = sphere.Radius();
|
||||
if(r > max_radius) max_radius = r;
|
||||
}
|
||||
if(radius < best_radius) {
|
||||
best = k;
|
||||
best_radius = radius;
|
||||
grid.Init();
|
||||
close.clear();
|
||||
close.resize(nexus.size());
|
||||
|
||||
vector<int> targets;
|
||||
vector<double> dists;
|
||||
for(unsigned int patch = 0; patch < nexus.size(); patch++) {
|
||||
float radius = nexus[patch].sphere.Radius();
|
||||
float max_distance = radius + max_radius + threshold;
|
||||
max_distance *= max_distance;
|
||||
grid.Closest(grid[patch], targets, dists, max_distance);
|
||||
|
||||
for(unsigned int i = 0; i < targets.size(); i++) {
|
||||
unsigned int target = targets[i];
|
||||
if(target == patch) continue;
|
||||
float dist = radius + nexus[target].sphere.Radius() + threshold;
|
||||
dist *= dist;
|
||||
if(dist >= dists[i]) {
|
||||
close[patch].insert(target);
|
||||
}
|
||||
}
|
||||
if(best == 14) break;
|
||||
sphere.Center() = sphere.Center() + pert[best];
|
||||
sphere.Radius() = best_radius;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
//DOUBLECROSS CHECK
|
||||
for(unsigned int patch = 0; patch < nexus.size(); patch++) {
|
||||
set<unsigned int>::iterator i;
|
||||
for(i = close[patch].begin(); i != close[patch].end(); i++) {
|
||||
if(!close[*i].count(patch)) {
|
||||
cerr << "Some problem width sphere intersection. Have alook.\n";
|
||||
cerr << "Meanwhile i fix it.\n";
|
||||
close[*i].insert(patch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void nxs::ComputeNormals(Nexus &nexus) {
|
||||
assert(nexus.signature.vnorm);
|
||||
assert(!nexus.borders.IsReadOnly());
|
||||
|
||||
//first calculate level 0 normals
|
||||
//I load all patches in a fragment
|
||||
//calculate normals
|
||||
//fix external borders getting from level below
|
||||
|
||||
//first try naive approach just load neighborough get normals and
|
||||
//fix border with lower level
|
||||
|
||||
vector<int> levels;
|
||||
nexus.history.BuildLevels(levels);
|
||||
Report report(nexus.size(), 15);
|
||||
|
||||
//TODO check level 0 is the finer onr
|
||||
|
||||
int current_level = 0;
|
||||
while(1) {
|
||||
int count = 0;
|
||||
for(unsigned int p = 0; p < nexus.size(); p++) {
|
||||
if(levels[p] != current_level) continue;
|
||||
count++;
|
||||
report.Step(p);
|
||||
|
||||
Border &border = nexus.GetBorder(p);
|
||||
|
||||
map<unsigned int, vector<Point3f> > normals;
|
||||
normals[p] = vector<Point3f>();
|
||||
|
||||
for(unsigned int i = 0; i < border.Size(); i++) {
|
||||
Link &link = border[i];
|
||||
if(levels[link.end_patch] == current_level)
|
||||
normals[link.end_patch] = vector<Point3f>();
|
||||
}
|
||||
map<unsigned int, vector<Point3f> >::iterator k;
|
||||
for(k = normals.begin(); k != normals.end(); k++) {
|
||||
Patch &patch = nexus.GetPatch((*k).first);
|
||||
|
||||
vector<Point3f> &normal = (*k).second;
|
||||
normal.resize(patch.nv, Point3f(0, 0, 0));
|
||||
|
||||
if(nexus.signature.face == Signature::TRIANGLES) {
|
||||
for(unsigned int i = 0; i < patch.nf; i++) {
|
||||
unsigned short *f = patch.Face(i);
|
||||
Point3f &v0 = patch.Vert3f(f[0]);
|
||||
Point3f &v1 = patch.Vert3f(f[1]);
|
||||
Point3f &v2 = patch.Vert3f(f[2]);
|
||||
Point3f norm = (v1 - v0) ^ (v2 - v0);
|
||||
normal[f[0]] += norm;
|
||||
normal[f[1]] += norm;
|
||||
normal[f[2]] += norm;
|
||||
}
|
||||
} else if(nexus.signature.face == Signature::STRIPS) {
|
||||
for(int i = 0; i < patch.nf - 2; i++) {
|
||||
unsigned short *f = patch.FaceBegin() + i;
|
||||
Point3f &v0 = patch.Vert3f(f[0]);
|
||||
Point3f &v1 = patch.Vert3f(f[1]);
|
||||
Point3f &v2 = patch.Vert3f(f[2]);
|
||||
Point3f norm = (v1 - v0) ^ (v2 - v0);
|
||||
if(i%2) norm = -norm;
|
||||
normal[f[0]] += norm;
|
||||
normal[f[1]] += norm;
|
||||
normal[f[2]] += norm;
|
||||
}
|
||||
} else
|
||||
assert(0);
|
||||
}
|
||||
|
||||
//now fix borders
|
||||
map<unsigned int, vector<Link> > lowers;
|
||||
for(unsigned int i = 0; i < border.Size(); i++) {
|
||||
Link &link = border[i];
|
||||
if(levels[link.end_patch] == current_level) {
|
||||
//TODO remove these asserts
|
||||
assert(normals[p].size() > link.start_vert);
|
||||
assert(normals.count(link.end_patch));
|
||||
assert(normals[link.end_patch].size() > link.end_vert);
|
||||
normals[p][link.start_vert] += normals[link.end_patch][link.end_vert];
|
||||
} else if (levels[link.end_patch] < current_level) {
|
||||
lowers[link.end_patch].push_back(link);
|
||||
}
|
||||
}
|
||||
|
||||
map<unsigned int, vector<Link> >::iterator s;
|
||||
for(s = lowers.begin(); s != lowers.end(); s++) {
|
||||
Patch &patch = nexus.GetPatch((*s).first);
|
||||
for(unsigned int i = 0; i < (*s).second.size(); i++) {
|
||||
Link &link = (*s).second[i];
|
||||
if(nexus.signature.vnorm == Encodings::FLOAT3)
|
||||
normals[p][link.start_vert] =
|
||||
((Point3f *)patch.VNormBegin())[link.end_vert];
|
||||
else if(nexus.signature.vnorm == Encodings::SHORT4) {
|
||||
Point3f &nor = normals[p][link.start_vert];
|
||||
short *n = ((short *)patch.VNormBegin()) + 4*link.end_vert;
|
||||
nor[0] = n[0];
|
||||
nor[1] = n[1];
|
||||
nor[2] = n[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
//copy and normalize
|
||||
Patch &patch = nexus.GetPatch(p);
|
||||
Entry &entry = nexus[p];
|
||||
Point3f *norm = (Point3f *)patch.VNormBegin();
|
||||
vector<Point3f> &newnormals = normals[p];
|
||||
assert(newnormals.size() == patch.nv);
|
||||
for(unsigned int i = 0; i < patch.nv; i++) {
|
||||
newnormals[i].Normalize();
|
||||
if(nexus.signature.vnorm == Encodings::SHORT4) {
|
||||
newnormals[i] *= 32766;
|
||||
short *np = ((short *)norm) + 4 * i;
|
||||
np[0] = (short)newnormals[i][0];
|
||||
np[1] = (short)newnormals[i][1];
|
||||
np[2] = (short)newnormals[i][2];
|
||||
np[3] = 0;
|
||||
} else if(nexus.signature.vnorm == Encodings::FLOAT3)
|
||||
norm[i] = newnormals[i];
|
||||
}
|
||||
}
|
||||
if(count == 0) break;
|
||||
current_level++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*void nxs::ComputeNormals(Nexus &nexus) {
|
||||
assert(nexus.signature.vnorm);
|
||||
|
||||
//setting borders readonly:
|
||||
|
||||
|
@ -254,36 +380,6 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* set<unsigned int> close;
|
||||
for(unsigned int i = 0; i < border.Size(); i++) {
|
||||
Link &link = border[i];
|
||||
if(link.IsNull()) continue;
|
||||
unsigned int off = tmpb_start[p];
|
||||
Point3f p = tmpb.read(off + i);
|
||||
p += normals[link.start_vert];
|
||||
tmpb.write(off + i, p);
|
||||
// tmpb[off + i] += normals[link.start_vert];
|
||||
close.insert(link.end_patch);
|
||||
}
|
||||
|
||||
set<unsigned int>::iterator k;
|
||||
for(k = close.begin(); k != close.end(); k++) {
|
||||
Border &remote = nexus.GetBorder(*k);
|
||||
unsigned int off = tmpb_start[*k];
|
||||
|
||||
for(unsigned int i = 0; i < remote.Size(); i++) {
|
||||
Link &link = remote[i];
|
||||
if(link.IsNull()) continue;
|
||||
if(link.end_patch != p) continue;
|
||||
Point3f p = tmpb.read(off + i);
|
||||
p += normals[link.end_vert];
|
||||
tmpb.write(off + i, p);
|
||||
// tmpb[off + i] += normals[link.end_vert];
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
//Second step unify normals across borders
|
||||
|
@ -321,60 +417,9 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
|||
tmpb.Delete();
|
||||
//TODO remove temporary file.
|
||||
nexus.borders.SetReadOnly(false);
|
||||
}
|
||||
|
||||
void nxs::ComputeTriStrip(unsigned short nfaces, unsigned short *faces,
|
||||
vector<unsigned short> &strip) {
|
||||
}*/
|
||||
|
||||
|
||||
vector<unsigned int> index;
|
||||
index.resize(nfaces*3);
|
||||
for(int i = 0; i < nfaces*3; i++) {
|
||||
index[i] = faces[i];
|
||||
}
|
||||
int cache_size = 0;
|
||||
tri_stripper stripper(index);
|
||||
stripper.SetCacheSize(cache_size);
|
||||
// = 0 will disable the cache optimizer
|
||||
stripper.SetMinStripSize(0);
|
||||
tri_stripper::primitives_vector primitives;
|
||||
stripper.Strip(&primitives);
|
||||
|
||||
if(primitives.back().m_Indices.size() < 3) {
|
||||
primitives.pop_back();
|
||||
}
|
||||
//TODO spostare questo dentro il ciclo che rimonta le strip.
|
||||
if(primitives.back().m_Type == tri_stripper::PT_Triangles) {
|
||||
tri_stripper::primitives p;
|
||||
p = primitives.back();
|
||||
primitives.pop_back();
|
||||
for(unsigned int i = 0; i < p.m_Indices.size(); i += 3) {
|
||||
tri_stripper::primitives s;
|
||||
s.m_Type = tri_stripper::PT_Triangle_Strip;
|
||||
s.m_Indices.push_back(p.m_Indices[i]);
|
||||
s.m_Indices.push_back(p.m_Indices[i+1]);
|
||||
s.m_Indices.push_back(p.m_Indices[i+2]);
|
||||
primitives.push_back(s);
|
||||
}
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < primitives.size(); i++) {
|
||||
tri_stripper::primitives &primitive = primitives[i];
|
||||
assert(primitive.m_Indices.size() != 0);
|
||||
int len = primitive.m_Indices.size();
|
||||
for(int l = 0; l < len; l++)
|
||||
strip.push_back(primitive.m_Indices[l]);
|
||||
|
||||
|
||||
if(i < primitives.size()-1) { //not the last primitive.
|
||||
strip.push_back(primitive.m_Indices[len-1]);
|
||||
//TODO optimize this!
|
||||
if((len%2) == 1) //do not change orientation....
|
||||
strip.push_back(primitive.m_Indices[len-1]);
|
||||
strip.push_back(primitives[i+1].m_Indices[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
//TODO why i created this function? wonder...
|
||||
|
@ -415,6 +460,35 @@ void nxs::Reorder(Signature &signature, Patch &patch) {
|
|||
}*/
|
||||
|
||||
//TODO actually use threshold
|
||||
|
||||
void nxs::Unify(Nexus &nexus, float threshold) {
|
||||
/* threshold = 0.00001;
|
||||
unsigned int duplicated = 0;
|
||||
unsigned int degenerate = 0;
|
||||
|
||||
for(unsigned int p = 0; p < nexus.size(); p++) {
|
||||
if(levels[p] != current_level) continue;
|
||||
count++;
|
||||
report.Step(p);
|
||||
|
||||
Border &border = nexus.GetBorder(p);
|
||||
|
||||
map<unsigned int, vector<Point3f> > normals;
|
||||
normals[p] = vector<Point3f>();
|
||||
|
||||
for(unsigned int i = 0; i < border.Size(); i++) {
|
||||
Link &link = border[i];
|
||||
if(levels[link.end_patch] == current_level)
|
||||
normals[link.end_patch] = vector<Point3f>();
|
||||
}
|
||||
map<unsigned int, vector<Point3f> >::iterator k;
|
||||
for(k = normals.begin(); k != normals.end(); k++) {
|
||||
Patch &patch = nexus.GetPatch((*k).first);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/*
|
||||
void nxs::Unify(Nexus &nexus, float threshold) {
|
||||
threshold = 0.001;
|
||||
//TODO what if colors or normals or strips?
|
||||
|
@ -551,7 +625,7 @@ void nxs::Unify(Nexus &nexus, float threshold) {
|
|||
if(degenerate)
|
||||
cerr << "Found " << degenerate << " degenerate face while unmifying\n";
|
||||
}
|
||||
|
||||
*/
|
||||
void nxs::ZSort(Nexus &nexus, vector<unsigned int> &forward,
|
||||
vector<unsigned int> &backward) {
|
||||
//lets get a bounding box from the sphere:
|
||||
|
@ -590,3 +664,4 @@ void nxs::ZSort(Nexus &nexus, vector<unsigned int> &forward,
|
|||
for(unsigned int i = 0; i < backward.size(); i++)
|
||||
backward[forward[i]] = i;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.8 2005/02/21 17:55:36 ponchio
|
||||
debug debug debug
|
||||
|
||||
Revision 1.7 2005/02/20 18:07:01 ponchio
|
||||
cleaning.
|
||||
|
||||
|
@ -42,6 +45,7 @@ Added copyright
|
|||
#ifndef NXS_ALGO_H
|
||||
#define NXS_ALGO_H
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include "patch.h"
|
||||
#include <vcg/space/sphere3.h>
|
||||
|
@ -58,10 +62,13 @@ namespace nxs {
|
|||
bool operator<(const ZEntry &e) const { return pos < e.pos; }
|
||||
};
|
||||
|
||||
//for every patch return close by (sphere intersecting)
|
||||
//threshold is added to the distance to make sure we do not miss anything
|
||||
void Connect(Nexus &nexus, std::vector< std::set<unsigned int> > &close,
|
||||
float threshold);
|
||||
|
||||
void ComputeNormals(Nexus &nexus);
|
||||
void ComputeTriStrip(unsigned short nfaces, unsigned short *faces,
|
||||
std::vector<unsigned short> &strip);
|
||||
void Reorder(Signature &signature, nxs::Patch &patch);
|
||||
|
||||
void Unify(Nexus &nexus, float threshold);
|
||||
void ZSort(Nexus &nexus, std::vector<unsigned int> &forward,
|
||||
std::vector<unsigned int> &backward);
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.20 2005/02/21 17:55:47 ponchio
|
||||
debug debug debug
|
||||
|
||||
Revision 1.19 2005/02/20 18:07:01 ponchio
|
||||
cleaning.
|
||||
|
||||
|
@ -432,7 +435,6 @@ void FourthStep(const string &crudefile, const string &output,
|
|||
exit(0);
|
||||
}
|
||||
nexus.MaxRam() = ram_buffer / nexus.chunk_size;
|
||||
//TODO Clear borders in case of failure!
|
||||
|
||||
VFile<unsigned int> vert_remap;
|
||||
if(!vert_remap.Load(output + ".rvm", true)) {
|
||||
|
@ -446,58 +448,36 @@ void FourthStep(const string &crudefile, const string &output,
|
|||
exit(0);
|
||||
}
|
||||
|
||||
/*float max_radius = 0;
|
||||
VPartition grid;
|
||||
for(int start = 0; start < nexus.size(); start++) {
|
||||
Entry &entry = nexus[start];
|
||||
Sphere3f &sphere = entry.sphere;
|
||||
if(sphere.Radius() > max_radius) max_radius = sphere.Radius();
|
||||
grid.push_back(sphere.Center());
|
||||
}
|
||||
grid.Init();
|
||||
max_radius *= max_radius * 4;
|
||||
vector<int> nears;
|
||||
vector<float> dists; */
|
||||
|
||||
vector<set<unsigned int> > close;
|
||||
Connect(nexus, close, 0.0001);
|
||||
|
||||
Report report(nexus.size());
|
||||
|
||||
for(int start = 0; start < nexus.size(); start++) {
|
||||
report.Step(start);
|
||||
Entry &s_entry = nexus[start];
|
||||
Sphere3f &sphere = s_entry.sphere;
|
||||
// Entry &s_entry = nexus[start];
|
||||
// Sphere3f &sphere = s_entry.sphere;
|
||||
|
||||
vector<Link> links;
|
||||
#ifdef WIN32
|
||||
hash_map<unsigned int, unsigned short> vremap;
|
||||
#else
|
||||
map<unsigned int, unsigned short> vremap;
|
||||
#endif
|
||||
for(unsigned int i = 0; i < vert_index[start].size; i++) {
|
||||
unsigned int global = vert_remap[vert_index[start].offset + i];
|
||||
vremap[global] = i;
|
||||
}
|
||||
|
||||
/*unsigned int n_nears = 10;
|
||||
while(1) {
|
||||
if(n_nears > grid.size()) n_nears = grid.size();
|
||||
grid.Closest(sphere.Center(), n_nears, nears, dists);
|
||||
if(dists.back() > max_radius) break;
|
||||
if(n_nears == grid.size()) break;
|
||||
n_nears *= 2;
|
||||
}
|
||||
// for(int end = 0; end < nexus.size(); end++) {
|
||||
// if(start == end) continue;
|
||||
set<unsigned int>::iterator t;
|
||||
for(t = close[start].begin(); t != close[start].end(); t++) {
|
||||
unsigned int end = (*t);
|
||||
|
||||
for(int n = 0; n < nears.size(); n++) {
|
||||
unsigned int end = nears[n]; */
|
||||
for(int end = 0; end < nexus.size(); end++) {
|
||||
if(start == end) continue;
|
||||
// Entry &e_entry = nexus[end];
|
||||
// float dist = Distance(s_entry.sphere.Center(), e_entry.sphere.Center());
|
||||
|
||||
Entry &e_entry = nexus[end];
|
||||
float dist = Distance(s_entry.sphere, e_entry.sphere);
|
||||
|
||||
if(dist > s_entry.sphere.Radius() + e_entry.sphere.Radius()) {
|
||||
continue;
|
||||
}
|
||||
// if(dist > s_entry.sphere.Radius() + e_entry.sphere.Radius()) {
|
||||
// continue;
|
||||
// }
|
||||
// assert(close[start].count(end));
|
||||
|
||||
for(unsigned int i = 0; i < vert_index[end].size; i++) {
|
||||
unsigned int global = vert_remap[vert_index[end].offset + i];
|
||||
|
@ -510,7 +490,6 @@ void FourthStep(const string &crudefile, const string &output,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
Border &border = nexus.GetBorder(start);
|
||||
nexus.borders.ResizeBorder(start, 3 * links.size());
|
||||
border.used = links.size();
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.25 2005/02/21 17:55:47 ponchio
|
||||
debug debug debug
|
||||
|
||||
Revision 1.24 2005/02/20 19:49:44 ponchio
|
||||
cleaning (a bit more).
|
||||
|
||||
|
@ -68,6 +71,7 @@ Added copyright
|
|||
#include <vcg/space/index/grid_static_ptr.h>
|
||||
|
||||
#include "nxsalgo.h"
|
||||
#include "strip.h"
|
||||
#include "nexus.h"
|
||||
#include "watch.h"
|
||||
|
||||
|
@ -463,14 +467,14 @@ int main(int argc, char *argv[]) {
|
|||
if(add_strips) {
|
||||
ComputeTriStrip(src_patch.nf, src_patch.FaceBegin(), strip);
|
||||
assert(strip.size() < 32767);
|
||||
out.AddPatch(src_entry.nvert, strip.size(), src_border.Available());
|
||||
out.AddPatch(src_entry.nvert, strip.size(), src_border.Capacity());
|
||||
if(verbose) {
|
||||
cerr << "tri: " << src_patch.nf << " strip: " << strip.size()
|
||||
<< " ratio: " << (float)strip.size()/(float)src_patch.nf
|
||||
<< endl;
|
||||
}
|
||||
} else
|
||||
out.AddPatch(src_entry.nvert, src_entry.nface, src_border.Available());
|
||||
out.AddPatch(src_entry.nvert, src_entry.nface, src_border.Capacity());
|
||||
|
||||
|
||||
Entry &dst_entry = out[p];
|
||||
|
|
|
@ -26,8 +26,9 @@ int main(int argc, char *argv[]) {
|
|||
crude.Resize(side * side, (side-1) * (side-1) * 2);
|
||||
for(unsigned int x = 0; x < side; x++)
|
||||
for(unsigned int y = 0; y < side; y++) {
|
||||
Point3f p(x*x*x/((float)side),
|
||||
y*y*y/((float)side), x*y/((float)side));
|
||||
// Point3f p(x*x*x/((float)side),
|
||||
// y*y*y/((float)side), x*y/((float)side));
|
||||
Point3f p(x, y, sqrt((float)x*x + y*y));
|
||||
crude.SetVertex(x + side * y, p);
|
||||
crude.GetBox().Add(p);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.12 2005/02/21 19:05:58 ponchio
|
||||
i already fixed this bug. I hate you cvs.
|
||||
|
||||
Revision 1.11 2005/02/19 12:06:55 ponchio
|
||||
Debug...
|
||||
|
||||
|
@ -85,9 +88,9 @@ Encodings::Encodings() {
|
|||
}
|
||||
|
||||
|
||||
void pad64(unsigned int &s) {
|
||||
if((s & 0x0000003f) != 0) {
|
||||
s>>=6; s++; s<<=6;
|
||||
void pad8(unsigned int &s) {
|
||||
if((s & 0x00000007) != 0) {
|
||||
s>>=3; s++; s<<=3;
|
||||
}
|
||||
}
|
||||
void pad(unsigned int &size) {
|
||||
|
@ -165,34 +168,33 @@ void Patch::Init(Signature &signature,
|
|||
assert(0);
|
||||
//non lo so...
|
||||
}
|
||||
pad64(offset);
|
||||
pad8(offset);
|
||||
|
||||
fstartc = (unsigned short)(offset/64);
|
||||
fstartc = fstart + offset;
|
||||
offset += encodings[signature.fcolor].size(nf);
|
||||
fstartn = (unsigned short)(offset/64);
|
||||
fstartn = fstart + offset;
|
||||
offset += encodings[signature.fnorm].size(nf);
|
||||
fstartt = (unsigned short)(offset/64);
|
||||
fstartt = fstart + offset;
|
||||
offset += encodings[signature.ftext].size(nf);
|
||||
fstartd = (unsigned short)(offset/64);
|
||||
fstartd = fstart + offset;
|
||||
offset += encodings[signature.fdata].size(nf);
|
||||
|
||||
vstart = fstart + offset;
|
||||
offset = 0;
|
||||
if(signature.vert == Signature::POINT3F)
|
||||
offset += nv * sizeof(float) * 3;
|
||||
else if(signature.vert == Signature::POINT4F)
|
||||
offset += nv * sizeof(float) * 4;
|
||||
else
|
||||
assert(0);
|
||||
pad64(offset);
|
||||
pad8(offset);
|
||||
|
||||
vstartc = (unsigned short)(offset/64);
|
||||
vstartc = fstart + offset;
|
||||
offset += encodings[signature.vcolor].size(nv);
|
||||
vstartn = (unsigned short)(offset/64);
|
||||
vstartn = fstart + offset;
|
||||
offset += encodings[signature.vnorm].size(nv);
|
||||
vstartt = (unsigned short)(offset/64);
|
||||
vstartt = fstart + offset;
|
||||
offset += encodings[signature.vtext].size(nv);
|
||||
vstartd = (unsigned short)(offset/64);
|
||||
vstartd = fstart + offset;
|
||||
offset += encodings[signature.vdata].size(nv);
|
||||
|
||||
|
||||
|
@ -251,7 +253,7 @@ unsigned int Patch::ByteSize(Signature &signature,
|
|||
assert(0);
|
||||
//non lo so...
|
||||
}
|
||||
pad64(size);
|
||||
pad8(size);
|
||||
|
||||
size += encodings[signature.fcolor].size(nface);
|
||||
size += encodings[signature.fnorm].size(nface);
|
||||
|
@ -264,7 +266,7 @@ unsigned int Patch::ByteSize(Signature &signature,
|
|||
size += nvert * sizeof(float) * 4;
|
||||
else
|
||||
assert(0);
|
||||
pad64(size);
|
||||
pad8(size);
|
||||
|
||||
size += encodings[signature.vcolor].size(nvert);
|
||||
size += encodings[signature.vnorm].size(nvert);
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.13 2005/02/19 12:06:55 ponchio
|
||||
Debug...
|
||||
|
||||
Revision 1.12 2005/02/19 10:45:05 ponchio
|
||||
Patch generalized and small fixes.
|
||||
|
||||
|
@ -81,9 +84,9 @@ namespace nxs {
|
|||
|
||||
unsigned int size(unsigned short n) {
|
||||
unsigned int s = (int)n * (int)bytes * (int)comps;
|
||||
//padding a 64 bytes
|
||||
if((s & 0x0000003f) != 0) {
|
||||
s>>=6; s++; s<<=6;
|
||||
//padding a 8 bytes
|
||||
if((s & 0x0000007) != 0) {
|
||||
s>>=3; s++; s<<=3;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
@ -121,15 +124,15 @@ class Patch {
|
|||
//vcg::Point3f &Vert(unsigned short v) { return VertBegin()[v]; }
|
||||
// unsigned short *Face(unsigned short f) { return FaceBegin() + f * 3; }
|
||||
|
||||
char *VColorBegin() { return vstart + 64*(int)vstartc; }
|
||||
char *VNormBegin() { return vstart + 64*(int)vstartn; }
|
||||
char *VTextBegin() { return vstart + 64*(int)vstartt; }
|
||||
char *VDataBegin() { return vstart + 64*(int)vstartd; }
|
||||
char *VColorBegin() { return vstartc; }
|
||||
char *VNormBegin() { return vstartn; }
|
||||
char *VTextBegin() { return vstartt; }
|
||||
char *VDataBegin() { return vstartd; }
|
||||
|
||||
char *FColorBegin() { return fstart + 64*(int)fstartc; }
|
||||
char *FNormBegin() { return fstart + 64*(int)fstartn; }
|
||||
char *FTextBegin() { return fstart + 64*(int)fstartt; }
|
||||
char *FDataBegin() { return fstart + 64*(int)fstartd; }
|
||||
char *FColorBegin() { return fstartc; }
|
||||
char *FNormBegin() { return fstartn; }
|
||||
char *FTextBegin() { return fstartt; }
|
||||
char *FDataBegin() { return fstartd; }
|
||||
|
||||
static unsigned int ChunkSize(Signature &signature,
|
||||
unsigned short nvert,
|
||||
|
@ -150,17 +153,15 @@ class Patch {
|
|||
unsigned short nf;
|
||||
unsigned short nv;
|
||||
|
||||
//these offset are from fstart in 64 bytes
|
||||
unsigned short fstartc;
|
||||
unsigned short fstartn;
|
||||
unsigned short fstartt;
|
||||
unsigned short fstartd;
|
||||
char *fstartc;
|
||||
char *fstartn;
|
||||
char *fstartt;
|
||||
char *fstartd;
|
||||
|
||||
//these offset are from vstart in 64 bytes
|
||||
unsigned short vstartc;
|
||||
unsigned short vstartn;
|
||||
unsigned short vstartt;
|
||||
unsigned short vstartd;
|
||||
char *vstartc;
|
||||
char *vstartn;
|
||||
char *vstartt;
|
||||
char *vstartd;
|
||||
};
|
||||
|
||||
} //namespace
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.4 2005/02/21 17:55:48 ponchio
|
||||
debug debug debug
|
||||
|
||||
Revision 1.3 2005/01/21 17:09:13 ponchio
|
||||
Porting and debug.
|
||||
|
||||
|
@ -95,6 +98,32 @@ void VPartition::Closest(const vcg::Point3f &p,
|
|||
dist = (float)dists;
|
||||
}
|
||||
|
||||
void VPartition::Closest(const vcg::Point3f &p,
|
||||
vector<int> &targets,
|
||||
vector<double> &dists,
|
||||
float max_distance) {
|
||||
|
||||
double point[3]; point[0] = p[0]; point[1] = p[1]; point[2] = p[2];
|
||||
|
||||
int seeds = 6;
|
||||
while(1) {
|
||||
if(seeds > size()) seeds = size();
|
||||
targets.resize(seeds);
|
||||
dists.resize(seeds);
|
||||
bd->annkSearch(&point[0], seeds, &(targets[0]), &(dists[0]));
|
||||
for(int i = 0; i < seeds; i++) {
|
||||
if(dists[i] > max_distance) {
|
||||
targets.resize(i);
|
||||
dists.resize(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(targets.size() < seeds) break;
|
||||
if(seeds == size()) break;
|
||||
seeds *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
void VPartition::Closest(const vcg::Point3f &p, unsigned int nsize,
|
||||
int *targets,
|
||||
double *dists) {
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.4 2005/02/21 17:55:49 ponchio
|
||||
debug debug debug
|
||||
|
||||
Revision 1.3 2005/01/18 22:46:58 ponchio
|
||||
Small changes.
|
||||
|
||||
|
@ -53,6 +56,7 @@ class ANNbruteForce;
|
|||
|
||||
namespace nxs {
|
||||
|
||||
//WARNING: all distances returned are SQUARED!!!!
|
||||
class VPartition: public std::vector<vcg::Point3f> {
|
||||
public:
|
||||
VPartition(): bd(NULL) {}
|
||||
|
@ -75,6 +79,11 @@ class VPartition: public std::vector<vcg::Point3f> {
|
|||
std::vector<float> &dist);
|
||||
void Closest(const vcg::Point3f &p,
|
||||
int &target, float &dist);
|
||||
|
||||
//return all targets widthin that distance (SQUARED!!!)
|
||||
void Closest(const vcg::Point3f &p, std::vector<int> &targets,
|
||||
std::vector<double> &dists,
|
||||
float max_distance);
|
||||
//most efficient!
|
||||
void Closest(const vcg::Point3f &p, unsigned int nsize,
|
||||
int *targets,
|
||||
|
|
Loading…
Reference in New Issue