Work in progress on ARVineyard and KineticSort. Commit to merge in CGAL 3.3 changes.
--- a/examples/ar-vineyard/CMakeLists.txt Wed Aug 15 11:52:17 2007 -0400
+++ b/examples/ar-vineyard/CMakeLists.txt Fri Aug 17 15:04:28 2007 -0400
@@ -3,5 +3,5 @@
foreach (t ${targets})
add_executable (${t} ${t}.cpp ${external_sources})
- target_link_libraries (${t} ${libraries} ${cgal_libraries})
+ target_link_libraries (${t} ${libraries} ${cgal_libraries} ${synaps_libraries})
endforeach (t)
--- a/examples/ar-vineyard/ar-simplex3d.h Wed Aug 15 11:52:17 2007 -0400
+++ b/examples/ar-vineyard/ar-simplex3d.h Fri Aug 17 15:04:28 2007 -0400
@@ -86,7 +86,7 @@
RealValue rho_; // rho_ is the squared radius of the smallest circumsphere
RealValue s_; // s_ is the squared distance from z to the affine hull of the simplex
RealValue v_; // v_ is the squared distance from z to the affine hull of the dual Voronoi cell
- RealValue phi_const_; // see LHI paper, Appendix 1
+ RealValue phi_const_; // see LHI paper, Appendices A and B
bool attached_;
};
--- a/examples/ar-vineyard/ar-vineyard.h Wed Aug 15 11:52:17 2007 -0400
+++ b/examples/ar-vineyard/ar-vineyard.h Fri Aug 17 15:04:28 2007 -0400
@@ -11,67 +11,80 @@
#include "topology/conesimplex.h"
#include "topology/filtration.h"
-
-#include <CGAL/Kinetic/Inexact_simulation_traits_1.h>
-#include <CGAL/Kinetic/Sort.h>
-#include <CGAL/Kinetic/Sort_visitor_base.h>
+#include "geometry/kinetic-sort.h"
#include <list>
#include "ar-simplex3d.h"
-#include <vector>
-
-class ARVineyardBase
-{
- public:
- /// \name CGAL Kinetic Sort types
- /// @{
- class SortVisitor;
- typedef CGAL::Kinetic::Inexact_simulation_traits_1 Traits;
- typedef CGAL::Kinetic::Sort<Traits, SortVisitor> Sort;
- typedef Traits::Simulator Simulator;
- typedef Traits::Active_points_1_table ActivePointsTable;
- typedef ActivePointsTable::Key Key;
-
- typedef Traits::Kinetic_kernel::
- Function_kernel::Construct_function CF;
- typedef Traits::Kinetic_kernel::Motion_function F;
- /// @}
-
- class ARConeSimplex;
- class MembershipFunctionChangeEvent;
-};
-
-class ARVineyardBase::ARConeSimplex: public ConeSimplex<ARSimplex3D>
+class ARConeSimplex: public ConeSimplex<ARSimplex3D>
{
public:
typedef ConeSimplex<ARSimplex3D> Parent;
typedef ARSimplex3D ARSimplex3D;
+ typedef Filtration<ARConeSimplex> Filtration;
+
+ /// \name Polynomial Kernel types
+ /// @{
+ typedef double FieldType;
+ typedef UPolynomial<FieldType> PolyKernel;
+ typedef PolyKernel::Polynomial Polynomial;
+ typedef Simulator<PolyKernel> Simulator;
+
+ typedef KineticSort<ARFiltration, SimplexTrajectoryExtractor, Simulator>
+ SimplexSort;
+ typedef SimplexSort::iterator SimplexSortIterator;
+ typedef SimplexSortIterator Key;
+ /// @}
+
+ /// \name Kinetic Sort types
+ /// @{
+ typedef std::list<Polynomial> ThresholdList;
+
+ struct ThresholdTrajectoryExtractor
+ { Polynomial operator()(ThresholdList::iterator i) const { return *i; } }
+ struct SimplexTrajectoryExtractor
+ { Polynomial operator()(ARFiltration::iterator i) const { i->thresholds().front(); }
+
+ typedef KineticSort<ThresholdList, ThresholdTrajectoryExtractor, Simulator>
+ ThresholdSort;
+ /// @}
ARConeSimplex(const ARSimplex3D& s, bool coned = false):
- Parent(s, coned) {}
+ Parent(s, coned),
+ thresholds_sort_(&thresholds_) {}
Key kinetic_key() const { return key_; }
void set_kinetic_key(Key k) { key_ = k; }
+ const ThresholdList& thresholds() const { return thresholds_; }
+
+ void schedule_thresholds(Simulator* simulator);
+
private:
Key key_;
+ ThresholdList thresholds_;
+ ThresholdSort thresholds_sort_;
+
+ void swap_thresholds(ThresholdList* tl, typename ThresholdList::iterator i);
};
-class ARVineyard: public ARVineyardBase
+class ARVineyard
{
public:
typedef ARVineyard Self;
- typedef Filtration<ARConeSimplex> ARFiltration;
+ typedef ARConeSimplex::Filtration ARFiltration;
typedef ARFiltration::Simplex Simplex;
typedef ARFiltration::Index Index;
typedef ARFiltration::Vineyard Vineyard;
typedef Vineyard::Evaluator Evaluator;
- typedef std::map<Key, Index> KeyIndexMap;
+ typedef ARConeSimplex::Simulator Simulator;
+ typedef ARConeSimplex::SimplexSort SimplexSort;
+
+
typedef std::list<Point> PointList;
class StaticEvaluator;
@@ -89,7 +102,7 @@
public:
// For Kinetic Sort
- void swap(Key a, Key b);
+ static void swap(ARFiltration* filtration, Index i);
private:
void add_simplices();
@@ -100,8 +113,6 @@
Vineyard* vineyard_;
Evaluator* evaluator_;
- KeyIndexMap kinetic_map_;
-
Point z_;
Delaunay dt_;
@@ -123,25 +134,6 @@
//BOOST_CLASS_EXPORT(ARVineyard)
-class ARVineyardBase::MembershipFunctionChangeEvent
-{
- public:
- MembershipFunctionChangeEvent(Key k, F function,
- ActivePointsTable::Handle apt):
- key_(k), function_(function), apt_(apt) {}
-
- void process(Simulator::Time t) const;
- std::ostream& operator<<(std::ostream& out) const;
-
- private:
- Key key_;
- F function_;
- ActivePointsTable::Handle apt_;
-};
-
-std::ostream& operator<<(std::ostream& out, const ARVineyardBase::MembershipFunctionChangeEvent& e)
-{ return e.operator<<(out); }
-
class ARVineyard::StaticEvaluator: public Evaluator
{
public:
@@ -173,19 +165,6 @@
};
-class ARVineyardBase::SortVisitor: public CGAL::Kinetic::Sort_visitor_base
-{
- public:
- SortVisitor(ARVineyard* arv): arv_(arv) {}
-
- template<class Vertex_handle>
- void before_swap(Vertex_handle a, Vertex_handle b) const;
-
- private:
- ARVineyard* arv_;
-};
-
-
#include "ar-vineyard.hpp"
#endif // __AR_VINEYARD_H__
--- a/examples/ar-vineyard/ar-vineyard.hpp Wed Aug 15 11:52:17 2007 -0400
+++ b/examples/ar-vineyard/ar-vineyard.hpp Fri Aug 17 15:04:28 2007 -0400
@@ -1,7 +1,27 @@
/* Implementation */
+void
+ARConeSimplex::
+swap_thresholds(ThresholdList* tl, typename ThresholdList::iterator i)
+{
+ AssertMsg(tl == &thresholds_, "Swap in the wrong list"); // might as well take advantage of the redundancy
+
+ typename ThresholdList::iterator n = boost::next(i);
+ tl->splice(i, *tl, n);
+ if (n == tl->begin())
+
+}
+
+void
+ARConeSimplex::
+schedule_thresholds(Simulator* simulator)
+{
+ thresholds_sort_.insert(thresholds_sort_.end(), thresholds_.begin(), thresholds_.end(), simulator);
+}
+
+
ARVineyard::
-ARVineyard(const PointList& points, const Point& z): z_(z)
+ARVineyard(const PointList& points, const Point& z): simplex_sort_(0), z_(z)
{
for (PointList::const_iterator cur = points.begin(); cur != points.end(); ++cur)
dt_.insert(*cur);
@@ -17,7 +37,7 @@
filtration_ = new ARFiltration(vineyard_);
for (ARSimplex3DVector::const_iterator cur = alpha_ordering.begin(); cur != alpha_ordering.end(); ++cur)
{
- filtration_->append(*cur); // Delaunay simplex
+ filtration_->append(ARConeSimplex(*cur)); // Delaunay simplex
filtration_->append(ARConeSimplex(*cur, true)); // Coned off delaunay simplex
}
}
@@ -46,6 +66,19 @@
{
AssertMsg(filtration_->is_paired(), "Simplices must be paired for a vineyard to be computed");
+ Simulator simulator;
+ SimplexSort simplex_sort(filtration_, swap);
+
+
+
+
+
+
+
+ simplex_sort.initialize(&simulator);
+
+
+
typedef Traits::Kinetic_kernel::Point_1 Point_1;
typedef Simulator::Time Time;
--- a/include/geometry/kinetic-sort.h Wed Aug 15 11:52:17 2007 -0400
+++ b/include/geometry/kinetic-sort.h Fri Aug 17 15:04:28 2007 -0400
@@ -10,33 +10,35 @@
* Maintains elements of the given data structure in the sorted order assuming the elements follow
* trajectories given by TrajectoryExtractor_.
*
- * \arg SortDS_ should be forward and backward iterable, swaps are handles via SwapCallback
+ * \arg ElementIterator_ iterator over the underlying data structure that's kept in sorted order
* \arg TrajectoryExtractor_ applied to the iterator into SortDS_ should return a rational
* function describing the
* \arg Simulator_ the Simulator type, e.g. Simulator. Note that KineticSort does not store
* a pointer to the Simulator (so a pointer is passed in each relevant operation)
+ * \arg Swap_ is called with an ElementIterator_ when a swap needs to be performed
*/
-template<class SortDS_, class TrajectoryExtractor_, class Simulator_>
+template<class ElementIterator_, class TrajectoryExtractor_,
+ class Simulator_, class Swap_ = boost::function<void(ElementIterator_ pos)>>
class KineticSort
{
public:
typedef Simulator_ Simulator;
typedef typename Simulator::PolynomialKernel PolynomialKernel;
- typedef SortDS_ SortDS;
+ typedef ElementIterator_ ElementIterator;
+ typedef Swap_ Swap;
typedef TrajectoryExtractor_ TrajectoryExtractor;
typedef typename Simulator::Key SimulatorKey;
- typedef typename SortDS::iterator SortDSIterator;
private:
/* Implementation */
struct Node
{
- SortDSIterator element;
+ ElementIterator element;
SimulatorKey swap_event_key;
- Node(SortDSIterator e, SimulatorKey k):
+ Node(ElementIterator e, SimulatorKey k):
element(e), swap_event_key(k) {}
};
@@ -44,22 +46,25 @@
public:
typedef typename NodeList::iterator iterator;
- typedef boost::function<void(SortDS*, SortDSIterator pos)>
- SwapCallback;
/// \name Core Functionality
/// @{
- KineticSort(SortDS* sort, Simulator* simulator, SwapCallback swap_callback);
+ KineticSort(Swap swap);
+ KineticSort(ElementIterator b, ElementIterator e, Swap swap, Simulator* simulator);
- template<class InputIterator>
- void insert(iterator pos, InputIterator f, InputIterator l, Simulator* simulator);
+ void insert(iterator pos, ElementIterator f, ElementIterator l, Simulator* simulator);
void erase(iterator pos, Simulator* simulator);
void update_trajectory(iterator pos, Simulator* simulator);
void swap(iterator pos, Simulator* simulator);
bool audit(Simulator* simulator) const;
+
+ iterator begin() { return list_.begin(); }
+ iterator end() { return list_.end(); }
+
+ void initialize(ElementIterator b, ElementIterator e, Simulator* simulator);
/// @}
private:
@@ -69,8 +74,7 @@
private:
NodeList list_;
- SortDS* sort_;
- SwapCallback swap_callback_;
+ Swap swap_;
};
#include "kinetic-sort.hpp"
--- a/include/geometry/kinetic-sort.hpp Wed Aug 15 11:52:17 2007 -0400
+++ b/include/geometry/kinetic-sort.hpp Fri Aug 17 15:04:28 2007 -0400
@@ -1,49 +1,63 @@
-template<class SortDS_, class TrajectoryExtractor_, class Simulator_>
-KineticSort<SortDS_, TrajectoryExtractor_, Simulator_>::
-KineticSort(SortDS* sort, Simulator* simulator, SwapCallback swap_callback):
- sort_(sort), swap_callback_(swap_callback)
+template<class ElementIterator_, class TrajectoryExtractor_, class Simulator_, class Swap_>
+KineticSort<ElementIterator_, TrajectoryExtractor_, Simulator_, Swap_>::
+KineticSort(Swap swap):
+ swap_(swap)
+{}
+
+template<class ElementIterator_, class TrajectoryExtractor_, class Simulator_, class Swap_>
+KineticSort<ElementIterator_, TrajectoryExtractor_, Simulator_, Swap_>::
+KineticSort(ElementIterator b, ElementIterator e, Swap swap, Simulator* simulator):
+ swap_(swap)
{
- for (SortDSIterator cur = sort->begin(); cur != sort->end(); ++cur)
+ initialize(b, e, simulator);
+}
+
+template<class ElementIterator_, class TrajectoryExtractor_, class Simulator_, class Swap_>
+void
+KineticSort<ElementIterator_, TrajectoryExtractor_, Simulator_, Swap_>::
+initialize(ElementIterator b, ElementIterator e,, Simulator* simulator)
+{
+ for (ElementIterator cur = b; cur != e; ++cur)
list_.push_back(Node(cur, simulator->null_key()));
schedule_swaps(list_.begin(), list_.end(), simulator);
}
-
-template<class SortDS_, class TrajectoryExtractor_, class Simulator_>
-template<class InputIterator>
+/// Adds elements in the range [f,l) of the underlying data structure to the management by the KineticSort.
+/// pos must be a valid iterator, i.e., it cannot be end().
+template<class ElementIterator_, class TrajectoryExtractor_, class Simulator_, class Swap_>
void
-KineticSort<SortDS_, TrajectoryExtractor_, Simulator_>::
-insert(iterator pos, InputIterator f, InputIterator l, Simulator* simulator)
+KineticSort<ElementIterator_, TrajectoryExtractor_, Simulator_, Swap_>::
+insert(iterator pos, ElementIterator f, ElementIterator l, Simulator* simulator)
{
iterator previous = pos; --previous;
if (previous != list_.end()) simulator->remove(previous->swap_event_key);
- sort_->insert(pos->element, f, l);
+ ElementIterator cur = boost::next(previous)->element;
+ while(cur != pos->element)
+ list_.insert(pos->element, Node(cur++, simulator->null_key()));
- SortDSIterator cur = boost::next(previous)->element;
- while(cur != pos->element)
- list_.insert(pos->element, Node(cur++));
if (previous != list_.end())
schedule_swaps(previous, pos, simulator);
else
schedule_swaps(list_.begin(), pos, simulator);
}
-template<class SortDS_, class TrajectoryExtractor_, class Simulator_>
+/// Removes pos from the KineticSort structure. Assumes that the element of the underlying data structure
+/// that *pos refers to has already been removed.
+template<class ElementIterator_, class TrajectoryExtractor_, class Simulator_, class Swap_>
void
-KineticSort<SortDS_, TrajectoryExtractor_, Simulator_>::
+KineticSort<ElementIterator_, TrajectoryExtractor_, Simulator_, Swap_>::
erase(iterator pos, Simulator* simulator)
{
simulator->remove(pos->swap_event_key);
- sort_->erase(pos->element);
iterator prev = pos; --prev;
list_.erase(pos);
schedule_swaps(prev, simulator);
}
-template<class SortDS_, class TrajectoryExtractor_, class Simulator_>
+template<class ElementIterator_, class TrajectoryExtractor_, class Simulator_, class Swap_>
void
-KineticSort<SortDS_, TrajectoryExtractor_, Simulator_>::
+KineticSort<ElementIterator_, TrajectoryExtractor_, Simulator_, Swap_>::
update_trajectory(iterator pos, Simulator* simulator)
{
iterator prev = boost::prior(pos);
@@ -61,15 +75,15 @@
}
-template<class SortDS_, class TrajectoryExtractor_, class Simulator_>
+template<class ElementIterator_, class TrajectoryExtractor_, class Simulator_, class Swap_>
void
-KineticSort<SortDS_, TrajectoryExtractor_, Simulator_>::
+KineticSort<ElementIterator_, TrajectoryExtractor_, Simulator_, Swap_>::
swap(iterator pos, Simulator* simulator)
{
- swap_callback_(sort_, pos->element);
-
- // TODO: add assertion that boost::next(pos) != list_.end()
-
+ AssertMsg(boost::next(pos) != list_.end(), "Cannot swap the last element");
+
+ swap(pos->element);
+
// Remove events
iterator prev = boost::prior(pos);
if (prev != list_.end())
@@ -88,9 +102,9 @@
//audit(simulator);
}
-template<class SortDS_, class TrajectoryExtractor_, class Simulator_>
+template<class ElementIterator_, class TrajectoryExtractor_, class Simulator_, class Swap_>
bool
-KineticSort<SortDS_, TrajectoryExtractor_, Simulator_>::
+KineticSort<ElementIterator_, TrajectoryExtractor_, Simulator_, Swap_>::
audit(Simulator* simulator) const
{
typedef typename Simulator::RationalFunction RationalFunction;
@@ -126,9 +140,9 @@
}
-template<class SortDS_, class TrajectoryExtractor_, class Simulator_>
+template<class ElementIterator_, class TrajectoryExtractor_, class Simulator_, class Swap_>
void
-KineticSort<SortDS_, TrajectoryExtractor_, Simulator_>::
+KineticSort<ElementIterator_, TrajectoryExtractor_, Simulator_, Swap_>::
schedule_swaps(iterator b, iterator e, Simulator* simulator)
{
typedef typename Simulator::RationalFunction RationalFunction;
@@ -150,9 +164,9 @@
if (cur != e) schedule_swaps(cur, simulator);
}
-template<class SortDS_, class TrajectoryExtractor_, class Simulator_>
+template<class ElementIterator_, class TrajectoryExtractor_, class Simulator_, class Swap_>
void
-KineticSort<SortDS_, TrajectoryExtractor_, Simulator_>::
+KineticSort<ElementIterator_, TrajectoryExtractor_, Simulator_, Swap_>::
schedule_swaps(iterator i, Simulator* simulator)
{
typedef typename Simulator::RationalFunction RationalFunction;
@@ -178,8 +192,8 @@
}
/* SwapEvent */
-template<class SortDS_, class TrajectoryExtractor_, class Simulator_>
-class KineticSort<SortDS_, TrajectoryExtractor_, Simulator_>::SwapEvent: public Simulator::Event
+template<class ElementIterator_, class TrajectoryExtractor_, class Simulator_, class Swap_>
+class KineticSort<ElementIterator_, TrajectoryExtractor_, Simulator_, Swap_>::SwapEvent: public Simulator::Event
{
public:
typedef typename Simulator::Event Parent;
@@ -199,9 +213,9 @@
iterator pos_;
};
-template<class SortDS_, class TrajectoryExtractor_, class Simulator_>
+template<class ElementIterator_, class TrajectoryExtractor_, class Simulator_, class Swap_>
bool
-KineticSort<SortDS_, TrajectoryExtractor_, Simulator_>::SwapEvent::
+KineticSort<ElementIterator_, TrajectoryExtractor_, Simulator_, Swap_>::SwapEvent::
process(Simulator* s) const
{
std::cout << "Swapping. Current time: " << s->current_time() << std::endl;
@@ -209,9 +223,9 @@
return true;
}
-template<class SortDS_, class TrajectoryExtractor_, class Simulator_>
+template<class ElementIterator_, class TrajectoryExtractor_, class Simulator_, class Swap_>
std::ostream&
-KineticSort<SortDS_, TrajectoryExtractor_, Simulator_>::SwapEvent::
+KineticSort<ElementIterator_, TrajectoryExtractor_, Simulator_, Swap_>::SwapEvent::
print(std::ostream& out) const
{
Parent::print(out) << ", SwapEvent at " << TrajectoryExtractor_()(position()->element);
--- a/include/topology/filtration.h Wed Aug 15 11:52:17 2007 -0400
+++ b/include/topology/filtration.h Fri Aug 17 15:04:28 2007 -0400
@@ -38,6 +38,8 @@
typedef typename FiltrationSimplex::Container FiltrationContainer;
typedef typename FiltrationContainer::Index Index;
typedef typename FiltrationContainer::const_Index const_Index;
+ typedef Index iterator;
+ typedef const_Index const_iterator;
/// @}
/// \name Cycles and Trails
--- a/tests/geometry/test-kinetic-sort.cpp Wed Aug 15 11:52:17 2007 -0400
+++ b/tests/geometry/test-kinetic-sort.cpp Fri Aug 17 15:04:28 2007 -0400
@@ -11,15 +11,16 @@
typedef UPolynomial<FieldType> PolyKernel;
typedef PolyKernel::Polynomial Polynomial;
typedef std::list<Polynomial> SortDS;
+typedef SortDS::iterator SortDSIterator;
typedef Simulator<PolyKernel> SimulatorFT;
class TrajectoryExtractor
{
public:
- Polynomial operator()(SortDS::iterator i) const { return *i; }
+ Polynomial operator()(SortDSIterator i) const { return *i; }
};
-typedef KineticSort<SortDS, TrajectoryExtractor, SimulatorFT> KineticSortDS;
+typedef KineticSort<SortDSIterator, TrajectoryExtractor, SimulatorFT> KineticSortDS;
struct EvaluatedComparison: public std::binary_function<const Polynomial&, const Polynomial&, bool>
{
@@ -29,7 +30,7 @@
FieldType vv;
};
-void swap(SortDS* s, SortDS::iterator i)
+void swap(SortDS* s, SortDSIterator i)
{
std::cout << "Swapping " << *i << " " << *boost::next(i) << std::endl;
s->splice(i, *s, boost::next(i));
@@ -52,7 +53,7 @@
std::cout << *cur << std::endl;
// Setup kinetic sort
- KineticSortDS ks(&list, &simulator, swap);
+ KineticSortDS ks(list.begin(), list.end(), std::bind1st(&swap, &list), &simulator);
while(!simulator.reached_infinity() && simulator.current_time() < 1)
{