Rasterific-0.7.2.1: A pure haskell drawing engine.

Graphics.Rasterific.Patch

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_north :: !CubicBezierNorth border, from left to right at top_east :: !CubicBezierEast obrder, from top to bottom_south :: !CubicBezierSouth border from right to left_west :: !CubicBezierWest border from bottom to top_coonValues :: !weightThe patch values

Instances

 Show weight => Show (CoonPatch weight) # MethodsshowsPrec :: Int -> CoonPatch weight -> ShowS #show :: CoonPatch weight -> String #showList :: [CoonPatch weight] -> ShowS # # MethodsfoldPoints :: (b -> Point -> b) -> b -> CoonPatch px -> b # # Methodstransform :: (Point -> Point) -> CoonPatch px -> CoonPatch px #transformM :: Monad m => (Point -> m Point) -> CoonPatch px -> m (CoonPatch px) #

data TensorPatch weight #

Describe a tensor patch

Constructors

 TensorPatch Fields_curve0 :: !CubicBezier _curve1 :: !CubicBezier _curve2 :: !CubicBezier _curve3 :: !CubicBezier _tensorValues :: !weight

Instances

 # MethodsfoldPoints :: (b -> Point -> b) -> b -> TensorPatch px -> b # # Methodstransform :: (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_northValue :: !a _eastValue :: !a _southValue :: !a _westValue :: !a

Instances

 # Methodsfmap :: (a -> b) -> ParametricValues a -> ParametricValues b #(<$) :: a -> ParametricValues b -> ParametricValues a # # Methodspure :: a -> ParametricValues a #(<*>) :: ParametricValues (a -> b) -> ParametricValues a -> ParametricValues b # # Methodsfold :: 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] #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) # MethodsshowList :: [ParametricValues a] -> ShowS # (Pixel px, Modulable (PixelBaseComponent px)) => BiSampleable (ParametricValues px) px # Basic bilinear interpolator Methodsinterpolate :: ParametricValues px -> Float -> Float -> px # How do we want to perform color/image interpolation within the patch. Constructors  PatchBilinear Bilinear interpolationimport 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 interpolationimport 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 

Instances

 # Methods # MethodsshowList :: [PatchInterpolation] -> ShowS #

Type of coordinate interpolation

data Subdivided a #

Store the new generated information after subdivision in 4 quadrants.

Constructors

 Subdivided Fields_northWest :: !aUpper left_northEast :: !aUpper right_southWest :: !aLower left_southEast :: !aLower right

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

 # Associated Typestype Holder Float :: * -> * MethodstoFloatPixel :: Float -> Holder Float FloatfromFloatPixel :: Holder Float Float -> FloatmaxRepresentable :: Proxy Float -> Float # Associated Typestype Holder Word8 :: * -> * MethodstoFloatPixel :: Word8 -> Holder Word8 FloatfromFloatPixel :: Holder Word8 Float -> Word8maxRepresentable :: Proxy Word8 -> Float # Associated Typestype Holder PixelRGB8 :: * -> * MethodstoFloatPixel :: PixelRGB8 -> Holder PixelRGB8 FloatfromFloatPixel :: Holder PixelRGB8 Float -> PixelRGB8maxRepresentable :: Proxy PixelRGB8 -> Float # Associated Typestype Holder PixelRGBA8 :: * -> * MethodstoFloatPixel :: PixelRGBA8 -> Holder PixelRGBA8 FloatfromFloatPixel :: Holder PixelRGBA8 Float -> PixelRGBA8maxRepresentable :: Proxy PixelRGBA8 -> Float

# 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.

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.

Constructors

 DebugOption Fields

Default options drawing nearly everything.

drawCoonPatchOutline :: CoonPatch px -> Drawing pxb () #

Draw the 4 bezier spline representing the boundary of a coon patch.

Helper function drawing many information about a coon patch.

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


Swap vertical/horizontal orientation of a tensor patch