Example #1
0
/*------------------------------------------------------------------+
	Take the calculated distances and eliminate those distances
	which are not local maximums, and hence not part of the 
	medial axis.
 +------------------------------------------------------------------*/
void CalcAxis( unsigned char* in, unsigned char* out, int w, int h )
{
	int i, j;
	unsigned char u, b, l, r, c;


	for( i=0; i<h; i++ ){
		for( j=0; j<w; j++ ){
			// get the four corners
			c = in[i*w+j];

			if( c!=0 ){
				u = ( i>0 	? in[(i-1)*w+j] : 0 );
				b = ( i+1<h	? in[(i+1)*w+j] : 0 );
				l = ( j>0	? in[i*w+j-1]   : 0 );
				r = ( j+1<w	? in[i*w+j+1]   : 0 );

				out[i*w+j] = ( ( c<u || c<b || c<l || c<r ) ? 0 : c );

			}// if
		} // for j
	} // for i

/*
	NOTE: as of right now, this does not account for objects of even pixels
	widths.  Hence, the medial axis could be two pixels thick!!
*/
	ThinData( out, w, h );
}
Example #2
0
void AATDistance::AddPoint(double longitude, double latitude,
                           int taskwaypoint) {
  if (taskwaypoint<0) return;

  bool was_entered = has_entered[taskwaypoint];
  has_entered[taskwaypoint] = true;

  if (!AATEnabled || DoOptimizeRoute()) return; // nothing else to do for non-AAT tasks

  LockTaskData();

  // should only add ONE point to start.
  // If restart, need to reset

  if (num_points[taskwaypoint]<MAXNUM_AATDISTANCE) {

    int n = num_points[taskwaypoint];

    bool new_point= false;

    if (n>1) {
      double dist;
      DistanceBearing(lat_points[taskwaypoint][n-2],
                      lon_points[taskwaypoint][n-2],
                      latitude,
                      longitude, &dist, NULL);
      if (dist>distancethreshold[taskwaypoint]) {
        new_point = true;
      }
    } else {
      // first point in sector
      new_point = true;

      if ((!was_entered) && (taskwaypoint>0) &&
          !Task[taskwaypoint].AATTargetLocked) {
        double qdist, bearing0, bearing1;
        DistanceBearing(Task[taskwaypoint-1].AATTargetLat,
                        Task[taskwaypoint-1].AATTargetLon,
                        latitude,
                        longitude,
                        &qdist, &bearing0);
        DistanceBearing(Task[taskwaypoint-1].AATTargetLat,
                        Task[taskwaypoint-1].AATTargetLon,
                        Task[taskwaypoint].AATTargetLat,
                        Task[taskwaypoint].AATTargetLon,
                        &qdist, &bearing1);
        // JMWAAT
        Task[taskwaypoint].AATTargetOffsetRadial = 0.0;
        // 20080615 JMW
	// was AngleLimit180(bearing1-bearing0);
	// now project along track line
	// target will be moved by ShiftTargetFromBehind
      }

    }
    if (taskwaypoint==0) {
      // force updating of start point
      new_point = true;
    }

    if (new_point) {
      if (taskwaypoint>0) {
        num_points[taskwaypoint]++;
        if (num_points[taskwaypoint]==MAXNUM_AATDISTANCE) {
          ThinData(taskwaypoint);
        }
      } else {
        // just replace current start
        num_points[taskwaypoint]= 1;
      }
    }

    // always replace last point
    lat_points[taskwaypoint][max(0,num_points[taskwaypoint]-1)]= latitude;
    lon_points[taskwaypoint][max(0,num_points[taskwaypoint]-1)]= longitude;

    // update max search for this and future waypoints
    if (taskwaypoint>0) {
      for (int i= taskwaypoint; i<MAXTASKPOINTS-1; i++) {
        UpdateSearch(i);
      }
      if (taskwaypoint == ActiveTaskPoint) {
        DistanceCovered_internal(longitude, latitude, true);
      }
    }
  }
  UnlockTaskData();

}