public:
// ---------- PUBLIC METHODS ------------
+ //! Empty constructor; should be used with caution.
+ NCollection_Array1()
+ : myLowerBound (1),
+ myUpperBound (0),
+ myDeletable (Standard_False),
+ myData (NULL)
+ {
+ //
+ }
+
//! Constructor
NCollection_Array1(const Standard_Integer theLower,
const Standard_Integer theUpper) :
*this = theOther;
}
+ //! Move constructor
+ NCollection_Array1 (const NCollection_Array1&& theOther)
+ : myLowerBound (theOther.myLowerBound),
+ myUpperBound (theOther.myUpperBound),
+ myDeletable (theOther.myDeletable),
+ myData (theOther.myData)
+ {
+ theOther.myUpperBound = theOther.myLowerBound - 1;
+ theOther.myDeletable = false;
+ theOther.myData = NULL;
+ }
+
//! C array-based constructor
NCollection_Array1 (const TheItemType& theBegin,
const Standard_Integer theLower,
Standard_Integer Length (void) const
{ return (myUpperBound-myLowerBound+1); }
+ //! Return TRUE if array has zero length.
+ Standard_Boolean IsEmpty() const { return myUpperBound < myLowerBound; }
+
//! Lower bound
Standard_Integer Lower (void) const
{ return myLowerBound; }
{
if (&theOther == this)
return *this;
+
Standard_DimensionMismatch_Raise_if (Length() != theOther.Length(), "NCollection_Array1::operator=");
+ if (myData == NULL)
+ {
+ return *this;
+ }
+
TheItemType * pMyItem = &myData[myLowerBound];
TheItemType * const pEndItem = &(theOther.myData)[theOther.myUpperBound];
TheItemType * pItem = &(theOther.myData)[theOther.myLowerBound];
while (pItem <= pEndItem) * pMyItem ++ = * pItem ++;
- return *this;
+ return *this;
+ }
+
+ //! Move assignment
+ NCollection_Array1& Move (NCollection_Array1&& theOther)
+ {
+ if (&theOther == this)
+ {
+ return *this;
+ }
+
+ if (myDeletable)
+ {
+ delete[] &myData[myLowerBound];
+ }
+ myLowerBound = theOther.myLowerBound;
+ myUpperBound = theOther.myUpperBound;
+ myDeletable = theOther.myDeletable;
+ myData = theOther.myData;
+
+ theOther.myUpperBound = theOther.myLowerBound - 1;
+ theOther.myDeletable = Standard_False;
+ theOther.myData = NULL;
+ return *this;
}
//! Assignment operator
return Assign (theOther);
}
+ //! Move assignment operator.
+ NCollection_Array1& operator= (NCollection_Array1&& theOther)
+ {
+ return Move (std::move (theOther));
+ }
+
//! @return first element
const TheItemType& First() const
{
myData[theIndex] = theItem;
}
+ //! Resizes the array to specified bounds.
+ //! No re-allocation will be done if length of array does not change,
+ //! but existing values will not be discarded if theToCopyData set to FALSE.
+ //! @param theLower new lower bound of array
+ //! @param theUpper new upper bound of array
+ //! @param theToCopyData flag to copy existing data into new array
+ void Resize (const Standard_Integer theLower,
+ const Standard_Integer theUpper,
+ const Standard_Boolean theToCopyData)
+ {
+ Standard_RangeError_Raise_if (theUpper < theLower, "NCollection_Array1::Resize");
+ const Standard_Integer anOldLen = Length();
+ const Standard_Integer aNewLen = theUpper - theLower + 1;
+ const Standard_Integer aLowerOld = myLowerBound;
+
+ TheItemType* aBeginOld = &myData[aLowerOld];
+ myLowerBound = theLower;
+ myUpperBound = theUpper;
+ if (aNewLen == anOldLen)
+ {
+ myData = aBeginOld - theLower;
+ return;
+ }
+
+ if (!theToCopyData && myDeletable)
+ {
+ delete[] aBeginOld;
+ }
+ TheItemType* aBeginNew = new TheItemType[aNewLen];
+ Standard_OutOfMemory_Raise_if (aBeginNew == NULL, "NCollection_Array1 : Allocation failed");
+ myData = aBeginNew - theLower;
+ if (!theToCopyData)
+ {
+ myDeletable = Standard_True;
+ return;
+ }
+
+ const Standard_Integer aLenCopy = Min (anOldLen, aNewLen);
+ for (Standard_Integer anIter = 0; anIter < aLenCopy; ++anIter)
+ {
+ aBeginNew[anIter] = aBeginOld[anIter];
+ }
+ if (myDeletable)
+ {
+ delete[] aBeginOld;
+ }
+ myDeletable = Standard_True;
+ }
+
//! Destructor - releases the memory
~NCollection_Array1 (void)
{ if (myDeletable) delete [] &(myData[myLowerBound]); }
Poly_Triangle.lxx
Poly_Triangulation.cxx
Poly_Triangulation.hxx
-Poly_Triangulation.lxx
//function : Poly_Triangulation
//purpose :
//=======================================================================
-Poly_Triangulation::Poly_Triangulation(const Standard_Integer NbNodes,
- const Standard_Integer NbTriangles,
- const Standard_Boolean UVNodes) :
- myDeflection(0),
- myNbNodes(NbNodes),
- myNbTriangles(NbTriangles),
- myNodes(1, NbNodes),
- myTriangles(1, NbTriangles)
+Poly_Triangulation::Poly_Triangulation(const Standard_Integer theNbNodes,
+ const Standard_Integer theNbTriangles,
+ const Standard_Boolean theHasUVNodes)
+: myDeflection(0),
+ myNodes (1, theNbNodes),
+ myTriangles (1, theNbTriangles)
{
- if (UVNodes) myUVNodes = new TColgp_HArray1OfPnt2d(1, myNbNodes);
+ if (theHasUVNodes) myUVNodes = new TColgp_HArray1OfPnt2d(1, theNbNodes);
}
//=======================================================================
//purpose :
//=======================================================================
-Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& Nodes,
- const Poly_Array1OfTriangle& Triangles) :
- myDeflection(0),
- myNbNodes(Nodes.Length()),
- myNbTriangles(Triangles.Length()),
- myNodes(1, Nodes.Length()),
- myTriangles(1, Triangles.Length())
+Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& theNodes,
+ const Poly_Array1OfTriangle& theTriangles)
+: myDeflection(0),
+ myNodes (1, theNodes.Length()),
+ myTriangles (1, theTriangles.Length())
{
- myNodes = Nodes;
- myTriangles = Triangles;
+ myNodes = theNodes;
+ myTriangles = theTriangles;
}
//=======================================================================
//purpose :
//=======================================================================
-Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& Nodes,
- const TColgp_Array1OfPnt2d& UVNodes,
- const Poly_Array1OfTriangle& Triangles) :
- myDeflection(0),
- myNbNodes(Nodes.Length()),
- myNbTriangles(Triangles.Length()),
- myNodes(1, Nodes.Length()),
- myTriangles(1, Triangles.Length())
+Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& theNodes,
+ const TColgp_Array1OfPnt2d& theUVNodes,
+ const Poly_Array1OfTriangle& theTriangles)
+: myDeflection(0),
+ myNodes (1, theNodes.Length()),
+ myTriangles (1, theTriangles.Length())
{
- myNodes = Nodes;
- myTriangles = Triangles;
- myUVNodes = new TColgp_HArray1OfPnt2d(1, myNbNodes);
- myUVNodes->ChangeArray1() = UVNodes;
+ myNodes = theNodes;
+ myTriangles = theTriangles;
+ myUVNodes = new TColgp_HArray1OfPnt2d (1, theNodes.Length());
+ myUVNodes->ChangeArray1() = theUVNodes;
}
//=======================================================================
//purpose :
//=======================================================================
-Standard_Real Poly_Triangulation::Deflection() const
-{
- return myDeflection;
-}
-
-//=======================================================================
-//function : Deflection
-//purpose :
-//=======================================================================
-
-void Poly_Triangulation::Deflection (const Standard_Real theDeflection)
+void Poly_Triangulation::Deflection(const Standard_Real theDeflection)
{
myDeflection = theDeflection;
}
myUVNodes.Nullify();
}
-//=======================================================================
-//function : Nodes
-//purpose :
-//=======================================================================
-
-const TColgp_Array1OfPnt& Poly_Triangulation::Nodes() const
-{
- return myNodes;
-}
-
-//=======================================================================
-//function : ChangeNodes
-//purpose :
-//=======================================================================
-
-TColgp_Array1OfPnt& Poly_Triangulation::ChangeNodes()
-{
- return myNodes;
-}
-
//=======================================================================
//function : Node
//purpose :
return myNodes.ChangeValue (theIndex);
}
-//=======================================================================
-//function : UVNodes
-//purpose :
-//=======================================================================
-
-const TColgp_Array1OfPnt2d& Poly_Triangulation::UVNodes() const
-{
- return myUVNodes->Array1();
-}
-
-//=======================================================================
-//function : ChangeUVNodes
-//purpose :
-//=======================================================================
-
-TColgp_Array1OfPnt2d& Poly_Triangulation::ChangeUVNodes()
-{
- return myUVNodes->ChangeArray1();
-}
-
//=======================================================================
//function : UVNode
//purpose :
return myUVNodes->ChangeValue (theIndex);
}
-//=======================================================================
-//function : Triangles
-//purpose :
-//=======================================================================
-
-const Poly_Array1OfTriangle& Poly_Triangulation::Triangles() const
-{
- return myTriangles;
-}
-
-//=======================================================================
-//function : ChangeTriangles
-//purpose :
-//=======================================================================
-
-Poly_Array1OfTriangle& Poly_Triangulation::ChangeTriangles()
-{
- return myTriangles;
-}
-
//=======================================================================
//function : Triangle
//purpose :
void Poly_Triangulation::SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals)
{
- if(theNormals.IsNull() || theNormals->Length() != 3*myNbNodes) {
+ if(theNormals.IsNull() || theNormals->Length() != 3 * NbNodes()) {
throw Standard_DomainError("Poly_Triangulation::SetNormals : wrong length");
}
const TShort_Array1OfShortReal& Poly_Triangulation::Normals() const
{
- if(myNormals.IsNull() || myNormals->Length() != 3*myNbNodes) {
+ if(myNormals.IsNull() || myNormals->Length() != 3 * NbNodes()) {
throw Standard_NullObject("Poly_Triangulation::Normals : "
"wrong length or null array");
}
TShort_Array1OfShortReal& Poly_Triangulation::ChangeNormals()
{
- if(myNormals.IsNull() || myNormals->Length() != 3*myNbNodes) {
+ if(myNormals.IsNull() || myNormals->Length() != 3 * NbNodes()) {
throw Standard_NullObject("Poly_Triangulation::ChangeNormals : "
"wrong length or null array");
}
Standard_Boolean Poly_Triangulation::HasNormals() const
{
- if(myNormals.IsNull() || myNormals->Length() != 3*myNbNodes) {
+ if(myNormals.IsNull() || myNormals->Length() != 3 * NbNodes()) {
return Standard_False;
}
return Standard_True;
Standard_EXPORT Poly_Triangulation (const Handle(Poly_Triangulation)& theTriangulation);
//! Returns the deflection of this triangulation.
- Standard_EXPORT Standard_Real Deflection() const;
+ Standard_Real Deflection() const { return myDeflection; }
//! Sets the deflection of this triangulation to theDeflection.
//! See more on deflection in Polygon2D
Standard_EXPORT void RemoveUVNodes();
//! Returns the number of nodes for this triangulation.
- Standard_Integer NbNodes() const { return myNbNodes; }
+ Standard_Integer NbNodes() const { return myNodes.Length(); }
//! Returns the number of triangles for this triangulation.
- Standard_Integer NbTriangles() const { return myNbTriangles; }
+ Standard_Integer NbTriangles() const { return myTriangles.Length(); }
//! Returns Standard_True if 2D nodes are associated with 3D nodes for this triangulation.
Standard_Boolean HasUVNodes() const { return !myUVNodes.IsNull(); }
//! Returns the table of 3D nodes (3D points) for this triangulation.
- Standard_EXPORT const TColgp_Array1OfPnt& Nodes() const;
+ const TColgp_Array1OfPnt& Nodes() const { return myNodes; }
//! Returns the table of 3D nodes (3D points) for this triangulation.
//! The returned array is
//! shared. Therefore if the table is selected by reference, you
//! can, by simply modifying it, directly modify the data
//! structure of this triangulation.
- Standard_EXPORT TColgp_Array1OfPnt& ChangeNodes();
+ TColgp_Array1OfPnt& ChangeNodes() { return myNodes; }
//! Returns node at the given index.
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
//! The function HasUVNodes checks if 2D nodes
//! are associated with the 3D nodes of this triangulation.
//! Const reference on the 2d nodes values.
- Standard_EXPORT const TColgp_Array1OfPnt2d& UVNodes() const;
+ const TColgp_Array1OfPnt2d& UVNodes() const { return myUVNodes->Array1(); }
//! Returns the table of 2D nodes (2D points) associated with
//! each 3D node of this triangulation.
//! Therefore if the table is selected by reference,
//! you can, by simply modifying it, directly modify the data
//! structure of this triangulation.
- Standard_EXPORT TColgp_Array1OfPnt2d& ChangeUVNodes();
+ TColgp_Array1OfPnt2d& ChangeUVNodes() { return myUVNodes->ChangeArray1(); }
//! Returns UVNode at the given index.
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
Standard_EXPORT gp_Pnt2d& ChangeUVNode (const Standard_Integer theIndex);
//! Returns the table of triangles for this triangulation.
- Standard_EXPORT const Poly_Array1OfTriangle& Triangles() const;
+ const Poly_Array1OfTriangle& Triangles() const { return myTriangles; }
//! Returns the table of triangles for this triangulation.
//! Function ChangeUVNodes shares the returned array.
//! Therefore if the table is selected by reference,
//! you can, by simply modifying it, directly modify the data
//! structure of this triangulation.
- Standard_EXPORT Poly_Array1OfTriangle& ChangeTriangles();
+ Poly_Array1OfTriangle& ChangeTriangles() { return myTriangles; }
//! Returns triangle at the given index.
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles.
protected:
Standard_Real myDeflection;
- Standard_Integer myNbNodes;
- Standard_Integer myNbTriangles;
TColgp_Array1OfPnt myNodes;
Handle(TColgp_HArray1OfPnt2d) myUVNodes;
Poly_Array1OfTriangle myTriangles;
+++ /dev/null
-// Created on: 1995-03-06
-// Created by: Laurent PAINNOT
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-//=======================================================================
-//function : NbNodes
-//purpose :
-//=======================================================================
-
-inline Standard_Integer Poly_Triangulation::NbNodes() const
-{
- return myNbNodes;
-}
-
-//=======================================================================
-//function : NbTriangles
-//purpose :
-//=======================================================================
-
-inline Standard_Integer Poly_Triangulation::NbTriangles() const
-{
- return myNbTriangles;
-}
-
-//=======================================================================
-//function : HasUVNodes
-//purpose :
-//=======================================================================
-
-inline Standard_Boolean Poly_Triangulation::HasUVNodes() const
-{
- return !myUVNodes.IsNull();
-}
-