Mercurial > hg > svgui
diff layer/Colour3DPlotLayer.cpp @ 904:e0f08e108064 cxx11
Move to using double rather than float for floating-point calculations (float only for storage); more build fixes
author | Chris Cannam |
---|---|
date | Mon, 09 Mar 2015 12:02:10 +0000 |
parents | 1757933ce5a7 |
children | 4a578a360011 |
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.cpp Mon Mar 09 08:43:20 2015 +0000 +++ b/layer/Colour3DPlotLayer.cpp Mon Mar 09 12:02:10 2015 +0000 @@ -543,13 +543,13 @@ } bool -Colour3DPlotLayer::getValueExtents(float &min, float &max, +Colour3DPlotLayer::getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const { if (!m_model) return false; min = 0; - max = float(m_model->getHeight()); + max = double(m_model->getHeight()); logarithmic = false; unit = ""; @@ -558,14 +558,14 @@ } bool -Colour3DPlotLayer::getDisplayExtents(float &min, float &max) const +Colour3DPlotLayer::getDisplayExtents(double &min, double &max) const { if (!m_model) return false; - float hmax = float(m_model->getHeight()); + double hmax = double(m_model->getHeight()); - min = float(m_miny); - max = float(m_maxy); + min = m_miny; + max = m_maxy; if (max <= min) { min = 0; max = hmax; @@ -577,12 +577,12 @@ } bool -Colour3DPlotLayer::setDisplayExtents(float min, float max) +Colour3DPlotLayer::setDisplayExtents(double min, double max) { if (!m_model) return false; - m_miny = int(lrintf(min)); - m_maxy = int(lrintf(max)); + m_miny = int(lrint(min)); + m_maxy = int(lrint(max)); emit layerParametersChanged(); return true; @@ -590,7 +590,7 @@ bool Colour3DPlotLayer::getYScaleValue(const View *, int, - float &, QString &) const + double &, QString &) const { return false;//!!! } @@ -610,9 +610,9 @@ { if (!m_model) return 0; - float min, max; + double min, max; getDisplayExtents(min, max); - return m_model->getHeight() - int(lrintf(max - min)); + return m_model->getHeight() - int(lrint(max - min)); } void @@ -624,8 +624,8 @@ int dist = m_model->getHeight() - step; if (dist < 1) dist = 1; - float centre = float(m_miny) + (float(m_maxy) - float(m_miny)) / 2.f; - m_miny = int(lrintf(centre - float(dist)/2)); + double centre = m_miny + (m_maxy - m_miny) / 2.0; + m_miny = int(lrint(centre - dist/2.0)); if (m_miny < 0) m_miny = 0; m_maxy = m_miny + dist; if (m_maxy > m_model->getHeight()) m_maxy = m_model->getHeight(); @@ -644,18 +644,18 @@ 0, m_model->getHeight(), ""); } -float -Colour3DPlotLayer::getYForBin(View *v, float bin) const +double +Colour3DPlotLayer::getYForBin(View *v, double bin) const { - float y = bin; + double y = bin; if (!m_model) return y; - float mn = 0, mx = float(m_model->getHeight()); + double mn = 0, mx = m_model->getHeight(); getDisplayExtents(mn, mx); - float h = float(v->height()); + double h = v->height(); if (m_binScale == LinearBinScale) { y = h - (((bin - mn) * h) / (mx - mn)); } else { - float logmin = mn + 1, logmax = mx + 1; + double logmin = mn + 1, logmax = mx + 1; LogRange::mapRange(logmin, logmax); y = h - (((LogRange::map(bin + 1) - logmin) * h) / (logmax - logmin)); } @@ -665,21 +665,21 @@ int Colour3DPlotLayer::getIYForBin(View *v, int bin) const { - return int(roundf(getYForBin(v, float(bin)))); + return int(round(getYForBin(v, bin))); } -float -Colour3DPlotLayer::getBinForY(View *v, float y) const +double +Colour3DPlotLayer::getBinForY(View *v, double y) const { - float bin = y; + double bin = y; if (!m_model) return bin; - float mn = 0, mx = float(m_model->getHeight()); + double mn = 0, mx = m_model->getHeight(); getDisplayExtents(mn, mx); - float h = float(v->height()); + double h = v->height(); if (m_binScale == LinearBinScale) { bin = mn + ((h - y) * (mx - mn)) / h; } else { - float logmin = mn + 1, logmax = mx + 1; + double logmin = mn + 1, logmax = mx + 1; LogRange::mapRange(logmin, logmax); bin = LogRange::unmap(logmin + ((h - y) * (logmax - logmin)) / h) - 1; } @@ -689,7 +689,7 @@ int Colour3DPlotLayer::getIBinForY(View *v, int y) const { - return int(floorf(getBinForY(v, float(y)))); + return int(floor(getBinForY(v, y))); } QString @@ -724,7 +724,7 @@ if (symin < 0) symin = 0; if (symax > sh) symax = sh; - // float binHeight = float(v->height()) / (symax - symin); + // double binHeight = double(v->height()) / (symax - symin); // int sy = int((v->height() - y) / binHeight) + symin; int sy = getIBinForY(v, y); @@ -795,11 +795,11 @@ int ch = h - 20; if (ch > 20 && m_cache) { - float min = m_model->getMinimumLevel(); - float max = m_model->getMaximumLevel(); + double min = m_model->getMinimumLevel(); + double max = m_model->getMaximumLevel(); - float mmin = min; - float mmax = max; + double mmin = min; + double mmax = max; if (m_colourScale == LogScale) { LogRange::mapRange(mmin, mmax); @@ -808,12 +808,12 @@ mmax = 1.f; } else if (m_colourScale == AbsoluteScale) { if (mmin < 0) { - if (fabsf(mmin) > fabsf(mmax)) mmax = fabsf(mmin); - else mmax = fabsf(mmax); + if (fabs(mmin) > fabs(mmax)) mmax = fabs(mmin); + else mmax = fabs(mmax); mmin = 0; } else { - mmin = fabsf(mmin); - mmax = fabsf(mmax); + mmin = fabs(mmin); + mmax = fabs(mmax); } } @@ -824,7 +824,7 @@ paint.drawRect(4, 10, cw - 8, ch+1); for (int y = 0; y < ch; ++y) { - float value = ((max - min) * (float(ch-y) - 1.f)) / float(ch) + min; + double value = ((max - min) * (double(ch-y) - 1.0)) / double(ch) + min; if (m_colourScale == LogScale) { value = LogRange::map(value); } @@ -934,8 +934,8 @@ while (values.size() < m_model->getHeight()) values.push_back(0.f); if (!m_normalizeColumns && !m_normalizeHybrid) return values; - float colMax = 0.f, colMin = 0.f; - float min = 0.f, max = 0.f; + double colMax = 0.f, colMin = 0.f; + double min = 0.f, max = 0.f; min = m_model->getMinimumLevel(); max = m_model->getMaximumLevel(); @@ -948,17 +948,17 @@ for (int y = 0; y < values.size(); ++y) { - float value = values.at(y); - float norm = (value - colMin) / (colMax - colMin); - float newvalue = min + (max - min) * norm; + double value = values.at(y); + double norm = (value - colMin) / (colMax - colMin); + double newvalue = min + (max - min) * norm; - if (value != newvalue) values[y] = newvalue; + if (value != newvalue) values[y] = float(newvalue); } if (m_normalizeHybrid && (colMax > 0.0)) { - float logmax = log10f(colMax); + double logmax = log10(colMax); for (int y = 0; y < values.size(); ++y) { - values[y] *= logmax; + values[y] = float(values[y] * logmax); } } @@ -1085,8 +1085,8 @@ DenseThreeDimensionalModel::Column values; - float min = m_model->getMinimumLevel(); - float max = m_model->getMaximumLevel(); + double min = m_model->getMinimumLevel(); + double max = m_model->getMaximumLevel(); if (m_colourScale == LogScale) { LogRange::mapRange(min, max); @@ -1095,12 +1095,12 @@ max = 1.f; } else if (m_colourScale == AbsoluteScale) { if (min < 0) { - if (fabsf(min) > fabsf(max)) max = fabsf(min); - else max = fabsf(max); + if (fabs(min) > fabs(max)) max = fabs(min); + else max = fabs(max); min = 0; } else { - min = fabsf(min); - max = fabsf(max); + min = fabs(min); + max = fabs(max); } } @@ -1118,7 +1118,7 @@ } } - float visibleMax = 0.f, visibleMin = 0.f; + double visibleMax = 0.f, visibleMin = 0.f; if (normalizeVisible) { @@ -1126,7 +1126,7 @@ values = getColumn(c); - float colMax = 0.f, colMin = 0.f; + double colMax = 0.f, colMin = 0.f; for (int y = 0; y < cacheHeight; ++y) { if (y >= values.size()) break; @@ -1144,12 +1144,12 @@ if (visibleMin > visibleMax) std::swap(visibleMin, visibleMax); } else if (m_colourScale == AbsoluteScale) { if (visibleMin < 0) { - if (fabsf(visibleMin) > fabsf(visibleMax)) visibleMax = fabsf(visibleMin); - else visibleMax = fabsf(visibleMax); + if (fabs(visibleMin) > fabs(visibleMax)) visibleMax = fabs(visibleMin); + else visibleMax = fabs(visibleMax); visibleMin = 0; } else { - visibleMin = fabsf(visibleMin); - visibleMax = fabsf(visibleMax); + visibleMin = fabs(visibleMin); + visibleMax = fabs(visibleMax); } } } @@ -1178,7 +1178,7 @@ for (int y = 0; y < cacheHeight; ++y) { - float value = min; + double value = min; if (y < values.size()) { value = values.at(y); } @@ -1188,11 +1188,11 @@ if (m_colourScale == LogScale) { value = LogRange::map(value); } else if (m_colourScale == AbsoluteScale) { - value = fabsf(value); + value = fabs(value); } if (normalizeVisible) { - float norm = (value - visibleMin) / (visibleMax - visibleMin); + double norm = (value - visibleMin) / (visibleMax - visibleMin); value = min + (max - min) * norm; } @@ -1410,7 +1410,7 @@ if (showLabel) { if (sx >= 0 && sx < m_cache->width() && sy >= 0 && sy < m_cache->height()) { - float value = m_model->getValueAt(sx, sy); + double value = m_model->getValueAt(sx, sy); snprintf(labelbuf, buflen, "%06f", value); QString text(labelbuf); paint.setPen(v->getBackground()); @@ -1509,7 +1509,7 @@ sxa[x*2 + 1] = sx1; } - float logmin = float(symin+1), logmax = float(symax+1); + double logmin = symin+1, logmax = symax+1; LogRange::mapRange(logmin, logmax); #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT @@ -1520,7 +1520,7 @@ for (int y = 0; y < h; ++y) { - double sy = getBinForY(v, float(y)) - 0.5; + double sy = getBinForY(v, y) - 0.5; int syi = int(sy + epsilon); if (syi < 0 || syi >= source->height()) continue; @@ -1590,14 +1590,14 @@ } } else { - float sy0 = getBinForY(v, 0); + double sy0 = getBinForY(v, 0); int psy0i = -1, psy1i = -1; for (int y = 0; y < h; ++y) { - float sy1 = sy0; - sy0 = getBinForY(v, float(y + 1)); + double sy1 = sy0; + sy0 = getBinForY(v, double(y + 1)); int sy0i = int(sy0 + epsilon); int sy1i = int(sy1); @@ -1655,7 +1655,7 @@ } bool -Colour3DPlotLayer::snapToFeatureFrame(View *v, int &frame, +Colour3DPlotLayer::snapToFeatureFrame(View *v, sv_frame_t &frame, int &resolution, SnapType snap) const { @@ -1664,8 +1664,8 @@ } resolution = m_model->getResolution(); - int left = (frame / resolution) * resolution; - int right = left + resolution; + sv_frame_t left = (frame / resolution) * resolution; + sv_frame_t right = left + resolution; switch (snap) { case SnapLeft: frame = left; break;