使用 CatmullRom 生成平滑曲线
This commit is contained in:
@@ -9,6 +9,8 @@ import com.icegps.orx.ktx.area
|
||||
import com.icegps.orx.ktx.toColorInt
|
||||
import com.icegps.orx.ktx.toMapboxPoint
|
||||
import com.icegps.orx.ktx.toast
|
||||
import com.icegps.orx.triangulation.DelaunayTriangulation3D
|
||||
import com.icegps.orx.triangulation.Triangle3D
|
||||
import com.icegps.shared.ktx.TAG
|
||||
import com.mapbox.geojson.Feature
|
||||
import com.mapbox.geojson.FeatureCollection
|
||||
@@ -30,8 +32,7 @@ import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import com.icegps.orx.triangulation.DelaunayTriangulation3D
|
||||
import com.icegps.orx.triangulation.Triangle3D
|
||||
import org.openrndr.extra.shapes.splines.CatmullRomChain2
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.shape.Rectangle
|
||||
@@ -294,10 +295,21 @@ class ContoursManager(
|
||||
style.addLayer(layer)
|
||||
}
|
||||
|
||||
private var useCatmullRom: Boolean = true
|
||||
|
||||
fun setCatmullRom(enabled: Boolean) {
|
||||
useCatmullRom = enabled
|
||||
}
|
||||
|
||||
fun contoursToLineFeatures(contours: List<ShapeContour>, color: Int): List<List<Feature>> {
|
||||
return contours.drop(1).map { contour ->
|
||||
contour.segments.map { segment ->
|
||||
LineString.fromLngLats(listOf(segment.start.toMapboxPoint(), segment.end.toMapboxPoint()))
|
||||
LineString.fromLngLats(
|
||||
listOf(
|
||||
segment.start.toMapboxPoint(),
|
||||
segment.end.toMapboxPoint()
|
||||
)
|
||||
)
|
||||
}.map { lineString ->
|
||||
Feature.fromGeometry(lineString).apply {
|
||||
// 将颜色Int转换为十六进制字符串
|
||||
@@ -311,6 +323,12 @@ class ContoursManager(
|
||||
val lists = contours.drop(0).filter { it.segments.isNotEmpty() }.map { contour ->
|
||||
val start = contour.segments[0].start
|
||||
listOf(start) + contour.segments.map { it.end }
|
||||
}.map {
|
||||
if (!useCatmullRom) return@map it
|
||||
val cmr = CatmullRomChain2(it, 1.0, loop = true)
|
||||
val contour = ShapeContour.fromPoints(cmr.positions(200), true)
|
||||
val start = contour.segments[0].start
|
||||
listOf(start) + contour.segments.map { it.end }
|
||||
}.map { points -> points.map { it.toMapboxPoint() } }
|
||||
|
||||
if (lists.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user