Safe Haskell | None |
---|---|
Language | Haskell2010 |
Implementation using "An efficient algorithm for subdivising linear Coons surfaces" C.Yao and J.Rokne Computer aided design 8 (1991) 291-303
- data CoonPatch weight = CoonPatch {
- _north :: !CubicBezier
- _east :: !CubicBezier
- _south :: !CubicBezier
- _west :: !CubicBezier
- _coonValues :: !weight
- data TensorPatch weight = TensorPatch {
- _curve0 :: !CubicBezier
- _curve1 :: !CubicBezier
- _curve2 :: !CubicBezier
- _curve3 :: !CubicBezier
- _tensorValues :: !weight
- data ParametricValues a = ParametricValues {
- _northValue :: !a
- _eastValue :: !a
- _southValue :: !a
- _westValue :: !a
- data PatchInterpolation
- type CoonColorWeight = Float
- data Subdivided a = Subdivided {
- _northWest :: !a
- _northEast :: !a
- _southWest :: !a
- _southEast :: !a
- class (Applicative (Holder a), Functor (Holder a), Foldable (Holder a), Additive (Holder a)) => InterpolablePixel a
- rasterizeTensorPatch :: (PrimMonad m, ModulablePixel px, BiSampleable src px) => TensorPatch src -> DrawContext m px ()
- rasterizeCoonPatch :: (PrimMonad m, ModulablePixel px, BiSampleable src px) => CoonPatch src -> DrawContext m px ()
- renderImageMesh :: PrimMonad m => MeshPatch (ImageMesh PixelRGBA8) -> DrawContext m PixelRGBA8 ()
- renderCoonMesh :: forall m px. (PrimMonad m, RenderablePixel px, BiSampleable (ParametricValues px) px) => MeshPatch px -> DrawContext m px ()
- renderCoonMeshBicubic :: forall m px. (PrimMonad m, RenderablePixel px, BiSampleable (CubicCoefficient px) px) => MeshPatch px -> DrawContext m px ()
- renderCoonPatch :: forall m interp px. (PrimMonad m, RenderablePixel px, BiSampleable interp px) => CoonPatch interp -> DrawContext m px ()
- renderCoonPatchAtDeepness :: forall m interp px. (PrimMonad m, RenderablePixel px, BiSampleable interp px) => Int -> CoonPatch interp -> DrawContext m px ()
- renderTensorPatch :: forall m sampled px. (PrimMonad m, RenderablePixel px, BiSampleable sampled px) => TensorPatch sampled -> DrawContext m px ()
- renderTensorPatchAtDeepness :: forall m sampled px. (PrimMonad m, RenderablePixel px, BiSampleable sampled px) => Int -> TensorPatch sampled -> DrawContext m px ()
- data DebugOption = DebugOption {}
- defaultDebug :: DebugOption
- drawCoonPatchOutline :: CoonPatch px -> Drawing pxb ()
- debugDrawCoonPatch :: DebugOption -> CoonPatch (ParametricValues PixelRGBA8) -> Drawing PixelRGBA8 ()
- debugDrawTensorPatch :: DebugOption -> TensorPatch (ParametricValues px) -> Drawing PixelRGBA8 ()
- parametricBase :: UVPatch
- subdividePatch :: CoonPatch UVPatch -> Subdivided (CoonPatch UVPatch)
- subdivideTensorPatch :: TensorPatch UVPatch -> Subdivided (TensorPatch UVPatch)
- horizontalTensorSubdivide :: TensorPatch UVPatch -> (TensorPatch UVPatch, TensorPatch UVPatch)
- transposePatch :: TensorPatch (ParametricValues a) -> TensorPatch (ParametricValues a)
Types
Define the boundary and interpolated values of a coon patch.
-----> North _____----------------+ ^ +------------/ / . | / / | | / / | | / / east | | west | / | | | v \ \ . \ __-------------+ +----------------/ South <-----
CoonPatch | |
|
Show weight => Show (CoonPatch weight) # | |
PointFoldable (CoonPatch px) # | |
Transformable (CoonPatch px) # | |
data TensorPatch weight #
Describe a tensor patch
TensorPatch | |
|
PointFoldable (TensorPatch px) # | |
Transformable (TensorPatch px) # | |
data ParametricValues a #
Values associated to the corner of a patch
North East +--------------+ |0 1| | | | | | | |3 2| +--------------+ West South
ParametricValues | |
|
Functor ParametricValues # | |
Applicative ParametricValues # | |
Foldable ParametricValues # | |
Show a => Show (ParametricValues a) # | |
(Pixel px, Modulable (PixelBaseComponent px)) => BiSampleable (ParametricValues px) px # | Basic bilinear interpolator |
data PatchInterpolation #
How do we want to perform color/image interpolation within the patch.
PatchBilinear | Bilinear interpolation import qualified Data.Vector as V let colorCycle = cycle [ PixelRGBA8 0 0x86 0xc1 255 , PixelRGBA8 0xff 0xf4 0xc1 255 , PixelRGBA8 0xFF 0x53 0x73 255 , PixelRGBA8 0xff 0xf4 0xc1 255 , PixelRGBA8 0 0x86 0xc1 255] colors = V.fromListN (4 * 4) colorCycle renderMeshPatch PatchBilinear $ generateLinearGrid 3 3 (V2 10 10) (V2 60 60) colors |
PatchBicubic | Bicubic interpolation import qualified Data.Vector as V let colorCycle = cycle [ PixelRGBA8 0 0x86 0xc1 255 , PixelRGBA8 0xff 0xf4 0xc1 255 , PixelRGBA8 0xFF 0x53 0x73 255 , PixelRGBA8 0xff 0xf4 0xc1 255 , PixelRGBA8 0 0x86 0xc1 255] colors = V.fromListN (4 * 4) colorCycle renderMeshPatch PatchBicubic $ generateLinearGrid 3 3 (V2 10 10) (V2 60 60) colors |
type CoonColorWeight = Float #
Type of coordinate interpolation
data Subdivided a #
Store the new generated information after subdivision in 4 quadrants.
Subdivided | |
|
class (Applicative (Holder a), Functor (Holder a), Foldable (Holder a), Additive (Holder a)) => InterpolablePixel a #
Used for Coon patch rendering
toFloatPixel, fromFloatPixel, maxRepresentable
Rendering functions
Using Fast Forward Differences
rasterizeTensorPatch :: (PrimMonad m, ModulablePixel px, BiSampleable src px) => TensorPatch src -> DrawContext m px () #
Rasterize a tensor patch using the Fast Forward Diffrence algorithm, likely to be faster than the subdivision one.
rasterizeCoonPatch :: (PrimMonad m, ModulablePixel px, BiSampleable src px) => CoonPatch src -> DrawContext m px () #
Rasterize a coon patch using the Fast Forward Diffrence algorithm, likely to be faster than the subdivision one.
renderImageMesh :: PrimMonad m => MeshPatch (ImageMesh PixelRGBA8) -> DrawContext m PixelRGBA8 () #
Render an mesh patch by interpolating accross an image.
renderCoonMesh :: forall m px. (PrimMonad m, RenderablePixel px, BiSampleable (ParametricValues px) px) => MeshPatch px -> DrawContext m px () #
Render a simple coon mesh, with only color on the vertices.
renderCoonMeshBicubic :: forall m px. (PrimMonad m, RenderablePixel px, BiSampleable (CubicCoefficient px) px) => MeshPatch px -> DrawContext m px () #
Render a coon mesh but using cubic interpolation for the color.
Subdivision patch rendering
renderCoonPatch :: forall m interp px. (PrimMonad m, RenderablePixel px, BiSampleable interp px) => CoonPatch interp -> DrawContext m px () #
Render a coon patch using the subdivision algorithm (potentially slower and less precise in case of image mesh.
:: (PrimMonad m, RenderablePixel px, BiSampleable interp px) | |
=> Int | Maximum subdivision deepness |
-> CoonPatch interp | |
-> DrawContext m px () |
Render a coon patch using the subdivision algorithm (potentially slower and less precise in case of image mesh). You can provide a max deepness
renderTensorPatch :: forall m sampled px. (PrimMonad m, RenderablePixel px, BiSampleable sampled px) => TensorPatch sampled -> DrawContext m px () #
renderTensorPatchAtDeepness :: forall m sampled px. (PrimMonad m, RenderablePixel px, BiSampleable sampled px) => Int -> TensorPatch sampled -> DrawContext m px () #
Render a tensor patch using the subdivision algorithm (potentially slower and less precise in case of image mesh.
Debugging
data DebugOption #
Used to describe how to debug print a coon/tensort patch.
DebugOption | |
|
Default options drawing nearly everything.
drawCoonPatchOutline :: CoonPatch px -> Drawing pxb () #
Draw the 4 bezier spline representing the boundary of a coon patch.
debugDrawCoonPatch :: DebugOption -> CoonPatch (ParametricValues PixelRGBA8) -> Drawing PixelRGBA8 () #
Helper function drawing many information about a coon patch.
debugDrawTensorPatch :: DebugOption -> TensorPatch (ParametricValues px) -> Drawing PixelRGBA8 () #
Helper function drawing many information about a tensor patch.
parametricBase :: UVPatch #
Define the unit square in [0, 1]^2
Manipulation
subdividePatch :: CoonPatch UVPatch -> Subdivided (CoonPatch UVPatch) #
Split a coon patch into four new quadrants
subdivideTensorPatch :: TensorPatch UVPatch -> Subdivided (TensorPatch UVPatch) #
Subdivide a tensor patch into 4 new quadrant. Perform twice the horizontal subdivision with a transposition.
horizontalTensorSubdivide :: TensorPatch UVPatch -> (TensorPatch UVPatch, TensorPatch UVPatch) #
Perform an operation like:
o--------o--------o--------o | | | | | | | | | | | | o--------o--------o--------o | | | | | | | | | | | | o--------o--------o--------o | | | | | | | | | | | | o--------o--------o--------o | | | | | | | | | | | | o--------o--------o--------o to (more or less) o----*---o----*----o----*---o | | | | | | | | | | | | | | | | | | | | | o----*---o----*----o----*---o | | | | | | | | | | | | | | | | | | | | | o----*---o----*----o----*---o | | | | | | | | | | | | | | | | | | | | | o----*---o----*----o----*---o | | | | | | | | | | | | | | | | | | | | | o----*---o----*----o----*---o ------------------------- Left Right
transposePatch :: TensorPatch (ParametricValues a) -> TensorPatch (ParametricValues a) #
Swap vertical/horizontal orientation of a tensor patch