Skip to content

Commit

Permalink
codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
mi-sts committed May 4, 2024
1 parent d498ce6 commit cccc64b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
19 changes: 10 additions & 9 deletions src/main/kotlin/solve/rendering/canvas/SceneCanvas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class SceneCanvas : OpenGLCanvas() {
private var isFirstAssociatingFrameChosen = false
private var associationAdorner: AssociationAdorner? = null


private val contextMenu = buildContextMenu(canvas)

init {
Expand Down Expand Up @@ -99,7 +98,8 @@ class SceneCanvas : OpenGLCanvas() {
engineScene?.setFramesSelection(framesSelection)
associationManager.setFramesSelection(framesSelection)
framesSelectionSize = framesSelection.count()
lastFramesSelection = framesSelection }
lastFramesSelection = framesSelection
}

fun setColumnsNumber(columnsNumber: Int) {
this.columnsNumber = columnsNumber
Expand Down Expand Up @@ -334,8 +334,9 @@ class SceneCanvas : OpenGLCanvas() {
}

private fun onSecondAssociatingFrameChosen(secondFrameIndex: Int) {
if (!isFirstAssociatingFrameChosen)
if (!isFirstAssociatingFrameChosen) {
return
}

if (firstAssociatingFrameIndex != secondFrameIndex) {
associationManager.associate(firstAssociatingFrameIndex, secondFrameIndex)
Expand Down Expand Up @@ -378,7 +379,8 @@ class SceneCanvas : OpenGLCanvas() {
item("Clear associations").action {
if (associationManager.associationConnections.any {
it.firstFrameIndex == contextMenuInvokeFrameIndex || it.secondFrameIndex == contextMenuInvokeFrameIndex
}) {
}
) {
associationManager.clearAssociation(contextMenuInvokeFrameIndex)
}
}
Expand Down Expand Up @@ -434,17 +436,16 @@ class SceneCanvas : OpenGLCanvas() {
return shaderVector
}


// Returns a frame position in screen coordinates without taking into account the camera position.
fun getGlobalFrameScreenPosition(frameIndexCoordinates: Vector2i, framesSize: Vector2i) : Vector2f {
fun getGlobalFrameScreenPosition(frameIndexCoordinates: Vector2i, framesSize: Vector2i): Vector2f {
return Vector2f(
(framesSize.x.toFloat() + Renderer.getSpacingWidth(framesSize)) * frameIndexCoordinates.x ,
(framesSize.x.toFloat() + Renderer.getSpacingWidth(framesSize)) * frameIndexCoordinates.x,
(framesSize.y.toFloat() * (1f + Renderer.FramesSpacing)) * frameIndexCoordinates.y
)
}

// Returns a top left corner position in screen coordinates without taking into account the camera position.
fun getGlobalTopLeftCornerScreenPosition(window: Window, framesSize: Vector2i) : Vector2f {
fun getGlobalTopLeftCornerScreenPosition(window: Window, framesSize: Vector2i): Vector2f {
val topLeftCornerShaderPosition = window.calculateTopLeftCornerShaderPosition()
return shaderToFrameVector(topLeftCornerShaderPosition, framesSize).also {
it.x *= framesSize.x
Expand All @@ -457,7 +458,7 @@ class SceneCanvas : OpenGLCanvas() {
frameIndexCoordinates: Vector2i,
framesSize: Vector2i,
window: Window
) : Vector2f {
): Vector2f {
val globalFrameScreenPosition = getGlobalFrameScreenPosition(frameIndexCoordinates, framesSize)
val globalTopLeftCornerScreenPosition = getGlobalTopLeftCornerScreenPosition(window, framesSize)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package solve.rendering.engine.core.renderers

import org.joml.Vector2f
import solve.rendering.canvas.SceneCanvas
import solve.rendering.engine.Window
import solve.rendering.engine.utils.plus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class PointAssociationsRenderer(

linePoints.forEachIndexed { sideIndex, linePoint ->
val pointToVertexVector = Vector2f(normalVector) * AssociationLineWidth / window.camera.zoom /
DefaultLocalVerticesPositionsDivider
DefaultLocalVerticesPositionsDivider

val upperVertexPosition = linePoint + pointToVertexVector
val bottomVertexPosition = linePoint - pointToVertexVector
Expand Down
2 changes: 0 additions & 2 deletions src/main/kotlin/solve/scene/view/SceneView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import solve.rendering.canvas.SceneCanvas
import solve.rendering.engine.core.input.MouseButton
import solve.scene.SceneFacade
import solve.scene.controller.SceneController
import solve.scene.model.Landmark
import solve.scene.model.VisualizationFrame
import tornadofx.View
import tornadofx.onChange
import javafx.scene.input.MouseButton as JavaFXMouseButton
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package solve.scene.view.association

import org.joml.Vector2i
import solve.scene.model.Landmark

data class AssociationLine(
Expand Down
16 changes: 11 additions & 5 deletions src/main/kotlin/solve/scene/view/association/AssociationManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class AssociationManager {
val secondFramePointLayers = secondFrame.layers.filterIsInstance<Layer.PointLayer>()

if (associatingKeypointLayerIndex !in firstFrameKeypointLayers.indices ||
associatingKeypointLayerIndex !in secondFramePointLayers.indices) {
associatingKeypointLayerIndex !in secondFramePointLayers.indices
) {
println("There are no point layer with a given index to associate!")
return
}
Expand All @@ -42,7 +43,8 @@ class AssociationManager {
val firstKeypoint = firstFrameKeypoints[firstFrameKeypointUID] ?: return@forEach
val secondKeypoint = secondFrameKeypoints[firstFrameKeypointUID] ?: return@forEach

associationLines.add(AssociationLine(
associationLines.add(
AssociationLine(
firstFrameKeypointUID,
firstFrameIndex,
secondFrameIndex,
Expand All @@ -54,14 +56,18 @@ class AssociationManager {
}
_associationConnections.add(
AssociationConnection(
firstFrameIndex, secondFrameIndex, associatingKeypointLayerIndex, associationLines)
firstFrameIndex,
secondFrameIndex,
associatingKeypointLayerIndex,
associationLines
)
)
}

fun clearAssociation(frameIndex: Int, associatedKeypointLayerIndex: Int = 0) {
_associationConnections.removeAll {
it.keypointLayerIndex == associatedKeypointLayerIndex &&
(it.firstFrameIndex == frameIndex || it.secondFrameIndex == frameIndex)
(it.firstFrameIndex == frameIndex || it.secondFrameIndex == frameIndex)
}
}
}
}

0 comments on commit cccc64b

Please sign in to comment.