*** empty log message ***
This commit is contained in:
parent
3ad3628994
commit
6dfbfb3ec8
|
@ -0,0 +1,88 @@
|
|||
#include <vcg/traced_vector.h>
|
||||
#include <vcg/simple_temporary_data.h>
|
||||
|
||||
|
||||
#include<vcg/space/point3.h>
|
||||
#include<vcg/space/color4.h>
|
||||
using namespace vcg;
|
||||
#include <vcg/simplex/vertexplus/base.h>
|
||||
#include<vcg/math/base.h>
|
||||
|
||||
|
||||
class EdgeProto{};
|
||||
class Vertex0 : public VertexSimp1< Vertex0,EdgeProto,vcg::vert::Coord3fOpt>{};
|
||||
|
||||
typedef TVector<Vertex0> TVect;
|
||||
int main(){
|
||||
int i;
|
||||
|
||||
// partial test for CORE DATA ***********
|
||||
// put some vertex in a vector
|
||||
TVector<Vertex0> c1;
|
||||
|
||||
for( i = 0; i < 10; i++)
|
||||
c1.push_back(Vertex0());
|
||||
|
||||
c1.EnableAttribute<Vertex0::CoordType>();
|
||||
|
||||
// put some more vertex inthe vector
|
||||
for( i= 0; i < 10; i++)
|
||||
c1.push_back(Vertex0());
|
||||
|
||||
c1[2].P()=Point3f(1.0,2,3);
|
||||
Point3f p = c1[2].P();
|
||||
|
||||
// drop the attributes
|
||||
c1.DisableAttribute<Vertex0::CoordType>();
|
||||
// *****************************************
|
||||
|
||||
|
||||
// USER DATA
|
||||
// si puo' fare in 2 modi: Se il container e'di tipo TVector (traced vector)
|
||||
// si puo'usare
|
||||
//(1) c.NewTempData<TIPO_ATTRIBUTO>(); che si occupa di resizare
|
||||
// i container di dati temporanei (cioe' riflette tutte le push_back,reserve,resize
|
||||
// eventualemnte fatte sul vettore). NewTempoData resituisce una handle per accedere
|
||||
// al dato.
|
||||
|
||||
// (2) si usa SimpleTempData che e' come uno tranne che non supporta automaticamente
|
||||
// le variazioni di dimensione
|
||||
// del vettore (si puo' fare a mano pero')...s
|
||||
|
||||
// partial test for USER DATA ***********
|
||||
// modo (1)
|
||||
|
||||
for( i = 0; i < 10; i++)
|
||||
c1.push_back(Vertex0());
|
||||
|
||||
CATEntry<TVect,EntryCATMulti<TVect> >::Insert(c1); // questa riga sparira'
|
||||
|
||||
TempData<TVect,int> handle = c1.NewTempData<int>();
|
||||
handle[&c1[3]] = 71;
|
||||
// put some more vertex inthe vector
|
||||
for( i = 0; i < 10; i++)
|
||||
c1.push_back(Vertex0());
|
||||
int h = handle[&c1[3]];
|
||||
c1.DeleteTempData(handle);
|
||||
// *****************************************
|
||||
|
||||
|
||||
// partial test for USER DATA ***********
|
||||
// modo (2)
|
||||
|
||||
std::vector<Vertex0> c;
|
||||
for( i = 0; i < 10; i++)
|
||||
c.push_back(Vertex0());
|
||||
|
||||
SimpleTempData<std::vector<Vertex0>,int> tmp(c);
|
||||
tmp.Start();
|
||||
tmp[&c[1]] = 22;
|
||||
int hh = tmp[&c[1]];
|
||||
tmp.Stop();
|
||||
// **************************************
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -42,8 +42,6 @@ typedef STL_CONT::value_type VALUE_TYPE;
|
|||
virtual void Resort(VALUE_TYPE*,VALUE_TYPE*) =0;
|
||||
virtual void Remove(const STL_CONT&) = 0;
|
||||
virtual void AddDataElem(VALUE_TYPE*,int)=0;
|
||||
//virtual void Reserve(STL_CONT::value_type * pt,const int & rs)=0;
|
||||
//virtual void Resize(STL_CONT::value_type * pt,const int & rs)=0;
|
||||
|
||||
public:
|
||||
// ID serves as a type trait.
|
||||
|
|
|
@ -79,13 +79,14 @@ template <class STL_CONT>
|
|||
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------------------
|
||||
// WrapBase: used to implement a list of pointers to std::vector of different types
|
||||
// Wrap: derived from WrapBase (to take the function and from std::vector)
|
||||
struct WrapBase{
|
||||
virtual void Push_back(const int & n)=0;
|
||||
virtual void Reserve(const int & n)=0;
|
||||
virtual void Resize(const int & n)=0;
|
||||
};
|
||||
|
||||
// (note) double hineritance is not necessary, just handy
|
||||
template <class ATTR_TYPE>
|
||||
struct Wrap: public WrapBase,std::vector<ATTR_TYPE>{
|
||||
|
@ -93,9 +94,9 @@ struct Wrap: public WrapBase,std::vector<ATTR_TYPE>{
|
|||
virtual void Reserve(const int & n){reserve(n);}
|
||||
virtual void Resize(const int & n){resize(n);}
|
||||
};
|
||||
//-------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------------------
|
||||
// EntryCATMulti: entry type for multiple user data
|
||||
template <class STL_CONT>
|
||||
struct EntryCATMulti: public EntryCATBase<STL_CONT>{
|
||||
|
@ -121,10 +122,11 @@ virtual void Resize(const int & n){
|
|||
private:
|
||||
std::list< WrapBase * > data;
|
||||
};
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// TempData implements a handle to one of the vector od data stored in EntryCATMulti
|
||||
template <class STL_CONT, class ATTR_TYPE>
|
||||
class TempData{
|
||||
public:
|
||||
|
@ -139,6 +141,8 @@ public:
|
|||
return (*item)[pos];
|
||||
}
|
||||
};
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
}; // end namespace vcg
|
||||
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/****************************************************************************
|
||||
* 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. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef __VCGLIB_SIMPLE__
|
||||
#define __VCGLIB_SIMPLE__
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace vcg {
|
||||
|
||||
template <class STL_CONT, class ATTR_TYPE>
|
||||
class SimpleTempData{
|
||||
public:
|
||||
typedef typename ATTR_TYPE attr_type;
|
||||
|
||||
STL_CONT& c;
|
||||
std::vector<ATTR_TYPE> data;
|
||||
|
||||
SimpleTempData(STL_CONT &_c):c(_c){};
|
||||
|
||||
// access to data
|
||||
ATTR_TYPE & operator[](const STL_CONT::value_type *v){return data[v-&*c.begin()];}
|
||||
ATTR_TYPE & operator[](const int & i){return data[i];}
|
||||
|
||||
// start temporary attribute
|
||||
void Start(){data.reserve(c.capacity());data.resize(c.size());}
|
||||
|
||||
// stop temporary attribute
|
||||
void Stop(){data.clear();}
|
||||
|
||||
// update temproary data size
|
||||
bool UpdateSize(){
|
||||
if(data.size() != c.size())
|
||||
{
|
||||
data.resize(c.size());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
}; // end namespace vcg
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue