refactor + add colors
This commit is contained in:
parent
7c27a20994
commit
1554ed0ef5
@ -11,13 +11,10 @@ class Form1 {
|
||||
private val bin = Bin
|
||||
val view = View()
|
||||
|
||||
private var minTF = -3000
|
||||
private var widthTF = 2000
|
||||
|
||||
private var frameCount = 0
|
||||
private var nextFPSUpdate = System.currentTimeMillis() + 1000
|
||||
|
||||
fun displayFPS() {
|
||||
private fun displayFPS() {
|
||||
if (System.currentTimeMillis() >= nextFPSUpdate) {
|
||||
println("CT Visualizer (fps = $frameCount)")
|
||||
nextFPSUpdate = System.currentTimeMillis() + 1000
|
||||
@ -26,7 +23,7 @@ class Form1 {
|
||||
frameCount++
|
||||
}
|
||||
|
||||
fun openFileDialog() {
|
||||
private fun openFileDialog() {
|
||||
val fileChooser = JFileChooser()
|
||||
fileChooser.fileFilter = FileNameExtensionFilter("BIN Files", "bin")
|
||||
val result = fileChooser.showOpenDialog(null)
|
||||
|
@ -7,18 +7,16 @@ import org.lwjgl.system.MemoryUtil.NULL
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
fun main() {
|
||||
if (!glfwInit()) {
|
||||
if (!glfwInit())
|
||||
throw IllegalStateException("Unable to initialize GLFW")
|
||||
}
|
||||
|
||||
glfwDefaultWindowHints()
|
||||
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE)
|
||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE)
|
||||
|
||||
val window = glfwCreateWindow(800, 600, "CT Visualizer", NULL, NULL)
|
||||
if (window == NULL) {
|
||||
if (window == NULL)
|
||||
throw RuntimeException("Failed to create the GLFW window")
|
||||
}
|
||||
|
||||
glfwSetFramebufferSizeCallback(window) { _: Long, width: Int, height: Int ->
|
||||
glViewport(0, 0, width, height)
|
||||
|
@ -3,8 +3,8 @@ package org.exampl
|
||||
import java.awt.Color
|
||||
|
||||
object TransferHelper {
|
||||
private var min = -3000
|
||||
private var max = 16000
|
||||
private var min = -3100
|
||||
private var max = 5000
|
||||
|
||||
fun setTF(newMin: Int, newMax: Int) {
|
||||
min = newMin
|
||||
@ -12,7 +12,38 @@ object TransferHelper {
|
||||
}
|
||||
|
||||
fun transferFunction(value: Short): Color {
|
||||
val newVal = Math.max(0, Math.min((value - min) * 255 / (max - min), 255))
|
||||
return Color(newVal, newVal, newVal)
|
||||
val k = value.toFloat().map(min.toFloat()..max.toFloat(), 0f..1f)
|
||||
|
||||
/*
|
||||
0 -> black (0, 0, 0)
|
||||
.25 -> blue (0, 0, f)
|
||||
.5 -> green (0, f, 0)
|
||||
.75 -> yellow (f, f, 0)
|
||||
1 -> white (f, f, f)
|
||||
*/
|
||||
|
||||
return when (k) {
|
||||
in 0f..0.25f -> Color(0, 0, (k * 4 * 255).toInt())
|
||||
in 0.25f..0.5f -> {
|
||||
val g = k.map(0.25f..0.5f, 0f..255f).toInt()
|
||||
Color(0, g, 255 - g)
|
||||
}
|
||||
in 0.5f..0.75f -> {
|
||||
val r = k.map(0.5f..0.75f, 0f..255f).toInt()
|
||||
Color(r, 255, 0)
|
||||
}
|
||||
in 0.75f..1f -> {
|
||||
val b = k.map(0.75f..1f, 0f..255f).toInt()
|
||||
Color(255, 255, b)
|
||||
}
|
||||
else -> throw IllegalArgumentException("$value not in range [$min..$max]")
|
||||
}
|
||||
}
|
||||
|
||||
fun Float.map(fromRange: ClosedRange<Float>, toRange: ClosedRange<Float>): Float {
|
||||
if (fromRange.start == fromRange.endInclusive)
|
||||
return (toRange.start + toRange.endInclusive) / 2
|
||||
return (this - fromRange.start) * (toRange.endInclusive - toRange.start) /
|
||||
(fromRange.endInclusive - fromRange.start) + toRange.start
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user