Skip to content

Commit

Permalink
Removed duplicated code with rendering::sceneFromFirstRenderEngine (#819
Browse files Browse the repository at this point in the history
)

Signed-off-by: ahcorde <[email protected]>

Co-authored-by: Michael Carroll <[email protected]>
  • Loading branch information
ahcorde and mjcarroll authored May 27, 2021
1 parent 3480302 commit 65e8b04
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 152 deletions.
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

0 comments on commit 65e8b04

Please sign in to comment.