43 #include "PlusConfigure.h" 44 #include "vtkIGSIORecursiveCriticalSection.h" 49 #include "AgMD1Fundamental.h" 52 #include <vtkCharArray.h> 54 #include <vtkMatrix4x4.h> 55 #include <vtkObjectFactory.h> 56 #include <vtkSocketCommunicator.h> 57 #include <vtkTimerLog.h> 58 #include <vtkTransform.h> 76 const int VIRTUAL_SROM_SIZE = 1024;
78 bool AgilentError(
const std::string& functionName, ViStatus status)
83 Acqrs_errorMessage(VI_NULL, status, ErrMsg, 256);
84 cout << functionName <<
": " << ErrMsg << endl;
103 , SampleFrequencyHz(420000000.0)
104 , DelayTimeSec(0.000002)
105 , SampleCountPerAcquisition(11350)
106 , SegmentCountPerAcquisition(1)
114 , FirstPeakToNeedleTip(vtkSmartPointer<vtkMatrix4x4>::New())
115 , SecondPeakToNeedleTip(vtkSmartPointer<vtkMatrix4x4>::New())
116 , ThirdPeakToNeedleTip(vtkSmartPointer<vtkMatrix4x4>::New())
117 , SignalImage(vtkSmartPointer<vtkImageData>::New())
118 , EnvelopeArray(NULL)
123 , MinPeakDistance(280)
195 os << indent <<
"LastFrameNumber: " << this->
LastFrameNumber << std::endl;
196 os << indent <<
"InstrumentCount: " << this->
InstrumentCount << std::endl;
197 os << indent <<
"Status: " << this->
Status << std::endl;
198 os << indent <<
"ResourceName: " << this->
ResourceName << std::endl;
199 os << indent <<
"OptionsString: " << this->
OptionString << std::endl;
200 os << indent <<
"InstrumentID: " << this->
InstrumentID << std::endl;
201 os << indent <<
"SpeedOfSound: " << this->
SpeedOfSound << std::endl;
204 os << indent <<
"DelayTimeSec: " << this->
DelayTimeSec << std::endl;
207 os << indent <<
"FullScale: " << this->
FullScale << std::endl;
208 os << indent <<
"Offset: " << this->
Offset << std::endl;
209 os << indent <<
"Coupling: " << this->
Coupling << std::endl;
210 os << indent <<
"Bandwidth: " << this->
Bandwidth << std::endl;
211 os << indent <<
"TrigCoupling: " << this->
TrigCoupling << std::endl;
212 os << indent <<
"Slope: " << this->
Slope << std::endl;
213 os << indent <<
"Level: " << this->
Level << std::endl;
214 os << indent <<
"MinPeakDistance: " << this->
MinPeakDistance << std::endl;
223 os << indent <<
"ReadParameters: " << std::endl;
224 os << indent <<
" dataType: " << this->
ReadParameters.dataType << std::endl;
225 os << indent <<
" readMode: " << this->
ReadParameters.readMode << std::endl;
226 os << indent <<
" firstSegment: " << this->
ReadParameters.firstSegment << std::endl;
227 os << indent <<
" nbrSegments: " << this->
ReadParameters.nbrSegments << std::endl;
228 os << indent <<
" firstSampleInSeg: " << this->
ReadParameters.firstSampleInSeg << std::endl;
229 os << indent <<
" nbrSamplesInSeg: " << this->
ReadParameters.nbrSamplesInSeg << std::endl;
230 os << indent <<
" segmentOffset: " << this->
ReadParameters.segmentOffset << std::endl;
231 os << indent <<
" dataArraySize: " << this->
ReadParameters.dataArraySize << std::endl;
232 os << indent <<
" segDescArraySize: " << this->
ReadParameters.segDescArraySize << std::endl;
233 os << indent <<
" flags: " << this->
ReadParameters.flags << std::endl;
234 os << indent <<
" reserved: " << this->
ReadParameters.reserved << std::endl;
235 os << indent <<
" reserved2: " << this->
ReadParameters.reserved2 << std::endl;
236 os << indent <<
" reserved3: " << this->
ReadParameters.reserved3 << std::endl;
238 os << indent <<
"DataDescription: " << std::endl;
239 os << indent <<
" returnedSamplesPerSeg: " << this->
DataDescription.returnedSamplesPerSeg << std::endl;
240 os << indent <<
" indexFirstPoint: " << this->
DataDescription.indexFirstPoint << std::endl;
241 os << indent <<
" sampTime: " << this->
DataDescription.sampTime << std::endl;
242 os << indent <<
" vGain: " << this->
DataDescription.vGain << std::endl;
243 os << indent <<
" vOffset: " << this->
DataDescription.vOffset << std::endl;
244 os << indent <<
" returnedSegments: " << this->
DataDescription.returnedSegments << std::endl;
245 os << indent <<
" nbrAvgWforms: " << this->
DataDescription.nbrAvgWforms << std::endl;
246 os << indent <<
" actualTriggersInAcqLo: " << this->
DataDescription.actualTriggersInAcqLo << std::endl;
247 os << indent <<
" actualTriggersInAcqHi: " << this->
DataDescription.actualTriggersInAcqHi << std::endl;
248 os << indent <<
" actualDataSize: " << this->
DataDescription.actualDataSize << std::endl;
249 os << indent <<
" reserved2: " << this->
DataDescription.reserved2 << std::endl;
250 os << indent <<
" reserved3: " << this->
DataDescription.reserved3 << std::endl;
251 os << indent <<
" actualDataSize: " << this->
DataDescription.actualDataSize << std::endl;
253 os << indent <<
"SegmentDescription: " << std::endl;
255 os << indent <<
" timeStampLo: " << this->
SegmentDescription.timeStampLo << std::endl;
256 os << indent <<
" timeStampHi: " << this->
SegmentDescription.timeStampHi << std::endl;
261 os << indent <<
"DataArray: " << std::endl;
267 os << indent << std::endl;
269 os << indent <<
"EnvelopeArray: " << std::endl;
275 os << indent << std::endl;
277 os << indent <<
"PeakIdxArray: " << std::endl;
283 os << indent << std::endl;
287 os << indent <<
"HannWindow: " << std::endl;
292 os << indent << std::endl;
295 os << indent <<
"PeakEntries: " << std::endl;
298 os << indent <<
" X: " << it->first <<
", " <<
"Y: " << it->second << std::endl;
309 if (AgilentError(
"AcqrsD1_multiInstrAutoDefine", this->
Status))
316 LOG_ERROR(
"No instrument found!");
320 LOG_INFO(this->
InstrumentCount <<
" Agilent Acqiris Digitizer(s) found on your PC");
344 if (AgilentError(
"AcqrsD1_acquire", this->
Status))
352 if (AgilentError(
"AcqrsD1_waitForEndOfAcquisition", this->
Status))
356 AgilentError(
"AcqrsD1_stopAcquisition", this->
Status);
360 if (this->
Status != VI_SUCCESS)
366 LOG_ERROR(
"The acquisition has been stopped - data invalid!");
372 if (AgilentError(
"AcqrsD1_readData", this->
Status))
378 ViInt32 halfWindowSize = this->
KernelSize / 2;
379 for (ViInt32 s = this->
DataDescription.indexFirstPoint; s < this->
DataDescription.indexFirstPoint + this->DataDescription.returnedSamplesPerSeg; s++)
383 for (
int i = -halfWindowSize;
i < halfWindowSize + 1; ++
i)
385 if (s + i < this->
DataDescription.indexFirstPoint || s +
i > this->DataDescription.indexFirstPoint + this->DataDescription.returnedSamplesPerSeg)
398 ViReal64 absMaxValue(-1.0);
399 ViReal64 absMaxValueIndex = 0;
404 if (abs(
value) > absMaxValue)
406 absMaxValue = abs(
value);
407 absMaxValueIndex =
i;
412 ViReal64 noiseLevel = 0.1 * absMaxValue;
413 ViInt32 peakIdxCount(0);
422 ViReal64 diffNext = this->EnvelopeArray[
i + 1] - this->EnvelopeArray[
i];
423 if ((diffPrev * diffNext) <= 0 && diffPrev > 0)
430 if (peakIdxCount == 0)
432 LOG_INFO(
"No peaks found. Skipping frame.");
437 ViInt32 peakIndex(0);
438 ViInt32 nextIndex(0);
440 for (ViInt32
i = 0;
i < peakIdxCount;
i++)
444 if (
i + 1 < peakIdxCount)
505 videoSource->
AddItem(this->
SignalImage, US_IMG_ORIENT_MF, US_IMG_BRIGHTNESS, this->FrameNumber);
522 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(ViReal64,
DelayTimeSec, deviceConfig);
524 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(ViReal64,
FullScale, deviceConfig);
525 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(ViReal64,
Offset, deviceConfig);
526 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(ViInt32,
Bandwidth, deviceConfig);
527 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(ViInt32,
TrigCoupling, deviceConfig);
528 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(ViInt32,
Slope, deviceConfig);
529 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(ViReal64,
Level, deviceConfig);
530 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(ViInt32,
SpeedOfSound, deviceConfig);
531 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(ViInt32,
KernelSize, deviceConfig);
532 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(ViInt32,
MinPeakDistance, deviceConfig);
543 deviceConfig->SetDoubleAttribute(
"DelayTimeSec", this->
DelayTimeSec);
545 deviceConfig->SetDoubleAttribute(
"FullScale", this->
FullScale);
546 deviceConfig->SetDoubleAttribute(
"Offset", this->
Offset);
547 deviceConfig->SetIntAttribute(
"Bandwidth", this->
Bandwidth);
548 deviceConfig->SetIntAttribute(
"TrigCoupling", this->
TrigCoupling);
549 deviceConfig->SetIntAttribute(
"Slope", this->
Slope);
550 deviceConfig->SetDoubleAttribute(
"Level", this->
Level);
551 deviceConfig->SetIntAttribute(
"SpeedOfSound", this->
SpeedOfSound);
552 deviceConfig->SetIntAttribute(
"KernelSize", this->
KernelSize);
553 deviceConfig->SetIntAttribute(
"MinPeakDistance", this->
MinPeakDistance);
565 LOG_ERROR(
"Agilent scope device requires a video data source to write 1D signal to.");
572 LOG_ERROR(
"Agilent scope device requires a tool data source with ID \"FirstPeak\" to envelope detected first peak to.");
579 LOG_ERROR(
"Agilent scope device requires a tool data source with ID \"SecondPeak\" to envelope detected second peak to.");
586 LOG_ERROR(
"Agilent scope device requires a tool data source with ID \"ThirdPeak\" to envelope detected second peak to.");
600 if (AgilentError(
"Acqrs_InitWithOptions", this->
Status))
608 if (AgilentError(
"AcqrsD1_configHorizontal", this->
Status))
614 if (AgilentError(
"AcqrsD1_configMemory", this->
Status))
620 ViInt32 sampleCountPerAcq;
621 ViInt32 segmentCountPerAcq;
622 this->
Status = AcqrsD1_getMemory(this->
InstrumentID, &sampleCountPerAcq, &segmentCountPerAcq);
623 if (AgilentError(
"AcqrsD1_getMemory", this->
Status))
629 LOG_WARNING(
"Sample count or segment count per acquisition does not match requested values. Replacing with actual values.");
642 source->SetPixelType(VTK_SHORT);
646 if (AgilentError(
"AcqrsD1_configVertical", this->
Status))
652 this->
Status = AcqrsD1_configTrigClass(this->
InstrumentID, 0, 0x00000001, 0, 0, 0.0, 0.0);
653 if (AgilentError(
"AcqrsD1_configTrigClass", this->
Status))
660 if (AgilentError(
"AcqrsD1_configTrigSource", this->
Status))
674 this->
ReadParameters.segDescArraySize =
sizeof(AqSegmentDescriptor);
691 this->HannWindow[k] = 0.5 * (1 - cos((2 * vtkMath::Pi() * k) / (this->KernelSize - 1)));
702 if (AgilentError(
"Acqrs_close", this->
Status))
708 this->
Status = Acqrs_closeAll();
709 if (AgilentError(
"Acqrs_closeAll", this->
Status))
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *config)
PlusStatus GetDataSource(const char *aSourceId, vtkPlusDataSource *&aSource)
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
ViInt32 SampleCountPerAcquisition
unsigned long LastFrameNumber
Index of the last frame number.
virtual ~vtkPlusAgilentScopeTracker()
vtkSmartPointer< vtkMatrix4x4 > FirstPeakToNeedleTip
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *config)
PlusStatus InternalUpdate()
ViInt32 SegmentCountPerAcquisition
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_WRITING(deviceConfig, rootConfigElement)
vtkPlusAgilentScopeTracker()
vtkSmartPointer< vtkImageData > SignalImage
vtkStandardNewMacro(vtkPlusAgilentScopeTracker)
ViReal64 SampleIntervalSec
virtual PlusStatus ToolTimeStampedUpdate(const std::string &aToolSourceId, vtkMatrix4x4 *matrix, ToolStatus status, unsigned long frameNumber, double unfilteredtimestamp, const igsioFieldMapType *customFields=NULL)
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)
Interface class for Agilent oscilloscope devices.
void PrintSelf(ostream &os, vtkIndent indent)
virtual PlusStatus InternalDisconnect()
Disconnect from the oscilloscope hardware.
std::vector< std::pair< ViInt16, ViInt32 > > PeakEntries
virtual PlusStatus NotifyConfigured()
PlusStatus GetFirstVideoSource(vtkPlusDataSource *&anImage)
unsigned long FrameNumber
virtual PlusStatus InternalConnect()
Connect to the oscilloscope hardware.
AqSegmentDescriptor SegmentDescription
AqReadParameters ReadParameters
virtual PlusStatus StopRecording()
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_READING(deviceConfig, rootConfigElement)
vtkSmartPointer< vtkMatrix4x4 > SecondPeakToNeedleTip
const char const char * value
Phidget_ChannelClass uint32_t * count
bool StartThreadForInternalUpdates
PlusStatus SetNumberOfScalarComponents(unsigned int numberOfScalarComponents)
AqDataDescriptor DataDescription
std::string GetToolReferenceFrameName() const
vtkSmartPointer< vtkMatrix4x4 > ThirdPeakToNeedleTip
ViReal64 SampleFrequencyHz
Interface to a 3D positioning tool, video source, or generalized data stream.