-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
304 additions
and
1,192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/main/kotlin/solve/rendering/engine/core/renderers/PointAssociationsRenderer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package solve.rendering.engine.core.renderers | ||
|
||
import org.joml.Vector2f | ||
import org.joml.Vector3f | ||
import solve.constants.ShadersPointAssociationFragmentPath | ||
import solve.constants.ShadersPointAssociationVertexPath | ||
import solve.rendering.engine.Window | ||
import solve.rendering.engine.core.batch.PrimitiveType | ||
import solve.rendering.engine.core.batch.RenderBatch | ||
import solve.rendering.engine.shader.ShaderAttributeType | ||
import solve.rendering.engine.shader.ShaderProgram | ||
import solve.rendering.engine.shader.ShaderType | ||
import solve.rendering.engine.utils.minus | ||
import solve.rendering.engine.utils.plus | ||
import solve.rendering.engine.utils.times | ||
import solve.rendering.engine.utils.toFloatVector | ||
import solve.rendering.engine.utils.toVector2i | ||
import solve.scene.view.association.AssociationManager | ||
|
||
class PointAssociationsRenderer( | ||
window: Window, | ||
private val associationManager: AssociationManager | ||
) : Renderer(window) { | ||
override val maxBatchSize = 1000 | ||
|
||
init { | ||
renderPriority = 1 | ||
} | ||
|
||
override fun createShaderProgram(): ShaderProgram { | ||
val shaderProgram = ShaderProgram() | ||
shaderProgram.addShader(ShadersPointAssociationVertexPath, ShaderType.VERTEX) | ||
shaderProgram.addShader(ShadersPointAssociationFragmentPath, ShaderType.FRAGMENT) | ||
shaderProgram.link() | ||
|
||
return shaderProgram | ||
} | ||
|
||
override fun createNewBatch(zIndex: Int): RenderBatch { | ||
val shaderAttributesTypes = listOf( | ||
ShaderAttributeType.FLOAT2, | ||
ShaderAttributeType.FLOAT3 | ||
) | ||
|
||
return RenderBatch( | ||
maxBatchSize, | ||
zIndex, | ||
PrimitiveType.Quad, | ||
shaderAttributesTypes | ||
) | ||
} | ||
|
||
override fun uploadUniforms(shaderProgram: ShaderProgram) { | ||
shaderProgram.uploadMatrix4f(ProjectionUniformName, window.calculateProjectionMatrix()) | ||
} | ||
|
||
override fun updateBatchesData() { | ||
val associationConnections = associationManager.associationConnections | ||
|
||
associationConnections.forEach { associationConnection -> | ||
associationConnection.associationLines.forEach { associationLine -> | ||
val batch = getAvailableBatch(null, 0) | ||
|
||
val lineStartShaderPosition = getFramePixelShaderPosition( | ||
associationLine.firstKeypointFrameIndex, | ||
associationLine.firstKeypoint.coordinate.toVector2i().toFloatVector() | ||
) | ||
val lineFinishShaderPosition = getFramePixelShaderPosition( | ||
associationLine.secondKeypointFrameIndex, | ||
associationLine.secondKeypoint.coordinate.toVector2i().toFloatVector() | ||
) | ||
|
||
println("line start shader pos: ${lineStartShaderPosition}") | ||
println("line finish shader pos: ${lineFinishShaderPosition}") | ||
|
||
val lineVector = lineFinishShaderPosition - lineStartShaderPosition | ||
val normalVector = Vector2f(-lineVector.y, lineVector.x).normalize() | ||
val linePoints = listOf(lineStartShaderPosition, lineFinishShaderPosition) | ||
|
||
val firstKeypointColor = | ||
associationLine.firstKeypoint.layerSettings.getColor(associationLine.firstKeypoint) | ||
val secondKeypointColor = | ||
associationLine.secondKeypoint.layerSettings.getColor(associationLine.secondKeypoint) | ||
val lineColor = firstKeypointColor.interpolate(secondKeypointColor, 0.5) | ||
|
||
val lineColorVector = Vector3f( | ||
lineColor.red.toFloat(), | ||
lineColor.green.toFloat(), | ||
lineColor.blue.toFloat() | ||
) | ||
|
||
linePoints.forEachIndexed { sideIndex, linePoint -> | ||
val pointToVertexVector = Vector2f(normalVector) * AssociationLineWidth / window.camera.zoom / | ||
DefaultLocalVerticesPositionsDivider | ||
|
||
val upperVertexPosition = linePoint + pointToVertexVector | ||
val bottomVertexPosition = linePoint - pointToVertexVector | ||
val firstVertexPosition = if (sideIndex == 0) upperVertexPosition else bottomVertexPosition | ||
val secondVertexPosition = if (sideIndex == 0) bottomVertexPosition else upperVertexPosition | ||
batch.pushVector2f(firstVertexPosition) | ||
batch.pushVector3f(lineColorVector) | ||
batch.pushVector2f(secondVertexPosition) | ||
batch.pushVector3f(lineColorVector) | ||
} | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
private const val DefaultLocalVerticesPositionsDivider = 800f | ||
|
||
private const val AssociationLineWidth = 3.0f | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/solve/scene/view/association/AssociationConnection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package solve.scene.view.association | ||
|
||
data class AssociationConnection( | ||
val firstFrameIndex: Int, | ||
val secondFrameIndex: Int, | ||
val keypointLayerIndex: Int, | ||
val associationLines: List<AssociationLine> | ||
) |
Oops, something went wrong.