0024961: MeshVS: revision of DRAW commands
[occt.git] / src / XSDRAWSTLVRML / XSDRAWSTLVRML_DataSource3D.cxx
CommitLineData
709e97a0 1// Created on: 2014-08-04
2// Created by: Artem NOVIKOV
3// Copyright (c) 2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
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
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.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#include <XSDRAWSTLVRML_DataSource3D.ixx>
17
18#include <StlMesh_SequenceOfMeshTriangle.hxx>
19#include <StlMesh_MeshTriangle.hxx>
20#include <TColgp_SequenceOfXYZ.hxx>
21#include <TColStd_DataMapOfIntegerReal.hxx>
22#include <TColStd_DataMapOfIntegerInteger.hxx>
23
24//================================================================
25// Function : Constructor
26// Purpose :
27//================================================================
28XSDRAWSTLVRML_DataSource3D::XSDRAWSTLVRML_DataSource3D()
29{
30 for (Standard_Integer aNodeID = 1; aNodeID <= 16; aNodeID++)
31 {
32 myNodes.Add( aNodeID );
33 }
34
35 for (Standard_Integer anElemID = 1; anElemID <= 5; anElemID++)
36 {
37 myElements.Add( anElemID );
38 }
39
40 myNodeCoords = new TColStd_HArray2OfReal(1, 16, 1, 3);
41
42 myNodeCoords->SetValue( 1, 1, 5 );
43 myNodeCoords->SetValue( 1, 2, 5 );
44 myNodeCoords->SetValue( 1, 3, 20 );
45
46 myNodeCoords->SetValue( 2, 1, 0 );
47 myNodeCoords->SetValue( 2, 2, 10 );
48 myNodeCoords->SetValue( 2, 3, 10 );
49
50 myNodeCoords->SetValue( 3, 1, 10 );
51 myNodeCoords->SetValue( 3, 2, 0 );
52 myNodeCoords->SetValue( 3, 3, 10 );
53
54 myNodeCoords->SetValue( 4, 1, 0 );
55 myNodeCoords->SetValue( 4, 2, 0 );
56 myNodeCoords->SetValue( 4, 3, 10 );
57
58 myNodeCoords->SetValue( 5, 1, -10 );
59 myNodeCoords->SetValue( 5, 2, 0 );
60 myNodeCoords->SetValue( 5, 3, 10 );
61
62 myNodeCoords->SetValue( 6, 1, -10 );
63 myNodeCoords->SetValue( 6, 2, 10 );
64 myNodeCoords->SetValue( 6, 3, 10 );
65
66 myNodeCoords->SetValue( 7, 1, -10 );
67 myNodeCoords->SetValue( 7, 2, 10 );
68 myNodeCoords->SetValue( 7, 3, 0 );
69
70 myNodeCoords->SetValue( 8, 1, -10 );
71 myNodeCoords->SetValue( 8, 2, 0 );
72 myNodeCoords->SetValue( 8, 3, 0 );
73
74 myNodeCoords->SetValue( 9, 1, 0 );
75 myNodeCoords->SetValue( 9, 2, 0 );
76 myNodeCoords->SetValue( 9, 3, 0 );
77
78 myNodeCoords->SetValue( 10, 1, 0 );
79 myNodeCoords->SetValue( 10, 2, 10 );
80 myNodeCoords->SetValue( 10, 3, 0 );
81
82 myNodeCoords->SetValue( 11, 1, 0 );
83 myNodeCoords->SetValue( 11, 2, -10 );
84 myNodeCoords->SetValue( 11, 3, 10 );
85
86 myNodeCoords->SetValue( 12, 1, 10 );
87 myNodeCoords->SetValue( 12, 2, -10 );
88 myNodeCoords->SetValue( 12, 3, 10 );
89
90 myNodeCoords->SetValue( 13, 1, 10 );
91 myNodeCoords->SetValue( 13, 2, -10 );
92 myNodeCoords->SetValue( 13, 3, 0 );
93
94 myNodeCoords->SetValue( 14, 1, 0 );
95 myNodeCoords->SetValue( 14, 2, -10 );
96 myNodeCoords->SetValue( 14, 3, 0 );
97
98 myNodeCoords->SetValue( 15, 1, 10 );
99 myNodeCoords->SetValue( 15, 2, 0 );
100 myNodeCoords->SetValue( 15, 3, 0 );
101
102 myNodeCoords->SetValue( 16, 1, 5 );
103 myNodeCoords->SetValue( 16, 2, 5 );
104 myNodeCoords->SetValue( 16, 3, -10 );
105
106 myElemNbNodes = new TColStd_HArray1OfInteger(1, 5);
107
108 myElemNbNodes->SetValue( 1, 4 );
109 myElemNbNodes->SetValue( 2, 8 );
110 myElemNbNodes->SetValue( 3, 6 );
111 myElemNbNodes->SetValue( 4, 8 );
112 myElemNbNodes->SetValue( 5, 4 );
113
114 myElemNodes = new TColStd_HArray2OfInteger(1, 5, 1, 8);
115
116 myElemNodes->SetValue(1, 1, 1);
117 myElemNodes->SetValue(1, 2, 2);
118 myElemNodes->SetValue(1, 3, 3);
119 myElemNodes->SetValue(1, 4, 4);
120
121 myElemNodes->SetValue(2, 1, 2);
122 myElemNodes->SetValue(2, 2, 4);
123 myElemNodes->SetValue(2, 3, 5);
124 myElemNodes->SetValue(2, 4, 6);
125 myElemNodes->SetValue(2, 5, 7);
126 myElemNodes->SetValue(2, 6, 8);
127 myElemNodes->SetValue(2, 7, 9);
128 myElemNodes->SetValue(2, 8, 10);
129
130 myElemNodes->SetValue(3, 1, 2);
131 myElemNodes->SetValue(3, 2, 3);
132 myElemNodes->SetValue(3, 3, 4);
133 myElemNodes->SetValue(3, 4, 10);
134 myElemNodes->SetValue(3, 5, 15);
135 myElemNodes->SetValue(3, 6, 9);
136
137 myElemNodes->SetValue(4, 1, 4);
138 myElemNodes->SetValue(4, 2, 3);
139 myElemNodes->SetValue(4, 3, 12);
140 myElemNodes->SetValue(4, 4, 11);
141 myElemNodes->SetValue(4, 5, 14);
142 myElemNodes->SetValue(4, 6, 13);
143 myElemNodes->SetValue(4, 7, 15);
144 myElemNodes->SetValue(4, 8, 9);
145
146 myElemNodes->SetValue(5, 1, 16);
147 myElemNodes->SetValue(5, 2, 15);
148 myElemNodes->SetValue(5, 3, 10);
149 myElemNodes->SetValue(5, 4, 9);
150}
151
152//================================================================
153// Function : GetGeom
154// Purpose :
155//================================================================
156Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetGeom
157( const Standard_Integer theID, const Standard_Boolean theIsElement,
158 TColStd_Array1OfReal& theCoords, Standard_Integer& theNbNodes,
159 MeshVS_EntityType& theType ) const
160{
161 if (theIsElement)
162 {
163 if (theID >= 1 && theID <= myElements.Extent())
164 {
165 theType = MeshVS_ET_Volume;
166 theNbNodes = myElemNbNodes->Value(theID);
167
168 for (Standard_Integer aNodeI = 1, aGlobCoordI = 1; aNodeI <= theNbNodes; aNodeI++)
169 {
170 Standard_Integer anIdxNode = myElemNodes->Value(theID, aNodeI);
171 for(Standard_Integer aCoordI = 1; aCoordI <= 3; aCoordI++, aGlobCoordI++ )
172 theCoords(aGlobCoordI) = myNodeCoords->Value(anIdxNode, aCoordI);
173 }
174
175 return Standard_True;
176 }
177 else
178 return Standard_False;
179 }
180 else
181 if (theID >= 1 && theID <= myNodes.Extent())
182 {
183 theType = MeshVS_ET_Node;
184 theNbNodes = 1;
185
186 theCoords( 1 ) = myNodeCoords->Value(theID, 1);
187 theCoords( 2 ) = myNodeCoords->Value(theID, 2);
188 theCoords( 3 ) = myNodeCoords->Value(theID, 3);
189 return Standard_True;
190 }
191 else
192 return Standard_False;
193}
194
195//================================================================
196// Function : Get3DGeom
197// Purpose :
198//================================================================
199Standard_Boolean XSDRAWSTLVRML_DataSource3D::Get3DGeom
200( const Standard_Integer theID, Standard_Integer& theNbNodes,
201 Handle(MeshVS_HArray1OfSequenceOfInteger)& theData ) const
202{
203 Handle(MeshVS_HArray1OfSequenceOfInteger) aMeshData;
204 if (theID == 1 || theID == 5)
205 {
206 aMeshData = new MeshVS_HArray1OfSequenceOfInteger(1,4);
207 theNbNodes = 4;
208 for (Standard_Integer anElemI = 1; anElemI <= 4; anElemI++)
209 {
210 aMeshData->ChangeValue(anElemI).Append( (anElemI - 1) % 4 );
211 aMeshData->ChangeValue(anElemI).Append( anElemI % 4 );
212 aMeshData->ChangeValue(anElemI).Append( (anElemI + 1) % 4 );
213 }
214 theData = aMeshData;
215 return Standard_True;
216 }
217
218 if (theID == 2 || theID == 4)
219 {
220 aMeshData = new MeshVS_HArray1OfSequenceOfInteger(1,6);
221 theNbNodes = 8;
222 for (Standard_Integer anElemI = 1, k = 1; anElemI <= 4; anElemI++)
223 {
224 aMeshData->ChangeValue(anElemI).Append( (k - 1) % 8 );
225 aMeshData->ChangeValue(anElemI).Append( k % 8 );
226 aMeshData->ChangeValue(anElemI).Append( (k + 1) % 8 );
227 aMeshData->ChangeValue(anElemI).Append( (k + 2) % 8 );
228 k+=2;
229 }
230
231 aMeshData->ChangeValue(5).Append( 0 );
232 aMeshData->ChangeValue(5).Append( 3 );
233 aMeshData->ChangeValue(5).Append( 4 );
234 aMeshData->ChangeValue(5).Append( 7 );
235
236 aMeshData->ChangeValue(6).Append( 1 );
237 aMeshData->ChangeValue(6).Append( 2 );
238 aMeshData->ChangeValue(6).Append( 5 );
239 aMeshData->ChangeValue(6).Append( 6 );
240
241 theData = aMeshData;
242 return Standard_True;
243 }
244
245 if (theID == 3)
246 {
247 aMeshData = new MeshVS_HArray1OfSequenceOfInteger(1,5);
248 theNbNodes = 6;
249 for (Standard_Integer anElemI = 1; anElemI <= 2; anElemI++)
250 {
251 aMeshData->ChangeValue(anElemI).Append( (anElemI - 1) * 3 );
252 aMeshData->ChangeValue(anElemI).Append( (anElemI - 1) * 3 + 1 );
253 aMeshData->ChangeValue(anElemI).Append( (anElemI - 1) * 3 + 2 );
254 }
255 for (Standard_Integer anElemI = 1; anElemI <= 3; anElemI++)
256 {
257 aMeshData->ChangeValue(2 + anElemI).Append( (anElemI - 1) % 3 );
258 aMeshData->ChangeValue(2 + anElemI).Append( anElemI % 3 );
259 aMeshData->ChangeValue(2 + anElemI).Append( anElemI % 3 + 3 );
260 aMeshData->ChangeValue(2 + anElemI).Append( (anElemI - 1) % 3 + 3 );
261 }
262 theData = aMeshData;
263 return Standard_True;
264 }
265
266 return Standard_False;
267}
268
269//================================================================
270// Function : GetGeomType
271// Purpose :
272//================================================================
273Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetGeomType
274( const Standard_Integer theID,
275 const Standard_Boolean theIsElement,
276 MeshVS_EntityType& theType ) const
277{
278 if (theIsElement)
279 {
280 if (theID >= 1 && theID <= myElements.Extent())
281 {
282 theType = MeshVS_ET_Volume;
283 return Standard_True;
284 }
285 }
286 else
287 if (theID >= 1 && theID <= myNodes.Extent())
288 {
289 theType = MeshVS_ET_Node;
290 return Standard_True;
291 }
292
293 return Standard_False;
294}
295
296//================================================================
297// Function : GetAddr
298// Purpose :
299//================================================================
300Standard_Address XSDRAWSTLVRML_DataSource3D::GetAddr
301( const Standard_Integer, const Standard_Boolean ) const
302{
303 return NULL;
304}
305
306//================================================================
307// Function : GetNodesByElement
308// Purpose :
309//================================================================
310Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetNodesByElement
311( const Standard_Integer theID,
312 TColStd_Array1OfInteger& theNodeIDs,
313 Standard_Integer& theNbNodes ) const
314{
315 Standard_Integer aLow;
316 if (theID == 1 || theID == 5)
317 {
318 theNbNodes = 4;
319 aLow = theNodeIDs.Lower();
320 theNodeIDs (aLow) = myElemNodes->Value(theID, 1 );
321 theNodeIDs (aLow + 1) = myElemNodes->Value(theID, 2 );
322 theNodeIDs (aLow + 2) = myElemNodes->Value(theID, 3 );
323 theNodeIDs (aLow + 3) = myElemNodes->Value(theID, 4 );
324 return Standard_True;
325 }
326
327 if (theID == 2 || theID == 4)
328 {
329 theNbNodes = 8;
330 aLow = theNodeIDs.Lower();
331 theNodeIDs (aLow) = myElemNodes->Value(theID, 1 );
332 theNodeIDs (aLow + 1) = myElemNodes->Value(theID, 2 );
333 theNodeIDs (aLow + 2) = myElemNodes->Value(theID, 3 );
334 theNodeIDs (aLow + 3) = myElemNodes->Value(theID, 4 );
335 theNodeIDs (aLow + 4) = myElemNodes->Value(theID, 5 );
336 theNodeIDs (aLow + 5) = myElemNodes->Value(theID, 6 );
337 theNodeIDs (aLow + 6) = myElemNodes->Value(theID, 7 );
338 theNodeIDs (aLow + 7) = myElemNodes->Value(theID, 8 );
339 return Standard_True;
340 }
341
342 if (theID == 3)
343 {
344 theNbNodes = 6;
345 aLow = theNodeIDs.Lower();
346 theNodeIDs (aLow) = myElemNodes->Value(theID, 1 );
347 theNodeIDs (aLow + 1) = myElemNodes->Value(theID, 2 );
348 theNodeIDs (aLow + 2) = myElemNodes->Value(theID, 3 );
349 theNodeIDs (aLow + 3) = myElemNodes->Value(theID, 4 );
350 theNodeIDs (aLow + 4) = myElemNodes->Value(theID, 5 );
351 theNodeIDs (aLow + 5) = myElemNodes->Value(theID, 6 );
352 return Standard_True;
353 }
354
355 return Standard_False;
356}
357
358//================================================================
359// Function : GetAllNodes
360// Purpose :
361//================================================================
362const TColStd_PackedMapOfInteger& XSDRAWSTLVRML_DataSource3D::GetAllNodes() const
363{
364 return myNodes;
365}
366
367//================================================================
368// Function : GetAllElements
369// Purpose :
370//================================================================
371const TColStd_PackedMapOfInteger& XSDRAWSTLVRML_DataSource3D::GetAllElements() const
372{
373 return myElements;
374}
375
376//================================================================
377// Function : GetNormal
378// Purpose :
379//================================================================
380Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetNormal
381( const Standard_Integer /*theID*/, const Standard_Integer /*theMax*/,
382 Standard_Real& /*theNx*/, Standard_Real& /*theNy*/,Standard_Real& /*theNz*/ ) const
383{
384 return Standard_False;
385}