Microflow 3D  v1.0
STLReader.cpp
Go to the documentation of this file.
1 // ==============================================================================================
2 // Microflow 3D, http://www.microflow.pwr.edu.pl/
3 // Created by Roman Szafran on 25.03.19.
4 // Copyright (c) 2019 Wroclaw University of Science and Technology.
5 // Distributed under the Apache License, Version 2.0. You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0 or see accompanying file license.txt.
7 // Redistributions of source code must retain the above copyright and license notice.
8 // ==============================================================================================
9 
10 #include "STLReader.h"
11 
12 
13 MF::RW::STLReaderTyti::STLReaderTyti(const std::string& FileName, bool verbose) {
14 
15  // Check the file existence
16  std::ifstream isFile(FileName);
17  if (!isFile.good())
18  throw std::runtime_error(FileName + " - File not found!");
19  // Reading .stl file.
20  stlGrid = tyti::stl::read<float>(FileName);
21  std::cout << "Grid from " << FileName << " has been read successfully ----> " << stlGrid.first.header << std::endl;
22  // If verbose is true, the stl file content is displayed
23  if (verbose) {
24  std::cout << "solid " << stlGrid.first.header << std::endl;
25  for (size_t i = 0; i < stlGrid.first.normals.size(); ++i) {
26  std::cout << "\tfacet normal "
27  << " " << stlGrid.first.normals[i].data[0] << " "
28  << " " << stlGrid.first.normals[i].data[1] << " "
29  << " " << stlGrid.first.normals[i].data[2] << " "
30  << "\n";
31 
32  std::cout << "\t\touter loop\n";
33  for (int j : {0, 1, 2}) {
34  std::cout << "\t\t\tvertex"
35  << " " << stlGrid.first.vertices[3 * i + j].data[0] << " "
36  << " " << stlGrid.first.vertices[3 * i + j].data[1] << " "
37  << " " << stlGrid.first.vertices[3 * i + j].data[2] << " "
38  << "\n";
39  }
40  std::cout << "\t\tendloop\n"
41  << "\tendfacet\n";
42  }
43  std::cout << "endsolid " << stlGrid.first.header << "\n";
44  }
45 }
STLReaderTyti(const std::string &FileName, bool verbose=false)
Definition: STLReader.cpp:13