Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Michael Migliore
VTK
Commits
adb55aa8
Commit
adb55aa8
authored
Aug 18, 2017
by
Sujin Philip
Browse files
Update vtkmExternalFaces
1) Support mapping cell fields 2) Support more types of datasets
parent
5d55287c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Accelerators/Vtkm/Testing/Cxx/TestVTKMExternalFaces.cxx
View file @
adb55aa8
...
...
@@ -17,10 +17,12 @@
#include
"vtkActor.h"
#include
"vtkCell.h"
#include
"vtkCellData.h"
#include
"vtkCylinder.h"
#include
"vtkNew.h"
#include
"vtkPolyData.h"
#include
"vtkPolyDataMapper.h"
#include
"vtkRandomAttributeGenerator.h"
#include
"vtkRegressionTestImage.h"
#include
"vtkRenderer.h"
#include
"vtkRenderWindow.h"
...
...
@@ -92,30 +94,43 @@ int TestVTKMExternalFaces(int argc, char* argv[])
transFilter
->
SetInputConnection
(
clipSphr
->
GetOutputPort
());
transFilter
->
SetTransform
(
transform
.
GetPointer
());
vtkNew
<
vtkRandomAttributeGenerator
>
cellDataAdder
;
cellDataAdder
->
SetInputConnection
(
transFilter
->
GetOutputPort
());
cellDataAdder
->
SetDataTypeToFloat
();
cellDataAdder
->
GenerateCellVectorsOn
();
vtkNew
<
vtkmExternalFaces
>
externalFaces
;
externalFaces
->
SetInputConnection
(
transFilt
er
->
GetOutputPort
());
externalFaces
->
SetInputConnection
(
cellDataAdd
er
->
GetOutputPort
());
// execute pipeline
externalFaces
->
Update
();
vtkUnstructuredGrid
*
result
=
externalFaces
->
GetOutput
();
vtkIdType
numInputPoints
=
externalFaces
->
GetOutput
()
->
GetNumberOfPoints
();
vtkIdType
numInputPoints
=
result
->
GetNumberOfPoints
();
externalFaces
->
CompactPointsOn
();
externalFaces
->
Update
();
result
=
externalFaces
->
GetOutput
();
if
(
externalFaces
->
GetOutput
()
->
GetNumberOfPoints
()
>=
numInputPoints
)
if
(
result
->
GetNumberOfPoints
()
>=
numInputPoints
)
{
std
::
cout
<<
"Expecting the number of points in the output to be less "
<<
"than the input ("
<<
externalFaces
->
GetOutput
()
->
GetNumberOfPoints
()
<<
">="
<<
result
->
GetNumberOfPoints
()
<<
">="
<<
numInputPoints
<<
")
\n
"
;
return
1
;
}
if
(
result
->
GetCellData
()
->
GetArray
(
"RandomCellVectors"
)
->
GetNumberOfTuples
()
!=
result
->
GetNumberOfCells
())
{
std
::
cout
<<
"Expecting a cell field with number of entries equal to "
<<
"the number of cells"
;
return
1
;
}
vtkNew
<
vtkPolyData
>
polydata
;
if
(
!
Convert2DUnstructuredGridToPolyData
(
externalFaces
->
GetOutput
(),
polydata
.
GetPointer
()))
if
(
!
Convert2DUnstructuredGridToPolyData
(
result
,
polydata
.
GetPointer
()))
{
std
::
cout
<<
"Error converting result to polydata
\n
"
;
return
1
;
...
...
Accelerators/Vtkm/vtkmExternalFaces.cxx
View file @
adb55aa8
...
...
@@ -25,7 +25,6 @@
#include
"vtkUnsignedCharArray.h"
#include
"vtkUnstructuredGrid.h"
#include
"vtkmlib/ArrayConverters.h"
#include
"vtkmlib/DataSetConverters.h"
#include
"vtkmlib/Storage.h"
...
...
@@ -38,7 +37,6 @@
#include
<vtkm/filter/ExternalFaces.h>
vtkStandardNewMacro
(
vtkmExternalFaces
)
//------------------------------------------------------------------------------
...
...
@@ -61,7 +59,7 @@ void vtkmExternalFaces::PrintSelf(ostream& os, vtkIndent indent)
}
//------------------------------------------------------------------------------
void
vtkmExternalFaces
::
SetInputData
(
vtkUnstructuredGrid
*
ds
)
void
vtkmExternalFaces
::
SetInputData
(
vtkUnstructuredGrid
*
ds
)
{
this
->
SetInputDataObject
(
0
,
ds
);
}
...
...
@@ -76,12 +74,15 @@ vtkUnstructuredGrid* vtkmExternalFaces::GetOutput()
int
vtkmExternalFaces
::
FillInputPortInformation
(
int
,
vtkInformation
*
info
)
{
info
->
Set
(
vtkAlgorithm
::
INPUT_REQUIRED_DATA_TYPE
(),
"vtkUnstructuredGrid"
);
info
->
Append
(
vtkAlgorithm
::
INPUT_REQUIRED_DATA_TYPE
(),
"vtkImageData"
);
info
->
Append
(
vtkAlgorithm
::
INPUT_REQUIRED_DATA_TYPE
(),
"vtkStructuredGrid"
);
info
->
Append
(
vtkAlgorithm
::
INPUT_REQUIRED_DATA_TYPE
(),
"vtkRectilinearGrid"
);
return
1
;
}
//------------------------------------------------------------------------------
int
vtkmExternalFaces
::
FillOutputPortInformation
(
int
vtkNotUsed
(
port
),
vtkInformation
*
info
)
vtkInformation
*
info
)
{
info
->
Set
(
vtkDataObject
::
DATA_TYPE_NAME
(),
"vtkUnstructuredGrid"
);
return
1
;
...
...
@@ -93,7 +94,7 @@ int vtkmExternalFaces::ProcessRequest(vtkInformation* request,
vtkInformationVector
*
outputVector
)
{
// generate the data
if
(
request
->
Has
(
vtkDemandDrivenPipeline
::
REQUEST_DATA
()))
if
(
request
->
Has
(
vtkDemandDrivenPipeline
::
REQUEST_DATA
()))
{
return
this
->
RequestData
(
request
,
inputVector
,
outputVector
);
}
...
...
@@ -109,8 +110,8 @@ int vtkmExternalFaces::RequestData(vtkInformation* request,
vtkInformation
*
inInfo
=
inputVector
[
0
]
->
GetInformationObject
(
0
);
vtkInformation
*
outInfo
=
outputVector
->
GetInformationObject
(
0
);
vtk
UnstructuredGrid
*
input
=
vtk
UnstructuredGrid
::
SafeDownCast
(
inInfo
->
Get
(
vtkDataObject
::
DATA_OBJECT
()));
vtk
DataSet
*
input
=
vtk
DataSet
::
SafeDownCast
(
inInfo
->
Get
(
vtkDataObject
::
DATA_OBJECT
()));
vtkUnstructuredGrid
*
output
=
vtkUnstructuredGrid
::
SafeDownCast
(
outInfo
->
Get
(
vtkDataObject
::
DATA_OBJECT
()));
...
...
@@ -128,6 +129,7 @@ int vtkmExternalFaces::RequestData(vtkInformation* request,
// apply the filter
vtkm
::
filter
::
ExternalFaces
filter
;
filter
.
SetCompactPoints
(
this
->
CompactPoints
);
filter
.
SetPassPolyData
(
true
);
vtkm
::
filter
::
Result
result
=
filter
.
Execute
(
in
,
policy
);
if
(
!
result
.
IsDataSetValid
())
{
...
...
@@ -135,55 +137,28 @@ int vtkmExternalFaces::RequestData(vtkInformation* request,
return
0
;
}
if
(
this
->
CompactPoints
)
// map fields
vtkm
::
Id
numFields
=
static_cast
<
vtkm
::
Id
>
(
in
.
GetNumberOfFields
());
for
(
vtkm
::
Id
fieldIdx
=
0
;
fieldIdx
<
numFields
;
++
fieldIdx
)
{
// map fields
vtkm
::
Id
numFields
=
static_cast
<
vtkm
::
Id
>
(
in
.
GetNumberOfFields
());
for
(
vtkm
::
Id
fieldIdx
=
0
;
fieldIdx
<
numFields
;
++
fieldIdx
)
const
vtkm
::
cont
::
Field
&
field
=
in
.
GetField
(
fieldIdx
);
try
{
const
vtkm
::
cont
::
Field
&
field
=
in
.
GetField
(
fieldIdx
);
try
{
filter
.
MapFieldOntoOutput
(
result
,
field
,
policy
);
}
catch
(
vtkm
::
cont
::
Error
&
e
)
{
vtkWarningMacro
(
<<
"Unable to use VTKm to convert field( "
<<
field
.
GetName
()
<<
" ) to the ExternalFaces"
<<
" output: "
<<
e
.
what
());
}
filter
.
MapFieldOntoOutput
(
result
,
field
,
policy
);
}
// convert back to vtkDataSet (vtkUnstructuredGrid)
if
(
!
fromvtkm
::
Convert
(
result
.
GetDataSet
(),
output
,
input
))
catch
(
vtkm
::
cont
::
Error
&
e
)
{
vtkErrorMacro
(
<<
"Unable to convert VTKm DataSet back to VTK"
);
return
0
;
vtkWarningMacro
(
<<
"Unable to use VTKm to convert field( "
<<
field
.
GetName
()
<<
" ) to the ExternalFaces"
<<
" output: "
<<
e
.
what
());
}
}
else
{
// convert just the cellset from vtkm to vtk
vtkNew
<
vtkCellArray
>
cells
;
vtkNew
<
vtkUnsignedCharArray
>
types
;
vtkNew
<
vtkIdTypeArray
>
locations
;
vtkm
::
cont
::
DynamicCellSet
cellSet
=
result
.
GetDataSet
().
GetCellSet
();
if
(
!
fromvtkm
::
Convert
(
cellSet
,
cells
.
GetPointer
(),
types
.
GetPointer
(),
locations
.
GetPointer
()))
{
vtkErrorMacro
(
<<
"Unable to convert VTKm DataSet back to VTK"
);
return
0
;
}
// copy points from input to output
output
->
SetPoints
(
input
->
GetPoints
());
// add the new cellset to output
output
->
SetCells
(
types
.
GetPointer
(),
locations
.
GetPointer
(),
cells
.
GetPointer
());
// copy the point data from input to output
output
->
GetPointData
()
->
PassData
(
input
->
GetPointData
());
// convert back to vtkDataSet (vtkUnstructuredGrid)
if
(
!
fromvtkm
::
Convert
(
result
.
GetDataSet
(),
output
,
input
))
{
vtkErrorMacro
(
<<
"Unable to convert VTKm DataSet back to VTK"
);
return
0
;
}
return
1
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment