0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- manual
[occt.git] / src / XSDRAWSTLVRML / XSDRAWSTLVRML_DataSource.cxx
CommitLineData
b311480e 1// Created on: 2004-06-10
2// Created by: Alexander SOLOVYOV
973c2be1 3// Copyright (c) 2004-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
7fd59977 16
42cf5bc1 17#include <Standard_Type.hxx>
18#include <StlMesh_Mesh.hxx>
7fd59977 19#include <StlMesh_MeshTriangle.hxx>
42cf5bc1 20#include <StlMesh_SequenceOfMeshTriangle.hxx>
7fd59977 21#include <TColgp_SequenceOfXYZ.hxx>
7fd59977 22#include <TColStd_DataMapOfIntegerInteger.hxx>
42cf5bc1 23#include <TColStd_DataMapOfIntegerReal.hxx>
24#include <XSDRAWSTLVRML_DataSource.hxx>
7fd59977 25
26//================================================================
27// Function : Constructor
28// Purpose :
29//================================================================
30XSDRAWSTLVRML_DataSource::XSDRAWSTLVRML_DataSource( const Handle( StlMesh_Mesh )& aMesh )
31{
32 myMesh = aMesh;
33
34 if( !myMesh.IsNull() )
35 {
36 const TColgp_SequenceOfXYZ& aCoords = myMesh->Vertices();
37 Standard_Integer len = aCoords.Length(), i, j;
38 myNodeCoords = new TColStd_HArray2OfReal(1, len, 1, 3);
39 cout << "Nodes : " << len << endl;
40
41 gp_XYZ xyz;
42
43 for( i = 1; i <= len; i++ )
44 {
45 myNodes.Add( i );
46 xyz = aCoords(i);
47
48 myNodeCoords->SetValue(i, 1, xyz.X());
49 myNodeCoords->SetValue(i, 2, xyz.Y());
50 myNodeCoords->SetValue(i, 3, xyz.Z());
51 }
52
53 const StlMesh_SequenceOfMeshTriangle& aSeq = myMesh->Triangles();
54 len = aSeq.Length();
55 myElemNormals = new TColStd_HArray2OfReal(1, len, 1, 3);
56 myElemNodes = new TColStd_HArray2OfInteger(1, len, 1, 3);
57
58 cout << "Elements : " << len << endl;
59
60 for( i = 1; i <= len; i++ )
61 {
62 myElements.Add( i );
63 Handle( StlMesh_MeshTriangle ) aTriangle = aSeq.Value( i );
64 Standard_Integer V[3]; Standard_Real nx, ny, nz;
65
66 aTriangle->GetVertexAndOrientation( V[0], V[1], V[2], nx, ny, nz );
67
68 for( j = 0; j < 3; j++ )
69 {
70 myElemNodes->SetValue(i, j+1, V[j]);
71 }
72
73 myElemNormals->SetValue(i, 1, nx);
74 myElemNormals->SetValue(i, 2, ny);
75 myElemNormals->SetValue(i, 3, nz);
76 }
77 }
78 cout << "Construction is finished" << endl;
79}
80
81//================================================================
82// Function : GetGeom
83// Purpose :
84//================================================================
85Standard_Boolean XSDRAWSTLVRML_DataSource::GetGeom
86( const Standard_Integer ID, const Standard_Boolean IsElement,
87 TColStd_Array1OfReal& Coords, Standard_Integer& NbNodes,
88 MeshVS_EntityType& Type ) const
89{
90 if( myMesh.IsNull() )
91 return Standard_False;
92
93 if( IsElement )
94 {
95 if( ID>=1 && ID<=myElements.Extent() )
96 {
97 Type = MeshVS_ET_Face;
98 NbNodes = 3;
99
100 for( Standard_Integer i = 1, k = 1; i <= 3; i++ )
101 {
102 Standard_Integer IdxNode = myElemNodes->Value(ID, i);
103 for(Standard_Integer j = 1; j <= 3; j++, k++ )
104 Coords(k) = myNodeCoords->Value(IdxNode, j);
105 }
106
107 return Standard_True;
108 }
109 else
110 return Standard_False;
111 }
112 else
113 if( ID>=1 && ID<=myNodes.Extent() )
114 {
115 Type = MeshVS_ET_Node;
116 NbNodes = 1;
117
118 Coords( 1 ) = myNodeCoords->Value(ID, 1);
119 Coords( 2 ) = myNodeCoords->Value(ID, 2);
120 Coords( 3 ) = myNodeCoords->Value(ID, 3);
121 return Standard_True;
122 }
123 else
124 return Standard_False;
125}
126
127//================================================================
128// Function : GetGeomType
129// Purpose :
130//================================================================
131Standard_Boolean XSDRAWSTLVRML_DataSource::GetGeomType
132( const Standard_Integer,
133 const Standard_Boolean IsElement,
134 MeshVS_EntityType& Type ) const
135{
136 if( IsElement )
137 {
138 Type = MeshVS_ET_Face;
139 return Standard_True;
140 }
141 else
142 {
143 Type = MeshVS_ET_Node;
144 return Standard_True;
145 }
146}
147
148//================================================================
149// Function : GetAddr
150// Purpose :
151//================================================================
152Standard_Address XSDRAWSTLVRML_DataSource::GetAddr
153( const Standard_Integer, const Standard_Boolean ) const
154{
155 return NULL;
156}
157
158//================================================================
159// Function : GetNodesByElement
160// Purpose :
161//================================================================
162Standard_Boolean XSDRAWSTLVRML_DataSource::GetNodesByElement
163( const Standard_Integer ID,
164 TColStd_Array1OfInteger& theNodeIDs,
35e08fe8 165 Standard_Integer& /*theNbNodes*/ ) const
7fd59977 166{
167 if( myMesh.IsNull() )
168 return Standard_False;
169
170 if( ID>=1 && ID<=myElements.Extent() && theNodeIDs.Length() >= 3 )
171 {
172 Standard_Integer aLow = theNodeIDs.Lower();
173 theNodeIDs (aLow) = myElemNodes->Value(ID, 1 );
174 theNodeIDs (aLow + 1) = myElemNodes->Value(ID, 2 );
175 theNodeIDs (aLow + 2) = myElemNodes->Value(ID, 3 );
176 return Standard_True;
177 }
178 return Standard_False;
179}
180
181//================================================================
182// Function : GetAllNodes
183// Purpose :
184//================================================================
185const TColStd_PackedMapOfInteger& XSDRAWSTLVRML_DataSource::GetAllNodes() const
186{
187 return myNodes;
188}
189
190//================================================================
191// Function : GetAllElements
192// Purpose :
193//================================================================
194const TColStd_PackedMapOfInteger& XSDRAWSTLVRML_DataSource::GetAllElements() const
195{
196 return myElements;
197}
198
199//================================================================
200// Function : GetNormal
201// Purpose :
202//================================================================
203Standard_Boolean XSDRAWSTLVRML_DataSource::GetNormal
204( const Standard_Integer Id, const Standard_Integer Max,
205 Standard_Real& nx, Standard_Real& ny,Standard_Real& nz ) const
206{
207 if( myMesh.IsNull() )
208 return Standard_False;
209
210 if( Id>=1 && Id<=myElements.Extent() && Max>=3 )
211 {
212 nx = myElemNormals->Value(Id, 1);
213 ny = myElemNormals->Value(Id, 2);
214 nz = myElemNormals->Value(Id, 3);
215 return Standard_True;
216 }
217 else
218 return Standard_False;
219}
220