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