Pragma Include Include Include Include Include Class Stlread Public Std Vector Vertexstack Q37101011

#pragma once

#include

#include

#include

#include

#include

class STLRead

{

public:

        std::vectorvertex_stack_;

        std::vector>index_stack_;

        std::vectornormal_stack_;

public:

        void readSTL(constchar* filename)

        {

              using namespace std;

              cout << “Start Reading STL file: ” << filename <<“n”;

              ifstream file(filename, std::ifstream::binary);

              if (file.is_open() == false) {

                      std::cout << filename << ” does not exist. Programterminated.” << std::endl; exit(-1);

              }

              // stl file format

              char header[80];

              file.read(header, sizeof(header));

              //cout << “[header]n” << header << endl;

              unsigned int num_tri;

              file.read((char*)&num_tri, sizeof(num_tri));

              //std::cout << “# of triangles: ” << num_tri <<std::endl;

              vertex_stack_.clear();

              index_stack_.clear();

              normal_stack_.clear();

              vertex_stack_.resize(num_tri * 3);

              index_stack_.resize(num_tri);

              normal_stack_.resize(num_tri);

              for (int t = 0; t < (int)num_tri; t++)

              {

                      // TODO: Read normal

                      // TODO: Read each vertex

                      // Read attribute size

                      unsigned short att_count;

                      if (!file.read((char*)&att_count, sizeof(att_count))){

                             cerr << “IOError: bad format (3).” << endl;

                      }

              }

              file.clear();

              file.close();

              std::cout << “Reading complete.” << std::endl;

              std::cout << “# of vertices

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.