Skip to content
Permalink
Browse files

Removed line from pom; melted drawSpline into constructor of CurveGeo…

…metry; renamed CurveGeometry to Curve; created a new test for the Catmullromspline.
  • Loading branch information
Domino2357 committed Mar 24, 2020
1 parent 31e0def commit a785dbd24ab360c9e914616cff585064e933456b
@@ -541,7 +541,6 @@
<artifactId>lwjgl3-awt</artifactId>
<version>${lwjgl3-awt.version}</version>
</dependency>

</dependencies>

<repositories>
@@ -15,7 +15,7 @@ import kotlin.math.acos
* The number n corresponds to the number of segments you wish to have between you control points.
* @author Justin Buerger <burger@mpi-cbg.de>
*/
class CurveGeometry(curve: CatmullRomSpline, n: Int = 100): Node("CurveGeometry"), HasGeometry {
class Curve(curve: CatmullRomSpline, baseShape: () -> ArrayList<GLVector>): Node("CurveGeometry"), HasGeometry {
override val vertexSize = 3
override val texcoordSize = 2
override var geometryType = GeometryType.TRIANGLES
@@ -25,7 +25,7 @@ class CurveGeometry(curve: CatmullRomSpline, n: Int = 100): Node("CurveGeometry"
override var texcoords: FloatBuffer = BufferUtils.allocateFloat(0)
override var indices: IntBuffer = BufferUtils.allocateInt(0)

private val curve = curve.catMullRomChain()
private val chain = curve.catMullRomChain()

/**
* This function renders the spline.
@@ -35,9 +35,9 @@ class CurveGeometry(curve: CatmullRomSpline, n: Int = 100): Node("CurveGeometry"
* a banister. Please not that the base shape needs an equal number of points in each segments but it
* can very well vary in thickness.
*/
fun drawSpline(baseShape: (() -> List<GLVector>)) {
init {
val bases = ArrayList<GLMatrix>()
computeFrenetFrames(curve).forEach { (t, n, b, tr) ->
computeFrenetFrames(chain).forEach { (t, n, b, tr) ->
if(n != null && b != null) {
val inverseMatrix = GLMatrix(floatArrayOf(
n.x(), b.x(), t.x(), 0f,
@@ -83,12 +83,12 @@ class CurveGeometry(curve: CatmullRomSpline, n: Int = 100): Node("CurveGeometry"
* [i] index of the curve (not the geometry!)
*/
private fun getTangent(i: Int): GLVector {
val s = curve.size
val s = chain.size
return when(i) {
0 -> ((curve[i+1] - curve[i]).normalized)
(s-2) -> ((curve[i+1] - curve[i]).normalized)
(s-1) -> ((curve[i] - curve[i-1]).normalized)
else -> ((curve[i+1] - curve[i-1]).normalized)
0 -> ((chain[i+1] - chain[i]).normalized)
(s-2) -> ((chain[i+1] - chain[i]).normalized)
(s-1) -> ((chain[i] - chain[i-1]).normalized)
else -> ((chain[i+1] - chain[i-1]).normalized)
}
}

@@ -204,6 +204,6 @@ class CurveGeometry(curve: CatmullRomSpline, n: Int = 100): Node("CurveGeometry"
* Getter for the curve.
*/
fun getCurve(): ArrayList<GLVector> {
return curve
return chain
}
}
@@ -13,7 +13,7 @@ import org.junit.Test
*
* @author Justin Bürger
*/
class CurveGeometryBaseShapeTest: SceneryBase("CurveGeometryBaseShapeTest", windowWidth = 1280, windowHeight = 720) {
class CurveBaseShapeTest: SceneryBase("CurveGeometryBaseShapeTest", windowWidth = 1280, windowHeight = 720) {

override fun init() {

@@ -31,10 +31,6 @@ class CurveGeometryBaseShapeTest: SceneryBase("CurveGeometryBaseShapeTest", wind
points.add(GLVector(0f, 0f, 0f))
points.add(GLVector(2f, 1f, 0f))



val catmullRom = CatmullRomSpline(points)
val geo = CurveGeometry(catmullRom, 200)
fun triangle(): ArrayList<GLVector> {
val list = ArrayList<GLVector>()
list.add(GLVector(0.3f, 0.3f, 0f))
@@ -43,9 +39,8 @@ class CurveGeometryBaseShapeTest: SceneryBase("CurveGeometryBaseShapeTest", wind
return list
}


geo.drawSpline { triangle() }

val catmullRom = CatmullRomSpline(points)
val geo = Curve(catmullRom) { triangle() }

scene.addChild(geo)

@@ -19,8 +19,8 @@ class CatmullRomSplineTests {
* Tests if the curve object has actually the number of points defined in the class.
*/
@Test
fun testCreation() {
logger.info("This is the test for the CatmullRomSpline.")
fun testLength() {
logger.info("This is the test for the Length of the chain.")
val point1 = Random.randomVectorFromRange(3, -30f, -10f)
val point2 = Random.randomVectorFromRange(3, -9f, 20f)
val point3 = Random.randomVectorFromRange(3, 21f, 30f)
@@ -37,4 +37,27 @@ class CatmullRomSplineTests {
assertTrue(curve.catMullRomChain().size == 100 || curve.catMullRomChain().size == 101)
}

/**
* This test verifies that the points created by the Catmull Rom Spline are sufficiently equidistant.
*/
@Test
fun testChain() {
logger.info("This is the test for the Length of the chain.")
val point1 = Random.randomVectorFromRange(3, -30f, -10f)
val point2 = Random.randomVectorFromRange(3, -9f, 20f)
val point3 = Random.randomVectorFromRange(3, 21f, 30f)
val point4 = Random.randomVectorFromRange(3, 31f, 100f)

val controlPoints = arrayListOf(point1, point2, point3, point4)

val curve = CatmullRomSpline(controlPoints)
val chain = curve.catMullRomChain()
val i = Random.randomFromRange(1f, 98f).toInt()
val distance = chain[i].minus(chain[i+1]).length2()
val distanceDifferences = chain.windowed(2, 1) {
it[0].minus(it[1]).length2().minus(distance) }.toList()
println(distanceDifferences)
assertTrue { distanceDifferences.filter { it < 0.1 } == distanceDifferences }
}

}
@@ -3,19 +3,19 @@ package graphics.scenery.tests.unit
import cleargl.GLVector
import graphics.scenery.numerics.Random
import graphics.scenery.CatmullRomSpline
import graphics.scenery.CurveGeometry
import graphics.scenery.Curve
import graphics.scenery.utils.LazyLogger
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertFails
import kotlin.test.assertNotNull

/**
* This is the test class for the [CurveGeometry]
* This is the test class for the [Curve]
*
* @author Justin Bürger, burger@mpi-cbg.com
*/
class CurveGeometryTests {
class CurveTests {
private val logger by LazyLogger()

/**
@@ -33,7 +33,15 @@ class CurveGeometryTests {

val curve = CatmullRomSpline(controlPoints)

val geometry = CurveGeometry(curve)
fun triangle(): ArrayList<GLVector> {
val list = ArrayList<GLVector>()
list.add(GLVector(0.3f, 0.3f, 0f))
list.add(GLVector(0.3f, -0.3f, 0f))
list.add(GLVector(-0.3f, -0.3f, 0f))
return list
}

val geometry = Curve(curve) { triangle() }
val frenetFrames = geometry.computeFrenetFrames(geometry.getCurve())

assertEquals(curve.catMullRomChain(), geometry.getCurve())
@@ -62,8 +70,6 @@ class CurveGeometryTests {

val curve = CatmullRomSpline(controlPoints)

val geometry = CurveGeometry(curve)

/*
For this baseShape function the number of points may differ each time
the baseShape function is invoked. However, the algorithm for calculating
@@ -84,7 +90,7 @@ class CurveGeometryTests {
}
}

assertFails { geometry.drawSpline { triangleFalse() } }
assertFails { Curve(curve) { triangleFalse() } }
}

}

0 comments on commit a785dbd

Please sign in to comment.
You can’t perform that action at this time.