ply.spec.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**
  2. * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import Ply from '../ply/parser'
  7. import { PlyTable, PlyList } from '../ply/schema';
  8. const plyString = `ply
  9. format ascii 1.0
  10. comment file created by MegaMol
  11. element vertex 6
  12. property float x
  13. property float y
  14. property float z
  15. property uchar red
  16. property uchar green
  17. property uchar blue
  18. property uchar alpha
  19. property float nx
  20. property float ny
  21. property float nz
  22. property int atomid
  23. property uchar contactcount_r
  24. property uchar contactcount_g
  25. property uchar contactcount_b
  26. property uchar contactsteps_r
  27. property uchar contactsteps_g
  28. property uchar contactsteps_b
  29. property uchar hbonds_r
  30. property uchar hbonds_g
  31. property uchar hbonds_b
  32. property uchar hbondsteps_r
  33. property uchar hbondsteps_g
  34. property uchar hbondsteps_b
  35. property uchar molcount_r
  36. property uchar molcount_g
  37. property uchar molcount_b
  38. property uchar spots_r
  39. property uchar spots_g
  40. property uchar spots_b
  41. property uchar rmsf_r
  42. property uchar rmsf_g
  43. property uchar rmsf_b
  44. element face 2
  45. property list uchar int vertex_index
  46. end_header
  47. 130.901 160.016 163.033 90 159 210 255 -0.382 -0.895 -0.231 181 21 100 150 24 102 151 20 100 150 20 100 150 30 106 154 20 100 150 171 196 212
  48. 131.372 159.778 162.83 90 159 210 255 -0.618 -0.776 -0.129 178 21 100 150 24 102 151 20 100 150 20 100 150 30 106 154 20 100 150 141 177 199
  49. 131.682 159.385 163.089 90 159 210 255 -0.773 -0.579 -0.259 180 21 100 150 24 102 151 20 100 150 20 100 150 30 106 154 20 100 150 172 196 212
  50. 131.233 160.386 162.11 90 159 210 255 -0.708 -0.383 -0.594 178 21 100 150 24 102 151 20 100 150 20 100 150 30 106 154 20 100 150 141 177 199
  51. 130.782 160.539 162.415 90 159 210 255 -0.482 -0.459 -0.746 181 21 100 150 24 102 151 20 100 150 20 100 150 30 106 154 20 100 150 171 196 212
  52. 131.482 160.483 161.621 90 159 210 255 -0.832 -0.431 -0.349 179 21 100 150 24 102 151 20 100 150 20 100 150 30 106 154 20 100 150 171 196 212
  53. 3 0 2 1
  54. 3 3 5 4
  55. `
  56. const plyCubeString = `ply
  57. format ascii 1.0
  58. comment test cube
  59. element vertex 24
  60. property float32 x
  61. property float32 y
  62. property float32 z
  63. property uint32 material_index
  64. element face 6
  65. property list uint8 int32 vertex_indices
  66. element material 6
  67. property uint8 red
  68. property uint8 green
  69. property uint8 blue
  70. end_header
  71. -1 -1 -1 0
  72. 1 -1 -1 0
  73. 1 1 -1 0
  74. -1 1 -1 0
  75. 1 -1 1 1
  76. -1 -1 1 1
  77. -1 1 1 1
  78. 1 1 1 1
  79. 1 1 1 2
  80. 1 1 -1 2
  81. 1 -1 -1 2
  82. 1 -1 1 2
  83. -1 1 -1 3
  84. -1 1 1 3
  85. -1 -1 1 3
  86. -1 -1 -1 3
  87. -1 1 1 4
  88. -1 1 -1 4
  89. 1 1 -1 4
  90. 1 1 1 4
  91. 1 -1 1 5
  92. 1 -1 -1 5
  93. -1 -1 -1 5
  94. -1 -1 1 5
  95. 4 0 1 2 3
  96. 4 4 5 6 7
  97. 4 8 9 10 11
  98. 4 12 13 14 15
  99. 4 16 17 18 19
  100. 4 20 21 22 23
  101. 255 0 0
  102. 0 255 0
  103. 0 0 255
  104. 255 255 0
  105. 0 255 255
  106. 255 0 255
  107. `
  108. describe('ply reader', () => {
  109. it('basic', async () => {
  110. const parsed = await Ply(plyString).run();
  111. if (parsed.isError) return;
  112. const plyFile = parsed.result;
  113. const vertex = plyFile.getElement('vertex') as PlyTable
  114. if (!vertex) return
  115. const x = vertex.getProperty('x')
  116. if (!x) return
  117. expect(x.value(0)).toEqual(130.901)
  118. const face = plyFile.getElement('face') as PlyList
  119. if (!face) return
  120. expect(face.value(0)).toEqual({ count: 3, entries: [0, 2, 1]})
  121. expect(face.value(1)).toEqual({ count: 3, entries: [3, 5, 4]})
  122. expect.assertions(3)
  123. });
  124. it('material', async () => {
  125. const parsed = await Ply(plyCubeString).run();
  126. if (parsed.isError) return;
  127. const plyFile = parsed.result;
  128. const vertex = plyFile.getElement('vertex') as PlyTable
  129. if (!vertex) return
  130. expect(vertex.rowCount).toBe(24)
  131. const face = plyFile.getElement('face') as PlyList
  132. if (!face) return
  133. expect(face.rowCount).toBe(6)
  134. const material = plyFile.getElement('face') as PlyTable
  135. if (!material) return
  136. expect(face.rowCount).toBe(6)
  137. expect.assertions(3)
  138. });
  139. });