MCPcopy Create free account
hub / github.com/MITK/MITK / StartSession

Method StartSession

Modules/PythonSegmentation/src/mitknnInteractiveTool.cpp:802–844  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

800}
801
802void mitk::nnInteractiveTool::StartSession()
803{
804 if (this->IsSessionRunning())
805 this->EndSession();
806
807 auto prefs = GetPreferences();
808
809 // Materialize the session-defining preferences with their effective values so a
810 // later no-op preferences "OK" does not register as a value change and tear the
811 // session down (mitk::Preferences fires its change event only on an actual
812 // change, and a default written into a never-stored key counts as one). Safe
813 // here: no session is running yet, so the GUI's stale-session observer is a
814 // no-op for these writes.
815 for (const auto& [key, defaultValue] : GetSessionDefiningPreferences())
816 prefs->Put(key, prefs->Get(key, defaultValue));
817
818 m_Impl->Remote = prefs->Get("nnInteractive/inferenceMode", "local") == "remote";
819
820 // The context is created lightweight (see CreatePythonContext) so the
821 // pre-session checks map no venv native libraries. A session does need the
822 // bindings (NumPy for mask exchange, the MITK module), so import them now.
823 // Activate() is idempotent, so re-running it here only adds the bindings.
824 if (auto* pythonContext = m_Impl->GetPythonContext())
825 pythonContext->Activate();
826
827 try
828 {
829 if (m_Impl->Remote)
830 this->ConstructRemoteSession();
831 else
832 this->ConstructLocalSession();
833 }
834 catch (...)
835 {
836 // If construction failed before a session was established, do not leave the
837 // remote flag set: IsRemoteSession() must report false when nothing runs,
838 // and EndSession() (the usual reset path) is a no-op without a session.
839 if (!this->IsSessionRunning())
840 m_Impl->Remote = false;
841
842 throw;
843 }
844}
845
846void mitk::nnInteractiveTool::ConstructRemoteSession()
847{

Callers 1

Calls 9

IsSessionRunningMethod · 0.95
EndSessionMethod · 0.95
ConstructLocalSessionMethod · 0.95
GetPreferencesFunction · 0.70
PutMethod · 0.45
GetMethod · 0.45
GetPythonContextMethod · 0.45
ActivateMethod · 0.45

Tested by

no test coverage detected