avtZonePickQuery.C 9.46 KB
Newer Older
hrchilds's avatar
hrchilds committed
1
2
3
4
5
6
// ************************************************************************* //
//                              avtZonePickQuery.C                           //
// ************************************************************************* //

#include <avtZonePickQuery.h>

hrchilds's avatar
hrchilds committed
7
8
#include <vtkCellData.h>
#include <vtkDataArray.h>
hrchilds's avatar
hrchilds committed
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
#include <vtkDataSet.h>
#include <vtkFieldData.h>
#include <vtkVisItUtility.h>

#include <avtMatrix.h>
#include <avtTerminatingSource.h>
#include <avtVector.h>

#include <DebugStream.h>


// ****************************************************************************
//  Method: avtZonePickQuery constructor
//
//  Programmer: Kathleen Bonnell
//  Creation:   May 20, 2004 
//
//  Modifications:
//
// ****************************************************************************

avtZonePickQuery::avtZonePickQuery()
{
}


// ****************************************************************************
//  Method: avtZonePickQuery 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 20, 2004 
//
//  Modifications:
//
// ****************************************************************************

avtZonePickQuery::~avtZonePickQuery()
{
}


// ****************************************************************************
//  Method: avtZonePickQuery::SetInvTransform
//
//  Purpose:
//      Sets the inverseTransform, used to return correct pick points. 
//
//  Programmer: Kathleen Bonnell
//  Creation:   May 20, 2004 
//
// ****************************************************************************

void
avtZonePickQuery::SetInvTransform(const avtMatrix *m)
{
    transform =  m;
}



// ****************************************************************************
//  Method: avtZonePickQuery::Execute
//
//  Purpose:
//      Processes a single domain.
//
//  Programmer: Kathleen Bonnell  
//  Creation:   May 20, 2004
//
//  Modifications:
hrchilds's avatar
hrchilds committed
83
84
85
//    Kathleen Bonnell, Tue Aug 10 09:12:54 PDT 2004
//    When material selection has been applied, ensure that RetrieveVarInfo
//    will be using the correct zone id for this dataset.
hrchilds's avatar
hrchilds committed
86
//
hrchilds's avatar
hrchilds committed
87
88
89
90
//    Kathleen Bonnell, Thu Aug 26 09:50:31 PDT 2004 
//    Handle case when pickatts.domain has not yet been set. (e.g. when
//    picking 2d contour or boundary plots.)
//
hrchilds's avatar
hrchilds committed
91
92
93
94
//    Kathleen Bonnell, Mon Aug 30 17:53:58 PDT 2004
//    Modified early-return test -- split into two, and use new flag 
//    skippedLocate. 
//
hrchilds's avatar
hrchilds committed
95
96
97
98
//    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
99
100
101
102
103
104
//    Kathleen Bonnell, Tue Jun 28 10:57:39 PDT 2005 
//    Readded 'needRealId' test, modified so that Real ids are calculated only
//    under specific conditions:  we don't already know the picked Node, ghosts
//    were Created, we have the Ghosts array and the data is structured.  
//    E.g. when we are picking on the Contour plot of AMR data.
//
hrchilds's avatar
hrchilds committed
105
106
107
//    Kathleen Bonnell, Fri Jul  8 14:15:21 PDT 2005 
//    Modified test for determining if 'real' id needs to be calculated. 
//
hrchilds's avatar
hrchilds committed
108
109
110
111
112
// ****************************************************************************

void
avtZonePickQuery::Execute(vtkDataSet *ds, const int dom)
{
hrchilds's avatar
hrchilds committed
113
114
115
116
117
    if (ds == NULL || pickAtts.GetFulfilled())
    {
            return;
    }
    if (dom != pickAtts.GetDomain() && !skippedLocate)
hrchilds's avatar
hrchilds committed
118
119
120
121
122
    {
        return;
    }

    int pickedZone = pickAtts.GetElementNumber();
hrchilds's avatar
hrchilds committed
123
    int type = ds->GetDataObjectType();
hrchilds's avatar
hrchilds committed
124

hrchilds's avatar
hrchilds committed
125
126
127
128
    //
    // We may need the real Id when we are picking on a Contour of an
    // AMR mesh. 
    //
hrchilds's avatar
hrchilds committed
129
130
131
132
133
134
135
136
137
138
139
140
141
    bool needRealId = false;
    if (pickedZone == -1 && ghostType == AVT_CREATED_GHOSTS &&
        (type == VTK_STRUCTURED_GRID || type == VTK_RECTILINEAR_GRID))
    {
        if (pickAtts.GetHasMixedGhostTypes() == -1)
        {
            needRealId = vtkVisItUtility::ContainsMixedGhostZoneTypes(ds);
        }
        else 
        {
            needRealId = (pickAtts.GetHasMixedGhostTypes() == 1);
        }
    }
hrchilds's avatar
hrchilds committed
142
143
144
145
146
147
148
149
150
151
152

    if (pickedZone == -1)
    {
        //
        //  If a valid zone hasn't already been determined, locate it now.
        //  
        float *cellPoint  = pickAtts.GetCellPoint();
        pickedZone = vtkVisItUtility::FindCell(ds, cellPoint);

        if (pickedZone == -1)
        {
hrchilds's avatar
hrchilds committed
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
            if (pickAtts.GetDomain() != -1)
            {
                //
                //  If a valid zone still hasn't been found, and we were
                //  expecting one for this domain, there's some kind of 
                //  problem. 
                //  
                pickAtts.SetDomain(-1);
                pickAtts.SetElementNumber(-1);
                debug5 << "PICK BIG PROBLEM!  Could not find zone"
                       << "corresponding to pick point" << endl;
                pickAtts.SetErrorMessage("Pick encountered an internal error"
                    " (could not find zone corresponding to pick point).\n"
                    "Please contact a VisIt developer"); 
                pickAtts.SetError(true);
            }
hrchilds's avatar
hrchilds committed
169
170
            return;
        }
hrchilds's avatar
hrchilds committed
171
172
173
174
175

        vtkDataArray *ghost = ds->GetCellData()->GetArray("avtGhostZones");
        if (ghost && ghost->GetTuple1(pickedZone) > 0)
            return;

hrchilds's avatar
hrchilds committed
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
        pickAtts.SetElementNumber(pickedZone);
    }

    if (!pickAtts.GetMatSelected())
    {
        bool success = false;
        GetZoneCoords(ds, pickedZone);
        success = RetrieveNodes(ds, pickedZone);
        if (success)
        {
            pickAtts.SetElementNumber(pickedZone);
            RetrieveVarInfo(ds);
            pickAtts.SetFulfilled(true);
        }
        else
        {
            // the zone/node could not be found, no further processing required.
            // 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
204
205
206
207
208
209
    //
    //  The database needs a valid domain
    // 
    if (pickAtts.GetDomain() == -1)
        pickAtts.SetDomain(dom);
    
hrchilds's avatar
hrchilds committed
210
211
212
213
214
215
    if (needRealId && pickAtts.GetMatSelected())
    {
        SetRealIds(ds);
        pickAtts.SetElementNumber(pickAtts.GetRealElementNumber());
    }

hrchilds's avatar
hrchilds committed
216
217
218
219
220
221
222
    //
    //  Allow the database to add any missing information.
    // 
    src->Query(&pickAtts);

    if (pickAtts.GetMatSelected())
    {
hrchilds's avatar
hrchilds committed
223
224
225
226
227
        //
        // The zone id stored in ElementNumber will not be correct relative
        // to this dataset.  Retrieve the correct one for use with 
        // RetrieveVarInfo, then reset it.
        //
hrchilds's avatar
hrchilds committed
228
229
230
        int currentZone = GetCurrentZoneForOriginal(ds, 
                            pickAtts.GetElementNumber());
        RetrieveVarInfo(ds, currentZone, pickAtts.GetIncidentElements());
hrchilds's avatar
hrchilds committed
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
    }

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

hrchilds's avatar
hrchilds committed
250
251
252
253
254
255
256
257
258
259
    if (needRealId && !pickAtts.GetMatSelected())
    {
        SetRealIds(ds);
        //
        // Put the real ids in the correct spot for output.
        //
        pickAtts.SetElementNumber(pickAtts.GetRealElementNumber());
        pickAtts.SetIncidentElements(pickAtts.GetRealIncidentElements());
    }

hrchilds's avatar
hrchilds committed
260
261
262
263
264
265
266
267
268
269
270
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
321
322
323
    pickAtts.SetElementNumber(pickAtts.GetElementNumber() + cellOrigin);
    //
    // If the points of this dataset have been transformed, and we know 
    // the inverse transform matrix, transform the pick point that will 
    // be displayed in the pick info window.
    //
    if (transform != NULL)
    {
        avtVector v1(pickAtts.GetPickPoint());
        v1 = (*transform) * v1;
        // 
        // PickPoint is used for placing the pick letter, so set
        // this tranformed point in CellPoint instead.
        // 
        float ppt[3] = { v1.x, v1.y, v1.z };
        pickAtts.SetCellPoint(ppt);
    }
    else 
    {
        // 
        // CellPoint may have been 'fudged' towards the cell center by
        // avtLocateCellQuery.  Make sure the point that will be displayed
        // is not that 'fudged' point.
        // 
        pickAtts.SetCellPoint(pickAtts.GetPickPoint());
    }
}



// ****************************************************************************
//  Method: avtZonePickQuery::Preparation
//
//  Purpose:
//    Allows this pick to modify pickAtts before filters are applied.  
//
//  Programmer: Kathleen Bonnell
//  Creation:   June 2, 2004 
//
// ****************************************************************************

void
avtZonePickQuery::Preparation()
{
    //
    // Transform the point that will be used in locating the cell. 
    //
    float *cellPoint  = pickAtts.GetCellPoint();
    if (transform != NULL)
    {
        //
        // Transform the intersection point back to original space.
        //
        avtVector v1(cellPoint);
        v1 = (*transform) * v1;
        cellPoint[0] = v1.x;
        cellPoint[1] = v1.y;
        cellPoint[2] = v1.z;
        //
        // Reset the cell point to the transformed point.
        //
        pickAtts.SetCellPoint(cellPoint);
    }
}
hrchilds's avatar
hrchilds committed
324