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
6a45464b
Commit
6a45464b
authored
May 28, 2021
by
Christina
Browse files
add dataprocessor
parent
0e70d2f6
Pipeline
#507594
passed with stages
in 131 minutes and 57 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
VadereSimulator/src/org/vadere/simulator/projects/dataprocessing/processor/AreaDensityCountingNormedProcessor.java
0 → 100644
View file @
6a45464b
package
org.vadere.simulator.projects.dataprocessing.processor
;
import
org.vadere.annotation.factories.dataprocessors.DataProcessorClass
;
import
org.vadere.simulator.control.simulation.SimulationState
;
import
org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey
;
import
org.vadere.state.attributes.processor.AttributesAreaDensityCountingProcessor
;
import
org.vadere.state.attributes.processor.AttributesProcessor
;
import
org.vadere.state.scenario.Pedestrian
;
import
org.vadere.state.traci.CompoundObject
;
import
org.vadere.state.traci.CompoundObjectBuilder
;
import
org.vadere.state.traci.CompoundObjectProvider
;
import
org.vadere.state.traci.TraCIDataType
;
import
java.util.Collection
;
@DataProcessorClass
(
label
=
"AreaDensityCountingNormedProcessor"
)
public
class
AreaDensityCountingNormedProcessor
extends
AreaDataProcessor
<
Double
>
implements
CompoundObjectProvider
{
public
AreaDensityCountingNormedProcessor
()
{
super
(
"areaDensityCountingNormed"
);
setAttributes
(
new
AttributesAreaDensityCountingProcessor
());
}
@Override
protected
void
doUpdate
(
final
SimulationState
state
)
{
// Compute density by counting the pedestrians
int
pedCount
=
0
;
// Here could also be another processor. However, because a processor uses more memory, all pedestrians
// are collected from the state directly.
Collection
<
Pedestrian
>
pedestrians
=
state
.
getTopography
().
getPedestrianDynamicElements
().
getElements
();
// Alternatively, this could be implemented with "Streams"
for
(
Pedestrian
p
:
pedestrians
)
{
if
(
this
.
getMeasurementArea
().
getShape
().
contains
(
p
.
getPosition
())){
pedCount
++;
}
}
// With the area of the shape the density IS normalized to [ped/m^2] "pedCount/area"
double
measurementArea
=
this
.
getMeasurementArea
().
asPolygon
().
getArea
();
double
density
=
(
1.0
*
pedCount
)/
measurementArea
;
this
.
putValue
(
new
TimestepKey
(
state
.
getStep
()),
density
);
}
@Override
public
AttributesProcessor
getAttributes
()
{
if
(
super
.
getAttributes
()
==
null
)
{
setAttributes
(
new
AttributesAreaDensityCountingProcessor
());
}
return
super
.
getAttributes
();
}
@Override
public
CompoundObject
provide
(
CompoundObjectBuilder
builder
)
{
double
lastValue
=
getValue
(
getLastKey
());
int
measurementAreaId
=
this
.
getMeasurementArea
().
getId
();
return
builder
.
rest
()
.
add
(
TraCIDataType
.
INTEGER
)
// measurementAreaId
.
add
(
TraCIDataType
.
INTEGER
)
// timestep of count
.
add
(
TraCIDataType
.
DOUBLE
)
// countInId
.
build
(
measurementAreaId
,
getLastKey
().
getTimestep
(),
lastValue
);
}
}
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