Skip to content

Commit

Permalink
apply changes to ci vct
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 committed Sep 5, 2024
1 parent c899cc2 commit 28f7987
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ GlobalIlluminationCiVct::~GlobalIlluminationCiVct()
}

/////////////////////////////////////////////////
void GlobalIlluminationCiVct::LoadGlobalIlluminationCiVct()
bool GlobalIlluminationCiVct::LoadGlobalIlluminationCiVct()
REQUIRES(this->dataPtr->serviceMutex)
{
auto loadedEngNames = rendering::loadedEngines();
if (loadedEngNames.empty())
{
return;
return false;
}

// assume there is only one engine loaded
Expand All @@ -194,24 +194,24 @@ void GlobalIlluminationCiVct::LoadGlobalIlluminationCiVct()
{
gzerr << "Internal error: failed to load engine [" << engineName
<< "]. GlobalIlluminationCiVct plugin won't work." << std::endl;
return;
return false;
}

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

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

if (!scene->IsInitialized() || scene->VisualCount() == 0)
{
return;
return false;
}

// Create visual
Expand All @@ -225,6 +225,7 @@ void GlobalIlluminationCiVct::LoadGlobalIlluminationCiVct()
<< std::endl;

gz::gui::App()->findChild<gz::gui::MainWindow *>()->removeEventFilter(this);
return false;
}
else
{
Expand Down Expand Up @@ -254,6 +255,7 @@ void GlobalIlluminationCiVct::LoadGlobalIlluminationCiVct()

this->OnRefreshCamerasImpl();
}
return true;
}

/// \brief XML helper to retrieve values and handle errors
Expand Down Expand Up @@ -358,9 +360,7 @@ void GlobalIlluminationCiVct::LoadConfig(
const tinyxml2::XMLElement *_pluginElem)
{
if (this->title.empty())
this->title = "Global Illumination (VCT)";

std::lock_guard<std::mutex> lock(this->dataPtr->serviceMutex);
this->title = "Global Illumination (CI VCT)";

if (auto elem = _pluginElem->FirstChildElement("enabled"))
{
Expand Down Expand Up @@ -447,15 +447,25 @@ bool GlobalIlluminationCiVct::eventFilter(QObject *_obj, QEvent *_event)
{
if (_event->type() == gz::gui::events::Render::kType)
{
// This event is called in Scene3d's RenderThread, so it's safe to make
// This event is called in the render thread, so it's safe to make
// rendering calls here

std::lock_guard<std::mutex> lock(this->dataPtr->serviceMutex);
if (!this->dataPtr->initialized)
{
this->LoadGlobalIlluminationCiVct();
if (this->LoadGlobalIlluminationCiVct())
{
this->SetEnabled(this->dataPtr->enabled);
this->SetBounceCount(this->dataPtr->bounceCount);
this->SetHighQuality(this->dataPtr->highQuality);
this->SetAnisotropic(this->dataPtr->anisotropic);
this->SetDebugVisualizationMode(this->dataPtr->debugVisMode);
this->EnabledChanged();
this->LightingChanged();
this->DebugVisualizationModeChanged();
}
}

std::lock_guard<std::mutex> lock(this->dataPtr->serviceMutex);
if (this->dataPtr->gi)
{
if (!this->dataPtr->visualDirty && !this->dataPtr->gi->Enabled() &&
Expand Down Expand Up @@ -563,10 +573,6 @@ bool GlobalIlluminationCiVct::eventFilter(QObject *_obj, QEvent *_event)
this->dataPtr->resetRequested = false;
}
}
else
{
gzerr << "GI pointer is not set" << std::endl;
}
}

// Standard event processing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ inline namespace GZ_SIM_VERSION_NAMESPACE
public: bool eventFilter(QObject *_obj, QEvent *_event) override;

/// \brief Load the scene and attach LidarVisual to the scene
public: void LoadGlobalIlluminationCiVct();
/// \return True if GI CIVCT is loaded successfully, false otherwise.
public: bool LoadGlobalIlluminationCiVct();

/// \brief Set debug visualization mode GlogbalIllumination
/// \param[in] _mode Index of selected debug visualization mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ bool GlobalIlluminationVct::eventFilter(QObject *_obj, QEvent *_event)
{
if (_event->type() == gz::gui::events::Render::kType)
{
// This event is called in Scene3d's RenderThread, so it's safe to make
// This event is called in render thread, so it's safe to make
// rendering calls here

if (!this->dataPtr->initialized)
Expand Down

0 comments on commit 28f7987

Please sign in to comment.