mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
0025936: Modeling Data - reusable data structure for 2D tesselation (3- and 4-nodal mesh)
// Added lost files
This commit is contained in:
60
src/Poly/Poly_Element.cxx
Normal file
60
src/Poly/Poly_Element.cxx
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright (c) 2015 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.
|
||||
|
||||
#include <Poly_Element.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : Poly_Element
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Poly_Element::Poly_Element()
|
||||
{
|
||||
myTriangles[0] = myTriangles[1] = 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Poly_Element
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Poly_Element::Poly_Element (const Standard_Integer theTriangle1,
|
||||
const Standard_Integer theTriangle2)
|
||||
{
|
||||
myTriangles[0] = theTriangle1;
|
||||
myTriangles[1] = theTriangle2;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Set
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Poly_Element::Set (const Standard_Integer theTriangle1,
|
||||
const Standard_Integer theTriangle2)
|
||||
{
|
||||
myTriangles[0] = theTriangle1;
|
||||
myTriangles[1] = theTriangle2;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Get
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Poly_Element::Get (Standard_Integer& theTriangle1,
|
||||
Standard_Integer& theTriangle2) const
|
||||
{
|
||||
theTriangle1 = myTriangles[0];
|
||||
theTriangle2 = myTriangles[1];
|
||||
}
|
84
src/Poly/Poly_Element.hxx
Normal file
84
src/Poly/Poly_Element.hxx
Normal file
@@ -0,0 +1,84 @@
|
||||
// Copyright (c) 2015 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.
|
||||
|
||||
#ifndef _Poly_Element_HeaderFile
|
||||
#define _Poly_Element_HeaderFile
|
||||
|
||||
#include <Standard_DefineAlloc.hxx>
|
||||
#include <Standard_Integer.hxx>
|
||||
#include <Standard_OutOfRange.hxx>
|
||||
|
||||
//! Describes an element on mesh.
|
||||
//! It can be defined as triangle index (in this case second index will be 0)
|
||||
//! or as a pair of triangles indices that make up the quad.
|
||||
class Poly_Element
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
DEFINE_STANDARD_ALLOC
|
||||
|
||||
//! Constructs an element and sets all indices to zero.
|
||||
Standard_EXPORT Poly_Element();
|
||||
|
||||
//! Constructs an element and sets it indices.
|
||||
Standard_EXPORT Poly_Element (const Standard_Integer theTriangle1,
|
||||
const Standard_Integer theTriangle2);
|
||||
|
||||
//! Sets the value of triangles indices.
|
||||
Standard_EXPORT void Set (const Standard_Integer theTriangle1,
|
||||
const Standard_Integer theTriangle2);
|
||||
|
||||
//! Returns the triangles indices of this element in theTriangle1, theTriangle2.
|
||||
Standard_EXPORT void Get (Standard_Integer& theTriangle1,
|
||||
Standard_Integer& theTriangle2) const;
|
||||
|
||||
//! @return the triangle index of given element theIndex.
|
||||
//! Raises OutOfRange from Standard if theIndex is not in 1,2.
|
||||
Standard_Integer Value (const Standard_Integer theIndex) const
|
||||
{
|
||||
Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 2, NULL);
|
||||
return myTriangles[theIndex - 1];
|
||||
}
|
||||
|
||||
Standard_Integer operator() (const Standard_Integer theIndex) const { return Value (theIndex); }
|
||||
|
||||
//! @return the triangle index of given element theIndex.
|
||||
//! Raises OutOfRange from Standard if theIndex is not in 1,2.
|
||||
Standard_Integer& ChangeValue (const Standard_Integer theIndex)
|
||||
{
|
||||
Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 2, NULL);
|
||||
return myTriangles[theIndex - 1];
|
||||
}
|
||||
|
||||
Standard_Integer& operator() (const Standard_Integer theIndex) { return ChangeValue (theIndex); }
|
||||
|
||||
//! @return Standard_True if the first element index > 0 and the second index == 0.
|
||||
Standard_Boolean IsTriangle() const
|
||||
{
|
||||
return (myTriangles[0] > 0 && myTriangles[1] == 0);
|
||||
}
|
||||
|
||||
//! @return Standard_True if the first and the second element indices > 0.
|
||||
Standard_Boolean IsQuad() const
|
||||
{
|
||||
return (myTriangles[0] > 0 && myTriangles[1] > 0);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Standard_Integer myTriangles[2];
|
||||
|
||||
};
|
||||
|
||||
#endif // _Poly_Element_HeaderFile
|
199
src/Poly/Poly_Mesh.cxx
Normal file
199
src/Poly/Poly_Mesh.cxx
Normal file
@@ -0,0 +1,199 @@
|
||||
// Copyright (c) 2015 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.
|
||||
|
||||
#include <Poly_Mesh.hxx>
|
||||
|
||||
#include <Standard_DefineHandle.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT (Poly_Mesh, Poly_Triangulation)
|
||||
|
||||
//=======================================================================
|
||||
//function : Poly_Mesh
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Poly_Mesh::Poly_Mesh (const Standard_Boolean theHasUVNodes)
|
||||
: Poly_Triangulation (0, 0, theHasUVNodes),
|
||||
myNbQuads (0)
|
||||
{}
|
||||
|
||||
//=======================================================================
|
||||
//function : Poly_Mesh
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Poly_Mesh::Poly_Mesh (const Handle(Poly_Triangulation)& theTriangulation)
|
||||
: Poly_Triangulation ( theTriangulation ),
|
||||
myNbQuads (0)
|
||||
{
|
||||
const Standard_Integer aNbTris = theTriangulation->NbTriangles();
|
||||
|
||||
// Fill collection of elements
|
||||
if ( aNbTris )
|
||||
myElements.SetValue( aNbTris - 1, Poly_Element() );
|
||||
|
||||
// Populate elements with triangles
|
||||
for ( Standard_Integer i = 1; i <= aNbTris; ++i )
|
||||
{
|
||||
myElements(i - 1).Set(i, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Copy
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(Poly_Triangulation) Poly_Mesh::Copy() const
|
||||
{
|
||||
const Standard_Boolean hasUV = HasUVNodes();
|
||||
Handle(Poly_Mesh) aCopy = new Poly_Mesh(hasUV);
|
||||
// Copy nodes
|
||||
Standard_Integer aNbNodes = NbNodes();
|
||||
for ( Standard_Integer i = 1; i <= aNbNodes; ++i )
|
||||
{
|
||||
aCopy->AddNode(Node(i));
|
||||
if ( hasUV )
|
||||
aCopy->ChangeUVNode(i) = UVNode(i);
|
||||
}
|
||||
// Copy triangles
|
||||
Standard_Integer aNbTriangles = NbTriangles();
|
||||
const Standard_Boolean hasNormals = HasNormals();
|
||||
for ( Standard_Integer i = 1; i <= aNbTriangles; ++i )
|
||||
{
|
||||
aCopy->AddTriangle(Triangle(i));
|
||||
// Pass normal vector (if any)
|
||||
if ( hasNormals )
|
||||
aCopy->SetNormal(i, Normal(i));
|
||||
}
|
||||
// Copy quads
|
||||
aCopy->myNbQuads = myNbQuads;
|
||||
aCopy->myElements = myElements;
|
||||
return aCopy;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AddElement
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Poly_Mesh::AddElement (const Standard_Integer theN1,
|
||||
const Standard_Integer theN2,
|
||||
const Standard_Integer theN3)
|
||||
{
|
||||
Standard_Integer anIndex = Poly_Triangulation::AddTriangle( Poly_Triangle(theN1, theN2, theN3) );
|
||||
return addElement( Poly_Element(anIndex, 0) );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AddElement
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Poly_Mesh::AddElement (const Standard_Integer theN1,
|
||||
const Standard_Integer theN2,
|
||||
const Standard_Integer theN3,
|
||||
const Standard_Integer theN4)
|
||||
{
|
||||
Standard_Integer anIndex1 = Poly_Triangulation::AddTriangle( Poly_Triangle(theN1, theN2, theN3) );
|
||||
Standard_Integer anIndex2 = Poly_Triangulation::AddTriangle( Poly_Triangle(theN1, theN3, theN4) );
|
||||
return addElement( Poly_Element(anIndex1, anIndex2) );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Element
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Poly_Element& Poly_Mesh::Element (const Standard_Integer theIndex) const
|
||||
{
|
||||
if ( theIndex < 1 || theIndex > myElements.Size() )
|
||||
{
|
||||
Standard_OutOfRange::Raise("Poly_Mesh::Element : index out of range");
|
||||
}
|
||||
|
||||
return myElements.Value(theIndex - 1);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Element
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Poly_Mesh::Element (const Standard_Integer theIndex,
|
||||
Standard_Integer& theN1,
|
||||
Standard_Integer& theN2,
|
||||
Standard_Integer& theN3,
|
||||
Standard_Integer& theN4) const
|
||||
{
|
||||
if ( theIndex < 1 || theIndex > myElements.Size() )
|
||||
{
|
||||
Standard_OutOfRange::Raise("Poly_Mesh::Element : index out of range");
|
||||
}
|
||||
|
||||
const Poly_Element& anElem = Element(theIndex);
|
||||
Standard_Integer aTriIdx1, aTriIdx2;
|
||||
anElem.Get(aTriIdx1, aTriIdx2);
|
||||
|
||||
// Get node indices for the first triangle
|
||||
const Poly_Triangle& aTri1 = Poly_Triangulation::Triangle(aTriIdx1);
|
||||
aTri1.Get(theN1, theN2, theN3);
|
||||
|
||||
// If the second triangle exists, take its node indices for quad
|
||||
if ( aTriIdx2 )
|
||||
{
|
||||
const Poly_Triangle& aTri2 = Poly_Triangulation::Triangle(aTriIdx2);
|
||||
aTri2.Get(theN1, theN3, theN4);
|
||||
}
|
||||
else
|
||||
theN4 = 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetElement
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Poly_Mesh::SetElement (const Standard_Integer theIndex, const Poly_Element& theElement)
|
||||
{
|
||||
if ( theIndex < 1 || theIndex > myElements.Size() )
|
||||
{
|
||||
Standard_OutOfRange::Raise("Poly_Mesh::SetElement : index out of range");
|
||||
}
|
||||
|
||||
if ( myElements.Value(theIndex - 1).Value(2) == 0 && theElement.Value(2) != 0 )
|
||||
{
|
||||
myNbQuads++;
|
||||
}
|
||||
else if ( myElements.Value(theIndex - 1).Value(2) != 0 && theElement.Value(2) == 0 )
|
||||
{
|
||||
myNbQuads--;
|
||||
}
|
||||
|
||||
myElements.SetValue(theIndex - 1, theElement);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : addElement
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Poly_Mesh::addElement(const Poly_Element& theElement)
|
||||
{
|
||||
myElements.Append(theElement);
|
||||
if ( theElement.Value(2) != 0 )
|
||||
{
|
||||
myNbQuads++;
|
||||
}
|
||||
return myElements.Size();
|
||||
}
|
104
src/Poly/Poly_Mesh.hxx
Normal file
104
src/Poly/Poly_Mesh.hxx
Normal file
@@ -0,0 +1,104 @@
|
||||
// Copyright (c) 2015 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.
|
||||
|
||||
#ifndef _Poly_Mesh_HeaderFile
|
||||
#define _Poly_Mesh_HeaderFile
|
||||
|
||||
#include <Poly_Element.hxx>
|
||||
#include <Poly_Triangulation.hxx>
|
||||
|
||||
//! This class is extension for Poly_Triangulation.
|
||||
//! It allows to store mesh with quad polygons as table of Poly_Element.
|
||||
//! Keep in mind that when you add a triangle, it is also added to the table of elements
|
||||
//! as Poly_Element. And it will have first index set to triangle index from Poly_Triangulation
|
||||
//! and second index will be set to 0.
|
||||
class Poly_Mesh : public Poly_Triangulation
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//! Constructs an empty mesh.
|
||||
//! @param theHasUVNodes indicates whether 2D nodes will be associated with
|
||||
//! 3D ones, (i.e. to enable a 2D representation).
|
||||
Standard_EXPORT Poly_Mesh (const Standard_Boolean theHasUVNodes = Standard_False);
|
||||
|
||||
//! Constructs a mesh from existing triangulation.
|
||||
//! @param theTriangulation source triangulation.
|
||||
Standard_EXPORT Poly_Mesh (const Handle(Poly_Triangulation)& theTriangulation);
|
||||
|
||||
//! Creates full copy of current mesh
|
||||
Standard_EXPORT virtual Handle(Poly_Triangulation) Copy() const;
|
||||
|
||||
//! Adds element to the mesh.
|
||||
//! @param theN1 index of the first node.
|
||||
//! @param theN2 index of the second node.
|
||||
//! @param theN3 index of the third node.
|
||||
//! @return index of the added element.
|
||||
Standard_EXPORT Standard_Integer AddElement (const Standard_Integer theN1,
|
||||
const Standard_Integer theN2,
|
||||
const Standard_Integer theN3);
|
||||
|
||||
//! Adds element to the mesh.
|
||||
//! @param theN1 index of the first node.
|
||||
//! @param theN2 index of the second node.
|
||||
//! @param theN3 index of the third node.
|
||||
//! @param theN4 index of the fourth node.
|
||||
//! @return index of the added element.
|
||||
Standard_EXPORT Standard_Integer AddElement (const Standard_Integer theN1,
|
||||
const Standard_Integer theN2,
|
||||
const Standard_Integer theN3,
|
||||
const Standard_Integer theN4);
|
||||
|
||||
//! @return the number of elements for this mesh.
|
||||
Standard_Integer NbElements() const { return myElements.Size(); }
|
||||
|
||||
//! @return the number of quads for this mesh.
|
||||
Standard_Integer NbQuads() const { return myNbQuads; }
|
||||
|
||||
//! @return element at the given index.
|
||||
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements.
|
||||
Standard_EXPORT const Poly_Element& Element (const Standard_Integer theIndex) const;
|
||||
|
||||
//! @return nodes of the element at the given index.
|
||||
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements.
|
||||
Standard_EXPORT void Element (const Standard_Integer theIndex,
|
||||
Standard_Integer& theN1,
|
||||
Standard_Integer& theN2,
|
||||
Standard_Integer& theN3,
|
||||
Standard_Integer& theN4) const;
|
||||
|
||||
//! Sets the element at the given index.
|
||||
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements.
|
||||
Standard_EXPORT void SetElement (const Standard_Integer theIndex, const Poly_Element& theElement);
|
||||
|
||||
protected:
|
||||
|
||||
//! Adds element to the mesh.
|
||||
//! @param theElement element to add.
|
||||
//! @return index of the added element.
|
||||
Standard_EXPORT Standard_Integer addElement (const Poly_Element& theElement);
|
||||
|
||||
private:
|
||||
|
||||
NCollection_Vector<Poly_Element> myElements;
|
||||
Standard_Integer myNbQuads;
|
||||
|
||||
public:
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(Poly_Mesh, Poly_Triangulation)
|
||||
|
||||
};
|
||||
|
||||
DEFINE_STANDARD_HANDLE(Poly_Mesh, Poly_Triangulation)
|
||||
|
||||
#endif // _Poly_Mesh_HeaderFile
|
Reference in New Issue
Block a user