vtkSurfaceFilter.C 10.5 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.
*
*****************************************************************************/

39
// ****************************************************************************
hrchilds's avatar
hrchilds committed
40 41 42 43 44 45 46 47 48
//  Class:   vtkSurfaceFilter
//
//  Purpose:
//    Derived type of vtkDataSetToDataSetFilter.
//
//  Notes:  
//
//  Programmer:  Kathleen S. Bonnell
//
bonnell's avatar
bonnell committed
49
//  Creation:  14 March 2001
hrchilds's avatar
hrchilds committed
50 51 52
//
//  Modifications:
//
53
// ****************************************************************************
hrchilds's avatar
hrchilds committed
54

hrchilds's avatar
hrchilds committed
55 56
#include "vtkSurfaceFilter.h"

hrchilds's avatar
hrchilds committed
57
#include <vtkCell.h>
hrchilds's avatar
hrchilds committed
58 59
#include <vtkCellArray.h>
#include <vtkCellData.h>
hrchilds's avatar
hrchilds committed
60
#include <vtkIdList.h>
61 62
#include <vtkInformation.h>
#include <vtkInformationVector.h>
hrchilds's avatar
hrchilds committed
63
#include <vtkObjectFactory.h>
hrchilds's avatar
hrchilds committed
64 65 66
#include <vtkPointData.h>
#include <vtkPointSet.h>
#include <vtkPolyData.h>
hrchilds's avatar
hrchilds committed
67 68 69
#include <vtkRectilinearGrid.h>
#include <vtkStructuredGrid.h>
#include <vtkUnstructuredGrid.h>
70
#include <vtkVisItUtility.h>
hrchilds's avatar
hrchilds committed
71

72
// ****************************************************************************
hrchilds's avatar
hrchilds committed
73
//  Modifications:
bonnell's avatar
bonnell committed
74 75
//    Kathleen Bonnell, Wed Mar  6 15:14:29 PST 2002
//    Replace 'New' method with Macro to match VTK 4.0 API.
76
// ****************************************************************************
hrchilds's avatar
hrchilds committed
77 78

vtkStandardNewMacro(vtkSurfaceFilter);
79
vtkCxxSetObjectMacro(vtkSurfaceFilter, inScalars, vtkDataArray); 
hrchilds's avatar
hrchilds committed
80 81


82
// ****************************************************************************
hrchilds's avatar
hrchilds committed
83 84 85 86 87 88
// Construct with 
vtkSurfaceFilter::vtkSurfaceFilter()
{
  this->inScalars = NULL;
}

89 90

// ****************************************************************************
hrchilds's avatar
hrchilds committed
91 92 93 94 95 96
// Destructor
vtkSurfaceFilter::~vtkSurfaceFilter()
{
  this->SetinScalars(NULL);
}

97 98 99

// ****************************************************************************
//  Method: vtkSurfaceFilter::RequestData
hrchilds's avatar
hrchilds committed
100
//
bonnell's avatar
bonnell committed
101 102
//  Purpose:
//    vtk Required method. Updates state of the filter by
hrchilds's avatar
hrchilds committed
103
//
104
//  Arguments:  None
hrchilds's avatar
hrchilds committed
105
//
bonnell's avatar
bonnell committed
106
//  Returns:    None
hrchilds's avatar
hrchilds committed
107
//
108 109 110 111 112 113 114 115 116 117 118 119 120
//  Assumptions and Comments:
//
//  Programmer: Kathleen S. Bonnell
//  Creation:   12 March 2001
//
//  Modifications:
//
// ****************************************************************************
int
vtkSurfaceFilter::RequestData(
  vtkInformation *vtkNotUsed(request),
  vtkInformationVector **inputVector,
  vtkInformationVector *outputVector)
hrchilds's avatar
hrchilds committed
121
{
122 123 124 125 126 127 128 129 130 131 132
  // get the info objects
  vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
  vtkInformation *outInfo = outputVector->GetInformationObject(0);

  //
  // Initialize some frequently used values.
  //
  vtkDataSet *input = vtkDataSet::SafeDownCast(
    inInfo->Get(vtkDataObject::DATA_OBJECT()));
  vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(
    outInfo->Get(vtkDataObject::DATA_OBJECT()));
hrchilds's avatar
hrchilds committed
133 134 135 136

  if (inScalars == NULL)
  {
      vtkErrorMacro(<<"Cannot execute, scalars not set");
137
      return 1;
hrchilds's avatar
hrchilds committed
138 139 140
  }

  if (input->GetDataObjectType() == VTK_RECTILINEAR_GRID)
141
      this->ExecuteRectilinearGrid( (vtkRectilinearGrid *) input, output);
hrchilds's avatar
hrchilds committed
142
  else
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
      this->ExecutePointSet( (vtkPointSet*) input, output);

  return 1;
} // RequestData


// ****************************************************************************
//  Method: vtkSurfaceFilter::FillInputPortInformation
//
// ****************************************************************************

int
vtkSurfaceFilter::FillInputPortInformation(int, vtkInformation *info)
{
  info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
  return 1;
} // FillInputPortInformation


// ****************************************************************************
//  Method: vtkSurfaceFilter::PrintSelf
//
bonnell's avatar
bonnell committed
165
//  Purpose:  Prints pertinent information regarding the state of this class
166 167 168 169 170 171
//            to the given output stream.
//
//  Arguments:
//    os      The output stream to which the information is printed
//    indent  The amount of spaces to indent.
//
bonnell's avatar
bonnell committed
172
//  Returns:  None
173 174
//
//  Assumptions and Comments:
bonnell's avatar
bonnell committed
175
//    Calls the superclass method first.
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
//
//  Programmer: Kathleen S. Bonnell
//  Creation:   5 October 2000
//
//  Modifications:
//
// ****************************************************************************
void 
vtkSurfaceFilter::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);

  os << indent << "zVals :    ";
  inScalars->PrintSelf(os, indent); 
  os << indent << "\n";
}
hrchilds's avatar
hrchilds committed
192 193


194 195 196 197
// ****************************************************************************
//  Method: vtkSurfaceFilter::ExecuteRectilinearGrid
//
//  Purpose:  
bonnell's avatar
bonnell committed
198
//    Execution method for rectilinear grid input types.
199 200
//
//  Arguments: rg   the rectilinear grid input
hrchilds's avatar
hrchilds committed
201
//
202
//  Returns:   None 
hrchilds's avatar
hrchilds committed
203
//
204
//  Assumptions and Comments:
hrchilds's avatar
hrchilds committed
205
//
206 207
//  Programmer: Kathleen S. Bonnell
//  Creation:   5 October 2000
hrchilds's avatar
hrchilds committed
208
//
209
//  Modifications:
hrchilds's avatar
hrchilds committed
210 211
//    Kathleen Bonnell, Fri Feb  8 11:03:49 PST 2002
//    vtkScalars has been deprecated in VTK 4.0, use vtkDataArray instead.
212 213 214 215
//
//    Kathleen Biagas, Thu Aug 30 16:26:44 MST 2012
//    Preserve coordinate type.
//
216
// ****************************************************************************
hrchilds's avatar
hrchilds committed
217
void 
218 219
vtkSurfaceFilter::ExecuteRectilinearGrid(vtkRectilinearGrid *rg,
  vtkUnstructuredGrid *output)
hrchilds's avatar
hrchilds committed
220 221
{
  vtkDebugMacro(<<"ExecuteRectilinearGrid::");
222

hrchilds's avatar
hrchilds committed
223 224 225 226 227
  int numPoints = rg->GetNumberOfPoints();
  int numCells = rg->GetNumberOfCells();
  int *cellTypes = new int [numCells];
  vtkCellArray *cells = vtkCellArray::New();

228
  vtkPoints *outPoints = vtkVisItUtility::NewPoints(rg);
hrchilds's avatar
hrchilds committed
229 230 231 232
  outPoints->SetNumberOfPoints(numPoints);

  int dims[3];
  rg->GetDimensions(dims);
hrchilds's avatar
hrchilds committed
233
  double point[3]; 
234
  double val;
hrchilds's avatar
hrchilds committed
235 236 237
  for (int i = 0; i < numPoints; ++i)
  {
    rg->GetPoint(i, point);
238
    val = inScalars->GetTuple1(i); 
hrchilds's avatar
hrchilds committed
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
    if (dims[2] == 1) // replace z coordinates with val
    {
        point[2] = val;
    }
    else if (dims[1] == 1) // replace y coordinates with val
    {
        point[1] = val;
    }
    else  // replace x coordinates with val
    {
        point[0] = val;
    }
    outPoints->SetPoint(i, point);
  }

254
  vtkCell * aCell = NULL;
hrchilds's avatar
hrchilds committed
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
  for (int j = 0; j < numCells; ++j)
  {
    aCell = rg->GetCell(j);
    cellTypes[j] = aCell->GetCellType();
    cells->InsertNextCell(aCell);
  }

  output->SetPoints(outPoints);
  output->SetCells(cellTypes, cells);
  output->GetPointData()->PassData(rg->GetPointData());
  output->GetCellData()->PassData(rg->GetCellData());

  delete [] cellTypes;
  outPoints->Delete();
  cells->Delete();

} // ExecuteRectilinearGrid

      
274 275 276
// ****************************************************************************
//  Method: vtkSurfaceFilter::ExecutePointSet
//
bonnell's avatar
bonnell committed
277 278
//  Purpose:
//    Execution method for rectilinear grid input types.
hrchilds's avatar
hrchilds committed
279
//
280
//  Arguments: rg   the rectilinear grid input
hrchilds's avatar
hrchilds committed
281
//
bonnell's avatar
bonnell committed
282
//  Returns:   None
hrchilds's avatar
hrchilds committed
283
//
284
//  Assumptions and Comments:
hrchilds's avatar
hrchilds committed
285
//
286 287 288 289
//  Programmer: Kathleen S. Bonnell
//  Creation:   5 October 2000
//
//  Modifications:
hrchilds's avatar
hrchilds committed
290 291
//    Kathleen Bonnell, Fri Feb  8 11:03:49 PST 2002
//    vtkScalars has been deprecated in VTK 4.0, use vtkDataArray instead.
292
//
hrchilds's avatar
hrchilds committed
293 294 295
//    Hank Childs, Thu Sep 12 19:12:35 PDT 2002
//    Fix memory leak.
//
296 297 298
//    Kathleen Biagas, Thu Aug 30 16:26:44 MST 2012
//    Preserve coordinate type.
//
299
// ****************************************************************************
hrchilds's avatar
hrchilds committed
300
void 
301
vtkSurfaceFilter::ExecutePointSet(vtkPointSet *ps, vtkUnstructuredGrid *output)
hrchilds's avatar
hrchilds committed
302 303 304 305 306 307 308 309 310 311 312
{
  vtkDebugMacro(<<"ExecutePointSet::");

  vtkPoints *inPoints = ps->GetPoints();

  if ( inScalars->GetNumberOfTuples() != inPoints->GetNumberOfPoints() )
  {
      vtkErrorMacro(<<"Number of scalars must match number of points!");
      return;
  }

313
  vtkPoints *outPoints = vtkPoints::New(inPoints->GetDataType());
hrchilds's avatar
hrchilds committed
314 315
  outPoints->SetNumberOfPoints(inPoints->GetNumberOfPoints());

hrchilds's avatar
hrchilds committed
316
  double point[3];
hrchilds's avatar
hrchilds committed
317 318 319
  for (int i = 0; i < inScalars->GetNumberOfTuples(); ++i)
  {
     inPoints->GetPoint(i, point);
320
     point[2] = inScalars->GetTuple1(i);
hrchilds's avatar
hrchilds committed
321 322 323 324 325
     outPoints->SetPoint(i, point); 
  }
  int numCells = ps->GetNumberOfCells();
  int *cellTypes = new int [numCells];
  vtkCellArray *cells = vtkCellArray::New();
326
  vtkCell * aCell = NULL; /// TODO: is switch handling all cases?
hrchilds's avatar
hrchilds committed
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
  for (int j = 0; j < numCells; ++j)
  {
    switch(ps->GetDataObjectType())
    {
        case VTK_POLY_DATA : 
             aCell = ((vtkPolyData*)ps)->GetCell(j); break;
        case VTK_STRUCTURED_GRID : 
             aCell = ((vtkStructuredGrid*)ps)->GetCell(j); break;
        case VTK_UNSTRUCTURED_GRID : 
             aCell = ((vtkUnstructuredGrid*)ps)->GetCell(j); break;
    }
    cellTypes[j] = aCell->GetCellType();
    cells->InsertNextCell(aCell);
  }

  output->SetPoints(outPoints);
  output->SetCells(cellTypes, cells);
  output->GetPointData()->PassData(ps->GetPointData());
  output->GetCellData()->PassData(ps->GetCellData());

  // free memory used locally
  delete [] cellTypes;
  outPoints->Delete();
  cells->Delete();

} // ExecutePointSet