fill_props.hh 2.96 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#ifndef FILL_PROPS_HH
#define FILL_PROPS_HH

#include <OpenMesh/Core/Utils/Property.hh>
#include "int2roman.hh"


template <typename Mesh>
bool 
fill_props( Mesh& _m, OpenMesh::VPropHandleT<float> _ph, bool _check=false)
{
  static float a[9] = { 1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f };

  for(typename Mesh::VertexIter it=_m.vertices_begin(); 
      it != _m.vertices_end(); ++it)
  {
Jan Möbius's avatar
Jan Möbius committed
17
    const float v = a[it->idx()%9];
18
    if ( _check && !(_m.property( _ph, *it ) == v) )
Jan Möbius's avatar
Jan Möbius committed
19 20
      return false;
    else  
21
      _m.property( _ph, *it ) = v;
Jan Möbius's avatar
Jan Möbius committed
22 23 24 25 26 27 28 29 30
  }
  return true;
}


template <typename Mesh>
bool 
fill_props( Mesh& _m, OpenMesh::EPropHandleT<bool> _ph, bool _check=false )
{
Jan Möbius's avatar
Jan Möbius committed
31

Jan Möbius's avatar
Jan Möbius committed
32 33 34
  for( typename Mesh::EdgeIter it=_m.edges_begin();
       it != _m.edges_end(); ++it)
  {
Jan Möbius's avatar
Jan Möbius committed
35 36
    const size_t n = it->idx();
    const bool   v = ((n&(n-1))==0); // true for 0,1,2,4,8,..
Jan Möbius's avatar
Jan Möbius committed
37

38
    if (_check && _m.property( _ph, *it ) != v)
Jan Möbius's avatar
Jan Möbius committed
39 40
    {
      std::cout << "    eprop_bool: " << n << " -> " 
41
                << _m.property(_ph, *it ) << " != " << v << std::endl;
Jan Möbius's avatar
Jan Möbius committed
42 43 44 45
      return false;
    }
    else
    {
46
      _m.property( _ph, *it ) = v;
Jan Möbius's avatar
Jan Möbius committed
47 48 49 50 51 52 53 54 55 56 57 58
      std::cout << "    eprop_bool: " << n << " -> " << v << std::endl;
    }
  }
  return true;
}



template <typename Mesh>
bool 
fill_props(Mesh& _m, OpenMesh::FPropHandleT<std::string> _ph, bool _check=false)
{
Jan Möbius's avatar
Jan Möbius committed
59

Jan Möbius's avatar
Jan Möbius committed
60 61 62
  for( typename Mesh::FaceIter it=_m.faces_begin();
       it != _m.faces_end(); ++it)
  {
63 64
    const int n = (it->idx()) + 1;
    _m.property( _ph, *it ) = int2roman(n);
Jan Möbius's avatar
Jan Möbius committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
  }
  return true;
}


template <typename Mesh, typename T>
bool 
fill_props( Mesh& _m, OpenMesh::HPropHandleT<T> _ph, bool _check=false)
{
  T    v;  
  static float a[9] = { 1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f };
  static float b[9] = { 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f, 1.1f };
  static float c[9] = { 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f, 1.1f, 2.2f };
  static float d[9] = { 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f, 1.1f, 2.2f, 3.3f };
  static double values[9] = { 0.1, 0.02, 0.003, 0.0004, 0.00005, 0.000006,
                              0.0000007, 0.00000008, 0.000000009 };

  for( typename Mesh::HalfedgeIter it=_m.halfedges_begin();
       it != _m.halfedges_end(); ++it)
  {
Jan Möbius's avatar
Jan Möbius committed
85
    const int n = it->idx();
Jan Möbius's avatar
Jan Möbius committed
86

87
    v = it->idx()+1; // ival
Jan Möbius's avatar
Jan Möbius committed
88 89 90 91 92 93 94
    v = values[n%9];         // dval
    v = ((n&(n-1))==0);      // bval
    v.vec4fval[0] = a[n%9];
    v.vec4fval[1] = b[n%9];
    v.vec4fval[2] = c[n%9];
    v.vec4fval[3] = d[n%9];

95
    if ( _check && _m.property( _ph, *it ) != v )
Jan Möbius's avatar
Jan Möbius committed
96 97
      return false;
    else
98
      _m.property( _ph, *it ) = v;
Jan Möbius's avatar
Jan Möbius committed
99 100 101 102 103 104 105 106 107 108
  }
  return true;
}

template <typename Mesh, typename T>
bool 
fill_props( Mesh& _m, OpenMesh::MPropHandleT<T> _ph, bool _check=false)
{
  for( typename Mesh::FaceIter it=_m.faces_begin(); it != _m.faces_end(); ++it)
  {
Jan Möbius's avatar
Jan Möbius committed
109
    const size_t idx = it->idx();
Jan Möbius's avatar
Jan Möbius committed
110 111 112 113 114 115 116 117 118 119
    if ( _check && _m.property( _ph )[int2roman(idx+1)] != idx )
      return false;
    else
      _m.property( _ph )[int2roman(idx+1)] = idx;
  }
  return true;
}


#endif