Rasterific-0.7.2.1: A pure haskell drawing engine.

Safe HaskellNone
LanguageHaskell2010

Graphics.Rasterific.Patch

Contents

Description

Implementation using "An efficient algorithm for subdivising linear Coons surfaces" C.Yao and J.Rokne Computer aided design 8 (1991) 291-303

Synopsis

Types

data CoonPatch weight #

Define the boundary and interpolated values of a coon patch.

                       ----->
                 North     _____----------------+
  ^          +------------/                     / .
  |         /                                  /       |
  |        /                                  /        |
  |       /                                  /  east   |
  | west |                                  /          |
         |                                 |           v
          \                                 \   .
           \                  __-------------+
            +----------------/
                   South
                      <-----

Constructors

CoonPatch 

Fields

Instances

Show weight => Show (CoonPatch weight) # 

Methods

showsPrec :: Int -> CoonPatch weight -> ShowS #

show :: CoonPatch weight -> String #

showList :: [CoonPatch weight] -> ShowS #

PointFoldable (CoonPatch px) # 

Methods

foldPoints :: (b -> Point -> b) -> b -> CoonPatch px -> b #

Transformable (CoonPatch px) # 

Methods

transform :: (Point -> Point) -> CoonPatch px -> CoonPatch px #

transformM :: Monad m => (Point -> m Point) -> CoonPatch px -> m (CoonPatch px) #

data TensorPatch weight #

Describe a tensor patch

Instances

PointFoldable (TensorPatch px) # 

Methods

foldPoints :: (b -> Point -> b) -> b -> TensorPatch px -> b #

Transformable (TensorPatch px) # 

Methods

transform :: (Point -> Point) -> TensorPatch px -> TensorPatch px #

transformM :: Monad m => (Point -> m Point) -> TensorPatch px -> m (TensorPatch px) #

data ParametricValues a #

Values associated to the corner of a patch

 North               East
     +--------------+
     |0            1|
     |              |
     |              |
     |              |
     |3            2|
     +--------------+
 West                South

Constructors

ParametricValues 

Fields

Instances

Functor ParametricValues # 

Methods

fmap :: (a -> b) -> ParametricValues a -> ParametricValues b #

(<$) :: a -> ParametricValues b -> ParametricValues a #

Applicative ParametricValues # 
Foldable ParametricValues # 

Methods

fold :: Monoid m => ParametricValues m -> m #

foldMap :: Monoid m => (a -> m) -> ParametricValues a -> m #

foldr :: (a -> b -> b) -> b -> ParametricValues a -> b #

foldr' :: (a -> b -> b) -> b -> ParametricValues a -> b #

foldl :: (b -> a -> b) -> b -> ParametricValues a -> b #

foldl' :: (b -> a -> b) -> b -> ParametricValues a -> b #

foldr1 :: (a -> a -> a) -> ParametricValues a -> a #

foldl1 :: (a -> a -> a) -> ParametricValues a -> a #

toList :: ParametricValues a -> [a] #

null :: ParametricValues a -> Bool #

length :: ParametricValues a -> Int #

elem :: Eq a => a -> ParametricValues a -> Bool #

maximum :: Ord a => ParametricValues a -> a #

minimum :: Ord a => ParametricValues a -> a #

sum :: Num a => ParametricValues a -> a #

product :: Num a => ParametricValues a -> a #

Show a => Show (ParametricValues a) # 
(Pixel px, Modulable (PixelBaseComponent px)) => BiSampleable (ParametricValues px) px #

Basic bilinear interpolator

Methods

interpolate :: ParametricValues px -> Float -> Float -> px #

data PatchInterpolation #

How do we want to perform color/image interpolation within the patch.

Constructors

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.

Constructors

Subdivided 

Fields

class (Applicative (Holder a), Functor (Holder a), Foldable (Holder a), Additive (Holder a)) => InterpolablePixel a #

Used for Coon patch rendering

Minimal complete definition

toFloatPixel, fromFloatPixel, maxRepresentable

Instances

InterpolablePixel Float # 

Associated Types

type Holder Float :: * -> *

InterpolablePixel Word8 # 

Associated Types

type Holder Word8 :: * -> *

InterpolablePixel PixelRGB8 # 

Associated Types

type Holder PixelRGB8 :: * -> *

InterpolablePixel PixelRGBA8 # 

Associated Types

type Holder PixelRGBA8 :: * -> *

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.

renderCoonPatchAtDeepness #

Arguments

:: (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.

defaultDebug :: 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