Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:38

0001 // Copyright (c) 2021 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _Poly_ArrayOfNodes_HeaderFile
0015 #define _Poly_ArrayOfNodes_HeaderFile
0016 
0017 #include <NCollection_AliasedArray.hxx>
0018 #include <gp_Pnt.hxx>
0019 #include <gp_Vec3f.hxx>
0020 #include <Standard_Macro.hxx>
0021 
0022 //! Defines an array of 3D nodes of single/double precision configurable at construction time.
0023 class Poly_ArrayOfNodes : public NCollection_AliasedArray<>
0024 {
0025 public:
0026 
0027   //! Empty constructor of double-precision array.
0028   Poly_ArrayOfNodes() : NCollection_AliasedArray ((Standard_Integer )sizeof(gp_Pnt))
0029   {
0030     //
0031   }
0032 
0033   //! Constructor of double-precision array.
0034   Poly_ArrayOfNodes (Standard_Integer theLength)
0035   : NCollection_AliasedArray ((Standard_Integer )sizeof(gp_Pnt), theLength)
0036   {
0037     //
0038   }
0039 
0040   //! Copy constructor 
0041   Standard_EXPORT Poly_ArrayOfNodes (const Poly_ArrayOfNodes& theOther);
0042 
0043   //! Constructor wrapping pre-allocated C-array of values without copying them.
0044   Poly_ArrayOfNodes (const gp_Pnt& theBegin,
0045                      Standard_Integer theLength)
0046   : NCollection_AliasedArray (theBegin, theLength)
0047   {
0048     //
0049   }
0050 
0051   //! Constructor wrapping pre-allocated C-array of values without copying them.
0052   Poly_ArrayOfNodes (const gp_Vec3f& theBegin,
0053                      Standard_Integer theLength)
0054   : NCollection_AliasedArray (theBegin, theLength)
0055   {
0056     //
0057   }
0058 
0059   //! Destructor.
0060   Standard_EXPORT ~Poly_ArrayOfNodes();
0061 
0062   //! Returns TRUE if array defines nodes with double precision.
0063   bool IsDoublePrecision() const { return myStride == (Standard_Integer )sizeof(gp_Pnt); }
0064 
0065   //! Sets if array should define nodes with double or single precision.
0066   //! Raises exception if array was already allocated.
0067   void SetDoublePrecision (bool theIsDouble)
0068   {
0069     if (myData != NULL) { throw Standard_ProgramError ("Poly_ArrayOfNodes::SetDoublePrecision() should be called before allocation"); }
0070     myStride = Standard_Integer(theIsDouble ? sizeof(gp_Pnt) : sizeof(gp_Vec3f));
0071   }
0072 
0073   //! Copies data of theOther array to this.
0074   //! The arrays should have the same length,
0075   //! but may have different precision / number of components (data conversion will be applied in the latter case).
0076   Standard_EXPORT Poly_ArrayOfNodes& Assign (const Poly_ArrayOfNodes& theOther);
0077 
0078   //! Move assignment.
0079   Poly_ArrayOfNodes& Move (Poly_ArrayOfNodes& theOther)
0080   {
0081     NCollection_AliasedArray::Move (theOther);
0082     return *this;
0083   }
0084 
0085   //! Assignment operator; @sa Assign()
0086   Poly_ArrayOfNodes& operator= (const Poly_ArrayOfNodes& theOther) { return Assign (theOther); }
0087 
0088   //! Move constructor
0089   Poly_ArrayOfNodes (Poly_ArrayOfNodes&& theOther) Standard_Noexcept
0090   : NCollection_AliasedArray (std::move (theOther))
0091   {
0092     //
0093   }
0094 
0095   //! Move assignment operator; @sa Move()
0096   Poly_ArrayOfNodes& operator= (Poly_ArrayOfNodes&& theOther) Standard_Noexcept
0097   {
0098     return Move (theOther);
0099   }
0100 
0101 public:
0102 
0103   //! A generalized accessor to point.
0104   inline gp_Pnt Value (Standard_Integer theIndex) const;
0105 
0106   //! A generalized setter for point.
0107   inline void SetValue (Standard_Integer theIndex, const gp_Pnt& theValue);
0108 
0109   //! operator[] - alias to Value
0110   gp_Pnt operator[] (Standard_Integer theIndex) const { return Value (theIndex); }
0111 
0112 };
0113 
0114 // =======================================================================
0115 // function : Value
0116 // purpose  :
0117 // =======================================================================
0118 inline gp_Pnt Poly_ArrayOfNodes::Value (Standard_Integer theIndex) const
0119 {
0120   if (myStride == (Standard_Integer )sizeof(gp_Pnt))
0121   {
0122     return NCollection_AliasedArray::Value<gp_Pnt> (theIndex);
0123   }
0124   else
0125   {
0126     const gp_Vec3f& aVec3 = NCollection_AliasedArray::Value<gp_Vec3f> (theIndex);
0127     return gp_Pnt (aVec3.x(), aVec3.y(), aVec3.z());
0128   }
0129 }
0130 
0131 // =======================================================================
0132 // function : SetValue
0133 // purpose  :
0134 // =======================================================================
0135 inline void Poly_ArrayOfNodes::SetValue (Standard_Integer theIndex, const gp_Pnt& theValue)
0136 {
0137   if (myStride == (Standard_Integer )sizeof(gp_Pnt))
0138   {
0139     NCollection_AliasedArray::ChangeValue<gp_Pnt> (theIndex) = theValue;
0140   }
0141   else
0142   {
0143     gp_Vec3f& aVec3 = NCollection_AliasedArray::ChangeValue<gp_Vec3f> (theIndex);
0144     aVec3.SetValues ((float )theValue.X(), (float )theValue.Y(), (float )theValue.Z());
0145   }
0146 }
0147 
0148 #endif // _Poly_ArrayOfNodes_HeaderFile