Agent appearance の設定方法 - crest-cassia/CrowdWalk GitHub Wiki

Agent appearance の設定方法

Agent appearance ファイルを使ってエージェントの表示方法を標準形式(緑の ●)以外に変更することが出来ます。

  • プロパティファイルが存在するディレクトリに Agent appearance ファイルを作成します。
  • プロパティファイルに Agent appearance の設定を追加します。

プロパティファイルの設定方法

agent_appearance_file 項目に Agent appearance ファイルのパスを指定します。

"agent_appearance_file" : "agent_appearance.json",

Agent appearance ファイルの記述方法

  • JSON 形式で記述します。
  • ルートの要素は配列です。その中に複数の連想配列を記述します。
  • 連想配列には tag、model、2D_View、3D_View を記述し、これで一つの定義となります。
  • tag には、この定義を適用するエージェントを決めるためのキーワードを設定します。このキーワードとエージェントのタグ(ジェネレーションファイルの conditions で設定したタグ)の照合がおこなわれます。
    • キーワードが "文字列" の場合にはタグに "文字列" が含まれていれば該当します。(部分一致)
    • キーワードが "/正規表現/" の場合にはタグがその正規表現とマッチすれば該当します。
    • キーワードが "*" の場合にはすべてに該当します。
  • model にはエージェントの状態変化を表示に反映する方法を設定します。
    • className にはクラス名を設定します。
    • parameters には初期設定用のパラメータを設定します。(必要な場合)
  • 2D_View には 2D シミュレーションビューアで使用するエージェントの形状を設定します。
    • className にはクラス名を設定します。
    • parameters には初期設定用のパラメータを設定します。(必要な場合)
  • 3D_View には 3D シミュレーションビューアで使用するエージェントの形状を設定します。
    • className にはクラス名を設定します。
    • parameters には初期設定用のパラメータを設定します。(必要な場合)
  • tag で設定されたどのキーワードにも該当しなかったエージェントには標準形式が適用されます。
  • className に不適切な値を設定すると "Agent appearance file error: invalid className" や "java.lang.ClassCastException" が発生して CrowdWalk がエラー終了します。

使用可能な className

項目 className 使用可能 model
model SpeedModel エージェントの歩行速度に応じて色を変える
2D_View RoundAgent 丸いエージェント SpeedModel
SquareAgent 四角いエージェント SpeedModel
TriangleAgent 進行方向を向いて進む三角形のエージェント SpeedModel
3D_View SphereAgent 球体エージェント SpeedModel
CubeAgent 立方体エージェント SpeedModel
PlaneTriangleAgent 進行方向を向いて進む平面三角形のエージェント SpeedModel
TriangleMeshAgent ユーザー定義のポリゴンエージェント
(TriangleMesh(三角形メッシュ)についてはポリゴンデータの作り方参照)
SpeedModel

TriangleMeshAgent のパラメータ

名前 内容
points 実数配列 頂点座標(x, y, z)配列を一次元配列にフラット化したもの。
距離 1.0 がエージェントの直径に相当する
faces 整数配列 faces(points のインデックス値)
rotationAngle -180.0~180.0 ポリゴンに加える基本回転の角度
rotationAxis "X" / "Y" / "Z" ポリゴンに加える基本回転の回転軸
drawMode "FILL" / "LINE" 描画モード(塗り潰しまたはワイヤフレーム)
デフォルトは "FILL"

Agent appearance ファイルの記述例

[
    {
        "tag" : "ROOM_03",
        "model" : {
            "className" : "SpeedModel"
        },
        "2D_View" : {
            "className" : "RoundAgent"
        },
        "3D_View" : {
            "className" : "SphereAgent"
        }
    },
    {
        "tag" : "/_\\d1/",
        "model" : {
            "className" : "SpeedModel",
            "parameters" : {
                "coefficientOfHue" : 0.65
            }
        },
        "2D_View" : {
            "className" : "RoundAgent"
        },
        "3D_View" : {
            "className" : "SphereAgent"
        }
    },
    {
        "tag" : "*",
        "model" : {
            "className" : "SpeedModel"
        },
        "2D_View" : {
            "className" : "SquareAgent"
        },
        "3D_View" : {
            "className" : "CubeAgent"
        }
    }
]

使用したジェネレーションファイル

#{ "version" : 2}
[
 {"rule":"EACH",
  "agentType":{"className":"NaiveAgent"},
  "conditions": ["ROOM_01"],
  "total":5,"speedModel":"LANE",
  "startPlace":"ROOM1",
  "startTime":"7:30","duration":1,
  "goal":"EXIT",
  "plannedRoute":[{"":WAIT_UNTIL,"target":"HALLWAY_1","how":"SCATTER","until":"RESUME"}]},
 {"rule":"EACH",
  "agentType":{"className":"NaiveAgent"},
  "conditions": ["ROOM_02"],
  "total":10,"speedModel":"LANE",
  "startPlace":"ROOM2",
  "startTime":"7:30","duration":1,
  "goal":"EXIT",
  "plannedRoute":[{"":WAIT_FOR,"target":"HALLWAY_2","how":"PACK","until":300}]},
 {"rule":"EACH",
  "agentType":{"className":"NaiveAgent"},
  "conditions": ["ROOM_03"],
  "total":5,"speedModel":"LANE",
  "startPlace":"ROOM3",
  "startTime":"7:30","duration":1,
  "goal":"EXIT",
  "plannedRoute":[]}
]

3D シミュレーションビューアのスクリーンショット

capture000002

TriangleMeshAgent の定義サンプル(四角錐エージェント)

Agent appearance ファイル

[
    {
        "tag" : "*",
        "model" : {
            "className" : "SpeedModel"
        },
        "2D_View" : {
            "className" : "TriangleAgent"
        },
        "3D_View" : {
            "className" : "TriangleMeshAgent",
            "parameters" : {
                "description" : "横向きの四角錐",
                "points" : [
                    0.0, 0.0, 0.0,
                    0.0, 1.0, -0.5,
                    -0.5, 1.0, 0.0,
                    0.5, 1.0, 0.0,
                    0.0, 1.0, 0.5
                ],
                "faces" : [
                    0, 0,   2, 0,   1, 0,
                    0, 0,   1, 0,   3, 0,
                    0, 0,   3, 0,   4, 0,
                    0, 0,   4, 0,   2, 0,
                    4, 0,   1, 0,   2, 0,
                    4, 0,   3, 0,   1, 0
                ],
                "rotationAngle" : 90.0,
                "rotationAxis" : "Z"
            }
        }
    }
]

3D シミュレーションビューアのスクリーンショット(新国立劇場の避難シミュレーション)

capture000239

標準形式の設定ファイル

標準形式で表示するための設定ファイルが "CrowdWalk/crowdwalk/src/main/resources/agent_appearance.json" です。
プロパティファイルで agent_appearance_file が設定されていなければ標準形式の設定ファイルが使用されます。

標準形式の設定ファイルの内容:

[
    {
        "tag" : "*",
        "model" : {
            "className" : "SpeedModel",
            "parameters" : {
                "coefficientOfHue" : 0.35,
                "exponent" : 5.0,
                "saturation" : 0.8588,
                "brightness" : 0.698
            }
        },
        "2D_View" : {
            "className" : "RoundAgent",
            "parameters" : {}
        },
        "3D_View" : {
            "className" : "SphereAgent",
            "parameters" : {}
        }
    }
]

開発者向け情報

model クラスの作成

model クラスは CrowdWalk/crowdwalk/src/main/java/nodagumi/ananPJ/Gui/AgentAppearance/model ディレクトリに、AgentAppearanceModel のサブクラスとして作成します。

  • エージェントの色を変化させる場合は ColorModel のサブクラスにして、インスタンス変数 rgb にRGB値をセットします。
  • 初期設定パラメータの解析は init() メソッドをオーバーライドして記述します。パラメータの読み取りは JsonicHashMapGetter クラスのメソッドでおこないます。

2D_View クラスの作成

2D_View のクラスは CrowdWalk/crowdwalk/src/main/java/nodagumi/ananPJ/Gui/AgentAppearance/view2d ディレクトリに、AgentViewBase2D のサブクラスとして作成します。

  • 初期設定パラメータの解析は init() メソッドをオーバーライドして記述します。パラメータの読み取りは JsonicHashMapGetter クラスのメソッドでおこないます。

3D_View クラスの作成

3D_View のクラスは CrowdWalk/crowdwalk/src/main/java/nodagumi/ananPJ/Gui/AgentAppearance/view3d ディレクトリに、AgentViewBase3D のサブクラスとして作成します。

  • 初期設定パラメータの解析は init() メソッドをオーバーライドして記述します。パラメータの読み取りは JsonicHashMapGetter クラスのメソッドでおこないます。

クラスローダー用の設定

新しくクラスを作成した時には "CrowdWalk/crowdwalk/src/main/resources/agent_appearance_classes.json" に定義を加える必要があります。

{
    "SpeedModel" : "nodagumi.ananPJ.Gui.AgentAppearance.model.SpeedModel",
    "RoundAgent" : "nodagumi.ananPJ.Gui.AgentAppearance.view2d.RoundAgent",
    "SquareAgent" : "nodagumi.ananPJ.Gui.AgentAppearance.view2d.SquareAgent",
    "TriangleAgent" : "nodagumi.ananPJ.Gui.AgentAppearance.view2d.TriangleAgent",
    "SphereAgent" : "nodagumi.ananPJ.Gui.AgentAppearance.view3d.SphereAgent",
    "CubeAgent" : "nodagumi.ananPJ.Gui.AgentAppearance.view3d.CubeAgent",
    "PlaneTriangleAgent" : "nodagumi.ananPJ.Gui.AgentAppearance.view3d.PlaneTriangleAgent",
    "TriangleMeshAgent" : "nodagumi.ananPJ.Gui.AgentAppearance.view3d.TriangleMeshAgent"
}
⚠️ **GitHub.com Fallback** ⚠️