avtPickByNodeQuery.C 12 KB
Newer Older
hrchilds's avatar
hrchilds committed
1
2
/*****************************************************************************
*
brugger's avatar
   
brugger committed
3
* Copyright (c) 2000 - 2012, 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. 
//
hrchilds's avatar
hrchilds committed
137
138
139
140
141
// ****************************************************************************

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

hrchilds's avatar
hrchilds committed
147
148
149
150
151
    if (!pickAtts.GetElementIsGlobal())
    {
        if (dom != pickAtts.GetDomain())
            return;
    }
hrchilds's avatar
hrchilds committed
152
153
154
155
    else if (ds->GetPointData()->GetArray("avtGlobalNodeNumbers") == NULL)
    {
        pickAtts.SetDomain(-1);
        pickAtts.SetElementNumber(-1);
hrchilds's avatar
hrchilds committed
156
157
158
        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
159
160
161
        pickAtts.SetError(true);
        return; 
    }
hrchilds's avatar
hrchilds committed
162

hrchilds's avatar
hrchilds committed
163
    int nodeid = pickAtts.GetElementNumber();
bonnell's avatar
bonnell committed
164
    int usernodeid = nodeid;
hrchilds's avatar
hrchilds committed
165
166
167
    int maxEls = ds->GetNumberOfPoints(); 

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

hrchilds's avatar
hrchilds committed
173
    bool DBsuppliedNodeId = true;
hrchilds's avatar
hrchilds committed
174
175
    if (!pickAtts.GetMatSelected() && ghostType != AVT_CREATED_GHOSTS)
    {
hrchilds's avatar
hrchilds committed
176
177
        if (pickAtts.GetElementIsGlobal())
        {
bonnell's avatar
bonnell committed
178
179
180
            usernodeid = vtkVisItUtility::GetLocalElementForGlobal(ds, 
                          usernodeid, false);
            if (usernodeid == -1)
hrchilds's avatar
hrchilds committed
181
                return;
bonnell's avatar
bonnell committed
182
            nodeid = usernodeid;
hrchilds's avatar
hrchilds committed
183
            pickAtts.SetGlobalElement(pickAtts.GetElementNumber());
hrchilds's avatar
hrchilds committed
184
185
            DBsuppliedNodeId = false;
        }
hrchilds's avatar
hrchilds committed
186
187
188
        GetNodeCoords(ds, nodeid);    
        if (RetrieveZones(ds, nodeid))
        {
hrchilds's avatar
hrchilds committed
189
            RetrieveVarInfo(ds, nodeid);
hrchilds's avatar
hrchilds committed
190
191
192
193
            pickAtts.SetFulfilled(true);
        }
        else
        {
hrchilds's avatar
hrchilds committed
194
195
            // the incidient zones could not be found, 
            // no further processing required.
hrchilds's avatar
hrchilds committed
196
197
198
199
200
201
202
203
204
205
206
            // 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
207
208
209
    if (pickAtts.GetElementIsGlobal())
        pickAtts.SetDomain(dom);

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

hrchilds's avatar
hrchilds committed
215
216
217
    if (!pickAtts.GetFulfilled())
        return;

hrchilds's avatar
hrchilds committed
218
219
220
    if (pickAtts.GetElementIsGlobal() && DBsuppliedNodeId)
    {
        nodeid = GetCurrentNodeForOriginal(ds, pickAtts.GetElementNumber());
bonnell's avatar
bonnell committed
221
        usernodeid = nodeid;
hrchilds's avatar
hrchilds committed
222
        ConvertElNamesToGlobal();
hrchilds's avatar
hrchilds committed
223
    }
bonnell's avatar
bonnell committed
224
    pickAtts.SetElementNumber(usernodeid + nodeOrigin);
hrchilds's avatar
hrchilds committed
225
    if (pickAtts.GetMatSelected())
hrchilds's avatar
hrchilds committed
226
227
228
229
230
231
232
233
    {
        //
        // 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
234
235
236
237
        if (!pickAtts.GetElementIsGlobal())
            RetrieveVarInfo(ds, pickAtts.GetElementNumber(), currentZones); 
        else 
            RetrieveVarInfo(ds, nodeid, currentZones); 
hrchilds's avatar
hrchilds committed
238
    }
hrchilds's avatar
hrchilds committed
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261

    //
    // 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
262
263
    // If the plot was transformed && the transform is available, 
    // then transform the node coordinates.
hrchilds's avatar
hrchilds committed
264
265
266
267
268
    //
    // 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
269
    double coord[3];
hrchilds's avatar
hrchilds committed
270
    ds->GetPoint(nodeid, coord);
hrchilds's avatar
hrchilds committed
271
272
273
274
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
    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
321
322
323
//    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
324
//
hrchilds's avatar
hrchilds committed
325
326
327
//    Kathleen Bonnell, Tue Nov  8 10:45:43 PST 2005
//    Added avtDatAttributes arg.
//
bonnell's avatar
bonnell committed
328
329
330
//    Kathleen Bonnell, Mon Oct  8 18:54:53 PDT 2007 
//    Add support for node origin. 
//
hrchilds's avatar
hrchilds committed
331
332
333
// ****************************************************************************

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


// ****************************************************************************
//  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;
}