polyhedron.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002     
00003     polyhedron.hpp -- a representation of a convex polyhedron and operations on it.
00004 
00005     This file is a part of the Arageli library.
00006 
00007     Copyright (C) Sergey S. Lyalin, 2006
00008     University of Nizhni Novgorod, Russia, 2005--2006
00009 
00010 *****************************************************************************/
00011 
00021 #ifndef _ARAGELI_polyhedron_hpp_
00022 #define _ARAGELI_polyhedron_hpp_
00023 
00024 #include "config.hpp"
00025 
00026 #include "gcd.hpp"
00027 #include "big_int.hpp"
00028 #include "rational.hpp"
00029 #include "cone.hpp"
00030 #include "sideset.hpp"
00031 #include "vector.hpp"
00032 #include "matrix.hpp"
00033 
00034 
00035 namespace Arageli
00036 {
00037 
00038 struct fromempty_t {};
00039 const fromempty_t fromempty = fromempty_t();
00040 
00041 struct fromivert_t {};
00042 const fromivert_t fromivert = fromivert_t();
00043 
00044 struct fromvert_t {};
00045 const fromvert_t fromvert = fromvert_t();
00046 
00047 
00048 template <typename T, typename M, typename C> class polyhedron_default_config {};
00049 
00050 
00052 
00057 template
00058 <
00059     typename T = big_int,
00060     typename M = matrix<big_int>,
00061     typename C = cone<T, M>,
00062     typename CFG = polyhedron_default_config<T, M, C>
00063 >
00064 class polyhedron
00065 {
00066 public:
00067 
00068     //typedef matrix<R> vertices_type;
00069 
00070     typedef C cone;
00071 
00072     typedef typename C::inequation_element_type inequation_element_type;
00073     typedef typename C::equation_element_type equation_element_type;
00074     typedef typename C::generatrix_element_type generatrix_element_type;
00075     typedef typename C::basis_element_type basis_element_type;
00076 
00077     typedef typename C::inequation_type inequation_type;
00078     typedef typename C::equation_type equation_type;
00079     typedef typename C::generatrix_type generatrix_type;
00080     typedef typename C::basis_type basis_type;
00081 
00082     typedef typename C::size_type size_type;
00083     typedef typename C::dim_type dim_type;
00084     typedef typename C::difference_type difference_type;
00085 
00086 
00088 
00090     polyhedron () : cone_m(1, fromnull) {}
00091 
00092     
00094 
00095     template <typename D>
00096     polyhedron (const D& dim, const fromempty_t&)
00097     :   cone_m(dim + 1, fromnull)
00098     {}
00099          
00100 
00102 
00103     template <typename D>
00104     polyhedron (const D& dim, const fromspace_t&);
00105 
00106 
00108 
00111     template <typename M1>
00112     polyhedron (const M1& ineqmat, const fromineq_t&);
00113 
00114 
00116     template <typename M1>
00117     polyhedron (const M1& vert, const fromivert_t&);
00118 
00119 
00121 
00126     template <typename M1>
00127     polyhedron (const M1& vert, const fromvert_t&);
00128 
00129 
00132     sideset sides () const;
00134 
00135 
00136     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00138 
00140 
00141 
00143     bool is_implicit_valid () const
00144     { return cone_m.is_implicit_valid(); }
00145 
00147     bool is_parametric_valid () const
00148     { return cone_m.is_parametric_valid(); }
00149 
00151     bool is_all_valid () const
00152     { return cone_m.is_all_valid(); }
00153 
00155 
00159     bool is_implicit_normal () const
00160     { return cone_m.is_implicit_normal(); }
00161 
00163 
00167     bool is_parametric_normal () const
00168     { return cone_m.is_parametric_normal(); }
00169 
00171     bool is_all_normal () const
00172     { return cone_m.is_all_normal(); }
00173 
00174 
00176 
00177 
00178     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00180 
00182 
00183 
00185 
00187     void validate_implicit () const
00188     { cone_m.validate_implicit(); }
00189 
00191 
00193     void validate_parametric () const
00194     { cone_m.validate_parametric(); }
00195 
00197     void validate_all () const
00198     { cone_m.validate_all(); }
00199     
00201 
00203     void normalize_implicit () const
00204     { cone_m.normalize_implicit(); }
00205 
00207 
00209     void normalize_parametric () const
00210     { cone_m.normalize_parametric(); }
00211     
00213     void normalize_all () const
00214     { cone_m.normalize_all(); }
00215 
00216 
00218 
00219 
00220     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00222 
00224 
00225     
00227 
00230     void set_valid_implicit ()
00231     { cone_m.set_valid_implicit(); }
00232 
00234 
00237     void set_valid_parametric ()
00238     { cone_m.set_valid_parametric(); }
00239 
00241 
00244     void set_valid_all ()
00245     { cone_m.set_valid_all(); }
00246 
00248 
00251     void set_normal_implicit ()
00252     { cone_m.set_normal_implicit(); }
00253 
00255 
00258     void set_normal_parametric ()
00259     { cone_m.set_normal_parametric(); }
00260 
00262 
00265     void set_normal_all ()
00266     { cone_m.set_normal_all(); }
00267 
00269 
00270 
00271     // Brrrrr!
00272     template <typename M1>
00273     M1 vertices () const
00274     {
00275         normalize_parametric();
00276         M1 res = cone_m.generatrix_matrix();
00277 
00278         for(std::size_t i = 0; i < res.nrows();)
00279             if(Arageli::is_null(res(i, 0)))
00280                 res.erase_row(i);
00281             else
00282             {
00283                 res.div_row(i, safe_reference(res(i, 0)));
00284                 ++i;
00285             }
00286 
00287         res.erase_col(0);
00288 
00289         return res;
00290     }
00291 
00292     // Brrrrr!
00293     const T& inequation_matrix (std::size_t i, std::size_t j) const
00294     { return cone_m.inequation_matrix()(i, j); }
00295 
00296     // Brrrrr!
00297     vector<T> facet_normal (std::size_t i) const
00298     {
00299         vector<T> res = cone_m.inequation_matrix().copy_row(i);
00300         res.pop_front();
00301         return res;
00302     }
00303 
00304     std::size_t space_dim () const { return cone_m.space_dim() - 1; }
00305 
00306 private:
00307 
00308     C cone_m;
00309 
00310 };
00311 
00312 
00314 template
00315 <
00316     typename Out, 
00317     typename T,
00318     typename R,
00319     typename M,
00320     typename CFG
00321 >
00322 void output_vrml (Out& out, const polyhedron<T, R, M, CFG>& p);
00323 
00324 
00325 class pstricks_color_map
00326 {
00327 public:
00328 
00329     pstricks_color_map
00330     (
00331         double rstart_a,
00332         double gstart_a,
00333         double bstart_a,
00334         double rend_a,
00335         double gend_a,
00336         double bend_a,
00337         std::size_t n_a,
00338         const std::string& name_a
00339     );
00340 
00342     const std::string& name (double x) const;
00343 
00344 };
00345 
00346 
00348 
00350 template
00351 <
00352     typename Out,
00353     typename P,
00354     typename X1, typename Y1, typename X2, typename Y2,
00355     typename Viewdir,
00356     typename Colormap
00357 >
00358 void output_polytope_pstricks_3d
00359 (
00360     Out& out,
00361     const P& p,
00362     double x1,
00363     double y1,
00364     double x2,
00365     double y2,
00366     double linewidth,
00367     const Viewdir& viewdir,
00368     const Colormap& colormap
00369 );
00370 
00371 
00372 } // namesapce Arageli
00373 
00374 
00375 #ifdef ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE
00376     #define ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE_polyhedron
00377     #include "polyhedron.cpp"
00378     #undef  ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE_polyhedron
00379 #endif
00380 
00381 #endif  // #ifndef _ARAGELI_polyhedron_hpp_

Generated on Thu Aug 31 17:38:08 2006 for Arageli by  doxygen 1.4.7