1 // Created on: 1995-09-25
2 // Created by: Philippe GIRODENGO
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 //=======================================================================
20 #include <Precision.hxx>
21 #include <Standard_NegativeValue.hxx>
22 #include <Standard_NoSuchObject.hxx>
23 #include <Standard_NullValue.hxx>
24 #include <Standard_Type.hxx>
25 #include <StlMesh_Mesh.hxx>
26 #include <StlMesh_MeshDomain.hxx>
28 IMPLEMENT_STANDARD_RTTIEXT(StlMesh_Mesh,Standard_Transient)
30 //=======================================================================
31 //function : StlMesh_Mesh
34 //=======================================================================
35 StlMesh_Mesh::StlMesh_Mesh()
36 : nbTriangles (0), nbVertices (0), xyzmax (-(Precision::Infinite()), -(Precision::Infinite()), -(Precision::Infinite())), xyzmin (Precision::Infinite(), Precision::Infinite(), Precision::Infinite())
39 //=======================================================================
40 //function : AddDomain
43 //=======================================================================
45 void StlMesh_Mesh::AddDomain()
47 Handle(StlMesh_MeshDomain) MD = new StlMesh_MeshDomain;
51 //=======================================================================
52 //function : AddDomain
55 //=======================================================================
57 void StlMesh_Mesh::AddDomain(const Standard_Real Deflection)
59 Handle(StlMesh_MeshDomain) MD = new StlMesh_MeshDomain (Deflection);
63 //=======================================================================
64 //function : AddTriangle
67 //=======================================================================
69 Standard_Integer StlMesh_Mesh::AddTriangle(const Standard_Integer V1, const Standard_Integer V2,
70 const Standard_Integer V3, const Standard_Real Xn,
71 const Standard_Real Yn, const Standard_Real Zn)
74 return (domains.Last())->AddTriangle (V1, V2, V3, Xn, Yn, Zn);
77 //=======================================================================
78 //function : AddVertex
81 //=======================================================================
83 Standard_Integer StlMesh_Mesh::AddVertex(const Standard_Real X, const Standard_Real Y, const Standard_Real Z)
86 if (X > xyzmax.X()) xyzmax.SetX (X);
87 if (Y > xyzmax.Y()) xyzmax.SetY (Y);
88 if (Z > xyzmax.Z()) xyzmax.SetZ (Z);
89 if (X < xyzmin.X()) xyzmin.SetX (X);
90 if (Y < xyzmin.Y()) xyzmin.SetY (Y);
91 if (Z < xyzmin.Z()) xyzmin.SetZ (Z);
93 return (domains.Last())->AddVertex (X, Y, Z);
96 //=======================================================================
97 //function : AddOnlyNewVertex
100 //=======================================================================
102 Standard_Integer StlMesh_Mesh::AddOnlyNewVertex(const Standard_Real X, const Standard_Real Y, const Standard_Real Z)
104 Standard_Boolean IsNew = Standard_True;
105 Standard_Integer VIndex = (domains.Last())->AddOnlyNewVertex (X, Y, Z, IsNew);
106 if (IsNew) nbVertices++;
110 //=======================================================================
114 //=======================================================================
116 void StlMesh_Mesh::Bounds(gp_XYZ& XYZmax, gp_XYZ& XYZmin) const
122 //=======================================================================
126 //=======================================================================
128 void StlMesh_Mesh::Clear()
132 xyzmax.SetCoord(-(Precision::Infinite()),-(Precision::Infinite()),-(Precision::Infinite()));
133 xyzmin.SetCoord(Precision::Infinite(),Precision::Infinite(),Precision::Infinite());
137 //=======================================================================
138 //function : Deflection
141 //=======================================================================
143 Standard_Real StlMesh_Mesh::Deflection(const Standard_Integer DomainIndex) const
144 {return (domains.Value (DomainIndex))->Deflection ();}
146 //=======================================================================
147 //function : NbTriangles
150 //=======================================================================
152 Standard_Integer StlMesh_Mesh::NbTriangles(const Standard_Integer DomainIndex) const
153 { return (domains.Value(DomainIndex))->NbTriangles ();}
155 //=======================================================================
156 //function : NbVertices
159 //=======================================================================
161 Standard_Integer StlMesh_Mesh::NbVertices(const Standard_Integer DomainIndex) const
162 { return (domains.Value(DomainIndex))->NbVertices ();}
164 //=======================================================================
165 //function : Triangles
168 //=======================================================================
170 const StlMesh_SequenceOfMeshTriangle& StlMesh_Mesh::Triangles(const Standard_Integer DomainIndex) const
171 { return (domains.Value (DomainIndex))->Triangles ();}
173 //=======================================================================
174 //function : Vertices
177 //=======================================================================
179 const TColgp_SequenceOfXYZ& StlMesh_Mesh::Vertices(const Standard_Integer DomainIndex) const
180 { return (domains.Value (DomainIndex))->Vertices ();}