triangulation.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002     
00003     triangulation.cpp -- See declarations in triangulation.hpp.
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 
00018 #include "config.hpp"
00019 
00020 #if !defined(ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE) || \
00021     defined(ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE_triangulation)
00022 
00023 #include <stack>
00024 
00025 #include "submatrix/indexed.hpp"
00026 #include "vector.hpp"
00027 
00028 #include "triangulation.hpp"
00029 
00030 
00031 namespace Arageli
00032 {
00033 
00034 template
00035 <
00036     typename Q,
00037     typename Dim1,
00038     typename TR,
00039     typename Dim2,
00040     typename Ctrler
00041 >
00042 void triangulate_simple_1
00043 (
00044     const Q& q,
00045     const Dim1& dim,
00046     TR& tr,
00047     const Dim2& subspdim,
00048     Ctrler ctrler
00049 )
00050 {
00051     typedef typename Q::size_type Idx;
00052     typedef indexed_submatrix<const Q> SubQ;
00053 
00054     SubQ curq(&q, fromall);
00055     vector<Idx, false> cursimplex;
00056     Idx curineq = 0;
00057     vector<Idx, false> erasedrows;
00058     Idx curdim = dim;
00059     
00060     // stack of pairs (number of inequation, corresponding q matrix)
00061     typedef std::pair<Idx, SubQ> IdxAndSubQ;
00062     std::stack<IdxAndSubQ> stackq;
00063     
00064     for(;;)
00065     {
00066         if(curq.is_empty())
00067         {
00068             // Add subsimplexes from a subspace (if any).
00069             for(Idx i = 0; i <= subspdim; ++i)
00070             {
00071                 for(Idx j = 0; j <= subspdim; ++j)
00072                     if(i != j)cursimplex.push_back(j + q.nrows());
00073                 if(tr.ncols() < cursimplex.size())
00074                     tr.assign();
00075                 if(tr.ncols() <= cursimplex.size())
00076                     tr.insert_row(tr.nrows(), cursimplex);
00077                 cursimplex.erase(cursimplex.size() - subspdim, subspdim);
00078             }
00079 
00080             curineq = curq.ncols();
00081         }
00082 
00083         for(; curineq < curq.ncols() && is_null(curq(0, curineq)); ++curineq);
00084 
00085         if(curineq < curq.ncols())
00086         {
00087             erasedrows.push_back(0);
00088             
00089             for(Idx i = 1; i < curq.nrows(); ++i)
00090                 if(!is_null(curq(i, curineq)))
00091                     erasedrows.push_back(i);
00092 
00093             if(erasedrows.size() < curq.nrows() || curq.nrows() == 1)
00094             {
00095                 // Reduction of the matrix q to the next facet
00096                 // that is not incidented to the first ray.
00097 
00098                 cursimplex.push_back(curq.row_index()[0]);
00099                 stackq.push(IdxAndSubQ(curineq, curq));
00100                 curq.row_index().erase_subvector(erasedrows);
00101                 curq.col_index().erase(curineq);
00102                 curineq = 0;
00103                 --curdim;
00104 
00105                 for(Idx j = 0; j < curq.ncols();)
00106                 {
00107                     Idx zeros = 0;
00108                     for(Idx i = 0; i < curq.nrows(); ++i)
00109                         zeros += is_null(curq(i, j));
00110 
00111                     if(zeros < curdim-1)curq.col_index().erase(j);
00112                     else ++j;
00113                 } 
00114             }
00115             else
00116             {
00117                 ++curineq;
00118             }
00119 
00120             erasedrows.assign();
00121         }
00122         else
00123         {
00124             if(stackq.empty())break;    // end of triangulation process
00125             curineq = stackq.top().first + 1;   // move to the next inequation
00126             curq = stackq.top().second;
00127             stackq.pop();
00128             ARAGELI_ASSERT_1(!cursimplex.is_empty());
00129             cursimplex.pop_back();
00130             ++curdim;
00131         }
00132     }
00133 }
00134 
00135 
00136 
00137 }
00138 
00139 
00140 #else   // #if !defined(ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE) || ...
00141 
00142 
00143 namespace Arageli
00144 {
00145 
00146 // PLACE ALL NOT TEMPLATE NOT INLINE IMPLEMENTATIONS HERE
00147 
00148 }
00149 
00150 
00151 #endif  // #if !defined(ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE) || ...

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