int compare_localmotions(const LocalMotions* lms1, const LocalMotions* lms2){ test_bool(vs_vector_size(lms1) == vs_vector_size(lms2)); int i; for(i=0; i<vs_vector_size(lms1); i++){ test_bool(LMGet(lms1,i)->v.x == LMGet(lms2,i)->v.x); test_bool(LMGet(lms1,i)->v.y == LMGet(lms2,i)->v.y); } return 1; }
Transform simpleMotionsToTransform(TransformData* td, const LocalMotions* motions){ int center_x = 0; int center_y = 0; Transform t = null_transform(); if(motions==0) return t; int num_motions=vs_vector_size(motions); double *angles = (double*) vs_malloc(sizeof(double) * num_motions); LocalMotion meanmotion; int i; if(num_motions < 1) return t; // calc center point of all remaining fields for (i = 0; i < num_motions; i++) { center_x += LMGet(motions,i)->f.x; center_y += LMGet(motions,i)->f.y; } center_x /= num_motions; center_y /= num_motions; // cleaned mean meanmotion = cleanmean_localmotions(motions); // figure out angle if (num_motions < 6) { // the angle calculation is inaccurate for 5 and less fields t.alpha = 0; } else { for (i = 0; i < num_motions; i++) { // substract avg and calc angle LocalMotion m = sub_localmotion(LMGet(motions,i),&meanmotion); angles[i] = calcAngle(&m, center_x, center_y); } double min, max; t.alpha = -cleanmean(angles, num_motions, &min, &max); if (max - min > td->maxAngleVariation) { t.alpha = 0; vs_log_info(td->modName, "too large variation in angle(%f)\n", max-min); } } vs_free(angles); // compensate for off-center rotation double p_x = (center_x - td->fiSrc.width / 2); double p_y = (center_y - td->fiSrc.height / 2); t.x = meanmotion.v.x + (cos(t.alpha) - 1) * p_x - sin(t.alpha) * p_y; t.y = meanmotion.v.y + sin(t.alpha) * p_x + (cos(t.alpha) - 1) * p_y; return t; }
int* localmotions_gety(const LocalMotions* localmotions){ int len = vs_vector_size(localmotions); int* ys = vs_malloc(sizeof(int) * len); int i; for (i=0; i<len; i++){ ys[i]=LMGet(localmotions,i)->v.y; } return ys; }
int vsStoreLocalmotions(FILE* f, const LocalMotions* lms){ int len = vs_vector_size(lms); int i; fprintf(f,"List %i [",len); for (i=0; i<len; i++){ if(i>0) fprintf(f,","); if(storeLocalmotion(f,LMGet(lms,i)) <= 0) return 0; } fprintf(f,"]"); return 1; }