Medical Imaging Interaction Toolkit  2023.12.99-fc5b483f
Medical Imaging Interaction Toolkit
mitk::SegmentAnythingPythonService Class Reference

Segment Anything Model Python process handler class. More...

#include <mitkSegmentAnythingPythonService.h>

Inheritance diagram for mitk::SegmentAnythingPythonService:
Collaboration diagram for mitk::SegmentAnythingPythonService:

Public Types

enum  Status { READY, OFF, KILLED, CUDAError }
 

Public Member Functions

 SegmentAnythingPythonService (std::string workingDir, std::string modelType, std::string checkPointPath, unsigned int gpuId, std::string backend)
 Construct a new Segment Anything Python Service object. Specify working directory, ViT model type, checkpoint path, gpu id and backend. More...
 
 ~SegmentAnythingPythonService ()
 Destroy the Segment Anything Python Service object. Stop the async python process and deletes temporary directories. More...
 
virtual void SetMitkTempDir (std::string _arg)
 
virtual std::string GetMitkTempDir () const
 
void StartAsyncProcess ()
 Creates temp directories and calls start_python_daemon function async. More...
 
void StopAsyncProcess ()
 Writes KILL to the control file to stop the daemon process. More...
 
void TransferImageToProcess (const Image *inputAtTimeStep, std::string &UId)
 Writes image as nifity file with unique id (UId) as file name. More...
 
void TransferPointsToProcess (const std::string &triggerCSV) const
 Writes csv stringstream of points to a csv file for python daemon to read. More...
 
LabelSetImage::Pointer RetrieveImageFromProcess (long timeOut=-1) const
 Waits for output nifity file from the daemon to appear and reads it as a mitk::Image. More...
 

Static Public Member Functions

static void onPythonProcessEvent (itk::Object *, const itk::EventObject &, void *)
 Static function to print out everything from itk::EventObject. Used as callback in mitk::ProcessExecutor object. More...
 
static bool CheckStatus ()
 Checks CurrentStatus enum variable and returns true if daemon is READY (to read files) state, false is OFF state or throws exception if daemon is found KILL or Cuda error state. More...
 

Static Public Attributes

static Status CurrentStatus
 

Detailed Description

Segment Anything Model Python process handler class.

Definition at line 30 of file mitkSegmentAnythingPythonService.h.

Member Enumeration Documentation

◆ Status

Enumerator
READY 
OFF 
KILLED 
CUDAError 

Definition at line 33 of file mitkSegmentAnythingPythonService.h.

Constructor & Destructor Documentation

◆ SegmentAnythingPythonService()

mitk::SegmentAnythingPythonService::SegmentAnythingPythonService ( std::string  workingDir,
std::string  modelType,
std::string  checkPointPath,
unsigned int  gpuId,
std::string  backend 
)

Construct a new Segment Anything Python Service object. Specify working directory, ViT model type, checkpoint path, gpu id and backend.

Parameters
workingDirof python process
modelTypeof ViT
checkPointPathof specified model type
gpuId
backendSAM or MedSAM

◆ ~SegmentAnythingPythonService()

mitk::SegmentAnythingPythonService::~SegmentAnythingPythonService ( )

Destroy the Segment Anything Python Service object. Stop the async python process and deletes temporary directories.

Member Function Documentation

◆ CheckStatus()

static bool mitk::SegmentAnythingPythonService::CheckStatus ( )
static

Checks CurrentStatus enum variable and returns true if daemon is READY (to read files) state, false is OFF state or throws exception if daemon is found KILL or Cuda error state.

Returns
bool

◆ GetMitkTempDir()

virtual std::string mitk::SegmentAnythingPythonService::GetMitkTempDir ( ) const
virtual

◆ onPythonProcessEvent()

static void mitk::SegmentAnythingPythonService::onPythonProcessEvent ( itk::Object *  ,
const itk::EventObject &  ,
void *   
)
static

Static function to print out everything from itk::EventObject. Used as callback in mitk::ProcessExecutor object.

◆ RetrieveImageFromProcess()

LabelSetImage::Pointer mitk::SegmentAnythingPythonService::RetrieveImageFromProcess ( long  timeOut = -1) const

Waits for output nifity file from the daemon to appear and reads it as a mitk::Image.

Returns
LabelSetImage::Pointer

◆ SetMitkTempDir()

virtual void mitk::SegmentAnythingPythonService::SetMitkTempDir ( std::string  _arg)
virtual

◆ StartAsyncProcess()

void mitk::SegmentAnythingPythonService::StartAsyncProcess ( )

Creates temp directories and calls start_python_daemon function async.

◆ StopAsyncProcess()

void mitk::SegmentAnythingPythonService::StopAsyncProcess ( )

Writes KILL to the control file to stop the daemon process.

◆ TransferImageToProcess()

void mitk::SegmentAnythingPythonService::TransferImageToProcess ( const Image inputAtTimeStep,
std::string &  UId 
)

Writes image as nifity file with unique id (UId) as file name.

◆ TransferPointsToProcess()

void mitk::SegmentAnythingPythonService::TransferPointsToProcess ( const std::string &  triggerCSV) const

Writes csv stringstream of points to a csv file for python daemon to read.

Member Data Documentation

◆ CurrentStatus

Status mitk::SegmentAnythingPythonService::CurrentStatus
static

Definition at line 113 of file mitkSegmentAnythingPythonService.h.


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