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.
17 #include <Standard_Type.hxx>
18 #include <TColgp_SequenceOfXYZ.hxx>
19 #include <TColStd_DataMapOfIntegerInteger.hxx>
20 #include <TColStd_DataMapOfIntegerReal.hxx>
21 #include <XSDRAWSTLVRML_DataSource3D.hxx>
23 IMPLEMENT_STANDARD_RTTIEXT(XSDRAWSTLVRML_DataSource3D,MeshVS_DataSource)
25 //================================================================
26 // Function : Constructor
28 //================================================================
29 XSDRAWSTLVRML_DataSource3D::XSDRAWSTLVRML_DataSource3D()
31 for (Standard_Integer aNodeID = 1; aNodeID <= 16; aNodeID++)
33 myNodes.Add( aNodeID );
36 for (Standard_Integer anElemID = 1; anElemID <= 5; anElemID++)
38 myElements.Add( anElemID );
41 myNodeCoords = new TColStd_HArray2OfReal(1, 16, 1, 3);
43 myNodeCoords->SetValue( 1, 1, 5 );
44 myNodeCoords->SetValue( 1, 2, 5 );
45 myNodeCoords->SetValue( 1, 3, 20 );
47 myNodeCoords->SetValue( 2, 1, 0 );
48 myNodeCoords->SetValue( 2, 2, 10 );
49 myNodeCoords->SetValue( 2, 3, 10 );
51 myNodeCoords->SetValue( 3, 1, 10 );
52 myNodeCoords->SetValue( 3, 2, 0 );
53 myNodeCoords->SetValue( 3, 3, 10 );
55 myNodeCoords->SetValue( 4, 1, 0 );
56 myNodeCoords->SetValue( 4, 2, 0 );
57 myNodeCoords->SetValue( 4, 3, 10 );
59 myNodeCoords->SetValue( 5, 1, -10 );
60 myNodeCoords->SetValue( 5, 2, 0 );
61 myNodeCoords->SetValue( 5, 3, 10 );
63 myNodeCoords->SetValue( 6, 1, -10 );
64 myNodeCoords->SetValue( 6, 2, 10 );
65 myNodeCoords->SetValue( 6, 3, 10 );
67 myNodeCoords->SetValue( 7, 1, -10 );
68 myNodeCoords->SetValue( 7, 2, 10 );
69 myNodeCoords->SetValue( 7, 3, 0 );
71 myNodeCoords->SetValue( 8, 1, -10 );
72 myNodeCoords->SetValue( 8, 2, 0 );
73 myNodeCoords->SetValue( 8, 3, 0 );
75 myNodeCoords->SetValue( 9, 1, 0 );
76 myNodeCoords->SetValue( 9, 2, 0 );
77 myNodeCoords->SetValue( 9, 3, 0 );
79 myNodeCoords->SetValue( 10, 1, 0 );
80 myNodeCoords->SetValue( 10, 2, 10 );
81 myNodeCoords->SetValue( 10, 3, 0 );
83 myNodeCoords->SetValue( 11, 1, 0 );
84 myNodeCoords->SetValue( 11, 2, -10 );
85 myNodeCoords->SetValue( 11, 3, 10 );
87 myNodeCoords->SetValue( 12, 1, 10 );
88 myNodeCoords->SetValue( 12, 2, -10 );
89 myNodeCoords->SetValue( 12, 3, 10 );
91 myNodeCoords->SetValue( 13, 1, 10 );
92 myNodeCoords->SetValue( 13, 2, -10 );
93 myNodeCoords->SetValue( 13, 3, 0 );
95 myNodeCoords->SetValue( 14, 1, 0 );
96 myNodeCoords->SetValue( 14, 2, -10 );
97 myNodeCoords->SetValue( 14, 3, 0 );
99 myNodeCoords->SetValue( 15, 1, 10 );
100 myNodeCoords->SetValue( 15, 2, 0 );
101 myNodeCoords->SetValue( 15, 3, 0 );
103 myNodeCoords->SetValue( 16, 1, 5 );
104 myNodeCoords->SetValue( 16, 2, 5 );
105 myNodeCoords->SetValue( 16, 3, -10 );
107 myElemNbNodes = new TColStd_HArray1OfInteger(1, 5);
109 myElemNbNodes->SetValue( 1, 4 );
110 myElemNbNodes->SetValue( 2, 8 );
111 myElemNbNodes->SetValue( 3, 6 );
112 myElemNbNodes->SetValue( 4, 8 );
113 myElemNbNodes->SetValue( 5, 4 );
115 myElemNodes = new TColStd_HArray2OfInteger(1, 5, 1, 8);
117 myElemNodes->SetValue(1, 1, 1);
118 myElemNodes->SetValue(1, 2, 2);
119 myElemNodes->SetValue(1, 3, 3);
120 myElemNodes->SetValue(1, 4, 4);
122 myElemNodes->SetValue(2, 1, 2);
123 myElemNodes->SetValue(2, 2, 4);
124 myElemNodes->SetValue(2, 3, 5);
125 myElemNodes->SetValue(2, 4, 6);
126 myElemNodes->SetValue(2, 5, 7);
127 myElemNodes->SetValue(2, 6, 8);
128 myElemNodes->SetValue(2, 7, 9);
129 myElemNodes->SetValue(2, 8, 10);
131 myElemNodes->SetValue(3, 1, 2);
132 myElemNodes->SetValue(3, 2, 3);
133 myElemNodes->SetValue(3, 3, 4);
134 myElemNodes->SetValue(3, 4, 10);
135 myElemNodes->SetValue(3, 5, 15);
136 myElemNodes->SetValue(3, 6, 9);
138 myElemNodes->SetValue(4, 1, 4);
139 myElemNodes->SetValue(4, 2, 3);
140 myElemNodes->SetValue(4, 3, 12);
141 myElemNodes->SetValue(4, 4, 11);
142 myElemNodes->SetValue(4, 5, 14);
143 myElemNodes->SetValue(4, 6, 13);
144 myElemNodes->SetValue(4, 7, 15);
145 myElemNodes->SetValue(4, 8, 9);
147 myElemNodes->SetValue(5, 1, 16);
148 myElemNodes->SetValue(5, 2, 15);
149 myElemNodes->SetValue(5, 3, 10);
150 myElemNodes->SetValue(5, 4, 9);
153 //================================================================
154 // Function : GetGeom
156 //================================================================
157 Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetGeom
158 ( const Standard_Integer theID, const Standard_Boolean theIsElement,
159 TColStd_Array1OfReal& theCoords, Standard_Integer& theNbNodes,
160 MeshVS_EntityType& theType ) const
164 if (theID >= 1 && theID <= myElements.Extent())
166 theType = MeshVS_ET_Volume;
167 theNbNodes = myElemNbNodes->Value(theID);
169 for (Standard_Integer aNodeI = 1, aGlobCoordI = 1; aNodeI <= theNbNodes; aNodeI++)
171 Standard_Integer anIdxNode = myElemNodes->Value(theID, aNodeI);
172 for(Standard_Integer aCoordI = 1; aCoordI <= 3; aCoordI++, aGlobCoordI++ )
173 theCoords(aGlobCoordI) = myNodeCoords->Value(anIdxNode, aCoordI);
176 return Standard_True;
179 return Standard_False;
182 if (theID >= 1 && theID <= myNodes.Extent())
184 theType = MeshVS_ET_Node;
187 theCoords( 1 ) = myNodeCoords->Value(theID, 1);
188 theCoords( 2 ) = myNodeCoords->Value(theID, 2);
189 theCoords( 3 ) = myNodeCoords->Value(theID, 3);
190 return Standard_True;
193 return Standard_False;
196 //================================================================
197 // Function : Get3DGeom
199 //================================================================
200 Standard_Boolean XSDRAWSTLVRML_DataSource3D::Get3DGeom
201 ( const Standard_Integer theID, Standard_Integer& theNbNodes,
202 Handle(MeshVS_HArray1OfSequenceOfInteger)& theData ) const
204 Handle(MeshVS_HArray1OfSequenceOfInteger) aMeshData;
205 if (theID == 1 || theID == 5)
207 aMeshData = new MeshVS_HArray1OfSequenceOfInteger(1,4);
209 for (Standard_Integer anElemI = 1; anElemI <= 4; anElemI++)
211 aMeshData->ChangeValue(anElemI).Append( (anElemI - 1) % 4 );
212 aMeshData->ChangeValue(anElemI).Append( anElemI % 4 );
213 aMeshData->ChangeValue(anElemI).Append( (anElemI + 1) % 4 );
216 return Standard_True;
219 if (theID == 2 || theID == 4)
221 aMeshData = new MeshVS_HArray1OfSequenceOfInteger(1,6);
223 for (Standard_Integer anElemI = 1, k = 1; anElemI <= 4; anElemI++)
225 aMeshData->ChangeValue(anElemI).Append( (k - 1) % 8 );
226 aMeshData->ChangeValue(anElemI).Append( k % 8 );
227 aMeshData->ChangeValue(anElemI).Append( (k + 1) % 8 );
228 aMeshData->ChangeValue(anElemI).Append( (k + 2) % 8 );
232 aMeshData->ChangeValue(5).Append( 0 );
233 aMeshData->ChangeValue(5).Append( 3 );
234 aMeshData->ChangeValue(5).Append( 4 );
235 aMeshData->ChangeValue(5).Append( 7 );
237 aMeshData->ChangeValue(6).Append( 1 );
238 aMeshData->ChangeValue(6).Append( 2 );
239 aMeshData->ChangeValue(6).Append( 5 );
240 aMeshData->ChangeValue(6).Append( 6 );
243 return Standard_True;
248 aMeshData = new MeshVS_HArray1OfSequenceOfInteger(1,5);
250 for (Standard_Integer anElemI = 1; anElemI <= 2; anElemI++)
252 aMeshData->ChangeValue(anElemI).Append( (anElemI - 1) * 3 );
253 aMeshData->ChangeValue(anElemI).Append( (anElemI - 1) * 3 + 1 );
254 aMeshData->ChangeValue(anElemI).Append( (anElemI - 1) * 3 + 2 );
256 for (Standard_Integer anElemI = 1; anElemI <= 3; anElemI++)
258 aMeshData->ChangeValue(2 + anElemI).Append( (anElemI - 1) % 3 );
259 aMeshData->ChangeValue(2 + anElemI).Append( anElemI % 3 );
260 aMeshData->ChangeValue(2 + anElemI).Append( anElemI % 3 + 3 );
261 aMeshData->ChangeValue(2 + anElemI).Append( (anElemI - 1) % 3 + 3 );
264 return Standard_True;
267 return Standard_False;
270 //================================================================
271 // Function : GetGeomType
273 //================================================================
274 Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetGeomType
275 ( const Standard_Integer theID,
276 const Standard_Boolean theIsElement,
277 MeshVS_EntityType& theType ) const
281 if (theID >= 1 && theID <= myElements.Extent())
283 theType = MeshVS_ET_Volume;
284 return Standard_True;
288 if (theID >= 1 && theID <= myNodes.Extent())
290 theType = MeshVS_ET_Node;
291 return Standard_True;
294 return Standard_False;
297 //================================================================
298 // Function : GetAddr
300 //================================================================
301 Standard_Address XSDRAWSTLVRML_DataSource3D::GetAddr
302 ( const Standard_Integer, const Standard_Boolean ) const
307 //================================================================
308 // Function : GetNodesByElement
310 //================================================================
311 Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetNodesByElement
312 ( const Standard_Integer theID,
313 TColStd_Array1OfInteger& theNodeIDs,
314 Standard_Integer& theNbNodes ) const
316 Standard_Integer aLow;
317 if (theID == 1 || theID == 5)
320 aLow = theNodeIDs.Lower();
321 theNodeIDs (aLow) = myElemNodes->Value(theID, 1 );
322 theNodeIDs (aLow + 1) = myElemNodes->Value(theID, 2 );
323 theNodeIDs (aLow + 2) = myElemNodes->Value(theID, 3 );
324 theNodeIDs (aLow + 3) = myElemNodes->Value(theID, 4 );
325 return Standard_True;
328 if (theID == 2 || theID == 4)
331 aLow = theNodeIDs.Lower();
332 theNodeIDs (aLow) = myElemNodes->Value(theID, 1 );
333 theNodeIDs (aLow + 1) = myElemNodes->Value(theID, 2 );
334 theNodeIDs (aLow + 2) = myElemNodes->Value(theID, 3 );
335 theNodeIDs (aLow + 3) = myElemNodes->Value(theID, 4 );
336 theNodeIDs (aLow + 4) = myElemNodes->Value(theID, 5 );
337 theNodeIDs (aLow + 5) = myElemNodes->Value(theID, 6 );
338 theNodeIDs (aLow + 6) = myElemNodes->Value(theID, 7 );
339 theNodeIDs (aLow + 7) = myElemNodes->Value(theID, 8 );
340 return Standard_True;
346 aLow = theNodeIDs.Lower();
347 theNodeIDs (aLow) = myElemNodes->Value(theID, 1 );
348 theNodeIDs (aLow + 1) = myElemNodes->Value(theID, 2 );
349 theNodeIDs (aLow + 2) = myElemNodes->Value(theID, 3 );
350 theNodeIDs (aLow + 3) = myElemNodes->Value(theID, 4 );
351 theNodeIDs (aLow + 4) = myElemNodes->Value(theID, 5 );
352 theNodeIDs (aLow + 5) = myElemNodes->Value(theID, 6 );
353 return Standard_True;
356 return Standard_False;
359 //================================================================
360 // Function : GetAllNodes
362 //================================================================
363 const TColStd_PackedMapOfInteger& XSDRAWSTLVRML_DataSource3D::GetAllNodes() const
368 //================================================================
369 // Function : GetAllElements
371 //================================================================
372 const TColStd_PackedMapOfInteger& XSDRAWSTLVRML_DataSource3D::GetAllElements() const
377 //================================================================
378 // Function : GetNormal
380 //================================================================
381 Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetNormal
382 ( const Standard_Integer /*theID*/, const Standard_Integer /*theMax*/,
383 Standard_Real& /*theNx*/, Standard_Real& /*theNy*/,Standard_Real& /*theNz*/ ) const
385 return Standard_False;