1999-03-01 15:39:39 +00:00
|
|
|
// clipper.hxx -- top level routines to take a series of arbitrary areas and
|
|
|
|
// produce a tight fitting puzzle pieces that combine to make a
|
|
|
|
// tile
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started February 1999.
|
|
|
|
//
|
|
|
|
// Copyright (C) 1999 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 _CLIPPER_HXX
|
|
|
|
#define _CLIPPER_HXX
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __cplusplus
|
|
|
|
# error This library requires C++
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include <Include/compiler.h>
|
|
|
|
|
1999-06-06 02:31:34 +00:00
|
|
|
#if 0
|
1999-03-01 15:39:39 +00:00
|
|
|
// include Generic Polygon Clipping Library
|
|
|
|
//
|
|
|
|
// http://www.cs.man.ac.uk/aig/staff/alan/software/
|
|
|
|
//
|
|
|
|
extern "C" {
|
|
|
|
#include <gpc.h>
|
|
|
|
}
|
1999-06-06 02:31:34 +00:00
|
|
|
#endif
|
|
|
|
|
1999-06-07 03:40:33 +00:00
|
|
|
#include <Main/construct_types.hxx>
|
1999-06-06 02:31:34 +00:00
|
|
|
#include <Triangulate/polygon.hxx>
|
1999-03-01 15:39:39 +00:00
|
|
|
|
|
|
|
#include STL_STRING
|
|
|
|
#include <vector>
|
|
|
|
|
1999-03-17 23:48:58 +00:00
|
|
|
FG_USING_STD(string);
|
|
|
|
FG_USING_STD(vector);
|
|
|
|
|
|
|
|
|
1999-06-06 02:31:34 +00:00
|
|
|
// typedef vector < gpc_polygon * > gpcpoly_container;
|
|
|
|
// typedef gpcpoly_container::iterator gpcpoly_iterator;
|
|
|
|
// typedef gpcpoly_container::const_iterator const_gpcpoly_iterator;
|
1999-03-17 23:48:58 +00:00
|
|
|
|
1999-03-01 15:39:39 +00:00
|
|
|
|
1999-03-19 00:26:18 +00:00
|
|
|
#define FG_MAX_AREA_TYPES 20
|
1999-03-13 23:51:32 +00:00
|
|
|
#define EXTRA_SAFETY_CLIP
|
1999-06-06 02:31:34 +00:00
|
|
|
// #define FG_MAX_VERTICES 100000
|
1999-03-01 15:39:39 +00:00
|
|
|
|
1999-03-17 23:48:58 +00:00
|
|
|
|
1999-06-06 02:31:34 +00:00
|
|
|
class FGPolyList {
|
1999-03-01 15:39:39 +00:00
|
|
|
public:
|
1999-06-06 02:31:34 +00:00
|
|
|
poly_list polys[FG_MAX_AREA_TYPES];
|
|
|
|
FGPolygon safety_base;
|
1999-03-01 15:39:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-03-13 23:51:32 +00:00
|
|
|
class FGClipper {
|
1999-03-01 15:39:39 +00:00
|
|
|
|
1999-03-13 23:51:32 +00:00
|
|
|
private:
|
1999-03-01 15:39:39 +00:00
|
|
|
|
1999-06-06 02:31:34 +00:00
|
|
|
// gpc_vertex_list v_list;
|
1999-03-13 23:51:32 +00:00
|
|
|
// static gpc_polygon poly;
|
1999-06-06 02:31:34 +00:00
|
|
|
FGPolyList polys_in, polys_clipped;
|
1999-03-01 15:39:39 +00:00
|
|
|
|
1999-03-13 23:51:32 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
FGClipper( void );
|
1999-03-01 15:39:39 +00:00
|
|
|
|
1999-03-13 23:51:32 +00:00
|
|
|
// Destructor
|
|
|
|
~FGClipper( void );
|
|
|
|
|
|
|
|
// Initialize Clipper (allocate and/or connect structures)
|
|
|
|
bool init();
|
|
|
|
|
|
|
|
// Load a polygon definition file
|
|
|
|
bool load_polys(const string& path);
|
|
|
|
|
1999-06-07 03:40:33 +00:00
|
|
|
// remove any slivers from in polygon and move them to out
|
|
|
|
// polygon.
|
|
|
|
void move_slivers( FGPolygon& in, FGPolygon& out );
|
|
|
|
|
|
|
|
// for each sliver contour, see if a union with another polygon
|
|
|
|
// yields a polygon with no increased contours (i.e. the sliver is
|
|
|
|
// adjacent and can be merged.) If so, replace the clipped
|
|
|
|
// polygon with the new polygon that has the sliver merged in.
|
|
|
|
void merge_slivers( FGPolyList& clipped, FGPolygon& slivers );
|
1999-05-27 00:19:04 +00:00
|
|
|
|
1999-03-13 23:51:32 +00:00
|
|
|
// Do actually clipping work
|
|
|
|
bool clip_all(const point2d& min, const point2d& max);
|
1999-03-17 23:48:58 +00:00
|
|
|
|
|
|
|
// return output poly list
|
1999-06-06 02:31:34 +00:00
|
|
|
inline FGPolyList get_polys_clipped() const { return polys_clipped; }
|
1999-03-13 23:51:32 +00:00
|
|
|
};
|
1999-03-01 15:39:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif // _CLIPPER_HXX
|
|
|
|
|
|
|
|
|