Optimizations...
This commit is contained in:
parent
e96b8ca53b
commit
c68ebbc920
|
@ -1,5 +1,6 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <hash_map>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
//#include <wrap/strip/tristrip.h>
|
//#include <wrap/strip/tristrip.h>
|
||||||
|
@ -18,6 +19,11 @@ using namespace triangle_stripper;
|
||||||
void nxs::ComputeNormals(Nexus &nexus) {
|
void nxs::ComputeNormals(Nexus &nexus) {
|
||||||
assert(nexus.signature & NXS_NORMALS_SHORT ||
|
assert(nexus.signature & NXS_NORMALS_SHORT ||
|
||||||
nexus.signature & NXS_NORMALS_FLOAT);
|
nexus.signature & NXS_NORMALS_FLOAT);
|
||||||
|
|
||||||
|
//setting borders readonly:
|
||||||
|
|
||||||
|
assert(!nexus.borders.IsReadonly());
|
||||||
|
nexus.borders.SetReadOnly(true);
|
||||||
|
|
||||||
bool use_short = (nexus.signature & NXS_NORMALS_SHORT) != 0;
|
bool use_short = (nexus.signature & NXS_NORMALS_SHORT) != 0;
|
||||||
|
|
||||||
|
@ -46,50 +52,52 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
||||||
//first step normals in the same patch.
|
//first step normals in the same patch.
|
||||||
cerr << "First Step\n";
|
cerr << "First Step\n";
|
||||||
Report report(nexus.index.size(), 5);
|
Report report(nexus.index.size(), 5);
|
||||||
|
vector<Point3f> normals;
|
||||||
|
|
||||||
for(unsigned int p = 0; p < nexus.index.size(); p++) {
|
for(unsigned int p = 0; p < nexus.index.size(); p++) {
|
||||||
report.Step(p);
|
report.Step(p);
|
||||||
Patch &patch = nexus.GetPatch(p);
|
Patch &patch = nexus.GetPatch(p);
|
||||||
|
|
||||||
vector<Point3f> normals;
|
normals.clear();
|
||||||
normals.resize(patch.nv, Point3f(0, 0, 0));
|
normals.resize(patch.nv, Point3f(0, 0, 0));
|
||||||
|
|
||||||
|
|
||||||
if(nexus.signature & NXS_FACES)
|
if(nexus.signature & NXS_FACES)
|
||||||
for(unsigned int i = 0; i < patch.nf; i++) {
|
for(unsigned int i = 0; i < patch.nf; i++) {
|
||||||
unsigned short *f = patch.Face(i);
|
unsigned short *f = patch.Face(i);
|
||||||
Point3f &v0 = patch.Vert(f[0]);
|
Point3f &v0 = patch.Vert(f[0]);
|
||||||
Point3f &v1 = patch.Vert(f[1]);
|
Point3f &v1 = patch.Vert(f[1]);
|
||||||
Point3f &v2 = patch.Vert(f[2]);
|
Point3f &v2 = patch.Vert(f[2]);
|
||||||
|
|
||||||
Point3f norm = (v1 - v0) ^ (v2 - v0);
|
Point3f norm = (v1 - v0) ^ (v2 - v0);
|
||||||
normals[f[0]] += norm;
|
normals[f[0]] += norm;
|
||||||
normals[f[1]] += norm;
|
normals[f[1]] += norm;
|
||||||
normals[f[2]] += norm;
|
normals[f[2]] += norm;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(nexus.signature & NXS_STRIP)
|
if(nexus.signature & NXS_STRIP)
|
||||||
for(int i = 0; i < patch.nf - 2; i++) {
|
for(int i = 0; i < patch.nf - 2; i++) {
|
||||||
unsigned short *f = patch.FaceBegin() + i;
|
unsigned short *f = patch.FaceBegin() + i;
|
||||||
Point3f &v0 = patch.Vert(f[0]);
|
Point3f &v0 = patch.Vert(f[0]);
|
||||||
Point3f &v1 = patch.Vert(f[1]);
|
Point3f &v1 = patch.Vert(f[1]);
|
||||||
Point3f &v2 = patch.Vert(f[2]);
|
Point3f &v2 = patch.Vert(f[2]);
|
||||||
|
|
||||||
Point3f norm = (v1 - v0) ^ (v2 - v0);
|
Point3f norm = (v1 - v0) ^ (v2 - v0);
|
||||||
if(i%2) norm = -norm;
|
if(i%2) norm = -norm;
|
||||||
normals[f[0]] += norm;
|
normals[f[0]] += norm;
|
||||||
normals[f[1]] += norm;
|
normals[f[1]] += norm;
|
||||||
normals[f[2]] += norm;
|
normals[f[2]] += norm;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(use_short) {
|
if(use_short) {
|
||||||
for(unsigned int i = 0; i < patch.nv; i++) {
|
for(unsigned int i = 0; i < patch.nv; i++) {
|
||||||
Point3f &norm = normals[i];
|
Point3f &norm = normals[i];
|
||||||
norm.Normalize();
|
norm.Normalize();
|
||||||
short *n = patch.Norm16(i);
|
short *n = patch.Norm16(i);
|
||||||
for(int k = 0; k < 3; k++) {
|
for(int k = 0; k < 3; k++) {
|
||||||
n[k] = (short)(norm[k] * 32766);
|
n[k] = (short)(norm[k] * 32766);
|
||||||
}
|
}
|
||||||
n[3] = 0;
|
n[3] = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
memcpy(patch.Norm16Begin(), &*normals.begin(),
|
memcpy(patch.Norm16Begin(), &*normals.begin(),
|
||||||
|
@ -103,12 +111,14 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
||||||
map<unsigned int, map<unsigned short, Point3f> > bnorm;
|
map<unsigned int, map<unsigned short, Point3f> > bnorm;
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int poff = tmpb_start[p];
|
||||||
for(unsigned int i = 0; i < border.Size(); i++) {
|
for(unsigned int i = 0; i < border.Size(); i++) {
|
||||||
Link &link = border[i];
|
Link &link = border[i];
|
||||||
if(link.IsNull()) continue;
|
if(link.IsNull()) continue;
|
||||||
Point3f pt = normals[link.start_vert];
|
Point3f pt = normals[link.start_vert];
|
||||||
bnorm[p][link.start_vert] = pt;
|
//bnorm[p][link.start_vert] = pt;
|
||||||
bnorm[link.end_patch][link.end_vert] = pt;
|
bnorm[link.end_patch][link.end_vert] = pt;
|
||||||
|
tmpb[poff + i] += pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
map<unsigned int, map<unsigned short, Point3f> >::iterator k;
|
map<unsigned int, map<unsigned short, Point3f> >::iterator k;
|
||||||
|
@ -117,11 +127,12 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
||||||
Border border = nexus.GetBorder(patch);
|
Border border = nexus.GetBorder(patch);
|
||||||
unsigned int offset = tmpb_start[patch];
|
unsigned int offset = tmpb_start[patch];
|
||||||
for(unsigned int i = 0; i < border.Size(); i++) {
|
for(unsigned int i = 0; i < border.Size(); i++) {
|
||||||
Link &link = border[i];
|
Link &link = border[i];
|
||||||
assert(!link.IsNull());
|
//assert(!link.IsNull());
|
||||||
//TODO not accurate
|
//TODO not accurate
|
||||||
if((*k).second.count(link.start_vert))
|
if(link.end_patch != p) continue;
|
||||||
tmpb[offset + i] = (*k).second[link.start_vert];
|
if((*k).second.count(link.start_vert))
|
||||||
|
tmpb[offset + i] += (*k).second[link.start_vert];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,6 +195,7 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
||||||
tmpb.Close();
|
tmpb.Close();
|
||||||
tmpb.Delete();
|
tmpb.Delete();
|
||||||
//TODO remove temporary file.
|
//TODO remove temporary file.
|
||||||
|
nexus.borders.SetReadOnly(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*void nxs::ComputeTriStrip(unsigned short nfaces, unsigned short *faces,
|
/*void nxs::ComputeTriStrip(unsigned short nfaces, unsigned short *faces,
|
||||||
|
|
|
@ -389,11 +389,11 @@ int main(int argc, char *argv[]) {
|
||||||
dst_entry.error = src_entry.error;
|
dst_entry.error = src_entry.error;
|
||||||
|
|
||||||
//adding borders.
|
//adding borders.
|
||||||
for(unsigned int i = 0; i < src_border.Size(); i++) {
|
/*for(unsigned int i = 0; i < src_border.Size(); i++) {
|
||||||
Link &link = src_border[i];
|
Link &link = src_border[i];
|
||||||
if(link.IsNull()) continue;
|
if(link.IsNull()) continue;
|
||||||
assert(link.end_patch < nexus.index.size());
|
assert(link.end_patch < nexus.index.size());
|
||||||
}
|
}*/
|
||||||
Border dst_border = out.GetBorder(patch);
|
Border dst_border = out.GetBorder(patch);
|
||||||
out.borders.ResizeBorder(patch, src_border.Size());
|
out.borders.ResizeBorder(patch, src_border.Size());
|
||||||
memcpy(dst_border.Start(), src_border.Start(),
|
memcpy(dst_border.Start(), src_border.Start(),
|
||||||
|
|
Loading…
Reference in New Issue