Developer Documentation

FloatingSubtreeNode.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2016, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42 /*
43 * This class is available on C++11 compilers only.
44 */
45 #if (defined(_MSC_VER) && (_MSC_VER >= 1900)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
46
47 #include "../../ACG/Scenegraph/FloatingSubtreeNode.hh"
48
49 #include <ACG/GL/IRenderer.hh>
50
51 namespace ACG {
52 namespace SceneGraph {
53
54 FloatingSubtreeNode::FloatingSubtreeNode(
55 GLMatrixd modelview_override,
56 BaseNode *_parent, const std::string &_name)
57
58 : BaseNode(_parent, _name),
59 modelview_override_(std::move(modelview_override)),
60 enable_modelview_override_(true),
61 enable_overlay_(true) {
62
63 modelview_override_inv_ = modelview_override_;
64 modelview_override_inv_.invert();
65 }
66
67 FloatingSubtreeNode::~FloatingSubtreeNode() {
68
69 }
70
71 void FloatingSubtreeNode::enter(GLState &_state,
72 const DrawModes::DrawMode &_drawMode) {
73 if (enable_modelview_override_) {
74 _state.push_modelview_matrix();
75 _state.set_modelview(modelview_override_, modelview_override_inv_);
76 }
77 }
78
79 void FloatingSubtreeNode::enter(IRenderer* _renderer, GLState& _state,
80 const DrawModes::DrawMode& _drawMode) {
81 FloatingSubtreeNode::enter(_state, _drawMode);
82 }
83
84 void FloatingSubtreeNode::leave(GLState &_state,
85 const DrawModes::DrawMode &_drawMode) {
86 if (enable_modelview_override_) {
87 _state.pop_modelview_matrix();
88 }
89 }
90
91 void FloatingSubtreeNode::leave(IRenderer* _renderer, GLState& _state,
92 const DrawModes::DrawMode& _drawMode) {
93 FloatingSubtreeNode::leave(_state, _drawMode);
94 if (enable_overlay_) {
95 for (auto &obj_it : _renderer->getCollectedSubtreeObjects()) {
96 obj_it.overlay = true;
97 }
98 }
99 }
100
101
102 void FloatingSubtreeNode::enterPick(GLState &_state, PickTarget _target,
103 const DrawModes::DrawMode &_drawMode) {
104 FloatingSubtreeNode::enter(_state, _drawMode);
105 }
106
107 void FloatingSubtreeNode::leavePick(GLState &_state, PickTarget _target,
108 const DrawModes::DrawMode &_drawMode) {
109 FloatingSubtreeNode::leave(_state, _drawMode);
110 }
111
112 void FloatingSubtreeNode::setModelViewOverride(GLMatrixd modelview_override) {
113 modelview_override_ = std::move(modelview_override);
114 modelview_override_inv_ = modelview_override_;
115 modelview_override_inv_.invert();
116 }
117
118 void FloatingSubtreeNode::boundingBox(Vec3d &_bbMin, Vec3d &_bbMax) {
119 if (enable_modelview_override_) {
120 if (status() != BaseNode::HideChildren) {
121 BoundingBoxAction action;
122 BaseNode::ChildIter cIt, cEnd(childrenEnd());
123
124 // Process all children which are not second pass
125 for (cIt = childrenBegin(); cIt != cEnd; ++cIt)
126 if (~(*cIt)->traverseMode() & BaseNode::SecondPass)
127 traverse(*cIt, action);
128
129 // Process all children which are second pass
130 for (cIt = childrenBegin(); cIt != cEnd; ++cIt)
131 if ((*cIt)->traverseMode() & BaseNode::SecondPass)
132 traverse(*cIt, action);
133
134 // Transform bounding box to view space
135 Vec3d minVS = modelview_override_.transform_point(action.bbMin());
136 Vec3d maxVS = modelview_override_.transform_point(action.bbMax());
137
138 _bbMin.minimize(minVS);
139 _bbMax.maximize(maxVS);
140 }
141 }
142 }
143
144 } /* namespace Scenegraph */
145 } /* namespace ACG */
146
147 #endif /* C++11 */
OpenMesh::VectorT::maximize
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition: Vector11T.hh:563
ACG::SceneGraph::BaseNode::HideChildren
Draw this node, but hide children.
Definition: BaseNode.hh:396
ACG
Namespace providing different geometric functions concerning angles.
Definition: BaseObjectData.hh:68
ACG::SceneGraph::BaseNode::SecondPass
Draw node in second pass.
Definition: BaseNode.hh:445
ACG::GLMatrixd
GLMatrixT< double > GLMatrixd
typedef
Definition: GLMatrixT.hh:326
ACG::Vec3d
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:121
std
STL namespace.
SceneGraph
Definition: QtPrincipalAxisDialog.hh:67
ACG::SceneGraph::ACG::SceneGraph::BaseNode::childrenBegin
ChildIter childrenBegin()
Returns: begin-iterator of children.
Definition: MeshNode2T_impl.hh:294
ACG::SceneGraph::ACG::SceneGraph::BaseNode::status
StatusMode status() const
Get node&#39;s status.
Definition: MeshNode2T_impl.hh:401
ACG::SceneGraph::PickTarget
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
OpenMesh::VectorT::minimize
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Definition: Vector11T.hh:535
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:104
ACG::SceneGraph::traverse
void traverse(BaseNode *_node, Action &_action)
Definition: SceneGraph.hh:137
ACG::SceneGraph::ACG::SceneGraph::BaseNode::childrenEnd
ChildIter childrenEnd()
Returns: end-iterator of children.
Definition: MeshNode2T_impl.hh:298
ACG::SceneGraph::BaseNode::ChildIter
std::vector< BaseNode * >::iterator ChildIter
allows to iterate over children
Definition: BaseNode.hh:286