/* Copyright (c) 1997-2010
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Darmstadt, Germany)
   http://www.polymake.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.
--------------------------------------------------------------------------------
   $Project: polymake $$Id: crosscut_complex.cc 9991 2010-12-12 23:36:28Z gawrilow $
*/

#include "polymake/client.h"
#include "polymake/IncidenceMatrix.h"
#include "polymake/linalg.h"
#include "polymake/Rational.h"

namespace polymake { namespace topaz {

perl::Object crosscut_complex(perl::Object p_in, perl::OptionSet options)
{
   const IncidenceMatrix<> C = p_in.give("VERTICES_IN_FACETS");
   perl::Object p_out("SimplicialComplex");
   p_out.set_description() << "Crosscut complex of " << p_in.name() << endl;
   p_out.take("FACETS") << rows(C);

   const bool no_coord=options["noc"];
   if (!no_coord) {
      const bool bounded=p_in.give("BOUNDED");
      if (bounded) {
         const Matrix<Rational> V = p_in.give("VERTICES");
         p_out.take("GEOMETRIC_REALIZATION") << dehomogenize(V);
      }
   }

   return p_out;
}

UserFunction4perl("# @category Producing a simplicial complex from other objects\n"
                  "# Produce the __crosscut complex__ of the boundary of a polytope.\n"
                  "# @param polytope::Polytope p"
                  "# @option Bool noc suppresses copying the vertex coordinates to [[GEOMETRIC_REALIZATION]]\n"
                  "# @return SimplicialComplex",
                  &crosscut_complex, "crosscut_complex(polytope::Polytope, { noc => 0 })");
} }

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