aimstil  5.0.5
aims_wrap.h
Go to the documentation of this file.
1 #ifndef AIMS_WRAP_H_
2 #define AIMS_WRAP_H_
3 
4 
6 
7 // includes from AIMS
8 #include "aims/io/reader.h"
9 #include "aims/io/writer.h"
10 #include "aims/mesh/surface.h"
11 #include "aims/mesh/texture.h"
12 #include "aims/utility/anytype_reader.h"
13 #include "aims/vector/vector.h"
14 
15 // includes from TIL
16 #include "til/cat2type.h"
17 #include "til/is_traits.h"
18 #include "til/numeric_array.h"
19 //#include "til/Point.h"
20 
21 // includes from TIL
22 //#include "convert.h"
23 #include "globalTraits.h"
24 #include "MeshTraits.h"
25 #include "meshUtils.h"
26 
27 #define TIL_COMMA ,
28 
29 //-----------------------------------------------------------------------------
30 
35 template < typename T, int D >
36 inline
37 bool operator < (const AimsVector<T,D> &v1,
38  const AimsVector<T,D> &v2)
39 {
40  for (int d = 0; d < D; ++d)
41  {
42  if (v1.item(d) < v2.item(d))
43  return true;
44  else if (v2.item(d) < v1.item(d))
45  return false;
46  }
47  // v1 and v2 are equal: return false
48  return false;
49 }
50 
51 //-----------------------------------------------------------------------------
52 
55 inline
56 const char ** aims_const_hack(char** argv)
57 {
58  return static_cast<const char**>(static_cast<void*>(argv));
59  //const char * &temp = const_cast<char*&>(*argv);
60  //return &temp;
61 }
62 
63 //-----------------------------------------------------------------------------
64 
65 namespace til
66 {
67  //TODO: add an aims namespace for those functions that are not extending functionality of til but that are really
68  // adding functions in the namespace for manual convertions.
69 
71 
73  template < class T, int D >
74  inline std::size_t size(const AimsVector<T,D> &)
75  {
76  return D;
77  }
78 
79  template < typename T, int D >
80  void
81  add(AimsVector<T,D> & v1, const AimsVector<T,D> & v2)
82  {
83  v1 += v2;
84  }
85  template <typename T, int D>
86  void mul(AimsVector<T,D> &v, T d)
87  {
88  v *= d;
89  }
90 
91  template < typename T, int D >
92  struct value_type_of<AimsVector<T,D> > { typedef T type; };
93 
95 
96 
97 
98 
99 
101 
102  TIL_DECLARE_IS_SPEC_T(3DPoint, typename T, AimsVector<T TIL_COMMA 3>);
103 
105 
106 
107  namespace functor
108  {
109  template < >
110  class CastTo< boost::array<size_t, 3>, AimsVector<uint, 3> >
111  : public std::binary_function<boost::array<size_t, 3> &, const AimsVector<uint, 3> &, void>
112  {
113  public:
114  void operator()(boost::array<size_t, 3> & y, const AimsVector<uint, 3> & x) const
115  {
116  y[0] = x[0]; y[1] = x[1]; y[2] = x[2];
117  }
118  };
119 
120  template < >
121  class CastTo< AimsVector<uint, 3>, boost::array<size_t, 3> >
122  : public std::binary_function<AimsVector<uint, 3> &, const boost::array<size_t, 3> &, void>
123  {
124  public:
125  void
126  operator()(AimsVector<uint, 3> & y, const boost::array<size_t, 3> & x) const
127  {
128  y[0] = x[0]; y[1] = x[1]; y[2] = x[2];
129  }
130  };
131 
132  template < >
133  class CastTo< numeric_array<size_t, 3>, AimsVector<uint, 3> >
134  : public std::binary_function<numeric_array<size_t, 3> &, const AimsVector<uint, 3> &, void>
135  {
136  public:
137  void operator()(numeric_array<size_t, 3> & y, const AimsVector<uint, 3> & x) const
138  {
139  y[0] = x[0]; y[1] = x[1]; y[2] = x[2];
140  }
141  };
142 
143  template < >
144  class CastTo< AimsVector<uint, 3>, numeric_array<size_t, 3> >
145  : public std::binary_function<AimsVector<uint, 3> &, const numeric_array<size_t, 3> &, void>
146  {
147  public:
148  void
149  operator()(AimsVector<uint, 3> & y, const numeric_array<size_t, 3> & x) const
150  {
151  y[0] = x[0]; y[1] = x[1]; y[2] = x[2];
152  }
153  };
154 
155  template < >
156  class CastTo< numeric_array<float,3>, AimsVector<float,3> >
157  : public std::binary_function<numeric_array<float,3> &, const AimsVector<float,3> &, void>
158  {
159  public:
160  void
161  operator()(numeric_array<float,3> & y, const AimsVector<float,3> & x) const
162  {
163  y[0] = x[0]; y[1] = x[1]; y[2] = x[2];
164  }
165  };
166 
167  template < >
168  class CastTo< AimsVector<float,3>, numeric_array<float,3> >
169  : public std::binary_function<AimsVector<float,3> &, const numeric_array<float,3> &, void>
170  {
171  public:
172  void
173  operator()(AimsVector<float,3> & y, const numeric_array<float,3> & x) const
174  {
175  y[0] = x[0]; y[1] = x[1]; y[2] = x[2];
176  }
177  };
178  /*
179  template < >
180  class CastTo< Point<float,3>, AimsVector<float,3> >
181  : public std::binary_function<Point<float,3> &, const AimsVector<float,3> &, void>
182  {
183  public:
184  void
185  operator()(Point<float,3> & y, const AimsVector<float,3> & x) const
186  {
187  y[0] = x[0]; y[1] = x[1]; y[2] = x[2];
188  }
189  };
190 
191  template < >
192  class CastTo< AimsVector<float,3>, Point<float,3> >
193  : public std::binary_function<AimsVector<float,3> &, const Point<float,3> &, void>
194  {
195  public:
196  void
197  operator()(AimsVector<float,3> & y, const Point<float,3> & x) const
198  {
199  y[0] = x[0]; y[1] = x[1]; y[2] = x[2];
200  }
201  };
202  */
203 
204  template <typename TContainer>
205  class CastTo<Texture1d, TContainer>
206  : public std::binary_function<Texture1d &, const TContainer &, void>
207  {
208  public:
209  void
210  operator()(Texture1d & t, const TContainer & c)
211  {
212  for (std::size_t i=0; i<size(c); ++i)
213  t.item(i) = c[i];
214  }
215  };
216 
217  } // namespace functor
218 
219 /*
220  template < typename T1, typename T2, int D >
221  inline
222  void convert(const AimsVector<T1,D> & x, boost::array<T2,D> & y)
223  {
224  detail::convert_fixedLoop<D>(x,y);
225  }
226 
227  template < typename T1, typename T2, int D >
228  inline
229  void convert(const Vector<T1,D> & x, AimsVector<T2,D> & y)
230  {
231  detail::convert_fixedLoop<D>(x,y);
232  }
233 
234  template < typename T1, typename T2, int D >
235  inline
236  void convert(const AimsVector<T1,D> & x, Point<T2,D> & y)
237  {
238  detail::convert_fixedLoop<D>(x,y);
239  }
240  */
241 
242 
243  // This is assuming Texture1d is cleared
244  template <typename TContainer>
245  inline void convert(const TContainer &c, Texture1d & t)
246  {
247  for (std::size_t i=0; i<size(c); ++i)
248  t.item(i) = c[i];
249  }
250 
251 
252  /*
253  template < typename T1, typename T2>
254  inline
255  void convert(const AimsVector<T1,3> & x, Point<T2,3> & y)
256  {
257  detail::convert_fixedLoop<3>(x,y);
258  }
259  */
260 
261 
262  /*
263  template < typename T, int D >
264  inline
265  void convert(const AimsVector<T, D> & x, boost::array<T, D> & v)
266  {
267  for (int i=0; i<D; ++i) y[i]=x[i];
268  }
269  */
270  /*
272  template < typename T1, typename T2, int D >
273  inline
274  void convert(const AimsVector<T1,D> & x, Vector<T2,D> & y)
275  {
276  for (int i=0; i<D; ++i) convert(x[i], y[i]);
277  }
278  */
279 
281 
282 
283  //template < int D, class T > class AimsTimeSurfaceFaceCollection;
284 
286  template < int D, class T >
287  //struct MeshTraits<AimsTimeSurface<D,T> >
288  struct MeshTraits<AimsTimeSurface<D,T> > : public MeshTraits_default
289  {
290  // constants
291  enum { has_faces_indices = 1 };
292 
293  // typedefs
294  typedef Point3df Vertex;
295  typedef std::vector<Vertex> VertexCollection;
296  typedef AimsVector<uint, D> FaceIndex;
297  typedef std::vector<FaceIndex> FaceIndexCollection;
298  //typedef AimsTimeSurfaceFaceCollection<D,T> FaceCollection;
299  };
300 
301 
302  /*
306  template < int D, class T >
307  class AimsTimeSurfaceFaceCollection
308  {
309  public: // constructors & destructor
310  AimsTimeSurfaceFaceCollection(AimsTimeSurface<D,T> &mesh) :
311  m_mesh(mesh)
312  {
313  }
314 
315  public: // functions
316 
317 
318  class ConstIterator
319  {
320  / *
321  public: // Face
322 
323  class Face
324  {
325  public: // constructors & destructor
326  Face(const AimsTimeSurface<D,T> & mesh, typename MeshTraits<AimsTimeSurface<D,T> >::FaceIndex &f)
327  : m_mesh(mesh), m_f(f) {}
328 
329  public: // functions
330  typename MeshTraits<AimsTimeSurface<D,T> >::Vertex &
331  operator[](int i)
332  {
333  return getVertices(m_mesh)[m_f[i]];
334  }
335 
336  private: // data
337  const AimsTimeSurface<D,T> & m_mesh;
338  typename MeshTraits<AimsTimeSurface<D,T> >::FaceIndex & m_f;
339  };
340  * /
341 
342  public: // constructors & destructor
343  ConstIterator(AimsTimeSurface<D,T> & mesh, typename MeshTraits<AimsTimeSurface<D,T> >::FaceIndexCollection::iterator i)
344  : m_vertices(getVertices(mesh)), m_i(i) {}
345 
346  public: // functions
347  inline void operator++() { ++m_i; }
348  inline const ConstIterator & operator*() const { return (*this); }
349  inline bool operator!=(const ConstIterator &i) const { return m_i != i.m_i; }
350  inline const typename MeshTraits<AimsTimeSurface<D,T> >::Vertex &
351  operator[](int i) const
352  {
353  return m_vertices[(*m_i)[i]];
354  }
355 
356  private: // data
357  const typename MeshTraits<AimsTimeSurface<D,T> >::VertexCollection & m_vertices;
358  //const AimsTimeSurface<D,T> & m_mesh;
359  typename MeshTraits<AimsTimeSurface<D,T> >::FaceIndexCollection::iterator m_i;
360  //Face m_face;
361  };
362  typedef ConstIterator const_iterator;
363 
364  ConstIterator begin() { return ConstIterator(m_mesh, getFaceIndices(m_mesh).begin()); }
365  ConstIterator end() { return ConstIterator(m_mesh, getFaceIndices(m_mesh).end()); }
366 
367  private: // data
368  AimsTimeSurface<D,T> & m_mesh;
369  };
370  */
371 
372 
374  std::set<AimsVector<uint, 2> >
375  getEdges(const AimsSurfaceTriangle *surf);
376 
378 
379 
380  //template < int D, class T > class AimsSurfaceFaceCollection;
381 
383  template < int D, class T >
384  //struct MeshTraits<AimsTimeSurface<D,T> >
385  struct MeshTraits<AimsSurface<D,T> > : public MeshTraits_default
386  {
387  // constants
388  static const bool has_edges = false;
389  static const bool has_faces = false;
390  static const bool has_faces_indices = true;
391 
392  // typedefs
393  typedef Point3df Vertex;
394  typedef std::vector<Vertex> VertexCollection;
395  typedef AimsVector<uint, D> FaceIndex;
396  typedef std::vector<FaceIndex> FaceIndexCollection;
397  //typedef AimsSurfaceFaceCollection<D,T> FaceCollection;
398  };
399 
400 
401 
402  /*
405  template < int D, class T >
406  class AimsSurfaceFaceCollection
407  {
408  public: // constructors & destructor
409  AimsSurfaceFaceCollection(AimsSurface<D,T> &mesh) :
410  m_mesh(mesh)
411  {
412  }
413 
414  public: // functions
415 
416 
417  class ConstIterator
418  {
419  / *
420  public: // Face
421 
422  class Face
423  {
424  public: // constructors & destructor
425  Face(const AimsTimeSurface<D,T> & mesh, typename MeshTraits<AimsTimeSurface<D,T> >::FaceIndex &f)
426  : m_mesh(mesh), m_f(f) {}
427 
428  public: // functions
429  typename MeshTraits<AimsTimeSurface<D,T> >::Vertex &
430  operator[](int i)
431  {
432  return getVertices(m_mesh)[m_f[i]];
433  }
434 
435  private: // data
436  const AimsTimeSurface<D,T> & m_mesh;
437  typename MeshTraits<AimsTimeSurface<D,T> >::FaceIndex & m_f;
438  };
439  * /
440 
441  public: // constructors & destructor
442  ConstIterator(AimsSurface<D,T> & mesh, typename MeshTraits<AimsSurface<D,T> >::FaceIndexCollection::iterator i)
443  : m_vertices(getVertices(mesh)), m_i(i) {}
444 
445  public: // functions
446  inline void operator++() { ++m_i; }
447  inline const ConstIterator & operator*() const { return (*this); }
448  inline bool operator!=(const ConstIterator &i) const { return m_i != i.m_i; }
449  inline const typename MeshTraits<AimsSurface<D,T> >::Vertex &
450  operator[](int i) const
451  {
452  return m_vertices[(*m_i)[i]];
453  }
454 
455  private: // data
456  const typename MeshTraits<AimsSurface<D,T> >::VertexCollection & m_vertices;
457  //const AimsSurface<D,T> & m_mesh;
458  typename MeshTraits<AimsSurface<D,T> >::FaceIndexCollection::iterator m_i;
459  //Face m_face;
460  };
461  typedef ConstIterator const_iterator;
462 
463  ConstIterator begin() { return ConstIterator(m_mesh, getFaceIndices(m_mesh).begin()); }
464  ConstIterator end() { return ConstIterator(m_mesh, getFaceIndices(m_mesh).end()); }
465 
466  private: // data
467  AimsSurface<D,T> & m_mesh;
468  };
469  */
470 
471 
472  template < int D, class T >
474  getVertices(const AimsSurface<D,T> &mesh)
475  {
476  return mesh.vertex();
477  }
478 
479  template < int D, class T >
480  typename MeshTraits<AimsSurface<D,T> >::VertexCollection &
481  getVertices(AimsSurface<D,T> &mesh)
482  {
483  return mesh.vertex();
484  }
485 
486  template < int D, class T >
487  inline
488  //const typename MeshTraits<AimsTimeSurface<D, T> >::Vertex &
489  const Point3df &
490  //getFaceVertex(const AimsTimeSurface<D,T> &mesh, const typename MeshTraits<AimsTimeSurface<D,T> >::FaceIndexCollection::const_iterator &iFC, int i)
492  (
493  const AimsSurface<D,T> & mesh,
494  const std::vector<AimsVector<unsigned int, 3> >::const_iterator & iFC,
495  int i
496  )
497  {
498  return mesh.vertex()[(*iFC)[i]];
499  }
500 
501 
502  template < int D, class T >
503  inline
504  const typename MeshTraits<AimsSurface<D,T> >::FaceIndexCollection &
505  getFaceIndices(const AimsSurface<D,T> & mesh)
506  {
507  return mesh.polygon();
508  }
509 
510  /*
511  template < int D, class T >
512  inline
513  typename MeshTraits<AimsSurface<D,T> >::FaceIndexCollection &
514  getFaceIndices_my(const AimsSurface<D,T> & mesh)
515  {
516  return mesh.polygon();
517  }
518  */
519 
520  template < int D, class T >
521  inline
522  typename MeshTraits<AimsSurface<D,T> >::FaceIndexCollection &
523  getFaceIndices(AimsSurface<D,T> & mesh)
524  {
525  return mesh.polygon();
526  }
527 
528  /*
529  template < int D, class T >
530  inline
531  const typename MeshTraits<AimsSurface<D,T> >::FaceCollection
532  getFaces(const AimsSurface<D,T> & mesh)
533  {
534  return AimsSurfaceFaceCollection<D,T>(mesh);
535  }
536  */
537  /*
538  template < int D, class T >
539  inline
540  //typename MeshTraits<AimsTimeSurface<D,T> >::FaceCollection
541  typename MeshTraits<AimsSurface<D,T> >::FaceCollection
542  getFaces(AimsSurface<D,T> & mesh)
543  {
544  return AimsSurfaceFaceCollection<D,T>(mesh);
545  }
546  */
547 
548  template < int D, class T >
549  const typename MeshTraits<AimsTimeSurface<D,T> >::VertexCollection &
550  getVertices(const AimsTimeSurface<D,T> &mesh)
551  {
552  return mesh.vertex();
553  }
554 
555  template < int D, class T >
556  typename MeshTraits<AimsTimeSurface<D,T> >::VertexCollection &
557  getVertices(AimsTimeSurface<D,T> &mesh)
558  {
559  return mesh.vertex();
560  }
561 
562 
564  template < int D, class T >
565  inline
566  //const typename MeshTraits<AimsTimeSurface<D, T> >::Vertex &
567  const Point3df &
568  //getFaceVertex(const AimsTimeSurface<D,T> &mesh, const typename MeshTraits<AimsTimeSurface<D,T> >::FaceIndexCollection::const_iterator &iFC, int i)
570  (
571  const AimsTimeSurface<D,T> & mesh,
572  const std::vector<AimsVector<unsigned int, 3> >::const_iterator & iFC,
573  int i
574  )
575  {
576  return mesh.vertex()[(*iFC)[i]];
577  }
578  template < int D, class T >
579  const typename MeshTraits<AimsTimeSurface<D,T> >::FaceIndexCollection &
580  getFaceIndices(const AimsTimeSurface<D,T> & mesh)
581  {
582  return mesh.polygon();
583  }
584 
586  template < int D, class T >
587  typename MeshTraits<AimsTimeSurface<D,T> >::FaceIndexCollection &
588  getFaceIndices(AimsTimeSurface<D,T> & mesh)
589  {
590  return mesh.polygon();
591  }
592 
593  /*
594  template < int D, class T >
595  const typename MeshTraits<AimsTimeSurface<D,T> >::FaceCollection
596  getFaces(const AimsTimeSurface<D,T> & mesh)
597  {
598  return AimsTimeSurfaceFaceCollection<D,T>(mesh);
599  }
600  */
601 
602  /*
603  template < int D, class T >
604  //typename MeshTraits<AimsTimeSurface<D,T> >::FaceCollection
605  typename MeshTraits<AimsTimeSurface<D,T> >::FaceCollection
606  getFaces(AimsTimeSurface<D,T> & mesh)
607  {
608  return AimsTimeSurfaceFaceCollection<D,T>(mesh);
609  }
610  */
611 
612  // WARNING: BundleLoader has been moved to the roca lib for now.
613  /*
614  class BundleLoader : public comist::BundleListener
615  {
616  public: // typedefs
617 
618  typedef numeric_array<float,3> Point;
619  typedef std::vector<Point> Fiber;
620  typedef std::vector<Fiber> Bundle;
621 
622  public: // constructors & destructor
623 
624  BundleLoader() : m_fibers(new Bundle) {}
625  virtual ~BundleLoader() {}
626 
627  public: // set & get
628 
629  boost::shared_ptr<Bundle> getFibers() const { return m_fibers; }
630 
631  private: // functions
632 
633  void bundleStarted(const comist::BundleProducer &, const comist::BundleInfo &)
634  {
635  }
636  void bundleTerminated(const comist::BundleProducer &, const comist::BundleInfo &)
637  {
638  }
639  void fiberStarted(const comist::BundleProducer &, const comist::BundleInfo &, const comist::FiberInfo &)
640  {
641  m_fibers->push_back(Fiber());
642  }
643  void fiberTerminated(const comist::BundleProducer &, const comist::BundleInfo &, const comist::FiberInfo &)
644  {
645  }
646  void newFiberPoint(const comist::BundleProducer &, const comist::BundleInfo &, const comist::FiberInfo &, const comist::FiberPoint & point)
647  {
648  m_fibers->back().push_back(til::convert<Point>(point));
649  }
650  void noMoreBundle(const comist::BundleProducer &)
651  {
652  }
653 
654  private: // data
655 
656  boost::shared_ptr<Bundle> m_fibers;
657  };
658  */
659 
660 
662 
663  namespace functor
664  {
665 
666  template < typename TParam, typename T >
667  typename boost::enable_if<boost::is_pointer<typename TParam::FaceIndex::value_type> >::type
668  convertAimsMesh(Mesh<TParam> & mesh, const T & aimsmesh)
669  {
670  detail::convert_mesh_2(aimsmesh, mesh);
671  }
672 
673  template < typename TParam, typename T >
674  typename boost::disable_if<boost::is_pointer<typename TParam::FaceIndex::value_type> >::type
675  convertAimsMesh(Mesh<TParam> & mesh, const T & aimsmesh)
676  {
678  detail::convert_aimsmeshTomesh1(aimsmesh, mesh);
679  }
680 
681  template < typename TParam, typename T >
682  typename boost::enable_if<boost::is_pointer<typename TParam::FaceIndex::value_type> >::type
683  convertAimsMesh(T & aimsmesh, const Mesh<TParam> & mesh)
684  {
685  detail::convert_mesh_3(mesh, aimsmesh);
686  }
687 
688  template < typename TParam, typename T >
689  typename boost::disable_if<boost::is_pointer<typename TParam::FaceIndex::value_type> >::type
690  convertAimsMesh(T & aimsmesh, const Mesh<TParam> & mesh)
691  {
693  detail::convert_mesh1Toaimsmesh(mesh, aimsmesh);
694  }
695 
696  template < typename TParam >
697  class CastTo<Mesh<TParam>, AimsSurfaceTriangle >
698  : public std::binary_function<Mesh<TParam> &, const AimsSurfaceTriangle &, void>
699  {
700  public:
701  void
702  operator()(Mesh<TParam> & mesh, const AimsSurfaceTriangle & aimsMesh) const
703  {
704  convertAimsMesh(mesh, aimsMesh);
705  }
706  };
707 
708 
709  template < typename TParam >
710  class CastTo<Mesh<TParam>, AimsSurface<3,Void> >
711  : public std::binary_function<Mesh<TParam> &, const AimsSurface<3,Void> &, void>
712  {
713  public:
714 
715  void operator()(Mesh<TParam> & mesh, const AimsSurface<3,Void> & aimsMesh) const
716  {
717  convertAimsMesh(mesh, aimsMesh);
718  }
719  };
720 
721  template < typename T >
722  class CastTo<AimsSurfaceTriangle, T >
723  : public std::binary_function<AimsSurfaceTriangle &, const T &, void>
724  {
725  public:
726  void
727  operator()(AimsSurfaceTriangle & aimsMesh, const T & mesh) const
728  {
729  convertAimsMesh(aimsMesh, mesh);
730  }
731  };
732 
733 
734  /*
735  template < typename TParam >
736  class CastTo<AimsSurface<3,Void>, Mesh<TParam> >
737  : public std::binary_function<AimsSurface<3,Void> &, const Mesh<TParam> &, void>
738  {
739  public:
740  void
741  operator()(AimsSurface<3,Void> & aimsMesh, const Mesh<TParam> & mesh) const
742  {
743  if (boost::is_pointer<typename TParam::FaceIndex::value_type>::value)
744  detail::convert_mesh_3(mesh, aimsMesh);
745  else
746  detail::convert_mesh_1(mesh, aimsMesh);
747  }
748  };*/
749 
750  template < typename T >
751  class CastTo<AimsSurface<3,Void>, T >
752  : public std::binary_function<AimsSurface<3,Void> &, const T &, void>
753  {
754  public:
755  void
756  operator()(AimsSurface<3,Void> & aimsMesh, const T & mesh) const
757  {
758  convertAimsMesh(aimsMesh, mesh);
759  }
760  };
761 
762  } // namespace functor
763 
764 
765  template < typename TVertex, typename TFace >
766  void write_mesh(const std::vector<TVertex> & vertices, const std::vector<TFace> & faces, aims::Writer<AimsSurfaceTriangle> w)
767  {
768  AimsSurfaceTriangle s;
769  Mesh1 tmp;
770  getVertices(tmp) = vertices;
771  getFaceIndices(tmp) = faces;
772  convert(s, tmp);
773  w.write(s);
774  }
775 
776  template < typename TVertex, typename TFace >
777  void write_mesh(const std::vector<TVertex> & vertices, const std::vector<TFace> & faces, const char * name)
778  {
779  write_mesh(vertices, faces, (aims::Writer<AimsSurfaceTriangle>(name)));
780  }
781 
782  template < typename TMesh >
783  void write_mesh(const TMesh & mesh, const char * name)
784  {
785  write_mesh(getVertices(mesh), getFaceIndices(mesh), name);
786  }
787 
788  template < typename T >
789  void writeTexture(const T & data, const char * name)
790  {
791  Texture1d t;
792  t.reserve(data.size());
793  for (std::size_t i = 0; i < data.size(); ++i) t.push_back(data[i]);
794  aims::Writer<Texture1d> w(name);
795  w.write(t);
796  }
797 
798  template < typename T >
799  void read_mesh(aims::Reader<T> & r, Mesh_N & mesh)
800  {
801  AimsSurfaceTriangle s;
802  r.read(s);
803  til::Mesh1 mesh0;
804  til::convert(mesh0, s);
805  mesh = addNeighborsToMesh(mesh0);
806  }
807 
808  template < typename T, typename TVertexCollection, typename TFaceCollection >
809  void read_mesh(aims::Reader<T> const & r, TVertexCollection & vertices, TFaceCollection & faces)
810  {
811  T s;
812  r.read(s);
813  til::convert(vertices, til::getVertices(s));
815  }
816 
817  template < typename T >
818  void read_anyType(T & data, const std::string name)
819  {
820  aims::AnyTypeReader<AimsData<float> > r(name);
821  r.read(data);
822  }
823 
824  template < typename T >
825  void aimswrite(const T & data, const std::string name)
826  {
827  aims::Writer<T> w(name);
828  w.write(data);
829  }
830 
831  template < typename TIterator1, typename TIterator2 >
832  void convert_collection(TIterator1 begin1, TIterator1 end1, TIterator2 begin2)
833  {
834  for (; begin1 != end1; ++begin1, ++begin2)
835  {
836  convert2(*begin1).into(*begin2);
837  }
838  }
839 
840  template < typename VertexCollection, typename FaceCollection >
841  void convert_mesh(AimsSurface<3, Void> const & mesh, VertexCollection & vertices, FaceCollection & faces)
842  {
843  vertices.resize(mesh.vertex().size());
844  convert_collection(mesh.vertex().begin(), mesh.vertex().end(), vertices.begin());
845  faces.resize(mesh.polygon().size());
846  convert_collection(mesh.polygon().begin(), mesh.polygon().end(), faces.begin());
847  }
848 
849  template < typename VertexCollection, typename FaceCollection >
850  void convert_mesh(VertexCollection const & vertices, FaceCollection const & faces, AimsSurface<3, Void> & mesh)
851  {
852  mesh.vertex().resize(vertices.size());
853  convert_collection(vertices.begin(), vertices.end(), mesh.vertex().begin());
854  mesh.polygon().resize(faces.size());
855  convert_collection(faces.begin(), faces.end(), mesh.polygon().begin());
856  }
857 
858 } // namespace til
859 
860 #undef TIL_COMMA
861 
862 #endif /*AIMS_WRAP_H_*/
void operator()(AimsVector< float, 3 > &y, const numeric_array< float, 3 > &x) const
Definition: aims_wrap.h:173
void convert_collection(TIterator1 begin1, TIterator1 end1, TIterator2 begin2)
Definition: aims_wrap.h:832
A class to represent a very basic mesh, consisting of a set of vertices and a set of edges...
void convert(TTo &x, const TFrom &y)
Definition: functors.h:410
TIL_DECLARE_IS_SPEC_T(3DPoint, typename T, boost::array< T TIL_COMMA 3 >)
void read_mesh(aims::Reader< T > &r, Mesh_N &mesh)
Definition: aims_wrap.h:799
void operator()(Texture1d &t, const TContainer &c)
Definition: aims_wrap.h:210
void convert_mesh1Toaimsmesh(const til::Mesh1 &meshFrom, AimsTimeSurface< 3, Void > &meshTo)
Definition: meshUtils.h:115
void operator()(AimsSurfaceTriangle &aimsMesh, const T &mesh) const
Definition: aims_wrap.h:727
void operator()(numeric_array< size_t, 3 > &y, const AimsVector< uint, 3 > &x) const
Definition: aims_wrap.h:137
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
void operator()(AimsSurface< 3, Void > &aimsMesh, const T &mesh) const
Definition: aims_wrap.h:756
void operator()(numeric_array< float, 3 > &y, const AimsVector< float, 3 > &x) const
Definition: aims_wrap.h:161
numeric_array< T, D > size(const Box< T, D > &box)
Return the size of a box.
Definition: boxTools.h:56
const Point3df & getFaceVertex(const AimsSurface< D, T > &mesh, const std::vector< AimsVector< unsigned int, 3 > >::const_iterator &iFC, int i)
Definition: aims_wrap.h:492
std::vector< FaceIndex > FaceIndexCollection
Definition: aims_wrap.h:396
std::vector< Vertex > VertexCollection
Definition: aims_wrap.h:295
std::set< AimsVector< uint, 2 > > getEdges(const AimsSurfaceTriangle *surf)
Get all edges in mesh.
functor::Convertor< T > convert2(const T &from)
Definition: functors.h:419
TRes add(T1 x, T2 y)
Definition: functors.h:394
void convert_mesh_3(const TMeshFrom &meshFrom, TMeshTo &meshTo)
Definition: meshUtils.h:162
std::vector< FaceIndex > FaceIndexCollection
Definition: aims_wrap.h:297
void operator()(boost::array< size_t, 3 > &y, const AimsVector< uint, 3 > &x) const
Definition: aims_wrap.h:114
Static cast functor.
Definition: functors.h:136
void operator()(AimsVector< uint, 3 > &y, const boost::array< size_t, 3 > &x) const
Definition: aims_wrap.h:126
void read_anyType(T &data, const std::string name)
Definition: aims_wrap.h:818
Default values for MeshTraits.
Definition: MeshTraits.h:24
void write_mesh(const std::vector< TVertex > &vertices, const std::vector< TFace > &faces, aims::Writer< AimsSurfaceTriangle > w)
Definition: aims_wrap.h:766
void convert_mesh_2(const TMeshFrom &meshFrom, TMeshTo &meshTo)
When indices of from are numbers and two are pointers.
Definition: meshUtils.h:134
detail::AddNeighborIndexAttribute< Mesh< TParam > > addNeighborsToMesh(const Mesh< TParam > &mesh)
Definition: meshUtils.h:499
TRes mul(T1 x, T2 y)
Definition: functors.h:402
Traits for meshes.
const MeshTraits< AimsSurface< D, T > >::FaceIndexCollection & getFaceIndices(const AimsSurface< D, T > &mesh)
Definition: aims_wrap.h:505
boost::disable_if< boost::is_pointer< typename TParam::FaceIndex::value_type > >::type convertAimsMesh(T &aimsmesh, const Mesh< TParam > &mesh)
Definition: aims_wrap.h:690
AimsVector< uint, D > FaceIndex
Definition: aims_wrap.h:395
std::vector< Vertex > VertexCollection
Definition: aims_wrap.h:394
void operator()(AimsVector< uint, 3 > &y, const numeric_array< size_t, 3 > &x) const
Definition: aims_wrap.h:149
void convert_aimsmeshTomesh1(const AimsTimeSurface< 3, Void > &meshFrom, til::Mesh1 &meshTo)
Definition: meshUtils.h:98
This class enhance a mesh class with a neighbor index attribute.
void convert_mesh(AimsSurface< 3, Void > const &mesh, VertexCollection &vertices, FaceCollection &faces)
Definition: aims_wrap.h:841
void operator()(Mesh< TParam > &mesh, const AimsSurfaceTriangle &aimsMesh) const
Definition: aims_wrap.h:702
Externalization of the standard value_type member typedef.
Definition: traits.h:198
void operator()(Mesh< TParam > &mesh, const AimsSurface< 3, Void > &aimsMesh) const
Definition: aims_wrap.h:715
void aimswrite(const T &data, const std::string name)
Definition: aims_wrap.h:825
const MeshTraits< AimsSurface< D, T > >::VertexCollection & getVertices(const AimsSurface< D, T > &mesh)
Definition: aims_wrap.h:474
const char ** aims_const_hack(char **argv)
Hack around bad AimsApplication definition.
Definition: aims_wrap.h:56
void writeTexture(const T &data, const char *name)
Definition: aims_wrap.h:789
T::value_type type
Definition: traits.h:200