Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cityjson
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WANDER
cityjson
Commits
d90c69ae
Commit
d90c69ae
authored
2 years ago
by
Knuiman, Bart
Browse files
Options
Downloads
Patches
Plain Diff
Height correctly applies now.
parent
98688342
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Runtime/3rdParty/TIFF/TiffUtils.cs
+33
-15
33 additions, 15 deletions
Runtime/3rdParty/TIFF/TiffUtils.cs
Runtime/BasisVoorziening.cs
+16
-5
16 additions, 5 deletions
Runtime/BasisVoorziening.cs
Runtime/GeoTiffHeight.cs
+16
-6
16 additions, 6 deletions
Runtime/GeoTiffHeight.cs
with
65 additions
and
26 deletions
Runtime/3rdParty/TIFF/TiffUtils.cs
+
33
−
15
View file @
d90c69ae
...
...
@@ -10,7 +10,9 @@ namespace Wander
{
static
float
InvalidSample
=
-
999
;
public
static
float
[]
DecodePixelsAsFloat
(
string
path
,
out
int
width
,
out
int
height
)
public
static
float
[]
DecodePixelsAsFloat
(
string
path
,
out
int
width
,
out
int
height
,
bool
flipVertically
,
out
double
originX
,
out
double
originY
,
out
double
pixelSizeX
,
out
double
pixelSizeY
)
{
width
=
0
;
height
=
0
;
...
...
@@ -18,20 +20,34 @@ namespace Wander
byte
[]
tiffBytes
=
File
.
ReadAllBytes
(
path
);
TiffStreamForBytes
ts
=
new
TiffStreamForBytes
(
tiffBytes
);
using
(
Tiff
inImage
=
Tiff
.
ClientOpen
(
"bytes"
,
"r"
,
null
,
ts
)
)
using
(
Tiff
tiff
=
Tiff
.
ClientOpen
(
"bytes"
,
"r"
,
null
,
ts
)
)
{
if
(
inImage
==
null
)
if
(
tiff
==
null
)
{
throw
new
InvalidDataException
(
"Tiff data not valid"
);
}
width
=
inImage
.
GetField
(
TiffTag
.
IMAGEWIDTH
)[
0
].
ToInt
();
height
=
inImage
.
GetField
(
TiffTag
.
IMAGELENGTH
)[
0
].
ToInt
();
int
tile_width
=
inImage
.
GetField
(
TiffTag
.
TILEWIDTH
)[
0
].
ToInt
();
int
tile_height
=
inImage
.
GetField
(
TiffTag
.
TILELENGTH
)[
0
].
ToInt
();
int
tileSize
=
inImage
.
TileSize
();
width
=
tiff
.
GetField
(
TiffTag
.
IMAGEWIDTH
)[
0
].
ToInt
();
height
=
tiff
.
GetField
(
TiffTag
.
IMAGELENGTH
)[
0
].
ToInt
();
int
tile_width
=
tiff
.
GetField
(
TiffTag
.
TILEWIDTH
)[
0
].
ToInt
();
int
tile_height
=
tiff
.
GetField
(
TiffTag
.
TILELENGTH
)[
0
].
ToInt
();
int
tileSize
=
tiff
.
TileSize
();
byte
[]
tileData
=
new
byte
[
tileSize
];
// Obtain coords
{
FieldValue
[]
modelPixelScaleTag
=
tiff
.
GetField
((
TiffTag
)
33550
);
FieldValue
[]
modelTiepointTag
=
tiff
.
GetField
((
TiffTag
)
33922
);
byte
[]
modelPixelScale
=
modelPixelScaleTag
[
1
].
GetBytes
();
pixelSizeX
=
BitConverter
.
ToDouble
(
modelPixelScale
,
0
);
pixelSizeY
=
BitConverter
.
ToDouble
(
modelPixelScale
,
8
)
*
-
1
;
byte
[]
modelTransformation
=
modelTiepointTag
[
1
].
GetBytes
();
originX
=
BitConverter
.
ToDouble
(
modelTransformation
,
24
);
originY
=
BitConverter
.
ToDouble
(
modelTransformation
,
32
);
}
// output
output
=
new
float
[
width
*
height
];
for
(
int
row
=
0
;
row
<
height
;
row
+=
tile_height
)
...
...
@@ -39,7 +55,7 @@ namespace Wander
for
(
int
col
=
0
;
col
<
width
;
col
+=
tile_width
)
{
// Read the tile into an RGBA array
int
res
=
inImage
.
ReadTile
(
tileData
,
0
,
col
,
row
,
0
,
0
);
int
res
=
tiff
.
ReadTile
(
tileData
,
0
,
col
,
row
,
0
,
0
);
if
(
res
==
-
1
)
throw
new
InvalidDataException
(
"Invalid tiff tile"
);
...
...
@@ -48,14 +64,16 @@ namespace Wander
int
y2
=
row
+
y
;
if
(
y2
>=
height
)
continue
;
for
(
int
x
=
0
;
x
<
tile_width
;
x
++
)
for
(
int
x
=
0
;
x
<
tile_width
;
x
++)
{
int
x2
=
col
+
x
;
if
(
x2
>=
width
)
int
x2
=
col
+
x
;
if
(
x2
>=
width
)
continue
;
float
h
=
BitConverter
.
ToSingle
(
tileData
,
(
x
*
tile_height
+
y
)
*
4
);
output
[
y2
*
width
+
x2
]
=
h
;
//float h = BitConverter.ToSingle( tileData, (x * tile_height + y) * 4 );
float
h
=
BitConverter
.
ToSingle
(
tileData
,
(
y
*
tile_width
+
x
)
*
4
);
//int y3 = flipVertically? height-1-y2 : y2;
output
[
y2
*
width
+
x2
]
=
h
;
}
}
}
...
...
@@ -101,7 +119,7 @@ namespace Wander
}
}
h
=
data
[
addr
];
if
(
h
<
-
10
||
h
>
250
)
if
(
h
<
-
10
||
h
>
250
)
// Ensure final is valid.
h
=
0
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Runtime/BasisVoorziening.cs
+
16
−
5
View file @
d90c69ae
...
...
@@ -16,6 +16,10 @@ namespace Wander
public
float
[]
data
;
public
int
width
;
public
int
height
;
public
double
originX
;
public
double
originY
;
public
double
pixelSizeX
;
public
double
pixelSizeY
;
}
public
interface
IGetHeight
...
...
@@ -222,6 +226,8 @@ namespace Wander
m
.
SetUVs
(
0
,
cb
.
uv
);
m
.
SetTriangles
(
cb
.
indices
,
0
);
m
.
RecalculateNormals
();
m
.
Optimize
();
m
.
UploadMeshData
(
true
);
#if UNITY_EDITOR
if
(
saveAssetsToDisk
)
...
...
@@ -371,19 +377,24 @@ namespace Wander
Vector3
offset
=
new
Vector3
(
tsl
.
X
,
tsl
.
Y
,
tsl
.
Z
);
var
unityVertices
=
cj
.
Vertices
.
Select
(
v
=>
{
double
x
=
((
v
.
x
*
(
double
)
sc
.
X
+
(
double
)
offset
.
x
)
-
(
double
)
offsetX
);
// double y = ((v.z * (double)sc.Z + (double)offset.z) - (double)0);
double
z
=
((
v
.
y
*
(
double
)
sc
.
Y
+
(
double
)
offset
.
y
)
-
(
double
)
offsetY
);
double
x
=
((
v
.
x
*
(
double
)
sc
.
X
+
(
double
)
offset
.
x
));
double
z
=
((
v
.
y
*
(
double
)
sc
.
Y
+
(
double
)
offset
.
y
));
double
y
=
0
;
if
(
heightData
.
data
!=
null
)
{
int
xPixel
=
(
int
)((
x
-
cj
.
GeoExtentM
in
.
X
)
*
tileWidth
);
int
yPixel
=
(
int
)((
z
-
cj
.
GeoExtentMin
.
Z
)
*
tileHeight
);
int
xPixel
=
Mathf
.
FloorToInt
(
(
float
)((
x
-
heightData
.
orig
inX
)
/
heightData
.
pixelSizeX
)
);
int
yPixel
=
Mathf
.
FloorToInt
(
(
float
)((
z
-
heightData
.
originY
)
/
heightData
.
pixelSizeY
)
);
if
(
xPixel
>=
0
&&
xPixel
<
heightData
.
width
&&
yPixel
>=
0
&&
yPixel
<
heightData
.
height
)
{
y
=
heightData
.
data
[
yPixel
*
heightData
.
width
+
xPixel
];
// if ( y < -10 ) y = 0; // Filter already ensures final output is valid.
// if ( y > 250 ) y = 0;
}
}
x
-=
(
double
)
offsetX
;
z
-=
(
double
)
offsetY
;
//y=0;
var
vNew
=
new
Vector3
((
float
)
x
,
(
float
)
y
,
(
float
)
z
);
//vNew -= new Vector3(offsetX, 0, offsetY);
...
...
This diff is collapsed.
Click to expand it.
Runtime/GeoTiffHeight.cs
+
16
−
6
View file @
d90c69ae
...
...
@@ -9,6 +9,8 @@ namespace Wander
{
void
RegisterInterfaces
()
{
// if (!enabled)
// return;
var
bsv
=
GetComponent
<
BasisVoorziening
>();
if
(
bsv
!=
null
)
{
...
...
@@ -20,7 +22,6 @@ namespace Wander
{
tileName
=
Path
.
GetFileNameWithoutExtension
(
tileName
).
ToLower
();
string
[]
tileWords
=
tileName
.
Split
(
'_'
,
'.'
,
'#'
,
','
);
tileName
=
tileName
.
ToLower
();
List
<
string
>
files
=
new
List
<
string
>();
files
.
AddRange
(
Directory
.
GetFiles
(
rootFolder
,
"*.tiff"
,
SearchOption
.
AllDirectories
)
);
...
...
@@ -34,17 +35,26 @@ namespace Wander
{
if
(
tileWords
[
k
].
Length
==
5
&&
tileWords
[
k
]==
fileWords
[
j
])
{
float
[]
data
=
TiffUtils
.
DecodePixelsAsFloat
(
files
[
i
],
out
int
width
,
out
int
height
);
float
[]
data
=
TiffUtils
.
DecodePixelsAsFloat
(
files
[
i
],
out
int
width
,
out
int
height
,
true
,
out
double
originX
,
out
double
originY
,
out
double
pixelSizeX
,
out
double
pixelSizeY
);
TiffUtils
.
FilterFloatData
(
data
,
width
,
height
);
return
new
HeightData
{
width
=
width
,
height
=
height
,
data
=
data
width
=
width
,
height
=
height
,
data
=
data
,
originX
=
originX
,
originY
=
originY
,
pixelSizeX
=
pixelSizeX
,
pixelSizeY
=
pixelSizeY
};
}
}
}
}
}
return
default
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment