Skip to content

Commit 31aa47c

Browse files
committed
fixed position and color conversion in potree writer
1 parent 4b1b7d3 commit 31aa47c

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/PointCloud/Potree/V2/Potree2Writer.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,17 @@ public Potree2Writer(ref PotreeData potreeData) : base(ref potreeData) { }
120120
{
121121
if (offsetPosition > -1)
122122
{
123-
// TODO: Fix position conversion
124-
//binaryWriter.BaseStream.Position = node.ByteOffset + offsetPosition + i * _potreeData.Metadata.PointSize;
123+
binaryWriter.BaseStream.Position = node.ByteOffset + offsetPosition + i * _potreeData.Metadata.PointSize;
125124

126-
//var position = Potree2Consts.YZflip * point.Position;
125+
var position = Potree2Consts.YZflip * point.Position;
127126

128-
//binaryWriter.Write(position.x);
129-
//binaryWriter.Write(position.y);
130-
//binaryWriter.Write(position.z);
127+
int x = Convert.ToInt32(position.x / _potreeData.Metadata.Scale.x);
128+
int y = Convert.ToInt32(position.y / _potreeData.Metadata.Scale.y);
129+
int z = Convert.ToInt32(position.z / _potreeData.Metadata.Scale.z);
130+
131+
binaryWriter.Write(x);
132+
binaryWriter.Write(y);
133+
binaryWriter.Write(z);
131134
}
132135

133136
if (offsetIntensity > -1)
@@ -174,16 +177,15 @@ public Potree2Writer(ref PotreeData potreeData) : base(ref potreeData) { }
174177

175178
if (offsetColor > -1)
176179
{
177-
// TODO: Fix color conversion
178-
//binaryWriter.BaseStream.Position = node.ByteOffset + offsetColor + i * _potreeData.Metadata.PointSize;
180+
binaryWriter.BaseStream.Position = node.ByteOffset + offsetColor + i * _potreeData.Metadata.PointSize;
179181

180-
//ushort r = (ushort)MathF.Floor(point.Color.r >= 1f ? 255 : point.Color.r * 256f);
181-
//ushort g = (ushort)MathF.Floor(point.Color.g >= 1f ? 255 : point.Color.g * 256f);
182-
//ushort b = (ushort)MathF.Floor(point.Color.b >= 1f ? 255 : point.Color.b * 256f);
182+
ushort r = Convert.ToUInt16(point.Color.r * 256);
183+
ushort g = Convert.ToUInt16(point.Color.g * 256);
184+
ushort b = Convert.ToUInt16(point.Color.b * 256);
183185

184-
//binaryWriter.Write(r);
185-
//binaryWriter.Write(g);
186-
//binaryWriter.Write(b);
186+
binaryWriter.Write(r);
187+
binaryWriter.Write(g);
188+
binaryWriter.Write(b);
187189
}
188190
}
189191

0 commit comments

Comments
 (0)