1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | /* |
---|
3 | * Copyright (C) 2004-2013 HUBzero Foundation, LLC |
---|
4 | * |
---|
5 | * Author: Leif Delgass <ldelgass@purdue.edu> |
---|
6 | */ |
---|
7 | |
---|
8 | #include <cassert> |
---|
9 | |
---|
10 | #include <vtkDataSet.h> |
---|
11 | #include <vtkStructuredGrid.h> |
---|
12 | #include <vtkPolyData.h> |
---|
13 | #include <vtkOutlineFilter.h> |
---|
14 | #include <vtkStructuredGridOutlineFilter.h> |
---|
15 | |
---|
16 | #include "Outline.h" |
---|
17 | #include "Trace.h" |
---|
18 | |
---|
19 | using namespace VtkVis; |
---|
20 | |
---|
21 | Outline::Outline() : |
---|
22 | GraphicsObject() |
---|
23 | { |
---|
24 | } |
---|
25 | |
---|
26 | Outline::~Outline() |
---|
27 | { |
---|
28 | #ifdef WANT_TRACE |
---|
29 | if (_dataSet != NULL) |
---|
30 | TRACE("Deleting Outline for %s", _dataSet->getName().c_str()); |
---|
31 | else |
---|
32 | TRACE("Deleting Outline with NULL DataSet"); |
---|
33 | #endif |
---|
34 | } |
---|
35 | |
---|
36 | /** |
---|
37 | * \brief Create and initialize a VTK Prop to render a mesh |
---|
38 | */ |
---|
39 | void Outline::initProp() |
---|
40 | { |
---|
41 | GraphicsObject::initProp(); |
---|
42 | } |
---|
43 | |
---|
44 | /** |
---|
45 | * \brief Internal method to set up pipeline after a state change |
---|
46 | */ |
---|
47 | void Outline::update() |
---|
48 | { |
---|
49 | if (_dataSet == NULL) { |
---|
50 | return; |
---|
51 | } |
---|
52 | |
---|
53 | if (_pdMapper == NULL) { |
---|
54 | _pdMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); |
---|
55 | _pdMapper->SetResolveCoincidentTopologyToPolygonOffset(); |
---|
56 | _pdMapper->ScalarVisibilityOff(); |
---|
57 | } |
---|
58 | |
---|
59 | vtkDataSet *ds = _dataSet->getVtkDataSet(); |
---|
60 | vtkStructuredGrid *sg = vtkStructuredGrid::SafeDownCast(ds); |
---|
61 | if (sg != NULL) { |
---|
62 | vtkSmartPointer<vtkStructuredGridOutlineFilter> ofilter = vtkSmartPointer<vtkStructuredGridOutlineFilter>::New(); |
---|
63 | #ifdef USE_VTK6 |
---|
64 | ofilter->SetInputData(ds); |
---|
65 | #else |
---|
66 | ofilter->SetInput(ds); |
---|
67 | #endif |
---|
68 | ofilter->ReleaseDataFlagOn(); |
---|
69 | _pdMapper->SetInputConnection(ofilter->GetOutputPort()); |
---|
70 | } else { |
---|
71 | vtkSmartPointer<vtkOutlineFilter> ofilter = vtkSmartPointer<vtkOutlineFilter>::New(); |
---|
72 | #ifdef USE_VTK6 |
---|
73 | ofilter->SetInputData(ds); |
---|
74 | #else |
---|
75 | ofilter->SetInput(ds); |
---|
76 | #endif |
---|
77 | ofilter->ReleaseDataFlagOn(); |
---|
78 | _pdMapper->SetInputConnection(ofilter->GetOutputPort()); |
---|
79 | } |
---|
80 | |
---|
81 | initProp(); |
---|
82 | |
---|
83 | setVisibility(_dataSet->getVisibility()); |
---|
84 | |
---|
85 | getActor()->SetMapper(_pdMapper); |
---|
86 | _pdMapper->Update(); |
---|
87 | |
---|
88 | #ifdef WANT_TRACE |
---|
89 | double *b = getBounds(); |
---|
90 | TRACE("bounds: %g %g %g %g %g %g", b[0], b[1], b[2], b[3], b[4], b[5]); |
---|
91 | #endif |
---|
92 | } |
---|
93 | |
---|
94 | /** |
---|
95 | * \brief Set a group of world coordinate planes to clip rendering |
---|
96 | * |
---|
97 | * Passing NULL for planes will remove all cliping planes |
---|
98 | */ |
---|
99 | void Outline::setClippingPlanes(vtkPlaneCollection *planes) |
---|
100 | { |
---|
101 | if (_pdMapper != NULL) { |
---|
102 | _pdMapper->SetClippingPlanes(planes); |
---|
103 | } |
---|
104 | } |
---|