From 77ef53bd83d2bfbd732d5b9584c1e8223ee77b39 Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 4 Jan 2001 20:33:14 +0000 Subject: [PATCH] Initial revision. --- src/Lib/Output/Makefile.am | 6 ++ src/Lib/Output/output.cxx | 135 +++++++++++++++++++++++++++++++++++++ src/Lib/Output/output.hxx | 53 +++++++++++++++ 3 files changed, 194 insertions(+) create mode 100644 src/Lib/Output/Makefile.am create mode 100644 src/Lib/Output/output.cxx create mode 100644 src/Lib/Output/output.hxx diff --git a/src/Lib/Output/Makefile.am b/src/Lib/Output/Makefile.am new file mode 100644 index 00000000..96785151 --- /dev/null +++ b/src/Lib/Output/Makefile.am @@ -0,0 +1,6 @@ +noinst_LIBRARIES = libOutput.a + +libOutput_a_SOURCES = \ + output.cxx output.hxx + +INCLUDES += -I$(top_srcdir)/src -I$(top_srcdir)/src/Lib diff --git a/src/Lib/Output/output.cxx b/src/Lib/Output/output.cxx new file mode 100644 index 00000000..cb826b28 --- /dev/null +++ b/src/Lib/Output/output.cxx @@ -0,0 +1,135 @@ +// output.cxx -- routines to output a polygon model of an airport +// +// Written by Curtis Olson, started September 1999. +// +// Copyright (C) 1999 - 2000 Curtis L. Olson - curt@flightgear.org +// +// 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 of the License, or +// (at your option) any later version. +// +// 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. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ +// + + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include +#include +#include + +#include +#include STL_STRING + +#include + +#include +#include + +#include "output.hxx" + +#ifdef _MSC_VER +# include +#endif + +FG_USING_STD( cout ); +FG_USING_STD( endl ); + + +void write_polygon( const FGPolygon& poly, const string& base ) { + for ( int i = 0; i < poly.contours(); ++i ) { + char name[256]; + sprintf(name, "%s%d", base.c_str(), i ); + FILE *fp = fopen( name, "w" ); + + for ( int j = 0; j < poly.contour_size( i ); ++j ) { + Point3D p0 = poly.get_pt(i, j); + fprintf(fp, "%.8f %.8f\n", p0.x(), p0.y()); + } + Point3D p0 = poly.get_pt(i, 0); + fprintf(fp, "%.8f %.8f\n", p0.x(), p0.y()); + fclose(fp); + } +} + + +// update index +void write_index(const string& base, const SGBucket& b, const string& name) { + string dir = base + "/" + b.gen_base_path(); +#ifdef _MSC_VER + fg_mkdir( dir.c_str() ); +#else + string command = "mkdir -p " + dir; + system(command.c_str()); +#endif + + string file = dir + "/" + b.gen_index_str() + ".ind"; + // string file = dir + "/" + name; + cout << "Output file = " << file << endl; + + FILE *fp; + if ( (fp = fopen( file.c_str(), "a" )) == NULL ) { + cout << "ERROR: opening " << file << " for writing!" << endl; + exit(-1); + } + + fprintf( fp, "OBJECT %s\n", name.c_str() ); + fclose( fp ); +} + + +void write_boundary( const string& base, const SGBucket& b, + const FGPolygon& bounds, long int p_index ) +{ + Point3D p; + + string dir = base + "/" + b.gen_base_path(); +#ifdef _MSC_VER + fg_mkdir( dir.c_str() ); +#else + string command = "mkdir -p " + dir; + system(command.c_str()); +#endif + + string file = dir + "/" + b.gen_index_str(); + + char poly_index[256]; + sprintf( poly_index, "%ld", p_index ); + file += "."; + file += poly_index; + + cout << "Output file = " << file << endl; + + FILE *fp; + if ( (fp = fopen( file.c_str(), "w" )) == NULL ) { + cout << "ERROR: opening " << file << " for writing!" << endl; + exit(-1); + } + + fprintf( fp, "Hole\n" ); + + fprintf( fp, "%d\n", bounds.contours() ); + for ( int i = 0; i < bounds.contours(); ++i ) { + fprintf( fp, "%d\n", bounds.contour_size(i) ); + fprintf( fp, "%d\n", bounds.get_hole_flag(i) ); + for ( int j = 0; j < bounds.contour_size(i); ++j ) { + p = bounds.get_pt( i, j ); + fprintf( fp, "%.15f %.15f\n", p.x(), p.y() ); + } + } + fclose( fp ); +} diff --git a/src/Lib/Output/output.hxx b/src/Lib/Output/output.hxx new file mode 100644 index 00000000..319e02b1 --- /dev/null +++ b/src/Lib/Output/output.hxx @@ -0,0 +1,53 @@ +// output.hxx -- routines to output a polygon model of an airport +// +// Written by Curtis Olson, started September 1999. +// +// Copyright (C) 1999 - 2000 Curtis L. Olson - curt@flightgear.org +// +// 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 of the License, or +// (at your option) any later version. +// +// 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. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ +// + + +#ifndef _TG_OUTPUT_HXX +#define _TG_OUTPUT_HXX + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include + +#include +#include + +#include +#include STL_STRING + +#include + + +void write_polygon( const FGPolygon& poly, const string& base ); + +// update index +void write_index(const string& base, const SGBucket& b, const string& name); + +void write_boundary( const string& base, const SGBucket& b, + const FGPolygon& bounds, long int p_index ); + +#endif // _TG_OUTPUT_HXX