This commit is contained in:
Federico Ponchio 2004-07-15 14:32:49 +00:00
parent b53fe209a1
commit 34ac04a21b
6 changed files with 134 additions and 88 deletions

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.2 2004/07/05 15:49:39 ponchio
Windows (DevCpp, mingw) port.
Revision 1.1 2004/07/04 15:30:00 ponchio
Changed directory structure.
@ -224,10 +227,12 @@ int main(int argc, char *argv[]) {
patch.FaceBegin()[k*3 + j] = remap[face[j]];
}
}
assert(count == remap.size());
assert(entry.nvert == remap.size());
//record start of border:
entry.border_start = border_remap.Size();
// border_start.push_back(border_remap.Size());
//TODO hash_set?
set<unsigned int> border_patches;
map<unsigned int, unsigned short>::iterator m;
@ -249,28 +254,68 @@ int main(int argc, char *argv[]) {
}
//and number of borders:
entry.border_size = border_remap.Size() - entry.border_start;
//border_size.push_back(border_remap.Size() - border_start.back());
delete []faces;
}
//we can now update bounding sphere.
for(unsigned int i = 0; i < nexus.index.size(); i++) {
for(unsigned int i = 0; i < nexus.index.size(); i++)
nexus.sphere.Add(nexus.index[i].sphere);
}
//and last convert RemapLinks into Links
nexus.borders.Resize(border_remap.Size());
for(unsigned int i = 0; i < border_remap.Size(); i++) {
RemapLink start_link = border_remap[i];
Nexus::Entry &entry = nexus.index[start_link.patch];
for(unsigned int k = entry.border_start;
k < entry.border_start + entry.border_size; k++) {
RemapLink end_link = border_remap[k];
if(start_link.abs_vert == end_link.abs_vert) { //found the match
nexus.borders[i] = Link(start_link.rel_vert,
end_link.rel_vert, start_link.patch);
for(unsigned int i = 0; i < nexus.index.size(); i++) {
Nexus::Entry &local = nexus.index[i];
// K is the main iterator (where we write to in nexus.borders)
for(unsigned int k = local.border_start;
k < local.border_start + local.border_size; k++) {
RemapLink start_link = border_remap[k];
assert(start_link.rel_vert < local.nvert);
Nexus::Entry &remote = nexus.index[start_link.patch];
bool found = false;
for(unsigned int j = remote.border_start;
j < remote.border_start + remote.border_size; j++) {
RemapLink end_link = border_remap[j];
assert(end_link.rel_vert < remote.nvert);
if(start_link.abs_vert == end_link.abs_vert &&
end_link.patch == i) { //found the match
assert(!found);
nexus.borders[k] = Link(start_link.rel_vert,
end_link.rel_vert, start_link.patch);
found = true;
}
}
assert(nexus.borders[k].start_vert < local.nvert);
assert(found);
}
}
nexus.borders.Flush();
//Checking border consistency:
for(unsigned int i = 0; i < nexus.index.size(); i++) {
Border border = nexus.GetBorder(i);
Nexus::Entry &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;
}
assert(link.end_patch < nexus.index.size());
assert(link.start_vert < entry.nvert);
Nexus::Entry &remote = nexus.index[link.end_patch];
assert(link.end_vert < remote.nvert);
}
}
nexus.Close();
return 0;

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.2 2004/07/05 15:49:39 ponchio
Windows (DevCpp, mingw) port.
Revision 1.1 2004/07/04 15:30:00 ponchio
Changed directory structure.
@ -126,6 +129,10 @@ int main(int argc, char *argv[]) {
bool rotate = true;
glClearColor(0, 0, 0, 0);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
int quit = 0;
SDL_Event event;
int x, y;
@ -166,10 +173,10 @@ int main(int argc, char *argv[]) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, 1, 0.1, 100);
gluPerspective(40, 1, 0.1, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,3, 0,0,0, 0,1,0);
gluLookAt(0,0,6, 0,0,0, 0,1,0);
float scale = 2/sphere.Radius();
@ -182,27 +189,37 @@ int main(int argc, char *argv[]) {
glTranslatef(-center[0], -center[1], -center[2]);
for(unsigned int i = 0; i < nexus.index.size(); i++) {
Patch patch = nexus.GetPatch(i);
unsigned int val = i + 1;
glColor3ub((val * 27)%255, (val * 37)%255, (val * 87)%255);
glColor3ub(((val * 27)%128) + 128,
((val * 37)%128) + 128,
((val * 87)%128) + 128);
glBegin(GL_TRIANGLES);
unsigned short *f = patch.FaceBegin();
for(unsigned int j = 0; j < patch.FaceSize() * 3; j++) {
Point3f &p = patch.Vert(f[j]);
glVertex3f(p[0], p[1], p[2]);
for(unsigned int j = 0; j < patch.FaceSize()*3; j+= 3) {
Point3f &p1 = patch.Vert(f[j]);
Point3f &p2 = patch.Vert(f[j+1]);
Point3f &p3 = patch.Vert(f[j+2]);
Point3f n = ((p2 - p1) ^ (p3 - p1));
glNormal3f(n[0], n[1], n[2]);
glVertex3f(p1[0], p1[1], p1[2]);
glVertex3f(p2[0], p2[1], p2[2]);
glVertex3f(p3[0], p3[1], p3[2]);
}
glEnd();
// glColor3ub(((val * 27)%255)/2, ((val * 37)%255)/2, ((val * 87)%255)/2);
glColor3f(1, 1, 1);
//drawing borders
glColor3f(1, 1, 1);
Border border = nexus.GetBorder(i);
glPointSize(4);
glPointSize(1);
glBegin(GL_POINTS);
for(unsigned int k = 0; k < border.Size(); k++) {
if(border[k].IsNull()) continue;
Point3f &p = patch.Vert(border[k].start_vert);
glVertex3f(p[0], p[1], p[2]);
}

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.2 2004/07/05 17:07:14 ponchio
Tested a bit.
Revision 1.1 2004/07/04 15:24:50 ponchio
Created
@ -52,6 +55,7 @@ int main(int argc, char *argv[]) {
return -1;
}
unsigned int duplicated = 0;
for(unsigned int p = 0; p < nexus.index.size(); p++) {
Nexus::Entry &entry = nexus.index[p];
Patch patch = nexus.GetPatch(p);
@ -67,11 +71,12 @@ int main(int argc, char *argv[]) {
if(!vertices.count(point)) {
vertices[point] = vcount++;
} else {
cerr << "Duplicated point\n";
duplicated++;
}
remap[i] = vertices[point];
}
assert(vertices.size() <= patch.VertSize());
if(vertices.size() == patch.VertSize()) //no need to unify
continue;
@ -79,23 +84,21 @@ int main(int argc, char *argv[]) {
newvert.resize(vertices.size());
map<Point3f, unsigned short>::iterator k;
for(k = vertices.begin(); k != vertices.end(); k++) {
newvert[remap[(*k).second]] = (*k).first;
newvert[(*k).second] = (*k).first;
}
vector<unsigned short> newface;
newface.resize(patch.FaceSize() * 3);
for(unsigned int f = 0; f < (unsigned int)(patch.FaceSize() *3); f++) {
newface[f] = remap[f];
}
for(unsigned int f = 0; f < newface.size(); f++)
newface[f] = remap[patch.FaceBegin()[f]];
//rewrite patch now.
patch.Resize(newvert.size(), newface.size());
entry.nvert = newvert.size();
entry.nface = newface.size();
memcpy(patch.VertBegin(), &(newvert[0]),
patch.VertSize() * sizeof(Point3f));
memcpy(patch.FaceBegin(), &(newface[0]),
patch.FaceSize() * 3 * sizeof(unsigned short));
patch.Resize(entry.nvert, entry.nface);
memcpy(patch.VertBegin(), &(newvert[0]), entry.nvert*sizeof(Point3f));
memcpy(patch.FaceBegin(), &(newface[0]), entry.nface*3*sizeof(unsigned short));
//fix patch borders now
set<unsigned int> close; //bordering pathes
@ -110,9 +113,9 @@ int main(int argc, char *argv[]) {
for(c = close.begin(); c != close.end(); c++) {
Border bord = nexus.GetBorder(*c);
for(unsigned int b = 0; b < bord.Size(); b++) {
if(border[b].IsNull()) continue;
if(bord[b].IsNull()) continue;
if(bord[b].end_patch == p) {
bord[b].end_vert = remap[border[b].end_vert];
bord[b].end_vert = remap[bord[b].end_vert];
}
}
}
@ -132,5 +135,6 @@ int main(int argc, char *argv[]) {
links.insert(border[b]);
}
}
cerr << "Found " << duplicated << " duplicated vertices" << endl;
return 0;
}

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.2 2004/07/05 15:49:39 ponchio
Windows (DevCpp, mingw) port.
Revision 1.1 2004/07/04 15:30:00 ponchio
Changed directory structure.
@ -111,6 +114,7 @@ int main(int argc, char *argv[]) {
return false;
}
unsigned int vertex_offset = crude.Vertices();
for(unsigned int i = 0; i < pf.elements.size(); i++) {
if(!strcmp( pf.ElemName(i),"vertex")) {
unsigned int n_vertices = pf.ElemNumber(i);
@ -140,6 +144,9 @@ int main(int argc, char *argv[]) {
PlyFace face;
for(unsigned v = offset; v < offset + n_faces; v++) {
pf.Read((void *) &face);
face.f[0] += vertex_offset;
face.f[1] += vertex_offset;
face.f[2] += vertex_offset;
assert(face.f[0] < crude.Vertices() &&
face.f[1] < crude.Vertices() &&
face.f[2] < crude.Vertices());

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.7 2004/07/05 15:49:39 ponchio
Windows (DevCpp, mingw) port.
Revision 1.6 2004/07/04 15:23:48 ponchio
Debug
@ -258,59 +261,33 @@ template <class T> class VFile {
Buffer buffer;
buffer.key = chunk;
buffer.data = new T[chunk_size];
buffer.size = chunk_size;
if(buffer.size + chunk * chunk_size > n_elements)
buffer.size = n_elements -chunk * chunk_size;
buffer.size = n_elements - chunk * chunk_size;
buffer.data = new T[buffer.size];
buffers.push_front(buffer);
index[buffer.key] = buffers.begin();
SetPosition(chunk);
ReadBuffer(buffer.data, buffer.size);
/*#ifdef WIN32
if(INVALID_SET_FILE_POINTER == SetFilePointer(fp, chunk * chunk_size * sizeof(T), 0, FILE_BEGIN)) {
#else
if(fseek(fp, chunk * chunk_size * sizeof(T), SEEK_SET)) {
#endif
assert(0 && "failed to fseek");
return *(buffer.data);
}
#ifdef WIN32
unsigned int tmp;
tmp = ReadFile(fp, buffer.data, sizeof(T) * buffer.size, &tmp, NULL);
if(tmp != sizeof(T) * buffer.size)
assert(0 && "failed reading.");
return (*buffer.data);
#else
if(buffer.size != fread(buffer.data, sizeof(T), buffer.size, fp)) {
if(feof(fp)) {
assert(0 && "end of file");
} else {
assert(0 && "failed reading!");
}
return (*buffer.data);
}
#endif
*/
return *(buffer.data + offset);
}
void PushBack(const T &t) {
Resize(n_elements+1);
operator[](n_elements-1) = t;
}
/** you can get a region instead of an element but:
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) {
assert(start + size <= n_elements);
assert((size % chunk_size) == 0);
assert((start % chunk_size) == 0);
if(size == 0) return NULL;
unsigned int chunk = start/chunk_size;
unsigned int offset = start - chunk*chunk_size;
assert(offset == 0);
if(index.count(chunk))
return ((*(index[chunk])).data);
@ -324,32 +301,22 @@ template <class T> class VFile {
Buffer buffer;
buffer.key = chunk;
buffer.data = new T[chunk_size * size];
buffer.size = chunk_size * size;
if(buffer.size + chunk * chunk_size > n_elements)
buffer.size = -chunk * chunk_size + n_elements;
buffer.size = size;
buffer.data = new T[buffer.size];
buffers.push_front(buffer);
index[chunk] = buffers.begin();
SetPosition(chunk);
ReadBuffer(buffer.data, buffer.size);
/*if(fseek(fp, chunk * chunk_size * sizeof(T), SEEK_SET)) {
assert(0 && "failed to fseek");
return buffer.data;
}
if(buffer.size != fread(buffer.data, sizeof(T), buffer.size, fp)) {
if(feof(fp)) {
assert(0 && "end of file");
} else {
assert(0 && "failed reading!");
}
return buffer.data;
} */
return buffer.data;
}
void PushBack(const T &t) {
Resize(n_elements+1);
operator[](n_elements-1) = t;
}
unsigned int Size() { return n_elements; }
unsigned int ChunkSize() { return chunk_size; }
unsigned int QueueSize() { return queue_size; }

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.2 2004/07/05 15:49:39 ponchio
Windows (DevCpp, mingw) port.
Revision 1.1 2004/07/04 15:30:00 ponchio
Changed directory structure.
@ -188,6 +191,9 @@ int main(int argc, char *argv[]) {
if(!pp.count(patch))
totvert++;
vert_remap.Insert(face[k], patch);
// if(i > 240000 && (i%100)==0) {
// cerr << "inserted " << i << " face: " << face[k] << " \n";
// }
}
}
watch.Stop();