Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-28 10:21:32

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_Type.hxx>
0021 #include <Standard_ReadLineBuffer.hxx>
0022 #include <Standard_IStream.hxx>
0023 
0024 class Message_ProgressRange;
0025 
0026 //! An abstract class implementing procedure to read STL file.
0027 //!
0028 //! This class is not bound to particular data structure and can be used to read the file directly
0029 //! into arbitrary data model. To use it, create descendant class and implement methods addNode()
0030 //! and addTriangle().
0031 //!
0032 //! Call method Read() to read the file. In the process of reading, the tool will call methods
0033 //! addNode() and addTriangle() to fill the mesh data structure.
0034 //!
0035 //! The nodes with equal coordinates are merged automatically on the fly.
0036 class RWStl_Reader : public Standard_Transient
0037 {
0038   DEFINE_STANDARD_RTTIEXT(RWStl_Reader, Standard_Transient)
0039 public:
0040   //! Default constructor.
0041   Standard_EXPORT RWStl_Reader();
0042 
0043   //! Reads data from STL file (either binary or Ascii).
0044   //! This function supports reading multi-domain STL files formed by concatenation
0045   //! of several "plain" files.
0046   //! The mesh nodes are not merged between domains.
0047   //! Unicode paths can be given in UTF-8 encoding.
0048   //! Format is recognized automatically by analysis of the file header.
0049   //! Returns true if success, false on error or user break.
0050   Standard_EXPORT bool Read(const char* theFile, const Message_ProgressRange& theProgress);
0051 
0052   //! Guess whether the stream is an Ascii STL file, by analysis of the first bytes (~200).
0053   //! If the stream does not support seekg() then the parameter isSeekgAvailable should
0054   //! be passed as 'false', in this case the function attempts to put back the read symbols
0055   //! to the stream which thus must support ungetc().
0056   //! Returns true if the stream seems to contain Ascii STL.
0057   Standard_EXPORT bool IsAscii(Standard_IStream& theStream, 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 bool 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 bool ReadAscii(Standard_IStream&            theStream,
0074                                  Standard_ReadLineBuffer&     theBuffer,
0075                                  const std::streampos         theUntilPos,
0076                                  const Message_ProgressRange& theProgress);
0077 
0078 public:
0079   //! Callback function to be implemented in descendant.
0080   //! Should create new node with specified coordinates in the target model, and return its ID as
0081   //! integer.
0082   virtual int 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(int theN1, int theN2, int 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 
0092 public:
0093   //! Return merge tolerance; M_PI/2 by default - all nodes are merged regardless angle between
0094   //! triangles.
0095   double MergeAngle() const { return myMergeAngle; }
0096 
0097   //! Set merge angle in radians.
0098   //! Specify something like M_PI/4 (45 degrees) to avoid merge nodes between triangles at sharp
0099   //! corners.
0100   void SetMergeAngle(double theAngleRad) { myMergeAngle = theAngleRad; }
0101 
0102   //! Return linear merge tolerance; 0.0 by default (only 3D points with exactly matching
0103   //! coordinates are merged).
0104   double MergeTolerance() const { return myMergeTolearance; }
0105 
0106   //! Set linear merge tolerance.
0107   void SetMergeTolerance(double theTolerance) { myMergeTolearance = theTolerance; }
0108 
0109 protected:
0110   double myMergeAngle;
0111   double myMergeTolearance;
0112 };
0113 
0114 #endif