Exemple #1
0
void FrustumCulling::ComputeFrustum(
  double horizontalFOV, double verticalFOV,
  double nearPlaneDist, double farPlaneDist
)
{
  // view vector for the camera  - third column of the orientation matrix
  Eigen::Vector3d view = orientation_.col( 2 );
  // up vector for the camera  - second column of the orientation matix
  Eigen::Vector3d up = -orientation_.col( 1 );
  // right vector for the camera - first column of the orientation matrix
  Eigen::Vector3d right = orientation_.col( 0 );

  float vfov_rad = float (verticalFOV * M_PI / 180); // degrees to radians
  float hfov_rad = float (horizontalFOV * M_PI / 180); // degrees to radians

  float np_h = float (2 * tan (vfov_rad / 2) * nearPlaneDist);  // near plane height
  float np_w = float (2 * tan (hfov_rad / 2) * nearPlaneDist);  // near plane width

  float fp_h = float (2 * tan (vfov_rad / 2) * farPlaneDist);    // far plane height
  float fp_w = float (2 * tan (hfov_rad / 2) * farPlaneDist);    // far plane width

  Eigen::Vector3d fp_c (position_ + view * farPlaneDist);  // far plane center
  fp_tl = Eigen::Vector3d(fp_c + (up * fp_h / 2) - (right * fp_w / 2));  // Top left corner of the far plane
  fp_tr = Eigen::Vector3d(fp_c + (up * fp_h / 2) + (right * fp_w / 2));  // Top right corner of the far plane
  fp_bl = Eigen::Vector3d(fp_c - (up * fp_h / 2) - (right * fp_w / 2));  // Bottom left corner of the far plane
  fp_br = Eigen::Vector3d(fp_c - (up * fp_h / 2) + (right * fp_w / 2));  // Bottom right corner of the far plane

  Eigen::Vector3d np_c (position_ + view * nearPlaneDist);                   // near plane center
  Eigen::Vector3d np_tr (np_c + (up * np_h / 2) + (right * np_w / 2));   // Top right corner of the near plane
  Eigen::Vector3d np_bl (np_c - (up * np_h / 2) - (right * np_w / 2));   // Bottom left corner of the near plane
  Eigen::Vector3d np_br (np_c - (up * np_h / 2) + (right * np_w / 2));   // Bottom right corner of the near plane

  Eigen::Vector3d fp_b_vec = fp_bl - fp_br;
  Eigen::Vector3d fp_normal =  fp_b_vec.cross(fp_tr - fp_br);   // Far plane equation - cross product of the perpendicular edges of the far plane
  farPlane_.head( 3 ) = fp_normal;
  farPlane_[ 3 ] = -fp_c.dot( fp_normal );

  Eigen::Vector3d np_b_vec = np_tr - np_br;
  Eigen::Vector3d np_normal =  np_b_vec.cross(np_bl - np_br);   // Near plane equation - cross product of the perpendicular edges of the near plane
  nearPlane_.head( 3 ) = np_normal;
  nearPlane_[3] = -np_c.dot( np_normal );

  Eigen::Vector3d a (fp_bl - position_);    // Vector connecting the camera and far plane bottom left
  Eigen::Vector3d b (fp_br - position_);    // Vector connecting the camera and far plane bottom right
  Eigen::Vector3d c (fp_tr - position_);    // Vector connecting the camera and far plane top right
  Eigen::Vector3d d (fp_tl - position_);    // Vector connecting the camera and far plane top left

  //                   Frustum and the vectors a, b, c and d. 'position_' is the position of the camera
  //                             _________
  //                           /|       . |
  //                       d  / |   c .   |
  //                         /  | __._____|
  //                        /  /  .      .
  //                 a <---/-/  .    .
  //                      / / .   .  b
  //                     /   .
  //                     .
  //                   T
  //

//  std::cout << "a: " << a << std::endl;
//  std::cout << "d: " << d << std::endl;
//  std::cout << "d: " << T << std::endl;

  Eigen::Vector3d rightPlane_normal = b.cross (c);
  rightPlane_.head( 3 ) = rightPlane_normal;
  rightPlane_[3] = -position_.dot( rightPlane_normal );

  Eigen::Vector3d leftPlane_normal = d.cross (a);
  leftPlane_.head( 3 ) = leftPlane_normal;
  leftPlane_[3] = -position_.dot( leftPlane_normal );

  Eigen::Vector3d topPlane_normal = c.cross (d);
  topPlane_.head( 3 ) = topPlane_normal;
  topPlane_[3] = -position_.dot( topPlane_normal );

  Eigen::Vector3d bottomPlane_normal = a.cross (b);
  bottomPlane_.head( 3 ) = bottomPlane_normal;
  bottomPlane_[3] = -position_.dot( bottomPlane_normal );

//  std::cout << "leftPlane_normal: " << leftPlane_normal << std::endl;

//  std::cout << "nearPlane_:" << std::endl << nearPlane_ << std::endl;
//  std::cout << "farPlane_:" << std::endl << farPlane_ << std::endl;
//  std::cout << "leftPlane_:" << std::endl << leftPlane_ << std::endl;
//  std::cout << "rightPlane_:" << std::endl << rightPlane_ << std::endl;
//  std::cout << "topPlane_:" << std::endl << topPlane_ << std::endl;
//  std::cout << "bottomPlane_:" << std::endl << bottomPlane_ << std::endl;
}
Exemple #2
0
void infer_slope(const QUESO::FullEnvironment & env) {


// Statistical Inverse Problem: Compute posterior pdf for slope 'm' and y-intercept c

// Step 1: Instantiate the parameter space

	QUESO::VectorSpace<> paramSpace(env, "param_", 2, NULL); // 2 since we have a 2D problem
	
// Step 2: Parameter domain

	QUESO::GslVector paramMinValues(paramSpace.zeroVector());
	QUESO::GslVector paramMaxValues(paramSpace.zeroVector());

	paramMinValues[0] = 2.;
	paramMaxValues[0] = 5.;

	paramMinValues[1] = 3.;
	paramMaxValues[1] = 7.;
	
	QUESO::BoxSubset<> paramDomain("param_", paramSpace, paramMinValues, paramMaxValues);

// Step 3: Instantiate likelihood

	Likelihood<> lhood("like_", paramDomain);

// Step 4: Define the prior RV

	QUESO::UniformVectorRV<> priorRv("prior_", paramDomain);

// Step 5: Instantiate the inverse problem

	QUESO::GenericVectorRV<> postRv("post_", paramSpace);
	QUESO::StatisticalInverseProblem<> ip("", NULL, priorRv, lhood, postRv);

// Step 6: Solve the inverse problem

// Randomly sample for the initial state?
	QUESO::GslVector paramInitials(paramSpace.zeroVector());
	priorRv.realizer().realization(paramInitials);

// Initialize the Cov matrix:
	QUESO::GslMatrix proposalCovMatrix(paramSpace.zeroVector());
	proposalCovMatrix(0,0) = std::pow(std::abs(paramInitials[0]) / 20.0, 2.0);
	proposalCovMatrix(1,1) = std::pow(std::abs(paramInitials[1]) / 20.0, 2.0);

	ip.solveWithBayesMetropolisHastings(NULL, paramInitials, &proposalCovMatrix);

// Using the posterior pdfs for m and c, compute 'y' at a given 'x'
 
// Step 1: Instantiate the qoi space

	QUESO::VectorSpace<> qoiSpace(env, "qoi_", 1, NULL);

// Step 2: Instantiate the parameter domain

// Not necessary here because the posterior from SIP is used as the RV for SFP

// Step 3: Instantiate the qoi object to be used by QUESO

	Qoi<> qoi("qoi_", paramDomain, qoiSpace);

// Step 4: Define the input RV

// Not required because we use the posterior as RV

// Step 5: Instantiate the forward problem

	QUESO::GenericVectorRV<> qoiRv("qoi_", qoiSpace);
	
	QUESO::StatisticalForwardProblem<> fp("", NULL, postRv, qoi, qoiRv);

// Step 6: Solve the forward problem

	std::cout << "Solving the SFP with Monte Carlo" << std::endl << std::endl;
	fp.solveWithMonteCarlo(NULL);

	system("mv outputData/sfp_lineSlope_qoi_seq.txt outputData/sfp_lineSlope_qoi_seq_post.txt");

// SENSITIVITY ANALYSIS

// For m

	Qoi_m<> qoi_m("qoi_", paramDomain, qoiSpace);
		
// Step 4: Define the input RV

// Not required because we use the prior as RV for sensitivity analysis

// Step 5: Instantiate the forward problem

	QUESO::StatisticalForwardProblem<> fp_m("", NULL, priorRv, qoi_m, qoiRv);

// Step 6: Solve the forward problem

	fp_m.solveWithMonteCarlo(NULL);

	system("mv outputData/sfp_lineSlope_qoi_seq.txt outputData/sense_m.txt");

// For c

	Qoi_c<> qoi_c("qoi_", paramDomain, qoiSpace);
		
// Step 4: Define the input RV

// Not required because we use the prior as RV for sensitivity analysis

// Step 5: Instantiate the forward problem

	QUESO::StatisticalForwardProblem<> fp_c("", NULL, priorRv, qoi_c, qoiRv);

// Step 6: Solve the forward problem

	fp_c.solveWithMonteCarlo(NULL);

	system("mv outputData/sfp_lineSlope_qoi_seq.txt outputData/sense_c.txt");

// For both, m and c

	Qoi_mc<> qoi_mc("qoi_", paramDomain, qoiSpace);
		
// Step 4: Define the input RV

// Not required because we use the prior as RV for sensitivity analysis

// Step 5: Instantiate the forward problem

	QUESO::StatisticalForwardProblem<> fp_mc("", NULL, priorRv, qoi_mc, qoiRv);

// Step 6: Solve the forward problem

	fp_mc.solveWithMonteCarlo(NULL);

	system("mv outputData/sfp_lineSlope_qoi_seq.txt outputData/sense_mc.txt");
}