improve variable and function names
This commit is contained in:
+10
-10
@@ -149,19 +149,19 @@ class SimulateWrapper {
|
|||||||
|
|
||||||
void ClearFigures() { simulate_->user_figures_.clear(); }
|
void ClearFigures() { simulate_->user_figures_.clear(); }
|
||||||
|
|
||||||
void SetText(
|
void SetTexts(
|
||||||
const std::vector<std::tuple<int, int, std::string, std::string>>& overlay_texts) {
|
const std::vector<std::tuple<int, int, std::string, std::string>>& texts) {
|
||||||
// Collection of [font, gridpos, text1, text2] tuples for overlay text
|
// Collection of [font, gridpos, text1, text2] tuples for overlay text
|
||||||
std::vector<std::tuple<int, int, std::string, std::string>> user_overlay_text;
|
std::vector<std::tuple<int, int, std::string, std::string>> user_texts;
|
||||||
for (const auto& [font, gridpos, text1, text2] : overlay_texts) {
|
for (const auto& [font, gridpos, text1, text2] : texts) {
|
||||||
user_overlay_text.push_back(std::make_tuple(font, gridpos, text1, text2));
|
user_texts.push_back(std::make_tuple(font, gridpos, text1, text2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set them all at once to prevent overlay text flickering.
|
// Set them all at once to prevent text flickering.
|
||||||
simulate_->user_text_ = user_overlay_text;
|
simulate_->user_texts_ = user_texts;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClearText() { simulate_->user_text_.clear(); }
|
void ClearTexts() { simulate_->user_texts_.clear(); }
|
||||||
|
|
||||||
void SetImages(
|
void SetImages(
|
||||||
const std::vector<std::tuple<mjrRect, pybind11::array&>> viewports_images
|
const std::vector<std::tuple<mjrRect, pybind11::array&>> viewports_images
|
||||||
@@ -303,9 +303,9 @@ PYBIND11_MODULE(_simulate, pymodule) {
|
|||||||
.def("set_figures", &SimulateWrapper::SetFigures,
|
.def("set_figures", &SimulateWrapper::SetFigures,
|
||||||
py::arg("viewports_figures"))
|
py::arg("viewports_figures"))
|
||||||
.def("clear_figures", &SimulateWrapper::ClearFigures)
|
.def("clear_figures", &SimulateWrapper::ClearFigures)
|
||||||
.def("set_text", &SimulateWrapper::SetText,
|
.def("set_texts", &SimulateWrapper::SetTexts,
|
||||||
py::arg("overlay_texts"))
|
py::arg("overlay_texts"))
|
||||||
.def("clear_text", &SimulateWrapper::ClearText)
|
.def("clear_texts", &SimulateWrapper::ClearTexts)
|
||||||
.def("set_images", &SimulateWrapper::SetImages,
|
.def("set_images", &SimulateWrapper::SetImages,
|
||||||
py::arg("viewports_images"))
|
py::arg("viewports_images"))
|
||||||
.def("clear_images", &SimulateWrapper::ClearImages)
|
.def("clear_images", &SimulateWrapper::ClearImages)
|
||||||
|
|||||||
@@ -139,12 +139,12 @@ class Handle:
|
|||||||
if sim is not None:
|
if sim is not None:
|
||||||
sim.clear_figures()
|
sim.clear_figures()
|
||||||
|
|
||||||
def set_text(self, overlay_texts: Union[Tuple[Optional[int], Optional[int], Optional[str], Optional[str]],
|
def set_texts(self, texts: Union[Tuple[Optional[int], Optional[int], Optional[str], Optional[str]],
|
||||||
List[Tuple[Optional[int], Optional[int], Optional[str], Optional[str]]]]):
|
List[Tuple[Optional[int], Optional[int], Optional[str], Optional[str]]]]):
|
||||||
"""Overlay text on the viewer.
|
"""Overlay text on the viewer.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
overlay_texts: Single tuple or list of tuples of (font, gridpos, text1, text2)
|
texts: Single tuple or list of tuples of (font, gridpos, text1, text2)
|
||||||
font: Font style from mujoco.mjtFontScale
|
font: Font style from mujoco.mjtFontScale
|
||||||
gridpos: Position of text box from mujoco.mjtGridPos
|
gridpos: Position of text box from mujoco.mjtGridPos
|
||||||
text1: Left text column, defaults to empty string if None
|
text1: Left text column, defaults to empty string if None
|
||||||
@@ -153,8 +153,8 @@ class Handle:
|
|||||||
sim = self._sim()
|
sim = self._sim()
|
||||||
if sim is not None:
|
if sim is not None:
|
||||||
# Convert single tuple to list if needed
|
# Convert single tuple to list if needed
|
||||||
if isinstance(overlay_texts, tuple):
|
if isinstance(texts, tuple):
|
||||||
overlay_texts = [overlay_texts]
|
texts = [texts]
|
||||||
|
|
||||||
# Convert None values to empty strings
|
# Convert None values to empty strings
|
||||||
default_font = mujoco.mjtFontScale.mjFONTSCALE_150
|
default_font = mujoco.mjtFontScale.mjFONTSCALE_150
|
||||||
@@ -164,14 +164,14 @@ class Handle:
|
|||||||
default_gridpos if gridpos is None else gridpos,
|
default_gridpos if gridpos is None else gridpos,
|
||||||
"" if text1 is None else text1,
|
"" if text1 is None else text1,
|
||||||
"" if text2 is None else text2)
|
"" if text2 is None else text2)
|
||||||
for font, gridpos, text1, text2 in overlay_texts]
|
for font, gridpos, text1, text2 in texts]
|
||||||
|
|
||||||
sim.set_text(processed_texts)
|
sim.set_texts(processed_texts)
|
||||||
|
|
||||||
def clear_text(self):
|
def clear_texts(self):
|
||||||
sim = self._sim()
|
sim = self._sim()
|
||||||
if sim is not None:
|
if sim is not None:
|
||||||
sim.clear_text()
|
sim.clear_texts()
|
||||||
|
|
||||||
def set_images(
|
def set_images(
|
||||||
self, viewports_images: Union[Tuple[mujoco.MjrRect, np.ndarray],
|
self, viewports_images: Union[Tuple[mujoco.MjrRect, np.ndarray],
|
||||||
|
|||||||
@@ -2606,7 +2606,7 @@ void Simulate::Render() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// overlay text
|
// overlay text
|
||||||
for (auto& [font, gridpos, text1, text2] : this->user_text_) {
|
for (auto& [font, gridpos, text1, text2] : this->user_texts_) {
|
||||||
ShowOverlayText(this, rect, font, gridpos, text1, text2);
|
ShowOverlayText(this, rect, font, gridpos, text1, text2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -253,7 +253,7 @@ class Simulate {
|
|||||||
mjvScene* user_scn = nullptr;
|
mjvScene* user_scn = nullptr;
|
||||||
mjtByte user_scn_flags_prev_[mjNRNDFLAG];
|
mjtByte user_scn_flags_prev_[mjNRNDFLAG];
|
||||||
std::vector<std::pair<mjrRect, mjvFigure>> user_figures_;
|
std::vector<std::pair<mjrRect, mjvFigure>> user_figures_;
|
||||||
std::vector<std::tuple<int, int, std::string, std::string>> user_text_;
|
std::vector<std::tuple<int, int, std::string, std::string>> user_texts_;
|
||||||
std::vector<std::tuple<mjrRect, unsigned char*>> user_images_;
|
std::vector<std::tuple<mjrRect, unsigned char*>> user_images_;
|
||||||
|
|
||||||
// OpenGL rendering and UI
|
// OpenGL rendering and UI
|
||||||
|
|||||||
Reference in New Issue
Block a user