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
2b6c655b
Commit
2b6c655b
authored
Jan 29, 2025
by
Matthias Betz
Browse files
removing jogl dependency
parent
ca7fe768
Pipeline
#10980
failed with stage
in 52 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
CityDoctorParent/CityDoctorModel/pom.xml
View file @
2b6c655b
...
...
@@ -30,14 +30,6 @@
<groupId>
gov.nist.math
</groupId>
<artifactId>
jama
</artifactId>
</dependency>
<dependency>
<groupId>
org.jogamp.gluegen
</groupId>
<artifactId>
gluegen-rt-main
</artifactId>
</dependency>
<dependency>
<groupId>
org.jogamp.jogl
</groupId>
<artifactId>
jogl-all-main
</artifactId>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/datastructure/ConcretePolygon.java
View file @
2b6c655b
...
...
@@ -18,21 +18,21 @@
*/
package
de.hft.stuttgart.citydoctor2.datastructure
;
import
java.io.Serial
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
de.hft.stuttgart.citydoctor2.check.Check
;
import
de.hft.stuttgart.citydoctor2.check.CheckError
;
import
de.hft.stuttgart.citydoctor2.check.CheckId
;
import
de.hft.stuttgart.citydoctor2.check.Checkable
;
import
de.hft.stuttgart.citydoctor2.math.Vector3d
;
import
de.hft.stuttgart.citydoctor2.tesselation.
Jogl
Tesselator
;
import
de.hft.stuttgart.citydoctor2.tesselation.
Earcut
Tesselator
;
import
de.hft.stuttgart.citydoctor2.tesselation.TesselatedPolygon
;
import
de.hft.stuttgart.citydoctor2.utils.CopyHandler
;
import
de.hft.stuttgart.citydoctor2.utils.Copyable
;
import
java.io.Serial
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
/**
* A polygon that actually contains the rings and points representing the
* geometry
...
...
@@ -77,7 +77,7 @@ public class ConcretePolygon extends Polygon {
*/
@Override
public
TesselatedPolygon
tesselate
()
{
return
Jogl
Tesselator
.
tesselatePolygon
(
this
);
return
Earcut
Tesselator
.
tesselatePolygon
(
this
);
}
/*
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/math/Ray.java
View file @
2b6c655b
...
...
@@ -18,9 +18,7 @@
*/
package
de.hft.stuttgart.citydoctor2.math
;
import
de.hft.stuttgart.citydoctor2.datastructure.Polygon
;
import
de.hft.stuttgart.citydoctor2.tesselation.TesselatedPolygon
;
import
de.hft.stuttgart.citydoctor2.tesselation.JoglTesselator
;
/**
* A ray constructed by a point and a direction. A ray has a starting point and
...
...
@@ -97,8 +95,4 @@ public class Ray {
}
}
public
Vector3d
intersectsPolygon
(
Polygon
p
)
{
return
intersectsPolygon
(
JoglTesselator
.
tesselatePolygon
(
p
));
}
}
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/tesselation/JoglTesselator.java
deleted
100644 → 0
View file @
ca7fe768
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package
de.hft.stuttgart.citydoctor2.tesselation
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
com.jogamp.opengl.GL
;
import
com.jogamp.opengl.glu.GLU
;
import
com.jogamp.opengl.glu.GLUtessellator
;
import
com.jogamp.opengl.glu.GLUtessellatorCallbackAdapter
;
import
de.hft.stuttgart.citydoctor2.datastructure.LinearRing
;
import
de.hft.stuttgart.citydoctor2.datastructure.Polygon
;
import
de.hft.stuttgart.citydoctor2.datastructure.Vertex
;
import
de.hft.stuttgart.citydoctor2.math.Vector3d
;
/**
* Tesselator to create triangles out of polygons. Uses JOGL implementation.
*
* @author Matthias Betz
*
*/
public
class
JoglTesselator
{
private
static
final
String
DATA_WAS_NOT_A_LIST
=
"data was not a list"
;
private
static
final
GLU
glu
=
new
GLU
();
private
static
final
GLUtessellator
tess
=
GLU
.
gluNewTess
();
private
static
final
GLUtessellatorCallbackAdapter
callback
;
private
static
final
ArrayList
<
Primitive
>
primitives
=
new
ArrayList
<>();
static
{
callback
=
new
GLUtessellatorCallbackAdapter
()
{
private
Primitive
lastPrimitive
;
@Override
public
void
beginData
(
int
type
,
Object
data
)
{
if
(!(
data
instanceof
ArrayList
<?>))
{
throw
new
IllegalStateException
(
DATA_WAS_NOT_A_LIST
);
}
@SuppressWarnings
(
"unchecked"
)
ArrayList
<
Vector3d
>
vertices
=
(
ArrayList
<
Vector3d
>)
data
;
lastPrimitive
=
new
Primitive
(
type
,
vertices
);
primitives
.
add
(
lastPrimitive
);
}
@Override
public
void
vertexData
(
Object
vertex
,
Object
data
)
{
if
(!(
data
instanceof
ArrayList
))
{
throw
new
IllegalStateException
(
DATA_WAS_NOT_A_LIST
);
}
if
(!(
vertex
instanceof
Integer
))
{
throw
new
IllegalStateException
(
"vertex has to be an Integer"
);
}
lastPrimitive
.
addIndex
((
Integer
)
vertex
);
}
@Override
public
void
combineData
(
double
[]
coords
,
Object
[]
vertexIndices
,
float
[]
weights
,
Object
[]
outgoingData
,
Object
data
)
{
if
(!(
data
instanceof
ArrayList
<?>))
{
throw
new
IllegalStateException
(
DATA_WAS_NOT_A_LIST
);
}
@SuppressWarnings
(
"unchecked"
)
ArrayList
<
Vector3d
>
vertices
=
(
ArrayList
<
Vector3d
>)
data
;
// to ensure the coordinates are valid
double
[]
myCoords
=
Arrays
.
copyOf
(
coords
,
3
);
Vector3d
newVertex
=
new
Vector3d
(
myCoords
);
outgoingData
[
0
]
=
vertices
.
size
();
vertices
.
add
(
newVertex
);
}
@Override
public
void
errorData
(
int
errnum
,
Object
data
)
{
throw
new
TesselationException
(
"GLU Error "
+
glu
.
gluErrorString
(
errnum
));
}
};
GLU
.
gluTessCallback
(
tess
,
GLU
.
GLU_TESS_BEGIN_DATA
,
callback
);
GLU
.
gluTessCallback
(
tess
,
GLU
.
GLU_TESS_VERTEX_DATA
,
callback
);
GLU
.
gluTessCallback
(
tess
,
GLU
.
GLU_TESS_ERROR_DATA
,
callback
);
GLU
.
gluTessCallback
(
tess
,
GLU
.
GLU_TESS_COMBINE_DATA
,
callback
);
GLU
.
gluTessCallback
(
tess
,
GLU
.
GLU_TESS_END_DATA
,
callback
);
}
public
static
TesselatedPolygon
tesselatePolygon
(
Polygon
p
)
{
return
tesselatePolygon
(
p
,
true
);
}
public
static
TesselatedPolygon
tesselatePolygon
(
Polygon
p
,
boolean
discardDegeneratedTriangles
)
{
ArrayList
<
Vector3d
>
vertices
=
new
ArrayList
<>();
Vector3d
normal
=
p
.
calculateNormalNormalized
();
synchronized
(
tess
)
{
GLU
.
gluTessProperty
(
tess
,
GLU
.
GLU_TESS_BOUNDARY_ONLY
,
GL
.
GL_FALSE
);
GLU
.
gluTessBeginPolygon
(
tess
,
vertices
);
GLU
.
gluTessNormal
(
tess
,
normal
.
getX
(),
normal
.
getY
(),
normal
.
getZ
());
// exterior ring
LinearRing
ext
=
p
.
getExteriorRing
();
createContour
(
vertices
,
ext
);
// interior rings
for
(
LinearRing
lr
:
p
.
getInnerRings
())
{
createContour
(
vertices
,
lr
);
}
GLU
.
gluTessEndPolygon
(
tess
);
ArrayList
<
Integer
>
indices
=
new
ArrayList
<>();
for
(
Primitive
primitive
:
primitives
)
{
primitive
.
fillListWithIndices
(
indices
,
discardDegeneratedTriangles
);
}
primitives
.
clear
();
return
new
TesselatedPolygon
(
vertices
,
indices
,
p
);
}
}
private
static
void
createContour
(
List
<
Vector3d
>
vertices
,
LinearRing
lr
)
{
GLU
.
gluTessBeginContour
(
tess
);
for
(
Vertex
v
:
lr
.
getVertices
())
{
vertices
.
add
(
v
);
GLU
.
gluTessVertex
(
tess
,
v
.
getCoordinates
(),
0
,
vertices
.
size
()
-
1
);
}
GLU
.
gluTessEndContour
(
tess
);
}
public
static
TesselatedRing
tesselateRing
(
LinearRing
r
,
boolean
discardDegeneratedTriangles
)
{
ArrayList
<
Vector3d
>
vertices
=
new
ArrayList
<>();
Vector3d
normal
=
r
.
calculateNormal
();
synchronized
(
tess
)
{
GLU
.
gluTessBeginPolygon
(
tess
,
vertices
);
GLU
.
gluTessNormal
(
tess
,
normal
.
getX
(),
normal
.
getY
(),
normal
.
getZ
());
createContour
(
vertices
,
r
);
GLU
.
gluTessEndPolygon
(
tess
);
ArrayList
<
Integer
>
indices
=
new
ArrayList
<>();
for
(
Primitive
primitive
:
primitives
)
{
primitive
.
fillListWithIndices
(
indices
,
discardDegeneratedTriangles
);
}
primitives
.
clear
();
return
new
TesselatedRing
(
vertices
,
indices
,
r
);
}
}
public
static
TesselatedRing
tesselateRing
(
LinearRing
r
)
{
return
tesselateRing
(
r
,
true
);
}
private
JoglTesselator
()
{
// only static useage
}
}
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/tesselation/Primitive.java
deleted
100644 → 0
View file @
ca7fe768
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package
de.hft.stuttgart.citydoctor2.tesselation
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
com.jogamp.opengl.GL
;
import
de.hft.stuttgart.citydoctor2.math.Vector3d
;
/**
* Result of the tesselation process. Primitives can be converted to triangles.
*
* @author Matthias Betz
*
*/
public
class
Primitive
{
private
static
final
Logger
logger
=
LogManager
.
getLogger
(
Primitive
.
class
);
private
static
final
double
AREA_EPSILON
=
0.00001
;
private
final
int
type
;
private
final
List
<
Integer
>
pIndices
=
new
ArrayList
<>();
private
final
List
<
Vector3d
>
vertices
;
public
Primitive
(
int
type
,
List
<
Vector3d
>
vertices
)
{
this
.
vertices
=
vertices
;
this
.
type
=
type
;
}
public
void
fillListWithIndices
(
List
<
Integer
>
indices
,
boolean
discardDegeneratedTriangles
)
{
switch
(
type
)
{
case
GL
.
GL_TRIANGLES
:
for
(
int
i
=
0
;
i
<
pIndices
.
size
();
i
+=
3
)
{
addToListIfAreaNonNull
(
pIndices
.
get
(
i
),
pIndices
.
get
(
i
+
1
),
pIndices
.
get
(
i
+
2
),
indices
,
discardDegeneratedTriangles
);
}
break
;
case
GL
.
GL_TRIANGLE_STRIP
:
for
(
int
i
=
0
;
i
<
pIndices
.
size
()
-
2
;
i
++)
{
if
(
i
%
2
==
0
)
{
addToListIfAreaNonNull
(
pIndices
.
get
(
i
),
pIndices
.
get
(
i
+
1
),
pIndices
.
get
(
i
+
2
),
indices
,
discardDegeneratedTriangles
);
}
else
{
addToListIfAreaNonNull
(
pIndices
.
get
(
i
),
pIndices
.
get
(
i
+
2
),
pIndices
.
get
(
i
+
1
),
indices
,
discardDegeneratedTriangles
);
}
}
break
;
case
GL
.
GL_TRIANGLE_FAN
:
Integer
first
=
pIndices
.
get
(
0
);
for
(
int
i
=
0
;
i
<
pIndices
.
size
()
-
2
;
i
++)
{
addToListIfAreaNonNull
(
first
,
pIndices
.
get
(
i
+
1
),
pIndices
.
get
(
i
+
2
),
indices
,
discardDegeneratedTriangles
);
}
break
;
default
:
throw
new
IllegalStateException
(
"unknown triangle type found: "
+
type
);
}
}
public
void
addIndex
(
Integer
i
)
{
pIndices
.
add
(
i
);
}
private
void
addToListIfAreaNonNull
(
Integer
i1
,
Integer
i2
,
Integer
i3
,
List
<
Integer
>
indices
,
boolean
discardDegeneratedTriangles
)
{
Vector3d
v1
=
vertices
.
get
(
i1
);
Vector3d
v2
=
vertices
.
get
(
i2
);
Vector3d
v3
=
vertices
.
get
(
i3
);
if
(
discardDegeneratedTriangles
&&
Math
.
abs
(
calculateAreaOfTriangle
(
v1
,
v2
,
v3
))
<=
AREA_EPSILON
)
{
// switch to discard degenerated triangles is enabled and triangle has nearly no area
logger
.
trace
(
"Tesselator created degenerated triangle, ignoring"
);
}
else
{
indices
.
add
(
i1
);
indices
.
add
(
i2
);
indices
.
add
(
i3
);
}
}
/**
* Calculates the area of a triangle given by the 3 points
*
* @param v1 the first point of the triangle
* @param v2 the second point of the triangle
* @param v3 the last point of the triangle
* @return the area of the triangle
*/
private
static
double
calculateAreaOfTriangle
(
Vector3d
v1
,
Vector3d
v2
,
Vector3d
v3
)
{
double
a
=
v1
.
getDistance
(
v2
);
double
b
=
v2
.
getDistance
(
v3
);
double
c
=
v1
.
getDistance
(
v3
);
double
s
=
0.5d
*
(
a
+
b
+
c
);
return
Math
.
sqrt
(
s
*
(
s
-
a
)
*
(
s
-
b
)
*
(
s
-
c
));
}
}
Matthias Betz
@betzms
mentioned in commit
7a5a9132
·
Jan 29, 2025
mentioned in commit
7a5a9132
mentioned in commit 7a5a91322ab18069e91fb5ac8620c207ea8e2213
Toggle commit list
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