* scribo/util/box_intersection.hh: New.
* scribo/filter/object_links_bbox_overlap.hh: Make use of this new
routine.
---
scribo/ChangeLog | 9 +++
scribo/scribo/filter/object_links_bbox_overlap.hh | 25 ++--------
.../util/{color_to_hex.hh => box_intersection.hh} | 53 +++++++++++---------
3 files changed, 43 insertions(+), 44 deletions(-)
copy scribo/scribo/util/{color_to_hex.hh => box_intersection.hh} (56%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 3c70e89..959746f 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,14 @@
2011-05-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add util::box_intersection.
+
+ * scribo/util/box_intersection.hh: New.
+
+ * scribo/filter/object_links_bbox_overlap.hh: Make use of this new
+ routine.
+
+2011-05-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Various small fixes in Scribo.
* scribo/core/paragraph_info.hh: Add validity information.
diff --git a/scribo/scribo/filter/object_links_bbox_overlap.hh
b/scribo/scribo/filter/object_links_bbox_overlap.hh
index a93d849..29b71ba 100644
--- a/scribo/scribo/filter/object_links_bbox_overlap.hh
+++ b/scribo/scribo/filter/object_links_bbox_overlap.hh
@@ -41,6 +41,7 @@
# include <scribo/core/object_links.hh>
# include <scribo/core/component_set.hh>
# include <scribo/filter/object_links_bbox_ratio.hh>
+# include <scribo/util/box_intersection.hh>
namespace scribo
{
@@ -80,32 +81,14 @@ namespace scribo
const component_set<L>& components = links.components();
object_links<L> output = links.duplicate();
- bool has_intersection;
- mln_site(L) pmin, pmax;
float ratio_i, ratio_link_i;
for_all_links(i, links)
if (links.is_linked(i))
{
- has_intersection = true;
- for (unsigned dim = 0; dim < mln_site_(L)::dim; ++dim)
- {
- pmin[dim] = math::max(components(i).bbox().pmin()[dim],
- components(links(i)).bbox().pmin()[dim]);
- pmax[dim] = math::min(components(i).bbox().pmax()[dim],
- components(links(i)).bbox().pmax()[dim]);
-
- if (pmin[dim] > pmax[dim])
- {
- has_intersection = false;
- break;
- }
- }
-
- if (!has_intersection)
- continue;
-
- mln_box(L) interbbox(pmin, pmax);
+ mln_box(L)
+ interbbox = scribo::util::box_intersection(components(i).bbox(),
+ components(links(i)).bbox());
ratio_i = interbbox.nsites() /(float)components(i).bbox().nsites();
ratio_link_i = interbbox.nsites() /(float)components(links(i)).bbox().nsites();
diff --git a/scribo/scribo/util/color_to_hex.hh b/scribo/scribo/util/box_intersection.hh
similarity index 56%
copy from scribo/scribo/util/color_to_hex.hh
copy to scribo/scribo/util/box_intersection.hh
index e0ee33f..f090233 100644
--- a/scribo/scribo/util/color_to_hex.hh
+++ b/scribo/scribo/util/box_intersection.hh
@@ -23,18 +23,17 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_UTIL_COLOR_TO_HEX_HH
-# define SCRIBO_UTIL_COLOR_TO_HEX_HH
+#ifndef SCRIBO_UTIL_BOX_INTERSECTION_HH
+# define SCRIBO_UTIL_BOX_INTERSECTION_HH
/// \file
///
-/// Convert hexadecimal encoded colors to value::rgb8.
+/// Return the box corresponding to the intersection of two boxes.
-#include <cstdio>
-#include <iostream>
-#include <string.h>
-#include <mln/value/rgb8.hh>
+#include <mln/core/site_set/box.hh>
+#include <mln/math/min.hh>
+#include <mln/math/max.hh>
namespace scribo
{
@@ -43,30 +42,38 @@ namespace scribo
{
using namespace mln;
- std::string color_to_hex(const value::rgb8& v);
+ /// \brief Return the box corresponding to the intersection of two
+ /// boxes.
+ ///
+ /// \return An invalid box if there is no intersection. The box
+ /// corresponding to the intersection, otherwise.
+ template <typename P>
+ box<P>
+ box_intersection(const box<P>& lhs, const box<P>& rhs);
# ifndef MLN_INCLUDE_ONLY
- std::string color_to_hex(const value::rgb8& v)
+ template <typename P>
+ box<P>
+ box_intersection(const box<P>& lhs, const box<P>& rhs)
{
- std::string result = "#";
+ trace::entering("scribo::util::box_intersection");
- char buf[3];
+ P pmin, pmax;
+ for (unsigned dim = 0; dim < P::dim; ++dim)
+ {
+ pmin[dim] = math::max(lhs.pmin()[dim], rhs.pmin()[dim]);
+ pmax[dim] = math::min(lhs.pmax()[dim], rhs.pmax()[dim]);
- int c = v.red();
- sprintf(buf, "%.2X", c);
- result.append(buf);
+ if (pmin[dim] > pmax[dim]) // No intersection.
+ return box<P>();
+ }
- c = v.green();
- sprintf(buf, "%.2X", c);
- result.append(buf);
+ box<P> output(pmin, pmax);
- c = v.blue();
- sprintf(buf, "%.2X", c);
- result.append(buf);
-
- return result;
+ trace::exiting("scribo::util::box_intersection");
+ return output;
}
# endif // ! MLN_INCLUDE_ONLY
@@ -75,4 +82,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_UTIL_COLOR_TO_HEX_HH
+#endif // ! SCRIBO_UTIL_BOX_INTERSECTION_HH
--
1.5.6.5
Show replies by date