Medical Imaging Interaction Toolkit  2025.08.99-f7084adb
Medical Imaging Interaction Toolkit
mitk::PythonContext Class Reference

#include <mitkPythonContext.h>

Inheritance diagram for mitk::PythonContext:
Collaboration diagram for mitk::PythonContext:

Public Member Functions

 mitkClassMacroItkParent (PythonContext, itk::LightObject)
 
 mitkNewMacro1Param (Self, const std::string &)
 
void Activate ()
 Imports essential python packages: numpy, os, sys, io and pyMITK. Also adds current bin folder to path. More...
 
bool HasVariable (const std::string &varName)
 Check if given variable exists in the current context defined by globals (m_GlobalDictionary) & locals (m_LocalDictionary) namespaces. More...
 
template<typename T >
std::optional< T > GetVariableAs (const std::string &varName)
 
mitk::ImageLoadImageFromPython (const std::string &varName)
 Provides view into mitk::Image type object in Python as mitk::Image* pointer in MITK. More...
 
void TransferBaseDataToPython (mitk::BaseData *mitkImage, const std::string &varName="_mitk_image")
 Creates view of mitk::BaseData pointer in MITK into corresponding SWIG proxy type object in Python. More...
 
std::string ExecuteString (const std::string &pyCommands)
 Executes the given python syntax in the current context defined by globals (m_GlobalDictionary) & locals (m_LocalDictionary) namespaces. More...
 
std::string ExecuteFile (const std::string &filePath)
 Executes the given python file in the current context defined by globals (m_GlobalDictionary) & locals (m_LocalDictionary) More...
 
std::string GetPythonExceptionTraceback ()
 Returns any exception stacktrace occured in python as string back to MITK. More...
 
std::string GetStdOut (const std::string &varName="_mitk_stdout")
 Returns value from the given string stream object. See: https://docs.python.org/3/library/io.html#io.StringIO.getvalue. More...
 
template<>
MITKPYTHON_EXPORT std::optional< bool > GetVariableAs (const std::string &)
 
template<>
MITKPYTHON_EXPORT std::optional< int > GetVariableAs (const std::string &)
 
template<>
MITKPYTHON_EXPORT std::optional< double > GetVariableAs (const std::string &)
 

Static Public Member Functions

static Pointer New ()
 

Protected Member Functions

 PythonContext (const std::string &venvName={})
 
 ~PythonContext ()
 

Detailed Description

Definition at line 24 of file mitkPythonContext.h.

Constructor & Destructor Documentation

◆ PythonContext()

mitk::PythonContext::PythonContext ( const std::string &  venvName = {})
explicitprotected

◆ ~PythonContext()

mitk::PythonContext::~PythonContext ( )
protected

Member Function Documentation

◆ Activate()

void mitk::PythonContext::Activate ( )

Imports essential python packages: numpy, os, sys, io and pyMITK. Also adds current bin folder to path.

◆ ExecuteFile()

std::string mitk::PythonContext::ExecuteFile ( const std::string &  filePath)

Executes the given python file in the current context defined by globals (m_GlobalDictionary) & locals (m_LocalDictionary)

◆ ExecuteString()

std::string mitk::PythonContext::ExecuteString ( const std::string &  pyCommands)

Executes the given python syntax in the current context defined by globals (m_GlobalDictionary) & locals (m_LocalDictionary) namespaces.

◆ GetPythonExceptionTraceback()

std::string mitk::PythonContext::GetPythonExceptionTraceback ( )

Returns any exception stacktrace occured in python as string back to MITK.

◆ GetStdOut()

std::string mitk::PythonContext::GetStdOut ( const std::string &  varName = "_mitk_stdout")

Returns value from the given string stream object. See: https://docs.python.org/3/library/io.html#io.StringIO.getvalue.

◆ GetVariableAs() [1/4]

template<>
MITKPYTHON_EXPORT std::optional<bool> mitk::PythonContext::GetVariableAs ( const std::string &  )

◆ GetVariableAs() [2/4]

template<>
MITKPYTHON_EXPORT std::optional<int> mitk::PythonContext::GetVariableAs ( const std::string &  )

◆ GetVariableAs() [3/4]

template<>
MITKPYTHON_EXPORT std::optional<double> mitk::PythonContext::GetVariableAs ( const std::string &  )

◆ GetVariableAs() [4/4]

template<typename T >
std::optional<T> mitk::PythonContext::GetVariableAs ( const std::string &  varName)

◆ HasVariable()

bool mitk::PythonContext::HasVariable ( const std::string &  varName)

Check if given variable exists in the current context defined by globals (m_GlobalDictionary) & locals (m_LocalDictionary) namespaces.

◆ LoadImageFromPython()

mitk::Image* mitk::PythonContext::LoadImageFromPython ( const std::string &  varName)

Provides view into mitk::Image type object in Python as mitk::Image* pointer in MITK.

◆ mitkClassMacroItkParent()

mitk::PythonContext::mitkClassMacroItkParent ( PythonContext  ,
itk::LightObject   
)

◆ mitkNewMacro1Param()

mitk::PythonContext::mitkNewMacro1Param ( Self  ,
const std::string &   
)

◆ New()

static Pointer mitk::PythonContext::New ( )
static

◆ TransferBaseDataToPython()

void mitk::PythonContext::TransferBaseDataToPython ( mitk::BaseData mitkImage,
const std::string &  varName = "_mitk_image" 
)

Creates view of mitk::BaseData pointer in MITK into corresponding SWIG proxy type object in Python.


The documentation for this class was generated from the following file: