Exemple #1
0
/*
 * Checks whether a coordinate is valid for processing.
 * Coordinates are valid iff their x and y coordinates are in the
 * range of the floating point representation.
 *
 * @param coord the coordinate to validate
 * @return <code>true</code> if the coordinate is valid
 */
bool
IsValidOp::isValid(const Coordinate &coord)
{
	if (! FINITE(coord.x) ) return false;
	if (! FINITE(coord.y) ) return false;
	return true;
}
/* Extract a jet from an image at a paticular location */
GaborJet extractJet(GFTYPE x, GFTYPE y, Image im, JetMasks masks){
    GaborJet jet = NULL;
    if( masks->size ){
        /* This algrithm aproximates the gabor parameters at a location in continuous space
        By computing the gabor convoluation at an integer location close to the contiuous
        point and then shifting the phase parameters the apropreate amount. It is much faster
        then using linear interpolation and it is probably more accurate. */
        int i;
        float rx = ROUND(x);
        float ry = ROUND(y);
        float dx = x - rx;
        float dy = y - ry;
        jet = makeGaborJet(masks->size/2);

        /* Add a pointer to the mask parameters for future use */
        jet->params = masks->params;


        /* Compute the jet coeffecents */
        for( i = 0; i < jet->length; i++){
            jet->realPart[i] = convolvePoint(rx, ry, 0, im, masks->masks[2*i]);
            jet->imagPart[i] = convolvePoint(rx, ry, 0, im, masks->masks[2*i+1]);
            FINITE(jet->realPart[i]);
            FINITE(jet->imagPart[i]);
        }
        computePolar(jet);

        /* Adjust phase coordinates */
        for( i = 0; i < jet->length; i++){
            jet->ang[i] +=  dx * jet->params->kx[2*i] + dy * jet->params->ky[2*i];
        }

        /* Recompute coeffecents based on phase change */
        for( i = 0; i < jet->length; i++){
            jet->realPart[i] = jet->mag[i] * cos(jet->ang[i]);
            jet->imagPart[i] = jet->mag[i] * sin(jet->ang[i]);
        }
    }
    else{
        jet = makeGaborJet(0);
    }

    /* Save the jet location */
    jet->x = x;
    jet->y = y;

    return jet;
}
static void upd (double &a, double &b, double &c, double &d, double &e, double &f, double &g, double &h, double &i, const double cp, const float spread) {
    //  assert (a==b&&b==c&&c==d&&d==e&&e==f);
    if (a!=b||a!=c||a!=d||a!=e||a!=f||!FINITE (a)) {
        a=b=c=d=e=f=0;
    }
    while (a-cp > 1.5*spread) {
        a-=3*spread;
        b-=3*spread;
        c-=3*spread;
        d-=3*spread;
        e-=3*spread;
        f-=3*spread;
        g-=3*spread;
        h-=3*spread;
        i-=3*spread;
    }
    while (a-cp < -1.5*spread) {
        a+=3*spread;
        b+=3*spread;
        c+=3*spread;
        d+=3*spread;
        e+=3*spread;
        f+=3*spread;
        g+=3*spread;
        h+=3*spread;
        i+=3*spread;
    }
}
Exemple #4
0
/*public*/
double
HCoordinate::getY() const
{
	double a = y/w;
	if ( !FINITE(a) ) {
		throw  NotRepresentableException();
	}
	return a;
}
Exemple #5
0
/**
* Read a binary image from a file where the pixels are stored as 32 bit
* floating point numbers using Sun byte order.  The compiler directive WINDOWS
* is used to control how the byte order is interpreted when storing the pixels
* into the data structure images. Images are a one dimensional array of floats
* that contains each successive image in sequence, where each image has in turn
* been unrolled into a 1 dimensional vector.
*
* @param fname The name of the file from which to read the image.
* @param n The index of this image in the images array.
* @param images The matrix into the image is read. Only the nth column is affected.
*/
void readFile(const char *fname, int n, Matrix images) {
    int i;
    FILE *f;

    char nan_error[100];
    char inf_error[100];
    char line[FILE_LINE_LENGTH];
    char imagetype[FILE_LINE_LENGTH];

    if (debuglevel > 1)
        printf("\nReading file: %s\n", fname);

    /* Check to makesure file is of expected size */
    if (images->row_dim != autoFileLength(fname)) {
        DEBUG_CHECK(autoFileLength(fname) < images->row_dim, "File does not contian enough values");
        printf("Warning: file length is greater than vector length.  Croping file...\n");
    }

    f = fopen( fname, "rb" );
    if ( !f ) { printf("Can't open %s\n", fname); exit(1); }

    /* check to see if image is of type RASTER_ID */
    fgets(line,FILE_LINE_LENGTH,f); /* only read in enough to determine
                                    * if the file is of proper type */
    sscanf(line,"%s",imagetype);
    if(strcmp(imagetype,RASTER_ID) == 0 || strcmp(imagetype,"CSU_RASTER") ==0){
        rewind(f);
        /* read in the first line to move the buffer to the data. */
        fgets(imagetype,FILE_LINE_LENGTH,f);
    }
    else{
        /* There is no header info. Just read the data */
        rewind(f);
    }

    /* Set up error messages for use later */
    sprintf(nan_error, "Not A Number value in file: %s", fname);
    sprintf(inf_error, "Infinite value in file: %s", fname);

    for (i = 0;i < images->row_dim;i++) {
        float flt;
        /* read in the correct byte order for floating point values */
        readFloat(f, &flt);

#ifdef CHECK_VALS
        /* Check values to make sure they are real */
        FINITE(flt);
#endif
        /* Save value to images */
        ME(images, i, n) = (double)flt;
    }
    fclose(f);
}
Exemple #6
0
/*public static*/
void
HCoordinate::intersection(const Coordinate &p1, const Coordinate &p2,
	const Coordinate &q1, const Coordinate &q2, Coordinate &ret)
{

#if GEOS_DEBUG
	cerr << __FUNCTION__ << ":" << endl
	     << setprecision(20)
	     << " p1: " << p1 << endl
	     << " p2: " << p2 << endl
	     << " q1: " << q1 << endl
	     << " q2: " << q2 << endl;
#endif

	// unrolled computation

	double px = p1.y - p2.y;
	double py = p2.x - p1.x;
	double pw = p1.x * p2.y - p2.x * p1.y;

	double qx = q1.y - q2.y;
	double qy = q2.x - q1.x;
	double qw = q1.x * q2.y - q2.x * q1.y;

	double x = py * qw - qy * pw;
	double y = qx * pw - px * qw;
	double w = px * qy - qx * py;

	double xInt = x/w;
	double yInt = y/w;

	if ( (!FINITE(xInt)) || (!FINITE(yInt)) )
	{
		throw NotRepresentableException();
	}

	ret = Coordinate(xInt, yInt);
}
int R_finite(double x)
{
#ifdef HAVE_WORKING_ISFINITE
    return isfinite(x);
#elif HAVE_WORKING_FINITE
    return finite(x);
#else
/* neither finite nor isfinite work. Do we really need the AIX exception? */
# ifdef _AIX
#  include <fp.h>
     return FINITE(x);
# elif defined(_MSC_VER)
     return _finite(x);
#else
    return (!isnan(x) & (x != 1/0.0) & (x != -1.0/0.0));
# endif
#endif
}
Exemple #8
0
int igraph_finite(double x)
{
#ifdef isfinite 
    return isfinite(x);
#elif HAVE_ISFINITE == 1
    return isfinite(x);
#elif HAVE_FINITE == 1
    return finite(x);
#else
/* neither finite nor isfinite work. Do we really need the AIX exception? */
# ifdef _AIX
#  include <fp.h>
     return FINITE(x);
# else
    return (!isnan(x) & (x != IGRAPH_POSINFINITY) & (x != IGRAPH_NEGINFINITY));
# endif
#endif
}
int RobustDeterminant::signOfDet2x2(double x1,double y1,double x2,double y2) {
	// returns -1 if the determinant is negative,
	// returns  1 if the determinant is positive,
	// retunrs  0 if the determinant is null.
	int sign=1;
	double swap;
	double k;

  // Protect against non-finite numbers
  if ( !FINITE(x1) || !FINITE(y1) || !FINITE(x2) || !FINITE(y2) )
  {
    throw util::IllegalArgumentException("RobustDeterminant encountered non-finite numbers ");
  }

	/*
	*  testing null entries
	*/
	if ((x1==0.0) || (y2==0.0)) {
		if ((y1==0.0) || (x2==0.0)) {
			return 0;
		} else if (y1>0) {
			if (x2>0) {
				return -sign;
			} else {
				return sign;
			}
		} else {
			if (x2>0) {
				return sign;
			} else {
				return -sign;
			}
		}
	}
	if ((y1==0.0) || (x2==0.0)) {
		if (y2>0) {
			if (x1>0) {
				return sign;
			} else {
				return -sign;
			}
		} else {
			if (x1>0) {
				return -sign;
			} else {
				return sign;
			}
		}
	}

	/*
	*  making y coordinates positive and permuting the entries
	*  so that y2 is the biggest one
	*/
	if (0.0<y1) {
		if (0.0<y2) {
			if (y1<=y2) {
				;
			} else {
				sign=-sign;
				swap=x1;
				x1=x2;
				x2=swap;
				swap=y1;
				y1=y2;
				y2=swap;
			}
		} else {
			if (y1<=-y2) {
				sign=-sign;
				x2=-x2;
				y2=-y2;
			} else {
				swap=x1;
				x1=-x2;
				x2=swap;
				swap=y1;
				y1=-y2;
				y2=swap;
			}
		}
	} else {
		if (0.0<y2) {
			if (-y1<=y2) {
				sign=-sign;
				x1=-x1;
				y1=-y1;
			} else {
				swap=-x1;
				x1=x2;
				x2=swap;
				swap=-y1;
				y1=y2;
				y2=swap;
			}
		} else {
			if (y1>=y2) {
				x1=-x1;
				y1=-y1;
				x2=-x2;
				y2=-y2;
			} else {
				sign=-sign;
				swap=-x1;
				x1=-x2;
				x2=swap;
				swap=-y1;
				y1=-y2;
				y2=swap;
			}
		}
	}

	/*
	*  making x coordinates positive
	*/
	/*
	*  if |x2|<|x1| one can conclude
	*/
	if (0.0<x1) {
		if (0.0<x2) {
			if (x1 <= x2) {
				;
			} else {
				return sign;
			}
		} else {
			return sign;
		}
	} else {
		if (0.0<x2) {
			return -sign;
		} else {
			if (x1 >= x2) {
				sign=-sign;
				x1=-x1;
				x2=-x2;
			} else {
				return -sign;
			}
		}
	}

	/*
	*  all entries strictly positive   x1 <= x2 and y1 <= y2
	*/
	while (true) {
		k=std::floor(x2/x1);
		x2=x2-k*x1;
		y2=y2-k*y1;

		/*
		*  testing if R (new U2) is in U1 rectangle
		*/
		if (y2<0.0) {
			return -sign;
		}
		if (y2>y1) {
			return sign;
		}

		/*
		*  finding R'
		*/
		if (x1>x2+x2) {
			if (y1<y2+y2) {
				return sign;
			}
		} else {
			if (y1>y2+y2) {
				return -sign;
			} else {
				x2=x1-x2;
				y2=y1-y2;
				sign=-sign;
			}
		}
		if (y2==0.0) {
			if (x2==0.0) {
				return 0;
			} else {
				return -sign;
			}
		}
		if (x2==0.0) {
			return sign;
		}

		/*
		*  exchange 1 and 2 role.
		*/
		k=std::floor(x1/x2);
		x1=x1-k*x2;
		y1=y1-k*y2;

		/*
		*  testing if R (new U1) is in U2 rectangle
		*/
		if (y1<0.0) {
			return sign;
		}
		if (y1>y2) {
			return -sign;
		}

		/*
		*  finding R'
		*/
		if (x2>x1+x1) {
			if (y2<y1+y1) {
				return -sign;
			}
		} else {
			if (y2>y1+y1) {
				return sign;
			} else {
				x1=x2-x1;
				y1=y2-y1;
				sign=-sign;
			}
		}
		if (y1==0.0) {
			if (x1==0.0) {
				return 0;
			} else {
				return sign;
			}
		}
		if (x1==0.0) {
			return -sign;
		}
	}
}
Exemple #10
0
*/  static void Check_Overflow(REBDEC dval)
/*
***********************************************************************/
{
    if (!FINITE(dval)) raise Error_0(RE_OVERFLOW);
}
Exemple #11
0
*/  static void Check_Overflow(REBDEC dval)
/*
***********************************************************************/
{
	if (!FINITE(dval)) Trap(RE_OVERFLOW);
}
Exemple #12
0
/**
 * Compute bounding box/tile intersections.
 * \param  winInfo - which window/mural
 * \param  bucketInfo - results of intersection tests
 * \todo XXX someday break this function into a bunch of subroutines, one for
 * each bucketing mode.
 */
static void
doBucket( const WindowInfo *winInfo, TileSortBucketInfo *bucketInfo )
{
	static const CRrecti fullscreen = {-CR_MAXINT, CR_MAXINT, -CR_MAXINT, CR_MAXINT};
	static const CRrecti nullscreen = {0, 0, 0, 0};
	GET_CONTEXT(g);

	/* the bounds should be valid at this point */
	/*CRASSERT(bucketInfo->objectMin.x != FLT_MAX);*/

	/* Init bucketInfo results */
	bucketInfo->pixelBounds = nullscreen;
	/* Initialize the results/hits bitvector.  Each bit represents a server.
	 * If the bit is set, send the geometry to that server.  There are 32
	 * bits per word in the vector.
	 */
	{
		int j;
		for (j = 0; j < CR_MAX_BITARRAY; j++)
			bucketInfo->hits[j] = 0;
	}

	/* We might be broadcasting, *or* we might be defining a display list,
	 * which goes to everyone (currently).
	 */
	if (winInfo->bucketMode == BROADCAST || g->lists.currentIndex) {
		bucketInfo->pixelBounds = fullscreen;
		FILLDIRTY(bucketInfo->hits);
		return;
	}

	/* Check for infinite bounding box values.  If so, broadcast.
	 * This can happen when glVertex4f() is called with w=0.  This
	 * is done in the NVIDIA infinite_shadow_volume demo.
	 */
	if (!FINITE(bucketInfo->objectMin.x) || !FINITE(bucketInfo->objectMax.x)) {
		bucketInfo->pixelBounds = fullscreen;
		FILLDIRTY(bucketInfo->hits);
		return;
	}

	/* When using vertex programs, vertices may get warped/displaced.
	 * This is a way to grow the bounding box a little if needed.
	 */
	if (tilesort_spu.bboxScale != 1.0) {
		GLfloat scale = tilesort_spu.bboxScale;
		/* compute center point of box */
		GLfloat cx = 0.5f * (bucketInfo->objectMin.x + bucketInfo->objectMax.x);
		GLfloat cy = 0.5f * (bucketInfo->objectMin.y + bucketInfo->objectMax.y);
		GLfloat cz = 0.5f * (bucketInfo->objectMin.z + bucketInfo->objectMax.z);
		/* scale bounds relative to center point */
		bucketInfo->objectMin.x = cx + (bucketInfo->objectMin.x - cx) * scale;
		bucketInfo->objectMin.y = cy + (bucketInfo->objectMin.y - cy) * scale;
		bucketInfo->objectMin.z = cz + (bucketInfo->objectMin.z - cz) * scale;
		bucketInfo->objectMax.x = cx + (bucketInfo->objectMax.x - cx) * scale;
		bucketInfo->objectMax.y = cy + (bucketInfo->objectMax.y - cy) * scale;
		bucketInfo->objectMax.z = cz + (bucketInfo->objectMax.z - cz) * scale;
	}

	/*
	 * OK, now do bucketing
	 */
	if (winInfo->bucketMode == TEST_ALL_TILES)
	{
		float xmin, ymin, xmax, ymax, zmin, zmax;
		CRrecti ibounds;
		int i, j;

		if (!TransformBBox(winInfo, 0,
								 /* in */ &bucketInfo->objectMin, &bucketInfo->objectMax,
								 /* out */ &xmin, &ymin, &zmin, &xmax, &ymax, &zmax, &ibounds))
			return; /* not visible, all done */

		/* Explicitly test the bounding box (ibounds) against all tiles on
		 * all servers.
		 */
		for (i=0; i < tilesort_spu.num_servers; i++) 
		{
			const ServerWindowInfo *servWinInfo = winInfo->server + i;
			/* only bother if the stereo left/right flags agree */
			if (servWinInfo->eyeFlags & thread->currentContext->stereoDestFlags) {
				/* 32 bits (flags) per element in hits[] */
				const int node32 = i >> 5;
				const int node = i & 0x1f;

				if (winInfo->matrixSource == MATRIX_SOURCE_SERVERS) {
					/* recompute bounds */
					TransformBBox(winInfo, i,
												&bucketInfo->objectMin,	&bucketInfo->objectMax, /*in*/
												&xmin, &ymin, &zmin, &xmax, &ymax, &ymin, &ibounds);
				}

				bucketInfo->pixelBounds = ibounds;

				for (j = 0; j < servWinInfo->num_extents; j++) 
				{
					if (ibounds.x1 < servWinInfo->extents[j].x2 && 
							ibounds.x2 >= servWinInfo->extents[j].x1 &&
							ibounds.y1 < servWinInfo->extents[j].y2 &&
							ibounds.y2 >= servWinInfo->extents[j].y1) 
					{
						bucketInfo->hits[node32] |= (1 << node);
						break;
					}
				}
			}
		}
		/* all done */
	} 
/*
 * This function wants to be passed the inverse transformation matrix!!
 */
void
gimp_transform_resize_boundary (const GimpMatrix3   *inv,
                                GimpTransformResize  resize,
                                gint                 u1,
                                gint                 v1,
                                gint                 u2,
                                gint                 v2,
                                gint                *x1,
                                gint                *y1,
                                gint                *x2,
                                gint                *y2)
{
  gdouble dx1, dx2, dx3, dx4;
  gdouble dy1, dy2, dy3, dy4;

  g_return_if_fail (inv != NULL);

  /*  initialize with the original boundary  */
  *x1 = u1;
  *y1 = v1;
  *x2 = u2;
  *y2 = v2;

  /* if clipping then just return the original rectangle */
  if (resize == GIMP_TRANSFORM_RESIZE_CLIP)
    return;

  gimp_matrix3_transform_point (inv, u1, v1, &dx1, &dy1);
  gimp_matrix3_transform_point (inv, u2, v1, &dx2, &dy2);
  gimp_matrix3_transform_point (inv, u1, v2, &dx3, &dy3);
  gimp_matrix3_transform_point (inv, u2, v2, &dx4, &dy4);

  /*  check if the transformation matrix is valid at all  */
  if (! FINITE (dx1) || ! FINITE (dy1) ||
      ! FINITE (dx2) || ! FINITE (dy2) ||
      ! FINITE (dx3) || ! FINITE (dy3) ||
      ! FINITE (dx4) || ! FINITE (dy4))
    {
      g_warning ("invalid transform matrix");
      /* since there is no sensible way to deal with this, just do the same as
       * with GIMP_TRANSFORM_RESIZE_CLIP: return
       */
      return;
    }

  switch (resize)
    {
    case GIMP_TRANSFORM_RESIZE_ADJUST:
      /* return smallest rectangle (with sides parallel to x- and y-axis)
       * that surrounds the new points */
      gimp_transform_resize_adjust (dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4,
                                    x1, y1, x2, y2);
      break;

    case GIMP_TRANSFORM_RESIZE_CROP:
      gimp_transform_resize_crop (dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4,
                                  0.0,
                                  x1, y1, x2, y2);
      break;

    case GIMP_TRANSFORM_RESIZE_CROP_WITH_ASPECT:
      gimp_transform_resize_crop (dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4,
                                  ((gdouble) u2 - u1) / (v2 - v1),
                                  x1, y1, x2, y2);
      break;

    case GIMP_TRANSFORM_RESIZE_CLIP:
      /* Remove warning about not handling all enum values. We handle
       * this case in the beginning of the function
       */
      break;
    }

  /* ensure that resulting rectangle has at least area 1 */
  if (*x1 == *x2)
    (*x2)++;

  if (*y1 == *y2)
    (*y2)++;
}
Exemple #14
0
		bool Vec2::valid() const
		{
			return FINITE(v[0])&FINITE(v[1]);
		}
Exemple #15
0
//
//  MAKE_Decimal: C
//
void MAKE_Decimal(REBVAL *out, enum Reb_Kind kind, const REBVAL *arg) {
    REBDEC d;

    switch (VAL_TYPE(arg)) {
    case REB_DECIMAL:
        d = VAL_DECIMAL(arg);
        goto dont_divide_if_percent;

    case REB_PERCENT:
        d = VAL_DECIMAL(arg);
        goto dont_divide_if_percent;

    case REB_INTEGER:
        d = cast(REBDEC, VAL_INT64(arg));
        goto dont_divide_if_percent;

    case REB_MONEY:
        d = deci_to_decimal(VAL_MONEY_AMOUNT(arg));
        goto dont_divide_if_percent;

    case REB_LOGIC:
        d = VAL_LOGIC(arg) ? 1.0 : 0.0;
        goto dont_divide_if_percent;

    case REB_CHAR:
        d = cast(REBDEC, VAL_CHAR(arg));
        goto dont_divide_if_percent;

    case REB_TIME:
        d = VAL_TIME(arg) * NANO;
        break;

    case REB_STRING:
        {
        REBYTE *bp;
        REBCNT len;
        bp = Temp_Byte_Chars_May_Fail(arg, MAX_SCAN_DECIMAL, &len, FALSE);

        VAL_RESET_HEADER(out, kind);
        if (!Scan_Decimal(
            &d, bp, len, LOGICAL(kind != REB_PERCENT)
        )) {
            goto bad_make;
        }
        break;
        }

    case REB_BINARY:
        Binary_To_Decimal(arg, out);
        VAL_RESET_HEADER(out, kind);
        d = VAL_DECIMAL(out);
        break;

#ifdef removed
//          case REB_ISSUE:
    {
        REBYTE *bp;
        REBCNT len;
        bp = Temp_Byte_Chars_May_Fail(arg, MAX_HEX_LEN, &len, FALSE);
        if (Scan_Hex(&VAL_INT64(out), bp, len, len) == 0)
            fail (Error_Bad_Make(REB_DECIMAL, val));
        d = VAL_DECIMAL(out);
        break;
    }
#endif

    default:
        if (ANY_ARRAY(arg) && VAL_ARRAY_LEN_AT(arg) == 2) {
            RELVAL *item = VAL_ARRAY_AT(arg);
            if (IS_INTEGER(item))
                d = cast(REBDEC, VAL_INT64(item));
            else if (IS_DECIMAL(item) || IS_PERCENT(item))
                d = VAL_DECIMAL(item);
            else {
                REBVAL specific;
                COPY_VALUE(&specific, item, VAL_SPECIFIER(arg));

                fail (Error_Invalid_Arg(&specific));
            }

            ++item;

            REBDEC exp;
            if (IS_INTEGER(item))
                exp = cast(REBDEC, VAL_INT64(item));
            else if (IS_DECIMAL(item) || IS_PERCENT(item))
                exp = VAL_DECIMAL(item);
            else {
                REBVAL specific;
                COPY_VALUE(&specific, item, VAL_SPECIFIER(arg));
                fail (Error_Invalid_Arg(&specific));
            }

            while (exp >= 1) {
                //
                // !!! Comment here said "funky. There must be a better way"
                //
                --exp;
                d *= 10.0;
                if (!FINITE(d))
                    fail (Error(RE_OVERFLOW));
            }

            while (exp <= -1) {
                ++exp;
                d /= 10.0;
            }
        }
        else
            fail (Error_Bad_Make(kind, arg));
    }

    if (kind == REB_PERCENT)
        d /= 100.0;

dont_divide_if_percent:
    if (!FINITE(d))
        fail (Error(RE_OVERFLOW));

    VAL_RESET_HEADER(out, kind);
    VAL_DECIMAL(out) = d;
    return;

bad_make:
    fail (Error_Bad_Make(kind, arg));
}