Ejemplo n.º 1
0
tstring GetModulePath( HMODULE hm /*= NULL*/ )
{
	std::vector< wchar_t > vTemp( MAX_PATH+1, 0 );
	::GetModuleFileName( hm, &vTemp[0], MAX_PATH );

	return &vTemp[0];
}
Ejemplo n.º 2
0
wstring UTF8toUTF16( string strUTF8 )
{
	if ( strUTF8.empty() )
	{
		return L"";
	}

	std::vector< wchar_t > vTemp( strUTF8.length()+1, 0 );
	MultiByteToWideChar( CP_UTF8, 0, strUTF8.c_str(), strUTF8.length(), &vTemp[0], strUTF8.length() );

	return &vTemp[0];
}
Ejemplo n.º 3
0
// initializes the rays that have previously been declared
void Camera::generateImagePlane(){

	//generate u,v,w
	//set w to be exactly opposite of the viewing direction, and make sure it is normalized
	wVec = -d.normalize();

	// create a temporary vector for 'up'
	Vector4d vTemp(0,1,0);
	//set v to be perpendicular to w and the 'up' vector
	uVec = vTemp.crossProduct(wVec).normalize();
	
	//finally, set u to be perpendicular to both v and w.  This should be roughly representative of the 'up' vector, but part of the orthonormal basis.
	vVec = wVec.crossProduct(uVec).normalize();

	//compute l, r, b, & t
	
	//calculate modifier for field of view first...
	float pi = std::atan(1.0f) * 4.0f;
	
	float fovMod = tan(fov*pi/(2*180));

	//cout << "Fov Mod = " << fovMod << endl;

	r = ((float)width/(float)height) * fovMod * (focalLength);
	l = -r;
	t = fovMod * (focalLength);
	b = -t;
	
	//delcare u & v, the pixel locations for the current pixel
	float u, v;
	Vector4d tempVector;
	srand48 (time (0));
	
	for (int heightCounter = 0; heightCounter < height * sampleMultiplier; heightCounter++){
		for (int widthCounter = 0; widthCounter < width * sampleMultiplier; widthCounter++){

			u = l + (r - l)*(widthCounter + (drand48() - 0.5))/(width * sampleMultiplier);			
			v = b + (t - b)*(heightCounter + (drand48() - 0.5))/(height * sampleMultiplier);
			
			//set ray direction
			tempVector = Vector4d(wVec*(-focalLength) + uVec * u + vVec * v).normalize();

			//set ray origin
			rays[width * sampleMultiplier * heightCounter + widthCounter] = Ray4d(e, tempVector);
			rays[width * sampleMultiplier * heightCounter + widthCounter].sampleX = heightCounter % sampleMultiplier;
			rays[width * sampleMultiplier * heightCounter + widthCounter].sampleY = widthCounter % sampleMultiplier;
			rays[width * sampleMultiplier * heightCounter + widthCounter].maxSampleX = sampleMultiplier;
			rays[width * sampleMultiplier * heightCounter + widthCounter].maxSampleY = sampleMultiplier;
		}	
	}
}
Ejemplo n.º 4
0
void CDFisMatrix::CalcFmDR()
{
	////////////////////// Wielandt¡¯s deflation ///////////////////////
	int nTot_mesh_num = p_vFisMatrix.size();
	vector<double> vTemp(nTot_mesh_num);

	int nIndex = 0;
	int j = 0;
	for(j = 0;j < nTot_mesh_num; ++j)  
	{
	    if(p_vEigVec[j] == 1)
		{
			nIndex = j;
			break;
		}
	}
	if(j >= nTot_mesh_num)
	{
		printf("Wrong deflation.\n");
	}

	for(int j = 0;j < nTot_mesh_num; ++j)  
	{
		vTemp[j] = p_vFisMatrix[nIndex][j];
	}
	for(int i = 0;i < nTot_mesh_num; ++i)  
	{
		for(int j = 0;j < nTot_mesh_num; ++j)
		{
			p_vFisMatrix[i][j] = p_vFisMatrix[i][j] -   p_vEigVec[i] *  vTemp[j];
		}
	}

	p_vFisMatrix.erase(p_vFisMatrix.begin() + nIndex);
	for(int i = 0;i < nTot_mesh_num - 1; ++i)
	{
		p_vFisMatrix[i].erase(p_vFisMatrix[i].begin() + nIndex );
	}

	///////////// Calculate K1 and S1 by power iteration /////////////////
	double dEigValTemp = 0;
	vector<double> vEigVecTemp;
	GlobeFunFsc::CalcEigVec(p_vFisMatrix,dEigValTemp,vEigVecTemp); 

	/////////// Obtain DR /////////
	p_dDR = dEigValTemp/p_dEigVal;

	//printf("DR = %f/%f = %f\n",EigValTemp,EigVal,DR);
	return;
}
Ejemplo n.º 5
0
void CProfileReader::ModifyModelInfo(CMesh *pTerrain)
{
    D3DXVECTOR3 vTemp(0,1000,0);
    pTerrain->InterSect(&(m_hallInfo.vPos+vTemp), &D3DXVECTOR3(0,-1,0), &m_hallInfo.vPos,INTERSECT_NEGATIVEY);
    m_hallInfo.vLook.y = m_hallInfo.vPos.y;
    pTerrain->InterSect(&(m_LJInfo.vPos+vTemp), &D3DXVECTOR3(0,-1,0), &m_LJInfo.vPos,INTERSECT_NEGATIVEY);
    m_LJInfo.vLook.y = m_LJInfo.vPos.y;
    pTerrain->InterSect(&(m_bikeInfo.vPos+vTemp), &D3DXVECTOR3(0,-1,0), &m_bikeInfo.vPos,INTERSECT_NEGATIVEY);
    m_bikeInfo.vLook.y = m_bikeInfo.vPos.y;
    pTerrain->InterSect(&(m_smallCarInfo.vPos+vTemp), &D3DXVECTOR3(0,-1,0), &m_smallCarInfo.vPos,INTERSECT_NEGATIVEY);
    m_smallCarInfo.vLook.y = m_smallCarInfo.vPos.y;
    pTerrain->InterSect(&(m_bigCarInfo.vPos+vTemp), &D3DXVECTOR3(0,-1,0), &m_bigCarInfo.vPos,INTERSECT_NEGATIVEY);
    m_bigCarInfo.vLook.y = m_bigCarInfo.vPos.y;
    pTerrain->InterSect(&(m_busInfo.vPos+vTemp), &D3DXVECTOR3(0,-1,0), &m_busInfo.vPos,INTERSECT_NEGATIVEY);
    m_busInfo.vLook.y = m_busInfo.vPos.y;

}
Ejemplo n.º 6
0
string UTF16toUTF8( wstring strUTF16 )
{
	if ( strUTF16.empty() )
	{
		return "";
	}

	int nLen8 = WideCharToMultiByte( CP_UTF8, 0, strUTF16.c_str(), strUTF16.length(), 0, 0, 0, 0 );
	if ( 0 == nLen8 )
	{
		return "";
	}

	std::vector<char> vTemp( nLen8+1, 0 );
	WideCharToMultiByte( CP_UTF8, 0, strUTF16.c_str(), strUTF16.length(), &vTemp[0], nLen8, 0, 0 );

	return &vTemp[0];
}
Ejemplo n.º 7
0
void QuadraticRegressorTrainer::SetData (Mat* pmExamples, Vec* pvObj)
{
	int nInNum = pmExamples->Cols();
	int nConNum = nInNum * 2 + nInNum*(nInNum-1) / 2 + 1;
	
	m_pmData = new Mat(pmExamples->Rows(), nConNum, MAT_Tdouble);
	int i, j;
	for (i = 0; i < pmExamples->Rows(); i ++)
	{
		Vec vTemp(pmExamples->data.db[i], nInNum, MAT_Tdouble);
		Vec* pvConverted = QuadraticRegressor::iConvert(&vTemp);
		for (j = 0; j < nConNum-1; j ++)
			m_pmData->data.db[i][j] = pvConverted->data.db[j];
		m_pmData->data.db[i][j] = 1;
	}
	m_pvObj = new Vec(pmExamples->Rows(), MAT_Tdouble);
	memcpy (m_pvObj->data.db, pvObj->data.db, sizeof(double)*pmExamples->Rows());
}
Ejemplo n.º 8
0
/**
* CAIGroup::disband
* @date Modified April 26, 2006
*/
void CAIGroup::disband(bool bDisperse)
{
	std::list<CEnemy*>::iterator oEnemyIter = m_loEnemies.begin();
	CAIStatePathPlan* poPlan = CAIStatePathPlan::getInstancePtr();

	// for dispersal
	CAIStateMove* poMove = NULL;
	D3DXVECTOR3 vFrontBack(0.0f, 0.0f, 0.0f), vLeftRight(0.0f, 0.0f, 0.0f), vTemp(0.0f, 0.0f, 0.0f);
	CAINode* poGoalNode = NULL;
	float fDot = 0.0f;

	// if the enemies are to disperse, this information is needed
	if (bDisperse)
	{
		poMove = CAIStateMove::getInstancePtr();

		calculateAvgPos();
		poGoalNode = CAIManager::getInstancePtr()->findBestGoal(*oEnemyIter);
		// calculate vectors to perform a halfspace tests to determine members' position in the group
		D3DXVec3Subtract(&vFrontBack, &poGoalNode->getPosition(), &m_vAvgPos);
		D3DXVec3Normalize(NULL, &vFrontBack, &vFrontBack);
		D3DXVec3Cross(&vLeftRight, &D3DXVECTOR3(0.0f, 1.0f, 0.0f), &vLeftRight);
		D3DXVec3Normalize(NULL, &vLeftRight, &vLeftRight);
	}

	while (oEnemyIter != m_loEnemies.end())
	{
		(*oEnemyIter)->getAI()->setGroup(NULL);

		if (bDisperse)
		{
			if ((*oEnemyIter)->getType() == OBJ_ENEMY_ZOMBIECITIZEN)
			{
				D3DXVec3Subtract(&vTemp, &ENEMY_PTR(oEnemyIter)->getBV().centerPt, &m_vAvgPos);
				D3DXVec3Normalize(NULL, &vTemp, &vTemp);
				fDot = D3DXVec3Dot(&vTemp, &vFrontBack);

				// if this enemy is in back send him straight to the goal
				if (fDot <= 0.0f)
				{
					(*oEnemyIter)->setAIState(poPlan);
				}
				// if this enemy is in front, make him move forward
				else
				{
					ENEMY_PTR(oEnemyIter)->setOrientation(vTemp);
					D3DXVec3Scale(&vTemp, &vFrontBack, 10.0f);
					ENEMY_PTR(oEnemyIter)->setVelocity(vTemp);
					(*oEnemyIter)->setAIState(poMove);
				}
			}
			else
			{
				(*oEnemyIter)->setAIState(poPlan);
			}

		}
		else
		{
			(*oEnemyIter)->setAIState(poPlan);
		}
		
		oEnemyIter = m_loEnemies.erase(oEnemyIter);
	}
}
Ejemplo n.º 9
0
 //-----------------------------------------------------------------------
 void Camera::lookAt( Real x, Real y, Real z )
 {
     Vector3 vTemp( x, y, z );
     this->lookAt(vTemp);
 }
Ejemplo n.º 10
0
// This routine set up the IloCplex algorithm to solve the worker LP, and
// creates the worker LP (i.e., the dual of flow constraints and
// capacity constraints of the flow MILP)
//
// Modeling variables:
// forall k in V0, i in V:
//    u(k,i) = dual variable associated with flow constraint (k,i)
//
// forall k in V0, forall (i,j) in A:
//    v(k,i,j) = dual variable associated with capacity constraint (k,i,j)
//
// Objective:
// minimize sum(k in V0) sum((i,j) in A) x(i,j) * v(k,i,j)
//          - sum(k in V0) u(k,0) + sum(k in V0) u(k,k)
//
// Constraints:
// forall k in V0, forall (i,j) in A: u(k,i) - u(k,j) <= v(k,i,j)
//
// Nonnegativity on variables v(k,i,j)
// forall k in V0, forall (i,j) in A: v(k,i,j) >= 0
//
void
createWorkerLP(IloCplex cplex, IloNumVarArray v, IloNumVarArray u, 
               IloObjective obj, IloInt numNodes)
{

   IloInt i, j, k;
   IloEnv env = cplex.getEnv();
   IloModel mod(env, "atsp_worker"); 

   // Set up IloCplex algorithm to solve the worker LP

   cplex.extract(mod);
   cplex.setOut(env.getNullStream());
      
   // Turn off the presolve reductions and set the CPLEX optimizer
   // to solve the worker LP with primal simplex method.

   cplex.setParam(IloCplex::Reduce, 0);
   cplex.setParam(IloCplex::RootAlg, IloCplex::Primal); 
   
   // Create variables v(k,i,j) forall k in V0, (i,j) in A
   // For simplicity, also dummy variables v(k,i,i) are created.
   // Those variables are fixed to 0 and do not partecipate to 
   // the constraints.

   IloInt numArcs  = numNodes * numNodes;
   IloInt vNumVars = (numNodes-1) * numArcs;
   IloNumVarArray vTemp(env, vNumVars, 0, IloInfinity);
   for (k = 1; k < numNodes; ++k) {
      for (i = 0; i < numNodes; ++i) {
         vTemp[(k-1)*numArcs + i *numNodes + i].setBounds(0, 0);
      }
   }
   v.clear();
   v.add(vTemp);
   vTemp.end();
   mod.add(v);

   // Set names for variables v(k,i,j) 

   for (k = 1; k < numNodes; ++k) {
      for(i = 0; i < numNodes; ++i) {
         for(j = 0; j < numNodes; ++j) {
            char varName[100];
            sprintf(varName, "v.%d.%d.%d", (int) k, (int) i, (int) j); 
            v[(k-1)*numArcs + i*numNodes + j].setName(varName);
         }
      }
   }
   
   // Associate indices to variables v(k,i,j)

   IloIntArray vIndex(env, vNumVars);
   for (j = 0; j < vNumVars; ++j)
   {
      vIndex[j] = j;
      v[j].setObject(&vIndex[j]);
   }

   // Create variables u(k,i) forall k in V0, i in V

   IloInt uNumVars = (numNodes-1) * numNodes;
   IloNumVarArray uTemp(env, uNumVars, -IloInfinity, IloInfinity);
   u.clear();
   u.add(uTemp);
   uTemp.end();
   mod.add(u);

   // Set names for variables u(k,i) 

   for (k = 1; k < numNodes; ++k) {
      for(i = 0; i < numNodes; ++i) {
         char varName[100];
         sprintf(varName, "u.%d.%d", (int) k, (int) i); 
         u[(k-1)*numNodes + i].setName(varName);
      }
   }

   // Associate indices to variables u(k,i)

   IloIntArray uIndex(env, uNumVars);
   for (j = 0; j < uNumVars; ++j)
   {
      uIndex[j] = vNumVars + j;
      u[j].setObject(&uIndex[j]);
   }

   // Initial objective function is empty

   obj.setSense(IloObjective::Minimize);
   mod.add(obj);

   // Add constraints:
   // forall k in V0, forall (i,j) in A: u(k,i) - u(k,j) <= v(k,i,j)

   for (k = 1; k < numNodes; ++k) {
      for(i = 0; i < numNodes; ++i) {
         for(j = 0; j < numNodes; ++j) {
            if ( i != j ) {
               IloExpr expr(env);
               expr -= v[(k-1)*numArcs + i*(numNodes) + j];
               expr += u[(k-1)*numNodes + i];
               expr -= u[(k-1)*numNodes + j];
               mod.add(expr <= 0);
               expr.end();
            }
         }
      }
   }

}// END createWorkerLP
Ejemplo n.º 11
0
HRESULT CConnect::OnConnection(LPDISPATCH Application, ext_ConnectMode ConnectMode, LPDISPATCH AddInInst, SAFEARRAY **custom)
{
	TSAUTO();
	Application->QueryInterface(__uuidof(IDispatch), reinterpret_cast<LPVOID*>(&this->m_spApplication));
	AddInInst->QueryInterface(__uuidof(IDispatch), reinterpret_cast<LPVOID*>(&this->m_spAddInInstance));
	//是否显示按钮
	CRegKey key;
	DWORD dwValue;
	if(key.Open(HKEY_CURRENT_USER, _T("Software\\WordEncLock")) == ERROR_SUCCESS){
		if (key.QueryValue(dwValue, _T("silent")) == ERROR_SUCCESS){
			if (dwValue == 1){
				g_sIsSilent = TRUE;
			}
		}
	}
	key.Close();
	if (g_sIsSilent){
		return S_OK;
	}
	CComQIPtr<_Application> spApp(Application);
	ATLASSERT(spApp);
	if (!spApp){//获取失败说明是excel
		//g_sIsSilent = TRUE;
		return S_OK;
	}
	g_Application = spApp;
	
	HRESULT hr;
	CComPtr<Office::_CommandBars>  spCmdBars; 
	hr =  g_Application->get_CommandBars(&spCmdBars);
	if(FAILED(hr))
		return hr;
	ATLASSERT(spCmdBars);

	// now we add a new toolband to Word
	// to which we''ll add 2 buttons
	CComVariant vName("");
	CComPtr<Office::CommandBar> spNewCmdBar;

	CComVariant vPos(1); 
	CComVariant vTemp(VARIANT_TRUE); // menu is temporary        
	CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);            
	spNewCmdBar = spCmdBars->Add(vName, vPos, vEmpty, vTemp);

	CComPtr < Office::CommandBarControls> spBarControls;
	spBarControls = spNewCmdBar->GetControls();
	ATLASSERT(spBarControls);


	CComVariant vToolBarType(1);
	CComVariant vShow(VARIANT_TRUE);
	CComPtr<Office::CommandBarControl>  spNewBar; 

	// add first button
	spNewBar = spBarControls->Add(vToolBarType,vEmpty,vEmpty,vEmpty,vShow); 
	ATLASSERT(spNewBar);

	CComQIPtr < Office::_CommandBarButton> spCmdButton(spNewBar);

	ATLASSERT(spCmdButton);
	m_spButton = spCmdButton;
	AppEvents::DispEventAdvise(m_spButton);

	HBITMAP hBmp =(HBITMAP)::LoadImage(g_hModule,
		MAKEINTRESOURCE(IDB_BITMAP1),IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS);
	::OpenClipboard(NULL);
	::EmptyClipboard();
	::SetClipboardData(CF_BITMAP, (HANDLE)hBmp);
	::CloseClipboard();
	::DeleteObject(hBmp);        

	spCmdButton->PutStyle(Office::msoButtonIconAndWrapCaption);
	hr = spCmdButton->PasteFace();
	if (FAILED(hr))
		return hr;
	spCmdButton->PutVisible(VARIANT_TRUE); 
	spCmdButton->PutCaption(OLESTR("Word安全锁")); 
	spCmdButton->PutEnabled(VARIANT_TRUE);
	spCmdButton->PutTooltipText(OLESTR("Word安全锁")); 
	spCmdButton->PutTag(OLESTR("给Word文档加密")); 
	spNewCmdBar->PutVisible(VARIANT_TRUE); 
	return S_OK;
}
Ejemplo n.º 12
0
void GrayScott::step()
{
    // update step
    if (world.rank == 0) {
        ++currStep_;
    }
    
    
    MPI_Request request[8];
    MPI_Status status[8];
    
    // exchange boundaries along y-direction
    if (world.coord_x % 2 == 0) { // first send top, then botton
        
        MPI_Isend(&u_[(Nx_loc)*(Ny_loc)],   1, bottom_boundary, world.bottom_proc, TAG, cart_comm, &request[0]);
        MPI_Irecv(&u_[(Nx_loc+1)*(Ny_loc)], 1, bottom_boundary, world.bottom_proc, TAG, cart_comm, &request[1]);
        MPI_Isend(&u_[(Ny_loc)],            1, top_boundary,    world.top_proc,    TAG, cart_comm, &request[2]);
        MPI_Irecv(&u_[0],                   1, top_boundary,    world.top_proc,    TAG, cart_comm, &request[3]);
        
        MPI_Isend(&v_[(Nx_loc)*(Ny_loc)],   1, bottom_boundary, world.bottom_proc, TAG, cart_comm, &request[4]);
        MPI_Irecv(&v_[(Nx_loc+1)*(Ny_loc)], 1, bottom_boundary, world.bottom_proc, TAG, cart_comm, &request[5]);
        MPI_Isend(&v_[(Ny_loc)],            1, top_boundary,    world.top_proc,    TAG, cart_comm, &request[6]);
        MPI_Irecv(&v_[0],                   1, top_boundary,    world.top_proc,    TAG, cart_comm, &request[7]);
    }
    else { // first send botton, then top
        
        MPI_Irecv(&u_[0],                   1, top_boundary,    world.top_proc,    TAG, cart_comm, &request[0]);
        MPI_Isend(&u_[(Ny_loc)],            1, top_boundary,    world.top_proc,    TAG, cart_comm, &request[1]);
        MPI_Irecv(&u_[(Nx_loc+1)*(Ny_loc)], 1, bottom_boundary, world.bottom_proc, TAG, cart_comm, &request[2]);
        MPI_Isend(&u_[(Nx_loc)*(Ny_loc)],   1, bottom_boundary, world.bottom_proc, TAG, cart_comm, &request[3]);
        
        MPI_Irecv(&v_[0],                   1, top_boundary,    world.top_proc,    TAG, cart_comm, &request[4]);
        MPI_Isend(&v_[(Ny_loc)],            1, top_boundary,    world.top_proc,    TAG, cart_comm, &request[5]);
        MPI_Irecv(&v_[(Nx_loc+1)*(Ny_loc)], 1, bottom_boundary, world.bottom_proc, TAG, cart_comm, &request[6]);
        MPI_Isend(&v_[(Nx_loc)*(Ny_loc)],   1, bottom_boundary, world.bottom_proc, TAG, cart_comm, &request[7]);
    }
    
    
    
    
    // u and v at the half step
    std::vector<double> uTemp(u_.size());
    std::vector<double> vTemp(v_.size());
    
    // right hand sides for u and for v
    std::vector<double> uRhs(N_);
    std::vector<double> vRhs(N_);
    
    
    
    
    /****************** DIFFUSION (ADI) ***************************************/
    
    // perform the first half-step
    // loop over all rows
    
    
    // parallelize outer loop (y-direction) with mpi, inner loop with openmp (TODO)
    
    // inner grid points
    #pragma omp parallel num_threads(nthreads_)
    {
    std::vector<double> puRhs(N_);
    std::vector<double> pvRhs(N_);
    #pragma omp for
    for (int i=1; i<Nx_loc-1; ++i) {
        // create right-hand side of the systems
        for (int j=0; j<N_; ++j) {
            puRhs[j] = U(i,j) + uCoeff * (U(i+1,j) - 2.*U(i,j) + U(i-1,j));
            pvRhs[j] = V(i,j) + vCoeff * (V(i+1,j) - 2.*V(i,j) + V(i-1,j));
        }
        
        TriDiagMatrixSolver::solve(N_, matU1_, puRhs, &UTEMP(i,0), 1);
        TriDiagMatrixSolver::solve(N_, matV1_, pvRhs, &VTEMP(i,0), 1);
    }
    } // omp parallel
    
    
    
    // wait for boundaries to arrive
    MPI_Waitall(8,request,status);
    
    
    // update local boundaries

    if (world.rank == 0) {
        // i=0 local and global
        for (int j=0; j<N_; ++j) {
            uRhs[j] = U(0,j) + uCoeff * (U(1,j) - U(0,j));
            vRhs[j] = V(0,j) + vCoeff * (V(1,j) - V(0,j));
        }
        TriDiagMatrixSolver::solve(N_, matU1_, uRhs, &UTEMP(0,0), 1);
        TriDiagMatrixSolver::solve(N_, matV1_, vRhs, &VTEMP(0,0), 1);
    }
    else {
        // i=0 local
        for (int j=0; j<N_; ++j) {
            uRhs[j] = U(0,j) + uCoeff * (U(0+1,j) - 2.*U(0,j) + U(0-1,j));
            vRhs[j] = V(0,j) + vCoeff * (V(0+1,j) - 2.*V(0,j) + V(0-1,j));
        }
        
        TriDiagMatrixSolver::solve(N_, matU1_, uRhs, &UTEMP(0,0), 1);
        TriDiagMatrixSolver::solve(N_, matV1_, vRhs, &VTEMP(0,0), 1);
    }
    
    
    if (world.rank == world.size-1) {
        // i=Nx_loc-1 local and i=N_-1 global
        for (int j=0; j<N_; ++j) {
            uRhs[j] = U(Nx_loc-1,j) + uCoeff * (- U(Nx_loc-1,j) + U(Nx_loc-2,j));
            vRhs[j] = V(Nx_loc-1,j) + vCoeff * (- V(Nx_loc-1,j) + V(Nx_loc-2,j));
        }
        TriDiagMatrixSolver::solve(N_, matU1_, uRhs, &UTEMP(Nx_loc-1,0), 1);
        TriDiagMatrixSolver::solve(N_, matV1_, vRhs, &VTEMP(Nx_loc-1,0), 1);
    }
    else {
        // i=Nx_loc-1 local
        for (int j=0; j<N_; ++j) {
            uRhs[j] = U(Nx_loc-1,j) + uCoeff * (U(Nx_loc-1+1,j) - 2.*U(Nx_loc-1,j) + U(Nx_loc-1-1,j));
            vRhs[j] = V(Nx_loc-1,j) + vCoeff * (V(Nx_loc-1+1,j) - 2.*V(Nx_loc-1,j) + V(Nx_loc-1-1,j));
        }
        
        TriDiagMatrixSolver::solve(N_, matU1_, uRhs, &UTEMP(Nx_loc-1,0), 1);
        TriDiagMatrixSolver::solve(N_, matV1_, vRhs, &VTEMP(Nx_loc-1,0), 1);
    }
    
    
    MPI_Barrier(MPI_COMM_WORLD);
    
    
    // transpose matrix
    
    // TODO either send-datatype also for recieve and then local transpose, or recv-datatype
    // -> test which faster
    
    // transpose global blocks (send from uTemp to u_)
    // start at Ny_loc, because we ignore the ghost cells
    
    if (localtranspose_) {
        MPI_Alltoall(&uTemp[Ny_loc], 1, block_resized_send, &u_[Ny_loc], 1, block_resized_send, MPI_COMM_WORLD);
        MPI_Alltoall(&vTemp[Ny_loc], 1, block_resized_send, &v_[Ny_loc], 1, block_resized_send, MPI_COMM_WORLD);
        
        // locally transpose blocks
        #pragma omp parallel num_threads(nthreads_)// for private(ind1) private(ind2)
        {
        int ind1, ind2;
        #pragma omp for
        for (int b=0; b<Nb_loc; ++b) {
            for (int i=0; i<Nx_loc; ++i) {
                for (int j=0; j<i; ++j) {
                    ind1 = (i+1)*Ny_loc + j + b*Nx_loc; // regular index + offset of block
                    ind2 = (j+1)*Ny_loc + i + b*Nx_loc; // switch i and j
                    
                    std::swap(u_[ind1], u_[ind2]);
                    std::swap(v_[ind1], v_[ind2]);
                }
            }
        }
        } // omp parallel
    }
    else {
        MPI_Alltoall(&uTemp[Ny_loc], 1, block_resized_send, &u_[Ny_loc], 1, block_resized_recv, MPI_COMM_WORLD);
        MPI_Alltoall(&vTemp[Ny_loc], 1, block_resized_send, &v_[Ny_loc], 1, block_resized_recv, MPI_COMM_WORLD);
    }
    


    // exchange new boundaries
    if (world.coord_x % 2 == 0) { // first send top, then bottom
        
        MPI_Isend(&u_[(Nx_loc)*(Ny_loc)],   1, bottom_boundary, world.bottom_proc, TAG, cart_comm, &request[0]);
        MPI_Irecv(&u_[(Nx_loc+1)*(Ny_loc)], 1, bottom_boundary, world.bottom_proc, TAG, cart_comm, &request[1]);
        MPI_Isend(&u_[(Ny_loc)],            1, top_boundary,    world.top_proc,    TAG, cart_comm, &request[2]);
        MPI_Irecv(&u_[0],                   1, top_boundary,    world.top_proc,    TAG, cart_comm, &request[3]);
        
        MPI_Isend(&v_[(Nx_loc)*(Ny_loc)],   1, bottom_boundary, world.bottom_proc, TAG, cart_comm, &request[4]);
        MPI_Irecv(&v_[(Nx_loc+1)*(Ny_loc)], 1, bottom_boundary, world.bottom_proc, TAG, cart_comm, &request[5]);
        MPI_Isend(&v_[(Ny_loc)],            1, top_boundary,    world.top_proc,    TAG, cart_comm, &request[6]);
        MPI_Irecv(&v_[0],                   1, top_boundary,    world.top_proc,    TAG, cart_comm, &request[7]);
    }
    else { // first send bottom, then top
        
        MPI_Irecv(&u_[0],                   1, top_boundary,    world.top_proc,    TAG, cart_comm, &request[0]);
        MPI_Isend(&u_[(Ny_loc)],            1, top_boundary,    world.top_proc,    TAG, cart_comm, &request[1]);
        MPI_Irecv(&u_[(Nx_loc+1)*(Ny_loc)], 1, bottom_boundary, world.bottom_proc, TAG, cart_comm, &request[2]);
        MPI_Isend(&u_[(Nx_loc)*(Ny_loc)],   1, bottom_boundary, world.bottom_proc, TAG, cart_comm, &request[3]);
        
        MPI_Irecv(&v_[0],                   1, top_boundary,    world.top_proc,    TAG, cart_comm, &request[4]);
        MPI_Isend(&v_[(Ny_loc)],            1, top_boundary,    world.top_proc,    TAG, cart_comm, &request[5]);
        MPI_Irecv(&v_[(Nx_loc+1)*(Ny_loc)], 1, bottom_boundary, world.bottom_proc, TAG, cart_comm, &request[6]);
        MPI_Isend(&v_[(Nx_loc)*(Ny_loc)],   1, bottom_boundary, world.bottom_proc, TAG, cart_comm, &request[7]);
    }

    

    // inner grid points
    #pragma omp parallel num_threads(nthreads_)
    {
    std::vector<double> puRhs(N_);
    std::vector<double> pvRhs(N_);
    #pragma omp for
    for (int i=1; i<Nx_loc-1; ++i) {
        // create right-hand side of the systems
        for (int j=0; j<N_; ++j) {
            puRhs[j] = U(i,j) + uCoeff * (U(i+1,j) - 2.*U(i,j) + U(i-1,j));
            pvRhs[j] = V(i,j) + vCoeff * (V(i+1,j) - 2.*V(i,j) + V(i-1,j));
        }
        
        TriDiagMatrixSolver::solve(N_, matU1_, puRhs, &UTEMP(i,0), 1);
        TriDiagMatrixSolver::solve(N_, matV1_, pvRhs, &VTEMP(i,0), 1);
    }
    } // omp parallel
    
    
    // wait for boundaries to arrive
    MPI_Waitall(8,request,status);
    
    
    // update local boundaries

    // top
    if (world.rank == 0) {
        // i=0 local and global
        for (int j=0; j<N_; ++j) {
            uRhs[j] = U(0,j) + uCoeff * (U(1,j) - U(0,j));
            vRhs[j] = V(0,j) + vCoeff * (V(1,j) - V(0,j));
        }
        TriDiagMatrixSolver::solve(N_, matU1_, uRhs, &UTEMP(0,0), 1);
        TriDiagMatrixSolver::solve(N_, matV1_, vRhs, &VTEMP(0,0), 1);
    }
    else {
        // i=0 local, but not globally
        for (int j=0; j<N_; ++j) {
            uRhs[j] = U(0,j) + uCoeff * (U(0+1,j) - 2.*U(0,j) + U(0-1,j));
            vRhs[j] = V(0,j) + vCoeff * (V(0+1,j) - 2.*V(0,j) + V(0-1,j));
        }
        
        TriDiagMatrixSolver::solve(N_, matU1_, uRhs, &UTEMP(0,0), 1);
        TriDiagMatrixSolver::solve(N_, matV1_, vRhs, &VTEMP(0,0), 1);
    }
    
    // bottom
    if (world.rank == world.size-1) {
        // i=Nx_loc-1 local and i=N_-1 global
        for (int j=0; j<N_; ++j) {
            uRhs[j] = U(Nx_loc-1,j) + uCoeff * (- U(Nx_loc-1,j) + U(Nx_loc-2,j));
            vRhs[j] = V(Nx_loc-1,j) + vCoeff * (- V(Nx_loc-1,j) + V(Nx_loc-2,j));
        }
        TriDiagMatrixSolver::solve(N_, matU1_, uRhs, &UTEMP(Nx_loc-1,0), 1);
        TriDiagMatrixSolver::solve(N_, matV1_, vRhs, &VTEMP(Nx_loc-1,0), 1);
    }
    else {
        // i=Nx_loc-1 local
        for (int j=0; j<N_; ++j) {
            uRhs[j] = U(Nx_loc-1,j) + uCoeff * (U(Nx_loc-1+1,j) - 2.*U(Nx_loc-1,j) + U(Nx_loc-1-1,j));
            vRhs[j] = V(Nx_loc-1,j) + vCoeff * (V(Nx_loc-1+1,j) - 2.*V(Nx_loc-1,j) + V(Nx_loc-1-1,j));
        }
        
        TriDiagMatrixSolver::solve(N_, matU1_, uRhs, &UTEMP(Nx_loc-1,0), 1);
        TriDiagMatrixSolver::solve(N_, matV1_, vRhs, &VTEMP(Nx_loc-1,0), 1);
    }
    
    
    
    MPI_Barrier(MPI_COMM_WORLD);
    
    // transpose back
    
    // transpose global blocks (send from uTemp to u_)
    // start at Ny_loc, because we ignore the ghost cells
    
    if (localtranspose_) {
        MPI_Alltoall(&uTemp[Ny_loc], 1, block_resized_send, &u_[Ny_loc], 1, block_resized_send, MPI_COMM_WORLD);
        MPI_Alltoall(&vTemp[Ny_loc], 1, block_resized_send, &v_[Ny_loc], 1, block_resized_send, MPI_COMM_WORLD);
        
        // locally transpose blocks
        #pragma omp parallel num_threads(nthreads_)// for private(ind1) private(ind2)
        {
        int ind1, ind2;
        #pragma omp for
        for (int b=0; b<Nb_loc; ++b) {
            for (int i=0; i<Nx_loc; ++i) {
                for (int j=0; j<i; ++j) {
                    ind1 = (i+1)*Ny_loc + j + b*Nx_loc; // regular index + offset of block
                    ind2 = (j+1)*Ny_loc + i + b*Nx_loc; // switch i and j
                    
                    std::swap(u_[ind1], u_[ind2]);
                    std::swap(v_[ind1], v_[ind2]);
                }
            }
        }
        } // omp parallel
    }
    else {
        MPI_Alltoall(&uTemp[Ny_loc], 1, block_resized_send, &u_[Ny_loc], 1, block_resized_recv, MPI_COMM_WORLD);
        MPI_Alltoall(&vTemp[Ny_loc], 1, block_resized_send, &v_[Ny_loc], 1, block_resized_recv, MPI_COMM_WORLD);
    }
    
    
    
    /****************** REACTION **********************************************/

    #pragma omp parallel num_threads(nthreads_)
    {
    double uind, vind;
    #pragma omp for collapse(2)
    for (int j=0; j<Ny_loc; ++j) {
        for (int i=0; i<Nx_loc; ++i) {
//            const int ind = (i+1)*Ny_loc + j;
//            uind = u_[ind];
//            vind = v_[ind];
//            u_[ind] += dt_ * ( -uind*vind*vind + F_*(1.-uind) );
//            v_[ind] += dt_ * ( uind*vind*vind - (F_+k_)*vind );
            uind = U(i,j);
            vind = V(i,j);
            U(i,j) += dt_ * ( -uind*vind*vind + F_*(1.-uind) );
            V(i,j) += dt_ * ( uind*vind*vind - (F_+k_)*vind );
        }
    }
    } // omp parallel
    
    MPI_Barrier(MPI_COMM_WORLD);
}
Ejemplo n.º 13
0
HRESULT CMyAddin::InstallInterface(IExchExtCallback		*lpExchangeCallback)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	try
	{
		CString csTitle = APP_NAME; // This will be the display-name of the toolbar
		HBITMAP hBmp;

		// First we need to get the active Explorer, you could see this as the active window (it's more to it but let's keep it at that for now)
		Outlook::_ExplorerPtr spExplorer = m_OLAppPtr->ActiveExplorer();
		if (spExplorer == NULL)
		{
			return S_FALSE;
		}

		// Then we need to have a pointer to the commandbars, that is the toolbars in the UI
		Office::_CommandBarsPtr spCmdBars = spExplorer->CommandBars;
		if (spCmdBars == NULL)
		{
			return S_FALSE;
		}

		try 
		{ 
			CComVariant vName(csTitle); // This is the caption of the toolbar
			CComVariant vTemp(TRUE);	
			CComPtr <Office::CommandBar> spToolbar;	
			
			CComVariant vPos(1); 
			//CComVariant vTemp(VARIANT_TRUE); 		
			CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);

			/*spToolbar = spCmdBars->Add(vName,		// Caption
									   vtMissing,   // <ignore this for now>
									   vtMissing,   // <ignore this for now>
									   vTemp);      // The toolbar should be temporary, 
													// that way we have to add it every time we*/
			//spToolbar = spCmdBars->Add(vName,		// Caption
			//						   vPos,   // <ignore this for now>
			//						   vEmpty,   // <ignore this for now>
			//						   vTemp);      // The toolbar should be temporary, 
													// that way we have to add it every time we

			CComPtr <Office::CommandBarControl>  pButton	  = NULL; 
			CComPtr <Office::CommandBarControls> pBarControls = NULL; 

			//pBarControls = spToolbar->GetControls();

			/*m_pToolBar = (Office::CommandBarControlPtr)(pBarControls->Add((long)Office::msoBarFloating, //msoControlButton, 
																	   vtMissing, 
																	   vtMissing, 
																	   vtMissing, 
																	   vTemp));*/			
			
			// get the outlok Context Menu. for this enumerate all the command bars for "Context Menu" command bar			
			CComPtr<Office::CommandBar> pTempBar;
			for(long i = 0; i < spCmdBars->Count ; i++)
			{			
				CComVariant vItem(i+1);		 //zero based index
				pTempBar=NULL;
				spCmdBars->get_Item(vItem,&pTempBar);				
				if((pTempBar) && (!wcscmp(CString(APP_NAME).AllocSysString(),pTempBar->Name)))
				{
					return S_FALSE;
				}		
			}



			m_pToolBar = (Office::CommandBarPtr)(spCmdBars->Add(APP_NAME, vPos, /*Office::msoBarFloating,*/ vtMissing, vTemp));
			pButton = (Office::CommandBarControlPtr)m_pToolBar->Controls->Add(Office::msoControlButton,
																	  vtMissing, vtMissing, vtMissing, vTemp);

			pButton->Caption  = APP_NAME;
			pButton->OnAction = "MyButtonsAction";

			BOOL bSetImage = TRUE;
			// I've set this to FALSE, but if you want an image to appear on the button, 
			// you will need to have an image in the resources.
			// The only drawback of this is that there is only one way of 
			// putting an image on the button, and that is by going through the 
			// clipboard. And by doing so, the contents of the clipboard will be
			// lost, unless you implement some logic to store the clipboard-data
			// before doing this and then restoring the data once the image is on 
			// the button.
			if (bSetImage)
			{
				UINT uiBitmapId = 0;
				CComQIPtr <Office::_CommandBarButton> spCmdButton(pButton);

				// to set a bitmap to a button, load a 32x32 bitmap
				// and copy it to clipboard. Call CommandBarButton's PasteFace()
				// to copy the bitmap to the button face. to use
				// Outlook's set of predefined bitmap, set button's FaceId to 	
				// the button whose bitmap you want to use
				
				hBmp =(HBITMAP)::LoadImage(AfxGetInstanceHandle(),
												   MAKEINTRESOURCE(IDB_BITMAP_PHONE),
												   IMAGE_BITMAP,
												   0,
												   0,
												   LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT);

				if (hBmp)
				{					
					// put bitmap into Clipboard
					::OpenClipboard(NULL);
					::EmptyClipboard();
					::SetClipboardData(CF_BITMAP, (HANDLE)hBmp);
					::CloseClipboard();
					::DeleteObject(hBmp);	

					// set style before setting bitmap
					spCmdButton->PutStyle(Office::msoButtonIconAndCaption);
					if (FAILED(spCmdButton->PasteFace()))
					{
						TRACE("Failed to paste face to button\n");
					}

					
				}/* else {
					char serr[50];
					DWORD err = GetLastError();
					ltoa(err, serr, 10);
					MessageBox(NULL, serr, "error", MB_OK);
				}*/
			}
			// With the button physically added to the toolbar, we just need to 
			// create an object of COutlookButton to sink it's events.
			m_pMyButton = new COutlookButton(pButton);
			m_pMyButton->m_OLAppPtr = m_OLAppPtr;

			// The only thing left to do is to make the toolbar visible.
			//spToolbar->PutVisible(VARIANT_TRUE); 
			LoadToolbarSettings();
		} 
		catch(...)
		{
		}


		// Add menu item

		_bstr_t bstrNewMenuText(CString(APP_NAME).AllocSysString());
		CComPtr < Office::CommandBarControls> spCmdCtrls;
		CComPtr < Office::CommandBarControls> spCmdBarCtrls; 
		CComPtr < Office::CommandBarPopup> spCmdPopup;
		CComPtr < Office::CommandBarControl> spCmdCtrl;
		CComPtr < Office::CommandBar> spCmdBar;

		// get CommandBar that is Outlook's main menu
		HRESULT hr = spCmdBars->get_ActiveMenuBar(&spCmdBar); 
		if (FAILED(hr))
			return S_FALSE; //hr;
		// get menu as CommandBarControls 
		spCmdCtrls = spCmdBar->GetControls(); 
		ATLASSERT(spCmdCtrls);

		// we want to add a menu entry to Outlook's 6th(Tools) menu     //item
		CComVariant vItem(5);
		spCmdCtrl= spCmdCtrls->GetItem(vItem);
		ATLASSERT(spCmdCtrl);
        
		IDispatchPtr spDisp;
		spDisp = spCmdCtrl->GetControl(); 
        
		// a CommandBarPopup interface is the actual menu item
		CComQIPtr < Office::CommandBarPopup> ppCmdPopup(spDisp);  
		ATLASSERT(ppCmdPopup);
            
		spCmdBarCtrls = ppCmdPopup->GetControls();
		ATLASSERT(spCmdBarCtrls);
        
		CComVariant vMenuType(1); // type of control - menu
		CComVariant vMenuPos(6);  
		CComVariant vMenuEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
		CComVariant vMenuShow(VARIANT_TRUE); // menu should be visible
		CComVariant vMenuTemp(VARIANT_TRUE); // menu is temporary        
    
        
		CComPtr < Office::CommandBarControl> spNewMenu;
		// now create the actual menu item and add it
		spNewMenu = spCmdBarCtrls->Add(vMenuType, vMenuEmpty, vMenuEmpty, 
										   vMenuEmpty, vMenuTemp); 
		ATLASSERT(spNewMenu);
            
		spNewMenu->PutCaption(bstrNewMenuText);
		spNewMenu->PutEnabled(VARIANT_TRUE);
		spNewMenu->PutVisible(VARIANT_TRUE); 
		spNewMenu->OnAction = "MyButtonsAction";
    
		//we'd like our new menu item to look cool and display
		// an icon. Get menu item  as a CommandBarButton
		CComQIPtr < Office::_CommandBarButton> spCmdMenuButton(spNewMenu);
		ATLASSERT(spCmdMenuButton);
		spCmdMenuButton->PutStyle(Office::msoButtonIconAndCaption);
    
		// we want to use the same toolbar bitmap for menuitem too.
		// we grab the CommandBarButton interface so we can add
		// a bitmap to it through PasteFace().
		spCmdMenuButton->PasteFace(); 


		// Empty whatever we put in the clipboard
		::OpenClipboard(NULL);
		::EmptyClipboard();
		::CloseClipboard();

		// With the button physically added to the toolbar, we just need to 
		// create an object of COutlookButton to sink it's events.
		m_pMyMenuItem = new COutlookButton(spNewMenu);
		m_pMyMenuItem->m_OLAppPtr = m_OLAppPtr;

		// show the menu        
		spNewMenu->PutVisible(VARIANT_TRUE); 
   }
   catch(...)
   {
   }

   return S_FALSE;
}
Ejemplo n.º 14
0
Mat CHOG::get(const Mat &img, int nBins, SqNeighbourhood nbhd)
{
	DGM_ASSERT_MSG(nBins < CV_CN_MAX, "Number of bins (%d) exceeds the maximum allowed number (%d)", nBins, CV_CN_MAX);
	
	int	i;						// bins index
	int	x, y;
	int	width	= img.cols;
	int	height	= img.rows;

	// Converting to one channel image
	Mat	I;
	if (img.channels() != 1) cvtColor(img, I, cv::ColorConversionCodes::COLOR_RGB2GRAY);
	else img.copyTo(I);
	
	// Derivatives
	Mat Ix = CGradient::getDerivativeX(I);
	Mat Iy = CGradient::getDerivativeY(I);

	// Initializing bins and integrals
	vec_mat_t vTemp(nBins);
	vec_mat_t vBins(nBins);
	vec_mat_t vInts(nBins);

	for (i = 0; i < nBins; i++) {
		vTemp[i].create(img.size(), CV_8UC1);
		vBins[i].create(img.size(), CV_32FC1);	
		vBins[i].setTo(0);
	}

	std::vector<float *>	pBins(nBins);
	std::vector<double *>	pInts0(nBins);
	std::vector<double *>	pInts1(nBins);
	std::vector<byte *>		pTemp(nBins);
	
	// Caclculating the bins
	for (y = 0; y < height; y++) {
		float *pIx = Ix.ptr<float>(y);
		float *pIy = Iy.ptr<float>(y);
		for (i = 0; i < nBins; i++) pBins[i] = vBins[i].ptr<float>(y);
		for (x = 0; x < width; x++) {
			float ix = pIx[x];
			float iy = pIy[x];
			
			// gradient Magnitude
			float gMgn = sqrtf(ix*ix + iy*iy);

			// gradient Orientation
			if (fabs(ix) < FLT_EPSILON) ix = SIGN(ix) * FLT_EPSILON;
			float tg = iy / ix;
			float gOrt = (0.5f + atanf(tg) / (float)Pi) * 180.0f;			// [0°; 180°]

			// filling in the bins
			float gOrtStep = 180.0f / nBins;
			for (i = 0; i < nBins; i++)
				if (gOrt <= (i + 1) * gOrtStep) {
					pBins[i][x] = gMgn;
					break;
				}
		}
	}

	// Calculating the integrals
	for (i = 0; i < nBins; i++) integral(vBins[i], vInts[i]);
	
	for (y = 0; y < height; y++) {	
		int y0 = MAX(0, y - nbhd.upperGap);		
		int y1 = MIN(y + nbhd.lowerGap, height - 1);
		for (i = 0; i < nBins; i++) pInts0[i] = vInts[i].ptr<double>(y0);
		for (i = 0; i < nBins; i++) pInts1[i] = vInts[i].ptr<double>(y1 + 1);
		for (i = 0; i < nBins; i++) pTemp[i]  = vTemp[i].ptr<byte>(y);
		for (x = 0; x < width; x++) {
			int x0 = MAX(0, x - nbhd.leftGap);
			int x1 = MIN(x + nbhd.rightGap, width - 1);

			Mat HOGcell(cv::Size(nBins, 1), CV_64FC1);
			double *pHOGcell = HOGcell.ptr<double>(0);
			for (i = 0; i < nBins; i++) pHOGcell[i] = pInts1[i][x1 + 1] - pInts1[i][x0] - pInts0[i][x1 + 1] + pInts0[i][x0];
			normalize(HOGcell, HOGcell, 255, 0, cv::NormTypes::NORM_MINMAX);
			for (i = 0; i < nBins; i++) pTemp[i][x] = static_cast<byte>(pHOGcell[i]);
			HOGcell.release();
		} // x
	} // y

	Mat res;
	merge(vTemp, res);

	return res;	
}
Ejemplo n.º 15
0
/*static*/
CVector3f CVector3f::ScalarDivide( const CVector3f &v, float s)
{
	CVector3f vTemp(v);
	vTemp /= s;
	return vTemp;
}
Ejemplo n.º 16
0
/*static*/
CVector3f CVector3f::ScalarMultiply( const CVector3f &v, float s)
{
	CVector3f vTemp(v);
	vTemp *= s;
	return vTemp;
}