Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-06 09:21:59

0001 // Created on: 2017-06-13
0002 // Created by: Alexander MALYSHEV
0003 // Copyright (c) 2017 OPEN CASCADE SAS
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_HeaderFile
0017 #define _RWStl_HeaderFile
0018 
0019 #include <OSD_Path.hxx>
0020 #include <Poly_Triangulation.hxx>
0021 #include <Standard_Macro.hxx>
0022 #include <Message_ProgressScope.hxx>
0023 #include <NCollection_Sequence.hxx>
0024 
0025 //! This class provides methods to read and write triangulation from / to the STL files.
0026 class RWStl
0027 {
0028 public:
0029   //! Write triangulation to binary STL file.
0030   //! binary format of an STL file.
0031   //! Returns false if the cannot be opened;
0032   Standard_EXPORT static bool WriteBinary(
0033     const occ::handle<Poly_Triangulation>& theMesh,
0034     const OSD_Path&                        thePath,
0035     const Message_ProgressRange&           theProgress = Message_ProgressRange());
0036 
0037   //! Write triangulation to binary STL stream.
0038   Standard_EXPORT static bool WriteBinary(
0039     const occ::handle<Poly_Triangulation>& theMesh,
0040     Standard_OStream&                      theStream,
0041     const Message_ProgressRange&           theProgress = Message_ProgressRange());
0042 
0043   //! write the meshing in a file following the
0044   //! Ascii format of an STL file.
0045   //! Returns false if the cannot be opened;
0046   Standard_EXPORT static bool WriteAscii(
0047     const occ::handle<Poly_Triangulation>& theMesh,
0048     const OSD_Path&                        thePath,
0049     const Message_ProgressRange&           theProgress = Message_ProgressRange());
0050 
0051   //! Write triangulation to ASCII STL stream.
0052   Standard_EXPORT static bool WriteAscii(
0053     const occ::handle<Poly_Triangulation>& theMesh,
0054     Standard_OStream&                      theStream,
0055     const Message_ProgressRange&           theProgress = Message_ProgressRange());
0056 
0057   //! Read specified STL file and returns its content as triangulation.
0058   //! In case of error, returns Null handle.
0059   Standard_EXPORT static occ::handle<Poly_Triangulation> ReadFile(
0060     const OSD_Path&              theFile,
0061     const Message_ProgressRange& theProgress = Message_ProgressRange());
0062 
0063   //! Read specified STL file and returns its content as triangulation.
0064   //! In case of error, returns Null handle.
0065   static occ::handle<Poly_Triangulation> ReadFile(
0066     const char* const            theFile,
0067     const Message_ProgressRange& theProgress = Message_ProgressRange())
0068   {
0069     return ReadFile(theFile, M_PI / 2.0, theProgress);
0070   }
0071 
0072   //! Read specified STL file and returns its content as triangulation.
0073   //! @param[in] theFile file path to read
0074   //! @param[in] theMergeAngle maximum angle in radians between triangles to merge equal nodes;
0075   //! M_PI/2 means ignore angle
0076   //! @param[in] theProgress progress indicator
0077   //! @return result triangulation or NULL in case of error
0078   Standard_EXPORT static occ::handle<Poly_Triangulation> ReadFile(
0079     const char* const            theFile,
0080     const double                 theMergeAngle,
0081     const Message_ProgressRange& theProgress = Message_ProgressRange());
0082 
0083   //! Read specified STL file and fills triangulation list for multi-domain case.
0084   //! @param[in] theFile file path to read
0085   //! @param[in] theMergeAngle maximum angle in radians between triangles to merge equal nodes;
0086   //! M_PI/2 means ignore angle
0087   //! @param[out] theTriangList triangulation list for multi-domain case
0088   //! @param[in] theProgress progress indicator
0089   Standard_EXPORT static void ReadFile(
0090     const char* const                                      theFile,
0091     const double                                           theMergeAngle,
0092     NCollection_Sequence<occ::handle<Poly_Triangulation>>& theTriangList,
0093     const Message_ProgressRange&                           theProgress = Message_ProgressRange());
0094 
0095   //! Read triangulation from a binary STL file
0096   //! In case of error, returns Null handle.
0097   Standard_EXPORT static occ::handle<Poly_Triangulation> ReadBinary(
0098     const OSD_Path&              thePath,
0099     const Message_ProgressRange& theProgress = Message_ProgressRange());
0100 
0101   //! Read triangulation from an Ascii STL file
0102   //! In case of error, returns Null handle.
0103   Standard_EXPORT static occ::handle<Poly_Triangulation> ReadAscii(
0104     const OSD_Path&              thePath,
0105     const Message_ProgressRange& theProgress = Message_ProgressRange());
0106 
0107   //! Read triangulation from binary STL stream
0108   //! In case of error, returns Null handle.
0109   Standard_EXPORT static occ::handle<Poly_Triangulation> ReadBinaryStream(
0110     Standard_IStream&            theStream,
0111     const double                 theMergeAngle = M_PI / 2.0,
0112     const Message_ProgressRange& theProgress   = Message_ProgressRange());
0113 
0114   //! Read triangulation from ASCII STL stream
0115   //! In case of error, returns Null handle.
0116   Standard_EXPORT static occ::handle<Poly_Triangulation> ReadAsciiStream(
0117     Standard_IStream&            theStream,
0118     const double                 theMergeAngle = M_PI / 2.0,
0119     const Message_ProgressRange& theProgress   = Message_ProgressRange());
0120 
0121   //! Read STL data from stream (auto-detects ASCII vs Binary)
0122   //! In case of error, returns Null handle.
0123   Standard_EXPORT static occ::handle<Poly_Triangulation> ReadStream(
0124     Standard_IStream&            theStream,
0125     const double                 theMergeAngle = M_PI / 2.0,
0126     const Message_ProgressRange& theProgress   = Message_ProgressRange());
0127 };
0128 
0129 #endif