• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

p_complex.cc

00001 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #include <algorithm>
00027 #include <iterator>
00028 #include <iostream>
00029 
00030 #include <mln/value/int_u8.hh>
00031 #include <mln/core/alias/point2d.hh>
00032 
00033 #include <mln/core/site_set/p_faces.hh>
00034 #include <mln/core/image/complex_image.hh>
00035 
00036 /* FIXME: Split this test (and maybe factor common parts, like the
00037    construction of the complex), since it exercises too many features
00038    in a single file.  */
00039 
00040 
00041 int main()
00042 {
00043   using namespace mln;
00044 
00045   /*----------.
00046   | Complex.  |
00047   `----------*/
00048 
00049   /* A 2-d (simplicial) complex and its adjacency graph.
00050 
00051        c   0     1     2     3
00052      r .------------------------
00053        |        v0      e3     v3
00054      0 |         o-----------o                v0----e3----v3      
00055        |        / \ ,-----. /                / \    |    /   
00056        |       / . \ \ t1/ /                /   \   t1  /    
00057      1 |   e0 / / \ e1\ / / e4             e0.  ,e1ยด  `e4  
00058        |     / /t0 \ \ ' /                /   t0  \   /      
00059        |    / `-----' \ /                /    |    \ /       
00060      2 |   o-----------o                v1----e2----v2
00061        | v1     e2      v2
00062 
00063        v = vertex
00064        e = edge
00065        t = triangle
00066   */
00067 
00068 
00069   const unsigned D = 2;
00070 
00071   topo::complex<D> c;
00072 
00073   // 0-faces (points).
00074   topo::n_face<0, D> v0 = c.add_face();
00075   topo::n_face<0, D> v1 = c.add_face();
00076   topo::n_face<0, D> v2 = c.add_face();
00077   topo::n_face<0, D> v3 = c.add_face();
00078  
00079   // 1-faces (segments).
00080   topo::n_face<1, D> e0 = c.add_face(v0 + v1);
00081   topo::n_face<1, D> e1 = c.add_face(v0 + v2);
00082   topo::n_face<1, D> e2 = c.add_face(v1 + v2);
00083   topo::n_face<1, D> e3 = c.add_face(v0 + v3);
00084   topo::n_face<1, D> e4 = c.add_face(v2 + v3);
00085 
00086   // 2-faces (triangles).
00087   topo::n_face<2, D> t0 = c.add_face(e0 + e1 + e2);
00088   topo::n_face<2, D> t1 = c.add_face(e1 + e3 + e4);
00089 
00090 
00091   /*------------------------------.
00092   | Complex geometry (location).  |
00093   `------------------------------*/
00094 
00095   typedef point2d P;
00096   typedef geom::complex_geometry<D, P> G;
00097   G geom;
00098   geom.add_location(point2d(0,1)); // 0-face #0.
00099   geom.add_location(point2d(2,0)); // 0-face #1.
00100   geom.add_location(point2d(2,2)); // 0-face #2.
00101   geom.add_location(point2d(0,3)); // 0-face #3. 
00102 
00103 
00104   /*---------------------.
00105   | Complex-based pset.  |
00106   `---------------------*/
00107 
00108   // A pset.
00109   p_complex<D, G> pc(c, geom);
00110 
00111   // An iterator on this pset.
00112   p_complex_fwd_piter_<D, G> p(pc);
00113   for_all(p)
00114   {
00115     std::cout << p << ": ";
00116     // Print site(s).
00117     mln_site_(G) s(p);
00118     std::copy (s.sites.begin(), s.sites.end(),
00119                std::ostream_iterator<P>(std::cout, " "));
00120     std::cout << std::endl;
00121   }
00122 }

Generated on Fri Sep 16 2011 16:33:46 for Milena (Olena) by  doxygen 1.7.1