Chapter 51
Geomview

Andreas Fabri and Sylvain Pion

51.1   Definition

This chapter presents the CGAL interface to Geomview1, which is a viewer for three-dimensional objects, originally developed at the Geometry Center in Minneapolis2.

Geomview 1.8.1 is required.

Note: In releases up to and including 2.2, CGAL used to have the following requirement : the last line in the startup file .geomview must be (echo "started"). This is no longer necessary.

An object of the class Geomview_stream is a stream in which geometric objects can be inserted and where geometric objects can be extracted from. The constructor starts Geomview either on the local either on a remote machine.

Not all but most classes of the CGAL kernel have output operators for the Geomview_stream. 2D objects are embedded in the xy-plane. Input is only provided for points. Polyhedron and 2D and 3D triangulations have output operators for the Geomview_stream.

51.2   Implementation

The constructor forks a process and establishes two pipes between the processes. The forked process is then overlaid with Geomview. The file descriptors stdin and stdout of Geomview are hooked on the two pipes.

All insert operators construct expressions in gcl, the Geomview command language, which is a subset of LISP. These expressions are sent to Geomview via the pipe. The extract operators notify interest for a certain kind of events. When such an event happens Geomview sends a description of the event in gcl and the extract operator has to parse this expression.

In order to implement further insert and extract operators you should take a look at the implementation and at the Geomview manual.

51.3   Example

The following program ouputs successively a 2D Delaunay triangulation (projected), a 3D Delaunay, and a terrain from the set of points.
// Copyright (c) 2000, 2001, 2004  Utrecht University (The Netherlands),
// ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany),
// INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
// (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria),
// and Tel-Aviv University (Israel).  All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; version 2.1 of the License.
// See the file LICENSE.LGPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.2-branch/Geomview/demo/Geomview/terrain.C $
// $Id: terrain.C 28567 2006-02-16 14:30:13Z lsaboret $
// 
//
// Author(s)     : Sylvain Pion

#include <CGAL/Cartesian.h>
#include <iostream>

#ifndef CGAL_USE_GEOMVIEW
int main()
{
  std::cout << "Geomview doesn't work on Windows, so..." << std::endl;
  return 0;
}
#else

#include <fstream>
#include <unistd.h> // for sleep()

#include <CGAL/Triangulation_euclidean_traits_xy_3.h>

#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Delaunay_triangulation_3.h>

#include <CGAL/IO/Geomview_stream.h>
#include <CGAL/IO/Triangulation_geomview_ostream_2.h>
#include <CGAL/IO/Triangulation_geomview_ostream_3.h>

#include <CGAL/intersections.h>

typedef CGAL::Cartesian<double>  K;

typedef K::Point_2 Point2;
typedef CGAL::Triangulation_euclidean_traits_xy_3<K> Gt3;
typedef Gt3::Point Point3;

typedef CGAL::Delaunay_triangulation_2<K>   Delaunay;
typedef CGAL::Delaunay_triangulation_2<Gt3> Terrain;

typedef CGAL::Delaunay_triangulation_3<K>   Delaunay3d;

int main()
{
  CGAL::Geomview_stream gv(CGAL::Bbox_3(-100, -100, -100, 600, 600, 600));
  gv.set_line_width(4);
  // gv.set_trace(true);
  gv.set_bg_color(CGAL::Color(0, 200, 200));
  // gv.clear();

  Delaunay D;
  Delaunay3d D3d;
  Terrain T;
  std::ifstream iFile("data/points3", std::ios::in);
  Point3 p;

  while ( iFile >> p ) 
  { 
      D.insert( Point2(p.x(), p.y()) ); 
      D3d.insert( p );
      T.insert( p );
  }

  // use different colors, and put a few sleeps/clear.

  gv << CGAL::BLUE;
  std::cout << "Drawing 2D Delaunay triangulation in wired mode.\n";
  gv.set_wired(true);
  gv << D;

#if 1 // It's too slow !  Needs to use OFF for that.
  gv << CGAL::RED;
  std::cout << "Drawing its Voronoi diagram.\n";
  gv.set_wired(true);
  D.draw_dual(gv);
#endif

  sleep(5);
  gv.clear();

  std::cout << "Drawing 2D Delaunay triangulation in non-wired mode.\n";
  gv.set_wired(false);
  gv << D;
  sleep(5);
  gv.clear();

  std::cout << "Drawing 3D Delaunay triangulation in wired mode.\n";
  gv.set_wired(true);
  gv << D3d;
  sleep(5);
  gv.clear();
  std::cout << "Drawing 3D Delaunay triangulation in non-wired mode.\n";
  gv.set_wired(false);
  gv << D3d;
  sleep(5);
  gv.clear();

  std::cout << "Drawing Terrain in wired mode.\n";
  gv.set_wired(true);
  gv << T;
  sleep(5);
  gv.clear();
  std::cout << "Drawing Terrain in non-wired mode.\n";
  gv.set_wired(false);
  gv << T;

  std::cout << "Enter a key to finish" << std::endl;
  char ch;
  std::cin >> ch;

  return 0;
}
#endif


Footnotes

 1  http://www.geomview.org/
 2  http://www.geom.umn.edu/