Skip to content
GitLab
Menu
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
140d6bd8
Commit
140d6bd8
authored
May 05, 2017
by
Sujin Philip
Browse files
Add clipping with implicit function to vtkmClip
parent
4b34c3d7
Changes
6
Hide whitespace changes
Inline
Side-by-side
Accelerators/Vtkm/Testing/Cxx/CMakeLists.txt
View file @
140d6bd8
...
...
@@ -5,6 +5,7 @@ include_directories(${VTKm_INCLUDE_DIRS})
vtk_add_test_cxx
(
${
vtk-module
}
CxxTests tests
TestVTKMCleanGrid.cxx
TestVTKMClip.cxx
TestVTKMClipWithImplicitFunction.cxx
# TestVTKMGradientAndVorticity.cxx,NO_VALID
TestVTKMExternalFaces.cxx
TestVTKMLevelOfDetail.cxx
...
...
Accelerators/Vtkm/Testing/Cxx/TestVTKMClip.cxx
View file @
140d6bd8
...
...
@@ -74,16 +74,12 @@ int TestVTKMClip(int, char*[])
sphereClipper
->
SetInputData
(
sphere
);
sphereClipper
->
SetComputeScalars
(
true
);
sphereClipper
->
SetClipValue
(
0.
);
sphereClipper
->
Update
();
if
(
!
sphereClipper
->
GetOutput
()
->
IsA
(
"vtkPolyData"
))
{
std
::
cerr
<<
"Expected an input with 2D cells to produce polydata. Got: "
<<
sphereClipper
->
GetOutput
()
->
GetClassName
()
<<
"
\n
"
;
return
EXIT_FAILURE
;
}
vtkNew
<
vtkDataSetSurfaceFilter
>
sphSurface
;
sphSurface
->
SetInputConnection
(
sphereClipper
->
GetOutputPort
());
vtkNew
<
vtkPolyDataMapper
>
sphereMapper
;
sphereMapper
->
SetInputConnection
(
sph
ereClipper
->
GetOutputPort
());
sphereMapper
->
SetInputConnection
(
sph
Surface
->
GetOutputPort
());
sphereMapper
->
SetScalarVisibility
(
1
);
sphereMapper
->
SetScalarModeToUsePointFieldData
();
sphereMapper
->
SelectColorArray
(
"x+y"
);
...
...
@@ -116,13 +112,6 @@ int TestVTKMClip(int, char*[])
tetClipper
->
SetInputData
(
tets
);
tetClipper
->
SetComputeScalars
(
true
);
tetClipper
->
SetClipValue
(
0.
);
tetClipper
->
Update
();
if
(
!
tetClipper
->
GetOutput
()
->
IsA
(
"vtkUnstructuredGrid"
))
{
std
::
cerr
<<
"Expected an input with 3D cells to produce an ugrid. Got: "
<<
tetClipper
->
GetOutput
()
->
GetClassName
()
<<
"
\n
"
;
return
EXIT_FAILURE
;
}
vtkNew
<
vtkDataSetSurfaceFilter
>
tetSurface
;
tetSurface
->
SetInputConnection
(
tetClipper
->
GetOutputPort
());
...
...
@@ -147,13 +136,6 @@ int TestVTKMClip(int, char*[])
imageClipper
->
SetInputData
(
image
);
imageClipper
->
SetComputeScalars
(
true
);
imageClipper
->
SetClipValue
(
0.
);
imageClipper
->
Update
();
if
(
!
tetClipper
->
GetOutput
()
->
IsA
(
"vtkUnstructuredGrid"
))
{
std
::
cerr
<<
"Expected an imagedata to produce a clipped ugrid. Got: "
<<
tetClipper
->
GetOutput
()
->
GetClassName
()
<<
"
\n
"
;
return
EXIT_FAILURE
;
}
vtkNew
<
vtkDataSetSurfaceFilter
>
imageSurface
;
imageSurface
->
SetInputConnection
(
imageClipper
->
GetOutputPort
());
...
...
Accelerators/Vtkm/Testing/Cxx/TestVTKMClipWithImplicitFunction.cxx
0 → 100644
View file @
140d6bd8
/*=========================================================================
Program: Visualization Toolkit
Module: TestVTKMClipWithImplicitFunction.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include
"vtkmClip.h"
#include
"vtkActor.h"
#include
"vtkDataArray.h"
#include
"vtkDataSetSurfaceFilter.h"
#include
"vtkNew.h"
#include
"vtkPointData.h"
#include
"vtkPolyData.h"
#include
"vtkPolyDataMapper.h"
#include
"vtkRegressionTestImage.h"
#include
"vtkRenderer.h"
#include
"vtkRenderWindow.h"
#include
"vtkRenderWindowInteractor.h"
#include
"vtkRTAnalyticSource.h"
#include
"vtkSphere.h"
int
TestVTKMClipWithImplicitFunction
(
int
argc
,
char
*
argv
[])
{
vtkNew
<
vtkRTAnalyticSource
>
wavelet
;
wavelet
->
SetWholeExtent
(
-
8
,
8
,
-
8
,
8
,
-
8
,
8
);
wavelet
->
SetCenter
(
0
,
0
,
0
);
vtkNew
<
vtkSphere
>
sphere
;
sphere
->
SetCenter
(
0
,
0
,
0
);
sphere
->
SetRadius
(
10
);
vtkNew
<
vtkmClip
>
clip
;
clip
->
SetInputConnection
(
wavelet
->
GetOutputPort
());
clip
->
SetClipFunction
(
sphere
.
GetPointer
());
vtkNew
<
vtkDataSetSurfaceFilter
>
surface
;
surface
->
SetInputConnection
(
clip
->
GetOutputPort
());
vtkNew
<
vtkPolyDataMapper
>
mapper
;
mapper
->
SetInputConnection
(
surface
->
GetOutputPort
());
mapper
->
SetScalarRange
(
37
,
150
);
vtkNew
<
vtkActor
>
actor
;
actor
->
SetMapper
(
mapper
.
GetPointer
());
vtkNew
<
vtkRenderer
>
renderer
;
renderer
->
AddActor
(
actor
.
GetPointer
());
renderer
->
ResetCamera
();
vtkNew
<
vtkRenderWindow
>
renWin
;
renWin
->
AddRenderer
(
renderer
.
GetPointer
());
vtkNew
<
vtkRenderWindowInteractor
>
iren
;
iren
->
SetRenderWindow
(
renWin
.
GetPointer
());
iren
->
Initialize
();
renWin
->
Render
();
int
retVal
=
vtkRegressionTestImage
(
renWin
.
GetPointer
());
if
(
retVal
==
vtkRegressionTester
::
DO_INTERACTOR
)
{
iren
->
Start
();
}
return
!
retVal
;
}
Accelerators/Vtkm/Testing/Data/Baseline/TestVTKMClipWithImplicitFunction.png.md5
0 → 100644
View file @
140d6bd8
9e17bd4d4454c63f73bf8694961737aa
Accelerators/Vtkm/vtkmClip.cxx
View file @
140d6bd8
...
...
@@ -19,11 +19,13 @@
#include
"vtkDataArray.h"
#include
"vtkDataSet.h"
#include
"vtkDemandDrivenPipeline.h"
#include
"vtkImplicitFunction.h"
#include
"vtkInformation.h"
#include
"vtkInformationVector.h"
#include
"vtkObjectFactory.h"
#include
"vtkPointData.h"
#include
"vtkPolyData.h"
#include
"vtkTableBasedClipDataSet.h"
#include
"vtkUnstructuredGrid.h"
#include
"vtkmlib/ArrayConverters.h"
...
...
@@ -37,6 +39,10 @@
#include
"vtkmFilterPolicy.h"
#include
<vtkm/filter/ClipWithField.h>
#include
<vtkm/filter/ClipWithImplicitFunction.h>
#include
<algorithm>
vtkStandardNewMacro
(
vtkmClip
)
...
...
@@ -46,13 +52,16 @@ void vtkmClip::PrintSelf(std::ostream &os, vtkIndent indent)
this
->
Superclass
::
PrintSelf
(
os
,
indent
);
os
<<
indent
<<
"ClipValue: "
<<
this
->
ClipValue
<<
"
\n
"
;
os
<<
indent
<<
"ClipFunction:
\n
"
;
this
->
ClipFunction
->
PrintSelf
(
os
,
indent
.
GetNextIndent
());
os
<<
indent
<<
"ComputeScalars: "
<<
this
->
ComputeScalars
<<
"
\n
"
;
}
//------------------------------------------------------------------------------
vtkmClip
::
vtkmClip
()
:
ClipValue
(
0.
),
ComputeScalars
(
true
)
ComputeScalars
(
true
),
ClipFunction
(
nullptr
)
{
// Clip active point scalars by default
this
->
SetInputArrayToProcess
(
0
,
0
,
0
,
vtkDataObject
::
FIELD_ASSOCIATION_POINTS
,
...
...
@@ -64,54 +73,26 @@ vtkmClip::~vtkmClip()
{
}
//------------------------------------------------------------------------------
int
vtkmClip
::
RequestDataObject
(
vtkInformation
*
,
vtkInformationVector
**
inVec
,
vtkInformationVector
*
outVec
)
//----------------------------------------------------------------------------
vtkMTimeType
vtkmClip
::
GetMTime
()
{
vtk
Information
*
inInfo
=
inVec
[
0
]
->
GetInformationObject
(
0
);
if
(
!
inInfo
)
vtk
MTimeType
mTime
=
this
->
Superclass
::
GetMTime
(
);
if
(
this
->
ClipFunction
)
{
return
0
;
mTime
=
std
::
max
(
mTime
,
this
->
ClipFunction
->
GetMTime
())
;
}
return
mTime
;
}
vtkDataSet
*
input
=
vtkDataSet
::
SafeDownCast
(
inInfo
->
Get
(
vtkDataObject
::
DATA_OBJECT
()));
if
(
input
)
//----------------------------------------------------------------------------
void
vtkmClip
::
SetClipFunction
(
vtkImplicitFunction
*
clipFunction
)
{
if
(
this
->
ClipFunction
!=
clipFunction
)
{
// If the input has 3D cells, we will produce an unstructured grid. Otherwise,
// we'll make a polydata:
bool
has3DCells
=
false
;
vtkCellIterator
*
i
=
input
->
NewCellIterator
();
for
(
i
->
InitTraversal
();
!
i
->
IsDoneWithTraversal
();
i
->
GoToNextCell
())
{
if
(
i
->
GetCellDimension
()
==
3
)
{
has3DCells
=
true
;
break
;
}
}
i
->
Delete
();
vtkInformation
*
info
=
outVec
->
GetInformationObject
(
0
);
vtkDataObject
*
output
=
info
->
Get
(
vtkDataObject
::
DATA_OBJECT
());
if
(
has3DCells
&&
(
!
output
||
!
output
->
IsA
(
"vtkUnstructuredGrid"
)))
{
vtkNew
<
vtkUnstructuredGrid
>
newOutput
;
info
->
Set
(
vtkDataObject
::
DATA_OBJECT
(),
newOutput
.
Get
());
}
else
if
(
!
has3DCells
&&
(
!
output
||
!
output
->
IsA
(
"vtkPolyData"
)))
{
vtkNew
<
vtkPolyData
>
newOutput
;
info
->
Set
(
vtkDataObject
::
DATA_OBJECT
(),
newOutput
.
Get
());
}
return
1
;
this
->
ClipFunction
=
clipFunction
;
this
->
ClipFunctionConverter
.
Set
(
clipFunction
);
this
->
Modified
();
}
return
0
;
}
//------------------------------------------------------------------------------
...
...
@@ -124,8 +105,9 @@ int vtkmClip::RequestData(vtkInformation *,
// Extract data objects from info:
vtkDataSet
*
input
=
vtkDataSet
::
SafeDownCast
(
inInfo
->
Get
(
vtkDataObject
::
DATA_OBJECT
()));
vtkDataObject
*
outputDO
=
outInfo
->
Get
(
vtkDataObject
::
DATA_OBJECT
());
vtkDataSet
::
SafeDownCast
(
inInfo
->
Get
(
vtkDataObject
::
DATA_OBJECT
()));
vtkUnstructuredGrid
*
output
=
vtkUnstructuredGrid
::
SafeDownCast
(
outInfo
->
Get
(
vtkDataObject
::
DATA_OBJECT
()));
// Find the scalar array:
int
assoc
=
this
->
GetInputArrayAssociation
(
0
,
inInfoVec
);
...
...
@@ -160,17 +142,39 @@ int vtkmClip::RequestData(vtkInformation *,
}
// Configure vtkm filter:
vtkm
::
filter
::
ClipWithField
filter
;
filter
.
SetClipValue
(
this
->
ClipValue
)
;
vtkm
::
filter
::
ClipWithField
fi
eldFi
lter
;
vtkm
::
filter
::
ClipWithImplicitFunction
functionFilter
;
// Run filter:
vtkm
::
filter
::
ResultDataSet
result
;
vtkmInputFilterPolicy
policy
;
result
=
filter
.
Execute
(
in
,
field
,
policy
);
if
(
this
->
ClipFunction
)
{
auto
function
=
this
->
ClipFunctionConverter
.
Get
();
if
(
function
.
get
())
{
functionFilter
.
SetImplicitFunction
(
function
);
result
=
functionFilter
.
Execute
(
in
,
policy
);
}
}
else
{
fieldFilter
.
SetClipValue
(
this
->
ClipValue
);
result
=
fieldFilter
.
Execute
(
in
,
field
,
policy
);
}
if
(
!
result
.
IsValid
())
{
vtkErrorMacro
(
"vtkm Clip filter failed to run."
);
vtkWarningMacro
(
<<
"vtkm Clip filter failed to run.
\n
"
<<
"Falling back to serial implementation."
);
vtkNew
<
vtkTableBasedClipDataSet
>
filter
;
filter
->
SetClipFunction
(
this
->
ClipFunction
);
filter
->
SetValue
(
this
->
ClipValue
);
filter
->
SetInputData
(
input
);
filter
->
Update
();
output
->
ShallowCopy
(
filter
->
GetOutput
());
return
1
;
}
...
...
@@ -191,7 +195,10 @@ int vtkmClip::RequestData(vtkInformation *,
try
{
if
(
!
filter
.
MapFieldOntoOutput
(
result
,
pField
,
policy
))
bool
success
=
this
->
ClipFunction
?
functionFilter
.
MapFieldOntoOutput
(
result
,
pField
,
policy
)
:
fieldFilter
.
MapFieldOntoOutput
(
result
,
pField
,
policy
);
if
(
!
success
)
{
throw
vtkm
::
cont
::
ErrorBadValue
(
"MapFieldOntoOutput returned false."
);
}
...
...
@@ -209,29 +216,11 @@ int vtkmClip::RequestData(vtkInformation *,
}
// Convert result to output:
vtkUnstructuredGrid
*
outputUG
=
vtkUnstructuredGrid
::
SafeDownCast
(
outputDO
);
vtkPolyData
*
outputPD
=
outputUG
?
NULL
:
vtkPolyData
::
SafeDownCast
(
outputDO
);
bool
outputValid
=
false
;
if
(
outputUG
)
{
outputValid
=
fromvtkm
::
Convert
(
result
.
GetDataSet
(),
outputUG
,
input
);
}
else
if
(
outputPD
)
{
outputValid
=
fromvtkm
::
Convert
(
result
.
GetDataSet
(),
outputPD
,
input
);
}
else
{
vtkErrorMacro
(
"Unsupported output data object type: "
<<
(
outputDO
?
outputDO
->
GetClassName
()
:
"(NULL)"
));
return
1
;
}
bool
outputValid
=
fromvtkm
::
Convert
(
result
.
GetDataSet
(),
output
,
input
);
if
(
!
outputValid
)
{
vtkErrorMacro
(
"Error generating vtk
PolyData
from vtkm's result."
);
output
DO
->
Initialize
();
vtkErrorMacro
(
"Error generating vtk
UnstructuredGrid
from vtkm's result."
);
output
->
Initialize
();
return
1
;
}
...
...
@@ -249,10 +238,3 @@ int vtkmClip::FillInputPortInformation(int, vtkInformation *info)
info
->
Append
(
vtkAlgorithm
::
INPUT_REQUIRED_DATA_TYPE
(),
"vtkImageData"
);
return
1
;
}
//------------------------------------------------------------------------------
int
vtkmClip
::
FillOutputPortInformation
(
int
,
vtkInformation
*
info
)
{
info
->
Set
(
vtkDataObject
::
DATA_TYPE_NAME
(),
"vtkPointSet"
);
return
1
;
}
Accelerators/Vtkm/vtkmClip.h
View file @
140d6bd8
...
...
@@ -21,13 +21,18 @@
#define vtkmClip_h
#include
"vtkAcceleratorsVTKmModule.h"
// For export macro
#include
"vtkDataSetAlgorithm.h"
#include
"vtkUnstructuredGridAlgorithm.h"
#include
"vtkmlib/ImplicitFunctionConverter.h"
// For ImplicitFunctionConverter
class
VTKACCELERATORSVTKM_EXPORT
vtkmClip
:
public
vtkDataSetAlgorithm
#include
<memory>
// For std::shared_ptr
class
vtkImplicitFunction
;
class
VTKACCELERATORSVTKM_EXPORT
vtkmClip
:
public
vtkUnstructuredGridAlgorithm
{
public:
static
vtkmClip
*
New
();
vtkTypeMacro
(
vtkmClip
,
vtk
DataSet
Algorithm
)
vtkTypeMacro
(
vtkmClip
,
vtk
UnstructuredGrid
Algorithm
)
void
PrintSelf
(
ostream
&
os
,
vtkIndent
indent
)
VTK_OVERRIDE
;
/**
...
...
@@ -44,21 +49,31 @@ public:
vtkGetMacro
(
ComputeScalars
,
bool
)
vtkSetMacro
(
ComputeScalars
,
bool
)
/**
* Set the implicit function with which to perform the clipping. If set,
* \c ClipValue is ignored and the clipping is performed using the implicit
* function.
*/
void
SetClipFunction
(
vtkImplicitFunction
*
);
vtkGetObjectMacro
(
ClipFunction
,
vtkImplicitFunction
);
vtkMTimeType
GetMTime
()
VTK_OVERRIDE
;
protected:
vtkmClip
();
~
vtkmClip
();
int
RequestDataObject
(
vtkInformation
*
,
vtkInformationVector
**
,
vtkInformationVector
*
)
VTK_OVERRIDE
;
int
RequestData
(
vtkInformation
*
,
vtkInformationVector
**
,
vtkInformationVector
*
)
VTK_OVERRIDE
;
int
FillInputPortInformation
(
int
port
,
vtkInformation
*
info
)
VTK_OVERRIDE
;
int
FillOutputPortInformation
(
int
port
,
vtkInformation
*
info
)
VTK_OVERRIDE
;
double
ClipValue
;
bool
ComputeScalars
;
vtkImplicitFunction
*
ClipFunction
;
tovtkm
::
ImplicitFunctionConverter
ClipFunctionConverter
;
private:
vtkmClip
(
const
vtkmClip
&
)
VTK_DELETE_FUNCTION
;
void
operator
=
(
const
vtkmClip
&
)
VTK_DELETE_FUNCTION
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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