aimstil  5.0.5
pointListTools.h
Go to the documentation of this file.
1 #ifndef TIL_POINTLISTTOOLS_H
2 #define TIL_POINTLISTTOOLS_H
3 
4 #include <cartobase/config/cartobase_config.h>
5 
6 // Includes from STL
7 #include <memory>
8 #include <vector>
9 
10 // Includes from TIL library
11 #include "til/til_common.h"
12 
13 
14 // Namespace
15 namespace til {
16 
17 template < typename T >
18 bool contains(const std::vector<numeric_array<T,3> > &pl, const numeric_array<T,3> &v)
19 {
20  typename std::vector<numeric_array<T,3> >::const_iterator iPl;
21 
22  for (iPl = pl->begin(); iPl != pl->end(); ++iPl)
23  {
24  if ((*iPl) == v) return true;
25  }
26  return false;
27 }
28 
29 
32 // TODO: should be called sum
33 template < typename T1, typename T2 >
34 void add(const std::vector<numeric_array<T1,3> > &pl, numeric_array<T2,3> &v)
35 {
36  typename std::vector<numeric_array<T1,3> >::const_iterator iPl;
37 
38  for (iPl = pl.begin(); iPl != pl.end(); ++iPl)
39  {
40  v += iPl->data();
41  }
42 }
43 
44 
45 template < typename T1, typename T2 >
46 void add2ndOrder(const std::vector<numeric_array<T1,3> > &pl, SymMatrix3<T2> &mat)
47 {
48  typename std::vector<numeric_array<T1,3> >::const_iterator iPl;
49 
50  // TODO: there is probably something better than using this temp variable
51  SymMatrix3<T1> temp;
52 
53  for (iPl = pl->begin(); iPl != pl->end(); ++iPl)
54  {
55  tdot(*iPl, temp);
56  add(temp, mat);
57  }
58 }
59 /*
60 template < typename TImage >
61 class SetImageVoxel
62 {
63 public:
64  SetImageVoxel(const Ptr<TImage> &im, typename TImage::value_type value) : m_im(im), m_value(value) {}
65  void operator()(const numeric_array<int,3> &pos)
66  {
67  if (contains(m_im, *iPl)) (*m_im)(pos) = m_value;
68  }
69 private:
70  Ptr<TImage> m_im;
71  typename TImage::value_type m_value;
72 };
73 
74 
76 template < class TImage >
77 SetImageVoxel<TImage> setImageVoxel(const Ptr<TImage> &im, typename TImage::value_type value)
78 {
79  return SetImageVoxel<TImage>(im, value);
80 }
81 */
82 
84 /*
85 template < class TImage >
86 void dumpPointListInImage(const std::vector<numeric_array<int,3> > &pl, const Ptr<TImage > &im, typename TImage::value_type value)
87 {
88  std::vector<numeric_array<int,3> >::const_iterator iPl;
89 
90  for (iPl = pl->begin(); iPl != pl->end(); ++iPl)
91  {
92  if (contains(im, *iPl))
93  {
94  im(*iPl) = value;
95  }
96  }
97 }
98 */
99 
100 // TODO: that's not worth a function, coz there is probably a grep out there...
101 template < class TImage1, class TImage2>
102 std::unique_ptr<std::vector<numeric_array<int,3> > >
104 (
105  const std::vector<numeric_array<int,3> > &pl,
106  const TImage1 &im,
107  TImage2 &seg,
108  typename TImage1::value_type threshold,
109  typename TImage2::value_type background
110 )
111 {
112 
113  std::unique_ptr<std::vector<numeric_array<int,3> > > newPl = new std::vector<numeric_array<int,3> >;
114  std::vector<numeric_array<int,3> >::const_iterator iPl;
115 
116  for (iPl = pl.begin(); iPl != pl.end(); ++iPl)
117  {
118  if (im.getValue(*iPl) > threshold)
119  {
120  newPl->push_back(*iPl);
121  }
122  else
123  {
124  seg(*iPl) = background;
125  }
126  }
127  return newPl;
128 }
129 
130 } // namespace
131 
132 #endif
void add2ndOrder(const std::vector< numeric_array< T1, 3 > > &pl, SymMatrix3< T2 > &mat)
A class to store a 3*3 symetric matrix.
Definition: SymMatrix3.h:23
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
General macros, definitions and functions.
TRes add(T1 x, T2 y)
Definition: functors.h:394
void tdot(numeric_array< T, 3 > const &v, SymMatrix3< T > &mat)
Stores v.v^T in mat.
boost::enable_if< is_numeric_container< TStorage >, bool >::type contains(const Box< T, D > &box, const TStorage &v)
Check whether a point lies within box.
Definition: boxTools.h:15
std::unique_ptr< std::vector< numeric_array< int, 3 > > > keepPointsAboveThreshold(const std::vector< numeric_array< int, 3 > > &pl, const TImage1 &im, TImage2 &seg, typename TImage1::value_type threshold, typename TImage2::value_type background)
std::for_each(pl.begin(), pl.end(), setImageVoxel(im, value))