VTK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vtkDaxThresholdImpl.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 2012 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 __vtkDaxThresholdImpl_h
18 #define __vtkDaxThresholdImpl_h
19 
20 // Common code
21 #include "vtkDaxConfig.h"
22 #include "vtkDaxDetailCommon.h"
23 
24 #include "vtkDispatcher.h"
25 #include "vtkDoubleDispatcher.h"
26 #include "vtkNew.h"
27 
28 //cell types we support
29 #include "vtkCellTypes.h"
30 #include "vtkGenericCell.h"
31 #include "vtkHexahedron.h"
32 #include "vtkLine.h"
33 #include "vtkQuad.h"
34 #include "vtkTetra.h"
35 #include "vtkTriangle.h"
36 #include "vtkVertex.h"
37 #include "vtkVoxel.h"
38 #include "vtkWedge.h"
39 
40 //fields we support
41 #include "vtkFloatArray.h"
42 #include "vtkIntArray.h"
43 #include "vtkUnsignedCharArray.h"
44 
45 //datasets we support
46 #include "vtkDataObjectTypes.h"
47 #include "vtkImageData.h"
48 #include "vtkStructuredGrid.h"
49 #include "vtkUniformGrid.h"
50 #include "vtkUnstructuredGrid.h"
51 
52 //helpers that convert to and from Dax
53 #include "vtkToDax/CellTypeToType.h"
54 #include "vtkToDax/Containers.h"
55 #include "vtkToDax/DataSetTypeToType.h"
56 #include "vtkToDax/FieldTypeToType.h"
57 #include "vtkToDax/Portals.h"
58 #include "vtkToDax/Threshold.h"
59 
60 
61 namespace vtkDax{
62 namespace detail{
63 
65  {
66  typedef int ReturnType;
69  double Min;
70  double Max;
71 
73 
75  vtkCell* cell, double lower, double upper):
76  Input(in),Cell(cell),Min(lower),Max(upper),Result(out){}
77 
78  template<typename LHS>
79  int operator()(LHS &arrayField) const
80  {
81  //we can derive the type of the field at compile time, but not the
82  //length
83  switch(arrayField.GetNumberOfComponents())
84  {
85  case 1:
86  //first we extract the field type of the array
87  //second we extract the number of components
88  typedef typename vtkToDax::FieldTypeToType<LHS,1>::FieldType FT1;
89  return dispatchOnFieldType<LHS,FT1>(arrayField);
90  case 2:
91  typedef typename vtkToDax::FieldTypeToType<LHS,2>::FieldType FT2;
92  return dispatchOnFieldType<LHS,FT2>(arrayField);
93  case 3:
94  typedef typename vtkToDax::FieldTypeToType<LHS,3>::FieldType FT3;
95  return dispatchOnFieldType<LHS,FT3>(arrayField);
96  default:
97  //currently only support 1 to 3 components
98  //we need to make dispatch on field data smarter in that it does
99  //this automagically
100  return 0;
101  }
102 
103 
104  }
105 
106  template<typename VTKArrayType, typename DaxFieldType>
107  int dispatchOnFieldType(VTKArrayType& vtkField) const
108  {
109  typedef DaxFieldType FieldType;
110  typedef vtkToDax::vtkArrayContainerTag<VTKArrayType> FieldTag;
111  typedef dax::cont::ArrayHandle<FieldType,FieldTag> FieldHandle;
112  typedef typename dax::cont::ArrayHandle<FieldType,
113  FieldTag>::PortalConstControl PortalType;
114 
115  FieldHandle field = FieldHandle( PortalType(&vtkField,
116  vtkField.GetNumberOfTuples() ) );
117  vtkToDax::Threshold<FieldHandle> threshold(field,
118  FieldType(Min),
119  FieldType(Max));
120  threshold.setFieldName(vtkField.GetName());
121  threshold.setOutputGrid(this->Result);
122 
123  //see if we have a valid data set type
124  //if so will perform the threshold if possible
126  dataDispatcher.Add<vtkImageData,vtkVoxel>(threshold);
127  dataDispatcher.Add<vtkUniformGrid,vtkVoxel>(threshold);
128 
129  dataDispatcher.Add<vtkUnstructuredGrid,vtkHexahedron>(threshold);
130  dataDispatcher.Add<vtkUnstructuredGrid,vtkLine>(threshold);
131  dataDispatcher.Add<vtkUnstructuredGrid,vtkQuad>(threshold);
132  dataDispatcher.Add<vtkUnstructuredGrid,vtkTetra>(threshold);
133  dataDispatcher.Add<vtkUnstructuredGrid,vtkTriangle>(threshold);
134  dataDispatcher.Add<vtkUnstructuredGrid,vtkVertex>(threshold);
135  dataDispatcher.Add<vtkUnstructuredGrid,vtkWedge>(threshold);
136 
137  int validThreshold = dataDispatcher.Go(this->Input,this->Cell);
138  return validThreshold;
139  }
140  private:
141  void operator=(const ValidThresholdInput&);
142  };
143 } //end detail namespace
144 
145 
146 //------------------------------------------------------------------------------
148  vtkDataArray* field, double lower, double upper)
149 {
150  //we are doing a point threshold now verify we have suitable cells
151  //Dax currently supports: hexs,lines,quads,tets,triangles,vertex,voxel,wedge
152  //if something a cell that doesn't match that list we punt to the
153  //VTK implementation.
155 
156  //construct the object that holds all the state needed to do the threshold
157  vtkDax::detail::ValidThresholdInput validInput(input,output,cType.Cell,
158  lower,
159  upper);
160 
161 
162  //setup the dispatch to only allow float and int array to go to the next step
163  vtkDispatcher<vtkAbstractArray,int> fieldDispatcher;
164  fieldDispatcher.Add<vtkFloatArray>(validInput);
165  fieldDispatcher.Add<vtkUnsignedCharArray>(validInput);
166  fieldDispatcher.Add<vtkIntArray>(validInput);
167  return fieldDispatcher.Go(field);
168 }
169 
170 } //end vtkDax namespace
171 // VTK-HeaderTest-Exclude: vtkDaxThresholdImpl.h
172 #endif
ReturnType Go(BaseLhs *lhs, BaseRhs *rhs)
void Add(Functor fun)
int operator()(LHS &arrayField) const
GLenum GLenum GLenum input
Definition: vtkgl.h:15941
abstract class to specify dataset behavior
Definition: vtkDataSet.h:60
a cell that represents a 3D point
Definition: vtkVertex.h:35
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:45
GLuint in
Definition: vtkgl.h:16905
a cell that represents a 2D quadrilateral
Definition: vtkQuad.h:40
int dispatchOnFieldType(VTKArrayType &vtkField) const
void Add(Functor fun)
a 3D cell that represents a tetrahedron
Definition: vtkTetra.h:46
cell represents a 1D line
Definition: vtkLine.h:34
abstract class to specify cell behavior
Definition: vtkCell.h:58
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:45
Dispatch to functor based on two pointer types.
a cell that represents a 3D orthogonal parallelepiped
Definition: vtkVoxel.h:43
int Threshold(vtkDataSet *input, vtkUnstructuredGrid *output, vtkDataArray *field, double lower, double upper)
topologically and geometrically regular array of data
Definition: vtkImageData.h:44
dataset represents arbitrary combinations of all possible cell types
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:53
a cell that represents a linear 3D hexahedron
Definition: vtkHexahedron.h:46
ValidThresholdInput(vtkDataSet *in, vtkUnstructuredGrid *out, vtkCell *cell, double lower, double upper)
Dispatch to functor based on a pointer type.
Definition: vtkDispatcher.h:90
dynamic, self-adjusting array of unsigned char
CellTypeInDataSet cellType(vtkDataSet *input)
image data with blanking
ReturnType Go(BaseLhs *lhs)
a cell that represents a triangle
Definition: vtkTriangle.h:40
a 3D cell that represents a linear wedge
Definition: vtkWedge.h:48