/* Copyright (c) 1997-2005
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
   http://www.math.tu-berlin.de/polymake,  mailto:polymake@math.tu-berlin.de

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
*/

#ident "$Project: polymake $$Id: 3D_tools.tcc 6357 2005-09-22 17:12:12Z gawrilow $"

namespace polymake { namespace topaz {

template <typename Complex>
bool C3_is_manifold (std::ostream& os, const Complex& C, const bool quiet)
{
   DIMENSION_CHECK(C.empty(), "C3_is_manifold: Complex is empty.");

   // compute the vertex set and test whether C is a pure 3-complex
   Set<int> V;
   for (typename Entire<Complex>::const_iterator c_it=entire(C); !c_it.at_end(); ++c_it) {
      V += *c_it;
      DIMENSION_CHECK_WRAP(c_it->size()>4, "C3_is_manifold: Dimension of " << *c_it << " is greater 3.");

      if (c_it->size()!=4)  // complex is not pure
	 return false;
   }

   // iterate over the vertices and test if their links are 2-balls or 2-spheres
   for (Entire< Set<int> >::iterator it=entire(V); !it.at_end(); ++it)
      if ( !C2_is_BOS(link(C,scalar2set(*it))) ) {
	 if (!quiet)
	    wrap(os) << "C3_is_manifold: Link of " << *it
		     << " is not a 2-ball or 2-sphere." << endl;
	 return false;
      }

   return true;
}

} }

// Local Variables:
// mode:C++
// c-basic-offset:3
// End:
