1 // Created on: 2014-08-04
2 // Created by: Artem NOVIKOV
3 // Copyright (c) 2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <XSDRAWSTLVRML_DataSource3D.ixx>
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>
24 //================================================================
25 // Function : Constructor
27 //================================================================
28 XSDRAWSTLVRML_DataSource3D::XSDRAWSTLVRML_DataSource3D()
30 for (Standard_Integer aNodeID = 1; aNodeID <= 16; aNodeID++)
32 myNodes.Add( aNodeID );
35 for (Standard_Integer anElemID = 1; anElemID <= 5; anElemID++)
37 myElements.Add( anElemID );
40 myNodeCoords = new TColStd_HArray2OfReal(1, 16, 1, 3);
42 myNodeCoords->SetValue( 1, 1, 5 );
43 myNodeCoords->SetValue( 1, 2, 5 );
44 myNodeCoords->SetValue( 1, 3, 20 );
46 myNodeCoords->SetValue( 2, 1, 0 );
47 myNodeCoords->SetValue( 2, 2, 10 );
48 myNodeCoords->SetValue( 2, 3, 10 );
50 myNodeCoords->SetValue( 3, 1, 10 );
51 myNodeCoords->SetValue( 3, 2, 0 );
52 myNodeCoords->SetValue( 3, 3, 10 );
54 myNodeCoords->SetValue( 4, 1, 0 );
55 myNodeCoords->SetValue( 4, 2, 0 );
56 myNodeCoords->SetValue( 4, 3, 10 );
58 myNodeCoords->SetValue( 5, 1, -10 );
59 myNodeCoords->SetValue( 5, 2, 0 );
60 myNodeCoords->SetValue( 5, 3, 10 );
62 myNodeCoords->SetValue( 6, 1, -10 );
63 myNodeCoords->SetValue( 6, 2, 10 );
64 myNodeCoords->SetValue( 6, 3, 10 );
66 myNodeCoords->SetValue( 7, 1, -10 );
67 myNodeCoords->SetValue( 7, 2, 10 );
68 myNodeCoords->SetValue( 7, 3, 0 );
70 myNodeCoords->SetValue( 8, 1, -10 );
71 myNodeCoords->SetValue( 8, 2, 0 );
72 myNodeCoords->SetValue( 8, 3, 0 );
74 myNodeCoords->SetValue( 9, 1, 0 );
75 myNodeCoords->SetValue( 9, 2, 0 );
76 myNodeCoords->SetValue( 9, 3, 0 );
78 myNodeCoords->SetValue( 10, 1, 0 );
79 myNodeCoords->SetValue( 10, 2, 10 );
80 myNodeCoords->SetValue( 10, 3, 0 );
82 myNodeCoords->SetValue( 11, 1, 0 );
83 myNodeCoords->SetValue( 11, 2, -10 );
84 myNodeCoords->SetValue( 11, 3, 10 );
86 myNodeCoords->SetValue( 12, 1, 10 );
87 myNodeCoords->SetValue( 12, 2, -10 );
88 myNodeCoords->SetValue( 12, 3, 10 );
90 myNodeCoords->SetValue( 13, 1, 10 );
91 myNodeCoords->SetValue( 13, 2, -10 );
92 myNodeCoords->SetValue( 13, 3, 0 );
94 myNodeCoords->SetValue( 14, 1, 0 );
95 myNodeCoords->SetValue( 14, 2, -10 );
96 myNodeCoords->SetValue( 14, 3, 0 );
98 myNodeCoords->SetValue( 15, 1, 10 );
99 myNodeCoords->SetValue( 15, 2, 0 );
100 myNodeCoords->SetValue( 15, 3, 0 );
102 myNodeCoords->SetValue( 16, 1, 5 );
103 myNodeCoords->SetValue( 16, 2, 5 );
104 myNodeCoords->SetValue( 16, 3, -10 );
106 myElemNbNodes = new TColStd_HArray1OfInteger(1, 5);
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 );
114 myElemNodes = new TColStd_HArray2OfInteger(1, 5, 1, 8);
116 myElemNodes->SetValue(1, 1, 1);
117 myElemNodes->SetValue(1, 2, 2);
118 myElemNodes->SetValue(1, 3, 3);
119 myElemNodes->SetValue(1, 4, 4);
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);
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);
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);
146 myElemNodes->SetValue(5, 1, 16);
147 myElemNodes->SetValue(5, 2, 15);
148 myElemNodes->SetValue(5, 3, 10);
149 myElemNodes->SetValue(5, 4, 9);
152 //================================================================
153 // Function : GetGeom
155 //================================================================
156 Standard_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
163 if (theID >= 1 && theID <= myElements.Extent())
165 theType = MeshVS_ET_Volume;
166 theNbNodes = myElemNbNodes->Value(theID);
168 for (Standard_Integer aNodeI = 1, aGlobCoordI = 1; aNodeI <= theNbNodes; aNodeI++)
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);
175 return Standard_True;
178 return Standard_False;
181 if (theID >= 1 && theID <= myNodes.Extent())
183 theType = MeshVS_ET_Node;
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;
192 return Standard_False;
195 //================================================================
196 // Function : Get3DGeom
198 //================================================================
199 Standard_Boolean XSDRAWSTLVRML_DataSource3D::Get3DGeom
200 ( const Standard_Integer theID, Standard_Integer& theNbNodes,
201 Handle(MeshVS_HArray1OfSequenceOfInteger)& theData ) const
203 Handle(MeshVS_HArray1OfSequenceOfInteger) aMeshData;
204 if (theID == 1 || theID == 5)
206 aMeshData = new MeshVS_HArray1OfSequenceOfInteger(1,4);
208 for (Standard_Integer anElemI = 1; anElemI <= 4; anElemI++)
210 aMeshData->ChangeValue(anElemI).Append( (anElemI - 1) % 4 );
211 aMeshData->ChangeValue(anElemI).Append( anElemI % 4 );
212 aMeshData->ChangeValue(anElemI).Append( (anElemI + 1) % 4 );
215 return Standard_True;
218 if (theID == 2 || theID == 4)
220 aMeshData = new MeshVS_HArray1OfSequenceOfInteger(1,6);
222 for (Standard_Integer anElemI = 1, k = 1; anElemI <= 4; anElemI++)
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 );
231 aMeshData->ChangeValue(5).Append( 0 );
232 aMeshData->ChangeValue(5).Append( 3 );
233 aMeshData->ChangeValue(5).Append( 4 );
234 aMeshData->ChangeValue(5).Append( 7 );
236 aMeshData->ChangeValue(6).Append( 1 );
237 aMeshData->ChangeValue(6).Append( 2 );
238 aMeshData->ChangeValue(6).Append( 5 );
239 aMeshData->ChangeValue(6).Append( 6 );
242 return Standard_True;
247 aMeshData = new MeshVS_HArray1OfSequenceOfInteger(1,5);
249 for (Standard_Integer anElemI = 1; anElemI <= 2; anElemI++)
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 );
255 for (Standard_Integer anElemI = 1; anElemI <= 3; anElemI++)
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 );
263 return Standard_True;
266 return Standard_False;
269 //================================================================
270 // Function : GetGeomType
272 //================================================================
273 Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetGeomType
274 ( const Standard_Integer theID,
275 const Standard_Boolean theIsElement,
276 MeshVS_EntityType& theType ) const
280 if (theID >= 1 && theID <= myElements.Extent())
282 theType = MeshVS_ET_Volume;
283 return Standard_True;
287 if (theID >= 1 && theID <= myNodes.Extent())
289 theType = MeshVS_ET_Node;
290 return Standard_True;
293 return Standard_False;
296 //================================================================
297 // Function : GetAddr
299 //================================================================
300 Standard_Address XSDRAWSTLVRML_DataSource3D::GetAddr
301 ( const Standard_Integer, const Standard_Boolean ) const
306 //================================================================
307 // Function : GetNodesByElement
309 //================================================================
310 Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetNodesByElement
311 ( const Standard_Integer theID,
312 TColStd_Array1OfInteger& theNodeIDs,
313 Standard_Integer& theNbNodes ) const
315 Standard_Integer aLow;
316 if (theID == 1 || theID == 5)
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;
327 if (theID == 2 || theID == 4)
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;
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;
355 return Standard_False;
358 //================================================================
359 // Function : GetAllNodes
361 //================================================================
362 const TColStd_PackedMapOfInteger& XSDRAWSTLVRML_DataSource3D::GetAllNodes() const
367 //================================================================
368 // Function : GetAllElements
370 //================================================================
371 const TColStd_PackedMapOfInteger& XSDRAWSTLVRML_DataSource3D::GetAllElements() const
376 //================================================================
377 // Function : GetNormal
379 //================================================================
380 Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetNormal
381 ( const Standard_Integer /*theID*/, const Standard_Integer /*theMax*/,
382 Standard_Real& /*theNx*/, Standard_Real& /*theNy*/,Standard_Real& /*theNz*/ ) const
384 return Standard_False;