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);
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;

View File

@ -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();
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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();
};

View File

@ -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();

View File

@ -245,6 +245,11 @@ void SkeletonToMesh::process()
std::vector<SkeletonSnapshot> 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<int> meshIds;
@ -266,9 +271,9 @@ void SkeletonToMesh::process()
std::map<QString, std::map<QString, QString>>::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);