8 #include "PlusConfigure.h" 12 #include <vtkImageData.h> 13 #include <vtkObjectFactory.h> 14 #include <vtkSmartPointer.h> 17 #include <igsioTrackedFrame.h> 18 #include <igsioVideoFrame.h> 19 #include <vtkIGSIOTrackedFrameList.h> 26 #include <ulterius_def.h> 27 #if PLUS_ULTRASONIX_SDK_MAJOR_VERSION == 1 28 #include <utx_imaging_modes.h> 48 this->Superclass::PrintSelf(os, indent);
55 if (volumeFileName == NULL)
57 LOG_ERROR(
"Failed to generate tracked frame from sonix volume - input file name is NULL!");
61 if (trackedFrameList == NULL)
63 LOG_ERROR(
"Failed to generate tracked frame from sonix volume - output tracked frame list is NULL!");
69 errno_t err = fopen_s(&fp, volumeFileName,
"rb");
73 LOG_ERROR(
"Error opening volume file: " << volumeFileName <<
" Error No.: " << err);
78 fseek(fp, 0, SEEK_END);
79 long fileSizeInBytes = ftell(fp);
86 fread(&hdr,
sizeof(hdr), 1, fp);
88 unsigned int dataType = static_cast<unsigned int>(hdr.type);
89 unsigned int sampleSizeInBytes = static_cast<unsigned int>(hdr.ss / 8);
90 unsigned int numberOfFrames = static_cast<unsigned int>(hdr.frames);
91 unsigned int frameSizeInBytes = static_cast<unsigned int>(hdr.w * hdr.h * sampleSizeInBytes);
92 FrameSizeType frameSize = { static_cast<unsigned int>(hdr.w), static_cast<unsigned int>(hdr.h), 1};
95 std::ostringstream strDataType;
96 strDataType << hdr.type;
98 std::ostringstream strTransmitFrequency;
99 strTransmitFrequency << hdr.txf;
101 std::ostringstream strSamplingFrequency;
102 strSamplingFrequency << hdr.sf;
104 std::ostringstream strProbeID;
105 strProbeID << hdr.probe;
107 std::ostringstream strDataRate;
108 strDataRate << hdr.dr;
110 std::ostringstream strLineDensity;
111 strLineDensity << hdr.ld;
113 unsigned int numberOfBytesToSkip = 0;
114 if ((fileSizeInBytes -
sizeof(hdr)) > frameSizeInBytes * numberOfFrames)
116 numberOfBytesToSkip = (fileSizeInBytes -
sizeof(hdr)) / numberOfFrames - frameSizeInBytes;
117 LOG_DEBUG(
"Each frame has " << numberOfBytesToSkip <<
" bytes header before the actual data");
119 else if ((fileSizeInBytes -
sizeof(hdr)) < frameSizeInBytes * numberOfFrames)
121 LOG_ERROR(
"Expected data size for reading (" << frameSizeInBytes * numberOfFrames
122 <<
" bytes) is larger than actual data size (" << fileSizeInBytes -
sizeof(hdr) <<
" bytes).");
128 if ((dataType == udtBPre) || (dataType == udtRF) || (dataType == udtMPre) || (dataType == udtPWRF) || (dataType == udtColorRF))
130 frameSize[0] = hdr.h;
131 frameSize[1] = hdr.w;
136 unsigned char* dataFromFile =
new unsigned char[frameSizeInBytes];
138 for (
unsigned int i = 0;
i < numberOfFrames;
i++)
141 fread(dataFromFile, numberOfBytesToSkip, 1, fp);
144 fread(dataFromFile, frameSizeInBytes, 1, fp);
150 pixelType = VTK_UNSIGNED_CHAR;
153 pixelType = VTK_SHORT;
156 LOG_ERROR(
"Uknown pixel type for data type: " << dataType);
161 unsigned int numberOfScalarComponents = 1;
163 igsioVideoFrame videoFrame;
164 if (videoFrame.AllocateFrame(frameSize, pixelType, numberOfScalarComponents) !=
PLUS_SUCCESS)
166 LOG_ERROR(
"Failed to allocate image data for frame #" <<
i);
171 memcpy(videoFrame.GetScalarPointer(), dataFromFile, frameSizeInBytes);
173 igsioTrackedFrame trackedFrame;
174 trackedFrame.SetImageData(videoFrame);
175 trackedFrame.SetTimestamp((1.0 * (
i + 1)) / acquisitionFrameRate);
177 trackedFrame.SetFrameField(
"SonixDataType", strDataType.str());
178 trackedFrame.SetFrameField(
"SonixTransmitFrequency", strTransmitFrequency.str());
179 trackedFrame.SetFrameField(
"SonixSamplingFrequency", strSamplingFrequency.str());
180 trackedFrame.SetFrameField(
"SonixDataRate", strDataRate.str());
181 trackedFrame.SetFrameField(
"SonixLineDensity", strLineDensity.str());
182 trackedFrame.SetFrameField(
"SonixProbeID", strProbeID.str());
185 trackedFrameList->AddTrackedFrame(&trackedFrame);
189 delete [] dataFromFile;
static PlusStatus GenerateTrackedFrameFromSonixVolume(const char *volumeFileName, vtkIGSIOTrackedFrameList *trackedFrameList, double acquisitionFrameRate=10)
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
vtkPlusSonixVolumeReader()
~vtkPlusSonixVolumeReader()
Reads a volume from file to tracked frame list.
vtkStandardNewMacro(vtkPlusSonixVolumeReader)