1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | /* |
---|
3 | * Copyright (C) 2004-2012 HUBzero Foundation, LLC |
---|
4 | * |
---|
5 | * Author: Leif Delgass <ldelgass@purdue.edu> |
---|
6 | */ |
---|
7 | |
---|
8 | #include <vtkPolyDataMapper.h> |
---|
9 | #include <vtkActor.h> |
---|
10 | #include <vtkRegularPolygonSource.h> |
---|
11 | #include <vtkPolyDataNormals.h> |
---|
12 | #include <vtkReverseSense.h> |
---|
13 | |
---|
14 | #include "Polygon.h" |
---|
15 | #include "Trace.h" |
---|
16 | |
---|
17 | using namespace VtkVis; |
---|
18 | |
---|
19 | Polygon::Polygon() : |
---|
20 | Shape() |
---|
21 | { |
---|
22 | } |
---|
23 | |
---|
24 | Polygon::~Polygon() |
---|
25 | { |
---|
26 | TRACE("Deleting Polygon"); |
---|
27 | } |
---|
28 | |
---|
29 | void Polygon::update() |
---|
30 | { |
---|
31 | if (_polygon == NULL) { |
---|
32 | _polygon = vtkSmartPointer<vtkRegularPolygonSource>::New(); |
---|
33 | } |
---|
34 | |
---|
35 | if (_pdMapper == NULL) { |
---|
36 | _pdMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); |
---|
37 | _pdMapper->SetResolveCoincidentTopologyToPolygonOffset(); |
---|
38 | _pdMapper->ScalarVisibilityOff(); |
---|
39 | } |
---|
40 | |
---|
41 | vtkSmartPointer<vtkPolyDataNormals> normalFilter = vtkSmartPointer<vtkPolyDataNormals>::New(); |
---|
42 | normalFilter->SetInputConnection(_polygon->GetOutputPort()); |
---|
43 | normalFilter->AutoOrientNormalsOff(); |
---|
44 | |
---|
45 | _pdMapper->SetInputConnection(_polygon->GetOutputPort()); |
---|
46 | |
---|
47 | initProp(); |
---|
48 | |
---|
49 | getActor()->SetMapper(_pdMapper); |
---|
50 | _pdMapper->Update(); |
---|
51 | } |
---|
52 | |
---|
53 | void Polygon::flipNormals(bool state) |
---|
54 | { |
---|
55 | if (_polygon == NULL || _pdMapper == NULL) |
---|
56 | return; |
---|
57 | |
---|
58 | if (state) { |
---|
59 | vtkSmartPointer<vtkReverseSense> filter = vtkSmartPointer<vtkReverseSense>::New(); |
---|
60 | filter->ReverseCellsOn(); |
---|
61 | filter->ReverseNormalsOn(); |
---|
62 | filter->SetInputConnection(_polygon->GetOutputPort()); |
---|
63 | |
---|
64 | _pdMapper->SetInputConnection(filter->GetOutputPort()); |
---|
65 | } else { |
---|
66 | _pdMapper->SetInputConnection(_polygon->GetOutputPort()); |
---|
67 | } |
---|
68 | _pdMapper->Update(); |
---|
69 | } |
---|
70 | |
---|