7 #include "PlusConfigure.h" 8 #include "vtkImageData.h" 10 #include "vtkObjectFactory.h" 13 #include "vtkPlusUSImagingParameters.h" 15 #include "usbprobedll_net.h" 48 class vtkPlusCapistranoVideoSource::vtkInternal
55 HWND ImageWindowHandle;
58 std::vector<unsigned char> MemoryBitmapBuffer;
60 bmBITMAPINFO BitmapInfo;
62 static const int samplesPerLine = 2048;
72 int DerivativeCompensation;
79 ProbeServo probeservo;
90 ProbeParams USProbeParams;
92 std::map<int, ProbeParams> USProbeParamsDB;
95 PULSER USProbePulserParams;
98 std::map<float, PULSER> USProbePulserParamsDB;
108 this->CreateUSProbeParamsDB();
109 this->CreateUSProbePulserParamsDB();
113 virtual vtkPlusCapistranoVideoSource::vtkInternal::~vtkInternal()
115 this->USProbeParamsDB.clear();
116 this->USProbePulserParamsDB.clear();
118 this->External = NULL;
122 void vtkPlusCapistranoVideoSource::vtkInternal::CreateLinearTGC(
int tgcMin,
int tgcMax)
124 int tgc[samplesPerLine] = {0};
126 float m = (float)(tgcMax - tgcMin) / samplesPerLine;
128 for (
int x = 0;
x < samplesPerLine;
x++)
130 tgc[
x] = (
int)(m * (
float)
x) +
b;
137 void vtkPlusCapistranoVideoSource::vtkInternal::CreateLinearTGC(
int initialTGC,
int midTGC,
int farTGC)
144 int tgc[samplesPerLine] = {0};
145 double firstSlope = (double)(midTGC - initialTGC) / (samplesPerLine / 2);
146 double secondSlope = (double)(farTGC - midTGC) / (samplesPerLine / 2);
148 for (
int x = 0;
x < samplesPerLine / 2;
x++)
150 tgc[
x] = (
int)(firstSlope * (
double)
x) + initialTGC;
151 tgc[samplesPerLine / 2 +
x] = (
int)(secondSlope * (
double)
x) + midTGC;
158 void vtkPlusCapistranoVideoSource::vtkInternal::CreateSinTGC(
int initialTGC,
int midTGC,
int farTGC)
164 int TGC[samplesPerLine] = {0};
167 m = (float)(farTGC - initialTGC) / samplesPerLine;
168 c = (float)(midTGC) - (farTGC + initialTGC) / 2.0f;
170 for (
x = 0;
x < samplesPerLine;
x++)
172 tgc = (m * (float)
x) +
b;
173 TGC[
x] = (
int)(tgc + (
float)c * std::sin(
x * vtkMath::Pi() / samplesPerLine - 1.0f));
184 vtkPlusCapistranoVideoSource::vtkInternal*
self =
185 (vtkPlusCapistranoVideoSource::vtkInternal*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
186 return DefWindowProc(hwnd, iMsg, wParam, lParam) ;
190 PlusStatus vtkPlusCapistranoVideoSource::vtkInternal::InitializeDIB(FrameSizeType imageSize)
192 this->BitmapInfo.bmiHeader.biSize =
sizeof(BITMAPINFOHEADER);
193 this->BitmapInfo.bmiHeader.biWidth = imageSize[0];
194 this->BitmapInfo.bmiHeader.biHeight = -static_cast<int>(imageSize[1]);
195 this->BitmapInfo.bmiHeader.biPlanes = 1;
196 this->BitmapInfo.bmiHeader.biBitCount = 8;
197 this->BitmapInfo.bmiHeader.biCompression = 0;
198 this->BitmapInfo.bmiHeader.biXPelsPerMeter = 0;
199 this->BitmapInfo.bmiHeader.biYPelsPerMeter = 0;
200 this->BitmapInfo.bmiHeader.biClrUsed = 0;
201 this->BitmapInfo.bmiHeader.biClrImportant = 0;
206 this->BitmapInfo.bmiHeader.biSizeImage = ((imageSize[0] * 8 + 31) & ~31) / 8 * imageSize[1];
208 for (
int i = 0;
i < 256; ++
i)
210 this->BitmapInfo.bmiColors[
i].rgbRed =
i;
211 this->BitmapInfo.bmiColors[
i].rgbBlue =
i;
212 this->BitmapInfo.bmiColors[
i].rgbGreen =
i;
213 this->BitmapInfo.bmiColors[
i].rgbReserved = 0;
216 bmSetBitmapInfo(&BitmapInfo);
221 void CreateLinearLUT(
BYTE lut[],
int Level,
int Window)
223 int center = Window / 2;
224 int left = Level - center;
225 int right = Level + center;
228 for (
int x = 0;
x < left;
x++)
234 for (
int x = right + 1;
x < 256;
x++)
240 float m = 255.0f / ((float) Window);
242 int startX = std::max(0, left);
243 int endX = std::min(right, 255);
245 for (
int x = startX;
x <= endX;
x++)
247 int y = (
int)(m * (
float)(
x - left) + 0.5f);
249 lut[
x] = (
BYTE)std::max(0, std::min(
y, 255));
254 void CreateLUT(
BYTE lut[],
int Brightness,
int Contrast,
int Level,
int Window)
256 int center = Window / 2;
257 int left = Level - center;
258 int right = Level + center;
259 for (
int x = 0;
x <= 255;
x++)
261 int y = (
int)((
float)Contrast / 256.0f * (float)(
x - 128) + Brightness);
262 lut[
x] = std::min(255, std::max(
y, 0));
267 void vtkPlusCapistranoVideoSource::vtkInternal::ClearBitmap()
269 bmClearBitmap(this->ImageWindowHandle, this->Bitmap);
273 void vtkPlusCapistranoVideoSource::vtkInternal::CheckCapistranoUSHW()
275 if (usbHardwareDetected())
278 usbProbeHandle(0, &ProbeHandle);
280 usbSelectProbe(ProbeHandle, 0);
284 ProbeHandle = usbUserProbeHandle();
285 usbSelectProbe(ProbeHandle, 0);
290 void vtkPlusCapistranoVideoSource::vtkInternal::CreateUSProbeParamsDB()
292 USProbeParamsDB.clear();
295 pt.probetype.PFDistance = 20.0f;
296 pt.probetype.FFDistance = 1.0f;
297 pt.probetype.Velocity = 1532.0f;
298 pt.probetype.NumVectors = 255;
300 pt.probetype.PulseFrequency = 35.0f;
302 pt.probetype.SampleFrequency = 80.0f;
305 pt.probetype.DisplayAngle =
306 vtkMath::RadiansFromDegrees(30.0f / 2.0f);
307 sprintf(pt.probetype.Name,
"WP");
308 pt.DisplayOffset = 0;
309 pt.PulseVoltage = 100.0f;
310 pt.probetype.OversampleRate = 0.0f;
311 pt.probetype.PivFaceSamples = 0.0f;
312 pt.probetype.MModeOffset = 0.0f;
313 pt.probetype.ArcScan = 0;
314 pt.probetype.PFDOffset = 0;
315 pt.probeservo.JitterComp = 25;
316 pt.probeservo.PositionScale = 60;
317 pt.probeservo.SweepAngle = 36.0f;
318 pt.probeservo.ServoGain = 60;
319 pt.probeservo.Overscan = 50;
320 pt.probeservo.DerivativeCompensation = 100;
322 USProbeParamsDB[0] = pt;
325 pt.probetype.PFDistance = 4.94f;
326 pt.probetype.FFDistance = 3.15;
327 pt.probetype.Velocity = 1532.0f;
328 pt.probetype.NumVectors = 255;
330 pt.probetype.PulseFrequency = 12.0f;
332 pt.probetype.SampleFrequency = 40.0f;
335 pt.probetype.DisplayAngle =
336 vtkMath::RadiansFromDegrees(60.0f / 2.0f);
337 sprintf(pt.probetype.Name,
"OP10");
338 pt.DisplayOffset = 128;
339 pt.PulseVoltage = 75.0f;
340 pt.probetype.OversampleRate = 0.0f;
341 pt.probetype.PivFaceSamples = 0.0f;
342 pt.probetype.MModeOffset = 0.0f;
343 pt.probetype.ArcScan = 0;
344 pt.probetype.PFDOffset = 0;
345 pt.probeservo.JitterComp = 35;
346 pt.probeservo.PositionScale = 14;
347 pt.probeservo.SweepAngle = 70.0f;
348 pt.probeservo.ServoGain = 70;
349 pt.probeservo.Overscan = 25;
350 pt.probeservo.DerivativeCompensation = 30;
353 USProbeParamsDB[1] = pt;
356 pt.probetype.PFDistance = 4.94f;
357 pt.probetype.FFDistance = 3.15;
358 pt.probetype.Velocity = 1532.0f;
359 pt.probetype.NumVectors = 255;
361 pt.probetype.PulseFrequency = 16.0f;
363 pt.probetype.SampleFrequency = 40.0f;
366 pt.probetype.DisplayAngle =
367 vtkMath::RadiansFromDegrees(60.0f / 2.0f);
368 sprintf(pt.probetype.Name,
"OP20");
369 pt.DisplayOffset = 132;
370 pt.PulseVoltage = 100.0f;
371 pt.probetype.OversampleRate = 0.0f;
372 pt.probetype.PivFaceSamples = 0.0f;
373 pt.probetype.MModeOffset = 0.0f;
374 pt.probetype.ArcScan = 0;
375 pt.probetype.PFDOffset = 0;
376 pt.probeservo.JitterComp = 0;
377 pt.probeservo.PositionScale = 14;
378 pt.probeservo.SweepAngle = 72.0f;
379 pt.probeservo.ServoGain = 30;
380 pt.probeservo.Overscan = 25;
381 pt.probeservo.DerivativeCompensation = 20;
383 USProbeParamsDB[2] = pt;
386 pt.probetype.PFDistance = 4.94f;
387 pt.probetype.FFDistance = 3.15;
388 pt.probetype.Velocity = 1532.0f;
389 pt.probetype.NumVectors = 255;
391 pt.probetype.PulseFrequency = 16.0f;
393 pt.probetype.SampleFrequency = 40.0f;
396 pt.probetype.DisplayAngle =
397 vtkMath::RadiansFromDegrees(60.0f / 2.0f);
398 sprintf(pt.probetype.Name,
"NoProbe");
399 pt.DisplayOffset = 0;
400 pt.PulseVoltage = 100.0f;
401 pt.probetype.OversampleRate = 0.0f;
402 pt.probetype.PivFaceSamples = 0.0f;
403 pt.probetype.MModeOffset = 0.0f;
404 pt.probetype.ArcScan = 0;
405 pt.probetype.PFDOffset = 0;
406 pt.probeservo.JitterComp = 25;
407 pt.probeservo.PositionScale = 14;
408 pt.probeservo.SweepAngle = 70.0f;
409 pt.probeservo.ServoGain = 40;
410 pt.probeservo.Overscan = 25;
411 pt.probeservo.DerivativeCompensation = 30;
414 USProbeParamsDB[3] = pt;
418 bool vtkPlusCapistranoVideoSource::vtkInternal::SetUSProbeParamsFromDB(
int probeID)
421 std::map<int, ProbeParams>::iterator it;
422 it = this->USProbeParamsDB.find(probeID);
423 if (it == this->USProbeParamsDB.end())
429 CheckCapistranoUSHW();
431 this->USProbeParams = it->second;
435 usbSetSampleDelay(this->USProbeParams.probetype.PFDOffset);
437 usbSetProbeVectors(this->USProbeParams.probetype.NumVectors);
438 this->USProbeParams.probetype.NumVectors = usbProbeNumVectors(NULL);
440 switch (this->USProbeParams.Filter)
443 usbSetFilter(FILTER_8MHZ);
446 usbSetFilter(FILTER_11MHZ);
449 usbSetFilter(FILTER_15MHZ);
452 usbSetFilter(FILTER_18MHZ);
456 usbSetFilter(FILTER_22MHZ);
459 usbSetFilter(FILTER_25MHZ);
462 usbSetFilter(FILTER_OFF);
466 int s = (
int)(80 / this->USProbeParams.probetype.SampleFrequency);
467 usbSetSampleClockDivider(s);
469 if (this->USProbeParams.Amode)
478 usbSetPulseVoltage(this->USProbeParams.PulseVoltage);
480 usbSetProbeJitterComp((
unsigned char)this->USProbeParams.probeservo.JitterComp);
482 usbSetProbePositionScale((
unsigned char)this->USProbeParams.probeservo.PositionScale);
485 usbSetProbeAngle(usbProbeAngle());
489 usbSetProbeServoGain((
unsigned char)this->USProbeParams.probeservo.ServoGain);
496 int byteTemp = (
int)(this->USProbeParams.probeservo.Overscan / 6.25f) - 1;
497 usbSetProbeOverscan(byteTemp);
499 usbSetProbeDerivComp((
unsigned char)this->USProbeParams.probeservo.DerivativeCompensation);
505 void vtkPlusCapistranoVideoSource::vtkInternal::CreateUSProbePulserParamsDB()
507 USProbePulserParamsDB.clear();
510 #if defined(CAPISTRANO_SDK2013) 512 pulser.MINDelay = 93;
513 pulser.MIDDelay = 94;
514 pulser.MAXDelay = 184;
516 USProbePulserParamsDB[10.0f] = pulser;
519 pulser.MINDelay = 13;
520 pulser.MIDDelay = 13;
521 pulser.MAXDelay = 13;
523 USProbePulserParamsDB[12.0f] = pulser;
526 pulser.MINDelay = 55;
527 pulser.MIDDelay = 56;
528 pulser.MAXDelay = 109;
530 USProbePulserParamsDB[16.0f] = pulser;
533 pulser.MINDelay = 49;
534 pulser.MIDDelay = 50;
535 pulser.MAXDelay = 96;
537 USProbePulserParamsDB[18.0f] = pulser;
540 pulser.MINDelay = 43;
541 pulser.MIDDelay = 44;
542 pulser.MAXDelay = 85;
544 USProbePulserParamsDB[20.0f] = pulser;
547 pulser.MINDelay = 33;
548 pulser.MIDDelay = 34;
549 pulser.MAXDelay = 65;
551 USProbePulserParamsDB[25.0f] = pulser;
554 pulser.MINDelay = 27;
555 pulser.MIDDelay = 28;
556 pulser.MAXDelay = 52;
558 USProbePulserParamsDB[30.0f] = pulser;
561 pulser.MINDelay = 23;
562 pulser.MIDDelay = 24;
563 pulser.MAXDelay = 48;
565 USProbePulserParamsDB[35.0f] = pulser;
568 pulser.MINDelay = 19;
569 pulser.MIDDelay = 20;
570 pulser.MAXDelay = 35;
572 USProbePulserParamsDB[45.0f] = pulser;
575 pulser.MINDelay = 15;
576 pulser.MIDDelay = 16;
577 pulser.MAXDelay = 29;
579 USProbePulserParamsDB[50.0f] = pulser;
582 pulser.MINDelay = 10;
583 pulser.MIDDelay = 10;
584 pulser.MAXDelay = 11;
586 USProbePulserParamsDB[10.0f] = pulser;
591 pulser.MAXDelay = 10;
593 USProbePulserParamsDB[12.0f] = pulser;
600 USProbePulserParamsDB[16.0f] = pulser;
607 USProbePulserParamsDB[18.0f] = pulser;
614 USProbePulserParamsDB[20.0f] = pulser;
621 USProbePulserParamsDB[25.0f] = pulser;
628 USProbePulserParamsDB[30.0f] = pulser;
635 USProbePulserParamsDB[35.0f] = pulser;
642 USProbePulserParamsDB[45.0f] = pulser;
649 USProbePulserParamsDB[50.0f] = pulser;
654 bool vtkPlusCapistranoVideoSource::vtkInternal::SetUSProbePulserParamsFromDB(
float freq)
657 std::map<float, PULSER>::iterator it;
658 it = this->USProbePulserParamsDB.find(freq);
659 if (it == this->USProbePulserParamsDB.end())
664 this->USProbePulserParams = it->second;
666 usbSetPulseFrequency(&this->USProbePulserParams);
698 os << indent <<
"Frozen: " <<
Frozen << std::endl;
701 os << indent <<
"ProbeID: " <<
ProbeID << std::endl;
702 os << indent <<
"ClockDivider: " <<
ClockDivider << std::endl;
703 os << indent <<
"CineBuffers: " <<
CineBuffers << std::endl;
708 os << indent <<
"SweepAngle: " <<
GetSweepAngle() << std::endl;
710 os << indent <<
"Overscan: " <<
GetOverscan() << std::endl;
712 os << indent <<
"Interpolate: " <<
Interpolate << std::endl;
713 os << indent <<
"AverageMode: " <<
AverageMode << std::endl;
715 os << indent <<
"LutCenter: " <<
LutCenter << std::endl;
716 os << indent <<
"LutWindow: " <<
LutWindow << std::endl;
722 LOG_TRACE(
"vtkPlusCapistranoVideoSource::ReadConfiguration");
727 LOG_ERROR(
"Failed to initialize Capistrano US Probe");
736 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(
int,
CineBuffers, deviceConfig);
737 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(
float,
SampleFrequency, deviceConfig);
738 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(
int, WobbleRate, deviceConfig);
739 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(
int, JitterCompensation, deviceConfig);
740 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(
int,
PositionScale, deviceConfig);
741 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(
float, SweepAngle, deviceConfig);
742 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(
int, ServoGain, deviceConfig);
743 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(
int, Overscan, deviceConfig);
744 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(
int, DerivativeCompensation, deviceConfig);
747 XML_READ_BOOL_ATTRIBUTE_OPTIONAL(
Interpolate, deviceConfig);
748 XML_READ_BOOL_ATTRIBUTE_OPTIONAL(
AverageMode, deviceConfig);
750 if (deviceConfig->GetScalarAttribute(
"CurrentBModeViewOption", bModeViewOption))
754 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(
double,
LutCenter, deviceConfig);
755 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(
double,
LutWindow, deviceConfig);
769 deviceConfig->SetAttribute(
"BidirectionalMode",
BidirectionalMode ?
"TRUE" :
"FALSE");
770 deviceConfig->SetAttribute(
"UpdateParameters",
UpdateParameters ?
"TRUE" :
"FALSE");
772 deviceConfig->SetIntAttribute(
"WobbleRate", this->
GetWobbleRate());
775 deviceConfig->SetFloatAttribute(
"SweepAngle", this->
GetSweepAngle());
776 deviceConfig->SetIntAttribute(
"ServoGain", this->
GetServoGain());
777 deviceConfig->SetIntAttribute(
"Overscan", this->
GetOverscan());
779 deviceConfig->SetDoubleAttribute(
"LutCenter", this->
LutCenter);
780 deviceConfig->SetDoubleAttribute(
"LutWindow", this->
LutWindow);
792 LOG_WARNING(
"vtkPlusCapistranoVideoSource is expecting one output channel and there are " 793 << this->
OutputChannels.size() <<
" channels. First output channel will be used.");
798 LOG_ERROR(
"No output channels defined for vtkPlusCapistranoVideoSource. Cannot proceed.");
809 std::ostringstream versionString;
810 versionString <<
"Capistrano BmodeUSB DLL v" << bmDLLVer() <<
", USBprobe DLL v" << usbDLLVer() << std::ends;
811 return versionString.str();
817 #if defined(CAPISTRANO_SDK2023) || defined(CAPISTRANO_SDK2019_3) || defined(CAPISTRANO_SDK2019_2) || defined(CAPISTRANO_SDK2019) || defined(CAPISTRANO_SDK2018) 821 LOG_ERROR(
"This method is not supported with this version of Capistrano SDK.");
829 #if defined(CAPISTRANO_SDK2019_3) || defined(CAPISTRANO_SDK2019_2) || defined(CAPISTRANO_SDK2019) || defined(CAPISTRANO_SDK2018) 833 LOG_ERROR(
"This method is not supported with this version of Capistrano SDK.");
841 #ifdef CAPISTRANO_SDK2018 845 LOG_ERROR(
"This method is not supported with this version of Capistrano SDK.");
857 , Internal(new vtkInternal(this))
884 FrameSizeType imageSize = {640, 800, 1};
889 double tgc[3] = {-128, -128, -128};
927 #if defined(CAPISTRANO_SDK2023) || defined(CAPISTRANO_SDK2019_3) || defined(CAPISTRANO_SDK2019_2) || defined(CAPISTRANO_SDK2019) || defined(CAPISTRANO_SDK2018) 928 int numberOfAttachedBoards = usbNumberAttachedBoards();
929 #else //cSDK2013 or cSDK2016 930 int numberOfAttachedBoards = usbNumberAttachedProbes();
932 LOG_DEBUG(
"Number of attached boards: " << numberOfAttachedBoards);
933 return numberOfAttachedBoards > 0;
946 usbErrorString errorStatus = {0};
947 #if defined(CAPISTRANO_SDK2023) || defined(CAPISTRANO_SDK2019_3) 948 wchar_t* appData = _wgetenv(L
"APPDATA");
949 std::wstring path = appData + std::wstring(L
"\\CLI");
950 wchar_t* filename_uni = L
"debug.txt";
951 usbUseFileNamePath((LPTSTR)filename_uni, (LPTSTR)path.c_str());
953 ULONG status = usbFindProbes(errorStatus);
954 LOG_DEBUG(
"Find USB probes: status=" << status <<
", details: " << errorStatus);
955 if (status != ERROR_SUCCESS)
957 LOG_ERROR(
"Capistrano finding probes failed");
968 LOG_ERROR(
"Could not allocate Cine buffers.");
973 double startTime = vtkIGSIOAccurateTimer::GetSystemTime();
974 while (!this->
IsBoardAttached() && (vtkIGSIOAccurateTimer::GetSystemTime() - startTime < 5))
985 LOG_ERROR(
"Failed to setup Capistrano US Probe");
998 this->
ProbeID = usbAttachedProbeID();
999 LOG_DEBUG(
"Probe ID =" <<
ProbeID);
1004 LOG_ERROR(
"Capistrano finding probes failed");
1009 #if defined(CAPISTRANO_SDK2023) || defined(CAPISTRANO_SDK2019_3) || defined(CAPISTRANO_SDK2019_2) || defined(CAPISTRANO_SDK2019) || defined(CAPISTRANO_SDK2018) 1010 int numberOfAttachedBoards = usbNumberAttachedBoards();
1011 #else //cSDK2013 or cSDK2016 1012 int numberOfAttachedBoards = usbNumberAttachedProbes();
1014 LOG_DEBUG(
"Number of attached boards: " << numberOfAttachedBoards);
1015 if (numberOfAttachedBoards == 0)
1017 LOG_ERROR(
"No Capistrano boards are attached");
1020 if (numberOfAttachedBoards > 1)
1022 LOG_WARNING(
"Multiple Capistrano boards are attached, using the first one");
1026 usbSetUnidirectionalMode();
1037 this->
Internal->SetUSProbePulserParamsFromDB(
1038 this->
Internal->USProbeParams.probetype.PulseFrequency);
1041 Internal->USProbeParams.probetype.OversampleRate = 2048.0f / imageSize[1];
1042 Internal->USProbeParams.probetype.SampleFrequency = 80.f / usbSampleClockDivider();
1043 Internal->USProbeParams.probetype.PivFaceSamples =
1044 Internal->USProbeParams.probetype.PFDistance *
1045 1000.0f *
Internal->USProbeParams.probetype.SampleFrequency
1046 / (0.5f *
Internal->USProbeParams.probetype.Velocity);
1057 HANDLE display = bmInitializeDisplay(imageSize[0] * imageSize[1], 0);
1058 if (display == NULL)
1060 LOG_ERROR(
"Could not initialize the display");
1065 this->
Internal->InitializeDIB(imageSize);
1072 LOG_ERROR(
"Unable to retrieve the video source in the CapistranoVideo device.");
1077 HINSTANCE hInst = GetModuleHandle(NULL);
1079 WNDCLASSEX wndclass = {};
1080 wndclass.cbSize =
sizeof(wndclass);
1081 wndclass.style = CS_CLASSDC;
1083 wndclass.cbClsExtra = 0;
1084 wndclass.cbWndExtra = 0;
1085 wndclass.hInstance = hInst;
1086 wndclass.hIcon = NULL;
1087 wndclass.hCursor = NULL;
1088 wndclass.hbrBackground = NULL;
1089 wndclass.lpszMenuName = NULL ;
1090 wndclass.lpszClassName = TEXT(
"ImageWindow");
1091 wndclass.hIconSm = NULL;
1092 RegisterClassEx(&wndclass);
1094 if (this->
Internal->ImageWindowHandle != NULL)
1096 bool b = DestroyWindow(this->
Internal->ImageWindowHandle);
1099 this->
Internal->ImageWindowHandle =
1100 CreateWindow(TEXT(
"ImageWindow"), TEXT(
"Ultrasound"),
1101 WS_OVERLAPPEDWINDOW,
1103 static_cast<int>(imageSize[0]),
1104 static_cast<int>(imageSize[1]),
1105 NULL, NULL, hInst, NULL);
1107 if (this->
Internal->ImageWindowHandle == NULL)
1109 LOG_ERROR(
"Failed to create capture window");
1114 HDC hdc = GetDC(this->
Internal->ImageWindowHandle) ;
1116 GetClientRect(this->
Internal->ImageWindowHandle, &rect) ;
1117 int cx = static_cast<int>(imageSize[0]);
1118 int cy = static_cast<int>(imageSize[1]);
1119 this->
Internal->DataHandle = CreateCompatibleBitmap(hdc, cx, cy);
1120 GetObject(this->
Internal->DataHandle,
sizeof(BITMAP), (LPVOID) &this->Internal->Bitmap) ;
1123 this->
Internal->MemoryBitmapBuffer.resize(imageSize[0]*imageSize[1], 0);
1147 std::vector<double> tgcVec;
1149 double gain[3] = {tgcVec[0], tgcVec[1], tgcVec[2]};
1151 if (gain[0] >= 0 && gain[1] >= 0 && gain[2] >= 0)
1168 LOG_ERROR(
"Unable to retrieve the video source in the CapistranoVideo device.");
1184 LOG_ERROR(
"Failed to initialize Image Window");
1193 LOG_ERROR(
"Failed to initialize Capistrano US Probe");
1203 LOG_ERROR(
"Failed to UpdateUSProbeParameters");
1209 LOG_ERROR(
"Failed to UpdateUSBModeParameters");
1222 LOG_ERROR(
"Failed to update Depth Mode");
1229 if (!usbHardwareDetected())
1231 LOG_ERROR(
"No Capistrano US Hardware");
1235 usbSetUnidirectionalMode();
1240 bmSetDisplayOffset(0);
1242 this->
Internal->RfDataBuffer = usbCurrentCineFrame();
1243 bmClearBitmap(this->
Internal->ImageWindowHandle, this->Internal->Bitmap);
1246 usbSetSampleDelay(1);
1249 std::string probeName;
1251 LOG_DEBUG(
"Capistrano probe name: " << probeName <<
", ID: " << usbProbeID(this->
Internal->ProbeHandle));
1255 std::ostringstream spacingStream;
1256 unsigned int numSpaceDimensions = 3;
1257 for (
unsigned int i = 0;
i < numSpaceDimensions ; ++
i)
1260 if (
i != numSpaceDimensions - 1)
1262 spacingStream <<
" ";
1265 this->
CustomFields[
"ElementSpacing"].first = FRAMEFIELD_FORCE_SERVER_SEND;
1266 this->
CustomFields[
"ElementSpacing"].second = spacingStream.str();
1274 LOG_TRACE(
"vtkPlusCapistranoVideoSource::InternalConnect");
1275 LOG_DEBUG(
"Capistrano Bmode DLL version " << bmDLLVer() <<
", USB probe DLL version " << usbDLLVer());
1289 LOG_DEBUG(
"Disconnect from Capistrano");
1324 this->
Internal->RfDataBuffer = usbCurrentCineFrame();
1326 this->
Internal->DataHandle = bmDrawImage(this->
Internal->ImageWindowHandle,
1327 this->Internal->RfDataBuffer,
1328 this->Internal->Bitmap,
1330 NULL, bmDI_DRAW, 0,
TRUE);
1332 GetObject(this->
Internal->DataHandle,
sizeof(BITMAP), &this->Internal->Bitmap);
1336 "Unable to retrieve the video source in the Capistrano device.");
1344 LOG_DEBUG(
"Set up image buffer for Capistrano");
1349 float depthScale = -1;
1350 usbProbeDepthScale(this->
Internal->ProbeHandle, &depthScale);
1352 std::string probeName;
1355 LOG_INFO(
"Frame size: " << frameSizeInPx[0] <<
"x" << frameSizeInPx[1]
1356 <<
", pixel type: " << vtkImageScalarTypeNameMacro(aSource->
GetPixelType())
1357 <<
", probe sample frequency (Hz): " << this->
Internal->USProbeParams.probetype.SampleFrequency
1358 <<
", probe name: " << probeName
1359 <<
", display zoom: " << bmDisplayZoom()
1360 <<
", probe depth scale (mm/sample):" << depthScale
1361 <<
", buffer image orientation: " 1366 const double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
1370 switch (usbWriteSpecialFunction(0x6d697303, 0))
1383 RETURN_WITH_FAIL_IF(aSource->
AddItem((
void*)this->Internal->Bitmap.bmBits,
1385 frameSizeInPx, VTK_UNSIGNED_CHAR,
1386 1, US_IMG_BRIGHTNESS, 0,
1388 unfilteredTimestamp,
1389 unfilteredTimestamp,
1392 "Error adding item to video source " << aSource->
GetSourceId());
1402 RETURN_WITH_FAIL_IF(this->
Internal->ProbeHandle == NULL,
1403 "vtkPlusCapistranoVideoSource::FreezeDevice failed: device not connected");
1404 RETURN_WITH_FAIL_IF(!usbHardwareDetected(),
1405 "Freeze failed, no hardware is detected");
1407 if (this->
Frozen == freeze)
1419 usbClearCineBuffers();
1422 "Failed to update US parameters");
1438 bool nextFrameReady = (usbWaitFrame() == 1);
1439 DWORD usbErrorCode = usbError();
1446 static bool messagePrinted =
false;
1448 switch (usbErrorCode)
1451 messagePrinted =
false;
1454 if (!messagePrinted)
1456 LOG_ERROR(
"USB: FAILURE. Probe was removed?");
1457 messagePrinted =
true;
1466 LOG_WARNING(
"USB timeout");
1470 if (!messagePrinted)
1472 LOG_ERROR(
"Lost Probe Synchronization. Please check probe cables and restart.");
1473 messagePrinted =
true;
1479 if (!messagePrinted)
1481 LOG_ERROR(
"USB: Stopped. Check probe and restart.");
1482 messagePrinted =
true;
1486 if (!messagePrinted)
1488 LOG_ERROR(
"USB: Unknown USB error: " << usbErrorCode);
1489 messagePrinted =
true;
1511 #if defined(CAPISTRANO_SDK2023) || defined(CAPISTRANO_SDK2019_3) || defined(CAPISTRANO_SDK2019_2) 1513 usbWriteSpecialFunction(0x6d697300,
mode);
1517 LOG_ERROR(
"This method is not supported with this version of Capistrano SDK.");
1524 #if defined(CAPISTRANO_SDK2023) || defined(CAPISTRANO_SDK2019_3) || defined(CAPISTRANO_SDK2019_2) 1528 LOG_ERROR(
"This method is not supported with this version of Capistrano SDK.");
1536 #if defined(CAPISTRANO_SDK2023) || defined(CAPISTRANO_SDK2019_3) || defined(CAPISTRANO_SDK2019_2) 1537 usbWriteSpecialFunction(0x6d697301, val);
1540 LOG_ERROR(
"This method is not supported with this version of Capistrano SDK.");
1547 #if defined(CAPISTRANO_SDK2023) || defined(CAPISTRANO_SDK2019_3) || defined(CAPISTRANO_SDK2019_2) 1548 PulsePeriod = usbWriteSpecialFunction(0x6d697302, 0);
1551 LOG_ERROR(
"This method is not supported with this version of Capistrano SDK.");
1566 usbSetBidirectionalMode();
1570 usbSetUnidirectionalMode();
1600 if (this->
Internal->SetUSProbePulserParamsFromDB(pf))
1610 usbSetProbeSpeed(wr);
1616 return usbProbeSpeed();
1622 usbSetProbeJitterComp(jitterComp);
1628 return usbProbeJitterComp();
1635 usbSetProbePositionScale(scale);
1647 usbSetProbeAngle(sweepAngle);
1653 return usbProbeAngle();
1659 usbSetProbeServoGain(servoGain);
1665 return usbProbeServoGain();
1671 usbSetProbeOverscan(
state);
1677 return usbProbeOverscan();
1683 usbSetProbeDerivComp(derComp);
1689 return usbProbeDerivComp();
1695 usbSetPulseVoltage(pv);
1702 return usbPulseVoltage();
1767 if (this->
Internal->ProbeHandle == NULL)
1769 LOG_ERROR(
"vtkPlusCapistranoVideoSource::SetDisplayZoomDevice failed: device not connected");
1774 bmSetDisplayZoom(zoom);
1775 LOG_TRACE(
"New zoom is " << bmDisplayZoom());
1803 if (this->
Internal->ProbeHandle == NULL)
1805 LOG_ERROR(
"vtkPlusCapistranoVideoSource::SetGainPercentDevice failed: device not connected");
1816 double initialGain, midGain, farGain;
1817 double maximumTGC = 512;
1818 if (gainPercent[0] >= 0 && gainPercent[1] >= 0 && gainPercent[2] >= 0)
1820 initialGain = -255 + gainPercent[0] * maximumTGC / 100 ;
1821 midGain = -255 + gainPercent[1] * maximumTGC / 100 ;
1822 farGain = -255 + gainPercent[2] * maximumTGC / 100 ;
1825 this->
Internal->CreateLinearTGC(initialGain, midGain, farGain);
1834 int temp = (
int)(depthMm / 18.0f);
1836 temp = std::max(temp, 1);
1837 temp = std::min(temp, 4);
1848 LOG_ERROR(
"Invalid scan depth.");
1866 "Failed to Update US probe parameters");
1868 "Failed to Update US BMode parameters");
1878 usbSetBidirectionalMode();
1882 usbSetUnidirectionalMode();
1888 LOG_ERROR(
"Could not allocate Cine buffers.");
1896 if (!this->
Internal->SetUSProbePulserParamsFromDB(this->ImagingParameters->GetFrequencyMhz()))
1898 LOG_ERROR(
"Invalid pulse frequency. Possible pulse frequencies: 10.0, 12.0, 16.0, 18.0, 20.0, 25.0, 30.0, 35.0, 45.0, 50");
1904 usbSetPulseVoltage(this->
Internal->USProbeParams.PulseVoltage);
1910 LOG_ERROR(
"Could not setup Scan Depth");
1926 LOG_ERROR(
"SetDisplayZoomDevice failed");
1943 ptCenter.x = imageSize[0] / 2;
1944 ptCenter.y = imageSize[1] / 2;
1948 this->
Internal->USProbeParams.probetype.OversampleRate = 2048.0f / imageSize[1];
1950 if (bmCalculateZoomDisplay(imageSize[0], imageSize[1], ptCenter,
1951 this->
Internal->USProbeParams.probetype, (
unsigned int)imageSize[0],
1952 this->CurrentBModeViewOption) == ERROR)
1954 LOG_ERROR(
"CalculateDisplay ERROR: Bad Theta Value");
1966 Internal->USProbeParams.probetype.OversampleRate = 2048.0f / imageSize[1];
1967 Internal->USProbeParams.probetype.SampleFrequency = 80.f / usbSampleClockDivider();
1968 Internal->USProbeParams.probetype.PivFaceSamples =
1969 Internal->USProbeParams.probetype.PFDistance * 1000.0f *
1970 Internal->USProbeParams.probetype.SampleFrequency /
1971 (0.5f *
Internal->USProbeParams.probetype.Velocity);
1975 usbClearCineBuffers();
1978 LOG_ERROR(
"CalculateDisplay ERROR: Bad Theta Value");
1990 usbSetSampleClockDivider(clockdivider);
1999 if (this->
Internal->ProbeHandle == NULL)
2001 LOG_ERROR(
"vtkPlusCapistranoVideoSource::GetSampleFrequencyDevice failed: device not connected");
2005 aFreq = this->
Internal->USProbeParams.probetype.SampleFrequency;
2006 LOG_TRACE(
"Current frequency is " << aFreq);
2014 if (this->
Internal->ProbeHandle == NULL)
2016 LOG_ERROR(
"vtkPlusICapistranoVideoSource::GetProbeVelocityDevice failed: device not connected");
2020 aVel = this->
Internal->USProbeParams.probetype.Velocity;
2021 LOG_TRACE(
"Current velocity is " << aVel);
2028 if (this->
Internal->ProbeHandle == NULL)
2030 LOG_ERROR(
"vtkPlusCapistranoVideoSource::SetGainPercentDevice failed: device not connected");
2037 typedef TCHAR usbProbeNameStringSafe[1000];
2039 usbProbeNameStringSafe probeNameWideStringPtr = {0};
2040 usbProbeName(this->
Internal->ProbeHandle, probeNameWideStringPtr);
2043 char probeNamePrintable[usbProbeNameMaxLength + 1] = {0};
2044 wcstombs(probeNamePrintable, (
wchar_t*)probeNameWideStringPtr, usbProbeNameMaxLength);
2046 probeName = probeNamePrintable;
2071 LOG_ERROR(
"Failed to set depth imaging parameter");
2085 LOG_ERROR(
"Failed to set frequency imaging parameter");
2093 std::vector<double> tgcVec;
2095 double tgc[3] = { tgcVec[0], tgcVec[1], tgcVec[2] };
2103 LOG_ERROR(
"Failed to set time gain compensation parameter");
2111 FrameSizeType imageSizeVec;
2120 LOG_ERROR(
"Failed to set image size parameter");
2134 LOG_ERROR(
"Failed to set intensity parameter");
2148 LOG_ERROR(
"Failed to set contrast parameter");
2162 LOG_ERROR(
"Failed to set zoom parameter");
2176 LOG_ERROR(
"Failed to set sound velocity parameter");
2190 LOG_ERROR(
"Failed to set voltage parameter");
PlusStatus GetHighPassFilter(int &HighPassFilter)
PlusStatus SetSampleFrequency(float sf)
static const char * KEY_IMAGESIZE
PlusStatus InternalStopRecording() override
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *deviceConfig)
static const char * CAPISTRANO_GET_MIS_MODE
PlusStatus WaitForFrame()
bool IsPending(const std::string ¶mName) const
PlusStatus FreezeDevice(bool freeze)
PlusStatus GetLowPassFilter(int &LowPassFilter)
vtkStandardNewMacro(vtkPlusCapistranoVideoSource)
PlusStatus CalculateDisplay()
PlusStatus SetOverscan(int state)
static const char * KEY_DEPTH
static const char * CAPISTRANO_SET_SAMPLE_FREQUENCY
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_WRITING(deviceConfig, rootConfigElement)
static const char * CAPISTRANO_GET_JITTER_COMPENSATION
PlusStatus InternalUpdate()
PlusStatus SetSweepAngle(float sweepAngle)
std::string GetSourceId() const
static const char * KEY_FREQUENCY
PlusStatus SetGainPercent(double gainPercent[3])
static const char * CAPISTRANO_SET_MIS_MODE
PlusStatus GetMISPulsePeriod(unsigned int &PulsePeriod)
PlusStatus SetContrast(double aContrast)
PlusStatus SetWobbleRate(unsigned char wobbleRate)
PlusStatus InitializeTGC()
PlusStatus GetDepthMm(double &aDepthMm) const
PlusStatus SetPulseVoltage(float pv)
PlusStatus SetInputFrameSize(unsigned int x, unsigned int y, unsigned int z)
virtual PlusStatus AddItem(vtkImageData *frame, US_IMAGE_ORIENTATION usImageOrientation, US_IMAGE_TYPE imageType, long frameNumber, double unfilteredTimestamp=UNDEFINED_TIMESTAMP, double filteredTimestamp=UNDEFINED_TIMESTAMP, const igsioFieldMapType *customFields=NULL)
std::string GetSdkVersion() override
PlusStatus SetServoGain(unsigned char servoGain)
PlusStatus GetSoundVelocity(float &aSoundVelocity) const
PlusStatus GetMISMode(bool &MISMode)
vtkPlusUsImagingParameters * ImagingParameters
Store the current imaging parameters.
bool RequireImageOrientationInConfiguration
PlusStatus SetImageType(US_IMAGE_TYPE imageType)
PlusStatus SetupProbe(int probeID=0)
PlusStatus SetPending(const std::string ¶mName, bool pending)
PlusStatus InitializeCapistranoProbe()
void PrintSelf(ostream &os, vtkIndent indent) override
double CurrentPixelSpacingMm[3]
Values used in calculation of image to transducer matrix.
PlusStatus UpdateUSParameters()
PlusStatus InternalDisconnect() override
PlusStatus SetGainPercentDevice(double gainPercent[3])
PlusStatus GetProbeVelocityDevice(float &aVel)
igsioFieldMapType CustomFields
PlusStatus SetPixelType(igsioCommon::VTKScalarPixelType pixelType)
static const char * CAPISTRANO_SET_BIDIRECTIONAL_MODE
PlusStatus SetTimeGainCompensation(const std::vector< double > &tgc)
PlusStatus UpdateDepthMode()
PlusStatus SetDisplayZoomDevice(double zoom)
unsigned char GetPositionScale()
PlusStatus InitializeLUT()
unsigned char GetDerivativeCompensation()
static const char * CAPISTRANO_GET_POSITION_SCALE
static const char * CAPISTRANO_SET_MIS_PULSE_PERIOD
Initial rotation matrix b
PlusStatus SetImageSize(const FrameSizeType &imageSize)
PlusStatus SetCineBuffers(int cinebuffer)
static const char * CAPISTRANO_SET_DERIVATIVE_COMPENSATION
vtkPlusCapistranoVideoSource()
static const char * KEY_INTENSITY
virtual igsioCommon::VTKScalarPixelType GetPixelType()
unsigned char GetJitterCompensation()
virtual PlusStatus Disconnect()
PlusStatus GetTimeGainCompensation(std::vector< double > &tgc) const
PlusStatus GetFirstActiveOutputVideoSource(vtkPlusDataSource *&aVideoSource)
PlusStatus SetBidirectionalMode(bool mode)
PlusStatus SetPowerDb(double aPower)
PlusStatus SetMISMode(bool mode)
unsigned long FrameNumber
PlusStatus ReadConfiguration(vtkXMLDataElement *config) override
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
PlusStatus SetJitterCompensation(unsigned char jitterComp)
static const char * CAPISTRANO_SET_SERVO_GAIN
PlusStatus GetProbeNameDevice(std::string &probeName)
PlusStatus GetHardwareVersion(int &HardwareVersion)
PlusStatus InitializeCapistranoVideoSource()
PlusStatus InternalApplyImagingParameterChange() override
PlusStatus InternalConnect() override
PlusStatus SetProbeVoltage(float aVoltage)
static const char * CAPISTRANO_SET_POSITION_SCALE
PlusStatus SetPulseFrequency(float pf)
PlusStatus SetBModeViewOption(unsigned int bmodeviewoption)
PlusStatus GetContrast(double &aContrast) const
PlusStatus GetSampleFrequencyDevice(float &aFreq)
PlusStatus UpdateUSProbeParameters()
PlusStatus SetGainPercent(double aGainPercent)
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_READING(deviceConfig, rootConfigElement)
PlusStatus SetImageSize(const FrameSizeType &imageSize)
PlusStatus SetDynRangeDb(double aDynRangeDb)
PlusStatus InternalStartRecording() override
PlusStatus SetSectorPercent(double aSectorPercent)
static const char * KEY_CONTRAST
PlusStatus GetImageSize(FrameSizeType &imageSize) const
PlusStatus WriteConfiguration(vtkXMLDataElement *config) override
static const char * KEY_SOUNDVELOCITY
PlusStatus SetInterpolate(bool interpolate)
PlusStatus GetZoomFactor(double &aZoomFactor) const
static const char * CAPISTRANO_FREEZE_PROBE
static const char * KEY_VOLTAGE
const char const char * value
virtual US_IMAGE_ORIENTATION GetInputImageOrientation()
static const char * CAPISTRANO_GET_MIS_PULSE_PERIOD
PlusStatus GetProbeVoltage(float &aVoltage) const
static const char * KEY_ZOOM
bool StartThreadForInternalUpdates
static const char * CAPISTRANO_GET_BIDIRECTIONAL_MODE
PlusStatus InitializeImageWindow()
PlusStatus SetDerivativeCompensation(unsigned char derivativeCompensation)
PlusStatus SetIntensity(double aIntensity)
unsigned char GetWobbleRate()
PlusStatus SetFrequencyMhz(double aFrequencyMhz)
PlusStatus SetLutWindow(double lutwindow)
ChannelContainer OutputChannels
PlusStatus SetPositionScale(unsigned char scale)
PlusStatus UpdateUSBModeParameters()
PlusStatus SetSoundVelocity(float ss)
PlusStatus GetFrequencyMhz(double &aFrequencyMhz) const
PlusStatus SetDepthMm(float depthMm)
PlusStatus SetFocusDepthPercent(double aFocusDepthPercent)
PlusStatus SetDepthMmDevice(float depthMm)
PlusStatus SetContrast(double value)
unsigned char GetServoGain()
Direction vectors of rods y
static const char * CAPISTRANO_SET_WOBBLE_RATE
PlusStatus SetZoomFactor(double aZoomFactor)
static const char * CAPISTRANO_SET_SWEEP_ANGLE
PlusStatus GetIntensity(double &aIntensity) const
PlusStatus SetScanDepth(float sd)
static const char * CAPISTRANO_GET_SWEEP_ANGLE
static LRESULT CALLBACK ImageWindowProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
PlusStatus NotifyConfigured() override
bool IsSet(const std::string ¶mName) const
PlusStatus SetAverageMode(bool averagemode)
Class for acquiring ultrasound images from Capistrano Labs USB ultrasound systems.
bool GetBidirectionalMode()
unsigned char PositionScale
PlusStatus SetZoomFactor(double zoomfactor)
~vtkPlusCapistranoVideoSource()
static const char * CAPISTRANO_GET_SERVO_GAIN
static const char * CAPISTRANO_GET_SAMPLE_FREQUENCY
static const char * CAPISTRANO_GET_WOBBLE_RATE
static const char * CAPISTRANO_SET_JITTER_COMPENSATION
PlusStatus SetIntensity(double value)
PlusStatus SetMISPulsePeriod(unsigned int val)
static const char * CAPISTRANO_IS_PROBE_FROZEN
PlusStatus SetDepthMm(double aDepthMm)
PlusStatus SetSoundVelocity(float aSoundVelocity)
static const char * CAPISTRANO_GET_DERIVATIVE_COMPENSATION
static const char * KEY_TGC
virtual int GetNumberOfItems()
unsigned int CurrentBModeViewOption
PlusStatus SetLutCenter(double lutcenter)
PlusStatus SetUpdateParameters(bool b)
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *deviceConfig)
Interface to a 3D positioning tool, video source, or generalized data stream.