diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2005-11-14 22:28:49 +0100 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2005-11-14 22:28:49 +0100 |
commit | 7bf6b08fcda6c2fc37405e4a77f23b73191bd671 (patch) | |
tree | 02df42664ab05af84c5048c02fb054cde5cdbdde | |
parent | 19850dc902ecd194254043adc457916c462a0263 (diff) |
fix ProjectionSphaeric::comp_params()
sprinkle some const
add copy constructor to Hill
-rw-r--r-- | src/Hill.H | 2 | ||||
-rw-r--r-- | src/Hill.cxx | 16 | ||||
-rw-r--r-- | src/Projection.H | 2 | ||||
-rw-r--r-- | src/Projection.cxx | 2 | ||||
-rw-r--r-- | src/ProjectionSphaeric.H | 10 | ||||
-rw-r--r-- | src/ProjectionSphaeric.cxx | 87 | ||||
-rw-r--r-- | src/ProjectionTangential.H | 4 | ||||
-rw-r--r-- | src/ProjectionTangential.cxx | 6 |
8 files changed, 75 insertions, 54 deletions
@@ -49,6 +49,8 @@ class Hill { Hill(const char *n, double p, double l, double h); + Hill(const Hill& h); + Hill(int x_tmp, int y_tmp); ~Hill(); diff --git a/src/Hill.cxx b/src/Hill.cxx index 9c39779..626e470 100644 --- a/src/Hill.cxx +++ b/src/Hill.cxx @@ -41,6 +41,22 @@ Hill::Hill(const char *n, double p, double l, double h) { flags = 0; } +Hill::Hill(const Hill& h) { + name = strdup(h.name); + phi = h.phi; + lam = h.lam; + height = h.height; + alph = h.alph; + a_view = h.a_view; + a_view = h.a_view; + dist = h.dist; + x = h.x; + y = h.y; + label_x = h.label_x; + label_y = h.label_y; + flags = h.flags; +} + Hill::Hill(int x_tmp, int y_tmp) { name = ""; phi = 0.0; diff --git a/src/Projection.H b/src/Projection.H index a003f3d..b81e531 100644 --- a/src/Projection.H +++ b/src/Projection.H @@ -39,6 +39,6 @@ class Projection { virtual void set_coordinates(Hill *m, const ViewParams *parms); - virtual int comp_params(Hill *m1, Hill *m2, ViewParams *parms); + virtual int comp_params(const Hill *m1, const Hill *m2, ViewParams *parms); }; #endif diff --git a/src/Projection.cxx b/src/Projection.cxx index 6a6adb0..57a210a 100644 --- a/src/Projection.cxx +++ b/src/Projection.cxx @@ -36,7 +36,7 @@ Projection::set_coordinates(Hill *m, const ViewParams *parms) { } int -Projection::comp_params(Hill *m1, Hill *m2, ViewParams *parms) { +Projection::comp_params(const Hill *m1, const Hill *m2, ViewParams *parms) { fprintf(stderr, "Error: Projection::comp_params()\n"); return 1; } diff --git a/src/ProjectionSphaeric.H b/src/ProjectionSphaeric.H index 8d38287..30a4413 100644 --- a/src/ProjectionSphaeric.H +++ b/src/ProjectionSphaeric.H @@ -26,14 +26,14 @@ class ProjectionSphaeric : public Projection { private: - double comp_scale(Hill *m1, Hill *m2, double d_m1_m2_2); - double comp_dir_view(Hill *m1, Hill *m2, double d_m1_2, double d_m2_2, double scale, double sign3); - double comp_nick_view(Hill *m1, Hill *m2, double d_m1_2, double scale, double dir_view); - double comp_tilt_view(Hill *m, double scale, double dir_view, double nick_view); + double comp_scale(const Hill *m1, const Hill *m2, double d_m1_m2_2); + double comp_dir_view(const Hill *m1, const Hill *m2, double d_m1_2, double d_m2_2, double scale, double sign3); + double comp_nick_view(const Hill *m1, const Hill *m2, double d_m1_2, double scale, double dir_view, double sign1); + double comp_tilt_view(const Hill *m, double scale, double dir_view, double nick_view); public: void set_coordinates(Hill *m, const ViewParams *parms); - int comp_params(Hill *m1, Hill *m2, ViewParams *parms); + int comp_params(const Hill *m1, const Hill *m2, ViewParams *parms); }; #endif diff --git a/src/ProjectionSphaeric.cxx b/src/ProjectionSphaeric.cxx index 528dd23..8ace1c0 100644 --- a/src/ProjectionSphaeric.cxx +++ b/src/ProjectionSphaeric.cxx @@ -24,63 +24,67 @@ #include "ProjectionSphaeric.H" -#define TILT_DIFF_UNDEF 100000.0 +#define BEST_UNDEF 10000000.0 int -ProjectionSphaeric::comp_params(Hill *m1, Hill *m2, ViewParams *parms) { - Hill *tmp; - double a_center_tmp[2], scale_tmp, a_nick_tmp[2]; - double a_tilt_tmp[2], a_tilt_diff[2]; - double a_tilt1, a_tilt2; +ProjectionSphaeric::comp_params(const Hill *m1, const Hill *m2, ViewParams *parms) { + const Hill *m_tmp; + Hill *tmp_m1; + Hill *tmp_m2; + double val; + ViewParams best, tmp; + double best_val = BEST_UNDEF; double d_m1_2, d_m2_2, d_m1_m2_2; - int i; + int i, j; - if (m1->x > m2->x) { - tmp = m1; + if (m1->x < m2->x) { + m_tmp = m1; m1 = m2; - m2 = tmp; + m2 = m_tmp; } d_m1_2 = pow(m1->x, 2.0) + pow(m1->y, 2.0); d_m2_2 = pow(m2->x, 2.0) + pow(m2->y, 2.0); d_m1_m2_2 = pow(m1->x - m2->x, 2.0) + pow(m1->y - m2->y, 2.0); - scale_tmp = comp_scale(m1, m2, d_m1_m2_2); + tmp.scale = comp_scale(m1, m2, d_m1_m2_2); - for(i=0; i<2; i++) { // we need to try two solutions ... - a_tilt_diff[i] = TILT_DIFF_UNDEF; // initialize to a high value - - a_center_tmp[i] = comp_dir_view(m1, m2, d_m1_2, d_m2_2, scale_tmp, - i==0?1.0:-1.0); - a_nick_tmp[i] = comp_nick_view(m1, m2, d_m1_2, scale_tmp, a_center_tmp[i]); - - if (isnan(a_center_tmp[i]) || isnan(scale_tmp) || isnan(a_nick_tmp[i])) { - ; - } else { - a_tilt1 = comp_tilt_view(m1, scale_tmp, a_center_tmp[i], a_nick_tmp[i]); - a_tilt2 = comp_tilt_view(m2, scale_tmp, a_center_tmp[i], a_nick_tmp[i]); - - if (!isnan(a_tilt1) && !isnan(a_tilt2)) { - a_tilt_diff[i] = fabs(a_tilt1 - a_tilt2); - } + for(i=0; i<2; i++) { // we need to try four possible solutions ... + for(j=0; j<2; j++) { + tmp.a_center = comp_dir_view(m1, m2, d_m1_2, d_m2_2, + tmp.scale, i==0?1.0:-1.0); + tmp.a_nick = comp_nick_view(m1, m2, d_m1_2, tmp.scale, tmp.a_center, + j==0?1.0:-1.0); // use the point with greater distance from center for tilt computation if (d_m1_2 > d_m2_2) { - a_tilt_tmp[i] = a_tilt1; + tmp.a_tilt = comp_tilt_view(m1, tmp.scale, tmp.a_center, tmp.a_nick); } else { - a_tilt_tmp[i] = a_tilt2; + tmp.a_tilt = comp_tilt_view(m2, tmp.scale, tmp.a_center, tmp.a_nick); + } + + if (isnan(tmp.a_center) || isnan(tmp.scale) || + isnan(tmp.a_nick) || isnan(tmp.a_tilt)) { + ; + } else { + tmp_m1 = new Hill(*m1); + tmp_m2 = new Hill(*m2); + set_coordinates(tmp_m1, &tmp); + set_coordinates(tmp_m2, &tmp); + val = sqrt(pow(tmp_m1->x - m1->x, 2.0) + pow(tmp_m1->y - m1->y, 2.0)); + val += sqrt(pow(tmp_m2->x - m2->x, 2.0) + pow(tmp_m2->y - m2->y, 2.0)); + delete(tmp_m1); + delete(tmp_m2); + if (val < best_val) { + best_val = val; + best = tmp; + } } } } - i = a_tilt_diff[0]<a_tilt_diff[1]?0:1; // Choose solution where difference - // of tilt angles is smaller. - - if (a_tilt_diff[i] != TILT_DIFF_UNDEF) { - parms->a_center = a_center_tmp[i]; - parms->scale = scale_tmp; - parms->a_nick = a_nick_tmp[i]; - parms->a_tilt = a_tilt_tmp[i]; + if (best_val < BEST_UNDEF) { + *parms = best; return 0; } else { return 1; @@ -100,7 +104,7 @@ ProjectionSphaeric::set_coordinates(Hill *m, const ViewParams *parms) { } double -ProjectionSphaeric::comp_scale(Hill *m1, Hill *m2, double d_m1_m2_2) { +ProjectionSphaeric::comp_scale(const Hill *m1, const Hill *m2, double d_m1_m2_2) { double sign1 = 1.0; double nick_m1 = m1->a_nick; double nick_m2 = m2->a_nick; @@ -113,7 +117,7 @@ ProjectionSphaeric::comp_scale(Hill *m1, Hill *m2, double d_m1_m2_2) { // using the sign3 parameter one can choose between the two possible solutions // sign3 must be 1.0 or -1.0 double -ProjectionSphaeric::comp_dir_view(Hill *m1, Hill *m2, double d_m1_2, double d_m2_2, double scale, double sign3) { +ProjectionSphaeric::comp_dir_view(const Hill *m1, const Hill *m2, double d_m1_2, double d_m2_2, double scale, double sign3) { double dir_view; double nick_m1 = m1->a_nick; double nick_m2 = m2->a_nick; @@ -127,9 +131,8 @@ ProjectionSphaeric::comp_dir_view(Hill *m1, Hill *m2, double d_m1_2, double d_m2 double -ProjectionSphaeric::comp_nick_view(Hill *m1, Hill *m2, double d_m1_2, double scale, double dir_view) { +ProjectionSphaeric::comp_nick_view(const Hill *m1, const Hill *m2, double d_m1_2, double scale, double dir_view, double sign1) { double nick_view; - double sign1 = -1.0; double nick_m1 = m1->a_nick; double dir_m1 = m1->alph; @@ -139,7 +142,7 @@ ProjectionSphaeric::comp_nick_view(Hill *m1, Hill *m2, double d_m1_2, double sca } double -ProjectionSphaeric::comp_tilt_view(Hill *m, double scale, double dir_view, double nick_view) { +ProjectionSphaeric::comp_tilt_view(const Hill *m, double scale, double dir_view, double nick_view) { double sin_a_tilt1, sin_a_tilt2, sin_a_tilt, res; double x_tmp = (m->alph - dir_view) * scale; double y_tmp = (m->a_nick - nick_view) * scale; diff --git a/src/ProjectionTangential.H b/src/ProjectionTangential.H index 6ebb91d..d4646d7 100644 --- a/src/ProjectionTangential.H +++ b/src/ProjectionTangential.H @@ -31,11 +31,11 @@ class ProjectionTangential : public Projection { double comp_scale(double alph_a, double alph_b, double d1, double d2); - int optimize(Hill *m1, Hill *m2, ViewParams *parms); + int optimize(const Hill *m1, const Hill *m2, ViewParams *parms); public: void set_coordinates(Hill *m, const ViewParams *parms); - int comp_params(Hill *m1, Hill *m2, ViewParams *parms); + int comp_params(const Hill *m1, const Hill *m2, ViewParams *parms); }; #endif diff --git a/src/ProjectionTangential.cxx b/src/ProjectionTangential.cxx index 60feaff..8297ee4 100644 --- a/src/ProjectionTangential.cxx +++ b/src/ProjectionTangential.cxx @@ -44,8 +44,8 @@ comp_tilt(double tan_nick_view, double tan_dir_view, double n_scale, double x, double y, double pi_d); int -ProjectionTangential::comp_params(Hill *m1, Hill *m2, ViewParams *parms) { - Hill *tmp; +ProjectionTangential::comp_params(const Hill *m1, const Hill *m2, ViewParams *parms) { + const Hill *tmp; double a_center_tmp, scale_tmp, a_nick_tmp; scale_tmp = comp_scale(m1->alph, m2->alph, m1->x, m2->x); @@ -77,7 +77,7 @@ ProjectionTangential::comp_params(Hill *m1, Hill *m2, ViewParams *parms) { } int -ProjectionTangential::optimize(Hill *m1, Hill *m2, ViewParams *parms) { +ProjectionTangential::optimize(const Hill *m1, const Hill *m2, ViewParams *parms) { int i; double tan_nick_view, tan_dir_view, n_scale; double tan_nick_m1, tan_dir_m1; |