vcglib/apps/nexus/metric.h

81 lines
3.0 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 $
2005-02-19 17:22:45 +01:00
Revision 1.4 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
#ifndef NXS_METRIC_H
#define NXS_METRIC_H
#include <wrap/gui/frustum.h>
#include <vcg/space/sphere3.h>
#include "nexus.h"
namespace nxs {
enum MetricKind { FRUSTUM, FLAT, DELTA };
class Metric {
public:
virtual void GetView() {}
2005-02-19 17:22:45 +01:00
virtual float GetError(Entry &entry, bool &visible) = 0;
2005-01-14 16:41:10 +01:00
};
class FlatMetric: public Metric {
public:
2005-02-19 17:22:45 +01:00
float GetError(Entry &entry, bool &visible) {
visible = true;
return entry.error; }
2005-01-14 16:41:10 +01:00
};
class FrustumMetric: public Metric {
public:
vcg::Frustumf frustum;
virtual void GetView() { frustum.GetView(); }
2005-02-19 17:22:45 +01:00
float GetError(Entry &entry, bool &visible) {
visible = true;
vcg::Sphere3f &sph = entry.sphere;
float dist = (sph.Center() - frustum.ViewPoint()).Norm() - sph.Radius();
2005-01-21 18:09:13 +01:00
2005-02-19 17:22:45 +01:00
if(dist < 0) return 1e20f;
2005-01-21 18:09:13 +01:00
2005-02-19 17:22:45 +01:00
float remote = frustum.Remoteness(sph.Center(), sph.Radius());
float error = entry.error/frustum.Resolution(dist);
if(remote > 0) {
visible = false;
error /= remote;
}
return error;
2005-01-14 16:41:10 +01:00
}
};
}
#endif