Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed duplicated code with rendering::sceneFromFirstRenderEngine #819

Merged
merged 3 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 10 additions & 48 deletions src/gui/plugins/align_tool/AlignTool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ namespace ignition::gazebo

/// \brief The map of the original transparency values for the nodes.
public: std::map<std::string, double> originalTransparency;

/// \brief Pointer to the scene.
public: rendering::ScenePtr scene{nullptr};
};
}

Expand Down Expand Up @@ -316,62 +319,20 @@ void AlignTool::Align()
if (this->dataPtr->currentState == AlignState::NONE)
return;

auto loadedEngNames = rendering::loadedEngines();
if (loadedEngNames.empty())
{
ignerr << "Internal error: engine should be loaded at this point."
<< std::endl;
return;
}

// Assume there is only one engine loaded
auto engineName = loadedEngNames[0];
if (loadedEngNames.size() > 1)
{
ignwarn << "Found more than one loaded engine "
"- using " << engineName << "." << std::endl;
}
auto engine = rendering::engine(engineName);

if (!engine)
{
ignerr << "Internal error: failed to load engine [" << engineName
<< "]. Align tool plugin won't work." << std::endl;
return;
}

if (engine->SceneCount() == 0)
{
ignerr<< "Internal error: no scenes are available with the loaded engine."
<< std::endl;
return;
}
// assume there is only one scene
// load scene
auto scene = engine->SceneByIndex(0);

if (!scene)
{
ignerr << "Internal error: scene is null." << std::endl;
return;
}

if (!scene->IsInitialized() || scene->VisualCount() == 0)
{
ignerr << "Internal error: scene is either not initialized "
"or there are no visuals within it." << std::endl;
return;
}
if (!this->dataPtr->scene)
this->dataPtr->scene = rendering::sceneFromFirstRenderEngine();

// Get current list of selected entities
std::vector<ignition::rendering::VisualPtr> selectedList;
ignition::rendering::VisualPtr relativeVisual;

for (const auto &entityId : this->dataPtr->selectedEntities)
{
for (auto i = 0u; i < scene->VisualCount(); ++i)
for (auto i = 0u; i < this->dataPtr->scene->VisualCount(); ++i)
{
ignition::rendering::VisualPtr vis = scene->VisualByIndex(i);
ignition::rendering::VisualPtr vis =
this->dataPtr->scene->VisualByIndex(i);
if (!vis)
continue;
if (std::get<int>(vis->UserData("gazebo-entity")) ==
Expand Down Expand Up @@ -417,7 +378,8 @@ void AlignTool::Align()
rendering::VisualPtr vis = selectedList[i];

// Check here to see if visual is top level or not, continue if not
rendering::VisualPtr topLevelVis = this->TopLevelVisual(scene, vis);
rendering::VisualPtr topLevelVis = this->TopLevelVisual(
this->dataPtr->scene, vis);
if (topLevelVis != vis)
continue;

Expand Down
37 changes: 1 addition & 36 deletions src/gui/plugins/grid_config/GridConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,42 +149,7 @@ void GridConfig::UpdateGrid()
/////////////////////////////////////////////////
void GridConfig::LoadGrid()
{
auto loadedEngNames = rendering::loadedEngines();
if (loadedEngNames.empty())
return;

// assume there is only one engine loaded
auto engineName = loadedEngNames[0];
if (loadedEngNames.size() > 1)
{
igndbg << "More than one engine is available. "
<< "Grid config plugin will use engine ["
<< engineName << "]" << std::endl;
}
auto engine = rendering::engine(engineName);
if (!engine)
{
ignerr << "Internal error: failed to load engine [" << engineName
<< "]. Grid plugin won't work." << std::endl;
return;
}

if (engine->SceneCount() == 0)
return;

// assume there is only one scene
// load scene
auto scene = engine->SceneByIndex(0);
if (!scene)
{
ignerr << "Internal error: scene is null." << std::endl;
return;
}

if (!scene->IsInitialized() || nullptr == scene->RootVisual())
{
return;
}
auto scene = rendering::sceneFromFirstRenderEngine();

// load grid
// if gridPtr found, load the existing gridPtr to class
Expand Down
37 changes: 1 addition & 36 deletions src/gui/plugins/transform_control/TransformControl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,42 +164,7 @@ void TransformControl::SnapToGrid()
/////////////////////////////////////////////////
void TransformControl::LoadGrid()
{
auto loadedEngNames = rendering::loadedEngines();
if (loadedEngNames.empty())
return;

// assume there is only one engine loaded
auto engineName = loadedEngNames[0];
if (loadedEngNames.size() > 1)
{
igndbg << "More than one engine is available. "
<< "Grid config plugin will use engine ["
<< engineName << "]" << std::endl;
}
auto engine = rendering::engine(engineName);
if (!engine)
{
ignerr << "Internal error: failed to load engine [" << engineName
<< "]. Grid plugin won't work." << std::endl;
return;
}

if (engine->SceneCount() == 0)
return;

// assume there is only one scene
// load scene
auto scene = engine->SceneByIndex(0);
if (!scene)
{
ignerr << "Internal error: scene is null." << std::endl;
return;
}

if (!scene->IsInitialized() || scene->VisualCount() == 0)
{
return;
}
auto scene = rendering::sceneFromFirstRenderEngine();

// load grid
// if gridPtr found, load the existing gridPtr to class
Expand Down
33 changes: 1 addition & 32 deletions src/systems/camera_video_recorder/CameraVideoRecorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,38 +218,7 @@ void CameraVideoRecorderPrivate::OnPostRender()
// get scene
if (!this->scene)
{
auto loadedEngNames = rendering::loadedEngines();
if (loadedEngNames.empty())
return;

// assume there is only one engine loaded
auto engineName = loadedEngNames[0];
if (loadedEngNames.size() > 1)
{
igndbg << "More than one engine is available. "
<< "Camera video recorder system will use engine ["
<< engineName << "]" << std::endl;
}
auto engine = rendering::engine(engineName);
if (!engine)
{
ignerr << "Internal error: failed to load engine [" << engineName
<< "]. Camera video recorder system won't work." << std::endl;
return;
}

if (engine->SceneCount() == 0)
return;

// assume there is only one scene
// load scene
auto s = engine->SceneByIndex(0);
if (!s)
{
ignerr << "Internal error: scene is null." << std::endl;
return;
}
this->scene = s;
this->scene = rendering::sceneFromFirstRenderEngine();
}

// return if scene not ready or no sensors available.
Expand Down