MorphoGraphX  2.0-1-227
Attributes.hpp
Go to the documentation of this file.
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2016 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef ATTRIBUTES_HPP
12 #define ATTRIBUTES_HPP
13 
20 #include <Config.hpp>
21 #include <QFile>
22 #include <QTextStream>
23 
24 #include <Hash.hpp>
25 #include <Types.hpp>
26 #include <Information.hpp>
27 #include <Progress.hpp>
28 #include <Triangle.hpp>
29 #include <Colors.hpp>
30 #include <tbb/concurrent_unordered_map.h>
31 
32 #include <omp.h>
33 
34 #include <Features.hpp>
35 
36 // GCC support for C++11 lacks is_trivially_copyable before 5.x (which exactly?)
37 #if __cplusplus >= 201103L && !__GNUC_LESS(5, 0)
38  #include <type_traits>
39  #define is_trivially_copyable std::is_trivially_copyable
40 #else
41  #include <tr1/type_traits>
42  #define is_trivially_copyable std::tr1::has_trivial_copy
43 #endif
44 
45 #include <Common.hpp>
46 
47 // Use TBB concurrent unordered map
48 #define STD_MAP tbb::concurrent_unordered_map
49 
50 template<bool, typename _Tp = void>
51 struct enable_if {};
52 
53 template<typename _Tp>
54 struct enable_if<true, _Tp> { typedef _Tp type; };
55 
59 #define IS_POD(T) typename enable_if<is_trivially_copyable<T>::value, T>::type
60 
61 namespace mgx
62 {
65 
66  namespace
67  {
68  // Functions to read/write QByteArray
69 
76  template<typename T>
77  bool readPOD(IS_POD(T) &data, const QByteArray &ba, size_t &pos)
78  {
79  if(qint64(pos + sizeof(T)) > ba.size()) {
80  Information::out << "Error reading past end of attribute" << endl;
81  return false;
82  }
83  memcpy(&data, ba.data() + pos, sizeof(T));
84  pos += sizeof(T);
85  return true;
86  }
87 
88  // Read a vector of POD type from QByteArray (use readAttr instead for matrices)
89  template<typename T>
90  bool readPODVector(IS_POD(T) &data, size_t n, const QByteArray &ba, size_t &pos)
91  {
92  if(qint64(pos + sizeof(T) * n) > ba.size()) {
93  Information::out << "Error reading past end of attribute" << endl;
94  return false;
95  }
96  memcpy(&data, ba.data() + pos, sizeof(T) * n);
97  pos += sizeof(T) * n;
98  return true;
99  }
100 
101  inline bool readChar(void *data, uint sz, const QByteArray &ba, size_t &pos)
102  {
103  if(qint64(pos + sz) > ba.size()) {
104  Information::out << "Error reading past end of attribute" << endl;
105  return false;
106  }
107  memcpy(data, ba.data() + pos, sz);
108  pos += sz;
109  return true;
110  }
111 
112  // Write to QByteArray
113  template<typename T>
114  bool writePOD(const IS_POD(T) &data, QByteArray &ba)
115  {
116  QByteArray qba(sizeof(T), 0);
117  memcpy(qba.data(), &data, sizeof(T));
118  ba.append(qba);
119  return true;
120  }
121 
122  template<typename T>
123  bool writePODVector(const IS_POD(T) &data, size_t n, QByteArray &ba)
124  {
125  QByteArray qba(sizeof(T) * n, 0);
126  memcpy(qba.data(), &data, sizeof(T) * n);
127  ba.append(qba);
128  return true;
129  }
130 
131  // Write an array of char
132  inline bool writeChar(const void *data, size_t sz, QByteArray &ba)
133  {
134  QByteArray qba(sz, 0);
135  memcpy(qba.data(), data, sz);
136  ba.append(qba);
137  return true;
138  }
139 
140  // File read/write functions
141 
142  // Write some (POD) data to a file
143  template <typename T>
144  bool writeFile(QIODevice &file, const T &data)
145  {
146  size_t qty = file.write((char*)&data, sizeof(T));
147  if(qty != sizeof(T))
148  throw QString("Attributes::write:Error on write");
149  return true;
150  }
151 
152  // Write a standard vector to a file
153  template <typename T>
154  bool writeFile(QIODevice &file, const std::vector<T> &data)
155  {
156  size_t sz = data.size();
157  writeFile(file, sz);
158  for(size_t i = 0; i < sz; i++)
159  writeFile(file, data[i]);
160  return true;
161  }
162 
163  // Write some data to a file
164  inline bool writeFile(QIODevice &file, char *data, size_t size)
165  {
166  size_t qty = file.write(data, size);
167  if(qty != size)
168  throw QString("Attributes::write:Error on write");
169  return true;
170  }
171 
172  // Write a QString to a file
173  inline bool writeFileQString(QIODevice &file, const QString &s)
174  {
175  QByteArray ba = s.toUtf8();
176  uint sz = ba.size();
177  return writeFile(file, sz)
178  and writeFile(file, ba.data(), sz);
179  }
180 
181  // Specialize for QString. We need to do this for any other complex types required
182  inline bool writeFile(QIODevice &file, const QString &s)
183  {
184  return writeFileQString(file, s);
185  }
186 
187  // Read some (POD) data from a file
188  template <typename T>
189  bool readFile(QIODevice &file, T &data)
190  {
191  size_t count = file.read((char*)&data, sizeof(T));
192  if(count != sizeof(T))
193  return false;
194 
195  return true;
196  }
197 
198  // Read a standard vector from a file
199  template <typename T>
200  bool readFile(QIODevice &file, std::vector<T> &data)
201  {
202  size_t sz;
203  bool result = readFile(file, sz);
204  data.reserve(data.size() + sz);
205  for(size_t i = 0; i < sz; i++) {
206  T value;
207  result &= readFile(file, value);
208  data.push_back(value);
209  }
210  return result;
211  }
212 
213  // Read a QString from a file
214  inline bool readFileQString(QIODevice &file, QString &s)
215  {
216  uint sz;
217  if(!readFile(file, sz))
218  return false;
219  QByteArray ba(sz, 0);
220  if(file.read(ba.data(), sz) != sz)
221  return false;
222  s = QString::fromUtf8(ba);
223  return true;
224  }
225 
226  // Specialize for QString. We need to do this for any other complex types required
227  inline bool readFile(QIODevice &file, QString &s)
228  {
229  return readFileQString(file, s);
230  }
231  }
232 
237  extern mgx_EXPORT IntVtxMap *vMap;
238  extern mgx_EXPORT IntCellMap *cMap;
239 
243  template<typename T>
244  bool readAttr(T &data, const QByteArray &ba, size_t &pos)
245  {
246  return readPOD<T>(data, ba, pos);
247  }
248 
249  template<size_t n, size_t m, typename T>
250  bool readAttr(Matrix<n, m, T> &data, const QByteArray &ba, size_t &pos)
251  {
252  for(size_t i = 0; i < n; ++i)
253  if(!readPODVector<T>(data[i][0], m, ba, pos))
254  return false;
255  return true;
256  }
257 
258  template<size_t n, typename T>
259  bool readAttr(Vector<n, T> &data, const QByteArray &ba, size_t &pos)
260  {
261  return readPODVector<T>(data[0], n, ba, pos);
262  }
263 
264  template<size_t n>
265  bool readAttr(Vector<n, Colorb> &data, const QByteArray &ba, size_t &pos)
266  {
267  for(size_t i = 0; i < n; ++i)
268  if(!readChar(&data[i][0], sizeof(Colorb), ba, pos))
269  return false;
270  return true;
271  }
272 
273  template<typename T, typename U>
274  bool readAttr(std::pair<T,U> &data, const QByteArray &ba, size_t &pos)
275  {
276  bool ok = readAttr(data.first,ba,pos);
277  if(ok) ok = readAttr(data.second,ba,pos);
278  return ok;
279  }
280 
281  template<>
282  inline bool readAttr(SymmetricTensor &data, const QByteArray &ba, size_t &pos)
283  {
284  return readPODVector<float>(data.ev1()[0], 9, ba, pos);
285  }
286 
287  // Specialize for vertex
288  // RSS: Maybe these 4 could be done with a pair of function templates
289  template<>
290  inline bool readAttr(vertex &v, const QByteArray &ba, size_t &pos)
291  {
292  uint vId = 0;
293  if(!readPOD<uint>(vId, ba, pos))
294  return false;
295  v = vertex(0);
296  if(vMap) {
297  IntVtxMap::iterator it = vMap->find(vId);
298  if(it != vMap->end())
299  v = it->second;
300  else
301  Information::out << "Vertex not found reading attribute" << endl;
302  }
303  return true;
304  }
305 
306  // Specialize for edge
307  template<>
308  inline bool readAttr(VtxVtxPair &pr, const QByteArray &ba, size_t &pos)
309  {
310  uint v1Id = 0, v2Id = 0;
311  if(!readPOD<uint>(v1Id, ba, pos))
312  return false;
313  if(!readPOD<uint>(v2Id, ba, pos))
314  return false;
315  if(vMap) {
316  IntVtxMap::iterator it = vMap->find(v1Id);
317  if(it != vMap->end())
318  pr.first = it->second;
319  else {
320  pr.first = vertex(0);
321  Information::out << "Vertex not found reading edge attribute" << endl;
322  }
323  it = vMap->find(v2Id);
324  if(it != vMap->end())
325  pr.second = it->second;
326  else {
327  pr.second = vertex(0);
328  Information::out << "Vertex not found reading edge attribute" << endl;
329  }
330  }
331  return true;
332  }
333 
334  // Specialize for triangle
335  template<>
336  inline bool readAttr(Triangle &t, const QByteArray &ba, size_t &pos)
337  {
338  uint v1Id = 0, v2Id = 0, v3Id = 0;
339  if(!readPOD<uint>(v1Id, ba, pos))
340  return false;
341  if(!readPOD<uint>(v2Id, ba, pos))
342  return false;
343  if(!readPOD<uint>(v3Id, ba, pos))
344  return false;
345  vertex v1(0), v2(0), v3(0);
346  if(vMap) {
347  IntVtxMap::iterator it = vMap->find(v1Id);
348  if(it != vMap->end())
349  v1 = it->second;
350  else
351  Information::out << "Vertex 1 not found reading triangle attribute" << endl;
352  it = vMap->find(v2Id);
353  if(it != vMap->end())
354  v2 = it->second;
355  else
356  Information::out << "Vertex 2 not found reading triangle attribute" << endl;
357  it = vMap->find(v3Id);
358  if(it != vMap->end())
359  v3 = it->second;
360  else
361  Information::out << "Vertex 3 not found reading triangle attribute" << endl;
362  t = Triangle(v1, v2, v3);
363  }
364  return true;
365  }
366 
367  // Specialize for cell
368  template<>
369  bool inline readAttr(cell &c, const QByteArray &ba, size_t &pos)
370  {
371  uint cId = 0;
372  if(!readPOD<uint>(cId, ba, pos))
373  return false;
374  c = cell(0);
375  if(cMap) {
376  IntCellMap::iterator it = cMap->find(cId);
377  if(it != cMap->end())
378  c = it->second;
379  else
380  Information::out << "Cell not found reading attribute" << endl;
381  }
382  return true;
383  }
384 
385  // Specialize for wall
386  template<>
387  inline bool readAttr(CellCellPair &pr, const QByteArray &ba, size_t &pos)
388  {
389  uint c1Id = 0, c2Id = 0;
390  if(!readPOD<uint>(c1Id, ba, pos))
391  return false;
392  if(!readPOD<uint>(c2Id, ba, pos))
393  return false;
394  pr.first = cell(0);
395  pr.second = cell(0);
396  if(cMap) {
397  IntCellMap::iterator it = cMap->find(c1Id);
398  if(it != cMap->end())
399  pr.first = it->second;
400  else
401  Information::out << "Cell not found reading wall attribute" << endl;
402  it = cMap->find(c2Id);
403  if(it != cMap->end())
404  pr.second = it->second;
405  else
406  Information::out << "Cell not found reading wall attribute" << endl;
407  }
408  return true;
409  }
410 
411  // Specialize for QString
412  template<>
413  inline bool readAttr(QString &data, const QByteArray &ba, size_t &pos)
414  {
415  // get the string size
416  //#pragma GCC diagnostic push
417  //#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
418  uint sz = 0;
419  if(!readPOD<uint>(sz, ba, pos))
420  return false;
421 
422  // Now read the data
423  QByteArray qba(sz, 0);
424  readChar(qba.data(), sz, ba, pos);
425  data = QString::fromUtf8(qba);
426  //#pragma GCC diagnostic pop
427  return true;
428  }
429  // Specialize for QStringList
430  template<>
431  inline bool readAttr(QStringList &data, const QByteArray &ba, size_t &pos)
432  {
433  // get the stringList size
434  uint sz = 0;
435  if(!readPOD<uint>(sz, ba, pos))
436  return false;
437  //Loop over the QStringList
438  for(uint i = 0; i < sz; i++){
439  readAttr(data[i], ba, pos);
440  }
441  return true;
442  }
443 
444  // Specialize for QByteArray
445  template<>
446  inline bool readAttr(QByteArray &qba, const QByteArray &ba, size_t &pos)
447  {
448  // get the data size
449  uint sz = 0;
450  if(!readPOD<uint>(sz, ba, pos))
451  return false;
452 
453  // Now read the data
454  qba.resize(sz);
455  readChar(qba.data(), sz, ba, pos);
456  return true;
457  }
458 
459 
460  // Specialize for Colorb
461  template<>
462  inline bool readAttr(Colorb &color, const QByteArray &ba, size_t &pos)
463  {
464  if(!readChar(&color[0], sizeof(Colorb), ba, pos))
465  return false;
466  return true;
467  }
468 
469  // Standard vectors
470  template <typename T>
471  inline bool readAttr(std::vector<T> &data, const QByteArray &ba, size_t &pos)
472  {
473  // get the data size
474  uint n = 0;
475  if(!readPOD<uint>(n, ba, pos))
476  return false;
477 
478  data.resize(n);
479  for(size_t i = 0; i < n; ++i)
480  if(!readAttr(data[i], ba, pos))
481  return false;
482  return true;
483  }
484 
485  // Standard maps
486  template <typename KeyT, typename ValueT>
487  inline bool readAttr(std::map<KeyT, ValueT> &data, const QByteArray &ba, size_t &pos)
488  {
489  // get the data size
490  uint n = 0;
491  if(!readPOD<uint>(n, ba, pos))
492  return false;
493 
494  for(size_t i = 0; i < n; ++i) {
495  KeyT key;
496  if(!readAttr(key, ba, pos))
497  return false;
498  ValueT value;
499  if(!readAttr(value, ba, pos))
500  return false;
501  data[key] = value;
502  }
503  return true;
504  }
505 
509  template<typename T>
510  bool writeAttr(const T &data, QByteArray &ba)
511  {
512  return writePOD<T>(data, ba);
513  }
514 
515  template<size_t n, size_t m, typename T>
516  bool writeAttr(const Matrix<n, m, T> &data, QByteArray &ba)
517  {
518  for(size_t i = 0; i < n; ++i)
519  if(!writePODVector<T>(data[i][0], m, ba))
520  return false;
521  return true;
522  }
523 
524  template<size_t n, typename T>
525  bool writeAttr(const Vector<n, T> &data, QByteArray &ba)
526  {
527  return writePODVector<T>(data[0], n, ba);
528  }
529 
530  template<size_t n>
531  bool writeAttr(const Vector<n, Colorb> &data, QByteArray &ba)
532  {
533  for(size_t i = 0; i < n; ++i)
534  if(!writeChar(&data[i][0], sizeof(Colorb), ba))
535  return false;
536  return true;
537  }
538 
539  template<typename T,typename U>
540  bool writeAttr(const std::pair<T,U> &data, QByteArray &ba)
541  {
542  bool ok = writeAttr(data.first,ba);
543  if(ok) ok = writeAttr(data.second,ba);
544  return ok;
545  }
546 
547  template<>
548  inline bool writeAttr(const SymmetricTensor &data, QByteArray &ba)
549  {
550  return writePODVector<float>(data.ev1()[0], 9, ba);
551  }
552 
553  // Specialize for vertex
554  template<>
555  inline bool writeAttr(const vertex &v, QByteArray &ba)
556  {
557  if(v.isNull()) {
558  Information::out << "writeAttr:Error, null vertex as key" << endl;
559  writePOD<uint>(std::numeric_limits<uint>::max(), ba); // A hack, but what else can we do?
560  return false;
561  }
562  return writePOD<uint>(v->saveId, ba);
563  }
564 
565  // Specialize for edge
566  template<>
567  inline bool writeAttr(const VtxVtxPair &e, QByteArray &ba)
568  {
569  return writeAttr(e.first, ba) and writeAttr(e.second, ba);
570  }
571 
572  // Specialize for triangle
573  template<>
574  inline bool writeAttr(const Triangle &t, QByteArray &ba)
575  {
576  return writePOD<uint>(t.v[0]->saveId, ba)
577  and writePOD<uint>(t.v[1]->saveId, ba)
578  and writePOD<uint>(t.v[2]->saveId, ba);
579  }
580 
581  // Specialize for cell
582  template<>
583  bool inline writeAttr(const cell &c, QByteArray &ba)
584  {
585  if(c.isNull()) {
586  Information::out << "writeAttr:Error, null cell as key" << endl;
587  writePOD<uint>(std::numeric_limits<uint>::max(), ba); // A hack, but what else can we do?
588  return false;
589  }
590  return writePOD<uint>(c->saveId, ba);
591  }
592 
593  // Specialize for wall
594  template<>
595  inline bool writeAttr(const CellCellPair &w, QByteArray &ba)
596  {
597  return writeAttr(w.first, ba) and writeAttr(w.second, ba);
598  }
599 
600  // Specialize for QString
601  template<>
602  inline bool writeAttr(const QString &s, QByteArray &ba)
603  {
604  QByteArray qba = s.toUtf8();
605  uint sz = qba.size();
606  return writeChar((char *)&sz, sizeof(uint), ba)
607  and writeChar((char *)qba.data(), sz, ba);
608  }
609 
610  // Specialize for QStringList
611  template<>
612  inline bool writeAttr(const QStringList &s, QByteArray &ba)
613  {
614  bool result = true;
615  for(int i = 0; i < s.size(); i++){
616  result &= writeAttr(s[i], ba);
617  }
618  return result;
619  }
620 
621  // Specialize for QByteArray
622  template<>
623  inline bool writeAttr(const QByteArray &qba, QByteArray &ba)
624  {
625  uint sz = qba.size();
626  return writeChar((char *)&sz, sizeof(uint), ba)
627  and writeChar((char *)qba.data(), sz, ba);
628  }
629 
630  // Specialize for Colorb
631  template<>
632  inline bool writeAttr(const Colorb &color, QByteArray &ba)
633  {
634  if(!writeChar(&color[0], sizeof(Colorb), ba))
635  return false;
636  return true;
637  }
638 
639  // Standard vectors
640  template <typename T>
641  bool writeAttr(const std::vector<T> &data, QByteArray &ba)
642  {
643  uint n = data.size();
644  if(!writeAttr(n, ba))
645  return false;
646 
647  for(size_t i = 0; i < n; ++i)
648  if(!writeAttr(data[i], ba))
649  return false;
650  return true;
651  }
652 
653  // Standard maps
654  template <typename KeyT, typename ValueT>
655  bool writeAttr(const std::map<KeyT, ValueT> &data, QByteArray &ba)
656  {
657  uint n = data.size();
658  if(!writeAttr(n, ba))
659  return false;
660 
661  for(typename std::map<KeyT, ValueT>::const_iterator i = data.begin(); i != data.end(); ++i) {
662  if(!writeAttr(i->first, ba))
663  return false;
664  if(!writeAttr(i->second, ba))
665  return false;
666  }
667  return true;
668  }
669 
685  template<typename KeyT, typename ValueT>
686  class AttrMap
687  {
688  public:
689  typedef std::pair<KeyT, ValueT> pair;
690  typedef typename STD_MAP<KeyT, ValueT>::iterator iterator;
691  typedef typename STD_MAP<KeyT, ValueT>::const_iterator const_iterator;
692 
693  // Constructor
694  AttrMap() : _defaultVal(ValueT())
695  {
696  omp_init_lock(&_lock);
697  };
698  explicit AttrMap(const ValueT &defaultVal) : _defaultVal(defaultVal)
699  {
700  omp_init_lock(&_lock);
701  };
702 
703  // Range constructor
704  template<typename IterT>
705  AttrMap(IterT first, IterT last, const ValueT &defaultVal = ValueT()) : _defaultVal(defaultVal)
706  {
707  _map.insert(first, last);
708  omp_init_lock(&_lock);
709  }
710 
711  // Copy constructor
712  AttrMap(const AttrMap &a) : _map(a._map), _defaultVal(a._defaultVal)
713  {
714  omp_init_lock(&_lock);
715  }
716 
717  // Assignment
719  {
720  _map = a._map;
721  _defaultVal = a._defaultVal;
722 
723  return *this;
724  }
725 
726  // Destructor
728  {
729  }
730 
737  const ValueT &operator[](const KeyT &key) const
738  {
739  const_iterator it = _map.find(key);
740  if(it == _map.end())
741  return _defaultVal;
742  return it->second;
743  }
744 
751  ValueT &operator[](const KeyT &key)
752  {
753  return _map[key];
754  }
755 
759  const ValueT &at(const KeyT &key) const
760  {
761  return (*this)[key];
762  }
763 
767  const ValueT &defaultVal() const
768  {
769  return _defaultVal;
770  };
771  ValueT &defaultVal()
772  {
773  return _defaultVal;
774  };
775 
776 // RSS The map should not be called directly, it may change
777 // /**
778 // * Get a reference to the map
779 // */
780 // const STD_MAP<KeyT, ValueT> &map() const
781 // {
782 // return _map;
783 // };
784 // STD_MAP<KeyT, ValueT> &map()
785 // {
786 // return _map;
787 // };
788 
792  ValueT &defaulVal()
793  {
794  return _defaultVal;
795  }
796  const ValueT &defaulVal() const
797  {
798  return _defaultVal;
799  }
800 
801  // The rest are boilerplate methods.
802  size_t size() const { return _map.size(); }
803  bool empty() const { return _map.empty(); }
804  size_t count (const KeyT &key) const { return _map.count(key); }
805  iterator begin() { return _map.begin(); }
806  const_iterator begin() const { return _map.begin(); }
807  iterator end() { return _map.end(); }
808  const_iterator end() const { return _map.end(); }
809  iterator find(const KeyT &key) { return _map.find(key); }
810  const_iterator find(const KeyT &key) const { return _map.find(key); }
811 
812  // RSS we need to clear the cache if the methods exist
813  void erase(iterator pos) { _map.unsafe_erase(pos); }
814  size_t erase(const KeyT &key) { return _map.unsafe_erase(key); }
815  void erase(iterator first, iterator last) { _map.unsafe_erase(first, last); }
816 
817  void clear() { _map.clear(); }
818  template<typename IterT>
819  void insert(IterT first, IterT last) { _map.insert(first, last); }
820 
821  private:
822  STD_MAP<KeyT, ValueT, std::hash<KeyT> > _map;
823  omp_lock_t _lock;
824  ValueT _defaultVal;
825  };
826 
827  // Convenience typedefs
839 
851 
863 
875 
887 
899 
909 
917  class mgx_EXPORT Attributes
918  {
919  private:
920  // These next two classes are only used from Attributes
925  class AttributeBase
926  {
927  public:
931  AttributeBase(const QString &name) : _name(name)
932  {
933  //Information::out << "Creating attribute:" << _name << endl; //NB
934  }
935 
939  virtual ~AttributeBase()
940  {
941  //Information::out << "Deleting attribute:" << _name << endl;
942  }
943 
947  const QString &name() { return _name; }
948 
952  virtual bool write(QByteArray &) { return true; }
953 
957  virtual void clear() {}
958 
962  virtual size_t size() = 0;
963 
964 
965  private:
966  QString _name;
967  };
976  template <typename KeyT, typename ValueT>
977  class Attribute : public AttributeBase
978  {
979  public:
984  Attribute(const QString &name, const ValueT &defaultVal = ValueT())
985  : AttributeBase(name), _map(defaultVal) {}
986 
990  ~Attribute() {}
991 
995  AttrMap<KeyT, ValueT> &map() { return _map; }
996  const AttrMap<KeyT, ValueT> &map() const { return _map; }
997 
1002  bool write(QByteArray &ba)
1003  {
1004  ba.clear();
1005 
1006  // Count the non-default entries
1007  size_t count = 0;
1008  for(typename AttrMap<KeyT, ValueT>::iterator i = _map.begin(); i != _map.end(); ++i)
1009  if(i->second == _map.defaultVal())
1010  continue;
1011  else
1012  count++;
1013 
1014  // Write the count
1015  writeAttr(count, ba);
1016 
1017  // Now write the map
1018  for(typename AttrMap<KeyT, ValueT>::iterator i = _map.begin(); i != _map.end(); ++i) {
1019  // Only write the non-default entries.
1020  if(i->second == _map.defaultVal())
1021  continue;
1022 
1023  // Write the key and value types
1024  if(writeAttr(i->first, ba)) {
1025  writeAttr(i->second, ba);
1026  } else {
1027  Information::out << "Attributes::write Error, key write failed" << endl;
1028  writeAttr(_map.defaultVal(), ba); // Happens if key write fails, like for vertices if null
1029  }
1030  progressAdvance();
1031  }
1032 
1033  // Write the default value
1034  writeAttr(_map.defaultVal(), ba);
1035 
1036  return true;
1037  }
1038 
1044  bool read(QByteArray &ba)
1045  {
1046  size_t pos = 0;
1047 
1048  // Read the count
1049  size_t count = 0;
1050  if(!readAttr(count, ba, pos))
1051  return false;
1052 
1053  // Key is overwritten by readAttr and does not need to be initialized.
1054 #pragma GCC diagnostic push
1055 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
1056  // Read in the map
1057  for(size_t i = 0; i < count; ++i) {
1058  KeyT key;
1059  readAttr(key, ba, pos);
1060  ValueT value;
1061  readAttr(value, ba, pos);
1062  _map[key] = value;
1063  progressAdvance();
1064  }
1065  // Read the default value
1066  ValueT value;
1067  if(!readAttr(value, ba, pos))
1068  return false;
1069  _map.defaultVal() = value;
1070 #pragma GCC diagnostic pop
1071 
1072  return true;
1073  }
1074 
1078  void clear()
1079  {
1080  _map.clear();
1081  }
1082 
1086  virtual size_t size() { return _map.size(); }
1087 
1088 
1089  private:
1090  AttrMap<KeyT, ValueT> _map;
1091  };
1092 
1093  public:
1098  Attributes() : _attributes(0), _saveRequired(true), _vMapAttr(0), _cMapAttr(0)
1099  {
1100  omp_init_lock(&_lock);
1101  }
1105  virtual ~Attributes ()
1106  {
1107  clear();
1108  }
1109 
1115  template <typename KeyT, typename ValueT>
1116  AttrMap<KeyT, ValueT>&attrMap(const QString &name, bool saveRequired = true)
1117  {
1118  Attribute<KeyT, ValueT> *a = dynamic_cast<Attribute<KeyT, ValueT> *>(_attributes[name]);
1119  if(!a) {
1120  // If the previous attribute with this name was a different type, delete it
1121  // and print a warning, if it is a system attribute throw an error
1122  if(_attributes[name]) {
1123  Information::out << "Warning, changing type for attribute: " << name << endl;
1124  delete _attributes[name];
1125  }
1126  a = new Attribute<KeyT, ValueT>(name);
1127  _attributes[name] = a;
1128  }
1129  // Check if attribute is loaded from byte array
1130  if(_ba[name].size() > 0) {
1131  vMap = _vMapAttr;
1132  cMap = _cMapAttr;
1133  // If there is a read error, it probably means it has a different layout, clear it
1134  if(!a->read(_ba[name])) {
1135  a->clear();
1136  Information::out << "Read error for attribute: " << name << ", clearing" << endl;
1137  } else
1138  Information::out << "Loaded attribute: " << name << ", Size:" << a->map().size() << endl;
1139  _ba[name].clear();
1140  }
1141  if(saveRequired)
1142  _saveRequired[name] = true;
1143 
1144  return a->map();
1145  }
1146 
1150  template <typename KeyT, typename ValueT>
1151  const AttrMap<KeyT, ValueT>* getAttrMap(const QString &name) const
1152  {
1153  const AttributeBase *attrbase = _attributes[name];
1154  const Attribute<KeyT, ValueT> *a = dynamic_cast<const Attribute<KeyT, ValueT> *>(attrbase);
1155  if (!a) {
1156  return 0;
1157  }
1158  return &a->map();
1159  }
1160 
1165  bool saveRequired(const QString &name) const
1166  {
1167  return _saveRequired[name];
1168  }
1169  bool setSaveRequired(const QString &name, bool saveReq)
1170  {
1171  return _saveRequired[name] = saveReq;
1172  }
1173 
1178  void erase(const QString &name)
1179  {
1180  AttributeBase *a = _attributes[name];
1181  if(a)
1182  delete a;
1183  _attributes.erase(name);
1184  }
1185 
1186 
1191  void clear()
1192  {
1193  // First erase the allocated items
1194  for(STD_MAP<QString, AttributeBase*>::iterator
1195  a = _attributes.begin(); a != _attributes.end(); ) {
1196  if(a->second)
1197  delete a->second;
1198  // Remove the maps
1199  AttrMap<QString, bool>::iterator saveIt = _saveRequired.find(a->first);
1200  if(saveIt != _saveRequired.end())
1201  _saveRequired.erase(saveIt);
1202  AttrMap<QString, QByteArray>::iterator baIt = _ba.find(a->first);
1203  if(baIt != _ba.end())
1204  _ba.erase(baIt);
1205 
1206  // and the attribute
1207  _attributes.erase(a++);
1208  }
1209 
1210  // Clear the vertex and cell maps
1211  if(_vMapAttr)
1212  delete _vMapAttr;
1213  _vMapAttr = 0;
1214  if(_cMapAttr)
1215  delete _cMapAttr;
1216  _cMapAttr = 0;
1217  }
1218 
1223  bool write(QIODevice &file)
1224  {
1225  // Find the number of attributes to save
1226  typedef std::pair<QString, bool> QStringBoolPair;
1227  size_t count = 0;
1228  forall(const QStringBoolPair &i, _attributes)
1229  if(_saveRequired[i.first])
1230  count++;
1231  writeFile(file, count);
1232 
1233  // Write the starting locations of each attribute, we'll fill them in as we go
1234  qint64 attrPos = file.pos();
1235  file.seek(attrPos + (count + 1) * sizeof(size_t));
1236 
1237  if(count > 0)
1238  Information::out << "Writing attributes:";
1239 
1240  typedef std::pair<QString, AttributeBase*> QStringAttrBasePr;
1241  forall(const QStringAttrBasePr &i, _attributes) {
1242  QString name = i.first;
1243  if(!_saveRequired[name])
1244  continue;
1245 
1246  // Put address of attribute in table at the start
1247  qint64 currentPos = file.pos();
1248  file.seek(attrPos);
1249  writeFile(file, size_t(currentPos));
1250  attrPos = file.pos();
1251  file.seek(currentPos);
1252 
1253  AttributeBase* ab = i.second;
1254 
1255  progressSetMsg(QString("Writing attribute: %1").arg(name));
1256 
1257  // Write the name
1258  writeFile(file, name);
1259 
1260  // If it was converted call the writer, otherwise just write the bytes.
1261  if(_ba[name].size() == 0) {
1262  QByteArray ba;
1263  ab->write(ba);
1264  file.write((char *)ba.data(),ba.size());
1265  Information::out << " " << name << ":" << ba.size();
1266  } else {
1267  file.write((char *)_ba[name].data(),_ba[name].size());
1268  Information::out << " " << name << ":" << _ba[name].size();
1269  }
1270  }
1271  if(count > 0)
1272  Information::out << "." << endl;
1273  // Put address of attribute in table at the start
1274  qint64 currentPos = file.pos();
1275  file.seek(attrPos);
1276  writeFile(file, size_t(currentPos));
1277  file.seek(currentPos);
1278 
1279  return true;
1280  }
1281 
1287  bool read(QIODevice &file, bool clearAttr = true)
1288  {
1289  // First clear whats there
1290  if(clearAttr)
1291  clear();
1292 
1293  // Read the number of attributes
1294  size_t count;
1295  readFile(file, count);
1296 
1297  // Read the starting location of each attribute, the last one is the end
1298  std::vector<size_t> attrPos;
1299  for(size_t i = 0; i <= count; ++i) {
1300  size_t pos;
1301  readFile(file, pos);
1302  attrPos.push_back(pos);
1303  }
1304 
1305  if(count > 0)
1306  Information::out << "Read attributes:";
1307 
1308  for(size_t i = 0; i < count; ++i) {
1309  // Go to attribute
1310  file.seek(attrPos[i]);
1311 
1312  // Read the name
1313  QString name;
1314  readFile(file, name);
1315 
1316  progressSetMsg(QString("Reading attribute: %1").arg(name));
1317 
1318  // If attributes exist for this name, clear them
1319  if(_attributes[name]) {
1320  delete _attributes[name];
1321  _attributes[name] = 0;
1322  }
1323 
1324  // Read in the data
1325  size_t sz = attrPos[i+1] - attrPos[i];
1326  QByteArray ba(sz, 0);
1327  file.read(ba.data(), sz);
1328  _ba[name] = ba;
1329  _saveRequired[name] = true;
1330  if(qint64(sz) != _ba[name].size())
1331  Information::out << endl << QString(
1332  "Warning, chars read (%1) doesn't match file size (%2) for attribute: %3")
1333  .arg(_ba[name].size()).arg(sz).arg(name) << endl;
1334  else
1335  Information::out << " " << name << ":" << ba.size();
1336  }
1337  if(count > 0)
1338  Information::out << "." << endl;
1339  file.seek(attrPos[count]);
1340 
1341  return true;
1342  }
1343 
1350  bool read(QIODevice &file, IntVtxMap *vMap, IntCellMap *cMap, bool clearAttr = true)
1351  {
1352  if(!read(file, clearAttr))
1353  return false;
1354  saveVtxCellMaps(vMap, cMap, clearAttr);
1355  return true;
1356  }
1357 
1358 
1364  bool saveVtxCellMaps(IntVtxMap *vMap, IntCellMap *cMap, bool clearAttr)
1365  {
1366  // Grab a copy of the vertex map, should only be called when loading the file
1367  // RSS Note that this will also keep the vertices alive, can we delete it at some point?
1368  if(vMap and _vMapAttr and clearAttr) {
1369  delete _vMapAttr;
1370  _vMapAttr = 0;
1371  }
1372  if(cMap and _cMapAttr and clearAttr) {
1373  delete _cMapAttr;
1374  _cMapAttr = 0;
1375  }
1376  if(vMap and !_vMapAttr)
1377  _vMapAttr = new IntVtxMap;
1378  if(cMap and !_cMapAttr)
1379  _cMapAttr = new IntCellMap;
1380 
1381  // Copy the data
1382  if(vMap)
1383  *_vMapAttr = *vMap;
1384  if(cMap)
1385  *_cMapAttr = *cMap;
1386 
1387  return true;
1388  }
1389 
1390  virtual size_t size(QString _name)
1391  {
1392  if(_name.size() != 0 and _attributes.find(_name) != _attributes.end()){
1393  if(_attributes[_name] != 0)
1394  return _attributes[_name]->size();
1395  }
1396  return 0;
1397  }
1398 
1402  QStringList getAttrList() const //NB
1403  {
1404  QStringList attrList;
1405  //Iterate over the _attributes map to get list of attributes
1406  for(AttrMap<QString, AttributeBase*>::const_iterator i = _attributes.begin(); i != _attributes.end(); ++i) {
1407  //qDebug() <<"\nQString in getAttrList\t" <<i->first ;
1408 
1409  if(_ba.find(i->first) != _ba.end())
1410  attrList << i->first;
1411  }
1412  return attrList;
1413  }
1414 
1418  QStringList clearNotparsedAttrList() const //NB
1419  {
1420  QStringList attrList;
1421  //Iterate over the _attributes map to get list of attributes
1422  for(AttrMap<QString, AttributeBase*>::const_iterator i = _attributes.begin(); i != _attributes.end(); ++i) {
1423  //qDebug() <<"\nQString in getAttrList\t" <<i->first ;
1424  if(_ba.find(i->first) != _ba.end() and _attributes.find(i->first) != _attributes.end()){ //Attributes that are parsed are put in the tree, rest removed -- check size : TODO
1425  if(_ba[i->first].size() == 0 and _attributes[i->first]->size() > 0)
1426  attrList <<i->first;
1427  }
1428  }
1429  //qDebug() <<"\nclearNotparsedAttrList\t" << attrList.size();
1430  return attrList;
1431  }
1432 
1433  private:
1434  // Attribute data and meta-data
1437  AttrMap<QString, bool> _saveRequired;
1438 
1439  // Pointer to vertex map to decode saveIds
1440  IntVtxMap *_vMapAttr;
1441  IntCellMap *_cMapAttr;
1442 
1443  omp_lock_t _lock;
1444  };
1445 
1446  // Syntax sugar for attributes.
1447  template<typename KeyT, typename ValueT>
1448  ValueT &operator->*(const KeyT &key, AttrMap<KeyT, ValueT> &map)
1449  {
1450  return map[key];
1451  }
1452  template<typename KeyT, typename ValueT>
1453  ValueT &operator->*(const KeyT &key, AttrMap<KeyT, ValueT> *map)
1454  {
1455  return (*map)[key];
1456  }
1457 
1458  // Since VV edges are second-class, walls and edges need special treatment
1459  template<typename ValueT>
1461  {
1462  return (*map)[CellCellPair(cell(e.source()), cell(e.target()))];
1463  }
1464  template<typename ValueT>
1466  {
1467  return map[CellCellPair(cell(e.source()), cell(e.target()))];
1468  }
1469 
1470  template<typename ValueT>
1472  {
1473  return map[VtxVtxPair(vertex(e.source()), vertex(e.target()))];
1474  }
1475  template<typename ValueT>
1477  {
1478  return (*map)[VtxVtxPair(vertex(e.source()), vertex(e.target()))];
1479  }
1480 }
1481 #endif
mgx::Attributes::clearNotparsedAttrList
QStringList clearNotparsedAttrList() const
Return a list of unparsed attribute names.
Definition: Attributes.hpp:1418
mgx::EdgeFloatAttr
AttrMap< edge, float > EdgeFloatAttr
Definition: Attributes.hpp:854
mgx::WallPoint2fAttr
AttrMap< wall, Point2f > WallPoint2fAttr
Definition: Attributes.hpp:879
mgx::uint
unsigned int uint
Definition: Geometry.hpp:41
mgx::AttrMap::empty
bool empty() const
Definition: Attributes.hpp:803
Features.hpp
mgx::VtxVec3ColorbAttr
AttrMap< vertex, Vec3Colorb > VtxVec3ColorbAttr
Definition: Attributes.hpp:847
mgx::AttrMap::pair
std::pair< KeyT, ValueT > pair
Definition: Attributes.hpp:689
mgx::AttrMap::operator[]
const ValueT & operator[](const KeyT &key) const
const Accessor
Definition: Attributes.hpp:737
mgx::vertex
vvGraph::vertex_t vertex
Type of a vertex.
Definition: Misc.hpp:50
mgx::QStringSymTensorAttr
AttrMap< QString, SymmetricTensor > QStringSymTensorAttr
Definition: Attributes.hpp:907
mgx::AttrMap::AttrMap
AttrMap(const ValueT &defaultVal)
Definition: Attributes.hpp:698
mgx::Attributes
Holds a set of attributes.
Definition: Attributes.hpp:917
mgx::AttrMap::AttrMap
AttrMap()
Definition: Attributes.hpp:694
mgx::IntIntPoint3fAttr
AttrMap< IntIntPair, Point3f > IntIntPoint3fAttr
Definition: Attributes.hpp:838
mgx::WallQStringAttr
AttrMap< wall, QString > WallQStringAttr
Definition: Attributes.hpp:886
Common.hpp
mgx::EdgeVec2ColorbAttr
AttrMap< edge, Vec2Colorb > EdgeVec2ColorbAttr
Definition: Attributes.hpp:858
mgx::Edge::target
identity_t target() const
Returns the identifier of the target of the edge.
Definition: Edge.hpp:178
mgx::AttrMap::defaulVal
ValueT & defaulVal()
The default value.
Definition: Attributes.hpp:792
mgx::CellMatrix3fAttr
AttrMap< cell, Matrix3f > CellMatrix3fAttr
Definition: Attributes.hpp:872
mgx::VtxFloatAttr
AttrMap< vertex, float > VtxFloatAttr
Definition: Attributes.hpp:842
mgx::AttrMap::erase
size_t erase(const KeyT &key)
Definition: Attributes.hpp:814
mgx::Attributes::saveRequired
bool saveRequired(const QString &name) const
Get a reference to the attribute's save status, it will be created if it doesn't exist.
Definition: Attributes.hpp:1165
Information.hpp
mgx::Edge::source
identity_t source() const
Returns the identifier of the source of the edge.
Definition: Edge.hpp:169
mgx::progressSetMsg
void progressSetMsg(const std::string &msg)
mgx::Vec3Colorb
Vector< 3, Colorb > Vec3Colorb
Definition: Attributes.hpp:64
mgx::QStringVec3ColorbAttr
AttrMap< QString, Vec3Colorb > QStringVec3ColorbAttr
Definition: Attributes.hpp:905
mgx::operator->*
ValueT & operator->*(const KeyT &key, AttrMap< KeyT, ValueT > &map)
Definition: Attributes.hpp:1448
mgx::AttrMap::insert
void insert(IterT first, IterT last)
Definition: Attributes.hpp:819
IS_POD
#define IS_POD(T)
Determines if template arguments are plain old data (POD) types.
Definition: Attributes.hpp:59
mgx::VtxPoint3fAttr
AttrMap< vertex, Point3f > VtxPoint3fAttr
Definition: Attributes.hpp:844
mgx::AttrMap::operator=
AttrMap & operator=(const AttrMap &a)
Definition: Attributes.hpp:718
mgx::AttrMap::erase
void erase(iterator first, iterator last)
Definition: Attributes.hpp:815
mgx::AttrMap::end
iterator end()
Definition: Attributes.hpp:807
mgx::EdgeVec3ColorbAttr
AttrMap< edge, Vec3Colorb > EdgeVec3ColorbAttr
Definition: Attributes.hpp:859
mgx::AttrMap::size
size_t size() const
Definition: Attributes.hpp:802
mgx::Edge
Definition: Edge.hpp:42
mgx::SymmetricTensor
Definition: SymmetricTensor.hpp:59
forall
#define forall
Definition: Forall.hpp:22
mgx::IntIntFloatAttr
AttrMap< IntIntPair, float > IntIntFloatAttr
Definition: Attributes.hpp:837
mgx::EdgeQStringAttr
AttrMap< edge, QString > EdgeQStringAttr
Definition: Attributes.hpp:862
n
#define n
Definition: Eigenvalues.hpp:36
uint
unsigned int uint
Definition: MorphoGraphX.hpp:14
mgx::TriSymTensorAttr
AttrMap< Triangle, SymmetricTensor > TriSymTensorAttr
Definition: Attributes.hpp:897
mgx::CellIntAttr
AttrMap< cell, int > CellIntAttr
Definition: Attributes.hpp:864
mgx::Vec2Colorb
Vector< 2, Colorb > Vec2Colorb
Definition: Attributes.hpp:63
mgx::CellSymTensorAttr
AttrMap< cell, SymmetricTensor > CellSymTensorAttr
Definition: Attributes.hpp:873
mgx::TriPoint3fAttr
AttrMap< Triangle, Point3f > TriPoint3fAttr
Definition: Attributes.hpp:892
Colors.hpp
mgx::CellColorbAttr
AttrMap< cell, Colorb > CellColorbAttr
Definition: Attributes.hpp:869
mgx::EdgeMatrix3fAttr
AttrMap< edge, Matrix3f > EdgeMatrix3fAttr
Definition: Attributes.hpp:860
mgx::VtxQStringAttr
AttrMap< vertex, QString > VtxQStringAttr
Definition: Attributes.hpp:850
mgx::AttrMap::begin
const_iterator begin() const
Definition: Attributes.hpp:806
mgx::IntVtxMap
std::unordered_map< int, vertex > IntVtxMap
Int to vertex map.
Definition: Types.hpp:146
mgx::VtxVtxPair
std::pair< vertex, vertex > VtxVtxPair
Definition: Types.hpp:150
mgx::AttrMap::erase
void erase(iterator pos)
Definition: Attributes.hpp:813
mgx::AttrMap::AttrMap
AttrMap(const AttrMap &a)
Definition: Attributes.hpp:712
mgx::Attributes::write
bool write(QIODevice &file)
Write the attributes to a file.
Definition: Attributes.hpp:1223
mgx::AttrMap::const_iterator
STD_MAP< KeyT, ValueT >::const_iterator const_iterator
Definition: Attributes.hpp:691
mgx::IntIntAttr
AttrMap< int, int > IntIntAttr
Definition: Attributes.hpp:828
mgx::IntVec2ColorbAttr
AttrMap< int, Vec2Colorb > IntVec2ColorbAttr
Definition: Attributes.hpp:832
mgx::Attributes::read
bool read(QIODevice &file, bool clearAttr=true)
Read the attributes from a file.
Definition: Attributes.hpp:1287
mgx::Vertex::isNull
bool isNull() const
Test if a vertex is a null vertex.
Definition: Vertex.hpp:235
mgx::VtxVec2ColorbAttr
AttrMap< vertex, Vec2Colorb > VtxVec2ColorbAttr
Definition: Attributes.hpp:846
mgx::VtxColorbAttr
AttrMap< vertex, Colorb > VtxColorbAttr
Definition: Attributes.hpp:845
mgx::CellBoolAttr
AttrMap< cell, bool > CellBoolAttr
Definition: Attributes.hpp:865
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::QStringMatrix3fAttr
AttrMap< QString, Matrix3f > QStringMatrix3fAttr
Definition: Attributes.hpp:906
mgx::TriQStringAttr
AttrMap< Triangle, QString > TriQStringAttr
Definition: Attributes.hpp:898
mgx::CellFloatAttr
AttrMap< cell, float > CellFloatAttr
Definition: Attributes.hpp:866
mgx::EdgePoint3fAttr
AttrMap< edge, Point3f > EdgePoint3fAttr
Definition: Attributes.hpp:856
mgx::EdgeColorbAttr
AttrMap< edge, Colorb > EdgeColorbAttr
Definition: Attributes.hpp:857
mgx::VtxPoint2fAttr
AttrMap< vertex, Point2f > VtxPoint2fAttr
Definition: Attributes.hpp:843
mgx::CellCellPair
std::pair< cell, cell > CellCellPair
Definition: Types.hpp:174
mgx::AttrMap::at
const ValueT & at(const KeyT &key) const
Counterpart to map::at(), which returns reference to default value if key is not found.
Definition: Attributes.hpp:759
mgx::WallSymTensorAttr
AttrMap< wall, SymmetricTensor > WallSymTensorAttr
Definition: Attributes.hpp:885
mgx::Attributes::getAttrMap
const AttrMap< KeyT, ValueT > * getAttrMap(const QString &name) const
Try to get a constant pointer to an attribute.
Definition: Attributes.hpp:1151
mgx::vMap
mgx_EXPORT IntVtxMap * vMap
Maps for saveId for vertices and cells, created when file is read Globals required for overloads of r...
mgx::WallVec3ColorbAttr
AttrMap< wall, Vec3Colorb > WallVec3ColorbAttr
Definition: Attributes.hpp:883
mgx::VtxIntAttr
AttrMap< vertex, int > VtxIntAttr
Definition: Attributes.hpp:840
mgx::cMap
mgx_EXPORT IntCellMap * cMap
mgx::TriVec3ColorbAttr
AttrMap< Triangle, Vec3Colorb > TriVec3ColorbAttr
Definition: Attributes.hpp:895
mgx::AttrMap::clear
void clear()
Definition: Attributes.hpp:817
mgx::TriVec2ColorbAttr
AttrMap< Triangle, Vec2Colorb > TriVec2ColorbAttr
Definition: Attributes.hpp:894
mgx::WallMatrix3fAttr
AttrMap< wall, Matrix3f > WallMatrix3fAttr
Definition: Attributes.hpp:884
mgx::CellPoint3fAttr
AttrMap< cell, Point3f > CellPoint3fAttr
Definition: Attributes.hpp:868
mgx::AttrMap::find
iterator find(const KeyT &key)
Definition: Attributes.hpp:809
mgx::Attributes::saveVtxCellMaps
bool saveVtxCellMaps(IntVtxMap *vMap, IntCellMap *cMap, bool clearAttr)
Set the saveId-vertex map for loading vertex and Index attributes Since the readAttr and writeAttr ar...
Definition: Attributes.hpp:1364
mgx::VtxBoolAttr
AttrMap< vertex, bool > VtxBoolAttr
Definition: Attributes.hpp:841
mgx::EdgePoint2fAttr
AttrMap< edge, Point2f > EdgePoint2fAttr
Definition: Attributes.hpp:855
Hash.hpp
mgx::max
T CU_HOST_DEVICE max(const T a, const T b)
Definition: Util.hpp:34
enable_if< true, _Tp >::type
_Tp type
Definition: Attributes.hpp:54
mgx::Attributes::~Attributes
virtual ~Attributes()
Destructor.
Definition: Attributes.hpp:1105
mgx::CellQStringAttr
AttrMap< cell, QString > CellQStringAttr
Definition: Attributes.hpp:874
mgx::QStringPoint3fAttr
AttrMap< QString, Point3f > QStringPoint3fAttr
Definition: Attributes.hpp:902
mgx::TriBoolAttr
AttrMap< Triangle, bool > TriBoolAttr
Definition: Attributes.hpp:889
Triangle.hpp
mgx::Attributes::attrMap
AttrMap< KeyT, ValueT > & attrMap(const QString &name, bool saveRequired=true)
Get the attribute, if it does not exist create it and add to the set If it exists,...
Definition: Attributes.hpp:1116
mgx::WallBoolAttr
AttrMap< wall, bool > WallBoolAttr
Definition: Attributes.hpp:877
mgx::AttrMap::~AttrMap
~AttrMap()
Definition: Attributes.hpp:727
mgx::Triangle::v
vertex v[3]
Definition: Triangle.hpp:108
mgx::CellPoint2fAttr
AttrMap< cell, Point2f > CellPoint2fAttr
Definition: Attributes.hpp:867
mgx::Attributes::Attributes
Attributes()
Constructor.
Definition: Attributes.hpp:1098
mgx::QStringQStringAttr
AttrMap< QString, QString > QStringQStringAttr
Definition: Attributes.hpp:908
mgx::IntQStringAttr
AttrMap< int, QString > IntQStringAttr
Definition: Attributes.hpp:836
mgx::QStringColorbAttr
AttrMap< QString, Colorb > QStringColorbAttr
Definition: Attributes.hpp:903
mgx::Attributes::size
virtual size_t size(QString _name)
Definition: Attributes.hpp:1390
mgx::EdgeBoolAttr
AttrMap< edge, bool > EdgeBoolAttr
Definition: Attributes.hpp:853
mgx::VtxMatrix3fAttr
AttrMap< vertex, Matrix3f > VtxMatrix3fAttr
Definition: Attributes.hpp:848
mgx::Triangle
class Triangle Triangle.hpp <Triangle.hpp>
Definition: Triangle.hpp:31
mgx::Attributes::clear
void clear()
Clear the attributes.
Definition: Attributes.hpp:1191
mgx::WallFloatAttr
AttrMap< wall, float > WallFloatAttr
Definition: Attributes.hpp:878
mgx::AttrMap::defaultVal
ValueT & defaultVal()
Definition: Attributes.hpp:771
Progress.hpp
mgx::AttrMap::defaultVal
const ValueT & defaultVal() const
Get a reference to the default value.
Definition: Attributes.hpp:767
mgx::cell
cellGraph::vertex_t cell
Type of a vertex.
Definition: Types.hpp:122
mgx::IntMatrix3fAttr
AttrMap< int, Matrix3f > IntMatrix3fAttr
Definition: Attributes.hpp:834
mgx::QStringVec2ColorbAttr
AttrMap< QString, Vec2Colorb > QStringVec2ColorbAttr
Definition: Attributes.hpp:904
mgx::QStringIntAttr
AttrMap< QString, int > QStringIntAttr
Definition: Attributes.hpp:900
mgx::progressAdvance
bool progressAdvance()
mgx::AttrMap::operator[]
ValueT & operator[](const KeyT &key)
Accessor.
Definition: Attributes.hpp:751
mgx::Information::out
mgx_EXPORT QTextStream out
mgx::Attributes::getAttrList
QStringList getAttrList() const
Return a list of attribute names.
Definition: Attributes.hpp:1402
mgx::IntSymTensorAttr
AttrMap< int, SymmetricTensor > IntSymTensorAttr
Definition: Attributes.hpp:835
mgx::Vector
Namespace containing all the utility classes.
Definition: Vector.hpp:48
mgx::TriIntAttr
AttrMap< Triangle, int > TriIntAttr
Definition: Attributes.hpp:888
mgx::WallPoint3fAttr
AttrMap< wall, Point3f > WallPoint3fAttr
Definition: Attributes.hpp:880
mgx::AttrMap::find
const_iterator find(const KeyT &key) const
Definition: Attributes.hpp:810
mgx::Attributes::read
bool read(QIODevice &file, IntVtxMap *vMap, IntCellMap *cMap, bool clearAttr=true)
Read the attributes from a file.
Definition: Attributes.hpp:1350
mgx::WallColorbAttr
AttrMap< wall, Colorb > WallColorbAttr
Definition: Attributes.hpp:881
mgx::EdgeIntAttr
AttrMap< edge, int > EdgeIntAttr
Definition: Attributes.hpp:852
mgx::WallIntAttr
AttrMap< wall, int > WallIntAttr
Definition: Attributes.hpp:876
mgx::TriMatrix3fAttr
AttrMap< Triangle, Matrix3f > TriMatrix3fAttr
Definition: Attributes.hpp:896
mgx::IntCellMap
std::unordered_map< int, cell > IntCellMap
Int to cell map.
Definition: Types.hpp:176
mgx::IntFloatAttr
AttrMap< int, float > IntFloatAttr
Definition: Attributes.hpp:829
mgx::Color
A utility class to encapsulate color data.
Definition: Color.hpp:34
mgx::writeAttr
bool writeAttr(const T &data, QByteArray &ba)
Write the attribute value from a QByteArray.
Definition: Attributes.hpp:510
Types.hpp
mgx::Attributes::setSaveRequired
bool setSaveRequired(const QString &name, bool saveReq)
Definition: Attributes.hpp:1169
mgx::AttrMap::iterator
STD_MAP< KeyT, ValueT >::iterator iterator
Definition: Attributes.hpp:690
mgx::AttrMap::end
const_iterator end() const
Definition: Attributes.hpp:808
mgx::AttrMap::defaulVal
const ValueT & defaulVal() const
Definition: Attributes.hpp:796
mgx::Attributes::erase
void erase(const QString &name)
Erase an attribute.
Definition: Attributes.hpp:1178
mgx::QStringFloatAttr
AttrMap< QString, float > QStringFloatAttr
Definition: Attributes.hpp:901
mgx::SymmetricTensor::ev1
Point3f & ev1()
Definition: SymmetricTensor.hpp:90
mgx::WallVec2ColorbAttr
AttrMap< wall, Vec2Colorb > WallVec2ColorbAttr
Definition: Attributes.hpp:882
mgx::EdgeSymTensorAttr
AttrMap< edge, SymmetricTensor > EdgeSymTensorAttr
Definition: Attributes.hpp:861
mgx::TriPoint2fAttr
AttrMap< Triangle, Point2f > TriPoint2fAttr
Definition: Attributes.hpp:891
mgx::Matrix
Definition: Matrix.hpp:39
mgx::IntVec3ColorbAttr
AttrMap< int, Vec3Colorb > IntVec3ColorbAttr
Definition: Attributes.hpp:833
mgx::readAttr
bool readAttr(T &data, const QByteArray &ba, size_t &pos)
Read the attribute value from a QByteArray.
Definition: Attributes.hpp:244
mgx::IntPoint3fAttr
AttrMap< int, Point3f > IntPoint3fAttr
Definition: Attributes.hpp:830
mgx::TriFloatAttr
AttrMap< Triangle, float > TriFloatAttr
Definition: Attributes.hpp:890
mgx::AttrMap::count
size_t count(const KeyT &key) const
Definition: Attributes.hpp:804
mgx::CellVec2ColorbAttr
AttrMap< cell, Vec2Colorb > CellVec2ColorbAttr
Definition: Attributes.hpp:870
mgx::CellVec3ColorbAttr
AttrMap< cell, Vec3Colorb > CellVec3ColorbAttr
Definition: Attributes.hpp:871
mgx::IntColorbAttr
AttrMap< int, Colorb > IntColorbAttr
Definition: Attributes.hpp:831
mgx::AttrMap::AttrMap
AttrMap(IterT first, IterT last, const ValueT &defaultVal=ValueT())
Definition: Attributes.hpp:705
mgx::AttrMap
Attribute map wraps std::map.
Definition: Attributes.hpp:686
enable_if
Definition: Attributes.hpp:51
mgx::AttrMap::begin
iterator begin()
Definition: Attributes.hpp:805
mgx::TriColorbAttr
AttrMap< Triangle, Colorb > TriColorbAttr
Definition: Attributes.hpp:893
mgx::VtxSymTensorAttr
AttrMap< vertex, SymmetricTensor > VtxSymTensorAttr
Definition: Attributes.hpp:849
mgx::Vertex
Definition: Vertex.hpp:58
mgx::map
CU_HOST_DEVICE Vector< dim, T > map(const T &(*fct)(const T1 &), const Vector< dim, T1 > &v)
Definition: Vector.hpp:1380