summaryrefslogtreecommitdiff
path: root/src/MeshVS/MeshVS_DeformedDataSource.cxx
blob: cb7755a7fd78a384643b7391c09fd8415f5b2f83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
// File:	MeshVS_DeformedDataSource.cxx
// Created:	Thu Dec 11 2003
// Author:	Alexander SOLOVYOV
// Copyright:	Open CASCADE 2003

#include <MeshVS_DeformedDataSource.ixx>
#include <MeshVS_Buffer.hxx>

//================================================================
// Function : Constructor MeshVS_DeformedDataSource
// Purpose  :
//================================================================
MeshVS_DeformedDataSource::MeshVS_DeformedDataSource( const Handle(MeshVS_DataSource)& theNonDeformDS,
                                                      const Standard_Real theMagnify )
{
  myNonDeformedDataSource = theNonDeformDS;
  SetMagnify ( theMagnify );
}

//================================================================
// Function : shiftCoord
// Purpose  : auxiliary: shift coordinate of the node on a given vector
//================================================================

static inline void shiftCoord (TColStd_Array1OfReal& Coords, Standard_Integer i, const gp_Vec &aVec)
{
  Coords(3*i-2) = Coords(3*i-2) + aVec.X();
  Coords(3*i-1) = Coords(3*i-1) + aVec.Y();
  Coords(3*i)   = Coords(3*i)   + aVec.Z();
}

//================================================================
// Function : GetGeom
// Purpose  :
//================================================================
Standard_Boolean MeshVS_DeformedDataSource::GetGeom( const Standard_Integer ID,
                                                     const Standard_Boolean IsElement,
                                                     TColStd_Array1OfReal& Coords,
                                                     Standard_Integer& NbNodes,
                                                     MeshVS_EntityType& Type) const
{
  if ( myNonDeformedDataSource.IsNull() ||
       ! myNonDeformedDataSource->GetGeom ( ID, IsElement, Coords, NbNodes, Type ) )
    return Standard_False;
  
  if ( Type==MeshVS_ET_Node )
  {
    gp_Vec Vect;
    if ( ! GetVector( ID, Vect ) )
      return Standard_False;
    shiftCoord ( Coords, 1, myMagnify * Vect );
  }
  else
  {
    MeshVS_Buffer aNodesBuf (NbNodes * sizeof(Standard_Integer));
    TColStd_Array1OfInteger aNodes (aNodesBuf, 1, NbNodes);
    if ( !myNonDeformedDataSource->GetNodesByElement ( ID, aNodes, NbNodes ) )
      return Standard_False;
    for ( int i=1; i <= NbNodes; i++ )
    {
      gp_Vec Vect;
      if ( ! GetVector( aNodes(i), Vect ) )
        return Standard_False;
      shiftCoord ( Coords, i, myMagnify * Vect );
    }
  }
  return Standard_True;
}

//================================================================
// Function : GetGeomType
// Purpose  :
//================================================================
Standard_Boolean MeshVS_DeformedDataSource::GetGeomType( const Standard_Integer ID,
                                                         const Standard_Boolean IsElement,
                                                         MeshVS_EntityType& Type) const
{
  if ( myNonDeformedDataSource.IsNull() )
    return Standard_False;
  else
    return myNonDeformedDataSource->GetGeomType( ID, IsElement, Type );
}

//================================================================
// Function : Get3DGeom
// Purpose  :
//================================================================
Standard_Boolean MeshVS_DeformedDataSource::Get3DGeom( const Standard_Integer ID, 
                                                       Standard_Integer& NbNodes,
                                                       Handle( MeshVS_HArray1OfSequenceOfInteger )& Data ) const
{
  if( myNonDeformedDataSource.IsNull() )
    return Standard_False;
  else
    return myNonDeformedDataSource->Get3DGeom( ID, NbNodes, Data );
}

//================================================================
// Function : GetAddr
// Purpose  :
//================================================================
Standard_Address MeshVS_DeformedDataSource::GetAddr( const Standard_Integer ID,
                                                     const Standard_Boolean IsElement ) const
{
  if ( myNonDeformedDataSource.IsNull() )
    return 0;
  else
    return myNonDeformedDataSource->GetAddr( ID, IsElement );
}

//================================================================
// Function : GetNodesByElement
// Purpose  :
//================================================================
Standard_Boolean MeshVS_DeformedDataSource::GetNodesByElement
                         (const Standard_Integer   ID,
                          TColStd_Array1OfInteger& NodeIDs,
                          Standard_Integer&        NbNodes) const
{
  if ( myNonDeformedDataSource.IsNull() )
    return Standard_False;
  else
    return myNonDeformedDataSource->GetNodesByElement( ID, NodeIDs, NbNodes );
}

//================================================================
// Function : GetAllNodes
// Purpose  :
//================================================================
const TColStd_PackedMapOfInteger& MeshVS_DeformedDataSource::GetAllNodes() const
{
  if ( myNonDeformedDataSource.IsNull() )
    return myEmptyMap;
  else
    return myNonDeformedDataSource->GetAllNodes();
}

//================================================================
// Function : GetAllElements
// Purpose  :
//================================================================
const TColStd_PackedMapOfInteger& MeshVS_DeformedDataSource::GetAllElements() const
{
  if ( myNonDeformedDataSource.IsNull() )
    return myEmptyMap;
  else
    return myNonDeformedDataSource->GetAllElements();
}

//================================================================
// Function : GetVectors
// Purpose  :
//================================================================
const MeshVS_DataMapOfIntegerVector& MeshVS_DeformedDataSource::GetVectors() const
{
  return myVectors;
}

//================================================================
// Function : SetVectors
// Purpose  :
//================================================================
void MeshVS_DeformedDataSource::SetVectors( const MeshVS_DataMapOfIntegerVector& Map )
{
  myVectors = Map;
}

//================================================================
// Function : GetVector
// Purpose  :
//================================================================
Standard_Boolean MeshVS_DeformedDataSource::GetVector( const Standard_Integer ID,
                                                       gp_Vec& Vect ) const
{
  Standard_Boolean aRes = myVectors.IsBound ( ID );
  if ( aRes )
    Vect = myVectors.Find ( ID );
  return aRes;
}

//================================================================
// Function : SetVector
// Purpose  :
//================================================================
void MeshVS_DeformedDataSource::SetVector( const Standard_Integer ID,
                                           const gp_Vec& Vect )
{
  Standard_Boolean aRes = myVectors.IsBound ( ID );
  if ( aRes )
    myVectors.ChangeFind ( ID ) = Vect;
  else
    myVectors.Bind( ID, Vect );
}

//================================================================
// Function : SetNonDeformedDataSource
// Purpose  :
//================================================================
void MeshVS_DeformedDataSource::SetNonDeformedDataSource( const Handle(MeshVS_DataSource)& theDS )
{
  myNonDeformedDataSource = theDS;
}

//================================================================
// Function : GetNonDeformedDataSource
// Purpose  :
//================================================================
Handle_MeshVS_DataSource MeshVS_DeformedDataSource::GetNonDeformedDataSource() const
{
  return myNonDeformedDataSource;
}

//================================================================
// Function : SetMagnify
// Purpose  :
//================================================================
void MeshVS_DeformedDataSource::SetMagnify( const Standard_Real theMagnify )
{
  if ( theMagnify<=0 )
    myMagnify = 1.0;
  else
    myMagnify = theMagnify;
}

//================================================================
// Function : GetMagnify
// Purpose  :
//================================================================
Standard_Real MeshVS_DeformedDataSource::GetMagnify() const
{
  return myMagnify;
}