Example #1
0
void CGppe::Predict_CGppe_Laplace(double sigma, MatrixXd t, MatrixXd x, VectorXd idx_global, VectorXd ind_t, VectorXd ind_x,
                                MatrixXd tstar, MatrixXd test_pair)
{

    int Kt_ss = 1;
    double sigma_star, val;
    MatrixXd Kx_star, Kx_star_star, kstar, Kss, Css;
    MatrixXd Kt_star = covfunc_t->Compute(t, tstar);

    Kx_star = GetMatRow(Kx, test_pair.transpose()).transpose(); //maybe need some transpose?

    Kx_star_star = GetMat(Kx, test_pair.transpose(), test_pair.transpose()); // test to test
    kstar = Kron(Kt_star, Kx_star);
    kstar = GetMatRow(kstar, idx_global);

    Kss = Kt_ss * Kx_star_star;

    mustar = kstar.transpose() * Kinv * GetVec(f, idx_global);
    Css    = Kss - kstar.transpose() * W * llt.solve(Kinv * kstar);

    sigma_star = sqrt(Css(0, 0) + Css(1, 1) - 2 * Css(0, 1) + pow(sigma, 2));
    val = ( mustar(0) - mustar(1) ) / sigma_star;
    p   = normcdf(val);

}
Example #2
0
void TapeHelpObject::GetWorldBoundBox(TimeValue t, INode* inode, ViewExp* vpt, Box3& box )
{
    if ( ! vpt || ! vpt->IsAlive() )
    {
        box.Init();
        return;
    }

    int i, nv;
    Matrix3 tm;
    float dtarg;
    Point3 pt;
    Point3 q[2];
    GetMat(t,inode,*vpt,tm);
    nv = mesh.getNumVerts();
    box.Init();
    for (i=0; i<nv; i++)
        box += tm*mesh.getVert(i);
    if (GetTargetPoint(t,inode,pt)) {
        tm = inode->GetObjectTM(t);
        dtarg = Length(tm.GetTrans()-pt)/Length(tm.GetRow(2));
        box += tm*Point3(float(0),float(0),-dtarg);
    }
    if(GetSpecLen()) {
        GetLinePoints(t, q, GetLength(t) );
        box += tm * q[0];
        box += tm * q[1];
    }
}
Example #3
0
void QVX_Object::ExportXYZ(void)
{
	QString OutFilePath = QFileDialog::getSaveFileName(NULL, "Export XYZ Coordinates", GetLastDir(), "TXT Files (*.txt)");

	QFile File(OutFilePath);
		
	if (!File.open(QIODevice::WriteOnly | QIODevice::Text)) {
		QMessageBox::warning(NULL, "File read error", "Could not open file. Aborting.");
		return;
	}
	QTextStream out(&File); 

	out << "MatIndex" << "\t" << "X (m)" << "\t" << "Y (m)" << "\t" << "Z (m)" << "\n";

	Vec3D<> Coord;
	int Mat;
	for (int i=0; i<GetStArraySize(); i++){
		Mat = GetMat(i);
		if (Mat != 0){
			Coord = GetXYZ(i);
			out << Mat << "\t" << Coord.x << "\t" << Coord.y << "\t" << Coord.z << "\n";
		}
	}

	File.close();
	SetLastDir(OutFilePath);

}
Example #4
0
static double RunTest
   (enum CBLAS_ORDER Order, enum TEST_UPLO Uplo, int N, int lda,
    int CacheSize, TYPE *res)
{
   TYPE *A, *AI, *C;
   int ierr;
   double t0, t1;

   A  = GetMat(Order, Uplo, N, lda);
   #ifdef DEBUG
      Mjoin(PATL,geprint)("A0", N, N, A, lda);
   #endif
   AI = DupMat(Order, N, N, A, lda, lda);
   t0 = ATL_flushcache(CacheSize);

   t0 = ATL_flushcache(-1);
   t0 = time00();
   test_inv(Order, Uplo, N, AI, lda); /* AI should now have inverse(A) */
   t1 = time00() - t0;
   t0 = ATL_flushcache(0);
   #ifdef DEBUG
      Mjoin(PATL,geprint)("A ", N, N, A, lda);
      Mjoin(PATL,geprint)("AI", N, N, AI, lda);
   #endif

   *res = GetResid(Order, Uplo, N, A, lda, AI, lda);
   free(AI);
   free(A);
   return(t1);
}
Example #5
0
int
FogObject::HitTest(TimeValue t, INode *inode, int type, int crossing,
                          int flags, IPoint2 *p, ViewExp *vpt)
{
    if ( ! vpt || ! vpt->IsAlive() )
		{
			// why are we here?
			DbgAssert(!"Doing HitTest() on invalid view port!");
			return FALSE;
		}
		
		HitRegion hitRegion;
    DWORD	savedLimits;
    int res = FALSE;
    Matrix3 m;
    GraphicsWindow *gw = vpt->getGW();	
    Material *mtl = gw->getMaterial();
    MakeHitRegion(hitRegion,type,crossing,4,p);	
    gw->setRndLimits(((savedLimits = gw->getRndLimits()) | GW_PICK) & ~GW_ILLUM);
    GetMat(t,inode,*vpt,m);
    gw->setTransform(m);
    gw->clearHitCode();
    if (mesh.select( gw, mtl, &hitRegion, flags & HIT_ABORTONHIT )) 
        return TRUE;
    gw->setRndLimits(savedLimits);
    return res;
}
Example #6
0
int
FogObject::Display(TimeValue t, INode* inode, ViewExp *vpt, int flags)
{
    if ( ! vpt || ! vpt->IsAlive() )
		{
			// why are we here?
			DbgAssert(!"Doing Display() on invalid view port!");
			return FALSE;
		}
		
		
		float radius;
    pblock->GetValue(PB_FOG_SIZE, t, radius, FOREVER);
    if (radius <= 0.0)
        return 0;
    BuildMesh(t);
    Matrix3 m;
    GraphicsWindow *gw = vpt->getGW();
    Material *mtl = gw->getMaterial();

    DWORD rlim = gw->getRndLimits();
    gw->setRndLimits(GW_WIREFRAME|GW_EDGES_ONLY|GW_BACKCULL| (rlim&GW_Z_BUFFER) );
    GetMat(t,inode,*vpt,m);
    gw->setTransform(m);
    if (inode->Selected()) 
        gw->setColor( LINE_COLOR, 1.0f, 1.0f, 1.0f);
    else if(!inode->IsFrozen())
        gw->setColor( LINE_COLOR, 1.0f, 0.0f, 0.0f);
    mesh.render( gw, mtl, NULL, COMP_ALL);

    gw->setRndLimits(rlim);
    return(0);
}
Example #7
0
int ProtHelpObject::HitTest(TimeValue t, INode *inode, int type, int crossing, int flags, IPoint2 *p, ViewExp *vpt) 
{
   if ( ! vpt || ! vpt->IsAlive() )
	{
		// why are we here
		DbgAssert(!_T("Invalid viewport!"));
		return FALSE;
	}
	 
	 HitRegion hitRegion;
   DWORD savedLimits;
   int res;
   Matrix3 m;
   GraphicsWindow *gw = vpt->getGW();  
   Material *mtl = gw->getMaterial();
   MakeHitRegion(hitRegion,type,crossing,4,p);  
   gw->setRndLimits(((savedLimits = gw->getRndLimits()) | GW_PICK) & ~GW_ILLUM);
   GetMat(t,inode,*vpt,m);
   gw->setTransform(m);
   // if we get a hit on the mesh, we're done
   gw->clearHitCode();
   if (mesh.select( gw, mtl, &hitRegion, flags & HIT_ABORTONHIT )) 
      return TRUE;
   // if not, check the target line, and set the pair flag if it's hit
   gw->clearHitCode();
   res = DrawLines(t, inode, gw, 1);
   gw->setRndLimits(savedLimits);
   return res;
}
Example #8
0
// From BaseObject
int TargetObject::HitTest(TimeValue t, INode *inode, int type, int crossing, int flags, IPoint2 *p, ViewExp *vpt) {
	if ( ! vpt || ! vpt->IsAlive() )
	{
		// why are we here
		DbgAssert(!_T("Invalid viewport!"));
		return FALSE;
	}
	
	HitRegion hitRegion;
	DWORD savedLimits;
	Matrix3 m;
	GraphicsWindow *gw = vpt->getGW();	
	MakeHitRegion(hitRegion,type,crossing,4,p);	
	gw->setRndLimits(((savedLimits = gw->getRndLimits()) | GW_PICK) & ~GW_ILLUM);
	GetMat(t,inode,*vpt,m);
	gw->setTransform(m);
	if(mesh.select( gw, gw->getMaterial(), &hitRegion, flags & HIT_ABORTONHIT ))
		return TRUE;
	gw->setRndLimits( savedLimits );
	return FALSE;

#if 0
	gw->setHitRegion(&hitRegion);
	gw->clearHitCode();
	gw->fWinMarker(&pt, HOLLOW_BOX_MRKR);
	return gw->checkHitCode();
#endif

	}
Example #9
0
int
BackgroundObject::Display(TimeValue t, INode* inode, ViewExp *vpt, int flags)
{
    float radius;
    pblock->GetValue(PB_BG_SIZE, t, radius, FOREVER);
    if (radius <= 0.0)
        return 0;
    BuildMesh(t);
    Matrix3 m;
    GraphicsWindow *gw = vpt->getGW();
    Material *mtl = gw->getMaterial();

    DWORD rlim = gw->getRndLimits();
    gw->setRndLimits(GW_WIREFRAME|GW_EDGES_ONLY|GW_BACKCULL);
    GetMat(t,inode,vpt,m);
    gw->setTransform(m);
    if (inode->Selected()) 
        gw->setColor( LINE_COLOR, 1.0f, 1.0f, 1.0f);
    else if(!inode->IsFrozen())
        gw->setColor( LINE_COLOR, 1.0f, 1.0f, 0.0f);
    mesh.render( gw, mtl, NULL, COMP_ALL);

    gw->setRndLimits(rlim);
    return(0);
}
Example #10
0
DWORD Camera::CvThreadProcImpl()
{
    cv::VideoCapture cap(0); // open the default camera

    if (!cap.isOpened())  // check if we succeeded
        return (DWORD)-1;

    //cap.set(CV_CAP_PROP_FRAME_WIDTH, 1920);
    //cap.set(CV_CAP_PROP_FRAME_HEIGHT, 1080);
    //cap.set(CV_CAP_PROP_FORMAT, CV_8UC4);

    while (!m_fShutdown)
    {
        cv::Mat* frame = GetMat();
        cap >> *frame; // get a new frame from camera

        std::shared_ptr<cv::Mat> pframe = std::shared_ptr<cv::Mat>(frame, [this](cv::Mat* mat) { Return(mat); });
        {
            std::lock_guard<std::mutex> lock(m_frameLock);
            m_currentFrame = pframe;
        }
        Fire();
    }

    return S_OK;
}
Example #11
0
void CGppe::Approx_CGppe_Laplace(const VectorXd & theta_x, const VectorXd& theta_t, const double& sigma, const MatrixXd& t, const MatrixXd &x, const TypePair & all_pairs,
                               const VectorXd & idx_global, const VectorXd& idx_global_1, const VectorXd& idx_global_2,
                               const VectorXd& ind_t, const VectorXd& ind_x, int M, int N)
{
    //Parameters function initialization
    double eps = 1E-6, psi_new, psi_old;
    M = all_pairs.rows();
    int n = M * N;
    f = VectorXd::Zero(n);
    VectorXd fvis = VectorXd::Zero(idx_global.rows());
    VectorXd deriv;
    double loglike = 0;

    covfunc_t->SetTheta(theta_t);
    covfunc_x->SetTheta(theta_x);

    MatrixXd Kt = covfunc_t->ComputeGrandMatrix(t);
    Kx = covfunc_x->ComputeGrandMatrix(x);

    MatrixXd K = GetMat(Kt, ind_t, ind_t).array() * GetMat(Kx, ind_x, ind_x).array();

    loglike = log_likelihood( sigma, all_pairs, idx_global_1, idx_global_2, M, N);
    Kinv = K.inverse();
    psi_new = loglike - 0.5 * fvis.transpose() * Kinv * fvis;
    psi_old = INT_MIN;
    while ((psi_new - psi_old) > eps)
    {
        psi_old = psi_new;
        deriv = deriv_log_likelihood_CGppe_fast( sigma, all_pairs, idx_global_1, idx_global_2, M, N);
        W = -deriv2_log_likelihood_CGppe_fast(sigma, all_pairs, idx_global_1, idx_global_2, M, N);
        W = GetMat(W, idx_global, idx_global);
        llt.compute(W + Kinv);
        L = llt.matrixL(); //no need to extract the triangular matrix here
        fvis = llt.solve(GetVec(deriv, idx_global) + W * fvis);
        for (int w = 0;w < idx_global.rows();w++)
        {
            f(idx_global(w)) = fvis(w);
        }
        loglike = log_likelihood( sigma, all_pairs, idx_global_1, idx_global_2, M, N);
        psi_new = loglike - 0.5 * fvis.transpose() * Kinv * fvis;
    }





}
Example #12
0
void
Cal3DObject::GetWorldBoundBox(TimeValue t, INode *inode, ViewExp *vpt,
                              Box3 &box)
{
    Matrix3 tm;
    GetMat(t, inode, vpt, tm);

    GetLocalBoundBox(t, inode, vpt, box);
    int nv = mesh.getNumVerts();
    box = box * tm;
}
Example #13
0
int ProtHelpObject::Display(TimeValue t, INode* inode, ViewExp *vpt, int flags) 
{
   if ( ! vpt || ! vpt->IsAlive() )
	{
		// why are we here
		DbgAssert(!_T("Invalid viewport!"));
		return FALSE;
	}
	 
	 Matrix3 m;
   GraphicsWindow *gw = vpt->getGW();
   Material *mtl = gw->getMaterial();

   created = TRUE;
   GetMat(t,inode,*vpt,m);
   gw->setTransform(m);
   DWORD rlim = gw->getRndLimits();
   gw->setRndLimits(GW_WIREFRAME|GW_EDGES_ONLY|GW_BACKCULL| (rlim&GW_Z_BUFFER) );
   if (inode->Selected()) 
      gw->setColor( LINE_COLOR, GetSelColor());
   else if(!inode->IsFrozen() && !inode->Dependent())
      gw->setColor( LINE_COLOR, GetUIColor(COLOR_TAPE_OBJ));
   mesh.render( gw, mtl, NULL, COMP_ALL);
   
   // calc angle
   lastAngle = 0.0;
   #define RadToDegDbl  (180.0 / 3.141592653589793)
   if(refNode[0] && refNode[1]) {
      Point3 origin = m.GetTrans();
      Point3 vec1 = refNode[0]->GetObjectTM(t).GetTrans() - origin;
      Point3 vec2 = refNode[1]->GetObjectTM(t).GetTrans() - origin;
      float len1 = Length(vec1);
      float len2 = Length(vec2);
      if(len1 > 0.00001f && len2 > 0.00001f) {
         double cosAng = (double)DotProd(vec1, vec2) / (double)(len1 * len2);
         if(fabs(cosAng) <= 0.999999)  // beyond float accuracy!
            lastAngle = acos(cosAng) * RadToDegDbl;
         else
            lastAngle = 180.0;
      }
   }
#if 0
   Point3 pt(0,0,0);
   TCHAR buf[32];
   _stprintf(buf, "%g", lastAngle);
   gw->setColor(TEXT_COLOR, GetUIColor(COLOR_TAPE_OBJ));
   gw->text(&pt, buf);
#endif
   DrawLines(t, inode, gw, 1);
   UpdateUI(t);
   gw->setRndLimits(rlim);
   return(0);
}
Example #14
0
void
BackgroundObject::GetWorldBoundBox(TimeValue t, INode* inode, ViewExp* vpt,
                                   Box3& box )
{
    Matrix3 tm;
    BuildMesh(t);            // 000829  --prs.
    GetMat(t,inode,vpt,tm);

    int nv = mesh.getNumVerts();
    box.Init();
    for (int i=0; i<nv; i++) 
        box += tm*mesh.getVert(i);
}
Example #15
0
int TargetObject::Display(TimeValue t, INode* inode, ViewExp *vpt, int flags) {
	if ( ! vpt || ! vpt->IsAlive() )
	{
		// why are we here
		DbgAssert(!_T("Invalid viewport!"));
		return FALSE;
	}
	
	if (MaxSDK::Graphics::IsRetainedModeEnabled())
	{
		// 11/15/2010 
		// In Nitrous view port, do not draw the target when seeing from the target's camera
		if (NULL != vpt && NULL != vpt->GetViewCamera() && vpt->GetViewCamera()->GetTarget() == inode)
		{
			return 0;
		}
	}

	Matrix3 m;
	GraphicsWindow *gw = vpt->getGW();
	GetMat(t,inode,*vpt,m);
	gw->setTransform(m);
	DWORD rlim = gw->getRndLimits();
	gw->setRndLimits(GW_WIREFRAME|GW_EDGES_ONLY|GW_BACKCULL| (rlim&GW_Z_BUFFER) );
	if (inode->Selected()) 
		gw->setColor( LINE_COLOR, GetSelColor());
	else if(!inode->IsFrozen() && !inode->Dependent() && inode->GetLookatNode()) {
		const ObjectState& os = inode->GetLookatNode()->EvalWorldState(t);
		Object* ob = os.obj;

		// 6/25/01 3:32pm --MQM-- 
		// set color to wire-frame color, 
		// instead of COLOR_LIGHT_OBJ or COLOR_CAMERA_OBJ
		if ( (ob!=NULL) && ( (ob->SuperClassID()==LIGHT_CLASS_ID) ||
							 (ob->SuperClassID()==CAMERA_CLASS_ID) ) )
		{													
			Color color(inode->GetWireColor());
			gw->setColor( LINE_COLOR, color );
		}
		else
			gw->setColor( LINE_COLOR, GetUIColor(COLOR_CAMERA_OBJ)); // default target color, just use camera targ color
	}

	mesh.render( gw, gw->getMaterial(), NULL, COMP_ALL);	
    gw->setRndLimits(rlim);
//	gw->fWinMarker(&pt,HOLLOW_BOX_MRKR);
	return(0);
	}
Example #16
0
void TargetObject::GetWorldBoundBox(TimeValue t, INode* inode, ViewExp* vpt, Box3& box )
	{

	if ( ! vpt || ! vpt->IsAlive() )
	{
		box.Init();
		return;
	}

	int i,nv;
	Matrix3 m;
	GetMat(t,inode,*vpt,m);
	nv = mesh.getNumVerts();
	box.Init();
	for (i=0; i<nv; i++) 
		box += m*mesh.getVert(i);
	}
Example #17
0
int TapeHelpObject::Display(TimeValue t, INode* inode, ViewExp *vpt, int flags)
{
    if ( ! vpt || ! vpt->IsAlive() )
    {
        // why are we here
        DbgAssert(!_T("Invalid viewport!"));
        return FALSE;
    }


    Matrix3 m;
    GraphicsWindow *gw = vpt->getGW();
    Material *mtl = gw->getMaterial();

    GetMat(t,inode,*vpt,m);
    gw->setTransform(m);
    DWORD rlim = gw->getRndLimits();
    gw->setRndLimits(GW_WIREFRAME|GW_EDGES_ONLY|GW_BACKCULL| (rlim&GW_Z_BUFFER) );
    if (inode->Selected())
        gw->setColor( LINE_COLOR, GetSelColor());
    else if(!inode->IsFrozen() && !inode->Dependent())
        gw->setColor( LINE_COLOR, GetUIColor(COLOR_TAPE_OBJ));
    mesh.render( gw, mtl, NULL, COMP_ALL);
    DrawLine(t,inode,gw,1);
    gw->setRndLimits(rlim);
    if(editting && !specLenState) {
        Point3 pt(0,0,0);
        Matrix3 tm = inode->GetObjectTM(t);
        GetTargetPoint(t,inode,pt);
        float den = Length(tm.GetRow(2));
        float dist = (den!=0)?Length(tm.GetTrans()-pt)/den : 0.0f;
        lengthSpin->SetValue( lastDist = dist, FALSE );
    }
    if(editting) {
        m.NoTrans();
        dirPt = m * Point3(0,0,1);
        float len = Length(dirPt);
        if(len != 0)
            dirPt *= 1.0f/len;
        UpdateUI(iObjParams->GetTime());
    }
    return(0);
}
Example #18
0
void
ProxSensorObject::GetWorldBoundBox(TimeValue t, INode* inode, ViewExp* vpt,
                                   Box3& box )
{
    if ( ! vpt || ! vpt->IsAlive() )
		{
			// why are we here?
			box.Init();
			return;
		}
		
		Matrix3 tm;
    BuildMesh(t);            // 000829  --prs.
    GetMat(t,inode,*vpt,tm);

    int nv = mesh.getNumVerts();
    box.Init();
    for (int i=0; i<nv; i++) 
        box += tm*mesh.getVert(i);
}
Example #19
0
int
BackgroundObject::HitTest(TimeValue t, INode *inode, int type, int crossing,
                          int flags, IPoint2 *p, ViewExp *vpt)
{
    HitRegion hitRegion;
    DWORD	savedLimits;
    int res = FALSE;
    Matrix3 m;
    GraphicsWindow *gw = vpt->getGW();	
    Material *mtl = gw->getMaterial();
    MakeHitRegion(hitRegion,type,crossing,4,p);	
    gw->setRndLimits(((savedLimits = gw->getRndLimits()) | GW_PICK) & ~GW_ILLUM);
    GetMat(t,inode,vpt,m);
    gw->setTransform(m);
    gw->clearHitCode();
    if (mesh.select( gw, mtl, &hitRegion, flags & HIT_ABORTONHIT )) 
        return TRUE;
    gw->setRndLimits(savedLimits);
    return res;
}
Example #20
0
void ProtHelpObject::GetWorldBoundBox(TimeValue t, INode* inode, ViewExp* vpt, Box3& box )
{
   if ( ! vpt || ! vpt->IsAlive() )
	{
		box.Init();
		return;
	}
	 int i, nv;
   Matrix3 tm;
   Point3 pt;
   GetMat(t,inode,*vpt,tm);
   nv = mesh.getNumVerts();
   box.Init();
   for (i=0; i<nv; i++) 
      box += tm*mesh.getVert(i);

   if (GetTargetPoint(0, t, &pt))
      box += pt;
   if (GetTargetPoint(1, t, &pt))
      box += pt;
}
Example #21
0
int TapeHelpObject::HitTest(TimeValue t, INode *inode, int type, int crossing, int flags, IPoint2 *p, ViewExp *vpt)
{
    if ( ! vpt || ! vpt->IsAlive() )
    {
        // why are we here
        DbgAssert(!_T("Invalid viewport!"));
        return FALSE;
    }

    HitRegion hitRegion;
    DWORD savedLimits;
    int res = 0;
    Matrix3 m;
    if (!enable) return  0;
    GraphicsWindow *gw = vpt->getGW();
    Material *mtl = gw->getMaterial();
    MakeHitRegion(hitRegion,type,crossing,4,p);
    gw->setRndLimits(((savedLimits = gw->getRndLimits()) | GW_PICK) & ~GW_ILLUM);
    GetMat(t,inode,*vpt,m);
    gw->setTransform(m);
    // if we get a hit on the mesh, we're done
    gw->clearHitCode();
    if (mesh.select( gw, mtl, &hitRegion, flags & HIT_ABORTONHIT ))
        return TRUE;
    // if not, check the target line, and set the pair flag if it's hit
    // this special case only works with point selection
    if(type != HITTYPE_POINT)
        return 0;
    // don't let line be active if only looking at selected stuff and target isn't selected
    if((flags & HIT_SELONLY) && (inode->GetTarget()) && !inode->GetTarget()->Selected() )
        return 0;
    gw->clearHitCode();
    res = DrawLine(t,inode,gw,-1);
    if(res != 0)
        inode->SetTargetNodePair(1);
    gw->setRndLimits(savedLimits);
    return res;
}
Example #22
0
int
Cal3DObject::Display(TimeValue t, INode *inode, ViewExp *vpt, int flags)
{
    pblock->GetValue(PB_CAL_SIZE, t, scale, FOREVER);
    if (scale <= 0.0)
        return 0;
    BuildMesh(t);
    Matrix3 m;
    GraphicsWindow *gw = vpt->getGW();
    Material *mtl = gw->getMaterial();

    DWORD rlim = gw->getRndLimits();
    gw->setRndLimits(/*GW_WIREFRAME*/ GW_ILLUM | GW_FLAT | GW_Z_BUFFER | GW_BACKCULL);
    GetMat(t, inode, vpt, m);
    gw->setTransform(m);
    if (inode->Selected())
        gw->setColor(LINE_COLOR, 1.0f, 1.0f, 1.0f);
    else if (!inode->IsFrozen())
        gw->setColor(LINE_COLOR, 0.0f, 1.0f, 0.0f);
    mesh.render(gw, mtl, NULL, COMP_ALL);
    gw->setRndLimits(rlim);
    return (0);
}
Example #23
0
void CGppe::Predictive_Utility_Distribution(MatrixXd t, MatrixXd tstar, int N, VectorXd idx_global)
{
    int Kt_ss = 1;
    VectorXd idx_xstar(N);
    MatrixXd Kstar, Kx_star_star, Kx_star, Kss, Css, Kt_star;
    for (int i = 0;i < N;i++)
    {
        idx_xstar(i) = i;
    }

    Kt_star = covfunc_t->Compute(t, tstar);
    Kx_star = GetMatRow(Kx, idx_xstar);//need to check for tranpose later?
    Kx_star_star = GetMat(Kx, idx_xstar, idx_xstar);

    Kstar = Kron(Kt_star, Kx_star);

    Kstar = GetMatRow(Kstar, idx_global);

    Kss = Kt_ss * Kx_star_star;
    mustar = Kstar.transpose() * Kinv * GetVec(f, idx_global);
    Css = Kss - Kstar.transpose() * W * llt.solve(Kinv * Kstar);
    varstar = Css.diagonal();
}
Example #24
0
double CGppe::maximum_expected_improvement(const VectorXd & theta_t, const VectorXd& theta_x, const double& sigma,
        const MatrixXd& t, const MatrixXd & x, const VectorXd& idx_global, const VectorXd& ind_t, const VectorXd& ind_x, MatrixXd tstar, int N, double fbest)
{
    VectorXd idx_xstar=Nfirst(N);
    int Kt_ss = 1;
    double  mei;
    MatrixXd Kx_star, Kx_star_star, kstar, Kss, Css;
    MatrixXd Kt_star = covfunc_t->Compute(t, tstar);
	//dsp(GetKinv(),"Kinv");


    Kx_star = GetMatRow(Kx, idx_xstar.transpose()); //maybe need some transpose?

    Kx_star_star = GetMat(Kx, idx_xstar.transpose(), idx_xstar.transpose()); // test to test
    kstar = Kron(Kt_star, Kx_star);

    kstar = GetMatRow(kstar, idx_global);
    Kss = Kt_ss * Kx_star_star;


    mustar = kstar.transpose() * Kinv * GetVec(f, idx_global);
    Css    = Kss - kstar.transpose() * W * llt.solve(Kinv * kstar);
    varstar = Css.diagonal();


    VectorXd sigmastar = sqrt(varstar.array());
    VectorXd z = (fbest - mustar.array()) / sigmastar.array();
    VectorXd pdfval = normpdf(z);
    VectorXd cdfval = normcdf(z);
    VectorXd inter = z.array() * (1 - cdfval.array());
    VectorXd el = sigmastar.cwiseProduct(inter - pdfval);

	el=-1*el;
    mei = el.maxCoeff();
    //dsp(mei,"mei");
    return mei;
}
void CQDM_Edit::FillHighlighted(bool CtrlDown) //fill the CurHighlighted array based on current drawing tool and coordinates
{
	switch (CurDrawTool){
		case DT_PEN:{
			int ToAdd = V2DFindVoxelUnder(CurCoord);
			if (!IsInHighlighted(ToAdd) && ToAdd != -1) CurHighlighted.push_back(ToAdd);
			break;
		}
		case DT_BOX: { //could be shortened a little...
			Vec3D<> Loc;
			int x, y, z;
			Vec3D<> BB = Vec3D<>(Lattice.GetXDimAdj(), Lattice.GetYDimAdj(), Lattice.GetZDimAdj())*GetLatticeDim()/2;

			Vec3D<> V1 = CurCoord.Min(DownCoord);
			Vec3D<> V2 = CurCoord.Max(DownCoord);

			CurHighlighted.clear();
			for (int i=0; i<Structure.GetArraySize(); i++){ //go through all voxels...
				GetXYZNom(&x, &y, &z, i);
				Loc = GetXYZ(i);
				//float LatDim = GetLatticeDim();
				switch(CurSecAxis){
					case ZAXIS:
						if (CurSecLayer != z) continue; //don't care if its not in this layer...
						if (Loc.x>V1.x-BB.x && Loc.x<V2.x+BB.x && Loc.y>V1.y-BB.y && Loc.y<V2.y+BB.y) CurHighlighted.push_back(i);
					break;
					case YAXIS:
						if (CurSecLayer != y) continue; //don't care if its not in this layer...
						if (Loc.x>V1.x-BB.x && Loc.x<V2.x+BB.x && Loc.z>V1.z-BB.z && Loc.z<V2.z+BB.z) CurHighlighted.push_back(i);
					break;
					case XAXIS:
						if (CurSecLayer != x) continue; //don't care if its not in this layer...
						if (Loc.y>V1.y-BB.y && Loc.y<V2.y+BB.y && Loc.z>V1.z-BB.z && Loc.z<V2.z+BB.z) CurHighlighted.push_back(i);
					break;
				}
			}
			break;
		}
		case DT_ELLIPSE: {
			Vec3D<> Offset, Off2, Size2;
			int x, y, z;
			Vec3D<> V1 = CurCoord.Min(DownCoord);
			Vec3D<> V2 = CurCoord.Max(DownCoord);

			int VoxN = V2DFindVoxelUnder(V1); //rounds to outside corners of voxels we've selected
			int VoxP = V2DFindVoxelUnder(V2);
			Vec3D<> LocN = GetXYZ(VoxN)-GetLatDimEnv()/2.0;
			Vec3D<> LocP = GetXYZ(VoxP)+GetLatDimEnv()/2.0;
			Vec3D<> Cen = (LocN+LocP)/2.0;
			Vec3D<> Size = (LocP-LocN)/2.0;

			CurHighlighted.clear();
			for (int i=0; i<Structure.GetArraySize(); i++){ //go through all voxels...
				GetXYZNom(&x, &y, &z, i);
				Offset = GetXYZ(i)-Cen;
				Off2 = Offset.Scale(Offset);
				Size2 = Size.Scale(Size);

				double LatDim = GetLatticeDim();
				switch(CurSecAxis){
					case ZAXIS:
						if (CurSecLayer != z) continue; //don't care if its not in this layer...
						if (Off2.x/Size2.x + Off2.y/Size2.y<1.0001) CurHighlighted.push_back(i);
					break;
					case YAXIS:
						if (CurSecLayer != y) continue; //don't care if its not in this layer...
						if (Off2.x/Size2.x + Off2.z/Size2.z<1.0001) CurHighlighted.push_back(i);
					break;
					case XAXIS:
						if (CurSecLayer != x) continue; //don't care if its not in this layer...
						if (Off2.y/Size2.y + Off2.z/Size2.z<1.0001) CurHighlighted.push_back(i);
					break;
				}
			}
			break;
		}
		case DT_BUCKET: {
			int CVox = V2DFindVoxelUnder(CurCoord);
			int ThisMat = GetMat(CVox);
			CurHighlighted.clear();
			CurHighlighted.push_back(CVox); //put the first index on the buffer...
//			if (ViewSection)

			int Iter = 0;
			int Xi, Yi, Zi, curInd, tmpInd;
			while (Iter != (int)CurHighlighted.size()){
				curInd = CurHighlighted[Iter];
				GetXYZNom(&Xi, &Yi, &Zi, curInd); //this location...

				
				for (int i=-1; i<=1; i++){for (int j=-1; j<=1; j++){for (int k=-1; k<=1; k++){
					if (i!=0 && !CtrlDown && (ViewSection && CurSecAxis == XAXIS)) continue; //if we are out of plane of current viewing section
					if (j!=0 && !CtrlDown&& (ViewSection && CurSecAxis == YAXIS)) continue;
					if (k!=0 && !CtrlDown && (ViewSection && CurSecAxis == ZAXIS)) continue;

					tmpInd = GetIndex(Xi+i, Yi+j, Zi+k);
					if (IsAdjacent(curInd, tmpInd, true) && GetMat(tmpInd) == ThisMat && !IsInHighlighted(tmpInd)) CurHighlighted.push_back(tmpInd);
				}}}

				Iter++;
			}

		}
	}
}