Lines to Quads

Lines to Quads

The objective of this exercise is to read in a file stream of X, Y & Z vertex co-ordinates from a laser line triangulation scan and rearrange the vertex into quadrates, present the data to OpenGL for rendering.

The file for import is in a .txt format of vertex co-ordinates with space & “ \n “ separation, stored in a stream from the start of the scan to the finish, input file is lines_quads_50.txt.

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
1.98242 240.482 80.755
1.94385 239.071 79.1838
1.90504 237.651 77.6026
2.05882 234.529 83.8671
2.05882 232.779 83.8671
2.09666 230.709 85.4084
2.09666 228.965 85.4084
1.94385 228.473 79.1838
1.98242 226.396 80.755
2.19021 222.995 89.2191
3.88654 228.473 79.1123
3.96365 226.396 80.682
3.96365 224.636 80.682
4.34192 221.408 88.3818
4.34192 219.676 88.3818
4.4899 215.669 91.3941
4.4899 213.947 91.3941
4.4899 212.225 91.3941
4.5632 210.251 92.8861
4.5632 208.534 92.8861
4.19205 228.965 85.3312
3.88654 242.604 79.1123
5.82688 240.837 78.9931
5.94249 238.721 80.5604
5.82688 237.305 78.9931
6.17151 234.529 83.6651
6.17151 232.779 83.6651
6.28493 230.709 85.2027
6.34136 228.808 85.9678
5.94249 228.157 80.5604
7.53078 243.15 76.4613
9.50224 241.195 77.0422
9.79221 238.896 79.3932
9.69587 237.305 78.612
9.88825 235.2 80.1718
10.2693 232.779 83.2615
10.4581 230.709 84.7916
10.4581 228.965 84.7916
10.4581 227.221 84.7916
9.79221 226.551 79.3932
-1.72721 241.037 70.3586
-1.72721 239.239 70.3586
-1.66676 237.971 67.8962
-1.82664 234.784 74.4092
-1.84634 232.833 75.2114
-1.86597 230.889 76.011
-1.74722 230.084 71.174
-1.74722 228.289 71.174
-1.74722 226.493 71.174
-1.94385 223.174 79.1838







The above file stream can be viewed as profile lines from the back of the head, around towards the face and finishing at the back of the head, looking at the profiles from within the head rotating to the right.

In reality there are 256 profile lines but to view for coding I have used only 5 with 10 vertex per profile, where the row number is the array number together with it’s X, Y & Z element of the array.

E.G. Row 0 is vertex array[0][0] array[0][1] array[0][2], Row 49 is vertex array[49][0] array[49][1] array[49][2]


Profile 5 Profile 1 Profile 2 Profile 3 Profile 4

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

// This program is to produce vertex co-ordinates which can be used as quadrilaterals
// to render a laser line scan surface model from surface lines of the human head

#include <iostream>
#include <fstream>

float array[50][3];
float ax[50];
float ay[50];
float az[50];

float* p0_0=&array[0][0]; float* p0_1=&array[0][1]; float* p0_2=&array[0][2];// set pointer to arrays
float* p10_0=&array[10][0]; float* p10_1=&array[10][1]; float* p10_2=&array[10][2];
float* p11_0=&array[11][0]; float* p11_1=&array[11][1]; float* p11_2=&array[11][2];
float* p1_0=&array[1][0]; float* p1_1=&array[1][1]; float* p1_2=&array[1][2];
float* p40_0; float* p40_1; float* p40_2;  // declare last profile pointers
float* p41_0; float* p41_1; float* p41_2;

int i;
int j;
int k;
using namespace std;

int main()
{
        ifstream in_file("c:\\bust\\lines_quads_50.txt"); // get file to be loaded
        ofstream fout("c:\\bust\\lines_quads_50_q.txt");  // output file to hard drive
    if(!in_file.is_open()) {
        cout<<"File not opened"<<"\n"; //if not there say so
        return 1;
    }
    for(i=0;i<50;i++) {
       for(j=0;j<3;j++) {
        in_file >> array[i][j]; // load file into array[30][3]
       }
    }
    for(i=0;i<50;i++) {
        for(j=0;j<1;j++) {
            ax[i] = array[i][j]; // pull out x co-ordinate
        }
    }
   for(i=0;i<50;i++) {
        for(j=1;j<2;j++) {
            ay[i] = array[i][j]; // pull out y co-ordinate
        }
    }
   for(i=0;i<50;i++) {
    for(j=2;j<3;j++) {
            az[i] = array[i][j]; // pull out z co-ordinate
        }
    }
       for(i=0;i<3;i++)  {  // loop through scan profiles
        for(j=0;j<9;j++)  { // loop through first profile and each profile that follows

     fout<<*p0_0<<" "<<*p0_1<<" "<<*p0_2<<"\n"            // print out to file
         << *p10_0<<" "<<*p10_1<<" "<<*p10_2<<"\n"
         << *p11_0<<" "<<*p11_1<<" "<<*p11_2<<"\n"
         << *p1_0<<" "<<*p1_1<<" "<<*p1_2<<"\n";
         p0_0 = p0_0+3; p0_1 = p0_1+3; p0_2 = p0_2+3;      // Increment pointer up by 3
         p10_0 = p10_0+3; p10_1 = p10_1+3; p10_2 = p10_2+3;
         p11_0 = p11_0+3; p11_1 = p11_1+3; p11_2 = p11_2+3;
         p1_0 = p1_0+3; p1_1 = p1_1+3; p1_2 = p1_2+3;
       }

        for(k=0;k<1;k++) {

         p0_0 = p0_0+3; p0_1 = p0_1+3; p0_2 = p0_2+3;      // Jump to next profile
         p10_0 = p10_0+3; p10_1 = p10_1+3; p10_2 = p10_2+3;
         p11_0 = p11_0+3; p11_1 = p11_1+3; p11_2 = p11_2+3;
         p1_0 = p1_0+3; p1_1 = p1_1+3; p1_2 = p1_2+3;
       }
       }
       {
        p40_0=&array[40][0]; p40_1=&array[40][1]; p40_2=&array[40][2]; // set pointers to last
        p0_0=&array[0][0]; p0_1=&array[0][1]; p0_2=&array[0][2];       // and first arrays
        p1_0=&array[1][0]; p1_1=&array[1][1]; p1_2=&array[1][2];
        p41_0=&array[41][0]; p41_1=&array[41][1]; p41_2=&array[41][2];
       }

    for(j=0;j<9;j++) { // loop through last and first profile

     fout<<*p40_0<<" "<<*p40_1<<" "<<*p40_2<<"\n" // append to file
         << *p0_0<<" "<<*p0_1<<" "<<*p0_2<<"\n"
         << *p1_0<<" "<<*p1_1<<" "<<*p1_2<<"\n"
         << *p41_0<<" "<<*p41_1<<" "<<*p41_2<<"\n";

         p40_0 = p40_0+3; p40_1 = p40_1+3; p40_2 = p40_2+3;      // Increment pointer up by 3
         p0_0 = p0_0+3; p0_1 = p0_1+3; p0_2 = p0_2+3;
         p1_0 = p1_0+3; p1_1 = p1_1+3; p1_2 = p1_2+3;
         p41_0 = p41_0+3; p41_1 = p41_1+3; p41_2 = p41_2+3;

       }
    return 0;
}


Is there a better way to code for this ?
lines 33-52 can be simplified:
1
2
3
4
unsigned counter = 0;
/*second part of the condition can be removed if file will not contain more than 50 entries*/
while((in_file >> ax[counter] >> ay[counter] >> az[counter]) && counter < 50)
    ++counter;

And I would use structs to store point data.

Also separate your program into functions with meaningful names.
Last edited on
Thanks for that, I will try and go through your points.

Entries will be of 512 vertex points

Peter
Last edited on
Topic archived. No new replies allowed.