Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-17 09:21:45

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 <NCollection_Vec3.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   //! Empty constructor of double-precision array.
0027   Poly_ArrayOfNodes()
0028       : NCollection_AliasedArray((int)sizeof(gp_Pnt))
0029   {
0030     //
0031   }
0032 
0033   //! Constructor of double-precision array.
0034   Poly_ArrayOfNodes(int theLength)
0035       : NCollection_AliasedArray((int)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, int theLength)
0045       : NCollection_AliasedArray(theBegin, theLength)
0046   {
0047     //
0048   }
0049 
0050   //! Constructor wrapping pre-allocated C-array of values without copying them.
0051   Poly_ArrayOfNodes(const NCollection_Vec3<float>& theBegin, int theLength)
0052       : NCollection_AliasedArray(theBegin, theLength)
0053   {
0054     //
0055   }
0056 
0057   //! Destructor.
0058   Standard_EXPORT ~Poly_ArrayOfNodes();
0059 
0060   //! Returns TRUE if array defines nodes with double precision.
0061   bool IsDoublePrecision() const { return myStride == (int)sizeof(gp_Pnt); }
0062 
0063   //! Sets if array should define nodes with double or single precision.
0064   //! Raises exception if array was already allocated.
0065   void SetDoublePrecision(bool theIsDouble)
0066   {
0067     if (myData != nullptr)
0068     {
0069       throw Standard_ProgramError(
0070         "Poly_ArrayOfNodes::SetDoublePrecision() should be called before allocation");
0071     }
0072     myStride = int(theIsDouble ? sizeof(gp_Pnt) : sizeof(NCollection_Vec3<float>));
0073   }
0074 
0075   //! Copies data of theOther array to this.
0076   //! The arrays should have the same length,
0077   //! but may have different precision / number of components (data conversion will be applied in
0078   //! the latter case).
0079   Standard_EXPORT Poly_ArrayOfNodes& Assign(const Poly_ArrayOfNodes& theOther);
0080 
0081   //! Move assignment.
0082   Poly_ArrayOfNodes& Move(Poly_ArrayOfNodes& theOther)
0083   {
0084     NCollection_AliasedArray::Move(theOther);
0085     return *this;
0086   }
0087 
0088   //! Assignment operator; @sa Assign()
0089   Poly_ArrayOfNodes& operator=(const Poly_ArrayOfNodes& theOther) { return Assign(theOther); }
0090 
0091   //! Move constructor
0092   Poly_ArrayOfNodes(Poly_ArrayOfNodes&& theOther) noexcept
0093       : NCollection_AliasedArray(std::move(theOther))
0094   {
0095     //
0096   }
0097 
0098   //! Move assignment operator; @sa Move()
0099   Poly_ArrayOfNodes& operator=(Poly_ArrayOfNodes&& theOther) noexcept { return Move(theOther); }
0100 
0101 public:
0102   //! A generalized accessor to point.
0103   inline gp_Pnt Value(int theIndex) const;
0104   inline gp_Pnt Value(const size_t theIndex) const;
0105 
0106   //! A generalized setter for point.
0107   inline void SetValue(int theIndex, const gp_Pnt& theValue);
0108   inline void SetValue(const size_t theIndex, const gp_Pnt& theValue);
0109 
0110   //! operator[] - alias to Value
0111   gp_Pnt operator[](int theIndex) const { return Value(theIndex); }
0112 };
0113 
0114 //=================================================================================================
0115 
0116 inline gp_Pnt Poly_ArrayOfNodes::Value(int theIndex) const
0117 {
0118   if (myStride == (int)sizeof(gp_Pnt))
0119   {
0120     return NCollection_AliasedArray::Value<gp_Pnt>(theIndex);
0121   }
0122   else
0123   {
0124     const NCollection_Vec3<float>& aVec3 =
0125       NCollection_AliasedArray::Value<NCollection_Vec3<float>>(theIndex);
0126     return gp_Pnt(aVec3.x(), aVec3.y(), aVec3.z());
0127   }
0128 }
0129 
0130 //=================================================================================================
0131 
0132 inline gp_Pnt Poly_ArrayOfNodes::Value(const size_t theIndex) const
0133 {
0134   Standard_OutOfRange_Raise_if(theIndex >= static_cast<size_t>(mySize),
0135                                "Poly_ArrayOfNodes::Value(), out of range index");
0136   return Value(static_cast<int>(theIndex));
0137 }
0138 
0139 //=================================================================================================
0140 
0141 inline void Poly_ArrayOfNodes::SetValue(int theIndex, const gp_Pnt& theValue)
0142 {
0143   if (myStride == (int)sizeof(gp_Pnt))
0144   {
0145     NCollection_AliasedArray::ChangeValue<gp_Pnt>(theIndex) = theValue;
0146   }
0147   else
0148   {
0149     NCollection_Vec3<float>& aVec3 =
0150       NCollection_AliasedArray::ChangeValue<NCollection_Vec3<float>>(theIndex);
0151     aVec3.SetValues((float)theValue.X(), (float)theValue.Y(), (float)theValue.Z());
0152   }
0153 }
0154 
0155 //=================================================================================================
0156 
0157 inline void Poly_ArrayOfNodes::SetValue(const size_t theIndex, const gp_Pnt& theValue)
0158 {
0159   Standard_OutOfRange_Raise_if(theIndex >= static_cast<size_t>(mySize),
0160                                "Poly_ArrayOfNodes::SetValue(), out of range index");
0161   SetValue(static_cast<int>(theIndex), theValue);
0162 }
0163 
0164 #endif // _Poly_ArrayOfNodes_HeaderFile