Windows porting small changes.

This commit is contained in:
Federico Ponchio 2004-10-09 14:46:47 +00:00
parent 3532708a3a
commit a466e95b83
8 changed files with 64 additions and 45 deletions

View File

@ -25,7 +25,7 @@ bool BorderServer::ResizeBorder(unsigned int border, unsigned int nbord) {
assert(border < borders.size());
BorderEntry &entry = borders[border];
if(nbord > entry.border_size) {
unsigned int capacity = nbord;
int capacity = nbord;
if(capacity < entry.border_size*2)
capacity = entry.border_size * 2;
unsigned int newstart = Size();

View File

@ -58,11 +58,11 @@ class Nexus {
Patch &GetPatch(unsigned int patch, bool flush = true);
Border GetBorder(unsigned int patch, bool flush = true);
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; }
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; }
//MOVE to nexus_build.cpp
void Join(const std::set<unsigned int> &patches,

View File

@ -85,7 +85,7 @@ void NexusMt::Render() {
glEnableClientState(GL_NORMAL_ARRAY);
//TODO textures and data.
for(unsigned int i = 0; i < cells.size(); i++) {
for(unsigned int i = 0; i < cells.size(); i++) {
unsigned int cell = cells[i];
Nexus::PatchInfo &entry = index[cell];
@ -154,6 +154,7 @@ void NexusMt::SetVbo(Vbo _vbo, unsigned int _vbo_size,
bool NexusMt::SetMode(Mode _mode) {
mode = _mode;
return true;
}
bool NexusMt::SetComponent(Component c, bool on) {
@ -168,13 +169,14 @@ bool NexusMt::SetComponent(Component c, bool on) {
components = COLOR * use_colors + NORMAL * use_normals +
TEXTURE * use_textures + DATA * use_data;
return true;
}
bool NexusMt::SetComponents(unsigned int mask) {
SetComponent(COLOR, mask & COLOR);
SetComponent(NORMAL, mask & NORMAL);
SetComponent(TEXTURE, mask & TEXTURE);
SetComponent(DATA, mask & DATA);
SetComponent(COLOR, (mask & COLOR) != 0);
SetComponent(NORMAL, (mask & NORMAL) != 0);
SetComponent(TEXTURE, (mask & TEXTURE) != 0);
SetComponent(DATA, (mask & DATA) != 0);
components = mask;
@ -206,7 +208,7 @@ void NexusMt::LoadHistory() {
for(unsigned int i = 0; i < (*u).created.size(); i++) {
unsigned int cell = (*u).created[i];
if(index[cell].error > node.error)
node.error = index[cell].error;
node.error = index[cell].error;
cell_node[cell] = current_node;
}

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.11 2004/10/04 16:49:54 ponchio
Daily backup. Preparing for compression.
Revision 1.10 2004/10/01 16:54:57 ponchio
Daily backup.
@ -72,15 +75,21 @@ Created
****************************************************************************/
#include <apps/nexus/nexusmt.h>
#include <iostream>
using namespace std;
#include <SDL/SDL.h>
#ifdef WIN32
#include <windows.h>
#endif
#include <GL/gl.h>
#include <GL/glu.h>
#include <apps/nexus/nexusmt.h>
#include <wrap/gui/trackball.h>
@ -140,7 +149,7 @@ int main(int argc, char *argv[]) {
float error = 4;
Trackball track;
int option;
// int option;
if(argc != 2) {
cerr << "Usage: " << argv[0] << " <nexus file>\n";
@ -218,11 +227,11 @@ int main(int argc, char *argv[]) {
case SDLK_r:
case SDLK_SPACE: rotate = !rotate; break;
case SDLK_MINUS: error *= 0.9;
case SDLK_MINUS: error *= 0.9f;
cerr << "error: " << error << endl; break;
case SDLK_EQUALS:
case SDLK_PLUS: error *= 1.1;
case SDLK_PLUS: error *= 1.1f;
cerr << "error: " << error << endl; break;
}
break;
@ -236,11 +245,14 @@ int main(int argc, char *argv[]) {
case SDL_MOUSEBUTTONDOWN:
x = event.button.x;
y = height - event.button.y;
#ifdef SDL_BUTTON_WHEELUP
if(event.button.button == SDL_BUTTON_WHEELUP)
track.MouseWheel(1);
else if(event.button.button == SDL_BUTTON_WHEELDOWN)
track.MouseWheel(-1);
else if(event.button.button == SDL_BUTTON_LEFT)
else
#endif
if(event.button.button == SDL_BUTTON_LEFT)
track.MouseDown(x, y, Trackball::BUTTON_LEFT);
else if(event.button.button == SDL_BUTTON_RIGHT)
track.MouseDown(x, y, Trackball::BUTTON_RIGHT);
@ -297,7 +309,7 @@ int main(int argc, char *argv[]) {
Point3f &p = nexus.sphere.Center();
float r = nexus.sphere.Radius();
glColor3f(0.8, 0.8, 0.8);
glColor3f(0.8f, 0.8f, 0.8f);
nexus.SetMode(mode);
nexus.SetPolicy(policy, error);
nexus.SetComponent(NexusMt::COLOR, show_colors);

View File

@ -45,7 +45,7 @@ void nxs::ComputeNormals(Nexus &nexus) {
}
if(nexus.signature & NXS_STRIP)
for(unsigned int i = 0; i < patch.nf-2; i++) {
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]);
@ -166,7 +166,7 @@ void nxs::ComputeTriStrip(unsigned short nfaces, unsigned short *faces,
vector<unsigned int> index;
index.resize(nfaces*3);
for(unsigned int i = 0; i < nfaces*3; i++) {
for(int i = 0; i < nfaces*3; i++) {
index[i] = faces[i];
}
int cache_size = 0;
@ -185,7 +185,7 @@ void nxs::ComputeTriStrip(unsigned short nfaces, unsigned short *faces,
tri_stripper::primitives p;
p = primitives.back();
primitives.pop_back();
for(int i = 0; i < p.m_Indices.size(); i += 3) {
for(unsigned int i = 0; i < p.m_Indices.size(); i += 3) {
tri_stripper::primitives s;
s.m_Type = tri_stripper::PT_Triangle_Strip;
s.m_Indices.push_back(p.m_Indices[i]);
@ -198,7 +198,7 @@ void nxs::ComputeTriStrip(unsigned short nfaces, unsigned short *faces,
for(unsigned int i = 0; i < primitives.size(); i++) {
tri_stripper::primitives &primitive = primitives[i];
assert(primitive.m_Indices.size() != 0);
unsigned int len = primitive.m_Indices.size();
int len = primitive.m_Indices.size();
for(int l = 0; l < len; l++)
strip.push_back(primitive.m_Indices[l]);

View File

@ -8,7 +8,7 @@ using namespace nxs;
using namespace vcg;
#ifdef WIN32
#include "getopt.h"
#include <wrap/system/getopt.h>
#else
#include <unistd.h>
#endif

View File

@ -1,6 +1,7 @@
#include "patchserver.h"
#include <iostream>
#include <algorithm>
using namespace std;
using namespace nxs;
@ -14,6 +15,7 @@ bool PatchServer::Create(const std::string &filename,
unsigned int rsize) {
signature = sig;
chunk_size = csize;
frame = 0;
ram_size = rsize;
ram_used = 0;
lru.clear();
@ -26,13 +28,13 @@ bool PatchServer::Load(const std::string &filename, Signature sig,
signature = sig;
chunk_size = csize;
ram_size = rsize;
frame = 0;
ram_used = 0;
lru.clear();
return File::Load(filename, readonly);
}
void PatchServer::Close() {
cerr << "Closing!" << endl;
void PatchServer::Close() {
FlushAll();
File::Close();
}
@ -98,10 +100,10 @@ Patch &PatchServer::GetPatch(unsigned int idx,
lru.push_back(PTime(idx, frame++));
ram_used += entry.ram_used;
}
//avoid frame overflow!
if(frame > (1<<30)) {
cerr << "oVERFLOW!" << endl;;
cerr << "oVERFLOW! (nothing dangerous... just warning." << endl;;
for(unsigned int i = 0; i < lru.size(); i++) {
if(lru[i].frame < (1<<29)) lru[i].frame = 0;
else lru[i].frame -= (1<<29);

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.9 2004/10/08 15:12:04 ponchio
Working version (maybe)
Revision 1.8 2004/10/04 16:49:54 ponchio
Daily backup. Preparing for compression.
@ -64,9 +67,9 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
unsigned int f_cells = crude.Faces() / mean_size;
unsigned int c_cells = (unsigned int)(scaling * f_cells);
cerr << "mean size: " << mean_size << endl;
cerr << "f cells: " << f_cells << endl;
cerr << "c_cells: " << c_cells << endl;
//cerr << "mean size: " << mean_size << endl;
//cerr << "f cells: " << f_cells << endl;
//cerr << "c_cells: " << c_cells << endl;
levels.push_back(VoronoiPartition());
levels.push_back(VoronoiPartition());
@ -77,7 +80,7 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
srand(0);
float fine_vmean = mean_size/2;
float fine_vmean = mean_size/2.0f;
float coarse_vmean = (mean_size/scaling)/2;
for(unsigned int i = 0; i < crude.Vertices(); i++) {
int f = (int)(fine_vmean*rand()/(RAND_MAX + 1.0));
@ -92,8 +95,8 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
}
}
//TODO! Check for duplicates (use the closest :P)
cerr << "fine_seeds.size: " << fine.size() << endl;
cerr << "coarse_seeds.size: " << coarse.size() << endl;
//cerr << "fine_seeds.size: " << fine.size() << endl;
//cerr << "coarse_seeds.size: " << coarse.size() << endl;
fine.Init();
coarse.Init();
@ -101,7 +104,7 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
//Fine optimization.
vector<Point3f> fcentroids;
vector<unsigned int> fcount;
for(unsigned int i = 0; i < steps; i++) {
for(int i = 0; i < steps; i++) {
cerr << "Optimization step 0: " << i << "/" << steps << endl;
fcentroids.clear();
fcount.clear();
@ -117,8 +120,8 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
}
for(unsigned int v = 0; v < fine.size(); v++) {
if(fcount[v] == 0) continue;
fine[v].p = fcentroids[v]/fcount[v];
fine[v].weight = pow(fcount[v]/(float)fine_vmean, 0.3f);
fine[v].p = fcentroids[v]/(float)fcount[v];
fine[v].weight = (float)pow(fcount[v]/(float)fine_vmean, 0.3f);
}
fine.Init();
}
@ -129,7 +132,7 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
if(fcount[i] > min_size)
seeds.push_back(fine[i]);
}
swap(fine, seeds);
swap((std::vector<Seed>)fine, seeds);
if(fine.size() == 0) fine.push_back(Point3f(0,0,0));
fine.Init();
@ -137,7 +140,7 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
//Coarse optimization.
vector<Point3f> ccentroids;
vector<unsigned int> ccount;
for(unsigned int i = 0; i < steps; i++) {
for(int i = 0; i < steps; i++) {
cerr << "Optimization step 0: " << i << "/" << steps << endl;
ccentroids.clear();
ccount.clear();
@ -154,8 +157,8 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
for(unsigned int v = 0; v < coarse.size(); v++) {
if(ccount[v] == 0) continue;
coarse[v].p = ccentroids[v]/ccount[v];
coarse[v].weight = pow(ccount[v]/(float)coarse_vmean, 0.3f);
coarse[v].p = ccentroids[v]/(float)ccount[v];
coarse[v].weight = (float)pow(ccount[v]/(float)coarse_vmean, 0.3f);
}
coarse.Init();
}
@ -167,7 +170,7 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
if(ccount[i] > (int)min_size)
seeds.push_back(coarse[i]);
}
swap(coarse, seeds);
swap((std::vector<Seed>)coarse, seeds);
if(coarse.size() == 0) coarse.push_back(Point3f(0,0,0));
coarse.Init();
@ -367,7 +370,7 @@ void VoronoiChain::BuildLevel(Nexus &nexus, unsigned int offset,
//Coarse optimization.
vector<Point3f> ccentroids;
vector<unsigned int> ccount;
for(unsigned int i = 0; i < steps; i++) {
for(int i = 0; i < steps; i++) {
cerr << "Optimization step 0: " << i << "/" << steps << endl;
ccentroids.clear();
ccount.clear();
@ -388,9 +391,9 @@ void VoronoiChain::BuildLevel(Nexus &nexus, unsigned int offset,
for(unsigned int v = 0; v < coarse.size(); v++) {
if(ccount[v] == 0) continue;
coarse[v].p = ccentroids[v]/ccount[v];
coarse[v].p = ccentroids[v]/(float)ccount[v];
//0.3 is related to the fact is doubled the box size.
coarse[v].weight = pow(ccount[v]/(float)coarse_vmean, 0.3f);
coarse[v].weight = (float)pow(ccount[v]/(float)coarse_vmean, 0.3f);
// fine.bbox.Add(fine[v].p);
}
// fine.Init(fine.bbox);
@ -401,7 +404,7 @@ void VoronoiChain::BuildLevel(Nexus &nexus, unsigned int offset,
if(ccount[i] > (int)min_size)
seeds.push_back(coarse[i]);
}
swap(coarse, seeds);
swap((vector<Seed>)coarse, seeds);
if(coarse.size() == 0) coarse.push_back(Point3f(0,0,0));
coarse.Init();