avtProjectFilter.C 22.9 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
5
* LLNL-CODE-442911
hrchilds's avatar
hrchilds committed
6 7
* All rights reserved.
*
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
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
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
// ************************************************************************* //
//  File: avtProjectFilter.C
// ************************************************************************* //

#include <avtProjectFilter.h>

45
#include <vtkCell.h>
hrchilds's avatar
hrchilds committed
46 47 48 49 50 51 52
#include <vtkCellData.h>
#include <vtkPointData.h>
#include <vtkRectilinearGrid.h>
#include <vtkStructuredGrid.h>
#include <vtkUnstructuredGrid.h>
#include <vtkPolyData.h>

hrchilds's avatar
hrchilds committed
53 54
#include <avtDatasetExaminer.h>
#include <avtExtents.h>
bonnell's avatar
bonnell committed
55
#include <vtkVisItUtility.h>
hrchilds's avatar
hrchilds committed
56

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


// ****************************************************************************
//  Method: avtProjectFilter constructor
//
//  Programmer: Jeremy Meredith
//  Creation:   September  3, 2004
//
// ****************************************************************************

avtProjectFilter::avtProjectFilter()
{
}


// ****************************************************************************
//  Method: avtProjectFilter destructor
//
//  Programmer: Jeremy Meredith
//  Creation:   September  3, 2004
//
//  Modifications:
//
// ****************************************************************************

avtProjectFilter::~avtProjectFilter()
{
}


// ****************************************************************************
//  Method:  avtProjectFilter::Create
//
//  Programmer: Jeremy Meredith
//  Creation:   September  3, 2004
//
// ****************************************************************************

avtFilter *
avtProjectFilter::Create()
{
    return new avtProjectFilter();
}


// ****************************************************************************
//  Method:      avtProjectFilter::SetAtts
//
//  Purpose:
//      Sets the state of the filter based on the attribute object.
//
//  Arguments:
//      a        The attributes to use.
//
//  Programmer: Jeremy Meredith
//  Creation:   September  3, 2004
//
// ****************************************************************************

void
avtProjectFilter::SetAtts(const AttributeGroup *a)
{
    atts = *(const ProjectAttributes*)a;
}


// ****************************************************************************
//  Method: avtProjectFilter::Equivalent
//
//  Purpose:
//      Returns true if creating a new avtProjectFilter with the given
//      parameters would result in an equivalent avtProjectFilter.
//
//  Programmer: Jeremy Meredith
//  Creation:   September  3, 2004
//
// ****************************************************************************

bool
avtProjectFilter::Equivalent(const AttributeGroup *a)
{
    return (atts == *(ProjectAttributes*)a);
}


// ****************************************************************************
//  Method: avtProjectFilter::ExecuteData
//
//  Purpose:
//      Sends the specified input and output through the Project filter.
//
//  Arguments:
150
//      in_dr      The input data representation.
hrchilds's avatar
hrchilds committed
151
//
152
//  Returns:       The output data representation.
hrchilds's avatar
hrchilds committed
153 154 155 156
//
//  Programmer: Jeremy Meredith
//  Creation:   September  3, 2004
//
157 158 159 160
//  Modifications:
//    Jeremy Meredith, Fri Sep 10 16:15:55 PDT 2004
//    Added projection of vectors.
//
161 162 163
//    Hank Childs, Tue Aug  3 09:28:35 PDT 2010
//    Fix bug with project of cell-centered vectors.
//
bonnell's avatar
bonnell committed
164 165 166
//    Kathleen Biagas, Wed Aug  8 17:31:54 PDT 2012
//    Use templatized ProjectVectors.
//
167 168 169
//    Eric Brugger, Thu Jul 31 14:44:16 PDT 2014
//    Modified the class to work with avtDataRepresentation.
//
hrchilds's avatar
hrchilds committed
170 171
// ****************************************************************************

172 173
avtDataRepresentation *
avtProjectFilter::ExecuteData(avtDataRepresentation *in_dr)
hrchilds's avatar
hrchilds committed
174
{
175 176 177 178 179
    //
    // Get the VTK data set.
    //
    vtkDataSet *in_ds = in_dr->GetDataVTK();

hrchilds's avatar
hrchilds committed
180
    int  datatype = in_ds->GetDataObjectType();
181
    vtkPointSet *out_ds = NULL;
hrchilds's avatar
hrchilds committed
182 183 184
    switch (datatype)
    {
      case VTK_RECTILINEAR_GRID:
185 186
        out_ds = ProjectRectilinearGrid((vtkRectilinearGrid*)in_ds);
        break;
hrchilds's avatar
hrchilds committed
187 188 189 190

      case VTK_STRUCTURED_GRID:
      case VTK_UNSTRUCTURED_GRID:
      case VTK_POLY_DATA:
191 192
        out_ds = ProjectPointSet((vtkPointSet*)in_ds);
        break;
hrchilds's avatar
hrchilds committed
193 194 195 196

      default:
        EXCEPTION0(ImproperUseException);
    }
197 198 199 200 201 202 203 204 205 206 207 208 209

    //
    // We have said normals are inappropriate, since this will be a
    // 2D data set.  We have not touched the vectors, however --
    // we have only projected the mesh itself so far.
    //
    vtkDataArray *vectors;
    vectors = out_ds->GetPointData()->GetVectors();
    if (vectors)
    {
        vtkDataArray *arr = vectors->NewInstance();
        arr->SetNumberOfComponents(3);
        arr->Allocate(3*vectors->GetNumberOfTuples());
bonnell's avatar
bonnell committed
210 211 212 213
        if (arr->GetDataType() == VTK_FLOAT)
            ProjectVectors<float>(in_ds, out_ds, vectors, arr, false);
        else if (arr->GetDataType() == VTK_DOUBLE)
            ProjectVectors<double>(in_ds, out_ds, vectors, arr, false);
214 215 216 217 218 219 220 221 222 223 224
        arr->SetName(vectors->GetName());
        out_ds->GetPointData()->RemoveArray(vectors->GetName());
        out_ds->GetPointData()->SetVectors(arr);
        arr->Delete();
    }
    vectors = out_ds->GetCellData()->GetVectors();
    if (vectors)
    {
        vtkDataArray *arr = vectors->NewInstance();
        arr->SetNumberOfComponents(3);
        arr->Allocate(3*vectors->GetNumberOfTuples());
bonnell's avatar
bonnell committed
225 226 227 228
        if (arr->GetDataType() == VTK_FLOAT)
            ProjectVectors<float>(in_ds, out_ds, vectors, arr, true);
        else if (arr->GetDataType() == VTK_DOUBLE)
            ProjectVectors<double>(in_ds, out_ds, vectors, arr, true);
229
        arr->SetName(vectors->GetName());
230 231
        out_ds->GetCellData()->RemoveArray(vectors->GetName());
        out_ds->GetCellData()->SetVectors(arr);
232 233 234
        arr->Delete();
    }

235 236
    avtDataRepresentation *out_dr = new avtDataRepresentation(out_ds,
        in_dr->GetDomain(), in_dr->GetLabel());
237

238 239 240
    out_ds->Delete();

    return out_dr;
hrchilds's avatar
hrchilds committed
241 242 243
}


hrchilds's avatar
hrchilds committed
244 245 246 247 248 249 250 251 252
// ****************************************************************************
//  Method: avtProjectFilter::PostExecute
//
//  Purpose:
//      Finds the extents once we have been projected and set those.
//
//  Programmer: Hank Childs
//  Creation:   January 20, 2005
//
253 254 255 256 257
//   Modifications:
//
//    Hank Childs, Thu Aug 26 13:47:30 PDT 2010
//    Change extents names.
//
hrchilds's avatar
hrchilds committed
258 259 260 261 262
// ****************************************************************************

void
avtProjectFilter::PostExecute(void)
{
263
    avtPluginDataTreeIterator::PostExecute();
hrchilds's avatar
hrchilds committed
264 265 266 267 268 269 270 271 272

    avtDataAttributes& outAtts = GetOutput()->GetInfo().GetAttributes();

    // get the outputs's spatial extents
    double se[6];
    avtDataset_p output = GetTypedOutput();
    avtDatasetExaminer::GetSpatialExtents(output, se);

    // over-write spatial extents
273 274
    outAtts.GetOriginalSpatialExtents()->Clear();
    outAtts.GetThisProcsOriginalSpatialExtents()->Set(se);
hrchilds's avatar
hrchilds committed
275 276 277
}


hrchilds's avatar
hrchilds committed
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
// ****************************************************************************
//  Method:  avtProjectFilter::ProjectPoint
//
//  Purpose:
//    Project a single point in-place.
//
//  Arguments:
//    x,y,z      the point to project
//
//  Programmer:  Jeremy Meredith
//  Creation:    September  3, 2004
//
// ****************************************************************************
void
avtProjectFilter::ProjectPoint(float &x,float &y,float &z)
{
    switch (atts.GetProjectionType())
    {
296 297
      case ProjectAttributes::ZYCartesian:
        x = z;
298
        //y = y;
299 300 301 302
        z = 0;
        break;

      case ProjectAttributes::XZCartesian:
303
        //x = x;
304 305 306 307
        y = z;
        z = 0;
        break;

hrchilds's avatar
hrchilds committed
308
      case ProjectAttributes::XYCartesian:
309 310
        //x = x;
        //y = y;
hrchilds's avatar
hrchilds committed
311 312 313
        z = 0;
        break;

314 315 316
      case ProjectAttributes::XRCylindrical:
        {
            float r = sqrt(y*y + z*z);
317
            //x = x;
318 319 320 321 322 323 324 325 326 327 328 329 330
            y = r;
            z = 0;
        }
        break;
      case ProjectAttributes::YRCylindrical:
        {
            float r = sqrt(x*x + z*z);
            x = y;
            y = r;
            z = 0;
        }
        break;

hrchilds's avatar
hrchilds committed
331 332 333 334 335 336 337 338 339 340 341
      case ProjectAttributes::ZRCylindrical:
        {
            float r = sqrt(x*x + y*y);
            x = z;
            y = r;
            z = 0;
        }
        break;
    }
}

342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
// ****************************************************************************
//  Method:  avtProjectFilter::ProjectPoint
//
//  Purpose:
//    Project a single point in-place.  Double precision copy version.
//
//  Arguments:
//    x,y,z      the point to project
//
//  Programmer:  Jeremy Meredith
//  Creation:    April  1, 2010
//
// ****************************************************************************
void
avtProjectFilter::ProjectPoint(double &x,double &y,double &z)
{
    switch (atts.GetProjectionType())
    {
      case ProjectAttributes::ZYCartesian:
        x = z;
whitlocb's avatar
whitlocb committed
362
        //y = y;
363 364 365 366
        z = 0;
        break;

      case ProjectAttributes::XZCartesian:
whitlocb's avatar
whitlocb committed
367
        //x = x;
368 369 370 371 372
        y = z;
        z = 0;
        break;

      case ProjectAttributes::XYCartesian:
whitlocb's avatar
whitlocb committed
373 374
        //x = x;
        //y = y;
375 376 377 378 379 380
        z = 0;
        break;

      case ProjectAttributes::XRCylindrical:
        {
            double r = sqrt(y*y + z*z);
whitlocb's avatar
whitlocb committed
381
            //x = x;
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
            y = r;
            z = 0;
        }
        break;
      case ProjectAttributes::YRCylindrical:
        {
            double r = sqrt(x*x + z*z);
            x = y;
            y = r;
            z = 0;
        }
        break;

      case ProjectAttributes::ZRCylindrical:
        {
            double r = sqrt(x*x + y*y);
            x = z;
            y = r;
            z = 0;
        }
        break;
    }
}

hrchilds's avatar
hrchilds committed
406
// ****************************************************************************
407
//  Method:  avtProjectFilter::ProjectRectilinearGrid
hrchilds's avatar
hrchilds committed
408 409
//
//  Purpose:
410
//    Converts a rectilinear grid to a curvilinear grid while projecting
hrchilds's avatar
hrchilds committed
411 412 413 414 415 416 417
//
//  Arguments:
//    in_ds      the rectilinear grid to project
//
//  Programmer:  Jeremy Meredith
//  Creation:    September  6, 2004
//
418 419 420 421
//  Modifications:
//    Jeremy Meredith, Fri Sep 10 16:16:12 PDT 2004
//    Always convert to a curvilinear grid.  The extra code wasn't even
//    worth it because I expect no one will ever want to do it.
bonnell's avatar
bonnell committed
422 423 424
//    
//    Kathleen Biagas, Wed Aug  8 15:37:10 PDT 2012
//    Preserve coordinate data type.
hrchilds's avatar
hrchilds committed
425
//
426 427 428
//    Eric Brugger, Thu Jul 31 14:44:16 PDT 2014
//    Modified the class to work with avtDataRepresentation.
//
hrchilds's avatar
hrchilds committed
429
// ****************************************************************************
430 431
vtkPointSet *
avtProjectFilter::ProjectRectilinearGrid(vtkRectilinearGrid *in_ds)
hrchilds's avatar
hrchilds committed
432 433 434 435 436 437
{
    int  dims[3];
    in_ds->GetDimensions(dims);

    int  numPts = dims[0]*dims[1]*dims[2];

bonnell's avatar
bonnell committed
438
    vtkPoints *pts = vtkVisItUtility::NewPoints(in_ds);
hrchilds's avatar
hrchilds committed
439 440 441 442 443 444 445 446 447 448 449 450 451
    pts->SetNumberOfPoints(numPts);

    vtkDataArray *x = in_ds->GetXCoordinates();
    vtkDataArray *y = in_ds->GetYCoordinates();
    vtkDataArray *z = in_ds->GetZCoordinates();

    int index = 0;
    for (int k = 0 ; k < dims[2] ; k++)
    {
        for (int j = 0 ; j < dims[1] ; j++)
        {
            for (int i = 0 ; i < dims[0] ; i++)
            {
bonnell's avatar
bonnell committed
452
                double pt[3];
hrchilds's avatar
hrchilds committed
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
                pt[0] = x->GetComponent(i,0);
                pt[1] = y->GetComponent(j,0);
                pt[2] = z->GetComponent(k,0);

                ProjectPoint(pt[0],pt[1],pt[2]);

                pts->SetPoint(index++, pt);
            }
        }
    }

    vtkStructuredGrid *out = vtkStructuredGrid::New();
    out->SetDimensions(dims);
    out->SetPoints(pts);
    pts->Delete();
    out->GetCellData()->ShallowCopy(in_ds->GetCellData());
    out->GetPointData()->ShallowCopy(in_ds->GetPointData());

    return out;
}


// ****************************************************************************
//  Method:  avtProjectFilter::ProjectPointSet
//
//  Purpose:
//    Projects a descendent of vtkPointSet.  This includes
//    curvilinear, unstructured, point meshes, and poly data.
//
//  Arguments:
//    in_ds      the data set to project
//
//  Programmer:  Jeremy Meredith
//  Creation:    September  6, 2004
//
488 489 490 491 492 493
//  Modifications:
//
//    Hank Childs, Fri Oct  5 08:55:01 PDT 2007
//    In the special case where we have a curvilinear mesh with dimensions
//    1xYxZ or Xx1xZ, then change the projected mesh to be XxYx1.
//
bonnell's avatar
bonnell committed
494 495 496
//    Kathleen Biagas, Wed Aug  8 17:33:35 PDT 2012
//    Preserve coordinate type.
//
497 498 499
//    Eric Brugger, Thu Jul 31 14:44:16 PDT 2014
//    Modified the class to work with avtDataRepresentation.
//
hrchilds's avatar
hrchilds committed
500
// ****************************************************************************
bonnell's avatar
bonnell committed
501

502
vtkPointSet *
hrchilds's avatar
hrchilds committed
503 504 505 506 507 508 509 510 511
avtProjectFilter::ProjectPointSet(vtkPointSet *in_ds)
{
    vtkPointSet *out_ds = in_ds->NewInstance();
    out_ds->ShallowCopy(in_ds);

    vtkPoints *old_pts = in_ds->GetPoints();
    int npoints = old_pts->GetNumberOfPoints();

    // Make a new point array
bonnell's avatar
bonnell committed
512
    vtkPoints *new_pts = vtkPoints::New(old_pts->GetDataType());
hrchilds's avatar
hrchilds committed
513
    new_pts->DeepCopy(old_pts);
bonnell's avatar
bonnell committed
514 515 516 517 518 519 520 521 522 523 524
    if (old_pts->GetDataType() == VTK_FLOAT)
    {
        float *points = (float*)new_pts->GetVoidPointer(0); 
        for (int i = 0 ; i < npoints ; i++)
        {
            ProjectPoint(points[i*3+0],
                         points[i*3+1],
                         points[i*3+2]);
        }
    }
    else if (old_pts->GetDataType() == VTK_DOUBLE)
hrchilds's avatar
hrchilds committed
525
    {
bonnell's avatar
bonnell committed
526 527 528 529 530 531 532
        double *points = (double*)new_pts->GetVoidPointer(0);
        for (int i = 0 ; i < npoints ; i++)
        {
            ProjectPoint(points[i*3+0],
                         points[i*3+1],
                         points[i*3+2]);
        }
hrchilds's avatar
hrchilds committed
533 534 535 536
    }
    out_ds->SetPoints(new_pts);
    new_pts->Delete();

537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
    //
    // If we are projecting a funny 2D curvilinear grid, then make it
    // be a normal 2D curvilinear grid.
    //
    if (out_ds->GetDataObjectType() == VTK_STRUCTURED_GRID)
    {
        vtkStructuredGrid *sgrid = (vtkStructuredGrid *) out_ds;
        int dims[3];
        sgrid->GetDimensions(dims);
        if (dims[0] == 1 && dims[1] != 1 && dims[2] != 1)
        {
            dims[0] = dims[1];
            dims[1] = dims[2];
            dims[2] = 1;
            sgrid->SetDimensions(dims);
        }
        if (dims[0] != 1 && dims[1] == 1 && dims[2] != 1)
        {
            dims[1] = dims[2];
            dims[2] = 1;
            sgrid->SetDimensions(dims);
        }
    }

hrchilds's avatar
hrchilds committed
561 562 563
    return out_ds;
}

564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
// ****************************************************************************
//  Method:  avtProjectFilter::ProjectVectors
//
//  Purpose:
//    Project some vectors!
//
//  Arguments:
//    old_ds          the original dataset
//    new_ds          the transformed one
//    in              the vectors to project
//    out             the place to store the new vectors
//    cell_centered   true if these vectors are cell data
//
//  Programmer:  Jeremy Meredith
//  Creation:    September 10, 2004
//
580 581 582 583
//  Modifications:
//    Jeremy Meredith, Thu Apr  1 14:43:48 EDT 2010
//    Took into account various ways one might want to transform a vector.
//
584 585 586
//    Kathleen Bonnell, Thu Dec  9 14:49:04 PST 2010
//    Normalize the vector before projection in the AsDirection case.
//
bonnell's avatar
bonnell committed
587 588 589
//    Kathleen Biagas, Wed Aug  8 17:36:03 PDT 2012
//    Templatized to handle different data types.
//
590
// ****************************************************************************
bonnell's avatar
bonnell committed
591 592

template <class T> void
593 594 595 596 597 598
avtProjectFilter::ProjectVectors(vtkDataSet *old_ds, 
                                 vtkDataSet *new_ds,
                                 vtkDataArray *in,
                                 vtkDataArray *out,
                                 bool cell_centered)
{
599 600 601
    const double instantEps    = 1.e-5;
    const double instantEpsInv = 1.e+5;

602
    int nvectors  = in->GetNumberOfTuples();
bonnell's avatar
bonnell committed
603 604
    T *inptr  = (T*)in->GetVoidPointer(0);
    T *outptr = (T*)out->GetVoidPointer(0);
605 606 607

    for (int i=0; i<nvectors; i++)
    {
hrchilds's avatar
hrchilds committed
608 609
        double oldpt[3];
        double newpt[3];
610 611 612

        if (cell_centered)
        {
hrchilds's avatar
hrchilds committed
613 614
            old_ds->GetPoint(old_ds->GetCell(i)->GetPointId(0), oldpt);
            new_ds->GetPoint(new_ds->GetCell(i)->GetPointId(0), newpt);
615 616 617
        }
        else
        {
hrchilds's avatar
hrchilds committed
618 619
            old_ds->GetPoint(i, oldpt);
            new_ds->GetPoint(i, newpt);
620 621
        }

622 623 624
        double u = inptr[i*3+0];
        double v = inptr[i*3+1];
        double w = inptr[i*3+2];
625

626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
        switch (atts.GetVectorTransformMethod())
        {
          case ProjectAttributes::None:
            outptr[i*3+0] = u;
            outptr[i*3+1] = v;
            outptr[i*3+2] = w;
            break;
            
          case ProjectAttributes::AsPoint:
            ProjectPoint(u,v,w);
            outptr[i*3+0] = u;
            outptr[i*3+1] = v;
            outptr[i*3+2] = w;
            break;
            
          case ProjectAttributes::AsDisplacement:
            {
            double x = oldpt[0] + u;
            double y = oldpt[1] + v;
            double z = oldpt[2] + w;
646

647
            ProjectPoint(x,y,z);
648

649 650 651 652 653 654 655 656
            outptr[i*3+0] = x - newpt[0];
            outptr[i*3+1] = y - newpt[1];
            outptr[i*3+2] = z - newpt[2];
            }
            break;

          case ProjectAttributes::AsDirection:
            {
657 658 659 660 661 662 663 664 665 666 667
            double mag = sqrt(u*u+v*v+w*w);
            double nu = 0., nv = 0., nw = 0.;
            if (mag != 0.)
            {
                nu = u/mag;
                nv = v/mag;
                nw = w/mag;
            }
            double x = oldpt[0] + nu*instantEps;
            double y = oldpt[1] + nv*instantEps;
            double z = oldpt[2] + nw*instantEps;
668

669 670
            ProjectPoint(x,y,z);

671 672 673
            outptr[i*3+0] = (x - newpt[0])*instantEpsInv*mag;
            outptr[i*3+1] = (y - newpt[1])*instantEpsInv*mag;
            outptr[i*3+2] = (z - newpt[2])*instantEpsInv*mag;
674 675 676
            }
            break;
        }
677 678 679
    }
}

hrchilds's avatar
hrchilds committed
680
// ****************************************************************************
hrchilds's avatar
hrchilds committed
681
//  Method:  avtProjectFilter::UpdateDataObjectInfo
hrchilds's avatar
hrchilds committed
682 683 684 685 686 687 688 689 690 691
//
//  Purpose:
//    Set up the atttributes and validity for the output of the filter.
//
//  Arguments:
//    none
//
//  Programmer:  Jeremy Meredith
//  Creation:    September  6, 2004
//
hrchilds's avatar
hrchilds committed
692 693 694 695 696
//  Modifications:
//
//    Hank Childs, Tue Feb  1 15:37:37 PST 2005
//    Allow normals, since if they are not appropriate, it will be detected.
//
hrchilds's avatar
hrchilds committed
697 698 699
//    Hank Childs, Fri Jan 13 09:58:47 PST 2006
//    Invalidate spatial meta-data.
//
700 701 702
//    Kathleen Biagas, Thu Aug 16 14:56:29 MST 2012
//    Indicate points were transformed by this operator.
//
whitlocb's avatar
whitlocb committed
703 704 705 706
//    Brad Whitlock, Mon Apr  7 15:55:02 PDT 2014
//    Add filter metadata used in export.
//    Work partially supported by DOE Grant SC0007548.
//
hrchilds's avatar
hrchilds committed
707
// ****************************************************************************
whitlocb's avatar
whitlocb committed
708

hrchilds's avatar
hrchilds committed
709
void
hrchilds's avatar
hrchilds committed
710
avtProjectFilter::UpdateDataObjectInfo(void)
hrchilds's avatar
hrchilds committed
711 712 713 714 715 716
{
    avtDataAttributes &inAtts      = GetInput()->GetInfo().GetAttributes();
    avtDataAttributes &outAtts     = GetOutput()->GetInfo().GetAttributes();
   
    if (inAtts.GetSpatialDimension() == 3)
        outAtts.SetSpatialDimension(2);
hrchilds's avatar
hrchilds committed
717 718

    GetOutput()->GetInfo().GetValidity().InvalidateSpatialMetaData();
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756

    switch (atts.GetProjectionType())
    {
      case ProjectAttributes::ZYCartesian:
        outAtts.SetXLabel(inAtts.GetZLabel());
        outAtts.SetYLabel(inAtts.GetYLabel());
        outAtts.SetZLabel("Projected X Axis");
        break;

      case ProjectAttributes::XZCartesian:
        outAtts.SetXLabel(inAtts.GetXLabel());
        outAtts.SetYLabel(inAtts.GetZLabel());
        outAtts.SetZLabel("Projected Y Axis");
        break;

      case ProjectAttributes::XYCartesian:
        outAtts.SetXLabel(inAtts.GetXLabel());
        outAtts.SetYLabel(inAtts.GetYLabel());
        outAtts.SetZLabel("Projected Z Axis");
        break;

      case ProjectAttributes::XRCylindrical:
        outAtts.SetXLabel(inAtts.GetXLabel());
        outAtts.SetYLabel("Radial Axis");
        outAtts.SetZLabel("Projected Theta Axis");
        break;
      case ProjectAttributes::YRCylindrical:
        outAtts.SetXLabel(inAtts.GetYLabel());
        outAtts.SetYLabel("Radial Axis");
        outAtts.SetZLabel("Projected Theta Axis");
        break;
      case ProjectAttributes::ZRCylindrical:
        outAtts.SetXLabel(inAtts.GetZLabel());
        outAtts.SetYLabel("Radial Axis");
        outAtts.SetZLabel("Projected Theta Axis");
        break;
    }

757 758 759
    GetOutput()->GetInfo().GetValidity().SetPointsWereTransformed(true);
    outAtts.SetCanUseInvTransform(false);
    outAtts.SetCanUseTransform(false);
whitlocb's avatar
whitlocb committed
760
    outAtts.AddFilterMetaData("Project");
hrchilds's avatar
hrchilds committed
761 762
}

763
// ****************************************************************************
hrchilds's avatar
hrchilds committed
764
//  Method: avtProjectFilter::ModifyContract
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
//
//  Purpose:
//    Turn on zone/node numbers if needed for pick (for example).
//
//  Programmer: Jeremy Meredith
//  Creation:   September  9, 2004
//
//  Note:  I copied this implementation from Displace for now since
//         it seemed the most alike to this requirements for getting
//         pick to work.
//
//  Modifications:
//
// ****************************************************************************

hrchilds's avatar
hrchilds committed
780 781
avtContract_p
avtProjectFilter::ModifyContract(avtContract_p spec)
782
{
hrchilds's avatar
hrchilds committed
783 784
    avtContract_p rv = new avtContract(spec);
    if (rv->GetDataRequest()->MayRequireZones())
785
    {
hrchilds's avatar
hrchilds committed
786
        rv->GetDataRequest()->TurnZoneNumbersOn();
787
    }
hrchilds's avatar
hrchilds committed
788
    if (rv->GetDataRequest()->MayRequireNodes())
789
    {
hrchilds's avatar
hrchilds committed
790
        rv->GetDataRequest()->TurnNodeNumbersOn();
791 792 793 794
    }
    return rv;
}