-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBmode.cpp
125 lines (108 loc) · 4.9 KB
/
Bmode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <iostream>
#include "ImageDisplay.h"
#include "dataBuffer.h"
#include "BmodeClass.h"
#include "imageParam.h"
using namespace std;
int main()
{
//// 1. Initialize imaging parameters
int numFrames = 2;
imageParam *parameters = new imageParam();
cout << "Params Created" << endl;
//// 2. Import data into linked list
// Create ifstream objects to keep track of line position
ifstream *imagFile = new ifstream;
ifstream *realFile = new ifstream;
imagFile->open("A4ImagRFData.txt"); // Replace the file name to A4ImagRFData_Mystery for last part
realFile->open("A4RealRFData.txt"); // Replace the file name to A4RealRFData_Mystery for last part
if (imagFile->fail() || realFile->fail())
{
cerr << "Cannot load from file, exiting program" << std::endl;
return -1;
}
// Read data from files into dataBuffer objects
dataBuffer *dataHead = new dataBuffer(imagFile, realFile, parameters->getNumElement(), parameters->getNumSample(), 0); // Create head node
dataHead->next = NULL; // Initialize head node "next" attibute
dataBuffer *currentData = dataHead; // Initialize current data pointer
for (int i = 1; i < parameters->getNumScanline(); i++)
{
currentData->next = new dataBuffer(imagFile, realFile, parameters->getNumElement(), parameters->getNumSample(), i); // Create new node and assign address to current node "next" attribute
currentData = currentData->next; // Point current node to newly created node
currentData->next = NULL; // Set new node "next" attribute to NULL
}
// Close and delete ifstream objects
imagFile->close();
realFile->close();
delete imagFile;
delete realFile;
cout << "Data Buffer Created" << endl;
//// 3. Beamform data into linked list
BmodeClass *scanlineHead = new BmodeClass(parameters, dataHead, 0);
scanlineHead->next = NULL;
// ASSIGNMENT 4 PART 5 BEGIN: TO BE COMPLETED BY STUDENTS
BmodeClass *currentScanline = scanlineHead; // Tracks which object is the current scanline
currentData = dataHead;
for (int i = 1; i < parameters->getNumScanline(); i++)
{ // Iterating to build up a linked list
currentData = currentData->next; // Assigns created object to the pointer next of currentScanline
// Advances the pointer currentScanline to the next entry
currentScanline->next = new BmodeClass(parameters, currentData, i);
currentScanline = currentScanline->next;
currentScanline->next = NULL;
}
// END OF ASSIGNMENT 4 PART 5
cout << "Scanline Buffer Created" << endl;
//// 4. Aggregate all scanlines into bmode image
float **image2D = new float *[parameters->getNumScanline()]; // Create array of pointers
currentScanline = scanlineHead; // Point current scanline to scanline node head
for (int i = 0; i < parameters->getNumScanline(); i++)
{
image2D[i] = new float[parameters->getNumPixel()];
currentScanline->getScanline(image2D[i]); // Point each array element to scanline contained in node
currentScanline = currentScanline->next; // Point current scanline to next node
}
cout << "Scanlines Aggregated" << endl;
//// 5. Display Linked list
ImageDisplay imaging;
cout << "ImageDisplay Created" << endl;
// Visualization loop
imaging.display(image2D, parameters->getNumScanline(), parameters->getNumPixel());
while (imaging.displayFlag)
{
imaging.checkInput(); // Check for keyboard presses
}
// Stop imaging and destroy imaging objects
imaging.exit();
//// 6. Destroy all objects
// Destroy Images
dataBuffer *nextData;
currentData = dataHead;
for (int f = 0; f < parameters->getNumScanline(); f++)
{
// Store next object
nextData = currentData->next;
// Destroy Current
delete currentData;
// Move on to the next object
currentData = nextData;
// Delete image data
delete[] image2D[f]; // use delete [] to deallocate an array
}
delete[] image2D; // use delete [] to deallocate an array
// Destroy Data
BmodeClass *nextScanline;
currentScanline = scanlineHead;
for (int f = 0; f < parameters->getNumScanline(); f++)
{
// currentData = currentData->next;
// Store next object
// Destroy Current
nextScanline = currentScanline->next;
delete currentScanline;
currentScanline = nextScanline;
}
// Destroy Params
delete parameters;
return 0;
}