|
||||
File indexing completed on 2025-01-18 10:04:52
0001 // Created: 2016-05-01 0002 // Author: Andrey Betenev 0003 // Copyright: Open CASCADE 2016 0004 // 0005 // This file is part of Open CASCADE Technology software library. 0006 // 0007 // This library is free software; you can redistribute it and/or modify it under 0008 // the terms of the GNU Lesser General Public License version 2.1 as published 0009 // by the Free Software Foundation, with special exception defined in the file 0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0011 // distribution for complete text of the license and disclaimer of any warranty. 0012 // 0013 // Alternatively, this file may be used under the terms of Open CASCADE 0014 // commercial license or contractual agreement. 0015 0016 #ifndef _RWStl_Reader_HeaderFile 0017 #define _RWStl_Reader_HeaderFile 0018 0019 #include <gp_XYZ.hxx> 0020 #include <Standard_ReadLineBuffer.hxx> 0021 #include <Standard_IStream.hxx> 0022 0023 class Message_ProgressRange; 0024 0025 //! An abstract class implementing procedure to read STL file. 0026 //! 0027 //! This class is not bound to particular data structure and can be used to read the file directly into arbitrary data model. 0028 //! To use it, create descendant class and implement methods addNode() and addTriangle(). 0029 //! 0030 //! Call method Read() to read the file. In the process of reading, the tool will call methods addNode() and addTriangle() to fill the mesh data structure. 0031 //! 0032 //! The nodes with equal coordinates are merged automatically on the fly. 0033 class RWStl_Reader : public Standard_Transient 0034 { 0035 DEFINE_STANDARD_RTTIEXT(RWStl_Reader, Standard_Transient) 0036 public: 0037 0038 //! Default constructor. 0039 Standard_EXPORT RWStl_Reader(); 0040 0041 //! Reads data from STL file (either binary or Ascii). 0042 //! This function supports reading multi-domain STL files formed by concatenation 0043 //! of several "plain" files. 0044 //! The mesh nodes are not merged between domains. 0045 //! Unicode paths can be given in UTF-8 encoding. 0046 //! Format is recognized automatically by analysis of the file header. 0047 //! Returns true if success, false on error or user break. 0048 Standard_EXPORT Standard_Boolean Read (const char* theFile, 0049 const Message_ProgressRange& theProgress); 0050 0051 //! Guess whether the stream is an Ascii STL file, by analysis of the first bytes (~200). 0052 //! If the stream does not support seekg() then the parameter isSeekgAvailable should 0053 //! be passed as 'false', in this case the function attempts to put back the read symbols 0054 //! to the stream which thus must support ungetc(). 0055 //! Returns true if the stream seems to contain Ascii STL. 0056 Standard_EXPORT Standard_Boolean IsAscii (Standard_IStream& theStream, 0057 const bool isSeekgAvailable); 0058 0059 //! Reads STL data from binary stream. 0060 //! The stream must be opened in binary mode. 0061 //! Stops after reading the number of triangles recorded in the file header. 0062 //! Returns true if success, false on error or user break. 0063 Standard_EXPORT Standard_Boolean ReadBinary (Standard_IStream& theStream, 0064 const Message_ProgressRange& theProgress); 0065 0066 //! Reads data from the stream assumed to contain Ascii STL data. 0067 //! The stream can be opened either in binary or in Ascii mode. 0068 //! Reading stops at the position specified by theUntilPos, 0069 //! or end of file is reached, or when keyword "endsolid" is found. 0070 //! Empty lines are not supported and will read to reading failure. 0071 //! If theUntilPos is non-zero, reads not more than until that position. 0072 //! Returns true if success, false on error or user break. 0073 Standard_EXPORT Standard_Boolean ReadAscii (Standard_IStream& theStream, 0074 Standard_ReadLineBuffer& theBuffer, 0075 const std::streampos theUntilPos, 0076 const Message_ProgressRange& theProgress); 0077 0078 public: 0079 0080 //! Callback function to be implemented in descendant. 0081 //! Should create new node with specified coordinates in the target model, and return its ID as integer. 0082 virtual Standard_Integer AddNode (const gp_XYZ& thePnt) = 0; 0083 0084 //! Callback function to be implemented in descendant. 0085 //! Should create new triangle built on specified nodes in the target model. 0086 virtual void AddTriangle (Standard_Integer theN1, Standard_Integer theN2, Standard_Integer theN3) = 0; 0087 0088 //! Callback function to be implemented in descendant. 0089 //! Should create a new triangulation for a solid in multi-domain case. 0090 virtual void AddSolid() {} 0091 public: 0092 0093 //! Return merge tolerance; M_PI/2 by default - all nodes are merged regardless angle between triangles. 0094 Standard_Real MergeAngle() const { return myMergeAngle; } 0095 0096 //! Set merge angle in radians. 0097 //! Specify something like M_PI/4 (45 degrees) to avoid merge nodes between triangles at sharp corners. 0098 void SetMergeAngle (Standard_Real theAngleRad) { myMergeAngle = theAngleRad; } 0099 0100 //! Return linear merge tolerance; 0.0 by default (only 3D points with exactly matching coordinates are merged). 0101 double MergeTolerance() const { return myMergeTolearance; } 0102 0103 //! Set linear merge tolerance. 0104 void SetMergeTolerance (double theTolerance) { myMergeTolearance = theTolerance; } 0105 0106 protected: 0107 0108 Standard_Real myMergeAngle; 0109 Standard_Real myMergeTolearance; 0110 0111 }; 0112 0113 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |