Guest User

Untitled

a guest
Dec 15th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.44 KB | None | 0 0
  1. module Lib
  2. ( someFunc
  3. ) where
  4.  
  5. import KdTree
  6. import Data.Maybe
  7. import ReturnNearestMap
  8. import qualified Data.Array.Repa as R
  9.  
  10. ps =
  11. let
  12.  
  13. p0 = Point3dIndexed (Point3d (negate 2) (negate 2) (negate 2)) 0 [(Point3d (negate 2) (negate 2) (negate 3)),(Point3d (negate 2) (negate 2) (negate 1)),(Point3d (negate 2) (negate 3) (negate 2)),(Point3d (negate 1) (negate 2) (negate 2)),(Point3d (negate 2) (negate 1) (negate 2)),(Point3d (negate 3) (negate 2) (negate 2))]
  14. p1 = Point3dIndexed (Point3d 0 (negate 2) (negate 2)) 1 [(Point3d 0 (negate 2) (negate 3)),(Point3d 0 (negate 2) (negate 1)),(Point3d 0 (negate 3) (negate 2)),(Point3d 1 (negate 2) (negate 2)),(Point3d 0 (negate 1) (negate 2)),(Point3d (negate 1) (negate 2) (negate 2))]
  15. p2 = Point3dIndexed (Point3d 2 (negate 2) (negate 2)) 2 [(Point3d 2 (negate 2) (negate 3)),(Point3d 2 (negate 2) (negate 1)),(Point3d 2 (negate 3) (negate 2)),(Point3d 3 (negate 2) (negate 2)),(Point3d 2 (negate 1) (negate 2)),(Point3d 1 (negate 2) (negate 2))]
  16. p3 = Point3dIndexed (Point3d (negate 2) 0 (negate 2)) 3 [(Point3d (negate 2) 0 (negate 3)),(Point3d (negate 2) 0 (negate 1)),(Point3d (negate 2) (negate 1) (negate 2)),(Point3d (negate 1) 0 (negate 2)),(Point3d (negate 2) 1 (negate 2)),(Point3d (negate 3) 0 (negate 2))]
  17. p4 = Point3dIndexed (Point3d 0 0 (negate 2)) 4 [(Point3d 0 0 (negate 3)),(Point3d 0 0 (negate 1)),(Point3d 0 (negate 1) (negate 2)),(Point3d 1 0 (negate 2)),(Point3d 0 1 (negate 2)),(Point3d (negate 1) 0 (negate 2))]
  18. p5 = Point3dIndexed (Point3d 2 0 (negate 2)) 5 [(Point3d 2 0 (negate 3)),(Point3d 2 0 (negate 1)),(Point3d 2 (negate 1) (negate 2)),(Point3d 3 0 (negate 2)),(Point3d 2 1 (negate 2)),(Point3d 1 0 (negate 2))]
  19. p6 = Point3dIndexed (Point3d (negate 2) 2 (negate 2)) 6 [(Point3d (negate 2) 2 (negate 3)),(Point3d (negate 2) 2 (negate 1)),(Point3d (negate 2) 1 (negate 2)),(Point3d (negate 1) 2 (negate 2)),(Point3d (negate 2) 3 (negate 2)),(Point3d (negate 3) 2 (negate 2))]
  20. p7 = Point3dIndexed (Point3d 0 2 (negate 2)) 7 [(Point3d 0 2 (negate 3)),(Point3d 0 2 (negate 1)),(Point3d 0 1 (negate 2)),(Point3d 1 2 (negate 2)),(Point3d 0 3 (negate 2)),(Point3d (negate 1) 2 (negate 2))]
  21. p8 = Point3dIndexed (Point3d 2 2 (negate 2)) 8 [(Point3d 2 2 (negate 3)),(Point3d 2 2 (negate 1)),(Point3d 2 1 (negate 2)),(Point3d 3 2 (negate 2)),(Point3d 2 3 (negate 2)),(Point3d 1 2 (negate 2))]
  22. p9 = Point3dIndexed (Point3d (negate 2) (negate 2) 0) 9 [(Point3d (negate 2) (negate 2) (negate 1)),(Point3d (negate 2) (negate 2) 1),(Point3d (negate 2) (negate 3) 0),(Point3d (negate 1) (negate 2) 0),(Point3d (negate 2) (negate 1) 0),(Point3d (negate 3) (negate 2) 0)]
  23. p10 = Point3dIndexed (Point3d 0 (negate 2) 0) 10 [(Point3d 0 (negate 2) (negate 1)),(Point3d 0 (negate 2) 1),(Point3d 0 (negate 3) 0),(Point3d 1 (negate 2) 0),(Point3d 0 (negate 1) 0),(Point3d (negate 1) (negate 2) 0)]
  24. p11 = Point3dIndexed (Point3d 2 (negate 2) 0) 11 [(Point3d 2 (negate 2) (negate 1)),(Point3d 2 (negate 2) 1),(Point3d 2 (negate 3) 0),(Point3d 3 (negate 2) 0),(Point3d 2 (negate 1) 0),(Point3d 1 (negate 2) 0)]
  25. p12 = Point3dIndexed (Point3d (negate 2) 0 0) 12 [(Point3d (negate 2) 0 (negate 1)),(Point3d (negate 2) 0 1),(Point3d (negate 2) (negate 1) 0),(Point3d (negate 1) 0 0),(Point3d (negate 2) 1 0),(Point3d (negate 3) 0 0)]
  26. p13 = Point3dIndexed (Point3d 0 0 0) 13 [(Point3d 0 0 (negate 1)),(Point3d 0 0 1),(Point3d 0 (negate 1) 0),(Point3d 1 0 0),(Point3d 0 1 0),(Point3d (negate 1) 0 0)]
  27. p14 = Point3dIndexed (Point3d 2 0 0) 14 [(Point3d 2 0 (negate 1)),(Point3d 2 0 1),(Point3d 2 (negate 1) 0),(Point3d 3 0 0),(Point3d 2 1 0),(Point3d 1 0 0)]
  28. p15 = Point3dIndexed (Point3d (negate 2) 2 0) 15 [(Point3d (negate 2) 2 (negate 1)),(Point3d (negate 2) 2 1),(Point3d (negate 2) 1 0),(Point3d (negate 1) 2 0),(Point3d (negate 2) 3 0),(Point3d (negate 3) 2 0)]
  29. p16 = Point3dIndexed (Point3d 0 2 0) 16 [(Point3d 0 2 (negate 1)),(Point3d 0 2 1),(Point3d 0 1 0),(Point3d 1 2 0),(Point3d 0 3 0),(Point3d (negate 1) 2 0)]
  30. p17 = Point3dIndexed (Point3d 2 2 0) 17 [(Point3d 2 2 (negate 1)),(Point3d 2 2 1),(Point3d 2 1 0),(Point3d 3 2 0),(Point3d 2 3 0),(Point3d 1 2 0)]
  31. p18 = Point3dIndexed (Point3d (negate 2) (negate 2) 2) 18 [(Point3d (negate 2) (negate 2) 1),(Point3d (negate 2) (negate 2) 3),(Point3d (negate 2) (negate 3) 2),(Point3d (negate 1) (negate 2) 2),(Point3d (negate 2) (negate 1) 2),(Point3d (negate 3) (negate 2) 2)]
  32. p19 = Point3dIndexed (Point3d 0 (negate 2) 2) 19 [(Point3d 0 (negate 2) 1),(Point3d 0 (negate 2) 3),(Point3d 0 (negate 3) 2),(Point3d 1 (negate 2) 2),(Point3d 0 (negate 1) 2),(Point3d (negate 1) (negate 2) 2)]
  33. p20 = Point3dIndexed (Point3d 2 (negate 2) 2) 20 [(Point3d 2 (negate 2) 1),(Point3d 2 (negate 2) 3),(Point3d 2 (negate 3) 2),(Point3d 3 (negate 2) 2),(Point3d 2 (negate 1) 2),(Point3d 1 (negate 2) 2)]
  34. p21 = Point3dIndexed (Point3d (negate 2) 0 2) 21 [(Point3d (negate 2) 0 1),(Point3d (negate 2) 0 3),(Point3d (negate 2) (negate 1) 2),(Point3d (negate 1) 0 2),(Point3d (negate 2) 1 2),(Point3d (negate 3) 0 2)]
  35. p22 = Point3dIndexed (Point3d 0 0 2) 22 [(Point3d 0 0 1),(Point3d 0 0 3),(Point3d 0 (negate 1) 2),(Point3d 1 0 2),(Point3d 0 1 2),(Point3d (negate 1) 0 2)]
  36. p23 = Point3dIndexed (Point3d 2 0 2) 23 [(Point3d 2 0 1),(Point3d 2 0 3),(Point3d 2 (negate 1) 2),(Point3d 3 0 2),(Point3d 2 1 2),(Point3d 1 0 2)]
  37. p24 = Point3dIndexed (Point3d (negate 2) 2 2) 24 [(Point3d (negate 2) 2 1),(Point3d (negate 2) 2 3),(Point3d (negate 2) 1 2),(Point3d (negate 1) 2 2),(Point3d (negate 2) 3 2),(Point3d (negate 3) 2 2)]
  38. p25 = Point3dIndexed (Point3d 0 2 2) 25 [(Point3d 0 2 1),(Point3d 0 2 3),(Point3d 0 1 2),(Point3d 1 2 2),(Point3d 0 3 2),(Point3d (negate 1) 2 2)]
  39. p26 = Point3dIndexed (Point3d 2 2 2) 26 [(Point3d 2 2 1),(Point3d 2 2 3),(Point3d 2 1 2),(Point3d 3 2 2),(Point3d 2 3 2),(Point3d 1 2 2)]
  40. in
  41. [p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23,p24,p25,p26]
  42.  
  43. getRelVertsNearRelVert relv =
  44. case relv of
  45. 1 -> [(-1,-1,-1,7),(0,-1,-1,8),(-1,0,-1,6),(0,0,-1,5),(-1,-1,0,3),(0,-1,0,4),(-1,0,0,2),(0,0,0,1)]
  46. 2 -> [(0,-1,-1,7),(1,-1,-1,8),(0,0,-1,6),(1,0,-1,5),(0,-1,0,3),(1,-1,0,4),(0,0,0,2),(1,0,0,1)]
  47. 3 -> [(0,0,-1,7),(1,0,-1,8),(0,1,-1,6),(1,1,-1,5),(0,0,0,3),(1,0,0,4),(0,1,0,2),(1,1,0,1)]
  48. 4 -> [(-1,0,-1,7),(0,0,-1,8),(-1,1,-1,6),(0,1,-1,5),(-1,0,0,3),(0,0,0,4),(-1,1,0,2),(0,1,0,1)]
  49. 5 -> [(-1,-1,0,7),(0,-1,0,8),(-1,0,0,6),(0,0,0,5),(-1,-1,1,3),(0,-1,1,4),(-1,0,1,2),(0,0,1,1)]
  50. 6 -> [(0,-1,0,7),(1,-1,0,8),(0,0,0,6),(1,0,0,5),(0,-1,1,3),(1,-1,1,4),(0,0,1,2),(1,0,1,1)]
  51. 7 -> [(0,0,0,7),(1,0,0,8),(0,1,0,6),(1,1,0,5),(0,0,1,3),(1,0,1,4),(0,1,1,2),(1,1,1,1)]
  52. 8 -> [(-1,0,0,7),(0,0,0,8),(-1,1,0,6),(0,1,0,5),(-1,0,1,3),(0,0,1,4),(-1,1,1,2),(0,1,1,1)]
  53.  
  54. getCellIndexfromPQR (p,q,r) pmax qmax rmax = (p*qmax*rmax) + (q*rmax) + r
  55.  
  56. getPQRfromCellIndex index pmax qmax rmax =
  57. let
  58. r = index `mod` rmax
  59. q = ((index - r) `div` rmax) `mod` qmax
  60. p = (index - (q*rmax) -r) `div` (qmax*rmax)
  61. in
  62. (p,q,r)
  63.  
  64. getAdjVertsfromCellIndex cellindex pmax qmax rmax =
  65. let
  66. (p,q,r) = getPQRfromCellIndex cellindex pmax qmax rmax
  67. in
  68. do
  69. i <- [1..8]
  70. let vs = do
  71. (dx,dy,dz,v) <- getRelVertsNearRelVert i
  72. if (p+dx) >=0 && (q+dy)>=0 && (r+dz) >=0 then
  73. return $ Just ((p+dx), (q+dy), (r+dz), v)
  74. else
  75. return Nothing
  76. return $ catMaybes vs
  77.  
  78. move_p3 :: Point3d->Point3d-> Point3d
  79. move_p3 p d = Point3d (p3x p + p3x d) (p3y p + p3y d) (p3z p + p3z d)
  80.  
  81. move_p3i :: Point3dIndexed->Point3d->Point3dIndexed
  82. move_p3i p3 d = Point3dIndexed (move_p3 (point p3) d) (index p3) (map (\x -> move_p3 x d) ( surfaceArray p3))
  83.  
  84. someFunc :: IO ()
  85. someFunc = do
  86. putStrLn "someFunc"
  87. putStrLn $ show $ returnNearestMap [ps !! 3, ps !! 4]
  88. let ps' = map (\x -> move_p3i x (Point3d 100 100 100)) ps
  89. let ps03 = [ps' !! 3, ps'!! 4]
  90. putStrLn $ show $ ps03
  91. putStrLn $ show $ returnNearestMap ps03
  92. putStrLn $ show $ (1,2,3)
  93. putStrLn $ show $ getAdjVertsfromCellIndex 12 3 3 3
Add Comment
Please, Sign In to add comment