avtPickByNodeQuery.C 13.3 KB
Newer Older
hrchilds's avatar
hrchilds committed
1 2
/*****************************************************************************
*
bonnell's avatar
bonnell committed
3
* Copyright (c) 2000 - 2017, 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
#include <avtVector.h>

#include <BadNodeException.h>
57
#include <float.h>
hrchilds's avatar
hrchilds committed
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


// ****************************************************************************
//  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.
//
140 141 142
//    Matt Larsen, Mon Jul 3 07:15:55 PDT 2017
//    Adding support for picking a node by label. 
//
hrchilds's avatar
hrchilds committed
143 144 145 146 147
// ****************************************************************************

void
avtPickByNodeQuery::Execute(vtkDataSet *ds, const int dom)
{
148 149
    bool pickByLabel = pickAtts.GetElementLabel() != "";

hrchilds's avatar
hrchilds committed
150
    if (pickAtts.GetFulfilled() || ds == NULL)
hrchilds's avatar
hrchilds committed
151 152 153 154
    {
        return;
    }

hrchilds's avatar
hrchilds committed
155 156 157 158 159
    if (!pickAtts.GetElementIsGlobal())
    {
        if (dom != pickAtts.GetDomain())
            return;
    }
160 161
    else if (ds->GetPointData()->GetArray("avtGlobalNodeNumbers") == NULL && 
             !pickByLabel)
hrchilds's avatar
hrchilds committed
162 163 164
    {
        pickAtts.SetDomain(-1);
        pickAtts.SetElementNumber(-1);
hrchilds's avatar
hrchilds committed
165 166 167
        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
168 169 170
        pickAtts.SetError(true);
        return; 
    }
hrchilds's avatar
hrchilds committed
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
    int nodeid;

    if(pickByLabel)
    {
        std::string nodeLabel = pickAtts.GetElementLabel();
        bool isZone = false;
        int id;
        bool error = GetElementIdByLabel(nodeLabel, isZone, id, dom); 

        if(error)
        {
            pickAtts.SetDomain(-1);
            pickAtts.SetElementNumber(-1);
            pickAtts.SetErrorMessage("Pick could not be performed because a node "
                                     "label was specified for Pick but the mesh "
                                     "does not contain zone label information.");
            pickAtts.SetError(true);
            return;
        }

        if( id != -1 )
        {
            nodeid = id;
        }
        else
        {
            return;
        }
    }
    else
    {
        nodeid = pickAtts.GetElementNumber();
    }

bonnell's avatar
bonnell committed
206
    int usernodeid = nodeid;
hrchilds's avatar
hrchilds committed
207 208 209
    int maxEls = ds->GetNumberOfPoints(); 

    // Verify the node number is in range.
hrchilds's avatar
hrchilds committed
210
    if (!pickAtts.GetElementIsGlobal() && (nodeid < 0 || nodeid >= maxEls))
hrchilds's avatar
hrchilds committed
211
    {
hrchilds's avatar
hrchilds committed
212
        EXCEPTION2(BadNodeException, nodeid+nodeOrigin, maxEls+nodeOrigin);
hrchilds's avatar
hrchilds committed
213 214
    } 

hrchilds's avatar
hrchilds committed
215
    bool DBsuppliedNodeId = true;
hrchilds's avatar
hrchilds committed
216 217
    if (!pickAtts.GetMatSelected() && ghostType != AVT_CREATED_GHOSTS)
    {
218
        if (pickAtts.GetElementIsGlobal() && !pickByLabel)
hrchilds's avatar
hrchilds committed
219
        {
bonnell's avatar
bonnell committed
220 221 222
            usernodeid = vtkVisItUtility::GetLocalElementForGlobal(ds, 
                          usernodeid, false);
            if (usernodeid == -1)
hrchilds's avatar
hrchilds committed
223
                return;
bonnell's avatar
bonnell committed
224
            nodeid = usernodeid;
hrchilds's avatar
hrchilds committed
225
            pickAtts.SetGlobalElement(pickAtts.GetElementNumber());
hrchilds's avatar
hrchilds committed
226 227
            DBsuppliedNodeId = false;
        }
hrchilds's avatar
hrchilds committed
228 229 230
        GetNodeCoords(ds, nodeid);    
        if (RetrieveZones(ds, nodeid))
        {
hrchilds's avatar
hrchilds committed
231
            RetrieveVarInfo(ds, nodeid);
hrchilds's avatar
hrchilds committed
232 233 234 235
            pickAtts.SetFulfilled(true);
        }
        else
        {
hrchilds's avatar
hrchilds committed
236 237
            // the incidient zones could not be found, 
            // no further processing required.
hrchilds's avatar
hrchilds committed
238 239 240 241 242 243 244 245 246 247 248
            // 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
249 250 251
    if (pickAtts.GetElementIsGlobal())
        pickAtts.SetDomain(dom);

hrchilds's avatar
hrchilds committed
252 253 254 255 256
    //
    //  Allow the database to add any missing information.
    // 
    src->Query(&pickAtts);

hrchilds's avatar
hrchilds committed
257 258 259
    if (!pickAtts.GetFulfilled())
        return;

hrchilds's avatar
hrchilds committed
260 261 262
    if (pickAtts.GetElementIsGlobal() && DBsuppliedNodeId)
    {
        nodeid = GetCurrentNodeForOriginal(ds, pickAtts.GetElementNumber());
bonnell's avatar
bonnell committed
263
        usernodeid = nodeid;
264 265
        if (pickAtts.GetShowGlobalIds())
            ConvertElNamesToGlobal();
hrchilds's avatar
hrchilds committed
266
    }
bonnell's avatar
bonnell committed
267
    pickAtts.SetElementNumber(usernodeid + nodeOrigin);
hrchilds's avatar
hrchilds committed
268
    if (pickAtts.GetMatSelected())
hrchilds's avatar
hrchilds committed
269 270 271 272 273 274 275 276
    {
        //
        // 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
277 278 279 280
        if (!pickAtts.GetElementIsGlobal())
            RetrieveVarInfo(ds, pickAtts.GetElementNumber(), currentZones); 
        else 
            RetrieveVarInfo(ds, nodeid, currentZones); 
hrchilds's avatar
hrchilds committed
281
    }
hrchilds's avatar
hrchilds committed
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304

    //
    // 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
305 306
    // If the plot was transformed && the transform is available, 
    // then transform the node coordinates.
hrchilds's avatar
hrchilds committed
307 308 309 310 311
    //
    // 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
312
    double coord[3];
313 314 315 316 317 318 319 320 321 322 323 324
    double *p = pickAtts.GetCellPoint();
    if (p[0] == FLT_MAX)
    {
        ds->GetPoint(nodeid, coord);
        pickAtts.SetCellPoint(coord);
    }
    else
    {
        coord[0] = p[0];
        coord[1] = p[1];
        coord[2] = p[2];
    }
hrchilds's avatar
hrchilds committed
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
    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
374 375 376
//    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
377
//
hrchilds's avatar
hrchilds committed
378 379 380
//    Kathleen Bonnell, Tue Nov  8 10:45:43 PST 2005
//    Added avtDatAttributes arg.
//
bonnell's avatar
bonnell committed
381 382 383
//    Kathleen Bonnell, Mon Oct  8 18:54:53 PDT 2007 
//    Add support for node origin. 
//
hrchilds's avatar
hrchilds committed
384 385 386
// ****************************************************************************

void
hrchilds's avatar
hrchilds committed
387
avtPickByNodeQuery::Preparation(const avtDataAttributes &)
hrchilds's avatar
hrchilds committed
388
{
hrchilds's avatar
hrchilds committed
389 390 391 392
    if (!pickAtts.GetElementIsGlobal())
    {
        int dom = pickAtts.GetDomain() - blockOrigin;
        pickAtts.SetDomain(dom < 0 ? 0 : dom);
bonnell's avatar
bonnell committed
393 394
        int node = pickAtts.GetElementNumber() - nodeOrigin;
        pickAtts.SetElementNumber(node < 0 ? 0 : node);
hrchilds's avatar
hrchilds committed
395 396 397 398 399
    }
    else 
    {
        pickAtts.SetDomain(-1);
    }
hrchilds's avatar
hrchilds committed
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
}


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