Working version.
This commit is contained in:
parent
5d7de0f69c
commit
fde19dc655
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.4 2004/09/30 00:27:08 ponchio
|
||||
Added used counter.
|
||||
|
||||
Revision 1.3 2004/07/05 17:02:17 ponchio
|
||||
Couple of const missing.
|
||||
|
||||
|
@ -70,6 +73,7 @@ class Border {
|
|||
Border(Link *l = NULL, unsigned short _used = 0, unsigned short _size = 0):
|
||||
start(l), used(_used), size(_size) {}
|
||||
unsigned int Size() { return used; }
|
||||
//TODO rename available to capacity.
|
||||
unsigned int Available() { return size; }
|
||||
Link &operator[](unsigned int i) { return start[i]; }
|
||||
Link *Start() { return start; }
|
||||
|
|
|
@ -6,6 +6,7 @@ using namespace nxs;
|
|||
|
||||
bool File::Create(const string &filename) {
|
||||
size = 0;
|
||||
readonly = false;
|
||||
#ifdef WIN32
|
||||
fp = CreateFile(filename.c_str(), GENERIC_READ | GENERIC_WRITE, 0,
|
||||
NULL, CREATE_ALWAYS, 0, NULL);
|
||||
|
@ -17,13 +18,17 @@ bool File::Create(const string &filename) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool File::Load(const string &filename) {
|
||||
bool File::Load(const string &filename, bool ronly) {
|
||||
readonly = ronly;
|
||||
#ifdef WIN32
|
||||
fp = CreateFile(filename.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if(fp == INVALID_HANDLE_VALUE) return false;
|
||||
#else
|
||||
fp = fopen(filename.c_str(), "rb+");
|
||||
if(readonly)
|
||||
fp = fopen(filename.c_str(), "rb");
|
||||
else
|
||||
fp = fopen(filename.c_str(), "rb+");
|
||||
if(!fp) return false;
|
||||
#endif
|
||||
|
||||
|
@ -48,8 +53,9 @@ void File::Close() {
|
|||
}
|
||||
}
|
||||
|
||||
void File::Resize(unsigned int elem) {
|
||||
void File::Redim(unsigned int elem) {
|
||||
assert(fp);
|
||||
assert(!readonly);
|
||||
if(elem > size) {
|
||||
|
||||
#ifdef WIN32
|
||||
|
@ -101,6 +107,7 @@ void File::ReadBuffer(void *data, unsigned int sz) {
|
|||
}
|
||||
|
||||
void File::WriteBuffer(void *data, unsigned int sz) {
|
||||
assert(!readonly);
|
||||
#ifdef WIN32
|
||||
DWORD tmp;
|
||||
WriteFile(fp, data, sz, &tmp, NULL);
|
||||
|
|
|
@ -21,15 +21,18 @@ class File {
|
|||
~File() { Close(); }
|
||||
|
||||
bool Create(const std::string &filename);
|
||||
bool Load(const std::string &filename);
|
||||
bool Load(const std::string &filename, bool readonly = false);
|
||||
void Close();
|
||||
|
||||
void Resize(unsigned int elem);
|
||||
unsigned int Length() { return size; }
|
||||
void Redim(unsigned int elem);
|
||||
|
||||
void SetPosition(unsigned int chunk);
|
||||
void ReadBuffer(void *data, unsigned int size);
|
||||
void WriteBuffer(void *data, unsigned int size);
|
||||
|
||||
bool IsReadOnly() { return readonly; }
|
||||
|
||||
protected:
|
||||
|
||||
#ifdef WIN32
|
||||
|
@ -38,6 +41,7 @@ class File {
|
|||
FILE *fp;
|
||||
#endif
|
||||
unsigned int size;
|
||||
bool readonly;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -25,11 +25,13 @@ bool Nexus::Create(const string &file, Signature sig) {
|
|||
|
||||
index.clear();
|
||||
|
||||
//Important: chunk_size must be 1 so that i can use Region in VFile.
|
||||
if(!patches.Create(file + ".nxp", 1)) {
|
||||
chunk_size = 1024;
|
||||
|
||||
if(!patches.Create(file + ".nxp", signature, chunk_size)) {
|
||||
cerr << "Could not create file: " << file << ".nxp" << endl;
|
||||
return false;
|
||||
}
|
||||
//Important: chunk_size must be 1 so that i can use Region in VFile.
|
||||
if(!borders.Create(file + ".nxb", 1)) {
|
||||
cerr << "Could not create file: " << file << ".nxb" << endl;
|
||||
return false;
|
||||
|
@ -38,7 +40,7 @@ bool Nexus::Create(const string &file, Signature sig) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Nexus::Load(const string &file) {
|
||||
bool Nexus::Load(const string &file, bool readonly) {
|
||||
index_file = fopen((file + ".nxs").c_str(), "rb+");
|
||||
if(!index_file) return false;
|
||||
|
||||
|
@ -51,14 +53,18 @@ bool Nexus::Load(const string &file) {
|
|||
if(!readed) return false;
|
||||
readed = fread(&sphere, sizeof(Sphere3f), 1, index_file);
|
||||
if(!readed) return false;
|
||||
readed = fread(&chunk_size, sizeof(unsigned int), 1, index_file);
|
||||
if(!readed) return false;
|
||||
|
||||
unsigned int size; //size of index
|
||||
readed = fread(&size, sizeof(unsigned int), 1, index_file);
|
||||
if(!readed) return false;
|
||||
|
||||
index.resize(size);
|
||||
readed = fread(&index[0], sizeof(Entry), size, index_file);
|
||||
readed = fread(&index[0], sizeof(PatchInfo), size, index_file);
|
||||
if(readed != size) return false;
|
||||
patches.ReadEntries(index_file);
|
||||
borders.ReadEntries(index_file);
|
||||
|
||||
//history size;
|
||||
fread(&size, sizeof(unsigned int), 1, index_file);
|
||||
|
@ -82,12 +88,15 @@ bool Nexus::Load(const string &file) {
|
|||
history[i].created[e] = buffer[pos++];
|
||||
}
|
||||
|
||||
if(!patches.Load(file + ".nxp", 1)) return false;
|
||||
//TODO support readonly
|
||||
if(!patches.Load(file + ".nxp", signature, chunk_size, readonly))
|
||||
return false;
|
||||
if(!borders.Load(file + ".nxb", 1)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Nexus::Close() {
|
||||
cerr << "Closing!" << endl;
|
||||
if(!index_file) return;
|
||||
rewind(index_file);
|
||||
|
||||
|
@ -95,10 +104,14 @@ void Nexus::Close() {
|
|||
fwrite(&totvert, sizeof(unsigned int), 1, index_file);
|
||||
fwrite(&totface, sizeof(unsigned int), 1, index_file);
|
||||
fwrite(&sphere, sizeof(Sphere3f), 1, index_file);
|
||||
fwrite(&chunk_size, sizeof(unsigned int), 1, index_file);
|
||||
|
||||
unsigned int size = index.size(); //size of index
|
||||
fwrite(&size, sizeof(unsigned int), 1, index_file);
|
||||
fwrite(&(index[0]), sizeof(Entry), size, index_file);
|
||||
fwrite(&(index[0]), sizeof(PatchInfo), size, index_file);
|
||||
|
||||
patches.WriteEntries(index_file);
|
||||
borders.WriteEntries(index_file);
|
||||
|
||||
vector<unsigned int> buffer;
|
||||
buffer.push_back(history.size());
|
||||
|
@ -124,39 +137,35 @@ void Nexus::Close() {
|
|||
borders.Close();
|
||||
}
|
||||
|
||||
Patch Nexus::GetPatch(unsigned int patch, bool flush) {
|
||||
Entry &entry = index[patch];
|
||||
Chunk *start = patches.GetRegion(entry.patch_start, entry.patch_used,flush);
|
||||
return Patch(signature, start, entry.nvert, entry.nface);
|
||||
Patch &Nexus::GetPatch(unsigned int patch, bool flush) {
|
||||
assert(patch < index.size());
|
||||
PatchInfo &info = index[patch];
|
||||
return patches.GetPatch(patch, info.nvert, info.nface, flush);
|
||||
}
|
||||
|
||||
Border Nexus::GetBorder(unsigned int patch, bool flush) {
|
||||
Entry &entry = index[patch];
|
||||
Link *start = borders.GetRegion(entry.border_start, entry.border_size,flush);
|
||||
return Border(start, entry.border_used, entry.border_size);
|
||||
PatchInfo &info = index[patch];
|
||||
return borders.GetBorder(patch);
|
||||
}
|
||||
|
||||
|
||||
unsigned int Nexus::AddPatch(unsigned int nvert, unsigned int nface,
|
||||
unsigned int nbord) {
|
||||
Entry entry;
|
||||
entry.patch_start = patches.Size();
|
||||
entry.patch_size = Patch::ChunkSize(signature, nvert, nface);
|
||||
entry.patch_used = entry.patch_size;
|
||||
entry.border_start = borders.Size();
|
||||
entry.border_size = nbord;
|
||||
entry.border_used = 0;
|
||||
entry.nvert = nvert;
|
||||
entry.nface = nface;
|
||||
|
||||
patches.Resize(patches.Size() + entry.patch_size);
|
||||
borders.Resize(borders.Size() + nbord);
|
||||
index.push_back(entry);
|
||||
PatchInfo info;
|
||||
info.nvert = nvert;
|
||||
info.nface = nface;
|
||||
|
||||
patches.AddPatch(nvert, nface);
|
||||
borders.AddBorder(nbord);
|
||||
|
||||
index.push_back(info);
|
||||
totvert += nvert;
|
||||
totface += nface;
|
||||
return index.size() -1;
|
||||
}
|
||||
|
||||
|
||||
void Nexus::Join(const std::set<unsigned int> &patches,
|
||||
std::vector<Point3f> &newvert,
|
||||
std::vector<unsigned int> &newface,
|
||||
|
@ -172,7 +181,7 @@ void Nexus::Join(const std::set<unsigned int> &patches,
|
|||
set<unsigned int>::const_iterator i;
|
||||
for(i = patches.begin(); i != patches.end(); i++) {
|
||||
unsigned int patch = *i;
|
||||
Nexus::Entry &entry = index[patch];
|
||||
PatchInfo &entry = index[patch];
|
||||
remap[*i].resize(entry.nvert, 0xffffffff);
|
||||
}
|
||||
|
||||
|
@ -183,7 +192,7 @@ void Nexus::Join(const std::set<unsigned int> &patches,
|
|||
unsigned int patch = *i;
|
||||
vector<unsigned int> &vmap = remap[*i];
|
||||
|
||||
Nexus::Entry &entry = index[patch];
|
||||
PatchInfo &entry = index[patch];
|
||||
fcount += entry.nface;
|
||||
for(unsigned int k = 0; k < entry.nvert; k++) {
|
||||
if(vmap[k] == 0xffffffff) { //first time
|
||||
|
@ -231,7 +240,7 @@ void Nexus::Join(const std::set<unsigned int> &patches,
|
|||
newvert[vmap[i]] = patch.Vert(i);
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < patch.nf; i++) {
|
||||
/* for(unsigned int i = 0; i < patch.nf; i++) {
|
||||
unsigned short *face = patch.Face(i);
|
||||
if(patch.Vert(face[0]) == patch.Vert(face[1]) ||
|
||||
patch.Vert(face[0]) == patch.Vert(face[2]) ||
|
||||
|
@ -251,7 +260,7 @@ void Nexus::Join(const std::set<unsigned int> &patches,
|
|||
cerr << patch.Face(i)[0] << " " << patch.Face(i)[1]
|
||||
<< patch.Face(i)[2] << endl;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
for(unsigned int i = 0; i < patch.nf; i++)
|
||||
for(int k = 0; k < 3; k++)
|
||||
newface[fcount++] = vmap[patch.Face(i)[k]];
|
||||
|
@ -273,7 +282,7 @@ void Nexus::Unify(float threshold) {
|
|||
unsigned int degenerate = 0;
|
||||
|
||||
for(unsigned int p = 0; p < index.size(); p++) {
|
||||
Nexus::Entry &entry = index[p];
|
||||
PatchInfo &entry = index[p];
|
||||
Patch patch = GetPatch(p);
|
||||
|
||||
unsigned int vcount = 0;
|
||||
|
@ -348,6 +357,7 @@ void Nexus::Unify(float threshold) {
|
|||
}
|
||||
}
|
||||
}
|
||||
//TODO: better to compact directly borders than setting them null.
|
||||
//finally: there may be duplicated borders
|
||||
for(unsigned int p = 0; p < index.size(); p++) {
|
||||
Border border = GetBorder(p);
|
||||
|
|
|
@ -5,39 +5,42 @@
|
|||
#include <vector>
|
||||
#include <set>
|
||||
#include <vcg/space/point3.h>
|
||||
#include <vcg/space/sphere3.h>
|
||||
#include "vfile.h"
|
||||
#include "patch.h"
|
||||
#include "border.h"
|
||||
|
||||
#include "patchserver.h"
|
||||
#include "borderserver.h"
|
||||
|
||||
namespace nxs {
|
||||
|
||||
|
||||
struct PatchInfo {
|
||||
unsigned short nvert;
|
||||
unsigned short nface;
|
||||
|
||||
vcg::Sphere3f sphere;
|
||||
float error;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Nexus {
|
||||
public:
|
||||
|
||||
struct Entry {
|
||||
Entry(): patch_start(0xffffffff), border_start(0xffffffff),
|
||||
patch_size(0), border_size(0), border_used(0),
|
||||
nvert(0), nface(0), sphere(vcg::Sphere3f()) {}
|
||||
|
||||
unsigned int patch_start; //granularita' Chunk
|
||||
struct BorderEntry {
|
||||
unsigned int border_start; //granuralita' Link
|
||||
unsigned short patch_size; //in chunks
|
||||
unsigned short patch_used; // in chunks (if compressed is < patch_size)
|
||||
unsigned short border_size; //in Links
|
||||
unsigned short border_used; //in Links
|
||||
|
||||
//Data used for extraction
|
||||
unsigned short nvert;
|
||||
unsigned short nface;
|
||||
vcg::Sphere3f sphere;
|
||||
float error;
|
||||
unsigned short ram;
|
||||
unsigned short agp;
|
||||
};
|
||||
|
||||
struct PatchInfo {
|
||||
unsigned short nvert;
|
||||
unsigned short nface;
|
||||
|
||||
vcg::Sphere3f sphere;
|
||||
float error;
|
||||
};
|
||||
|
||||
|
||||
//TODO optimize to be vector with offset.
|
||||
struct Update {
|
||||
std::vector<unsigned int> erased;
|
||||
std::vector<unsigned int> created;
|
||||
|
@ -46,46 +49,50 @@ class Nexus {
|
|||
|
||||
Nexus();
|
||||
virtual ~Nexus();
|
||||
|
||||
bool Create(const std::string &filename, Signature signature);
|
||||
virtual bool Load(const std::string &filename);
|
||||
virtual bool Load(const std::string &filename, bool readonly = false);
|
||||
virtual void Close();
|
||||
|
||||
Patch GetPatch(unsigned int patch, bool flush = true);
|
||||
unsigned int AddPatch(unsigned int nv, unsigned int nf, unsigned int nb);
|
||||
Patch &GetPatch(unsigned int patch, bool flush = true);
|
||||
Border GetBorder(unsigned int patch, bool flush = true);
|
||||
|
||||
bool IsCompressed() { return signature & NXS_COMPRESSED; }
|
||||
bool IsCompressed() { return signature & NXS_COMPRESSED; }
|
||||
bool HasStrips() { return signature & NXS_STRIP; }
|
||||
bool HasColors() { return signature & NXS_COLORS; }
|
||||
bool HasNormalsShort() { return signature & NXS_NORMALS_SHORT; }
|
||||
bool HasNormalsFloat() { return signature & NXS_NORMALS_FLOAT; }
|
||||
|
||||
//MOVE to nexus_build.cpp
|
||||
|
||||
unsigned int AddPatch(unsigned int nvert, unsigned int nface,
|
||||
unsigned int nbord);
|
||||
|
||||
// unsigned int Join(std::vector<unsigned int> &patches);
|
||||
void Join(const std::set<unsigned int> &patches,
|
||||
std::vector<vcg::Point3f> &vert,
|
||||
std::vector<unsigned int> &faces,
|
||||
std::vector<Link> &links);
|
||||
|
||||
//move to nxsalgo!
|
||||
void Unify(float threshold = 0.0f);
|
||||
|
||||
//TODO implement theese
|
||||
void CompactBorder(unsigned int patch);
|
||||
void CompactBorders();
|
||||
void CompactPatches();
|
||||
|
||||
/* Nexus data */
|
||||
|
||||
//BE CAREFUL: this 2 members get replicated into patchserver
|
||||
Signature signature;
|
||||
unsigned int chunk_size;
|
||||
|
||||
unsigned int totvert;
|
||||
unsigned int totface;
|
||||
vcg::Sphere3f sphere;
|
||||
|
||||
std::vector<Entry> index;
|
||||
std::vector<PatchInfo> index;
|
||||
|
||||
VFile<Chunk> patches;
|
||||
VFile<Link> borders;
|
||||
PatchServer patches;
|
||||
BorderServer borders;
|
||||
|
||||
std::vector<Update> history;
|
||||
|
||||
bool readonly;
|
||||
|
||||
private:
|
||||
FILE *index_file;
|
||||
};
|
||||
|
|
|
@ -18,7 +18,7 @@ void Policy::Visit(Node *node, std::queue<Node *> &qnode) {
|
|||
qnode.push(node);
|
||||
}
|
||||
|
||||
bool FrustumPolicy::Expand(unsigned int patch, Nexus::Entry &entry) {
|
||||
bool FrustumPolicy::Expand(unsigned int patch, Nexus::PatchInfo &entry) {
|
||||
if(entry.error == 0) return false;
|
||||
float dist = Distance(entry.sphere, frustum.ViewPoint());
|
||||
/*Point3f line = frustum.viewPoint() - cell->sphere.center;
|
||||
|
@ -33,17 +33,13 @@ bool FrustumPolicy::Expand(unsigned int patch, Nexus::Entry &entry) {
|
|||
}
|
||||
|
||||
|
||||
NexusMt::NexusMt(): vbo(VBO_AUTO), vbo_size(0), ram_size(128000000),
|
||||
NexusMt::NexusMt(): vbo(VBO_AUTO), vbo_size(0),
|
||||
policy(NULL), error(4), realtime(true),
|
||||
mode(SMOOTH) {
|
||||
policy = new FrustumPolicy();
|
||||
}
|
||||
|
||||
NexusMt::~NexusMt() {
|
||||
for(unsigned int i = 0; i < ram_buffer.size(); i++)
|
||||
if(ram_buffer[i].patch)
|
||||
delete ram_buffer[i].patch;
|
||||
}
|
||||
NexusMt::~NexusMt() {}
|
||||
|
||||
bool NexusMt::Load(const string &filename) {
|
||||
if(!Nexus::Load(filename)) return false;
|
||||
|
@ -59,9 +55,6 @@ bool NexusMt::Load(const string &filename) {
|
|||
SetComponent(TEXTURE, true);
|
||||
SetComponent(DATA, true);
|
||||
|
||||
frame = 0;
|
||||
ram_used = 0;
|
||||
ram_buffer.resize(index.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -94,13 +87,15 @@ void NexusMt::Render() {
|
|||
|
||||
for(unsigned int i = 0; i < cells.size(); i++) {
|
||||
unsigned int cell = cells[i];
|
||||
Nexus::Entry &entry = index[cell];
|
||||
Nexus::PatchInfo &entry = index[cell];
|
||||
|
||||
//frustum culling
|
||||
if(frustum.IsOutside(entry.sphere.Center(), entry.sphere.Radius()))
|
||||
continue;
|
||||
|
||||
Patch &patch = LoadPatch(cell);
|
||||
Patch &patch = GetPatch(cell);
|
||||
|
||||
assert(patch.start);
|
||||
|
||||
glVertexPointer(3, GL_FLOAT, 0, patch.VertBegin());
|
||||
if(use_colors)
|
||||
|
@ -154,7 +149,7 @@ void NexusMt::SetVbo(Vbo _vbo, unsigned int _vbo_size,
|
|||
if(!GLEW_ARB_vertex_buffer_object)
|
||||
vbo = VBO_OFF;
|
||||
vbo_size = _vbo_size;
|
||||
ram_size = _ram_size;
|
||||
patches.ram_size = _ram_size/chunk_size;
|
||||
}
|
||||
|
||||
bool NexusMt::SetMode(Mode _mode) {
|
||||
|
@ -344,27 +339,3 @@ void NexusMt::Select(vector<unsigned int> &selected) {
|
|||
}
|
||||
}
|
||||
|
||||
Patch &NexusMt::LoadPatch(unsigned int p) {
|
||||
Sgurz &sgurz = ram_buffer[p];
|
||||
if(sgurz.patch) {
|
||||
sgurz.last_frame = frame;
|
||||
return *(sgurz.patch);
|
||||
}
|
||||
|
||||
Entry &entry = index[p];
|
||||
Chunk *start = new Chunk[entry.patch_size];
|
||||
ram_used += entry.patch_size * sizeof(Chunk);
|
||||
patches.SetPosition(entry.patch_start * sizeof(Chunk));
|
||||
patches.ReadBuffer(start, entry.patch_used * sizeof(Chunk));
|
||||
Patch *patch = new Patch(signature, start, entry.nvert, entry.nface);
|
||||
sgurz.patch = patch;
|
||||
|
||||
if(ram_used > ram_size * 1.5)
|
||||
FlushRam();
|
||||
|
||||
return *(sgurz.patch);
|
||||
}
|
||||
|
||||
void NexusMt::FlushRam() {
|
||||
//use drame info and error to prune
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace nxs {
|
|||
|
||||
class Policy {
|
||||
public:
|
||||
virtual bool Expand(unsigned int patch, Nexus::Entry &entry) = 0;
|
||||
virtual bool Expand(unsigned int patch, Nexus::PatchInfo &entry) = 0;
|
||||
virtual void GetView() {}
|
||||
virtual void Visit(Node *node, std::queue<Node *> &qnode);
|
||||
};
|
||||
|
@ -35,7 +35,7 @@ namespace nxs {
|
|||
|
||||
FrustumPolicy(float _err = 4): error(_err) {}
|
||||
void GetView() { frustum.GetView(); }
|
||||
bool Expand(unsigned int patch, Nexus::Entry &entry);
|
||||
bool Expand(unsigned int patch, Nexus::PatchInfo &entry);
|
||||
};
|
||||
|
||||
class NexusMt: public Nexus {
|
||||
|
@ -67,7 +67,6 @@ class NexusMt: public Nexus {
|
|||
|
||||
Vbo vbo;
|
||||
unsigned int vbo_size;
|
||||
unsigned int ram_size;
|
||||
|
||||
Policy *policy;
|
||||
float error;
|
||||
|
@ -104,22 +103,6 @@ class NexusMt: public Nexus {
|
|||
void ClearHistory();
|
||||
void Select(std::vector<unsigned int> &selected);
|
||||
Patch &LoadPatch(unsigned int p);
|
||||
void FlushRam();
|
||||
|
||||
unsigned int frame;
|
||||
unsigned int ram_used;
|
||||
|
||||
struct Sgurz {
|
||||
Sgurz(Patch *_patch = NULL, unsigned int _vbo = 0,
|
||||
unsigned int _vio = 0, unsigned int _last_frame = 0):
|
||||
patch(_patch), vbo(_vbo), vio(_vio), last_frame(_last_frame) {}
|
||||
Patch *patch;
|
||||
unsigned int vbo; //vertex buffer
|
||||
unsigned int vio; //index buffer
|
||||
unsigned int last_frame;
|
||||
};
|
||||
|
||||
std::vector<Sgurz> ram_buffer;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <vector>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
|
||||
#include <wrap/strip/tristrip.h>
|
||||
|
||||
|
@ -24,7 +25,7 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
|||
|
||||
//first step normals in the same patch.
|
||||
for(unsigned int p = 0; p < nexus.index.size(); p++) {
|
||||
Patch patch = nexus.GetPatch(p);
|
||||
Patch &patch = nexus.GetPatch(p);
|
||||
|
||||
vector<Point3f> normals;
|
||||
normals.resize(patch.nv, Point3f(0, 0, 0));
|
||||
|
@ -76,7 +77,7 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
|||
for(unsigned int p = 0; p < nexus.index.size(); p++) {
|
||||
//notice now ew allow flushing of old patches
|
||||
|
||||
Patch patch = nexus.GetPatch(p);
|
||||
Patch &patch = nexus.GetPatch(p);
|
||||
Border border = nexus.GetBorder(p);
|
||||
|
||||
//first pass we collect all normals
|
||||
|
@ -95,7 +96,7 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
|||
}
|
||||
|
||||
//no flushing now!
|
||||
Patch remote = nexus.GetPatch(link.end_patch, false);
|
||||
Patch &remote = nexus.GetPatch(link.end_patch, false);
|
||||
assert(link.end_vert < remote.nv);
|
||||
|
||||
if(use_short) {
|
||||
|
@ -110,7 +111,7 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
|||
Link &link = border[i];
|
||||
if(link.IsNull()) continue;
|
||||
|
||||
Patch remote = nexus.GetPatch(link.end_patch, false);
|
||||
Patch &remote = nexus.GetPatch(link.end_patch, false);
|
||||
Point3f &n = normals[link.start_vert];
|
||||
n.Normalize();
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "nxsbuild.h"
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
|
||||
using namespace nxs;
|
||||
using namespace vcg;
|
||||
|
@ -34,27 +35,23 @@ void nxs::NexusAllocate(Crude &crude,
|
|||
|
||||
nexus.index.resize(patch_faces.size());
|
||||
|
||||
unsigned int totchunks = 0;
|
||||
// unsigned int totchunks = 0;
|
||||
//now that we know various sizes, lets allocate space
|
||||
for(unsigned int i = 0; i < nexus.index.size(); i++) {
|
||||
Nexus::Entry &entry = nexus.index[i];
|
||||
Nexus::PatchInfo &entry = nexus.index[i];
|
||||
|
||||
if(patch_faces[i] == 0 || patch_verts[i] == 0)
|
||||
cerr << "Warning! Empty patch.\n";
|
||||
|
||||
entry.patch_start = totchunks;
|
||||
entry.patch_size = Patch::ChunkSize(nexus.signature,
|
||||
patch_verts[i], patch_faces[i]);
|
||||
entry.patch_used = entry.patch_size;
|
||||
totchunks += entry.patch_size;
|
||||
entry.border_start = 0xffffffff;
|
||||
nexus.patches.AddPatch(patch_verts[i], patch_faces[i]);
|
||||
|
||||
entry.nvert = patch_verts[i];
|
||||
entry.nface = 0;
|
||||
entry.nface = patch_faces[i];
|
||||
entry.error = 0;
|
||||
}
|
||||
|
||||
nexus.patches.Resize(totchunks);
|
||||
|
||||
patch_faces.clear();
|
||||
patch_faces.resize(nexus.index.size(), 0);
|
||||
|
||||
//now we sort the faces into the patches (but still using absolute indexing
|
||||
//instead of relative indexing
|
||||
|
@ -62,8 +59,8 @@ void nxs::NexusAllocate(Crude &crude,
|
|||
Crude::Face &face = crude.face[i];
|
||||
unsigned int npatch = face_remap[i];
|
||||
|
||||
Nexus::Entry &entry = nexus.index[npatch];
|
||||
|
||||
Nexus::PatchInfo &entry = nexus.index[npatch];
|
||||
// cerr << "Entrynf: " << entry.nface << endl;
|
||||
//TODO this is slow because we have to initialize patch.
|
||||
//just get patch.start.
|
||||
Patch patch = nexus.GetPatch(npatch);
|
||||
|
@ -75,8 +72,11 @@ void nxs::NexusAllocate(Crude &crude,
|
|||
cerr << "Found degenerate.\n";
|
||||
continue;
|
||||
}
|
||||
faces[entry.nface] = face;
|
||||
entry.nface++;
|
||||
faces[patch_faces[npatch]++] = face;
|
||||
}
|
||||
for(unsigned int i = 0; i < nexus.index.size(); i++) {
|
||||
Nexus::PatchInfo &entry = nexus.index[i];
|
||||
entry.nface = patch_faces[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,12 +89,12 @@ void nxs::NexusFill(Crude &crude,
|
|||
//finally for every patch we collect the vertices
|
||||
//and fill the patch.
|
||||
//we need to remember start and size in border_remap;
|
||||
// vector<unsigned int> border_start;
|
||||
// vector<unsigned int> border_size;
|
||||
|
||||
for(unsigned int i = 0; i < nexus.index.size(); i++) {
|
||||
Patch patch = nexus.GetPatch(i);
|
||||
Nexus::Entry &entry = nexus.index[i];
|
||||
Nexus::PatchInfo &entry = nexus.index[i];
|
||||
// cerr << "entryf: " << entry.nface << endl;
|
||||
// cerr << "nf: " << patch.nf << endl;
|
||||
|
||||
//make a copy of faces (we need to write there :P)
|
||||
Crude::Face *faces = new Crude::Face[patch.nf];
|
||||
|
@ -107,6 +107,7 @@ void nxs::NexusFill(Crude &crude,
|
|||
unsigned int count = 0;
|
||||
map<unsigned int, unsigned short> remap;
|
||||
|
||||
assert(patch.nf != 0);
|
||||
for(unsigned int k = 0; k < patch.nf; k++) {
|
||||
Crude::Face &face = faces[k];
|
||||
for(int j = 0; j < 3; j++) {
|
||||
|
@ -123,7 +124,7 @@ void nxs::NexusFill(Crude &crude,
|
|||
assert(entry.nvert == remap.size());
|
||||
|
||||
//record start of border:
|
||||
entry.border_start = border_remap.Size();
|
||||
unsigned int border_start = border_remap.Size();
|
||||
|
||||
//TODO hash_set?
|
||||
set<unsigned int> border_patches;
|
||||
|
@ -144,8 +145,8 @@ void nxs::NexusFill(Crude &crude,
|
|||
border_remap.PushBack(link);
|
||||
}
|
||||
}
|
||||
//and number of borders:
|
||||
entry.border_used = border_remap.Size() - entry.border_start;
|
||||
unsigned int needed = border_remap.Size() - border_start;
|
||||
nexus.borders.AddBorder(2 * needed, needed);
|
||||
delete []faces;
|
||||
}
|
||||
|
||||
|
@ -153,45 +154,21 @@ void nxs::NexusFill(Crude &crude,
|
|||
for(unsigned int i = 0; i < nexus.index.size(); i++)
|
||||
nexus.sphere.Add(nexus.index[i].sphere);
|
||||
|
||||
//test no duplicated faces:
|
||||
/* for(unsigned int i = 0; i < nexus.index.size(); i++) {
|
||||
Patch patch = nexus.GetPatch(i);
|
||||
for(unsigned int k = 0; k < patch.nf; k++) {
|
||||
assert(patch.Face(k)[0] != patch.Face(k)[1]);
|
||||
assert(patch.Face(k)[0] != patch.Face(k)[2]);
|
||||
assert(patch.Face(k)[1] != patch.Face(k)[2]);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void nxs::NexusFixBorder(Nexus &nexus,
|
||||
VFile<RemapLink> &border_remap) {
|
||||
|
||||
//and last convert RemapLinks into Links
|
||||
nexus.borders.Resize(border_remap.Size() * 2);
|
||||
//* 2 is to accomodate future borders
|
||||
|
||||
for(unsigned int i = 0; i < nexus.index.size(); i++) {
|
||||
Nexus::Entry &local = nexus.index[i];
|
||||
local.border_start *= 2;
|
||||
local.border_size = local.border_used * 2;
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < nexus.index.size(); i++) {
|
||||
Nexus::Entry &local = nexus.index[i];
|
||||
|
||||
unsigned int remap_start = local.border_start/2;
|
||||
for(unsigned int i = 0; i < nexus.borders.borders.size(); i++) {
|
||||
BorderEntry &local = nexus.borders.borders[i];
|
||||
//* 2 is to accomodate future borders
|
||||
|
||||
unsigned int remap_start = local.border_start/2;
|
||||
|
||||
// K is the main iterator (where we write to in nexus.borders)
|
||||
for(unsigned int k = 0; k < local.border_used; k++) {
|
||||
|
||||
|
||||
RemapLink start_link = border_remap[k + remap_start];
|
||||
assert(start_link.rel_vert < local.nvert);
|
||||
|
||||
Nexus::Entry &remote = nexus.index[start_link.patch];
|
||||
BorderEntry &remote = nexus.borders.borders[start_link.patch];
|
||||
|
||||
bool found = false;
|
||||
|
||||
|
@ -210,8 +187,6 @@ void nxs::NexusFixBorder(Nexus &nexus,
|
|||
found = true;
|
||||
}
|
||||
}
|
||||
// assert(nexus.borders[k + local.border_start].start_vert < local.nvert);
|
||||
// assert(found);
|
||||
}
|
||||
}
|
||||
nexus.borders.Flush();
|
||||
|
@ -219,21 +194,20 @@ void nxs::NexusFixBorder(Nexus &nexus,
|
|||
//Checking border consistency:
|
||||
/* for(unsigned int i = 0; i < nexus.index.size(); i++) {
|
||||
Border border = nexus.GetBorder(i);
|
||||
Nexus::Entry &entry = nexus.index[i];
|
||||
Nexus::PatchInfo &entry = nexus.index[i];
|
||||
for(unsigned int k = 0; k < border.Size(); k++) {
|
||||
Link &link = border[k];
|
||||
if(link.start_vert >= entry.nvert) {
|
||||
cerr << "K: " << k << endl;
|
||||
cerr << "patch: " << i << " nvert: " << entry.nvert << " startv: "
|
||||
<< link.start_vert << endl;
|
||||
cerr << "bstart: " << entry.border_start
|
||||
<< "bsize: " << entry.border_size << endl;
|
||||
// cerr << "bstart: " << entry.border_start
|
||||
// << "bsize: " << entry.border_size << endl;
|
||||
}
|
||||
assert(link.end_patch < nexus.index.size());
|
||||
assert(link.start_vert < entry.nvert);
|
||||
Nexus::Entry &remote = nexus.index[link.end_patch];
|
||||
Nexus::PatchInfo &remote = nexus.index[link.end_patch];
|
||||
assert(link.end_vert < remote.nvert);
|
||||
}
|
||||
|
||||
}*/
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue