Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Types | Public Member Functions
icl::core::DataSegment< T, N > Struct Template Reference

The DataSegment class defines a strided data segment (or 1D or 2D ordred array of vectors) More...

#include <DataSegment.h>

Inheritance diagram for icl::core::DataSegment< T, N >:
icl::core::DataSegmentBase

List of all members.

Public Types

typedef math::FixedColVector
< T, N > 
VectorType
 vector typedef

Public Member Functions

 DataSegment (T *data=0, size_t stride=0, size_t numElements=0, icl32s organizedWidth=-1)
 Constructor (basically passes all parameters to the Base class)
math::FixedColVector< T, N > & operator[] (int idx)
 linear index operator
const math::FixedColVector< T,
N > & 
operator[] (int idx) const
 linear index operator (const)
math::FixedColVector< T, N > & operator() (int x, int y)
 2D-index operator (only for organized data segments)
const math::FixedColVector< T,
N > & 
operator() (int x, int y) const
 2D-index operator (only for organized data segments, const)
template<class OtherT >
void deepCopy (DataSegment< OtherT, N > dst) const throw (utils::ICLException)
 copies the data segment to into another element-wise
bool isPacked () const
 returns whether the data is packed in memory (stride is sizeof(T)*N)
template<class OtherT >
bool equals (DataSegment< OtherT, N > dst, float tollerance=1.0e-5) const
 compares two data segments element wise given given maximun tollerance
template<class Fill >
void fillScalar (Fill scalarValue)
 fills each scalar value of each entry with given value
template<class Fill >
void fill (Fill vecValue)
 fills each vector entry with given value

Detailed Description

template<class T, int N>
struct icl::core::DataSegment< T, N >

The DataSegment class defines a strided data segment (or 1D or 2D ordred array of vectors)

Each data segment is defined by

Each single vector is assumed to be packed in memory (e.g. the vector element stride is always sizeof(T)) the distance between two vector entries can be set to an arbitrary constant value (stride). Optionally, an organizedWidth value > 0 can be given, which set up the DataSegement to be 2D-organized.

Integration with the DataSegment base class

The DataSegmentBase class is used as a generic interface for arbitrary DataSegment implementations. Since the DataSegment templates have no own data, a DataSegmentBase instance can simply be reinterpreted as a specific DataSegment-template version. For type-safe converions, the DataSegmentBase::as method can be used. This will reinterpret itself as a special DataSegment-template version and it will also use the runtime-information of the DataSegmentBase to check whether this conversion is allowed.

1D Vector types

The DataSegment class is specialized for 1D-vector types. In this case the access operators (index-operator for linear access, the (x,y)-operator for 2D-organized access), are adapted to not return T-references directly rather than FixedColVector<T,1> references.

Examples

Here are two examples that show some basic use of the DataSegment class. Please note, that usually, the programmes does not need to create DataSegments manually. Instead, e.g. the PointCloudObject-classes provide select-methods, that automatically create DataSegment instances.

  #include <ICLQt/Common.h>
  #include <ICLGeom/GeomDefs.h>
  #include <ICLCore/DataSegment.h>
  
  
  int main(){
    Vec data[5]; // linear data xyzh,xyzh,...
    
    // wrapper segment for the first 3 floats of every entry/row
    DataSegment<float,3> xyz(&data[0][0], sizeof(Vec), 5);
  
    // special segment for the last float of the segments
    DataSegment<float,1> h(&data[0][3], sizeof(Vec), 5);
    
    // xyz.getDim() returns the number of wrapped elements
    for(int i=0;i<xyz.getDim();++i){
      xyz[i] = FixedColVector<float,3>(1,2,3); // vector based assginment
      h[i] = 1;       // vector dim. is 1 -> scalar assignment
    }
    
    for(int i=0;i<5;++i){
      std::cout << "data[" << i << "]: " << data[i].transp() << std::endl;
    }
        
  }

Here is a more complex example, that shows how to use 2D-organized data segments:

#include <ICLQt/Common.h>
#include <ICLGeom/GeomDefs.h>
#include <ICLCore/DataSegment.h>

// utility structure used for demonstration
struct DataPoint{
  Vec xyz;        // 4 floats xyzh
  icl8u r,g,b,a;  // 4 single uchars for r,g,b and alpha
  Vec normal;     // 4 floats for a normal vector
  int label;      // a single int vector
};

int main(){
  Array2D<DataPoint> array(4,3);

   DataSegment<float,3> xyz(&array(0,0).xyz[0],sizeof(DataPoint), 12, 4);
  DataSegment<float,1> h(&array(0,0).xyz[3],sizeof(DataPoint), 12, 4);
  DataSegment<icl8u,4> rgba(&array(0,0).r,sizeof(DataPoint), 12, 4);
  DataSegment<float,4> n(&array(0,0).normal[0],sizeof(DataPoint), 12, 4);
  DataSegment<int,1>   l(&array(0,0).label,sizeof(DataPoint), 12, 4);

  for(int y=0;y<3;++y){    
    for(int x=0;x<4;++x){
      xyz(x,y) = FixedColVector<float,3>(x,y,0);
      h(x,y) = 1;              // scalar assignment
      rgba(x,y) = FixedColVector<icl8u,4>(x,y,x+y,255);
      n(x,y) = Vec(1,0,0,1);
      l(x,y) = x > y ? 1 : 0;  // scalar assignment
    }
  }
}

Member Typedef Documentation

template<class T, int N>
typedef math::FixedColVector<T,N> icl::core::DataSegment< T, N >::VectorType

vector typedef


Constructor & Destructor Documentation

template<class T, int N>
icl::core::DataSegment< T, N >::DataSegment ( T *  data = 0,
size_t  stride = 0,
size_t  numElements = 0,
icl32s  organizedWidth = -1 
) [inline]

Constructor (basically passes all parameters to the Base class)


Member Function Documentation

template<class T, int N>
template<class OtherT >
void icl::core::DataSegment< T, N >::deepCopy ( DataSegment< OtherT, N >  dst) const throw (utils::ICLException) [inline]

copies the data segment to into another element-wise

template<class T, int N>
template<class OtherT >
bool icl::core::DataSegment< T, N >::equals ( DataSegment< OtherT, N >  dst,
float  tollerance = 1.0e-5 
) const [inline]

compares two data segments element wise given given maximun tollerance

If the source and destination segments have different dimensions, isOrganized flag or organized-size, the check returns always false

template<class T, int N>
template<class Fill >
void icl::core::DataSegment< T, N >::fill ( Fill  vecValue) [inline]

fills each vector entry with given value

value is a template parameter, so it can also be a class that can be converted to T elements.

template<class T, int N>
template<class Fill >
void icl::core::DataSegment< T, N >::fillScalar ( Fill  scalarValue) [inline]

fills each scalar value of each entry with given value

value is a template parameter, so it can also be a class that can be converted to T elements

          DataSegment<float,4> ds = ..;
          fill(ds,URand(0,255));
template<class T, int N>
bool icl::core::DataSegment< T, N >::isPacked ( ) const [inline]

returns whether the data is packed in memory (stride is sizeof(T)*N)

template<class T, int N>
math::FixedColVector<T,N>& icl::core::DataSegment< T, N >::operator() ( int  x,
int  y 
) [inline]

2D-index operator (only for organized data segments)

Reimplemented from icl::core::DataSegmentBase.

template<class T, int N>
const math::FixedColVector<T,N>& icl::core::DataSegment< T, N >::operator() ( int  x,
int  y 
) const [inline]

2D-index operator (only for organized data segments, const)

Reimplemented from icl::core::DataSegmentBase.

template<class T, int N>
math::FixedColVector<T,N>& icl::core::DataSegment< T, N >::operator[] ( int  idx) [inline]

linear index operator

Reimplemented from icl::core::DataSegmentBase.

template<class T, int N>
const math::FixedColVector<T,N>& icl::core::DataSegment< T, N >::operator[] ( int  idx) const [inline]

linear index operator (const)

Reimplemented from icl::core::DataSegmentBase.


The documentation for this struct was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines