SMIL  1.0.4
geo-cuts-tools.hpp
1 /* __HEAD__
2  * Copyright (c) 2011-2016, Matthieu FAESSEL and ARMINES
3  * Copyright (c) 2017-2023, Centre de Morphologie Mathematique
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
15  * names of its contributors may be used to endorse or promote products
16  * derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28  * THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * Description :
31  * Common Geo-Cuts Tools
32  *
33  * History :
34  * - 20/03/2019 - by Jose-Marcio Martins da Cruz
35  * Just created it...
36  * - XX/XX/XXXX -
37  *
38  *
39  * __HEAD__ - Stop here !
40  */
41 
42 #ifndef _D_GEOCUTSTOOLS_HPP_
43 #define _D_GEOCUTSTOOLS_HPP_
44 
45 namespace geocuts
46 {
47  /*
48  * Some useful tools
49  */
50 
51 /*
52  *
53  *
54  *
55  */
56 #ifndef __BOOST_INCLUDED__
57 #define __BOOST_INCLUDED__
58 
59 /*
60  *To prevent doxygen try to document boost included headers
61  */
63 #include <boost/config.hpp>
64 // for boost::tie
65 #include <boost/utility.hpp>
66 // for boost::graph_traits
67 #include <boost/graph/graph_traits.hpp>
68 #include <boost/graph/adjacency_list.hpp>
69 #include <boost/version.hpp>
70 
71 #if BOOST_VERSION >= 104700
72 #include <boost/graph/boykov_kolmogorov_max_flow.hpp>
73 #elif BOOST_VERSION >= 103500
74 #include <boost/graph/kolmogorov_max_flow.hpp>
75 #endif
76 
78 #endif // __BOOST_INCLUDED__
79 
82  static int debugOn = false;
83 
84  /*
85  typedef struct {
86  float x;
87  float y;
88  float p;
89  } morceau;
90 
91  typedef std::list<morceau> affine_par_morceaux;
92  */
93 
94 #ifndef SMIL_ENTER_FUNCTION
95 #define SMIL_ENTER_FUNCTION(a) \
96  { \
97  if (debugOn) \
98  std::cout << "Entering function " << __func__ << " " << (a) \
99  << std::endl; \
100  }
101 
102 #define SMIL_REGISTER_ERROR(a)
103 #endif
104 
105 #define M_PI 3.14159265358979323846
106 #define INFINI_POSITIF std::numeric_limits<double>::max)()
107 #define _SECURE_SCL 0
108 
109  /* This function selects points from an Structuring element
110  * generating a positive offset
111  */
112  inline vector<IntPoint> filterStrElt(StrElt se)
113  {
114  vector<IntPoint> pts(0);
115 
116  vector<IntPoint>::iterator it, itStart, itEnd;
117  itStart = se.points.begin();
118  itEnd = se.points.end();
119 
120  for (it = itStart; it != itEnd; it++) {
121  bool ok = (4 * it->z + 2 * it->y + it->x) > 0;
122  if (ok)
123  pts.push_back(*it);
124 
125  if (debugOn) {
126  std::cout << (ok ? "GOOD " : "BAD ") << std::right << " "
127  << std::setw(6) << it->x << " " << std::setw(6) << it->y
128  << " " << std::setw(6) << it->z << endl;
129  }
130  }
131  return pts;
132  }
133 
134 #if 0
135  typedef graph_traits<Graph>::vertex_descriptor vertexDescriptor_T;
136 
137  inline kolmogorovMaxFlow(Graph& g,
138  CapacityEdgeMap capacity,
139  ResidualCapacityEdgeMap residual_capacity,
140  ReverseEdgeMap rev,
141  ColorMap color,
142  IndexMap indexmap,
143  vertexDescriptor_T vSource,
144  vertexDescriptor_T vSink);
145  {
146  double flow;
147 
148 #if BOOST_VERSION >= 104700
149  flow = boykov_kolmogorov_max_flow(g, capacity, residual_capacity, rev,
150  color, indexmap, vSource, vSink);
151 #else
152  flow = kolmogorov_max_flow(g, capacity, residual_capacity, rev,
153  color, indexmap, vSource, vSink);
154 #endif
155  return flow;
156  }
157 #endif
158 
160 } // namespace geocuts
161 
162 #endif // _D_GEOCUTSTOOLS_HPP_
163