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