Profile Lines to Polygon



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



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

#include <iostream>
#include <fstream>

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

float* p0_0=&array[0][0]; float* p0_1=&array[0][1]; float* p0_2=&array[0][2];// set pointer to arrays first and last profiles
float* p1_0=&array[1][0]; float* p1_1=&array[1][1]; float* p1_2=&array[1][2];
float* p110_0=&array[110][0]; float* p110_1=&array[110][1]; float* p110_2=&array[110][2];
float* p111_0=&array[111][0]; float* p111_1=&array[111][1]; float* p111_2=&array[111][2];

float* p28050_0=&array[28050][0]; float* p28050_1=&array[28050][1]; float* p28050_2=&array[28050][2];// set pointer to arrays last profiles
float* p28051_0=&array[28051][0]; float* p28051_1=&array[28051][1]; float* p28051_2=&array[28051][2];


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

int main()
{
        ifstream in_file("c:\\bust\\dad_3d.xyz"); // get file to be loaded
        ofstream fout("c:\\bust\\poly\\dad_poly_8.stl");  // 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<28160;i++) {
       for(j=0;j<3;j++) {
        in_file >> array[i][j]; // load file into array
       }
    }
    for(i=0;i<28160;i++) {
        for(j=0;j<1;j++) {
            ax[i] = array[i][j]; // pull out x co-ordinate
        }
    }
   for(i=0;i<28160;i++) {
        for(j=1;j<2;j++) {
            ay[i] = array[i][j]; // pull out y co-ordinate
        }
    }
   for(i=0;i<28160;i++) {
    for(j=2;j<3;j++) {
            az[i] = array[i][j]; // pull out z co-ordinate
        }
    }

    fout<<"solid name"<<"\n\n";  // print out file name

    for(j=0;j<255;j++){        // loop through scan profiles, number of profiles per scan
       for(i=0;i<109;i++) {    // loop through first profile and each profile that follows
                               // number of points per profile 0 to 109 = 110 points

   fout <<"facet normal  0.0     0.0   0.0"<<"\n"
        <<"   outer loop"<<"\n"
        <<"      vertex     "<<*p1_0<<"     "<<*p1_1<<"     "<<*p1_2<<"\n" // print out to file
         <<"      vertex     "<<*p0_0<<"     "<<*p0_1<<"     "<<*p0_2<<"\n"
         <<"      vertex     "<<*p110_0<<"     "<<*p110_1<<"     "<<*p110_2<<"\n"
         <<"  endloop"<<"\n"<<"endfacet"<<"\n"

        <<"facet normal  0.0     0.0   0.0"<<"\n"
        <<"   outer loop"<<"\n"
        <<"      vertex     "<<*p1_0<<"     "<<*p1_1<<"     "<<*p1_2<<"\n" // print out to file
         <<"      vertex     "<<*p110_0<<"     "<<*p110_1<<"     "<<*p110_2<<"\n"
         <<"      vertex     "<<*p111_0<<"     "<<*p111_1<<"     "<<*p111_2<<"\n"
         <<"  endloop"<<"\n"<<"endfacet"<<"\n";

        p0_0 = p0_0+3; p0_1 = p0_1+3; p0_2 = p0_2+3;      // Increament pointer up by 3
        p1_0 = p1_0+3; p1_1 = p1_1+3; p1_2 = p1_2+3;
        p110_0 = p110_0+3; p110_1 = p110_1+3; p110_2 = p110_2+3;
        p111_0 = p111_0+3; p111_1 = p111_1+3; p111_2 = p111_2+3;
       }
       for(k=0;k<1;k++) {
        p0_0 = p0_0+3; p0_1 = p0_1+3; p0_2 = p0_2+3;      // Increament pointer to jump
        p1_0 = p1_0+3; p1_1 = p1_1+3; p1_2 = p1_2+3;      // to next profile
        p110_0 = p110_0+3; p110_1 = p110_1+3; p110_2 = p110_2+3;
        p111_0 = p111_0+3; p111_1 = p111_1+3; p111_2 = p111_2+3;
       }
    }
       {
        p0_0=&array[0][0]; p0_1=&array[0][1]; p0_2=&array[0][2]; // set pointers back to the
        p1_0=&array[1][0]; p1_1=&array[1][1]; p1_2=&array[1][2]; // start of the stream
        p110_0=&array[110][0]; p110_1=&array[110][1]; p110_2=&array[110][2];
        p111_0=&array[111][0]; p111_1=&array[111][1]; p111_2=&array[111][2];
        }

    for(l=0;l<109;l++) {

    fout<<"facet normal  0.0     0.0   0.0"<<"\n"  // printing last and first profiles render
        <<"   outer loop"<<"\n"
        <<"      vertex     "<<*p1_0<<"     "<<*p1_1<<"     "<<*p1_2<<"\n" // print out to file
         <<"      vertex     "<<*p28050_0<<"     "<<*p28050_1<<"     "<<*p28050_2<<"\n"
         <<"      vertex     "<<*p0_0<<"     "<<*p0_1<<"     "<<*p0_2<<"\n"
         <<"  endloop"<<"\n"<<"endfacet"<<"\n"

        <<"facet normal  0.0     0.0   0.0"<<"\n"
        <<"   outer loop"<<"\n"
         <<"      vertex     "<<*p1_0<<"     "<<*p1_1<<"     "<<*p1_2<<"\n"
         <<"      vertex     "<<*p28051_0<<"     "<<*p28051_1<<"     "<<*p28051_2<<"\n"
         <<"      vertex     "<<*p28050_0<<"     "<<*p28050_1<<"     "<<*p28050_2<<"\n"
         <<"  endloop"<<"\n"<<"endfacet"<<"\n";

        p0_0 = p0_0+3; p0_1 = p0_1+3; p0_2 = p0_2+3;      // Increament pointer up by 3
        p1_0 = p1_0+3; p1_1 = p1_1+3; p1_2 = p1_2+3;
        p28050_0 = p28050_0+3; p28050_1 = p28050_1+3; p28050_2 = p28050_2+3;
        p28051_0 = p28051_0+3; p28051_1 = p28051_1+3; p28051_2 = p28051_2+3;
       }
      fout<<"\n"<<"endsolid"<<"\n";  // print out end of file
    return 0;
}


I post this to continue with my reproduction of the human head process
Last edited on
Topic archived. No new replies allowed.