int FabAtHomePrinter::fillSegmentList(const vector<Point>& points, const int startIndex)
{
	if(points.size() == 0)
	{
		return -1;
	}
	ClearSegList((float)points[startIndex].x, (float)points[startIndex].y, (float)points[startIndex].z);
	for(unsigned int i = startIndex+1; i < points.size(); ++i)
	{
		int res = AddLineSeg((float)points[i].x, (float)points[i].y, (float)points[i].z);
		if(res == -1)
		{
			//points[i-2], points[i-1], and points[i] form two consecutive line segments that are not tangent.
			//Stop at points[i-1].
               return i-1;
		}
		if(res == -2)
		{
			//The segment list is full.
			return i-1;
		}
	}
	//All points have been inserted.
	return points.size()-1;
}
Beispiel #2
0
/* we generate contour maps by sampling the value at various
   latitude and longitude positions:

         lon1  lon3  lon2
    lat1  1-----*-----2
          |           |
    lat3  *           * lat4
          |           |
    lat2  3-----*-----4
              lon4

*/
void IsoBarMap::PlotRegion(std::list<PlotLineSeg*> &region,
                           double lat1, double lon1, double lat2, double lon2)
{
    double p1 = CachedParameter(lat1, lon1);
    double p2 = CachedParameter(lat1, lon2);
    double p3 = CachedParameter(lat2, lon1);
    double p4 = CachedParameter(lat2, lon2);

    if(isnan(p1) || isnan(p2) || isnan(p3) || isnan(p4))
        return;

    double ry1, ry2, ry3, ry4;
    double lon3, lon4, lat3, lat4;
    /* horizontal interpolate to determine intermediate longitudes as well
       as the contours they are on. */
    if(!Interpolate(lon1, lon2, p1, p2, false, lat1, lon3, ry1) ||
            !Interpolate(lon1, lon2, p3, p4, false, lat2, lon4, ry2)) {
        lon3 = (lon1+lon2)/2;
        PlotRegion(region, lat1, lon1, lat2, lon3);
        PlotRegion(region, lat1, lon3, lat2, lon2);
        return;
    }

    /* vertical interpolate */
    if(!Interpolate(lat1, lat2, p1, p3, true, lon1, lat3, ry3) ||
            !Interpolate(lat1, lat2, p2, p4, true, lon2, lat4, ry4)) {
        lat3 = (lat1+lat2)/2;
        PlotRegion(region, lat1, lon1, lat3, lon2);
        PlotRegion(region, lat3, lon1, lat2, lon2);
        return;
    }

    /* un-normalize contours */
    ry1*=m_Spacing, ry2*=m_Spacing, ry3*=m_Spacing, ry4*=m_Spacing;

    /* determine which interpolations need line segments */
    switch(((isnan(lat4)*2 + isnan(lat3))*2 + isnan(lon4))*2 + isnan(lon3)) {
    case 0: /* all 4 sides? need to recurse to get better resolution */
        lon3 = (lon1+lon2)/2;
        lat3 = (lat1+lat2)/2;
        PlotRegion(region, lat1, lon1, lat3, lon3);
        PlotRegion(region, lat1, lon3, lat3, lon2);
        PlotRegion(region, lat3, lon1, lat2, lon3);
        PlotRegion(region, lat3, lon3, lat2, lon2);
        break;
    case 1:
    case 2:
    case 4:
    case 8:
    case 7:
    case 11:
    case 13:
    case 14:
        break; /* impossible! */
    case 3: /* horizontal */
        AddLineSeg(region, lat3, lon1, lat4, lon2, ry3, ry4);
        break;
    case 5: /* diagonal */
        AddLineSeg(region, lat2, lon4, lat4, lon2, ry2, ry4);
        break;
    case 6: /* diagonal */
        AddLineSeg(region, lat1, lon3, lat4, lon2, ry1, ry4);
        break;
    case 9: /* diagonal */
        AddLineSeg(region, lat3, lon1, lat2, lon4, ry2, ry3);
        break;
    case 10:/* diagonal */
        AddLineSeg(region, lat3, lon1, lat1, lon3, ry1, ry3);
        break;
    case 12:/* vertical */
        AddLineSeg(region, lat1, lon3, lat2, lon4, ry1, ry2);
        break;
    case 15: /* no intersections */
        break;
    }
}