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 "Group.h" |
---|
9 | #include "Trace.h" |
---|
10 | |
---|
11 | using namespace VtkVis; |
---|
12 | |
---|
13 | Group::Group() |
---|
14 | { |
---|
15 | } |
---|
16 | |
---|
17 | Group::~Group() |
---|
18 | { |
---|
19 | } |
---|
20 | |
---|
21 | /** |
---|
22 | * \brief Create and initialize VTK Props to render the Group |
---|
23 | */ |
---|
24 | void Group::initProp() |
---|
25 | { |
---|
26 | if (_prop == NULL) { |
---|
27 | _prop = vtkSmartPointer<vtkAssembly>::New(); |
---|
28 | } |
---|
29 | } |
---|
30 | |
---|
31 | void Group::update() |
---|
32 | { |
---|
33 | initProp(); |
---|
34 | } |
---|
35 | |
---|
36 | void Group::addChild(const NodeId& name, GraphicsObject *obj) |
---|
37 | { |
---|
38 | if (obj == NULL) |
---|
39 | return; |
---|
40 | if (obj->getProp3D() != NULL) { |
---|
41 | getAssembly()->AddPart(obj->getProp3D()); |
---|
42 | } |
---|
43 | _nodes[name] = obj; |
---|
44 | } |
---|
45 | |
---|
46 | GraphicsObject *Group::getChild(const NodeId& name) |
---|
47 | { |
---|
48 | NodeHashmap::iterator itr = _nodes.find(name); |
---|
49 | if (itr == _nodes.end()) { |
---|
50 | return NULL; |
---|
51 | } else { |
---|
52 | return itr->second; |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | void Group::removeChild(const NodeId& name) |
---|
57 | { |
---|
58 | NodeHashmap::iterator itr = _nodes.find(name); |
---|
59 | if (itr == _nodes.end()) { |
---|
60 | ERROR("Node not found: '%s'", name.c_str()); |
---|
61 | return; |
---|
62 | } |
---|
63 | GraphicsObject *obj = itr->second; |
---|
64 | if (obj->getProp3D() != NULL) { |
---|
65 | getAssembly()->RemovePart(obj->getProp3D()); |
---|
66 | } |
---|
67 | _nodes.erase(itr); |
---|
68 | } |
---|
69 | |
---|
70 | /** |
---|
71 | * \brief Set a group of world coordinate planes to clip rendering |
---|
72 | * |
---|
73 | * Passing NULL for planes will remove all cliping planes |
---|
74 | */ |
---|
75 | void Group::setClippingPlanes(vtkPlaneCollection *planes) |
---|
76 | { |
---|
77 | for (NodeHashmap::iterator itr = _nodes.begin(); |
---|
78 | itr != _nodes.end(); ++itr) { |
---|
79 | itr->second->setClippingPlanes(planes); |
---|
80 | } |
---|
81 | } |
---|