[3773] | 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 <vtkSmartPointer.h> |
---|
| 9 | #include <vtkTextActor3D.h> |
---|
| 10 | #include <vtkTextProperty.h> |
---|
| 11 | #include <vtkProp3DFollower.h> |
---|
| 12 | #include <vtkRenderer.h> |
---|
| 13 | |
---|
| 14 | #include "Text3D.h" |
---|
| 15 | #include "Trace.h" |
---|
| 16 | |
---|
| 17 | using namespace VtkVis; |
---|
| 18 | |
---|
| 19 | Text3D::Text3D() : |
---|
| 20 | GraphicsObject() |
---|
| 21 | { |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | Text3D::~Text3D() |
---|
| 25 | { |
---|
| 26 | TRACE("Deleting Text3D"); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | void Text3D::initProp() |
---|
| 30 | { |
---|
| 31 | if (_prop == NULL) { |
---|
| 32 | _prop = vtkSmartPointer<vtkTextActor3D>::New(); |
---|
| 33 | vtkTextProperty *property = getTextProperty(); |
---|
| 34 | property->SetColor(_color[0], _color[1], _color[2]); |
---|
| 35 | if (_dataSet != NULL) |
---|
| 36 | _opacity = _dataSet->getOpacity(); |
---|
| 37 | property->SetOpacity(_opacity); |
---|
| 38 | |
---|
| 39 | if (_dataSet != NULL) |
---|
| 40 | setVisibility(_dataSet->getVisibility()); |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | void Text3D::update() |
---|
| 45 | { |
---|
| 46 | initProp(); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | void Text3D::setOpacity(double opacity) |
---|
| 50 | { |
---|
| 51 | GraphicsObject::setOpacity(opacity); |
---|
| 52 | |
---|
| 53 | vtkTextProperty *property = getTextProperty(); |
---|
| 54 | if (property == NULL) |
---|
| 55 | return; |
---|
| 56 | |
---|
| 57 | property->SetOpacity(_opacity); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | void Text3D::setColor(float color[3]) |
---|
| 61 | { |
---|
| 62 | GraphicsObject::setColor(color); |
---|
| 63 | |
---|
| 64 | vtkTextProperty *property = getTextProperty(); |
---|
| 65 | if (property == NULL) |
---|
| 66 | return; |
---|
| 67 | |
---|
| 68 | property->SetColor(_color[0], _color[1], _color[2]); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | void Text3D::setFont(const char *fontName) |
---|
| 72 | { |
---|
| 73 | vtkTextProperty *property = getTextProperty(); |
---|
| 74 | if (property == NULL) |
---|
| 75 | return; |
---|
| 76 | |
---|
| 77 | property->SetFontFamilyAsString(fontName); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | void Text3D::setFontSize(int size) |
---|
| 81 | { |
---|
| 82 | vtkTextProperty *property = getTextProperty(); |
---|
| 83 | if (property == NULL) |
---|
| 84 | return; |
---|
| 85 | |
---|
| 86 | property->SetFontSize(size); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | void Text3D::setBold(bool state) |
---|
| 90 | { |
---|
| 91 | vtkTextProperty *property = getTextProperty(); |
---|
| 92 | if (property == NULL) |
---|
| 93 | return; |
---|
| 94 | |
---|
| 95 | property->SetBold((state ? 1 : 0)); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | void Text3D::setItalic(bool state) |
---|
| 99 | { |
---|
| 100 | vtkTextProperty *property = getTextProperty(); |
---|
| 101 | if (property == NULL) |
---|
| 102 | return; |
---|
| 103 | |
---|
| 104 | property->SetItalic((state ? 1 : 0)); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | void Text3D::setShadow(bool state) |
---|
| 108 | { |
---|
| 109 | vtkTextProperty *property = getTextProperty(); |
---|
| 110 | if (property == NULL) |
---|
| 111 | return; |
---|
| 112 | |
---|
| 113 | property->SetShadow((state ? 1 : 0)); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | void Text3D::setFollowCamera(bool state, vtkRenderer *renderer) |
---|
| 117 | { |
---|
| 118 | if (state && vtkTextActor3D::SafeDownCast(_prop) != NULL) { |
---|
| 119 | vtkSmartPointer<vtkTextActor3D> textActor = vtkTextActor3D::SafeDownCast(_prop); |
---|
| 120 | vtkSmartPointer<vtkProp3DFollower> follower = vtkSmartPointer<vtkProp3DFollower>::New(); |
---|
| 121 | follower->SetCamera(renderer->GetActiveCamera()); |
---|
| 122 | follower->SetProp3D(textActor); |
---|
| 123 | renderer->RemoveViewProp(textActor); |
---|
| 124 | _prop = follower; |
---|
| 125 | renderer->AddViewProp(_prop); |
---|
| 126 | } else if (!state && vtkProp3DFollower::SafeDownCast(_prop) != NULL) { |
---|
| 127 | vtkSmartPointer<vtkProp3DFollower> follower = vtkProp3DFollower::SafeDownCast(_prop); |
---|
| 128 | vtkSmartPointer<vtkTextActor3D> textActor = vtkTextActor3D::SafeDownCast(follower->GetProp3D()); |
---|
| 129 | renderer->RemoveViewProp(follower); |
---|
| 130 | _prop = textActor; |
---|
| 131 | textActor->SetUserMatrix(NULL); |
---|
| 132 | textActor->SetUserTransform(NULL); |
---|
| 133 | renderer->AddViewProp(_prop); |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | void Text3D::setClippingPlanes(vtkPlaneCollection *planes) |
---|
| 138 | { |
---|
| 139 | // FIXME: How to get Mapper? |
---|
| 140 | } |
---|