2310e12c15c9f8035866de52ed4ad37dd3d03126
[occt.git] / src / StlMesh / StlMesh_Mesh.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 //=======================================================================
18
19 #include <gp_XYZ.hxx>
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>
27
28 IMPLEMENT_STANDARD_RTTIEXT(StlMesh_Mesh,Standard_Transient)
29
30 //=======================================================================
31 //function : StlMesh_Mesh
32 //design   : 
33 //warning  : 
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())
37 { }
38
39 //=======================================================================
40 //function : AddDomain
41 //design   : 
42 //warning  : 
43 //=======================================================================
44
45 void StlMesh_Mesh::AddDomain()
46 {
47   Handle(StlMesh_MeshDomain) MD = new StlMesh_MeshDomain;
48   domains.Append (MD);
49 }
50
51 //=======================================================================
52 //function : AddDomain
53 //design   : 
54 //warning  : 
55 //=======================================================================
56
57 void StlMesh_Mesh::AddDomain(const Standard_Real Deflection)
58 {
59   Handle(StlMesh_MeshDomain) MD = new StlMesh_MeshDomain (Deflection);
60   domains.Append (MD);
61 }
62
63 //=======================================================================
64 //function : AddTriangle
65 //design   : 
66 //warning  : 
67 //=======================================================================
68
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)
72 {
73   nbTriangles++;
74   return (domains.Last())->AddTriangle (V1, V2, V3, Xn, Yn, Zn);
75 }
76
77 //=======================================================================
78 //function : AddVertex
79 //design   : 
80 //warning  : 
81 //=======================================================================
82
83 Standard_Integer StlMesh_Mesh::AddVertex(const Standard_Real X, const Standard_Real Y, const Standard_Real Z)
84 {
85   nbVertices++;
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);
92   
93   return (domains.Last())->AddVertex (X, Y, Z);
94 }
95
96 //=======================================================================
97 //function : AddOnlyNewVertex
98 //design   : 
99 //warning  : 
100 //=======================================================================
101
102 Standard_Integer StlMesh_Mesh::AddOnlyNewVertex(const Standard_Real X, const Standard_Real Y, const Standard_Real Z)
103 {
104   Standard_Boolean IsNew = Standard_True;
105   Standard_Integer VIndex = (domains.Last())->AddOnlyNewVertex (X, Y, Z, IsNew); 
106   if (IsNew) nbVertices++;
107   return VIndex;
108 }
109
110 //=======================================================================
111 //function : Bounds
112 //design   : 
113 //warning  : 
114 //=======================================================================
115
116 void StlMesh_Mesh::Bounds(gp_XYZ& XYZmax, gp_XYZ& XYZmin) const 
117 {
118   XYZmax = xyzmax;
119   XYZmin = xyzmin;
120 }
121
122 //=======================================================================
123 //function : Clear
124 //design   : 
125 //warning  : 
126 //=======================================================================
127
128 void StlMesh_Mesh::Clear()
129 {
130   nbTriangles = 0;
131   nbVertices  = 0;
132   xyzmax.SetCoord(-(Precision::Infinite()),-(Precision::Infinite()),-(Precision::Infinite()));
133   xyzmin.SetCoord(Precision::Infinite(),Precision::Infinite(),Precision::Infinite()); 
134   domains.Clear ();
135 }
136
137 //=======================================================================
138 //function : Deflection
139 //design   : 
140 //warning  : 
141 //=======================================================================
142
143 Standard_Real StlMesh_Mesh::Deflection(const Standard_Integer DomainIndex) const 
144 {return (domains.Value (DomainIndex))->Deflection ();}
145
146 //=======================================================================
147 //function : NbTriangles
148 //design   : 
149 //warning  : 
150 //=======================================================================
151
152 Standard_Integer StlMesh_Mesh::NbTriangles(const Standard_Integer DomainIndex) const 
153 { return (domains.Value(DomainIndex))->NbTriangles ();}
154
155 //=======================================================================
156 //function : NbVertices
157 //design   : 
158 //warning  : 
159 //=======================================================================
160
161 Standard_Integer StlMesh_Mesh::NbVertices(const Standard_Integer DomainIndex) const 
162 { return (domains.Value(DomainIndex))->NbVertices ();}
163
164 //=======================================================================
165 //function : Triangles
166 //design   : 
167 //warning  : 
168 //=======================================================================
169
170 const StlMesh_SequenceOfMeshTriangle& StlMesh_Mesh::Triangles(const Standard_Integer DomainIndex) const 
171 { return (domains.Value (DomainIndex))->Triangles ();}
172
173 //=======================================================================
174 //function : Vertices
175 //design   : 
176 //warning  : 
177 //=======================================================================
178
179 const TColgp_SequenceOfXYZ& StlMesh_Mesh::Vertices(const Standard_Integer DomainIndex) const 
180 { return (domains.Value (DomainIndex))->Vertices ();}
181