예제 #1
0
int main(){
	const char* rows[5] = {"SUM", "SUMSTR", "SUMCONSTSTR", 
			       "COPY", "COPYCONSTSTR"};
	const char* cols[1] = {"n=1e9 doubles"};
	const int n = 1000*1000*1000;
	double *a, *b;
	
	init_mem(a, b, n);
	
	double bw[5];
	bw[0] = time(a, b, n, SUM);
	bw[1] = time(a, b, n, SUMSTR);
	bw[2] = time(a, b, n, SUMCONSTSTR);
	bw[3] = time(a, b, n, COPY);
	bw[4] = time(a, b, n, COPYCONSTSTR);

	verify_dir("DBG/");
	char fname[200];
	sprintf(fname, "DBG/time_sc_stride_%d.txt", STR);
	link_cout(fname);

	Table tbl;
	tbl.dim(5, 1);
	tbl.rows(rows);
	tbl.cols(cols);
	tbl.data(bw);
	char banner[200];
	sprintf(banner, "memory bw in bytes/cycle, stride = %d\n", STR);
	tbl.print(banner);
	
	unlink_cout();

	release_mem(a, b);

}
예제 #2
0
파일: storage_net.c 프로젝트: tedcy/ydfs
static void do_recv_file_count_end(aio_work_node_t *work_node)
{
	storage_client_t *pClient;
	
	pClient = (storage_client_t *)work_node->arg;
	
	pClient->file.writ_size += work_node->size;

	if(pClient->trunk_file_node != NULL)
	{
		pClient->trunk_file_node->size += work_node->size;	
		release_occupied_trunk_file(pClient->nio_node->non_occupied_trunk_file_head,pClient->trunk_file_node);
	}
	else
	{
		/*synced file*/
		close(pClient->file.fd);
	}
	logDebug("file_name %s,now_write_size %d,total writ %d",pClient->file.file_name,work_node->size,pClient->file.writ_size);
	
	release_mem(&pClient->nio_node->dio_buf_pool,work_node->mem_node);
	
	if(pClient->file.proc != NULL)
		pClient->file.proc(pClient->nio_node->eventLoop,pClient->sockfd,pClient,AE_READABLE);
	
	return ;
}
예제 #3
0
파일: tracker_net.c 프로젝트: tedcy/ydfs
void clean_tracker_client(tracker_client_t *pClient)
{
	if(pClient == NULL)
		return ;
	if(pClient->sockfd != 0)
		close(pClient->sockfd);
	release_mem(&pClient->nio_node->pClient_buf_pool,pClient->mem_node);
	return;
}
void IterQuantityAccessContiguous<T_info>::resize( int num_quantities ) {
  TEUCHOS_TEST_FOR_EXCEPTION(
    num_quantities < 1, std::length_error
    ,"IterQuantityAccessContiguous::resize(num_quantities): Error, "
    "name = "<<name_<<", num_quantities = "<<num_quantities<<" must be greater than zero" );
  if( num_quantities_ != num_quantities )
    release_mem();
  num_quantities_ = num_quantities;
  max_offset_ = std::numeric_limits<int>::min() + num_quantities_; // uninitialized
}
예제 #5
0
파일: storage_net.c 프로젝트: tedcy/ydfs
void clean_storage_client(storage_client_t *pClient)
{
	fflush(g_storage_service.sync_pool.binlog_fp);
	
	if(pClient == NULL)
		return ;
	if(pClient->sockfd != 0)
		close(pClient->sockfd);
	
	release_mem(&pClient->nio_node->pClient_buf_pool,pClient->mem_node);
	return;
}
void IterQuantityAccessContiguous<T_info>::set_factory(
  const abstract_factory_ptr_t& abstract_factory
  )
{
  release_mem();
  abstract_factory_ = abstract_factory;
  max_offset_ = std::numeric_limits<int>::min() + num_quantities_;  // uninitialized
  // ToDo: Don't wipe out storage, just reallocate new objects
  // as iteration quantities are updated.  This will take a little bit of
  // work and more overhead but it should be worth it in some types of
  // applications.
}
예제 #7
0
파일: storage_net.c 프로젝트: tedcy/ydfs
/*nio_recv_file*/
static void do_recv_file_count(aio_work_node_t *work_node)
{
	storage_client_t *pClient;
	
	pClient = (storage_client_t *)work_node->arg;
	
	pClient->file.writ_size += work_node->size;

	if(pClient->trunk_file_node != NULL)
	{
		pClient->trunk_file_node->size += work_node->size;	
	}

	logDebug("file_name %s,now_write_size %d,total writ %d",pClient->file.file_name,work_node->size,pClient->file.writ_size);
	
	release_mem(&pClient->nio_node->dio_buf_pool,work_node->mem_node);
	return ;
}
예제 #8
0
bool CIYuv::allocate_mem()
{
  int h, pos;
  BYTE *buf1D;
  BYTE **buf2D;

  release_mem();

  if( (buf1D=(unsigned char *)malloc(size_in_byte*sizeof(BYTE))) == NULL ) return false;

  if( (buf2D=(BYTE **)malloc((height+heightUV*2)*sizeof(BYTE *))) == NULL )
  {
    free(buf1D);
    return false;
  }
  memset(&buf1D[0], 0, picsizeY);
  memset(&buf1D[picsizeY], 128, picsizeUV*2);

  Y = buf2D;
  U = &(buf2D[height]);
  V = &(buf2D[height+heightUV]);

  for(h=pos=0; h<height; h++, pos+=width)
    Y[h] = &(buf1D[pos]);
  for(h=0; h<heightUV; h++, pos+=widthUV)
    U[h] = &(buf1D[pos]);
  for(h=0; h<heightUV; h++, pos+=widthUV)
    V[h] = &(buf1D[pos]);

  comp[0] = Y;
  comp[1] = U;
  comp[2] = V;

  pBuffer = Y[0]; // buf1D;

  return true;
}
예제 #9
0
int
main(int argc, char **argv)
{
	addrxlat_ctx_t *ctx;
	const char *err;
	void *(old_realloc_hook)(void *, size_t, const void *);
	int errors;
	size_t len, explen, maxlen;
	int i;

	ctx = addrxlat_ctx_new();
	if (!ctx) {
		perror("Cannot allocate context");
		return TEST_ERR;
	}

	errors = 0;

	puts("Testing single error message...");
	for (i = 0; i < sizeof(loremipsum); ++i) {
		addrxlat_ctx_clear_err(ctx);
		addrxlat_ctx_err(ctx, ADDRXLAT_ERR_CUSTOM_BASE,
				 "%.*s", i, loremipsum);
		err = addrxlat_ctx_get_err(ctx);
		len = strlen(err);
		if (len != i) {
			printf("Wrong error message length: %zd != %d\n",
			       len, i);
			++errors;
		}
		if (memcmp(err, loremipsum, i)) {
			printf("Wrong error message: %s\n", err);
			++errors;
		}
	}

	puts("Testing appended message...");
	for (i = 0; i < sizeof(loremipsum); ++i) {
		addrxlat_ctx_clear_err(ctx);
		addrxlat_ctx_err(ctx, ADDRXLAT_ERR_CUSTOM_BASE, othermsg);
		err = addrxlat_ctx_get_err(ctx);
		if (strcmp(err, othermsg)) {
			printf("Wrong last level message: %s\n", err);
			++errors;
		}

		addrxlat_ctx_err(ctx, ADDRXLAT_ERR_CUSTOM_BASE,
				 "%.*s", i, loremipsum);
		err = addrxlat_ctx_get_err(ctx);
		len = strlen(err);
		explen = i + strlen(": ") + strlen(othermsg);
		if (len != explen) {
			printf("Wrong error message length: %zd != %zd\n",
			       len, explen);
			++errors;
		} else if (memcmp(err, loremipsum, i) ||
			   memcmp(err + i, ": ", 2) ||
			   strcmp(err + i + 2, othermsg)) {
			printf("Wrong error message: %s\n", err);
			++errors;
		}
	}

	puts("Testing prepended message...");
	for (i = 0; i < sizeof(loremipsum); ++i) {
		addrxlat_ctx_clear_err(ctx);
		addrxlat_ctx_err(ctx, ADDRXLAT_ERR_CUSTOM_BASE,
				 "%.*s", i, loremipsum);
		err = addrxlat_ctx_get_err(ctx);
		len = strlen(err);
		if (len != i || memcmp(err, loremipsum, i)) {
			printf("Wrong original message (len=%d)\n", i);
			++errors;
			continue;
		}

		addrxlat_ctx_err(ctx, ADDRXLAT_ERR_CUSTOM_BASE, othermsg);
		err = addrxlat_ctx_get_err(ctx);
		len = strlen(err);
		explen = strlen(othermsg) + i;
		if (i > 0)
			explen += strlen(": ");
		if (len != explen) {
			printf("Wrong error message length: %zd != %zd\n",
			       len, explen);
			++errors;
		} else if (i == 0) {
			if (strcmp(err, othermsg)) {
				printf("Wrong error message: %s\n", err);
				++errors;
			}
		} else if (memcmp(err, othermsg, strlen(othermsg)) ||
			   memcmp(err + strlen(othermsg), ": ", 2) ||
			   memcmp(err + strlen(othermsg) + 2, loremipsum, i)) {
			printf("Wrong error message: %s\n", err);
			++errors;
		}
	}

	puts("Invalid format string...");
	addrxlat_ctx_clear_err(ctx);
	addrxlat_ctx_err(ctx, ADDRXLAT_ERR_CUSTOM_BASE,
			 "%9999999999999d", 0);
	err = addrxlat_ctx_get_err(ctx);
	if (strcmp(err, "(bad format string)")) {
		printf("Unexpected message: %s\n", err);
		++errors;
	}

	/* Allocation failures. */
	puts("\nALLOCATION FAILURE TESTS"
	     "\n------------------------\n");

	/* First, allocate a new context to make sure that already allocated
	 * space cannot be re-used. */
	addrxlat_ctx_decref(ctx);
	ctx = addrxlat_ctx_new();
	if (!ctx) {
		perror("Cannot allocate fresh context");
		return TEST_ERR;
	}

	/* Get size of the fallback buffer. */
	if (force_nomem())
		return TEST_ERR;
	addrxlat_ctx_err(ctx, ADDRXLAT_ERR_CUSTOM_BASE, loremipsum);
	if (release_mem())
		return TEST_ERR;

	err = addrxlat_ctx_get_err(ctx);
	if (err[0] != '<') {
		printf("Error message not truncated: %s\n", err);
		++errors;
		goto out;
	}

	maxlen = strlen(err);
	printf("Fallback buffer length: %zd\n", maxlen);

	puts("Testing single error message...");
	if (force_nomem())
		return TEST_ERR;
	for (i = maxlen; i < sizeof(loremipsum); ++i) {
		addrxlat_ctx_clear_err(ctx);
		addrxlat_ctx_err(ctx, ADDRXLAT_ERR_CUSTOM_BASE,
				 "%.*s", i, loremipsum);
		err = addrxlat_ctx_get_err(ctx);
		len = strlen(err);
		if (len != maxlen) {
			printf("Wrong error message length: %zd != %zd\n",
			       len, maxlen);
			++errors;
		}
		if ((i <= maxlen && memcmp(err, loremipsum, maxlen)) ||
		    (i > maxlen &&
		     (err[0] != '<' ||
		      memcmp(err + 1, loremipsum + 1, maxlen - 2) ||
		      err[maxlen-1] != '>'))) {
			printf("Wrong error message: %s\n", err);
			++errors;
		}
	}
	if (release_mem())
		return TEST_ERR;

	puts("Testing appended message...");
	if (force_nomem())
		return TEST_ERR;
	for (i = maxlen - strlen(othermsg) - 2; i < sizeof(loremipsum); ++i) {
		addrxlat_ctx_clear_err(ctx);
		addrxlat_ctx_err(ctx, ADDRXLAT_ERR_CUSTOM_BASE, othermsg);
		err = addrxlat_ctx_get_err(ctx);
		if (strcmp(err, othermsg)) {
			printf("Wrong last level message: %s\n", err);
			++errors;
		}

		addrxlat_ctx_err(ctx, ADDRXLAT_ERR_CUSTOM_BASE,
				 "%.*s", i, loremipsum);
		err = addrxlat_ctx_get_err(ctx);
		len = strlen(err);
		if (len != maxlen) {
			printf("Wrong error message length: %zd != %zd\n",
			       len, maxlen);
			++errors;
			continue;
		}

		len -= strlen(othermsg) + 2;
		if (memcmp(err + len, ": ", 2) ||
		    strcmp(err + len + 2, othermsg)) {
			printf("Wrong other message: %s\n", err);
			++errors;
		} else if (i <= maxlen - strlen(othermsg) - 2) {
			if (memcmp(err, loremipsum, i)) {
				printf("Wrong error message: %s\n", err);
				++errors;
			}
		} else if (err[0] != '<') {
			printf("Wrong truncate at begin: %s\n", err);
			++errors;
		} else if (i <= maxlen) {
			if (memcmp(err + 1, loremipsum + 1 + i - len, len - 1)) {
				printf("Wrong truncate at end: %s\n", err);
				++errors;
			}
		} else if (memcmp(err + 1, loremipsum + 1 + maxlen - len, len - 2) ||
			   err[len-1] != '>') {
			printf("Wrong truncate in middle: %s\n", err);
			++errors;
		}
	}
	if (release_mem())
		return TEST_ERR;

	puts("Testing prepended message...");
	for (i = maxlen - strlen(othermsg) - 2; i < sizeof(loremipsum); ++i) {
		addrxlat_ctx_clear_err(ctx);
		addrxlat_ctx_err(ctx, ADDRXLAT_ERR_CUSTOM_BASE,
				 "%.*s", i, loremipsum);
		err = addrxlat_ctx_get_err(ctx);
		len = strlen(err);
		if (len != i || memcmp(err, loremipsum, i)) {
			printf("Wrong original message (len=%d)\n", i);
			++errors;
			continue;
		}

		if (force_nomem())
			return TEST_ERR;
		addrxlat_ctx_err(ctx, ADDRXLAT_ERR_CUSTOM_BASE, othermsg);
		if (release_mem())
			return TEST_ERR;
		err = addrxlat_ctx_get_err(ctx);
		len = strlen(err);
		if (i <= maxlen)
			explen = maxlen;
		else
			explen = i + 1;
		if (len != explen) {
			printf("Wrong error message length: %zd != %zd\n",
			       len, explen);
			++errors;
			continue;
		}

		if (i == maxlen - strlen(othermsg) - 2) {
			if (memcmp(err, othermsg, strlen(othermsg)) ||
			    memcmp(err + len - i - 2, ": ", 2) ||
			    memcmp(err + len - i, loremipsum, i)) {
				printf("Wrong message: %s\n", err);
				++errors;
			}
		} else if (err[0] != '<') {
			printf("Message not truncated: %s\n", err);
			++errors;
		} else if (i < maxlen - 2) {
			if (memcmp(err + 1, othermsg + strlen(othermsg) - (len - i - 3), len - i - 3) ||
			    memcmp(err + len - i - 2, ": ", 2) ||
			    memcmp(err + len - i, loremipsum, i)) {
				printf("Wrong combined message: %s\n", err);
			}
		} else if (i == maxlen - 2) {
			if (memcmp(err + 1, othermsg + strlen(othermsg) - (len - i - 2), len - i - 2) ||
			    err[len - i - 1] != ' ' ||
			    memcmp(err + len - i, loremipsum, i)) {
				printf("Wrong combined message: %s\n", err);
			}
		} else if (i == maxlen) {
			if (memcmp(err + 1, loremipsum + 1, maxlen - 1)) {
				printf("Wrong truncate at begin: %s\n", err);
				++errors;
			}
		} else if (memcmp(err + 1, loremipsum, i)) {
			printf("Wrong message: %s\n", err);
			++errors;
		}
	}

out:
	printf("\nAll done: %d errors\n", errors);

	return errors == 0 ? TEST_OK : TEST_FAIL;
}
예제 #10
0
파일: xform.c 프로젝트: BreezeLee/LibSift
/*
Calculates a best-fit image transform from image feature correspondences
using RANSAC.

For more information refer to:

Fischler, M. A. and Bolles, R. C.  Random sample consensus: a paradigm for
model fitting with applications to image analysis and automated cartography.
<EM>Communications of the ACM, 24</EM>, 6 (1981), pp. 381--395.

@param features an array of features; only features with a non-NULL match
	of type mtype are used in homography computation
@param n number of features in feat
@param mtype determines which of each feature's match fields to use
	for model computation; should be one of FEATURE_FWD_MATCH,
	FEATURE_BCK_MATCH, or FEATURE_MDL_MATCH; if this is FEATURE_MDL_MATCH,
	correspondences are assumed to be between a feature's img_pt field
	and its match's mdl_pt field, otherwise correspondences are assumed to
	be between the the feature's img_pt field and its match's img_pt field
@param xform_fn pointer to the function used to compute the desired
	transformation from feature correspondences
@param m minimum number of correspondences necessary to instantiate the
	model computed by xform_fn
@param p_badxform desired probability that the final transformation
	returned by RANSAC is corrupted by outliers (i.e. the probability that
	no samples of all inliers were drawn)
@param err_fn pointer to the function used to compute a measure of error
	between putative correspondences and a computed model
@param err_tol correspondences within this distance of a computed model are
	considered as inliers
@param inliers if not NULL, output as an array of pointers to the final
	set of inliers
@param n_in if not NULL and \a inliers is not NULL, output as the final
	number of inliers

@return Returns a transformation matrix computed using RANSAC or NULL
	on error or if an acceptable transform could not be computed.
*/
CvMat* ransac_xform( struct feature* features, int n, int mtype,
					ransac_xform_fn xform_fn, int m, double p_badxform,
					ransac_err_fn err_fn, double err_tol,
                    struct feature*** inliers, int* n_in )
{
    //matched:所有具有mtype类型匹配点的特征点的数组,也就是样本集
    //sample:单个样本,即4个特征点的数组
    //consensus:当前一致集;
    //consensus_max:当前最大一致集(即当前的最好结果的一致集)
	struct feature** matched, ** sample, ** consensus, ** consensus_max = NULL;
    struct ransac_data* rdata;//每个特征点的feature_data域的ransac数据指针
    CvPoint2D64f* pts, * mpts;//每个样本对应的两个坐标数组:特征点坐标数组pts和匹配点坐标数组mpts
    CvMat* M = NULL;//当前变换矩阵
    //p:当前计算出的模型的错误概率,当p小于p_badxform时迭代停止
    //in_frac:内点数目占样本总数目的百分比
	double p, in_frac = RANSAC_INLIER_FRAC_EST;
    //nm:输入的特征点数组中具有mtype类型匹配点的特征点个数
    //in:当前一致集中元素个数
    //in_min:一致集中元素个数允许的最小值,保证RANSAC最终计算出的转换矩阵错误的概率小于p_badxform所需的最小内点数目
    //in_max:当前最优一致集(最大一致集)中元素的个数
    //k:迭代次数,与计算当前模型的错误概率有关
	int i, nm, in, in_min, in_max = 0, k = 0;

    //找到特征点数组features中所有具有mtype类型匹配点的特征点,放到matched数组(样本集)中,返回值nm是matched数组的元素个数
	nm = get_matched_features( features, n, mtype, &matched );
    //若找到的具有匹配点的特征点个数小于计算变换矩阵需要的最小特征点对个数,出错
	if( nm < m )
    {   //出错处理,特征点对个数不足
		fprintf( stderr, "Warning: not enough matches to compute xform, %s" \
			" line %d\n", __FILE__, __LINE__ );
		goto end;
	}

	/* initialize random number generator */
    srand( time(NULL) );//初始化随机数生成器

    //计算保证RANSAC最终计算出的转换矩阵错误的概率小于p_badxform所需的最小内点数目
	in_min = calc_min_inliers( nm, m, RANSAC_PROB_BAD_SUPP, p_badxform );
    //当前计算出的模型的错误概率,内点所占比例in_frac越大,错误概率越小;迭代次数k越大,错误概率越小
    p = pow( 1.0 - pow( in_frac, m ), k );
	i = 0;

    //当前错误概率大于输入的允许错误概率p_badxform,继续迭代
	while( p > p_badxform )
	{
        //从样本集matched中随机抽选一个RANSAC样本(即一个4个特征点的数组),放到样本变量sample中
		sample = draw_ransac_sample( matched, nm, m );
        //从样本中获取特征点和其对应匹配点的二维坐标,分别放到输出参数pts和mpts中
		extract_corresp_pts( sample, m, mtype, &pts, &mpts );
        //调用参数中传入的函数xform_fn,计算将m个点的数组pts变换为mpts的矩阵,返回变换矩阵给M
        M = xform_fn( pts, mpts, m );//一般传入lsq_homog()函数
        if( ! M )//出错判断
			goto iteration_end;
        //给定特征点集,变换矩阵,误差函数,计算出当前一致集consensus,返回一致集中元素个数给in
		in = find_consensus( matched, nm, mtype, M, err_fn, err_tol, &consensus);

        //若当前一致集大于历史最优一致集,即当前一致集为最优,则更新最优一致集consensus_max
		if( in > in_max )
		{
            if( consensus_max )//若之前有最优值,释放其空间
				free( consensus_max );
            consensus_max = consensus;//更新最优一致集
            in_max = in;//更新最优一致集中元素个数
            in_frac = (double)in_max / nm;//最优一致集中元素个数占样本总个数的百分比
		}
        else//若当前一致集小于历史最优一致集,释放当前一致集
			free( consensus );
		cvReleaseMat( &M );

iteration_end:
        release_mem( pts, mpts, sample );
        p = pow( 1.0 - pow( in_frac, m ), ++k );//更新当前错误概率
	}

    //根据最优一致集计算最终的变换矩阵
	/* calculate final transform based on best consensus set */
    //若最优一致集中元素个数大于最低标准,即符合要求
	if( in_max >= in_min )
	{
        //从最优一致集中获取特征点和其对应匹配点的二维坐标,分别放到输出参数pts和mpts中
		extract_corresp_pts( consensus_max, in_max, mtype, &pts, &mpts );
        //调用参数中传入的函数xform_fn,计算将in_max个点的数组pts变换为mpts的矩阵,返回变换矩阵给M
		M = xform_fn( pts, mpts, in_max );
        /***********下面会再进行一次迭代**********/
        //根据变换矩阵M从样本集matched中计算出一致集consensus,返回一致集中元素个数给in
		in = find_consensus( matched, nm, mtype, M, err_fn, err_tol, &consensus);
		cvReleaseMat( &M );
		release_mem( pts, mpts, consensus_max );
        //从一致集中获取特征点和其对应匹配点的二维坐标,分别放到输出参数pts和mpts中
		extract_corresp_pts( consensus, in, mtype, &pts, &mpts );
        //调用参数中传入的函数xform_fn,计算将in个点的数组pts变换为mpts的矩阵,返回变换矩阵给M
		M = xform_fn( pts, mpts, in );
		if( inliers )
		{
            *inliers = consensus;//将最优一致集赋值给输出参数:inliers,即内点集合
			consensus = NULL;
		}
		if( n_in )
            *n_in = in;//将最优一致集中元素个数赋值给输出参数:n_in,即内点个数
		release_mem( pts, mpts, consensus );
	}
	else if( consensus_max )
    {   //没有计算出符合要求的一致集
		if( inliers )
			*inliers = NULL;
		if( n_in )
			*n_in = 0;
		free( consensus_max );
	}

    //RANSAC算法结束:恢复特征点中被更改的数据域feature_data,并返回变换矩阵M
end:
	for( i = 0; i < nm; i++ )
	{
        //利用宏feat_ransac_data来提取matched[i]中的feature_data成员并转换为ransac_data格式的指针
		rdata = feat_ransac_data( matched[i] );
        //恢复feature_data成员的以前的值
		matched[i]->feature_data = rdata->orig_feat_data;
        free( rdata );//释放内存
	}
	free( matched );

    return M;//返回求出的变换矩阵M
}
예제 #11
0
/*
  Calculates a best-fit image transform from image feature correspondences
  using RANSAC.
  
  For more information refer to:
  
  Fischler, M. A. and Bolles, R. C.  Random sample consensus: a paradigm for
  model fitting with applications to image analysis and automated cartography.
  <EM>Communications of the ACM, 24</EM>, 6 (1981), pp. 381--395.
  
  @param features an array of features; only features with a non-NULL match
    of type mtype are used in homography computation
  @param n number of features in feat
  @param mtype determines which of each feature's match fields to use
    for model computation; should be one of FEATURE_FWD_MATCH,
    FEATURE_BCK_MATCH, or FEATURE_MDL_MATCH; if this is FEATURE_MDL_MATCH,
    correspondences are assumed to be between a feature's img_pt field
    and its match's mdl_pt field, otherwise correspondences are assumed to
    be between the the feature's img_pt field and its match's img_pt field
  @param xform_fn pointer to the function used to compute the desired
    transformation from feature correspondences
  @param m minimum number of correspondences necessary to instantiate the
    model computed by xform_fn
  @param p_badxform desired probability that the final transformation
    returned by RANSAC is corrupted by outliers (i.e. the probability that
    no samples of all inliers were drawn)
  @param err_fn pointer to the function used to compute a measure of error
    between putative correspondences and a computed model
  @param err_tol correspondences within this distance of a computed model are
    considered as inliers
  @param inliers if not NULL, output as an array of pointers to the final
    set of inliers
  @param n_in if not NULL and \a inliers is not NULL, output as the final
    number of inliers
  
  @return Returns a transformation matrix computed using RANSAC or NULL
    on error or if an acceptable transform could not be computed.
*/
CvMat* ransac_xform( struct feature* features, int n, int mtype,
		     ransac_xform_fn xform_fn, int m, double p_badxform,
		     ransac_err_fn err_fn, double err_tol,
		     struct feature*** inliers, int* n_in )
{
  struct feature** matched, ** sample, ** consensus, ** consensus_max = NULL;
  struct ransac_data* rdata;
  CvPoint2D64f* pts, * mpts;
  CvMat* M = NULL;
  double p, in_frac = RANSAC_INLIER_FRAC_EST;
  int i, nm, in, in_min, in_max = 0, k = 0;

  nm = get_matched_features( features, n, mtype, &matched );
  if( nm < m )
    {
      fprintf( stderr, "Warning: not enough matches to compute xform, %s" \
	       " line %d\n", __FILE__, __LINE__ );
      goto end;
    }

  srandom( time(NULL) );

  in_min = calc_min_inliers( nm, m, RANSAC_PROB_BAD_SUPP, p_badxform );
  p = pow( 1.0 - pow( in_frac, m ), k );
  while( p > p_badxform )
    {
      sample = draw_ransac_sample( matched, nm, m );
      extract_corresp_pts( sample, m, mtype, &pts, &mpts );
      M = xform_fn( pts, mpts, m );
      if( ! M )
	goto iteration_end;
      in = find_consensus( matched, nm, mtype, M, err_fn, err_tol, &consensus);
      if( in > in_max )
	{
	  if( consensus_max )
	    free( consensus_max );
	  consensus_max = consensus;
	  in_max = in;
	  in_frac = (double)in_max / nm;
	}
      else
	free( consensus );
      cvReleaseMat( &M );

    iteration_end:
      release_mem( pts, mpts, sample );
      p = pow( 1.0 - pow( in_frac, m ), ++k );
    }

  /* calculate final transform based on best consensus set */
  if( in_max >= in_min )
    {
      extract_corresp_pts( consensus_max, in_max, mtype, &pts, &mpts );
      M = xform_fn( pts, mpts, in_max );
      in = find_consensus( matched, nm, mtype, M, err_fn, err_tol, &consensus);
      cvReleaseMat( &M );
      release_mem( pts, mpts, consensus_max );
      extract_corresp_pts( consensus, in, mtype, &pts, &mpts );
      M = xform_fn( pts, mpts, in );
      if( inliers )
	{
	  *inliers = consensus;
	  consensus = NULL;
	}
      if( n_in )
	*n_in = in;
      release_mem( pts, mpts, consensus );
    }
  else if( consensus_max )
    {
      if( inliers )
	*inliers = NULL;
      if( n_in )
	*n_in = 0;
      free( consensus_max );
    }

 end:
  for( i = 0; i < nm; i++ )
    {
      rdata = feat_ransac_data( matched[i] );
      matched[i]->feature_data = rdata->orig_feat_data;
      free( rdata );
    }
  free( matched );
  return M;
}
IterQuantityAccessContiguous<T_info>::~IterQuantityAccessContiguous() {
  release_mem();
}
예제 #13
0
    void cellp( double delta_t)
    #endif
    {
     int itype,iindex, cn,ismax=False;
     int cells_survived = 0;
     int PrintLoopVar=PrintGap;
     double bigEndT, jjj;
     int snow;
     double TotalCells;
	 int SendCellCountOneTime;
	 char stemp[255];
	 int ksumlevel;
	 int GiveTimeCount;
	 int envnowl = 0;
     extern void release_mem();
	 extern double rand01(int), ranmarm(int);
#ifdef TEST
     time_t stime;
#endif
    #ifndef DLL
       FILE *out;/* the pointer to s2.out, the interface file to Java */
    #endif
    
    #ifdef TESTMPI
   	extern int nrepetitions;
    #endif

	if (Cured == False)
	{
		SendCellCountOneTime = True;
	}
	else
	{
		SendCellCountOneTime = False;
	}

    	/*_ASSERT(0);*/
    
    /*  This func call inits the nexttoxtime variable*/
	Tblength = (long) (ntypes/Class[0].no_levels);
    InitNextToxTime();
	SetBBForPatient();		
    snow = 0;
  	if ((GiveTimeCount = 48 - (ntypes * 3)) < 0) GiveTimeCount = 0;
  
 
    /*		Changes: 12 September 1996
     *		while((timevec[itime] <= StartT) && (itime <= nallts)) itime++;
     *		<= changed to < .  This ensures that itime is no increased when timevec[itime] = startT
     */
         
         
    	/* added by Qinshou 10/25/96 for test suites */
    	
    #ifdef TEST
    	/* construct output file name  */
       
    	if ( nrepetitions == 1 ) {
			if (numTest <= 9 )
				sprintf(outName,"%s0%1d.%d.%d.0%d.out",outName,numTest,nrepetitions,(int)EndT,(int)(delta_t*1000));
			else 
				sprintf(outName,"%s%2d.%d.%d.0%d.out",outName,numTest,nrepetitions,(int)EndT,(int)(delta_t*1000));
    		out = fopen(outName,"w");
		}
    	else 
			out = fopen(outName,"a");

		if ( out==NULL )
    	{
    			printf("Error opening %s\n",outName);
  				Memory=False;
  				return;
    	}
       if ( nrepetitions ==1 )
			printvalue(out);
   #endif
    	  
      t=StartT;
      UpdateTime = 0.0;
      cellpitime = 2;
 	  nowenv = 0;

	if (KineticsModel == IsGompertz ) {

	 for ( iindex=1; iindex<=active_ntypes;iindex++) {
	
		 /* Number_of_Gomp_Classes includes gomp class for whole body */
		  for ( cn=0; cn <Number_of_Gomp_Classes; cn++ ) {
			if ( LookUp[iindex].mark != NEG ) {
				ksumlevel =  SumGompLevel(cn,iindex);
				if ( IsGompSumOverFlow(ksumlevel,cn)) {
					Memory = False;
					return;
				}
				NGomp(cn,ksumlevel) += CN[iindex]; /* GompRuleIndex=0 is for whole body */
			}
		  }

			/* micro class add VE and CA cells */
			cn = Number_of_Gomp_Classes;
			ksumlevel =  SumGompLevel(cn,iindex);
				
			if ( (iindex > pre_ntypes ) && IsGompSumOverFlow(ksumlevel,cn)){
				Memory = false;
				return;
			}

			NGomp(cn,ksumlevel) += CN[iindex];
   
		}
	}

       while((timevec[cellpitime] > t) && (timevec[cellpitime] < t + delta_t) && (cellpitime <= nallts)) cellpitime++;

          /* For each sample, the cell population is got at time EndT.    */
          bigEndT = EndT + delta_t / 2;
          while ( t < bigEndT )
          {   
 
  		  /*for speed sake, only update cell counts if patient isn't cured*/
    		  if (Cured != True)
    		  {
  				if (NextPBin(&envnowl) == False )
				{

  					release_mem(SIM);
  					Memory=False;
#ifdef DLL
  					MessageBox(NULL,"Sorry. The total number of cell types has exceeded the memory limits, Please reduce the number of levels or number of classes. Try again.","treat.dll",MB_ICONEXCLAMATION | MB_OK);
#else
					printf("Sorry. The total number of cell types has exceeded the memory limits\n");
#endif
					return;
  				}
    			if ((t >= timevec[cellpitime]  ) && ( timevec[cellpitime] < t+delta_t) && (cellpitime <= nallts))
    			{
  					for ( itype = 1; itype <= active_ntypes; itype++ )
    				{   
					    if ( timesurv(cellpitime,itype,envnowl) < 1.0 )
						{
							jjj = timesurv(cellpitime,itype,envnowl);
 							nDescOfItype(itype) = grand_b_n( CN[itype], timesurv(cellpitime,itype,envnowl) ) - CN[itype];
							if (Update_CN_NGomp(itype,envnowl)== false ){
  								release_mem(SIM);
  								Memory=False;
#ifdef DLL
  								MessageBox(NULL,"Sorry. The total number of cell types has exceeded the memory limits, Please reduce the number of levels or number of classes. Try again.","treat.dll",MB_ICONEXCLAMATION | MB_OK);
#else
								printf("Sorry. The total number of cell types has exceeded the memory limits\n");
#endif
								return ;
							}

							//should send treatment event right here
							
							//also, send plot update event
						}
					}					
					if (CheckForTreatment())
						PlotHandler();
					CheckForTox();					
    				cellpitime++;
    			 }
    			}
    
  		  /* check for any toxicity events */
/*#ifdef DLL*/
    	  CheckForTox();

		  /* call here for CheckBBRules */
		CheckBBRules();
		ResetBBEveryDeltaT();

		//do this in case the enviroment was changed by a rule.
		envnowl = nowenv;
//		CheckForTreatment();
		if ((HasGuaranteeTimeChecked == False) && (nconds >0))
		{
			CheckGuaranteeTime();
		}

		  if ( TrialSim  == False || TSFirstTreatmentHappened == True )
			  check_events();

/*#endif */
		  if (( t >= BeginPlotTime) && (t <= EndPlotTime))
		  {
 			  if ( PrintLoopVar ==  PrintGap) 
   			  {
    			  if (nrepetitions == 1)
    			  {
    		   			  if (Cured != True)
    					  {	
		/*#ifdef DLL */
    							//AddToCellQ();
							  PlotHandler();
		#ifdef DLL
    							if (SleepTime != 0)
    							{ 
    								if (SleepTime != -1)
    									Sleep(SleepTime);
    								else
    									while(SleepTime == -1)
    										Sleep(0);
    							}
		#endif    
		/*#else*/
		#ifdef TEST
		/*						fprintf(out,"%5.3e",t);*/
 							fprintf(out,"%5.3e [%d]",t, active_ntypes);
		#endif
  							for (itype = 1; itype <= active_ntypes; itype++ )
    							{
		#ifdef TEST
		/* 							fprintf(out," %5.2e",CN[itype]); */
 				fprintf(out," %5.2e (%d,%s)",CN[itype],LookUp[itype].LookUpId,cellname(itype));
				fflush(out);
		#endif
    							}
		#ifdef TEST
    						fprintf(out,"\n");
		#endif
		/*#endif*/
  						   }/* close cured */
						  if ((Cured == True) && (SendCellCountOneTime == True))
						  {
//							  AddToCellQ();
							  PlotHandler();
							  SendCellCountOneTime = False;
						  }

  					} /* close nrepetions */

				  PrintLoopVar = 1;
			  }/* printloopvar */
			  else 
					PrintLoopVar++;
		  }/*begin and end plot time */
/*#ifdef DLL*/
/*  		  if (nrepetitions == 1)
  		  {
  				if (snow++ == GiveTimeCount)
    			 {
    				 snow = 0;
    				 Sleep(0);
  				  }
  		   } */
  
		  
  		  /* check to see if patient has died, if so end simulation */

    		  if ((Dead == True) || (EndSim == True)) 
    		  {
	  			  release_mem(SIM);
    	  	      return;
    	      }
/* #endif */
#ifdef TEST
		if ( nrepetitions == 1 ) {
			  if (( t >= 5.0 && t < 5.0 + delta_t ) || 
				  ( t >= 10.0 && t < 10.0 + delta_t ) || 
				  ( t >= 15.0 && t < 15.0 + delta_t ) || 
				  ( t >= 20.0 && t < 20.0 + delta_t ) || 
				  ( t >= 25.0 && t < 25.0 + delta_t ) || 
				  ( t >= 30.0 && t < 30.0 + delta_t ) || 
				  ( t >= 31.0 && t < 31.0 + delta_t ) || 
				  ( t >= 32.0 && t < 32.0 + delta_t ) || 
				  ( t >= 33.0 && t < 33.0 + delta_t ) || 
				  ( t >= 34.0 && t < 34.0 + delta_t ) || 
				  ( t >= 35.0 && t < 35.0 + delta_t ) || 
				  ( t >= 36.0 && t < 36.0 + delta_t ) ||
				  ( t >= 37.0 && t < 37.0 + delta_t ) || 
				  ( t >= 38.0 && t < 38.0 + delta_t ) ||
				  ( t >= 39.0 && t < 39.0 + delta_t ) || 
				  ( t >= 40.0 && t < 40.0 + delta_t ) || 
				  ( t >= 41.0 && t < 41.0 + delta_t ) || 
				  ( t >= 42.0 && t < 42.0 + delta_t ) || 
				  ( t >= 43.0 && t < 43.0 + delta_t ) || 
				  ( t >= 44.0 && t < 44.0 + delta_t ) || 
				  ( t >= 45.0 && t < 45.0 + delta_t ))
			  {
				  printf("At time %lf cell types = %d systime %d\n",t,active_ntypes,time(&stime)-saitime);
			  }
		}
#endif

		
    		  t = t+delta_t;
 
     }
    
#ifdef TEST
  	if ((GuaranteeReset == false) && ( nrepetitions > 1 )) {
		if ( ntypes  > 10 ) {
  			 for (iindex =1;iindex<= active_ntypes;iindex++) 
  	 			  fprintf(out,"%e ",CN[iindex]);
  			 fprintf(out,"\n");
		}
		else { 
	/* for pgf test, get rearranged output including zero cell counts */
			 for (iindex =1;iindex<= active_ntypes;iindex++) {
				  itype = iindex-1;
				  do {
					  itype++;
					  if ((int)LookUp[iindex].LookUpId == itype )
  	 					 fprintf(out,"%e ",CN[itype]);
					  else  fprintf(out,"%e ",ZERO);
				 } while ((int)LookUp[iindex].LookUpId != itype);
			 }

			 for (iindex = LookUp[active_ntypes].LookUpId+1;iindex<=(int)ntypes ;iindex++) 
				 fprintf(out,"%e ",ZERO);
  			 fprintf(out,"\n");
		}
  	}
    	fclose(out);
#endif
/*#ifdef DLL*/
  	/* if patient didn't die and has cells less than diagnosis, then NED event */
		if (GuaranteeReset == False)
		{
			TotalCells = AllCells();
  			sprintf(stemp,"%e",TotalCells);
    		/* if(TotalCells < diagnosis_threshold)*/
			if (DiagnosedNow == False )
    		{
  			/*if patient didn't die and has cells less than diagnosis, 
  			// then an end of followup with NED event */
  			AddToEventQ((t-delta_t),EFUNEDEVENT,stemp,".",".");
  			}
			else
  			{
  			/* Patient didn't die, and had a diagnosable tumor
  			// so add an end of follow up event with tumor */
  			AddToEventQ((t - delta_t),EFUTUMEVENT,stemp,".",".");
			}
			
			/*//if a CR or PR is pending, but the simulation ended before it couldn't 
			//be checked after the TumorExamInterval is up, post it now.*/
			if (CompleteResponse.checked == True)
				AddToEventQ(CompleteResponse.time,CREVENT,".",".",".");
			else if (PartialResponse.checked == True)
				AddToEventQ(PartialResponse.time,RESPONSEEVENT,".",".",".");
		}
/*	//	else
	//		AddToEventQ((t - delta_t),NORESPONSEEVENT,".",".",".");*/

/*#endif */	
    	SimRunning = False;
		release_mem(SIM);
 return;
}
예제 #14
0
CIYuv::~CIYuv()
{
  release_mem();
}