diff options
-rw-r--r-- | filter-ewma2/ftnoir_filter_ewma2.cpp | 2 | ||||
-rw-r--r-- | filter-kalman/kalman.cpp | 2 | ||||
-rw-r--r-- | opentrack-compat/options.cpp | 2 | ||||
-rw-r--r-- | pose-widget/glwidget.cpp | 22 | ||||
-rw-r--r-- | proto-fsuipc/ftnoir_protocol_fsuipc.cpp | 3 | ||||
-rw-r--r-- | spline-widget/functionconfig.cpp | 20 | ||||
-rw-r--r-- | tracker-aruco/ftnoir_tracker_aruco.cpp | 34 | ||||
-rw-r--r-- | tracker-pt/camera.cpp | 6 | ||||
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt.cpp | 3 | ||||
-rwxr-xr-x | tracker-pt/point_tracker.cpp | 19 | ||||
-rw-r--r-- | tracker-pt/point_tracker.h | 2 | ||||
-rw-r--r-- | tracker-rift-025/ftnoir_tracker_rift_025.cpp | 6 | ||||
-rwxr-xr-x | tracker-rift-080/ftnoir_tracker_rift_080.cpp | 2 |
13 files changed, 67 insertions, 56 deletions
diff --git a/filter-ewma2/ftnoir_filter_ewma2.cpp b/filter-ewma2/ftnoir_filter_ewma2.cpp index c09fb912..6f9e428c 100644 --- a/filter-ewma2/ftnoir_filter_ewma2.cpp +++ b/filter-ewma2/ftnoir_filter_ewma2.cpp @@ -49,7 +49,7 @@ void FTNoIR_Filter::filter(const double *input, double *output) } } // Get the time in seconds since last run and restart the timer. - auto dt = timer.restart() / 1000.0f; + const double dt = timer.restart() / 1000; // Calculate delta_alpha and noise_alpha from dt. double delta_alpha = dt/(dt + delta_RC); double noise_alpha = dt/(dt + noise_RC); diff --git a/filter-kalman/kalman.cpp b/filter-kalman/kalman.cpp index 39a08703..0e7537d1 100644 --- a/filter-kalman/kalman.cpp +++ b/filter-kalman/kalman.cpp @@ -80,7 +80,7 @@ void FTNoIR_Filter::filter(const double* input, double *output) if (!timer.isValid()) timer.start(); // Get the time in seconds since last run and restart the timer. - auto dt = timer.restart() / 1000.0f; + const double dt = timer.restart() / 1000; // Note this is a terrible way to detect when there is a new // frame of tracker input, but it is the best we have. bool new_input = false; diff --git a/opentrack-compat/options.cpp b/opentrack-compat/options.cpp index 550fec24..9dcb10ab 100644 --- a/opentrack-compat/options.cpp +++ b/opentrack-compat/options.cpp @@ -160,7 +160,7 @@ pbundle opt_singleton::bundle(const opt_singleton::k &key) qDebug() << "bundle +" << key; auto shr = std::make_shared<v>(key); - implsgl_data[key] = tt(cnt(1), shr); + implsgl_data[key] = tt(1, shr); return shr; } diff --git a/pose-widget/glwidget.cpp b/pose-widget/glwidget.cpp index 1b30e585..a2ed422e 100644 --- a/pose-widget/glwidget.cpp +++ b/pose-widget/glwidget.cpp @@ -34,13 +34,15 @@ void GLWidget::paintEvent ( QPaintEvent * event ) { void GLWidget::rotateBy(float xAngle, float yAngle, float zAngle, float x, float y, float z) { + using std::sin; + using std::cos; - float c1 = cos(yAngle / 57.295781); - float s1 = sin(yAngle / 57.295781); - float c2 = cos(xAngle / 57.295781); - float s2 = sin(xAngle / 57.295781); - float c3 = cos(zAngle / 57.295781); - float s3 = sin(zAngle / 57.295781); + float c1 = cos(yAngle / 57.295781f); + float s1 = sin(yAngle / 57.295781f); + float c2 = cos(xAngle / 57.295781f); + float s2 = sin(xAngle / 57.295781f); + float c3 = cos(zAngle / 57.295781f); + float s3 = sin(zAngle / 57.295781f); rotation = rmat(c2*c3, -c2*s3, s2, c1*s3+c3*s1*s2, c1*c3-s1*s2*s3, -c2*s1, @@ -86,12 +88,14 @@ private: inline GLWidget::vec3 GLWidget::normal(const vec3& p1, const vec3& p2, const vec3& p3) { + using std::sqrt; + vec3 u = p2 - p1; vec3 v = p3 - p1; vec3 tmp = u.cross(v); - num i = 1./sqrt(tmp.dot(tmp)); + num i = 1/sqrt(tmp.dot(tmp)); return tmp * i; } @@ -199,7 +203,7 @@ void GLWidget::project_quad_texture() { const unsigned char r___ = orig[orig_pos___ + 2]; const unsigned char g___ = orig[orig_pos___ + 1]; const unsigned char b___ = orig[orig_pos___ + 0]; - + const unsigned char a1 = orig[orig_pos + 3]; const unsigned char a2 = orig[orig_pos_ + 3]; const unsigned char a3 = orig[orig_pos__ + 3]; @@ -224,7 +228,7 @@ void GLWidget::project_quad_texture() { GLWidget::vec2 GLWidget::project(const vec3 &point) { vec3 ret = rotation * point; - num z = std::max<num>(.75, 1. + translation.z()/-60); + num z = std::max<num>(.75f, 1 + translation.z()/-60); int w = width(), h = height(); num x = w * translation.x() / 2 / -40; if (std::abs(x) > w/2) diff --git a/proto-fsuipc/ftnoir_protocol_fsuipc.cpp b/proto-fsuipc/ftnoir_protocol_fsuipc.cpp index 702a92d4..91a61693 100644 --- a/proto-fsuipc/ftnoir_protocol_fsuipc.cpp +++ b/proto-fsuipc/ftnoir_protocol_fsuipc.cpp @@ -28,8 +28,7 @@ FTNoIR_Protocol::~FTNoIR_Protocol() } int FTNoIR_Protocol::scale2AnalogLimits( float x, float min_x, float max_x ) { -double y; -double local_x; + float y, local_x; local_x = x; if (local_x > max_x) { diff --git a/spline-widget/functionconfig.cpp b/spline-widget/functionconfig.cpp index 777b4f6f..9fb5ea38 100644 --- a/spline-widget/functionconfig.cpp +++ b/spline-widget/functionconfig.cpp @@ -84,8 +84,8 @@ void Map::reload() { auto& data = cur.data; data = std::vector<float>(value_count); - const int mult = precision(); - const int mult_ = mult * 30; + const float mult = precision(); + const float mult_ = mult * 30; const int sz = data.size(); @@ -112,24 +112,24 @@ void Map::reload() { const float p0_y = p0.y(), p1_y = p1.y(), p2_y = p2.y(), p3_y = p3.y(); // multiplier helps fill in all the x's needed - const int end = std::min<int>(sz, p2.x() * mult_); - const int start = p1.x() * mult; + const int end = std::min<int>(sz, p2_x * mult_); + const int start = p1_x * mult; for (int j = start; j < end; j++) { const float t = (j - start) / (float) (end - start); const float t2 = t*t; const float t3 = t*t*t; - const int x = .5 * ((2. * p1_x) + + const int x = .5f * ((2.f * p1_x) + (-p0_x + p2_x) * t + - (2. * p0_x - 5. * p1_x + 4. * p2_x - p3_x) * t2 + - (-p0_x + 3. * p1_x - 3. * p2_x + p3_x) * t3) + (2.f * p0_x - 5.f * p1_x + 4.f * p2_x - p3_x) * t2 + + (-p0_x + 3.f * p1_x - 3.f * p2_x + p3_x) * t3) * mult; - const float y = .5 * ((2. * p1_y) + + const float y = .5f * ((2.f * p1_y) + (-p0_y + p2_y) * t + - (2. * p0_y - 5. * p1_y + 4. * p2_y - p3_y) * t2 + - (-p0_y + 3. * p1_y - 3. * p2_y + p3_y) * t3); + (2. * p0_y - 5.f * p1_y + 4.f * p2_y - p3_y) * t2 + + (-p0_y + 3.f * p1_y - 3.f * p2_y + p3_y) * t3); if (x >= 0 && x < sz) data[x] = y; diff --git a/tracker-aruco/ftnoir_tracker_aruco.cpp b/tracker-aruco/ftnoir_tracker_aruco.cpp index 316c7e13..294552ea 100644 --- a/tracker-aruco/ftnoir_tracker_aruco.cpp +++ b/tracker-aruco/ftnoir_tracker_aruco.cpp @@ -216,27 +216,29 @@ void Tracker::run() ::sprintf(buf, "Hz: %d", (int)cur_fps); cv::putText(frame, buf, cv::Point(10, 32), cv::FONT_HERSHEY_PLAIN, scale, cv::Scalar(0, 255, 0), scale*2); + const float hx = s.headpos_x, hy = s.headpos_y, hz = s.headpos_z; + if (markers.size() == 1 && markers[0].size() == 4) { const auto& m = markers.at(0); - const float size = 40; + constexpr float size = 40; cv::Mat obj_points(4,3,CV_32FC1); const int x1=1, x2=2, x3=3, x4=0; - obj_points.at<float>(x1,0)=-size + s.headpos_x; - obj_points.at<float>(x1,1)=-size + s.headpos_y; - obj_points.at<float>(x1,2)= 0 + s.headpos_z; + obj_points.at<float>(x1,0)=-size + hx; + obj_points.at<float>(x1,1)=-size + hy; + obj_points.at<float>(x1,2)= 0 + hz; - obj_points.at<float>(x2,0)=size + s.headpos_x; - obj_points.at<float>(x2,1)=-size + s.headpos_y; - obj_points.at<float>(x2,2)= 0 + s.headpos_z; + obj_points.at<float>(x2,0)=size + hx; + obj_points.at<float>(x2,1)=-size + hy; + obj_points.at<float>(x2,2)= 0 + hz; - obj_points.at<float>(x3,0)=size + s.headpos_x; - obj_points.at<float>(x3,1)=size + s.headpos_y; - obj_points.at<float>(x3,2)= 0 + s.headpos_z; + obj_points.at<float>(x3,0)=size + hx; + obj_points.at<float>(x3,1)=size + hy; + obj_points.at<float>(x3,2)= 0 + hz; - obj_points.at<float>(x4,0)= -size + s.headpos_x; - obj_points.at<float>(x4,1)= size + s.headpos_y; - obj_points.at<float>(x4,2)= 0 + s.headpos_z; + obj_points.at<float>(x4,0)= -size + hx; + obj_points.at<float>(x4,1)= size + hy; + obj_points.at<float>(x4,2)= 0 + hz; std::vector<cv::Point2f> img_points = m; if (!cv::solvePnP(obj_points, img_points, intrinsics, dist_coeffs, rvec, tvec, false, cv::SOLVEPNP_ITERATIVE)) @@ -256,9 +258,9 @@ void Tracker::run() for (int i = 0; i < 4; i++) { - obj_points.at<float>(i, 0) -= s.headpos_x; - obj_points.at<float>(i, 1) -= s.headpos_y; - obj_points.at<float>(i, 2) -= s.headpos_z; + obj_points.at<float>(i, 0) -= hx; + obj_points.at<float>(i, 1) -= hy; + obj_points.at<float>(i, 2) -= hz; } cv::Mat rvec_, tvec_; diff --git a/tracker-pt/camera.cpp b/tracker-pt/camera.cpp index 600ab26a..c995c11b 100644 --- a/tracker-pt/camera.cpp +++ b/tracker-pt/camera.cpp @@ -57,12 +57,12 @@ bool Camera::get_frame(float dt, cv::Mat* frame) { bool new_frame = _get_frame(frame); // measure fps of valid frames - const float dt_smoothing_const = 0.95; + constexpr float dt_smoothing_const = 0.95; dt_valid += dt; if (new_frame) { - dt_mean = dt_smoothing_const * dt_mean + (1.0 - dt_smoothing_const) * dt_valid; - cam_info.fps = dt_mean > 1e-3 ? 1.0 / dt_mean : 0; + dt_mean = dt_smoothing_const * dt_mean + (1 - dt_smoothing_const) * dt_valid; + cam_info.fps = dt_mean > 1e-3f ? 1 / dt_mean : 0; dt_valid = 0; } else diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp index c4ab5963..3415eecd 100644 --- a/tracker-pt/ftnoir_tracker_pt.cpp +++ b/tracker-pt/ftnoir_tracker_pt.cpp @@ -197,6 +197,9 @@ void Tracker_PT::data(double *data) 0, 1, 0); R = R_EG * R * R_EG.t(); + using std::atan2; + using std::sqrt; + // extract rotation angles float alpha, beta, gamma; beta = atan2( -R(2,0), sqrt(R(2,1)*R(2,1) + R(2,2)*R(2,2)) ); diff --git a/tracker-pt/point_tracker.cpp b/tracker-pt/point_tracker.cpp index 493f311c..c7947c98 100755 --- a/tracker-pt/point_tracker.cpp +++ b/tracker-pt/point_tracker.cpp @@ -166,11 +166,14 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float cv::Matx33f R_1, R_2; cv::Matx33f* R_current; - const int MAX_ITER = 100; - const float EPS_THRESHOLD = 1e-4; + constexpr int MAX_ITER = 100; + const float EPS_THRESHOLD = 1e-4f; const cv::Vec2f* order = order_.points; + using std::sqrt; + using std::atan; + int i=1; for (; i<MAX_ITER; ++i) { @@ -178,10 +181,10 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float epsilon_2 = k.dot(model.M02)/Z0; // vector of scalar products <I0, M0i> and <J0, M0i> - cv::Vec2f I0_M0i(order[1][0]*(1.0 + epsilon_1) - order[0][0], - order[2][0]*(1.0 + epsilon_2) - order[0][0]); - cv::Vec2f J0_M0i(order[1][1]*(1.0 + epsilon_1) - order[0][1], - order[2][1]*(1.0 + epsilon_2) - order[0][1]); + cv::Vec2f I0_M0i(order[1][0]*(1 + epsilon_1) - order[0][0], + order[2][0]*(1 + epsilon_2) - order[0][0]); + cv::Vec2f J0_M0i(order[1][1]*(1 + epsilon_1) - order[0][1], + order[2][1]*(1 + epsilon_2) - order[0][1]); // construct projection of I, J onto M0i plane: I0 and J0 I0_coeff = model.P * I0_M0i; @@ -194,7 +197,7 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float float IJ0 = I0.dot(J0); float JJ0 = J0.dot(J0); float rho, theta; - // CAVEAT don't change to comparison with a small epsilon, e.g. 1e-4. -sh 20160423 + // CAVEAT don't change to comparison with an epsilon -sh 20160423 if (JJ0 == II0) { rho = std::sqrt(std::abs(2*IJ0)); theta = -PI/4; @@ -215,7 +218,7 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float J_1 = J0 + rho*sin(theta)*model.u; J_2 = J0 - rho*sin(theta)*model.u; - float norm_const = 1.0/cv::norm(I_1); // all have the same norm + float norm_const = 1/cv::norm(I_1); // all have the same norm // create rotation matrices I_1 *= norm_const; J_1 *= norm_const; diff --git a/tracker-pt/point_tracker.h b/tracker-pt/point_tracker.h index 2757f22c..e70059ff 100644 --- a/tracker-pt/point_tracker.h +++ b/tracker-pt/point_tracker.h @@ -78,7 +78,7 @@ public: float s11 = M01.dot(M01); float s12 = M01.dot(M02); float s22 = M02.dot(M02); - P = 1.0/(s11*s22-s12*s12) * cv::Matx22f(s22, -s12, -s12, s11); + P = 1/(s11*s22-s12*s12) * cv::Matx22f(s22, -s12, -s12, s11); } void set_model(settings_pt& s) diff --git a/tracker-rift-025/ftnoir_tracker_rift_025.cpp b/tracker-rift-025/ftnoir_tracker_rift_025.cpp index 9588aaf8..4b938763 100644 --- a/tracker-rift-025/ftnoir_tracker_rift_025.cpp +++ b/tracker-rift-025/ftnoir_tracker_rift_025.cpp @@ -67,9 +67,9 @@ void Rift_Tracker::data(double *data) Quatf hmdOrient = pSFusion->GetOrientation(); double newHeadPose[6]; - float yaw = 0.0f; - float pitch = 0.0f; - float roll = 0.0f; + float yaw = 0; + float pitch = 0; + float roll = 0; hmdOrient.GetEulerAngles<Axis_Y, Axis_X, Axis_Z>(&yaw, &pitch , &roll); newHeadPose[Pitch] = pitch; newHeadPose[Roll] = roll; diff --git a/tracker-rift-080/ftnoir_tracker_rift_080.cpp b/tracker-rift-080/ftnoir_tracker_rift_080.cpp index 059f67e8..d5d6cbd6 100755 --- a/tracker-rift-080/ftnoir_tracker_rift_080.cpp +++ b/tracker-rift-080/ftnoir_tracker_rift_080.cpp @@ -57,7 +57,7 @@ void Rift_Tracker::data(double *data) yaw += s.constant_drift; old_yaw=yaw; } - constexpr double d2r = 57.295781; + constexpr float d2r = 57.295781f; data[Yaw] = yaw * -d2r; data[Pitch] = pitch * d2r; data[Roll] = roll * d2r; |