From 6e2c3ac2e1bee381d2008fbdcdf6a30b74344613 Mon Sep 17 00:00:00 2001 From: Petros Koutsolampros Date: Sat, 13 Jul 2024 18:24:16 +0300 Subject: [PATCH] Fix all-line map generation --- depthmapX/graphdoc.cpp | 16 ++-- depthmapX/mainwindow.cpp | 19 ++-- depthmapX/salaobj/metagraphdx.cpp | 147 +++++++++++++++++------------- depthmapX/salaobj/metagraphdx.h | 26 +++--- depthmapX/salaobj/shapemapdx.cpp | 4 +- depthmapX/salaobj/shapemapdx.h | 3 +- salalib | 2 +- 7 files changed, 118 insertions(+), 99 deletions(-) diff --git a/depthmapX/graphdoc.cpp b/depthmapX/graphdoc.cpp index 1673bc0..7952707 100644 --- a/depthmapX/graphdoc.cpp +++ b/depthmapX/graphdoc.cpp @@ -206,7 +206,7 @@ LayerManagerImpl &QGraphDoc::getLayers(int type, std::optional layer) { break; case MetaGraphDX::VIEWAXIAL: tab = (!layer.has_value()) ? &(m_meta_graph->getDisplayedShapeGraph().getLayers()) - : &(m_meta_graph->getShapeGraphs()[layer.value()]->getLayers()); + : &(m_meta_graph->getShapeGraphs()[layer.value()].getLayers()); break; case MetaGraphDX::VIEWDATA: tab = (!layer.has_value()) ? &(m_meta_graph->getDisplayedDataMap().getLayers()) // @@ -228,7 +228,7 @@ const LayerManagerImpl &QGraphDoc::getLayers(int type, std::optional lay break; case MetaGraphDX::VIEWAXIAL: tab = (!layer.has_value()) ? &(m_meta_graph->getDisplayedShapeGraph().getLayers()) - : &(m_meta_graph->getShapeGraphs()[layer.value()]->getLayers()); + : &(m_meta_graph->getShapeGraphs()[layer.value()].getLayers()); break; case MetaGraphDX::VIEWDATA: tab = (!layer.has_value()) ? &(m_meta_graph->getDisplayedDataMap().getLayers()) // @@ -252,7 +252,7 @@ AttributeTableHandle &QGraphDoc::getAttributeTableHandle(int type, std::optional case MetaGraphDX::VIEWAXIAL: tab = (!layer.has_value()) ? &(m_meta_graph->getDisplayedShapeGraph().getAttributeTableHandle()) - : &(m_meta_graph->getShapeGraphs()[layer.value()]->getAttributeTableHandle()); + : &(m_meta_graph->getShapeGraphs()[layer.value()].getAttributeTableHandle()); break; case MetaGraphDX::VIEWDATA: tab = (!layer.has_value()) @@ -278,7 +278,7 @@ const AttributeTableHandle &QGraphDoc::getAttributeTableHandle(int type, case MetaGraphDX::VIEWAXIAL: tab = (!layer.has_value()) ? &(m_meta_graph->getDisplayedShapeGraph().getAttributeTableHandle()) - : &(m_meta_graph->getShapeGraphs()[layer.value()]->getAttributeTableHandle()); + : &(m_meta_graph->getShapeGraphs()[layer.value()].getAttributeTableHandle()); break; case MetaGraphDX::VIEWDATA: tab = (!layer.has_value()) @@ -307,15 +307,15 @@ void QGraphDoc::OnLayerNew() { } else if (dlg.m_layer_type == 1) { int ref = m_meta_graph->addShapeGraph(dlg.m_name.toStdString(), ShapeMap::CONVEXMAP); m_meta_graph->setDisplayedShapeGraphRef(ref); - map = m_meta_graph->getShapeGraphs()[size_t(ref)].get(); + map = &m_meta_graph->getShapeGraphs()[size_t(ref)]; } else if (dlg.m_layer_type == 2) { int ref = m_meta_graph->addShapeGraph(dlg.m_name.toStdString(), ShapeMap::AXIALMAP); m_meta_graph->setDisplayedShapeGraphRef(ref); - map = m_meta_graph->getShapeGraphs()[size_t(ref)].get(); + map = &m_meta_graph->getShapeGraphs()[size_t(ref)]; } else if (dlg.m_layer_type == 3) { int ref = m_meta_graph->addShapeGraph(dlg.m_name.toStdString(), ShapeMap::PESHMAP); m_meta_graph->setDisplayedShapeGraphRef(ref); - map = m_meta_graph->getShapeGraphs()[size_t(ref)].get(); + map = &m_meta_graph->getShapeGraphs()[size_t(ref)]; } QtRegion r = m_meta_graph->getBoundingBox(); @@ -2243,7 +2243,7 @@ void QGraphDoc::OnPushToLayer() { i != m_meta_graph->getDisplayedShapeGraphRef()) { names.insert( std::make_pair(std::pair(MetaGraphDX::VIEWAXIAL, int(i)), - std::string("Shape Graphs: ") + shapegraphs[i]->getName())); + std::string("Shape Graphs: ") + shapegraphs[i].getName())); } } for (i = 0; i < m_meta_graph->getPointMaps().size(); i++) { diff --git a/depthmapX/mainwindow.cpp b/depthmapX/mainwindow.cpp index d1957d9..c64d822 100644 --- a/depthmapX/mainwindow.cpp +++ b/depthmapX/mainwindow.cpp @@ -1225,9 +1225,9 @@ void MainWindow::OnSelchangingTree(QTreeWidgetItem *hItem, int col) { } else if (entry.m_subcat == -1 && m_indexWidget->isEditableColumn(col)) { // hit editable box if (entry.m_type == 1) { - int type = graph->getShapeGraphs()[entry.m_cat]->getInternalMap().getMapType(); + int type = graph->getShapeGraphs()[entry.m_cat].getInternalMap().getMapType(); if (type != ShapeMap::SEGMENTMAP && type != ShapeMap::ALLLINEMAP) { - graph->getShapeGraphs()[entry.m_cat]->setEditable( + graph->getShapeGraphs()[entry.m_cat].setEditable( m_indexWidget->isItemSetEditable(hItem)); update = true; } @@ -1247,7 +1247,7 @@ void MainWindow::OnSelchangingTree(QTreeWidgetItem *hItem, int col) { // They've clicked on the displayed layers if (entry.m_type == 1) { update = true; - graph->getShapeGraphs()[entry.m_cat]->getInternalMap().setLayerVisible( + graph->getShapeGraphs()[entry.m_cat].getInternalMap().setLayerVisible( entry.m_subcat, m_indexWidget->isItemSetVisible(hItem)); } else if (entry.m_type == 2) { update = true; @@ -1347,11 +1347,11 @@ void MainWindow::SetGraphTreeChecks() { } break; case 1: { - int type = graph->getShapeGraphs()[entry.m_cat]->getInternalMap().getMapType(); + int type = graph->getShapeGraphs()[entry.m_cat].getInternalMap().getMapType(); if (type == ShapeMap::SEGMENTMAP || type == ShapeMap::ALLLINEMAP) { editable = MetaGraphDX::NOT_EDITABLE; } else { - editable = graph->getShapeGraphs()[entry.m_cat]->isEditable() + editable = graph->getShapeGraphs()[entry.m_cat].isEditable() ? MetaGraphDX::EDITABLE_ON : MetaGraphDX::EDITABLE_OFF; } @@ -1378,7 +1378,7 @@ void MainWindow::SetGraphTreeChecks() { // do not currently have layers supported bool show = false; if (entry.m_type == 1) { - show = graph->getShapeGraphs()[entry.m_cat]->getInternalMap().isLayerVisible( + show = graph->getShapeGraphs()[entry.m_cat].getInternalMap().isLayerVisible( entry.m_subcat); } else if (entry.m_type == 2) { show = graph->getDataMaps()[entry.m_cat].getInternalMap().isLayerVisible( @@ -1465,13 +1465,13 @@ void MainWindow::MakeGraphTree() { m_treeroots[1] = hItem; } for (size_t i = 0; i < m_treeDoc->m_meta_graph->getShapeGraphs().size(); i++) { - QString name = QString(m_treeDoc->m_meta_graph->getShapeGraphs()[i]->getName().c_str()); + QString name = QString(m_treeDoc->m_meta_graph->getShapeGraphs()[i].getName().c_str()); QTreeWidgetItem *hItem = m_indexWidget->addNewItem(name, m_treeroots[1]); m_indexWidget->setItemVisibility(hItem, Qt::Unchecked); m_indexWidget->setItemEditability(hItem, Qt::Unchecked); ItemTreeEntry entry(1, (short)i, -1); m_treegraphmap.insert(std::make_pair(hItem, entry)); - LayerManagerImpl &layers = m_treeDoc->m_meta_graph->getShapeGraphs()[i]->getLayers(); + LayerManagerImpl &layers = m_treeDoc->m_meta_graph->getShapeGraphs()[i].getLayers(); if (layers.getNumLayers() > 1) { for (int j = 0; j < layers.getNumLayers(); j++) { QString name = QString(layers.getLayerName(j).c_str()); @@ -2637,7 +2637,8 @@ void MainWindow::updateToolbar() { (m_p->m_meta_graph->getDisplayedPointMap().getFilledPointCount() > 1)) || (((m_p->m_meta_graph->getViewClass() & MetaGraphDX::VIEWAXIAL) && (m_p->m_meta_graph->getState() & MetaGraphDX::SHAPEGRAPHS)) && - (!m_p->m_meta_graph->getDisplayedShapeGraph().isSegmentMap())))) + (m_p->m_meta_graph->hasDisplayedShapeGraph() && + !m_p->m_meta_graph->getDisplayedShapeGraph().isSegmentMap())))) JoinToolButton->setEnabled(true); else { if (tmpView) { diff --git a/depthmapX/salaobj/metagraphdx.cpp b/depthmapX/salaobj/metagraphdx.cpp index b682bcc..9108f47 100644 --- a/depthmapX/salaobj/metagraphdx.cpp +++ b/depthmapX/salaobj/metagraphdx.cpp @@ -762,7 +762,7 @@ bool MetaGraphDX::makeBSPtree(BSPNodeTree &bspNodeTree, Communicator *communicat return m_bspNodeTree.built(); } -size_t MetaGraphDX::addShapeGraph(std::unique_ptr &&shapeGraph) { +size_t MetaGraphDX::addShapeGraph(ShapeGraphDX &&shapeGraph) { m_shapeGraphs.emplace_back(std::move(shapeGraph)); auto mapref = m_shapeGraphs.size() - 1; setDisplayedShapeGraphRef(mapref); @@ -771,24 +771,19 @@ size_t MetaGraphDX::addShapeGraph(std::unique_ptr &&shapeGraph) { return mapref; } -size_t MetaGraphDX::addShapeGraph(std::unique_ptr &&shapeGraph) { - return addShapeGraph(std::make_unique(std::move(shapeGraph))); -} - size_t MetaGraphDX::addShapeGraph(ShapeGraph &&shapeGraph) { - return addShapeGraph(std::make_unique(std::move(shapeGraph))); + return addShapeGraph(ShapeGraphDX(std::make_unique(std::move(shapeGraph)))); } size_t MetaGraphDX::addShapeGraph(const std::string &name, int type) { - auto mapref = - addShapeGraph(std::make_unique(std::make_unique(name, type))); + auto mapref = addShapeGraph(std::make_unique(name, type)); // add a couple of default columns: - AttributeTable &table = m_shapeGraphs[size_t(mapref)]->getInternalMap().getAttributeTable(); + AttributeTable &table = m_shapeGraphs[size_t(mapref)].getInternalMap().getAttributeTable(); auto connIdx = table.insertOrResetLockedColumn("Connectivity"); if ((type & ShapeMap::LINEMAP) != 0) { table.insertOrResetLockedColumn("Line Length"); } - m_shapeGraphs[mapref]->setDisplayedAttribute(static_cast(connIdx)); + m_shapeGraphs[mapref].setDisplayedAttribute(static_cast(connIdx)); return mapref; } size_t MetaGraphDX::addShapeMap(const std::string &name) { @@ -875,11 +870,15 @@ bool MetaGraphDX::convertDataToAxial(Communicator *comm, std::string layer_name, addShapeGraph(MapConverter::convertDataToAxial( comm, layer_name, getDisplayedDataMap().getInternalMap(), pushvalues)); - m_shapeGraphs.back()->overrideDisplayedAttribute(-2); // <- override if it's already showing - m_shapeGraphs.back()->setDisplayedAttribute( - m_shapeGraphs.back()->getAttributeTable().getColumnIndex("Connectivity")); + m_shapeGraphs.back().overrideDisplayedAttribute(-2); // <- override if it's already showing + m_shapeGraphs.back().setDisplayedAttribute( + m_shapeGraphs.back().getAttributeTable().getColumnIndex("Connectivity")); - setDisplayedShapeGraphRef(m_shapeGraphs.size() - 1); + int newIdx = m_shapeGraphs.size() - 1; + if (newIdx < 0) + unsetDisplayedShapeGraphRef(); + else + setDisplayedShapeGraphRef(newIdx); } catch (Communicator::CancelledException) { converted = false; } @@ -927,9 +926,14 @@ bool MetaGraphDX::convertToConvex(Communicator *comm, std::string layer_name, bo converted = true; } - m_shapeGraphs.back()->overrideDisplayedAttribute(-2); // <- override if it's already showing - m_shapeGraphs.back()->setDisplayedAttribute(-1); - setDisplayedShapeGraphRef(m_shapeGraphs.size() - 1); + m_shapeGraphs.back().overrideDisplayedAttribute(-2); // <- override if it's already showing + m_shapeGraphs.back().setDisplayedAttribute(-1); + + int newIdx = m_shapeGraphs.size() - 1; + if (newIdx < 0) + unsetDisplayedShapeGraphRef(); + else + setDisplayedShapeGraphRef(newIdx); } catch (Communicator::CancelledException) { converted = false; @@ -970,7 +974,11 @@ bool MetaGraphDX::convertDrawingToSegment(Communicator *comm, std::string layer_ addShapeGraph(MapConverter::convertDrawingToSegment(comm, layer_name, shownMapsInternal)); - setDisplayedShapeGraphRef(m_shapeGraphs.size() - 1); + int newIdx = m_shapeGraphs.size() - 1; + if (newIdx < 0) + unsetDisplayedShapeGraphRef(); + else + setDisplayedShapeGraphRef(newIdx); } catch (Communicator::CancelledException) { converted = false; } @@ -997,9 +1005,13 @@ bool MetaGraphDX::convertDataToSegment(Communicator *comm, std::string layer_nam addShapeGraph(MapConverter::convertDataToSegment( comm, layer_name, getDisplayedDataMap().getInternalMap(), pushvalues)); - m_shapeGraphs.back()->overrideDisplayedAttribute(-2); // <- override if it's already showing - m_shapeGraphs.back()->setDisplayedAttribute(-1); - setDisplayedShapeGraphRef(m_shapeGraphs.size() - 1); + m_shapeGraphs.back().overrideDisplayedAttribute(-2); // <- override if it's already showing + m_shapeGraphs.back().setDisplayedAttribute(-1); + int newIdx = m_shapeGraphs.size() - 1; + if (newIdx < 0) + unsetDisplayedShapeGraphRef(); + else + setDisplayedShapeGraphRef(newIdx); } catch (Communicator::CancelledException) { converted = false; } @@ -1186,11 +1198,15 @@ bool MetaGraphDX::convertAxialToSegment(Communicator *comm, std::string layer_na MapConverter::convertAxialToSegment(comm, getDisplayedShapeGraph().getInternalMap(), layer_name, keeporiginal, pushvalues, stubremoval)); - m_shapeGraphs.back()->overrideDisplayedAttribute(-2); // <- override if it's already showing - m_shapeGraphs.back()->setDisplayedAttribute( - m_shapeGraphs.back()->getAttributeTable().getColumnIndex("Connectivity")); + m_shapeGraphs.back().overrideDisplayedAttribute(-2); // <- override if it's already showing + m_shapeGraphs.back().setDisplayedAttribute( + m_shapeGraphs.back().getAttributeTable().getColumnIndex("Connectivity")); - setDisplayedShapeGraphRef(m_shapeGraphs.size() - 1); + int newIdx = m_shapeGraphs.size() - 1; + if (newIdx < 0) + unsetDisplayedShapeGraphRef(); + else + setDisplayedShapeGraphRef(newIdx); } catch (Communicator::CancelledException) { converted = false; } @@ -1255,23 +1271,22 @@ bool MetaGraphDX::makeAllLineMap(Communicator *communicator, const Point2f &seed // this is an index to look up the all line map, used by UI to determine if // can make fewest line map note: it is not saved for historical reasons if (hasAllLineMap()) { - removeShapeGraph(m_allLineMapIdx.value()); - m_allLineMapIdx = std::nullopt; + removeShapeGraph(m_allLineMapData->index); + m_allLineMapData = std::nullopt; } { - AllLineMap allm; + auto allm = AllLine::createAllLineMap(); std::vector> visibleDrawingFiles; auto shownMaps = getShownDrawingMaps(); for (const auto &pixel : shownMaps) { visibleDrawingFiles.push_back(pixel.first.get().getInternalMap()); } - allm.generate(communicator, visibleDrawingFiles, seed); - addShapeGraph(std::move(allm)); + m_allLineMapData = AllLine::generate(communicator, allm, visibleDrawingFiles, seed); + m_allLineMapData->index = addShapeGraph(std::move(allm)); } - m_allLineMapIdx = m_shapeGraphs.size() - 1; - setDisplayedShapeGraphRef(m_allLineMapIdx.value()); + setDisplayedShapeGraphRef(m_allLineMapData->index); } catch (Communicator::CancelledException) { mapMade = false; } @@ -1299,22 +1314,17 @@ bool MetaGraphDX::makeFewestLineMap(Communicator *communicator, int replace) { return false; } - AllLineMap *alllinemap = - dynamic_cast(m_shapeGraphs[m_allLineMapIdx.value()].get()); - - if (alllinemap == nullptr) { - throw depthmapX::RuntimeException("Failed to cast from ShapeGraph to AllLineMap"); - } + auto &alllinemap = m_shapeGraphs[m_allLineMapData->index]; - auto [fewestlinemap_subsets, fewestlinemap_minimal] = - alllinemap->extractFewestLineMaps(communicator); + auto [fewestlinemap_subsets, fewestlinemap_minimal] = AllLine::extractFewestLineMaps( + communicator, alllinemap.getInternalMap(), *m_allLineMapData); if (replace != 0) { std::optional index = std::nullopt; for (size_t i = 0; i < m_shapeGraphs.size(); i++) { - if (m_shapeGraphs[i]->getName() == "Fewest-Line Map (Subsets)" || - m_shapeGraphs[i]->getName() == "Fewest Line Map (Subsets)") { + if (m_shapeGraphs[i].getName() == "Fewest-Line Map (Subsets)" || + m_shapeGraphs[i].getName() == "Fewest Line Map (Subsets)") { index = i; } } @@ -1324,8 +1334,8 @@ bool MetaGraphDX::makeFewestLineMap(Communicator *communicator, int replace) { } for (size_t i = 0; i < m_shapeGraphs.size(); i++) { - if (m_shapeGraphs[i]->getName() == "Fewest-Line Map (Subsets)" || - m_shapeGraphs[i]->getName() == "Fewest Line Map (Subsets)") { + if (m_shapeGraphs[i].getName() == "Fewest-Line Map (Subsets)" || + m_shapeGraphs[i].getName() == "Fewest Line Map (Subsets)") { index = int(i); } } @@ -1337,7 +1347,11 @@ bool MetaGraphDX::makeFewestLineMap(Communicator *communicator, int replace) { addShapeGraph(std::move(fewestlinemap_subsets)); addShapeGraph(std::move(fewestlinemap_minimal)); - setDisplayedShapeGraphRef(m_shapeGraphs.size() - 2); + int newIdx = m_shapeGraphs.size() - 2; + if (newIdx < 0) + unsetDisplayedShapeGraphRef(); + else + setDisplayedShapeGraphRef(newIdx); } catch (Communicator::CancelledException) { mapMade = false; @@ -1728,7 +1742,7 @@ bool MetaGraphDX::pushValuesToLayer(int sourcetype, size_t sourcelayer, int dest if (colIn.has_value() && desttype == VIEWVGA && ((sourcetype & VIEWDATA) || (sourcetype & VIEWAXIAL))) { auto &sourceMap = - sourcetype & VIEWDATA ? m_dataMaps[sourcelayer] : *m_shapeGraphs[sourcelayer]; + sourcetype & VIEWDATA ? m_dataMaps[sourcelayer] : m_shapeGraphs[sourcelayer]; auto &destMap = m_pointMaps[destlayer]; auto colInName = sourceMap.getAttributeTable().getColumnName(*colIn); auto colOutName = destMap.getAttributeTable().getColumnName(colOut); @@ -1737,7 +1751,7 @@ bool MetaGraphDX::pushValuesToLayer(int sourcetype, size_t sourcelayer, int dest } else if (sourcetype & VIEWDATA) { if (desttype == VIEWAXIAL) { auto &sourceMap = m_dataMaps[sourcelayer]; - auto &destMap = *m_shapeGraphs[destlayer]; + auto &destMap = m_shapeGraphs[destlayer]; auto colInName = colIn.has_value() ? std::make_optional(sourceMap.getAttributeTable().getColumnName(*colIn)) @@ -1775,7 +1789,7 @@ bool MetaGraphDX::pushValuesToLayer(int sourcetype, size_t sourcelayer, int dest destMap.getInternalMap(), colOutName, pushFunc); } else if (desttype == VIEWAXIAL) { auto &sourceMap = m_pointMaps[sourcelayer]; - auto &destMap = *m_shapeGraphs[destlayer]; + auto &destMap = m_shapeGraphs[destlayer]; auto colInName = colIn.has_value() ? std::make_optional(sourceMap.getAttributeTable().getColumnName(*colIn)) @@ -1787,7 +1801,7 @@ bool MetaGraphDX::pushValuesToLayer(int sourcetype, size_t sourcelayer, int dest } } else if (sourcetype & VIEWAXIAL) { if (desttype == VIEWDATA) { - auto &sourceMap = *m_shapeGraphs[sourcelayer]; + auto &sourceMap = m_shapeGraphs[sourcelayer]; auto &destMap = m_dataMaps[destlayer]; auto colInName = colIn.has_value() @@ -1797,8 +1811,8 @@ bool MetaGraphDX::pushValuesToLayer(int sourcetype, size_t sourcelayer, int dest PushValues::axialToShape(sourceMap.getInternalMap(), colInName, destMap.getInternalMap(), colOutName, pushFunc); } else if (desttype == VIEWAXIAL) { - auto &sourceMap = *m_shapeGraphs[sourcelayer]; - auto &destMap = *m_shapeGraphs[destlayer]; + auto &sourceMap = m_shapeGraphs[sourcelayer]; + auto &destMap = m_shapeGraphs[destlayer]; auto colInName = colIn.has_value() ? std::make_optional(sourceMap.getAttributeTable().getColumnName(*colIn)) @@ -1815,8 +1829,8 @@ bool MetaGraphDX::pushValuesToLayer(int sourcetype, size_t sourcelayer, int dest m_pointMaps[destlayer].overrideDisplayedAttribute(-2); m_pointMaps[destlayer].setDisplayedAttribute(static_cast(colOut)); } else if (desttype == VIEWAXIAL) { - m_shapeGraphs[destlayer]->overrideDisplayedAttribute(-2); - m_shapeGraphs[destlayer]->setDisplayedAttribute(static_cast(colOut)); + m_shapeGraphs[destlayer].overrideDisplayedAttribute(-2); + m_shapeGraphs[destlayer].setDisplayedAttribute(static_cast(colOut)); } else if (desttype == VIEWDATA) { m_dataMaps[destlayer].overrideDisplayedAttribute(-2); m_dataMaps[destlayer].setDisplayedAttribute(static_cast(colOut)); @@ -1922,7 +1936,9 @@ int MetaGraphDX::getDisplayedMapType() { case VIEWVGA: return ShapeMap::POINTMAP; case VIEWAXIAL: - return getDisplayedShapeGraph().getMapType(); + return hasDisplayedShapeGraph() && getDisplayedShapeGraphRef() != static_cast(-1) + ? getDisplayedShapeGraph().getMapType() + : ShapeMap::EMPTYMAP; case VIEWDATA: return getDisplayedDataMap().getMapType(); } @@ -2105,7 +2121,7 @@ AttributeTable &MetaGraphDX::getAttributeTable(std::optional type, break; case VIEWAXIAL: tab = (!layer.has_value()) ? &(getDisplayedShapeGraph().getAttributeTable()) - : &(m_shapeGraphs[layer.value()]->getAttributeTable()); + : &(m_shapeGraphs[layer.value()].getAttributeTable()); break; case VIEWDATA: tab = (!layer.has_value()) ? &(getDisplayedDataMap().getAttributeTable()) @@ -2128,7 +2144,7 @@ const AttributeTable &MetaGraphDX::getAttributeTable(std::optional type, break; case VIEWAXIAL: tab = (!layer.has_value()) ? &(getDisplayedShapeGraph().getAttributeTable()) - : &(m_shapeGraphs[layer.value()]->getAttributeTable()); + : &(m_shapeGraphs[layer.value()].getAttributeTable()); break; case VIEWDATA: tab = (!layer.has_value()) ? &(getDisplayedDataMap().getAttributeTable()) @@ -2208,15 +2224,15 @@ MetaGraphReadWrite::ReadStatus MetaGraphDX::readFromStream(std::istream &stream, { auto ddIt = dd.perShapeGraph.begin(); for (auto &&map : mgd.shapeGraphs) { - m_shapeGraphs.push_back(std::make_unique(std::move(map))); - auto &newMapDX = *m_shapeGraphs.back(); + m_shapeGraphs.emplace_back(std::make_unique(std::move(map))); + auto &newMapDX = m_shapeGraphs.back(); newMapDX.setEditable(std::get<0>(*ddIt)); newMapDX.setShow(std::get<1>(*ddIt)); newMapDX.setDisplayedAttribute(std::get<2>(*ddIt)); ddIt++; } } - m_allLineMapIdx = mgd.allLineMapIdx; + m_allLineMapData = mgd.allLineMapData; m_state = dd.state; m_viewClass = dd.viewClass; @@ -2228,7 +2244,7 @@ MetaGraphReadWrite::ReadStatus MetaGraphDX::readFromStream(std::istream &stream, m_displayedDatamap = dd.displayedDataMap == static_cast(-1) ? std::nullopt : std::make_optional(dd.displayedDataMap); - m_displayedShapegraph = dd.displayedShapeGraph == static_cast(-1) + m_displayedShapegraph = static_cast(dd.displayedShapeGraph) < 0 ? std::nullopt : std::make_optional(dd.displayedShapeGraph); } catch (MetaGraphReadWrite::MetaGraphReadError &e) { @@ -2255,7 +2271,8 @@ MetaGraphReadWrite::ReadStatus MetaGraphDX::write(const std::string &filename, i std::vector perPointMap; std::vector> dataMaps; std::vector perDataMap; - std::vector>> shapeGraphs; + std::vector> shapeGraphs; + std::vector perShapeGraph; for (auto &mapGroupDX : m_drawingFiles) { @@ -2280,9 +2297,9 @@ MetaGraphReadWrite::ReadStatus MetaGraphDX::write(const std::string &filename, i std::make_tuple(mapDX.isEditable(), mapDX.isShown(), mapDX.getDisplayedAttribute())); } for (auto &mapDX : m_shapeGraphs) { - dataMaps.push_back(mapDX->getInternalMap()); - perDataMap.push_back( - std::make_tuple(mapDX->isEditable(), mapDX->isShown(), mapDX->getDisplayedAttribute())); + shapeGraphs.push_back(mapDX.getInternalMap()); + perShapeGraph.push_back( + std::make_tuple(mapDX.isEditable(), mapDX.isShown(), mapDX.getDisplayedAttribute())); } int tempState = 0, tempViewClass = 0; @@ -2304,7 +2321,7 @@ MetaGraphReadWrite::ReadStatus MetaGraphDX::write(const std::string &filename, i MetaGraphReadWrite::write( filename, // MetaGraph Data version, m_metaGraph.name, m_metaGraph.region, m_metaGraph.fileProperties, drawingFiles, - pointMaps, dataMaps, shapeGraphs, m_allLineMapIdx, + pointMaps, dataMaps, shapeGraphs, m_allLineMapData, // display data tempState, tempViewClass, m_showGrid, m_showText, perDrawingMap, m_displayedPointmap.has_value() ? static_cast(*m_displayedPointmap) diff --git a/depthmapX/salaobj/metagraphdx.h b/depthmapX/salaobj/metagraphdx.h index 7032a41..05be3f7 100644 --- a/depthmapX/salaobj/metagraphdx.h +++ b/depthmapX/salaobj/metagraphdx.h @@ -49,7 +49,7 @@ class MetaGraphDX { std::vector>> m_drawingFiles; std::vector m_dataMaps; - std::vector> m_shapeGraphs; + std::vector m_shapeGraphs; std::vector m_pointMaps; std::optional m_displayedDatamap = std::nullopt; std::optional m_displayedPointmap = std::nullopt; @@ -171,7 +171,7 @@ class MetaGraphDX { private: // helpful to know this for creating fewest line maps, although has to be reread at input - std::optional m_allLineMapIdx = std::nullopt; + std::optional m_allLineMapData = std::nullopt; void removePointMap(size_t i) { if (m_displayedPointmap.has_value()) { @@ -224,8 +224,7 @@ class MetaGraphDX { bool polyClose(int shape_ref); bool polyCancel(int shape_ref); // - size_t addShapeGraph(std::unique_ptr &&shapeGraph); - size_t addShapeGraph(std::unique_ptr &&shapeGraph); + size_t addShapeGraph(ShapeGraphDX &&shapeGraph); size_t addShapeGraph(ShapeGraph &&shapeGraph); size_t addShapeGraph(const std::string &name, int type); size_t addShapeMap(const std::string &name); @@ -260,13 +259,13 @@ class MetaGraphDX { bool analyseTopoMet(Communicator *communicator, Options options); // <- options copied to keep thread safe // - bool hasAllLineMap() { return m_allLineMapIdx.has_value(); } + bool hasAllLineMap() { return m_allLineMapData.has_value(); } bool hasFewestLineMaps() { for (const auto &shapeGraph : m_shapeGraphs) { - if (shapeGraph->getName() == "Fewest-Line Map (Subsets)" || - shapeGraph->getName() == "Fewest Line Map (Subsets)" || - shapeGraph->getName() == "Fewest-Line Map (Minimal)" || - shapeGraph->getName() == "Fewest Line Map (Minimal)") { + if (shapeGraph.getName() == "Fewest-Line Map (Subsets)" || + shapeGraph.getName() == "Fewest Line Map (Subsets)" || + shapeGraph.getName() == "Fewest-Line Map (Minimal)" || + shapeGraph.getName() == "Fewest Line Map (Minimal)") { return true; } } @@ -316,12 +315,13 @@ class MetaGraphDX { return std::nullopt; } - std::vector> &getShapeGraphs() { return m_shapeGraphs; } + std::vector &getShapeGraphs() { return m_shapeGraphs; } bool hasDisplayedShapeGraph() const { return m_displayedShapegraph.has_value(); } - ShapeGraphDX &getDisplayedShapeGraph() { return *m_shapeGraphs[m_displayedShapegraph.value()]; } + ShapeGraphDX &getDisplayedShapeGraph() { return m_shapeGraphs[m_displayedShapegraph.value()]; } const ShapeGraphDX &getDisplayedShapeGraph() const { - return *m_shapeGraphs[m_displayedShapegraph.value()]; + return m_shapeGraphs[m_displayedShapegraph.value()]; } + void unsetDisplayedShapeGraphRef() { m_displayedShapegraph = std::nullopt; } void setDisplayedShapeGraphRef(size_t map) { if (m_displayedShapegraph.has_value() && m_displayedShapegraph != map) getDisplayedShapeGraph().clearSel(); @@ -333,7 +333,7 @@ class MetaGraphDX { if (m_displayedShapegraph.has_value()) { if (m_shapeGraphs.size() == 1) m_displayedShapegraph = std::nullopt; - else if (m_displayedShapegraph.value() != 0 && m_displayedShapegraph.value() >= i) + else if (m_displayedShapegraph.value() > 0 && m_displayedShapegraph.value() >= i) m_displayedShapegraph.value()--; } m_shapeGraphs.erase(std::next(m_shapeGraphs.begin(), static_cast(i))); diff --git a/depthmapX/salaobj/shapemapdx.cpp b/depthmapX/salaobj/shapemapdx.cpp index c6acf58..1c00e4c 100644 --- a/depthmapX/salaobj/shapemapdx.cpp +++ b/depthmapX/salaobj/shapemapdx.cpp @@ -437,7 +437,7 @@ float ShapeMapDX::getSelectedAvg(size_t attributeIdx) { bool ShapeMapDX::clearSel() { // note, only clear if need be, as m_attributes->deselectAll is slow - if (m_selectionSet.size()) { + if (!m_selectionSet.empty()) { m_selectionSet.clear(); } return true; @@ -445,7 +445,7 @@ bool ShapeMapDX::clearSel() { QtRegion ShapeMapDX::getSelBounds() { QtRegion r; - if (m_selectionSet.size()) { + if (!m_selectionSet.empty()) { for (auto &shapeRef : m_selectionSet) { r = runion(r, getInternalMap().getAllShapes().at(shapeRef).getBoundingBox()); } diff --git a/depthmapX/salaobj/shapemapdx.h b/depthmapX/salaobj/shapemapdx.h index 435c957..1f998d4 100644 --- a/depthmapX/salaobj/shapemapdx.h +++ b/depthmapX/salaobj/shapemapdx.h @@ -197,7 +197,8 @@ class ShapeMapDX : public AttributeMapDX { bool write(std::ostream &stream); // Simple wrappers - auto getName() { return getInternalMap().getName(); } + auto &getName() { return getInternalMap().getName(); } + const auto &getName() const { return getInternalMap().getName(); } auto getMapType() { return getInternalMap().getMapType(); } auto getAllPointsWithColour() { return getInternalMap().getAllPointsWithColour(m_selectionSet); diff --git a/salalib b/salalib index 23a0a3b..71c3162 160000 --- a/salalib +++ b/salalib @@ -1 +1 @@ -Subproject commit 23a0a3b254a8cc482e412a475fae18e3ad581887 +Subproject commit 71c3162b17a44a232c9982c21c76af313eb62205