GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
graphic_main_robot_control.cpp
[詳解]
1
3
4// Copyright(c) 2023-2025 Design Engineering Laboratory, Saitama University
5// Released under the MIT license
6// https://opensource.org/licenses/mit-license.php
7
9
10#include "camera_dragger.h"
11#include "math_util.h"
12#include "dxlib_camera.h"
13#include "dxlib_gui_camera.h"
17#include "dxlib_util.h"
19#include "keyboard.h"
21#include "node_initializer.h"
22#include "phantomx_mk2_const.h"
23
24namespace designlab
25{
26
28 const std::shared_ptr<GraphicDataBroker>& broker,
29 const std::shared_ptr<const IHexapodCoordinateConverter>& converter_ptr,
30 const std::shared_ptr<const IHexapodJointCalculator>& calculator_ptr,
31 const std::shared_ptr<const IHexapodPostureValidator>& checker_ptr,
32 const std::shared_ptr<const ApplicationSettingRecord>& setting_ptr) :
33 mouse_ptr_(std::make_shared<Mouse>()),
34 broker_(broker),
35 converter_ptr_(converter_ptr),
36 calculator_ptr_(calculator_ptr),
37 display_node_switch_gui_(std::make_shared<DxlibGuiDisplayNodeSwitcher>(setting_ptr->window_size_x, setting_ptr->window_size_y)),
38 map_renderer_(std::make_shared<MapRenderer>())
39{
40 assert(broker_ != nullptr);
41 assert(converter_ptr_ != nullptr);
42 assert(calculator_ptr_ != nullptr);
43
44 const SimulationMapParameter map_param;
45 MapCreatorForSimulation map_creator(map_param);
46
47 map_state_ = map_creator.InitMap();
48 divided_map_state_.Init(map_state_, {});
49
50 const auto camera = std::make_shared<DxlibCamera>();
51 const auto camera_gui = std::make_shared<DxlibGuiCamera>(setting_ptr->window_size_x, setting_ptr->window_size_y, camera);
52 camera_gui->SetPos(10, 10, kDxlibGuiAnchorLeftTop, true);
53
54 const auto camera_dragger = std::make_shared<CameraDragger>(camera);
55
56 const auto camera_parameter_gui = std::make_shared<DxlibGuiCameraParameterDisplayer>(setting_ptr->window_size_x, setting_ptr->window_size_y, camera);
57 camera_parameter_gui->SetPos(10, 10, kDxlibGuiAnchorLeftTop, true);
58 camera_parameter_gui->SetVisible(false);
59
60 const auto node_display_gui = std::make_shared<DxlibGuiNodeDisplayer>(setting_ptr->window_size_x, setting_ptr->window_size_y, converter_ptr, calculator_ptr, checker_ptr);
61 node_display_gui->SetPos(setting_ptr->window_size_x - 10, 10, kDxlibGuiAnchorRightTop, true);
62
63 const auto robot_control_gui = std::make_shared<DxlibGuiRobotControl>(setting_ptr->window_size_x, setting_ptr->window_size_y, converter_ptr, calculator_ptr, checker_ptr);
64 robot_control_gui->SetPos(10, setting_ptr->window_size_y - 10, kDxlibGuiAnchorLeftBottom, true);
65
66 const auto [hexapod_renderer, hexapod_node_setter] =
67 HexapodRendererBuilder::Build(converter_ptr_, calculator_ptr_, setting_ptr->gui_display_quality);
68
69 map_renderer_->SetMapState(map_state_);
70 map_renderer_->SetNode(RobotStateNode{});
71
72 gui_updater_.Register(display_node_switch_gui_, 1);
73 gui_updater_.Register(camera_parameter_gui, 1);
74 gui_updater_.Register(camera_dragger, 0);
75 gui_updater_.Register(node_display_gui, 1);
76 gui_updater_.Register(camera_gui, 1);
77 gui_updater_.Register(robot_control_gui, 1);
78
79 gui_updater_.OpenTerminal();
80
81 node_setter_group_.Register(camera_gui);
82 node_setter_group_.Register(node_display_gui);
83 node_setter_group_.Register(hexapod_node_setter);
84 node_setter_group_.Register(map_renderer_);
85 node_setter_group_.Register(robot_control_gui);
86
87 render_group_.Register(hexapod_renderer);
88 render_group_.Register(map_renderer_);
89}
90
92{
93 assert(mouse_ptr_ != nullptr);
94
95 mouse_ptr_->Update();
96
97 gui_updater_.Activate(mouse_ptr_);
98
99 if (!graph_.empty())
100 {
101 // 表示するノードを取得する.
102 size_t display_node_index_ = display_node_switch_gui_->GetDisplayNodeNum();
103
104 // ノードの情報を設定するGUIに情報を伝達する.
105 node_setter_group_.SetNode(graph_.at(display_node_index_));
106 }
107
108 if (broker_->graph.GetUpdateCount() != graph_update_count_)
109 {
110 graph_update_count_ = broker_->graph.GetUpdateCount();
111
112 graph_ = broker_->graph.GetData();
113
114 display_node_switch_gui_->SetGraphData(graph_.size(), { graph_.size() - 1 });
115 }
116
117 if (broker_->map_state.GetUpdateCount() != map_update_count_)
118 {
119 map_update_count_ = broker_->map_state.GetUpdateCount();
120
121 map_state_ = broker_->map_state.GetData();
122
123 divided_map_state_.Init(map_state_, {});
124
125 map_renderer_->SetMapState(map_state_);
126 }
127
128 return true;
129}
130
132{
133 render_group_.Draw();
134
135 gui_updater_.Draw();
136}
137
138} // namespace designlab
void Init(const MapState &map_state, const Vector3 global_robot_com)
マップのデータを初期化する. ロボットの重心座標を中心にマップのデータを格子状に分割し, その中に存在する脚設置可能点を集める.
void Register(const std::shared_ptr< IDxlib3dRenderer > &renderer)
3D描画を行うクラスを登録する.
void Draw() const
登録されているクラスの draw 関数を呼ぶ. また,Zソートを行う.
ノードの表示・切り替えを行うGUIのクラス.
void Register(const std::shared_ptr< T > &gui_ptr, int priority)
UpdateとDrawを行うGUIを登録する. IDxlibClickableまたは,IDxlibDraggable, IDxlibWheelHandlerを継承している場合は,それらも同時に登録す...
void OpenTerminal()
Terminalを開く. 他のGUIをRegisterした後に呼び出すこと. 2回目以降の呼び出しは無視される. また,Terminalは最も優先度が高い.
void Draw() const
登録済みのGUIのDraw関数を実行する.
void Activate(const std::shared_ptr< const Mouse > &mouse_ptr)
GUIのUpdate関数を実行し,クリック,ドラッグなどの判定を行う. 優先度の高いものから順に各種判定を行う.
void Register(const std::shared_ptr< IDxlibNodeSetter > &setter)
ノードの設定を行うクラスを登録する.
void SetNode(const RobotStateNode &node)
登録済みの全てのクラスに対してノードの設定を行う.
void Draw() const override
描画を行う. ここでは描画系の処理のみを行い内部のデータを 更新しないため const を付けている.
bool Update() override
描画画面の更新を行う.純粋仮想関数のため, 継承先では必ず override する必要がある.
GraphicMainRobotControl(const std::shared_ptr< GraphicDataBroker > &broker, const std::shared_ptr< const IHexapodCoordinateConverter > &converter_ptr, const std::shared_ptr< const IHexapodJointCalculator > &calculator_ptr, const std::shared_ptr< const IHexapodPostureValidator > &checker_ptr, const std::shared_ptr< const ApplicationSettingRecord > &setting_ptr)
static std::tuple< std::shared_ptr< IDxlib3dRenderer >, std::shared_ptr< IDxlibNodeSetter > > Build(const std::shared_ptr< const IHexapodCoordinateConverter > &converter_ptr, const std::shared_ptr< const IHexapodJointCalculator > &calculator_ptr, DisplayQuality display_quality)
HexapodRendererクラスのインスタンスを作成する. static関数なので,HexapodRendererBuilder::Build()と呼び出す.
シミュレーション用のマップを生成するクラス.
MapState InitMap() override
マップの初期化を行う.
マップの描画を行うクラス.
Dxlibでマウス入力を取得するクラス.
Definition mouse.h:21
constexpr unsigned int kDxlibGuiAnchorLeftBottom
constexpr unsigned int kDxlibGuiAnchorRightTop
constexpr unsigned int kDxlibGuiAnchorLeftTop
Definition com_type.h:24
グラフ構造のためのノード(頂点).旧名 LNODE
マップ生成時のモードとオプションを指定する構造体.