1 // Created on: 2003-12-11
2 // Created by: Alexander SOLOVYOV
3 // Copyright (c) 2003-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.
18 #include <MeshVS_Buffer.hxx>
19 #include <MeshVS_DataSource.hxx>
20 #include <MeshVS_DeformedDataSource.hxx>
21 #include <Standard_Type.hxx>
23 IMPLEMENT_STANDARD_RTTIEXT(MeshVS_DeformedDataSource,MeshVS_DataSource)
25 //================================================================
26 // Function : Constructor MeshVS_DeformedDataSource
28 //================================================================
29 MeshVS_DeformedDataSource::MeshVS_DeformedDataSource( const Handle(MeshVS_DataSource)& theNonDeformDS,
30 const Standard_Real theMagnify )
32 myNonDeformedDataSource = theNonDeformDS;
33 SetMagnify ( theMagnify );
36 //================================================================
37 // Function : shiftCoord
38 // Purpose : auxiliary: shift coordinate of the node on a given vector
39 //================================================================
41 static inline void shiftCoord (TColStd_Array1OfReal& Coords, Standard_Integer i, const gp_Vec &aVec)
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();
48 //================================================================
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
58 if ( myNonDeformedDataSource.IsNull() ||
59 ! myNonDeformedDataSource->GetGeom ( ID, IsElement, Coords, NbNodes, Type ) )
60 return Standard_False;
62 if ( Type==MeshVS_ET_Node )
65 if ( ! GetVector( ID, Vect ) )
66 return Standard_False;
67 shiftCoord ( Coords, 1, myMagnify * Vect );
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++ )
78 if ( ! GetVector( aNodes(i), Vect ) )
79 return Standard_False;
80 shiftCoord ( Coords, i, myMagnify * Vect );
86 //================================================================
87 // Function : GetGeomType
89 //================================================================
90 Standard_Boolean MeshVS_DeformedDataSource::GetGeomType( const Standard_Integer ID,
91 const Standard_Boolean IsElement,
92 MeshVS_EntityType& Type) const
94 if ( myNonDeformedDataSource.IsNull() )
95 return Standard_False;
97 return myNonDeformedDataSource->GetGeomType( ID, IsElement, Type );
100 //================================================================
101 // Function : Get3DGeom
103 //================================================================
104 Standard_Boolean MeshVS_DeformedDataSource::Get3DGeom( const Standard_Integer ID,
105 Standard_Integer& NbNodes,
106 Handle( MeshVS_HArray1OfSequenceOfInteger )& Data ) const
108 if( myNonDeformedDataSource.IsNull() )
109 return Standard_False;
111 return myNonDeformedDataSource->Get3DGeom( ID, NbNodes, Data );
114 //================================================================
115 // Function : GetAddr
117 //================================================================
118 Standard_Address MeshVS_DeformedDataSource::GetAddr( const Standard_Integer ID,
119 const Standard_Boolean IsElement ) const
121 if ( myNonDeformedDataSource.IsNull() )
124 return myNonDeformedDataSource->GetAddr( ID, IsElement );
127 //================================================================
128 // Function : GetNodesByElement
130 //================================================================
131 Standard_Boolean MeshVS_DeformedDataSource::GetNodesByElement
132 (const Standard_Integer ID,
133 TColStd_Array1OfInteger& NodeIDs,
134 Standard_Integer& NbNodes) const
136 if ( myNonDeformedDataSource.IsNull() )
137 return Standard_False;
139 return myNonDeformedDataSource->GetNodesByElement( ID, NodeIDs, NbNodes );
142 //================================================================
143 // Function : GetAllNodes
145 //================================================================
146 const TColStd_PackedMapOfInteger& MeshVS_DeformedDataSource::GetAllNodes() const
148 if ( myNonDeformedDataSource.IsNull() )
151 return myNonDeformedDataSource->GetAllNodes();
154 //================================================================
155 // Function : GetAllElements
157 //================================================================
158 const TColStd_PackedMapOfInteger& MeshVS_DeformedDataSource::GetAllElements() const
160 if ( myNonDeformedDataSource.IsNull() )
163 return myNonDeformedDataSource->GetAllElements();
166 //================================================================
167 // Function : GetVectors
169 //================================================================
170 const MeshVS_DataMapOfIntegerVector& MeshVS_DeformedDataSource::GetVectors() const
175 //================================================================
176 // Function : SetVectors
178 //================================================================
179 void MeshVS_DeformedDataSource::SetVectors( const MeshVS_DataMapOfIntegerVector& Map )
184 //================================================================
185 // Function : GetVector
187 //================================================================
188 Standard_Boolean MeshVS_DeformedDataSource::GetVector( const Standard_Integer ID,
191 Standard_Boolean aRes = myVectors.IsBound ( ID );
193 Vect = myVectors.Find ( ID );
197 //================================================================
198 // Function : SetVector
200 //================================================================
201 void MeshVS_DeformedDataSource::SetVector( const Standard_Integer ID,
204 Standard_Boolean aRes = myVectors.IsBound ( ID );
206 myVectors.ChangeFind ( ID ) = Vect;
208 myVectors.Bind( ID, Vect );
211 //================================================================
212 // Function : SetNonDeformedDataSource
214 //================================================================
215 void MeshVS_DeformedDataSource::SetNonDeformedDataSource( const Handle(MeshVS_DataSource)& theDS )
217 myNonDeformedDataSource = theDS;
220 //================================================================
221 // Function : GetNonDeformedDataSource
223 //================================================================
224 Handle(MeshVS_DataSource) MeshVS_DeformedDataSource::GetNonDeformedDataSource() const
226 return myNonDeformedDataSource;
229 //================================================================
230 // Function : SetMagnify
232 //================================================================
233 void MeshVS_DeformedDataSource::SetMagnify( const Standard_Real theMagnify )
238 myMagnify = theMagnify;
241 //================================================================
242 // Function : GetMagnify
244 //================================================================
245 Standard_Real MeshVS_DeformedDataSource::GetMagnify() const