Ejemplo n.º 1
0
S2DB::S2DB( QWidget *p ) : QFrame( p )
{
  setupUi( this );

  Read = false;
  CBar->setAutoScale( AutoScaleB->isChecked() );
  S2DV->setCBar( CBar );

  MCAsDirSel = new QFileDialog;
  MCAsDirSel->setAcceptMode( QFileDialog::AcceptOpen );
  MCAsDirSel->setDirectory( QDir::currentPath() );
  qDebug() << "Cur Path" << QDir::currentPath();
  MCAsDirSel->setNameFilter( "*" );
  MCAsDirSel->setFileMode( QFileDialog::Directory );
  MCAsDirSel->setConfirmOverwrite( false );

  PopDialog = new QDialog;
  PopDialog->resize( 600, 400 );
  QGridLayout *bl = new QGridLayout;
  PopDialog->setLayout( bl );
  popping = false;
  layout = NULL;

  connect( PopDialog, SIGNAL( finished(int) ), this, SLOT( PopUp() ),
	   Qt::UniqueConnection );
  connect( PopB, SIGNAL( clicked() ), this, SLOT( PopUp() ), 
	   Qt::UniqueConnection );
  
  connect( LoadMCAsB, SIGNAL( clicked() ), MCAsDirSel, SLOT( show() ),
	   Qt::UniqueConnection );
  connect( MCAsDirSel, SIGNAL( fileSelected( const QString & ) ),
	   this, SLOT( LoadMCAs( const QString & ) ),
	   Qt::UniqueConnection );
  
#if 0
  connect( S2DPopUp, SIGNAL( clicked() ), this, SIGNAL( popup() ), Qt::UniqueConnection );
  connect( S2DPrintB, SIGNAL( clicked() ), this, SIGNAL( print() ), Qt::UniqueConnection );
#endif
  
  connect( AutoScaleB, SIGNAL( toggled( bool ) ), CBar, SLOT( setAutoScale( bool ) ), Qt::UniqueConnection );
  connect( zmax, SIGNAL( editingFinished() ), this, SLOT( newInputZmax() ), Qt::UniqueConnection );
  connect( zmin, SIGNAL( editingFinished() ), this, SLOT( newInputZmin() ), Qt::UniqueConnection );
  connect( S2DV, SIGNAL( newAutoZmax( double ) ), CBar, SLOT( newAutoZmax( double ) ), Qt::UniqueConnection );
  connect( S2DV, SIGNAL( newAutoZmin( double ) ), CBar, SLOT( newAutoZmin( double ) ), Qt::UniqueConnection );
  connect( CBar, SIGNAL( newZZ( QString, QString ) ), this, SLOT( newZZ( QString, QString ) ), Qt::UniqueConnection );
  connect( CBar, SIGNAL( newScale() ), S2DV, SLOT( update() ), Qt::UniqueConnection );

  mapLoadTimer = new QTimer;
  connect( mapLoadTimer, SIGNAL( timeout() ),
	   this, SLOT( loadNextMap() ), Qt::UniqueConnection );
  loadingMCAMap = false;
  loadingAMCA = false;

  mapSaveTimer = new QTimer;
  connect( mapSaveTimer, SIGNAL( timeout() ),
	   this, SLOT( saveNextMap() ), Qt::UniqueConnection );
  savingMCAMap = false;
  savingAMCA = false;
}
Ejemplo n.º 2
0
void Matrix::scale(float x, float y, float z) {
    Matrix* m = newScale(x, y, z);
    Matrix* temp = new Matrix(*this);
    if (m != NULL && temp != NULL) {
        multiply(*temp, *m);
    }
    delete m;
    delete temp;
}
Ejemplo n.º 3
0
void CelAnimMesh::setCommonScale( Shape::Mesh & otherMesh )
{
   CelAnimMesh *potherMesh = dynamic_cast<CelAnimMesh *>(&otherMesh);
   AssertFatal(potherMesh,
      "TS::CelAnimMesh::setCommonScale:  meshes not same type");

#if 0 
   // array of unpacked verts -- points only
   Point3F *unpackedVerts = new Point3F[fVerts.size()];
   int v;
   for (v=0;v<fVerts.size();v++)
      fVerts[v].getPoint(unpackedVerts[v],fScale,fOrigin);

   Point3F *otherUnpackedVerts = new Point3F[potherMesh->fVerts.size()];
   for (v=0;v<potherMesh->fVerts.size();v++)
      potherMesh->fVerts[v].getPoint(otherUnpackedVerts[v],potherMesh->fScale,potherMesh->fOrigin);

   // get minVert and maxVert for setting new fScale, fOrigin, and fRadius
   Point3F minVert = unpackedVerts[0];
   Point3F maxVert = unpackedVerts[0];
   for (v=1;v<fVerts.size();v++)
   {
      minVert.setMin( unpackedVerts[v] );
      maxVert.setMax( unpackedVerts[v] );
   }
   for (v=0;v<potherMesh->fVerts.size();v++)
   {
      minVert.setMin( otherUnpackedVerts[v] );
      maxVert.setMax( otherUnpackedVerts[v] );
   }

   // figure new fOrigin, fScale, and fRadius
   Point3F newOrigin = minVert;
   maxVert -= minVert;
   Point3F newScale( maxVert.x/255.0f, maxVert.y/255.0f, maxVert.z/255.0f);
   float newRadius = maxVert.len();

   // re-pack this shapes verts     
   int i;
   Point3F temp;
   for (i=0;i<fVerts.size();i++)
      fVerts[i].setPoint(unpackedVerts[i],newScale,newOrigin);
   fOrigin=newOrigin;
   fScale=newScale;
   fRadius=newRadius;

   // re-pack other shapes verts
   for (i=0;i<potherMesh->fVerts.size();i++)
      potherMesh->fVerts[i].setPoint(otherUnpackedVerts[i],newScale,newOrigin);
   potherMesh->fOrigin=fOrigin;
   potherMesh->fScale=newScale;
   potherMesh->fRadius=newRadius;

   delete [] unpackedVerts;
   delete [] otherUnpackedVerts;
#endif      
}
Ejemplo n.º 4
0
void MGuiWindow::autoScale(void)
{
	MVector2 tmp;
	MVector2 newScale(0, 0);

    unsigned int i;
    unsigned int size = m_objects.size();
    for(i=0; i<size; i++)
	{
		MGui2d * object = m_objects[i];
		tmp = object->getPosition()
		    + object->getScale();

		if(tmp.x > newScale.x) newScale.x = tmp.x;
		if(tmp.y > newScale.y) newScale.y = tmp.y;
	}

	setScale(newScale);
	resizeScroll();
}
Ejemplo n.º 5
0
bool VMCcuda::runWithDrift()
{
    resetRun();
    IndexType block = 0;
    IndexType nAcceptTot = 0;
    IndexType nRejectTot = 0;
    int nat = W.getTotalNum();
    int nw  = W.getActiveWalkers();

    vector<RealType>  LocalEnergy(nw), oldScale(nw), newScale(nw);
    vector<PosType>   delpos(nw);
    vector<PosType>   dr(nw);
    vector<PosType>   newpos(nw);
    vector<ValueType> ratios(nw), rplus(nw), rminus(nw);
    vector<PosType>  oldG(nw), newG(nw);
    vector<ValueType> oldL(nw), newL(nw);
    vector<Walker_t*> accepted(nw);
    Matrix<ValueType> lapl(nw, nat);
    Matrix<GradType>  grad(nw, nat);

    // First, do warmup steps
    for (int step=0; step<myWarmupSteps; step++) {
        for(int iat=0; iat<nat; iat++) {
            Psi.getGradient (W, iat, oldG);

            //create a 3N-Dimensional Gaussian with variance=1
            makeGaussRandomWithEngine(delpos,Random);
            for(int iw=0; iw<nw; iw++) {
                oldScale[iw] = getDriftScale(m_tauovermass,oldG[iw]);
                dr[iw] = (m_sqrttau*delpos[iw]) + (oldScale[iw]*oldG[iw]);
                newpos[iw]=W[iw]->R[iat] + dr[iw];
                ratios[iw] = 1.0;
            }
            W.proposeMove_GPU(newpos, iat);

            Psi.ratio(W,iat,ratios,newG, newL);

            accepted.clear();
            vector<bool> acc(nw, false);
            for(int iw=0; iw<nw; ++iw) {
                PosType drOld =
                    newpos[iw] - (W[iw]->R[iat] + oldScale[iw]*oldG[iw]);
                RealType logGf = -m_oneover2tau * dot(drOld, drOld);
                newScale[iw]   = getDriftScale(m_tauovermass,newG[iw]);
                PosType drNew  =
                    (newpos[iw] + newScale[iw]*newG[iw]) - W[iw]->R[iat];

                RealType logGb =  -m_oneover2tau * dot(drNew, drNew);
                RealType x = logGb - logGf;
                RealType prob = ratios[iw]*ratios[iw]*std::exp(x);

                if(Random() < prob) {
                    accepted.push_back(W[iw]);
                    nAccept++;
                    W[iw]->R[iat] = newpos[iw];
                    acc[iw] = true;
                }
                else
                    nReject++;
            }
            W.acceptMove_GPU(acc);
            if (accepted.size())
                Psi.update(accepted,iat);
        }
    }

    // Now do data collection steps
    do {
        IndexType step = 0;
        nAccept = nReject = 0;
        Estimators->startBlock(nSteps);
        do {
            step++;
            CurrentStep++;
            for (int isub=0; isub<nSubSteps; isub++) {
                for(int iat=0; iat<nat; iat++) {
                    Psi.getGradient (W, iat, oldG);

                    //create a 3N-Dimensional Gaussian with variance=1
                    makeGaussRandomWithEngine(delpos,Random);
                    for(int iw=0; iw<nw; iw++) {
                        oldScale[iw] = getDriftScale(m_tauovermass,oldG[iw]);
                        dr[iw] = (m_sqrttau*delpos[iw]) + (oldScale[iw]*oldG[iw]);
                        newpos[iw]=W[iw]->R[iat] + dr[iw];
                        ratios[iw] = 1.0;
                    }
                    W.proposeMove_GPU(newpos, iat);

                    Psi.ratio(W,iat,ratios,newG, newL);

                    accepted.clear();
                    vector<bool> acc(nw, false);
                    for(int iw=0; iw<nw; ++iw) {
                        PosType drOld =
                            newpos[iw] - (W[iw]->R[iat] + oldScale[iw]*oldG[iw]);
                        // if (dot(drOld, drOld) > 25.0)
                        //   cerr << "Large drift encountered!  Old drift = " << drOld << endl;
                        RealType logGf = -m_oneover2tau * dot(drOld, drOld);
                        newScale[iw]   = getDriftScale(m_tauovermass,newG[iw]);
                        PosType drNew  =
                            (newpos[iw] + newScale[iw]*newG[iw]) - W[iw]->R[iat];
                        // if (dot(drNew, drNew) > 25.0)
                        //   cerr << "Large drift encountered!  Drift = " << drNew << endl;
                        RealType logGb =  -m_oneover2tau * dot(drNew, drNew);
                        RealType x = logGb - logGf;
                        RealType prob = ratios[iw]*ratios[iw]*std::exp(x);

                        if(Random() < prob) {
                            accepted.push_back(W[iw]);
                            nAccept++;
                            W[iw]->R[iat] = newpos[iw];
                            acc[iw] = true;
                        }
                        else
                            nReject++;
                    }
                    W.acceptMove_GPU(acc);
                    if (accepted.size())
                        Psi.update(accepted,iat);
                }
                // cerr << "Rank = " << myComm->rank() <<
                //   "  CurrentStep = " << CurrentStep << "  isub = " << isub << endl;
            }
            Psi.gradLapl(W, grad, lapl);
            H.evaluate (W, LocalEnergy);
            if (myPeriod4WalkerDump && (CurrentStep % myPeriod4WalkerDump)==0)
                W.saveEnsemble();
            Estimators->accumulate(W);
        } while(step<nSteps);
        Psi.recompute(W);

        double accept_ratio = (double)nAccept/(double)(nAccept+nReject);
        Estimators->stopBlock(accept_ratio);

        nAcceptTot += nAccept;
        nRejectTot += nReject;
        ++block;
        recordBlock(block);
    } while(block<nBlocks);
    //finalize a qmc section
    if (!myComm->rank())
        gpu::cuda_memory_manager.report();
    return finalize(block);
}
bool KX_IpoSGController::Update(double currentTime)
{
	if (m_modified)
	{
		T_InterpolatorList::iterator i;
		for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
			(*i)->Execute(m_ipotime);//currentTime);
		}
		
		SG_Spatial* ob = (SG_Spatial*)m_pObject;

		//initialization on the first frame of the IPO
		if (! m_ipo_start_initialized && currentTime > 0.0) {
			m_ipo_start_point = ob->GetLocalPosition();
			m_ipo_start_orient = ob->GetLocalOrientation();
			m_ipo_start_scale = ob->GetLocalScale();
			m_ipo_start_initialized = true;
			if (!m_ipo_euler_initialized) {
				// do it only once to avoid angle discontinuities
				m_ipo_start_orient.getEuler(m_ipo_start_euler[0], m_ipo_start_euler[1], m_ipo_start_euler[2]);
				m_ipo_euler_initialized = true;
			}
		}

		//modifies position?
		if (m_ipo_channels_active[OB_LOC_X]  || m_ipo_channels_active[OB_LOC_Y]  || m_ipo_channels_active[OB_LOC_Z] ||
		    m_ipo_channels_active[OB_DLOC_X] || m_ipo_channels_active[OB_DLOC_Y] || m_ipo_channels_active[OB_DLOC_Z])
		{
			if (m_ipo_as_force == true) 
			{
				if (m_game_object && ob && m_game_object->GetPhysicsController()) 
				{
					m_game_object->GetPhysicsController()->ApplyForce(m_ipo_local ?
						ob->GetWorldOrientation() * m_ipo_xform.GetPosition() :
						m_ipo_xform.GetPosition(), false);
				}
			} 
			else
			{
				// Local ipo should be defined with the object position at (0,0,0)
				// Local transform is applied to the object based on initial position
				MT_Point3 newPosition(0.0,0.0,0.0);
				
				if (!m_ipo_add)
					newPosition = ob->GetLocalPosition();
				//apply separate IPO channels if there is any data in them
				//Loc and dLoc act by themselves or are additive
				//LocX and dLocX
				if (m_ipo_channels_active[OB_LOC_X]) {
					newPosition[0] = (m_ipo_channels_active[OB_DLOC_X] ? m_ipo_xform.GetPosition()[0] + m_ipo_xform.GetDeltaPosition()[0] : m_ipo_xform.GetPosition()[0]);
				}
				else if (m_ipo_channels_active[OB_DLOC_X] && m_ipo_start_initialized) {
					newPosition[0] = (((!m_ipo_add)?m_ipo_start_point[0]:0.0) + m_ipo_xform.GetDeltaPosition()[0]);
				}
				//LocY and dLocY
				if (m_ipo_channels_active[OB_LOC_Y]) {
					newPosition[1] = (m_ipo_channels_active[OB_DLOC_Y] ? m_ipo_xform.GetPosition()[1] + m_ipo_xform.GetDeltaPosition()[1] : m_ipo_xform.GetPosition()[1]);
				}
				else if (m_ipo_channels_active[OB_DLOC_Y] && m_ipo_start_initialized) {
					newPosition[1] = (((!m_ipo_add)?m_ipo_start_point[1]:0.0) + m_ipo_xform.GetDeltaPosition()[1]);
				}
				//LocZ and dLocZ
				if (m_ipo_channels_active[OB_LOC_Z]) {
					newPosition[2] = (m_ipo_channels_active[OB_DLOC_Z] ? m_ipo_xform.GetPosition()[2] + m_ipo_xform.GetDeltaPosition()[2] : m_ipo_xform.GetPosition()[2]);
				}
				else if (m_ipo_channels_active[OB_DLOC_Z] && m_ipo_start_initialized) {
					newPosition[2] = (((!m_ipo_add)?m_ipo_start_point[2]:0.0) + m_ipo_xform.GetDeltaPosition()[2]);
				}
				if (m_ipo_add) {
					if (m_ipo_local)
						newPosition = m_ipo_start_point + m_ipo_start_scale*(m_ipo_start_orient*newPosition);
					else
						newPosition = m_ipo_start_point + newPosition;
				}
				if (m_game_object)
					m_game_object->NodeSetLocalPosition(newPosition);
			}
		}
		//modifies orientation?
		if (m_ipo_channels_active[OB_ROT_X]  || m_ipo_channels_active[OB_ROT_Y]  || m_ipo_channels_active[OB_ROT_Z] ||
		    m_ipo_channels_active[OB_DROT_X] || m_ipo_channels_active[OB_DROT_Y] || m_ipo_channels_active[OB_DROT_Z])
		{
			if (m_ipo_as_force) {
				
				if (m_game_object && ob) {
					m_game_object->ApplyTorque(m_ipo_local ?
						ob->GetWorldOrientation() * m_ipo_xform.GetEulerAngles() :
						m_ipo_xform.GetEulerAngles(), false);
				}
			} else if (m_ipo_add) {
				if (m_ipo_start_initialized) {
					double yaw=0, pitch=0,  roll=0;	//delta Euler angles

					//RotX and dRotX
					if (m_ipo_channels_active[OB_ROT_X])
						yaw += m_ipo_xform.GetEulerAngles()[0];
					if (m_ipo_channels_active[OB_DROT_X])
						yaw += m_ipo_xform.GetDeltaEulerAngles()[0];

					//RotY dRotY
					if (m_ipo_channels_active[OB_ROT_Y])
						pitch += m_ipo_xform.GetEulerAngles()[1];
					if (m_ipo_channels_active[OB_DROT_Y])
						pitch += m_ipo_xform.GetDeltaEulerAngles()[1];
					
					//RotZ and dRotZ
					if (m_ipo_channels_active[OB_ROT_Z])
						roll += m_ipo_xform.GetEulerAngles()[2];
					if (m_ipo_channels_active[OB_DROT_Z])
						roll += m_ipo_xform.GetDeltaEulerAngles()[2];

					MT_Matrix3x3 rotation(MT_Vector3(yaw, pitch, roll));
					if (m_ipo_local)
						rotation = m_ipo_start_orient * rotation;
					else
						rotation = rotation * m_ipo_start_orient;
					if (m_game_object)
						m_game_object->NodeSetLocalOrientation(rotation);
				}
			} else if (m_ipo_channels_active[OB_ROT_X] || m_ipo_channels_active[OB_ROT_Y] || m_ipo_channels_active[OB_ROT_Z]) {
				if (m_ipo_euler_initialized) {
					// assume all channel absolute
					// All 3 channels should be specified but if they are not, we will take 
					// the value at the start of the game to avoid angle sign reversal 
					double yaw=m_ipo_start_euler[0], pitch=m_ipo_start_euler[1], roll=m_ipo_start_euler[2];

					//RotX and dRotX
					if (m_ipo_channels_active[OB_ROT_X]) {
						yaw = (m_ipo_channels_active[OB_DROT_X] ? (m_ipo_xform.GetEulerAngles()[0] + m_ipo_xform.GetDeltaEulerAngles()[0]) : m_ipo_xform.GetEulerAngles()[0] );
					}
					else if (m_ipo_channels_active[OB_DROT_X]) {
						yaw += m_ipo_xform.GetDeltaEulerAngles()[0];
					}

					//RotY dRotY
					if (m_ipo_channels_active[OB_ROT_Y]) {
						pitch = (m_ipo_channels_active[OB_DROT_Y] ? (m_ipo_xform.GetEulerAngles()[1] + m_ipo_xform.GetDeltaEulerAngles()[1]) : m_ipo_xform.GetEulerAngles()[1] );
					}
					else if (m_ipo_channels_active[OB_DROT_Y]) {
						pitch += m_ipo_xform.GetDeltaEulerAngles()[1];
					}
					
					//RotZ and dRotZ
					if (m_ipo_channels_active[OB_ROT_Z]) {
						roll = (m_ipo_channels_active[OB_DROT_Z] ? (m_ipo_xform.GetEulerAngles()[2] + m_ipo_xform.GetDeltaEulerAngles()[2]) : m_ipo_xform.GetEulerAngles()[2] );
					}
					else if (m_ipo_channels_active[OB_DROT_Z]) {
						roll += m_ipo_xform.GetDeltaEulerAngles()[2];
					}
					if (m_game_object)
						m_game_object->NodeSetLocalOrientation(MT_Vector3(yaw, pitch, roll));
				}
			} else if (m_ipo_start_initialized) {
				// only DROT, treat as Add
				double yaw=0, pitch=0,  roll=0;	//delta Euler angles

				//dRotX
				if (m_ipo_channels_active[OB_DROT_X])
					yaw = m_ipo_xform.GetDeltaEulerAngles()[0];

				//dRotY
				if (m_ipo_channels_active[OB_DROT_Y])
					pitch = m_ipo_xform.GetDeltaEulerAngles()[1];
				
				//dRotZ
				if (m_ipo_channels_active[OB_DROT_Z])
					roll = m_ipo_xform.GetDeltaEulerAngles()[2];

				// dRot are always local
				MT_Matrix3x3 rotation(MT_Vector3(yaw, pitch, roll));
				rotation = m_ipo_start_orient * rotation;
				if (m_game_object)
					m_game_object->NodeSetLocalOrientation(rotation);
			}
		}
		//modifies scale?
		if (m_ipo_channels_active[OB_SIZE_X] || m_ipo_channels_active[OB_SIZE_Y] || m_ipo_channels_active[OB_SIZE_Z] ||
		    m_ipo_channels_active[OB_DSIZE_X] || m_ipo_channels_active[OB_DSIZE_Y] || m_ipo_channels_active[OB_DSIZE_Z])
		{
			//default is no scale change
			MT_Vector3 newScale(1.0,1.0,1.0);
			if (!m_ipo_add)
				newScale = ob->GetLocalScale();

			if (m_ipo_channels_active[OB_SIZE_X]) {
				newScale[0] = (m_ipo_channels_active[OB_DSIZE_X] ? (m_ipo_xform.GetScaling()[0] + m_ipo_xform.GetDeltaScaling()[0]) : m_ipo_xform.GetScaling()[0]);
			}
			else if (m_ipo_channels_active[OB_DSIZE_X] && m_ipo_start_initialized) {
				newScale[0] = (m_ipo_xform.GetDeltaScaling()[0] + ((!m_ipo_add)?m_ipo_start_scale[0]:0.0));
			}

			//RotY dRotY
			if (m_ipo_channels_active[OB_SIZE_Y]) {
				newScale[1] = (m_ipo_channels_active[OB_DSIZE_Y] ? (m_ipo_xform.GetScaling()[1] + m_ipo_xform.GetDeltaScaling()[1]): m_ipo_xform.GetScaling()[1]);
			}
			else if (m_ipo_channels_active[OB_DSIZE_Y] && m_ipo_start_initialized) {
				newScale[1] = (m_ipo_xform.GetDeltaScaling()[1] + ((!m_ipo_add)?m_ipo_start_scale[1]:0.0));
			}
			
			//RotZ and dRotZ
			if (m_ipo_channels_active[OB_SIZE_Z]) {
				newScale[2] = (m_ipo_channels_active[OB_DSIZE_Z] ? (m_ipo_xform.GetScaling()[2] + m_ipo_xform.GetDeltaScaling()[2]) : m_ipo_xform.GetScaling()[2]);
			}
			else if (m_ipo_channels_active[OB_DSIZE_Z] && m_ipo_start_initialized) {
				newScale[2] = (m_ipo_xform.GetDeltaScaling()[2] + ((!m_ipo_add)?m_ipo_start_scale[2]:1.0));
			}

			if (m_ipo_add) {
				newScale = m_ipo_start_scale * newScale;
			}
			if (m_game_object)
				m_game_object->NodeSetLocalScale(newScale);
		}

		m_modified=false;
	}
	return false;
}
Ejemplo n.º 7
0
void CPhysicsActor::SetScale( Vec3& scale )
{
	// do not scale if scale is currently 1:1 or if the scale
	// has not changed
	if( scale.x == 1 && scale.y == 1 && scale.z == 1 ||
		scale == m_CurrentScale )
	{
		return;
	}

	// make sure the scale is valid
	// No 0 scales or negative scales!
	if( scale.x <= 0 && scale.y <= 0 && scale.z <= 0 )
	{
		m_ToolBox->Log( LOGWARNING, _T("CPhysicsActor::SetScale() Invalid scale!\n" ) );
		return;
	}

	NxVec3 newScale( scale.x, scale.y, scale.z );

	// unscale the old scale
	// Loop through shapes in the actor
	unsigned int numShapes = m_Actor->getNbShapes();
	NxShape*const* shapes = m_Actor->getShapes();
   	NxShape* currentShape;

	NxVec3 shapeLocalPosition;

	// for each shape type scale its dimensions
	while( numShapes-- >= 1 )
	{
		currentShape = shapes[numShapes];

		// get the shape's type
		NxShapeType type = currentShape->getType();

		switch( type )
		{
			case NX_SHAPE_BOX:
				{
					// do something
					NxBoxShape* shape = (NxBoxShape*)currentShape;
					// rescale box dimensions
					NxVec3 dimensions = shape->getDimensions();
					
					Vec3 newDimensions(dimensions.x, dimensions.y, dimensions.z);
					RescaleVector( newDimensions, scale );

					// set the shape data with the newly rescaled dimensions
					shape->setDimensions( NxVec3(newDimensions.x, newDimensions.y, newDimensions.z) );
					break;
				}
			case NX_SHAPE_SPHERE:
				{
					// do something
					NxSphereShape* shape = (NxSphereShape*)currentShape;
					float radius = shape->getRadius();
					radius /= m_CurrentScale.x;
					radius *= newScale.x;
					// set the shape data with the newly rescaled dimensions
					shape->setRadius( radius );
					break;
				}
			case NX_SHAPE_CAPSULE:
				{
					// do something
					NxCapsuleShape* shape;
					shape = (NxCapsuleShape*)currentShape;
					// rescale radius
					float radius = shape->getRadius();
					radius /= m_CurrentScale.x;
					radius *= newScale.x;
					// rescale height
					float height = shape->getHeight();
					height /= m_CurrentScale.z;
					height *= newScale.z;
					// set the shape data with the newly rescaled dimensions
					shape->setRadius( radius );
					shape->setHeight( height );
					break;
				}
			default:
				m_ToolBox->Log( LOGWARNING, _T("CPhysicsObject::SetScale() Attempting to scale on unsupported shape!\n" ) );
				return;
		}

		// get the shape's local position and rescale it
		shapeLocalPosition = currentShape->getLocalPosition();

		Vec3 newShapeLocalPosition(shapeLocalPosition.x, shapeLocalPosition.y, shapeLocalPosition.z);
		RescaleVector( newShapeLocalPosition, scale );

		currentShape->setLocalPosition( NxVec3(newShapeLocalPosition.x, newShapeLocalPosition.y, newShapeLocalPosition.z) );
	}

	// Set the current scale to the new scale so we can unscale the scale
	m_CurrentScale = scale;
}
Ejemplo n.º 8
0
  bool DMCcuda::run() 
  { 
    bool NLmove = NonLocalMove == "yes";
    bool scaleweight = ScaleWeight == "yes";
    if (NLmove) 
      app_log() << "  Using Casula nonlocal moves in DMCcuda.\n";
    if (scaleweight)
      app_log() << "  Scaling weight per Umrigar/Nightengale.\n";
      
    resetRun();
    Mover->MaxAge = 1;
    IndexType block = 0;
    IndexType nAcceptTot = 0;
    IndexType nRejectTot = 0;
    int nat = W.getTotalNum();
    int nw  = W.getActiveWalkers();
    
    vector<RealType>  LocalEnergy(nw), LocalEnergyOld(nw), 
      oldScale(nw), newScale(nw);
    vector<PosType>   delpos(nw);
    vector<PosType>   dr(nw);
    vector<PosType>   newpos(nw);
    vector<ValueType> ratios(nw), rplus(nw), rminus(nw), R2prop(nw), R2acc(nw);
    vector<PosType>  oldG(nw), newG(nw);
    vector<ValueType> oldL(nw), newL(nw);
    vector<Walker_t*> accepted(nw);
    Matrix<ValueType> lapl(nw, nat);
    Matrix<GradType>  grad(nw, nat);
    vector<ValueType> V2(nw), V2bar(nw);
    vector<vector<NonLocalData> > Txy(nw);

    for (int iw=0; iw<nw; iw++)
      W[iw]->Weight = 1.0;
    do {
      IndexType step = 0;
      nAccept = nReject = 0;
      Estimators->startBlock(nSteps);
      
      do {
        step++;
	CurrentStep++;
	nw = W.getActiveWalkers();
	ResizeTimer.start();
	LocalEnergy.resize(nw);       oldScale.resize(nw);
	newScale.resize(nw);          delpos.resize(nw);
	dr.resize(nw);                newpos.resize(nw);
	ratios.resize(nw);            rplus.resize(nw);
	rminus.resize(nw);            oldG.resize(nw);
	newG.resize(nw);              oldL.resize(nw);
	newL.resize(nw);              accepted.resize(nw);
	lapl.resize(nw, nat);         grad.resize(nw, nat);
	R2prop.resize(nw,0.0);        R2acc.resize(nw,0.0);
	V2.resize(nw,0.0);            V2bar.resize(nw,0.0);

	W.updateLists_GPU();
	ResizeTimer.stop();

	if (NLmove) {
	  Txy.resize(nw);
	  for (int iw=0; iw<nw; iw++) {
	    Txy[iw].clear();
	    Txy[iw].push_back(NonLocalData(-1, 1.0, PosType()));
	  }
	}

	for (int iw=0; iw<nw; iw++)
	  W[iw]->Age++;
	
	DriftDiffuseTimer.start();
        for(int iat=0; iat<nat; iat++) {
	  Psi.getGradient (W, iat, oldG);

          //create a 3N-Dimensional Gaussian with variance=1
          makeGaussRandomWithEngine(delpos,Random);
          for(int iw=0; iw<nw; iw++) {
	    delpos[iw] *= m_sqrttau;
	    oldScale[iw] = getDriftScale(m_tauovermass,oldG[iw]);
	    dr[iw] = delpos[iw] + (oldScale[iw]*oldG[iw]);
            newpos[iw]=W[iw]->R[iat] + dr[iw];
	    ratios[iw] = 1.0;
	    R2prop[iw] += dot(delpos[iw], delpos[iw]);
	  }
	  W.proposeMove_GPU(newpos, iat);
	  
          Psi.ratio(W,iat,ratios,newG, newL);
	  	  
          accepted.clear();
	  vector<bool> acc(nw, false);
          for(int iw=0; iw<nw; ++iw) {
	    PosType drOld = 
	      newpos[iw] - (W[iw]->R[iat] + oldScale[iw]*oldG[iw]);
	    RealType logGf = -m_oneover2tau * dot(drOld, drOld);
	    newScale[iw]   = getDriftScale(m_tauovermass,newG[iw]);
	    PosType drNew  = 
	      (newpos[iw] + newScale[iw]*newG[iw]) - W[iw]->R[iat];
	    RealType logGb =  -m_oneover2tau * dot(drNew, drNew);
	    RealType x = logGb - logGf;
	    RealType prob = ratios[iw]*ratios[iw]*std::exp(x);
	    
            if(Random() < prob && ratios[iw] > 0.0) {
              accepted.push_back(W[iw]);
	      nAccept++;
	      W[iw]->R[iat] = newpos[iw];
	      W[iw]->Age = 0;
	      acc[iw] = true;
	      R2acc[iw] += dot(delpos[iw], delpos[iw]);
	      V2[iw]    += m_tauovermass * m_tauovermass * dot(newG[iw],newG[iw]);
	      V2bar[iw] +=  newScale[iw] *  newScale[iw] * dot(newG[iw],newG[iw]);
	    }
	    else {
	      nReject++;
	      V2[iw]    += m_tauovermass * m_tauovermass * dot(oldG[iw],oldG[iw]);
	      V2bar[iw] +=  oldScale[iw] *  oldScale[iw] * dot(oldG[iw],oldG[iw]);
	    }	      
	  }
	  W.acceptMove_GPU(acc);
	  if (accepted.size())
	    Psi.update(accepted,iat);
	}
	DriftDiffuseTimer.stop();
	//	Psi.recompute(W, false);
	Psi.gradLapl(W, grad, lapl);
	HTimer.start();
	if (NLmove)	  H.evaluate (W, LocalEnergy, Txy);
	else    	  H.evaluate (W, LocalEnergy);
	HTimer.stop();
// 	for (int iw=0; iw<nw; iw++) {
// 	  branchEngine->clampEnergy(LocalEnergy[iw]);
// 	  W[iw]->getPropertyBase()[LOCALENERGY] = LocalEnergy[iw];
// 	}
	if (CurrentStep == 1)
	  LocalEnergyOld = LocalEnergy;
	
	if (NLmove) {
	  // Now, attempt nonlocal move
	  accepted.clear();
	  vector<int> iatList;
	  vector<PosType> accPos;
	  for (int iw=0; iw<nw; iw++) {
	    /// HACK HACK HACK
// 	    if (LocalEnergy[iw] < -2300.0) {
// 	      cerr << "Walker " << iw << " has energy " 
// 		   << LocalEnergy[iw] << endl;;
// 	      double maxWeight = 0.0;
// 	      int elMax = -1;
// 	      PosType posMax;
// 	      for (int j=1; j<Txy[iw].size(); j++)
// 		if (std::fabs(Txy[iw][j].Weight) > std::fabs(maxWeight)) {
// 		  maxWeight = Txy[iw][j].Weight;
// 		  elMax = Txy[iw][j].PID;
// 		  posMax = W[iw]->R[elMax] + Txy[iw][j].Delta;
// 		}
// 	      cerr << "Maximum weight is " << maxWeight << " for electron " 
// 		   << elMax << " at position " << posMax << endl;
// 	      PosType unit = W.Lattice.toUnit(posMax);
// 	      unit[0] -= round(unit[0]);
// 	      unit[1] -= round(unit[1]);
// 	      unit[2] -= round(unit[2]);
// 	      cerr << "Reduced position = " << unit << endl;
// 	    }

	    int ibar = NLop.selectMove(Random(), Txy[iw]);
		    
	    if (ibar) {
	      accepted.push_back(W[iw]);
	      int iat = Txy[iw][ibar].PID;
	      iatList.push_back(iat);
	      accPos.push_back(W[iw]->R[iat] + Txy[iw][ibar].Delta);
	    }
	  }
	  if (accepted.size()) {
	    Psi.ratio(accepted,iatList, accPos, ratios, newG, newL);
	    Psi.update(accepted,iatList);
	    for (int i=0; i<accepted.size(); i++)
	      accepted[i]->R[iatList[i]] = accPos[i];
	    W.NLMove_GPU (accepted, accPos, iatList);
	    // HACK HACK HACK
	    // Recompute the kinetic energy
	    // Psi.gradLapl(W, grad, lapl);
	    // H.evaluate (W, LocalEnergy);
	    //W.copyWalkersToGPU();
	  }
	}

	// Now branch
	BranchTimer.start();
	for (int iw=0; iw<nw; iw++) {
	  RealType v2=0.0, v2bar=0.0;
	  for(int iat=0; iat<nat; iat++) {
	    v2 += dot(W.G[iat],W.G[iat]);
	    RealType newscale = getDriftScale(m_tauovermass,newG[iw]);
	    v2 += m_tauovermass * m_tauovermass * dot(newG[iw],newG[iw]);
	    v2bar +=  newscale * newscale * dot(newG[iw],newG[iw]);
	  }
	  //RealType scNew = std::sqrt(V2bar[iw] / V2[iw]);
	  RealType scNew = std::sqrt(v2bar/v2);
	  RealType scOld = (CurrentStep == 1) ? scNew : W[iw]->getPropertyBase()[DRIFTSCALE];

	  W[iw]->getPropertyBase()[DRIFTSCALE] = scNew;
	  // fprintf (stderr, "iw = %d  scNew = %1.8f  scOld = %1.8f\n", iw, scNew, scOld);
	  RealType tauRatio = R2acc[iw] / R2prop[iw];
	  if (tauRatio < 0.5) 
	    cerr << "  tauRatio = " << tauRatio << endl;
	  RealType taueff = m_tauovermass * tauRatio;
	  if (scaleweight) 
	    W[iw]->Weight *= branchEngine->branchWeightTau
	      (LocalEnergy[iw], LocalEnergyOld[iw], scNew, scOld, taueff);
	  else
	    W[iw]->Weight *= branchEngine->branchWeight
	      (LocalEnergy[iw], LocalEnergyOld[iw]);

	  W[iw]->getPropertyBase()[R2ACCEPTED] = R2acc[iw];
	  W[iw]->getPropertyBase()[R2PROPOSED] = R2prop[iw];
	  
	}
	Mover->setMultiplicity(W.begin(), W.end());
	branchEngine->branch(CurrentStep,W);
	nw = W.getActiveWalkers();
	LocalEnergyOld.resize(nw);
	for (int iw=0; iw<nw; iw++)
	  LocalEnergyOld[iw] = W[iw]->getPropertyBase()[LOCALENERGY];
	BranchTimer.stop();
      } while(step<nSteps);
      Psi.recompute(W, true);


      double accept_ratio = (double)nAccept/(double)(nAccept+nReject);
      Estimators->stopBlock(accept_ratio);

      nAcceptTot += nAccept;
      nRejectTot += nReject;
      ++block;
      
      recordBlock(block);
    } while(block<nBlocks);
    //finalize a qmc section
    return finalize(block);
  }
Ejemplo n.º 9
0
  bool DMCcuda::runWithNonlocal() 
  { 
    resetRun();
    Mover->MaxAge = 1;
    IndexType block = 0;
    IndexType nAcceptTot = 0;
    IndexType nRejectTot = 0;
    int nat = W.getTotalNum();
    int nw  = W.getActiveWalkers();
    
    vector<RealType>  LocalEnergy(nw), LocalEnergyOld(nw), 
      oldScale(nw), newScale(nw);
    vector<PosType>   delpos(nw);
    vector<PosType>   dr(nw);
    vector<PosType>   newpos(nw);
    vector<ValueType> ratios(nw), rplus(nw), rminus(nw), R2prop(nw), R2acc(nw);
    vector<PosType>  oldG(nw), newG(nw);
    vector<ValueType> oldL(nw), newL(nw);
    vector<Walker_t*> accepted(nw);
    Matrix<ValueType> lapl(nw, nat);
    Matrix<GradType>  grad(nw, nat);
    vector<vector<NonLocalData> > Txy(nw);
    for (int iw=0; iw<nw; iw++)
      W[iw]->Weight = 1.0;
    do {
      IndexType step = 0;
      nAccept = nReject = 0;
      Estimators->startBlock(nSteps);
      
      do {
        step++;
	CurrentStep++;
	nw = W.getActiveWalkers();
	LocalEnergy.resize(nw);    	oldScale.resize(nw);
	newScale.resize(nw);    	delpos.resize(nw);
	dr.resize(nw);                  newpos.resize(nw);
	ratios.resize(nw);	        rplus.resize(nw);
	rminus.resize(nw);              oldG.resize(nw);
	newG.resize(nw);                oldL.resize(nw);
	newL.resize(nw);                accepted.resize(nw);
	lapl.resize(nw, nat);           grad.resize(nw, nat);
	R2prop.resize(nw,0.0);          R2acc.resize(nw,0.0);

	W.updateLists_GPU();

	Txy.resize(nw);
	for (int iw=0; iw<nw; iw++) {
	  Txy[iw].clear();
	  Txy[iw].push_back(NonLocalData(-1, 1.0, PosType()));
	  W[iw]->Age++;
	}
	
        for(int iat=0; iat<nat; iat++) {
	  Psi.getGradient (W, iat, oldG);
	  
          //create a 3N-Dimensional Gaussian with variance=1
          makeGaussRandomWithEngine(delpos,Random);
          for(int iw=0; iw<nw; iw++) {
	    delpos[iw] *= m_sqrttau;
	    oldScale[iw] = getDriftScale(m_tauovermass,oldG[iw]);
	    dr[iw] = delpos[iw] + (oldScale[iw]*oldG[iw]);
            newpos[iw]=W[iw]->R[iat] + dr[iw];
	    ratios[iw] = 1.0;
	    R2prop[iw] += dot(delpos[iw], delpos[iw]);
	  }
	  W.proposeMove_GPU(newpos, iat);
	  
          Psi.ratio(W,iat,ratios,newG, newL);
	  	  
          accepted.clear();
	  vector<bool> acc(nw, false);
          for(int iw=0; iw<nw; ++iw) {
	    PosType drOld = 
	      newpos[iw] - (W[iw]->R[iat] + oldScale[iw]*oldG[iw]);
	    RealType logGf = -m_oneover2tau * dot(drOld, drOld);
	    newScale[iw]   = getDriftScale(m_tauovermass,newG[iw]);
	    PosType drNew  = 
	      (newpos[iw] + newScale[iw]*newG[iw]) - W[iw]->R[iat];
	    RealType logGb =  -m_oneover2tau * dot(drNew, drNew);
	    RealType x = logGb - logGf;
	    RealType prob = ratios[iw]*ratios[iw]*std::exp(x);
	    
            if(Random() < prob && ratios[iw] > 0.0) {
              accepted.push_back(W[iw]);
	      nAccept++;
	      W[iw]->R[iat] = newpos[iw];
	      W[iw]->Age = 0;
	      acc[iw] = true;
	      R2acc[iw] += dot(delpos[iw], delpos[iw]);
	    }
	    else 
	      nReject++;
	  }
	  W.acceptMove_GPU(acc);
	  if (accepted.size())
	    Psi.update(accepted,iat);
	}
	for (int iw=0; iw < nw; iw++) 
	  if (W[iw]->Age)
	    cerr << "Encountered stuck walker with iw=" << iw << endl;

	//	Psi.recompute(W, false);
	Psi.gradLapl(W, grad, lapl);
	H.evaluate (W, LocalEnergy, Txy);
	if (CurrentStep == 1)
	  LocalEnergyOld = LocalEnergy;
	
	// Now, attempt nonlocal move
	accepted.clear();
	vector<int> iatList;
	vector<PosType> accPos;
	for (int iw=0; iw<nw; iw++) {
	  int ibar = NLop.selectMove(Random(), Txy[iw]);
	  // cerr << "Txy[iw].size() = " << Txy[iw].size() << endl;
	  if (ibar) {
	    accepted.push_back(W[iw]);
	    int iat = Txy[iw][ibar].PID;
	    iatList.push_back(iat);
	    accPos.push_back(W[iw]->R[iat] + Txy[iw][ibar].Delta);
	  }
	}
	if (accepted.size()) {
	  //   W.proposeMove_GPU(newpos, iatList);
	  Psi.ratio(accepted,iatList, accPos, ratios, newG, newL);
	  Psi.update(accepted,iatList);
	  for (int i=0; i<accepted.size(); i++)
	    accepted[i]->R[iatList[i]] = accPos[i];
	  W.copyWalkersToGPU();
	}

	// Now branch
	for (int iw=0; iw<nw; iw++) {
	  W[iw]->Weight *= branchEngine->branchWeight(LocalEnergy[iw], LocalEnergyOld[iw]);
	  W[iw]->getPropertyBase()[R2ACCEPTED] = R2acc[iw];
	  W[iw]->getPropertyBase()[R2PROPOSED] = R2prop[iw];
	}
	Mover->setMultiplicity(W.begin(), W.end());
	branchEngine->branch(CurrentStep,W);
	nw = W.getActiveWalkers();
	LocalEnergyOld.resize(nw);
	for (int iw=0; iw<nw; iw++)
	  LocalEnergyOld[iw] = W[iw]->getPropertyBase()[LOCALENERGY];
      } while(step<nSteps);
      Psi.recompute(W, true);


      double accept_ratio = (double)nAccept/(double)(nAccept+nReject);
      Estimators->stopBlock(accept_ratio);

      nAcceptTot += nAccept;
      nRejectTot += nReject;
      ++block;
      
      recordBlock(block);
    } while(block<nBlocks);
    //finalize a qmc section
    return finalize(block);
  }
Ejemplo n.º 10
0
// Load the data.
void GPCMDataReader::load(
    std::vector<std::string> filelist,      // List of files from which to load the data.
    std::vector<double> noiselist           // Amount of noise to add to each file.
    )
{
    // Read data files.
    int i = 0;
    for (std::vector<std::string>::iterator itr = filelist.begin();
         itr != filelist.end(); ++itr)
    {
        // Load the file.
        MatrixXd data = loadFile(*itr);

        // Load auxiliary data.
        MatrixXd aux = loadAuxFile(*itr);

        // Check for blank auxiliary data.
        if (aux.cols() == 0)
            aux.setZero(data.rows(),1);

        // Add noise if desired.
        addDataNoise(data,noiselist[i]);

        // Concatenate into Y.
        MatrixXd newY(data.rows()+Y.rows(),data.cols());
        MatrixXd newAux(data.rows()+Y.rows(),aux.cols());

        // Store data.
        if (Y.rows() > 0)
            newY << Y,data;
        else
            newY = data;

        // Store auxiliary.
        if (auxData.rows() > 0)
            newAux << auxData,aux;
        else
            newAux = aux;

        // Switch over to the new matrices.
        Y = newY;
        auxData = newAux;

        // Concatenate into sequence.
        sequence.push_back(Y.rows());

        // Increment index.
        i++;
    }

    // Do any additional processing here, such as computing velocities and building supplementary
    // data structures.
    postProcessData();

    // Remove constant entries.
    MatrixXd constantEntries;
    std::vector<int> constantIndices;
    std::vector<int> variableIndices;
    int totalIndices = removeConstantEntries(Y,constantEntries,
        constantIndices,variableIndices);

    // Remove constant entries from scales.
    if (supplementary->getScale().cols() > 0)
    {
        MatrixXd newScale(1,variableIndices.size());
        for (unsigned i = 0; i < variableIndices.size(); i++)
        {
            newScale(0,i) = supplementary->getScale()(0,variableIndices[i]);
        }
        supplementary->getScale() = newScale;
    }

    // Pass duplicate entry information to supplement.
    supplementary->setConstant(constantEntries,constantIndices,variableIndices,totalIndices);
}
Ejemplo n.º 11
0
unsigned int CObjTreePlugin::insertBBox(unsigned int id, const geometry_msgs::Pose &pose, const geometry_msgs::Vector3 &scale, CObjTreePlugin::Operation op)
{
    printf("insertBoundingBox called, mode %d\n", op);

    if(op == INSERT && m_octree.removeObject(id))
    {
        //Updating existing box
        removePrimitiveMarker(id);
    }

    objtree::Point newPosition(pose.position.x, pose.position.y, pose.position.z);
    objtree::Vector4f newOrientation(pose.orientation.x, pose.orientation.y, pose.orientation.z, pose.orientation.w);
    objtree::Point newScale(scale.x, scale.y, scale.z);

    //Compute minimal aligned bounding box
    Eigen::Vector3f min, max;
    Eigen::Vector3f vec[4];
    vec[0] = Eigen::Vector3f(-scale.x/2.0f, -scale.y/2.0f, -scale.z/2.0f);
    vec[1] = Eigen::Vector3f(-scale.x/2.0f,  scale.y/2.0f, -scale.z/2.0f);
    vec[2] = Eigen::Vector3f( scale.x/2.0f, -scale.y/2.0f, -scale.z/2.0f);
    vec[3] = Eigen::Vector3f( scale.x/2.0f,  scale.y/2.0f, -scale.z/2.0f);

    Eigen::Quaternionf q(pose.orientation.w, pose.orientation.x, pose.orientation.y, pose.orientation.z);

    min = max = q*vec[0];

    for(int i = 1; i < 4; i++)
    {
        vec[i] = q*vec[i];

        for(int j = 0; j < 3; j++)
        {
            if(min[j] > vec[i][j]) min[j] = vec[i][j];
            if(max[j] < vec[i][j]) max[j] = vec[i][j];
        }
    }

    for(int i = 0; i < 4; i++)
    {
        vec[i] = -vec[i];

        for(int j = 0; j < 3; j++)
        {
            if(min[j] > vec[i][j]) min[j] = vec[i][j];
            if(max[j] < vec[i][j]) max[j] = vec[i][j];
        }
    }

    Eigen::Vector3f alignedScale(max-min);
    objtree::Box alignedBox(min[0]+newPosition.x, min[1]+newPosition.y, min[2]+newPosition.z, alignedScale[0], alignedScale[1], alignedScale[2]);

    objtree::GBBox *newBox = new objtree::GBBox(newPosition, newOrientation, newScale, alignedBox);
    newBox->setId(id);

    switch(op)
    {
        case INSERT: return m_octree.insert(newBox);
        case UPDATE: return m_octree.insertUpdate(newBox);
        case GET_SIMILAR:
        {
            unsigned int id = -1;
            const objtree::Object *object = m_octree.getSimilarObject(newBox);
            if(object)
            {
                id = object->id();
            }

            delete newBox;
            return id;
        }
    }

    return -1;
}