Generate coords around root joint

master
Jeremy Hu 2018-03-29 16:01:57 +08:00
parent 9892d1bc2c
commit 53dfb62460
7 changed files with 59 additions and 5 deletions

View File

@ -175,6 +175,12 @@ MainWindow::MainWindow()
QAction *markAsTrunkAct = new QAction(tr("Mark as &Trunk"), this); QAction *markAsTrunkAct = new QAction(tr("Mark as &Trunk"), this);
connect(markAsTrunkAct, &QAction::triggered, skeletonWidget->graphicsView(), &SkeletonEditGraphicsView::markAsTrunk); 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); QAction *changeTurnaroundAct = new QAction(tr("&Change Turnaround..."), this);
connect(changeTurnaroundAct, &QAction::triggered, skeletonWidget, &SkeletonWidget::changeTurnaround); connect(changeTurnaroundAct, &QAction::triggered, skeletonWidget, &SkeletonWidget::changeTurnaround);
@ -196,6 +202,9 @@ MainWindow::MainWindow()
editMenu->addAction(markAsBranchAct); editMenu->addAction(markAsBranchAct);
editMenu->addAction(markAsTrunkAct); editMenu->addAction(markAsTrunkAct);
editMenu->addSeparator(); editMenu->addSeparator();
editMenu->addAction(markAsRootAct);
editMenu->addAction(markAsChildAct);
editMenu->addSeparator();
editMenu->addAction(changeTurnaroundAct); editMenu->addAction(changeTurnaroundAct);
bool connectResult = false; bool connectResult = false;

View File

@ -545,6 +545,7 @@ void SkeletonEditGraphicsView::saveToSnapshot(SkeletonSnapshot *snapshot)
(*snapshotNode)["sideColorName"] = nodeItem->sideColorName(); (*snapshotNode)["sideColorName"] = nodeItem->sideColorName();
(*snapshotNode)["radius"] = QString("%1").arg(nodeItem->radius()); (*snapshotNode)["radius"] = QString("%1").arg(nodeItem->radius());
(*snapshotNode)["isBranch"] = QString("%1").arg(nodeItem->isBranch() ? "true" : "false"); (*snapshotNode)["isBranch"] = QString("%1").arg(nodeItem->isBranch() ? "true" : "false");
(*snapshotNode)["isRoot"] = QString("%1").arg(nodeItem->isRoot() ? "true" : "false");
QPointF origin = nodeItem->origin(); QPointF origin = nodeItem->origin();
(*snapshotNode)["x"] = QString("%1").arg(origin.x()); (*snapshotNode)["x"] = QString("%1").arg(origin.x());
(*snapshotNode)["y"] = QString("%1").arg(origin.y()); (*snapshotNode)["y"] = QString("%1").arg(origin.y());
@ -593,3 +594,21 @@ void SkeletonEditGraphicsView::markAsTrunk()
emit nodesChanged(); 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();
}
}

View File

@ -22,6 +22,8 @@ public slots:
void turnOnAddNodeMode(); void turnOnAddNodeMode();
void markAsBranch(); void markAsBranch();
void markAsTrunk(); void markAsTrunk();
void markAsRoot();
void markAsChild();
public: public:
SkeletonEditGraphicsView(QWidget *parent = 0); SkeletonEditGraphicsView(QWidget *parent = 0);
void updateBackgroundImage(const QImage &image); void updateBackgroundImage(const QImage &image);

View File

@ -9,7 +9,8 @@ SkeletonEditNodeItem::SkeletonEditNodeItem(const QRectF &rect, QGraphicsItem *pa
m_nextSidePair(NULL), m_nextSidePair(NULL),
m_sideColor(Theme::red), m_sideColor(Theme::red),
m_sideColorName("red"), m_sideColorName("red"),
m_isBranch(false) m_isBranch(false),
m_isRoot(false)
{ {
setData(0, "node"); setData(0, "node");
updateAppearance(); updateAppearance();
@ -26,6 +27,17 @@ bool SkeletonEditNodeItem::isBranch()
return m_isBranch; return m_isBranch;
} }
void SkeletonEditNodeItem::markAsRoot(bool isRoot)
{
m_isRoot = isRoot;
updateAppearance();
}
bool SkeletonEditNodeItem::isRoot()
{
return m_isRoot;
}
const QString &SkeletonEditNodeItem::sideColorName() const QString &SkeletonEditNodeItem::sideColorName()
{ {
return m_sideColorName; return m_sideColorName;
@ -112,7 +124,7 @@ void SkeletonEditNodeItem::updateAppearance()
QColor penColor = m_sideColor; QColor penColor = m_sideColor;
penColor.setAlphaF(m_checked ? Theme::checkedAlpha : (m_isBranch ? Theme::branchAlpha : Theme::normalAlpha)); penColor.setAlphaF(m_checked ? Theme::checkedAlpha : (m_isBranch ? Theme::branchAlpha : Theme::normalAlpha));
QPen pen(penColor); QPen pen(penColor);
pen.setWidth(Theme::skeletonNodeBorderSize); pen.setWidth(m_isRoot ? Theme::skeletonNodeBorderSize : (Theme::skeletonNodeBorderSize * 2));
setPen(pen); setPen(pen);
QColor brushColor = m_sideColor; QColor brushColor = m_sideColor;

View File

@ -21,6 +21,8 @@ public:
void setChecked(bool checked); void setChecked(bool checked);
void markAsBranch(bool isBranch); void markAsBranch(bool isBranch);
bool isBranch(); bool isBranch();
void markAsRoot(bool isRoot);
bool isRoot();
SkeletonEditNodeItem *nextSidePair(); SkeletonEditNodeItem *nextSidePair();
void setNextSidePair(SkeletonEditNodeItem *nodeItem); void setNextSidePair(SkeletonEditNodeItem *nodeItem);
const QColor &sideColor(); const QColor &sideColor();
@ -35,6 +37,7 @@ private:
QColor m_sideColor; QColor m_sideColor;
QString m_sideColorName; QString m_sideColorName;
bool m_isBranch; bool m_isBranch;
bool m_isRoot;
private: private:
void updateAppearance(); void updateAppearance();
}; };

View File

@ -257,6 +257,10 @@ void SkeletonSnapshot::resolveRootNode()
for (nodeIterator = nodes.begin(); nodeIterator != nodes.end(); nodeIterator++) { for (nodeIterator = nodes.begin(); nodeIterator != nodes.end(); nodeIterator++) {
if ("red" != nodeIterator->second["sideColorName"]) if ("red" != nodeIterator->second["sideColorName"])
continue; continue;
if ("true" == nodeIterator->second["isRoot"]) {
m_rootNode = nodeIterator->first;
break;
}
if (nodeNeighborCountMap[nodeIterator->first] < 3) if (nodeNeighborCountMap[nodeIterator->first] < 3)
continue; continue;
float radius = nodeIterator->second["radius"].toFloat(); float radius = nodeIterator->second["radius"].toFloat();

View File

@ -245,6 +245,11 @@ void SkeletonToMesh::process()
std::vector<SkeletonSnapshot> groups; std::vector<SkeletonSnapshot> groups;
QRectF globalFront = m_snapshot.boundingBoxFront(); QRectF globalFront = m_snapshot.boundingBoxFront();
QRectF globalSide = m_snapshot.boundingBoxSide(); 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); m_snapshot.splitByConnectivity(&groups);
std::vector<int> meshIds; std::vector<int> meshIds;
@ -266,9 +271,9 @@ void SkeletonToMesh::process()
std::map<QString, std::map<QString, QString>>::iterator nextSidePair = skeleton->nodes.find(nodeIterator->second["nextSidePair"]); std::map<QString, std::map<QString, QString>>::iterator nextSidePair = skeleton->nodes.find(nodeIterator->second["nextSidePair"]);
if (nextSidePair == skeleton->nodes.end()) if (nextSidePair == skeleton->nodes.end())
continue; continue;
float x = (nodeIterator->second["x"].toFloat() - globalFront.left()) / canvasHeight; float x = (nodeIterator->second["x"].toFloat() - frontMiddleX) / canvasHeight;
float y = (nodeIterator->second["y"].toFloat() - globalFront.top()) / canvasHeight; float y = (nodeIterator->second["y"].toFloat() - frontMiddleY) / canvasHeight;
float z = (nextSidePair->second["x"].toFloat() - globalSide.left()) / canvasHeight; float z = (nextSidePair->second["x"].toFloat() - sideMiddleX) / canvasHeight;
float r = nodeIterator->second["radius"].toFloat() / canvasHeight; float r = nodeIterator->second["radius"].toFloat() / canvasHeight;
float t = nextSidePair->second["radius"].toFloat() / canvasHeight; float t = nextSidePair->second["radius"].toFloat() / canvasHeight;
int bmeshNodeId = meshlite_bmesh_add_node(meshliteContext, bmeshId, x, y, z, r, t); int bmeshNodeId = meshlite_bmesh_add_node(meshliteContext, bmeshId, x, y, z, r, t);