Krita Source Code Documentation
Loading...
Searching...
No Matches
KisBezierMeshDetails Namespace Reference

Classes

struct  BaseMeshNode
 
class  Mesh
 

Enumerations

enum  SmartMoveMeshControlMode { MoveFree , MoveSymmetricLock , MoveRotationLock }
 

Functions

void assignPatchData (KisBezierPatch *patch, const QRectF &srcRect, const BaseMeshNode &tl, const BaseMeshNode &tr, const BaseMeshNode &bl, const BaseMeshNode &br)
 
void lerpNodeData (const BaseMeshNode &left, const BaseMeshNode &right, qreal t, BaseMeshNode &dst)
 
KRITAGLOBAL_EXPORT bool loadValue (const QDomElement &parent, BaseMeshNode *node)
 
KRITAGLOBAL_EXPORT QDebug operator<< (QDebug dbg, const BaseMeshNode &n)
 
template<typename Node , typename Patch >
QDebug operator<< (QDebug dbg, const Mesh< Node, Patch > &mesh)
 
KRITAGLOBAL_EXPORT void saveValue (QDomElement *parent, const QString &tag, const BaseMeshNode &node)
 
template<typename NodeArg , typename PatchArg >
void smartMoveControl (Mesh< NodeArg, PatchArg > &mesh, typename Mesh< NodeArg, PatchArg >::ControlPointIndex index, const QPointF &move, SmartMoveMeshControlMode mode, bool scaleNodeMoves)
 

Enumeration Type Documentation

◆ SmartMoveMeshControlMode

Enumerator
MoveFree 
MoveSymmetricLock 
MoveRotationLock 

Definition at line 1434 of file KisBezierMesh.h.

Function Documentation

◆ assignPatchData()

void KisBezierMeshDetails::assignPatchData ( KisBezierPatch * patch,
const QRectF & srcRect,
const BaseMeshNode & tl,
const BaseMeshNode & tr,
const BaseMeshNode & bl,
const BaseMeshNode & br )
inline

Definition at line 112 of file KisBezierMesh.h.

118{
119 patch->originalRect = srcRect;
120 Q_UNUSED(tl);
121 Q_UNUSED(tr);
122 Q_UNUSED(bl);
123 Q_UNUSED(br);
124}

References KisBezierPatch::originalRect.

◆ lerpNodeData()

void KisBezierMeshDetails::lerpNodeData ( const BaseMeshNode & left,
const BaseMeshNode & right,
qreal t,
BaseMeshNode & dst )
inline

Definition at line 104 of file KisBezierMesh.h.

105{
106 Q_UNUSED(left);
107 Q_UNUSED(right);
108 Q_UNUSED(t);
109 Q_UNUSED(dst);
110}

◆ loadValue()

bool KisBezierMeshDetails::loadValue ( const QDomElement & parent,
KisBezierMeshDetails::BaseMeshNode * node )

Definition at line 38 of file KisBezierMesh.cpp.

39{
40 if (!KisDomUtils::Private::checkType(parent, "mesh-node")) return false;
41
42 KisDomUtils::loadValue(parent, "node", &node->node);
43 KisDomUtils::loadValue(parent, "left-control", &node->leftControl);
44 KisDomUtils::loadValue(parent, "right-control", &node->rightControl);
45 KisDomUtils::loadValue(parent, "top-control", &node->topControl);
46 KisDomUtils::loadValue(parent, "bottom-control", &node->bottomControl);
47
48 return true;
49}
bool checkType(const QDomElement &e, const QString &expectedType)
bool loadValue(const QDomElement &e, float *v)

References KisBezierMeshDetails::BaseMeshNode::bottomControl, KisDomUtils::Private::checkType(), KisBezierMeshDetails::BaseMeshNode::leftControl, KisDomUtils::loadValue(), KisBezierMeshDetails::BaseMeshNode::node, KisBezierMeshDetails::BaseMeshNode::rightControl, and KisBezierMeshDetails::BaseMeshNode::topControl.

◆ operator<<() [1/2]

QDebug KisBezierMeshDetails::operator<< ( QDebug dbg,
const BaseMeshNode & n )

Definition at line 13 of file KisBezierMesh.cpp.

13 {
14 dbg.nospace() << "Node " << n.node << " "
15 << "(lC: " << n.leftControl << " "
16 << "tC: " << n.topControl << " "
17 << "rC: " << n.rightControl << " "
18 << "bC: " << n.bottomControl << ") ";
19 return dbg.nospace();
20}

References KisBezierMeshDetails::BaseMeshNode::bottomControl, KisBezierMeshDetails::BaseMeshNode::leftControl, KisBezierMeshDetails::BaseMeshNode::node, KisBezierMeshDetails::BaseMeshNode::rightControl, and KisBezierMeshDetails::BaseMeshNode::topControl.

◆ operator<<() [2/2]

template<typename Node , typename Patch >
QDebug KisBezierMeshDetails::operator<< ( QDebug dbg,
const Mesh< Node, Patch > & mesh )

Definition at line 1293 of file KisBezierMesh.h.

1294{
1295 dbg.nospace() << "Mesh " << mesh.size() << "\n";
1296
1297 for (int y = 0; y < mesh.size().height(); y++) {
1298 for (int x = 0; x < mesh.size().width(); x++) {
1299 dbg.nospace() << " node(" << x << ", " << y << ") " << mesh.node(x, y) << "\n";
1300 }
1301 }
1302 return dbg.space();
1303}
Node & node(int col, int row)

References KisBezierMeshDetails::Mesh< NodeArg, PatchArg >::node(), and KisBezierMeshDetails::Mesh< NodeArg, PatchArg >::size().

◆ saveValue()

void KisBezierMeshDetails::saveValue ( QDomElement * parent,
const QString & tag,
const BaseMeshNode & node )

Definition at line 24 of file KisBezierMesh.cpp.

25{
26 QDomDocument doc = parent->ownerDocument();
27 QDomElement e = doc.createElement(tag);
28 parent->appendChild(e);
29
30 e.setAttribute("type", "mesh-node");
31 KisDomUtils::saveValue(&e, "node", node.node);
32 KisDomUtils::saveValue(&e, "left-control", node.leftControl);
33 KisDomUtils::saveValue(&e, "right-control", node.rightControl);
34 KisDomUtils::saveValue(&e, "top-control", node.topControl);
35 KisDomUtils::saveValue(&e, "bottom-control", node.bottomControl);
36}
void saveValue(QDomElement *parent, const QString &tag, const QSize &size)

References KisBezierMeshDetails::BaseMeshNode::bottomControl, KisBezierMeshDetails::BaseMeshNode::leftControl, KisBezierMeshDetails::BaseMeshNode::node, KisBezierMeshDetails::BaseMeshNode::rightControl, KisDomUtils::saveValue(), and KisBezierMeshDetails::BaseMeshNode::topControl.

◆ smartMoveControl()

template<typename NodeArg , typename PatchArg >
void KisBezierMeshDetails::smartMoveControl ( Mesh< NodeArg, PatchArg > & mesh,
typename Mesh< NodeArg, PatchArg >::ControlPointIndex index,
const QPointF & move,
SmartMoveMeshControlMode mode,
bool scaleNodeMoves )

Definition at line 1441 of file KisBezierMesh.h.

1446{
1447 using ControlType = typename Mesh<NodeArg, PatchArg>::ControlType;
1448 using ControlPointIndex = typename Mesh<NodeArg, PatchArg>::ControlPointIndex;
1449// using ControlPointIterator = typename Mesh<NodeArg, PatchArg>::control_point_iterator;
1450 using SegmentIterator = typename Mesh<NodeArg, PatchArg>::segment_iterator;
1451
1452 auto it = mesh.find(index);
1454
1455 if (it.isNode()) {
1456 auto preAdjustSegment = [] (Mesh<NodeArg, PatchArg> &mesh,
1457 SegmentIterator it,
1458 const QPointF &normalizedOffset) {
1459
1460 if (it == mesh.endSegments()) return;
1461
1462 const QPointF base1 = it.p3() - it.p0();
1463 const QPointF base2 = it.p3() - it.p0() - normalizedOffset;
1464
1465 {
1466 const QPointF control = it.p1() - it.p0();
1467 const qreal dist0 = KisAlgebra2D::norm(base1);
1468 const qreal dist1 = KisAlgebra2D::dotProduct(base2, base1) / dist0;
1469 const qreal coeff = dist1 / dist0;
1470
1471 it.p1() = it.p0() + coeff * (control);
1472 }
1473 {
1474 const QPointF control = it.p2() - it.p3();
1475 const qreal dist0 = KisAlgebra2D::norm(base1);
1476 const qreal dist1 = KisAlgebra2D::dotProduct(base2, base1) / dist0;
1477 const qreal coeff = dist1 / dist0;
1478
1479 it.p2() = it.p3() + coeff * (control);
1480 }
1481 };
1482
1483 if (scaleNodeMoves) {
1484 preAdjustSegment(mesh, it.topSegment(), -move);
1485 preAdjustSegment(mesh, it.leftSegment(), -move);
1486 preAdjustSegment(mesh, it.bottomSegment(), move);
1487 preAdjustSegment(mesh, it.rightSegment(), move);
1488 }
1489
1490 it.node().translate(move);
1491
1492 } else {
1493 const QPointF newPos = *it + move;
1494
1495 if (mode == MoveRotationLock || mode == MoveSymmetricLock) {
1496 const qreal rotation = KisAlgebra2D::angleBetweenVectors(*it - it.node().node,
1497 newPos - it.node().node);
1498 QTransform R;
1499 R.rotateRadians(rotation);
1500
1501 const QTransform t =
1502 QTransform::fromTranslate(-it.node().node.x(), -it.node().node.y()) *
1503 R *
1504 QTransform::fromTranslate(it.node().node.x(), it.node().node.y());
1505
1506 if (mode == MoveRotationLock) {
1507 for (int intType = 0; intType < 4; intType++) {
1508 ControlType type = static_cast<ControlType>(intType);
1509
1510 if (type == ControlType::Node ||
1511 type == index.controlType) {
1512
1513 continue;
1514 }
1515
1516 auto neighbourIt = mesh.find(ControlPointIndex(index.nodeIndex, type));
1517 if (neighbourIt == mesh.endControlPoints()) continue;
1518
1519 *neighbourIt = t.map(*neighbourIt);
1520 }
1521 } else {
1522 auto neighbourIt = it.symmetricControl();
1523 if (neighbourIt != mesh.endControlPoints()) {
1524 *neighbourIt = t.map(*neighbourIt);
1525 }
1526 }
1527 }
1528
1529 *it = newPos;
1530 }
1531}
Eigen::Matrix< double, 4, 2 > R
typename ControlPointIndex::ControlType ControlType
control_point_iterator find(const ControlPointIndex &index)
control_point_iterator endControlPoints()
segment_iterator endSegments()
KisNodeSP node() const
Definition Node.cpp:827
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
qreal angleBetweenVectors(const QPointF &v1, const QPointF &v2)
qreal norm(const T &a)
PointTypeTraits< T >::value_type dotProduct(const T &a, const T &b)

References KisAlgebra2D::angleBetweenVectors(), KisBezierMeshDetails::Mesh< NodeArg, PatchArg >::ControlPointIndex::controlType, KisAlgebra2D::dotProduct(), KisBezierMeshDetails::Mesh< NodeArg, PatchArg >::endControlPoints(), KisBezierMeshDetails::Mesh< NodeArg, PatchArg >::endSegments(), KisBezierMeshDetails::Mesh< NodeArg, PatchArg >::find(), KIS_SAFE_ASSERT_RECOVER_RETURN, MoveRotationLock, MoveSymmetricLock, KisBezierMeshDetails::Mesh< NodeArg, PatchArg >::node(), KisBezierMeshDetails::Mesh< NodeArg, PatchArg >::ControlPointIndex::nodeIndex, KisAlgebra2D::norm(), R, and KisBezierMeshDetails::Mesh< NodeArg, PatchArg >::control_point_iterator_impl< is_const >::symmetricControl().