/* Copyright (c) 1997-2006
   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: boundary_of_pseudo_manifold.cc,v 1.13 2006/02/27 00:11:25 gawrilow Exp $"

#include <Poly.h>
#include <Array.h>
#include <complex_tools.h>

namespace polymake {
namespace topaz {
  
void boundary_of_pseudo_manifold(Poly& p, const char* boundary_section)
{
   const HasseDiagram<> HD = p.give("HASSE_DIAGRAM");
   const bool is_pmf = p.give("PSEUDO_MANIFOLD");
   if (!is_pmf)
      throw std::runtime_error("boundary_of_pseudo_manifold: Complex is not a PSEUDO_MANIFOLD.");
   
   const Boundary_of_PseudoManifold B=boundary_of_pseudo_manifold(HD);
   if (B.empty())
      p.take(boundary_section) << Set<int>();  // an empty complex is represented by a single empty face.
   else
      p.take(boundary_section) << as_array(B);
}
   
} }

using namespace polymake;

/** @file boundary_of_pseudo_manifold
 *
 *  Produce the boundary (= ridges contained in one facet only) of a @see SimplicialComplex.PSEUDO_MANIFOLD.
 *
 *  @synopsis boundary_of_pseudo_manifold <file> <boundary_section>
 *
 *  @reading  PSEUDO_MANIFOLD, HASSE_DIAGRAM
 *  @writing  <boundary_section>
 *
 */


int main(int argc, const char* argv[])
{
   if (argc != 3) {
      cerr << "usage: " << argv[0] << " <file> <boundary_section>" << endl;
      return 1;
   }
   try {
      Poly p(argv[1], ios::in | ios::out);
      topaz::boundary_of_pseudo_manifold(p, argv[2]);
   } 
   catch (const std::exception& e) {
      cerr << e.what() << endl;
      return 1;
   }
   return 0;
}


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