// 从配置文件重新生成插件列表
int CPluginManager::ReloadPlugin(DWORD dwFlag)
{
	LOG((LEVEL_FUNC_IN_OUT,"CPluginManager::ReloadPlugin,flag = %d\n",dwFlag));	
	
	// 卸载所有插件
	for_each(m_PluginList.begin(),m_PluginList.end(),bind2nd(mem_fun_ref(&CPluginInfo::UnLoadPlug),0));
	
	// 清除链表
	m_PluginList.clear();

	// 重新从配置文件读
	std::string strPluginConfigFile(m_szPluginConfigPath);
	strPluginConfigFile += TSP_PLUGIN_S_CONFIG_NAME;

	// 如果配置文件不正确,由于下载模块很可能调用此函数,所以不返回错,这样可以通过升级更新到新的
	if( !ReadPluginIniFile<CPluginInfo>(m_PluginList,strPluginConfigFile,true) )
	{
		LOG((LEVEL_ERROR,"读取插件配置文件错\n"));
		return DDCE_CALL_FAIL;
	}
	
	// 去除不属于此部分管理的插件,不用判断返回值
	ExceptPluginFile(m_PluginList);

	// 设置所有插件状态为未加载	
	for_each(m_PluginList.begin(),m_PluginList.end(),bind2nd(mem_fun_ref(&CPluginInfo::Status),CPluginInfo::STATUS_UNLOAD));			

	return 0;
}
//改变所有插件状态
int CPluginManager::StatusAll(int flag)
{
	if( flag == CPluginInfo::STATUS_RUNNING )
		for_each(m_PluginList.begin(),m_PluginList.end(),bind2nd(mem_fun_ref(&CPluginInfo::StartPlug),&m_plugParam));
	else if( flag == CPluginInfo::STATUS_UNLOAD )
		for_each(m_PluginList.begin(),m_PluginList.end(),bind2nd(mem_fun_ref(&CPluginInfo::UnLoadPlug),0));
	else if( flag == CPluginInfo::STATUS_LOAD )
		for_each(m_PluginList.begin(),m_PluginList.end(),bind2nd(mem_fun_ref(&CPluginInfo::LoadPlug),0));
	else if( flag == CPluginInfo::STATUS_STOP )
		for_each(m_PluginList.begin(),m_PluginList.end(),bind2nd(mem_fun_ref(&CPluginInfo::StopPlug),0));
	else if( flag == CPluginInfo::STATUS_DELETE )
	{
		// 需要删除链表中记录
		for_each(m_PluginList.begin(),m_PluginList.end(),bind2nd(mem_fun_ref(&CPluginInfo::RemovePlug),0));
		m_PluginList.clear();

		// 除了测试,其他情况只有卸载会调这个,把自己的配置文件也删了		
		std::string strPluginConfigFile(m_szPluginConfigPath);
		strPluginConfigFile += TSP_PLUGIN_S_CONFIG_NAME;
		
		if( !DeleteFile(strPluginConfigFile.c_str()) )
		{
			LOG((LEVEL_ERROR,"删除插件失败(%s):%d \n",strPluginConfigFile.c_str(),GetLastError()));
		}

	}
	else
	{
		LOG((LEVEL_WARNNING,"插件状态未找到:%d\n",flag));
	}

	return 0;
}
示例#3
0
int main()
{
  Klasse obj;
  const Klasse& objc = obj;

  mem_fun(&Klasse::vf0c)(&objc);
  mem_fun(&Klasse::vf1c)(&objc, 1);

  mem_fun_ref(&Klasse::vf0c)(objc);
  mem_fun_ref(&Klasse::vf1c)(objc, 1);
  return 0;
}
示例#4
0
void CLatticeFrame::print (std::string prefix)
{
    if (m_bwType & BESTWORD) printf ("B");
    if (m_bwType & USER_SELECTED) printf ("U");
    printf ("\n");

    prefix += "    ";
    printf ("  Lexicon States:\n");
    for_each (m_lexiconStates.begin (), m_lexiconStates.end (), 
              bind2nd (mem_fun_ref (&TLexiconState::print), prefix));

    printf ("  Lattice States:\n");
    for_each (m_latticeStates.begin (), m_latticeStates.end (), 
              bind2nd (mem_fun_ref (&TLatticeState::print), prefix));
    printf ("\n");
}
TTErr TTAudioGraphObject::resetAudio()
{
	sSharedMutex->lock();
	for_each(mAudioInlets.begin(), mAudioInlets.end(), mem_fun_ref(&TTAudioGraphInlet::reset));		
	sSharedMutex->unlock();
	return kTTErrNone;
}
示例#6
0
  result_type operator()(ast::score& score)
  {
    if (!score.time_sigs.empty()) global_time_signature = score.time_sigs.front();

    {
      std::vector<std::future<bool>> staves;
      for (ast::part &part: score.parts) {
        if (!part.empty()) {
          std::size_t const staff_count{part.front().paragraphs.size()};
          for (std::size_t staff_index = 0; staff_index < staff_count;
               ++staff_index) {
            staves.emplace_back
            ( async( std::launch::async
                   , std::move(annotate_staff<ErrorHandler>( error_handler
                                                           , report_error
                                                           , global_time_signature
                                                           , score.key_sig
                                                           ))
                   , staff_index, std::ref(part))
            );
          }
        }
      }
      if (!all_of( begin(staves), end(staves)
                 , mem_fun_ref(&std::future<bool>::get)))
        return false;
    }

    return unfold(score);
  }
示例#7
0
void reads::estimateFragLengthMean()
{
	int i;
	int totalRC = readsClusterVec.size();
	int topNo = (int) (param.topPercent * totalRC / 100.0);
	vector<readsCluster> sub_rcv;

	sort(readsClusterVec.begin(), readsClusterVec.end(), mem_fun_ref(&readsCluster::sortByDense));
	sort(readsClusterVec.begin(), readsClusterVec.begin()+topNo, mem_fun_ref(&readsCluster::sortByPos));
	for (i=0; i<(topNo-1); i++)
	{
		if (readsClusterVec[i].r_chrIdx == readsClusterVec[i+1].r_chrIdx && readsClusterVec[i].r_end > readsClusterVec[i+1].r_start)
		{
			sub_rcv.push_back(readsClusterVec[i++]);
			sub_rcv.push_back(readsClusterVec[i]);
		}
	}
	totalRC = sub_rcv.size();
	double avgPos, lastAvgPos = 0;
	vector<double> fragLengthSample;
	for (i=0; i<totalRC; i++)
	{
		avgPos = sub_rcv[i].r_avgPos;
		if (i%2==0)
			lastAvgPos = avgPos;
		else
			fragLengthSample.push_back(avgPos - lastAvgPos);
		//printf("%d\t%d\t%d\t%d\t%d\t%.1f\t%d\t%d\t%d\t%.1f\t%.lf\t%c\n", 
    //    sub_rcv[i].r_chrIdx, sub_rcv[i].r_start, sub_rcv[i].r_end, sub_rcv[i].r_length, sub_rcv[i].r_count, sub_rcv[i].r_dense, sub_rcv[i].r_thickStart, sub_rcv[i].r_thickEnd, sub_rcv[i].r_summit, sub_rcv[i].r_summitVal, avgPos, sub_rcv[i].r_strand);
	}
	if (fragLengthSample.size() == 0)
	{
		fprintf(stderr, "WARNING: not enough binding regions to estimate the everage fragment length.\n");
		param.fragLengthMean = -1;
		return;
	}
	//printVec(fragLengthSample);
	//printf("%f\t%f\n", avg(fragLengthSample), var(fragLengthSample));
	param.fragLengthMean = avg(fragLengthSample); // avg(fragLengthSample) under estimates the fragment length mean, because of the truncation at the tail and overlap bindings.
}
TTErr TTAudioGraphObject::process(TTAudioSignalPtr& returnedSignal, TTUInt16 forOutletNumber)
{
	lock();
	switch (mStatus) {		

		// we have not processed anything yet, so let's get started
		case kTTAudioGraphProcessNotStarted:
			mStatus = kTTAudioGraphProcessingCurrently;
			
			if (mAudioFlags & kTTAudioGraphGenerator) {			// a generator (or no input)
				getUnitGenerator()->process(mInputSignals, mOutputSignals);
			}
			else {												// a processor
				// zero our collected input samples
				mInputSignals->clearAll();

				// pull (process, sum, and collect) all of our source audio
				for_each(mAudioInlets.begin(), mAudioInlets.end(), mem_fun_ref(&TTAudioGraphInlet::process));

				if (!(mAudioFlags & kTTAudioGraphNonAdapting)) {
					// examples of non-adapting objects are join≈ and matrix≈
					// non-adapting in this case means channel numbers -- vector sizes still adapt
					mOutputSignals->matchNumChannels(mInputSignals);
				}
				mOutputSignals->allocAllWithVectorSize(mInputSignals->getVectorSize());
				getUnitGenerator()->process(mInputSignals, mOutputSignals);
			}
			
			// TODO: we're doing a copy below -- is that what we really want?  Or can we just return the pointer?
			returnedSignal = mAudioOutlets[forOutletNumber].mBufferedOutput;
			mStatus = kTTAudioGraphProcessComplete;
			break;
		
		// we already processed everything that needs to be processed, so just set the pointer
		case kTTAudioGraphProcessComplete:
			returnedSignal = mAudioOutlets[forOutletNumber].mBufferedOutput;
			break;
		
		// to prevent feedback / infinite loops, we just hand back the last calculated output here
		case kTTAudioGraphProcessingCurrently:
			returnedSignal = mAudioOutlets[forOutletNumber].mBufferedOutput;
			break;
		
		// we should never get here
		default:
			unlock();
			return kTTErrGeneric;
	}
	unlock();
	return kTTErrNone;
}
///	free all memory allocations for database
///	\param	dbInfo - pointer to database information
void CDatabaseManager::ReleaseDatabase(DATABASEINFO *dbInfo)
{
	DATABASEDATA *data = dbInfo->m_DatabaseData;
	if (data != NULL)
	{
		for_each(data, data + dbInfo->m_nItems, mem_fun_ref(&DATABASEDATA::Release));
		GLOBALFREE(data);
	}
	// free up the alloc CHashString*
	delete dbInfo->m_SchemaName;
	delete dbInfo->m_FileName;
	// TODO: Check that name is owned by DATABASEINFO structure also
	//delete dbInfo->m_DatabaseName;
	//delete dbInfo->m_SchemaFile;
}
//---------------------------------------------------------
int main() 
{
	int a[3]={ 4, 6, 2 };
	std::vector<int> v(a, a+3);
	std::vector<base*> u;
	u.push_back(new A());
	u.push_back(new B());
	Fct Fct_obj;
	///////////////////////////////////////////////////
	std::for_each(a, a+3, fct);
	std::cout<<std::endl;
	///////////////////////////////////////////////////
	std::for_each(v.begin(), v.end(), fct);
	std::cout<<std::endl;
	// or:
	std::for_each(v.begin(), v.end(), Fct_obj);
	std::cout<<std::endl;
	///////////////////////////////////////////////////
	std::for_each(u.begin(), u.end(), std::mem_fun(&base::f));
	///////////////////////////////////////////////////
	/*std::vector<base> t;
	  t.push_back(A());
	  t.push_back(B());

	  std::std::for_each(u.begin(), u.end(), mem_fun(&base::f));*/
	///////////////////////// http://www.java2s.com/Code/Cpp/Vector/Callmemberfunctionforeachelementinvector.htm
	///////////////////////////////////////////////////
	std::vector<myClass> z(5);
	std::for_each(z.begin(), z.end(), std::mem_fun_ref(&myClass::print));
	std::for_each(z.begin(), z.end(), std::bind2nd(mem_fun_ref(&myClass::printString), "some text"));
	///////////////////////////////////////////////////
	std::vector<myClass*> y;
	y.push_back(new myClass(5));
	std::for_each(y.begin(), y.end(), std::mem_fun(&myClass::print));
	std::for_each(y.begin(), y.end(), std::bind2nd(mem_fun(&myClass::printString), "some text"));
	///////////////////////////////////////////////////
	myClass c;
	c.print_();
	///////////////////////////////////////////////////
	return 0;
}
示例#11
0
// Remove trailing whitespace
void
Macro::value_rtrim()
{
	// Took me three hours to arrive at
	value.erase((find_if(value.rbegin(), value.rend(), not1(mem_fun_ref(&Ptoken::is_space)))).base(), value.end());
}
示例#12
0
文件: ptrmem12.C 项目: 0day-ci/gcc
void h ()
{
  mem_fun_ref(&A::f);
}
示例#13
0
/*! Check if this Wall still belongs to Cell a, otherwise gives it to Cell b.
  \return true: Wall was corrected
  \return false: Wall was still correct
*/
bool Wall::CorrectWall( void ) {


  // collect all cells to which my nodes are connected on one list
  list<CellBase *> owners;
  transform(n1->owners.begin(),n1->owners.end(), back_inserter(owners), mem_fun_ref(&Neighbor::getCell));
  transform(n2->owners.begin(),n2->owners.end(), back_inserter(owners), mem_fun_ref(&Neighbor::getCell));

  // get the list of duplicates
  list<CellBase *> wall_owners;
  owners.sort();
  //transform(owners.begin(), owners.end(), ostream_iterator<int>(cerr, ", "), mem_fun(&Cell::Index));
  duplicates_copy( owners.begin(), owners.end(), back_inserter(wall_owners) );

  // duplicates are the cells to which the Wall belongs
  // For the first division, wall finds three "owners", including the boundary_polygon.
  // Remove that one from the list.
  //cerr << "wall_owners.size() = " << wall_owners.size() << endl;
  if (wall_owners.size() == 3 && nwalls==1 /* bug-fix 22/10/2007; confine this condition to first division only */) {

#ifdef QDEBUG
    qDebug() << "nwalls = " << nwalls << endl;
#endif
    // special case for first cleavage

    // find boundary polygon in the wall owners list
    list<CellBase *>::iterator bpit = find_if (
					       wall_owners.begin(), wall_owners.end(), 
					       mem_fun( &CellBase::BoundaryPolP )
					       );
    if (bpit!=wall_owners.end()) {

      // add a Wall with the boundary_polygon to each cell
      Wall *bp_wall1 = new Wall( n2, n1, c1, (*bpit) );
      bp_wall1->CopyWallContents(*this);
      ((Cell *)c1)->AddWall( bp_wall1);
      ((Cell *)(*bpit))->AddWall(bp_wall1);

      Wall *bp_wall2 = new Wall( n1, n2, c2, (*bpit) );
      bp_wall2->CopyWallContents(*this);
      ((Cell *)c2)->AddWall( bp_wall2);
      ((Cell *)(*bpit))->AddWall(bp_wall2);

      wall_owners.erase(bpit); 

    }else {

#ifdef QDEBUG
      qDebug() << "Wall::CorrectWall says: Wall has three owners, but none of them is the BoundaryPolygon. I have no clue what to do with this case... Sorry!" << endl;
      cerr << "Wall: " << *this << endl;
      qDebug() << "Owners are: ";
      transform(wall_owners.begin(), wall_owners.end(), ostream_iterator<int>(cerr, "  "), mem_fun (&CellBase::Index) );
      qDebug() << endl;
      qDebug() << "Owners node " << n1->Index() << ": ";

      for (list<Neighbor>::iterator i = n1->owners.begin(); i!=n1->owners.end(); i++) {
	qDebug() << i->getCell()->Index() << " ";
      }

      qDebug() << endl;
      qDebug() << "Owners node " << n2->Index() << ": ";

      for (list<Neighbor>::iterator i = n2->owners.begin(); i!=n2->owners.end(); i++) {
	qDebug() << i->getCell()->Index() << " ";
      }
      qDebug() << endl;
#endif
      std::exit(1);
    }
  }

#ifdef QDEBUG
  if (wall_owners.size() == 1) {
    qDebug() << "Corner point. Special case." << endl;
  }
#endif

  CellBase *cell1 = wall_owners.front();
  CellBase *cell2 = wall_owners.back();

  if ( (c1 == cell1 && c2==cell2) || (c1 == cell2 && c2 == cell1) ) {

    return false;
  }

  if ( c1 == cell1 ) {
    //cerr << "Block 1\n";
    ((Cell *)c2) -> RemoveWall(this);
    c2 = cell2;
    ((Cell *)c2) -> AddWall(this);
  } else {
    if ( c1 == cell2 ) {
      //	cerr << "Block 2\n";
      ((Cell *)c2) -> RemoveWall(this);
      c2 = cell1;
      ((Cell *)c2) -> AddWall(this);
    } else {
      if ( c2 == cell1) {
	((Cell *)c1)->RemoveWall(this);
	c1 = cell2;
	((Cell *)c1) -> AddWall(this);
	//  cerr << "Block 3\n";
      } else {
	if ( c2 == cell2) {
	  ((Cell *)c1)->RemoveWall(this);
	  c1 = cell1;
	  ((Cell *)c1)->AddWall(this);
	  //	  cerr << "Block 3\n";
	} else {
#ifdef QDEBUG
	  qDebug() << "Warning, cell wall was not corrected." << endl;
#endif
	  return false;
	}
      }
    }
  }
  return true;
}
//解析插件配置文件,下载并装载
BOOL CPluginManager::Update(const string &strPluginDownLoadFile)
{
	LOG((LEVEL_FUNC_IN_OUT,"CPluginManager::ProcessConfig\n"));

	int ret;	

	// 创建下载目录
	CreateDirectory(m_szPluginDownLoadPath.c_str(),NULL);
	m_recycle.Push(m_szPluginDownLoadPath,CTspRecycle::FLAG_DIR);
	
	// 组装插件配置文件文件名
	std::string strPluginConfigFile(m_szPluginConfigPath);
	strPluginConfigFile += TSP_PLUGIN_S_CONFIG_NAME;

	std::string strPluginDownLoadTmpFile;

	// 锁住这个链表,由于网络IO是异步,这个操作需要同步
	nm_ddc::CLockGuard<nm_ddc::CThreadMutex> guard(&m_lock);	

	// 读取配置信息到临时链表中
	std::list<CPluginInfo> l;
	if( !ReadPluginIniFile<CPluginInfo>(l,strPluginDownLoadFile,true) )	
	{
		LOG((LEVEL_WARNNING,"解析插件配置文件失败.%s\n",strPluginDownLoadFile.c_str()));
		return FALSE;
	}
	// 去除不属于此功能管理的插件
	ExceptPluginFile(l);

	// 新旧链表的迭代器声明
	std::list<CPluginInfo>::iterator iterNew=l.begin();
	std::list<CPluginInfo>::iterator iterOld;
	char md5[33] = {0};
	BOOL bRet = FALSE;

	// 比较新老列表,确定要下载的项
	for(;iterNew!=l.end();++iterNew)
	{
		// 在老列表中查找
		iterOld = find(m_PluginList.begin(),m_PluginList.end(),iterNew->m_strName);
		if( iterOld != m_PluginList.end() )
		{
			// 找到先做一次自我检测,防止配置文件和实体文件不一致导致不更新
			bRet = MD5_Caculate_File ( iterOld->m_strFullName.c_str(),md5);

			// 比较md5值
			if( bRet && strncmp(iterNew->m_md5,iterOld->m_md5,32) == 0 )
			{
				// 还要看strFullName,如果一样,说明没变化,仅仅复制个标志位,后面交换到老列表中
				if( iterOld->m_strFullName == iterNew->m_strFullName && 
					iterOld->m_pid == iterNew->m_pid )	
				{
					*iterNew = *iterOld;
					
					LOG((LEVEL_INFO,"(the same dll,don't update)  %s : %d\n",iterOld->m_strFullName.c_str(),iterOld->m_status));

					// 用初始状态替代运行状态,防止析构时被卸载
					if( iterOld->m_status == CPluginInfo::STATUS_RUNNING )
						iterOld->m_status = CPluginInfo::STATUS_INIT;
					else
					{
						// 其他状态就卸载再加载吧
						LOG((LEVEL_INFO,"插件未变化,但升级中将被卸载:%s,状态:%d.\n",iterOld->m_strFullName.c_str(),iterOld->m_status));
						iterOld->RemovePlug();	
					}								
				}
				else
				{
					// 直接拷贝到新路径
					ret = ComfirmCopyFile(iterOld->m_strFullName.c_str(),iterNew->m_strFullName.c_str());					
					if( ret != 0 )
					{
						LOG((LEVEL_ERROR,"拷贝文件出错:(%s==>%s),Lasterror=%d\n",iterOld->m_strFullName.c_str(),iterNew->m_strFullName.c_str(),GetLastError()));
					}
					iterNew->m_status = CPluginInfo::STATUS_UNLOAD;	

					// 拷贝过去的插件肯定能启动成功(最少和老插件一样的状态),所以这里把老插件信息完全删除
					iterOld->RemovePlug();
				}
				
				// 新纪录中已经有了,老记录中删除
				m_PluginList.erase(iterOld);				
			}
			else
				// 准备下载
				iterNew->m_status = CPluginInfo::STATUS_WAITDOWNLOAD;
		}
		else
			// 准备下载
			iterNew->m_status = CPluginInfo::STATUS_WAITDOWNLOAD;
	}

	// 下载
	for_each( l.begin(),l.end(),bind2nd(mem_fun_ref(&CPluginInfo::DownloadPlug),m_szPluginDownLoadPath) );

	// 根据下载情况,改记录
	for( iterNew=l.begin();iterNew!=l.end();++iterNew )
	{
		// 在老配置中找
		iterOld = find(m_PluginList.begin(),m_PluginList.end(),iterNew->m_strName.c_str() );

		if( iterNew->m_status == CPluginInfo::STATUS_DOWNLOAD )
		{
			// 组装下载文件名
			strPluginDownLoadTmpFile.assign(m_szPluginDownLoadPath);
			strPluginDownLoadTmpFile += iterNew->m_strName;

			//先加入回收站
			m_recycle.Push(strPluginDownLoadTmpFile);

			// 如果找到,停用,删除
			if( iterOld != m_PluginList.end() )
			{
				ret = iterOld->RemovePlug();
				if( ret != 0 )
				{
					LOG((LEVEL_WARNNING,"卸载插件 %s 出错:%d(%x)\n",iterNew->m_strName.c_str()));
				}
			}

			//将插件文件拷贝到目的地
			ret = ComfirmCopyFile(strPluginDownLoadTmpFile.c_str(),iterNew->m_strFullName.c_str());					
			if( ret != 0 )
			{
				LOG((LEVEL_ERROR,"拷贝文件出错:(%s==>%s),Lasterror=%d\n",strPluginDownLoadTmpFile.c_str(),iterNew->m_strFullName.c_str(),GetLastError()));
			}

			// 改状态为准备启用
			iterNew->m_status = CPluginInfo::STATUS_UNLOAD;
		}
		else if( iterNew->m_status == CPluginInfo::STATUS_ERROR )
		{
			// 可能下载失败,也可能以前就失败,不管怎样,都把信息复制过去
			if( iterOld != m_PluginList.end() )
				*iterNew = *iterOld;
		}

		//把url删掉,为了不在后面写入配置文件中;写配置文件是个通用的程序
		iterNew->m_strURL = "";
	}

	// 遍历老插件配置文件,如果新配置中没有,删除
	for( iterOld=m_PluginList.begin();iterOld!=m_PluginList.end();++iterOld )
	{
		// 在新配置中找
		iterNew = find(l.begin(),l.end(),iterOld->m_strName.c_str() );

		// 如果没找到,卸载
		if( iterNew == l.end() )
			iterOld->RemovePlug();
			// l.push_back(*iterOld); //插入
	}

	// 根据新配置写加密ini文件
	if( !WritePluginIniFile(l,strPluginConfigFile,true) )
	{
		LOG((LEVEL_ERROR,"写配置文件错:%s",strPluginConfigFile.c_str()));
	}

	// 清理现场
	m_recycle.PopAll();

	// 清空老列表,为了避免析构时自动卸载插件,这里强制将状态设为删除
	for_each( m_PluginList.begin(),m_PluginList.end(),bind2nd(mem_fun_ref(&CPluginInfo::Status),CPluginInfo::STATUS_DELETE) );
	m_PluginList.clear();

	// 交换新老插件列表
	m_PluginList.swap(l);

	//把INIT状态的改为RUNNING
	LOG((LEVEL_INFO,"m_PluginList.size()=%d.\n",m_PluginList.size()));
	for( iterOld=m_PluginList.begin();iterOld!=m_PluginList.end();++iterOld )
	{
		LOG((LEVEL_INFO,"%s : %d\n",iterOld->m_strFullName.c_str(),iterOld->m_status));
		if( iterOld->m_status == CPluginInfo::STATUS_INIT )
			iterOld->m_status = CPluginInfo::STATUS_RUNNING;
	}

	// 启用
	StatusAll(CPluginInfo::STATUS_RUNNING);
	

	return TRUE;
}
void MeshBuilder::normalizeNormals() {
    for_each(m_Normals.begin(), m_Normals.end(), mem_fun_ref(&Vector3f::normalize));
}
示例#16
0
void reads::detectBS2()
{
	param.fragLengthMean += param.smoothArm;
	param.fragLengthVar  = param.fragLengthMean * param.fragLengthMean / 8.0;
	param.lmLength = (int) (0.8 * param.fragLengthMean);
	param.lmArm = param.lmLength / 2;
	vector<int> f_maxPos, r_maxPos, distBSIdx;
	//int f_maxPos, r_maxPos, distBS;
	vector<double> f_max, r_max, tmp;
	//double f_max, r_max;
	double R2_theshold = param.R2_cutoff;
	int i, j;
	int totalRC = readsClusterVec.size();
	//int arm = param.smoothArm + param.lmArm;
	vector<readsCluster> sub_rcv;
	char strand;

	// for linear model
	lm *lm_signal;
	lm_signal = new lm();
	lm_signal->generateX();

	sort(readsClusterVec.begin(), readsClusterVec.end(), mem_fun_ref(&readsCluster::sortByPos));
	for (i=0; i<totalRC; i++)
	{
		strand = readsClusterVec[i].r_strand;
		if (strand == 'f' || strand == '+')
		{
			if (lm_signal->slipSolve2BS(readsClusterVec[i].r_vec, 'f'))
			{
				//multiVec(lm_signal->R2Vec, lm_signal->slopeVec, tmp);
				//getTopN(tmp, f_max, f_maxPos, 2, 0.01);
				//getTopN(lm_signal->R2Vec, f_max, f_maxPos, 2, param.R2_cutoff);
				get2BSTop(lm_signal->R2Mat, f_max, f_maxPos, distBSIdx);
				for (j=0; j<(int)f_maxPos.size(); j++)
				{
					if (lm_signal->R2Mat[distBSIdx[j]][f_maxPos[j]] > R2_theshold)
					{
						//printf("%d\n", distBSIdx[j]);
//						bingdingSite newBS(readsClusterVec[i].r_chrIdx, readsClusterVec[i].r_end + arm - f_maxPos[j], lm_signal->R2Mat[distBSIdx[j]][f_maxPos[j]], lm_signal->slopeMat[distBSIdx[j]][f_maxPos[j]], '+');
						//printf("%d\t%f\t%f\t+\n",readsClusterVec[i].r_end + arm - f_maxPos[j], lm_signal->R2Mat[distBSIdx[j]][f_maxPos[j]], lm_signal->slopeMat[distBSIdx[j]][f_maxPos[j]]);
//						BSVec.push_back(newBS);
						if (distBSIdx[j] > 0)
						{
//							bingdingSite newBS(readsClusterVec[i].r_chrIdx, readsClusterVec[i].r_end + arm - f_maxPos[j] - lm_signal->distVec[distBSIdx[j]], lm_signal->R2Mat[distBSIdx[j]][f_maxPos[j]], lm_signal->slopeMat[distBSIdx[j]][f_maxPos[j]], '+');
							//printf("%d\t%f\t%f\t+\n",readsClusterVec[i].r_end + arm - f_maxPos[j] - lm_signal->distVec[distBSIdx[j]], lm_signal->R2Mat[distBSIdx[j]][f_maxPos[j]], lm_signal->slopeMat[distBSIdx[j]][f_maxPos[j]]);
//							BSVec.push_back(newBS);
						}
						if (lm_signal->slopeMat[distBSIdx[j]][f_maxPos[j]] > maxSlope)
							maxSlope = lm_signal->slopeMat[distBSIdx[j]][f_maxPos[j]];
					}
				}
			}
		}
		if (strand == 'r' || strand == '-')
		{
			if (lm_signal->slipSolve2BS(readsClusterVec[i].r_vec, 'r'))
			{
				//multiVec(lm_signal->R2Vec, lm_signal->slopeVec, tmp);
				//getTopN(tmp, r_max, r_maxPos, 2, 0.01);
				//getTopN(lm_signal->R2Vec, r_max, r_maxPos, 2, param.R2_cutoff);
				get2BSTop(lm_signal->R2Mat, r_max, r_maxPos, distBSIdx);
				for (j=0; j<(int)r_maxPos.size(); j++)
				{
					if (lm_signal->R2Mat[distBSIdx[j]][r_maxPos[j]] > R2_theshold)
					{
						//printf("%d\n", distBSIdx[j]);
//						bingdingSite newBS(readsClusterVec[i].r_chrIdx, readsClusterVec[i].r_start - arm + r_maxPos[j], lm_signal->R2Mat[distBSIdx[j]][r_maxPos[j]], lm_signal->slopeMat[distBSIdx[j]][r_maxPos[j]], '-');
						//printf("%d\t%f\t%f\t-\n",readsClusterVec[i].r_start - arm + r_maxPos[j], lm_signal->R2Mat[distBSIdx[j]][r_maxPos[j]], lm_signal->slopeMat[distBSIdx[j]][r_maxPos[j]]);
//						BSVec.push_back(newBS);
						if (distBSIdx[j] > 0)
						{
//							bingdingSite newBS(readsClusterVec[i].r_chrIdx, readsClusterVec[i].r_start - arm + r_maxPos[j] + lm_signal->distVec[distBSIdx[j]], lm_signal->R2Mat[distBSIdx[j]][r_maxPos[j]], lm_signal->slopeMat[distBSIdx[j]][r_maxPos[j]], '-');
							//printf("%d\t%f\t%f\t-\n",readsClusterVec[i].r_start - arm + r_maxPos[j] + lm_signal->distVec[distBSIdx[j]], lm_signal->R2Mat[distBSIdx[j]][r_maxPos[j]], lm_signal->slopeMat[distBSIdx[j]][r_maxPos[j]]);
//							BSVec.push_back(newBS);
						}
						if (lm_signal->slopeMat[distBSIdx[j]][r_maxPos[j]] > maxSlope)
							maxSlope = lm_signal->slopeMat[distBSIdx[j]][r_maxPos[j]];
					}
				}
			}
		}
	}
}
示例#17
0
void reads::detectBS()
{
	param.fragLengthMean += param.smoothArm; // add the soomth arm to the average length
	//param.fragLengthVar  = param.fragLengthMean * param.fragLengthMean / 8.0;
	param.fragLengthVar  = param.fragLengthMean * param.fragLengthMean / 10.0;
	//param.fragLengthVar  = param.fragLengthMean * 20.0;
	param.lmLength = (int) (0.8 * param.fragLengthMean);
	param.lmArm = param.lmLength / 2;
	vector<int> f_maxPos, r_maxPos;
	vector<double> f_max, r_max, tmp, tmp2;
	//double R2_theshold = param.R2_cutoff;
	int i, j;
	int totalRC = readsClusterVec.size();
	//int arm = param.smoothArm + param.lmArm;
  int arm;
  if (param.smoothArm > 0) 
	  arm = param.smoothArm + param.lmArm + 5; //param.motifWidth / 4; // add the half motif width for shift the binding site a litter farther from the signal
  else
	  arm = 3 * param.smoothBandwidth + param.lmArm + 5; //param.motifWidth / 4;
	vector<readsCluster> sub_rcv;
	char strand;
	double pval;
	double foldChange;
	double qval1, qval2;
	int chrIdx;
	int pos = 0;
	double R2 = 0;
	double slope = 0;

	if (totalRC == 0)
		return;

	// for linear model
	lm *lm_signal;
	lm_signal = new lm();
	lm_signal->generateX();

	sort(readsClusterVec.begin(), readsClusterVec.end(), mem_fun_ref(&readsCluster::sortByPos));
	for (i=0; i<totalRC; i++)
	{
		strand = readsClusterVec[i].r_strand;
		chrIdx = readsClusterVec[i].r_chrIdx;
		pval = readsClusterVec[i].pval;
		foldChange = readsClusterVec[i].foldChange;
		qval1 = readsClusterVec[i].qval1;
		qval2 = readsClusterVec[i].qval2;
		if (strand == 'f' || strand == '+')
		{

			if (lm_signal->slipSolve(readsClusterVec[i].r_vec, 'f'))
			{
        logVec(lm_signal->slopeVec, tmp);
				multiVec(tmp, lm_signal->R2Vec, tmp2);

        //printf("fwd R2 slope log_slope R2*log_slope vecs:\n");
        //printVec(lm_signal->R2Vec);
        //printVec(lm_signal->slopeVec);
        //printVec(tmp);
        //printVec(tmp2);

				getTopN(tmp2, lm_signal->slopeVec, f_max, f_maxPos, 2, param.motifWidth);
				//getTopN(lm_signal->R2Vec, lm_signal->slopeVec, f_max, f_maxPos, 2, param.motifWidth);
				for (j=0; j<(int)f_maxPos.size(); j++)
				{
					pos = readsClusterVec[i].r_end + arm - f_maxPos[j];
					R2 = lm_signal->R2Vec[f_maxPos[j]];
					slope = lm_signal->slopeVec[f_maxPos[j]];

		      bingdingSite newBS(chrIdx, pos, R2, slope, strand, pval, foldChange, qval1, qval2);
		      BSVec.push_back(newBS);
		      if (slope > maxSlope)
			      maxSlope = slope;
		      if (R2 > maxR2)
			      maxR2 = R2;
		      if (foldChange > maxFC)
			      maxFC = foldChange;

					/*if (lm_signal->R2Vec[f_maxPos[j]] > R2_theshold)
					{
						bingdingSite newBS(readsClusterVec[i].r_chrIdx, readsClusterVec[i].r_end + arm - f_maxPos[j], lm_signal->R2Vec[f_maxPos[j]], lm_signal->slopeVec[f_maxPos[j]], '+');
						//printf("%d\t%d\t%d\t%d\t%f\t%f\t+\n",readsClusterVec[i].r_end, arm, f_maxPos[j], readsClusterVec[i].r_end + arm - f_maxPos[j], lm_signal->R2Vec[f_maxPos[j]], lm_signal->slopeVec[f_maxPos[j]]);
						BSVec.push_back(newBS);
						if (lm_signal->slopeVec[f_maxPos[j]] > maxSlope)
							maxSlope = lm_signal->slopeVec[f_maxPos[j]];
					}*/
				}
			}
		}
		if (strand == 'r' || strand == '-')
		{
			if (lm_signal->slipSolve(readsClusterVec[i].r_vec, 'r'))
			{
        logVec(lm_signal->slopeVec, tmp);
				multiVec(tmp, lm_signal->R2Vec, tmp2);

        //printf("rvs R2 slope log_slope R2*log_slope vecs:\n");
        //printVec(lm_signal->R2Vec);
        //printVec(lm_signal->slopeVec);
        //printVec(tmp);
        //printVec(tmp2);

				getTopN(tmp2, lm_signal->slopeVec, r_max, r_maxPos, 2, param.motifWidth);
				//getTopN(lm_signal->R2Vec, lm_signal->slopeVec, r_max, r_maxPos, 2, param.motifWidth);
				for (j=0; j<(int)r_maxPos.size(); j++)
				{
					pos = readsClusterVec[i].r_start - arm + r_maxPos[j];
					R2 = lm_signal->R2Vec[r_maxPos[j]];
					slope = lm_signal->slopeVec[r_maxPos[j]];

		      bingdingSite newBS(chrIdx, pos, R2, slope, strand, pval, foldChange, qval1, qval2);
		      BSVec.push_back(newBS);
		      if (slope > maxSlope)
			      maxSlope = slope;
		      if (R2 > maxR2)
			      maxR2 = R2;
		      if (foldChange > maxFC)
			      maxFC = foldChange;

					/*if (lm_signal->R2Vec[r_maxPos[j]] > R2_theshold)
					{
						bingdingSite newBS(readsClusterVec[i].r_chrIdx, readsClusterVec[i].r_start - arm + r_maxPos[j], lm_signal->R2Vec[r_maxPos[j]], lm_signal->slopeVec[r_maxPos[j]], '-');
						//printf("%d\t%d\t%d\t%d\t%f\t%f\t-\n",readsClusterVec[i].r_start, arm, r_maxPos[j], readsClusterVec[i].r_start - arm + r_maxPos[j], lm_signal->R2Vec[r_maxPos[j]], lm_signal->slopeVec[r_maxPos[j]]);
						BSVec.push_back(newBS);
						if (lm_signal->slopeVec[r_maxPos[j]] > maxSlope)
							maxSlope = lm_signal->slopeVec[r_maxPos[j]];
					}*/
				}
			}
		}
		//chrIdx(chrIdx), pos(pos), R2(R2), slope(slope), strand(strand), pval(pval), foldChange(foldChange),qval(qval)

		/*if (param.VERBOSE && i % 100 == 0)
			printf("  %.2f%% done...\r", 100.0 * (double) i / (double) totalRC);*/
	}
}
示例#18
0
HRESULT KG3DScenePvsEditor::RenderForMainWindow(KG3DSceneOutputWnd& wndCur)
{
	KG3DSceneOutputWnd* pWnd = &wndCur;
    KG3DRenderState RenderState;

    D3DXVECTOR3 vPlacePos;
    D3DXMATRIX  matProj;
    D3DXMATRIX  matView;

    KG3DRepresentObjectPVS* pPvs = m_pPvs;

    ProcessSpaceNodeByCamera(&pWnd->GetCamera());
    CalcFrustum(&pWnd->GetCamera());

    if (KG3DSceneSpaceNode::GetTopVisableNode() != g_cGraphicsTool.GetCurScene()->m_lpSceneOutDoorSpaceMgr)
        pPvs = static_cast<KG3DRepresentObjectPVS*>(KG3DSceneSpaceNode::GetTopVisableNode());
    
    if (pPvs)
        pPvs->UpdateVisiableSubset(NULL);

    if (m_bRunMode && m_pRunder)
    {
        KG3DTrackCamera* pTrackCamera = pWnd->GetCamera().GetTrackCameraInterface();

        D3DXVECTOR3 vecNpcPos;
        D3DXVECTOR3 vecNpcDir;

        m_pRunder->GetCurPosition(&vecNpcPos);
        m_pRunder->GetDirection(&vecNpcDir);
        vecNpcPos = vecNpcPos + D3DXVECTOR3(0.0f, 180.0f, 0.0f);

        pTrackCamera->BindScene(this);
        pTrackCamera->UpdateAsClient(vecNpcPos, vecNpcDir, m_pRunder->m_fMoveSpeed, m_pRunder->m_dwMovementType);
        pTrackCamera->FrameMove();
    }
    else
        TrackCamareFrameMove();

    if (m_lpPointLightRender)
        m_lpPointLightRender->FrameMove();

    RenderWindowBegin(pWnd,TRUE);

	if(m_lpLightMapBaker && m_lpLightMapBaker->m_bShowDebug)
	{
		m_lpLightMapBaker->ShowDebug();
	}
	else
	{
		RenderState.SetSamplerState(0, D3DSAMP_MAGFILTER, (D3DTEXTUREFILTERTYPE)g_cEngineOption.nSampMagFilter);
		RenderState.SetSamplerState(0, D3DSAMP_MINFILTER, (D3DTEXTUREFILTERTYPE)g_cEngineOption.nSampMinFilter);
		RenderState.SetSamplerState(0, D3DSAMP_MIPFILTER, (D3DTEXTUREFILTERTYPE)g_cEngineOption.nSampMipFilter);
		RenderState.SetSamplerState(0, D3DSAMP_MAXANISOTROPY ,g_cEngineOption.dwMaxAnisotropy);
		RenderState.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
		RenderState.SetRenderState(D3DRS_ZENABLE, TRUE);

		g_cGraphicsTool.ApplyLight(*this);

		g_SetShaderSharedParams(*this, wndCur, NULL, NULL);//这个没有ConverMap
		if (m_pPvs)
		{
			m_pPvs->FrameMove();
			m_pPvs->RenderHierarchy(m_bCull, m_lpPointLightRender);
		}

		if (m_pHandObj)
		{
			if (GetPlaceObjectPos(vPlacePos, pWnd))
				m_pHandObj->SetTranslation(&vPlacePos);
			m_pHandObj->FrameMove();
			m_pHandObj->RenderHierarchy();
		}

		if (m_pHandPtl)
		{
			D3DXVECTOR3 vScal = D3DXVECTOR3(1.f, 1.f, 1.f);
			D3DXMATRIX  matLocal;
			D3DXMATRIX  matScal;

			D3DXMatrixIdentity(&matLocal);

			switch (m_dwPlacePortalMode)
			{
			case PLACE_PTL_BILLBOARD :    
				*((D3DXVECTOR3*)&matLocal.m[0]) = pWnd->GetCamera().GetCameraRight();
				*((D3DXVECTOR3*)&matLocal.m[1]) = pWnd->GetCamera().GetCameraUp();
				*((D3DXVECTOR3*)&matLocal.m[2]) = pWnd->GetCamera().GetCameraFront();
				break;
			case PLACE_PTL_LOCK_Y :
				*((D3DXVECTOR3*)&matLocal.m[0]) = pWnd->GetCamera().GetCameraRight();
				*((D3DXVECTOR3*)&matLocal.m[1]) = D3DXVECTOR3(0.f, 1.f, 0.f);
				D3DXVec3Cross((D3DXVECTOR3*)&matLocal.m[2], (D3DXVECTOR3*)&matLocal.m[0], (D3DXVECTOR3*)&matLocal.m[1]);
				break;
			case PLACE_PTL_HOR :
				*((D3DXVECTOR3*)&matLocal.m[0]) = D3DXVECTOR3(1.f, 0.f, 0.f);
				*((D3DXVECTOR3*)&matLocal.m[1]) = D3DXVECTOR3(0.f, 0.f, 1.f);
				*((D3DXVECTOR3*)&matLocal.m[2]) = D3DXVECTOR3(0.f, -1.f, 0.f);
				break;
			default :
				break;
			}

			if (GetPlacePortalPos(vPlacePos, pWnd, m_pHandPtl))
				*((D3DXVECTOR3*)&matLocal.m[3]) = vPlacePos;

			m_pHandPtl->GetScaling(&vScal);
			D3DXMatrixScaling(&matScal, vScal.x, vScal.y, vScal.z);

			matLocal = matScal * matLocal;

			m_pHandPtl->UpdateByMatrix(matLocal);

			m_pHandPtl->FrameMove();
			m_pHandPtl->Render(0x550000ff);
		}

		if (m_bRunMode && m_pRunder)
		{
			//m_pRunder->NPCFrameMove();

			_ASSERTE(NULL != m_pRunder);
			KSF::FrameMoveSceneRunner(*m_pRunder, *this);

			m_pRunder->RenderHierarchy();
		}

		if (m_pPvs)
			m_pPvs->Render(0x550000ff);

		for_each(m_listRenderEntity.begin(), m_listRenderEntity.end(), mem_fun_ref(&KG3DSceneEntity::Render));
		//////////////////////////////////////////////////////////////////////////
		if(m_lpLightMapBaker)
			m_lpLightMapBaker->Render();

		matProj = m_SceneWndManager->GetCurOutputWnd()->GetCamera().GetProjectionMatrix();
		matView = m_SceneWndManager->GetCurOutputWnd()->GetCamera().GetViewMatrix();

		if (!m_bRunMode)
			RenderSelectedEntityMark(this->GetEditState(), m_SceneWndManager->GetCurOutputWnd()->m_Viewport, matProj, matView, TRUE);

		DrawGroundGrid();
		DrawInfo();

		if (g_cEngineManager.GetFocusScene() == this)
		{
			g_cGraphicsTool.DrawFocusRect(
				m_SceneWndManager->GetCurOutputWnd()->m_Viewport, 
				4,
				0xFFFFFF00
				);
		}


		GetEnvironment().Render();
	}

    RenderWindowEnd(pWnd);

    if (m_pPvs)
        m_pPvs->ClearFrustums();

    return S_OK;
}
示例#19
0
文件: ptrmem12.C 项目: 0day-ci/gcc
void f()
{
  mem_fun_ref(&A::f);
}