mirror of
https://github.com/OpenCMT/uLib.git
synced 2025-12-06 07:21:31 +01:00
[uLib geometry]
- adds some getters/setters to Programmable accessor - DataSet and Attributes ... start working on .. to be continued
This commit is contained in:
@@ -35,22 +35,9 @@ struct is_iterator {
|
||||
|
||||
template <typename D>
|
||||
class ProgrammableAccessor_Base {
|
||||
protected:
|
||||
|
||||
public:
|
||||
virtual D Get(void *) const = 0;
|
||||
virtual void Set(void *,const D) const = 0;
|
||||
|
||||
// template <typename T>
|
||||
// T Get(void *ob) const {
|
||||
// return static_cast<T>(this->Get(ob));
|
||||
// }
|
||||
|
||||
// template <typename T>
|
||||
// void Set(void *ob, const T data) const {
|
||||
// this->Set(ob,static_cast<D>(data));
|
||||
// }
|
||||
|
||||
virtual ~ProgrammableAccessor_Base() {}
|
||||
};
|
||||
|
||||
@@ -181,25 +168,19 @@ template <typename D >
|
||||
class ProgrammableAccessor : public Named {
|
||||
public:
|
||||
|
||||
// struct Wrapper {
|
||||
// Wrapper(const ProgrammableAccessor<D> *ac, void *ob) :
|
||||
// m_access(ac), m_object(ob)
|
||||
// { assert(ob != NULL); }
|
||||
|
||||
// template <typename T>
|
||||
// inline T Get() const { return static_cast<T>(m_access->Get(m_object)); }
|
||||
|
||||
// template <typename T>
|
||||
// inline void Set(const T data) const { return m_access->Set(m_object,static_cast<T>(data)); }
|
||||
|
||||
// void *m_object;
|
||||
// const ProgrammableAccessor<D> *m_access;
|
||||
// };
|
||||
|
||||
ProgrammableAccessor() : Named("") {}
|
||||
|
||||
ProgrammableAccessor(const char *name) : Named(name) {}
|
||||
|
||||
template < typename F >
|
||||
ProgrammableAccessor(const char *name, F f) : Named(name)
|
||||
{ SetAccessFunctions(f); }
|
||||
|
||||
template < typename F1, typename F2 >
|
||||
ProgrammableAccessor(const char *name, F1 f1, F2 f2) : Named(name)
|
||||
{ SetAccessFunctions(f1,f2); }
|
||||
|
||||
template < typename F >
|
||||
ProgrammableAccessor(F f) : Named(f)
|
||||
{ SetAccessFunctions(f); }
|
||||
@@ -209,8 +190,7 @@ public:
|
||||
{ SetAccessFunctions(f1,f2); }
|
||||
|
||||
|
||||
// ----- move to factory //
|
||||
|
||||
// ----- factory functions //
|
||||
template <typename R, typename T1>
|
||||
inline void SetAccessFunctions(R(*_pg)(const T1 *), void(*_ps)(T1*,R) = NULL) {
|
||||
m_base = SmartPointer< detail::ProgrammableAccessor_Base<D> >(new detail::functor_by_static_acc<D,R,T1>(_pg,_ps));
|
||||
@@ -243,8 +223,23 @@ public:
|
||||
}
|
||||
// ------ //
|
||||
|
||||
/*
|
||||
// struct Wrapper {
|
||||
// Wrapper(const ProgrammableAccessor<D> *ac, void *ob) :
|
||||
// m_access(ac), m_object(ob)
|
||||
// { assert(ob != NULL); }
|
||||
|
||||
// template <typename T>
|
||||
// inline T Get() const { return static_cast<T>(m_access->Get(m_object)); }
|
||||
|
||||
// template <typename T>
|
||||
// inline void Set(const T data) const { return m_access->Set(m_object,static_cast<T>(data)); }
|
||||
|
||||
// void *m_object;
|
||||
// const ProgrammableAccessor<D> *m_access;
|
||||
// };
|
||||
// const Wrapper operator() (void *ob) const { return Wrapper(this,ob); }
|
||||
*/
|
||||
|
||||
inline D Get(void *ob) const { return m_base->Get(ob); }
|
||||
|
||||
|
||||
@@ -62,6 +62,8 @@ namespace uLib {
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
|
||||
template < typename T >
|
||||
void print_is_iter(const T &t, typename boost::disable_if< detail::is_iterator<T> >::type *dummy = 0 ) {
|
||||
std::cout << "no";
|
||||
@@ -146,7 +148,7 @@ int main() {
|
||||
std::cout << va2.Get(&v) << "\n";
|
||||
}
|
||||
|
||||
{
|
||||
{ // test is iterator ..
|
||||
Vector<Vox>::Iterator it;
|
||||
Vox v;
|
||||
std::cout << "is iter? ";
|
||||
|
||||
@@ -85,6 +85,7 @@ int main()
|
||||
for(uLib::Vector<float>::Iterator it = v.begin(); it!=v.end(); it++)
|
||||
std::cout << *it <<" ";
|
||||
std::cout << std::endl;
|
||||
|
||||
// std::sort(v.begin(),v.end(),LT<float>());
|
||||
|
||||
|
||||
|
||||
@@ -43,33 +43,12 @@
|
||||
namespace uLib {
|
||||
|
||||
|
||||
//typedef std::iterator SequenceIterator;
|
||||
|
||||
//template < typename T >
|
||||
//struct Enumeration {
|
||||
|
||||
//};
|
||||
|
||||
//template < typename T >
|
||||
//struct Iterator {
|
||||
|
||||
//};
|
||||
|
||||
//class AbstractDenseSequence {
|
||||
//public:
|
||||
|
||||
// virtual bool Empty() const = 0;
|
||||
|
||||
|
||||
//};
|
||||
|
||||
|
||||
class AbstractArray {
|
||||
public:
|
||||
virtual const void * GetDataPointer(Id_t id) const = 0;
|
||||
// virtual const void * GetDataPointer(Id_t id) const = 0;
|
||||
virtual void * GetDataPointer(Id_t id) = 0;
|
||||
virtual void SetSize(const size_t size) = 0;
|
||||
virtual const size_t GetSize() const = 0;
|
||||
virtual ~AbstractArray() {}
|
||||
};
|
||||
|
||||
@@ -78,13 +57,14 @@ public:
|
||||
template < typename T >
|
||||
class DataAttributes {
|
||||
public:
|
||||
DataAttributes() : m_Active(NULL) {}
|
||||
|
||||
template < typename F >
|
||||
void AddAttribute(const char *name, F f) {
|
||||
ProgrammableAccessor<T> pa(name);
|
||||
pa.SetAccessFunctions(f);
|
||||
m_Accessors.push_back(pa);
|
||||
if(m_Accessors.size() == 1)
|
||||
SetActive(name);
|
||||
m_Active = &m_Accessors.back();
|
||||
}
|
||||
|
||||
template < typename F1, typename F2 >
|
||||
@@ -92,8 +72,7 @@ public:
|
||||
ProgrammableAccessor<T> pa(name);
|
||||
pa.SetAccessFunctions(f1,f2);
|
||||
m_Accessors.push_back(pa);
|
||||
if(m_Accessors.size() == 1)
|
||||
SetActive(name);
|
||||
m_Active = &m_Accessors.back();
|
||||
}
|
||||
|
||||
ProgrammableAccessor<T> * GetAttribute(const char *name) /*const*/ {
|
||||
@@ -159,6 +138,9 @@ private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// TO BE MOVED OR REMOVED ...
|
||||
template <
|
||||
typename T,
|
||||
class ScalarAccess
|
||||
|
||||
@@ -179,3 +179,50 @@ void ImageData::ExportToVtkXml(const char *file, bool density_type)
|
||||
fclose(vtk_file);
|
||||
printf("%s vtk file saved\n",file);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// DATASET IMAGE
|
||||
|
||||
//void ImageData::SetSize(const Vector3f v)
|
||||
//{
|
||||
// ImageSpace::SetSize( v.array() / this->GetDims().array().cast<float>() );
|
||||
//}
|
||||
|
||||
//Vector3f ImageData::GetSize() const
|
||||
//{
|
||||
// return ImageSpace::GetSize().array() * this->GetDims().array().cast<float>();
|
||||
//}
|
||||
|
||||
//bool ImageData::IsInsideBounds(const Vector4f pt) const
|
||||
//{
|
||||
// Vector4f ptl = ImageSpace::GetLocalPoint(pt);
|
||||
// int result = 0;
|
||||
// for ( int i=0; i<3 ;++i) {
|
||||
// result += ptl(i) > (float)this->GetDims()(i);
|
||||
// result += ptl(i) < 0;
|
||||
// }
|
||||
// return result == 0;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@ public:
|
||||
ImageData(const Vector3i &size) : ImageMap(size) {}
|
||||
|
||||
void SetSize(const Vector3f v);
|
||||
|
||||
Vector3f GetSize() const;
|
||||
|
||||
bool IsInsideBounds(const Vector4f pt) const;
|
||||
@@ -62,39 +61,73 @@ public:
|
||||
};
|
||||
|
||||
|
||||
template < class SeqCnt >
|
||||
class DataSetImage : public DataSet, public ImageSpace, public ImageMap {
|
||||
|
||||
|
||||
class DataVectorImage : public ImageData {
|
||||
typedef float ScalarT;
|
||||
public:
|
||||
DataSetImage() : ImageMap(Vector3i::Zero()), m_Sequence() {}
|
||||
DataSetImage(const Vector3i &size) : ImageMap(size), m_Sequence(new SeqCnt(size.prod())) {}
|
||||
|
||||
inline void * GetDataPointer(const Id_t id) const {
|
||||
return m_Data->GetDataPointer(id);
|
||||
void SetSize(const Vector3f v) {
|
||||
// ImageSpace::SetSize( v.array() / this->GetDims().array().cast<float>() );
|
||||
}
|
||||
|
||||
float GetValue(const Vector3i id) const { return m_Scalars.Get<float>(GetDataPointer(Map(id))); }
|
||||
float GetValue(const int id) const { return m_Scalars.Get<float>(GetDataPointer(id)); }
|
||||
void SetValue(const Vector3i id, float value) { m_Scalars.Set<float>(GetDataPointer(Map(id)),value); }
|
||||
void SetValue(const int id, float value) { m_Scalars.Set<float>(GetDataPointer(id),value); }
|
||||
|
||||
void SetDims(const Vector3i &size) {
|
||||
ImageMap::SetDims(size);
|
||||
m_Data->SetSize(size.prod());
|
||||
Vector3f GetSize() const {
|
||||
// return ImageSpace::GetSize().array() * this->GetDims().array().cast<float>();
|
||||
}
|
||||
|
||||
// uLibRefMacro(Data,AbstractArray*)
|
||||
uLibRefMacro(Data,SmartPointer<AbstractArray>)
|
||||
uLibRefMacro(Scalars,ProgrammableAccessor<ScalarT>)
|
||||
bool IsInsideBounds(const Vector4f pt) const {
|
||||
Vector4f ptl = ImageSpace::GetLocalPoint(pt);
|
||||
int result = 0;
|
||||
for (int i=0; i<3; ++i) {
|
||||
result += ptl(i) > (float)this->GetDims()(i);
|
||||
result += ptl(i) < 0;
|
||||
}
|
||||
return result == 0;
|
||||
}
|
||||
|
||||
void SetDims(const Vector3i &size) { m_Sequence->resize(size.prod()); }
|
||||
|
||||
inline void * GetDataPointer(Id_t id) { return &m_Sequence->at(id); }
|
||||
|
||||
private:
|
||||
// AbstractArray* m_Data;
|
||||
SmartPointer<AbstractArray> m_Data;
|
||||
ProgrammableAccessor<ScalarT> m_Scalars;
|
||||
SmartPointer<SeqCnt> m_Sequence;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//class DataVectorImage : public ImageData {
|
||||
// typedef float ScalarT;
|
||||
//public:
|
||||
|
||||
// inline void * GetDataPointer(const Id_t id) const {
|
||||
// return m_Data->GetDataPointer(id);
|
||||
// }
|
||||
|
||||
// float GetValue(const Vector3i id) const { return m_Scalars.Get<float>(GetDataPointer(Map(id))); }
|
||||
// float GetValue(const int id) const { return m_Scalars.Get<float>(GetDataPointer(id)); }
|
||||
// void SetValue(const Vector3i id, float value) { m_Scalars.Set<float>(GetDataPointer(Map(id)),value); }
|
||||
// void SetValue(const int id, float value) { m_Scalars.Set<float>(GetDataPointer(id),value); }
|
||||
|
||||
// void SetDims(const Vector3i &size) {
|
||||
// ImageMap::SetDims(size);
|
||||
// m_Data->SetSize(size.prod());
|
||||
// }
|
||||
|
||||
// uLibRefMacro(Data,SmartPointer<AbstractArray>)
|
||||
// uLibRefMacro(Scalars,ProgrammableAccessor<ScalarT>)
|
||||
//private:
|
||||
// SmartPointer<AbstractArray> m_Data;
|
||||
// ProgrammableAccessor<ScalarT> m_Scalars;
|
||||
//};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -80,9 +80,6 @@ public:
|
||||
|
||||
Vector3i UnMap(int index) const;
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
Order m_DataOrder;
|
||||
Vector3i m_Dims;
|
||||
|
||||
@@ -80,31 +80,48 @@ struct MyVoxelJitterAccess {
|
||||
|
||||
int main() {
|
||||
|
||||
DataVectorCompound< MyVoxel, MyVoxelMeanAccess > data;
|
||||
data.Data().push_back( MyVoxel(5,1) );
|
||||
data.Data().push_back( MyVoxel(10,2) );
|
||||
data.Data().push_back( MyVoxel(15,3) );
|
||||
data.Data().push_back( MyVoxel(2368,1) );
|
||||
// {
|
||||
// DataVectorCompound< MyVoxel, MyVoxelMeanAccess > data;
|
||||
// data.Data().push_back( MyVoxel(5,1) );
|
||||
// data.Data().push_back( MyVoxel(10,2) );
|
||||
// data.Data().push_back( MyVoxel(15,3) );
|
||||
// data.Data().push_back( MyVoxel(2368,1) );
|
||||
|
||||
data[3].value = 123;
|
||||
// data[3].value = 123;
|
||||
|
||||
DataVectorCompound< MyVoxel, MyVoxelValueAccess > data2 = data;
|
||||
// DataVectorCompound< MyVoxel, MyVoxelValueAccess > data2 = data;
|
||||
|
||||
std::cout << "image data test \n";
|
||||
foreach (MyVoxel &el, data2.Data()) {
|
||||
std::cout << "-> " << el.value << " - " << el.count << "\n";
|
||||
// std::cout << "image data test \n";
|
||||
// foreach (MyVoxel &el, data2.Data()) {
|
||||
// std::cout << "-> " << el.value << " - " << el.count << "\n";
|
||||
// }
|
||||
|
||||
// DataVectorCompound< MyVoxel, MyVoxelJitterAccess > data3 = data2;
|
||||
// data3.A0().min = -1;
|
||||
// data3.A0().max = 1;
|
||||
// data3.AddScalarAccess("scalars",&MyVoxel::value);
|
||||
// data3.AddScalarAccess("counts",&MyVoxel::count);
|
||||
|
||||
// std::cout << "image data test \n";
|
||||
// for(int i=0; i<data3.GetSize(); ++i) {
|
||||
// std::cout << " -> " << data3.GetScalar(i) << " - " << data3.GetScalar("counts",i) << "\n";
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
DataSetImage< Vector<MyVoxel> > img( Vector3i(3,3,3) );
|
||||
img.AddScalarAccess("value",&MyVoxel::value);
|
||||
img.AddScalarAccess("count",&MyVoxel::count);
|
||||
|
||||
for(int x = 0; x < img.GetDims().prod(); ++x) {
|
||||
img.SetActiveScalars("value");
|
||||
img.SetScalar(x,x);
|
||||
img.SetScalar("count",x,2*x);
|
||||
std::cout << " [" << img.GetScalar("value",x) << "," << img.GetScalar("count", x) << "]";
|
||||
}
|
||||
|
||||
DataVectorCompound< MyVoxel, MyVoxelJitterAccess > data3 = data2;
|
||||
data3.A0().min = -1;
|
||||
data3.A0().max = 1;
|
||||
data3.AddScalarAccess("scalars",&MyVoxel::value);
|
||||
data3.AddScalarAccess("counts",&MyVoxel::count);
|
||||
|
||||
std::cout << "image data test \n";
|
||||
for(int i=0; i<data3.GetSize(); ++i) {
|
||||
std::cout << " -> " << data3.GetScalar(i) << " - " << data3.GetScalar("counts",i) << "\n";
|
||||
}
|
||||
std::cout << "\n";
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user