More work on triangulation and finding a point inside of each contour/hole
of a polygon.
This commit is contained in:
parent
7e21f8b28f
commit
f6392100ac
7 changed files with 188 additions and 10 deletions
|
@ -61,6 +61,23 @@ typedef group_list::iterator group_list_iterator;
|
|||
typedef group_list::const_iterator const_group_list_iterator;
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
// calculate distance in meters between two lat/lon points
|
||||
static double gc_dist( Point3D p1, Point3D p2 ) {
|
||||
|
@ -407,6 +424,9 @@ static FGPolygon add_nodes_to_poly( const FGPolygon& poly,
|
|||
|
||||
// end of segment is beginning of next segment
|
||||
result.add_node( i, p1 );
|
||||
|
||||
// maintain original hole flag setting
|
||||
result.set_hole_flag( i, poly.get_hole_flag( i ) );
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -875,6 +895,12 @@ void build_airport( string airport_raw, string_list& runways_raw,
|
|||
cout << "result_b = " << result_b.contours() << endl;
|
||||
accum = polygon_union( runway_b, accum );
|
||||
|
||||
char tmpa[256], tmpb[256];
|
||||
sprintf( tmpa, "a%d", i );
|
||||
sprintf( tmpb, "b%d", i );
|
||||
write_polygon( result_a, tmpa );
|
||||
write_polygon( result_b, tmpb );
|
||||
|
||||
// print runway points
|
||||
cout << "clipped runway pts (a)" << endl;
|
||||
for ( int j = 0; j < result_a.contours(); ++j ) {
|
||||
|
@ -903,15 +929,15 @@ void build_airport( string airport_raw, string_list& runways_raw,
|
|||
}
|
||||
}
|
||||
|
||||
// generate convex hull
|
||||
FGPolygon hull = convex_hull(apt_pts);
|
||||
FGPolygon base_nodes = polygon_diff( hull, accum );
|
||||
|
||||
if ( apt_pts.size() == 0 ) {
|
||||
cout << "no airport points generated" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// generate convex hull
|
||||
FGPolygon hull = convex_hull(apt_pts);
|
||||
FGPolygon base_nodes = polygon_diff( hull, accum );
|
||||
|
||||
// add segments to polygons to remove any possible "T"
|
||||
// intersections
|
||||
FGTriNodes tmp_nodes;
|
||||
|
@ -966,6 +992,8 @@ void build_airport( string airport_raw, string_list& runways_raw,
|
|||
cout << "Ready to try new striper" << endl;
|
||||
cout << "First calculate a 'point inside' for each contour and hole"
|
||||
<< endl;
|
||||
write_polygon( base_nodes, "base" );
|
||||
|
||||
/* 1 */ calc_points_inside( base_nodes );
|
||||
for ( int i = 0; i < base_nodes.contours(); ++i ) {
|
||||
cout << base_nodes.get_point_inside( i ) << endl;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <Build/poly_support.hxx>
|
||||
#include <Polygon/polygon.hxx>
|
||||
#include <Triangle/tri_support.h>
|
||||
|
||||
#include "triangle.hxx"
|
||||
|
||||
|
@ -240,6 +241,7 @@ int FGTriangle::rebuild( FGConstruct& c ) {
|
|||
}
|
||||
|
||||
|
||||
#if 0
|
||||
static void write_out_data(struct triangulateio *out) {
|
||||
FILE *node = fopen("tile.node", "w");
|
||||
fprintf(node, "%d 2 %d 0\n",
|
||||
|
@ -289,6 +291,7 @@ static void write_out_data(struct triangulateio *out) {
|
|||
}
|
||||
fclose(fp);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// Front end triangulator for polygon list. Allocates and builds up
|
||||
|
@ -429,7 +432,7 @@ int FGTriangle::run_triangulate( const string& angle, const int pass ) {
|
|||
vorout.normlist = (REAL *) NULL; // Needed only if -v switch used.
|
||||
|
||||
// TEMPORARY
|
||||
write_out_data(&in);
|
||||
write_tri_data(&in);
|
||||
|
||||
// Triangulate the points. Switches are chosen to read and write
|
||||
// a PSLG (p), preserve the convex hull (c), number everything
|
||||
|
@ -462,7 +465,7 @@ int FGTriangle::run_triangulate( const string& angle, const int pass ) {
|
|||
triangulate( (char *)tri_options.c_str(), &in, &out, &vorout );
|
||||
|
||||
// TEMPORARY
|
||||
// write_out_data(&out);
|
||||
// write_tri_data(&out);
|
||||
|
||||
// now copy the results back into the corresponding FGTriangle
|
||||
// structures
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
extern "C" {
|
||||
#include <Triangle/triangle.h>
|
||||
}
|
||||
#include <Triangle/tri_support.h>
|
||||
|
||||
#include "poly_support.hxx"
|
||||
#include "trinodes.hxx"
|
||||
|
@ -503,7 +504,7 @@ static triele_list contour_tesselate( const point_list contour ) {
|
|||
vorout.normlist = (REAL *) NULL; // Needed only if -v switch used.
|
||||
|
||||
// TEMPORARY
|
||||
// write_out_data(&in);
|
||||
write_tri_data(&in);
|
||||
|
||||
// Triangulate the points. Switches are chosen to read and write
|
||||
// a PSLG (p), number everything from zero (z), and produce an
|
||||
|
@ -512,7 +513,8 @@ static triele_list contour_tesselate( const point_list contour ) {
|
|||
// splitting (YY), no quality refinement (q)
|
||||
|
||||
string tri_options;
|
||||
tri_options = "pzYYen";
|
||||
// tri_options = "pzYYen";
|
||||
tri_options = "zYYen";
|
||||
cout << "Triangulation with options = " << tri_options << endl;
|
||||
|
||||
triangulate( (char *)tri_options.c_str(), &in, &out, &vorout );
|
||||
|
@ -630,6 +632,13 @@ void calc_points_inside( FGPolygon& p ) {
|
|||
cout << "calculating points for poly with contours = " << p.contours()
|
||||
<< endl;
|
||||
|
||||
for ( int i = 0; i < p.contours(); ++i ) {
|
||||
if ( p.get_hole_flag( i ) ) {
|
||||
cout << "contour " << i << " is a hole" << endl;
|
||||
} else {
|
||||
cout << "contour " << i << " is not a hole" << endl;
|
||||
}
|
||||
}
|
||||
for ( int i = 0; i < p.contours(); ++i ) {
|
||||
if ( p.get_hole_flag( i ) ) {
|
||||
cout << " hole = " << i << endl;
|
||||
|
|
|
@ -13,7 +13,9 @@ CPPFLAGS += -DTRILIBRARY
|
|||
|
||||
noinst_LIBRARIES = libTriangle.a
|
||||
|
||||
libTriangle_a_SOURCES = triangle.c triangle.h
|
||||
libTriangle_a_SOURCES = \
|
||||
triangle.c triangle.h \
|
||||
tri_support.c tri_support.h
|
||||
|
||||
if HAVE_XWINDOWS
|
||||
|
||||
|
|
82
src/Lib/TriangleJRS/tri_support.c
Normal file
82
src/Lib/TriangleJRS/tri_support.c
Normal file
|
@ -0,0 +1,82 @@
|
|||
// tri_support.c -- supporting routines for the triangulation library
|
||||
//
|
||||
// Written by Curtis Olson, started May 2000.
|
||||
//
|
||||
// Copyright (C) 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$
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "tri_support.h"
|
||||
|
||||
|
||||
void write_tri_data( struct triangulateio *out ) {
|
||||
int i, j;
|
||||
FILE *node, *ele, *fp;
|
||||
|
||||
node = fopen("tile.node", "w");
|
||||
fprintf(node, "%d 2 %d 0\n",
|
||||
out->numberofpoints, out->numberofpointattributes);
|
||||
for (i = 0; i < out->numberofpoints; ++i) {
|
||||
fprintf(node, "%d %.6f %.6f %.2f\n",
|
||||
i, out->pointlist[2*i], out->pointlist[2*i + 1], 0.0);
|
||||
}
|
||||
fclose(node);
|
||||
|
||||
ele = fopen("tile.ele", "w");
|
||||
fprintf(ele, "%d 3 0\n", out->numberoftriangles);
|
||||
for (i = 0; i < out->numberoftriangles; ++i) {
|
||||
fprintf(ele, "%d ", i);
|
||||
for (j = 0; j < out->numberofcorners; ++j) {
|
||||
fprintf(ele, "%d ", out->trianglelist[i * out->numberofcorners + j]);
|
||||
}
|
||||
for (j = 0; j < out->numberoftriangleattributes; ++j) {
|
||||
fprintf(ele, "%.6f ",
|
||||
out->triangleattributelist[i
|
||||
* out->numberoftriangleattributes
|
||||
+ j]
|
||||
);
|
||||
}
|
||||
fprintf(ele, "\n");
|
||||
}
|
||||
fclose(ele);
|
||||
|
||||
fp = fopen("tile.poly", "w");
|
||||
fprintf(fp, "0 2 1 0\n");
|
||||
fprintf(fp, "%d 1\n", out->numberofsegments);
|
||||
for (i = 0; i < out->numberofsegments; ++i) {
|
||||
fprintf(fp, "%d %d %d %d\n",
|
||||
i, out->segmentlist[2*i], out->segmentlist[2*i + 1],
|
||||
out->segmentmarkerlist[i] );
|
||||
}
|
||||
fprintf(fp, "%d\n", out->numberofholes);
|
||||
for (i = 0; i < out->numberofholes; ++i) {
|
||||
fprintf(fp, "%d %.6f %.6f\n",
|
||||
i, out->holelist[2*i], out->holelist[2*i + 1]);
|
||||
}
|
||||
fprintf(fp, "%d\n", out->numberofregions);
|
||||
for (i = 0; i < out->numberofregions; ++i) {
|
||||
fprintf(fp, "%d %.6f %.6f %.6f\n",
|
||||
i, out->regionlist[4*i], out->regionlist[4*i + 1],
|
||||
out->regionlist[4*i + 2]);
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
|
47
src/Lib/TriangleJRS/tri_support.h
Normal file
47
src/Lib/TriangleJRS/tri_support.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
// tri_support.h -- supporting routines for the triangulation library
|
||||
//
|
||||
// Written by Curtis Olson, started May 2000.
|
||||
//
|
||||
// Copyright (C) 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 _TRI_SUPPORT_H
|
||||
#define _TRI_SUPPORT_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define REAL double
|
||||
#include "triangle.h"
|
||||
|
||||
|
||||
void write_tri_data( struct triangulateio *out );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // _TRI_SUPPORT_H
|
||||
|
||||
|
|
@ -245,6 +245,10 @@
|
|||
/* */
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifndef _SHEWCHUK_TRIANGLE_H
|
||||
#define _SHEWCHUK_TRIANGLE_H
|
||||
|
||||
|
||||
/* CLO: 3/21/99 - this could be done as a compile flag, but I always want
|
||||
this defined and I don't want to sprinkle extra stuff throughout the
|
||||
Makefile system if I don't have to. */
|
||||
|
@ -287,3 +291,6 @@ void triangulate(char *, struct triangulateio *, struct triangulateio *,
|
|||
#else /* not ANSI_DECLARATORS */
|
||||
void triangulate();
|
||||
#endif /* not ANSI_DECLARATORS */
|
||||
|
||||
|
||||
#endif /* SHEWCHUK TRIANGLE */
|
||||
|
|
Loading…
Add table
Reference in a new issue