-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
44 lines (37 loc) · 1.34 KB
/
main.cpp
File metadata and controls
44 lines (37 loc) · 1.34 KB
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
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include "trkfileio.h"
using namespace std;
int main()
{
/// input & output filename
string strInputFilePath = "/path/to/input.trk";
string strOutputFilePath = "/path/to/output.trk";
/// create reader and open file
TrkFileReader cReader(strInputFilePath);
if( !cReader.open() )
return EXIT_FAILURE;
/// create writer and create an empty new file
TrkFileWriter cWriter(strOutputFilePath);
cWriter.copyHeader(cReader.getHeader()); /// Copy header from the input file, beacuse the coordinates system (LPS/RAS/..) is defined in header.
if( !cWriter.create() )
return EXIT_FAILURE;
/// random sampling (0.1%)
vector<float> cTrk;
size_t iTotalTrackNum = cReader.getTotalTrkNum(); /// total number of tracks in input file
srand((unsigned int)(time(nullptr))); /// random seed
for(size_t i = 0; i < iTotalTrackNum; i++)
{
if( rand() % 1000 < 998 ) /// 0.1% random sampling
continue;
cTrk.clear();
cReader.readTrack(i, cTrk); /// read one track from input
cWriter.appendTrack(cTrk); /// write it back to output
}
/// close input and output file
cWriter.close();
cReader.close();
cout << "Finished" << endl;
return EXIT_SUCCESS;
}