Fixing normals...
This commit is contained in:
parent
0251d89f11
commit
6b4b4f3de7
|
@ -189,7 +189,7 @@ bool History::UpdatesToQuick() {
|
|||
|
||||
Node &node = tmp_nodes[current_node];
|
||||
|
||||
//created cells belong to this node, we look also for max error.
|
||||
//created cells belong to this node,
|
||||
for(unsigned int i = 0; i < (*u).created.size(); i++) {
|
||||
unsigned int cell = (*u).created[i];
|
||||
cell_node[cell] = current_node;
|
||||
|
@ -295,3 +295,41 @@ bool History::UpdatesToQuick() {
|
|||
|
||||
return LoadPointers();
|
||||
}
|
||||
|
||||
void History::BuildLevels(map<unsigned int, unsigned int> &levels) {
|
||||
levels.clear();
|
||||
if(buffer) {
|
||||
//Saved in quick mode:
|
||||
for(unsigned int n = 0; n < n_nodes(); n++) {
|
||||
Node *node = nodes+n;
|
||||
Node::iterator l;
|
||||
unsigned int current = 0;
|
||||
if(node != nodes) { //not root
|
||||
Link *inlink = node->in_begin();
|
||||
unsigned int p = inlink->begin()->patch;
|
||||
assert(levels.count(p));
|
||||
current = levels[p]+1;
|
||||
}
|
||||
for(l = node->out_begin(); l != node->out_end(); l++) {
|
||||
Link &link = *l;
|
||||
Link::iterator c;
|
||||
for(c = link.begin(); c != link.end(); c++) {
|
||||
unsigned int p = (*c).patch;
|
||||
levels[p] = current;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cerr << "updates.size: " << updates.size() << endl;
|
||||
//Saved in updates mode:
|
||||
for(unsigned int i = 0; i < updates.size(); i++) {
|
||||
Update &u = updates[i];
|
||||
unsigned int current = 0;
|
||||
if(!u.erased.size()) current = 0;
|
||||
else current = levels[u.erased[0]] + 1;
|
||||
for(unsigned int i = 0; i < u.created.size(); i++) {
|
||||
levels[u.created[i]] = current;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define NXS_HISTORY_H
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
//TODO fix a bit better the quick <-> updates duality
|
||||
|
||||
|
@ -83,6 +84,8 @@ namespace nxs {
|
|||
bool UpdatesToQuick();
|
||||
bool IsQuick() { return buffer != NULL; }
|
||||
|
||||
void BuildLevels(std::map<unsigned int, unsigned int> &levels);
|
||||
|
||||
int &quick() { return ((int *)buffer)[0]; }
|
||||
int &n_nodes() { return ((int *)buffer)[1]; }
|
||||
int &n_in_links() { return ((int *)buffer)[2]; }
|
||||
|
|
|
@ -51,12 +51,17 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
|||
tmpb[i] = zero;
|
||||
tmpb.Flush();
|
||||
|
||||
|
||||
map<unsigned int, unsigned int> levels;
|
||||
nexus.history.BuildLevels(levels);
|
||||
|
||||
//first step normals in the same patch.
|
||||
cerr << "First Step\n";
|
||||
Report report(nexus.size(), 5);
|
||||
vector<Point3f> normals;
|
||||
|
||||
for(unsigned int p = 0; p < nexus.size(); p++) {
|
||||
unsigned int current_level = levels[p];
|
||||
report.Step(p);
|
||||
Patch &patch = nexus.GetPatch(p);
|
||||
|
||||
|
@ -108,27 +113,29 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
|||
|
||||
Border &border = nexus.GetBorder(p);
|
||||
|
||||
|
||||
map<unsigned int, map<unsigned short, Point3f> > bnorm;
|
||||
map<unsigned int, Link> bcopy;
|
||||
|
||||
unsigned int poff = tmpb_start[p];
|
||||
for(unsigned int i = 0; i < border.Size(); i++) {
|
||||
Link &link = border[i];
|
||||
if(link.IsNull()) continue; //this should never happen now.
|
||||
Point3f pt = normals[link.start_vert];
|
||||
//bnorm[p][link.start_vert] = pt;
|
||||
bnorm[link.end_patch][link.end_vert] = pt;
|
||||
tmpb[poff + i] += pt;
|
||||
|
||||
if(levels[link.end_patch] == current_level) {
|
||||
bnorm[link.end_patch][link.end_vert] = pt;
|
||||
tmpb[poff + i] += pt;
|
||||
} else if(levels[link.end_patch] > current_level) {
|
||||
bcopy[i] = link;
|
||||
}
|
||||
}
|
||||
|
||||
map<unsigned int, map<unsigned short, Point3f> >::iterator k;
|
||||
for(k = bnorm.begin(); k != bnorm.end(); k++) {
|
||||
unsigned int patch = (*k).first;
|
||||
Border &border = nexus.GetBorder(patch);
|
||||
Border &rborder = nexus.GetBorder(patch);
|
||||
unsigned int offset = tmpb_start[patch];
|
||||
for(unsigned int i = 0; i < border.Size(); i++) {
|
||||
Link &link = border[i];
|
||||
for(unsigned int i = 0; i < rborder.Size(); i++) {
|
||||
Link &link = rborder[i];
|
||||
//assert(!link.IsNull());
|
||||
//TODO not accurate
|
||||
if(link.end_patch != p) continue;
|
||||
|
@ -137,6 +144,24 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
|||
}
|
||||
}
|
||||
|
||||
//Uncomment this only when links are ok!
|
||||
map<unsigned int, Link>::iterator j;
|
||||
for(j = bcopy.begin(); j != bcopy.end(); j++) {
|
||||
unsigned int b = (*j).first;
|
||||
Link link = (*j).second;
|
||||
Border &rborder = nexus.GetBorder(link.end_patch, false);
|
||||
unsigned int offset = tmpb_start[link.end_patch];
|
||||
for(unsigned int i = 0; i < rborder.Size(); i++) {
|
||||
Link &rlink = rborder[i];
|
||||
if(rlink.end_patch == p && rlink.start_vert == link.end_vert) {
|
||||
assert(rlink.end_vert == link.start_vert);
|
||||
tmpb[poff + b] = tmpb[offset + i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* set<unsigned int> close;
|
||||
for(unsigned int i = 0; i < border.Size(); i++) {
|
||||
Link &link = border[i];
|
||||
|
@ -163,7 +188,7 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
|||
tmpb.write(off + i, p);
|
||||
// tmpb[off + i] += normals[link.end_vert];
|
||||
}
|
||||
}*/
|
||||
}*/
|
||||
}
|
||||
|
||||
//Second step unify normals across borders
|
||||
|
@ -180,6 +205,7 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
|||
unsigned int off = tmpb_start[p];
|
||||
// Point3f &n = tmpb[off + i];
|
||||
Point3f n = tmpb[off + i];
|
||||
if(n == Point3f(0.0f,0.0f,0.0f)) continue;
|
||||
n.Normalize();
|
||||
if(use_short) {
|
||||
n *= 32766;
|
||||
|
|
|
@ -336,6 +336,11 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
//TODO set rambuffer low (or even direct access!)
|
||||
|
||||
//Fixing history
|
||||
unsigned int h_size;
|
||||
char *buffer = nexus.history.Save(h_size);
|
||||
out.history.Load(h_size, buffer);
|
||||
|
||||
Report report(nexus.size());
|
||||
cout << "Copying and allocating...\n";
|
||||
for(unsigned int patch = 0; patch < nexus.size(); patch++) {
|
||||
|
@ -442,12 +447,6 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
out.sphere = nexus.sphere;
|
||||
|
||||
//Fixing history
|
||||
unsigned int h_size;
|
||||
char *buffer = nexus.history.Save(h_size);
|
||||
out.history.Load(h_size, buffer);
|
||||
// out.history = nexus.history;
|
||||
|
||||
out.Close();
|
||||
nexus.Close();
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue