packages feed

ply-loader 0.1.1.1 → 0.1.1.2

raw patch · 3 files changed

+25/−19 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- PLY.Data: loadMeshesV3 :: (PLYType a, Fractional a) => FilePath -> ByteString -> IO (Either [String] (Vector (V3 a)))
+ PLY.Data: loadMeshesV3 :: (PLYType a, Fractional a, Conjugate a, RealFloat a) => FilePath -> ByteString -> IO (Either [String] (Vector (V3 a)))

Files

ply-loader.cabal view
@@ -1,5 +1,5 @@ name:                ply-loader-version:             0.1.1.1+version:             0.1.1.2 synopsis:            PLY file loader.  description:         PLY is a lightweight file format for representing 3D@@ -49,7 +49,7 @@  executable ply2bin   main-is:          Main.hs-  ghc-options:      -O2 -Wall -threaded+  ghc-options:      -O2 -Wall -threaded "-with-rtsopts=-N"   hs-source-dirs:   src/executable   build-depends:    base >= 4.6 && < 5,                      bytestring >= 0.10,
src/PLY/Conf.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE OverloadedStrings #-}--- |Parse Stanford 3D Scanning Repository ".conf" files that place+-- |Parse Stanford 3D Scanning Repository \"@.conf@\" files that place -- individual PLY models into a consistent coordinate frame. module PLY.Conf (parseConf, Transformation, Conf(..)) where import Control.Applicative@@ -24,7 +24,9 @@ transformation :: Parser (V3 Double, Quaternion Double) transformation = (,) <$> vec <*> rotation   where vec = (\[x,y,z] -> V3 x y z) <$> count 3 (skipSpace *> double)-        rotation = Quaternion <$> (skipSpace *> double) <*> vec+        rotation = flip Quaternion <$> vec <*> (skipSpace *> double)+        --rotation = Quaternion <$> (skipSpace *> double) <*> vec+        --rev (V3 x y z) = V3 z y x  -- |Parse a mesh file specification. mesh :: Parser (ByteString, Transformation Double)
src/PLY/Data.hs view
@@ -23,7 +23,6 @@                  loadMeshesV3, loadHeader) where import Control.Applicative import Control.Concurrent.ParallelIO (parallel)-import Control.Lens (view) import Data.Attoparsec.Char8 import Data.ByteString (ByteString) import qualified Data.ByteString as BS@@ -32,9 +31,7 @@ import Data.Vector (Vector) import qualified Data.Vector as V import qualified Data.Vector.Storable as VS-import Linear.Matrix (mkTransformation, (!*))-import Linear.V3-import Linear.V4 (vector)+import Linear import System.Directory (canonicalizePath) import System.FilePath (takeDirectory, (</>)) @@ -116,28 +113,35 @@ -- are loaded from the same directory that contained the @.conf@ file, -- and the data associated with @element@ (e.g. @\"vertex\"@) is -- loaded, transformed, and concatenated from all the meshes.-loadMeshesV3 :: forall a. (PLYType a, Fractional a) => +loadMeshesV3 :: forall a. (PLYType a, Fractional a, Conjugate a, RealFloat a) =>                 FilePath -> ByteString -> IO (Either [String] (VS.Vector (V3 a))) loadMeshesV3 confFile element = do dir <- takeDirectory <$>                                            canonicalizePath confFile                                    c <- parseConf <$> BS.readFile confFile+                                   let cam = let Right (Conf (t,r) _) = c+                                             in fmap (fmap realToFrac) $+                                                mkTransformation r t                                    either (return . Left . (:[]))-                                          (fmap checkConcat . loadAllMeshes dir)+                                          (fmap checkConcat . loadAllMeshes dir cam)                                           c-    where checkErrors :: [Either String (VS.Vector (V3 a))] -> Either [String] [VS.Vector (V3 a)]+    where checkErrors :: [Either String (VS.Vector (V3 a))]+                      -> Either [String] [VS.Vector (V3 a)]           checkErrors xs = let (ls,rs) = partitionEithers xs                            in if null ls then Right rs else Left ls-          checkConcat :: [Either String (VS.Vector (V3 a))] -> Either [String] (VS.Vector (V3 a))+          checkConcat :: [Either String (VS.Vector (V3 a))]+                      -> Either [String] (VS.Vector (V3 a))           checkConcat = (fmap VS.concat $!) . checkErrors-          loadMesh :: FilePath -> (ByteString, Transformation Double) -> -                      IO (Either String (VS.Vector (V3 a)))-          loadMesh d (f, (t,r)) = -            let m = mkTransformation (fmap realToFrac r) (fmap realToFrac t)+          loadMesh :: FilePath -> M44 a -> (ByteString, Transformation Double)+                   -> IO (Either String (VS.Vector (V3 a)))+          loadMesh d _cam (f, (t,r)) = +            -- It is convenient to ignore the camera transformation so+            -- that the object is at the origin.+            let m = (^+^ fmap realToFrac t ) . rotate (conjugate (fmap realToFrac r))             in (loadPLY                  >=!> loadElementsV3 element-                >=!> return . VS.map (view _xyz . (m !*) . vector))+                >=!> return . VS.map m)                <$> BS.readFile (d </> BC.unpack f)-          loadAllMeshes :: FilePath -> Conf -> +          loadAllMeshes :: FilePath -> M44 a -> Conf ->                             IO ([Either String (VS.Vector (V3 a))])-          loadAllMeshes dir = parallel . map (loadMesh dir) . meshes+          loadAllMeshes dir cam = parallel . map (loadMesh dir cam) . meshes {-# INLINABLE loadMeshesV3 #-}