Backup (added strips and normals)

This commit is contained in:
Federico Ponchio 2004-09-30 23:56:33 +00:00
parent e5d01c7a80
commit 430070f9fd
6 changed files with 58 additions and 50 deletions

View File

@ -84,11 +84,12 @@ void NexusMt::Render() {
//TODO textures and data.
for(unsigned int i = 0; i < cells.size(); i++) {
Nexus::Entry &entry = index[cells[i]];
unsigned int cell = cells[i];
Nexus::Entry &entry = index[cell];
//frustum culling
// if(frustum.Outside(entry.sphere.center, entry.sphere.radius))
// continue;
Patch patch = GetPatch(cells[i]);
Patch patch = GetPatch(cell);
glVertexPointer(3, GL_FLOAT, 0, patch.VertBegin());
if(use_colors)
glColorPointer(4, GL_UNSIGNED_BYTE, 0, patch.ColorBegin());
@ -97,6 +98,8 @@ void NexusMt::Render() {
switch(mode) {
case POINTS:
glDrawArrays(GL_POINTS, 0, patch.nv); break;
case DEBUG:
glColor3ub((cell * 27)%255, (cell * 37)%255, (cell * 87)%255);
case SMOOTH:
if(signature & NXS_FACES)
glDrawElements(GL_TRIANGLES, patch.nf * 3,

View File

@ -57,7 +57,8 @@ class NexusMt: public Nexus {
XRAY,
HIDDEN_LINE,
FLAT_WIRE,
FLAT};
FLAT,
DEBUG };
enum Component { COLOR = 0x1,
NORMAL = 0x2,
@ -79,7 +80,6 @@ class NexusMt: public Nexus {
bool use_textures;
bool use_data;
NexusMt();
bool Load(const std::string &filename);

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.8 2004/09/30 00:27:42 ponchio
Lot of changes. Backup.
Revision 1.7 2004/09/28 10:26:35 ponchio
Backup
@ -185,6 +188,7 @@ int main(int argc, char *argv[]) {
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_CULL_FACE);
int quit = 0;
SDL_Event event;
int x, y;
@ -268,6 +272,7 @@ int main(int argc, char *argv[]) {
Point3f center = sphere.Center();
glTranslatef(-center[0], -center[1], -center[2]);
nexus.SetMode(NexusMt::DEBUG);
nexus.SetPolicy(NexusMt::FRUSTUM, error);
nexus.SetComponent(NexusMt::COLOR, show_colors);
nexus.SetComponent(NexusMt::NORMAL, show_normals);

View File

@ -1,6 +1,7 @@
#include <iostream>
using namespace std;
#include "nxsalgo.h"
#include "nexus.h"
using namespace nxs;
@ -238,55 +239,42 @@ int main(int argc, char *argv[]) {
Patch src_patch = nexus.GetPatch(patch);
Border src_border = nexus.GetBorder(patch);
out.AddPatch(src_entry.nvert, src_entry.nface, src_entry.border_size);
vector<unsigned short> strip;
if(add_strip) {
ComputeTriStrip(src_patch.nf, src_patch.FaceBegin(), strip);
out.AddPatch(src_entry.nvert, strip.size(), src_entry.border_size);
} else
out.AddPatch(src_entry.nvert, src_entry.nface, src_entry.border_size);
Nexus::Entry &dst_entry = out.index[patch];
Patch dst_patch = out.GetPatch(patch);
Border dst_border = out.GetBorder(patch);
//copy vertices: //no clustering
memcpy(dst_patch.VertBegin(), src_patch.VertBegin(),
src_patch.nv * sizeof(Point3f));
//now faces.
if(add_strip) {
cerr << "Unsupported strips\n";
return -1;
memcpy(dst_patch.FaceBegin(), &*strip.begin(),
strip.size() * sizeof(short));
} else {
memcpy(dst_patch.FaceBegin(), src_patch.FaceBegin(),
src_patch.nf * sizeof(unsigned short) *3);
}
if(add_colors) {
//source of color:
cerr << "Unsupported color\n";
return -1;
}
if(add_normals) {
vector<Point3f> normals;
normals.resize(dst_patch.nv, Point3f(0, 0, 0));
if((nexus.signature & NXS_COLORS) && (out.signature & NXS_COLORS))
memcpy(dst_patch.ColorBegin(), src_patch.ColorBegin(),
src_patch.nv * sizeof(unsigned int));
for(unsigned int i = 0; i < dst_patch.nf; i++) {
unsigned short *f = dst_patch.Face(i);
Point3f &v0 = dst_patch.Vert(f[0]);
Point3f &v1 = dst_patch.Vert(f[1]);
Point3f &v2 = dst_patch.Vert(f[2]);
Point3f norm = (v1 - v0) ^ (v2 - v0);
normals[f[0]] += norm;
normals[f[1]] += norm;
normals[f[2]] += norm;
}
for(unsigned int i = 0; i < dst_patch.nv; i++) {
Point3f &norm = normals[i];
norm.Normalize();
short *n = dst_patch.Norm16(i);
for(int k = 0; k < 3; k++) {
n[k] = (short)(norm[k] * 32766);
}
n[3] = 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);
//copying entry information;
dst_entry.sphere = src_entry.sphere;
@ -297,17 +285,18 @@ int main(int argc, char *argv[]) {
memcpy(dst_border.Start(), src_border.Start(),
src_border.Size() * sizeof(Link));
}
//TODO !!! FIX NORMALS ACROSS BORDERS
/*
for(unsigned int patch = 0; patch < nexus.index.size(); patch++) {
for(unsigned int i = 0; i < dst_border.Size(); i++) {
Link &link = dst_border[i];
//we just make the mean...
}
}
*/
//TODO this is ok only if we have faces still!
if(add_normals) {
cerr << "Computing normals" << endl;
ComputeNormals(out);
}
if(add_colors) {
//source of color:
cerr << "Unsupported color\n";
return -1;
}
//fixing sphere.
out.sphere = nexus.sphere;

View File

@ -5,8 +5,7 @@
#include <iostream>
namespace nxs {
enum Signature { NXS_DEFAULT = 0x00000000,
NXS_FACES = 0x00000001,
enum Signature { NXS_FACES = 0x00000001,
NXS_STRIP = 0x00000002,
NXS_COLORS = 0x00000010,
NXS_NORMALS_SHORT = 0x00000100,
@ -41,6 +40,8 @@ class Patch {
inline unsigned int *ColorBegin();
inline short *Norm16Begin();
inline short *Norm16(unsigned short v);
inline vcg::Point3f *Norm32Begin();
inline vcg::Point3f &Norm32(unsigned short v);
static unsigned int ChunkSize(Signature signature,
unsigned short nvert,
@ -90,6 +91,13 @@ inline short *Patch::Norm16(unsigned short v) {
return Norm16Begin() + 4 * v;
}
inline vcg::Point3f *Patch::Norm32Begin() {
return (vcg::Point3f *)(((char *)vstart) + nstart);
}
inline vcg::Point3f &Patch::Norm32(unsigned short v) {
return Norm32Begin()[v];
}
} //namespace
#endif

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.9 2004/07/20 14:04:32 ponchio
Improved efficience in operator[]
Revision 1.8 2004/07/15 14:32:49 ponchio
Debug.
@ -294,7 +297,7 @@ template <class T> class VFile {
1)region must be Chunk aligned.
2)you get impredictable results if regions overlap or mix with operator[]
*/
T *GetRegion(unsigned int start, unsigned int size) {
T *GetRegion(unsigned int start, unsigned int size, bool flush = true) {
assert(start + size <= n_elements);
assert((size % chunk_size) == 0);
assert((start % chunk_size) == 0);
@ -305,7 +308,7 @@ template <class T> class VFile {
if(index.count(chunk))
return ((*(index[chunk])).data);
if(buffers.size() > queue_size) {
while(flush && buffers.size() > queue_size) {
Buffer &buffer= buffers.back();
FlushBuffer(buffer);
index.erase(buffer.key);