vcglib/apps/nexus/nexusmt.h

152 lines
2.9 KiB
C
Raw Normal View History

2004-09-17 17:25:59 +02:00
#ifndef NXS_NEXUS_MT_H
#define NXS_NEXUS_MT_H
#include "nexus.h"
2004-09-28 12:26:35 +02:00
#include <vector>
#include <queue>
2004-09-17 17:25:59 +02:00
2004-09-28 12:26:35 +02:00
#include <wrap/gui/frustum.h>
2004-09-17 17:25:59 +02:00
2004-09-28 12:26:35 +02:00
namespace nxs {
2004-09-17 17:25:59 +02:00
2004-10-14 15:42:33 +02:00
typedef std::vector<unsigned int> Frag;
2004-09-28 12:26:35 +02:00
struct Node {
std::vector<Node *> in;
std::vector<Node *> out;
std::vector<Frag> frags;
float error;
2004-10-14 15:42:33 +02:00
bool visited;
bool pushed;
};
struct TNode {
float error;
Node *node;
TNode(Node *n, float e): node(n), error(e) {}
bool operator<(const TNode &n) { return error < n.error; }
2004-09-28 12:26:35 +02:00
};
2004-10-15 18:45:27 +02:00
2004-10-14 15:42:33 +02:00
class Metric {
2004-09-28 12:26:35 +02:00
public:
2004-10-14 15:42:33 +02:00
vector<Nexus::PatchInfo> *index;
2004-10-19 06:05:56 +02:00
float GetError(Node *node);
float GetError(Frag &frag);
virtual float GetError(unsigned int cell) = 0;
2004-10-14 15:42:33 +02:00
virtual void GetView() {}
2004-09-28 12:26:35 +02:00
};
2004-09-17 17:25:59 +02:00
2004-10-14 15:42:33 +02:00
class FlatMetric: public Metric {
2004-09-28 12:26:35 +02:00
public:
2004-10-14 15:42:33 +02:00
void GetView() {}
2004-10-19 06:05:56 +02:00
float GetError(unsigned int cell);
2004-10-14 15:42:33 +02:00
};
class DeltaMetric: public Metric {
public:
vcg::Point3f delta;
void GetView() {}
2004-10-19 06:05:56 +02:00
float GetError(unsigned int cell);
2004-10-14 15:42:33 +02:00
};
class FrustumMetric: public Metric {
public:
vcg::Frustumf frustum;
2004-09-30 02:27:42 +02:00
2004-09-28 12:26:35 +02:00
void GetView() { frustum.GetView(); }
2004-10-19 06:05:56 +02:00
float GetError(unsigned int cell);
2004-10-14 15:42:33 +02:00
};
class Policy {
public:
float error;
int ram_used;
int ram_size;
vector<PatchEntry> *entries;
void Init();
bool Expand(TNode &node);
void NodeVisited(Node *node);
2004-09-28 12:26:35 +02:00
};
class NexusMt: public Nexus {
private:
2004-09-17 17:25:59 +02:00
std::vector<Node> nodes;
2004-09-28 12:26:35 +02:00
2004-09-17 17:25:59 +02:00
public:
2004-09-30 02:27:42 +02:00
//Vertex buffer object mode
2004-10-15 18:45:27 +02:00
enum Vbo { VBO_AUTO, //autodetect best size
2004-09-30 02:27:42 +02:00
VBO_OFF, //no vertex buffer object
VBO_FIXED }; //user supplied size
2004-10-14 15:42:33 +02:00
enum MetricKind { FRUSTUM, //screen error extraction
GEOMETRY, //geometry error extraction
DELTA }; //delta error
2004-09-30 02:27:42 +02:00
enum Mode { POINTS,
SMOOTH,
XRAY,
HIDDEN_LINE,
FLAT_WIRE,
2004-10-01 01:56:33 +02:00
FLAT,
DEBUG };
2004-09-30 02:27:42 +02:00
enum Component { COLOR = 0x1,
NORMAL = 0x2,
TEXTURE = 0x4,
DATA = 0x8};
2004-10-15 18:45:27 +02:00
Vbo vbo_mode;
2004-09-30 02:27:42 +02:00
2004-10-14 15:42:33 +02:00
Metric *metric;
Policy policy;
2004-09-30 02:27:42 +02:00
Mode mode;
unsigned int components;
bool use_normals;
bool use_colors;
bool use_textures;
bool use_data;
2004-10-14 15:42:33 +02:00
//statistics:
unsigned int tri_rendered;
unsigned int tri_total;
2004-09-30 02:27:42 +02:00
NexusMt();
~NexusMt();
2004-09-30 02:27:42 +02:00
2004-10-10 19:19:42 +02:00
bool Load(const std::string &filename, bool readonly = true);
2004-10-15 18:45:27 +02:00
bool InitGL(Vbo mode = VBO_AUTO, unsigned int vbo_size = 0);
2004-09-30 02:27:42 +02:00
void Render();
2004-10-15 18:45:27 +02:00
2004-10-14 15:42:33 +02:00
void SetMetric(MetricKind kind);
void SetError(float error);
2004-10-15 18:45:27 +02:00
void SetRamExtractionSize(unsigned int ram_size);
void SetVboSize(unsigned int vbo_size);
2004-10-14 15:42:33 +02:00
2004-09-30 02:27:42 +02:00
bool SetMode(Mode mode);
bool SetComponent(Component c, bool on);
bool SetComponents(unsigned int mask);
2004-10-14 15:42:33 +02:00
2004-10-30 22:17:03 +02:00
void Draw(std::vector<unsigned int> &selected);
2004-10-14 15:42:33 +02:00
void Extract(std::vector<unsigned int> &selected);
2004-09-17 17:25:59 +02:00
2004-09-28 12:26:35 +02:00
protected:
2004-09-30 02:27:42 +02:00
void LoadHistory();
void ClearHistory();
2004-10-14 15:42:33 +02:00
void VisitNode(Node *node, std::vector<TNode> &heap);
2004-09-28 12:26:35 +02:00
void Select(std::vector<unsigned int> &selected);
Patch &LoadPatch(unsigned int p);
2004-09-17 17:25:59 +02:00
};
}
2004-09-28 12:26:35 +02:00
2004-09-17 17:25:59 +02:00
#endif