LCOV - code coverage report
Current view: top level - meshio - stl.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 23 23 100.0 %
Date: 2020-10-29 15:47:51 Functions: 9 9 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2015, Lakshman Anumolu, Pradeep Garigipati
       3             :  * All rights reserved.
       4             :  *
       5             :  * This file is part of MeshIO whose distribution is governed by
       6             :  * the BSD 2-Clause License contained in the accompanying LICENSE.txt
       7             :  * file.
       8             :  */
       9             : 
      10             : #ifndef __STL_HPP__
      11             : #define __STL_HPP__
      12             : 
      13             : #include <meshio/vectors.hpp>
      14             : 
      15             : #include <vector>
      16             : #include <string>
      17             : #include <fstream>
      18             : #include <sstream>
      19             : #include <cstdint>
      20             : 
      21             : namespace meshio {
      22             : namespace stl {
      23             : 
      24             : enum class Format {
      25             :     Ascii,
      26             :     Binary,
      27             : };
      28             : 
      29             : /* class to store data from STL file */
      30             : template<class T>
      31          54 : class Data {
      32             :   public:
      33             :     std::vector< Vec4<T> >      mPositions;
      34             :     std::vector< Vec3<float> >  mNormals;
      35             : 
      36          36 :     Data() {}
      37             : 
      38          36 :     ~Data() {
      39          36 :         this->clear();
      40          72 :     }
      41             : 
      42             :     void resize(unsigned pNumTriangles) {
      43          11 :         mPositions.resize(3*pNumTriangles);
      44          11 :         mNormals.resize(pNumTriangles);
      45          11 :     }
      46             : 
      47             :     void clear() {
      48          37 :         mPositions.clear();
      49          37 :         mNormals.clear();
      50          37 :     }
      51             : 
      52             :     bool operator==(const Data<T>& pSTLObj) {
      53           7 :         if(this->mPositions.size() != pSTLObj.mPositions.size())
      54           1 :             return false;
      55             : 
      56           6 :         if(this->mNormals.size() != pSTLObj.mNormals.size())
      57           1 :             return false;
      58             : 
      59         298 :         for(unsigned i = 0; i < mPositions.size(); ++i)
      60         289 :             if(!(this->mPositions[i] == pSTLObj.mPositions[i]))
      61           1 :                 return false;
      62             : 
      63          80 :         for(unsigned i = 0; i < mNormals.size(); ++i)
      64          73 :             if(!(this->mNormals[i] == pSTLObj.mNormals[i]))
      65           1 :                 return false;
      66             : 
      67           3 :         return true;
      68           7 :     }
      69             : };
      70             : 
      71             : template<typename T=float>
      72             : bool read(std::vector< meshio::stl::Data<T> > &pObjects, const char* pFileName);
      73             : 
      74             : template<typename T=float>
      75             : bool write(const char* pFileName,
      76             :            const meshio::stl::Format pFormat,
      77             :            const std::vector< meshio::stl::Data<T> > &pObjects);
      78             : 
      79             : #include <meshio/details/stl.inl>
      80             : 
      81             : }
      82             : }
      83             : 
      84             : #endif // __STL_HPP__

Generated by: LCOV version 1.15