Guest User

Untitled

a guest
Dec 11th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. {-# OPTIONS_GHC -threaded -O2 #-}
  2. {-# LANGUAGE OverloadedStrings #-}
  3.  
  4. -- This benchmark was executed with the following options:
  5. -- -s 100 +RTS -N1 -RTS
  6.  
  7. import Criterion.Main
  8. import Graphics.Implicit
  9.  
  10. import Graphics.Implicit.Export.TextBuilderUtils
  11. import Graphics.Implicit.Definitions
  12. import Graphics.Implicit.Export.Definitions
  13. import Graphics.Implicit.Export.SymbolicObj2
  14. import Graphics.Implicit.Export.SymbolicObj3
  15.  
  16. import qualified Data.Text.Lazy.IO as TextIO
  17.  
  18.  
  19. formatWithLazyText triangles = toLazyText $ stlHeader <> mconcat (map triangle triangles) <> stlFooter
  20. where
  21. stlHeader = "solid ImplictCADExport\n"
  22. stlFooter = "endsolid ImplictCADExport\n"
  23. vertex :: ℝ3 -> Builder
  24. vertex (x,y,z) = mconcat ["vertex "
  25. ,bf x , " "
  26. ,bf y , " "
  27. ,bf z]
  28. triangle :: (ℝ3, ℝ3, ℝ3) -> Builder
  29. triangle (a,b,c) = "facet normal 0 0 0\nouter loop\n"
  30. <> vertex a <> "\n"
  31. <> vertex b <> "\n"
  32. <> vertex c
  33. <> "\nendloop\nendfacet\n"
  34.  
  35. formatWithString triangles = text
  36. where
  37. stlHeader = "solid ImplictCADExport\n"
  38. stlFooter = "endsolid ImplictCADExport\n"
  39. vertex :: ℝ3 -> String
  40. vertex (x,y,z) = "vertex " ++ show x ++ " " ++ show y ++ " " ++ show z
  41. stlTriangle :: (ℝ3, ℝ3, ℝ3) -> String
  42. stlTriangle (a,b,c) =
  43. "facet normal 0 0 0\n"
  44. ++ "outer loop\n"
  45. ++ vertex a ++ "\n"
  46. ++ vertex b ++ "\n"
  47. ++ vertex c ++ "\n"
  48. ++ "endloop\n"
  49. ++ "endfacet\n"
  50. text = stlHeader
  51. ++ (concat $ map stlTriangle triangles)
  52. ++ stlFooter
  53.  
  54. model = union [
  55. rect3R 0 (0,0,0) (20,20,20),
  56. translate (30,30,30) (rect3R 0 (0,0,0) (40,40,40))
  57. ]
  58.  
  59.  
  60. main = defaultMain [
  61. bgroup "writing stl" [
  62. bench "with Text.Lazy" $ nfIO $ TextIO.writeFile "/dev/null" $ formatWithLazyText $ discreteAprox 1 model,
  63. bench "with String" $ nfIO $ writeFile "/dev/null" $ formatWithString $ discreteAprox 1 model
  64. ]
  65. ]
Add Comment
Please, Sign In to add comment