mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-09 13:21:51 +09:00
Hosek skylight model translated from C to Kotlin
This commit is contained in:
@@ -9,9 +9,9 @@ import com.badlogic.gdx.graphics.Pixmap
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.EMDASH
|
||||
import net.torvald.colourutil.CIEXYZUtil.toColorRaw
|
||||
import net.torvald.colourutil.CIEXYZUtil.toXYZ
|
||||
import net.torvald.colourutil.CIEYXY
|
||||
import net.torvald.parametricsky.datasets.DatasetCIEXYZ
|
||||
import net.torvald.parametricsky.datasets.DatasetRGB
|
||||
import net.torvald.parametricsky.datasets.DatasetSpectral
|
||||
import net.torvald.terrarum.inUse
|
||||
import java.awt.Dimension
|
||||
import javax.swing.*
|
||||
@@ -50,7 +50,8 @@ class Application : Game() {
|
||||
private lateinit var testTex: Texture
|
||||
|
||||
var turbidity = 5.0
|
||||
//var thetaOfSun = 0.0
|
||||
var albedo = 0.0
|
||||
var elevation = 0.0
|
||||
|
||||
override fun getScreen(): Screen {
|
||||
return super.getScreen()
|
||||
@@ -63,7 +64,8 @@ class Application : Game() {
|
||||
override fun render() {
|
||||
Gdx.graphics.setTitle("Daylight Model $EMDASH F: ${Gdx.graphics.framesPerSecond}")
|
||||
|
||||
genTexLoop(turbidity)
|
||||
|
||||
genTexLoop(ArHosekSkyModel.arhosek_xyz_skymodelstate_alloc_init(turbidity, albedo, elevation))
|
||||
|
||||
|
||||
val tex = Texture(oneScreen)
|
||||
@@ -99,7 +101,7 @@ class Application : Game() {
|
||||
* Generated texture is as if you took the panorama picture of sky: up 70deg to horizon, east-south-west;
|
||||
* with sun not moving (sun is at exact south, sun's height is adjustable)
|
||||
*/
|
||||
private fun genTexLoop(T: Double) {
|
||||
private fun genTexLoop(state: ArHosekSkyModelState) {
|
||||
|
||||
fun normaliseY(y: Double): Float {
|
||||
var v = y.coerceAtLeast(0.0)
|
||||
@@ -109,62 +111,7 @@ class Application : Game() {
|
||||
return v.toFloat()
|
||||
}
|
||||
|
||||
val theta = Math.toRadians(45.0) // of observer
|
||||
|
||||
// loop DAY
|
||||
for (x in 0 until outTexWidth) { // theta_s (time of day)
|
||||
for (y in 0 until outTexHeight) { // gamma
|
||||
val theta_s = Math.toRadians(x * (90.0 / outTexWidth.toDouble()))
|
||||
val gamma = Math.toRadians((outTexHeight - y) * (90.0 / outTexHeight.toDouble())) // of observer
|
||||
|
||||
val Y_z = Model.getAbsoluteZenithLuminance(T, theta_s).coerceAtLeast(0.0) / 88.0
|
||||
val x_z = Model.getZenithChromaX(T, theta_s)
|
||||
val y_z = Model.getZenithChromaY(T, theta_s)
|
||||
|
||||
val Y_p = Y_z * Model.getFforLuma(theta, gamma, T) / Model.getFforLuma(0.0, theta_s, T)
|
||||
val Y_oc = Y_z * (1.0 + 2.0 * Math.cos(theta)) / 3.0
|
||||
val x_p = (x_z * Model.getFforChromaX(theta, gamma, T) / Model.getFforChromaX(0.0, theta_s, T)).coerceIn(0.0, 1.0)
|
||||
val y_p = (y_z * Model.getFforChromaY(theta, gamma, T) / Model.getFforChromaY(0.0, theta_s, T)).coerceIn(0.0, 1.0)
|
||||
|
||||
val normalisedY = normaliseY(Y_p)
|
||||
|
||||
//println("$Y_p -> $normalisedY, $x_p, $y_p")
|
||||
|
||||
val rgbColour = CIEYXY(normalisedY, x_p.toFloat(), y_p.toFloat()).toXYZ().toColorRaw()
|
||||
|
||||
oneScreen.setColor(rgbColour)
|
||||
oneScreen.drawPixel(x, y)
|
||||
}
|
||||
}
|
||||
// end loop DAY
|
||||
|
||||
// loop NIGHT
|
||||
for (x in outTexWidth until outTexWidth * 2) {
|
||||
for (y in 0 until outTexHeight) {
|
||||
val theta_s = Math.toRadians(90.0 - (x - outTexWidth) * (90.0 / outTexWidth.toDouble())) // 90 downTo 0
|
||||
val theta_sReal = Math.toRadians(120.0)
|
||||
val gamma = Math.toRadians((outTexHeight - y) * (90.0 / outTexHeight.toDouble())) // of observer
|
||||
|
||||
val Y_z = Model.getAbsoluteZenithLuminance(T, theta_sReal)
|
||||
val x_z = Model.getZenithChromaX(T, theta_s)
|
||||
val y_z = Model.getZenithChromaY(T, theta_s)
|
||||
|
||||
val Y_p = Y_z * Model.getFforLuma(theta, gamma, T) / Model.getFforLuma(0.0, theta_sReal, T)
|
||||
val Y_oc = Y_z * (1.0 + 2.0 * Math.cos(theta)) / 3.0
|
||||
val x_p = (x_z * Model.getFforChromaX(theta, gamma, T) / Model.getFforChromaX(0.0, theta_s, T)).coerceIn(0.0, 1.0)
|
||||
val y_p = (y_z * Model.getFforChromaY(theta, gamma, T) / Model.getFforChromaY(0.0, theta_s, T)).coerceIn(0.0, 1.0)
|
||||
|
||||
val normalisedY = normaliseY(Y_p)
|
||||
|
||||
//println("$Y_p -> $normalisedY, $x_p, $y_p")
|
||||
|
||||
val rgbColour = CIEYXY(normalisedY, x_p.toFloat(), y_p.toFloat()).toXYZ().toColorRaw()
|
||||
|
||||
oneScreen.setColor(rgbColour)
|
||||
oneScreen.drawPixel(x, y)
|
||||
}
|
||||
}
|
||||
// end loop NIGHT
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,6 +177,9 @@ class Application : Game() {
|
||||
|
||||
oneScreen = Pixmap(outTexWidth * 2, outTexHeight, Pixmap.Format.RGBA8888)
|
||||
|
||||
DatasetSpectral
|
||||
DatasetCIEXYZ
|
||||
DatasetRGB
|
||||
|
||||
ApplicationController(this)
|
||||
}
|
||||
@@ -240,32 +190,27 @@ class Application : Game() {
|
||||
|
||||
val mainPanel = JPanel()
|
||||
|
||||
val turbidityControl = JSlider(2, 64, 5)
|
||||
//val theta_sControl = JSlider(0, 15, 0)
|
||||
|
||||
val turbidityValueDisp = JLabel()
|
||||
//val theta_sValueDisp = JLabel()
|
||||
|
||||
//val theta_sValue: Double
|
||||
// get() = theta_sControl.value * (90.0 / theta_sControl.maximum)
|
||||
val turbidityControl = JSpinner(SpinnerNumberModel(5, 1, 10, 1))
|
||||
val albedoControl = JSpinner(SpinnerNumberModel(0.3, 0.0, 1.0, 0.05))
|
||||
val elevationControl = JSpinner(SpinnerNumberModel(45, 0, 90, 5))
|
||||
|
||||
init {
|
||||
val turbidityPanel = JPanel()
|
||||
val theta_sPanel = JPanel()
|
||||
val albedoPanel = JPanel()
|
||||
val elevationPanel = JPanel()
|
||||
|
||||
turbidityPanel.add(JLabel("Turbidity"))
|
||||
turbidityPanel.add(turbidityControl)
|
||||
turbidityPanel.add(turbidityValueDisp)
|
||||
|
||||
turbidityValueDisp.text = turbidityControl.value.toString()
|
||||
//theta_sValueDisp.text = theta_sValue.toString()
|
||||
albedoPanel.add(JLabel("Albedo"))
|
||||
albedoPanel.add(albedoControl)
|
||||
|
||||
//theta_sPanel.add(JLabel("Theta_s"))
|
||||
//theta_sPanel.add(theta_sControl)
|
||||
//theta_sPanel.add(theta_sValueDisp)
|
||||
elevationPanel.add(JLabel("Elevation"))
|
||||
elevationPanel.add(elevationControl)
|
||||
|
||||
mainPanel.add(turbidityPanel)
|
||||
mainPanel.add(theta_sPanel)
|
||||
mainPanel.add(albedoPanel)
|
||||
mainPanel.add(elevationPanel)
|
||||
|
||||
this.isVisible = true
|
||||
this.defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE
|
||||
@@ -275,14 +220,16 @@ class Application : Game() {
|
||||
|
||||
|
||||
turbidityControl.addChangeListener {
|
||||
turbidityValueDisp.text = turbidityControl.value.toString()
|
||||
app.turbidity = turbidityControl.value.toDouble()
|
||||
app.turbidity = turbidityControl.value as Double
|
||||
}
|
||||
|
||||
//theta_sControl.addChangeListener {
|
||||
// theta_sValueDisp.text = theta_sValue.toString()
|
||||
// app.thetaOfSun = Math.toRadians(theta_sValue)
|
||||
//}
|
||||
albedoControl.addChangeListener {
|
||||
app.albedo = albedoControl.value as Double
|
||||
}
|
||||
|
||||
elevationControl.addChangeListener {
|
||||
app.elevation = Math.toRadians((elevationControl.value as Int).toDouble())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
1276
src/net/torvald/parametricsky/ArHosekSkyModel.kt
Normal file
1276
src/net/torvald/parametricsky/ArHosekSkyModel.kt
Normal file
File diff suppressed because it is too large
Load Diff
137
src/net/torvald/parametricsky/datasets/DatasetCIEXYZ.kt
Normal file
137
src/net/torvald/parametricsky/datasets/DatasetCIEXYZ.kt
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
This source is published under the following 3-clause BSD license.
|
||||
|
||||
Copyright (c) 2012 - 2013, Lukas Hosek and Alexander Wilkie
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* None of the names of the contributors may be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES
|
||||
LOSS OF USE, DATA, OR PROFITS OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
/* ============================================================================
|
||||
|
||||
This file is part of a sample implementation of the analytical skylight and
|
||||
solar radiance models presented in the SIGGRAPH 2012 paper
|
||||
|
||||
|
||||
"An Analytic Model for Full Spectral Sky-Dome Radiance"
|
||||
|
||||
and the 2013 IEEE CG&A paper
|
||||
|
||||
"Adding a Solar Radiance Function to the Hosek Skylight Model"
|
||||
|
||||
both by
|
||||
|
||||
Lukas Hosek and Alexander Wilkie
|
||||
Charles University in Prague, Czech Republic
|
||||
|
||||
|
||||
Version: 1.4a, February 22nd, 2013
|
||||
|
||||
Version history:
|
||||
|
||||
1.4a February 22nd, 2013
|
||||
Removed unnecessary and counter-intuitive solar radius parameters
|
||||
from the interface of the colourspace sky dome initialisation functions.
|
||||
|
||||
1.4 February 11th, 2013
|
||||
Fixed a bug which caused the relative brightness of the solar disc
|
||||
and the sky dome to be off by a factor of about 6. The sun was too
|
||||
bright: this affected both normal and alien sun scenarios. The
|
||||
coefficients of the solar radiance function were changed to fix this.
|
||||
|
||||
1.3 January 21st, 2013 (not released to the public)
|
||||
Added support for solar discs that are not exactly the same size as
|
||||
the terrestrial sun. Also added support for suns with a different
|
||||
emission spectrum ("Alien World" functionality).
|
||||
|
||||
1.2a December 18th, 2012
|
||||
Fixed a mistake and some inaccuracies in the solar radiance function
|
||||
explanations found in ArHosekSkyModel.h. The actual source code is
|
||||
unchanged compared to version 1.2.
|
||||
|
||||
1.2 December 17th, 2012
|
||||
Native RGB data and a solar radiance function that matches the turbidity
|
||||
conditions were added.
|
||||
|
||||
1.1 September 2012
|
||||
The coefficients of the spectral model are now scaled so that the output
|
||||
is given in physical units: W / (m^-2 * sr * nm). Also, the output of the
|
||||
XYZ model is now no longer scaled to the range [0...1]. Instead, it is
|
||||
the result of a simple conversion from spectral data via the CIE 2 degree
|
||||
standard observer matching functions. Therefore, after multiplication
|
||||
with 683 lm / W, the Y channel now corresponds to luminance in lm.
|
||||
|
||||
1.0 May 11th, 2012
|
||||
Initial release.
|
||||
|
||||
|
||||
Please visit http://cgg.mff.cuni.cz/projects/SkylightModelling/ to check if
|
||||
an updated version of this code has been published!
|
||||
|
||||
============================================================================ */
|
||||
|
||||
|
||||
/*
|
||||
|
||||
This file contains the coefficient data for the spectral version of the model.
|
||||
|
||||
*/
|
||||
|
||||
// Uses Sep 9 pattern / Aug 23 mean dataset
|
||||
|
||||
package net.torvald.parametricsky.datasets
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
object DatasetCIEXYZ {
|
||||
|
||||
val datasetXYZ1 = DatasetOp.readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetXYZ1.bin")
|
||||
val datasetXYZ2 = DatasetOp.readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetXYZ2.bin")
|
||||
val datasetXYZ3 = DatasetOp.readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetXYZ3.bin")
|
||||
|
||||
val datasetXYZRad1 = DatasetOp.readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetXYZRad1.bin")
|
||||
val datasetXYZRad2 = DatasetOp.readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetXYZRad2.bin")
|
||||
val datasetXYZRad3 = DatasetOp.readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetXYZRad3.bin")
|
||||
|
||||
init {
|
||||
assertEquals(1080, datasetXYZ2.size, "Dataset size mismatch: expected 1080, got ${datasetXYZ2.size}")
|
||||
assertEquals(120, datasetXYZRad2.size, "Dataset size mismatch: expected 120, got ${datasetXYZRad2.size}")
|
||||
|
||||
assertEquals( -1.117001e+000, datasetXYZ1[0], "Dataset not parsed correctly - expected ${-1.117001e+000}, got ${datasetXYZ1[0]}")
|
||||
}
|
||||
|
||||
|
||||
val datasetsXYZ = arrayOf(
|
||||
datasetXYZ1,
|
||||
datasetXYZ2,
|
||||
datasetXYZ3
|
||||
)
|
||||
|
||||
val datasetsXYZRad = arrayOf(
|
||||
datasetXYZRad1,
|
||||
datasetXYZRad2,
|
||||
datasetXYZRad3
|
||||
)
|
||||
}
|
||||
24
src/net/torvald/parametricsky/datasets/DatasetOp.kt
Normal file
24
src/net/torvald/parametricsky/datasets/DatasetOp.kt
Normal file
@@ -0,0 +1,24 @@
|
||||
package net.torvald.parametricsky.datasets
|
||||
|
||||
import net.torvald.terrarum.serialise.toLittleLong
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
|
||||
object DatasetOp {
|
||||
|
||||
fun readDatasetFromFile(filepath: String): DoubleArray {
|
||||
val file = File(filepath)
|
||||
val entrysize = file.length().toInt() / 8
|
||||
val fis = FileInputStream(file)
|
||||
|
||||
val ret = DoubleArray(entrysize) {
|
||||
val inputbuf = ByteArray(8)
|
||||
fis.read(inputbuf)
|
||||
val rawnum = inputbuf.toLittleLong()
|
||||
Double.fromBits(rawnum)
|
||||
}
|
||||
|
||||
fis.close()
|
||||
return ret
|
||||
}
|
||||
}
|
||||
136
src/net/torvald/parametricsky/datasets/DatasetRGB.kt
Normal file
136
src/net/torvald/parametricsky/datasets/DatasetRGB.kt
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
This source is published under the following 3-clause BSD license.
|
||||
|
||||
Copyright (c) 2012 - 2013, Lukas Hosek and Alexander Wilkie
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* None of the names of the contributors may be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES
|
||||
LOSS OF USE, DATA, OR PROFITS OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
/* ============================================================================
|
||||
|
||||
This file is part of a sample implementation of the analytical skylight and
|
||||
solar radiance models presented in the SIGGRAPH 2012 paper
|
||||
|
||||
|
||||
"An Analytic Model for Full Spectral Sky-Dome Radiance"
|
||||
|
||||
and the 2013 IEEE CG&A paper
|
||||
|
||||
"Adding a Solar Radiance Function to the Hosek Skylight Model"
|
||||
|
||||
both by
|
||||
|
||||
Lukas Hosek and Alexander Wilkie
|
||||
Charles University in Prague, Czech Republic
|
||||
|
||||
|
||||
Version: 1.4a, February 22nd, 2013
|
||||
|
||||
Version history:
|
||||
|
||||
1.4a February 22nd, 2013
|
||||
Removed unnecessary and counter-intuitive solar radius parameters
|
||||
from the interface of the colourspace sky dome initialisation functions.
|
||||
|
||||
1.4 February 11th, 2013
|
||||
Fixed a bug which caused the relative brightness of the solar disc
|
||||
and the sky dome to be off by a factor of about 6. The sun was too
|
||||
bright: this affected both normal and alien sun scenarios. The
|
||||
coefficients of the solar radiance function were changed to fix this.
|
||||
|
||||
1.3 January 21st, 2013 (not released to the public)
|
||||
Added support for solar discs that are not exactly the same size as
|
||||
the terrestrial sun. Also added support for suns with a different
|
||||
emission spectrum ("Alien World" functionality).
|
||||
|
||||
1.2a December 18th, 2012
|
||||
Fixed a mistake and some inaccuracies in the solar radiance function
|
||||
explanations found in ArHosekSkyModel.h. The actual source code is
|
||||
unchanged compared to version 1.2.
|
||||
|
||||
1.2 December 17th, 2012
|
||||
Native RGB data and a solar radiance function that matches the turbidity
|
||||
conditions were added.
|
||||
|
||||
1.1 September 2012
|
||||
The coefficients of the spectral model are now scaled so that the output
|
||||
is given in physical units: W / (m^-2 * sr * nm). Also, the output of the
|
||||
XYZ model is now no longer scaled to the range [0...1]. Instead, it is
|
||||
the result of a simple conversion from spectral data via the CIE 2 degree
|
||||
standard observer matching functions. Therefore, after multiplication
|
||||
with 683 lm / W, the Y channel now corresponds to luminance in lm.
|
||||
|
||||
1.0 May 11th, 2012
|
||||
Initial release.
|
||||
|
||||
|
||||
Please visit http://cgg.mff.cuni.cz/projects/SkylightModelling/ to check if
|
||||
an updated version of this code has been published!
|
||||
|
||||
============================================================================ */
|
||||
|
||||
|
||||
/*
|
||||
|
||||
This file contains the coefficient data for the spectral version of the model.
|
||||
|
||||
*/
|
||||
|
||||
// uses Aug 23 dataset
|
||||
|
||||
package net.torvald.parametricsky.datasets
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
object DatasetRGB {
|
||||
|
||||
val datasetRGB1 = DatasetOp.readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetRGB1.bin")
|
||||
val datasetRGB2 = DatasetOp.readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetRGB2.bin")
|
||||
val datasetRGB3 = DatasetOp.readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetRGB3.bin")
|
||||
|
||||
val datasetRGBRad1 = DatasetOp.readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetRGBRad1.bin")
|
||||
val datasetRGBRad2 = DatasetOp.readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetRGBRad2.bin")
|
||||
val datasetRGBRad3 = DatasetOp.readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetRGBRad3.bin")
|
||||
|
||||
init {
|
||||
assertEquals(1080, datasetRGB2.size, "Dataset size mismatch: expected 1080, got ${datasetRGB2.size}")
|
||||
assertEquals(120, datasetRGBRad2.size, "Dataset size mismatch: expected 120, got ${datasetRGBRad2.size}")
|
||||
|
||||
assertEquals( -1.099459e+000, datasetRGB1[0], "Dataset not parsed correctly - expected ${-1.099459e+000}, got ${datasetRGB1[0]}")
|
||||
}
|
||||
|
||||
val datasetsRGB = arrayOf(
|
||||
datasetRGB1,
|
||||
datasetRGB2,
|
||||
datasetRGB3
|
||||
)
|
||||
|
||||
val datasetsRGBRad = arrayOf(
|
||||
datasetRGBRad1,
|
||||
datasetRGBRad2,
|
||||
datasetRGBRad3
|
||||
)
|
||||
}
|
||||
232
src/net/torvald/parametricsky/datasets/DatasetSpectral.kt
Normal file
232
src/net/torvald/parametricsky/datasets/DatasetSpectral.kt
Normal file
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
This source is published under the following 3-clause BSD license.
|
||||
|
||||
Copyright (c) 2012 - 2013, Lukas Hosek and Alexander Wilkie
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* None of the names of the contributors may be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES
|
||||
LOSS OF USE, DATA, OR PROFITS OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
/* ============================================================================
|
||||
|
||||
This file is part of a sample implementation of the analytical skylight and
|
||||
solar radiance models presented in the SIGGRAPH 2012 paper
|
||||
|
||||
|
||||
"An Analytic Model for Full Spectral Sky-Dome Radiance"
|
||||
|
||||
and the 2013 IEEE CG&A paper
|
||||
|
||||
"Adding a Solar Radiance Function to the Hosek Skylight Model"
|
||||
|
||||
both by
|
||||
|
||||
Lukas Hosek and Alexander Wilkie
|
||||
Charles University in Prague, Czech Republic
|
||||
|
||||
|
||||
Version: 1.4a, February 22nd, 2013
|
||||
|
||||
Version history:
|
||||
|
||||
1.4a February 22nd, 2013
|
||||
Removed unnecessary and counter-intuitive solar radius parameters
|
||||
from the interface of the colourspace sky dome initialisation functions.
|
||||
|
||||
1.4 February 11th, 2013
|
||||
Fixed a bug which caused the relative brightness of the solar disc
|
||||
and the sky dome to be off by a factor of about 6. The sun was too
|
||||
bright: this affected both normal and alien sun scenarios. The
|
||||
coefficients of the solar radiance function were changed to fix this.
|
||||
|
||||
1.3 January 21st, 2013 (not released to the public)
|
||||
Added support for solar discs that are not exactly the same size as
|
||||
the terrestrial sun. Also added support for suns with a different
|
||||
emission spectrum ("Alien World" functionality).
|
||||
|
||||
1.2a December 18th, 2012
|
||||
Fixed a mistake and some inaccuracies in the solar radiance function
|
||||
explanations found in ArHosekSkyModel.h. The actual source code is
|
||||
unchanged compared to version 1.2.
|
||||
|
||||
1.2 December 17th, 2012
|
||||
Native RGB data and a solar radiance function that matches the turbidity
|
||||
conditions were added.
|
||||
|
||||
1.1 September 2012
|
||||
The coefficients of the spectral model are now scaled so that the output
|
||||
is given in physical units: W / (m^-2 * sr * nm). Also, the output of the
|
||||
XYZ model is now no longer scaled to the range [0...1]. Instead, it is
|
||||
the result of a simple conversion from spectral data via the CIE 2 degree
|
||||
standard observer matching functions. Therefore, after multiplication
|
||||
with 683 lm / W, the Y channel now corresponds to luminance in lm.
|
||||
|
||||
1.0 May 11th, 2012
|
||||
Initial release.
|
||||
|
||||
|
||||
Please visit http://cgg.mff.cuni.cz/projects/SkylightModelling/ to check if
|
||||
an updated version of this code has been published!
|
||||
|
||||
============================================================================ */
|
||||
|
||||
|
||||
/*
|
||||
|
||||
This file contains the coefficient data for the spectral version of the model.
|
||||
|
||||
*/
|
||||
|
||||
// uses Apr 26 dataset
|
||||
|
||||
package net.torvald.parametricsky.datasets
|
||||
|
||||
import net.torvald.parametricsky.datasets.DatasetOp.readDatasetFromFile
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
object DatasetSpectral {
|
||||
|
||||
val dataset320 = readDatasetFromFile("./work_files/skylight/hosek_model_source/dataset320.bin")
|
||||
val dataset360 = readDatasetFromFile("./work_files/skylight/hosek_model_source/dataset360.bin")
|
||||
val dataset400 = readDatasetFromFile("./work_files/skylight/hosek_model_source/dataset400.bin")
|
||||
val dataset440 = readDatasetFromFile("./work_files/skylight/hosek_model_source/dataset440.bin")
|
||||
val dataset480 = readDatasetFromFile("./work_files/skylight/hosek_model_source/dataset480.bin")
|
||||
val dataset520 = readDatasetFromFile("./work_files/skylight/hosek_model_source/dataset520.bin")
|
||||
val dataset560 = readDatasetFromFile("./work_files/skylight/hosek_model_source/dataset560.bin")
|
||||
val dataset600 = readDatasetFromFile("./work_files/skylight/hosek_model_source/dataset600.bin")
|
||||
val dataset640 = readDatasetFromFile("./work_files/skylight/hosek_model_source/dataset640.bin")
|
||||
val dataset680 = readDatasetFromFile("./work_files/skylight/hosek_model_source/dataset680.bin")
|
||||
val dataset720 = readDatasetFromFile("./work_files/skylight/hosek_model_source/dataset720.bin")
|
||||
|
||||
val datasetRad320 = readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetRad320.bin")
|
||||
val datasetRad360 = readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetRad360.bin")
|
||||
val datasetRad400 = readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetRad400.bin")
|
||||
val datasetRad440 = readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetRad440.bin")
|
||||
val datasetRad480 = readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetRad480.bin")
|
||||
val datasetRad520 = readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetRad520.bin")
|
||||
val datasetRad560 = readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetRad560.bin")
|
||||
val datasetRad600 = readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetRad600.bin")
|
||||
val datasetRad640 = readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetRad640.bin")
|
||||
val datasetRad680 = readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetRad680.bin")
|
||||
val datasetRad720 = readDatasetFromFile("./work_files/skylight/hosek_model_source/datasetRad720.bin")
|
||||
|
||||
val solarDataset320 = readDatasetFromFile("./work_files/skylight/hosek_model_source/solarDataset320.bin")
|
||||
val solarDataset360 = readDatasetFromFile("./work_files/skylight/hosek_model_source/solarDataset360.bin")
|
||||
val solarDataset400 = readDatasetFromFile("./work_files/skylight/hosek_model_source/solarDataset400.bin")
|
||||
val solarDataset440 = readDatasetFromFile("./work_files/skylight/hosek_model_source/solarDataset440.bin")
|
||||
val solarDataset480 = readDatasetFromFile("./work_files/skylight/hosek_model_source/solarDataset480.bin")
|
||||
val solarDataset520 = readDatasetFromFile("./work_files/skylight/hosek_model_source/solarDataset520.bin")
|
||||
val solarDataset560 = readDatasetFromFile("./work_files/skylight/hosek_model_source/solarDataset560.bin")
|
||||
val solarDataset600 = readDatasetFromFile("./work_files/skylight/hosek_model_source/solarDataset600.bin")
|
||||
val solarDataset640 = readDatasetFromFile("./work_files/skylight/hosek_model_source/solarDataset640.bin")
|
||||
val solarDataset680 = readDatasetFromFile("./work_files/skylight/hosek_model_source/solarDataset680.bin")
|
||||
val solarDataset720 = readDatasetFromFile("./work_files/skylight/hosek_model_source/solarDataset720.bin")
|
||||
|
||||
init {
|
||||
assertEquals(1080, dataset600.size, "Dataset size mismatch - expected 1080, got ${dataset600.size}")
|
||||
assertEquals(120, datasetRad600.size, "Dataset size mismatch - expected 120, got ${datasetRad600.size}")
|
||||
assertEquals(1800, solarDataset600.size, "Dataset size mismatch - expected 1800, got ${solarDataset600.size}")
|
||||
|
||||
assertEquals(-1.341049e+001, dataset320[0], "Dataset not parsed correctly - expected ${-1.341049e+001}, got ${dataset320[0]}")
|
||||
}
|
||||
|
||||
val datasets = arrayOf(
|
||||
dataset320,
|
||||
dataset360,
|
||||
dataset400,
|
||||
dataset440,
|
||||
dataset480,
|
||||
dataset520,
|
||||
dataset560,
|
||||
dataset600,
|
||||
dataset640,
|
||||
dataset680,
|
||||
dataset720
|
||||
)
|
||||
|
||||
val datasetsRad = arrayOf(
|
||||
datasetRad320,
|
||||
datasetRad360,
|
||||
datasetRad400,
|
||||
datasetRad440,
|
||||
datasetRad480,
|
||||
datasetRad520,
|
||||
datasetRad560,
|
||||
datasetRad600,
|
||||
datasetRad640,
|
||||
datasetRad680,
|
||||
datasetRad720
|
||||
)
|
||||
|
||||
val solarDatasets = arrayOf(
|
||||
solarDataset320,
|
||||
solarDataset360,
|
||||
solarDataset400,
|
||||
solarDataset440,
|
||||
solarDataset480,
|
||||
solarDataset520,
|
||||
solarDataset560,
|
||||
solarDataset600,
|
||||
solarDataset640,
|
||||
solarDataset680,
|
||||
solarDataset720
|
||||
)
|
||||
|
||||
val limbDarkeningDataset320 = doubleArrayOf(0.087657, 0.767174, 0.658123, -1.02953, 0.703297, -0.186735)
|
||||
|
||||
val limbDarkeningDataset360 = doubleArrayOf(0.122953, 1.01278, 0.238687, -1.12208, 1.17087, -0.424947)
|
||||
|
||||
val limbDarkeningDataset400 = doubleArrayOf(0.123511, 1.08444, -0.405598, 0.370629, -0.240567, 0.0674778)
|
||||
|
||||
val limbDarkeningDataset440 = doubleArrayOf(0.158489, 1.23346, -0.875754, 0.857812, -0.484919, 0.110895)
|
||||
|
||||
val limbDarkeningDataset480 = doubleArrayOf(0.198587, 1.30507, -1.25998, 1.49727, -1.04047, 0.299516)
|
||||
|
||||
val limbDarkeningDataset520 = doubleArrayOf(0.23695, 1.29927, -1.28034, 1.37760, -0.85054, 0.21706)
|
||||
|
||||
val limbDarkeningDataset560 = doubleArrayOf(0.26892, 1.34319, -1.58427, 1.91271, -1.31350, 0.37295)
|
||||
|
||||
val limbDarkeningDataset600 = doubleArrayOf(0.299804, 1.36718, -1.80884, 2.29294, -1.60595, 0.454874)
|
||||
|
||||
val limbDarkeningDataset640 = doubleArrayOf(0.33551, 1.30791, -1.79382, 2.44646, -1.89082, 0.594769)
|
||||
|
||||
val limbDarkeningDataset680 = doubleArrayOf(0.364007, 1.27316, -1.73824, 2.28535, -1.70203, 0.517758)
|
||||
|
||||
val limbDarkeningDataset720 = doubleArrayOf(0.389704, 1.2448, -1.69708, 2.14061, -1.51803, 0.440004)
|
||||
|
||||
val limbDarkeningDatasets = arrayOf(
|
||||
limbDarkeningDataset320,
|
||||
limbDarkeningDataset360,
|
||||
limbDarkeningDataset400,
|
||||
limbDarkeningDataset440,
|
||||
limbDarkeningDataset480,
|
||||
limbDarkeningDataset520,
|
||||
limbDarkeningDataset560,
|
||||
limbDarkeningDataset600,
|
||||
limbDarkeningDataset640,
|
||||
limbDarkeningDataset680,
|
||||
limbDarkeningDataset720
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user