MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkUSTelemedScanConverterPlugin.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
14#include "mitkImageWriteAccessor.h"
15
17 : m_Plugin(nullptr), m_OutputImage(nullptr)
18{
19}
20
25
26// -- internal Telemed API function
27HRESULT __stdcall USTelemedScanConverterPlugin::QueryInterface(const IID& iid, void** ppv)
28{
29 reinterpret_cast<IUnknown*>(*ppv)->AddRef() ;
30 return S_OK ;
31}
32
33// -- internal Telemed API function
35{
36 return InterlockedIncrement(&m_cRef) ;
37}
38
39// -- internal Telemed API function
41{
42 if (InterlockedDecrement(&m_cRef) == 0)
43 {
44 delete this ;
45 return 0 ;
46 }
47 return m_cRef ;
48}
49
51 PBYTE pBufferInterim,
52 int nInterimBufferLen,
53 PBYTE pBufferOut,
54 int nOutBufferLen,
55 int nOutX1,
56 int nOutY1,
57 int nOutX2,
58 int nOutY2
59 )
60{
61 if ( m_OutputImage.IsNull() ) { return S_FALSE; };
62 m_OutputImageMutex->lock();
63 // initialize mitk::Image with given image size on the first time
64 if ( ! m_OutputImage->IsInitialized() )
65 {
66 unsigned int dim[]={static_cast<unsigned int>(abs(nOutX2 - nOutX1)), static_cast<unsigned int>(abs(nOutY2 - nOutY1))}; // image dimensions
67
68 m_OutputImage->Initialize(mitk::MakeScalarPixelType<BYTE>(), 2, dim);
69 }
70
71 // lock the image for writing an copy the given buffer into the image then
72 m_OutputImage->SetSlice(pBufferOut);
73
74 m_OutputImageMutex->unlock();
75
76 return S_OK;
77}
78
80{
81 if (m_Plugin != nullptr)
82 {
83 // remove this callback from Telemed API plugin
84 m_Plugin->SetCallback(nullptr,USPC_BUFFER_INTERIM_OUTPUT);
85 }
86}
87
88void USTelemedScanConverterPlugin::SetOutputImage(mitk::Image::Pointer outputImage, std::mutex* outputImageMutex)
89{
90 m_OutputImage = outputImage;
91 m_OutputImageMutex = outputImageMutex;
92}
93
95{
96 // make sure that there is no scan converter plugin registered already
97 this->ReleasePlugin();
98
99 HRESULT hr;
100
101 // it is ok to call this method with a nullptr plugin to remove
102 // a previous callback
103 if (plugin == nullptr)
104 {
105 MITK_INFO("IUsgfwScanConverterPluginCB")("ScanConverterPlugin")
106 << "nullptr plugin set to the scan converter. The callback for the previous plugin is removed now.";
107 return S_OK;
108 }
109
110 // get Telemed API plugin from the COM library
111 Usgfw2Lib::IUsgScanConverterPlugin* tmp_plugin;
112 hr = plugin->QueryInterface(__uuidof(Usgfw2Lib::IUsgScanConverterPlugin), (void**)&tmp_plugin);
113
114 if (FAILED(hr))
115 {
116 MITK_WARN("IUsgfwScanConverterPluginCB")("ScanConverterPlugin")
117 << "Could not query com interface for IUsgScanConverterPlugin (" << hr << ").";
118 return hr;
119 }
120
121 // get the converter for scan lines from the COM library and
122 // save it as a member attribute
123 hr = tmp_plugin->get_ScanConverter((IUnknown**)&m_Plugin);
124
125 if (FAILED(hr))
126 {
127 MITK_WARN("IUsgfwScanConverterPluginCB")("ScanConverterPlugin")
128 << "Could not get ScanConverter from plugin (" << hr << ").";
129 return hr;
130 }
131
132 SAFE_RELEASE(tmp_plugin);
133
134 // now the callback can be set -> interface functions of this
135 // object will be called from now on when new image data is
136 // available
137 hr = m_Plugin->SetCallback(this,USPC_BUFFER_INTERIM_OUTPUT);
138
139 if (FAILED(hr))
140 {
141 MITK_WARN("IUsgfwScanConverterPluginCB")("ScanConverterPlugin")
142 << "Could not set callback for plugin (" << hr << ").";
143 return hr;
144 }
145
146 return S_OK;
147}
virtual HRESULT __stdcall QueryInterface(const IID &iid, void **ppv)
STDMETHOD SetScanConverterPlugin(IDispatch *plugin)
STDMETHOD InterimOutBufferCB(PBYTE pBufferInterim, int nInterimBufferLen, PBYTE pBufferOut, int nOutBufferLen, int nOutX1, int nOutY1, int nOutX2, int nOutY2)
void SetOutputImage(mitk::Image::Pointer outputImage, std::mutex *outputImageMutex)
#define SAFE_RELEASE(x)