Skip to content

Commit d2a0e12

Browse files
authored
Merge pull request #7 from mathturtle/composite-data-examples
Add a vtkCompositePolyDataMapper2 example
2 parents 1f2be5f + faf13c4 commit d2a0e12

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

Cxx/CompositeData/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ SET(NEEDS_ARGS
3232

3333
ADD_TEST(${KIT}-OverlappingAMR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${KIT}CxxTests
3434
TestOverlappingAMR -E 35)
35+
ADD_TEST(${KIT}-CompositePolyDataMapper ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${KIT}CxxTests
36+
TestCompositePolyDataMapper)
3537

3638
INCLUDE(${WikiExamples_SOURCE_DIR}/CMake/ExamplesTesting.cmake)
3739

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include <vtkMultiBlockDataSet.h>
2+
#include <vtkSphereSource.h>
3+
#include <vtkNew.h>
4+
#include <vtkCompositePolyDataMapper2.h>
5+
#include <vtkCompositeDataDisplayAttributes.h>
6+
#include <vtkActor.h>
7+
#include <vtkRenderer.h>
8+
#include <vtkRenderWindow.h>
9+
#include <vtkRenderWindowInteractor.h>
10+
11+
int main( int argc, char *argv[] )
12+
{
13+
vtkNew<vtkSphereSource> sphere1;
14+
sphere1->SetRadius(3);
15+
sphere1->SetCenter(0,0,0);
16+
sphere1->Update();
17+
vtkNew<vtkSphereSource> sphere2;
18+
sphere2->SetRadius(2);
19+
sphere2->SetCenter(2,0,0);
20+
sphere2->Update();
21+
22+
vtkNew<vtkMultiBlockDataSet> mbds;
23+
mbds->SetNumberOfBlocks(3);
24+
mbds->SetBlock(0, sphere1->GetOutput());
25+
// Leave block 1 NULL. NULL blocks are valid and should be handled by
26+
// algorithms that process multiblock datasets. Especially when
27+
// running in parallel where the blocks owned by other processes are
28+
// NULL in this process.
29+
mbds->SetBlock(2, sphere2->GetOutput());
30+
31+
vtkNew<vtkCompositePolyDataMapper2> mapper;
32+
mapper->SetInputData((vtkPolyData*)mbds.Get());
33+
vtkNew<vtkCompositeDataDisplayAttributes> cdsa;
34+
35+
// You can use the vtkCompositeDataDisplayAttributes to set the color
36+
// opacity and visibiliy of individual blocks of the multiblock dataset.
37+
// This sets the block at flat index 3 red
38+
// Note that the index is the flat index in the tree, so the whole multiblock
39+
// is index 0 and the blocks are flat indexes 1, 2 and 3. This affects
40+
// the block returned by mbds->GetBlock(2).
41+
double color[] = {1, 0, 0};
42+
cdsa->SetBlockColor(3, color);
43+
44+
mapper->SetCompositeDataDisplayAttributes(cdsa.Get());
45+
46+
vtkNew<vtkActor> actor;
47+
actor->SetMapper(mapper.Get());
48+
49+
vtkNew<vtkRenderer> renderer;
50+
vtkNew<vtkRenderWindow> renderWindow;
51+
renderWindow->AddRenderer(renderer.Get());
52+
vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
53+
renderWindowInteractor->SetRenderWindow(renderWindow.Get());
54+
55+
renderer->AddActor(actor.Get());
56+
57+
renderWindow->Render();
58+
renderWindowInteractor->Start();
59+
60+
return EXIT_SUCCESS;
61+
}

0 commit comments

Comments
 (0)