Beispiel #1
0
NUM find_scout_planet( AS_INF *info )
{
 COUNT i;
 register AS_INF *pt;
 NUM pl, mi;
 register MINU sun;

 pl = 0, mi = 0;
 sun = (info+SUN)->minutes_total;
 for ( i = MOON, pt = info + MOON; i <= maxplan; ++i, ++pt ) {
     if ( pt->minutes_total < sun && pt->minutes_total > mi ) {
	pl = i;
	mi = pt->minutes_total;
        }
     }
 if ( pl == 0 ) {   /* this takes care of situations where the sun is
		       in a low degree and nothing preceeds it. */
    mi = sun;
    sun += d2m(360);
    for ( i = MOON, pt = info + MOON; i <= PLUTO; ++i, ++pt ) {
	if ( pt->minutes_total > mi ) {
	   pl = i;
	   mi = pt->minutes_total;
	   }
	}
    }
 return( pl );
}
Beispiel #2
0
// descriptor matching
inline void BriskInterface::radiusMatch( int nlhs, mxArray *plhs[], 
            int nrhs, const mxArray *prhs[] ){
    // insure correct arguments
    if(nrhs<3)
        mexErrMsgTxt("Two descriptors must be passed.");
    if(nlhs!=1)
        mexErrMsgTxt("Specify one output argument.");
    if(mxGetClassID(prhs[1])!=mxUINT8_CLASS || 
            mxGetClassID(prhs[2])!=mxUINT8_CLASS)
        mexErrMsgTxt("Wrong descriptor type.");

    // get the two input descriptors
    mxArray *d1, *d2;
    mexCallMATLAB(1, &d1, 1, (mxArray**)&prhs[1], "transpose");
    mexCallMATLAB(1, &d2, 1, (mxArray**)&prhs[2], "transpose");
    // cast to cv::Mat
    const int N1 = mxGetN(d1);
    const int N2 = mxGetN(d2);
    const int M = mxGetM(d1);
    if(M!=mxGetM(d2))
        mexErrMsgTxt("Incompatible descriptors (wrong no. bytes).");
    uchar* data1 = (uchar*)mxGetData(d1);
    uchar* data2 = (uchar*)mxGetData(d2);
    cv::Mat d1m(N1,M,CV_8U,data1);
    cv::Mat d2m(N2,M,CV_8U,data2);

    // get the radius, if provided
    int k=90;
    if(nrhs>3){
        if(!mxIsScalarNonComplexDouble(prhs[3]))
            mexErrMsgTxt("Wrong type for radius.");
        double* kd=mxGetPr(prhs[3]);
        if (*kd<0.0) *kd=0.0;
        k=int(*kd);
    }

    // perform the match
    std::vector<std::vector<cv::DMatch> > matches;
    p_matcher->radiusMatch(d1m,d2m,matches,k);

    // assign the output - first determine the matrix size
    const unsigned int msize=matches.size();
    unsigned int maxMatches=0;
    for(int m=0; m<msize; m++){
        const unsigned int size=matches[m].size();
        if(size>maxMatches) maxMatches=size;
    }

    // allocate memory
    plhs[0]=mxCreateDoubleMatrix(msize,maxMatches,mxREAL);
    double *data=mxGetPr(plhs[0]);

    // fill
    for(int m=0; m<msize; m++){
        const unsigned int size=matches[m].size();
        for(int s=0; s<size; s++){
            data[m+s*msize]=matches[m][s].trainIdx+1;
        }
    }
}
Beispiel #3
0
void uiDrawMatrixTranslate(uiDrawMatrix *m, double x, double y)
{
    D2D1_MATRIX_3X2_F dm;

    m2d(m, &dm);
    dm = dm * D2D1::Matrix3x2F::Translation(x, y);
    d2m(&dm, m);
}
Beispiel #4
0
/* Compute the fisher information matrix
	each element is the 2nd derivative of the log-likelihood evaluated at convergence
	element i,j = ( d^2/(dpi*dpj)[ln(f(x,p))] ) | p_f
*/
void fisher (int numparams, double *p, struct kslice *ks, double *A)
{
	int ii, ij, inu, itht;
	double corr1, corr2, mod, datapt;
	double *d1, **d2;


	d1 = calloc(numparams,sizeof(double));
	d2 = malloc(numparams*sizeof(double*));
	for (ii=0; ii<numparams; ii++)
		d2[ii] = calloc(numparams,sizeof(double));

	/* clear matrix in perperation of incremental sums */
	for (ii=0; ii<numparams*numparams; ii++)
		A[ii] = 0.0;

	/* loop over data, summing ML and matrix elements */
	for (inu=ks->start; inu<=ks->end; inu++)
	{
		for (itht=0; itht<ks->ntheta; itht++)
		{
			datapt = ks->data[inu-ks->start][itht];
			/* compute things for a single pixel */
			mod = model(p, ks, inu, itht);
			corr1 = (1.0 - datapt/mod)/mod;
			corr2 = (2.0*datapt/mod - 1.0)/(mod*mod);
			
			/* call to find all first derivatives */
			dm(p, ks, inu, itht, d1);
			d2m(p, ks, inu, itht, d2);
			
			/* matrix element is d2m/didj*corr1 + dm/di*dm/dj*corr2 */
			for (ii=0; ii<numparams; ii++)
			{
				for (ij=0; ij<numparams; ij++)
				{
					/* add contribution to matrix element ii,ij */
					A[ii*numparams+ij] += d2[ii][ij]*corr1 + d1[ii]*d1[ij]*corr2;
				}
			}
		}
	}

	for (ii=0; ii<numparams; ii++)
	{
		for (ij=0; ij<numparams; ij++)
		{
			/* load data */
/*			if (A[ii*numparams+ij] != A[ij*numparams+ii])
				printf("problem at %d %d\n", ii, ij);
*/			/*A[ij*numparams+ii] = A[ij*numparams+ii];*/
		}
	}
	free(d1);
	for (ii=0; ii<numparams; ii++)
		free(d2[ii]);
	free(d2);
}
Beispiel #5
0
void uiDrawMatrixMultiply(uiDrawMatrix *dest, uiDrawMatrix *src)
{
    D2D1_MATRIX_3X2_F c, d;

    m2d(dest, &c);
    m2d(src, &d);
    c = c * d;
    d2m(&c, dest);
}
Beispiel #6
0
double div_2_rads( double numerator, double divisor )
{
 double res, atres;

 if ( divisor != 0.0 )
    res = numerator / divisor;
 else if ( numerator > 0.0 )
    return( d2m(90) );
 else if ( numerator < 0.0 )
    return( d2m(270) );
 else 
    return( 0 );
 atres = atan( res );
 if ( divisor < 0.0 )
    atres += PI;
 else if ( numerator < 0.0 )
    atres += 2.0 * PI;
 return( atres );
}
Beispiel #7
0
int uiDrawMatrixInvert(uiDrawMatrix *m)
{
    D2D1_MATRIX_3X2_F d;

    m2d(m, &d);
    if (D2D1InvertMatrix(&d) == FALSE)
        return 0;
    d2m(&d, m);
    return 1;
}
Beispiel #8
0
void uiDrawMatrixSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount)
{
    D2D1_MATRIX_3X2_F dm;
    D2D1_POINT_2F center;

    m2d(m, &dm);
    center.x = x;
    center.y = y;
    dm = dm * D2D1::Matrix3x2F::Skew(r2d(xamount), r2d(yamount), center);
    d2m(&dm, m);
}
Beispiel #9
0
void uiDrawMatrixRotate(uiDrawMatrix *m, double x, double y, double amount)
{
    D2D1_MATRIX_3X2_F dm;
    D2D1_POINT_2F center;

    m2d(m, &dm);
    center.x = x;
    center.y = y;
    dm = dm * D2D1::Matrix3x2F::Rotation(r2d(amount), center);
    d2m(&dm, m);
}
Beispiel #10
0
void uiDrawMatrixScale(uiDrawMatrix *m, double xCenter, double yCenter, double x, double y)
{
    D2D1_MATRIX_3X2_F dm;
    D2D1_POINT_2F center;

    m2d(m, &dm);
    center.x = xCenter;
    center.y = yCenter;
    dm = dm * D2D1::Matrix3x2F::Scale(x, y, center);
    d2m(&dm, m);
}
Beispiel #11
0
void uiDrawMatrixRotate(uiDrawMatrix *m, double x, double y, double amount)
{
	D2D1_POINT_2F center;
	D2D1_MATRIX_3X2_F dm;
	uiDrawMatrix rm;

	amount *= 180 / M_PI;		// must be in degrees
	center.x = x;
	center.y = y;
	D2D1MakeRotateMatrix(amount, center, &dm);
	d2m(&dm, &rm);
	uiDrawMatrixMultiply(m, &rm);
}
Beispiel #12
0
void uiDrawMatrixSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount)
{
	D2D1_POINT_2F center;
	D2D1_MATRIX_3X2_F dm;
	uiDrawMatrix sm;

	xamount *= 180 / M_PI;		// must be in degrees
	yamount *= 180 / M_PI;		// must be in degrees
	center.x = x;
	center.y = y;
	D2D1MakeSkewMatrix(xamount, yamount, center, &dm);
	d2m(&dm, &sm);
	uiDrawMatrixMultiply(m, &sm);
}
Beispiel #13
0
MINU comp_med_coeli( TIM *tp )
{
 DEGR degs, m;
 MINU mins, mc, secs;
 double x;

 sidereal_2_angular( tp, &degs, &mins, &secs );  /* convert sidereal time to angular */
 right_asc_mh = degrees_2_rads( degs, mins ); /* change to radians */
 x = (((double) secs)/60.0)/60;
 x *= ( PI / 180.0 );
 right_asc_mh += x;
 if ( right_asc_mh > ( PI + PI ) )
    right_asc_mh -= ( PI + PI );
 mc = div_2_minutes( _tan( right_asc_mh ), cos_obliquity );
 med_coeli = div_2_rads( _tan( right_asc_mh ), cos_obliquity );
 m = abs( (mc / 60) - degs );
 if ( m > 150 && m < 210 ) {
    mc += d2m(180);
    med_coeli += PI;
    }
 mc %= d2m(360);
 med_coeli = fmodulus(med_coeli,TWO_PI);
 return( mc );
}
Beispiel #14
0
MINU calc_ascendant( DEG_MIN *lat )
{
 double temp, temp2, temp3;

 latitude = degrees_2_rads( lat->degrees, lat->minutes ); 
 tan_latitude = _tan(latitude);
 temp = _cos( right_asc_mh );
 temp2 = ( sin_obliquity * tan_latitude );
 temp3 = ( cos_obliquity * _sin( right_asc_mh ) );
 temp2 += temp3;
 if ( temp2 == 0.0 && temp3 == 0.0 )
    asc_rads = PI/2.0;
 else
    asc_rads= div_2_rads( temp, -temp2 );
 if ( temp2 == 0.0 && temp3 == 0.0 )
    return( d2m(90) );
 else
    return( div_2_minutes( temp, -temp2 ) );
}
Beispiel #15
0
void uiDrawTransform(uiDrawContext *c, uiDrawMatrix *m)
{
	D2D1_MATRIX_3X2_F dm;
	uiDrawMatrix already;
	uiDrawMatrix temp;

	ID2D1RenderTarget_GetTransform(c->rt, &dm);
	d2m(&dm, &already);
	temp = *m;		// don't modify m
	// you would think we have to do already * m, right?
	// WRONG! we have to do m * already
	// why? a few reasons
	// a) this lovely comment in cairo's source - http://cgit.freedesktop.org/cairo/tree/src/cairo-matrix.c?id=0537479bd1d4c5a3bc0f6f41dec4deb98481f34a#n330
	// 	Direct2D uses column vectors and I don't know if this is even documented
	// b) that's what Core Graphics does
	// TODO see if Microsoft says to do this
	uiDrawMatrixMultiply(&temp, &already);
	m2d(&temp, &dm);
	ID2D1RenderTarget_SetTransform(c->rt, &dm);
}