VTK
CompactPointField.h
Go to the documentation of this file.
1 //=============================================================================
2 //
3 // Copyright (c) Kitware, Inc.
4 // All rights reserved.
5 // See LICENSE.txt for details.
6 //
7 // This software is distributed WITHOUT ANY WARRANTY; without even
8 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9 // PURPOSE. See the above copyright notice for more information.
10 //
11 // Copyright 2014 Sandia Corporation.
12 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
13 // the U.S. Government retains certain rights in this software.
14 //
15 //=============================================================================
16 
17 #ifndef vtkToDax_CompactPointField_h
18 #define vtkToDax_CompactPointField_h
19 
20 #include "vtkDataSet.h"
21 #include "vtkDispatcher.h"
22 
23 #include "vtkToDax/Containers.h"
25 
27 
28 namespace vtkToDax {
29 
30 template<typename DispatcherType>
32 {
33  DispatcherType *Dispatcher;
35 
36  CompactPointField(DispatcherType &dispatcher,
37  vtkDataSet *output)
38  : Dispatcher(&dispatcher), Output(output) { }
39 
40  template<typename InputVTKArrayType>
41  int operator()(InputVTKArrayType &inputFieldVTKArray)
42  {
43  switch(inputFieldVTKArray.GetNumberOfComponents())
44  {
45  case 1: return this->DoCompact<1>(inputFieldVTKArray);
46  case 2: return this->DoCompact<2>(inputFieldVTKArray);
47  case 3: return this->DoCompact<3>(inputFieldVTKArray);
48  case 4: return this->DoCompact<4>(inputFieldVTKArray);
49  default:
50  vtkGenericWarningMacro(
51  << "Cannot compact point array " << inputFieldVTKArray.GetName()
52  << " with " << inputFieldVTKArray.GetNumberOfComponents()
53  << " components.");
54  return 0;
55  }
56  }
57 
58  template<int NumComponents, typename InputVTKArrayType>
59  int DoCompact(InputVTKArrayType &inputFieldVTKArray)
60  {
63  ::DaxValueType DaxValueType;
64  typedef dax::cont::ArrayHandle<DaxValueType, ContainerTag>
65  FieldHandleType;
66  typedef typename FieldHandleType::PortalConstControl PortalType;
67 
68  if (inputFieldVTKArray.GetNumberOfComponents() != NumComponents)
69  {
70  // Generally this method is only called from operator(), and that
71  // method is supposed to check that this does not happen.
72  vtkGenericWarningMacro(
73  << "vtkToDax::CompactPointField in unexpected function call.");
74  return 0;
75  }
76 
77  FieldHandleType daxInputField =
78  FieldHandleType(PortalType(&inputFieldVTKArray,
79  inputFieldVTKArray.GetNumberOfTuples()));
80 
81  FieldHandleType daxOutputField;
82 
83  this->Dispatcher->CompactPointField(daxInputField, daxOutputField);
84 
85  daxToVtk::addPointData(this->Output,
86  daxOutputField,
87  inputFieldVTKArray.GetName());
88 
89  return 1;
90  }
91 };
92 
93 } // namespace vtkToDax
94 
95 #endif //vtkToDax_CompactPointField_h
abstract class to specify dataset behavior
Definition: vtkDataSet.h:62
CompactPointField(DispatcherType &dispatcher, vtkDataSet *output)
int operator()(InputVTKArrayType &inputFieldVTKArray)
void addPointData(vtkDataSet *output, FieldType &outputArray, const std::string &name)
int DoCompact(InputVTKArrayType &inputFieldVTKArray)