1
0
Fork 0

Got rid of the unused parts of the old calc_points_inside()-code.

This commit is contained in:
Ralf Gerlich 2008-01-09 14:15:48 +01:00
parent f4b4a7dc3c
commit 2b93966193
2 changed files with 0 additions and 468 deletions

View file

@ -111,138 +111,6 @@ static bool intersects( Point3D p0, Point3D p1, double x, Point3D *result ) {
return false;
}
// calculate some "arbitrary" point inside the specified contour for
// assigning attribute areas
Point3D calc_point_inside_old( const TGPolygon& p, const int contour,
const TGTriNodes& trinodes ) {
Point3D tmp, min, ln, p1, p2, p3, m, result, inside_pt;
int min_node_index = 0;
int min_index = 0;
int p1_index = 0;
int p2_index = 0;
int ln_index = 0;
int i;
// 1. find a point on the specified contour, min, with smallest y
// min.y() starts greater than the biggest possible lat (degrees)
min.sety( 100.0 );
point_list c = p.get_contour(contour);
point_list_iterator current, last;
current = c.begin();
last = c.end();
for ( i = 0; i < p.contour_size( contour ); ++i ) {
tmp = p.get_pt( contour, i );
if ( tmp.y() < min.y() ) {
min = tmp;
min_index = trinodes.find( min );
min_node_index = i;
// cout << "min index = " << *current
// << " value = " << min_y << endl;
} else {
// cout << " index = " << *current << endl;
}
}
//cout << "min node index = " << min_node_index << endl;
//cout << "min index = " << min_index
//<< " value = " << trinodes.get_node( min_index )
//<< " == " << min << endl;
// 2. take midpoint, m, of min with neighbor having lowest
// fabs(slope)
if ( min_node_index == 0 ) {
p1 = c[1];
p2 = c[c.size() - 1];
} else if ( min_node_index == (int)(c.size()) - 1 ) {
p1 = c[0];
p2 = c[c.size() - 2];
} else {
p1 = c[min_node_index - 1];
p2 = c[min_node_index + 1];
}
p1_index = trinodes.find( p1 );
p2_index = trinodes.find( p2 );
double s1 = fabs( slope(min, p1) );
double s2 = fabs( slope(min, p2) );
if ( s1 < s2 ) {
ln_index = p1_index;
ln = p1;
} else {
ln_index = p2_index;
ln = p2;
}
TGTriSeg base_leg( min_index, ln_index, 0 );
m.setx( (min.x() + ln.x()) / 2.0 );
m.sety( (min.y() + ln.y()) / 2.0 );
//cout << "low mid point = " << m << endl;
// 3. intersect vertical line through m and all other segments of
// all other contours of this polygon. save point, p3, with
// smallest y > m.y
p3.sety(100);
for ( i = 0; i < (int)p.contours(); ++i ) {
//cout << "contour = " << i << " size = " << p.contour_size( i ) << endl;
for ( int j = 0; j < (int)(p.contour_size( i ) - 1); ++j ) {
// cout << " p1 = " << poly[i][j] << " p2 = "
// << poly[i][j+1] << endl;
p1 = p.get_pt( i, j );
p2 = p.get_pt( i, j+1 );
p1_index = trinodes.find( p1 );
p2_index = trinodes.find( p2 );
if ( intersects(p1, p2, m.x(), &result) ) {
//cout << "intersection = " << result << endl;
if ( ( result.y() < p3.y() ) &&
( result.y() > m.y() ) &&
!( base_leg == TGTriSeg(p1_index, p2_index, 0) ) ) {
p3 = result;
}
}
}
// cout << " p1 = " << poly[i][0] << " p2 = "
// << poly[i][poly[i].size() - 1] << endl;
p1 = p.get_pt( i, 0 );
p2 = p.get_pt( i, p.contour_size( i ) - 1 );
p1_index = trinodes.find( p1 );
p2_index = trinodes.find( p2 );
if ( intersects(p1, p2, m.x(), &result) ) {
//cout << "intersection = " << result << endl;
if ( ( result.y() < p3.y() ) &&
( result.y() > m.y() ) &&
!( base_leg == TGTriSeg(p1_index, p2_index, 0) ) ) {
p3 = result;
}
}
}
if ( p3.y() < 100 ) {
//cout << "low intersection of other segment = " << p3 << endl;
inside_pt = Point3D( (m.x() + p3.x()) / 2.0,
(m.y() + p3.y()) / 2.0,
0.0 );
} else {
cout << "Error: Failed to find a point inside :-(" << endl;
inside_pt = p3;
}
// 4. take midpoint of p2 && m as an arbitrary point inside polygon
//cout << "inside point = " << inside_pt << endl;
return inside_pt;
}
// basic triangulation of a polygon with out adding points or
// splitting edges, this should triangulate around interior holes.
void polygon_tesselate( const TGPolygon &p,
@ -488,336 +356,6 @@ TGPolygon polygon_tesselate_alt( TGPolygon &p ) {
return result;
}
// basic triangulation of a contour with out adding points or
// splitting edges but cuts out any of the specified holes
static void contour_tesselate( TGContourNode *node, const TGPolygon &p,
const TGPolygon &hole_polys,
const point_list &hole_pts,
triele_list &elelist,
point_list &out_pts )
{
struct triangulateio in, out, vorout;
int i;
// make sure all elements of these structs point to "NULL"
zero_triangulateio( &in );
zero_triangulateio( &out );
zero_triangulateio( &vorout );
int counter, start, end;
// list of points
int contour_num = node->get_contour_num();
// cout << "Tesselating contour = " << contour_num << endl;
point_list contour = p.get_contour( contour_num );
double max_x = contour[0].x();
int total_pts = contour.size();
// cout << "contour = " << contour_num << " nodes = " << total_pts << endl;
#if 0
// testing ... don't enable this if not testing
if ( contour_num != 0 || total_pts != 28 ) {
out_pts.push_back( Point3D(0, 0, 0) );
out_pts.push_back( Point3D(0, 1, 0) );
out_pts.push_back( Point3D(1, 1, 0) );
elelist.push_back( TGTriEle( 0, 1, 2, 0.0 ) );
return;
}
#endif
for ( i = 0; i < hole_polys.contours(); ++i ) {
total_pts += hole_polys.contour_size( i );
}
in.numberofpoints = total_pts;
// cout << "total points = " << total_pts << endl;
in.pointlist = (REAL *) malloc(in.numberofpoints * 2 * sizeof(REAL));
counter = 0;
for ( i = 0; i < (int)contour.size(); ++i ) {
in.pointlist[2*counter] = contour[i].x();
in.pointlist[2*counter + 1] = contour[i].y();
if ( contour[i].x() > max_x ) {
max_x = contour[i].x();
}
++counter;
}
for ( i = 0; i < hole_polys.contours(); ++i ) {
point_list hole_contour = hole_polys.get_contour( i );
for ( int j = 0; j < (int)hole_contour.size(); ++j ) {
in.pointlist[2*counter] = hole_contour[j].x();
in.pointlist[2*counter + 1] = hole_contour[j].y();
if ( hole_contour[j].x() > max_x ) {
max_x = hole_contour[j].x();
}
++counter;
}
}
in.numberofpointattributes = 1;
in.pointattributelist = (REAL *) malloc(in.numberofpoints *
in.numberofpointattributes *
sizeof(REAL));
counter = 0;
for ( i = 0; i < (int)contour.size(); ++i ) {
in.pointattributelist[counter] = contour[i].z();
++counter;
}
for ( i = 0; i < hole_polys.contours(); ++i ) {
point_list hole_contour = hole_polys.get_contour( i );
for ( int j = 0; j < (int)hole_contour.size(); ++j ) {
in.pointattributelist[counter] = hole_contour[j].z();
++counter;
}
}
// in.pointmarkerlist = (int *) malloc(in.numberofpoints * sizeof(int));
// for ( i = 0; i < in.numberofpoints; ++i) {
// in.pointmarkerlist[i] = 0;
// }
in.pointmarkerlist = NULL;
// segment list
in.numberofsegments = in.numberofpoints;
in.segmentlist = (int *) malloc(in.numberofsegments * 2 * sizeof(int));
in.segmentmarkerlist = (int *) malloc(in.numberofsegments * sizeof(int));
counter = 0;
start = 0;
end = contour.size() - 1;
for ( i = 0; i < end; ++i ) {
in.segmentlist[counter++] = i;
in.segmentlist[counter++] = i + 1;
in.segmentmarkerlist[i] = 0;
}
in.segmentlist[counter++] = end;
in.segmentlist[counter++] = start;
in.segmentmarkerlist[contour.size() - 1] = 0;
for ( i = 0; i < hole_polys.contours(); ++i ) {
point_list hole_contour = hole_polys.get_contour( i );
start = end + 1;
end = start + hole_contour.size() - 1;
for ( int j = 0; j < (int)hole_contour.size() - 1; ++j ) {
in.segmentlist[counter++] = j + start;
in.segmentlist[counter++] = j + start + 1;
}
in.segmentlist[counter++] = end;
in.segmentlist[counter++] = start;
}
for ( i = 0; i < in.numberofsegments; ++i ) {
in.segmentmarkerlist[i] = 0;
}
// hole list
in.numberofholes = hole_pts.size() + 1;
in.holelist = (REAL *) malloc(in.numberofholes * 2 * sizeof(REAL));
// outside of polygon
counter = 0;
in.holelist[counter++] = max_x + 1.0;
in.holelist[counter++] = 0.0;
for ( i = 0; i < (int)hole_pts.size(); ++i ) {
in.holelist[counter++] = hole_pts[i].x();
in.holelist[counter++] = hole_pts[i].y();
}
// region list
in.numberofregions = 0;
in.regionlist = NULL;
// no triangle list
in.numberoftriangles = 0;
in.numberofcorners = 0;
in.numberoftriangleattributes = 0;
in.trianglelist = NULL;
in.triangleattributelist = NULL;
in.trianglearealist = NULL;
in.neighborlist = NULL;
// no edge list
in.numberofedges = 0;
in.edgelist = NULL;
in.edgemarkerlist = NULL;
in.normlist = NULL;
// dump the results to screen
// print_tri_data( &in );
// TEMPORARY
// write_tri_data(&in);
/* cout << "Press return to continue:";
char junk;
cin >> junk; */
// Triangulate the points. Switches are chosen to read and write
// a PSLG (p), number everything from zero (z), and produce an
// edge list (e), and a triangle neighbor list (n).
// no new points on boundary (Y), no internal segment
// splitting (YY), no quality refinement (q)
// Quite (Q)
string tri_options;
tri_options = "pzYYenQ"; // add multiple "V" entries for verbosity
//cout << "Triangulation with options = " << tri_options << endl;
triangulate( (char *)tri_options.c_str(), &in, &out, &vorout );
// TEMPORARY
// write_tri_data(&out);
// now copy the results back into the corresponding TGTriangle
// structures
// triangles
elelist.clear();
int n1, n2, n3;
double attribute;
for ( i = 0; i < out.numberoftriangles; ++i ) {
n1 = out.trianglelist[i * 3];
n2 = out.trianglelist[i * 3 + 1];
n3 = out.trianglelist[i * 3 + 2];
if ( out.numberoftriangleattributes > 0 ) {
attribute = out.triangleattributelist[i];
} else {
attribute = 0.0;
}
// cout << "triangle = " << n1 << " " << n2 << " " << n3 << endl;
elelist.push_back( TGTriEle( n1, n2, n3, attribute ) );
}
// output points
out_pts.clear();
double x, y, z;
for ( i = 0; i < out.numberofpoints; ++i ) {
x = out.pointlist[i * 2 ];
y = out.pointlist[i * 2 + 1];
z = out.pointattributelist[i];
out_pts.push_back( Point3D(x, y, z) );
}
// free mem allocated to the "Triangle" structures
free(in.pointlist);
free(in.pointattributelist);
free(in.pointmarkerlist);
free(in.regionlist);
free(out.pointlist);
free(out.pointattributelist);
free(out.pointmarkerlist);
free(out.trianglelist);
free(out.triangleattributelist);
// free(out.trianglearealist);
free(out.neighborlist);
free(out.segmentlist);
free(out.segmentmarkerlist);
free(out.edgelist);
free(out.edgemarkerlist);
free(vorout.pointlist);
free(vorout.pointattributelist);
free(vorout.edgelist);
free(vorout.normlist);
}
#if 0
// depricated code, also note the method for finding the center point
// of a triangle is depricated and weights the 3 vertices unevenly.
// Find a point inside the polygon without regard for holes
static Point3D point_inside_hole( point_list contour ) {
triele_list elelist; = contour_tesselate( contour );
if ( elelist.size() <= 0 ) {
cout << "Error polygon triangulated to zero triangles!" << endl;
exit(-1);
}
TGTriEle t = elelist[0];
Point3D p1 = contour[ t.get_n1() ];
Point3D p2 = contour[ t.get_n2() ];
Point3D p3 = contour[ t.get_n3() ];
Point3D m1 = ( p1 + p2 ) / 2;
Point3D m2 = ( p1 + p3 ) / 2;
Point3D center = ( m1 + m2 ) / 2;
return center;
}
#endif
// Find a point inside a specific polygon contour taking holes into
// consideration
static Point3D point_inside_contour( TGContourNode *node, const TGPolygon &p ) {
int contour_num;
int i;
TGPolygon hole_polys;
hole_polys.erase();
point_list hole_pts;
hole_pts.clear();
// build list of hole points
// cout << "contour has " << node->get_num_kids() << " kids" << endl;
for ( i = 0; i < node->get_num_kids(); ++i ) {
if ( node->get_kid( i ) != NULL ) {
contour_num = node->get_kid(i)->get_contour_num();
// cout << " child = " << contour_num << endl;
hole_pts.push_back( p.get_point_inside( contour_num ) );
point_list contour = p.get_contour( contour_num );
hole_polys.add_contour( contour, 1 );
}
}
triele_list elelist;
point_list out_pts;
// cout << "before contour tesselate" << endl;
contour_tesselate( node, p, hole_polys, hole_pts, elelist, out_pts );
if ( elelist.size() <= 0 ) {
cout << "Error polygon triangulated to zero triangles!" << endl;
return Point3D( -200, -200, 0 );
// exit(-1);
}
// cout << "after contour tesselate" << endl;
// find the largest triangle in the group
double max_area = 0.0;
int biggest = 0;
for ( i = 0; i < (int)elelist.size(); ++i ) {
TGTriEle t = elelist[i];
Point3D p1 = out_pts[ t.get_n1() ];
Point3D p2 = out_pts[ t.get_n2() ];
Point3D p3 = out_pts[ t.get_n3() ];
double area = triangle_area( p1, p2, p3 );
if ( area > max_area ) {
max_area = area;
biggest = i;
}
}
// find center point of largest triangle
//cout << "biggest = " << biggest + 1 << " out of " << elelist.size() << endl;
TGTriEle t = elelist[biggest];
contour_num = node->get_contour_num();
Point3D p1 = out_pts[ t.get_n1() ];
Point3D p2 = out_pts[ t.get_n2() ];
Point3D p3 = out_pts[ t.get_n3() ];
//cout << "hole tri = " << p1 << endl << " " << p2 << endl << " " << p3 << endl;
// new
Point3D center = ( p1 + p2 + p3 ) / 3;
return center;
}
static void intersect_yline_with_contour( double yline, TGContourNode *node, TGPolygon &p, vector < double > &xcuts ) {
int contour_num = node->get_contour_num();
const point_list& pts=p.get_contour(contour_num);

View file

@ -64,12 +64,6 @@ void polygon_tesselate( const TGPolygon &p,
// will modify the points_inside list for your polygon.
TGPolygon polygon_tesselate_alt( TGPolygon &p );
// calculate some "arbitrary" point inside the specified contour for
// assigning attribute areas. This requires data structures outside
// of "TGPolygon" which is why it is living over here in "Lib/Geometry"
Point3D calc_point_inside_old( const TGPolygon& p, const int contour,
const TGTriNodes& trinodes );
// calculate some "arbitrary" point inside each of the polygons contours
void calc_points_inside( TGPolygon& p );