main.qml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>
  5. *
  6. * This file is part of NeuralNetwork project https://git.semlanik.org/semlanik/NeuralNetwork
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this
  9. * software and associated documentation files (the "Software"), to deal in the Software
  10. * without restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  12. * to permit persons to whom the Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all copies
  16. * or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. import QtQuick 2.11
  26. import QtQuick.Window 2.11
  27. import QtQuick.Controls 1.4
  28. ApplicationWindow {
  29. id: root
  30. visible: true
  31. width: 1024
  32. height: 768
  33. Rectangle {
  34. id: bottomLayer
  35. anchors.fill: parent
  36. color: "#000000"
  37. }
  38. Row {
  39. id: rowww
  40. anchors.left: parent.left
  41. anchors.top: parent.top
  42. anchors.margins: 10
  43. Repeater {
  44. id: layerRepeater
  45. model: visualizerModel.sizes.length
  46. delegate: Item {
  47. id: layerDelegate
  48. property alias neurons: neuronRepeater
  49. anchors.verticalCenter: parent.verticalCenter
  50. property int layerIndex: model.index
  51. property int layerSize: visualizerModel.sizes[layerIndex]
  52. width: 120
  53. height: activationsColumn.height
  54. Column {
  55. id: activationsColumn
  56. width: 50
  57. spacing: 20
  58. Repeater {
  59. id: neuronRepeater
  60. model: layerSize
  61. delegate: Rectangle {
  62. id: neuron
  63. width: 30
  64. height: 30
  65. radius: 15
  66. }
  67. }
  68. }
  69. }
  70. }
  71. onWidthChanged: {
  72. console.log("width: " + width)
  73. if (width !== visualizerModel.sizes.length*120) {
  74. return
  75. }
  76. for (var i = 1; i < layerRepeater.count; i++) {
  77. var neurons = layerRepeater.itemAt(i).neurons
  78. var neuronsPrev = layerRepeater.itemAt(i - 1).neurons
  79. for (var j = 0; j < neurons.count; j++) {
  80. var neuron = neurons.itemAt(j)
  81. var coord = layerRepeater.itemAt(i).mapToItem(root.contentItem, neuron.x + neuron.width/2, neuron.y + neuron.height/2)
  82. for(var k = 0; k < neuronsPrev.count; k++) {
  83. var neuronPrev = neuronsPrev.itemAt(k)
  84. var coordPrev = layerRepeater.itemAt(i - 1).mapToItem(root.contentItem, neuronPrev.x + neuronPrev.width/2, neuronPrev.y + neuronPrev.height/2)
  85. var angle = Math.atan2(coordPrev.y - coord.y, coordPrev.x - coord.x) * 180 / Math.PI
  86. var length = Math.sqrt(Math.pow(coordPrev.x - coord.x, 2) + Math.pow(coordPrev.y - coord.y, 2))
  87. connection.createObject(bottomLayer, {x: coord.x, y: coord.y, width: length, angle: angle})
  88. }
  89. }
  90. }
  91. }
  92. }
  93. Component {
  94. id: connection
  95. Rectangle {
  96. property alias angle: trans.angle
  97. transformOrigin: Item.Left
  98. transform: Rotation {
  99. id: trans
  100. }
  101. height: 1
  102. color: "#5500ff00"
  103. }
  104. }
  105. }