Debugged
This commit is contained in:
parent
298d7c14c6
commit
ef01c54189
|
@ -24,19 +24,27 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.1 2004/06/23 17:17:46 ponchio
|
||||||
|
Created
|
||||||
|
|
||||||
|
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef NXS_PCHAIN_H
|
#ifndef NXS_PCHAIN_H
|
||||||
#define NXS_PCHAIN_H
|
#define NXS_PCHAIN_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <vcg/space/point3.h>
|
#include <vcg/space/point3.h>
|
||||||
|
|
||||||
|
/** Partition must be a class with a Key type, with
|
||||||
|
Levels, Locate, Priority, Save(FILE *), Load(FILE *)
|
||||||
|
as in pvoronoi.h */
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
template <class Partition> class PChain {
|
template <class Partition> class PChain {
|
||||||
public:
|
public:
|
||||||
typedef typename Partition::Key Key;
|
typedef typename Partition::Key Key;
|
||||||
|
std::vector<Partition> levels;
|
||||||
|
|
||||||
unsigned int Levels() {
|
unsigned int Levels() {
|
||||||
return levels.size();
|
return levels.size();
|
||||||
|
@ -51,8 +59,29 @@ template <class Partition> class PChain {
|
||||||
assert(level < levels.size());
|
assert(level < levels.size());
|
||||||
return levels[level].Priority(level, p, key);
|
return levels[level].Priority(level, p, key);
|
||||||
}
|
}
|
||||||
private:
|
bool Save(const std::string &file) {
|
||||||
std::vector<Partition> levels;
|
FILE *fp = fopen(file.c_str(), "wb+");
|
||||||
|
if(!fp) return false;
|
||||||
|
int n = Levels();
|
||||||
|
fwrite(&n, sizeof(int), 1, fp);
|
||||||
|
for(int i = 0; i < n; i++)
|
||||||
|
levels[i].Save(fp);
|
||||||
|
fclose(fp);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool Load(const std::string &file) {
|
||||||
|
levels.clear();
|
||||||
|
FILE *fp = fopen(file.c_str(), "rb");
|
||||||
|
if(!fp) return false;
|
||||||
|
int n;
|
||||||
|
fread(&n, sizeof(int), 1, fp);
|
||||||
|
levels.resize(n);
|
||||||
|
for(int i = 0; i < n; i++)
|
||||||
|
levels[i].Load(fp);
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}//namespace
|
}//namespace
|
||||||
|
|
|
@ -24,11 +24,17 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.1 2004/06/23 17:17:46 ponchio
|
||||||
|
Created
|
||||||
|
|
||||||
|
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#pragma warning(disable:4786 4804 4244 4018 4267 4311)
|
#pragma warning(disable:4786 4804 4244 4018 4267 4311)
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <iostream>
|
||||||
#include "pvoronoi.h"
|
#include "pvoronoi.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace vcg;
|
using namespace vcg;
|
||||||
using namespace nxs;
|
using namespace nxs;
|
||||||
|
@ -119,6 +125,11 @@ unsigned int VoronoiPartition::count(Key key) {
|
||||||
return key > 0 && key < size();
|
return key > 0 && key < size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Seed &VoronoiPartition::operator[](Key key) {
|
||||||
|
assert(key < all_seeds.size());
|
||||||
|
return all_seeds[key];
|
||||||
|
}
|
||||||
|
|
||||||
VoronoiPartition::Key VoronoiPartition::Locate(const vcg::Point3f &p) {
|
VoronoiPartition::Key VoronoiPartition::Locate(const vcg::Point3f &p) {
|
||||||
int target;
|
int target;
|
||||||
Closest(p, target);
|
Closest(p, target);
|
||||||
|
@ -131,3 +142,41 @@ float VoronoiPartition::Priority(const vcg::Point3f &p, Key key) {
|
||||||
return seed.Dist(p);
|
return seed.Dist(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VoronoiPartition::Save(const std::string &file) {
|
||||||
|
FILE *fp = fopen(file.c_str(), "wb+");
|
||||||
|
if(!fp) return false;
|
||||||
|
Save(fp);
|
||||||
|
fclose(fp);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VoronoiPartition::Load(const std::string &file) {
|
||||||
|
FILE *fp = fopen(file.c_str(), "rb");
|
||||||
|
if(!fp) return false;
|
||||||
|
Load(fp);
|
||||||
|
fclose(fp);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int VoronoiPartition::Save(FILE *fp) {
|
||||||
|
fwrite(&bbox, sizeof(Box3f), 1, fp);
|
||||||
|
int n = all_seeds.size();
|
||||||
|
fwrite(&n, sizeof(int), 1, fp);
|
||||||
|
fwrite(&all_seeds[0], sizeof(Seed), all_seeds.size(), fp);
|
||||||
|
return sizeof(Box3f) + sizeof(int) + sizeof(Seed) * all_seeds.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int VoronoiPartition::Load(FILE *fp) {
|
||||||
|
clear();
|
||||||
|
fread(&bbox, sizeof(Box3f), 1, fp);
|
||||||
|
int n;
|
||||||
|
fread(&n, sizeof(int), 1, fp);
|
||||||
|
all_seeds.resize(n);
|
||||||
|
fread(&all_seeds[0], sizeof(Seed), all_seeds.size(), fp);
|
||||||
|
ug_seeds.resize(n);
|
||||||
|
for(int i = 0; i < n; i++)
|
||||||
|
ug_seeds[i] = all_seeds[i];
|
||||||
|
ug.SetBBox(bbox);
|
||||||
|
ug.Set(ug_seeds);
|
||||||
|
return sizeof(Box3f) + sizeof(int) + sizeof(Seed) * all_seeds.size();
|
||||||
|
}
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.1 2004/06/23 17:17:46 ponchio
|
||||||
|
Created
|
||||||
|
|
||||||
|
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
@ -32,6 +35,8 @@ $Log: not supported by cvs2svn $
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <string>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <vcg/space/point3.h>
|
#include <vcg/space/point3.h>
|
||||||
#include <vcg/space/box3.h>
|
#include <vcg/space/box3.h>
|
||||||
|
@ -87,10 +92,15 @@ namespace nxs {
|
||||||
iterator end();
|
iterator end();
|
||||||
int size();
|
int size();
|
||||||
unsigned int count(Key key);
|
unsigned int count(Key key);
|
||||||
|
Seed &operator[](Key key);
|
||||||
void clear();
|
void clear();
|
||||||
Key Locate(const vcg::Point3f &p);
|
Key Locate(const vcg::Point3f &p);
|
||||||
float Priority(const vcg::Point3f &p, Key key);
|
float Priority(const vcg::Point3f &p, Key key);
|
||||||
|
|
||||||
|
bool Save(const std::string &file);
|
||||||
|
bool Load(const std::string &file);
|
||||||
|
unsigned int Save(FILE *fp);
|
||||||
|
unsigned int Load(FILE *fp);
|
||||||
private:
|
private:
|
||||||
vcg::Box3f bbox;
|
vcg::Box3f bbox;
|
||||||
vcg::GridStaticPtr< std::vector<Seed> > ug;
|
vcg::GridStaticPtr< std::vector<Seed> > ug;
|
||||||
|
|
Loading…
Reference in New Issue