Patch generalized and small fixes.
This commit is contained in:
parent
cce86d42f8
commit
9ce3dba5f7
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.28 2005/02/08 12:43:03 ponchio
|
||||
Added copyright
|
||||
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -42,13 +45,13 @@ Nexus::~Nexus() {
|
|||
Close();
|
||||
}
|
||||
|
||||
bool Nexus::Create(const string &file, Signature sig, unsigned int c_size) {
|
||||
bool Nexus::Create(const string &file, Signature &sig, unsigned int c_size) {
|
||||
signature = sig;
|
||||
totvert = 0;
|
||||
totface = 0;
|
||||
sphere = Sphere3f();
|
||||
chunk_size = c_size;
|
||||
unsigned int header_size = 256;
|
||||
unsigned int header_size = 256; //a bit more than 64 needed
|
||||
if(chunk_size > header_size) header_size = chunk_size;
|
||||
|
||||
history.Clear();
|
||||
|
@ -119,7 +122,10 @@ void Nexus::Close() {
|
|||
void Nexus::SaveHeader() {
|
||||
unsigned int magic = 0x3053584e; // nxs0
|
||||
WriteBuffer(&magic, sizeof(unsigned int));
|
||||
WriteBuffer(&signature, sizeof(unsigned int));
|
||||
unsigned int version = 1;
|
||||
WriteBuffer(&version, sizeof(unsigned int));
|
||||
|
||||
WriteBuffer(&signature, sizeof(Signature));
|
||||
WriteBuffer(&chunk_size, sizeof(unsigned int));
|
||||
WriteBuffer(&offset, sizeof(int64));
|
||||
WriteBuffer(&history_offset, sizeof(int64));
|
||||
|
@ -135,7 +141,14 @@ bool Nexus::LoadHeader() {
|
|||
cerr << "Invalid magic. Not a nxs file\n";
|
||||
return false;
|
||||
}
|
||||
ReadBuffer(&signature, sizeof(unsigned int));
|
||||
//Current version is 1
|
||||
unsigned int version;
|
||||
ReadBuffer(&version, sizeof(unsigned int));
|
||||
if(version != NXS_CURRENT_VERSION) {
|
||||
cerr << "Old version. Sorry.\n";
|
||||
return false;
|
||||
}
|
||||
ReadBuffer(&signature, sizeof(Signature));
|
||||
ReadBuffer(&chunk_size, sizeof(unsigned int));
|
||||
ReadBuffer(&offset, sizeof(int64));
|
||||
ReadBuffer(&history_offset, sizeof(int64));
|
||||
|
@ -238,7 +251,7 @@ Patch *Nexus::LoadPatch(unsigned int idx) {
|
|||
|
||||
MFile::SetPosition((int64)entry.patch_start * (int64)chunk_size);
|
||||
|
||||
if((signature & NXS_COMPRESSED) == 0) { //not compressed
|
||||
if(signature.compr == 0) { //not compressed
|
||||
MFile::ReadBuffer(ram, entry.disk_size * chunk_size);
|
||||
} else {
|
||||
unsigned char *disk = new unsigned char[entry.disk_size * chunk_size];
|
||||
|
@ -248,6 +261,9 @@ Patch *Nexus::LoadPatch(unsigned int idx) {
|
|||
disk, entry.disk_size * chunk_size);
|
||||
delete []disk;
|
||||
}
|
||||
} else {
|
||||
//zero all bytes... so compressio gets better with padding.
|
||||
memset(ram, 0, entry.ram_size * chunk_size);
|
||||
}
|
||||
ram_used += entry.ram_size;
|
||||
entry.patch = patch;
|
||||
|
@ -259,7 +275,7 @@ void Nexus::FlushPatch(unsigned int id) {
|
|||
assert(entry.patch);
|
||||
|
||||
if(!MFile::IsReadOnly()) { //write back patch
|
||||
if((signature & NXS_COMPRESSED)) {
|
||||
if(signature.compr) {
|
||||
unsigned int compressed_size;
|
||||
char *compressed = entry.patch->Compress(entry.ram_size * chunk_size,
|
||||
compressed_size);
|
||||
|
@ -282,11 +298,11 @@ void Nexus::FlushPatch(unsigned int id) {
|
|||
Redim(Length() + entry.disk_size * chunk_size);
|
||||
}
|
||||
MFile::SetPosition((int64)entry.patch_start * (int64)chunk_size);
|
||||
MFile::WriteBuffer(entry.patch->start, entry.disk_size * chunk_size);
|
||||
MFile::WriteBuffer(entry.patch->fstart, entry.disk_size * chunk_size);
|
||||
}
|
||||
}
|
||||
|
||||
delete [](entry.patch->start);
|
||||
delete [](entry.patch->fstart);
|
||||
delete entry.patch;
|
||||
entry.patch = NULL;
|
||||
ram_used -= entry.ram_size;
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.20 2005/02/08 12:43:03 ponchio
|
||||
Added copyright
|
||||
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -77,6 +80,8 @@ struct Entry {
|
|||
|
||||
class Nexus: public IndexFile<Entry> {
|
||||
public:
|
||||
enum Version { NXS_CURRENT_VERSION = 1 };
|
||||
|
||||
//HEader data:
|
||||
Signature signature;
|
||||
unsigned int chunk_size;
|
||||
|
@ -95,7 +100,7 @@ class Nexus: public IndexFile<Entry> {
|
|||
Nexus() {}
|
||||
~Nexus();
|
||||
|
||||
bool Create(const std::string &filename, Signature signature,
|
||||
bool Create(const std::string &filename, Signature &signature,
|
||||
unsigned int chunk_size = 1024);
|
||||
bool Load(const std::string &filename, bool readonly = false);
|
||||
void Close();
|
||||
|
@ -111,11 +116,11 @@ class Nexus: public IndexFile<Entry> {
|
|||
//move to nxsalgo!
|
||||
void Unify(float threshold = 0.0f);
|
||||
|
||||
bool IsCompressed() { return (signature & NXS_COMPRESSED) != 0; }
|
||||
bool HasStrips() { return (signature & NXS_STRIP) != 0; }
|
||||
bool HasColors() { return (signature & NXS_COLORS) != 0; }
|
||||
bool HasNormalsShort() { return (signature & NXS_NORMALS_SHORT) != 0; }
|
||||
bool HasNormalsFloat() { return (signature & NXS_NORMALS_FLOAT) != 0; }
|
||||
bool IsCompressed() { return signature.compr != 0; }
|
||||
bool HasStrips() { return signature.face == Signature::STRIPS; }
|
||||
bool HasColors() { return signature.vcolor != 0; }
|
||||
bool HasNormals() { return signature.vnorm != 0; }
|
||||
bool HasTextures() { return signature.vtext != 0; }
|
||||
|
||||
unsigned int ram_max;
|
||||
unsigned int ram_used;
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.30 2005/02/17 15:39:44 ponchio
|
||||
Reorderes statistics a bit.
|
||||
|
||||
Revision 1.29 2005/02/14 17:11:07 ponchio
|
||||
aggiunta delle sphere
|
||||
|
||||
|
@ -143,9 +146,9 @@ void NexusMt::Render(Extraction &extraction, DrawContest &contest,
|
|||
preload.post(extraction.selected);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
if((signature & NXS_COLORS) && (contest.attrs & DrawContest::COLOR))
|
||||
if(signature.vcolor && (contest.attrs & DrawContest::COLOR))
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
if((signature & NXS_NORMALS_SHORT) && (contest.attrs & DrawContest::NORMAL))
|
||||
if(signature.vnorm && (contest.attrs & DrawContest::NORMAL))
|
||||
glEnableClientState(GL_NORMAL_ARRAY);
|
||||
|
||||
vector<Item> skipped;
|
||||
|
@ -155,12 +158,12 @@ void NexusMt::Render(Extraction &extraction, DrawContest &contest,
|
|||
Entry &entry = operator[](patch);
|
||||
vcg::Sphere3f &sphere = entry.sphere;
|
||||
|
||||
if(stats) stats->extr += entry.nface;
|
||||
if(stats) stats->extr += 2*entry.nvert;
|
||||
|
||||
if(extraction.frustum.IsOutside(sphere.Center(), sphere.Radius()))
|
||||
continue;
|
||||
|
||||
if(stats) stats->tri += entry.nface;
|
||||
if(stats) stats->tri += 2*entry.nvert;
|
||||
|
||||
if(!entry.patch) {
|
||||
skipped.push_back(extraction.selected[i]);
|
||||
|
@ -229,20 +232,28 @@ void NexusMt::Draw(unsigned int cell, DrawContest &contest) {
|
|||
|
||||
fstart = NULL;
|
||||
vstart = NULL;
|
||||
cstart = (char *)(sizeof(float) * patch.cstart);
|
||||
nstart = (char *)(sizeof(float) * patch.nstart);
|
||||
cstart = (char *)(64 * patch.vstartc);
|
||||
nstart = (char *)(64 * patch.vstartn);
|
||||
} else {
|
||||
fstart = (char *)patch.FaceBegin();
|
||||
vstart = (char *)patch.VertBegin();
|
||||
cstart = (char *)patch.ColorBegin();
|
||||
nstart = (char *)patch.Norm16Begin();
|
||||
vstart = (char *)patch.Vert3fBegin();
|
||||
cstart = (char *)patch.VColorBegin();
|
||||
nstart = (char *)patch.VNormBegin();
|
||||
}
|
||||
assert(signature.vert == Signature::POINT3F);
|
||||
glVertexPointer(3, GL_FLOAT, 0, vstart);
|
||||
|
||||
|
||||
if(signature.vcolor && contest.attrs & DrawContest::COLOR) {
|
||||
assert(signature.vcolor == Encodings::BYTE4);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, 0, cstart);
|
||||
}
|
||||
|
||||
glVertexPointer(3, GL_FLOAT, 0, vstart);
|
||||
if(contest.attrs & DrawContest::COLOR)
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, 0, cstart);
|
||||
if(contest.attrs & DrawContest::NORMAL)
|
||||
|
||||
if(signature.vnorm && contest.attrs & DrawContest::NORMAL) {
|
||||
assert(signature.vnorm == Encodings::SHORT4);
|
||||
glNormalPointer(GL_SHORT, 8, nstart);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -252,26 +263,25 @@ void NexusMt::Draw(unsigned int cell, DrawContest &contest) {
|
|||
case DrawContest::PATCHES:
|
||||
glColor3ub((cell * 27)%225 + 30, (cell * 37)%225 + 30, (cell * 87)%225 + 30);
|
||||
case DrawContest::SMOOTH:
|
||||
if(signature & NXS_FACES)
|
||||
if(signature.face == Signature::TRIANGLES)
|
||||
glDrawElements(GL_TRIANGLES, patch.nf * 3,
|
||||
GL_UNSIGNED_SHORT, fstart);
|
||||
else if(signature & NXS_STRIP)
|
||||
else if(signature.face == Signature::STRIPS)
|
||||
glDrawElements(GL_TRIANGLE_STRIP, patch.nf,
|
||||
GL_UNSIGNED_SHORT, fstart);
|
||||
break;
|
||||
case DrawContest::FLAT:
|
||||
if(use_vbo) {
|
||||
cerr << "Mode incompatible with VBO\n";
|
||||
exit(0);
|
||||
}
|
||||
if(signature & NXS_FACES) {
|
||||
cerr << "Unsupported rendering mode sorry\n";
|
||||
} else {
|
||||
if(signature.face == Signature::TRIANGLES) {
|
||||
glBegin(GL_TRIANGLES);
|
||||
unsigned short *f = patch.Face(0);
|
||||
for(int i = 0; i < patch.nf; i++) {
|
||||
|
||||
Point3f &p0 = patch.Vert(f[0]);
|
||||
Point3f &p1 = patch.Vert(f[1]);
|
||||
Point3f &p2 = patch.Vert(f[2]);
|
||||
Point3f &p0 = patch.Vert3f(f[0]);
|
||||
Point3f &p1 = patch.Vert3f(f[1]);
|
||||
Point3f &p2 = patch.Vert3f(f[2]);
|
||||
Point3f n = ((p1 - p0) ^ (p2 - p0));
|
||||
glNormal3f(n[0], n[1], n[2]);
|
||||
glVertex3f(p0[0], p0[1], p0[2]);
|
||||
|
@ -280,9 +290,9 @@ void NexusMt::Draw(unsigned int cell, DrawContest &contest) {
|
|||
f += 3;
|
||||
}
|
||||
glEnd();
|
||||
} else if(signature & NXS_STRIP) {
|
||||
} else if(signature.face = Signature::STRIPS) {
|
||||
cerr << "Unsupported rendering mode sorry\n";
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -340,8 +350,8 @@ void NexusMt::FlushPatch(unsigned int id) {
|
|||
if(entry.vbo_element)
|
||||
FlushVbo(entry);
|
||||
|
||||
if(entry.patch->start)
|
||||
delete [](entry.patch->start);
|
||||
if(entry.patch->fstart)
|
||||
delete [](entry.patch->fstart);
|
||||
delete entry.patch;
|
||||
entry.patch = NULL;
|
||||
ram_used -= entry.ram_size;
|
||||
|
@ -353,7 +363,10 @@ void NexusMt::LoadVbo(Entry &entry) {
|
|||
|
||||
Patch &patch = *entry.patch;
|
||||
unsigned int size = patch.nf * sizeof(unsigned short);
|
||||
if((signature & NXS_FACES) != 0) size *= 3;
|
||||
if(signature.face == Signature::TRIANGLES)
|
||||
size *= 3;
|
||||
else if(signature.face != Signature::STRIPS)
|
||||
assert(0);
|
||||
|
||||
glGenBuffersARB(1, &entry.vbo_element);
|
||||
assert(entry.vbo_element);
|
||||
|
@ -363,17 +376,17 @@ void NexusMt::LoadVbo(Entry &entry) {
|
|||
vbo_used += size;
|
||||
|
||||
//TODO fix this when we allow data :p
|
||||
size = sizeof(float) * patch.dstart;
|
||||
size = 64 * patch.vstartd;
|
||||
|
||||
glGenBuffersARB(1, &entry.vbo_array);
|
||||
assert(entry.vbo_array);
|
||||
glBindBufferARB(GL_ARRAY_BUFFER_ARB, entry.vbo_array);
|
||||
glBufferDataARB(GL_ARRAY_BUFFER_ARB, size, patch.VertBegin(),
|
||||
glBufferDataARB(GL_ARRAY_BUFFER_ARB, size, patch.Vert3fBegin(),
|
||||
GL_STATIC_DRAW_ARB);
|
||||
|
||||
vbo_used += size;
|
||||
delete [](entry.patch->start);
|
||||
entry.patch->start = NULL;
|
||||
delete [](entry.patch->fstart);
|
||||
entry.patch->fstart = NULL;
|
||||
}
|
||||
|
||||
void NexusMt::FlushVbo(Entry &entry) {
|
||||
|
@ -385,7 +398,7 @@ void NexusMt::FlushVbo(Entry &entry) {
|
|||
|
||||
Patch &patch = *entry.patch;
|
||||
vbo_used -= patch.nf * sizeof(unsigned short);
|
||||
vbo_used -= sizeof(float) * patch.dstart;
|
||||
vbo_used -= sizeof(float) * patch.vstartd;
|
||||
}
|
||||
|
||||
//Kept for historical reasons.
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.19 2005/02/18 13:04:12 ponchio
|
||||
Added patch reordering.
|
||||
|
||||
Revision 1.18 2005/02/17 16:40:35 ponchio
|
||||
Optimized BuildLevels.
|
||||
|
||||
|
@ -55,16 +58,13 @@ using namespace vcg;
|
|||
using namespace triangle_stripper;
|
||||
|
||||
void nxs::ComputeNormals(Nexus &nexus) {
|
||||
assert(nexus.signature & NXS_NORMALS_SHORT ||
|
||||
nexus.signature & NXS_NORMALS_FLOAT);
|
||||
assert(nexus.signature.vnorm);
|
||||
|
||||
//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
|
||||
unsigned int tmpb_offset = 0;
|
||||
vector<unsigned int> tmpb_start;
|
||||
|
@ -105,25 +105,24 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
|||
normals.clear();
|
||||
normals.resize(patch.nv, Point3f(0, 0, 0));
|
||||
|
||||
if(nexus.signature & NXS_FACES)
|
||||
if(nexus.signature.face == Signature::TRIANGLES)
|
||||
for(unsigned int i = 0; i < patch.nf; i++) {
|
||||
unsigned short *f = patch.Face(i);
|
||||
Point3f &v0 = patch.Vert(f[0]);
|
||||
Point3f &v1 = patch.Vert(f[1]);
|
||||
Point3f &v2 = patch.Vert(f[2]);
|
||||
Point3f &v0 = patch.Vert3f(f[0]);
|
||||
Point3f &v1 = patch.Vert3f(f[1]);
|
||||
Point3f &v2 = patch.Vert3f(f[2]);
|
||||
|
||||
Point3f norm = (v1 - v0) ^ (v2 - v0);
|
||||
normals[f[0]] += norm;
|
||||
normals[f[1]] += norm;
|
||||
normals[f[2]] += norm;
|
||||
}
|
||||
|
||||
if(nexus.signature & NXS_STRIP)
|
||||
if(nexus.signature.face == Signature::STRIPS)
|
||||
for(int i = 0; i < patch.nf - 2; i++) {
|
||||
unsigned short *f = patch.FaceBegin() + i;
|
||||
Point3f &v0 = patch.Vert(f[0]);
|
||||
Point3f &v1 = patch.Vert(f[1]);
|
||||
Point3f &v2 = patch.Vert(f[2]);
|
||||
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;
|
||||
|
@ -132,18 +131,17 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
|||
normals[f[2]] += norm;
|
||||
}
|
||||
|
||||
if(use_short) {
|
||||
for(unsigned int i = 0; i < patch.nv; i++) {
|
||||
if(nexus.signature.vnorm == Encodings::SHORT4) {
|
||||
short *n = (short *)patch.VNormBegin();
|
||||
for(unsigned int i = 0; i < patch.nv; i++, n += 4) {
|
||||
Point3f &norm = normals[i];
|
||||
norm.Normalize();
|
||||
short *n = patch.Norm16(i);
|
||||
for(int k = 0; k < 3; k++)
|
||||
n[k] = (short)(norm[k] * 32766);
|
||||
|
||||
n[3] = 0;
|
||||
}
|
||||
} else {
|
||||
memcpy(patch.Norm16Begin(), &*normals.begin(),
|
||||
} else if(nexus.signature.vnorm == Encodings::FLOAT3) {
|
||||
memcpy(patch.VNormBegin(), &*normals.begin(),
|
||||
normals.size() * sizeof(Point3f));
|
||||
}
|
||||
|
||||
|
@ -236,6 +234,9 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
|||
Patch &patch = nexus.GetPatch(p);
|
||||
Border &border = nexus.GetBorder(p);
|
||||
|
||||
Point3f *normf = (Point3f *)patch.VNormBegin();
|
||||
short *norms = (short *)patch.VNormBegin();
|
||||
|
||||
for(unsigned int i = 0; i < border.Size(); i++) {
|
||||
Link &link = border[i];
|
||||
if(link.IsNull()) continue;
|
||||
|
@ -244,15 +245,15 @@ void nxs::ComputeNormals(Nexus &nexus) {
|
|||
Point3f n = tmpb[off + i];
|
||||
if(n == Point3f(0.0f,0.0f,0.0f)) continue;
|
||||
n.Normalize();
|
||||
if(use_short) {
|
||||
if(nexus.signature.vnorm == Encodings::SHORT4) {
|
||||
n *= 32766;
|
||||
short *np = patch.Norm16(link.start_vert);
|
||||
short *np = norms + 4 * link.start_vert;
|
||||
np[0] = (short)n[0];
|
||||
np[1] = (short)n[1];
|
||||
np[2] = (short)n[2];
|
||||
np[3] = 0;
|
||||
} else {
|
||||
patch.Norm32(link.start_vert) = n;
|
||||
} else if(nexus.signature.vnorm == Encodings::FLOAT3) {
|
||||
normf[link.start_vert] = n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -315,13 +316,16 @@ void nxs::ComputeTriStrip(unsigned short nfaces, unsigned short *faces,
|
|||
}
|
||||
}
|
||||
|
||||
void nxs::Reorder(unsigned int signature, Patch &patch) {
|
||||
void nxs::Reorder(Signature &signature, Patch &patch) {
|
||||
vector<unsigned> remap;
|
||||
remap.resize(patch.nv, 0xffff);
|
||||
|
||||
int nf = patch.nf;
|
||||
if(signature & NXS_FACES)
|
||||
if(signature.face == Signature::TRIANGLES)
|
||||
nf *= 3;
|
||||
else if(signature.face != Signature::STRIPS) {
|
||||
assert(0); //mah...
|
||||
}
|
||||
|
||||
//building remap
|
||||
unsigned short *f = patch.FaceBegin();
|
||||
|
@ -343,9 +347,9 @@ void nxs::Reorder(unsigned int signature, Patch &patch) {
|
|||
|
||||
vector<Point3f> vert;
|
||||
vert.resize(patch.nv);
|
||||
memcpy(&*vert.begin(), patch.VertBegin(), patch.nv * sizeof(Point3f));
|
||||
memcpy(&*vert.begin(), patch.Vert3fBegin(), patch.nv * sizeof(Point3f));
|
||||
for(int i = 0; i < patch.nv; i++)
|
||||
patch.Vert(remap[i]) = vert[i];
|
||||
patch.Vert3f(remap[i]) = vert[i];
|
||||
}
|
||||
|
||||
//TODO actually use threshold
|
||||
|
@ -365,7 +369,7 @@ void nxs::Unify(Nexus &nexus, float threshold) {
|
|||
remap.resize(patch.nv);
|
||||
|
||||
for(unsigned int i = 0; i < patch.nv; i++) {
|
||||
Point3f &point = patch.Vert(i);
|
||||
Point3f &point = patch.Vert3f(i);
|
||||
|
||||
if(!vertices.count(point))
|
||||
vertices[point] = vcount++;
|
||||
|
@ -406,7 +410,7 @@ void nxs::Unify(Nexus &nexus, float threshold) {
|
|||
entry.nface = newface.size()/3;
|
||||
patch.Init(nexus.signature, entry.nvert, entry.nface);
|
||||
|
||||
memcpy(patch.VertBegin(), &(newvert[0]), entry.nvert*sizeof(Point3f));
|
||||
memcpy(patch.Vert3fBegin(), &(newvert[0]), entry.nvert*sizeof(Point3f));
|
||||
memcpy(patch.FaceBegin(), &(newface[0]), entry.nface*3*sizeof(short));
|
||||
|
||||
//testiamo il tutto... TODO remove this of course
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.5 2005/02/18 13:04:13 ponchio
|
||||
Added patch reordering.
|
||||
|
||||
Revision 1.4 2005/02/08 12:43:03 ponchio
|
||||
Added copyright
|
||||
|
||||
|
@ -34,6 +37,7 @@ Added copyright
|
|||
#define NXS_ALGO_H
|
||||
|
||||
#include <vector>
|
||||
#include "patch.h"
|
||||
|
||||
namespace nxs {
|
||||
|
||||
|
@ -49,7 +53,7 @@ namespace nxs {
|
|||
void ComputeNormals(Nexus &nexus);
|
||||
void ComputeTriStrip(unsigned short nfaces, unsigned short *faces,
|
||||
std::vector<unsigned short> &strip);
|
||||
void Reorder(unsigned int signature, nxs::Patch &patch);
|
||||
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.15 2005/02/14 15:17:36 ponchio
|
||||
Cleaning up.
|
||||
|
||||
Revision 1.14 2005/01/21 17:09:13 ponchio
|
||||
Porting and debug.
|
||||
|
||||
|
@ -289,7 +292,8 @@ void ThirdStep(const string &crudefile, const string &output,
|
|||
Nexus nexus;
|
||||
//TODO here i really need no ram_buffer.....
|
||||
nexus.MaxRam() = 0;
|
||||
if(!nexus.Create(output, NXS_FACES, chunk_size)) {
|
||||
Signature signature; //default triangles and vertices3f
|
||||
if(!nexus.Create(output, signature, chunk_size)) {
|
||||
cerr << "Could not create nexus output: " << output << endl;
|
||||
getchar();
|
||||
exit(0);
|
||||
|
@ -342,7 +346,7 @@ void ThirdStep(const string &crudefile, const string &output,
|
|||
0); //no borders!
|
||||
Patch &patch = nexus.GetPatch(patch_idx);
|
||||
memcpy(patch.FaceBegin(), &*faces.begin(), fcount * sizeof(short));
|
||||
memcpy(patch.VertBegin(), &*vertices.begin(), vcount * sizeof(Point3f));
|
||||
memcpy(patch.Vert3fBegin(), &*vertices.begin(), vcount * sizeof(Point3f));
|
||||
|
||||
Sphere3f &sphere = nexus[patch_idx].sphere;
|
||||
for(int i = 0; i < vertices.size(); i++)
|
||||
|
@ -355,7 +359,6 @@ void ThirdStep(const string &crudefile, const string &output,
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
//saving vert_remap
|
||||
int64 vroffset = vert_remap.Size();
|
||||
vert_index.push_back(BlockEntry(vroffset, vcount));
|
||||
|
@ -727,15 +730,15 @@ void BuildFragment(Nexus &nexus, VPartition &part,
|
|||
Border &border = nexus.GetBorder(*f);
|
||||
|
||||
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]);
|
||||
assert(patch.FaceBegin()[3*k + 0] != patch.FaceBegin()[3*k + 1]);
|
||||
assert(patch.FaceBegin()[3*k + 0] != patch.FaceBegin()[3*k + 2]);
|
||||
assert(patch.FaceBegin()[3*k + 1] != patch.FaceBegin()[3*k + 2]);
|
||||
}
|
||||
|
||||
|
||||
nxs.vert.resize(patch.nv);
|
||||
nxs.face.resize(patch.nf * 3);
|
||||
memcpy(&*nxs.vert.begin(), patch.VertBegin(), patch.nv * sizeof(Point3f));
|
||||
memcpy(&*nxs.vert.begin(), patch.Vert3fBegin(), patch.nv * sizeof(Point3f));
|
||||
memcpy(&*nxs.face.begin(), patch.FaceBegin(), patch.nf * 3*sizeof(short));
|
||||
for(unsigned int i = 0; i < border.Size(); i++) {
|
||||
Link &link = border[i];
|
||||
|
@ -815,7 +818,7 @@ void SaveFragment(Nexus &nexus, VChain &chain,
|
|||
Patch &patch = nexus.GetPatch(patch_idx);
|
||||
memcpy(patch.FaceBegin(), &outpatch.face[0],
|
||||
outpatch.face.size() * sizeof(unsigned short));
|
||||
memcpy(patch.VertBegin(), &outpatch.vert[0],
|
||||
memcpy(patch.Vert3fBegin(), &outpatch.vert[0],
|
||||
outpatch.vert.size() * sizeof(Point3f));
|
||||
|
||||
Entry &entry = nexus[patch_idx];
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.19 2005/02/18 13:04:13 ponchio
|
||||
Added patch reordering.
|
||||
|
||||
Revision 1.18 2005/02/08 12:43:03 ponchio
|
||||
Added copyright
|
||||
|
||||
|
@ -66,14 +69,14 @@ class CFace: public Face<CVertex, DUMMYEDGETYPE , CFace>{};
|
|||
|
||||
class CMesh: public tri::TriMesh<vector<CVertex>, vector<CFace> > {};
|
||||
|
||||
string getSuffix(unsigned int signature) {
|
||||
string getSuffix(Signature &signature) {
|
||||
string suff;
|
||||
if(signature&NXS_COMPRESSED) suff += "Z";
|
||||
if(signature&NXS_STRIP) suff += "S";
|
||||
if(signature&NXS_COLORS) suff += "C";
|
||||
if(signature&NXS_NORMALS_SHORT) suff += "N";
|
||||
if(signature&NXS_TEXTURES_SHORT) suff += "T";
|
||||
if(signature&NXS_DATA32) suff += "D";
|
||||
if(signature.compr) suff += "Z";
|
||||
if(signature.face == Signature::STRIPS) suff += "S";
|
||||
if(signature.vcolor) suff += "C";
|
||||
if(signature.vnorm) suff += "N";
|
||||
if(signature.vtext) suff += "T";
|
||||
if(signature.vdata) suff += "D";
|
||||
return suff;
|
||||
}
|
||||
|
||||
|
@ -87,15 +90,15 @@ int main(int argc, char *argv[]) {
|
|||
unsigned int ram_size = 128000000;
|
||||
unsigned int chunk_size = 0;
|
||||
|
||||
unsigned int add = 0;
|
||||
bool add_strip = false;
|
||||
bool add = false;
|
||||
bool add_strips = false;
|
||||
bool add_colors = false;
|
||||
bool add_normals = false;
|
||||
bool add_textures = false;
|
||||
bool add_data = false;
|
||||
|
||||
unsigned int remove = 0;
|
||||
bool remove_strip = false;
|
||||
bool remove = false;
|
||||
bool remove_strips = false;
|
||||
bool remove_colors = false;
|
||||
bool remove_normals = false;
|
||||
bool remove_textures = false;
|
||||
|
@ -116,60 +119,70 @@ int main(int argc, char *argv[]) {
|
|||
case 'l': verbose = true; break;
|
||||
case 'o': output = optarg; break;
|
||||
case 'a': {
|
||||
if(strstr(optarg, "strip")) {
|
||||
add_strip = true;
|
||||
add |= NXS_STRIP;
|
||||
remove |= NXS_FACES;
|
||||
if(strstr(optarg, "strips")) {
|
||||
add_strips = true;
|
||||
add = true;
|
||||
// add |= NXS_STRIP;
|
||||
// remove |= NXS_FACES;
|
||||
}
|
||||
if(strstr(optarg, "colors")) {
|
||||
add_colors = true;
|
||||
add |= NXS_COLORS;
|
||||
add = true;
|
||||
// add |= NXS_COLORS;
|
||||
}
|
||||
if(strstr(optarg, "normals")) {
|
||||
add_normals = true;
|
||||
add |= NXS_NORMALS_SHORT;
|
||||
add = true;
|
||||
// add |= NXS_NORMALS_SHORT;
|
||||
}
|
||||
if(strstr(optarg, "textures")) {
|
||||
add_textures = true;
|
||||
add |= NXS_TEXTURES_SHORT;
|
||||
add = true;
|
||||
// add |= NXS_TEXTURES_SHORT;
|
||||
}
|
||||
if(strstr(optarg, "data")) {
|
||||
add_data = true;
|
||||
add |= NXS_DATA32;
|
||||
// add |= NXS_DATA32;
|
||||
}
|
||||
if(add == 0) {
|
||||
if(add == false) {
|
||||
cerr << "Invalid -a argument: " << optarg << "\n"
|
||||
<< "Valid options are: strip, colors, normals, textures, data\n";
|
||||
<< "Valid options are: strips, colors, normals, textures, data\n";
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'r': {
|
||||
if(strstr(optarg, "strip")) {
|
||||
cerr << "Strip reming not supported!\n";
|
||||
if(strstr(optarg, "strips")) {
|
||||
cerr << "Strips removing not supported!\n";
|
||||
return -1;
|
||||
remove_strip = true;
|
||||
add |= NXS_FACES;
|
||||
remove |= NXS_STRIP;
|
||||
remove_strips = true;
|
||||
remove = true;
|
||||
add = true;
|
||||
// add |= NXS_FACES;
|
||||
// remove |= NXS_STRIP;
|
||||
}
|
||||
if(strstr(optarg, "colors")) {
|
||||
remove_colors = true;
|
||||
remove |= NXS_COLORS;
|
||||
remove = true;
|
||||
// remove |= NXS_COLORS;
|
||||
}
|
||||
if(strstr(optarg, "normals")) {
|
||||
remove_normals = true;
|
||||
remove |= NXS_NORMALS_SHORT;
|
||||
remove = true;
|
||||
// remove |= NXS_NORMALS_SHORT;
|
||||
}
|
||||
if(strstr(optarg, "textures")) {
|
||||
remove_textures = true;
|
||||
remove |= NXS_TEXTURES_SHORT;
|
||||
remove = true;
|
||||
// remove |= NXS_TEXTURES_SHORT;
|
||||
}
|
||||
if(strstr(optarg, "data")) {
|
||||
remove_data = true;
|
||||
remove |= NXS_DATA32;
|
||||
remove = true;
|
||||
// remove |= NXS_DATA32;
|
||||
}
|
||||
if(remove == 0) {
|
||||
if(remove == false) {
|
||||
cerr << "Invalid -a argument: " << optarg << "\n"
|
||||
<< "Valid options are: strip, colors, normals, textures, data\n";
|
||||
return -1;
|
||||
|
@ -233,7 +246,7 @@ int main(int argc, char *argv[]) {
|
|||
<< " -i : display some info about nexus file\n"
|
||||
<< " -l : list nodes\n"
|
||||
<< " -o <file>: output filename (default is adding 00 to nexus)\n"
|
||||
<< " -a <what>: Add [colors|normals|strip|textures|data|borders]\n"
|
||||
<< " -a <what>: Add [colors|normals|strips|textures|data|borders]\n"
|
||||
<< " -r <what>: As add...\n"
|
||||
<< " -p <ply> : Ply source for colors or textures or data\n"
|
||||
<< " -z : compress\n"
|
||||
|
@ -258,23 +271,23 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
|
||||
//Sanity tests
|
||||
if(remove_strip && !(nexus.signature & NXS_STRIP)) {
|
||||
if(remove_strips && !(nexus.signature.face != Signature::STRIPS)) {
|
||||
cerr << "Nexus file does not have strips\n";
|
||||
return -1;
|
||||
}
|
||||
if(remove_colors && !(nexus.signature & NXS_COLORS)) {
|
||||
if(remove_colors && !nexus.signature.vcolor) {
|
||||
cerr << "Nexus file does not have colors\n";
|
||||
return -1;
|
||||
}
|
||||
if(remove_normals && !(nexus.signature & NXS_NORMALS_SHORT)) {
|
||||
if(remove_normals && !nexus.signature.vnorm) {
|
||||
cerr << "Nexus file does not have normals\n";
|
||||
return -1;
|
||||
}
|
||||
if(remove_textures && !(nexus.signature & NXS_TEXTURES_SHORT)) {
|
||||
if(remove_textures && !nexus.signature.vtext) {
|
||||
cerr << "Nexus file does not have textures\n";
|
||||
return -1;
|
||||
}
|
||||
if(remove_data && !(nexus.signature & NXS_DATA32)) {
|
||||
if(remove_data && !nexus.signature.vdata) {
|
||||
cerr << "Nexus file does not have data\n";
|
||||
return -1;
|
||||
}
|
||||
|
@ -304,11 +317,12 @@ int main(int argc, char *argv[]) {
|
|||
meandist /= nexus.size() -1;
|
||||
cout << "Nexus file: " << input << "\n"
|
||||
<< "\n\tCompressed: " << nexus.IsCompressed()
|
||||
<< "\n\tStripped: " << (int)((nexus.signature&NXS_STRIP) !=0)
|
||||
<< "\n\tColor : " << (int)((nexus.signature&NXS_COLORS) !=0)
|
||||
<< "\n\tNormal : " << (int)((nexus.signature&NXS_NORMALS_SHORT) !=0)
|
||||
<< "\n\tTexture : " << (int)((nexus.signature&NXS_TEXTURES_SHORT) !=0)
|
||||
<< "\n\tData : " << (int)((nexus.signature&NXS_DATA32) !=0)
|
||||
<< "\n\tStripped: "
|
||||
<< (int)(nexus.signature.face == Signature::STRIPS)
|
||||
<< "\n\tColor : " << (int)(nexus.signature.vcolor !=0)
|
||||
<< "\n\tNormal : " << (int)((nexus.signature.vnorm) !=0)
|
||||
<< "\n\tTexture : " << (int)((nexus.signature.vtext) !=0)
|
||||
<< "\n\tData : " << (int)((nexus.signature.vdata) !=0)
|
||||
<< "\n\n\tVertices: " << nexus.totvert
|
||||
<< "\tFaces: " << nexus.totface
|
||||
<< "\tPatches: " << nexus.size()
|
||||
|
@ -332,7 +346,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
//determine if we must proceed:
|
||||
if(add == 0 && remove == 0 && !compress && !uncompress && !zsort &&
|
||||
if(!add && !remove && !compress && !uncompress && !zsort &&
|
||||
qvertex == 0 && qnormal == 0 && qcolor == 0 && qtexture == 0) {
|
||||
nexus.Close();
|
||||
return 0;
|
||||
|
@ -357,17 +371,29 @@ int main(int argc, char *argv[]) {
|
|||
grid.Set(mesh.face);
|
||||
}
|
||||
|
||||
if((add & NXS_NORMALS_SHORT) && compress) {
|
||||
cerr << "Its not possible to add normals and compress in the same step\n";
|
||||
if(add_normals && compress) {
|
||||
cerr << "Its not possible to add normals and compress in the same step\n"
|
||||
<< "Because normals requires 2 passes to be calculated\n\n";
|
||||
return -1;
|
||||
}
|
||||
unsigned int signature = nexus.signature;
|
||||
signature |= add;
|
||||
signature &= ~remove;
|
||||
if(compress) signature |= NXS_COMPRESSED;
|
||||
if(uncompress) signature &= ~NXS_COMPRESSED;
|
||||
|
||||
Signature signature = nexus.signature;
|
||||
if(add_strips) signature.face = Signature::STRIPS;
|
||||
if(add_normals) signature.vnorm = Encodings::SHORT4;
|
||||
if(add_colors) signature.vcolor = Encodings::BYTE4;
|
||||
|
||||
if(remove_normals) signature.vnorm = 0;
|
||||
if(remove_colors) signature.vcolor = 0;
|
||||
|
||||
if(compress) signature.compr = Signature::LZO;
|
||||
if(uncompress) signature.compr = 0;
|
||||
|
||||
if(!output.size()) output = input + getSuffix(signature);
|
||||
if(output == input) {
|
||||
cerr << "Output and input files are the same.\n"
|
||||
<< "You do not want to overwrite your data. Trust me.\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
cout << "Writing to nexus: " << output << endl;
|
||||
|
||||
|
@ -376,11 +402,12 @@ int main(int argc, char *argv[]) {
|
|||
if(!chunk_size)
|
||||
chunk_size = nexus.chunk_size;
|
||||
|
||||
if(!out.Create(output, (Signature)signature, chunk_size)) {
|
||||
if(!out.Create(output, signature, chunk_size)) {
|
||||
cerr << "Could not open output: " << output << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
//TODO fix this broken interface (you should not care abou chunk_size
|
||||
out.MaxRam() = ram_size / out.chunk_size;
|
||||
//TODO set rambuffer low (or even direct access!)
|
||||
|
||||
|
@ -424,10 +451,15 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
|
||||
vector<unsigned short> strip;
|
||||
if(add_strip) {
|
||||
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());
|
||||
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());
|
||||
|
||||
|
@ -436,58 +468,68 @@ int main(int argc, char *argv[]) {
|
|||
Patch &dst_patch = out.GetPatch(p);
|
||||
|
||||
//copy vertices:
|
||||
memcpy(dst_patch.VertBegin(), src_patch.VertBegin(),
|
||||
assert(out.signature.vert == Signature::POINT3F);
|
||||
assert(out.signature.vert = nexus.signature.vert);
|
||||
memcpy(dst_patch.Vert3fBegin(), src_patch.Vert3fBegin(),
|
||||
src_patch.nv * sizeof(Point3f));
|
||||
|
||||
if(qvertex && !add_normals) {
|
||||
float *ptr = (float *)dst_patch.VertBegin();
|
||||
for(int i = 0; i < dst_patch.nv*3; i++) {
|
||||
float *ptr = (float *)dst_patch.Vert3fBegin();
|
||||
for(int i = 0; i < dst_patch.nv*3; i++)
|
||||
ptr[i] = qvertex * (int)(ptr[i]/qvertex);
|
||||
//ptr[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//now faces.
|
||||
if(add_strip) {
|
||||
if(add_strips) {
|
||||
assert(out.signature.face == Signature::STRIPS);
|
||||
memcpy(dst_patch.FaceBegin(), &*strip.begin(),
|
||||
strip.size() * sizeof(short));
|
||||
} else {
|
||||
if(nexus.signature & NXS_STRIP) {
|
||||
assert(nexus.signature.face == out.signature.face);
|
||||
if(nexus.signature.face == Signature::STRIPS) {
|
||||
memcpy(dst_patch.FaceBegin(), src_patch.FaceBegin(),
|
||||
src_patch.nf * sizeof(unsigned short));
|
||||
} else {
|
||||
} else if(nexus.signature.face == Signature::TRIANGLES) {
|
||||
memcpy(dst_patch.FaceBegin(), src_patch.FaceBegin(),
|
||||
src_patch.nf * sizeof(unsigned short) * 3);
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
if((nexus.signature & NXS_COLORS) && (out.signature & NXS_COLORS))
|
||||
memcpy(dst_patch.ColorBegin(), src_patch.ColorBegin(),
|
||||
src_patch.nv * sizeof(unsigned int));
|
||||
if(nexus.signature.vcolor) {
|
||||
if(nexus.signature.vcolor == out.signature.vcolor) {
|
||||
memcpy(dst_patch.VColorBegin(), src_patch.VColorBegin(),
|
||||
Patch::encodings[out.signature.vcolor].size(dst_patch.nv));
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
if((nexus.signature & NXS_NORMALS_SHORT) &&
|
||||
(out.signature & NXS_NORMALS_SHORT))
|
||||
memcpy(dst_patch.Norm16Begin(), src_patch.Norm16Begin(),
|
||||
src_patch.nv * sizeof(short)*4);
|
||||
if(nexus.signature.vnorm) {
|
||||
if(nexus.signature.vnorm == out.signature.vnorm) {
|
||||
memcpy(dst_patch.VNormBegin(), src_patch.VNormBegin(),
|
||||
Patch::encodings[out.signature.vnorm].size(dst_patch.nv));
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
//reordering
|
||||
//WATCH OUT BORDERS!
|
||||
// Reorder(out.signature, dst_patch);
|
||||
//copying entry information;
|
||||
dst_entry.sphere = src_entry.sphere;
|
||||
dst_entry.error = src_entry.error;
|
||||
//WARNING copy also normals cone
|
||||
|
||||
//adding borders.
|
||||
/*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());
|
||||
}*/
|
||||
out.borders.ResizeBorder(p, src_border.Size());
|
||||
Border &dst_border = out.GetBorder(p);
|
||||
memcpy(dst_border.Start(), src_border.Start(),
|
||||
src_border.Size() * sizeof(Link));
|
||||
//TODO test this
|
||||
if(zsort)
|
||||
for(unsigned i = 0; i < dst_border.Size(); i++)
|
||||
dst_border[i].end_patch = backward[dst_border[i].end_patch];
|
||||
|
||||
}
|
||||
report.Finish();
|
||||
|
||||
|
@ -510,7 +552,7 @@ int main(int argc, char *argv[]) {
|
|||
report.Step(patch);
|
||||
Patch src_patch = nexus.GetPatch(patch);
|
||||
|
||||
float *ptr = (float *)src_patch.VertBegin();
|
||||
float *ptr = (float *)src_patch.Vert3fBegin();
|
||||
for(int i = 0; i < src_patch.nv*3; i++)
|
||||
ptr[i] = qvertex * (int)(ptr[i]/qvertex);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.9 2005/02/08 12:43:03 ponchio
|
||||
Added copyright
|
||||
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -44,6 +47,43 @@ static double wrkmem[LZO1X_999_MEM_COMPRESS/sizeof(double) +1];
|
|||
#endif
|
||||
|
||||
|
||||
Encodings Patch::encodings;
|
||||
|
||||
Encodings::Encodings() {
|
||||
for(unsigned int i = 0; i < 256; i++) {
|
||||
e[i].bytes = 0;
|
||||
e[i].comps = 0;
|
||||
e[i].pack = NULL;
|
||||
e[i].unpack = NULL;
|
||||
}
|
||||
e[1].bytes = 1;
|
||||
e[2].bytes = 2;
|
||||
e[3].bytes = 4;
|
||||
e[4].bytes = 8;
|
||||
e[1].comps = e[2].comps = e[3].comps = e[4].comps = 1;
|
||||
e[5].bytes = 1;
|
||||
e[6].bytes = 2;
|
||||
e[7].bytes = 4;
|
||||
e[8].bytes = 8;
|
||||
e[5].comps = e[6].comps = e[7].comps = e[8].comps = 2;
|
||||
e[9].bytes = 1;
|
||||
e[10].bytes = 2;
|
||||
e[11].bytes = 4;
|
||||
e[12].bytes = 8;
|
||||
e[9].comps = e[10].comps = e[11].comps = e[12].comps = 3;
|
||||
e[13].bytes = 1;
|
||||
e[14].bytes = 2;
|
||||
e[15].bytes = 4;
|
||||
e[16].bytes = 8;
|
||||
e[13].comps = e[14].comps = e[15].comps = e[16].comps = 4;
|
||||
}
|
||||
|
||||
|
||||
void pad64(unsigned int &s) {
|
||||
if((s & 0x0000003f) != 0) {
|
||||
s>>=6; s++; s<<=6;
|
||||
}
|
||||
}
|
||||
void pad(unsigned int &size) {
|
||||
while(size&0x3) size++;
|
||||
}
|
||||
|
@ -96,18 +136,61 @@ void unsubtract(float *buffer, unsigned int size) {
|
|||
}
|
||||
|
||||
|
||||
Patch::Patch(Signature signature, char *s,
|
||||
Patch::Patch(Signature &signature, char *s,
|
||||
unsigned short nvert, unsigned short nface):
|
||||
start(s) {
|
||||
fstart(s) {
|
||||
Init(signature, nvert, nface);
|
||||
}
|
||||
|
||||
void Patch::Init(Signature signature,
|
||||
void Patch::Init(Signature &signature,
|
||||
unsigned short nvert, unsigned short nface) {
|
||||
nv = nvert;
|
||||
nf = nface;
|
||||
|
||||
if(signature & NXS_FACES)
|
||||
unsigned int offset = 0;
|
||||
|
||||
if(signature.face == Signature::TRIANGLES)
|
||||
offset += nf * 3 * sizeof(unsigned short);
|
||||
else if (signature.face == Signature::STRIPS)
|
||||
offset += nf * sizeof(unsigned short);
|
||||
else if (signature.face == Signature::TETRAS)
|
||||
offset += nf * 4 * sizeof(unsigned short);
|
||||
else if (signature.face == Signature::SLICE) {
|
||||
assert(0);
|
||||
//non lo so...
|
||||
}
|
||||
pad64(offset);
|
||||
|
||||
fstartc = (unsigned short)offset/64;
|
||||
offset += encodings[signature.fcolor].size(nf);
|
||||
fstartn = (unsigned short)offset/64;
|
||||
offset += encodings[signature.fnorm].size(nf);
|
||||
fstartt = (unsigned short)offset/64;
|
||||
offset += encodings[signature.ftext].size(nf);
|
||||
fstartd = (unsigned short)offset/64;
|
||||
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);
|
||||
|
||||
vstartc = (unsigned short)offset/64;
|
||||
offset += encodings[signature.vcolor].size(nv);
|
||||
vstartn = (unsigned short)offset/64;
|
||||
offset += encodings[signature.vnorm].size(nv);
|
||||
vstartt = (unsigned short)offset/64;
|
||||
offset += encodings[signature.vtext].size(nv);
|
||||
vstartd = (unsigned short)offset/64;
|
||||
offset += encodings[signature.vdata].size(nv);
|
||||
|
||||
|
||||
/* if(signature & NXS_FACES)
|
||||
vstart = (float *)(((char *)start) + nf * sizeof(unsigned short) * 3);
|
||||
else if(signature & NXS_STRIP)
|
||||
vstart = (float *)(((char *)start) + nf * sizeof(unsigned short));
|
||||
|
@ -135,10 +218,10 @@ void Patch::Init(Signature signature,
|
|||
else if(signature & NXS_TEXTURES_FLOAT)
|
||||
dstart = tstart + nv;
|
||||
else
|
||||
dstart = tstart;
|
||||
dstart = tstart;*/
|
||||
}
|
||||
|
||||
unsigned int Patch::ChunkSize(Signature signature,
|
||||
unsigned int Patch::ChunkSize(Signature &signature,
|
||||
unsigned short nvert,
|
||||
unsigned short nface,
|
||||
unsigned int chunk_size) {
|
||||
|
@ -147,10 +230,50 @@ unsigned int Patch::ChunkSize(Signature signature,
|
|||
return size;
|
||||
}
|
||||
|
||||
unsigned int Patch::ByteSize(Signature signature,
|
||||
unsigned int Patch::ByteSize(Signature &signature,
|
||||
unsigned short nvert,
|
||||
unsigned short nface) {
|
||||
|
||||
unsigned int size = 0;
|
||||
if(signature.face == Signature::TRIANGLES)
|
||||
size += nface * 3 * sizeof(unsigned short);
|
||||
else if (signature.face == Signature::STRIPS)
|
||||
size += nface + sizeof(unsigned short);
|
||||
else if (signature.face == Signature::TETRAS)
|
||||
size += nface * 4 * sizeof(unsigned short);
|
||||
else if (signature.face == Signature::SLICE) {
|
||||
assert(0);
|
||||
//non lo so...
|
||||
}
|
||||
pad64(size);
|
||||
|
||||
size += encodings[signature.fcolor].size(nface);
|
||||
size += encodings[signature.fnorm].size(nface);
|
||||
size += encodings[signature.ftext].size(nface);
|
||||
size += encodings[signature.fdata].size(nface);
|
||||
|
||||
if(signature.vert == Signature::POINT3F)
|
||||
size += nvert * sizeof(float) * 3;
|
||||
else if(signature.vert == Signature::POINT4F)
|
||||
size += nvert * sizeof(float) * 4;
|
||||
else
|
||||
assert(0);
|
||||
pad64(size);
|
||||
|
||||
size += encodings[signature.vcolor].size(nvert);
|
||||
size += encodings[signature.vnorm].size(nvert);
|
||||
size += encodings[signature.vtext].size(nvert);
|
||||
size += encodings[signature.vdata].size(nvert);
|
||||
|
||||
//this condition should really rarely happen but helps save space
|
||||
//during construction
|
||||
if(size < nface * 3 * sizeof(unsigned int))
|
||||
size = nface * 3 * sizeof(unsigned int);
|
||||
|
||||
return size;
|
||||
|
||||
|
||||
/* unsigned int size = 0;
|
||||
if(signature & NXS_STRIP)
|
||||
size += nface * sizeof(unsigned short);
|
||||
else if(signature & NXS_FACES)
|
||||
|
@ -193,7 +316,7 @@ unsigned int Patch::ByteSize(Signature signature,
|
|||
if(size < nface * 3 * sizeof(unsigned int))
|
||||
size = nface * 3 * sizeof(unsigned int);
|
||||
|
||||
return size;
|
||||
return size;*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -205,20 +328,19 @@ char *Patch::Compress(unsigned int ram_size, unsigned int &size) {
|
|||
|
||||
//TODO use OVERLAP and test speed
|
||||
//TODO fill chunk padding with zeroes?
|
||||
//TODO compress only used memory!
|
||||
size = ram_size + ram_size/64 + 23;
|
||||
char *buffer = new char[size];
|
||||
#ifdef WIN32
|
||||
lzo1x_1_compress(((unsigned char *)start), ram_size,
|
||||
lzo1x_1_compress(((unsigned char *)fstart), ram_size,
|
||||
(unsigned char *)buffer + sizeof(int), &size,
|
||||
(char *)wrkmem);
|
||||
#else
|
||||
lzo1x_999_compress(((unsigned char *)start), ram_size,
|
||||
lzo1x_999_compress(((unsigned char *)fstart), ram_size,
|
||||
(unsigned char *)buffer + sizeof(int), &size,
|
||||
(char *)wrkmem);
|
||||
|
||||
lzo1x_optimize((unsigned char *)buffer + sizeof(int), size,
|
||||
((unsigned char *)start), &ram_size,
|
||||
((unsigned char *)fstart), &ram_size,
|
||||
NULL);
|
||||
#endif
|
||||
|
||||
|
@ -239,7 +361,7 @@ void Patch::Decompress(unsigned int ram_size, void *src, unsigned int src_sz) {
|
|||
unsigned int dst_size = ram_size;
|
||||
|
||||
int ret = lzo1x_decompress_safe(((unsigned char *)src) + sizeof(int), size,
|
||||
(unsigned char *)start, &dst_size, 0);
|
||||
(unsigned char *)fstart, &dst_size, 0);
|
||||
if(ret != 0) {
|
||||
cerr << "Ret from decompress: " << ret << endl;
|
||||
exit(-1);
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.11 2005/02/08 12:43:03 ponchio
|
||||
Added copyright
|
||||
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -35,47 +38,102 @@ $Log: not supported by cvs2svn $
|
|||
|
||||
namespace nxs {
|
||||
|
||||
enum Signature { NXS_FACES = 0x00000001,
|
||||
NXS_STRIP = 0x00000002,
|
||||
NXS_COLORS = 0x00000010,
|
||||
NXS_NORMALS_SHORT = 0x00000100,
|
||||
NXS_NORMALS_FLOAT = 0x00000200,
|
||||
NXS_TEXTURES_SHORT = 0x00001000,
|
||||
NXS_TEXTURES_FLOAT = 0x00002000,
|
||||
NXS_DATA8 = 0x00010000,
|
||||
NXS_DATA16 = 0x00020000,
|
||||
NXS_DATA32 = 0x00040000,
|
||||
NXS_DATA64 = 0x00080000,
|
||||
NXS_COMPRESSED = 0x10000000};
|
||||
struct Signature {
|
||||
|
||||
enum Face { TRIANGLES = 1, STRIPS = 2, TETRAS = 3, SLICE = 4 };
|
||||
|
||||
enum Vert { POINT2F = 1, POINT2D = 2,
|
||||
POINT3F = 2, POINT3D = 3,
|
||||
POINT4F = 4, POINT4D = 5 };
|
||||
|
||||
enum Compr { LZO = 1 };
|
||||
|
||||
unsigned char face;
|
||||
unsigned char vert;
|
||||
unsigned char compr;
|
||||
unsigned char future; //who knows...
|
||||
|
||||
unsigned char fcolor;
|
||||
unsigned char fnorm;
|
||||
unsigned char ftext;
|
||||
unsigned char fdata;
|
||||
|
||||
unsigned char vcolor;
|
||||
unsigned char vnorm;
|
||||
unsigned char vtext;
|
||||
unsigned char vdata;
|
||||
|
||||
Signature(): face(1), vert(2), compr(0), future(0),
|
||||
fcolor(0), fnorm(0), ftext(0), fdata(0),
|
||||
vcolor(0), vnorm(0), vtext(0), vdata(0) {}
|
||||
};
|
||||
|
||||
|
||||
struct Encoding {
|
||||
|
||||
unsigned char bytes; //size per element
|
||||
unsigned char comps; //number of components
|
||||
void (*pack)(char *start, unsigned int nelem);
|
||||
void (*unpack)(char *start, unsigned int nelem);
|
||||
|
||||
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;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
};
|
||||
|
||||
struct Encodings {
|
||||
enum Name { EMPTY = 0,
|
||||
BYTE1 = 1, SHORT1 = 2, FLOAT1 = 3, DOUBLE1 = 4,
|
||||
BYTE2 = 5, SHORT2 = 6, FLOAT2 = 7, DOUBLE2 = 8,
|
||||
BYTE3 = 9, SHORT3 = 10, FLOAT3 = 11, DOUBLE3 = 12,
|
||||
BYTE4 = 13, SHORT4 = 14, FLOAT4 = 15, DOUBLE4 = 16 };
|
||||
Encodings();
|
||||
Encoding &operator[](int n) { return e[n]; }
|
||||
protected:
|
||||
Encoding e[17];
|
||||
|
||||
|
||||
};
|
||||
|
||||
class Patch {
|
||||
public:
|
||||
|
||||
Patch(Signature signature, char *s,
|
||||
static Encodings encodings;
|
||||
|
||||
Patch(Signature &signature, char *s,
|
||||
unsigned short nv, unsigned short nf);
|
||||
|
||||
void Init(Signature signature, unsigned short nv, unsigned short nf);
|
||||
void Init(Signature &signature, unsigned short nv, unsigned short nf);
|
||||
|
||||
inline vcg::Point3f *VertBegin();
|
||||
inline unsigned short *FaceBegin();
|
||||
vcg::Point3f *Vert3fBegin() { return (vcg::Point3f *)vstart; }
|
||||
vcg::Point3f &Vert3f(int n) { return Vert3fBegin()[n]; }
|
||||
unsigned short *FaceBegin() { return (unsigned short *)fstart; }
|
||||
unsigned short *Face(int n) { return FaceBegin() + 3 * n; }
|
||||
|
||||
inline vcg::Point3f &Vert(unsigned short v);
|
||||
inline unsigned short *Face(unsigned short f);
|
||||
//vcg::Point3f &Vert(unsigned short v) { return VertBegin()[v]; }
|
||||
// unsigned short *Face(unsigned short f) { return FaceBegin() + f * 3; }
|
||||
|
||||
inline unsigned int *ColorBegin();
|
||||
inline short *Norm16Begin();
|
||||
inline short *Norm16(unsigned short v);
|
||||
inline vcg::Point3f *Norm32Begin();
|
||||
inline vcg::Point3f &Norm32(unsigned short v);
|
||||
char *VColorBegin() { return vstart + 64*vstartc; }
|
||||
char *VNormBegin() { return vstart + 64*vstartn; }
|
||||
char *VTextBegin() { return vstart + 64*vstartt; }
|
||||
char *VDataBegin() { return vstart + 64*vstartd; }
|
||||
|
||||
static unsigned int ChunkSize(Signature signature,
|
||||
char *FColorBegin() { return fstart + 64*fstartc; }
|
||||
char *FNormBegin() { return fstart + 64*fstartn; }
|
||||
char *FTextBegin() { return fstart + 64*fstartt; }
|
||||
char *FDataBegin() { return fstart + 64*fstartd; }
|
||||
|
||||
static unsigned int ChunkSize(Signature &signature,
|
||||
unsigned short nvert,
|
||||
unsigned short nface,
|
||||
unsigned int chunk_size);
|
||||
|
||||
static unsigned int ByteSize(Signature signature,
|
||||
static unsigned int ByteSize(Signature &signature,
|
||||
unsigned short nvert,
|
||||
unsigned short nface);
|
||||
|
||||
|
@ -83,51 +141,25 @@ class Patch {
|
|||
void Decompress(unsigned int ram_size, void *src, unsigned int src_sz);
|
||||
|
||||
|
||||
unsigned short nv;
|
||||
char *fstart;
|
||||
char *vstart;
|
||||
|
||||
unsigned short nf;
|
||||
unsigned short nv;
|
||||
|
||||
char *start;
|
||||
float *vstart;
|
||||
//these offset are from vstart!
|
||||
unsigned short cstart;
|
||||
unsigned short nstart;
|
||||
unsigned short tstart;
|
||||
unsigned short dstart;
|
||||
//these offset are from fstart in 64 bytes
|
||||
unsigned short fstartc;
|
||||
unsigned short fstartn;
|
||||
unsigned short fstartt;
|
||||
unsigned short fstartd;
|
||||
|
||||
//these offset are from vstart in 64 bytes
|
||||
unsigned short vstartc;
|
||||
unsigned short vstartn;
|
||||
unsigned short vstartt;
|
||||
unsigned short vstartd;
|
||||
};
|
||||
|
||||
inline vcg::Point3f *Patch::VertBegin() {
|
||||
return (vcg::Point3f *)vstart;
|
||||
}
|
||||
inline unsigned short *Patch::FaceBegin() {
|
||||
return (unsigned short *)start;
|
||||
}
|
||||
|
||||
inline vcg::Point3f &Patch::Vert(unsigned short v) {
|
||||
return VertBegin()[v];
|
||||
}
|
||||
inline unsigned short *Patch::Face(unsigned short f) {
|
||||
return FaceBegin() + f * 3;
|
||||
}
|
||||
|
||||
inline unsigned int *Patch::ColorBegin() {
|
||||
return (unsigned int *)(vstart + cstart);
|
||||
}
|
||||
|
||||
inline short *Patch::Norm16Begin() {
|
||||
return (short *)(vstart + nstart);
|
||||
}
|
||||
|
||||
inline short *Patch::Norm16(unsigned short v) {
|
||||
return Norm16Begin() + 4 * v;
|
||||
}
|
||||
|
||||
inline vcg::Point3f *Patch::Norm32Begin() {
|
||||
return (vcg::Point3f *)(vstart + nstart);
|
||||
}
|
||||
inline vcg::Point3f &Patch::Norm32(unsigned short v) {
|
||||
return Norm32Begin()[v];
|
||||
}
|
||||
|
||||
} //namespace
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.9 2005/02/08 12:43:03 ponchio
|
||||
Added copyright
|
||||
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -344,7 +347,7 @@ void nxs::BuildLevel(VChain &chain,
|
|||
cratio += ratio;
|
||||
if(cratio > 1) {
|
||||
Patch patch = nexus.GetPatch(idx);
|
||||
Point3f &v = patch.Vert(0);
|
||||
Point3f &v = patch.Vert3f(0);
|
||||
coarse->push_back(v);
|
||||
cratio -= 1;
|
||||
}
|
||||
|
@ -352,7 +355,7 @@ void nxs::BuildLevel(VChain &chain,
|
|||
|
||||
if(coarse->size() == 0) {
|
||||
Patch patch = nexus.GetPatch(0);
|
||||
coarse->push_back(patch.Vert(0));
|
||||
coarse->push_back(patch.Vert3f(0));
|
||||
}
|
||||
|
||||
float coarse_vmean = totface/(float)coarse->size();
|
||||
|
@ -380,9 +383,9 @@ void nxs::BuildLevel(VChain &chain,
|
|||
Patch patch = nexus.GetPatch(idx);
|
||||
for(unsigned int i = 0; i < patch.nf; i++) {
|
||||
unsigned short *face = patch.Face(i);
|
||||
Point3f bari = (patch.Vert(face[0]) +
|
||||
patch.Vert(face[1]) +
|
||||
patch.Vert(face[2]))/3;
|
||||
Point3f bari = (patch.Vert3f(face[0]) +
|
||||
patch.Vert3f(face[1]) +
|
||||
patch.Vert3f(face[2]))/3;
|
||||
|
||||
unsigned int target = coarse->Locate(bari);
|
||||
assert(target < coarse->size());
|
||||
|
@ -448,7 +451,7 @@ bool nxs::Optimize(VPartition &part,
|
|||
|
||||
if(max_size > target_size *3)
|
||||
max_size = target_size * 3;
|
||||
min_size = target_size * 0.3;
|
||||
min_size = (unsigned int)(target_size * 0.3f);
|
||||
|
||||
unsigned int toobig = 0;
|
||||
unsigned int toosmall = 0;
|
||||
|
|
Loading…
Reference in New Issue