/* Copyright (c) 1997-2004
   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: k_skeleton.cc,v 1.17 2004/10/26 18:57:01 gawrilow Exp $"

#include <ctime>

#include <Poly.h>
#include <complex_tools.h>
#include <argv_options.h>
#include <Rational.h>
#include <Matrix.h>

namespace polymake {
namespace topaz {
  
void k_skeleton(Poly& p_out, Poly& p_in, const int k,
		const bool geom_real, const bool no_labels,
		const std::string& comment)
{
   Array< Set<int> > C = p_in.give("FACETS");
   
   const PowerSet<int> Skeleton = k_skeleton(C,k);
   
   // no adjusting of vertices required
   
   p_out.take("DESCRIPTION") << comment;
   p_out.take("FACETS") << as_array(Skeleton);
   
   if (geom_real) {
      const Matrix<Rational> GR = p_in.give("GEOMETRIC_REALIZATION");
      p_out.take("GEOMETRIC_REALIZATION") << GR;
   }

   if (!no_labels) {
      const Array<std::string> L = p_in.give("VERTEX_LABELS");
      p_out.take("VERTEX_LABELS") << L;
   }
}

} }

using namespace polymake;

/** @file k_skeleton
 *
 *  Produce the $k$-skeleton.
 *
 *  The @c -nol flag tells the client not to write any labels.
 *
 *  @synopsis k_skeleton <out_file> <in_file> <k> [ -geom_real ] [ -nol ]
 *
 *  @reading  FACETS, may read VERTEX_LABELS
 *  @writing  DESCRIPTION, FACETS, may write VERTEX_LABELS
 *
 *  @index clients Producing a new simplicial complex from others
 */


int main(int argc, const char* argv[])
{
   argv_option options[]={ { "-nol" }, { "-geom_real" } };
   enum { no_labels, geom_real };
   if ( !extract_options(argc,argv,3,options) || argc<4 || argc>5 ) {
      cerr << "usage: " << argv[0] << " <out_file> <in_file> <k>  [ -geom_real ] [ -nol ]" << endl;
      return 1;
   }
   try {
      Poly p_in(argv[2], ios::in);
      Poly p_out(argv[1], ios::out | ios::trunc, p_in.type());

      const int k=atoi(argv[3]);

      std::ostringstream comment;
      comment << k << "-Skeleton of " << argv[2] << ".";

      topaz::k_skeleton(p_out, p_in, k, options[geom_real], options[no_labels], comment.str());
   } 
   catch (const std::exception& e) {
     cerr << e.what() << endl;
     return 1;
   }
   return 0;
}


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