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 <StlMesh_MeshTriangle.hxx>
19 #include <StlMesh_SequenceOfMeshTriangle.hxx>
20 #include <TColgp_SequenceOfXYZ.hxx>
21 #include <TColStd_DataMapOfIntegerInteger.hxx>
22 #include <TColStd_DataMapOfIntegerReal.hxx>
23 #include <XSDRAWSTLVRML_DataSource3D.hxx>
25 IMPLEMENT_STANDARD_RTTIEXT(XSDRAWSTLVRML_DataSource3D,MeshVS_DataSource)
27 //================================================================
28 // Function : Constructor
30 //================================================================
31 XSDRAWSTLVRML_DataSource3D::XSDRAWSTLVRML_DataSource3D()
33 for (Standard_Integer aNodeID = 1; aNodeID <= 16; aNodeID++)
35 myNodes.Add( aNodeID );
38 for (Standard_Integer anElemID = 1; anElemID <= 5; anElemID++)
40 myElements.Add( anElemID );
43 myNodeCoords = new TColStd_HArray2OfReal(1, 16, 1, 3);
45 myNodeCoords->SetValue( 1, 1, 5 );
46 myNodeCoords->SetValue( 1, 2, 5 );
47 myNodeCoords->SetValue( 1, 3, 20 );
49 myNodeCoords->SetValue( 2, 1, 0 );
50 myNodeCoords->SetValue( 2, 2, 10 );
51 myNodeCoords->SetValue( 2, 3, 10 );
53 myNodeCoords->SetValue( 3, 1, 10 );
54 myNodeCoords->SetValue( 3, 2, 0 );
55 myNodeCoords->SetValue( 3, 3, 10 );
57 myNodeCoords->SetValue( 4, 1, 0 );
58 myNodeCoords->SetValue( 4, 2, 0 );
59 myNodeCoords->SetValue( 4, 3, 10 );
61 myNodeCoords->SetValue( 5, 1, -10 );
62 myNodeCoords->SetValue( 5, 2, 0 );
63 myNodeCoords->SetValue( 5, 3, 10 );
65 myNodeCoords->SetValue( 6, 1, -10 );
66 myNodeCoords->SetValue( 6, 2, 10 );
67 myNodeCoords->SetValue( 6, 3, 10 );
69 myNodeCoords->SetValue( 7, 1, -10 );
70 myNodeCoords->SetValue( 7, 2, 10 );
71 myNodeCoords->SetValue( 7, 3, 0 );
73 myNodeCoords->SetValue( 8, 1, -10 );
74 myNodeCoords->SetValue( 8, 2, 0 );
75 myNodeCoords->SetValue( 8, 3, 0 );
77 myNodeCoords->SetValue( 9, 1, 0 );
78 myNodeCoords->SetValue( 9, 2, 0 );
79 myNodeCoords->SetValue( 9, 3, 0 );
81 myNodeCoords->SetValue( 10, 1, 0 );
82 myNodeCoords->SetValue( 10, 2, 10 );
83 myNodeCoords->SetValue( 10, 3, 0 );
85 myNodeCoords->SetValue( 11, 1, 0 );
86 myNodeCoords->SetValue( 11, 2, -10 );
87 myNodeCoords->SetValue( 11, 3, 10 );
89 myNodeCoords->SetValue( 12, 1, 10 );
90 myNodeCoords->SetValue( 12, 2, -10 );
91 myNodeCoords->SetValue( 12, 3, 10 );
93 myNodeCoords->SetValue( 13, 1, 10 );
94 myNodeCoords->SetValue( 13, 2, -10 );
95 myNodeCoords->SetValue( 13, 3, 0 );
97 myNodeCoords->SetValue( 14, 1, 0 );
98 myNodeCoords->SetValue( 14, 2, -10 );
99 myNodeCoords->SetValue( 14, 3, 0 );
101 myNodeCoords->SetValue( 15, 1, 10 );
102 myNodeCoords->SetValue( 15, 2, 0 );
103 myNodeCoords->SetValue( 15, 3, 0 );
105 myNodeCoords->SetValue( 16, 1, 5 );
106 myNodeCoords->SetValue( 16, 2, 5 );
107 myNodeCoords->SetValue( 16, 3, -10 );
109 myElemNbNodes = new TColStd_HArray1OfInteger(1, 5);
111 myElemNbNodes->SetValue( 1, 4 );
112 myElemNbNodes->SetValue( 2, 8 );
113 myElemNbNodes->SetValue( 3, 6 );
114 myElemNbNodes->SetValue( 4, 8 );
115 myElemNbNodes->SetValue( 5, 4 );
117 myElemNodes = new TColStd_HArray2OfInteger(1, 5, 1, 8);
119 myElemNodes->SetValue(1, 1, 1);
120 myElemNodes->SetValue(1, 2, 2);
121 myElemNodes->SetValue(1, 3, 3);
122 myElemNodes->SetValue(1, 4, 4);
124 myElemNodes->SetValue(2, 1, 2);
125 myElemNodes->SetValue(2, 2, 4);
126 myElemNodes->SetValue(2, 3, 5);
127 myElemNodes->SetValue(2, 4, 6);
128 myElemNodes->SetValue(2, 5, 7);
129 myElemNodes->SetValue(2, 6, 8);
130 myElemNodes->SetValue(2, 7, 9);
131 myElemNodes->SetValue(2, 8, 10);
133 myElemNodes->SetValue(3, 1, 2);
134 myElemNodes->SetValue(3, 2, 3);
135 myElemNodes->SetValue(3, 3, 4);
136 myElemNodes->SetValue(3, 4, 10);
137 myElemNodes->SetValue(3, 5, 15);
138 myElemNodes->SetValue(3, 6, 9);
140 myElemNodes->SetValue(4, 1, 4);
141 myElemNodes->SetValue(4, 2, 3);
142 myElemNodes->SetValue(4, 3, 12);
143 myElemNodes->SetValue(4, 4, 11);
144 myElemNodes->SetValue(4, 5, 14);
145 myElemNodes->SetValue(4, 6, 13);
146 myElemNodes->SetValue(4, 7, 15);
147 myElemNodes->SetValue(4, 8, 9);
149 myElemNodes->SetValue(5, 1, 16);
150 myElemNodes->SetValue(5, 2, 15);
151 myElemNodes->SetValue(5, 3, 10);
152 myElemNodes->SetValue(5, 4, 9);
155 //================================================================
156 // Function : GetGeom
158 //================================================================
159 Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetGeom
160 ( const Standard_Integer theID, const Standard_Boolean theIsElement,
161 TColStd_Array1OfReal& theCoords, Standard_Integer& theNbNodes,
162 MeshVS_EntityType& theType ) const
166 if (theID >= 1 && theID <= myElements.Extent())
168 theType = MeshVS_ET_Volume;
169 theNbNodes = myElemNbNodes->Value(theID);
171 for (Standard_Integer aNodeI = 1, aGlobCoordI = 1; aNodeI <= theNbNodes; aNodeI++)
173 Standard_Integer anIdxNode = myElemNodes->Value(theID, aNodeI);
174 for(Standard_Integer aCoordI = 1; aCoordI <= 3; aCoordI++, aGlobCoordI++ )
175 theCoords(aGlobCoordI) = myNodeCoords->Value(anIdxNode, aCoordI);
178 return Standard_True;
181 return Standard_False;
184 if (theID >= 1 && theID <= myNodes.Extent())
186 theType = MeshVS_ET_Node;
189 theCoords( 1 ) = myNodeCoords->Value(theID, 1);
190 theCoords( 2 ) = myNodeCoords->Value(theID, 2);
191 theCoords( 3 ) = myNodeCoords->Value(theID, 3);
192 return Standard_True;
195 return Standard_False;
198 //================================================================
199 // Function : Get3DGeom
201 //================================================================
202 Standard_Boolean XSDRAWSTLVRML_DataSource3D::Get3DGeom
203 ( const Standard_Integer theID, Standard_Integer& theNbNodes,
204 Handle(MeshVS_HArray1OfSequenceOfInteger)& theData ) const
206 Handle(MeshVS_HArray1OfSequenceOfInteger) aMeshData;
207 if (theID == 1 || theID == 5)
209 aMeshData = new MeshVS_HArray1OfSequenceOfInteger(1,4);
211 for (Standard_Integer anElemI = 1; anElemI <= 4; anElemI++)
213 aMeshData->ChangeValue(anElemI).Append( (anElemI - 1) % 4 );
214 aMeshData->ChangeValue(anElemI).Append( anElemI % 4 );
215 aMeshData->ChangeValue(anElemI).Append( (anElemI + 1) % 4 );
218 return Standard_True;
221 if (theID == 2 || theID == 4)
223 aMeshData = new MeshVS_HArray1OfSequenceOfInteger(1,6);
225 for (Standard_Integer anElemI = 1, k = 1; anElemI <= 4; anElemI++)
227 aMeshData->ChangeValue(anElemI).Append( (k - 1) % 8 );
228 aMeshData->ChangeValue(anElemI).Append( k % 8 );
229 aMeshData->ChangeValue(anElemI).Append( (k + 1) % 8 );
230 aMeshData->ChangeValue(anElemI).Append( (k + 2) % 8 );
234 aMeshData->ChangeValue(5).Append( 0 );
235 aMeshData->ChangeValue(5).Append( 3 );
236 aMeshData->ChangeValue(5).Append( 4 );
237 aMeshData->ChangeValue(5).Append( 7 );
239 aMeshData->ChangeValue(6).Append( 1 );
240 aMeshData->ChangeValue(6).Append( 2 );
241 aMeshData->ChangeValue(6).Append( 5 );
242 aMeshData->ChangeValue(6).Append( 6 );
245 return Standard_True;
250 aMeshData = new MeshVS_HArray1OfSequenceOfInteger(1,5);
252 for (Standard_Integer anElemI = 1; anElemI <= 2; anElemI++)
254 aMeshData->ChangeValue(anElemI).Append( (anElemI - 1) * 3 );
255 aMeshData->ChangeValue(anElemI).Append( (anElemI - 1) * 3 + 1 );
256 aMeshData->ChangeValue(anElemI).Append( (anElemI - 1) * 3 + 2 );
258 for (Standard_Integer anElemI = 1; anElemI <= 3; anElemI++)
260 aMeshData->ChangeValue(2 + anElemI).Append( (anElemI - 1) % 3 );
261 aMeshData->ChangeValue(2 + anElemI).Append( anElemI % 3 );
262 aMeshData->ChangeValue(2 + anElemI).Append( anElemI % 3 + 3 );
263 aMeshData->ChangeValue(2 + anElemI).Append( (anElemI - 1) % 3 + 3 );
266 return Standard_True;
269 return Standard_False;
272 //================================================================
273 // Function : GetGeomType
275 //================================================================
276 Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetGeomType
277 ( const Standard_Integer theID,
278 const Standard_Boolean theIsElement,
279 MeshVS_EntityType& theType ) const
283 if (theID >= 1 && theID <= myElements.Extent())
285 theType = MeshVS_ET_Volume;
286 return Standard_True;
290 if (theID >= 1 && theID <= myNodes.Extent())
292 theType = MeshVS_ET_Node;
293 return Standard_True;
296 return Standard_False;
299 //================================================================
300 // Function : GetAddr
302 //================================================================
303 Standard_Address XSDRAWSTLVRML_DataSource3D::GetAddr
304 ( const Standard_Integer, const Standard_Boolean ) const
309 //================================================================
310 // Function : GetNodesByElement
312 //================================================================
313 Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetNodesByElement
314 ( const Standard_Integer theID,
315 TColStd_Array1OfInteger& theNodeIDs,
316 Standard_Integer& theNbNodes ) const
318 Standard_Integer aLow;
319 if (theID == 1 || theID == 5)
322 aLow = theNodeIDs.Lower();
323 theNodeIDs (aLow) = myElemNodes->Value(theID, 1 );
324 theNodeIDs (aLow + 1) = myElemNodes->Value(theID, 2 );
325 theNodeIDs (aLow + 2) = myElemNodes->Value(theID, 3 );
326 theNodeIDs (aLow + 3) = myElemNodes->Value(theID, 4 );
327 return Standard_True;
330 if (theID == 2 || theID == 4)
333 aLow = theNodeIDs.Lower();
334 theNodeIDs (aLow) = myElemNodes->Value(theID, 1 );
335 theNodeIDs (aLow + 1) = myElemNodes->Value(theID, 2 );
336 theNodeIDs (aLow + 2) = myElemNodes->Value(theID, 3 );
337 theNodeIDs (aLow + 3) = myElemNodes->Value(theID, 4 );
338 theNodeIDs (aLow + 4) = myElemNodes->Value(theID, 5 );
339 theNodeIDs (aLow + 5) = myElemNodes->Value(theID, 6 );
340 theNodeIDs (aLow + 6) = myElemNodes->Value(theID, 7 );
341 theNodeIDs (aLow + 7) = myElemNodes->Value(theID, 8 );
342 return Standard_True;
348 aLow = theNodeIDs.Lower();
349 theNodeIDs (aLow) = myElemNodes->Value(theID, 1 );
350 theNodeIDs (aLow + 1) = myElemNodes->Value(theID, 2 );
351 theNodeIDs (aLow + 2) = myElemNodes->Value(theID, 3 );
352 theNodeIDs (aLow + 3) = myElemNodes->Value(theID, 4 );
353 theNodeIDs (aLow + 4) = myElemNodes->Value(theID, 5 );
354 theNodeIDs (aLow + 5) = myElemNodes->Value(theID, 6 );
355 return Standard_True;
358 return Standard_False;
361 //================================================================
362 // Function : GetAllNodes
364 //================================================================
365 const TColStd_PackedMapOfInteger& XSDRAWSTLVRML_DataSource3D::GetAllNodes() const
370 //================================================================
371 // Function : GetAllElements
373 //================================================================
374 const TColStd_PackedMapOfInteger& XSDRAWSTLVRML_DataSource3D::GetAllElements() const
379 //================================================================
380 // Function : GetNormal
382 //================================================================
383 Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetNormal
384 ( const Standard_Integer /*theID*/, const Standard_Integer /*theMax*/,
385 Standard_Real& /*theNx*/, Standard_Real& /*theNy*/,Standard_Real& /*theNz*/ ) const
387 return Standard_False;