/* 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: sphere.cc,v 1.10 2004/10/26 18:57:00 gawrilow Exp $"

#include <Poly.h>
#include <Matrix.h>
#include <Array.h>
#include <PowerSet.h>

namespace polymake {
namespace topaz {
  
void sphere(Poly& p, const int d)
{
   const Array< Set<int> > F(d+2, all_subsets_less_1(sequence(0,d+2)).begin());
   
   Matrix<int> Geom(d+2,d+1);
   for (int i=0; i<d+1; ++i)
      Geom(i+1,i) = 1;
   
   p.take("DESCRIPTION") << "A " << d
			 << "-dimensional sphere.\nRealized as the boundary of a "
			 << d+1 << "-simplex.";
   p.take("FACETS") << F;
   p.take("DIM") << d;
   p.take("PURE") << 1;
   p.take("MANIFOLD") << 1;
   p.take("CLOSED_PSEUDO_MANIFOLD") << 1;
   p.take("ORIENTED_PSEUDO_MANIFOLD") << 1;
   p.take("SPHERE") << 1;
   p.take("GEOMETRIC_REALIZATION") << Geom;
}

} }

using namespace polymake;

/** @file sphere
 *
 *  Produce a $d$-sphere.
 *
 *  @synopsis sphere <file> <dimension>
 *
 *  @writing  DESCRIPTION, FACETS, DIM, PURE, MANIFOLD, CLOSED_PSEUDO_MANIFOLD, ORIENTED_PSEUDO_MANIFOLD, SPHERE, GEOMETRIC_REALIZATION
 *
 *  @index clients Producing from scratch
 */


int main(int argc, const char *argv[])
{
   if (argc!=3) {
      cerr << "usage: " << argv[0] << " <file> <dimension>" << endl;
      return 1;
   }
   try {
      Poly p(argv[1], ios::out | ios::trunc, "topaz::default");

      const int d=atoi(argv[2]);
      if (d<0) {
	 cerr << argv[0] << ": d<0" << endl;
	 return 1;
      }

      topaz::sphere(p,d);
  }
   catch (const std::exception& e) {
     cerr << e.what() << endl;
     return 1;
   }
   return 0;
}


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