Add skeleton filters to orx-jumpflood
This commit is contained in:
@@ -24,6 +24,8 @@ class DistanceField : Filter() {
|
||||
|
||||
private val decodeFilter = PixelDistance()
|
||||
|
||||
var signedDistance = false
|
||||
|
||||
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
|
||||
if (thresholded == null) {
|
||||
thresholded = colorBuffer(target[0].width, target[0].height, format = ColorFormat.R)
|
||||
@@ -38,10 +40,11 @@ class DistanceField : Filter() {
|
||||
thresholdFilter.apply(source[0], thresholded!!)
|
||||
contourFilter.apply(thresholded!!, contoured!!)
|
||||
val result = jumpFlooder!!.jumpFlood(contoured!!)
|
||||
decodeFilter.signedDistance = signedDistance
|
||||
decodeFilter.originalSize = Vector2(target[0].width * 1.0, target[0].height * 1.0)
|
||||
decodeFilter.distanceScale = distanceScale
|
||||
decodeFilter.signedBit = false
|
||||
decodeFilter.apply(result, result)
|
||||
decodeFilter.apply(arrayOf(result, thresholded!!), arrayOf(result))
|
||||
result.copyTo(target[0])
|
||||
}
|
||||
}
|
||||
@@ -42,10 +42,12 @@ class PixelDistance : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/pixel
|
||||
var distanceScale: Double by parameters
|
||||
var originalSize: Vector2 by parameters
|
||||
var signedBit: Boolean by parameters
|
||||
var signedDistance: Boolean by parameters
|
||||
init {
|
||||
distanceScale = 1.0
|
||||
originalSize = Vector2(512.0, 512.0)
|
||||
signedBit = true
|
||||
signedDistance = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +122,7 @@ class JumpFlooder(val width: Int, val height: Int, format: ColorFormat = ColorFo
|
||||
}
|
||||
}
|
||||
|
||||
private fun encodeDecodeBitmap(drawer: Drawer, preprocess: Filter, decoder: Filter, bitmap: ColorBuffer,
|
||||
private fun encodeDecodeBitmap(preprocess: Filter, decoder: Filter, bitmap: ColorBuffer,
|
||||
jumpFlooder: JumpFlooder? = null,
|
||||
result: ColorBuffer? = null
|
||||
): ColorBuffer {
|
||||
@@ -136,7 +138,6 @@ private fun encodeDecodeBitmap(drawer: Drawer, preprocess: Filter, decoder: Filt
|
||||
if (jumpFlooder == null) {
|
||||
_jumpFlooder.destroy()
|
||||
}
|
||||
|
||||
return _result
|
||||
}
|
||||
|
||||
@@ -144,19 +145,17 @@ private fun encodeDecodeBitmap(drawer: Drawer, preprocess: Filter, decoder: Filt
|
||||
* Creates a color buffer containing the coordinates of the nearest centroids
|
||||
* @param bitmap a ColorBuffer with centroids in red (> 0)
|
||||
*/
|
||||
fun centroidsFromBitmap(drawer: Drawer, bitmap: ColorBuffer,
|
||||
fun centroidsFromBitmap(bitmap: ColorBuffer,
|
||||
jumpFlooder: JumpFlooder? = null,
|
||||
result: ColorBuffer? = null
|
||||
): ColorBuffer = encodeDecodeBitmap(drawer, passthrough, passthrough, bitmap, jumpFlooder, result)
|
||||
): ColorBuffer = encodeDecodeBitmap(passthrough, passthrough, bitmap, jumpFlooder, result)
|
||||
|
||||
fun distanceFieldFromBitmap(drawer: Drawer, bitmap: ColorBuffer,
|
||||
fun distanceFieldFromBitmap(bitmap: ColorBuffer,
|
||||
jumpFlooder: JumpFlooder? = null,
|
||||
result: ColorBuffer? = null
|
||||
): ColorBuffer = encodeDecodeBitmap(drawer, contourPoints, pixelDistance, bitmap, jumpFlooder, result)
|
||||
): ColorBuffer = encodeDecodeBitmap(contourPoints, pixelDistance, bitmap, jumpFlooder, result)
|
||||
|
||||
fun directionFieldFromBitmap(drawer: Drawer, bitmap: ColorBuffer,
|
||||
fun directionFieldFromBitmap(bitmap: ColorBuffer,
|
||||
jumpFlooder: JumpFlooder? = null,
|
||||
result: ColorBuffer? = null
|
||||
): ColorBuffer = encodeDecodeBitmap(drawer, contourPoints, pixelDirection, bitmap, jumpFlooder, result)
|
||||
|
||||
|
||||
): ColorBuffer = encodeDecodeBitmap(contourPoints, pixelDirection, bitmap, jumpFlooder, result)
|
||||
@@ -47,14 +47,12 @@ class InnerGlow : Filter() {
|
||||
@DoubleParameter("image opacity", 0.0, 1.0)
|
||||
var imageOpacity = 1.0
|
||||
|
||||
|
||||
@ColorParameter("color")
|
||||
var color = ColorRGBa.WHITE
|
||||
|
||||
private var jumpFlooder: JumpFlooder? = null
|
||||
private val decodeFilter = PixelDirection()
|
||||
private val glowFilter = InnerGlowFilter()
|
||||
|
||||
private var distance: ColorBuffer? = null
|
||||
|
||||
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
|
||||
|
||||
@@ -13,9 +13,10 @@ private class InpaintFilter : Filter(filterShaderFromUrl(resourceUrl("/shaders/g
|
||||
|
||||
var noise: Double by parameters
|
||||
var imageOpacity: Double by parameters
|
||||
var opacity : Double by parameters
|
||||
var shape : Double by parameters
|
||||
var opacity: Double by parameters
|
||||
var shape: Double by parameters
|
||||
var width: Double by parameters
|
||||
|
||||
init {
|
||||
noise = 0.0
|
||||
imageOpacity = 1.0
|
||||
@@ -33,7 +34,6 @@ class Inpaint : Filter() {
|
||||
@DoubleParameter("noise", 0.0, 1.0)
|
||||
var noise = 0.1
|
||||
|
||||
|
||||
@DoubleParameter("opacity", 0.0, 1.0)
|
||||
var opacity = 1.0
|
||||
|
||||
@@ -43,7 +43,6 @@ class Inpaint : Filter() {
|
||||
@DoubleParameter("shape", 0.0, 10.0)
|
||||
var shape = 0.0
|
||||
|
||||
|
||||
private var jumpFlooder: JumpFlooder? = null
|
||||
private val decodeFilter = PixelDirection()
|
||||
private val inpaintFilter = InpaintFilter()
|
||||
|
||||
@@ -47,13 +47,12 @@ class OuterGlow : Filter() {
|
||||
@DoubleParameter("image opacity", 0.0, 1.0)
|
||||
var imageOpacity = 1.0
|
||||
|
||||
|
||||
@ColorParameter("color")
|
||||
var color = ColorRGBa.WHITE
|
||||
|
||||
private var jumpFlooder: JumpFlooder? = null
|
||||
private val decodeFilter = PixelDirection()
|
||||
private val glowFilter = org.openrndr.extra.jumpfill.fx.OuterGlowFilter()
|
||||
private val glowFilter = OuterGlowFilter()
|
||||
|
||||
private var distance: ColorBuffer? = null
|
||||
|
||||
|
||||
83
orx-jumpflood/src/main/kotlin/fx/Skeleton.kt
Normal file
83
orx-jumpflood/src/main/kotlin/fx/Skeleton.kt
Normal file
@@ -0,0 +1,83 @@
|
||||
package org.openrndr.extra.jumpfill.fx
|
||||
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.*
|
||||
import org.openrndr.extra.jumpfill.*
|
||||
import org.openrndr.extra.parameters.ColorParameter
|
||||
|
||||
import org.openrndr.extra.parameters.Description
|
||||
import org.openrndr.extra.parameters.DoubleParameter
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.resourceUrl
|
||||
|
||||
private class SkeletonFilter : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/fx/skeleton.frag"))) {
|
||||
var skeletonColor: ColorRGBa by parameters
|
||||
var foregroundColor: ColorRGBa by parameters
|
||||
var backgroundColor: ColorRGBa by parameters
|
||||
|
||||
init {
|
||||
skeletonColor = ColorRGBa.WHITE
|
||||
foregroundColor = ColorRGBa.GRAY
|
||||
backgroundColor = ColorRGBa.TRANSPARENT
|
||||
}
|
||||
}
|
||||
|
||||
@Description("Skeleton")
|
||||
class Skeleton : Filter() {
|
||||
@DoubleParameter("threshold", 0.0, 1.0, order = 0)
|
||||
var threshold = 0.5
|
||||
|
||||
@DoubleParameter("distance scale", 0.0, 1.0, order = 1)
|
||||
var distanceScale = 1.0
|
||||
|
||||
@ColorParameter("skeleton color", order = 2)
|
||||
var skeletonColor = ColorRGBa.WHITE
|
||||
|
||||
@ColorParameter("foreground color", order = 3)
|
||||
var foregroundColor = ColorRGBa.GRAY
|
||||
|
||||
@ColorParameter("background color", order = 4)
|
||||
var backgroundColor = ColorRGBa.TRANSPARENT
|
||||
|
||||
private val thresholdFilter = Threshold()
|
||||
private var thresholded: ColorBuffer? = null
|
||||
private val contourFilter = ContourPoints()
|
||||
private var contoured: ColorBuffer? = null
|
||||
private var copied: ColorBuffer? = null
|
||||
private var jumpFlooder: JumpFlooder? = null
|
||||
|
||||
private val decodeFilter = PixelDistance()
|
||||
private val skeletonFilter = SkeletonFilter()
|
||||
|
||||
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
|
||||
if (thresholded == null) {
|
||||
thresholded = colorBuffer(target[0].width, target[0].height, format = ColorFormat.R)
|
||||
}
|
||||
if (contoured == null) {
|
||||
contoured = colorBuffer(target[0].width, target[0].height, format = ColorFormat.R)
|
||||
}
|
||||
if (jumpFlooder == null) {
|
||||
jumpFlooder = JumpFlooder(target[0].width, target[0].height)
|
||||
}
|
||||
if (copied == null) {
|
||||
copied = target[0].createEquivalent(type = ColorType.FLOAT32)
|
||||
}
|
||||
|
||||
thresholdFilter.threshold = threshold
|
||||
thresholdFilter.apply(source[0], thresholded!!)
|
||||
contourFilter.apply(thresholded!!, contoured!!)
|
||||
val result = jumpFlooder!!.jumpFlood(contoured!!)
|
||||
|
||||
decodeFilter.signedDistance = true
|
||||
decodeFilter.originalSize = Vector2(target[0].width * 1.0, target[0].height * 1.0)
|
||||
decodeFilter.distanceScale = distanceScale
|
||||
decodeFilter.signedBit = false
|
||||
decodeFilter.apply(arrayOf(result, thresholded!!), arrayOf(result))
|
||||
|
||||
result.copyTo(copied!!)
|
||||
skeletonFilter.skeletonColor = skeletonColor
|
||||
skeletonFilter.backgroundColor = backgroundColor
|
||||
skeletonFilter.foregroundColor = foregroundColor
|
||||
skeletonFilter.apply(copied!!, target[0])
|
||||
}
|
||||
}
|
||||
87
orx-jumpflood/src/main/kotlin/fx/StraightSkeleton.kt
Normal file
87
orx-jumpflood/src/main/kotlin/fx/StraightSkeleton.kt
Normal file
@@ -0,0 +1,87 @@
|
||||
package org.openrndr.extra.jumpfill.fx
|
||||
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.*
|
||||
import org.openrndr.extra.jumpfill.*
|
||||
import org.openrndr.extra.parameters.ColorParameter
|
||||
|
||||
import org.openrndr.extra.parameters.Description
|
||||
import org.openrndr.extra.parameters.DoubleParameter
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.resourceUrl
|
||||
import kotlin.math.sqrt
|
||||
|
||||
private class StraightSkeletonFilter : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/fx/straight-skeleton.frag"))) {
|
||||
var angleThreshold: Double by parameters
|
||||
var skeletonColor: ColorRGBa by parameters
|
||||
var foregroundColor: ColorRGBa by parameters
|
||||
var backgroundColor: ColorRGBa by parameters
|
||||
|
||||
init {
|
||||
skeletonColor = ColorRGBa.WHITE
|
||||
foregroundColor = ColorRGBa.GRAY
|
||||
backgroundColor = ColorRGBa.TRANSPARENT
|
||||
angleThreshold = sqrt(2.0) / 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
@Description("Skeleton")
|
||||
class StraightSkeleton : Filter() {
|
||||
@DoubleParameter("threshold", 0.0, 1.0, order = 0)
|
||||
var threshold = 0.5
|
||||
|
||||
@DoubleParameter("distance scale", 0.0, 1.0, order = 1)
|
||||
var distanceScale = 1.0
|
||||
|
||||
@DoubleParameter("angle threshold", 0.0, 1.0, order = 2)
|
||||
var angleThreshold = sqrt(2.0) / 2.0
|
||||
|
||||
@ColorParameter("skeleton color", order = 3)
|
||||
var skeletonColor = ColorRGBa.WHITE
|
||||
|
||||
@ColorParameter("foreground color", order = 4)
|
||||
var foregroundColor = ColorRGBa.GRAY
|
||||
|
||||
@ColorParameter("background color", order = 5)
|
||||
var backgroundColor = ColorRGBa.TRANSPARENT
|
||||
|
||||
private val thresholdFilter = Threshold()
|
||||
private var thresholded: ColorBuffer? = null
|
||||
private val contourFilter = ContourPoints()
|
||||
private var contoured: ColorBuffer? = null
|
||||
private var copied: ColorBuffer? = null
|
||||
private var jumpFlooder: JumpFlooder? = null
|
||||
|
||||
private val decodeFilter = PixelDirection()
|
||||
private val skeletonFilter = StraightSkeletonFilter()
|
||||
|
||||
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
|
||||
if (thresholded == null) {
|
||||
thresholded = colorBuffer(target[0].width, target[0].height, format = ColorFormat.R)
|
||||
}
|
||||
if (contoured == null) {
|
||||
contoured = colorBuffer(target[0].width, target[0].height, format = ColorFormat.R)
|
||||
}
|
||||
if (jumpFlooder == null) {
|
||||
jumpFlooder = JumpFlooder(target[0].width, target[0].height)
|
||||
}
|
||||
if (copied == null) {
|
||||
copied = target[0].createEquivalent(type = ColorType.FLOAT32)
|
||||
}
|
||||
|
||||
thresholdFilter.threshold = threshold
|
||||
thresholdFilter.apply(source[0], thresholded!!)
|
||||
contourFilter.apply(thresholded!!, contoured!!)
|
||||
val result = jumpFlooder!!.jumpFlood(contoured!!)
|
||||
decodeFilter.originalSize = Vector2(target[0].width * 1.0, target[0].height * 1.0)
|
||||
decodeFilter.distanceScale = distanceScale
|
||||
decodeFilter.apply(arrayOf(result, thresholded!!), arrayOf(result))
|
||||
result.copyTo(copied!!)
|
||||
|
||||
skeletonFilter.angleThreshold = angleThreshold
|
||||
skeletonFilter.skeletonColor = skeletonColor
|
||||
skeletonFilter.backgroundColor = backgroundColor
|
||||
skeletonFilter.foregroundColor = foregroundColor
|
||||
skeletonFilter.apply(copied!!, target[0])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user