Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CityDoctor
CityDoctor2
Commits
1745865f
Commit
1745865f
authored
Aug 08, 2024
by
Riegel
Browse files
Code cleaning Ref
#69
parent
5a6f4b46
Changes
163
Hide whitespace changes
Inline
Side-by-side
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/math/MovedRing.java
View file @
1745865f
...
...
@@ -32,7 +32,7 @@ import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
*/
public
class
MovedRing
{
private
List
<
Vector3d
>
vertices
;
private
final
List
<
Vector3d
>
vertices
;
private
LinearRing
original
;
public
static
MovedRing
ofRing
(
LinearRing
ring
,
Vector3d
movedBy
)
{
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/math/Plane.java
View file @
1745865f
...
...
@@ -18,6 +18,7 @@
*/
package
de.hft.stuttgart.citydoctor2.math
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -35,13 +36,14 @@ import de.hft.stuttgart.citydoctor2.math.PlaneSegmentIntersection.Type;
*/
public
class
Plane
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
1602547402497943364L
;
private
static
final
double
EPSILON
=
0.0001
;
private
UnitVector3d
normal
;
private
Vector3d
point
;
private
double
d
;
private
final
UnitVector3d
normal
;
private
final
Vector3d
point
;
private
final
double
d
;
/**
* Constructs a new plane from a normal vector and a reference point.
...
...
@@ -51,12 +53,14 @@ public class Plane implements Serializable {
*/
public
Plane
(
Vector3d
normal
,
Vector3d
p
)
{
point
=
p
;
this
.
normal
=
normal
.
normalize
();
d
=
this
.
normal
.
dot
(
point
);
if
(
d
<
0
)
{
this
.
normal
=
this
.
normal
.
invert
();
d
=
-
d
;
UnitVector3d
normalVector
=
normal
.
normalize
();
d
ouble
dot
=
normalVector
.
dot
(
point
);
if
(
d
ot
<
0
)
{
normal
Vector
=
normalVector
.
invert
();
d
ot
=
-
d
ot
;
}
this
.
d
=
dot
;
this
.
normal
=
normalVector
;
}
public
PlaneSegmentIntersection
intersects
(
Segment3d
s
)
{
...
...
@@ -89,9 +93,7 @@ public class Plane implements Serializable {
// intersection in segment
// calculate intersection point
Vector3d
intersection
=
s
.
getPointA
().
plus
(
dir
.
mult
(
si
));
PlaneSegmentIntersection
psi
=
new
PlaneSegmentIntersection
(
Type
.
INTERSECTION_POINT
);
psi
.
setPoint
(
intersection
);
return
psi
;
return
new
PlaneSegmentIntersection
(
Type
.
INTERSECTION_POINT
,
intersection
);
}
/**
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/math/PlaneSegmentIntersection.java
View file @
1745865f
...
...
@@ -30,21 +30,28 @@ public class PlaneSegmentIntersection {
NO_INTERSECTION
,
IN_PLANE
,
INTERSECTION_POINT
}
private
Type
type
;
private
Vector3d
point
;
private
final
Type
type
;
private
final
Vector3d
point
;
public
PlaneSegmentIntersection
(
Type
type
)
{
public
PlaneSegmentIntersection
(
Type
type
,
Vector3d
point
)
{
super
();
this
.
type
=
type
;
this
.
point
=
point
;
}
public
PlaneSegmentIntersection
(
Type
type
){
if
(
type
==
Type
.
INTERSECTION_POINT
){
throw
new
IllegalStateException
(
"Tried creating a PlaneSegmentIntersection of type INTERSECTION_POINT"
+
"without an intersection-point vector"
);
}
this
.
type
=
type
;
this
.
point
=
null
;
}
public
Vector3d
getPoint
()
{
return
point
;
}
public
void
setPoint
(
Vector3d
point
)
{
this
.
point
=
point
;
}
public
Type
getType
()
{
return
type
;
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/math/Polygon2d.java
View file @
1745865f
...
...
@@ -33,8 +33,8 @@ import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
*/
public
class
Polygon2d
{
private
Ring2d
exterior
;
private
List
<
Ring2d
>
innerRings
;
private
final
Ring2d
exterior
;
private
final
List
<
Ring2d
>
innerRings
;
public
static
Polygon2d
withProjection
(
Polygon
poly
)
{
ProjectionAxis
axis
=
ProjectionAxis
.
of
(
poly
);
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/math/ProjectionAxis.java
View file @
1745865f
...
...
@@ -37,7 +37,7 @@ public class ProjectionAxis {
private
static
final
String
DIVISOR_IS_0
=
"Divisor is 0"
;
private
int
[]
axis
;
private
final
int
[]
axis
;
public
static
ProjectionAxis
of
(
Polygon
p
)
{
return
getProjectionAxis
(
p
.
calculateNormal
());
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/math/Ray.java
View file @
1745865f
...
...
@@ -33,8 +33,8 @@ public class Ray {
public
static
final
double
EPSILON
=
0.0001
;
private
Vector3d
origin
;
private
UnitVector3d
direction
;
private
final
Vector3d
origin
;
private
final
UnitVector3d
direction
;
public
Ray
(
Vector3d
origin
,
Vector3d
direction
)
{
this
.
origin
=
origin
;
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/math/Ring2d.java
View file @
1745865f
...
...
@@ -32,8 +32,8 @@ import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
*/
public
class
Ring2d
{
private
List
<
Vector2d
>
ringVertices
;
private
LinearRing
original
;
private
final
List
<
Vector2d
>
ringVertices
;
private
final
LinearRing
original
;
public
static
Ring2d
of
(
MovedRing
movedRing
)
{
return
of
(
movedRing
,
ProjectionAxis
.
of
(
movedRing
));
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/math/Segment2d.java
View file @
1745865f
...
...
@@ -21,15 +21,15 @@ package de.hft.stuttgart.citydoctor2.math;
/**
* This class represents a line from a point to another point, it can be used to
* calculate the intersection of two edges
*
*
* @author Matthias Betz
*
*/
public
class
Segment2d
{
private
static
final
double
EPSILON
=
0.01
;
private
Vector2d
p1
;
private
Vector2d
p2
;
private
final
Vector2d
p1
;
private
final
Vector2d
p2
;
public
Segment2d
(
Vector2d
p1
,
Vector2d
p2
)
{
this
.
p1
=
p1
;
...
...
@@ -51,7 +51,7 @@ public class Segment2d {
double
numeratora
=
(
x4
-
x3
)
*
(
y1
-
y3
)
-
(
y4
-
y3
)
*
(
x1
-
x3
);
double
numeratorb
=
(
x2
-
x1
)
*
(
y1
-
y3
)
-
(
y2
-
y1
)
*
(
x1
-
x3
);
if
(
Math
.
abs
(
denominator
)
<
EPSILON
)
{
denominator
=
0.0
;
}
...
...
@@ -71,7 +71,7 @@ public class Segment2d {
return
ua
>
EPSILON
&&
ua
<
(
1
-
EPSILON
)
&&
ub
>
EPSILON
&&
ub
<
(
1
-
EPSILON
);
}
}
public
boolean
intersectsWithoutColinearity
(
Segment2d
other
)
{
double
x1
=
p1
.
getX
();
double
x2
=
p2
.
getX
();
...
...
@@ -89,7 +89,7 @@ public class Segment2d {
if
(
Math
.
abs
(
denominator
)
<
EPSILON
)
{
denominator
=
0.0
;
}
if
(
denominator
==
0
)
{
// both numerators == 0 means, lines are coincident, otherwise parallel
// parallel lines are not intersecting
...
...
@@ -103,7 +103,7 @@ public class Segment2d {
}
}
public
Vector2d
intersectionPoint
(
Segment2d
other
)
{
IntersectionPoint2d
inter
=
calculateIntersection
(
other
);
if
(
inter
==
null
)
{
...
...
@@ -111,7 +111,7 @@ public class Segment2d {
}
return
inter
.
getIntersectionPoint
();
}
public
IntersectionPoint2d
calculateIntersection
(
Segment2d
other
)
{
double
x1
=
p1
.
getX
();
double
x2
=
p2
.
getX
();
...
...
@@ -122,14 +122,14 @@ public class Segment2d {
double
y2
=
p2
.
getY
();
double
y3
=
other
.
getP1
().
getY
();
double
y4
=
other
.
getP2
().
getY
();
double
a1
=
x2
-
x1
;
double
b1
=
x4
-
x3
;
double
c1
=
x3
-
x1
;
double
a2
=
y2
-
y1
;
double
b2
=
y4
-
y3
;
double
c2
=
y3
-
y1
;
double
detA
=
b1
*
a2
-
a1
*
b2
;
double
detA1
=
b1
*
c2
-
c1
*
b2
;
double
detA2
=
a1
*
c2
-
c1
*
a2
;
...
...
@@ -143,15 +143,13 @@ public class Segment2d {
if
(
containsPoint
(
other
.
p2
))
{
return
new
IntersectionPoint2d
(
new
Line2d
(
other
.
p2
,
new
Vector2d
()),
0
);
}
return
null
;
}
else
{
// parallel
return
null
;
}
}
}
// parallel
return
null
;
}
double
s
=
detA1
/
detA
;
double
t
=
detA2
/
detA
;
if
(
s
<
0
||
s
>
1
||
t
<
0
||
t
>
1
)
{
// intersection on line but not on segment
return
null
;
...
...
@@ -160,7 +158,7 @@ public class Segment2d {
Vector2d
start
=
new
Vector2d
(
x1
,
y1
);
return
new
IntersectionPoint2d
(
new
Line2d
(
start
,
dir
),
s
);
}
public
boolean
containsPoint
(
Vector2d
p
)
{
double
xDir
=
p2
.
getX
()
-
p1
.
getX
();
if
(
xDir
==
0
)
{
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/math/Segment3d.java
View file @
1745865f
...
...
@@ -18,16 +18,18 @@
*/
package
de.hft.stuttgart.citydoctor2.math
;
import
java.io.Serial
;
import
java.io.Serializable
;
/**
* A bounded line between two points
*
*
* @author Matthias Betz
*
*/
public
class
Segment3d
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
-
506306945169934099L
;
private
static
final
double
PRECISION
=
0.00000001
;
...
...
@@ -44,7 +46,7 @@ public class Segment3d implements Serializable {
/**
* calculates the distance from this segment to the other segment
*
*
* @param otherSeg the other segment
* @return the distance
*/
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/math/Triangle2d.java
View file @
1745865f
...
...
@@ -20,15 +20,15 @@ package de.hft.stuttgart.citydoctor2.math;
/**
* A two dimensional triangle
*
*
* @author Matthias Betz
*
*/
public
class
Triangle2d
{
private
Vector2d
p1
;
private
Vector2d
p2
;
private
Vector2d
p3
;
private
final
Vector2d
p1
;
private
final
Vector2d
p2
;
private
final
Vector2d
p3
;
private
static
final
double
EPSILON
=
0
;
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/math/Triangle3d.java
View file @
1745865f
...
...
@@ -18,6 +18,7 @@
*/
package
de.hft.stuttgart.citydoctor2.math
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
de.hft.stuttgart.citydoctor2.tesselation.TesselatedPolygon
;
...
...
@@ -30,12 +31,13 @@ import de.hft.stuttgart.citydoctor2.tesselation.TesselatedPolygon;
*/
public
class
Triangle3d
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
-
6907333357794272435L
;
private
static
final
double
EPSILON
=
0.0001
;
private
Vector3d
p1
;
private
Vector3d
p2
;
private
Vector3d
p3
;
private
final
Vector3d
p1
;
private
final
Vector3d
p2
;
private
final
Vector3d
p3
;
private
TesselatedPolygon
partOf
;
...
...
@@ -154,8 +156,7 @@ public class Triangle3d implements Serializable {
Vector3d
a
=
p1
;
Vector3d
b
=
p2
;
Vector3d
c
=
p3
;
Vector3d
p
=
point
;
return
sameSide
(
p
,
a
,
b
,
c
)
&&
sameSide
(
p
,
b
,
a
,
c
)
&&
sameSide
(
p
,
c
,
a
,
b
);
return
sameSide
(
point
,
a
,
b
,
c
)
&&
sameSide
(
point
,
b
,
a
,
c
)
&&
sameSide
(
point
,
c
,
a
,
b
);
}
private
boolean
sameSide
(
Vector3d
p1
,
Vector3d
p2
,
Vector3d
a
,
Vector3d
b
)
{
...
...
@@ -248,14 +249,9 @@ public class Triangle3d implements Serializable {
return
false
;
}
if
(
p3
==
null
)
{
if
(
other
.
p3
!=
null
)
{
return
false
;
}
}
else
if
(!
p3
.
equals
(
other
.
p3
))
{
return
false
;
}
return
true
;
}
return
other
.
p3
==
null
;
}
else
return
p3
.
equals
(
other
.
p3
);
}
@Override
public
String
toString
()
{
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/math/UnitVector3d.java
View file @
1745865f
...
...
@@ -18,6 +18,7 @@
*/
package
de.hft.stuttgart.citydoctor2.math
;
import
java.io.Serial
;
import
java.util.Arrays
;
/**
...
...
@@ -29,6 +30,7 @@ public class UnitVector3d extends Vector3d {
private
static
final
String
UNIT_VECTOR_IS_IMMUTABLE
=
"Unit vector is immutable"
;
@Serial
private
static
final
long
serialVersionUID
=
-
374685263673211587L
;
public
static
final
UnitVector3d
X_AXIS
=
new
UnitVector3d
(
1
,
0
,
0
);
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/math/Vector3d.java
View file @
1745865f
...
...
@@ -18,6 +18,7 @@
*/
package
de.hft.stuttgart.citydoctor2.math
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
java.util.Arrays
;
...
...
@@ -29,6 +30,7 @@ import java.util.Arrays;
*/
public
class
Vector3d
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
3495650092142761365L
;
private
static
final
Vector3d
ORIGIN
=
new
Vector3d
();
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/math/graph/CycleNode.java
View file @
1745865f
...
...
@@ -44,7 +44,7 @@ public class CycleNode {
private
boolean
visited
=
false
;
private
Set
<
CycleNode
>
children
;
private
final
Set
<
CycleNode
>
children
;
public
CycleNode
(
LinearRing
value
)
{
children
=
new
HashSet
<>();
...
...
@@ -92,7 +92,7 @@ public class CycleNode {
if
(
lowlink
==
index
)
{
List
<
LinearRing
>
comps
=
new
LinkedList
<>();
CycleNode
w
=
null
;
CycleNode
w
;
do
{
w
=
s
.
pop
();
w
.
onStack
=
false
;
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/math/graph/KDTree.java
View file @
1745865f
...
...
@@ -35,7 +35,7 @@ public class KDTree {
private
static
final
int
K
=
3
;
private
Vertex
location
;
private
int
axis
;
private
final
int
axis
;
private
KDTree
left
;
private
KDTree
right
;
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/math/graph/PolygonGraph.java
View file @
1745865f
...
...
@@ -38,21 +38,14 @@ import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
*/
public
class
PolygonGraph
{
private
Map
<
Polygon
,
PolygonNode
>
nodeMap
;
private
final
Map
<
Polygon
,
PolygonNode
>
nodeMap
;
public
PolygonGraph
()
{
nodeMap
=
new
HashMap
<>();
}
private
PolygonNode
createOrGetNode
(
Polygon
p
)
{
PolygonNode
node
=
nodeMap
.
get
(
p
);
if
(
node
!=
null
)
{
return
node
;
}
else
{
node
=
new
PolygonNode
(
p
);
nodeMap
.
put
(
p
,
node
);
return
node
;
}
return
nodeMap
.
computeIfAbsent
(
p
,
PolygonNode:
:
new
);
}
public
void
addPolygonConnectionsFromVertex
(
Vertex
v
,
Geometry
geom
)
{
...
...
@@ -92,7 +85,7 @@ public class PolygonGraph {
List
<
List
<
Polygon
>>
components
=
new
ArrayList
<>();
for
(
PolygonNode
node
:
nodeMap
.
values
())
{
if
(
!
node
.
visited
())
{
if
(
node
.
isUn
visited
())
{
List
<
Polygon
>
component
=
new
ArrayList
<>();
Deque
<
PolygonNode
>
stack
=
new
LinkedList
<>();
stack
.
push
(
node
);
...
...
@@ -109,7 +102,7 @@ public class PolygonGraph {
node
.
setVisited
(
true
);
component
.
add
(
node
.
getContent
());
for
(
PolygonNode
child
:
node
.
getChildren
())
{
if
(
!
child
.
visited
())
{
if
(
child
.
isUn
visited
())
{
child
.
setVisited
(
true
);
stack
.
push
(
child
);
}
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/math/graph/PolygonNode.java
View file @
1745865f
...
...
@@ -31,8 +31,8 @@ import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
*/
public
class
PolygonNode
{
private
Polygon
content
;
private
Set
<
PolygonNode
>
children
;
private
final
Polygon
content
;
private
final
Set
<
PolygonNode
>
children
;
private
boolean
visited
=
false
;
public
PolygonNode
(
Polygon
p
)
{
...
...
@@ -56,8 +56,8 @@ public class PolygonNode {
this
.
visited
=
b
;
}
public
boolean
visited
()
{
return
visited
;
public
boolean
isUn
visited
()
{
return
!
visited
;
}
/*
...
...
@@ -88,13 +88,9 @@ public class PolygonNode {
return
false
;
PolygonNode
other
=
(
PolygonNode
)
obj
;
if
(
content
==
null
)
{
if
(
other
.
content
!=
null
)
return
false
;
}
else
if
(!
content
.
equals
(
other
.
content
))
{
return
false
;
}
return
true
;
}
return
other
.
content
==
null
;
}
else
return
content
.
equals
(
other
.
content
);
}
@Override
public
String
toString
()
{
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/parser/CityGmlParseException.java
View file @
1745865f
...
...
@@ -18,6 +18,8 @@
*/
package
de.hft.stuttgart.citydoctor2.parser
;
import
java.io.Serial
;
/**
* Exception when something went wrong while parsing the CityGML file.
*
...
...
@@ -26,6 +28,7 @@ package de.hft.stuttgart.citydoctor2.parser;
*/
public
class
CityGmlParseException
extends
Exception
{
@Serial
private
static
final
long
serialVersionUID
=
8602390540552748135L
;
public
CityGmlParseException
()
{
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/parser/CityGmlParser.java
View file @
1745865f
...
...
@@ -501,20 +501,14 @@ public class CityGmlParser {
Matcher
mURN
=
P_URN
.
matcher
(
srsName
);
// NOTE: Could use a HashMap if the switch/case becomes too long.
if
(
mURN
.
find
())
{
switch
(
mURN
.
group
(
1
))
{
case
"DE_DHDN_3GK2"
:
return
CRS_FACTORY
.
createFromName
(
"EPSG:31466"
);
case
"DE_DHDN_3GK3"
:
return
CRS_FACTORY
.
createFromName
(
"EPSG:31467"
);
case
"DE_DHDN_3GK4"
:
return
CRS_FACTORY
.
createFromName
(
"EPSG:31468"
);
case
"DE_DHDN_3GK5"
:
return
CRS_FACTORY
.
createFromName
(
"EPSG:31469"
);
case
"ETRS89_UTM32"
:
return
CRS_FACTORY
.
createFromName
(
"EPSG:25832"
);
default
:
return
null
;
}
return
switch
(
mURN
.
group
(
1
))
{
case
"DE_DHDN_3GK2"
->
CRS_FACTORY
.
createFromName
(
"EPSG:31466"
);
case
"DE_DHDN_3GK3"
->
CRS_FACTORY
.
createFromName
(
"EPSG:31467"
);
case
"DE_DHDN_3GK4"
->
CRS_FACTORY
.
createFromName
(
"EPSG:31468"
);
case
"DE_DHDN_3GK5"
->
CRS_FACTORY
.
createFromName
(
"EPSG:31469"
);
case
"ETRS89_UTM32"
->
CRS_FACTORY
.
createFromName
(
"EPSG:25832"
);
default
->
null
;
};
}
if
(
srsName
.
equals
(
"http://www.opengis.net/def/crs/EPSG/0/6697"
))
{
return
CRS_FACTORY
.
createFromParameters
(
"EPSG:6697"
,
"+proj=longlat +ellps=GRS80 +no_defs +axis=neu"
);
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/parser/EnvelopeFoundException.java
View file @
1745865f
...
...
@@ -20,6 +20,8 @@ package de.hft.stuttgart.citydoctor2.parser;
import
org.xml.sax.SAXException
;
import
java.io.Serial
;
/**
* To stop the SAXParser from further parsing when the relevant section has
* already been found.
...
...
@@ -29,6 +31,7 @@ import org.xml.sax.SAXException;
*/
public
class
EnvelopeFoundException
extends
SAXException
{
@Serial
private
static
final
long
serialVersionUID
=
-
9188617211115043815L
;
public
EnvelopeFoundException
()
{
...
...
Prev
1
…
3
4
5
6
7
8
9
Next
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment