7fd59977 |
1 | // File: XSDRAWSTLVRML_DataSource.cxx |
2 | // Created: Thu June 10 2004 |
3 | // Author: Alexander SOLOVYOV |
4 | // Copyright: Open CASCADE 2004 |
5 | |
6 | #include <XSDRAWSTLVRML_DataSource.ixx> |
7 | |
8 | #include <StlMesh_SequenceOfMeshTriangle.hxx> |
9 | #include <StlMesh_MeshTriangle.hxx> |
10 | #include <TColgp_SequenceOfXYZ.hxx> |
11 | #include <TColStd_DataMapOfIntegerReal.hxx> |
12 | #include <TColStd_DataMapOfIntegerInteger.hxx> |
13 | |
14 | //================================================================ |
15 | // Function : Constructor |
16 | // Purpose : |
17 | //================================================================ |
18 | XSDRAWSTLVRML_DataSource::XSDRAWSTLVRML_DataSource( const Handle( StlMesh_Mesh )& aMesh ) |
19 | { |
20 | myMesh = aMesh; |
21 | |
22 | if( !myMesh.IsNull() ) |
23 | { |
24 | const TColgp_SequenceOfXYZ& aCoords = myMesh->Vertices(); |
25 | Standard_Integer len = aCoords.Length(), i, j; |
26 | myNodeCoords = new TColStd_HArray2OfReal(1, len, 1, 3); |
27 | cout << "Nodes : " << len << endl; |
28 | |
29 | gp_XYZ xyz; |
30 | |
31 | for( i = 1; i <= len; i++ ) |
32 | { |
33 | myNodes.Add( i ); |
34 | xyz = aCoords(i); |
35 | |
36 | myNodeCoords->SetValue(i, 1, xyz.X()); |
37 | myNodeCoords->SetValue(i, 2, xyz.Y()); |
38 | myNodeCoords->SetValue(i, 3, xyz.Z()); |
39 | } |
40 | |
41 | const StlMesh_SequenceOfMeshTriangle& aSeq = myMesh->Triangles(); |
42 | len = aSeq.Length(); |
43 | myElemNormals = new TColStd_HArray2OfReal(1, len, 1, 3); |
44 | myElemNodes = new TColStd_HArray2OfInteger(1, len, 1, 3); |
45 | |
46 | cout << "Elements : " << len << endl; |
47 | |
48 | for( i = 1; i <= len; i++ ) |
49 | { |
50 | myElements.Add( i ); |
51 | Handle( StlMesh_MeshTriangle ) aTriangle = aSeq.Value( i ); |
52 | Standard_Integer V[3]; Standard_Real nx, ny, nz; |
53 | |
54 | aTriangle->GetVertexAndOrientation( V[0], V[1], V[2], nx, ny, nz ); |
55 | |
56 | for( j = 0; j < 3; j++ ) |
57 | { |
58 | myElemNodes->SetValue(i, j+1, V[j]); |
59 | } |
60 | |
61 | myElemNormals->SetValue(i, 1, nx); |
62 | myElemNormals->SetValue(i, 2, ny); |
63 | myElemNormals->SetValue(i, 3, nz); |
64 | } |
65 | } |
66 | cout << "Construction is finished" << endl; |
67 | } |
68 | |
69 | //================================================================ |
70 | // Function : GetGeom |
71 | // Purpose : |
72 | //================================================================ |
73 | Standard_Boolean XSDRAWSTLVRML_DataSource::GetGeom |
74 | ( const Standard_Integer ID, const Standard_Boolean IsElement, |
75 | TColStd_Array1OfReal& Coords, Standard_Integer& NbNodes, |
76 | MeshVS_EntityType& Type ) const |
77 | { |
78 | if( myMesh.IsNull() ) |
79 | return Standard_False; |
80 | |
81 | if( IsElement ) |
82 | { |
83 | if( ID>=1 && ID<=myElements.Extent() ) |
84 | { |
85 | Type = MeshVS_ET_Face; |
86 | NbNodes = 3; |
87 | |
88 | for( Standard_Integer i = 1, k = 1; i <= 3; i++ ) |
89 | { |
90 | Standard_Integer IdxNode = myElemNodes->Value(ID, i); |
91 | for(Standard_Integer j = 1; j <= 3; j++, k++ ) |
92 | Coords(k) = myNodeCoords->Value(IdxNode, j); |
93 | } |
94 | |
95 | return Standard_True; |
96 | } |
97 | else |
98 | return Standard_False; |
99 | } |
100 | else |
101 | if( ID>=1 && ID<=myNodes.Extent() ) |
102 | { |
103 | Type = MeshVS_ET_Node; |
104 | NbNodes = 1; |
105 | |
106 | Coords( 1 ) = myNodeCoords->Value(ID, 1); |
107 | Coords( 2 ) = myNodeCoords->Value(ID, 2); |
108 | Coords( 3 ) = myNodeCoords->Value(ID, 3); |
109 | return Standard_True; |
110 | } |
111 | else |
112 | return Standard_False; |
113 | } |
114 | |
115 | //================================================================ |
116 | // Function : GetGeomType |
117 | // Purpose : |
118 | //================================================================ |
119 | Standard_Boolean XSDRAWSTLVRML_DataSource::GetGeomType |
120 | ( const Standard_Integer, |
121 | const Standard_Boolean IsElement, |
122 | MeshVS_EntityType& Type ) const |
123 | { |
124 | if( IsElement ) |
125 | { |
126 | Type = MeshVS_ET_Face; |
127 | return Standard_True; |
128 | } |
129 | else |
130 | { |
131 | Type = MeshVS_ET_Node; |
132 | return Standard_True; |
133 | } |
134 | } |
135 | |
136 | //================================================================ |
137 | // Function : GetAddr |
138 | // Purpose : |
139 | //================================================================ |
140 | Standard_Address XSDRAWSTLVRML_DataSource::GetAddr |
141 | ( const Standard_Integer, const Standard_Boolean ) const |
142 | { |
143 | return NULL; |
144 | } |
145 | |
146 | //================================================================ |
147 | // Function : GetNodesByElement |
148 | // Purpose : |
149 | //================================================================ |
150 | Standard_Boolean XSDRAWSTLVRML_DataSource::GetNodesByElement |
151 | ( const Standard_Integer ID, |
152 | TColStd_Array1OfInteger& theNodeIDs, |
153 | Standard_Integer& theNbNodes ) const |
154 | { |
155 | if( myMesh.IsNull() ) |
156 | return Standard_False; |
157 | |
158 | if( ID>=1 && ID<=myElements.Extent() && theNodeIDs.Length() >= 3 ) |
159 | { |
160 | Standard_Integer aLow = theNodeIDs.Lower(); |
161 | theNodeIDs (aLow) = myElemNodes->Value(ID, 1 ); |
162 | theNodeIDs (aLow + 1) = myElemNodes->Value(ID, 2 ); |
163 | theNodeIDs (aLow + 2) = myElemNodes->Value(ID, 3 ); |
164 | return Standard_True; |
165 | } |
166 | return Standard_False; |
167 | } |
168 | |
169 | //================================================================ |
170 | // Function : GetAllNodes |
171 | // Purpose : |
172 | //================================================================ |
173 | const TColStd_PackedMapOfInteger& XSDRAWSTLVRML_DataSource::GetAllNodes() const |
174 | { |
175 | return myNodes; |
176 | } |
177 | |
178 | //================================================================ |
179 | // Function : GetAllElements |
180 | // Purpose : |
181 | //================================================================ |
182 | const TColStd_PackedMapOfInteger& XSDRAWSTLVRML_DataSource::GetAllElements() const |
183 | { |
184 | return myElements; |
185 | } |
186 | |
187 | //================================================================ |
188 | // Function : GetNormal |
189 | // Purpose : |
190 | //================================================================ |
191 | Standard_Boolean XSDRAWSTLVRML_DataSource::GetNormal |
192 | ( const Standard_Integer Id, const Standard_Integer Max, |
193 | Standard_Real& nx, Standard_Real& ny,Standard_Real& nz ) const |
194 | { |
195 | if( myMesh.IsNull() ) |
196 | return Standard_False; |
197 | |
198 | if( Id>=1 && Id<=myElements.Extent() && Max>=3 ) |
199 | { |
200 | nx = myElemNormals->Value(Id, 1); |
201 | ny = myElemNormals->Value(Id, 2); |
202 | nz = myElemNormals->Value(Id, 3); |
203 | return Standard_True; |
204 | } |
205 | else |
206 | return Standard_False; |
207 | } |
208 | |