Optimizations...

This commit is contained in:
Federico Ponchio 2004-12-04 15:48:57 +00:00
parent e96b8ca53b
commit c68ebbc920
2 changed files with 45 additions and 33 deletions

View File

@ -1,5 +1,6 @@
#include <vector>
#include <map>
#include <hash_map>
#include <iostream>
//#include <wrap/strip/tristrip.h>
@ -19,6 +20,11 @@ void nxs::ComputeNormals(Nexus &nexus) {
assert(nexus.signature & NXS_NORMALS_SHORT ||
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;
//TODO use a temporary file to store border normals
@ -46,11 +52,13 @@ void nxs::ComputeNormals(Nexus &nexus) {
//first step normals in the same patch.
cerr << "First Step\n";
Report report(nexus.index.size(), 5);
vector<Point3f> normals;
for(unsigned int p = 0; p < nexus.index.size(); p++) {
report.Step(p);
Patch &patch = nexus.GetPatch(p);
vector<Point3f> normals;
normals.clear();
normals.resize(patch.nv, Point3f(0, 0, 0));
@ -103,12 +111,14 @@ void nxs::ComputeNormals(Nexus &nexus) {
map<unsigned int, map<unsigned short, Point3f> > bnorm;
unsigned int poff = tmpb_start[p];
for(unsigned int i = 0; i < border.Size(); i++) {
Link &link = border[i];
if(link.IsNull()) continue;
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;
tmpb[poff + i] += pt;
}
map<unsigned int, map<unsigned short, Point3f> >::iterator k;
@ -118,10 +128,11 @@ void nxs::ComputeNormals(Nexus &nexus) {
unsigned int offset = tmpb_start[patch];
for(unsigned int i = 0; i < border.Size(); i++) {
Link &link = border[i];
assert(!link.IsNull());
//assert(!link.IsNull());
//TODO not accurate
if(link.end_patch != p) continue;
if((*k).second.count(link.start_vert))
tmpb[offset + i] = (*k).second[link.start_vert];
tmpb[offset + i] += (*k).second[link.start_vert];
}
}
@ -184,6 +195,7 @@ void nxs::ComputeNormals(Nexus &nexus) {
tmpb.Close();
tmpb.Delete();
//TODO remove temporary file.
nexus.borders.SetReadOnly(false);
}
/*void nxs::ComputeTriStrip(unsigned short nfaces, unsigned short *faces,

View File

@ -389,11 +389,11 @@ int main(int argc, char *argv[]) {
dst_entry.error = src_entry.error;
//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];
if(link.IsNull()) continue;
assert(link.end_patch < nexus.index.size());
}
}*/
Border dst_border = out.GetBorder(patch);
out.borders.ResizeBorder(patch, src_border.Size());
memcpy(dst_border.Start(), src_border.Start(),