Skip to content

Commit 83e1587

Browse files
committed
potree importer
1 parent eecbced commit 83e1587

File tree

5 files changed

+1036
-0
lines changed

5 files changed

+1036
-0
lines changed
Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Text.Json;
5+
6+
namespace Aardvark.Data.Potree
7+
{
8+
public static class PotreeMetaData
9+
{
10+
public static bool TryDeserialize(string filePath, out PotreeData data)
11+
{
12+
string json = File.ReadAllText(filePath);
13+
14+
var options = new JsonSerializerOptions
15+
{
16+
PropertyNameCaseInsensitive = true
17+
};
18+
19+
try
20+
{
21+
data = JsonSerializer.Deserialize<PotreeData>(json, options);
22+
return true;
23+
}
24+
catch (Exception ex)
25+
{
26+
//Serilog.Log.Error(ex);
27+
data = null;
28+
Console.WriteLine(ex.ToString());
29+
return false;
30+
}
31+
}
32+
33+
public class PotreeData
34+
{
35+
public string version { get; set; }
36+
public string name { get; set; }
37+
public string description { get; set; }
38+
public double points { get; set; }
39+
public string projection { get; set; }
40+
public PotreeHierarchy hierarchy { get; set; }
41+
public double[] offset { get; set; }
42+
public double[] scale { get; set; }
43+
public double spacing { get; set; }
44+
public PotreeBoundingBox boundingBox { get; set; }
45+
public string encoding { get; set; }
46+
public PotreeAttribute[] attributes { get; set; }
47+
}
48+
49+
public class PotreeHierarchy
50+
{
51+
public int firstChunkSize { get; set; }
52+
public int stepSize { get; set; }
53+
public int depth { get; set; }
54+
}
55+
56+
public class PotreeBoundingBox
57+
{
58+
public double[] min { get; set; }
59+
public double[] max { get; set; }
60+
}
61+
62+
public class PotreeAttribute
63+
{
64+
public string name { get; set; }
65+
public string description { get; set; }
66+
public int size { get; set; }
67+
public int numElements { get; set; }
68+
public int elementSize { get; set; }
69+
public string type { get; set; }
70+
public JsonElement[] min { get; set; }
71+
public JsonElement[] max { get; set; }
72+
public JsonElement[] scale { get; set; }
73+
public JsonElement[] offset { get; set; }
74+
public long[] histogram { get; set; }
75+
}
76+
77+
public static object JsonElementToObject(JsonElement element)
78+
{
79+
switch (element.ValueKind)
80+
{
81+
case JsonValueKind.Object:
82+
var obj = new Dictionary<string, object>();
83+
foreach (var property in element.EnumerateObject())
84+
{
85+
obj[property.Name] = JsonElementToObject(property.Value);
86+
}
87+
return obj;
88+
89+
case JsonValueKind.Array:
90+
var list = new List<object>();
91+
foreach (var item in element.EnumerateArray())
92+
{
93+
list.Add(JsonElementToObject(item));
94+
}
95+
return list;
96+
97+
case JsonValueKind.String:
98+
return element.GetString();
99+
100+
case JsonValueKind.Number:
101+
if (element.TryGetInt32(out int l))
102+
return l;
103+
else if (element.TryGetDouble(out double d))
104+
return d;
105+
else
106+
return element.GetRawText();
107+
108+
case JsonValueKind.True:
109+
return true;
110+
111+
case JsonValueKind.False:
112+
return false;
113+
114+
case JsonValueKind.Null:
115+
return null;
116+
117+
case JsonValueKind.Undefined:
118+
return null;
119+
}
120+
121+
return null;
122+
}
123+
}
124+
}
125+
126+
// "version": "2.0",
127+
// "name": "dense_pointcloud_100mio",
128+
// "description": "",
129+
// "points": 108692819,
130+
// "projection": "",
131+
// "hierarchy": {
132+
// "firstChunkSize": 4290,
133+
// "stepSize": 4,
134+
// "depth": 9
135+
// },
136+
// "offset": [71677.816000000006, 266019.81199999998, 669.71500000000003],
137+
// "scale": [0.001, 0.001, 0.001],
138+
// "spacing": 9.7567734375002146,
139+
// "boundingBox": {
140+
// "min": [71677.816000000006, 266019.81199999998, 669.71500000000003],
141+
// "max": [72926.683000000034, 267268.679, 1918.5820000000276]
142+
// },
143+
// "encoding": "BROTLI",
144+
// "attributes": [
145+
// {
146+
// "name": "position",
147+
// "description": "",
148+
// "size": 12,
149+
// "numElements": 3,
150+
// "elementSize": 4,
151+
// "type": "int32",
152+
// "min": [71677.816000000006, 266019.81199999998, 669.71500000000003],
153+
// "max": [72926.683000000005, 266554.69199999998, 825.78300000000002],
154+
// "scale": [1, 1, 1],
155+
// "offset": [0, 0, 0]
156+
//},{
157+
// "name": "intensity",
158+
// "description": "",
159+
// "size": 2,
160+
// "numElements": 1,
161+
// "elementSize": 2,
162+
// "type": "uint16",
163+
// "min": [0],
164+
// "max": [65535],
165+
// "scale": [1],
166+
// "offset": [0]
167+
168+
// },{
169+
// "name": "return number",
170+
// "description": "",
171+
// "size": 1,
172+
// "numElements": 1,
173+
// "elementSize": 1,
174+
// "type": "uint8",
175+
// "min": [1],
176+
// "max": [1],
177+
// "scale": [1],
178+
// "offset": [0]
179+
180+
// },{
181+
// "name": "number of returns",
182+
// "description": "",
183+
// "size": 1,
184+
// "numElements": 1,
185+
// "elementSize": 1,
186+
// "type": "uint8",
187+
// "min": [1],
188+
// "max": [1],
189+
// "scale": [1],
190+
// "offset": [0]
191+
192+
// },{
193+
// "name": "classification",
194+
// "description": "",
195+
// "size": 1,
196+
// "numElements": 1,
197+
// "elementSize": 1,
198+
// "type": "uint8",
199+
// "histogram": [108692819, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
200+
// "min": [0],
201+
// "max": [0],
202+
// "scale": [1],
203+
// "offset": [0]
204+
205+
// },{
206+
// "name": "scan angle rank",
207+
// "description": "",
208+
// "size": 1,
209+
// "numElements": 1,
210+
// "elementSize": 1,
211+
// "type": "uint8",
212+
// "min": [0],
213+
// "max": [0],
214+
// "scale": [1],
215+
// "offset": [0]
216+
217+
// },{
218+
// "name": "user data",
219+
// "description": "",
220+
// "size": 1,
221+
// "numElements": 1,
222+
// "elementSize": 1,
223+
// "type": "uint8",
224+
// "min": [0],
225+
// "max": [0],
226+
// "scale": [1],
227+
// "offset": [0]
228+
229+
// },{
230+
// "name": "point source id",
231+
// "description": "",
232+
// "size": 2,
233+
// "numElements": 1,
234+
// "elementSize": 2,
235+
// "type": "uint16",
236+
// "min": [1],
237+
// "max": [1],
238+
// "scale": [1],
239+
// "offset": [0]
240+
241+
// },{
242+
// "name": "rgb",
243+
// "description": "",
244+
// "size": 6,
245+
// "numElements": 3,
246+
// "elementSize": 2,
247+
// "type": "uint16",
248+
// "min": [0, 0, 0],
249+
// "max": [65535, 65535, 65535],
250+
// "scale": [1, 1, 1],
251+
// "offset": [0, 0, 0]
252+
253+
// }
254+
// ]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Aardvark.Base;
2+
using System;
3+
using System.Collections.Generic;
4+
5+
namespace Aardvark.Data.Potree
6+
{
7+
public class PotreeNode
8+
{
9+
public Guid Id { get; private set; }
10+
public string Name { get; set; }
11+
public int NodeType { get; set; }
12+
public bool HasChildren => !Children.IsEmpty();
13+
public long ByteOffset { get; set; }
14+
public long ByteSize { get; set; }
15+
16+
public PotreeOctree OctreeRoot { get; private set; }
17+
public Box3d BoundingBox { get; private set; }
18+
public Dictionary<int, PotreeNode> Children { get; private set; }
19+
public long NumPoints { get; set; }
20+
public PotreeNode Parent { get; set; }
21+
22+
public PotreeNode(string name, PotreeOctree rootGeometry, Box3d bbox)
23+
{
24+
Id = Guid.NewGuid();
25+
Name = name;
26+
OctreeRoot = rootGeometry;
27+
BoundingBox = bbox;
28+
Children = new Dictionary<int, PotreeNode>();
29+
NumPoints = 0;
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)