|
| 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