]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Allow to iterate on vertices when dim = 2 or 3.
authorBruno Turcksin <bruno.turcksin@gmail.com>
Mon, 16 Nov 2015 17:31:16 +0000 (11:31 -0600)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Mon, 16 Nov 2015 20:38:03 +0000 (14:38 -0600)
include/deal.II/grid/tria.h
include/deal.II/grid/tria_accessor.h
include/deal.II/grid/tria_accessor.templates.h
include/deal.II/grid/tria_iterator_selector.h
source/grid/tria.cc
tests/grid/vertex_iterator.cc
tests/grid/vertex_iterator.output

index 997636d7ff86fce2ecf684384c162516aa17663a..6609920cbd9af9f02d564b3e7b47dbfeb9e02fc8 100644 (file)
@@ -1408,6 +1408,9 @@ public:
   typedef TriaIterator      <TriaAccessor<dim-1, dim, spacedim> > face_iterator;
   typedef TriaActiveIterator<TriaAccessor<dim-1, dim, spacedim> > active_face_iterator;
 
+  typedef typename IteratorSelector::vertex_iterator        vertex_iterator;
+  typedef typename IteratorSelector::active_vertex_iterator active_vertex_iterator;
+
   typedef typename IteratorSelector::line_iterator        line_iterator;
   typedef typename IteratorSelector::active_line_iterator active_line_iterator;
 
@@ -2543,6 +2546,35 @@ public:
    */
   face_iterator        end_face () const;
 
+  /*
+   * @}
+   */
+
+  /*---------------------------------------*/
+  /*---------------------------------------*/
+
+  /**
+   * @name Vertex iterator functions
+   * @{
+   */
+
+  /**
+   * Iterator to the first used vertex.
+   */
+  vertex_iterator        begin_vertex() const;
+
+  /**
+   * Iterator to the first active vertex. Because all vertices are active,
+   * begin_vertex() and begin_active_vertex() return the same vertex.
+   */
+  active_vertex_iterator begin_active_vertex() const;
+
+  /**
+   * Iterator past the end; this iterator serves for comparisons of iterators
+   * with past-the-end or before-the-beginning states.
+   */
+  vertex_iterator        end_vertex() const;
+
   /*
    * @}
    */
@@ -3034,6 +3066,7 @@ private:
    */
   typedef TriaRawIterator   <CellAccessor<dim,spacedim>         > raw_cell_iterator;
   typedef TriaRawIterator   <TriaAccessor<dim-1, dim, spacedim> > raw_face_iterator;
+  typedef typename IteratorSelector::raw_vertex_iterator          raw_vertex_iterator;
   typedef typename IteratorSelector::raw_line_iterator            raw_line_iterator;
   typedef typename IteratorSelector::raw_quad_iterator            raw_quad_iterator;
   typedef typename IteratorSelector::raw_hex_iterator             raw_hex_iterator;
index ed642565f16aacec684e365c8268bec1885131bc..aa5e0170f842a335a4606edd9ea0a09cc9c02bee 100644 (file)
@@ -1546,11 +1546,9 @@ public:
   TriaAccessor (const InvalidAccessor<structdim2,dim2,spacedim2> &);
 
   /**
-   * Return the state of the iterator. Since an iterator to points can not be
-   * incremented or decremented, its state remains constant, and in particular
-   * equal to IteratorState::valid.
+   * Return the state of the iterator.
    */
-  static IteratorState::IteratorStates state ();
+  IteratorState::IteratorStates state () const;
 
   /**
    * Level of this object. Vertices have no level, so this function always
@@ -1571,16 +1569,14 @@ public:
    * @{
    */
   /**
-   * This operator advances the iterator to the next element. For points, this
-   * operation is not defined, so you can't iterate over point iterators.
+   * This operator advances the iterator to the next element.
    */
-  void operator ++ () const;
+  void operator ++ ();
 
   /**
-   * This operator moves the iterator to the previous element. For points,
-   * this operation is not defined, so you can't iterate over point iterators.
+   * This operator moves the iterator to the previous element.
    */
-  void operator -- () const;
+  void operator -- ();
   /**
    * Compare for equality.
    */
index 4ce7f713b16b3e13cfe50d7ce172139253dd8f85..03a760adfa94f78bc757c45379ba5ca45a45cbb4 100644 (file)
@@ -2193,9 +2193,12 @@ TriaAccessor<0, dim, spacedim>::copy_from (const TriaAccessor &t)
 template <int dim, int spacedim>
 inline
 IteratorState::IteratorStates
-TriaAccessor<0, dim, spacedim>::state ()
+TriaAccessor<0, dim, spacedim>::state () const
 {
-  return IteratorState::valid;
+  if (global_vertex_index != numbers::invalid_unsigned_int)
+    return IteratorState::valid;
+  else
+    return IteratorState::past_the_end;
 }
 
 
@@ -2223,9 +2226,11 @@ TriaAccessor<0, dim, spacedim>::index () const
 template <int dim, int spacedim>
 inline
 void
-TriaAccessor<0, dim, spacedim>::operator ++ () const
+TriaAccessor<0, dim, spacedim>::operator ++ ()
 {
-  Assert (false, ExcNotImplemented());
+  ++global_vertex_index;
+  if (global_vertex_index >= tria->n_vertices())
+    global_vertex_index = numbers::invalid_unsigned_int;
 }
 
 
@@ -2233,9 +2238,10 @@ TriaAccessor<0, dim, spacedim>::operator ++ () const
 template <int dim, int spacedim>
 inline
 void
-TriaAccessor<0, dim, spacedim>::operator -- () const
+TriaAccessor<0, dim, spacedim>::operator -- ()
 {
-  Assert (false, ExcNotImplemented());
+  if (global_vertex_index!=numbers::invalid_unsigned_int)
+    --global_vertex_index;
 }
 
 
index 6a990a7b1d62122fc3e15066629cbc25b5741200..29c48a12727b13b33f32e49b79dbb87e2ef01db1 100644 (file)
@@ -73,7 +73,9 @@ namespace internal
     template <int spacedim>
     struct Iterators<1,spacedim>
     {
+      typedef TriaRawIterator   <dealii::TriaAccessor<0, 1, spacedim> > raw_vertex_iterator;
       typedef TriaIterator      <dealii::TriaAccessor<0, 1, spacedim> > vertex_iterator;
+      typedef TriaActiveIterator<dealii::TriaAccessor<0, 1, spacedim> > active_vertex_iterator;
 
       typedef TriaRawIterator   <dealii::CellAccessor<1,spacedim> > raw_line_iterator;
       typedef TriaIterator      <dealii::CellAccessor<1,spacedim> > line_iterator;
@@ -134,7 +136,9 @@ namespace internal
     template <int spacedim>
     struct Iterators<2,spacedim>
     {
+      typedef TriaRawIterator   <dealii::TriaAccessor<0, 2, spacedim> > raw_vertex_iterator;
       typedef TriaIterator      <dealii::TriaAccessor<0, 2, spacedim> > vertex_iterator;
+      typedef TriaActiveIterator<dealii::TriaAccessor<0, 2, spacedim> > active_vertex_iterator;
 
       typedef TriaRawIterator   <dealii::TriaAccessor<1, 2, spacedim> > raw_line_iterator;
       typedef TriaIterator      <dealii::TriaAccessor<1, 2, spacedim> > line_iterator;
@@ -176,7 +180,9 @@ namespace internal
     template <int spacedim>
     struct Iterators<3,spacedim>
     {
+      typedef TriaRawIterator   <dealii::TriaAccessor<0, 3, spacedim> > raw_vertex_iterator;
       typedef TriaIterator      <dealii::TriaAccessor<0, 3, spacedim> > vertex_iterator;
+      typedef TriaActiveIterator<dealii::TriaAccessor<0, 3, spacedim> > active_vertex_iterator;
 
       typedef TriaRawIterator   <dealii::TriaAccessor<1, 3, spacedim> > raw_line_iterator;
       typedef TriaIterator      <dealii::TriaAccessor<1, 3, spacedim> > line_iterator;
index 05eff9f3e42f31dd2afc4e62b6a70cf9619d5064..d37c7e20a30107fb05639c82913d963da3cc6bf4 100644 (file)
@@ -10605,6 +10605,59 @@ Triangulation<dim,spacedim>::end_face () const
 }
 
 
+/*------------------------ Vertex iterator functions ------------------------*/
+
+
+template <int dim, int spacedim>
+typename Triangulation<dim,spacedim>::vertex_iterator
+Triangulation<dim,spacedim>::begin_vertex() const
+{
+  if (dim==1)
+    {
+      Assert(false, ExcNotImplemented());
+      return raw_vertex_iterator();
+    }
+  else
+    {
+      vertex_iterator i = raw_vertex_iterator(const_cast<Triangulation<dim, spacedim>*>(this),
+                                              0,
+                                              0);
+      if (i.state() != IteratorState::valid)
+        return i;
+      while (i->used() == false)
+        if ((++i).state() != IteratorState::valid)
+          return i;
+      return i;
+    }
+}
+
+
+
+template <int dim, int spacedim>
+typename Triangulation<dim,spacedim>::active_vertex_iterator
+Triangulation<dim,spacedim>::begin_active_vertex() const
+{
+  return begin_vertex();
+}
+
+
+
+template <int dim, int spacedim>
+typename Triangulation<dim,spacedim>::vertex_iterator
+Triangulation<dim,spacedim>::end_vertex() const
+{
+  if (dim==1)
+    {
+      Assert(false, ExcNotImplemented());
+      return raw_vertex_iterator();
+    }
+  else
+    return raw_vertex_iterator(const_cast<Triangulation<dim, spacedim>*>(this),
+                               -1,
+                               numbers::invalid_unsigned_int);
+}
+
+
 
 
 /*------------------------ Line iterator functions ------------------------*/
index c9b6df4e310f7602da552305c48e35d806549ce3..32d11f8c81885fa3c87f98210149a549e76e12da 100644 (file)
@@ -32,6 +32,12 @@ void test ()
   GridGenerator::hyper_cube (tria);
   tria.refine_global (2);
 
+  for (typename Triangulation<2>::vertex_iterator
+       vertex_it = tria.begin_vertex(); vertex_it != tria.end_vertex();
+       ++vertex_it)
+    deallog << vertex_it->center() <<std::endl;
+  deallog << std::endl;
+
   for (typename Triangulation<2>::active_cell_iterator
        cell = tria.begin_active(); cell != tria.end(); ++cell)
     {
index 7631dad293599c387969af5f86ea7391738617a7..2b7cf090de0ed8f11df2ccb311068631b7a2f2e5 100644 (file)
@@ -1,4 +1,30 @@
 
+DEAL::0.00000 0.00000
+DEAL::1.00000 0.00000
+DEAL::0.00000 1.00000
+DEAL::1.00000 1.00000
+DEAL::0.500000 0.00000
+DEAL::0.00000 0.500000
+DEAL::1.00000 0.500000
+DEAL::0.500000 1.00000
+DEAL::0.500000 0.500000
+DEAL::0.250000 0.00000
+DEAL::0.750000 0.00000
+DEAL::0.00000 0.250000
+DEAL::0.00000 0.750000
+DEAL::1.00000 0.250000
+DEAL::1.00000 0.750000
+DEAL::0.250000 1.00000
+DEAL::0.750000 1.00000
+DEAL::0.500000 0.250000
+DEAL::0.500000 0.750000
+DEAL::0.250000 0.500000
+DEAL::0.750000 0.500000
+DEAL::0.250000 0.250000
+DEAL::0.750000 0.250000
+DEAL::0.250000 0.750000
+DEAL::0.750000 0.750000
+DEAL::
 DEAL::0.00000 0.00000
 DEAL::0.250000 0.00000
 DEAL::0.00000 0.250000

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.