[3535] | 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 | |
---|
[3616] | 16 | #include "Outline.h" |
---|
[3535] | 17 | #include "Trace.h" |
---|
| 18 | |
---|
[3615] | 19 | using namespace VtkVis; |
---|
[3535] | 20 | |
---|
| 21 | Outline::Outline() : |
---|
[3621] | 22 | GraphicsObject() |
---|
[3535] | 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 | { |
---|
[3621] | 41 | GraphicsObject::initProp(); |
---|
[3535] | 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 | ofilter->SetInputData(ds); |
---|
| 64 | ofilter->ReleaseDataFlagOn(); |
---|
| 65 | _pdMapper->SetInputConnection(ofilter->GetOutputPort()); |
---|
| 66 | } else { |
---|
| 67 | vtkSmartPointer<vtkOutlineFilter> ofilter = vtkSmartPointer<vtkOutlineFilter>::New(); |
---|
| 68 | ofilter->SetInputData(ds); |
---|
| 69 | ofilter->ReleaseDataFlagOn(); |
---|
| 70 | _pdMapper->SetInputConnection(ofilter->GetOutputPort()); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | initProp(); |
---|
| 74 | |
---|
| 75 | setVisibility(_dataSet->getVisibility()); |
---|
| 76 | |
---|
| 77 | getActor()->SetMapper(_pdMapper); |
---|
| 78 | _pdMapper->Update(); |
---|
| 79 | |
---|
| 80 | #ifdef WANT_TRACE |
---|
| 81 | double *b = getBounds(); |
---|
| 82 | TRACE("bounds: %g %g %g %g %g %g", b[0], b[1], b[2], b[3], b[4], b[5]); |
---|
| 83 | #endif |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | /** |
---|
| 87 | * \brief Set a group of world coordinate planes to clip rendering |
---|
| 88 | * |
---|
| 89 | * Passing NULL for planes will remove all cliping planes |
---|
| 90 | */ |
---|
| 91 | void Outline::setClippingPlanes(vtkPlaneCollection *planes) |
---|
| 92 | { |
---|
| 93 | if (_pdMapper != NULL) { |
---|
| 94 | _pdMapper->SetClippingPlanes(planes); |
---|
| 95 | } |
---|
| 96 | } |
---|