Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
vadere
vadere
Commits
e093009b
Commit
e093009b
authored
Mar 16, 2020
by
Benedikt Zoennchen
Browse files
Mesh Counting Pedestrian Processor.
parent
895932c7
Pipeline
#224450
passed with stages
in 123 minutes and 23 seconds
Changes
8
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
VadereMeshing/src/org/vadere/meshing/mesh/gen/MeshPanel.java
View file @
e093009b
...
...
@@ -148,7 +148,7 @@ public class MeshPanel<V extends IVertex, E extends IHalfEdge, F extends IFace>
jFrame
.
setSize
((
int
)
width
+
10
,
(
int
)
height
+
10
);
jFrame
.
add
(
this
);
jFrame
.
setTitle
(
title
);
jFrame
.
setDefaultCloseOperation
(
WindowConstants
.
EXIT
_ON_CLOSE
);
jFrame
.
setDefaultCloseOperation
(
WindowConstants
.
DISPOSE
_ON_CLOSE
);
setVisible
(
true
);
jFrame
.
setVisible
(
true
);
//jFrame.setIgnoreRepaint(true);
...
...
VadereSimulator/src/org/vadere/simulator/projects/dataprocessing/datakey/FaceIdKey.java
0 → 100644
View file @
e093009b
package
org.vadere.simulator.projects.dataprocessing.datakey
;
import
org.jetbrains.annotations.NotNull
;
/**
* @author Benedikt Zoennchen
*/
public
class
FaceIdKey
implements
DataKey
<
FaceIdKey
>
{
private
final
int
faceId
;
public
FaceIdKey
(
final
int
faceId
)
{
this
.
faceId
=
faceId
;
}
public
int
getFaceId
()
{
return
faceId
;
}
@Override
public
int
compareTo
(
@NotNull
final
FaceIdKey
o
)
{
int
result
=
Integer
.
compare
(
this
.
faceId
,
o
.
faceId
);
return
result
;
}
public
static
String
getHeader
()
{
return
"faceId"
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
FaceIdKey
other
=
(
FaceIdKey
)
obj
;
if
(
faceId
!=
other
.
faceId
)
return
false
;
return
true
;
}
@Override
public
String
toString
()
{
return
Integer
.
toString
(
this
.
faceId
);
}
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
faceId
;
return
result
;
}
}
VadereSimulator/src/org/vadere/simulator/projects/dataprocessing/datakey/TimestepFaceIdKey.java
0 → 100644
View file @
e093009b
package
org.vadere.simulator.projects.dataprocessing.datakey
;
import
org.jetbrains.annotations.NotNull
;
public
class
TimestepFaceIdKey
implements
DataKey
<
TimestepFaceIdKey
>
{
private
final
int
timeStep
;
private
final
int
faceId
;
public
TimestepFaceIdKey
(
final
int
timeStep
,
final
int
faceId
)
{
this
.
timeStep
=
timeStep
;
this
.
faceId
=
faceId
;
}
public
int
getTimeStep
()
{
return
timeStep
;
}
public
int
getFaceId
()
{
return
faceId
;
}
@Override
public
int
compareTo
(
@NotNull
final
TimestepFaceIdKey
o
)
{
int
result
=
Integer
.
compare
(
this
.
timeStep
,
o
.
timeStep
);
if
(
result
==
0
)
{
result
=
Integer
.
compare
(
this
.
faceId
,
o
.
faceId
);
}
return
result
;
}
public
static
String
[]
getHeaders
()
{
return
new
String
[]
{
TimestepKey
.
getHeader
(),
FaceIdKey
.
getHeader
()
};
}
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
faceId
;
result
=
prime
*
result
+
timeStep
;
return
result
;
}
@Override
public
String
toString
()
{
return
"TimestepFaceIdKey{"
+
"timestep="
+
timeStep
+
", faceId="
+
faceId
+
'}'
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
TimestepFaceIdKey
other
=
(
TimestepFaceIdKey
)
obj
;
if
(
timeStep
!=
other
.
timeStep
)
return
false
;
if
(
faceId
!=
other
.
faceId
)
return
false
;
return
true
;
}
}
VadereSimulator/src/org/vadere/simulator/projects/dataprocessing/outputfile/TimestepKeyIdOutputFile.java
0 → 100644
View file @
e093009b
package
org.vadere.simulator.projects.dataprocessing.outputfile
;
import
org.vadere.annotation.factories.outputfiles.OutputFileClass
;
import
org.vadere.simulator.projects.dataprocessing.datakey.TimestepFaceIdKey
;
@OutputFileClass
(
dataKeyMapping
=
TimestepFaceIdKey
.
class
)
public
class
TimestepKeyIdOutputFile
extends
OutputFile
<
TimestepFaceIdKey
>
{
public
TimestepKeyIdOutputFile
()
{
super
(
TimestepFaceIdKey
.
getHeaders
());
}
@Override
public
String
[]
toStrings
(
final
TimestepFaceIdKey
key
)
{
return
new
String
[]
{
Integer
.
toString
(
key
.
getTimeStep
()),
Integer
.
toString
(
key
.
getFaceId
())
};
}
}
VadereSimulator/src/org/vadere/simulator/projects/dataprocessing/processor/MeshDensityCountingProcessor.java
0 → 100644
View file @
e093009b
package
org.vadere.simulator.projects.dataprocessing.processor
;
import
org.vadere.annotation.factories.dataprocessors.DataProcessorClass
;
import
org.vadere.meshing.mesh.gen.PFace
;
import
org.vadere.simulator.control.simulation.SimulationState
;
import
org.vadere.simulator.projects.dataprocessing.datakey.TimestepFaceIdKey
;
import
org.vadere.state.attributes.processor.AttributesMeshTimestepProcessor
;
import
org.vadere.state.scenario.Pedestrian
;
import
java.util.Collection
;
@DataProcessorClass
()
public
class
MeshDensityCountingProcessor
extends
MeshTimestepDataProcessor
<
Integer
>{
private
final
static
String
propertyNameNumberOfPedestrians
=
"numberOfPedestrians"
;
public
MeshDensityCountingProcessor
()
{
super
(
"meshDensityCounting"
);
setAttributes
(
new
AttributesMeshTimestepProcessor
());
}
@Override
protected
void
doUpdate
(
SimulationState
state
)
{
Collection
<
Pedestrian
>
peds
=
state
.
getTopography
().
getElements
(
Pedestrian
.
class
);
// reset count
for
(
PFace
f
:
getMesh
().
getFaces
())
{
getMesh
().
setIntegerData
(
f
,
propertyNameNumberOfPedestrians
,
0
);
}
// compute count
for
(
Pedestrian
ped
:
peds
)
{
if
(
getMeasurementArea
().
asPolygon
().
contains
(
ped
.
getPosition
()))
{
PFace
f
=
getTriangulation
().
locate
(
ped
.
getPosition
(),
ped
).
get
();
int
n
=
getMesh
().
getIntegerData
(
f
,
propertyNameNumberOfPedestrians
)
+
1
;
getMesh
().
setIntegerData
(
f
,
propertyNameNumberOfPedestrians
,
n
);
assert
!
getMesh
().
isBoundary
(
f
);
}
}
// write count
int
faceId
=
1
;
for
(
PFace
f
:
getMesh
().
getFaces
())
{
int
n
=
getMesh
().
getIntegerData
(
f
,
propertyNameNumberOfPedestrians
);
this
.
putValue
(
new
TimestepFaceIdKey
(
state
.
getStep
(),
faceId
),
n
);
faceId
++;
}
}
}
VadereSimulator/src/org/vadere/simulator/projects/dataprocessing/processor/MeshTimestepDataProcessor.java
0 → 100644
View file @
e093009b
package
org.vadere.simulator.projects.dataprocessing.processor
;
import
org.jetbrains.annotations.NotNull
;
import
org.vadere.annotation.factories.dataprocessors.DataProcessorClass
;
import
org.vadere.meshing.mesh.gen.IncrementalTriangulation
;
import
org.vadere.meshing.mesh.gen.MeshRenderer
;
import
org.vadere.meshing.mesh.gen.PFace
;
import
org.vadere.meshing.mesh.gen.PHalfEdge
;
import
org.vadere.meshing.mesh.gen.PMesh
;
import
org.vadere.meshing.mesh.gen.PVertex
;
import
org.vadere.meshing.mesh.impl.PMeshPanel
;
import
org.vadere.meshing.mesh.inter.IIncrementalTriangulation
;
import
org.vadere.meshing.mesh.inter.IMesh
;
import
org.vadere.meshing.mesh.triangulation.improver.eikmesh.gen.GenEikMesh
;
import
org.vadere.meshing.utils.color.Colors
;
import
org.vadere.simulator.control.simulation.SimulationState
;
import
org.vadere.simulator.projects.dataprocessing.ProcessorManager
;
import
org.vadere.simulator.projects.dataprocessing.datakey.TimestepFaceIdKey
;
import
org.vadere.state.attributes.processor.AttributesMeshTimestepProcessor
;
import
org.vadere.state.scenario.MeasurementArea
;
import
org.vadere.util.geometry.GeometryUtils
;
import
org.vadere.util.geometry.shapes.VPolygon
;
import
org.vadere.util.geometry.shapes.VRectangle
;
import
org.vadere.util.math.DistanceFunction
;
import
java.awt.*
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.function.Function
;
import
java.util.function.Predicate
;
/**
* @author Benedikt Zoennchen
*
* @param <V>
*/
@DataProcessorClass
(
label
=
"MeshTimestepDataProcessor"
)
public
abstract
class
MeshTimestepDataProcessor
<
V
>
extends
DataProcessor
<
TimestepFaceIdKey
,
V
>
{
private
IMesh
<
PVertex
,
PHalfEdge
,
PFace
>
mesh
;
private
IIncrementalTriangulation
<
PVertex
,
PHalfEdge
,
PFace
>
triangulation
;
private
MeasurementArea
measurementArea
;
protected
MeshTimestepDataProcessor
(
final
String
...
headers
)
{
super
(
headers
);
}
@Override
public
void
init
(
final
ProcessorManager
manager
)
{
super
.
init
(
manager
);
AttributesMeshTimestepProcessor
att
=
this
.
getAttributes
();
this
.
measurementArea
=
manager
.
getMeasurementArea
(
att
.
getMeasurementAreaId
(),
false
);
}
/*
@NotNull final IDistanceFunction distanceFunc,
@NotNull final IEdgeLengthFunction edgeLengthFunc,
@NotNull final Collection<? extends IPoint> fixPoints,
final double initialEdgeLen,
@NotNull final VRectangle bound,
@NotNull final Collection<? extends VShape> shapes,
@NotNull final IMeshSupplier<V, E, F> meshSupplier)
*/
@Override
public
void
preLoop
(
@NotNull
final
SimulationState
state
)
{
super
.
preLoop
(
state
);
VPolygon
measurementPolygon
=
measurementArea
.
asPolygon
();
GenEikMesh
<
PVertex
,
PHalfEdge
,
PFace
>
meshImprover
=
new
GenEikMesh
(
new
DistanceFunction
(
measurementPolygon
,
Collections
.
EMPTY_LIST
),
h
->
getAttributes
().
getEdgeLength
(),
Collections
.
EMPTY_LIST
,
getAttributes
().
getEdgeLength
(),
GeometryUtils
.
boundRelative
(
measurementPolygon
.
getPoints
()),
Collections
.
singleton
(
measurementPolygon
),
()
->
new
PMesh
()
);
/*Function<PVertex, Color> vertexColorFunction = v -> {
if(meshImprover.isSlidePoint(v)){
return Colors.BLUE;
} else if(meshImprover.isFixPoint(v)) {
return Colors.RED;
} else {
return Color.BLACK;
}
};
var meshRenderer = new MeshRenderer<>(meshImprover.getMesh(), f -> false, f -> Color.WHITE, e -> Color.GRAY, vertexColorFunction);
var meshPanel = new PMeshPanel(meshRenderer, 1000, 800);
meshPanel.display();
meshImprover.improve();
while (!meshImprover.isFinished()) {
synchronized (meshImprover.getMesh()) {
meshImprover.improve();
}
//Thread.sleep(500);
meshPanel.repaint();
}*/
triangulation
=
meshImprover
.
generate
();
triangulation
=
meshImprover
.
getTriangulation
();
mesh
=
triangulation
.
getMesh
();
var
meshRenderer
=
new
MeshRenderer
<>(
meshImprover
.
getMesh
(),
f
->
false
,
f
->
Color
.
WHITE
,
e
->
Color
.
GRAY
);
var
meshPanel
=
new
PMeshPanel
(
meshRenderer
,
300
,
300
);
meshPanel
.
display
();
//System.out.println(mesh.toPythonTriangulation(null));
}
public
IMesh
<
PVertex
,
PHalfEdge
,
PFace
>
getMesh
()
{
return
mesh
;
}
public
MeasurementArea
getMeasurementArea
()
{
return
this
.
measurementArea
;
}
public
IIncrementalTriangulation
<
PVertex
,
PHalfEdge
,
PFace
>
getTriangulation
()
{
return
triangulation
;
}
@Override
public
AttributesMeshTimestepProcessor
getAttributes
()
{
if
(
super
.
getAttributes
()
==
null
)
{
setAttributes
(
new
AttributesMeshTimestepProcessor
());
}
return
(
AttributesMeshTimestepProcessor
)
super
.
getAttributes
();
}
}
VadereState/src/org/vadere/state/attributes/processor/AttributesMeshTimestepProcessor.java
0 → 100644
View file @
e093009b
package
org.vadere.state.attributes.processor
;
public
class
AttributesMeshTimestepProcessor
extends
AttributesProcessor
{
private
int
measurementAreaId
=
-
1
;
private
double
edgeLength
=
1.0
;
public
int
getMeasurementAreaId
()
{
return
this
.
measurementAreaId
;
}
public
void
setMeasurementAreaId
(
final
int
measurementAreaId
)
{
checkSealed
();
this
.
measurementAreaId
=
measurementAreaId
;
}
public
double
getEdgeLength
()
{
return
edgeLength
;
}
public
void
setEdgeLength
(
final
double
edgeLength
)
{
checkSealed
();
this
.
edgeLength
=
edgeLength
;
}
}
VadereState/src/org/vadere/state/scenario/MeasurementArea.java
View file @
e093009b
...
...
@@ -51,6 +51,14 @@ public class MeasurementArea extends ScenarioElement {
return
null
;
}
public
VPolygon
asPolygon
()
{
VShape
shape
=
attributes
.
getShape
();
if
(
shape
instanceof
VRectangle
||
shape
instanceof
VPolygon
)
{
return
new
VPolygon
(
shape
);
}
return
null
;
}
/**
* Compare {@link MeasurementArea}s based on their shape.
* Important {@link VPolygon} != {@link VRectangle} even if all points are the same.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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