Read the obj file as ByteString and pass ByteString to the Parser
This commit is contained in:
parent
2d7a62770a
commit
e673fee652
@ -2,6 +2,7 @@
|
||||
|
||||
module CLI.Gif where
|
||||
|
||||
import qualified Data.ByteString.Char8 as B
|
||||
import Diagrams.Backend.Cairo.CmdLine
|
||||
import Graphics.Diagram.Gif
|
||||
import MyPrelude
|
||||
@ -9,5 +10,5 @@ import MyPrelude
|
||||
|
||||
gifCLI :: FilePath -> IO ()
|
||||
gifCLI _ = do
|
||||
mesh <- readFile "UB1_sonderfaelle.obj"
|
||||
mesh <- B.readFile "UB1_sonderfaelle.obj"
|
||||
gifMain (gifDiagS def mesh)
|
||||
|
@ -5,6 +5,7 @@ module GUI.Gtk (makeGUI) where
|
||||
import Control.Applicative
|
||||
import Control.Monad(unless)
|
||||
import Control.Monad.IO.Class
|
||||
import qualified Data.ByteString.Char8 as B
|
||||
import Diagrams.Prelude
|
||||
import Diagrams.Backend.Cairo
|
||||
import Diagrams.Backend.Cairo.Internal
|
||||
@ -235,7 +236,7 @@ saveAndDrawDiag :: FilePath -- ^ obj file to parse
|
||||
saveAndDrawDiag fp fps mygui =
|
||||
if (==) ".obj" . takeExtension $ fp
|
||||
then do
|
||||
mesh <- readFile fp
|
||||
mesh <- B.readFile fp
|
||||
mainDrawWindow <- widgetGetDrawWindow (mainDraw mygui)
|
||||
treeDrawWindow <- widgetGetDrawWindow (treeDraw mygui)
|
||||
adjustment <- rangeGetAdjustment (ptScale mygui)
|
||||
|
@ -5,6 +5,7 @@ module Graphics.Diagram.Gif where
|
||||
import Algebra.VectorTypes
|
||||
import Algorithms.ConvexHull.GrahamScan
|
||||
import Codec.Picture.Gif
|
||||
import qualified Data.ByteString.Char8 as B
|
||||
import Data.Monoid
|
||||
import Diagrams.Backend.Cairo
|
||||
import Diagrams.Prelude hiding ((<>))
|
||||
@ -33,5 +34,5 @@ gifDiag p xs =
|
||||
|
||||
-- |Same as gifDiag, except that it takes a string containing the
|
||||
-- mesh file content instead of the the points.
|
||||
gifDiagS :: DiagProp -> MeshString -> [(Diagram Cairo R2, GifDelay)]
|
||||
gifDiagS :: DiagProp -> B.ByteString -> [(Diagram Cairo R2, GifDelay)]
|
||||
gifDiagS p = gifDiag p . filterValidPT p . meshToArr
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
module Graphics.Diagram.Gtk where
|
||||
|
||||
import qualified Data.ByteString.Char8 as B
|
||||
import Diagrams.Backend.Cairo
|
||||
import Diagrams.Prelude
|
||||
import Graphics.Diagram.Plotter
|
||||
@ -36,7 +37,7 @@ diag p objs@(Objects _)
|
||||
|
||||
-- |Create the Diagram from a String which is supposed to be the contents
|
||||
-- of an obj file.
|
||||
diagS :: DiagProp -> MeshString -> Diagram Cairo R2
|
||||
diagS :: DiagProp -> B.ByteString -> Diagram Cairo R2
|
||||
diagS p mesh
|
||||
| algo p == 2 || algo p == 3 =
|
||||
diag p
|
||||
@ -49,7 +50,7 @@ diagS p mesh
|
||||
|
||||
-- |Create the tree diagram from a String which is supposed to be the contents
|
||||
-- of an obj file.
|
||||
diagTreeS :: DiagProp -> MeshString -> Diagram Cairo R2
|
||||
diagTreeS :: DiagProp -> B.ByteString -> Diagram Cairo R2
|
||||
diagTreeS p mesh
|
||||
| algo p == 4 = mkDiag treePretty p (Object
|
||||
. filterValidPT p
|
||||
|
@ -12,24 +12,23 @@ import Diagrams.TwoD.Types
|
||||
|
||||
-- |Convert a text String with multiple vertices and faces into
|
||||
-- a list of vertices, ordered by the faces specification.
|
||||
facesToArr :: String -> [[PT]]
|
||||
facesToArr :: B.ByteString -> [[PT]]
|
||||
facesToArr str = fmap (fmap (\y -> meshs str !! (fromIntegral y - 1)))
|
||||
(faces str)
|
||||
where
|
||||
meshs = meshToArr
|
||||
faces = rights . fmap (parseOnly parseFace) . B.lines . B.pack
|
||||
faces = rights . fmap (parseOnly parseFace) . B.lines
|
||||
|
||||
|
||||
-- |Convert a text String with multiple vertices into
|
||||
-- an array of float tuples.
|
||||
meshToArr :: String -- ^ the string to convert
|
||||
-> [PT] -- ^ the resulting vertice table
|
||||
meshToArr :: B.ByteString -- ^ the string to convert
|
||||
-> [PT] -- ^ the resulting vertice table
|
||||
meshToArr =
|
||||
fmap p2
|
||||
. rights
|
||||
. fmap (parseOnly parseVertice)
|
||||
. B.lines
|
||||
. B.pack
|
||||
|
||||
|
||||
-- |Creates a Parser that accepts a single vertice, such as 'v 1.0 2.0'.
|
||||
|
Loading…
Reference in New Issue
Block a user