예제 #1
0
static void do_adjust_relative(timelib_time* time)
{
	if (time->relative.have_weekday_relative) {
		do_adjust_for_weekday(time);
	}
	do_normalize(time);

	if (time->have_relative) {
		time->s += time->relative.s;
		time->i += time->relative.i;
		time->h += time->relative.h;

		time->d += time->relative.d;
		time->m += time->relative.m;
		time->y += time->relative.y;
	}
	switch (time->relative.first_last_day_of) {
		case 1: /* first */
			time->d = 1;
			break;
		case 2: /* last */
			time->d = 0;
			time->m++;
			break;
	}
	do_normalize(time);
}
예제 #2
0
static void do_adjust_special(timelib_time* time)
{
	if (time->relative.have_special_relative) {
		switch (time->relative.special.type) {
			case TIMELIB_SPECIAL_WEEKDAY:
				do_adjust_special_weekday(time);
				break;
		}
	}
	do_normalize(time);
	memset(&(time->relative.special), 0, sizeof(time->relative.special));
}
예제 #3
0
static void do_adjust_relative(timelib_time* time)
{
	if (time->have_weekday_relative) {
		do_adjust_for_weekday(time);
	}
	do_normalize(time);

	if (time->have_relative) {
		time->s += time->relative.s;
		time->i += time->relative.i;
		time->h += time->relative.h;

		time->d += time->relative.d;
		time->m += time->relative.m;
		time->y += time->relative.y;
	}
	do_normalize(time);

	memset(&(time->relative), 0, sizeof(time->relative));
	time->have_relative = 0;
}
예제 #4
0
static void do_adjust_special_early(timelib_time* time)
{
	if (time->relative.have_special_relative) {
		switch (time->relative.special.type) {
			case TIMELIB_SPECIAL_DAY_OF_WEEK_IN_MONTH:
				time->d = 1;
				time->m += time->relative.m;
				time->relative.m = 0;
				break;
			case TIMELIB_SPECIAL_LAST_DAY_OF_WEEK_IN_MONTH:
				time->d = 1;
				time->m += time->relative.m + 1;
				time->relative.m = 0;
				break;
		}
	}
	do_normalize(time);
}
예제 #5
0
int path_getrelative(lua_State* L)
{
	int i, last, count;
	char src[0x4000];
	char dst[0x4000];

	const char* p1 = luaL_checkstring(L, 1);
	const char* p2 = luaL_checkstring(L, 2);

	/* normalize the paths */
	do_normalize(L, src, p1);
	do_normalize(L, dst, p2);

	/* same directory? */
	if (strcmp(src, dst) == 0) {
		lua_pushstring(L, ".");
		return 1;
	}

	/* dollar macro? Can't tell what the real path might be, so treat
	 * as absolute. This enables paths like $(SDK_ROOT)/include to
	 * work as expected. */
	if (dst[0] == '$') {
		lua_pushstring(L, dst);
		return 1;
	}

	/* find the common leading directories */
	strcat(src, "/");
	strcat(dst, "/");

	last = -1;
	i = 0;
	while (src[i] && dst[i] && src[i] == dst[i]) {
		if (src[i] == '/') {
			last = i;
		}
		++i;
	}

	/* if I end up with just the root of the filesystem, either a single
	 * slash (/) or a drive letter (c:) then return the absolute path. */
	if (last <= 0 || (last == 2 && src[1] == ':')) {
		dst[strlen(dst) - 1] = '\0';
		lua_pushstring(L, dst);
		return 1;
	}

	/* count remaining levels in src */
	count = 0;
	for (i = last + 1; src[i] != '\0'; ++i) {
		if (src[i] == '/') {
			++count;
		}
	}

	/* start my result by backing out that many levels */
	src[0] = '\0';
	for (i = 0; i < count; ++i) {
		strcat(src, "../");
	}

	/* append what's left */
	strcat(src, dst + last + 1);

	/* remove trailing slash and done */
	src[strlen(src) - 1] = '\0';
	lua_pushstring(L, src);
	return 1;
}
예제 #6
0
void ProjectionFinder::get_coarse_registrations_for_subject(
             unsigned int i,RegistrationResults &coarse_RRs) {
  IMP_LOG_TERSE("ProjectionFinder: Coarse registration for subject " << i
          << std::endl);
  algebra::Transformation2D best_2d_transformation;
  double max_ccc=0.0;
  unsigned int projection_index = 0;
  coarse_RRs.resize(projections_.size());
  for(unsigned long j=0;j<projections_.size();++j) {
    ResultAlign2D RA;
    // Method without preprocessing
    if(params_.coarse_registration_method == ALIGN2D_NO_PREPROCESSING) {
      RA=get_complete_alignment(subjects_[i]->get_data(),
                          projections_[j]->get_data(),false);
    }
    // Methods with preprocessing and FFT alignment
    if(params_.coarse_registration_method == ALIGN2D_PREPROCESSING) {
      RA=get_complete_alignment_no_preprocessing(subjects_[i]->get_data(),
                                           SUBJECTS_[i],
                                           SUBJECTS_POLAR_AUTOC_[i],
                                           projections_[j]->get_data(),
                                           PROJECTIONS_POLAR_AUTOC_[j]);
    }

    // Method with centers of gravity alignment
    if(params_.coarse_registration_method == ALIGN2D_WITH_CENTERS) {
      RA = get_complete_alignment_with_centers_no_preprocessing(
                                                subjects_cog_[i],
                                                projections_cog_[j],
                                                SUBJECTS_POLAR_AUTOC_[i],
                                                PROJECTIONS_POLAR_AUTOC_[j]);
      // get_complete_alignment_with_centers_no_preprocessing returns a value of
      // Cross correlation from the rotational alignment but not the ccc.
      // compute the ccc here:
      cv::Mat aux;
      get_transformed(projections_[j]->get_data(),aux,RA.first);
      RA.second=get_cross_correlation_coefficient(subjects_[i]->get_data(),aux);
    }

    // Set result
    algebra::Vector2D shift(0.,0.);
    // Get values from the image
    algebra::Vector3D euler = projections_[j]->get_header().get_euler_angles();
    algebra::Rotation3D R = algebra::get_rotation_from_fixed_zyz(euler[0],
                                                                euler[1],
                                                                euler[2]);
    RegistrationResult projection_result(R,shift,j,i);
    projection_result.set_ccc(RA.second);


    // The coarse registration is based on maximizing the
    // cross-correlation-coefficient, but any other score can be calculated
    // at this point.
    IMP_NEW(Image,aux,());
    aux->set_was_used(true);
    get_transformed(projections_[j]->get_data(), aux->get_data(), RA.first);

    if(variances_.size() > 0) {
      score_function_->set_variance_image(variances_[i]);
    }
    double score = score_function_->get_score(subjects_[i], aux);
    projection_result.set_score(score);


    // add the 2D alignment transformation to the registration result
    // for the projection
    projection_result.add_in_plane_transformation(RA.first);
    // and store
    coarse_RRs[j]=projection_result;
    IMP_LOG_VERBOSE(
            "Coarse registration: " << coarse_RRs[j] << std::endl);
    if(RA.second>max_ccc) {
      max_ccc = RA.second;
      best_2d_transformation =  RA.first;
      projection_index = j;
    }
///******/
//    cv::Mat xx;
//    get_transformed(projections_[j]->get_data(),xx,RA.first);
//    std::ostringstream strmm;
//    strmm << "individual-" << i << "-" << j << ".spi";
//    write_matrix(xx,strmm.str());
///******/
  }

  if(params_.save_match_images) {
    IMP_NEW(em2d::Image,match,());

    get_transformed(projections_[projection_index]->get_data(),
                    match->get_data(),
                    best_2d_transformation);
    do_normalize(match,true);
    coarse_RRs[projection_index].set_in_image(match->get_header());
    std::ostringstream strm;

    strm << "coarse_match-";
    strm.fill('0');
    strm.width(4);
    strm << i << ".spi";
    IMP_NEW(em2d::SpiderImageReaderWriter, srw, ());
    match->set_name(strm.str()); ////
    match->set_was_used(true);
    match->write(strm.str(),srw);
  }