diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2532f607..440ccaa7 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -175,6 +175,12 @@ MainWindow::MainWindow() QAction *markAsTrunkAct = new QAction(tr("Mark as &Trunk"), this); connect(markAsTrunkAct, &QAction::triggered, skeletonWidget->graphicsView(), &SkeletonEditGraphicsView::markAsTrunk); + QAction *markAsRootAct = new QAction(tr("Mark as &Root"), this); + connect(markAsRootAct, &QAction::triggered, skeletonWidget->graphicsView(), &SkeletonEditGraphicsView::markAsRoot); + + QAction *markAsChildAct = new QAction(tr("Mark as &Child"), this); + connect(markAsChildAct, &QAction::triggered, skeletonWidget->graphicsView(), &SkeletonEditGraphicsView::markAsChild); + QAction *changeTurnaroundAct = new QAction(tr("&Change Turnaround..."), this); connect(changeTurnaroundAct, &QAction::triggered, skeletonWidget, &SkeletonWidget::changeTurnaround); @@ -196,6 +202,9 @@ MainWindow::MainWindow() editMenu->addAction(markAsBranchAct); editMenu->addAction(markAsTrunkAct); editMenu->addSeparator(); + editMenu->addAction(markAsRootAct); + editMenu->addAction(markAsChildAct); + editMenu->addSeparator(); editMenu->addAction(changeTurnaroundAct); bool connectResult = false; diff --git a/src/skeletoneditgraphicsview.cpp b/src/skeletoneditgraphicsview.cpp index 1649ff9d..c02cdeda 100644 --- a/src/skeletoneditgraphicsview.cpp +++ b/src/skeletoneditgraphicsview.cpp @@ -545,6 +545,7 @@ void SkeletonEditGraphicsView::saveToSnapshot(SkeletonSnapshot *snapshot) (*snapshotNode)["sideColorName"] = nodeItem->sideColorName(); (*snapshotNode)["radius"] = QString("%1").arg(nodeItem->radius()); (*snapshotNode)["isBranch"] = QString("%1").arg(nodeItem->isBranch() ? "true" : "false"); + (*snapshotNode)["isRoot"] = QString("%1").arg(nodeItem->isRoot() ? "true" : "false"); QPointF origin = nodeItem->origin(); (*snapshotNode)["x"] = QString("%1").arg(origin.x()); (*snapshotNode)["y"] = QString("%1").arg(origin.y()); @@ -593,3 +594,21 @@ void SkeletonEditGraphicsView::markAsTrunk() emit nodesChanged(); } } + +void SkeletonEditGraphicsView::markAsRoot() +{ + if (m_nextStartNodeItem) { + m_nextStartNodeItem->markAsRoot(true); + m_nextStartNodeItem->nextSidePair()->markAsRoot(true); + emit nodesChanged(); + } +} + +void SkeletonEditGraphicsView::markAsChild() +{ + if (m_nextStartNodeItem) { + m_nextStartNodeItem->markAsRoot(false); + m_nextStartNodeItem->nextSidePair()->markAsRoot(false); + emit nodesChanged(); + } +} diff --git a/src/skeletoneditgraphicsview.h b/src/skeletoneditgraphicsview.h index cd5e8206..3d9942e9 100644 --- a/src/skeletoneditgraphicsview.h +++ b/src/skeletoneditgraphicsview.h @@ -22,6 +22,8 @@ public slots: void turnOnAddNodeMode(); void markAsBranch(); void markAsTrunk(); + void markAsRoot(); + void markAsChild(); public: SkeletonEditGraphicsView(QWidget *parent = 0); void updateBackgroundImage(const QImage &image); diff --git a/src/skeletoneditnodeitem.cpp b/src/skeletoneditnodeitem.cpp index 3b6225a8..a71ddb33 100644 --- a/src/skeletoneditnodeitem.cpp +++ b/src/skeletoneditnodeitem.cpp @@ -9,7 +9,8 @@ SkeletonEditNodeItem::SkeletonEditNodeItem(const QRectF &rect, QGraphicsItem *pa m_nextSidePair(NULL), m_sideColor(Theme::red), m_sideColorName("red"), - m_isBranch(false) + m_isBranch(false), + m_isRoot(false) { setData(0, "node"); updateAppearance(); @@ -26,6 +27,17 @@ bool SkeletonEditNodeItem::isBranch() return m_isBranch; } +void SkeletonEditNodeItem::markAsRoot(bool isRoot) +{ + m_isRoot = isRoot; + updateAppearance(); +} + +bool SkeletonEditNodeItem::isRoot() +{ + return m_isRoot; +} + const QString &SkeletonEditNodeItem::sideColorName() { return m_sideColorName; @@ -112,7 +124,7 @@ void SkeletonEditNodeItem::updateAppearance() QColor penColor = m_sideColor; penColor.setAlphaF(m_checked ? Theme::checkedAlpha : (m_isBranch ? Theme::branchAlpha : Theme::normalAlpha)); QPen pen(penColor); - pen.setWidth(Theme::skeletonNodeBorderSize); + pen.setWidth(m_isRoot ? Theme::skeletonNodeBorderSize : (Theme::skeletonNodeBorderSize * 2)); setPen(pen); QColor brushColor = m_sideColor; diff --git a/src/skeletoneditnodeitem.h b/src/skeletoneditnodeitem.h index 8bb25bb9..7f97a168 100644 --- a/src/skeletoneditnodeitem.h +++ b/src/skeletoneditnodeitem.h @@ -21,6 +21,8 @@ public: void setChecked(bool checked); void markAsBranch(bool isBranch); bool isBranch(); + void markAsRoot(bool isRoot); + bool isRoot(); SkeletonEditNodeItem *nextSidePair(); void setNextSidePair(SkeletonEditNodeItem *nodeItem); const QColor &sideColor(); @@ -35,6 +37,7 @@ private: QColor m_sideColor; QString m_sideColorName; bool m_isBranch; + bool m_isRoot; private: void updateAppearance(); }; diff --git a/src/skeletonsnapshot.cpp b/src/skeletonsnapshot.cpp index 8a2ff5b8..5357d403 100644 --- a/src/skeletonsnapshot.cpp +++ b/src/skeletonsnapshot.cpp @@ -257,6 +257,10 @@ void SkeletonSnapshot::resolveRootNode() for (nodeIterator = nodes.begin(); nodeIterator != nodes.end(); nodeIterator++) { if ("red" != nodeIterator->second["sideColorName"]) continue; + if ("true" == nodeIterator->second["isRoot"]) { + m_rootNode = nodeIterator->first; + break; + } if (nodeNeighborCountMap[nodeIterator->first] < 3) continue; float radius = nodeIterator->second["radius"].toFloat(); diff --git a/src/skeletontomesh.cpp b/src/skeletontomesh.cpp index 886effab..adf075ae 100644 --- a/src/skeletontomesh.cpp +++ b/src/skeletontomesh.cpp @@ -245,6 +245,11 @@ void SkeletonToMesh::process() std::vector groups; QRectF globalFront = m_snapshot.boundingBoxFront(); QRectF globalSide = m_snapshot.boundingBoxSide(); + QString rootNodeId = m_snapshot.rootNode(); + printf("rootNodeId:%s\n", rootNodeId.toUtf8().constData()); + float frontMiddleX = m_snapshot.nodes[rootNodeId]["x"].toFloat(); + float frontMiddleY = m_snapshot.nodes[rootNodeId]["y"].toFloat(); + float sideMiddleX = m_snapshot.nodes[m_snapshot.nodes[rootNodeId]["nextSidePair"]]["x"].toFloat(); m_snapshot.splitByConnectivity(&groups); std::vector meshIds; @@ -266,9 +271,9 @@ void SkeletonToMesh::process() std::map>::iterator nextSidePair = skeleton->nodes.find(nodeIterator->second["nextSidePair"]); if (nextSidePair == skeleton->nodes.end()) continue; - float x = (nodeIterator->second["x"].toFloat() - globalFront.left()) / canvasHeight; - float y = (nodeIterator->second["y"].toFloat() - globalFront.top()) / canvasHeight; - float z = (nextSidePair->second["x"].toFloat() - globalSide.left()) / canvasHeight; + float x = (nodeIterator->second["x"].toFloat() - frontMiddleX) / canvasHeight; + float y = (nodeIterator->second["y"].toFloat() - frontMiddleY) / canvasHeight; + float z = (nextSidePair->second["x"].toFloat() - sideMiddleX) / canvasHeight; float r = nodeIterator->second["radius"].toFloat() / canvasHeight; float t = nextSidePair->second["radius"].toFloat() / canvasHeight; int bmeshNodeId = meshlite_bmesh_add_node(meshliteContext, bmeshId, x, y, z, r, t);