Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VTK Examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VTK
VTK Examples
Merge requests
!94
Modernising the code, improving images
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Modernising the code, improving images
Modernise_UnstructuredGrid
into
master
Overview
0
Commits
1
Pipelines
0
Changes
12
Merged
Andrew Maclean
requested to merge
Modernise_UnstructuredGrid
into
master
4 years ago
Overview
0
Commits
1
Pipelines
0
Changes
12
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
b06f6a3d
1 commit,
4 years ago
12 files
+
153
−
173
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
12
Search (e.g. *.vue) (Ctrl+P)
src/Cxx/UnstructuredGrid/ClipUnstructuredGridWithPlane.cxx
+
37
−
47
Options
#include
<vtkSmartPointer.h>
#include
<vtkTableBasedClipDataSet.h>
#include
<vtkUnstructuredGridReader.h>
#include
<vtkUnstructuredGrid.h>
#include
<vtkPlane.h>
#include
<vtkTransform.h>
#include
<vtkActor.h>
#include
<vtkCamera.h>
#include
<vtkCellTypes.h>
#include
<vtkDataSetMapper.h>
#include
<vtkLookupTable.h>
#include
<vtkNamedColors.h>
#include
<vtkNew.h>
#include
<vtkPlane.h>
#include
<vtkProperty.h>
#include
<vtkRenderWindow.h>
#include
<vtkRenderWindowInteractor.h>
#include
<vtkRenderer.h>
#include
<vtkTableBasedClipDataSet.h>
#include
<vtkTransform.h>
#include
<vtkUnstructuredGrid.h>
#include
<vtkUnstructuredGridReader.h>
#include
<vtkNamedColors.h>
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
2
)
{
std
::
cout
<<
"Usage: "
<<
argv
[
0
]
<<
" filename.vtk"
<<
std
::
endl
;
std
::
cout
<<
"Usage: "
<<
argv
[
0
]
<<
" filename.vtk e.g. treemesh.vtk"
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
// Create the reader for the data.
std
::
string
filename
=
argv
[
1
];
std
::
cout
<<
"Loading "
<<
filename
.
c_str
()
<<
std
::
endl
;
auto
reader
=
vtkSmartPointer
<
vtkUnstructuredGridReader
>::
New
();
vtkNew
<
vtkUnstructuredGridReader
>
reader
;
reader
->
SetFileName
(
filename
.
c_str
());
reader
->
Update
();
double
bounds
[
6
];
reader
->
GetOutput
()
->
GetBounds
(
bounds
);
reader
->
GetOutput
()
->
GetBounds
(
bounds
);
double
center
[
3
];
reader
->
GetOutput
()
->
GetCenter
(
center
);
reader
->
GetOutput
()
->
GetCenter
(
center
);
auto
colors
=
vtkSmartPointer
<
vtkNamedColors
>::
New
();
auto
renderer
=
vtkSmartPointer
<
vtkRenderer
>::
New
();
vtkNew
<
vtkNamedColors
>
colors
;
vtkNew
<
vtkRenderer
>
renderer
;
renderer
->
SetBackground
(
colors
->
GetColor3d
(
"Wheat"
).
GetData
());
renderer
->
UseHiddenLineRemovalOn
();
auto
renderWindow
=
vtkSmartPointer
<
vtkRenderWindow
>::
New
();
vtkNew
<
vtkRenderWindow
>
renderWindow
;
renderWindow
->
AddRenderer
(
renderer
);
renderWindow
->
SetSize
(
640
,
480
);
auto
interactor
=
vtkSmartPointer
<
vtkRenderWindowInteractor
>::
New
();
vtkNew
<
vtkRenderWindowInteractor
>
interactor
;
interactor
->
SetRenderWindow
(
renderWindow
);
double
xnorm
[
3
]
=
{
-
1.0
,
-
1.0
,
1.0
};
auto
clipPlane
=
vtkSmartPointer
<
vtkPlane
>::
New
()
;
vtkNew
<
vtkPlane
>
clipPlane
;
clipPlane
->
SetOrigin
(
reader
->
GetOutput
()
->
GetCenter
());
clipPlane
->
SetNormal
(
xnorm
);
auto
clipper
=
vtkSmartPointer
<
vtkTableBasedClipDataSet
>::
New
();
vtkNew
<
vtkTableBasedClipDataSet
>
clipper
;
clipper
->
SetClipFunction
(
clipPlane
);
clipper
->
SetInputData
(
reader
->
GetOutput
());
clipper
->
SetValue
(
0.0
);
clipper
->
GenerateClippedOutputOn
();
clipper
->
Update
();
auto
insideMapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
vtkNew
<
vtkDataSetMapper
>
insideMapper
;
insideMapper
->
SetInputData
(
clipper
->
GetOutput
());
insideMapper
->
ScalarVisibilityOff
();
auto
insideActor
=
vtkSmartPointer
<
vtkActor
>::
New
();
vtkNew
<
vtkActor
>
insideActor
;
insideActor
->
SetMapper
(
insideMapper
);
insideActor
->
GetProperty
()
->
SetDiffuseColor
(
colors
->
GetColor3d
(
"banana"
).
GetData
());
insideActor
->
GetProperty
()
->
SetDiffuseColor
(
colors
->
GetColor3d
(
"Banana"
).
GetData
());
insideActor
->
GetProperty
()
->
SetAmbient
(
.3
);
insideActor
->
GetProperty
()
->
EdgeVisibilityOn
();
auto
clippedMapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
vtkNew
<
vtkDataSetMapper
>
clippedMapper
;
clippedMapper
->
SetInputData
(
clipper
->
GetClippedOutput
());
clippedMapper
->
ScalarVisibilityOff
();
auto
clippedActor
=
vtkSmartPointer
<
vtkActor
>::
New
();
vtkNew
<
vtkActor
>
clippedActor
;
clippedActor
->
SetMapper
(
clippedMapper
);
clippedActor
->
GetProperty
()
->
SetDiffuseColor
(
colors
->
GetColor3d
(
"tomato"
).
GetData
());
clippedActor
->
GetProperty
()
->
SetDiffuseColor
(
colors
->
GetColor3d
(
"Tomato"
).
GetData
());
insideActor
->
GetProperty
()
->
SetAmbient
(
.3
);
clippedActor
->
GetProperty
()
->
EdgeVisibilityOn
();
// Create transforms to make a better visualization
auto
insideTransform
=
vtkSmartPointer
<
vtk
Transform
>::
New
()
;
vtkNew
<
vtkTransform
>
inside
Transform
;
insideTransform
->
Translate
(
-
(
bounds
[
1
]
-
bounds
[
0
])
*
.75
,
0
,
0
);
insideTransform
->
Translate
(
center
[
0
],
center
[
1
],
center
[
2
]);
insideTransform
->
RotateY
(
-
120.0
);
insideTransform
->
Translate
(
-
center
[
0
],
-
center
[
1
],
-
center
[
2
]);
insideActor
->
SetUserTransform
(
insideTransform
);
auto
clippedTransform
=
vtkSmartPointer
<
vtk
Transform
>::
New
()
;
vtkNew
<
vtkTransform
>
clipped
Transform
;
clippedTransform
->
Translate
((
bounds
[
1
]
-
bounds
[
0
])
*
.75
,
0
,
0
);
clippedTransform
->
Translate
(
center
[
0
],
center
[
1
],
center
[
2
]);
clippedTransform
->
RotateY
(
60.0
);
@@ -121,9 +113,9 @@ int main(int argc, char *argv[])
vtkIdType
numberOfCells
=
clipper
->
GetOutput
()
->
GetNumberOfCells
();
std
::
cout
<<
"------------------------"
<<
std
::
endl
;
std
::
cout
<<
"The inside dataset contains a "
<<
std
::
endl
<<
clipper
->
GetOutput
()
->
GetClassName
()
<<
" that has "
<<
numberOfCells
<<
" cells"
<<
std
::
endl
;
typedef
std
::
map
<
int
,
int
>
CellContainer
;
<<
clipper
->
GetOutput
()
->
GetClassName
()
<<
" that has "
<<
numberOfCells
<<
" cells"
<<
std
::
endl
;
typedef
std
::
map
<
int
,
int
>
CellContainer
;
CellContainer
cellMap
;
for
(
vtkIdType
i
=
0
;
i
<
numberOfCells
;
i
++
)
{
@@ -132,17 +124,16 @@ int main(int argc, char *argv[])
for
(
auto
c
:
cellMap
)
{
std
::
cout
<<
"
\t
Cell type "
<<
vtkCellTypes
::
GetClassNameFromTypeId
(
c
.
first
)
std
::
cout
<<
"
\t
Cell type "
<<
vtkCellTypes
::
GetClassNameFromTypeId
(
c
.
first
)
<<
" occurs "
<<
c
.
second
<<
" times."
<<
std
::
endl
;
}
numberOfCells
=
clipper
->
GetClippedOutput
()
->
GetNumberOfCells
();
std
::
cout
<<
"------------------------"
<<
std
::
endl
;
std
::
cout
<<
"The clipped dataset contains a "
<<
std
::
endl
<<
clipper
->
GetClippedOutput
()
->
GetClassName
()
<<
" that has "
<<
numberOfCells
<<
" cells"
<<
std
::
endl
;
typedef
std
::
map
<
int
,
int
>
OutsideCellContainer
;
<<
clipper
->
GetClippedOutput
()
->
GetClassName
()
<<
" that has "
<<
numberOfCells
<<
" cells"
<<
std
::
endl
;
typedef
std
::
map
<
int
,
int
>
OutsideCellContainer
;
CellContainer
outsideCellMap
;
for
(
vtkIdType
i
=
0
;
i
<
numberOfCells
;
i
++
)
{
@@ -151,8 +142,7 @@ int main(int argc, char *argv[])
for
(
auto
c
:
outsideCellMap
)
{
std
::
cout
<<
"
\t
Cell type "
<<
vtkCellTypes
::
GetClassNameFromTypeId
(
c
.
first
)
std
::
cout
<<
"
\t
Cell type "
<<
vtkCellTypes
::
GetClassNameFromTypeId
(
c
.
first
)
<<
" occurs "
<<
c
.
second
<<
" times."
<<
std
::
endl
;
}
return
EXIT_SUCCESS
;
Loading