b311480e |
1 | // Created on: 2003-12-11 |
2 | // Created by: Alexander SOLOVYOV |
973c2be1 |
3 | // Copyright (c) 2003-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 | |
42cf5bc1 |
16 | |
17 | #include <gp_Vec.hxx> |
7fd59977 |
18 | #include <MeshVS_Buffer.hxx> |
42cf5bc1 |
19 | #include <MeshVS_DataSource.hxx> |
20 | #include <MeshVS_DeformedDataSource.hxx> |
21 | #include <Standard_Type.hxx> |
7fd59977 |
22 | |
92efcf78 |
23 | IMPLEMENT_STANDARD_RTTIEXT(MeshVS_DeformedDataSource,MeshVS_DataSource) |
24 | |
7fd59977 |
25 | //================================================================ |
26 | // Function : Constructor MeshVS_DeformedDataSource |
27 | // Purpose : |
28 | //================================================================ |
29 | MeshVS_DeformedDataSource::MeshVS_DeformedDataSource( const Handle(MeshVS_DataSource)& theNonDeformDS, |
30 | const Standard_Real theMagnify ) |
31 | { |
32 | myNonDeformedDataSource = theNonDeformDS; |
33 | SetMagnify ( theMagnify ); |
34 | } |
35 | |
36 | //================================================================ |
37 | // Function : shiftCoord |
38 | // Purpose : auxiliary: shift coordinate of the node on a given vector |
39 | //================================================================ |
40 | |
41 | static inline void shiftCoord (TColStd_Array1OfReal& Coords, Standard_Integer i, const gp_Vec &aVec) |
42 | { |
43 | Coords(3*i-2) = Coords(3*i-2) + aVec.X(); |
44 | Coords(3*i-1) = Coords(3*i-1) + aVec.Y(); |
45 | Coords(3*i) = Coords(3*i) + aVec.Z(); |
46 | } |
47 | |
48 | //================================================================ |
49 | // Function : GetGeom |
50 | // Purpose : |
51 | //================================================================ |
52 | Standard_Boolean MeshVS_DeformedDataSource::GetGeom( const Standard_Integer ID, |
53 | const Standard_Boolean IsElement, |
54 | TColStd_Array1OfReal& Coords, |
55 | Standard_Integer& NbNodes, |
56 | MeshVS_EntityType& Type) const |
57 | { |
58 | if ( myNonDeformedDataSource.IsNull() || |
59 | ! myNonDeformedDataSource->GetGeom ( ID, IsElement, Coords, NbNodes, Type ) ) |
60 | return Standard_False; |
61 | |
62 | if ( Type==MeshVS_ET_Node ) |
63 | { |
64 | gp_Vec Vect; |
65 | if ( ! GetVector( ID, Vect ) ) |
66 | return Standard_False; |
67 | shiftCoord ( Coords, 1, myMagnify * Vect ); |
68 | } |
69 | else |
70 | { |
71 | MeshVS_Buffer aNodesBuf (NbNodes * sizeof(Standard_Integer)); |
72 | TColStd_Array1OfInteger aNodes (aNodesBuf, 1, NbNodes); |
73 | if ( !myNonDeformedDataSource->GetNodesByElement ( ID, aNodes, NbNodes ) ) |
74 | return Standard_False; |
75 | for ( int i=1; i <= NbNodes; i++ ) |
76 | { |
77 | gp_Vec Vect; |
78 | if ( ! GetVector( aNodes(i), Vect ) ) |
79 | return Standard_False; |
80 | shiftCoord ( Coords, i, myMagnify * Vect ); |
81 | } |
82 | } |
83 | return Standard_True; |
84 | } |
85 | |
86 | //================================================================ |
87 | // Function : GetGeomType |
88 | // Purpose : |
89 | //================================================================ |
90 | Standard_Boolean MeshVS_DeformedDataSource::GetGeomType( const Standard_Integer ID, |
91 | const Standard_Boolean IsElement, |
92 | MeshVS_EntityType& Type) const |
93 | { |
94 | if ( myNonDeformedDataSource.IsNull() ) |
95 | return Standard_False; |
96 | else |
97 | return myNonDeformedDataSource->GetGeomType( ID, IsElement, Type ); |
98 | } |
99 | |
100 | //================================================================ |
101 | // Function : Get3DGeom |
102 | // Purpose : |
103 | //================================================================ |
104 | Standard_Boolean MeshVS_DeformedDataSource::Get3DGeom( const Standard_Integer ID, |
105 | Standard_Integer& NbNodes, |
106 | Handle( MeshVS_HArray1OfSequenceOfInteger )& Data ) const |
107 | { |
108 | if( myNonDeformedDataSource.IsNull() ) |
109 | return Standard_False; |
110 | else |
111 | return myNonDeformedDataSource->Get3DGeom( ID, NbNodes, Data ); |
112 | } |
113 | |
114 | //================================================================ |
115 | // Function : GetAddr |
116 | // Purpose : |
117 | //================================================================ |
118 | Standard_Address MeshVS_DeformedDataSource::GetAddr( const Standard_Integer ID, |
119 | const Standard_Boolean IsElement ) const |
120 | { |
121 | if ( myNonDeformedDataSource.IsNull() ) |
122 | return 0; |
123 | else |
124 | return myNonDeformedDataSource->GetAddr( ID, IsElement ); |
125 | } |
126 | |
127 | //================================================================ |
128 | // Function : GetNodesByElement |
129 | // Purpose : |
130 | //================================================================ |
131 | Standard_Boolean MeshVS_DeformedDataSource::GetNodesByElement |
132 | (const Standard_Integer ID, |
133 | TColStd_Array1OfInteger& NodeIDs, |
134 | Standard_Integer& NbNodes) const |
135 | { |
136 | if ( myNonDeformedDataSource.IsNull() ) |
137 | return Standard_False; |
138 | else |
139 | return myNonDeformedDataSource->GetNodesByElement( ID, NodeIDs, NbNodes ); |
140 | } |
141 | |
142 | //================================================================ |
143 | // Function : GetAllNodes |
144 | // Purpose : |
145 | //================================================================ |
146 | const TColStd_PackedMapOfInteger& MeshVS_DeformedDataSource::GetAllNodes() const |
147 | { |
148 | if ( myNonDeformedDataSource.IsNull() ) |
149 | return myEmptyMap; |
150 | else |
151 | return myNonDeformedDataSource->GetAllNodes(); |
152 | } |
153 | |
154 | //================================================================ |
155 | // Function : GetAllElements |
156 | // Purpose : |
157 | //================================================================ |
158 | const TColStd_PackedMapOfInteger& MeshVS_DeformedDataSource::GetAllElements() const |
159 | { |
160 | if ( myNonDeformedDataSource.IsNull() ) |
161 | return myEmptyMap; |
162 | else |
163 | return myNonDeformedDataSource->GetAllElements(); |
164 | } |
165 | |
166 | //================================================================ |
167 | // Function : GetVectors |
168 | // Purpose : |
169 | //================================================================ |
170 | const MeshVS_DataMapOfIntegerVector& MeshVS_DeformedDataSource::GetVectors() const |
171 | { |
172 | return myVectors; |
173 | } |
174 | |
175 | //================================================================ |
176 | // Function : SetVectors |
177 | // Purpose : |
178 | //================================================================ |
179 | void MeshVS_DeformedDataSource::SetVectors( const MeshVS_DataMapOfIntegerVector& Map ) |
180 | { |
181 | myVectors = Map; |
182 | } |
183 | |
184 | //================================================================ |
185 | // Function : GetVector |
186 | // Purpose : |
187 | //================================================================ |
188 | Standard_Boolean MeshVS_DeformedDataSource::GetVector( const Standard_Integer ID, |
189 | gp_Vec& Vect ) const |
190 | { |
191 | Standard_Boolean aRes = myVectors.IsBound ( ID ); |
192 | if ( aRes ) |
193 | Vect = myVectors.Find ( ID ); |
194 | return aRes; |
195 | } |
196 | |
197 | //================================================================ |
198 | // Function : SetVector |
199 | // Purpose : |
200 | //================================================================ |
201 | void MeshVS_DeformedDataSource::SetVector( const Standard_Integer ID, |
202 | const gp_Vec& Vect ) |
203 | { |
204 | Standard_Boolean aRes = myVectors.IsBound ( ID ); |
205 | if ( aRes ) |
206 | myVectors.ChangeFind ( ID ) = Vect; |
207 | else |
208 | myVectors.Bind( ID, Vect ); |
209 | } |
210 | |
211 | //================================================================ |
212 | // Function : SetNonDeformedDataSource |
213 | // Purpose : |
214 | //================================================================ |
215 | void MeshVS_DeformedDataSource::SetNonDeformedDataSource( const Handle(MeshVS_DataSource)& theDS ) |
216 | { |
217 | myNonDeformedDataSource = theDS; |
218 | } |
219 | |
220 | //================================================================ |
221 | // Function : GetNonDeformedDataSource |
222 | // Purpose : |
223 | //================================================================ |
857ffd5e |
224 | Handle(MeshVS_DataSource) MeshVS_DeformedDataSource::GetNonDeformedDataSource() const |
7fd59977 |
225 | { |
226 | return myNonDeformedDataSource; |
227 | } |
228 | |
229 | //================================================================ |
230 | // Function : SetMagnify |
231 | // Purpose : |
232 | //================================================================ |
233 | void MeshVS_DeformedDataSource::SetMagnify( const Standard_Real theMagnify ) |
234 | { |
235 | if ( theMagnify<=0 ) |
236 | myMagnify = 1.0; |
237 | else |
238 | myMagnify = theMagnify; |
239 | } |
240 | |
241 | //================================================================ |
242 | // Function : GetMagnify |
243 | // Purpose : |
244 | //================================================================ |
245 | Standard_Real MeshVS_DeformedDataSource::GetMagnify() const |
246 | { |
247 | return myMagnify; |
248 | } |