0023948: Wrong intersection between a surface of revolution and a plane.
[occt.git] / src / XSDRAWSTLVRML / XSDRAWSTLVRML_DataSource.cxx
CommitLineData
b311480e 1// Created on: 2004-06-10
2// Created by: Alexander SOLOVYOV
973c2be1 3// Copyright (c) 2004-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16#include <XSDRAWSTLVRML_DataSource.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_DataSource::XSDRAWSTLVRML_DataSource( const Handle( StlMesh_Mesh )& aMesh )
29{
30 myMesh = aMesh;
31
32 if( !myMesh.IsNull() )
33 {
34 const TColgp_SequenceOfXYZ& aCoords = myMesh->Vertices();
35 Standard_Integer len = aCoords.Length(), i, j;
36 myNodeCoords = new TColStd_HArray2OfReal(1, len, 1, 3);
37 cout << "Nodes : " << len << endl;
38
39 gp_XYZ xyz;
40
41 for( i = 1; i <= len; i++ )
42 {
43 myNodes.Add( i );
44 xyz = aCoords(i);
45
46 myNodeCoords->SetValue(i, 1, xyz.X());
47 myNodeCoords->SetValue(i, 2, xyz.Y());
48 myNodeCoords->SetValue(i, 3, xyz.Z());
49 }
50
51 const StlMesh_SequenceOfMeshTriangle& aSeq = myMesh->Triangles();
52 len = aSeq.Length();
53 myElemNormals = new TColStd_HArray2OfReal(1, len, 1, 3);
54 myElemNodes = new TColStd_HArray2OfInteger(1, len, 1, 3);
55
56 cout << "Elements : " << len << endl;
57
58 for( i = 1; i <= len; i++ )
59 {
60 myElements.Add( i );
61 Handle( StlMesh_MeshTriangle ) aTriangle = aSeq.Value( i );
62 Standard_Integer V[3]; Standard_Real nx, ny, nz;
63
64 aTriangle->GetVertexAndOrientation( V[0], V[1], V[2], nx, ny, nz );
65
66 for( j = 0; j < 3; j++ )
67 {
68 myElemNodes->SetValue(i, j+1, V[j]);
69 }
70
71 myElemNormals->SetValue(i, 1, nx);
72 myElemNormals->SetValue(i, 2, ny);
73 myElemNormals->SetValue(i, 3, nz);
74 }
75 }
76 cout << "Construction is finished" << endl;
77}
78
79//================================================================
80// Function : GetGeom
81// Purpose :
82//================================================================
83Standard_Boolean XSDRAWSTLVRML_DataSource::GetGeom
84( const Standard_Integer ID, const Standard_Boolean IsElement,
85 TColStd_Array1OfReal& Coords, Standard_Integer& NbNodes,
86 MeshVS_EntityType& Type ) const
87{
88 if( myMesh.IsNull() )
89 return Standard_False;
90
91 if( IsElement )
92 {
93 if( ID>=1 && ID<=myElements.Extent() )
94 {
95 Type = MeshVS_ET_Face;
96 NbNodes = 3;
97
98 for( Standard_Integer i = 1, k = 1; i <= 3; i++ )
99 {
100 Standard_Integer IdxNode = myElemNodes->Value(ID, i);
101 for(Standard_Integer j = 1; j <= 3; j++, k++ )
102 Coords(k) = myNodeCoords->Value(IdxNode, j);
103 }
104
105 return Standard_True;
106 }
107 else
108 return Standard_False;
109 }
110 else
111 if( ID>=1 && ID<=myNodes.Extent() )
112 {
113 Type = MeshVS_ET_Node;
114 NbNodes = 1;
115
116 Coords( 1 ) = myNodeCoords->Value(ID, 1);
117 Coords( 2 ) = myNodeCoords->Value(ID, 2);
118 Coords( 3 ) = myNodeCoords->Value(ID, 3);
119 return Standard_True;
120 }
121 else
122 return Standard_False;
123}
124
125//================================================================
126// Function : GetGeomType
127// Purpose :
128//================================================================
129Standard_Boolean XSDRAWSTLVRML_DataSource::GetGeomType
130( const Standard_Integer,
131 const Standard_Boolean IsElement,
132 MeshVS_EntityType& Type ) const
133{
134 if( IsElement )
135 {
136 Type = MeshVS_ET_Face;
137 return Standard_True;
138 }
139 else
140 {
141 Type = MeshVS_ET_Node;
142 return Standard_True;
143 }
144}
145
146//================================================================
147// Function : GetAddr
148// Purpose :
149//================================================================
150Standard_Address XSDRAWSTLVRML_DataSource::GetAddr
151( const Standard_Integer, const Standard_Boolean ) const
152{
153 return NULL;
154}
155
156//================================================================
157// Function : GetNodesByElement
158// Purpose :
159//================================================================
160Standard_Boolean XSDRAWSTLVRML_DataSource::GetNodesByElement
161( const Standard_Integer ID,
162 TColStd_Array1OfInteger& theNodeIDs,
35e08fe8 163 Standard_Integer& /*theNbNodes*/ ) const
7fd59977 164{
165 if( myMesh.IsNull() )
166 return Standard_False;
167
168 if( ID>=1 && ID<=myElements.Extent() && theNodeIDs.Length() >= 3 )
169 {
170 Standard_Integer aLow = theNodeIDs.Lower();
171 theNodeIDs (aLow) = myElemNodes->Value(ID, 1 );
172 theNodeIDs (aLow + 1) = myElemNodes->Value(ID, 2 );
173 theNodeIDs (aLow + 2) = myElemNodes->Value(ID, 3 );
174 return Standard_True;
175 }
176 return Standard_False;
177}
178
179//================================================================
180// Function : GetAllNodes
181// Purpose :
182//================================================================
183const TColStd_PackedMapOfInteger& XSDRAWSTLVRML_DataSource::GetAllNodes() const
184{
185 return myNodes;
186}
187
188//================================================================
189// Function : GetAllElements
190// Purpose :
191//================================================================
192const TColStd_PackedMapOfInteger& XSDRAWSTLVRML_DataSource::GetAllElements() const
193{
194 return myElements;
195}
196
197//================================================================
198// Function : GetNormal
199// Purpose :
200//================================================================
201Standard_Boolean XSDRAWSTLVRML_DataSource::GetNormal
202( const Standard_Integer Id, const Standard_Integer Max,
203 Standard_Real& nx, Standard_Real& ny,Standard_Real& nz ) const
204{
205 if( myMesh.IsNull() )
206 return Standard_False;
207
208 if( Id>=1 && Id<=myElements.Extent() && Max>=3 )
209 {
210 nx = myElemNormals->Value(Id, 1);
211 ny = myElemNormals->Value(Id, 2);
212 nz = myElemNormals->Value(Id, 3);
213 return Standard_True;
214 }
215 else
216 return Standard_False;
217}
218