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 $
|
2005-03-02 16:12:50 +01:00
|
|
|
Revision 1.12 2005/03/02 10:40:17 ponchio
|
|
|
|
Extraction rewrittten (to fix recusive problems).
|
|
|
|
|
2005-03-02 11:40:18 +01:00
|
|
|
Revision 1.11 2005/02/20 19:49:44 ponchio
|
|
|
|
cleaning (a bit more).
|
|
|
|
|
2005-02-20 20:49:44 +01:00
|
|
|
Revision 1.10 2005/02/20 18:07:00 ponchio
|
|
|
|
cleaning.
|
|
|
|
|
2005-02-20 19:07:01 +01:00
|
|
|
Revision 1.9 2005/02/20 00:43:23 ponchio
|
|
|
|
Less memory x extraction. (removed frags)
|
|
|
|
|
2005-02-20 01:43:24 +01:00
|
|
|
Revision 1.8 2005/02/19 16:22:45 ponchio
|
|
|
|
Minor changes (visited and Cell)
|
|
|
|
|
2005-02-19 17:22:45 +01:00
|
|
|
Revision 1.7 2005/02/10 09:18:20 ponchio
|
|
|
|
Statistics.
|
|
|
|
|
2005-02-10 10:18:20 +01:00
|
|
|
Revision 1.6 2005/02/08 12:43:03 ponchio
|
|
|
|
Added copyright
|
|
|
|
|
2005-02-08 13:43:03 +01:00
|
|
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
2005-01-14 16:41:10 +01:00
|
|
|
#include "extraction.h"
|
|
|
|
#include "metric.h"
|
2005-03-02 16:12:50 +01:00
|
|
|
#include "nexus.h"
|
2005-01-14 16:41:10 +01:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace nxs;
|
|
|
|
|
2005-03-02 16:12:50 +01:00
|
|
|
/* Updateing strategy:
|
|
|
|
if i can refine (not at leaves,
|
|
|
|
have draw and extr buffer,
|
|
|
|
not past target_error)
|
|
|
|
i try to refine BUT
|
|
|
|
i can fail because i finish some buffer
|
|
|
|
(then i put the operation back on the stack)
|
|
|
|
if i have finished disk i should just quit
|
|
|
|
if i cannot refine i consider coarsening:
|
|
|
|
i need 1) not be at root (eheh)
|
|
|
|
2) have finished draw and extr buffer
|
|
|
|
(unless i am at error < target so i want to coarse
|
|
|
|
3) do not make global error worse
|
|
|
|
(unless it is error < target_error...)
|
|
|
|
a stability term is added (1.1) so that we do not flip
|
|
|
|
nodes in and out quickly
|
|
|
|
i try to coarse BUT
|
|
|
|
i can fail because i need disk
|
|
|
|
(then i put the operation back on the stack)
|
|
|
|
if i cannt coarse i just quit
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-01-21 18:09:13 +01:00
|
|
|
Extraction::Extraction(): target_error(4.0f), extr_max(10000),
|
|
|
|
draw_max(10000), disk_max(100) {
|
2005-01-14 16:41:10 +01:00
|
|
|
metric = new FrustumMetric;
|
|
|
|
}
|
|
|
|
|
|
|
|
Extraction::~Extraction() {
|
|
|
|
if(metric) delete metric;
|
|
|
|
}
|
|
|
|
|
2005-03-02 16:12:50 +01:00
|
|
|
void Extraction::SetMetric(Metric *m) {
|
|
|
|
if(metric)
|
|
|
|
delete metric;
|
|
|
|
metric = m;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Extraction::Extract(Nexus *_mt) {
|
2005-01-14 16:41:10 +01:00
|
|
|
mt = _mt;
|
2005-01-17 18:35:48 +01:00
|
|
|
root = mt->history.Root();
|
|
|
|
sink = root + (mt->history.n_nodes()-1);
|
2005-01-14 16:41:10 +01:00
|
|
|
|
|
|
|
//clear statistics
|
|
|
|
extr_used = draw_used = disk_used = 0;
|
|
|
|
|
|
|
|
//first we clear the visited flags
|
|
|
|
visited.clear();
|
2005-02-20 19:07:01 +01:00
|
|
|
visited.resize(mt->history.n_nodes(), false);
|
|
|
|
visible.clear();
|
|
|
|
visible.resize(mt->size(), true);
|
2005-03-02 16:12:50 +01:00
|
|
|
node_errors.clear();
|
|
|
|
node_errors.resize(mt->history.n_nodes(), -1);
|
2005-01-14 16:41:10 +01:00
|
|
|
|
2005-03-02 11:40:18 +01:00
|
|
|
front.clear();
|
2005-01-14 16:41:10 +01:00
|
|
|
|
|
|
|
Visit(root);
|
|
|
|
|
2005-03-02 11:40:18 +01:00
|
|
|
while(front.size()) {
|
|
|
|
pop_heap(front.begin(), front.end());
|
|
|
|
HeapNode hnode = front.back();
|
|
|
|
front.pop_back();
|
2005-01-14 16:41:10 +01:00
|
|
|
|
2005-01-17 18:35:48 +01:00
|
|
|
Node *node = hnode.node;
|
2005-02-19 17:22:45 +01:00
|
|
|
if(Visited(node)) continue;
|
2005-01-14 16:41:10 +01:00
|
|
|
|
2005-01-17 18:35:48 +01:00
|
|
|
if(Expand(hnode))
|
2005-01-14 16:41:10 +01:00
|
|
|
Visit(node);
|
2005-01-17 18:35:48 +01:00
|
|
|
}
|
|
|
|
Select();
|
|
|
|
draw_size = selected.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Extraction::Init() {
|
2005-03-02 11:40:18 +01:00
|
|
|
//I want to add all coarsable nodes
|
|
|
|
//and all refinable node (being careful about recursive dependencies)
|
|
|
|
for(Node *node = root; node != sink; node++) {
|
|
|
|
if(!Visited(node)) continue;
|
|
|
|
if(node != root && CanCoarse(node))
|
|
|
|
back.push_back(HeapNode(node, GetNodeError(node)));
|
|
|
|
|
|
|
|
for(Node::iterator n = node->out_begin; n != node->out_end; n++) {
|
|
|
|
Node *child = n->node;
|
|
|
|
if(Visited(child)) continue;
|
|
|
|
if(node_errors[child - root] != -1) continue; //already visited
|
|
|
|
|
|
|
|
float *error = GetNodeError(child);
|
|
|
|
if(CanRefine(node)) // TODO? && error > target_error
|
|
|
|
front.push_back(HeapNode(child, error));
|
|
|
|
|
|
|
|
if(*error > max_error) max_error = *error;
|
|
|
|
}
|
|
|
|
}
|
2005-01-17 18:35:48 +01:00
|
|
|
|
2005-03-02 11:40:18 +01:00
|
|
|
//recursively fix error
|
|
|
|
for(Node *node = root; node != sink; node++)
|
|
|
|
if(node_errors[node - root] != -1)
|
|
|
|
SetError(node, node_errors[node-root]);
|
2005-02-20 19:07:01 +01:00
|
|
|
|
2005-03-02 16:12:50 +01:00
|
|
|
|
2005-03-02 11:40:18 +01:00
|
|
|
//estimate cost of all the cut arcs (i need the visible info)
|
|
|
|
Cost cost;
|
|
|
|
for(Node *node = root; node != sink; node++) {
|
|
|
|
if(!Visited(node)) continue;
|
|
|
|
|
|
|
|
for(Node::iterator n = node->out_begin; n != node->out_end; n++) {
|
|
|
|
Link &link = *n;
|
|
|
|
if(Visited((*n).node)) continue;
|
|
|
|
for(unsigned int patch = link.begin; patch != link.end; patch++) {
|
|
|
|
Entry &entry = (*mt)[patch];
|
|
|
|
cost.extr += entry.ram_size;
|
|
|
|
if(Visible(patch)) cost.draw += entry.ram_size;
|
|
|
|
if(!entry.patch) cost.disk += entry.disk_size;
|
|
|
|
}
|
2005-01-14 16:41:10 +01:00
|
|
|
}
|
|
|
|
}
|
2005-03-02 11:40:18 +01:00
|
|
|
|
2005-01-17 18:35:48 +01:00
|
|
|
make_heap(front.begin(), front.end());
|
|
|
|
make_heap(back.begin(), back.end(), greater<HeapNode>());
|
|
|
|
|
|
|
|
extr_used = cost.extr;
|
|
|
|
draw_used = cost.draw;
|
|
|
|
disk_used = cost.disk;
|
|
|
|
}
|
2005-01-14 16:41:10 +01:00
|
|
|
|
2005-03-02 16:12:50 +01:00
|
|
|
void Extraction::Update(Nexus *_mt) {
|
2005-01-17 18:35:48 +01:00
|
|
|
mt = _mt;
|
|
|
|
root = mt->history.Root();
|
2005-03-02 11:40:18 +01:00
|
|
|
sink = mt->history.Sink();
|
2005-01-17 18:35:48 +01:00
|
|
|
|
|
|
|
if(!visited.size()) {
|
|
|
|
visited.resize(mt->history.n_nodes(), false);
|
2005-02-19 17:22:45 +01:00
|
|
|
SetVisited(root, true);
|
2005-02-20 19:07:01 +01:00
|
|
|
}
|
|
|
|
visible.clear();
|
|
|
|
visible.resize(mt->size(), true);
|
2005-03-02 16:12:50 +01:00
|
|
|
node_errors.clear();
|
|
|
|
node_errors.resize(mt->history.n_nodes(), -1);
|
|
|
|
|
|
|
|
front.clear();
|
|
|
|
back.clear();
|
|
|
|
|
|
|
|
max_error = -1;
|
2005-01-17 18:35:48 +01:00
|
|
|
|
|
|
|
Init();
|
2005-01-21 18:09:13 +01:00
|
|
|
|
2005-03-02 11:40:18 +01:00
|
|
|
bool can_refine = true;
|
2005-02-10 10:18:20 +01:00
|
|
|
|
2005-03-02 11:40:18 +01:00
|
|
|
while(1) {
|
|
|
|
while(can_refine) { //we have available budget
|
|
|
|
if(!front.size()) break; //we are at max level
|
|
|
|
if(*front[0].error < target_error) break; //already at target_error
|
|
|
|
|
|
|
|
max_error = *front[0].error;
|
2005-01-21 18:09:13 +01:00
|
|
|
pop_heap(front.begin(), front.end());
|
|
|
|
HeapNode hnode = front.back();
|
|
|
|
front.pop_back();
|
2005-02-20 19:07:01 +01:00
|
|
|
|
2005-03-02 11:40:18 +01:00
|
|
|
if(!Visited(hnode.node) && CanRefine(hnode.node)) {
|
|
|
|
if(!Refine(hnode)) {
|
|
|
|
can_refine = false;
|
|
|
|
front.push_back(hnode);
|
|
|
|
push_heap(front.begin(), front.end());
|
|
|
|
}
|
2005-01-21 18:09:13 +01:00
|
|
|
}
|
|
|
|
}
|
2005-03-02 11:40:18 +01:00
|
|
|
|
|
|
|
if(!back.size()) //nothing to coarse (happen only on extr_max < root.extr)
|
|
|
|
break;
|
2005-01-21 18:09:13 +01:00
|
|
|
|
2005-03-02 11:40:18 +01:00
|
|
|
if(*back.front().error >= target_error &&
|
|
|
|
(!front.size() ||
|
|
|
|
(*back.front().error * 1.4) >= *front.front().error))
|
|
|
|
break;
|
2005-01-21 18:09:13 +01:00
|
|
|
|
2005-01-17 18:35:48 +01:00
|
|
|
pop_heap(back.begin(), back.end(), greater<HeapNode>());
|
|
|
|
HeapNode hnode = back.back();
|
2005-01-21 18:09:13 +01:00
|
|
|
back.pop_back();
|
2005-03-02 11:40:18 +01:00
|
|
|
|
|
|
|
if(Visited(hnode.node) && //not already coarsed
|
|
|
|
CanCoarse(hnode.node) && //all children !visited
|
|
|
|
!Coarse(hnode)) { //no more disk
|
|
|
|
back.push_back(hnode);
|
|
|
|
push_heap(back.begin(), back.end(), greater<HeapNode>());
|
|
|
|
break;
|
2005-01-17 18:35:48 +01:00
|
|
|
}
|
2005-03-02 11:40:18 +01:00
|
|
|
can_refine = true;
|
2005-01-21 18:09:13 +01:00
|
|
|
}
|
2005-01-17 18:35:48 +01:00
|
|
|
|
2005-01-14 16:41:10 +01:00
|
|
|
Select();
|
2005-01-17 18:35:48 +01:00
|
|
|
draw_size = selected.size();
|
|
|
|
|
|
|
|
//Preloading now
|
2005-01-21 18:09:13 +01:00
|
|
|
for(unsigned int i = 0; i < 1000; i++) {
|
2005-01-17 18:35:48 +01:00
|
|
|
if(!front.size() && !back.size()) break;
|
|
|
|
if((i%2) && front.size()) {
|
|
|
|
pop_heap(front.begin(), front.end());
|
|
|
|
HeapNode hnode = front.back();
|
|
|
|
Node *node = hnode.node;
|
|
|
|
front.pop_back();
|
2005-02-03 13:35:01 +01:00
|
|
|
Node::iterator l;
|
2005-02-20 20:49:44 +01:00
|
|
|
for(l = node->out_begin; l != node->out_end; l++) {
|
2005-02-19 17:22:45 +01:00
|
|
|
Link &link = (*l);
|
2005-02-20 20:49:44 +01:00
|
|
|
for(unsigned int k = link.begin; k != link.end; k++) {
|
2005-02-20 01:43:24 +01:00
|
|
|
selected.push_back(Item(k, i));
|
2005-02-19 17:22:45 +01:00
|
|
|
}
|
2005-01-17 18:35:48 +01:00
|
|
|
}
|
|
|
|
} else if(back.size()) {
|
|
|
|
pop_heap(back.begin(), back.end(), greater<HeapNode>());
|
|
|
|
HeapNode hnode = back.back();
|
|
|
|
Node *node = hnode.node;
|
|
|
|
back.pop_back();
|
2005-02-20 20:49:44 +01:00
|
|
|
|
|
|
|
for(Node::iterator l = node->in_begin; l != node->in_end; l++) {
|
2005-02-19 17:22:45 +01:00
|
|
|
Link &link = (*l);
|
2005-02-20 20:49:44 +01:00
|
|
|
for(unsigned int k = link.begin; k != link.end; k++) {
|
2005-02-20 01:43:24 +01:00
|
|
|
selected.push_back(Item(k, i));
|
2005-02-19 17:22:45 +01:00
|
|
|
}
|
2005-01-17 18:35:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-02 11:40:18 +01:00
|
|
|
|
|
|
|
float *Extraction::GetNodeError(Node *node) {
|
|
|
|
float &maxerror = node_errors[node-root];
|
2005-02-20 20:49:44 +01:00
|
|
|
for(Node::iterator i = node->in_begin; i != node->in_end; i++) {
|
2005-01-17 18:35:48 +01:00
|
|
|
Link &link = *i;
|
2005-02-20 20:49:44 +01:00
|
|
|
for(unsigned int p = link.begin; p != link.end; p++) {
|
2005-02-20 01:43:24 +01:00
|
|
|
Entry &entry = (*mt)[p];
|
2005-02-19 17:22:45 +01:00
|
|
|
bool visible;
|
|
|
|
float error = metric->GetError(entry, visible);
|
2005-03-02 11:40:18 +01:00
|
|
|
// cerr << "Error for patch: " << p << " -> " << error << endl;
|
2005-01-17 18:35:48 +01:00
|
|
|
if(error > maxerror) maxerror = error;
|
2005-02-20 19:07:01 +01:00
|
|
|
SetVisible(p, visible);
|
2005-01-17 18:35:48 +01:00
|
|
|
}
|
|
|
|
}
|
2005-03-02 11:40:18 +01:00
|
|
|
return &maxerror;
|
2005-01-17 18:35:48 +01:00
|
|
|
}
|
|
|
|
|
2005-01-21 19:12:45 +01:00
|
|
|
bool Extraction::Refine(HeapNode hnode) {
|
2005-01-21 18:09:13 +01:00
|
|
|
|
|
|
|
Node *node = hnode.node;
|
2005-03-02 11:40:18 +01:00
|
|
|
|
2005-01-17 18:35:48 +01:00
|
|
|
Cost cost;
|
|
|
|
Diff(node, cost);
|
2005-03-02 11:40:18 +01:00
|
|
|
|
|
|
|
if(disk_used + cost.disk > disk_max ||
|
|
|
|
extr_used + cost.extr > extr_max ||
|
|
|
|
draw_used + cost.draw > draw_max)
|
2005-01-21 18:09:13 +01:00
|
|
|
return false;
|
2005-03-02 11:40:18 +01:00
|
|
|
|
2005-01-17 18:35:48 +01:00
|
|
|
extr_used += cost.extr;
|
|
|
|
draw_used += cost.draw;
|
|
|
|
disk_used += cost.disk;
|
|
|
|
|
2005-02-19 17:22:45 +01:00
|
|
|
SetVisited(node, true);
|
2005-01-17 18:35:48 +01:00
|
|
|
|
|
|
|
//now add to the front children (unless sink node)
|
|
|
|
|
2005-02-20 20:49:44 +01:00
|
|
|
for(Node::iterator i = node->out_begin; i != node->out_end; i++) {
|
2005-01-17 18:35:48 +01:00
|
|
|
Link &link = *i;
|
|
|
|
if(link.node == sink) continue;
|
|
|
|
|
2005-03-02 11:40:18 +01:00
|
|
|
float *error = &node_errors[link.node - root];
|
|
|
|
if(*error == -1)
|
|
|
|
error = GetNodeError(link.node);
|
|
|
|
if(*hnode.error < *error) *hnode.error = *error;
|
|
|
|
//TODO if(maxerror > target_error)
|
|
|
|
if(CanRefine((*i).node)) {
|
|
|
|
front.push_back(HeapNode((*i).node, error));
|
|
|
|
push_heap(front.begin(), front.end());
|
|
|
|
}
|
2005-01-17 18:35:48 +01:00
|
|
|
}
|
2005-01-21 18:09:13 +01:00
|
|
|
|
|
|
|
back.push_back(hnode);
|
|
|
|
push_heap(back.begin(), back.end(), greater<HeapNode>());
|
2005-01-17 18:35:48 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-01-21 19:12:45 +01:00
|
|
|
bool Extraction::Coarse(HeapNode hnode) {
|
2005-01-17 18:35:48 +01:00
|
|
|
Node *node = hnode.node;
|
2005-01-21 18:09:13 +01:00
|
|
|
|
2005-01-17 18:35:48 +01:00
|
|
|
Cost cost;
|
|
|
|
Diff(node, cost);
|
2005-03-02 11:40:18 +01:00
|
|
|
|
2005-01-17 18:35:48 +01:00
|
|
|
extr_used -= cost.extr;
|
|
|
|
draw_used -= cost.draw;
|
|
|
|
disk_used -= cost.disk;
|
|
|
|
|
|
|
|
if(disk_used > disk_max) return false;
|
|
|
|
|
2005-02-19 17:22:45 +01:00
|
|
|
SetVisited(node, false);
|
2005-01-17 18:35:48 +01:00
|
|
|
|
|
|
|
//now add to the back parents (unless root node)
|
2005-02-20 20:49:44 +01:00
|
|
|
for(Node::iterator i = node->in_begin; i != node->in_end; i++) {
|
2005-01-17 18:35:48 +01:00
|
|
|
Link &link = *i;
|
|
|
|
if(link.node == root) continue;
|
|
|
|
|
2005-03-02 11:40:18 +01:00
|
|
|
float *error = &node_errors[link.node - root];
|
|
|
|
if(*error == -1)
|
|
|
|
error = GetNodeError(link.node);
|
|
|
|
if(*error < *hnode.error) *error = *hnode.error;
|
|
|
|
|
|
|
|
if(CanCoarse(link.node)) {
|
|
|
|
back.push_back(HeapNode(link.node, error));
|
|
|
|
push_heap(back.begin(), back.end(), greater<HeapNode>());
|
|
|
|
}
|
2005-01-17 18:35:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
front.push_back(hnode);
|
|
|
|
push_heap(front.begin(), front.end());
|
|
|
|
return true;
|
2005-01-14 16:41:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Extraction::Select() {
|
|
|
|
selected.clear();
|
2005-01-17 18:35:48 +01:00
|
|
|
Node *root = mt->history.Root();
|
2005-01-14 16:41:10 +01:00
|
|
|
|
2005-01-17 18:35:48 +01:00
|
|
|
Node *nodes = mt->history.nodes;
|
2005-01-14 16:41:10 +01:00
|
|
|
for(unsigned int i = 0; i < visited.size(); i++) {
|
|
|
|
if(!visited[i]) continue;
|
2005-01-17 18:35:48 +01:00
|
|
|
Node &node = nodes[i];
|
2005-01-14 16:41:10 +01:00
|
|
|
|
2005-01-17 18:35:48 +01:00
|
|
|
Node::iterator n;
|
2005-02-20 20:49:44 +01:00
|
|
|
for(n = node.out_begin; n != node.out_end; n++) {
|
2005-01-14 16:41:10 +01:00
|
|
|
unsigned int n_out = (*n).node - root;
|
|
|
|
if(!visited[n_out]) {
|
2005-01-17 18:35:48 +01:00
|
|
|
Link &link = *n;
|
2005-02-20 20:49:44 +01:00
|
|
|
for(unsigned int p = link.begin; p != link.end; p++) {
|
2005-02-20 01:43:24 +01:00
|
|
|
selected.push_back(Item(p, 0));
|
2005-01-14 16:41:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-17 18:35:48 +01:00
|
|
|
void Extraction::Visit(Node *node) {
|
2005-02-19 17:22:45 +01:00
|
|
|
assert(!Visited(node));
|
2005-01-14 16:41:10 +01:00
|
|
|
|
2005-02-19 17:22:45 +01:00
|
|
|
SetVisited(node, true);
|
2005-01-14 16:41:10 +01:00
|
|
|
|
2005-02-20 20:49:44 +01:00
|
|
|
for(Node::iterator i = node->in_begin; i != node->in_end; i++) {
|
2005-02-19 17:22:45 +01:00
|
|
|
if(Visited((*i).node)) continue;
|
2005-01-14 16:41:10 +01:00
|
|
|
Visit((*i).node);
|
|
|
|
}
|
|
|
|
|
2005-01-17 18:35:48 +01:00
|
|
|
Cost cost;
|
|
|
|
Diff(node, cost);
|
|
|
|
extr_used += cost.extr;
|
|
|
|
draw_used += cost.draw;
|
|
|
|
disk_used += cost.disk;
|
|
|
|
|
2005-02-20 20:49:44 +01:00
|
|
|
for(Node::iterator i = node->out_begin; i != node->out_end; i++) {
|
2005-01-21 18:09:13 +01:00
|
|
|
float maxerror = -1;
|
2005-01-17 18:35:48 +01:00
|
|
|
Link &link = *i;
|
2005-02-20 20:49:44 +01:00
|
|
|
for(unsigned int p = link.begin; p != link.end; p++) {
|
2005-02-20 01:43:24 +01:00
|
|
|
Entry &entry = (*mt)[p];
|
2005-02-19 17:22:45 +01:00
|
|
|
bool visible;
|
|
|
|
float error = metric->GetError(entry, visible);
|
2005-01-14 16:41:10 +01:00
|
|
|
if(error > maxerror) maxerror = error;
|
2005-02-20 19:07:01 +01:00
|
|
|
SetVisible(p, visible);
|
2005-01-14 16:41:10 +01:00
|
|
|
}
|
|
|
|
//TODO this check may be dangerous for non saturating things...
|
|
|
|
if(maxerror > target_error) {
|
2005-03-02 11:40:18 +01:00
|
|
|
node_errors[(*i).node - root] = maxerror;
|
|
|
|
HeapNode hnode((*i).node, &node_errors[(*i).node - root]);
|
|
|
|
front.push_back(hnode);
|
|
|
|
push_heap(front.begin(), front.end());
|
2005-01-14 16:41:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Extraction::Expand(HeapNode &node) {
|
|
|
|
if(extr_used >= extr_max) return false;
|
|
|
|
if(draw_used >= draw_max) return false;
|
|
|
|
// if(disk_used >= disk_max) return false;
|
2005-03-02 11:40:18 +01:00
|
|
|
return *node.error > target_error;
|
2005-01-14 16:41:10 +01:00
|
|
|
}
|
|
|
|
|
2005-01-17 18:35:48 +01:00
|
|
|
void Extraction::Diff(Node *node, Cost &cost) {
|
|
|
|
Node::iterator i;
|
2005-02-20 20:49:44 +01:00
|
|
|
for(i = node->in_begin; i != node->in_end; i++) {
|
2005-01-17 18:35:48 +01:00
|
|
|
Link &link = *i;
|
2005-02-20 20:49:44 +01:00
|
|
|
for(unsigned int p = link.begin; p != link.end; p++) {
|
2005-02-20 01:43:24 +01:00
|
|
|
Entry &entry = (*mt)[p];
|
2005-03-02 11:40:18 +01:00
|
|
|
cost.extr -= entry.ram_size;
|
|
|
|
if(Visible(p)) cost.draw -= entry.ram_size;
|
|
|
|
if(!entry.patch) cost.disk -= entry.disk_size;
|
2005-01-14 16:41:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-20 20:49:44 +01:00
|
|
|
for(i = node->out_begin; i != node->out_end; i++) {
|
2005-01-17 18:35:48 +01:00
|
|
|
Link &link = *i;
|
2005-02-20 20:49:44 +01:00
|
|
|
for(unsigned int p = link.begin; p != link.end; p++) {
|
2005-02-20 01:43:24 +01:00
|
|
|
Entry &entry = (*mt)[p];
|
2005-03-02 11:40:18 +01:00
|
|
|
cost.extr += entry.ram_size;
|
|
|
|
if(Visible(p)) cost.draw += entry.ram_size;
|
|
|
|
if(!entry.patch) cost.disk += entry.disk_size;
|
2005-01-14 16:41:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-01-17 18:35:48 +01:00
|
|
|
|
2005-03-02 11:40:18 +01:00
|
|
|
void Extraction::SetError(Node *node, float error) {
|
|
|
|
for(Node::iterator i = node->in_begin; i != node->in_end; i++)
|
|
|
|
if(node_errors[(*i).node - root] != -1 &&
|
|
|
|
node_errors[(*i).node - root] < error) {
|
|
|
|
node_errors[(*i).node - root] = error;
|
|
|
|
SetError((*i).node, error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Extraction::CanRefine(Node *node) {
|
|
|
|
for(Node::iterator i = node->in_begin; i != node->in_end; i++)
|
|
|
|
if(!Visited((*i).node))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Extraction::CanCoarse(Node *node) {
|
|
|
|
for(Node::iterator i = node->out_begin; i != node->out_end; i++)
|
|
|
|
if(Visited((*i).node))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|