avtPickByNodeQuery.C 12.1 KB
Newer Older
hrchilds's avatar
hrchilds committed
1
2
/*****************************************************************************
*
3
* Copyright (c) 2000 - 2014, Lawrence Livermore National Security, LLC
hrchilds's avatar
hrchilds committed
4
* Produced at the Lawrence Livermore National Laboratory
brugger's avatar
   
brugger committed
5
* LLNL-CODE-442911
hrchilds's avatar
hrchilds committed
6
7
* All rights reserved.
*
brugger's avatar
   
brugger committed
8
* This file is  part of VisIt. For  details, see https://visit.llnl.gov/.  The
hrchilds's avatar
hrchilds committed
9
10
11
12
13
14
15
16
17
18
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution  and  use  in  source  and  binary  forms,  with  or  without
* modification, are permitted provided that the following conditions are met:
*
*  - Redistributions of  source code must  retain the above  copyright notice,
*    this list of conditions and the disclaimer below.
*  - Redistributions in binary form must reproduce the above copyright notice,
*    this  list of  conditions  and  the  disclaimer (as noted below)  in  the
brugger's avatar
   
brugger committed
19
20
21
*    documentation and/or other materials provided with the distribution.
*  - Neither the name of  the LLNS/LLNL nor the names of  its contributors may
*    be used to endorse or promote products derived from this software without
hrchilds's avatar
hrchilds committed
22
23
24
25
26
*    specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR  IMPLIED WARRANTIES, INCLUDING,  BUT NOT  LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE
brugger's avatar
   
brugger committed
27
28
29
* ARE  DISCLAIMED. IN  NO EVENT  SHALL LAWRENCE  LIVERMORE NATIONAL  SECURITY,
* LLC, THE  U.S.  DEPARTMENT OF  ENERGY  OR  CONTRIBUTORS BE  LIABLE  FOR  ANY
* DIRECT,  INDIRECT,   INCIDENTAL,   SPECIAL,   EXEMPLARY,  OR   CONSEQUENTIAL
hrchilds's avatar
hrchilds committed
30
31
32
33
34
35
36
37
38
* DAMAGES (INCLUDING, BUT NOT  LIMITED TO, PROCUREMENT OF  SUBSTITUTE GOODS OR
* SERVICES; LOSS OF  USE, DATA, OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER
* CAUSED  AND  ON  ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT
* LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY  WAY
* OUT OF THE  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/

hrchilds's avatar
hrchilds committed
39
40
41
42
43
44
45
46
// ************************************************************************* //
//                           avtPickByNodeQuery.C                            //
// ************************************************************************* //

#include <avtPickByNodeQuery.h>

#include <vtkDataSet.h>
#include <vtkFieldData.h>
hrchilds's avatar
hrchilds committed
47
#include <vtkPointData.h>
hrchilds's avatar
hrchilds committed
48
49
50
51
52
#include <vtkPoints.h>
#include <vtkIntArray.h>
#include <vtkVisItUtility.h>

#include <avtMatrix.h>
hrchilds's avatar
hrchilds committed
53
#include <avtOriginatingSource.h>
hrchilds's avatar
hrchilds committed
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
#include <avtVector.h>

#include <BadNodeException.h>



// ****************************************************************************
//  Method: avtPickByNodeQuery constructor
//
//  Programmer: Kathleen Bonnell
//  Creation:    May 10, 2004
//
//  Modifications:
//
// ****************************************************************************

avtPickByNodeQuery::avtPickByNodeQuery()
{
}


// ****************************************************************************
//  Method: avtPickByNodeQuery destructor
//
//  Purpose:
//      Defines the destructor.  Note: this should not be inlined in the header
//      because it causes problems for certain compilers.
//
//  Programmer: Kathleen Bonnell 
//  Creation:   May 10, 2004 
//
//  Modifications:
//
// ****************************************************************************

avtPickByNodeQuery::~avtPickByNodeQuery()
{
}


// ****************************************************************************
//  Method: avtPickByNodeQuery::Execute
//
//  Purpose:
//      Processes a single domain.
//
//  Programmer: Kathleen Bonnell  
//  Creation:   May 10, 2004
//
//  Modifications:
hrchilds's avatar
hrchilds committed
104
105
//    Kathleen Bonnell, Thu Jul  8 16:42:05 PDT 2004
//    Changed the way that nodeid is modified when accounting for ghost zones.
hrchilds's avatar
hrchilds committed
106
//
hrchilds's avatar
hrchilds committed
107
108
109
110
//    Kathleen Bonnell, Thu Sep 23 17:38:15 PDT 2004 
//    Removed 'needRealId' test, no longer needed (we are reporting ghost
//    zones when ghostType == AVT_HAS_GHOSTS). 
//
hrchilds's avatar
hrchilds committed
111
112
113
//    Kathleen Bonnell, Wed Dec 15 17:24:27 PST 2004 
//    Added logic to handle case when chosen node is to be considered global.
//
hrchilds's avatar
hrchilds committed
114
115
116
117
//    Kathleen Bonnell, Mon Dec 20 08:33:16 PST 2004 
//    Added early return when DB should determine local id from global, and 
//    pickAtts not fulfilled when returned from the query.
//
hrchilds's avatar
hrchilds committed
118
119
120
121
//    Kathleen Bonnell, Tue Feb  8 08:29:44 PST 2005 
//    Added test for presence of avtGlobalNodeNumbers array, create error
//    message when not available but should be.
//
hrchilds's avatar
hrchilds committed
122
123
124
//    Hank Childs, Thu Mar 10 10:36:51 PST 2005
//    Fix memory leak.
//
hrchilds's avatar
hrchilds committed
125
126
127
//    Kathleen Bonnell, Wed May 11 17:14:03 PDT 200 
//    Convert varnmames to Global names when the DB supplied the ids. 
//
hrchilds's avatar
hrchilds committed
128
129
130
//    Kathleen Bonnell, Tue Jan 30 16:25:23 PST 2007 
//    Send nodeid to RetrieveVarInfo.
//
hrchilds's avatar
hrchilds committed
131
132
//    Mark C. Miller, Tue Mar 27 08:39:55 PDT 2007
//    Added support for node origin
bonnell's avatar
bonnell committed
133
134
135
136
//
//    Kathleen Bonnell, Mon Oct  8 18:54:53 PDT 2007 
//    Completed support for node origin. 
//
137
138
139
//    Kathleen Biagas, Tue Jul 22 11:38:50 MST 2014
//    Don't convert to Global ids unless user wants ids shown as global.
//
hrchilds's avatar
hrchilds committed
140
141
142
143
144
// ****************************************************************************

void
avtPickByNodeQuery::Execute(vtkDataSet *ds, const int dom)
{
hrchilds's avatar
hrchilds committed
145
    if (pickAtts.GetFulfilled() || ds == NULL)
hrchilds's avatar
hrchilds committed
146
147
148
149
    {
        return;
    }

hrchilds's avatar
hrchilds committed
150
151
152
153
154
    if (!pickAtts.GetElementIsGlobal())
    {
        if (dom != pickAtts.GetDomain())
            return;
    }
hrchilds's avatar
hrchilds committed
155
156
157
158
    else if (ds->GetPointData()->GetArray("avtGlobalNodeNumbers") == NULL)
    {
        pickAtts.SetDomain(-1);
        pickAtts.SetElementNumber(-1);
hrchilds's avatar
hrchilds committed
159
160
161
        pickAtts.SetErrorMessage("Pick could not be performed because a global"
                                 " node id was specified for Pick but the mesh"
                                 " does not contain global node information.");
hrchilds's avatar
hrchilds committed
162
163
164
        pickAtts.SetError(true);
        return; 
    }
hrchilds's avatar
hrchilds committed
165

hrchilds's avatar
hrchilds committed
166
    int nodeid = pickAtts.GetElementNumber();
bonnell's avatar
bonnell committed
167
    int usernodeid = nodeid;
hrchilds's avatar
hrchilds committed
168
169
170
    int maxEls = ds->GetNumberOfPoints(); 

    // Verify the node number is in range.
hrchilds's avatar
hrchilds committed
171
    if (!pickAtts.GetElementIsGlobal() && (nodeid < 0 || nodeid >= maxEls))
hrchilds's avatar
hrchilds committed
172
    {
hrchilds's avatar
hrchilds committed
173
        EXCEPTION2(BadNodeException, nodeid+nodeOrigin, maxEls+nodeOrigin);
hrchilds's avatar
hrchilds committed
174
175
    } 

hrchilds's avatar
hrchilds committed
176
    bool DBsuppliedNodeId = true;
hrchilds's avatar
hrchilds committed
177
178
    if (!pickAtts.GetMatSelected() && ghostType != AVT_CREATED_GHOSTS)
    {
hrchilds's avatar
hrchilds committed
179
180
        if (pickAtts.GetElementIsGlobal())
        {
bonnell's avatar
bonnell committed
181
182
183
            usernodeid = vtkVisItUtility::GetLocalElementForGlobal(ds, 
                          usernodeid, false);
            if (usernodeid == -1)
hrchilds's avatar
hrchilds committed
184
                return;
bonnell's avatar
bonnell committed
185
            nodeid = usernodeid;
hrchilds's avatar
hrchilds committed
186
            pickAtts.SetGlobalElement(pickAtts.GetElementNumber());
hrchilds's avatar
hrchilds committed
187
188
            DBsuppliedNodeId = false;
        }
hrchilds's avatar
hrchilds committed
189
190
191
        GetNodeCoords(ds, nodeid);    
        if (RetrieveZones(ds, nodeid))
        {
hrchilds's avatar
hrchilds committed
192
            RetrieveVarInfo(ds, nodeid);
hrchilds's avatar
hrchilds committed
193
194
195
196
            pickAtts.SetFulfilled(true);
        }
        else
        {
hrchilds's avatar
hrchilds committed
197
198
            // the incidient zones could not be found, 
            // no further processing required.
hrchilds's avatar
hrchilds committed
199
200
201
202
203
204
205
206
207
208
209
            // SetDomain and ElementNumber to -1 to indicate failure. 
            pickAtts.SetDomain(-1);
            pickAtts.SetElementNumber(-1);
            pickAtts.SetErrorMessage("Pick encountered an internal "
                "error (could not find incident elements).\n"
                "Please contact a VisIt developer"); 
            pickAtts.SetError(true);
            return; 
        }
    }

hrchilds's avatar
hrchilds committed
210
211
212
    if (pickAtts.GetElementIsGlobal())
        pickAtts.SetDomain(dom);

hrchilds's avatar
hrchilds committed
213
214
215
216
217
    //
    //  Allow the database to add any missing information.
    // 
    src->Query(&pickAtts);

hrchilds's avatar
hrchilds committed
218
219
220
    if (!pickAtts.GetFulfilled())
        return;

hrchilds's avatar
hrchilds committed
221
222
223
    if (pickAtts.GetElementIsGlobal() && DBsuppliedNodeId)
    {
        nodeid = GetCurrentNodeForOriginal(ds, pickAtts.GetElementNumber());
bonnell's avatar
bonnell committed
224
        usernodeid = nodeid;
225
226
        if (pickAtts.GetShowGlobalIds())
            ConvertElNamesToGlobal();
hrchilds's avatar
hrchilds committed
227
    }
bonnell's avatar
bonnell committed
228
    pickAtts.SetElementNumber(usernodeid + nodeOrigin);
hrchilds's avatar
hrchilds committed
229
    if (pickAtts.GetMatSelected())
hrchilds's avatar
hrchilds committed
230
231
232
233
234
235
236
237
    {
        //
        // The zone numbers stored in IncidentElements are not the correct
        // ones to use with this dataset ... get the correct ones to use
        // with RetrieveVarInfo, then reset them.
        //
        intVector pickedZones = pickAtts.GetIncidentElements();
        intVector currentZones = GetCurrentZoneForOriginal(ds, pickedZones); 
hrchilds's avatar
hrchilds committed
238
239
240
241
        if (!pickAtts.GetElementIsGlobal())
            RetrieveVarInfo(ds, pickAtts.GetElementNumber(), currentZones); 
        else 
            RetrieveVarInfo(ds, nodeid, currentZones); 
hrchilds's avatar
hrchilds committed
242
    }
hrchilds's avatar
hrchilds committed
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265

    //
    // Set the domain and zone of pickAtts in relation to the
    // blockOrigin and cellOrigin of the problem.  
    // 
    if (singleDomain)
    {
        //
        // Indicate that there was only one domain.
        // We don't report the domain number for single-domain problems.
        //
        pickAtts.SetDomain(-1);
    }
    else
    {
        pickAtts.SetDomain(dom+blockOrigin);
    }

    //
    // PickPoint determines where on the screen the pick letter will be
    // placed.  This should be the actual node coordinates if the plot was 
    // NOT transformed.
    //
hrchilds's avatar
hrchilds committed
266
267
    // If the plot was transformed && the transform is available, 
    // then transform the node coordinates.
hrchilds's avatar
hrchilds committed
268
269
270
271
272
    //
    // If the plot was transformed && inverseTransform is NOT available,
    // there is no way to determine the location of the picked node in
    // transformed space, so  ????????
    //
hrchilds's avatar
hrchilds committed
273
    double coord[3];
hrchilds's avatar
hrchilds committed
274
    ds->GetPoint(nodeid, coord);
hrchilds's avatar
hrchilds committed
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
    pickAtts.SetCellPoint(coord);
    if (transform != NULL)
    {
        avtVector v1(coord);
        v1 = (*transform) *v1;
        coord[0] = v1.x;
        coord[1] = v1.y;
        coord[2] = v1.z;
        pickAtts.SetPickPoint(coord);
    }
    else if (pickAtts.GetNeedTransformMessage())
    {
        //
        // Points were transformed, but we don't need the message because
        // we are displaying the real node coords to the user in pick output.
        //
        pickAtts.SetNeedTransformMessage(false);
        //
        // We need to query the actual data to find a location for the
        // pick letter.  
        //
        pickAtts.SetNeedActualCoords(true);
        if (!pickAtts.GetMatSelected() && ghostType != AVT_CREATED_GHOSTS)
        {
            //
            // We have used a 'ghosted' id to query here, but have set the
            // element number back to what the user requested.  Tell the
            // locator code that it should use the RealElementNumber in
            // determining the node location.
            //
            pickAtts.SetRealElementNumber(nodeid);
        }
    }
    else
    {
        pickAtts.SetPickPoint(coord);
    }
}


// ****************************************************************************
//  Method: avtPickByNodeQuery::Preparation
//
//  Purpose:
//    Allows this pick query to modify pickAtts before filters are applied.    
//
//  Programmer: Kathleen Bonnell  
//  Creation:   May 10, 2004 
//
//  Modifications:
hrchilds's avatar
hrchilds committed
325
326
327
//    Kathleen Bonnell, Wed Dec 15 17:24:27 PST 2004
//    Set domain to -1 (so that no domain-restriction is performed) if
//    the node is global.
hrchilds's avatar
hrchilds committed
328
//
hrchilds's avatar
hrchilds committed
329
330
331
//    Kathleen Bonnell, Tue Nov  8 10:45:43 PST 2005
//    Added avtDatAttributes arg.
//
bonnell's avatar
bonnell committed
332
333
334
//    Kathleen Bonnell, Mon Oct  8 18:54:53 PDT 2007 
//    Add support for node origin. 
//
hrchilds's avatar
hrchilds committed
335
336
337
// ****************************************************************************

void
hrchilds's avatar
hrchilds committed
338
avtPickByNodeQuery::Preparation(const avtDataAttributes &)
hrchilds's avatar
hrchilds committed
339
{
hrchilds's avatar
hrchilds committed
340
341
342
343
    if (!pickAtts.GetElementIsGlobal())
    {
        int dom = pickAtts.GetDomain() - blockOrigin;
        pickAtts.SetDomain(dom < 0 ? 0 : dom);
bonnell's avatar
bonnell committed
344
345
        int node = pickAtts.GetElementNumber() - nodeOrigin;
        pickAtts.SetElementNumber(node < 0 ? 0 : node);
hrchilds's avatar
hrchilds committed
346
347
348
349
350
    }
    else 
    {
        pickAtts.SetDomain(-1);
    }
hrchilds's avatar
hrchilds committed
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
}


// ****************************************************************************
//  Method: avtPickByNodeQuery::SetTransform
//
//  Purpose:
//    Set the transform needed by this pick. 
//
//  Programmer: Kathleen Bonnell  
//  Creation:   May 10, 2004 
//
//  Modifications:
//
// ****************************************************************************

void
avtPickByNodeQuery::SetTransform(const avtMatrix *m)
{
    transform = m;
}