vcglib/apps/nexus/nxsedit.cpp

671 lines
20 KiB
C++
Raw Normal View History

2005-02-08 13:43:03 +01:00
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
* Copyright(C) 2004 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
/****************************************************************************
History
$Log: not supported by cvs2svn $
Revision 1.26 2005/02/22 10:38:14 ponchio
Debug, cleaning and optimization.
2005-02-22 11:38:17 +01:00
Revision 1.25 2005/02/21 17:55:47 ponchio
debug debug debug
2005-02-21 18:55:49 +01:00
Revision 1.24 2005/02/20 19:49:44 ponchio
cleaning (a bit more).
2005-02-20 20:49:44 +01:00
Revision 1.23 2005/02/20 18:07:01 ponchio
cleaning.
2005-02-20 19:07:01 +01:00
Revision 1.22 2005/02/20 00:43:24 ponchio
Less memory x extraction. (removed frags)
Revision 1.21 2005/02/19 17:14:02 ponchio
History quick by default.
2005-02-19 18:14:02 +01:00
Revision 1.20 2005/02/19 10:45:04 ponchio
Patch generalized and small fixes.
2005-02-19 11:45:05 +01:00
Revision 1.19 2005/02/18 13:04:13 ponchio
Added patch reordering.
2005-02-18 14:04:13 +01:00
Revision 1.18 2005/02/08 12:43:03 ponchio
Added copyright
2005-02-08 13:43:03 +01:00
****************************************************************************/
2004-10-30 22:17:03 +02:00
#ifdef WIN32
#include <wrap/system/getopt.h>
#else
#include <unistd.h>
#endif
#include <assert.h>
2004-09-30 03:24:45 +02:00
#include <iostream>
2004-10-30 22:17:03 +02:00
#include <vcg/simplex/vertex/with/vc.h>
#include <vcg/simplex/face/face.h>
#include <vcg/complex/trimesh/base.h>
//WARNING WARNING this must be included AFTER mesh includes....
#include <wrap/io_trimesh/import_ply.h>
#include <vcg/space/index/grid_static_ptr.h>
2004-09-30 03:24:45 +02:00
2004-10-01 01:56:33 +02:00
#include "nxsalgo.h"
2005-02-22 11:38:17 +01:00
#include "strip.h"
2004-09-30 03:24:45 +02:00
#include "nexus.h"
2004-10-21 14:22:21 +02:00
#include "watch.h"
2004-09-30 03:24:45 +02:00
using namespace nxs;
using namespace vcg;
2004-10-30 22:17:03 +02:00
using namespace std;
using namespace tri;
2004-09-30 03:24:45 +02:00
2004-10-30 22:17:03 +02:00
class CFace;
2004-09-30 03:24:45 +02:00
2004-10-30 22:17:03 +02:00
class CVertex: public VertexVCf<DUMMYEDGETYPE,CFace ,DUMMYTETRATYPE> {};
2004-10-11 18:03:18 +02:00
2004-10-30 22:17:03 +02:00
class CFace: public Face<CVertex, DUMMYEDGETYPE , CFace>{};
class CMesh: public tri::TriMesh<vector<CVertex>, vector<CFace> > {};
2004-10-11 18:03:18 +02:00
2005-02-19 11:45:05 +01:00
string getSuffix(Signature &signature) {
2004-10-01 18:54:57 +02:00
string suff;
2005-02-19 11:45:05 +01:00
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";
2004-10-01 18:54:57 +02:00
return suff;
}
2005-02-20 19:07:01 +01:00
void printInfo(Nexus &nexus, bool verbose, bool dump_history);
2004-09-30 03:24:45 +02:00
int main(int argc, char *argv[]) {
string input;
string output;
string plysource;
2005-02-20 19:07:01 +01:00
2004-09-30 03:24:45 +02:00
bool info = false;
2005-01-21 18:09:13 +01:00
bool verbose = false;
2005-02-19 18:14:02 +01:00
bool dump_history = false;
2005-02-20 19:07:01 +01:00
2004-10-10 19:19:42 +02:00
unsigned int ram_size = 128000000;
unsigned int chunk_size = 0;
2004-09-30 03:24:45 +02:00
2005-02-19 11:45:05 +01:00
bool add = false;
bool add_strips = false;
2004-09-30 03:24:45 +02:00
bool add_colors = false;
2005-02-20 19:07:01 +01:00
unsigned char add_normals = 0;
2004-09-30 03:24:45 +02:00
bool add_textures = false;
bool add_data = false;
2005-02-19 11:45:05 +01:00
bool remove = false;
bool remove_strips = false;
2004-09-30 03:24:45 +02:00
bool remove_colors = false;
bool remove_normals = false;
bool remove_textures = false;
bool remove_data = false;
bool compress = false;
bool uncompress = false;
2005-02-20 19:07:01 +01:00
bool zsort = false;
2004-09-30 03:24:45 +02:00
float qvertex = 0;
float qnormal = 0;
float qcolor = 0;
float qtexture = 0;
2005-02-20 19:07:01 +01:00
float cone_threshold = 0;
2004-09-30 03:24:45 +02:00
int option;
2005-02-20 19:07:01 +01:00
while((option = getopt(argc, argv, "ilho:a:r:zxsv:n:k:t:b:c:V:")) != EOF) {
2004-09-30 03:24:45 +02:00
switch(option) {
case 'i': info = true; break;
2005-01-21 18:09:13 +01:00
case 'l': verbose = true; break;
2005-02-19 18:14:02 +01:00
case 'h': dump_history = true; break;
2004-09-30 03:24:45 +02:00
case 'o': output = optarg; break;
2005-02-20 19:07:01 +01:00
case 'p': plysource = optarg; break;
2004-09-30 03:24:45 +02:00
case 'a': {
2005-02-20 19:07:01 +01:00
if(strstr(optarg, "strips")) { add_strips = true; add = true; }
if(strstr(optarg, "colors")) { add_colors = true; add = true; }
if(strstr(optarg, "normals")) {
add_normals = Encodings::SHORT4; add = true; }
if(strstr(optarg, "normalf")) {
add_normals = Encodings::FLOAT3; add = true; }
if(strstr(optarg, "textures")) { add_textures = true; add = true; }
if(strstr(optarg, "data")) { add_data = true; add = true; }
2005-02-19 11:45:05 +01:00
if(add == false) {
2004-09-30 03:24:45 +02:00
cerr << "Invalid -a argument: " << optarg << "\n"
2005-02-19 11:45:05 +01:00
<< "Valid options are: strips, colors, normals, textures, data\n";
2004-09-30 03:24:45 +02:00
return -1;
}
break;
}
case 'r': {
2005-02-19 11:45:05 +01:00
if(strstr(optarg, "strips")) {
cerr << "Strips removing not supported!\n";
2004-09-30 03:24:45 +02:00
return -1;
}
2005-02-20 19:07:01 +01:00
if(strstr(optarg, "colors")) { remove_colors = true; remove = true; }
if(strstr(optarg, "normals")) { remove_normals = true; remove = true; }
if(strstr(optarg, "textures")) { remove_textures = true; remove = true; }
if(strstr(optarg, "data")) { remove_data = true; remove = true; }
2005-02-19 11:45:05 +01:00
if(remove == false) {
2004-09-30 03:24:45 +02:00
cerr << "Invalid -a argument: " << optarg << "\n"
2005-02-20 19:07:01 +01:00
<< "Valid options are: strip, colors, normals, normalf, "
<< "textures, data\n";
2004-09-30 03:24:45 +02:00
return -1;
}
break;
}
2005-02-20 19:07:01 +01:00
2004-09-30 03:24:45 +02:00
case 'z': compress = true; break;
case 'x': uncompress = true; break;
2005-02-18 14:04:13 +01:00
case 's': zsort = true; break;
2004-09-30 03:24:45 +02:00
2005-02-20 19:07:01 +01:00
case 'V': cone_threshold = atof(optarg); break;
2004-10-21 15:40:16 +02:00
case 'v': qvertex = (float)atof(optarg);
2004-09-30 03:24:45 +02:00
if(qvertex == 0) {
cerr << "Invalid value for quantization: " << optarg << endl;
return -1;
}
break;
2004-10-21 15:40:16 +02:00
case 'n': qnormal = (float)atof(optarg);
2004-09-30 03:24:45 +02:00
if(qnormal == 0) {
cerr << "Invalid value for quantization: " << optarg << endl;
return -1;
}
break;
2004-10-21 15:40:16 +02:00
case 'k': qcolor = (float)atof(optarg);
2004-09-30 03:24:45 +02:00
if(qcolor == 0) {
cerr << "Invalid value for quantization: " << optarg << endl;
return -1;
}
break;
2004-10-21 15:40:16 +02:00
case 't': qtexture = (float)atof(optarg);
2004-09-30 03:24:45 +02:00
if(qtexture == 0) {
cerr << "Invalid value for quantization: " << optarg << endl;
return -1;
}
break;
2005-02-20 19:07:01 +01:00
2004-10-10 19:19:42 +02:00
case 'b': ram_size = atoi(optarg);
if(ram_size == 0) {
cerr << "Invalid ram_size: " << optarg << endl;
return -1;
}
break;
case 'c': chunk_size = atoi(optarg);
if(chunk_size == 0) {
cerr << "Invalid chunk_size: " << optarg << endl;
return -1;
}
break;
2004-09-30 03:24:45 +02:00
default: cerr << "Unknown option: " << (char)option << endl;
return -1;
}
}
if(optind != argc - 1) {
cerr << "Usage: " << argv[0] << " <nexus file> [options]\n"
<< " -i : display some info about nexus file\n"
2005-02-19 18:14:02 +01:00
<< " -l : list nodes\n"
<< " -h : list history\n"
2004-09-30 03:24:45 +02:00
<< " -o <file>: output filename (default is adding 00 to nexus)\n"
2005-02-20 19:07:01 +01:00
<< " -a <what>: Add [colors|normals|normalf|strips|textures|data|borders]\n"
2004-09-30 03:24:45 +02:00
<< " -r <what>: As add...\n"
<< " -p <ply> : Ply source for colors or textures or data\n"
<< " -z : compress\n"
<< " -x : uncompress\n"
2005-02-18 14:04:13 +01:00
<< " -s : sort using zcurve\n"
2004-09-30 03:24:45 +02:00
<< " -v<float>: Vertex quantization (float is the 0 level amount)\n"
<< " -n<float>: Normal quantization\n"
<< " -c<float>: Color quantization\n"
2005-02-20 19:07:01 +01:00
<< " -t<float>: Texture quantization\n"
<< " -V<float>: Normal cone threshold [0, 1] (0.95 default)\n\n"
<< " This option will not create a new nexus file\n";
2004-10-01 18:54:57 +02:00
return -1;
2004-09-30 03:24:45 +02:00
}
input = argv[optind];
2004-10-01 18:54:57 +02:00
2005-02-20 19:07:01 +01:00
//Sanity test of options...
if(compress && uncompress) {
cerr << "x and z are obviously exclusive :P\n";
return -1;
}
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;
}
2004-09-30 03:24:45 +02:00
2005-02-20 19:07:01 +01:00
bool compute_cones = false;
if(!add && !remove && !compress && !uncompress && !zsort &&
!qvertex && !qcolor && !qnormal && !qtexture && cone_threshold != 0)
compute_cones = true;
2004-09-30 03:24:45 +02:00
Nexus nexus;
2004-12-15 17:37:55 +01:00
2004-10-10 19:19:42 +02:00
if(!nexus.Load(input, true)) {
2004-10-21 14:22:21 +02:00
cerr << "Could not open nexus file: " << input << "\n";
2004-09-30 03:24:45 +02:00
return -1;
}
2005-01-14 16:25:29 +01:00
nexus.MaxRam() = ram_size / nexus.chunk_size;
2004-09-30 03:24:45 +02:00
2004-10-10 19:19:42 +02:00
2004-09-30 03:24:45 +02:00
//Sanity tests
2005-02-19 11:45:05 +01:00
if(remove_strips && !(nexus.signature.face != Signature::STRIPS)) {
2004-09-30 03:24:45 +02:00
cerr << "Nexus file does not have strips\n";
return -1;
}
2005-02-19 11:45:05 +01:00
if(remove_colors && !nexus.signature.vcolor) {
2004-09-30 03:24:45 +02:00
cerr << "Nexus file does not have colors\n";
return -1;
}
2005-02-19 11:45:05 +01:00
if(remove_normals && !nexus.signature.vnorm) {
2004-09-30 03:24:45 +02:00
cerr << "Nexus file does not have normals\n";
return -1;
}
2005-02-19 11:45:05 +01:00
if(remove_textures && !nexus.signature.vtext) {
2004-09-30 03:24:45 +02:00
cerr << "Nexus file does not have textures\n";
return -1;
}
2005-02-19 11:45:05 +01:00
if(remove_data && !nexus.signature.vdata) {
2004-09-30 03:24:45 +02:00
cerr << "Nexus file does not have data\n";
return -1;
}
2005-02-20 19:07:01 +01:00
if(add_strips && (nexus.signature.face == Signature::STRIPS)) {
cerr << "Nexus file already has strips\n";
return -1;
}
if(add_colors && nexus.signature.vcolor) {
cerr << "Nexus file already has colors\n";
return -1;
}
if(add_normals && nexus.signature.vnorm) {
cerr << "Nexus file already has normals\n";
return -1;
}
if(add_textures && nexus.signature.vtext) {
cerr << "Nexus file already has textures\n";
return -1;
}
if(add_data && nexus.signature.vdata) {
cerr << "Nexus file already has data\n";
return -1;
}
2004-09-30 03:24:45 +02:00
if(nexus.IsCompressed() && compress) {
cerr << "File already compressed.\n";
return -1;
}
if(!nexus.IsCompressed() && uncompress) {
cerr << "File not compressed.\n";
return -1;
}
if(info) {
2005-02-20 19:07:01 +01:00
cout << "Nexus file: " << input << "\n";
printInfo(nexus, verbose, dump_history);
2004-09-30 03:24:45 +02:00
}
2005-02-20 19:07:01 +01:00
2004-09-30 03:24:45 +02:00
//determine if we must proceed:
2005-02-19 11:45:05 +01:00
if(!add && !remove && !compress && !uncompress && !zsort &&
2005-02-20 19:07:01 +01:00
qvertex == 0 && qnormal == 0 && qcolor == 0 && qtexture == 0 &&
cone_threshold == 0) {
nexus.Close();
return 0;
}
if(compute_cones) {//just recalculate normal cones
cerr << "Unimplemented at the moment...\n";
/*vector<NCone3s> cones;
// ComputeCones(Nexus &nexus, float cone_threshold);
nexus.Close();
nexus.Load(intput, false);
for(unsigned int i = 0; i < nexus.size(); i++) {
nexus[i].cone = cones[i];
}*/
2004-09-30 03:24:45 +02:00
nexus.Close();
return 0;
}
2005-02-19 11:45:05 +01:00
2004-10-30 22:17:03 +02:00
CMesh mesh;
GridStaticPtr<CMesh::FaceContainer> grid;
if(add_colors) {
if(!plysource.size()) {
cerr << "No plysource specified when adding color (-p option)\n";
} else {
if(!tri::io::ImporterPLY<CMesh>::Open(mesh, plysource.c_str())) {
cerr << "Could not load ply: " << plysource << endl;
return -1;
}
//calcoliamo il box:
Box3f box;
for(unsigned int i = 0; i < mesh.vert.size(); i++)
box.Add(mesh.vert[i].P());
grid.SetBBox(box);
grid.Set(mesh.face);
2004-10-30 22:17:03 +02:00
}
}
2005-02-19 11:45:05 +01:00
Signature signature = nexus.signature;
if(add_strips) signature.face = Signature::STRIPS;
2005-02-20 19:07:01 +01:00
if(add_normals) signature.vnorm = add_normals;
2005-02-19 11:45:05 +01:00
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;
2004-09-30 03:24:45 +02:00
2004-10-01 18:54:57 +02:00
if(!output.size()) output = input + getSuffix(signature);
2005-02-19 11:45:05 +01:00
if(output == input) {
cerr << "Output and input files are the same.\n"
2005-02-20 19:07:01 +01:00
<< "Use option -o <filename>\n"
2005-02-19 11:45:05 +01:00
<< "You do not want to overwrite your data. Trust me.\n";
return -1;
}
2004-10-01 18:54:57 +02:00
2004-10-21 14:22:21 +02:00
cout << "Writing to nexus: " << output << endl;
2004-10-10 19:19:42 +02:00
2004-09-30 03:24:45 +02:00
Nexus out;
2004-12-15 17:37:55 +01:00
2004-10-10 19:19:42 +02:00
if(!chunk_size)
2005-01-14 16:25:29 +01:00
chunk_size = nexus.chunk_size;
2004-10-10 19:19:42 +02:00
2005-02-19 11:45:05 +01:00
if(!out.Create(output, signature, chunk_size)) {
2004-09-30 03:24:45 +02:00
cerr << "Could not open output: " << output << endl;
return -1;
}
2005-02-19 11:45:05 +01:00
//TODO fix this broken interface (you should not care abou chunk_size
2005-01-14 16:25:29 +01:00
out.MaxRam() = ram_size / out.chunk_size;
2004-10-21 14:22:21 +02:00
//TODO set rambuffer low (or even direct access!)
2005-02-18 14:04:13 +01:00
vector<unsigned int> forward;
vector<unsigned int> backward;
if(zsort)
ZSort(nexus, forward, backward);
2005-01-26 13:46:29 +01:00
//Fixing history
assert(nexus.history.IsQuick());
2005-02-19 18:14:02 +01:00
unsigned int hsize;
char *buffer = nexus.history.Save(hsize);
out.history.Load(hsize, buffer);
2005-01-26 13:46:29 +01:00
2005-02-18 14:04:13 +01:00
if(zsort) {
assert(0);
//TODO FIX THIS...
/* if(out.history.IsQuick()) {
2005-02-18 14:04:13 +01:00
for(unsigned int i = 0; i < out.history.n_frags(); i++)
2005-02-19 18:14:02 +01:00
out.history.frags[i] = backward[out.history.frags[i]];
2005-02-18 14:04:13 +01:00
} else {
for(unsigned int i = 0; i < out.history.updates.size(); i++) {
History::Update &update = out.history.updates[i];
for(unsigned int k = 0; k < update.created.size(); k++)
update.created[k] = backward[update.created[k]];
for(unsigned int k = 0; k < update.erased.size(); k++)
update.erased[k] = backward[update.erased[k]];
}
}*/
2005-02-18 14:04:13 +01:00
}
2005-01-14 16:25:29 +01:00
Report report(nexus.size());
2004-10-21 14:22:21 +02:00
cout << "Copying and allocating...\n";
2005-02-18 14:04:13 +01:00
for(unsigned int p = 0; p < nexus.size(); p++) {
unsigned int patch = p;
2004-10-21 14:22:21 +02:00
report.Step(patch);
2005-02-18 14:04:13 +01:00
if(zsort) patch = forward[patch];
2005-01-14 16:25:29 +01:00
Entry &src_entry = nexus[patch];
Patch &src_patch = nexus.GetPatch(patch);
2005-01-21 18:09:13 +01:00
Border &src_border = nexus.GetBorder(patch);
2004-09-30 03:24:45 +02:00
2004-10-01 01:56:33 +02:00
vector<unsigned short> strip;
2005-02-19 11:45:05 +01:00
if(add_strips) {
2004-10-01 01:56:33 +02:00
ComputeTriStrip(src_patch.nf, src_patch.FaceBegin(), strip);
assert(strip.size() < 65000);
2005-02-22 11:38:17 +01:00
out.AddPatch(src_entry.nvert, strip.size(), src_border.Capacity());
2005-02-19 11:45:05 +01:00
if(verbose) {
cerr << "tri: " << src_patch.nf << " strip: " << strip.size()
<< " ratio: " << (float)strip.size()/(float)src_patch.nf
<< endl;
}
2004-10-01 01:56:33 +02:00
} else
2005-02-22 11:38:17 +01:00
out.AddPatch(src_entry.nvert, src_entry.nface, src_border.Capacity());
2004-10-01 01:56:33 +02:00
2004-09-30 03:24:45 +02:00
2005-02-18 14:04:13 +01:00
Entry &dst_entry = out[p];
Patch &dst_patch = out.GetPatch(p);
2004-10-08 17:12:04 +02:00
2004-10-11 18:03:18 +02:00
//copy vertices:
2005-02-19 11:45:05 +01:00
assert(out.signature.vert == Signature::POINT3F);
assert(out.signature.vert = nexus.signature.vert);
memcpy(dst_patch.Vert3fBegin(), src_patch.Vert3fBegin(),
2004-09-30 03:24:45 +02:00
src_patch.nv * sizeof(Point3f));
2004-10-21 15:40:16 +02:00
if(qvertex && !add_normals) {
2005-02-19 11:45:05 +01:00
float *ptr = (float *)dst_patch.Vert3fBegin();
for(int i = 0; i < dst_patch.nv*3; i++)
ptr[i] = qvertex * (int)(ptr[i]/qvertex);
2004-10-11 18:03:18 +02:00
}
2005-02-19 11:45:05 +01:00
2004-09-30 03:24:45 +02:00
//now faces.
2005-02-19 11:45:05 +01:00
if(add_strips) {
assert(out.signature.face == Signature::STRIPS);
2004-10-01 01:56:33 +02:00
memcpy(dst_patch.FaceBegin(), &*strip.begin(),
strip.size() * sizeof(short));
2004-09-30 03:24:45 +02:00
} else {
2005-02-19 11:45:05 +01:00
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 if(nexus.signature.face == Signature::TRIANGLES) {
memcpy(dst_patch.FaceBegin(), src_patch.FaceBegin(),
src_patch.nf * sizeof(unsigned short) * 3);
2004-10-11 18:03:18 +02:00
} else {
2005-02-19 11:45:05 +01:00
assert(0);
2004-10-11 18:03:18 +02:00
}
2004-09-30 03:24:45 +02:00
}
2005-02-19 11:45:05 +01:00
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);
}
}
2004-10-01 01:56:33 +02:00
2005-02-19 11:45:05 +01:00
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);
}
}
2004-09-30 03:24:45 +02:00
//copying entry information;
dst_entry.sphere = src_entry.sphere;
dst_entry.error = src_entry.error;
2005-02-20 19:07:01 +01:00
dst_entry.cone = src_entry.cone;
2004-09-30 03:24:45 +02:00
2005-02-18 14:04:13 +01:00
out.borders.ResizeBorder(p, src_border.Size());
Border &dst_border = out.GetBorder(p);
2004-09-30 03:24:45 +02:00
memcpy(dst_border.Start(), src_border.Start(),
2004-12-15 17:37:55 +01:00
src_border.Size() * sizeof(Link));
2005-02-19 11:45:05 +01:00
//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];
2004-09-30 03:24:45 +02:00
}
2004-12-15 17:37:55 +01:00
report.Finish();
2004-09-30 03:24:45 +02:00
2004-10-01 01:56:33 +02:00
//TODO this is ok only if we have faces still!
if(add_normals) {
2004-10-21 14:22:21 +02:00
cout << "Computing normals" << endl;
2004-10-01 01:56:33 +02:00
ComputeNormals(out);
}
if(add_colors) {
// if(!plysource.size())
2004-10-01 01:56:33 +02:00
//source of color:
// cerr << "Unsupported color\n";
// return -1;
2004-10-01 01:56:33 +02:00
}
2004-10-30 22:17:03 +02:00
2004-10-21 15:40:16 +02:00
if(qvertex && add_normals) {
2005-01-14 16:25:29 +01:00
report.Init(nexus.size());
2004-10-21 14:22:21 +02:00
cout << "Quantizing vertices\n";
2005-01-14 16:25:29 +01:00
for(unsigned int patch = 0; patch < nexus.size(); patch++) {
2004-10-21 14:22:21 +02:00
report.Step(patch);
Patch src_patch = nexus.GetPatch(patch);
2005-02-19 11:45:05 +01:00
float *ptr = (float *)src_patch.Vert3fBegin();
2004-10-21 15:40:16 +02:00
for(int i = 0; i < src_patch.nv*3; i++)
ptr[i] = qvertex * (int)(ptr[i]/qvertex);
2004-10-21 14:22:21 +02:00
}
report.Finish();
}
2004-09-30 03:24:45 +02:00
out.sphere = nexus.sphere;
2005-01-14 16:25:29 +01:00
2004-09-30 03:24:45 +02:00
out.Close();
nexus.Close();
return 0;
}
2005-02-20 19:07:01 +01:00
void printInfo(Nexus &nexus, bool verbose, bool dump_history) {
//perform locality statistics
double meandist = 0;
vcg::Sphere3f last = nexus[0].sphere;
for(unsigned int i = 1; i < nexus.size(); i++) {
vcg::Sphere3f &sphere = nexus[i].sphere;
double dist = vcg::Distance(last.Center(), sphere.Center());
meandist += dist;
last = sphere;
}
meandist /= nexus.size() -1;
cout << "\n\tCompressed: " << nexus.IsCompressed()
2005-02-20 20:49:44 +01:00
<< "\n\tStripped : "
2005-02-20 19:07:01 +01:00
<< (int)(nexus.signature.face == Signature::STRIPS)
2005-02-20 20:49:44 +01:00
<< "\n\tColor : " << (int)(nexus.signature.vcolor)
<< "\n\tNormal : " << (int)(nexus.signature.vnorm)
<< "\n\tTexture : " << (int)(nexus.signature.vtext)
<< "\n\tData : " << (int)(nexus.signature.vdata)
2005-02-20 19:07:01 +01:00
<< "\n\n\tVertices: " << nexus.totvert
2005-02-20 20:49:44 +01:00
<< "\tFaces : " << nexus.totface
<< "\tPatches : " << nexus.size()
<< "\n\tSphere : "
2005-02-20 19:07:01 +01:00
<< nexus.sphere.Center()[0] << " "
<< nexus.sphere.Center()[1] << " "
<< nexus.sphere.Center()[2] << " R: "
<< nexus.sphere.Radius()
<< "\n\tAverage distance: " << meandist
<< "\n\tChunk size " << nexus.chunk_size << endl;
if(dump_history) {
if(nexus.history.IsQuick()) {
cout << "Quick format\n";
for(unsigned int i = 0; i < nexus.history.n_nodes(); i++) {
cout << "Node: " << i << " out: ";
2005-02-20 20:49:44 +01:00
History::Node node = nexus.history.nodes[i];
for(History::Link *l = node.out_begin; l != node.out_end; l++) {
2005-02-20 19:07:01 +01:00
cout << ".";
2005-02-20 20:49:44 +01:00
for(unsigned int p = l->begin; p != l->end; p++) {
2005-02-20 19:07:01 +01:00
cout << p << " ";
}
}
cout << " in: ";
2005-02-20 20:49:44 +01:00
for(History::Link *j = node.in_begin; j != node.in_end; j++) {
2005-02-20 19:07:01 +01:00
cout << ".";
2005-02-20 20:49:44 +01:00
for(unsigned int p = j->begin; p != j->end; p++) {
2005-02-20 19:07:01 +01:00
cout << p << " ";
}
}
cout << endl;
}
} else {
cout << "Update format\n";
for(unsigned int i = 0; i < nexus.history.updates.size(); i++) {
History::Update &update = nexus.history.updates[i];
cout << "Created: ";
for(unsigned int k = 0; k < update.created.size(); k++) {
cout << update.created[k] << " ";
}
cout << "\nErased: ";
for(unsigned int k = 0; k < update.erased.size(); k++) {
cout << update.erased[k] << " ";
}
cout << "\n\n";
}
}
}
if(verbose) {
for(unsigned int i = 0; i < nexus.size(); i++) {
Entry &entry = nexus[i];
cout << i << " -> nv: " << entry.nvert << " nf: " << entry.nface
<< " error: " << entry.error
<< " disk_size: " << entry.disk_size
<< " start: " << entry.patch_start << endl;
2005-02-21 18:55:49 +01:00
cout << " Cone: " << entry.cone.n[0] << " "
<< entry.cone.n[1] << " "
<< entry.cone.n[2] << " "
<< entry.cone.n[3] << "\n";
2005-02-20 19:07:01 +01:00
}
cout << endl;
}
}