From 538456cb1844381f2226ed355eae049c5ba4472b Mon Sep 17 00:00:00 2001 From: Ben Marchant <13385275+bmarchant@users.noreply.github.com> Date: Wed, 7 Dec 2022 11:31:00 -0600 Subject: [PATCH 1/2] Some averages in the stats weren't being calculated correctly (integer division), fixed that. Also sonar fixes. --- conf/core/ConfigOptions.asciidoc | 2 +- .../hoot/core/algorithms/WayDiscretizer.cpp | 2 +- .../algorithms/linearreference/WayString.cpp | 2 +- .../optimizer/IntegerProgrammingSolver.cpp | 4 +- .../optimizer/IntegerProgrammingSolver.h | 2 +- .../perty/DirectSequentialSimulation.cpp | 4 +- .../hoot/core/algorithms/perty/PertyOp.cpp | 4 +- .../core/algorithms/splitter/WaySplitter.cpp | 4 +- .../string/SqliteWordWeightDictionary.cpp | 4 +- .../string/TextFileWordWeightDictionary.cpp | 2 +- .../MaximalNearestSubline.cpp | 10 +- .../subline-matching/MaximalSubline.cpp | 2 +- .../cpp/hoot/core/algorithms/zindex/BBox.h | 2 +- .../cpp/hoot/core/algorithms/zindex/LongBox.h | 2 +- .../hoot/core/algorithms/zindex/ZValue.cpp | 2 +- .../hoot/core/conflate/ConflateExecutor.cpp | 8 +- .../cpp/hoot/core/conflate/DiffConflator.cpp | 2 +- .../hoot/core/conflate/highway/Roundabout.cpp | 2 +- .../core/conflate/matching/MatchConflicts.cpp | 2 +- .../matching/OptimalConstrainedMatches.cpp | 6 +- .../core/conflate/merging/RelationMerger.cpp | 2 +- .../conflate/network/NetworkMatchCreator.cpp | 4 +- .../RiverMaximalSublineSettingOptimizer.cpp | 6 +- .../cpp/hoot/core/criterion/ChainCriterion.h | 2 +- .../main/cpp/hoot/core/elements/ElementId.h | 2 +- .../main/cpp/hoot/core/elements/Relation.cpp | 2 +- .../src/main/cpp/hoot/core/elements/Way.h | 2 +- .../geometry/ElementToGeometryConverter.cpp | 2 +- .../cpp/hoot/core/geometry/GeometryMerger.cpp | 2 +- .../hoot/core/geometry/GeometryPainter.cpp | 2 +- .../RelationToMultiPolygonConverter.cpp | 2 +- .../main/cpp/hoot/core/info/IoSingleStat.cpp | 2 +- .../cpp/hoot/core/info/NumericStatistic.h | 2 +- .../main/cpp/hoot/core/io/DataConverter.cpp | 4 +- .../cpp/hoot/core/io/InternalIdReserver.cpp | 2 +- .../core/io/OsmApiDbSqlChangesetFileWriter.h | 2 +- .../core/io/OsmApiDbSqlStatementFormatter.h | 2 +- .../main/cpp/hoot/core/io/OsmPbfWriter.cpp | 4 +- .../main/cpp/hoot/core/io/OsmXmlDiskCache.cpp | 5 +- .../main/cpp/hoot/core/io/OsmXmlWriter.cpp | 2 +- .../core/io/schema/IntegerFieldDefinition.h | 6 +- .../hoot/core/scoring/AttributeComparator.cpp | 2 +- .../cpp/hoot/core/scoring/DirectedGraph.cpp | 2 +- .../cpp/hoot/core/scoring/MapCompareUtils.cpp | 2 +- .../main/cpp/hoot/core/util/SignalCatcher.cpp | 2 +- .../visitors/AverageNumericTagsVisitor.cpp | 2 +- .../core/visitors/BuildingHeightVisitor.h | 2 +- .../core/visitors/BuildingLevelsVisitor.h | 2 +- .../core/visitors/CountManualMatchesVisitor.h | 2 +- .../core/visitors/CountUniqueReviewsVisitor.h | 2 +- .../hoot/core/visitors/LengthOfWaysVisitor.h | 2 +- .../visitors/MatchCandidateCountVisitor.h | 2 +- .../cpp/hoot/core/visitors/MaxIdVisitor.h | 2 +- .../cpp/hoot/core/visitors/MinIdVisitor.h | 2 +- .../hoot/core/visitors/NodesPerWayVisitor.cpp | 2 +- .../core/visitors/RandomElementRenamer.cpp | 4 +- .../hoot/core/visitors/RandomWaySplitter.cpp | 2 +- .../core/visitors/SumNumericTagsVisitor.cpp | 2 +- .../cpp/hoot/core/visitors/TagCountVisitor.h | 8 +- .../hoot/core/visitors/TagKeyCountVisitor.h | 2 +- .../hoot/josm/ops/JosmMapValidatorAbstract.h | 2 +- .../main/cpp/hoot/js/elements/ElementJs.cpp | 2 +- .../main/cpp/hoot/js/elements/OsmMapJs.cpp | 2 +- .../src/main/cpp/hoot/js/elements/WayJs.cpp | 2 +- .../src/main/cpp/hoot/js/io/StreamUtilsJs.h | 2 +- .../js/schema/JavaScriptSchemaTranslator.cpp | 2 +- ...ConflateCmdStatsAllDataTypesTest.sh.stdout | 22 +-- ...onflateCmdStatsGenericRiversTest.sh.stdout | 22 +-- ...ConflateCmdStatsToyBuildingsTest.sh.stdout | 22 +-- .../cmd/slow/ConflatePoiStatsTest.sh.stdout | 14 +- test-files/cmd/slow/StatsCmdTest.sh.stdout | 4 +- .../cpp/tgs/Interpolation/IdwInterpolator.cpp | 2 +- .../KernelEstimationInterpolator.cpp | 12 +- .../main/cpp/tgs/RStarTree/HilbertRTree.cpp | 167 ++++-------------- tgs/src/main/cpp/tgs/RStarTree/HilbertRTree.h | 21 ++- .../RandomForest/BaseRandomForestManager.cpp | 2 +- .../tgs/RandomForest/InfoGainCalculator.cpp | 8 +- .../MultithreadedRandomForest.cpp | 4 +- tgs/src/main/cpp/tgs/Statistics/Random.h | 4 +- 79 files changed, 190 insertions(+), 299 deletions(-) diff --git a/conf/core/ConfigOptions.asciidoc b/conf/core/ConfigOptions.asciidoc index a88c8f4583..16e2c11c06 100644 --- a/conf/core/ConfigOptions.asciidoc +++ b/conf/core/ConfigOptions.asciidoc @@ -6045,7 +6045,7 @@ Examples that will be kept if the value is `true` include: === token.min.size -* Data Type: double +* Data Type: int * Default Value: `3` This is the minimum string size that the string tokenizer should accept as a token. If the string diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/WayDiscretizer.cpp b/hoot-core/src/main/cpp/hoot/core/algorithms/WayDiscretizer.cpp index 31ed738745..67b47bb45a 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/WayDiscretizer.cpp +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/WayDiscretizer.cpp @@ -119,7 +119,7 @@ bool WayDiscretizer::discretize(double spacing, vector& result) con Meters wayLength = ElementToGeometryConverter(_map).convertToLineString(_way)->getLength(); LOG_VART(wayLength); - int count = ceil(wayLength / spacing); + int count = static_cast(ceil(wayLength / spacing)); LOG_VART(count); spacing = wayLength / double(count); LOG_VART(spacing); diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/linearreference/WayString.cpp b/hoot-core/src/main/cpp/hoot/core/algorithms/linearreference/WayString.cpp index 5fce3df460..69d92bbc9e 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/linearreference/WayString.cpp +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/linearreference/WayString.cpp @@ -229,7 +229,7 @@ WayPtr WayString::copySimplifiedWayIntoMap(const ElementProvider& map, OsmMapPtr // add all the pre-existing nodes that we can. for (size_t i = formeri; i <= latteri; ++i) { - long nid = oldWay->getNodeId(i); + long nid = oldWay->getNodeId(static_cast(i)); newNids.push_back(nid); destination->addNode(std::make_shared(*map.getNode(nid))); } diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/optimizer/IntegerProgrammingSolver.cpp b/hoot-core/src/main/cpp/hoot/core/algorithms/optimizer/IntegerProgrammingSolver.cpp index d91dce07f8..04ae4e117d 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/optimizer/IntegerProgrammingSolver.cpp +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/optimizer/IntegerProgrammingSolver.cpp @@ -80,7 +80,7 @@ void IntegerProgrammingSolver::solveBranchAndCut() iocp.br_tech = GLP_BR_PCH; // Setup the time limit if necessary if (_timeLimit > 0) - iocp.tm_lim = _timeLimit * 1000.0 + 0.5; + iocp.tm_lim = static_cast(_timeLimit * 1000.0 + 0.5); // Setup message level if (Log::getInstance().getLevel() <= Log::Trace) iocp.msg_lev = GLP_MSG_ON; @@ -117,7 +117,7 @@ void IntegerProgrammingSolver::solveSimplex() glp_init_smcp(&smcp); // Setup the time limit if necessary if (_timeLimit > 0) - smcp.tm_lim = _timeLimit * 1000.0 + 0.5; + smcp.tm_lim = static_cast(_timeLimit * 1000.0 + 0.5); // Setup message level if (Log::getInstance().getLevel() <= Log::Trace) smcp.msg_lev = GLP_MSG_ON; diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/optimizer/IntegerProgrammingSolver.h b/hoot-core/src/main/cpp/hoot/core/algorithms/optimizer/IntegerProgrammingSolver.h index 1c07f7c7ec..92b39064af 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/optimizer/IntegerProgrammingSolver.h +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/optimizer/IntegerProgrammingSolver.h @@ -81,7 +81,7 @@ class IntegerProgrammingSolver */ void loadMatrix(const std::vector& i, const std::vector& j, const std::vector& r) { - glp_load_matrix(_lp, i.size() - 1, &(i[0]), &(j[0]), &(r[0])); + glp_load_matrix(_lp, static_cast(i.size() - 1), &(i[0]), &(j[0]), &(r[0])); } /** diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/perty/DirectSequentialSimulation.cpp b/hoot-core/src/main/cpp/hoot/core/algorithms/perty/DirectSequentialSimulation.cpp index 420aab49ea..cb573ccdaa 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/perty/DirectSequentialSimulation.cpp +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/perty/DirectSequentialSimulation.cpp @@ -95,8 +95,8 @@ Mat DirectSequentialSimulation::_gm2dPerturb2(geos::geom::Envelope env, Meters s // effects env.expandBy(3 * _gridSpacing); - int rows = max(2, ceil(env.getHeight() / _gridSpacing) + 1); - int cols = max(2, ceil(env.getWidth() / _gridSpacing) + 1); + int rows = max(2, static_cast(ceil(env.getHeight() / _gridSpacing)) + 1); + int cols = max(2, static_cast(ceil(env.getWidth() / _gridSpacing)) + 1); double r = exp(-_gridSpacing / _D); double s = exp(-_gridSpacing / _D); diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/perty/PertyOp.cpp b/hoot-core/src/main/cpp/hoot/core/algorithms/perty/PertyOp.cpp index abdde37e86..47162e84fa 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/perty/PertyOp.cpp +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/perty/PertyOp.cpp @@ -87,8 +87,8 @@ class ShiftMapVisitor : public ElementOsmMapVisitor Vec2d result; // calculate the grid cell that this point falls in. - int r = (p.y - _e.getMinY()) / _gridSpacing; - int c = (p.x - _e.getMinX()) / _gridSpacing; + int r = static_cast((p.y - _e.getMinY()) / _gridSpacing); + int c = static_cast((p.x - _e.getMinX()) / _gridSpacing); double dx = p.x - (_e.getMinX() + c * _gridSpacing); double dy = p.y - (_e.getMinY() + r * _gridSpacing); diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/splitter/WaySplitter.cpp b/hoot-core/src/main/cpp/hoot/core/algorithms/splitter/WaySplitter.cpp index 514ca41a0c..e5e3aabc70 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/splitter/WaySplitter.cpp +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/splitter/WaySplitter.cpp @@ -77,7 +77,7 @@ vector WaySplitter::createSplits(const vector& wl) const last = curr; } - WayLocation end(_map, _way, _way->getNodeCount() - 1, 0.0); + WayLocation end(_map, _way, static_cast(_way->getNodeCount()) - 1, 0.0); if (last.compareTo(end) != 0) { WayPtr w = WaySubline(last, end).toWay(_map, _nf); @@ -123,7 +123,7 @@ vector WaySplitter::split(const WayLocation& splitPoint) const else { WayLocation first(_map, _way, 0, 0.0); - WayLocation last(_map, _way, _way->getNodeCount() - 1, 0.0); + WayLocation last(_map, _way, static_cast(_way->getNodeCount()) - 1, 0.0); result.push_back(WaySubline(first, splitPoint).toWay(_map, _nf, true)); result.push_back(WaySubline(splitPoint, last).toWay(_map, _nf, false)); diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/string/SqliteWordWeightDictionary.cpp b/hoot-core/src/main/cpp/hoot/core/algorithms/string/SqliteWordWeightDictionary.cpp index 37e3a22beb..61de7c21dc 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/string/SqliteWordWeightDictionary.cpp +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/string/SqliteWordWeightDictionary.cpp @@ -50,12 +50,12 @@ double SqliteWordWeightDictionary::getWeight(const QString& word) const c = _reader.readCount(normalized); if (c > 0) _weights[normalized] = c; - return c; + return static_cast(c); } else c = it->second; - return c / (double)_count; + return static_cast(c) / static_cast(_count); } } diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/string/TextFileWordWeightDictionary.cpp b/hoot-core/src/main/cpp/hoot/core/algorithms/string/TextFileWordWeightDictionary.cpp index 5ed0943cb4..10ea27efa9 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/string/TextFileWordWeightDictionary.cpp +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/string/TextFileWordWeightDictionary.cpp @@ -63,7 +63,7 @@ void TextFileWordWeightDictionary::_loadFile(const QString& path) first.replace(totalWordCount, ""); bool ok; - _count += first.toDouble(&ok); + _count += static_cast(first.toDouble(&ok)); if (!ok) throw HootException("Bad double value in total word count: " + first); diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/subline-matching/MaximalNearestSubline.cpp b/hoot-core/src/main/cpp/hoot/core/algorithms/subline-matching/MaximalNearestSubline.cpp index c9f320d13a..0daed6a87c 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/subline-matching/MaximalNearestSubline.cpp +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/subline-matching/MaximalNearestSubline.cpp @@ -116,7 +116,7 @@ const vector& MaximalNearestSubline::getInterval() // Heuristic #1: use every vertex of B as a test point for (size_t ib = 0; ib < _b->getNodeCount(); ib++) { - ConstNodePtr node = _map->getNode(_b->getNodeId((long)ib)); + ConstNodePtr node = _map->getNode(_b->getNodeId(static_cast(ib))); LOG_VART(node.get()); if (node) { @@ -138,7 +138,7 @@ const vector& MaximalNearestSubline::getInterval() LocationOfPoint bPtLocator(_map, _b); for (size_t ia = 0; ia < _a->getNodeCount(); ia++) { - ConstNodePtr node = _map->getNode(_a->getNodeId((long)ia)); + ConstNodePtr node = _map->getNode(_a->getNodeId(static_cast(ia))); LOG_VART(node.get()); if (node) { @@ -280,12 +280,12 @@ vector MaximalNearestSubline::splitWay(OsmMapPtr map, int& mnsIndex) // if this is a or b if (end.getSegmentIndex() < (int)_a->getNodeCount() - 1 || end.getSegmentFraction() < 1.0) { - WayPtr way3 = WaySubline(end, WayLocation(map, _a, _a->getNodeCount() - 1, 0.0)).toWay(map, nf); + WayPtr way3 = WaySubline(end, WayLocation(map, _a, static_cast(_a->getNodeCount()) - 1, 0.0)).toWay(map, nf); double l = ElementToGeometryConverter(map).convertToLineString(way3)->getLength(); // if the way is too short, round to the first way. if (l < _minSplitSize) - end = WayLocation(map, _a, _a->getNodeCount() - 1, 0.0); + end = WayLocation(map, _a, static_cast(_a->getNodeCount()) - 1, 0.0); else result.push_back(way3); } @@ -296,7 +296,7 @@ vector MaximalNearestSubline::splitWay(OsmMapPtr map, int& mnsIndex) // if the way is big enough then add it on. if (l > _minSplitSize) { - mnsIndex = result.size(); + mnsIndex = static_cast(result.size()); result.push_back(way2); } else diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/subline-matching/MaximalSubline.cpp b/hoot-core/src/main/cpp/hoot/core/algorithms/subline-matching/MaximalSubline.cpp index 9c32e4a9b4..b1573c0c68 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/subline-matching/MaximalSubline.cpp +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/subline-matching/MaximalSubline.cpp @@ -625,7 +625,7 @@ cv::Mat MaximalSubline::_createConstraintMatrix(const vector& starts, const if ((size_t)ends[last] != pairs.size() - 1) { finalStarts.push_back(ends[last] - (ends[last] - starts[last]) / 3); - finalEnds.push_back(pairs.size() - 1); + finalEnds.push_back(static_cast(pairs.size()) - 1); } LOG_TRACE("finalStarts: " << finalStarts); diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/zindex/BBox.h b/hoot-core/src/main/cpp/hoot/core/algorithms/zindex/BBox.h index 8207a7b197..81b9460575 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/zindex/BBox.h +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/zindex/BBox.h @@ -40,7 +40,7 @@ class BBox BBox(const geos::geom::Envelope& envelope); virtual ~BBox(); - int getDimensions() const { return _max.size(); } + int getDimensions() const { return static_cast(_max.size()); } std::vector getMax() const { return _max; } std::vector getMin() const { return _min; } diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/zindex/LongBox.h b/hoot-core/src/main/cpp/hoot/core/algorithms/zindex/LongBox.h index 4ea99a389c..c68937e05c 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/zindex/LongBox.h +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/zindex/LongBox.h @@ -55,7 +55,7 @@ class LongBox LongBox expand(int size) const; - int getDimensions() const { return getMin().size(); } + int getDimensions() const { return static_cast(getMin().size()); } std::vector getMax() const { return _max; } std::vector getMin() const { return _min; } diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/zindex/ZValue.cpp b/hoot-core/src/main/cpp/hoot/core/algorithms/zindex/ZValue.cpp index 8485d02315..d5fa4e264a 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/zindex/ZValue.cpp +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/zindex/ZValue.cpp @@ -86,7 +86,7 @@ long int ZValue::calculateComponent(double v, int d) { if (d >= (int)_min.size() || d >= (int)_max.size()) throw HootException("Input vector size is greater than min or max size."); - return round(((v - _min[d]) / (_max[d] - _min[d])) * _range); + return round(((v - _min[d]) / (_max[d] - _min[d])) * static_cast(_range)); } void ZValue::decompose(long int v, vector& point) const diff --git a/hoot-core/src/main/cpp/hoot/core/conflate/ConflateExecutor.cpp b/hoot-core/src/main/cpp/hoot/core/conflate/ConflateExecutor.cpp index 0878abce68..b98c4b99f8 100644 --- a/hoot-core/src/main/cpp/hoot/core/conflate/ConflateExecutor.cpp +++ b/hoot-core/src/main/cpp/hoot/core/conflate/ConflateExecutor.cpp @@ -284,11 +284,11 @@ void ConflateExecutor::conflate(const QString& input1, const QString& input2, co double timingOutput = _taskTimer.getElapsedAndRestart(); double totalElapsed = totalTime.getElapsed(); _stats.append(SingleStat("(Dubious) Initial Elements Processed per Second", - initialElementCount / totalElapsed)); + static_cast(initialElementCount) / totalElapsed)); _stats.append(SingleStat("(Dubious) Final Elements Processed per Second", - (double)map->getElementCount() / totalElapsed)); + static_cast(map->getElementCount()) / totalElapsed)); _stats.append(SingleStat("Write Output Time (sec)", timingOutput)); - _stats.append(SingleStat("Final Element Count", (double)map->getElementCount())); + _stats.append(SingleStat("Final Element Count", static_cast(map->getElementCount()))); _stats.append(SingleStat("Total Time Elapsed (sec)", totalElapsed)); _stats.append(IoSingleStat(IoSingleStat::RChar)); _stats.append(IoSingleStat(IoSingleStat::WChar)); @@ -567,7 +567,7 @@ void ConflateExecutor::_writeChangesetStats() float ConflateExecutor::_getTaskWeight() const { - return 1.0 / (float)_numTotalTasks; + return 1.0f / (float)_numTotalTasks; } float ConflateExecutor::_getJobPercentComplete(const int currentTaskNum) const diff --git a/hoot-core/src/main/cpp/hoot/core/conflate/DiffConflator.cpp b/hoot-core/src/main/cpp/hoot/core/conflate/DiffConflator.cpp index 26d7539511..927a3927f6 100644 --- a/hoot-core/src/main/cpp/hoot/core/conflate/DiffConflator.cpp +++ b/hoot-core/src/main/cpp/hoot/core/conflate/DiffConflator.cpp @@ -720,7 +720,7 @@ void DiffConflator::_removeRefData(const bool removeSnapped) RemoveElementsVisitor removeRef1Visitor; removeRef1Visitor.setRecursive(true); removeRef1Visitor.addCriterion(removeCrit); - const int mapSizeBefore = _map->size(); + const int mapSizeBefore = static_cast(_map->size()); _map->visitRw(removeRef1Visitor); MemoryUsageChecker::getInstance().check(); OsmMapWriterFactory::writeDebugMap(_map, className(), "after-removing-ref-elements"); diff --git a/hoot-core/src/main/cpp/hoot/core/conflate/highway/Roundabout.cpp b/hoot-core/src/main/cpp/hoot/core/conflate/highway/Roundabout.cpp index 3123ad13e7..1a6f9f8f12 100644 --- a/hoot-core/src/main/cpp/hoot/core/conflate/highway/Roundabout.cpp +++ b/hoot-core/src/main/cpp/hoot/core/conflate/highway/Roundabout.cpp @@ -85,7 +85,7 @@ NodePtr Roundabout::getNewCenter(OsmMapPtr pMap) lat += pNode->getY(); } - count = _roundaboutNodes.size(); + count = static_cast(_roundaboutNodes.size()); lat = lat / count; lon = lon / count; diff --git a/hoot-core/src/main/cpp/hoot/core/conflate/matching/MatchConflicts.cpp b/hoot-core/src/main/cpp/hoot/core/conflate/matching/MatchConflicts.cpp index 6de1cc46fa..1569bb8547 100644 --- a/hoot-core/src/main/cpp/hoot/core/conflate/matching/MatchConflicts.cpp +++ b/hoot-core/src/main/cpp/hoot/core/conflate/matching/MatchConflicts.cpp @@ -95,7 +95,7 @@ void MatchConflicts::calculateMatchConflicts(const std::vector& m matchSet.clear(); } - matchSet.push_back(it->second); + matchSet.push_back(static_cast(it->second)); lastEid = it->first; eidToMatchCount++; diff --git a/hoot-core/src/main/cpp/hoot/core/conflate/matching/OptimalConstrainedMatches.cpp b/hoot-core/src/main/cpp/hoot/core/conflate/matching/OptimalConstrainedMatches.cpp index c3fa82ed59..408ba7bd86 100644 --- a/hoot-core/src/main/cpp/hoot/core/conflate/matching/OptimalConstrainedMatches.cpp +++ b/hoot-core/src/main/cpp/hoot/core/conflate/matching/OptimalConstrainedMatches.cpp @@ -92,14 +92,14 @@ void OptimalConstrainedMatches::_populateSolver(IntegerProgrammingSolver& solver solver.setObjectiveDirection(GLP_MAX); // each match is a column (variable) in the function that we want to maximize. - solver.addColumns(_matches.size()); + solver.addColumns(static_cast(_matches.size())); for (size_t i = 0; i < _matches.size(); i++) { - solver.setColumnKind(i + 1, GLP_BV); + solver.setColumnKind(static_cast(i) + 1, GLP_BV); //solver.setColumnBounds(i + 1, GLP_DB, 0.0, 1.0); // The score of a match is the coefficient. This makes higher score matches worth // more in the function. - solver.setObjectiveCoefficient(i + 1, _matches[i]->getScore() + EPSILON); + solver.setObjectiveCoefficient(static_cast(i) + 1, _matches[i]->getScore() + EPSILON); } // there is one row (constraint) for each conflict. diff --git a/hoot-core/src/main/cpp/hoot/core/conflate/merging/RelationMerger.cpp b/hoot-core/src/main/cpp/hoot/core/conflate/merging/RelationMerger.cpp index 3c137628a2..2e3dae5a8c 100644 --- a/hoot-core/src/main/cpp/hoot/core/conflate/merging/RelationMerger.cpp +++ b/hoot-core/src/main/cpp/hoot/core/conflate/merging/RelationMerger.cpp @@ -96,7 +96,7 @@ bool RelationMerger::_mergeMembers(RelationPtr replacingRelation, RelationPtr re { LOG_TRACE("Merging members..."); - const int numRelationBeingReplacedMembers = relationBeingReplaced->getMemberCount(); + const int numRelationBeingReplacedMembers = static_cast(relationBeingReplaced->getMemberCount()); int numMembersCopied = 0; // If a bounds was configured, we'll only merge in members that satisfy it. std::shared_ptr boundsCrit = ConfigUtils::getBoundsFilter(_map); diff --git a/hoot-core/src/main/cpp/hoot/core/conflate/network/NetworkMatchCreator.cpp b/hoot-core/src/main/cpp/hoot/core/conflate/network/NetworkMatchCreator.cpp index 3ffe5dd842..7435e58c67 100644 --- a/hoot-core/src/main/cpp/hoot/core/conflate/network/NetworkMatchCreator.cpp +++ b/hoot-core/src/main/cpp/hoot/core/conflate/network/NetworkMatchCreator.cpp @@ -101,7 +101,7 @@ void NetworkMatchCreator::createMatches(const ConstOsmMapPtr& map, std::vector(matches.size()); // use another class to extract graph nodes and graph edges. OsmNetworkExtractor e1; @@ -169,7 +169,7 @@ void NetworkMatchCreator::createMatches(const ConstOsmMapPtr& map, std::vector(matches.size()); LOG_STATUS( "Found " << StringUtils::formatLargeNumber(matchesSizeAfter - matchesSizeBefore) << diff --git a/hoot-core/src/main/cpp/hoot/core/conflate/river/RiverMaximalSublineSettingOptimizer.cpp b/hoot-core/src/main/cpp/hoot/core/conflate/river/RiverMaximalSublineSettingOptimizer.cpp index 24f0f1bf39..e1b82ab482 100644 --- a/hoot-core/src/main/cpp/hoot/core/conflate/river/RiverMaximalSublineSettingOptimizer.cpp +++ b/hoot-core/src/main/cpp/hoot/core/conflate/river/RiverMaximalSublineSettingOptimizer.cpp @@ -139,10 +139,10 @@ int RiverMaximalSublineSettingOptimizer::getFindBestMatchesMaxRecursions(const C // non-linear function here instead that reduces the recursions allowed more quickly as the // total length increases in order to optimize the performance for river length counts in the // middle of the scale. - maxRecursions = + maxRecursions = static_cast( std::round( - ((double)_maxIterationsScalingValue / _maxRiverLengthScalingValue) * - (_maxRiverLengthScalingValue - totalRiverLength)); + (static_cast(_maxIterationsScalingValue) / _maxRiverLengthScalingValue) * + (_maxRiverLengthScalingValue - totalRiverLength))); LOG_DEBUG( "Using maximum recursion value of: " << maxRecursions << " for total river length: " << totalRiverLength); diff --git a/hoot-core/src/main/cpp/hoot/core/criterion/ChainCriterion.h b/hoot-core/src/main/cpp/hoot/core/criterion/ChainCriterion.h index a59c25acef..af718c1ec2 100644 --- a/hoot-core/src/main/cpp/hoot/core/criterion/ChainCriterion.h +++ b/hoot-core/src/main/cpp/hoot/core/criterion/ChainCriterion.h @@ -67,7 +67,7 @@ class ChainCriterion : public ElementCriterion, public ElementCriterionConsumer, QString getName() const override { return className(); } QString getClassName() const override { return className(); } - int criteriaSize() const { return _criteria.size(); } + int criteriaSize() const { return static_cast(_criteria.size()); } protected: diff --git a/hoot-core/src/main/cpp/hoot/core/elements/ElementId.h b/hoot-core/src/main/cpp/hoot/core/elements/ElementId.h index 9469cb5a03..5c41454ed4 100644 --- a/hoot-core/src/main/cpp/hoot/core/elements/ElementId.h +++ b/hoot-core/src/main/cpp/hoot/core/elements/ElementId.h @@ -112,7 +112,7 @@ inline uint qHash(const ElementId& eid) inline uint qHash(const std::pair& peid) { - return Tgs::cantorPairing(qHash(peid.first), qHash(peid.second)); + return static_cast(Tgs::cantorPairing(qHash(peid.first), qHash(peid.second))); } } diff --git a/hoot-core/src/main/cpp/hoot/core/elements/Relation.cpp b/hoot-core/src/main/cpp/hoot/core/elements/Relation.cpp index 2d5398aea9..361f884064 100644 --- a/hoot-core/src/main/cpp/hoot/core/elements/Relation.cpp +++ b/hoot-core/src/main/cpp/hoot/core/elements/Relation.cpp @@ -186,7 +186,7 @@ void Relation::insertElement(const QString& role, const ElementId& elementId, si int Relation::numElementsByRole(const QString& role) const { - return getElementsByRole(role).size(); + return static_cast(getElementsByRole(role).size()); } std::vector Relation::getElementsByRole(const QString& role) const diff --git a/hoot-core/src/main/cpp/hoot/core/elements/Way.h b/hoot-core/src/main/cpp/hoot/core/elements/Way.h index 5e16e0d5df..b744520271 100644 --- a/hoot-core/src/main/cpp/hoot/core/elements/Way.h +++ b/hoot-core/src/main/cpp/hoot/core/elements/Way.h @@ -107,7 +107,7 @@ class Way : public Element int getNodeIndex(long nodeId) const; long getFirstNodeId() const { return getNodeId(0); } - long getLastNodeId() const { return getNodeId(getNodeCount() - 1); } + long getLastNodeId() const { return getNodeId(static_cast(getNodeCount()) - 1); } /** * Determines if an index is the first or last diff --git a/hoot-core/src/main/cpp/hoot/core/geometry/ElementToGeometryConverter.cpp b/hoot-core/src/main/cpp/hoot/core/geometry/ElementToGeometryConverter.cpp index a30ce127ec..ffde498657 100644 --- a/hoot-core/src/main/cpp/hoot/core/geometry/ElementToGeometryConverter.cpp +++ b/hoot-core/src/main/cpp/hoot/core/geometry/ElementToGeometryConverter.cpp @@ -157,7 +157,7 @@ std::shared_ptr ElementToGeometryConverter::convertToLineString(cons LOG_TRACE("Converting " << w->getElementId() << " to line string..."); const std::vector& ids = w->getNodeIds(); - int size = ids.size(); + size_t size = ids.size(); if (size == 1) size = 2; diff --git a/hoot-core/src/main/cpp/hoot/core/geometry/GeometryMerger.cpp b/hoot-core/src/main/cpp/hoot/core/geometry/GeometryMerger.cpp index 027f8217f9..a4d6e409db 100644 --- a/hoot-core/src/main/cpp/hoot/core/geometry/GeometryMerger.cpp +++ b/hoot-core/src/main/cpp/hoot/core/geometry/GeometryMerger.cpp @@ -59,7 +59,7 @@ GeometryPtr GeometryMerger::mergeGeometries(std::vector geometries, { LOG_DEBUG("Merging " << StringUtils::formatLargeNumber(geometries.size()) << " geometries..."); // Get the geometry count - _geometryCount = geometries.size(); + _geometryCount = static_cast(geometries.size()); // Update the max threads to speed up smaller datasets _maxThreads = std::min(_maxThreads, static_cast(geometries.size() / 2)); // Create and start the threads diff --git a/hoot-core/src/main/cpp/hoot/core/geometry/GeometryPainter.cpp b/hoot-core/src/main/cpp/hoot/core/geometry/GeometryPainter.cpp index eb0d4b2b05..7690182fac 100644 --- a/hoot-core/src/main/cpp/hoot/core/geometry/GeometryPainter.cpp +++ b/hoot-core/src/main/cpp/hoot/core/geometry/GeometryPainter.cpp @@ -72,7 +72,7 @@ void GeometryPainter::drawPoint(QPainter& pt, double x, double y, const QMatrix& void GeometryPainter::drawWay(QPainter& pt, const OsmMap* map, const Way* way, const QMatrix& m) { - int size = way->getNodeCount(); + int size = static_cast(way->getNodeCount()); QPolygonF a(size); for (int j = 0; j < size; j++) diff --git a/hoot-core/src/main/cpp/hoot/core/geometry/RelationToMultiPolygonConverter.cpp b/hoot-core/src/main/cpp/hoot/core/geometry/RelationToMultiPolygonConverter.cpp index fd1d6c82e4..6a46f2df80 100644 --- a/hoot-core/src/main/cpp/hoot/core/geometry/RelationToMultiPolygonConverter.cpp +++ b/hoot-core/src/main/cpp/hoot/core/geometry/RelationToMultiPolygonConverter.cpp @@ -121,7 +121,7 @@ Geometry* RelationToMultiPolygonConverter::_addHoles(vector& outers else if (im->isIntersects()) { contained = false; - polygonIndex = j; + polygonIndex = static_cast(j); } } } diff --git a/hoot-core/src/main/cpp/hoot/core/info/IoSingleStat.cpp b/hoot-core/src/main/cpp/hoot/core/info/IoSingleStat.cpp index db64397176..ed76d90f29 100644 --- a/hoot-core/src/main/cpp/hoot/core/info/IoSingleStat.cpp +++ b/hoot-core/src/main/cpp/hoot/core/info/IoSingleStat.cpp @@ -87,7 +87,7 @@ IoSingleStat::IoSingleStat(Type t) QStringList l = line.split(":"); bool ok; - value = l[1].trimmed().toLong(&ok); + value = static_cast(l[1].trimmed().toLong(&ok)); if (!ok) throw HootException(QString("Error parsing %1 from /proc/self/io (%2).").arg(typeString, l[1])); found = true; diff --git a/hoot-core/src/main/cpp/hoot/core/info/NumericStatistic.h b/hoot-core/src/main/cpp/hoot/core/info/NumericStatistic.h index 424fdfc86e..3e10feb04f 100644 --- a/hoot-core/src/main/cpp/hoot/core/info/NumericStatistic.h +++ b/hoot-core/src/main/cpp/hoot/core/info/NumericStatistic.h @@ -53,7 +53,7 @@ class NumericStatistic : public SingleStatistic virtual long getInformationCount() const { return 0; } virtual long getInformationMin() const { return 0; } virtual long getInformationMax() const { return 0; } - virtual long getInformationCountDiff() const { return getStat() - getInformationCount(); } + virtual long getInformationCountDiff() const { return static_cast(getStat()) - getInformationCount(); } virtual double getInformationAverage() const { return 0; } }; diff --git a/hoot-core/src/main/cpp/hoot/core/io/DataConverter.cpp b/hoot-core/src/main/cpp/hoot/core/io/DataConverter.cpp index 1d84ef963b..e616d43fcd 100644 --- a/hoot-core/src/main/cpp/hoot/core/io/DataConverter.cpp +++ b/hoot-core/src/main/cpp/hoot/core/io/DataConverter.cpp @@ -221,7 +221,7 @@ void DataConverter::_convertStreamable(const QStringList& inputs, const QString& int numTasks = 1; // Streaming combines reading/writing into a single step. int currentTask = 1; - const float taskWeight = 1.0 / (float)numTasks; + const float taskWeight = 1.0f / static_cast(numTasks); // Stream the i/o ElementStreamer(_translationScript).stream( @@ -239,7 +239,7 @@ void DataConverter::_convertMemoryBound(const QStringList& inputs, const QString numTasks++; int currentTask = 1; - const float taskWeight = 1.0 / (float)numTasks; + const float taskWeight = 1.0f / static_cast(numTasks); Progress inputLoadProgress( ConfigOptions().getJobId(), JOB_SOURCE, Progress::JobState::Running, 0.0, taskWeight); diff --git a/hoot-core/src/main/cpp/hoot/core/io/InternalIdReserver.cpp b/hoot-core/src/main/cpp/hoot/core/io/InternalIdReserver.cpp index 860a40f8ee..cfccc5ffed 100644 --- a/hoot-core/src/main/cpp/hoot/core/io/InternalIdReserver.cpp +++ b/hoot-core/src/main/cpp/hoot/core/io/InternalIdReserver.cpp @@ -92,7 +92,7 @@ int InternalIdReserver::getNextId() { if (_closed) throw HootException("This reserver has already been closed."); - return _nextId++; + return static_cast(_nextId++); } } diff --git a/hoot-core/src/main/cpp/hoot/core/io/OsmApiDbSqlChangesetFileWriter.h b/hoot-core/src/main/cpp/hoot/core/io/OsmApiDbSqlChangesetFileWriter.h index 508f9784a6..9ab5246205 100644 --- a/hoot-core/src/main/cpp/hoot/core/io/OsmApiDbSqlChangesetFileWriter.h +++ b/hoot-core/src/main/cpp/hoot/core/io/OsmApiDbSqlChangesetFileWriter.h @@ -99,7 +99,7 @@ class OsmApiDbSqlChangesetFileWriter : public OsmChangesetFileWriter geos::geom::Envelope _changesetBounds; /** Settings from the config file */ - double _changesetUserId; + long _changesetUserId; // id mappings for created elements QMap _remappedIds; diff --git a/hoot-core/src/main/cpp/hoot/core/io/OsmApiDbSqlStatementFormatter.h b/hoot-core/src/main/cpp/hoot/core/io/OsmApiDbSqlStatementFormatter.h index a3b2f43e44..f88223584d 100644 --- a/hoot-core/src/main/cpp/hoot/core/io/OsmApiDbSqlStatementFormatter.h +++ b/hoot-core/src/main/cpp/hoot/core/io/OsmApiDbSqlStatementFormatter.h @@ -88,7 +88,7 @@ class OsmApiDbSqlStatementFormatter : public ApiDbSqlStatementFormatter inline unsigned int _convertDegreesToNanodegrees(const double degrees) const { - return round(degrees * ApiDb::COORDINATE_SCALE); + return static_cast(round(degrees * ApiDb::COORDINATE_SCALE)); } inline static QStringList getNodeSqlHeaderStrings() diff --git a/hoot-core/src/main/cpp/hoot/core/io/OsmPbfWriter.cpp b/hoot-core/src/main/cpp/hoot/core/io/OsmPbfWriter.cpp index d06e893856..4e59f3a1c7 100644 --- a/hoot-core/src/main/cpp/hoot/core/io/OsmPbfWriter.cpp +++ b/hoot-core/src/main/cpp/hoot/core/io/OsmPbfWriter.cpp @@ -105,12 +105,12 @@ OsmPbfWriter::~OsmPbfWriter() long OsmPbfWriter::_convertLon(double lon) const { - return static_cast((1000000000.0 * lon - _lonOffset) / _granularity); + return static_cast((1000000000.0 * lon - static_cast(_lonOffset)) / _granularity); } long OsmPbfWriter::_convertLat(double lat) const { - return static_cast((1000000000.0 * lat - _latOffset) / _granularity); + return static_cast((1000000000.0 * lat - static_cast(_latOffset)) / _granularity); } int OsmPbfWriter::_convertString(const QString& s) diff --git a/hoot-core/src/main/cpp/hoot/core/io/OsmXmlDiskCache.cpp b/hoot-core/src/main/cpp/hoot/core/io/OsmXmlDiskCache.cpp index 6e80b4c1cc..6f86afe2e6 100644 --- a/hoot-core/src/main/cpp/hoot/core/io/OsmXmlDiskCache.cpp +++ b/hoot-core/src/main/cpp/hoot/core/io/OsmXmlDiskCache.cpp @@ -43,9 +43,8 @@ OsmXmlDiskCache::OsmXmlDiskCache() // Check for temp dir // If $HOOT_HOME/tmp doesn't exist, and we can't make it, then use /tmp QString tempDir = ConfPath::getHootHome() + "/tmp"; - if (!QDir(tempDir).exists()) - if (!QDir(tempDir).mkpath(".")) - tempDir = "/tmp"; + if (!QDir(tempDir).exists() && !QDir(tempDir).mkpath(".")) + tempDir = QDir::tempPath(); // Setup our temp file & get guaranteed unique name QString fnameTemplate = tempDir + "/disk.cache.osm.XXXXXX"; diff --git a/hoot-core/src/main/cpp/hoot/core/io/OsmXmlWriter.cpp b/hoot-core/src/main/cpp/hoot/core/io/OsmXmlWriter.cpp index 5bea9f9447..f6d96525ce 100644 --- a/hoot-core/src/main/cpp/hoot/core/io/OsmXmlWriter.cpp +++ b/hoot-core/src/main/cpp/hoot/core/io/OsmXmlWriter.cpp @@ -168,7 +168,7 @@ QString OsmXmlWriter::toString(const ConstOsmMapPtr& map, const bool formatXml) throw InternalErrorException(QObject::tr("Error opening QBuffer for writing. Odd.")); writer.write(map); - return QString::fromUtf8(buf->data(), buf->size()); + return QString::fromUtf8(buf->data(), static_cast(buf->size())); } QString OsmXmlWriter::_typeName(ElementType e) diff --git a/hoot-core/src/main/cpp/hoot/core/io/schema/IntegerFieldDefinition.h b/hoot-core/src/main/cpp/hoot/core/io/schema/IntegerFieldDefinition.h index d4068114bf..83b2edee71 100644 --- a/hoot-core/src/main/cpp/hoot/core/io/schema/IntegerFieldDefinition.h +++ b/hoot-core/src/main/cpp/hoot/core/io/schema/IntegerFieldDefinition.h @@ -49,9 +49,9 @@ class IntegerFieldDefinition : public FieldDefinition void addEnumeratedValue(int v) { _enumeratedValues.insert(v); } bool hasEnumeratedValue(int v) { return _enumeratedValues.find(v) != _enumeratedValues.end(); } - void setDefaultValue(double v) { _defaultValue = v; } - void setMaxValue(double max) { _max = max; } - void setMinValue(double min) { _min = min; } + void setDefaultValue(int v) { _defaultValue = v; } + void setMaxValue(int max) { _max = max; } + void setMinValue(int min) { _min = min; } private: diff --git a/hoot-core/src/main/cpp/hoot/core/scoring/AttributeComparator.cpp b/hoot-core/src/main/cpp/hoot/core/scoring/AttributeComparator.cpp index 8fb3997531..9f7bfa39c2 100644 --- a/hoot-core/src/main/cpp/hoot/core/scoring/AttributeComparator.cpp +++ b/hoot-core/src/main/cpp/hoot/core/scoring/AttributeComparator.cpp @@ -133,7 +133,7 @@ double AttributeComparator::compareMaps() for (auto score : scores) v += (score - _mean) * (score - _mean); - _s = sqrt(v / (scores.size() - 1)); + _s = sqrt(v / static_cast(scores.size() - 1)); _ci = zalpha * _s / sqrt(scores.size()); } diff --git a/hoot-core/src/main/cpp/hoot/core/scoring/DirectedGraph.cpp b/hoot-core/src/main/cpp/hoot/core/scoring/DirectedGraph.cpp index 104fa11a9b..d4b77b727b 100644 --- a/hoot-core/src/main/cpp/hoot/core/scoring/DirectedGraph.cpp +++ b/hoot-core/src/main/cpp/hoot/core/scoring/DirectedGraph.cpp @@ -90,7 +90,7 @@ void DirectedGraph::deriveEdges(const std::shared_ptr& map) continue; long nStart = way->getNodeId(0); - long nEnd = way->getNodeId(way->getNodeCount() - 1); + long nEnd = way->getNodeId(static_cast(way->getNodeCount()) - 1); if (cost >= 0) { if (isOneWay(way)) diff --git a/hoot-core/src/main/cpp/hoot/core/scoring/MapCompareUtils.cpp b/hoot-core/src/main/cpp/hoot/core/scoring/MapCompareUtils.cpp index 10d7ef2027..117387fbca 100644 --- a/hoot-core/src/main/cpp/hoot/core/scoring/MapCompareUtils.cpp +++ b/hoot-core/src/main/cpp/hoot/core/scoring/MapCompareUtils.cpp @@ -107,7 +107,7 @@ int MapCompareUtils::getRasterComparisonFinalScore(const OsmMapPtr& map1, const int MapCompareUtils::convertRawScoreToFinalScore(const double score) { - return score * 1000.0 + 0.5; + return static_cast(score * 1000.0 + 0.5); } } diff --git a/hoot-core/src/main/cpp/hoot/core/util/SignalCatcher.cpp b/hoot-core/src/main/cpp/hoot/core/util/SignalCatcher.cpp index 1bb539fbbe..017fb917ab 100644 --- a/hoot-core/src/main/cpp/hoot/core/util/SignalCatcher.cpp +++ b/hoot-core/src/main/cpp/hoot/core/util/SignalCatcher.cpp @@ -117,7 +117,7 @@ void SignalCatcher::print_stacktrace(FILE *out, unsigned int max_frames) void* addrlist[max_frames+1]; // retrieve current stack addresses - int addrlen = backtrace(addrlist, sizeof(addrlist) / sizeof(void*)); + int addrlen = backtrace(addrlist, static_cast(sizeof(addrlist) / sizeof(void*))); if (addrlen == 0) { diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/AverageNumericTagsVisitor.cpp b/hoot-core/src/main/cpp/hoot/core/visitors/AverageNumericTagsVisitor.cpp index 696e6dd6e0..cf356ab229 100644 --- a/hoot-core/src/main/cpp/hoot/core/visitors/AverageNumericTagsVisitor.cpp +++ b/hoot-core/src/main/cpp/hoot/core/visitors/AverageNumericTagsVisitor.cpp @@ -101,7 +101,7 @@ double AverageNumericTagsVisitor::getStat() const LOG_VART(_sum); LOG_VART(_tagCount); if (_sum > 0.0 && _tagCount > 0) - return _sum / _tagCount; + return _sum / static_cast(_tagCount); return 0.0; } diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/BuildingHeightVisitor.h b/hoot-core/src/main/cpp/hoot/core/visitors/BuildingHeightVisitor.h index 114936695b..aeb99db09a 100644 --- a/hoot-core/src/main/cpp/hoot/core/visitors/BuildingHeightVisitor.h +++ b/hoot-core/src/main/cpp/hoot/core/visitors/BuildingHeightVisitor.h @@ -66,7 +66,7 @@ class BuildingHeightVisitor : public ConstElementVisitor, public NumericStatisti double getMax() const override { return _maxHeight; } double getAverage() const override { - const double average = _numAffected == 0 ? 0.0 : _totalHeight / _numAffected; + const double average = _numAffected == 0 ? 0.0 : _totalHeight / static_cast(_numAffected); return average; } diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/BuildingLevelsVisitor.h b/hoot-core/src/main/cpp/hoot/core/visitors/BuildingLevelsVisitor.h index a88fa74ed5..dcf90d6c25 100644 --- a/hoot-core/src/main/cpp/hoot/core/visitors/BuildingLevelsVisitor.h +++ b/hoot-core/src/main/cpp/hoot/core/visitors/BuildingLevelsVisitor.h @@ -62,7 +62,7 @@ class BuildingLevelsVisitor : public ConstElementVisitor, public NumericStatisti double getMax() const override { return _maxLevels; } double getAverage() const override { - const double average = _numAffected == 0 ? 0.0 : _totalLevels / _numAffected; + const double average = _numAffected == 0 ? 0.0 : _totalLevels / static_cast(_numAffected); return average; } diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/CountManualMatchesVisitor.h b/hoot-core/src/main/cpp/hoot/core/visitors/CountManualMatchesVisitor.h index 78003293e4..0b70c74306 100644 --- a/hoot-core/src/main/cpp/hoot/core/visitors/CountManualMatchesVisitor.h +++ b/hoot-core/src/main/cpp/hoot/core/visitors/CountManualMatchesVisitor.h @@ -47,7 +47,7 @@ class CountManualMatchesVisitor : public ConstElementVisitor, public SingleStati CountManualMatchesVisitor(); ~CountManualMatchesVisitor() override = default; - double getStat() const override { return _numManualMatches; } + double getStat() const override { return static_cast(_numManualMatches); } /** * @see ElementVisitor diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/CountUniqueReviewsVisitor.h b/hoot-core/src/main/cpp/hoot/core/visitors/CountUniqueReviewsVisitor.h index 619886775c..3217842744 100644 --- a/hoot-core/src/main/cpp/hoot/core/visitors/CountUniqueReviewsVisitor.h +++ b/hoot-core/src/main/cpp/hoot/core/visitors/CountUniqueReviewsVisitor.h @@ -48,7 +48,7 @@ class CountUniqueReviewsVisitor : public ElementConstOsmMapVisitor, public Singl CountUniqueReviewsVisitor() = default; ~CountUniqueReviewsVisitor() override = default; - double getStat() const override { return _reviews.size(); } + double getStat() const override { return static_cast(_reviews.size()); } /** * @see ElementVisitor diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/LengthOfWaysVisitor.h b/hoot-core/src/main/cpp/hoot/core/visitors/LengthOfWaysVisitor.h index 1c4442beb2..fe65b7bc8d 100644 --- a/hoot-core/src/main/cpp/hoot/core/visitors/LengthOfWaysVisitor.h +++ b/hoot-core/src/main/cpp/hoot/core/visitors/LengthOfWaysVisitor.h @@ -65,7 +65,7 @@ class LengthOfWaysVisitor : public ElementConstOsmMapVisitor, public NumericStat double getMax() const override { return _largest; } double getAverage() const override { - const double average = _numAffected == 0 ? 0.0 : _total / _numAffected; + const double average = _numAffected == 0 ? 0.0 : _total / static_cast(_numAffected); return average; } diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/MatchCandidateCountVisitor.h b/hoot-core/src/main/cpp/hoot/core/visitors/MatchCandidateCountVisitor.h index ee6ffba4e7..5ea089bfd3 100644 --- a/hoot-core/src/main/cpp/hoot/core/visitors/MatchCandidateCountVisitor.h +++ b/hoot-core/src/main/cpp/hoot/core/visitors/MatchCandidateCountVisitor.h @@ -57,7 +57,7 @@ class MatchCandidateCountVisitor : public ElementConstOsmMapVisitor, public Sing */ void visit(const std::shared_ptr& e) override; - double getStat() const override { return _totalCandidateCount; } + double getStat() const override { return static_cast(_totalCandidateCount); } boost::any getData() const override { return _matchCandidateCountsByMatchCreator; } diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/MaxIdVisitor.h b/hoot-core/src/main/cpp/hoot/core/visitors/MaxIdVisitor.h index 15a20ac78f..9b261a4cd0 100644 --- a/hoot-core/src/main/cpp/hoot/core/visitors/MaxIdVisitor.h +++ b/hoot-core/src/main/cpp/hoot/core/visitors/MaxIdVisitor.h @@ -50,7 +50,7 @@ class MaxIdVisitor : public ConstElementVisitor, public SingleStatistic MaxIdVisitor(); ~MaxIdVisitor() override = default; - double getStat() const override { return _maxId; } + double getStat() const override { return static_cast(_maxId); } void visit(const ConstElementPtr& e) override; diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/MinIdVisitor.h b/hoot-core/src/main/cpp/hoot/core/visitors/MinIdVisitor.h index a39723fa73..23f989dd31 100644 --- a/hoot-core/src/main/cpp/hoot/core/visitors/MinIdVisitor.h +++ b/hoot-core/src/main/cpp/hoot/core/visitors/MinIdVisitor.h @@ -50,7 +50,7 @@ class MinIdVisitor : public ConstElementVisitor, public SingleStatistic MinIdVisitor(); ~MinIdVisitor() override = default; - double getStat() const override { return _minId; } + double getStat() const override { return static_cast(_minId); } void visit(const ConstElementPtr& e) override; diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/NodesPerWayVisitor.cpp b/hoot-core/src/main/cpp/hoot/core/visitors/NodesPerWayVisitor.cpp index 84ee36fed0..b2acdf51d3 100644 --- a/hoot-core/src/main/cpp/hoot/core/visitors/NodesPerWayVisitor.cpp +++ b/hoot-core/src/main/cpp/hoot/core/visitors/NodesPerWayVisitor.cpp @@ -83,7 +83,7 @@ void NodesPerWayVisitor::visit(const ConstElementPtr& e) ConstWayPtr way = std::dynamic_pointer_cast(e); LOG_VART(way->getElementId()); - const int numWayNodes = way->getNodeCount(); + const int numWayNodes = static_cast(way->getNodeCount()); _totalWayNodes += numWayNodes; LOG_VART(_totalWayNodes); if (_minNodesPerWay == 0 || numWayNodes < _minNodesPerWay) diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/RandomElementRenamer.cpp b/hoot-core/src/main/cpp/hoot/core/visitors/RandomElementRenamer.cpp index 80f8f3d4ae..02c6d82ed5 100644 --- a/hoot-core/src/main/cpp/hoot/core/visitors/RandomElementRenamer.cpp +++ b/hoot-core/src/main/cpp/hoot/core/visitors/RandomElementRenamer.cpp @@ -69,7 +69,7 @@ QString RandomElementRenamer::permuteName(const QString& s) // replace the letter with a random letter a-z or space case 0: { - char letter = uniLetter(*_rng); + char letter = static_cast(uniLetter(*_rng)); if (letter == 'z' + 1) { letter = ' '; @@ -79,7 +79,7 @@ QString RandomElementRenamer::permuteName(const QString& s) // randomly swap a letter. case 1: { - int pos = max(uni(*_rng) * result.size(), result.size() - 1); + int pos = max(static_cast(uni(*_rng) * result.size()), result.size() - 1); QChar c1 = result[i]; result[i] = result[pos]; result[pos] = c1; diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/RandomWaySplitter.cpp b/hoot-core/src/main/cpp/hoot/core/visitors/RandomWaySplitter.cpp index fde51a239b..cb7beea8af 100644 --- a/hoot-core/src/main/cpp/hoot/core/visitors/RandomWaySplitter.cpp +++ b/hoot-core/src/main/cpp/hoot/core/visitors/RandomWaySplitter.cpp @@ -232,7 +232,7 @@ MultiLineStringLocation RandomWaySplitter::_calcSplitPoint(ConstRelationPtr rela LOG_VART(members.size()); //find the way to split on - boost::uniform_int<> randomWayIndexDistribution(0, members.size() - 1); + boost::uniform_int<> randomWayIndexDistribution(0, static_cast(members.size()) - 1); int wayIndex = randomWayIndexDistribution(*_rng); wayId = members.at(wayIndex).getElementId(); LOG_VART(wayIndex); diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/SumNumericTagsVisitor.cpp b/hoot-core/src/main/cpp/hoot/core/visitors/SumNumericTagsVisitor.cpp index cb987522d5..50afc46b37 100644 --- a/hoot-core/src/main/cpp/hoot/core/visitors/SumNumericTagsVisitor.cpp +++ b/hoot-core/src/main/cpp/hoot/core/visitors/SumNumericTagsVisitor.cpp @@ -63,7 +63,7 @@ void SumNumericTagsVisitor::visit(const ConstElementPtr& e) const long value = strValue.toLong(&parsed); if (parsed) { - _sum += value; + _sum += static_cast(value); _numAffected++; } else diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/TagCountVisitor.h b/hoot-core/src/main/cpp/hoot/core/visitors/TagCountVisitor.h index 836274380e..eaf376391d 100644 --- a/hoot-core/src/main/cpp/hoot/core/visitors/TagCountVisitor.h +++ b/hoot-core/src/main/cpp/hoot/core/visitors/TagCountVisitor.h @@ -56,12 +56,12 @@ class TagCountVisitor : public ConstElementVisitor, public NumericStatistic void visit(const ConstElementPtr& e) override; long numWithStat() const override { return _numAffected; } - double getStat() const override { return _totalCount; } - double getMin() const override { return _smallestCount; } - double getMax() const override { return _largestCount; } + double getStat() const override { return static_cast(_totalCount); } + double getMin() const override { return static_cast(_smallestCount); } + double getMax() const override { return static_cast(_largestCount); } double getAverage() const override { - const double average = _numAffected == 0 ? 0.0 : _totalCount / _numAffected; + const double average = _numAffected == 0 ? 0.0 : static_cast(_totalCount) / static_cast(_numAffected); return average; } diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/TagKeyCountVisitor.h b/hoot-core/src/main/cpp/hoot/core/visitors/TagKeyCountVisitor.h index 51dd81d4d0..39d68795ed 100644 --- a/hoot-core/src/main/cpp/hoot/core/visitors/TagKeyCountVisitor.h +++ b/hoot-core/src/main/cpp/hoot/core/visitors/TagKeyCountVisitor.h @@ -60,7 +60,7 @@ class TagKeyCountVisitor : public ConstElementVisitor, public SingleStatistic, p */ void visit(const ConstElementPtr& e) override; - double getStat() const override { return _keyCount; } + double getStat() const override { return static_cast(_keyCount); } /** * @see Configurable diff --git a/hoot-josm/src/main/cpp/hoot/josm/ops/JosmMapValidatorAbstract.h b/hoot-josm/src/main/cpp/hoot/josm/ops/JosmMapValidatorAbstract.h index f932940a85..1f7f80057b 100644 --- a/hoot-josm/src/main/cpp/hoot/josm/ops/JosmMapValidatorAbstract.h +++ b/hoot-josm/src/main/cpp/hoot/josm/ops/JosmMapValidatorAbstract.h @@ -81,7 +81,7 @@ class JosmMapValidatorAbstract : public OsmMapOperation, public Configurable QString getCompletedStatusMessage() const override { return _errorSummary; } QString getSummary() const { return _errorSummary; } - int getNumElementsProcessed() const { return _numAffected; } + int getNumElementsProcessed() const { return static_cast(_numAffected); } int getNumValidationErrors() const { return _numValidationErrors; } int getNumFailingValidators() const { return _numFailingValidators; } diff --git a/hoot-js/src/main/cpp/hoot/js/elements/ElementJs.cpp b/hoot-js/src/main/cpp/hoot/js/elements/ElementJs.cpp index 56f92dd688..9dcd79b5ff 100644 --- a/hoot-js/src/main/cpp/hoot/js/elements/ElementJs.cpp +++ b/hoot-js/src/main/cpp/hoot/js/elements/ElementJs.cpp @@ -166,7 +166,7 @@ void ElementJs::getId(const FunctionCallbackInfo& args) ConstElementPtr e = ObjectWrap::Unwrap(args.This())->getConstElement(); - args.GetReturnValue().Set(Integer::New(current, e->getId())); + args.GetReturnValue().Set(Integer::New(current, static_cast(e->getId()))); } void ElementJs::getStatusInput(const FunctionCallbackInfo& args) diff --git a/hoot-js/src/main/cpp/hoot/js/elements/OsmMapJs.cpp b/hoot-js/src/main/cpp/hoot/js/elements/OsmMapJs.cpp index 30728721ce..47ee8af611 100644 --- a/hoot-js/src/main/cpp/hoot/js/elements/OsmMapJs.cpp +++ b/hoot-js/src/main/cpp/hoot/js/elements/OsmMapJs.cpp @@ -180,7 +180,7 @@ void OsmMapJs::getElementCount(const FunctionCallbackInfo& args) OsmMapJs* obj = ObjectWrap::Unwrap(args.This()); - args.GetReturnValue().Set(Number::New(current, obj->getConstMap()->getElementCount())); + args.GetReturnValue().Set(Number::New(current, static_cast(obj->getConstMap()->getElementCount()))); } void OsmMapJs::visit(const FunctionCallbackInfo& args) diff --git a/hoot-js/src/main/cpp/hoot/js/elements/WayJs.cpp b/hoot-js/src/main/cpp/hoot/js/elements/WayJs.cpp index 1fb910e065..7b08766eac 100644 --- a/hoot-js/src/main/cpp/hoot/js/elements/WayJs.cpp +++ b/hoot-js/src/main/cpp/hoot/js/elements/WayJs.cpp @@ -110,7 +110,7 @@ void WayJs::getNodeCount(const FunctionCallbackInfo& args) HandleScope scope(current); ConstWayPtr way = ObjectWrap::Unwrap(args.This())->getConstWay(); - args.GetReturnValue().Set(Number::New(current, way->getNodeCount())); + args.GetReturnValue().Set(Number::New(current, static_cast(way->getNodeCount()))); } } diff --git a/hoot-js/src/main/cpp/hoot/js/io/StreamUtilsJs.h b/hoot-js/src/main/cpp/hoot/js/io/StreamUtilsJs.h index 3dbba0f913..b1369bdd7b 100644 --- a/hoot-js/src/main/cpp/hoot/js/io/StreamUtilsJs.h +++ b/hoot-js/src/main/cpp/hoot/js/io/StreamUtilsJs.h @@ -117,7 +117,7 @@ QString toJson(const v8::Local object) v8::Local resultValue = JSON_stringify->Call(context, JSON, 1, args).ToLocalChecked(); v8::Local s = v8::Local::Cast(resultValue); - size_t utf8Length = s->Utf8Length(current) + 1; + int utf8Length = s->Utf8Length(current) + 1; std::unique_ptr buffer = std::make_unique(utf8Length); s->WriteUtf8(current, buffer.get(), utf8Length); diff --git a/hoot-js/src/main/cpp/hoot/js/schema/JavaScriptSchemaTranslator.cpp b/hoot-js/src/main/cpp/hoot/js/schema/JavaScriptSchemaTranslator.cpp index 780502694e..f2a8d628e2 100644 --- a/hoot-js/src/main/cpp/hoot/js/schema/JavaScriptSchemaTranslator.cpp +++ b/hoot-js/src/main/cpp/hoot/js/schema/JavaScriptSchemaTranslator.cpp @@ -400,7 +400,7 @@ void JavaScriptSchemaTranslator::_parseEnumerations(std::shared_ptrhasEnumeratedValue(v)) { if (logWarnCount < Log::getWarnMessageLimit()) diff --git a/test-files/cmd/slow/ConflateCmdStatsAllDataTypesTest.sh.stdout b/test-files/cmd/slow/ConflateCmdStatsAllDataTypesTest.sh.stdout index 4ef4789e9f..d0ba12c2ab 100644 --- a/test-files/cmd/slow/ConflateCmdStatsAllDataTypesTest.sh.stdout +++ b/test-files/cmd/slow/ConflateCmdStatsAllDataTypesTest.sh.stdout @@ -1,7 +1,7 @@ -15:37:47.466 STATUS .../cpp/hoot/core/cmd/DiffCmd.cpp( 112) Comparing ...st/all-data-types-out.osm and ...st/all-data-types-out.osm... -15:37:47.488 STATUS ...ore/io/OsmMapReaderFactory.cpp( 176) Read 167 elements from input in: 00:00. -15:37:47.494 STATUS ...ore/io/OsmMapReaderFactory.cpp( 176) Read 167 elements from input in: 00:00. -15:37:47.496 STATUS .../cpp/hoot/core/cmd/DiffCmd.cpp( 146) Map difference calculated in 00:00 total. +21:31:46.867 STATUS .../cpp/hoot/core/cmd/DiffCmd.cpp( 112) Comparing ...st/all-data-types-out.osm and ...st/all-data-types-out.osm... +21:31:46.889 STATUS ...ore/io/OsmMapReaderFactory.cpp( 176) Read 167 elements from input in: 00:00. +21:31:46.895 STATUS ...ore/io/OsmMapReaderFactory.cpp( 176) Read 167 elements from input in: 00:00. +21:31:46.897 STATUS .../cpp/hoot/core/cmd/DiffCmd.cpp( 146) Map difference calculated in 00:00 total. stats = (stat) OR (input map 1 stat) (input map 2 stat) (output map stat) Nodes 117 116 142 Ways 14 12 16 @@ -18,7 +18,7 @@ Unique Feature Tags 36 28 67 Unique Feature Tag Keys 11 9 21 Least Tags on a Feature 2 1 0 Most Tags on a Feature 4 4 6 -Average Tags Per Feature 3 2 3 +Average Tags Per Feature 3.08 2.818181818181818 3.242424242424242 Least Information Tags on a Feature 2 1 0 Most Information Tags on a Feature 4 4 6 Average Information Tags Per Feature 3.08 2.818181818181818 3.242424242424242 @@ -276,10 +276,10 @@ Percentage of Area of Map 2 Polygons Not Matched With Map 1 Polygons 358.12323 Percentage of Length of Map 1 Lines Matched With Map 2 Lines 94.07991736179613 Percentage of Length of Map 1 Lines Not Matched With Map 2 Lines 5.920051984052825 Percentage of Length of Map 2 Lines Not Matched With Map 1 Lines 0 -Calculate Stats for Input 1 Time (sec) 1.075518846511841 -Calculate Stats for Input 2 Time (sec) 0.8069651126861572 -Apply Pre-Conflate Ops Time (sec) 0.01336789131164551 -Apply Post-Conflate Ops Time (sec) 0.01035714149475098 -Calculate Stats for Output Time (sec) 0.8349521160125732 +Calculate Stats for Input 1 Time (sec) 1.141434907913208 +Calculate Stats for Input 2 Time (sec) 1.097521066665649 +Apply Pre-Conflate Ops Time (sec) 0.0137479305267334 +Apply Post-Conflate Ops Time (sec) 0.01029801368713379 +Calculate Stats for Output Time (sec) 0.8931570053100586 -15:37:47.092 STATUS ...pp/hoot/core/util/Progress.cpp( 80) Conflate (100%): Conflation job completed in 00:03 for reference map: ...late/unified/AllDataTypesA.osm and secondary map: ...late/unified/AllDataTypesB.osm and written to output: ...atsTest/all-data-types-out.osm +21:31:46.439 STATUS ...pp/hoot/core/util/Progress.cpp( 80) Conflate (100%): Conflation job completed in 00:04 for reference map: ...late/unified/AllDataTypesA.osm and secondary map: ...late/unified/AllDataTypesB.osm and written to output: ...atsTest/all-data-types-out.osm diff --git a/test-files/cmd/slow/ConflateCmdStatsGenericRiversTest.sh.stdout b/test-files/cmd/slow/ConflateCmdStatsGenericRiversTest.sh.stdout index e87625ddf2..9692182298 100644 --- a/test-files/cmd/slow/ConflateCmdStatsGenericRiversTest.sh.stdout +++ b/test-files/cmd/slow/ConflateCmdStatsGenericRiversTest.sh.stdout @@ -1,7 +1,7 @@ -22:38:32.311 STATUS .../cpp/hoot/core/cmd/DiffCmd.cpp( 112) Comparing ...st/generic-rivers-out.osm and ...st/generic-rivers-out.osm... -22:38:32.341 STATUS ...ore/io/OsmMapReaderFactory.cpp( 176) Read 481 elements from input in: 00:00. -22:38:32.357 STATUS ...ore/io/OsmMapReaderFactory.cpp( 176) Read 481 elements from input in: 00:00. -22:38:32.361 STATUS .../cpp/hoot/core/cmd/DiffCmd.cpp( 146) Map difference calculated in 00:00 total. +21:31:45.933 STATUS .../cpp/hoot/core/cmd/DiffCmd.cpp( 112) Comparing ...st/generic-rivers-out.osm and ...st/generic-rivers-out.osm... +21:31:45.965 STATUS ...ore/io/OsmMapReaderFactory.cpp( 176) Read 481 elements from input in: 00:00. +21:31:45.981 STATUS ...ore/io/OsmMapReaderFactory.cpp( 176) Read 481 elements from input in: 00:00. +21:31:45.985 STATUS .../cpp/hoot/core/cmd/DiffCmd.cpp( 146) Map difference calculated in 00:00 total. stats = (stat) OR (input map 1 stat) (input map 2 stat) (output map stat) Nodes 338 176 448 Ways 14 15 32 @@ -18,7 +18,7 @@ Unique Feature Tags 22 18 51 Unique Feature Tag Keys 6 4 20 Least Tags on a Feature 4 3 0 Most Tags on a Feature 6 4 9 -Average Tags Per Feature 5 3 5 +Average Tags Per Feature 5.142857142857143 3.133333333333333 5.375 Least Information Tags on a Feature 3 3 0 Most Information Tags on a Feature 5 4 8 Average Information Tags Per Feature 4.142857142857143 3.133333333333333 4.9375 @@ -73,10 +73,10 @@ Percentage of Number of Total Map 2 Features Not Matched With Map 1 Features 1 Percentage of Length of Map 1 Rivers Matched With Map 2 Rivers 99.99999999680529 Percentage of Length of Map 1 Rivers Not Matched With Map 2 Rivers 0 Percentage of Length of Map 2 Rivers Not Matched With Map 1 Rivers 54.19652446284084 -Calculate Stats for Input 1 Time (sec) 0.9689021110534668 -Calculate Stats for Input 2 Time (sec) 0.7046158313751221 -Apply Pre-Conflate Ops Time (sec) 0.0314481258392334 -Apply Post-Conflate Ops Time (sec) 0.01377987861633301 -Calculate Stats for Output Time (sec) 0.7581818103790283 +Calculate Stats for Input 1 Time (sec) 1.214991807937622 +Calculate Stats for Input 2 Time (sec) 0.892003059387207 +Apply Pre-Conflate Ops Time (sec) 0.03232502937316895 +Apply Post-Conflate Ops Time (sec) 0.01352500915527344 +Calculate Stats for Output Time (sec) 0.8231980800628662 -22:38:31.963 STATUS ...pp/hoot/core/util/Progress.cpp( 80) Conflate (100%): Conflation job completed in 00:02 for reference map: ...NIGS_Rivers_REF1-cropped-2.osm and secondary map: ...waterway_ss_REF2-cropped-2.osm and written to output: ...atsTest/generic-rivers-out.osm +21:31:45.529 STATUS ...pp/hoot/core/util/Progress.cpp( 80) Conflate (100%): Conflation job completed in 00:02 for reference map: ...NIGS_Rivers_REF1-cropped-2.osm and secondary map: ...waterway_ss_REF2-cropped-2.osm and written to output: ...atsTest/generic-rivers-out.osm diff --git a/test-files/cmd/slow/ConflateCmdStatsToyBuildingsTest.sh.stdout b/test-files/cmd/slow/ConflateCmdStatsToyBuildingsTest.sh.stdout index 20c72dbe86..15b1b2774f 100644 --- a/test-files/cmd/slow/ConflateCmdStatsToyBuildingsTest.sh.stdout +++ b/test-files/cmd/slow/ConflateCmdStatsToyBuildingsTest.sh.stdout @@ -1,7 +1,7 @@ -19:58:12.685 STATUS .../cpp/hoot/core/cmd/DiffCmd.cpp( 118) Comparing ...est/toy-buildings-out.osm and ...est/toy-buildings-out.osm... -19:58:12.702 STATUS ...ore/io/OsmMapReaderFactory.cpp( 192) Read 103 elements from input in: 00:00. -19:58:12.706 STATUS ...ore/io/OsmMapReaderFactory.cpp( 192) Read 103 elements from input in: 00:00. -19:58:12.707 STATUS .../cpp/hoot/core/cmd/DiffCmd.cpp( 156) Map difference calculated in 00:00 total. +21:31:46.084 STATUS .../cpp/hoot/core/cmd/DiffCmd.cpp( 112) Comparing ...est/toy-buildings-out.osm and ...est/toy-buildings-out.osm... +21:31:46.104 STATUS ...ore/io/OsmMapReaderFactory.cpp( 176) Read 103 elements from input in: 00:00. +21:31:46.108 STATUS ...ore/io/OsmMapReaderFactory.cpp( 176) Read 103 elements from input in: 00:00. +21:31:46.110 STATUS .../cpp/hoot/core/cmd/DiffCmd.cpp( 146) Map difference calculated in 00:00 total. stats = (stat) OR (input map 1 stat) (input map 2 stat) (output map stat) Nodes 70 41 90 Ways 10 8 12 @@ -18,7 +18,7 @@ Unique Feature Tags 16 14 24 Unique Feature Tag Keys 6 4 7 Least Tags on a Feature 2 2 1 Most Tags on a Feature 4 4 6 -Average Tags Per Feature 3 2 3 +Average Tags Per Feature 3.1 2.875 3.153846153846154 Least Information Tags on a Feature 2 2 1 Most Information Tags on a Feature 4 4 6 Average Information Tags Per Feature 3.1 2.875 3.153846153846154 @@ -82,10 +82,10 @@ Percentage of Number of Total Map 2 Features Not Matched With Map 1 Features 3 Percentage of Area of Map 1 Buildings Matched With Map 2 Buildings 883.2856402569838 Percentage of Area of Map 1 Buildings Not Matched With Map 2 Buildings 409.7576554696115 Percentage of Area of Map 2 Buildings Not Matched With Map 1 Buildings 311.1930828033256 -Calculate Stats for Input 1 Time (sec) 0.8223459720611572 -Calculate Stats for Input 2 Time (sec) 0.5136070251464844 -Apply Pre-Conflate Ops Time (sec) 0.003849029541015625 -Apply Post-Conflate Ops Time (sec) 0.003684043884277344 -Calculate Stats for Output Time (sec) 0.5505919456481934 +Calculate Stats for Input 1 Time (sec) 1.018394947052002 +Calculate Stats for Input 2 Time (sec) 0.586421012878418 +Apply Pre-Conflate Ops Time (sec) 0.00535893440246582 +Apply Post-Conflate Ops Time (sec) 0.004465103149414063 +Calculate Stats for Output Time (sec) 0.5951669216156006 -19:58:12.337 STATUS ...pp/hoot/core/util/Progress.cpp( 86) Conflate (100%): Conflation job completed in 00:01 for reference map: ...st-files/ToyBuildingsTestA.osm and secondary map: ...st-files/ToyBuildingsTestB.osm and written to output: ...tatsTest/toy-buildings-out.osm +21:31:45.724 STATUS ...pp/hoot/core/util/Progress.cpp( 80) Conflate (100%): Conflation job completed in 00:02 for reference map: ...st-files/ToyBuildingsTestA.osm and secondary map: ...st-files/ToyBuildingsTestB.osm and written to output: ...tatsTest/toy-buildings-out.osm diff --git a/test-files/cmd/slow/ConflatePoiStatsTest.sh.stdout b/test-files/cmd/slow/ConflatePoiStatsTest.sh.stdout index a4952867bc..2fdd2f1b75 100644 --- a/test-files/cmd/slow/ConflatePoiStatsTest.sh.stdout +++ b/test-files/cmd/slow/ConflatePoiStatsTest.sh.stdout @@ -14,7 +14,7 @@ Unique Feature Tags 7 6 24 Unique Feature Tag Keys 3 3 11 Least Tags on a Feature 2 3 0 Most Tags on a Feature 3 3 5 -Average Tags Per Feature 2 3 3 +Average Tags Per Feature 2.333333333333333 3 3.5 Least Information Tags on a Feature 1 2 0 Most Information Tags on a Feature 2 2 4 Average Information Tags Per Feature 1.333333333333333 2 2.5 @@ -62,10 +62,10 @@ Percentage Difference Between Total Features in Output and Total Features in Inp Percentage of Number of Total Map 1 Features Matched With Map 2 Features 66.66666666666666 Percentage of Number of Total Map 1 Features Not Matched With Map 2 Features 33.33333333333333 Percentage of Number of Total Map 2 Features Not Matched With Map 1 Features 33.33333333333333 -Calculate Stats for Input 1 Time (sec) 0.7503058910369873 -Calculate Stats for Input 2 Time (sec) 0.3566060066223145 -Apply Pre-Conflate Ops Time (sec) 0.0007119178771972656 -Apply Post-Conflate Ops Time (sec) 0.002981901168823242 -Calculate Stats for Output Time (sec) 0.5237259864807129 +Calculate Stats for Input 1 Time (sec) 0.9538021087646484 +Calculate Stats for Input 2 Time (sec) 0.7260439395904541 +Apply Pre-Conflate Ops Time (sec) 0.002640962600708008 +Apply Post-Conflate Ops Time (sec) 0.006155014038085938 +Calculate Stats for Output Time (sec) 0.7417359352111816 -18:13:09.534 STATUS ...pp/hoot/core/util/Progress.cpp( 81) Conflate (100%): Conflation job completed in 00:01 for reference map: ...test-files/dcpoi_clip.osm and secondary map: ...st-files/mapcruzinpoi_clip.osm and written to output: ...nflatePoiStatsTest/poi-out.osm +21:31:50.712 STATUS ...pp/hoot/core/util/Progress.cpp( 80) Conflate (100%): Conflation job completed in 00:01 for reference map: ...test-files/dcpoi_clip.osm and secondary map: ...st-files/mapcruzinpoi_clip.osm and written to output: ...nflatePoiStatsTest/poi-out.osm diff --git a/test-files/cmd/slow/StatsCmdTest.sh.stdout b/test-files/cmd/slow/StatsCmdTest.sh.stdout index 1cde1ce3e0..1f5dad9634 100644 --- a/test-files/cmd/slow/StatsCmdTest.sh.stdout +++ b/test-files/cmd/slow/StatsCmdTest.sh.stdout @@ -151,8 +151,8 @@ Full stats from multiple files to json... ], "Average Tags Per Feature": [ - "3", - "2" + "3.08", + "2.818181818181818" ], "Least Information Tags on a Feature": [ diff --git a/tgs/src/main/cpp/tgs/Interpolation/IdwInterpolator.cpp b/tgs/src/main/cpp/tgs/Interpolation/IdwInterpolator.cpp index 3b99858d6d..6f51529a80 100644 --- a/tgs/src/main/cpp/tgs/Interpolation/IdwInterpolator.cpp +++ b/tgs/src/main/cpp/tgs/Interpolation/IdwInterpolator.cpp @@ -159,7 +159,7 @@ const vector& IdwInterpolator::_interpolate(const vector& point, { continue; } - const vector& record = df.getDataVector(i); + const vector& record = df.getDataVector(static_cast(i)); // figure out the distance between point and this data vector double d = 0; diff --git a/tgs/src/main/cpp/tgs/Interpolation/KernelEstimationInterpolator.cpp b/tgs/src/main/cpp/tgs/Interpolation/KernelEstimationInterpolator.cpp index 977dac5547..e238c08e88 100644 --- a/tgs/src/main/cpp/tgs/Interpolation/KernelEstimationInterpolator.cpp +++ b/tgs/src/main/cpp/tgs/Interpolation/KernelEstimationInterpolator.cpp @@ -78,8 +78,8 @@ void KernelEstimationInterpolator::_buildModel() { // calculate the standard deviation in x double mean = 0; - size_t n = df.getNumDataVectors(); - for (size_t i = 0; i < n; ++i) + unsigned int n = df.getNumDataVectors(); + for (unsigned int i = 0; i < n; ++i) { double v = df.getDataVector(i)[_indColumns[0]]; mean += v; @@ -87,13 +87,13 @@ void KernelEstimationInterpolator::_buildModel() mean /= df.getNumDataVectors(); double sumDiff = 0; - for (size_t i = 0; i < n; ++i) + for (unsigned int i = 0; i < n; ++i) { double v = df.getDataVector(i)[_indColumns[0]]; sumDiff += (v - mean) * (v - mean); } - double sdx = sqrt(1.0 / (n - 1) * sumDiff); + double sdx = sqrt(1.0 / static_cast(n - 1) * sumDiff); // calculate a reasonable starting point w/ silverman's rule of thumb. Put a minimum at 1m to // prevent some edge conditions. @@ -148,7 +148,7 @@ double KernelEstimationInterpolator::_estimateError(unsigned int index) const while (it.next() && it.getDistance() < _sigma * 3.0 && iterations <= _maxAllowedPerLoopOptimizationIterations) { - size_t i = it.getId(); + unsigned int i = it.getId(); if (i == index) { continue; @@ -222,7 +222,7 @@ const vector& KernelEstimationInterpolator::interpolate(const vector& record = df.getDataVector(i); // figure out the distance between point and this data vector diff --git a/tgs/src/main/cpp/tgs/RStarTree/HilbertRTree.cpp b/tgs/src/main/cpp/tgs/RStarTree/HilbertRTree.cpp index 2a88d0fbaa..faa014cf8e 100644 --- a/tgs/src/main/cpp/tgs/RStarTree/HilbertRTree.cpp +++ b/tgs/src/main/cpp/tgs/RStarTree/HilbertRTree.cpp @@ -22,7 +22,7 @@ * This will properly maintain the copyright information. Maxar * copyrights will be updated automatically. * - * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020, 2021 Maxar (http://www.maxar.com/) + * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Maxar (http://www.maxar.com/) */ #include "HilbertRTree.h" @@ -45,17 +45,14 @@ using namespace std; namespace Tgs { -HilbertRTree::HilbertRTree(const std::shared_ptr& ps, int dimensions) : -RStarTree(ps, dimensions), -_hilbertCurve(std::make_shared(dimensions, 8)) +HilbertRTree::HilbertRTree(const std::shared_ptr& ps, int dimensions) + : RStarTree(ps, dimensions), + _hilbertCurve(std::make_shared(dimensions, 8)) { } void HilbertRTree::bulkInsert(const std::vector& boxes, const std::vector& fids) { - //std::cout << "Child count: " << getRoot()->getChildCount() << std::endl; - //std::cout << "boxes size: " << boxes.size() << std::endl; - //std::cout << "fids size: " << fids.size() << std::endl; assert(getRoot()->getChildCount() == 0); assert(boxes.size() == fids.size()); std::vector sortedBoxes; @@ -64,9 +61,7 @@ void HilbertRTree::bulkInsert(const std::vector& boxes, const std::vector childNodes; _createLeafNodes(sortedBoxes, childNodes); _setHeight(0); - //std::cout << "Child nodes count: " << childNodes.size() << std::endl; - //std::cout << "Creating parent nodes..." << std::endl; while (childNodes.size() != 1) { std::vector parentNodes; @@ -77,26 +72,20 @@ void HilbertRTree::bulkInsert(const std::vector& boxes, const std::vector& boxes, - const std::vector& fids, std::vector& hilbertBoxes) const +void HilbertRTree::_calculateHilbertValues(const std::vector& boxes, const std::vector& fids, + std::vector& hilbertBoxes) const { - //std::cout << "Calculating Hilbert values..." << std::endl; - assert(hilbertBoxes.size() == 0); HilbertCurve hilbertCurve(_dimensions, 16); hilbertBoxes.reserve(boxes.size()); Box bounds(_dimensions); - for (unsigned int i = 0; i < boxes.size(); i++) - { - bounds.expand(boxes[i]); - } + for (const auto& box : boxes) + bounds.expand(box); double boundsWidth[Box::MAX_DIMENSIONS] = { 0.0 }; for (int i = 0; i < bounds.getDimensions(); i++) - { boundsWidth[i] = bounds.getUpperBoundRaw(i) - bounds.getLowerBoundRaw(i); - } int point[Box::MAX_DIMENSIONS]; for (unsigned int i = 0; i < boxes.size(); i++) @@ -108,17 +97,13 @@ void HilbertRTree::_calculateHilbertValues(const std::vector& boxes, { double v = (box.getLowerBoundRaw(j) + box.getUpperBoundRaw(j)) / 2.0; if (boundsWidth[j] != 0) - { point[j] = int(((1 << ORDER) - 1) * ((v - bounds.getLowerBoundRaw(j)) / boundsWidth[j])); - } else - { point[j] = 0; - } assert(point[j] >= 0 && point[j] < (1 << ORDER)); } - hilbertBoxes.push_back(UserBoxHolder(boxes[i], fids[i], _hilbertCurve->encode(point))); + hilbertBoxes.push_back(UserBoxHolder(boxes[i], fids[i], static_cast(_hilbertCurve->encode(point)))); } sort(hilbertBoxes.begin(), hilbertBoxes.end()); } @@ -128,15 +113,12 @@ double HilbertRTree::_calculateArea(int parentId) const RTreeNode* parent = _getNode(parentId); double result = 0.0; for (int i = 0; i < parent->getChildCount(); i++) - { result += parent->getChildEnvelope(i).calculateVolume(); - } + if (parent->isLeafNode() == false) { for (int i = 0; i < parent->getChildCount(); i++) - { result += _calculateArea(parent->getChildNodeId(i)); - } } return result; @@ -150,9 +132,7 @@ double HilbertRTree::_calculateOverlap(int parentId) if (parent->isLeafNode() == false) { for (int i = 0; i < parent->getChildCount(); i++) - { result += _calculateOverlap(parent->getChildNodeId(i)); - } } return result; @@ -171,8 +151,7 @@ double HilbertRTree::_calculatePairwiseOverlap(int parentId, std::vector if (i != j) { // TODO: remove toBox and implement overlap calculation for BoxInternal - double o = parent->getChildEnvelope(j).calculateOverlap( - parent->getChildEnvelope(i).toBox()); + double o = parent->getChildEnvelope(j).calculateOverlap(parent->getChildEnvelope(i).toBox()); overlaps[i] += o; result += o; } @@ -186,14 +165,12 @@ int HilbertRTree::_chooseWeightedChild(const std::vector& weights) const assert(weights.size() > 0); int result = -1; double sum = 0.0; - for (unsigned int i = 0; i < weights.size(); i++) - { - sum += weights[i]; - } + for (auto weight : weights) + sum += weight; + if (sum == 0.0) - { - return Tgs::Random::instance()->generateInt(weights.size()); - } + return Tgs::Random::instance()->generateInt(static_cast(weights.size())); + double r = Tgs::Random::instance()->generateUniform() * sum; double incr = 0.0; for (unsigned int i = 0; i < weights.size(); i++) @@ -206,84 +183,47 @@ int HilbertRTree::_chooseWeightedChild(const std::vector& weights) const return result; } -void HilbertRTree::_createLeafNodes(const std::vector& hilbertBoxes, - std::vector& result) +void HilbertRTree::_createLeafNodes(const std::vector& hilbertBoxes, std::vector& result) { - //std::cout << " Creating leaf nodes..." << std::endl; - int maxChildCount = getRoot()->getMaxChildCount(); - //std::cout << "maxChildCount: " << maxChildCount << std::endl; result.reserve((int)ceil((float)hilbertBoxes.size() / (float)maxChildCount)); RTreeNode* node = _getRoot(); - //std::cout << "node == 0: " << (node == 0) << std::endl; - //std::cout << "node id: " << node->getId() << std::endl; - //std::cout << "node child count: " << node->getChildCount() << std::endl; result.push_back(node->getId()); - //int numProcessed = 0; - - for (unsigned int i = 0; i < hilbertBoxes.size(); i++) + for (const auto& hBox : hilbertBoxes) { if (node->getChildCount() == maxChildCount) { node = _store.createNode(); - //std::cout << "node == 0: " << (node == 0) << std::endl; - //std::cout << "node id: " << node->getId() << std::endl; result.push_back(node->getId()); } - node->addUserChild(*hilbertBoxes[i].box, hilbertBoxes[i].fid); - -// numProcessed++; -// if (numProcessed % 100000 == 0) -// { -// std::cout << " Created " << numProcessed << " of " << -// hilbertBoxes.size() << " leaf nodes." << std::endl; -// } + node->addUserChild(*hBox.box, hBox.fid); } } -void HilbertRTree::_createParentNodes(const std::vector& childNodes, - std::vector& result) +void HilbertRTree::_createParentNodes(const std::vector& childNodes, std::vector& result) { int maxChildCount = getRoot()->getMaxChildCount(); - //std::cout << "maxChildCount: " << maxChildCount << std::endl; result.reserve((int)ceil((float)childNodes.size() / (float)maxChildCount)); RTreeNode* node = _store.createNode(); - //std::cout << "node == 0: " << (node == 0) << std::endl; - //std::cout << "node id: " << node->getId() << std::endl; - //std::cout << "node child count: " << node->getChildCount() << std::endl; result.push_back(node->getId()); - //int numProcessed = 0; - - for (unsigned int i = 0; i < childNodes.size(); i++) + for (const auto& child : childNodes) { if (node->getChildCount() == maxChildCount) { node = _store.createNode(); -// std::cout << "node == 0: " << (node == 0) << std::endl; -// std::cout << "node id: " << node->getId() << std::endl; result.push_back(node->getId()); } - node->addNodeChild(_getNode(childNodes[i])); - -// numProcessed++; -// if (numProcessed % 1000 == 0) -// { -// std::cout << " Created " << -// numProcessed << " of " << childNodes.size() << " parent nodes." << std::endl; -// } + node->addNodeChild(_getNode(child)); } } void HilbertRTree::greedyShuffle() { _shuffleSize = _getRoot()->getMaxChildCount(); -// double startingOverlap = _calculateOverlap(_getRootId()); for (int i = 0; i < 10; i++) - { _greedyShuffle(_getRootId()); - } } void HilbertRTree::_greedyShuffle(int parentId) @@ -292,9 +232,7 @@ void HilbertRTree::_greedyShuffle(int parentId) const RTreeNode* parent = _getNode(parentId); // if we're a leaf, no shuffling is possible, return the overlap if (parent->isLeafNode()) - { return; - } // calculate the overlaps for each child, this tells us which ones need more balancing. std::vector overlaps; @@ -316,9 +254,7 @@ void HilbertRTree::_greedyShuffle(int parentId) { // randomly choose child based on overlap weight for (int i = 0; i < _shuffleSize; i++) - { _swapGrandChildNodes(parentId, overlaps); - } } } @@ -331,8 +267,8 @@ class BoxHolder BoxHolder(const BoxHolder&) = default; - BoxHolder(const HilbertRTree::BoxPair& bp, int hv) : - boxPair(bp) + BoxHolder(const HilbertRTree::BoxPair& bp, int hv) + : boxPair(bp) { hilbertValue = hv; } @@ -356,15 +292,12 @@ class BoxHolder int HilbertRTree::_splitBoxes(BoxVector& boxes) { Box bounds(_dimensions); - for (unsigned int i = 0; i < boxes.size(); i++) - { - bounds.expand(boxes[i].box); - } + for (const auto& b : boxes) + bounds.expand(b.box); + double boundsWidth[Box::MAX_DIMENSIONS] = { 0.0 }; for (int i = 0; i < bounds.getDimensions(); i++) - { boundsWidth[i] = bounds.getUpperBoundRaw(i) - bounds.getLowerBoundRaw(i); - } std::vector hilbertBoxes; int point[Box::MAX_DIMENSIONS]; @@ -376,16 +309,11 @@ int HilbertRTree::_splitBoxes(BoxVector& boxes) { double v = (box.getLowerBoundRaw(j) + box.getUpperBoundRaw(j)) / 2.0; if (boundsWidth[j] == 0) - { point[j] = 0; - } else - { point[j] = int(((1 << ORDER) - 1) * ((v - bounds.getLowerBoundRaw(j)) / boundsWidth[j])); - } assert(point[j] >= 0 && point[j] < (1 << ORDER)); } - hilbertBoxes.emplace_back(boxes[i], _hilbertCurve->encode(point)); } //sort(hilbertBoxes.begin(), hilbertBoxes.end()); @@ -406,9 +334,7 @@ int HilbertRTree::_splitBoxes(BoxVector& boxes) } while (swap); for (unsigned int i = 0; i < boxes.size(); i++) - { boxes[i] = hilbertBoxes[i].boxPair; - } return _chooseSplitIndex(boxes); } @@ -416,10 +342,9 @@ int HilbertRTree::_splitBoxes(BoxVector& boxes) double HilbertRTree::_sum(const std::vector& v) const { double result = 0.0; - for (unsigned int i = 0; i < v.size(); i++) - { - result += v[i]; - } + for (auto value : v) + result += value; + return result; } @@ -431,9 +356,7 @@ double HilbertRTree::_swapGrandChildNodes(int parentId, const std::vectorgetChildEnvelope(otherGrandChildOffset).toBox(); if (otherChildId == childId) - { return 0.0; - } double startOverlap = _calculatePairwiseOverlap(parentId, tmp) + _calculatePairwiseOverlap(childId, tmp) + _calculatePairwiseOverlap(otherChildId, tmp); - -// std::cout << "Swapping(" << parentId << ") " << childId << ":" << childIndex << " " << -// otherChildId << ":" << otherChildIndex << std::endl; - double startVolume = child->calculateEnvelope().calculateVolume() + otherChild->calculateEnvelope().calculateVolume(); -// double startPerimeter = child->calculateEnvelope().calculatePerimeter() + -// otherChild->calculateEnvelope().calculatePerimeter(); // swap the children. otherChild->updateChild(otherGrandChildOffset, child->getChildId(grandChildOffset), - child->getChildEnvelope(grandChildOffset).toBox()); + child->getChildEnvelope(grandChildOffset).toBox()); if (otherChild->isLeafNode() == false) { RTreeNode* otherGrandChild = _getNode(otherChild->getChildNodeId(otherGrandChildOffset)); -// std::cout << "Parent1 " << otherGrandChild->getParentId() << std::endl; otherGrandChild->setParentId(otherChildId); -// std::cout << "Parent1 " << otherGrandChild->getParentId() << std::endl; } child->updateChild(grandChildOffset, otherGrandChildId, otherGrandChildBox); if (child->isLeafNode() == false) { RTreeNode* grandChild = _getNode(child->getChildNodeId(grandChildOffset)); -// std::cout << "Parent2 " << grandChild->getParentId() << std::endl; grandChild->setParentId(childId); -// std::cout << "Parent2 " << grandChild->getParentId() << std::endl; } _updateBounds(child); _updateBounds(otherChild); double endVolume = child->calculateEnvelope().calculateVolume() + otherChild->calculateEnvelope().calculateVolume(); -// double endPerimeter = child->calculateEnvelope().calculatePerimeter() + -// otherChild->calculateEnvelope().calculatePerimeter(); - double endOverlap = _calculatePairwiseOverlap(parentId, tmp) + _calculatePairwiseOverlap(childId, tmp) + _calculatePairwiseOverlap(otherChildId, tmp); double result; - //std::cout << startOverlap << " " << endOverlap << "\t"; -// if (startOverlap * startPerimeter * startVolume > -// endOverlap * endPerimeter * endVolume) if (startVolume > endVolume) - { result = startOverlap - endOverlap; - //std::cout << "."; - } else { // swap the children back. child->updateChild(grandChildOffset, otherChild->getChildId(otherGrandChildOffset), - otherChild->getChildEnvelope(otherGrandChildOffset).toBox()); + otherChild->getChildEnvelope(otherGrandChildOffset).toBox()); if (child->isLeafNode() == false) { RTreeNode* grandChild = _getNode(child->getChildNodeId(grandChildOffset)); -// std::cout << " Parent1 " << grandChild->getParentId() << std::endl; assert(grandChild->getParentId() == otherChildId); -// std::cout << childId << std::endl; grandChild->setParentId(childId); -// std::cout << " Parent1 " << grandChild->getParentId() << std::endl; } otherChild->updateChild(otherGrandChildOffset, otherGrandChildId, otherGrandChildBox); if (child->isLeafNode() == false) { RTreeNode* otherGrandChild = _getNode(otherChild->getChildNodeId(otherGrandChildOffset)); assert(otherGrandChild->getParentId() == childId); -// std::cout << " Parent2 " << otherGrandChild->getParentId() << std::endl; otherGrandChild->setParentId(otherChildId); -// std::cout << " Parent2 " << otherGrandChild->getParentId() << std::endl; } _updateBounds(child); diff --git a/tgs/src/main/cpp/tgs/RStarTree/HilbertRTree.h b/tgs/src/main/cpp/tgs/RStarTree/HilbertRTree.h index a2edc223c2..cff69b631e 100644 --- a/tgs/src/main/cpp/tgs/RStarTree/HilbertRTree.h +++ b/tgs/src/main/cpp/tgs/RStarTree/HilbertRTree.h @@ -63,10 +63,10 @@ namespace Tgs int fid; int hilbertValue; - UserBoxHolder(const Box& b, int f, int hv) : - box(&b), - fid(f), - hilbertValue(hv) + UserBoxHolder(const Box& b, int f, int hv) + : box(&b), + fid(f), + hilbertValue(hv) { } @@ -82,8 +82,8 @@ namespace Tgs int _splitBoxes(BoxVector& boxes) override; - void _calculateHilbertValues(const std::vector& boxes, - const std::vector& fids, std::vector& hilbertBoxes) const; + void _calculateHilbertValues(const std::vector& boxes, const std::vector& fids, + std::vector& hilbertBoxes) const; double _calculateArea(int parentId); double _calculateOverlap(int parentId); double _calculatePairwiseOverlap(int parentId, std::vector& overlaps); @@ -94,10 +94,10 @@ namespace Tgs */ int _chooseWeightedChild(const std::vector& weights) const; - void _createLeafNodes(const std::vector& hilbertBoxes, - std::vector& result); - void _createParentNodes(const std::vector& childNodes, - std::vector& result); + void _createLeafNodes(const std::vector& hilbertBoxes, + std::vector& result); + void _createParentNodes(const std::vector& childNodes, + std::vector& result); /** * Greedily and randomly shuffles features for the better @@ -113,5 +113,4 @@ namespace Tgs using ConstHilbertRTreePtr = std::shared_ptr; } - #endif diff --git a/tgs/src/main/cpp/tgs/RandomForest/BaseRandomForestManager.cpp b/tgs/src/main/cpp/tgs/RandomForest/BaseRandomForestManager.cpp index 1a6798c915..cfd6bc4431 100644 --- a/tgs/src/main/cpp/tgs/RandomForest/BaseRandomForestManager.cpp +++ b/tgs/src/main/cpp/tgs/RandomForest/BaseRandomForestManager.cpp @@ -939,7 +939,7 @@ void BaseRandomForestManager::_trainRoundRobin(unsigned int numTrees, unsigned i { std::set classNames = _data->getClassLabels(); - unsigned int numClasses = _data->getClassLabels().size(); + size_t numClasses = _data->getClassLabels().size(); //Create one forest per class label _rfList.resize(numClasses * (numClasses - 1) / 2); diff --git a/tgs/src/main/cpp/tgs/RandomForest/InfoGainCalculator.cpp b/tgs/src/main/cpp/tgs/RandomForest/InfoGainCalculator.cpp index 6b644f3f13..0cff073835 100644 --- a/tgs/src/main/cpp/tgs/RandomForest/InfoGainCalculator.cpp +++ b/tgs/src/main/cpp/tgs/RandomForest/InfoGainCalculator.cpp @@ -38,6 +38,7 @@ namespace Tgs { + double InfoGainCalculator::_calcLogFunc(double n) const { if (n < std::numeric_limits::epsilon()) @@ -105,7 +106,6 @@ bool InfoGainCalculator::findDataSplit(const DataFrame& df, std::vector maxGr) { maxGr = infoGain[j]; //Get the max info gain ratio @@ -176,7 +176,7 @@ double InfoGainCalculator::getMaxInfoGainByFactor(const DataFrame& df, std::vect tmpIndices[0] = indices[i]; df.getClassPopulations(tmpIndices, popMap); - int tmpSize = indices.size() - i; + size_t tmpSize = indices.size() - i; entSum = 0.0; for (auto itr = popMap.begin(); itr != popMap.end(); ++itr) entSum += _calcLogFunc((double)itr->second / (double)tmpSize); @@ -255,10 +255,6 @@ double InfoGainCalculator::getMaxInfoGainRatioByFactor(const DataFrame& df, std: double gainRatio = infoGain / splitInfo; - //std::cout << " InfoGain1 " << infoGain << std::endl; - //std::cout << "left " << leftEnt << " right " << rightEnt << " split " << splitEnt << std::endl; - //std::cout << "leftSize " << leftSplit.size() << " rightSize " << rightSplit.size() << std::endl; - if (gainRatio > maxGr) { maxGr = gainRatio; diff --git a/tgs/src/main/cpp/tgs/RandomForest/MultithreadedRandomForest.cpp b/tgs/src/main/cpp/tgs/RandomForest/MultithreadedRandomForest.cpp index ad750b2136..35c71cdce0 100644 --- a/tgs/src/main/cpp/tgs/RandomForest/MultithreadedRandomForest.cpp +++ b/tgs/src/main/cpp/tgs/RandomForest/MultithreadedRandomForest.cpp @@ -83,7 +83,7 @@ void MultithreadedRandomForest::trainMulticlass(const std::shared_ptr _factorLabels = data->getFactorLabels(); _forest.clear(); - numFactors = std::min(data->getActiveFactorCount(), numFactors); + numFactors = std::min(static_cast(data->getActiveFactorCount()), numFactors); _numSplitFactors = numFactors; if (!data->empty()) @@ -112,7 +112,7 @@ void MultithreadedRandomForest::trainMulticlass(const std::shared_ptr std::vector badFactors; - unsigned int cutOffIdx = topFactors.size() - (unsigned int)((double)topFactors.size() * retrain); + unsigned int cutOffIdx = static_cast(topFactors.size() - (unsigned int)((double)topFactors.size() * retrain)); //Create a map from lowest to highest of important mapped to factor type std::multimap sortedFactors; diff --git a/tgs/src/main/cpp/tgs/Statistics/Random.h b/tgs/src/main/cpp/tgs/Statistics/Random.h index 2b4a5aee26..ae51c7c487 100644 --- a/tgs/src/main/cpp/tgs/Statistics/Random.h +++ b/tgs/src/main/cpp/tgs/Statistics/Random.h @@ -71,8 +71,8 @@ namespace Tgs { for (unsigned int i = 0; i < v.size() * 2; i++) std::swap( - v[Random::instance()->generateInt(v.size())], - v[Random::instance()->generateInt(v.size())]); + v[Random::instance()->generateInt(static_cast(v.size()))], + v[Random::instance()->generateInt(static_cast(v.size()))]); } private: From 1790df2c70b442cccd88527af74b91e0578611ef Mon Sep 17 00:00:00 2001 From: Ben Marchant <13385275+bmarchant@users.noreply.github.com> Date: Wed, 7 Dec 2022 14:27:20 -0600 Subject: [PATCH 2/2] Some averages in the stats weren't being calculated correctly (integer division), fixed that. Also sonar fixes. --- .../optimizer/IntegerProgrammingSolver.cpp | 4 +- .../optimizer/IntegerProgrammingSolver.h | 2 +- .../algorithms/splitter/LargeWaySplitter.cpp | 2 +- .../core/algorithms/splitter/WaySplitter.cpp | 28 ++-- .../core/algorithms/splitter/WaySplitter.h | 6 +- .../cpp/hoot/core/algorithms/zindex/LongBox.h | 2 +- .../hoot/core/geometry/GeometryPainter.cpp | 2 +- .../cpp/hoot/core/info/NumericStatistic.h | 2 +- .../core/io/schema/IntegerFieldDefinition.h | 2 +- .../core/visitors/BuildingHeightVisitor.h | 6 +- .../core/visitors/BuildingLevelsVisitor.h | 2 +- .../core/visitors/CountUniqueReviewsVisitor.h | 2 +- .../cpp/tgs/Interpolation/IdwInterpolator.cpp | 36 ++--- .../KernelEstimationInterpolator.cpp | 44 ++---- tgs/src/main/cpp/tgs/RStarTree/HilbertRTree.h | 2 +- tgs/src/main/cpp/tgs/Statistics/Random.cpp | 125 ++++++++++-------- tgs/src/main/cpp/tgs/Statistics/Random.h | 14 +- 17 files changed, 117 insertions(+), 164 deletions(-) diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/optimizer/IntegerProgrammingSolver.cpp b/hoot-core/src/main/cpp/hoot/core/algorithms/optimizer/IntegerProgrammingSolver.cpp index 04ae4e117d..ac15fa7003 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/optimizer/IntegerProgrammingSolver.cpp +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/optimizer/IntegerProgrammingSolver.cpp @@ -32,9 +32,9 @@ namespace hoot { IntegerProgrammingSolver::IntegerProgrammingSolver() + : _lp(glp_create_prob()), + _timeLimit(-1) { - _lp = glp_create_prob(); - _timeLimit = -1; } IntegerProgrammingSolver::~IntegerProgrammingSolver() diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/optimizer/IntegerProgrammingSolver.h b/hoot-core/src/main/cpp/hoot/core/algorithms/optimizer/IntegerProgrammingSolver.h index 92b39064af..7f927a9142 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/optimizer/IntegerProgrammingSolver.h +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/optimizer/IntegerProgrammingSolver.h @@ -22,7 +22,7 @@ * This will properly maintain the copyright information. Maxar * copyrights will be updated automatically. * - * @copyright Copyright (C) 2015, 2017, 2019, 2020, 2021 Maxar (http://www.maxar.com/) + * @copyright Copyright (C) 2015, 2017, 2019, 2020, 2021, 2022 Maxar (http://www.maxar.com/) */ #ifndef INTEGERPROGRAMMINGSOLVER_H #define INTEGERPROGRAMMINGSOLVER_H diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/splitter/LargeWaySplitter.cpp b/hoot-core/src/main/cpp/hoot/core/algorithms/splitter/LargeWaySplitter.cpp index b7cfc82206..f5399f4fdf 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/splitter/LargeWaySplitter.cpp +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/splitter/LargeWaySplitter.cpp @@ -49,8 +49,8 @@ namespace hoot int LargeWaySplitter::logWarnCount = 0; LargeWaySplitter::LargeWaySplitter(double threshold) + : _threshold(threshold) { - _threshold = threshold; } void LargeWaySplitter::apply(const std::shared_ptr& map) diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/splitter/WaySplitter.cpp b/hoot-core/src/main/cpp/hoot/core/algorithms/splitter/WaySplitter.cpp index e5e3aabc70..300bae1c67 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/splitter/WaySplitter.cpp +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/splitter/WaySplitter.cpp @@ -22,7 +22,7 @@ * This will properly maintain the copyright information. Maxar * copyrights will be updated automatically. * - * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020, 2021 Maxar (http://www.maxar.com/) + * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Maxar (http://www.maxar.com/) */ #include "WaySplitter.h" @@ -31,14 +31,14 @@ #include // Hoot -#include +#include #include #include +#include #include -#include -#include #include -#include +#include +#include using namespace geos::geom; using namespace std; @@ -46,10 +46,10 @@ using namespace std; namespace hoot { -WaySplitter::WaySplitter(const OsmMapPtr& map, WayPtr way) : -_map(map), -_way(way), -_nf(std::make_shared(_way)) +WaySplitter::WaySplitter(const OsmMapPtr& map, WayPtr way) + : _map(map), + _way(way), + _nf(std::make_shared(_way)) { } @@ -70,9 +70,7 @@ vector WaySplitter::createSplits(const vector& wl) const result[i] = WaySubline(last, curr).toWay(_map, _nf); result[i]->setPid(_way->getId()); if (result[i]->getNodeCount() == 0) - { result[i].reset(); - } } last = curr; } @@ -105,10 +103,8 @@ void WaySplitter::split(const OsmMapPtr& map, const WayPtr& w, double maxSize) WayLocation wl (map, w, l / 2.0); vector children = WaySplitter(map, w).split(wl); - for (size_t i = 0; i < children.size(); i++) - { - split(map, children[i], maxSize); - } + for (const auto& child : children) + split(map, child, maxSize); } } @@ -117,9 +113,7 @@ vector WaySplitter::split(const WayLocation& splitPoint) const vector result; if (splitPoint.isFirst() || splitPoint.isLast()) - { result.push_back(_way); - } else { WayLocation first(_map, _way, 0, 0.0); diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/splitter/WaySplitter.h b/hoot-core/src/main/cpp/hoot/core/algorithms/splitter/WaySplitter.h index b0e4958b6b..edca18a32e 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/splitter/WaySplitter.h +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/splitter/WaySplitter.h @@ -22,23 +22,23 @@ * This will properly maintain the copyright information. Maxar * copyrights will be updated automatically. * - * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2021 Maxar (http://www.maxar.com/) + * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2021, 2022 Maxar (http://www.maxar.com/) */ #ifndef WAYSPLITTER_H #define WAYSPLITTER_H // Hoot -#include #include #include +#include namespace hoot { -class WaySubline; class FindNodesInWayFactory; class WayLocation; +class WaySubline; /** * @brief The WaySplitter class splits ways. diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/zindex/LongBox.h b/hoot-core/src/main/cpp/hoot/core/algorithms/zindex/LongBox.h index c68937e05c..91cd78e4e2 100644 --- a/hoot-core/src/main/cpp/hoot/core/algorithms/zindex/LongBox.h +++ b/hoot-core/src/main/cpp/hoot/core/algorithms/zindex/LongBox.h @@ -22,7 +22,7 @@ * This will properly maintain the copyright information. Maxar * copyrights will be updated automatically. * - * @copyright Copyright (C) 2016, 2017, 2018, 2019, 2021 Maxar (http://www.maxar.com/) + * @copyright Copyright (C) 2016, 2017, 2018, 2019, 2021, 2022 Maxar (http://www.maxar.com/) */ #ifndef LONGBOX_H #define LONGBOX_H diff --git a/hoot-core/src/main/cpp/hoot/core/geometry/GeometryPainter.cpp b/hoot-core/src/main/cpp/hoot/core/geometry/GeometryPainter.cpp index 7690182fac..c865fc3d09 100644 --- a/hoot-core/src/main/cpp/hoot/core/geometry/GeometryPainter.cpp +++ b/hoot-core/src/main/cpp/hoot/core/geometry/GeometryPainter.cpp @@ -22,7 +22,7 @@ * This will properly maintain the copyright information. Maxar * copyrights will be updated automatically. * - * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020, 2021 Maxar (http://www.maxar.com/) + * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Maxar (http://www.maxar.com/) */ #include "GeometryPainter.h" diff --git a/hoot-core/src/main/cpp/hoot/core/info/NumericStatistic.h b/hoot-core/src/main/cpp/hoot/core/info/NumericStatistic.h index 3e10feb04f..f84c40b020 100644 --- a/hoot-core/src/main/cpp/hoot/core/info/NumericStatistic.h +++ b/hoot-core/src/main/cpp/hoot/core/info/NumericStatistic.h @@ -22,7 +22,7 @@ * This will properly maintain the copyright information. Maxar * copyrights will be updated automatically. * - * @copyright Copyright (C) 2015, 2018, 2019, 2020, 2021 Maxar (http://www.maxar.com/) + * @copyright Copyright (C) 2015, 2018, 2019, 2020, 2021, 2022 Maxar (http://www.maxar.com/) */ #ifndef NUMERIC_STATISTIC_H #define NUMERIC_STATISTIC_H diff --git a/hoot-core/src/main/cpp/hoot/core/io/schema/IntegerFieldDefinition.h b/hoot-core/src/main/cpp/hoot/core/io/schema/IntegerFieldDefinition.h index 83b2edee71..1e3d325b6c 100644 --- a/hoot-core/src/main/cpp/hoot/core/io/schema/IntegerFieldDefinition.h +++ b/hoot-core/src/main/cpp/hoot/core/io/schema/IntegerFieldDefinition.h @@ -22,7 +22,7 @@ * This will properly maintain the copyright information. Maxar * copyrights will be updated automatically. * - * @copyright Copyright (C) 2015, 2017, 2018, 2020, 2021 Maxar (http://www.maxar.com/) + * @copyright Copyright (C) 2015, 2017, 2018, 2020, 2021, 2022 Maxar (http://www.maxar.com/) */ #ifndef INTEGERFIELDDEFINITION_H #define INTEGERFIELDDEFINITION_H diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/BuildingHeightVisitor.h b/hoot-core/src/main/cpp/hoot/core/visitors/BuildingHeightVisitor.h index aeb99db09a..b46bf4eea7 100644 --- a/hoot-core/src/main/cpp/hoot/core/visitors/BuildingHeightVisitor.h +++ b/hoot-core/src/main/cpp/hoot/core/visitors/BuildingHeightVisitor.h @@ -22,16 +22,16 @@ * This will properly maintain the copyright information. Maxar * copyrights will be updated automatically. * - * @copyright Copyright (C) 2019, 2020, 2021 Maxar (http://www.maxar.com/) + * @copyright Copyright (C) 2019, 2020, 2021, 2022 Maxar (http://www.maxar.com/) */ #ifndef BUILDING_HEIGHT_VISITOR_H #define BUILDING_HEIGHT_VISITOR_H // hoot -#include -#include #include +#include +#include // Qt #include diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/BuildingLevelsVisitor.h b/hoot-core/src/main/cpp/hoot/core/visitors/BuildingLevelsVisitor.h index dcf90d6c25..74735ced76 100644 --- a/hoot-core/src/main/cpp/hoot/core/visitors/BuildingLevelsVisitor.h +++ b/hoot-core/src/main/cpp/hoot/core/visitors/BuildingLevelsVisitor.h @@ -22,7 +22,7 @@ * This will properly maintain the copyright information. Maxar * copyrights will be updated automatically. * - * @copyright Copyright (C) 2019, 2020, 2021 Maxar (http://www.maxar.com/) + * @copyright Copyright (C) 2019, 2020, 2021, 2022 Maxar (http://www.maxar.com/) */ #ifndef BUILDING_LEVELS_VISITOR_H diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/CountUniqueReviewsVisitor.h b/hoot-core/src/main/cpp/hoot/core/visitors/CountUniqueReviewsVisitor.h index 3217842744..38d4d25a49 100644 --- a/hoot-core/src/main/cpp/hoot/core/visitors/CountUniqueReviewsVisitor.h +++ b/hoot-core/src/main/cpp/hoot/core/visitors/CountUniqueReviewsVisitor.h @@ -22,7 +22,7 @@ * This will properly maintain the copyright information. Maxar * copyrights will be updated automatically. * - * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020, 2021 Maxar (http://www.maxar.com/) + * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Maxar (http://www.maxar.com/) */ #ifndef COUNTUNIQUEREVIEWSVISITOR_H #define COUNTUNIQUEREVIEWSVISITOR_H diff --git a/tgs/src/main/cpp/tgs/Interpolation/IdwInterpolator.cpp b/tgs/src/main/cpp/tgs/Interpolation/IdwInterpolator.cpp index 6f51529a80..1c1a968dfc 100644 --- a/tgs/src/main/cpp/tgs/Interpolation/IdwInterpolator.cpp +++ b/tgs/src/main/cpp/tgs/Interpolation/IdwInterpolator.cpp @@ -22,7 +22,7 @@ * This will properly maintain the copyright information. Maxar * copyrights will be updated automatically. * - * @copyright Copyright (C) 2015, 2019, 2021 Maxar (http://www.maxar.com/) + * @copyright Copyright (C) 2015, 2019, 2021, 2022 Maxar (http://www.maxar.com/) */ #include "IdwInterpolator.h" @@ -46,9 +46,9 @@ namespace Tgs using namespace std; IdwInterpolator::IdwInterpolator(double p) + : _p(p), + _stopDelta(0.1) { - _p = p; - _stopDelta = 0.1; } class IdwOptimizeFunction : public NelderMead::Function @@ -60,8 +60,7 @@ class IdwOptimizeFunction : public NelderMead::Function double f(Vector v) override { // a value less than zero isn't meaningful. - double p = std::max(0.0, v[0]); - _idw.setP(p); + _idw.setP(std::max(0.0, v[0])); return -_idw.estimateError(); } @@ -98,9 +97,7 @@ void IdwInterpolator::_buildModel() _p = result[0]; } if (iterations > _iterations) - { _iterations = iterations; - } } } @@ -138,15 +135,11 @@ const vector& IdwInterpolator::_interpolate(const vector& point, _result.resize(_depColumns.size()); for (size_t i = 0; i < _result.size(); i++) - { _result[i] = 0.0; - } vector simplePoint(_indColumns.size()); for (size_t i = 0; i < _indColumns.size(); i++) - { simplePoint[i] = point[_indColumns[i]]; - } KnnIteratorNd it(_getIndex(), simplePoint); double wSum = 0.0; @@ -154,18 +147,17 @@ const vector& IdwInterpolator::_interpolate(const vector& point, int iterations = 0; while (it.next() && samples < 50 && iterations <= _maxAllowedPerLoopOptimizationIterations) { - size_t i = it.getId(); - if ((int)i == ignoreId) - { + int i = it.getId(); + if (i == ignoreId) continue; - } + const vector& record = df.getDataVector(static_cast(i)); // figure out the distance between point and this data vector double d = 0; - for (size_t j = 0; j < _indColumns.size(); j++) + for (auto col : _indColumns) { - double v = point[_indColumns[j]] - record[_indColumns[j]]; + double v = point[col] - record[col]; d += v * v; } d = sqrt(d); @@ -176,9 +168,7 @@ const vector& IdwInterpolator::_interpolate(const vector& point, // Set the contribution equal to this value. for (size_t j = 0; j < _result.size(); j++) - { _result[j] += record[_depColumns[j]]; - } break; } @@ -188,21 +178,15 @@ const vector& IdwInterpolator::_interpolate(const vector& point, // calculate the contribution to the predicted value. for (size_t j = 0; j < _result.size(); j++) - { _result[j] += (record[_depColumns[j]] * w); - } iterations++; } if (iterations > _iterations) - { _iterations = iterations; - } for (size_t j = 0; j < _result.size(); j++) - { _result[j] /= wSum; - } return _result; } @@ -215,9 +199,7 @@ void IdwInterpolator::_readInterpolator(QIODevice& is) ds >> version; if (version != 0x0) - { throw Exception("Unexpected version."); - } ds >> _p; ds >> _stopDelta; diff --git a/tgs/src/main/cpp/tgs/Interpolation/KernelEstimationInterpolator.cpp b/tgs/src/main/cpp/tgs/Interpolation/KernelEstimationInterpolator.cpp index e238c08e88..322c0afcc3 100644 --- a/tgs/src/main/cpp/tgs/Interpolation/KernelEstimationInterpolator.cpp +++ b/tgs/src/main/cpp/tgs/Interpolation/KernelEstimationInterpolator.cpp @@ -22,7 +22,7 @@ * This will properly maintain the copyright information. Maxar * copyrights will be updated automatically. * - * @copyright Copyright (C) 2015, 2019, 2021 Maxar (http://www.maxar.com/) + * @copyright Copyright (C) 2015, 2019, 2021, 2022 Maxar (http://www.maxar.com/) */ #include "KernelEstimationInterpolator.h" @@ -46,9 +46,9 @@ namespace Tgs using namespace std; KernelEstimationInterpolator::KernelEstimationInterpolator(double sigma) + : _sigma(sigma), + _stopDelta(1.0) { - _sigma = sigma; - _stopDelta = 1.0; } class OptimizeFunction : public NelderMead::Function @@ -59,8 +59,7 @@ class OptimizeFunction : public NelderMead::Function double f(Vector v) override { - double s = std::max(0.1, v[0]); - _kei.setSigma(s); + _kei.setSigma(std::max(0.1, v[0])); return -_kei.estimateError(); } @@ -80,10 +79,7 @@ void KernelEstimationInterpolator::_buildModel() double mean = 0; unsigned int n = df.getNumDataVectors(); for (unsigned int i = 0; i < n; ++i) - { - double v = df.getDataVector(i)[_indColumns[0]]; - mean += v; - } + mean += df.getDataVector(i)[_indColumns[0]]; mean /= df.getNumDataVectors(); double sumDiff = 0; @@ -122,9 +118,7 @@ void KernelEstimationInterpolator::_buildModel() _sigma = result[0]; } if (iterations > _iterations) - { _iterations = iterations; - } } } @@ -136,9 +130,7 @@ double KernelEstimationInterpolator::_estimateError(unsigned int index) const const vector& uut = df.getDataVector(index); vector simplePoint(_indColumns.size()); for (size_t i = 0; i < _indColumns.size(); i++) - { simplePoint[i] = uut[_indColumns[i]]; - } double n0 = Normal::normal(0, _sigma); @@ -150,16 +142,14 @@ double KernelEstimationInterpolator::_estimateError(unsigned int index) const { unsigned int i = it.getId(); if (i == index) - { continue; - } const vector& record = df.getDataVector(i); // figure out the distance between point and this data vector double d = 0; - for (size_t j = 0; j < _indColumns.size(); j++) + for (auto col : _indColumns) { - double v = uut[_indColumns[j]] - record[_indColumns[j]]; + double v = uut[col] - record[col]; d += v * v; } d = sqrt(d); @@ -173,9 +163,7 @@ double KernelEstimationInterpolator::_estimateError(unsigned int index) const // calculate the contribution to the predicted value. for (size_t j = 0; j < predicted.size(); j++) - { predicted[j] += (record[_depColumns[j]] * w); - } } iterations++; @@ -186,15 +174,11 @@ double KernelEstimationInterpolator::_estimateError(unsigned int index) const double result = 0.0; for (size_t j = 0; j < predicted.size(); j++) { - //cout << "uut[_depColumns[" << j << "]] " << uut[_depColumns[j]] << endl; - //cout << "predicted[" << j << "] " << predicted[j] << endl; double diff = uut[_depColumns[j]] - (predicted[j] / wSum); result += diff * diff; } result = sqrt(result); - //cout << "wSum: " << wSum << " result: " << result << endl; - return result; } @@ -204,15 +188,11 @@ const vector& KernelEstimationInterpolator::interpolate(const vector simplePoint(_indColumns.size()); for (size_t i = 0; i < _indColumns.size(); i++) - { simplePoint[i] = point[_indColumns[i]]; - } double n0 = Normal::normal(0, _sigma); @@ -227,9 +207,9 @@ const vector& KernelEstimationInterpolator::interpolate(const vector& KernelEstimationInterpolator::interpolate(const vector& KernelEstimationInterpolator::interpolate(const vector> version; if (version != 0x0) - { throw Exception("Unexpected version."); - } ds >> _sigma; ds >> _stopDelta; diff --git a/tgs/src/main/cpp/tgs/RStarTree/HilbertRTree.h b/tgs/src/main/cpp/tgs/RStarTree/HilbertRTree.h index cff69b631e..2638dc2f3e 100644 --- a/tgs/src/main/cpp/tgs/RStarTree/HilbertRTree.h +++ b/tgs/src/main/cpp/tgs/RStarTree/HilbertRTree.h @@ -22,7 +22,7 @@ * This will properly maintain the copyright information. Maxar * copyrights will be updated automatically. * - * @copyright Copyright (C) 2015, 2017, 2018, 2019, 2021 Maxar (http://www.maxar.com/) + * @copyright Copyright (C) 2015, 2017, 2018, 2019, 2021, 2022 Maxar (http://www.maxar.com/) */ #ifndef __TGS__HILBERT_R_TREE_H__ diff --git a/tgs/src/main/cpp/tgs/Statistics/Random.cpp b/tgs/src/main/cpp/tgs/Statistics/Random.cpp index 5601ff5dc9..26cc5dc748 100644 --- a/tgs/src/main/cpp/tgs/Statistics/Random.cpp +++ b/tgs/src/main/cpp/tgs/Statistics/Random.cpp @@ -22,7 +22,7 @@ * This will properly maintain the copyright information. Maxar * copyrights will be updated automatically. * - * @copyright Copyright (C) 2015, 2016, 2019, 2020, 2021 Maxar (http://www.maxar.com/) + * @copyright Copyright (C) 2015, 2016, 2019, 2020, 2021, 2022 Maxar (http://www.maxar.com/) */ #include "Random.h" @@ -33,72 +33,81 @@ namespace Tgs { - std::shared_ptr Random::_instance; - Random::Random(unsigned int s) : - _is_single(false) - { - seed(s); - } +std::shared_ptr Random::_instance; - Random::Random() : - _is_single(true) - { - seed(0); - } +Random::Random(unsigned int s) + : _is_single(false) +{ + seed(s); +} - double Random::generateGaussian(double mean, double sigma) - { - double x, y, r2; - do - { - // choose x,y in uniform square (-1,-1) to (+1,+1) - x = -1 + 2 * generateUniform(); - y = -1 + 2 * generateUniform(); - // see if it is in the unit circle - r2 = x * x + y * y; - } - while (r2 > 1.0 || r2 == 0); - // Box-Muller transform - return mean + sigma * y * sqrt (-2.0 * log (r2) / r2); - } +Random::Random() + : _is_single(true) +{ + seed(0); +} - double Random::generateUniform() - { - return (double)generateInt() / (double)RAND_MAX; - } +std::shared_ptr Random::instance() +{ + if (!_instance) + _instance.reset(new Random()); + return _instance; +} - bool Random::coinToss() +double Random::generateGaussian(double mean, double sigma) +{ + double x, y, r2; + do { - return (generateInt() % 2) == 1; + // choose x,y in uniform square (-1,-1) to (+1,+1) + x = -1 + 2 * generateUniform(); + y = -1 + 2 * generateUniform(); + // see if it is in the unit circle + r2 = x * x + y * y; } + while (r2 > 1.0 || r2 == 0); + // Box-Muller transform + return mean + sigma * y * sqrt (-2.0 * log (r2) / r2); +} - int Random::generateInt(int max) - { - if (max <= 0) - return 0; - else - return generateInt() % max; - } +double Random::generateUniform() +{ + return static_cast(generateInt()) / static_cast(RAND_MAX); +} - int Random::generateInt() - { - if (_is_single) - return rand(); - else - return rand_r(&_seed); - } +bool Random::coinToss() +{ + return (generateInt() % 2) == 1; +} - void Random::seed(unsigned int s) - { - if (_is_single) - srand(s); - else - _seed = s; - } +int Random::generateInt(int max) +{ + if (max <= 0) + return 0; + else + return generateInt() % max; +} + +int Random::generateInt() +{ + if (_is_single) + return rand(); + else + return rand_r(&_seed); +} + +void Random::seed(unsigned int s) +{ + if (_is_single) + srand(s); + else + _seed = s; +} + +void Random::seed() +{ + seed(0); +} - void Random::seed() - { - seed(0); - } } diff --git a/tgs/src/main/cpp/tgs/Statistics/Random.h b/tgs/src/main/cpp/tgs/Statistics/Random.h index ae51c7c487..0dcc8fd075 100644 --- a/tgs/src/main/cpp/tgs/Statistics/Random.h +++ b/tgs/src/main/cpp/tgs/Statistics/Random.h @@ -22,7 +22,7 @@ * This will properly maintain the copyright information. Maxar * copyrights will be updated automatically. * - * @copyright Copyright (C) 2015, 2016, 2018, 2019, 2020, 2021 Maxar (http://www.maxar.com/) + * @copyright Copyright (C) 2015, 2016, 2018, 2019, 2020, 2021, 2022 Maxar (http://www.maxar.com/) */ #ifndef __TGS__RANDOM_H__ @@ -44,12 +44,7 @@ namespace Tgs Random(unsigned int seed); - static std::shared_ptr instance() - { - if (!_instance) - _instance.reset(new Random()); - return _instance; - } + static std::shared_ptr instance(); bool coinToss(); @@ -69,10 +64,9 @@ namespace Tgs template static void randomizeVector(std::vector<_T>& v) { + int s = static_cast(v.size()); for (unsigned int i = 0; i < v.size() * 2; i++) - std::swap( - v[Random::instance()->generateInt(static_cast(v.size()))], - v[Random::instance()->generateInt(static_cast(v.size()))]); + std::swap(v[Random::instance()->generateInt(s)], v[Random::instance()->generateInt(s)]); } private: