void sizeofCalculation() { check("int a, b; int a,sizeof(a+b)"); ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str()); check("int a, b; sizeof(a*b)"); ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str()); check("int a, b; sizeof(-a)"); ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str()); check("int a, b; sizeof(*a)"); ASSERT_EQUALS("", errout.str()); check("sizeof(void * const)"); ASSERT_EQUALS("", errout.str()); check("sizeof(int*[2])"); ASSERT_EQUALS("", errout.str()); check("sizeof(Fred**)"); ASSERT_EQUALS("", errout.str()); check("sizeof(foo++)"); ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str()); check("sizeof(--foo)"); ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str()); // #6888 checkP("#define SIZEOF1 sizeof(i != 2)\n" "#define SIZEOF2 ((sizeof(i != 2)))\n" "#define VOIDCAST1 (void)\n" "#define VOIDCAST2(SZ) static_cast<void>(SZ)\n" "int f(int i) {\n" " VOIDCAST1 SIZEOF1;\n" " VOIDCAST1 SIZEOF2;\n" " VOIDCAST2(SIZEOF1);\n" " VOIDCAST2(SIZEOF2);\n" " return i + foo(1);\n" "}"); ASSERT_EQUALS("", errout.str()); checkP("#define SIZEOF1 sizeof(i != 2)\n" "#define SIZEOF2 ((sizeof(i != 2)))\n" "int f(int i) {\n" " SIZEOF1;\n" " SIZEOF2;\n" " return i + foo(1);\n" "}"); ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) Found calculation inside sizeof().\n" "[test.cpp:5]: (warning, inconclusive) Found calculation inside sizeof().\n", errout.str()); }
void Reconstruction3D::computeP(const std::vector<std::pair<Eigen::Vector2d, Eigen::Vector2d>>& points, const Eigen::MatrixXd& E, std::vector<Eigen::MatrixXd>& P_solutions) { P_solutions.clear(); Eigen::JacobiSVD< Eigen::MatrixXd, Eigen::FullPivHouseholderQRPreconditioner > svd(E, Eigen::ComputeFullU | Eigen::ComputeFullV); Eigen::MatrixXd U = svd.matrixU(); Eigen::MatrixXd Vt = svd.matrixV().transpose(); Eigen::MatrixXd W(3, 3); W << 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0; Eigen::VectorXd u3 = U.col(2); //std::cout << "--- Computing P Matrix: " << std::endl // << "E: " << std::endl << E << std::endl << std::endl // << "U: " << std::endl << U << std::endl << std::endl // << "D: " << std::endl << svd.singularValues() << std::endl << std::endl // << "Vt: " << std::endl << Vt << std::endl << std::endl // << "W: " << std::endl << W << std::endl << std::endl // << "u3 :" << u3 << std::endl << std::endl; Eigen::MatrixXd P0(Eigen::MatrixXd::Identity(3, 4)); // Just K0: no translation or rotation. Eigen::MatrixXd UWVt = U * W * Vt; // P without translation part. Eigen::MatrixXd P1(3, 4); P1.block(0, 0, 3, 3) = UWVt; P1.block(0, 3, 3, 1) = u3; Eigen::MatrixXd bestP1; int numCorrectSolutions = 0; if (checkP(points, P0, P1)) { ++numCorrectSolutions; bestP1 = P1; std::cout << std::endl << "[Info] Best solution for P: 1st" << std::endl << std::endl; } P_solutions.push_back(P1); P1.block(0, 3, 3, 1) = -u3; if (checkP(points, P0, P1)) { ++numCorrectSolutions; bestP1 = P1; std::cout << std::endl << "[Info] Best solution for P: 2nd" << std::endl << std::endl; } P_solutions.push_back(P1); UWVt = U * W.transpose() * Vt; P1.block(0, 0, 3, 3) = UWVt; P1.block(0, 3, 3, 1) = u3; if (checkP(points, P0, P1)) { ++numCorrectSolutions; bestP1 = P1; std::cout << std::endl << "[Info] Best solution for P: 3rd" << std::endl << std::endl; } P_solutions.push_back(P1); P1.block(0, 3, 3, 1) = -u3; if (checkP(points, P0, P1)) { ++numCorrectSolutions; bestP1 = P1; std::cout << std::endl << "[Info] Best solution for P: 4th" << std::endl << std::endl; } P_solutions.push_back(P1); std::cout << "[Info] Number of correct solutions: " << numCorrectSolutions << std::endl << std::endl; }
/// Check validity of temperature, pressure and composition input. bool IncompressibleSolution::checkTPX(double T, double p, double x) { return (checkT(T,p,x) && checkP(T,p,x) && checkX(x)); }
Eigen::MatrixXd Reconstruction3D::computeP( const std::vector<std::pair<Eigen::Vector2d, Eigen::Vector2d>>& points, const Eigen::MatrixXd& E) { Eigen::JacobiSVD< Eigen::MatrixXd, Eigen::FullPivHouseholderQRPreconditioner > svd(E, Eigen::ComputeFullU | Eigen::ComputeFullV); Eigen::MatrixXd U = svd.matrixU(); Eigen::MatrixXd Vt = svd.matrixV().transpose(); Eigen::MatrixXd W(3, 3); W << 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0; Eigen::VectorXd u3 = U.col(2); //std::cout << "--- Computing P Matrix: " << std::endl // << "E: " << std::endl << E << std::endl << std::endl // << "U: " << std::endl << U << std::endl << std::endl // << "D: " << std::endl << svd.singularValues() << std::endl << std::endl // << "Vt: " << std::endl << Vt << std::endl << std::endl // << "W: " << std::endl << W << std::endl << std::endl // << "u3 :" << u3 << std::endl << std::endl; Eigen::MatrixXd P0(Eigen::MatrixXd::Identity(3, 4)); // Just K0: no translation or rotation. Eigen::MatrixXd UWVt = U * W * Vt; // P without translation part. Eigen::MatrixXd P1(3, 4); P1.block(0, 0, 3, 3) = UWVt; P1.block(0, 3, 3, 1) = u3; Eigen::MatrixXd bestP1 = P0; int numCorrectSolutions = 0; if (checkP(points, P0, P1)) { ++numCorrectSolutions; bestP1 = P1; } P1.block(0, 3, 3, 1) = -u3; if (checkP(points, P0, P1)) { ++numCorrectSolutions; bestP1 = P1; } UWVt = U * W.transpose() * Vt; P1.block(0, 0, 3, 3) = UWVt; P1.block(0, 3, 3, 1) = u3; if (checkP(points, P0, P1)) { ++numCorrectSolutions; bestP1 = P1; } P1.block(0, 3, 3, 1) = -u3; if (checkP(points, P0, P1)) { ++numCorrectSolutions; bestP1 = P1; } std::cout << "Number of correct solutions: " << numCorrectSolutions << std::endl << std::endl; if (numCorrectSolutions < 1) std::cerr << "[Error] : None of the results for P1 was accepted!" << std::endl << std::endl; else if (numCorrectSolutions > 1) std::cerr << "[Error] : More than one solution found : " << numCorrectSolutions << std::endl << std::endl; // else // std::cerr << "[Info] : Solution found for P: \n" << bestP1 << std::endl << std::endl; return bestP1; }