Developer Documentation
SlicePlugin.cc
1/*===========================================================================*\
2* *
3* OpenFlipper *
4 * Copyright (c) 2001-2015, 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
44
45#include "SlicePlugin.hh"
46
49
50SlicePlugin::SlicePlugin() :
51 tool_(nullptr),
52 toolIcon_(nullptr),
53 node_(nullptr)
54{
55
56}
57
58SlicePlugin::~SlicePlugin()
59{
60 delete toolIcon_;
61}
62
63void SlicePlugin::initializePlugin(){
64 //init the slice node
65 node_ = new ACG::SceneGraph::ClippingNode(0,"Clipping Node");
66
67
69
71 node_->setMultipassStatus(ACG::SceneGraph::BaseNode::NOPASS);
72
73 tool_ = new SliceToolBox();
74
75 QSize size(300, 300);
76 tool_->resize(size);
77
78 QButtonGroup* bbGroup = new QButtonGroup();
79 bbGroup->setExclusive( true );
80 bbGroup->addButton( tool_->radioAll );
81 bbGroup->addButton( tool_->radioTarget );
82
83 QButtonGroup* axisGroup = new QButtonGroup();
84 axisGroup->setExclusive( true );
85 axisGroup->addButton( tool_->radioX );
86 axisGroup->addButton( tool_->radioY );
87 axisGroup->addButton( tool_->radioZ );
88
89 tool_->radioAll->setChecked( true );
90 tool_->radioX->setChecked( true );
91
92 connect(tool_->radioAll, SIGNAL( released() ), this, SLOT( updateSlice() ) );
93 connect(tool_->radioTarget, SIGNAL( released() ), this, SLOT( updateSlice() ) );
94 connect(tool_->resetButton, SIGNAL( released() ), this, SLOT( resetParameters() ) );
95 connect(tool_->enabled, SIGNAL( released() ), this, SLOT( updateSlice() ) );
96 connect(tool_->radioX, SIGNAL( released() ), this, SLOT( updateSlice() ) );
97 connect(tool_->radioY, SIGNAL( released() ), this, SLOT( updateSlice() ) );
98 connect(tool_->radioZ, SIGNAL( released() ), this, SLOT( updateSlice() ) );
99 connect(tool_->posSlider, SIGNAL( valueChanged(int) ), this, SLOT( updateSlice(int) ) );
100 connect(tool_->sizeSlider, SIGNAL( valueChanged(int) ), this, SLOT( updateSlice(int) ) );
101
102 toolIcon_ = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"slice.png");
103 emit addToolbox( tr("Slice") , tool_, toolIcon_);
104}
105
106void SlicePlugin::resetParameters(){
107 tool_->posSlider->setValue(0);
108 tool_->sizeSlider->setValue(102);
109 updateSlice();
110}
111
112void SlicePlugin::updateSlice(int /*bla*/){
113 updateSlice();
114}
115
116void SlicePlugin::updateSlice(){
117
118 if ( tool_->enabled->isChecked() ) {
120 node_->setMultipassStatus(BaseNode::ALLPASSES);
121 } else {
123 node_->setMultipassStatus(ACG::SceneGraph::BaseNode::NOPASS);
124 }
125
126 if ( tool_->enabled->isChecked() ){
127
128 ACG::Vec3d bbmin;
129 ACG::Vec3d bbmax;
130
131 getBoundingBox( bbmin, bbmax);
132
133 ACG::Vec3d center = (bbmin + bbmax) * 0.5;
134 ACG::Vec3f pos (center[0], center[1], center[2]);
135
136 //get the normal
137 ACG::Vec3f normal(1.0, 0.0, 0.0);
138 float eps;
139 float offset = 0.0;
140
141 eps = tool_->sizeSlider->value() / 100.0;
142
143 if (eps == 0.0)
144 eps = 0.01f;
145
146 if (tool_->radioX->isChecked()){
147 normal = ACG::Vec3f(1.0, 0.0, 0.0);
148 eps *= (bbmax[0] - bbmin[0]);
149 offset = (bbmax[0] - bbmin[0]) * 0.5;
150 }else
151 if (tool_->radioY->isChecked()){
152 normal = ACG::Vec3f(0.0, 1.0, 0.0);
153 eps *= (bbmax[1] - bbmin[1]);
154 offset = (bbmax[1] - bbmin[1]) * 0.5;
155 }else
156 if (tool_->radioZ->isChecked()){
157 normal = ACG::Vec3f(0.0, 0.0, 1.0);
158 eps *= (bbmax[2] - bbmin[2]);
159 offset = (bbmax[2] - bbmin[2]) * 0.5;
160 }
161
162 pos += normal * ( (float)tool_->posSlider->value() / 100.0 ) * (offset + 0.1); //0.1 is just a little workarround
163
164 node_->set_plane(pos, normal, eps);
165 }
166 emit updateView();
167}
168
169void SlicePlugin::getBoundingBox(ACG::Vec3d& bbmin, ACG::Vec3d& bbmax){
170
171 bool firstRound = true;
172
174
175 if (tool_->radioTarget->isChecked())
177 else
178 restriction = PluginFunctions::ALL_OBJECTS;
179
180 for ( PluginFunctions::ObjectIterator o_it(restriction,DataType(DATA_ALL)) ;
181 o_it != PluginFunctions::objectsEnd(); ++o_it) {
182 // get scene size
183 ACG::Vec3d cur_min;
184 ACG::Vec3d cur_max;
185
186 o_it->getBoundingBox(cur_min, cur_max);
187
188 if (firstRound){
189 bbmin = cur_min;
190 bbmax = cur_max;
191 firstRound = false;
192 }else{
193 bbmin[0] = std::min( bbmin[0], cur_min[0]);
194 bbmin[1] = std::min( bbmin[1], cur_min[1]);
195 bbmin[2] = std::min( bbmin[2], cur_min[2]);
196 bbmax[0] = std::max( bbmax[0], cur_max[0]);
197 bbmax[1] = std::max( bbmax[1], cur_max[1]);
198 bbmax[2] = std::max( bbmax[2], cur_max[2]);
199 }
200 }
201
202 if ((bbmin[0] > bbmax[0]) || (bbmin[1] > bbmax[1]) || (bbmin[2] > bbmax[2]))
203 std::cerr << "Error while computing bounding box!";
204
205}
206
207
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
void setMultipassStatus(const MultipassBitMask _passStatus)
Set multipass settings for the nodes status functions.
Definition: BaseNode.hh:505
@ HideNode
Hide this node, but draw children.
Definition: BaseNode.hh:394
@ Active
Draw node & children.
Definition: BaseNode.hh:392
void set_status(StatusMode _s)
Set the status of this node.
Definition: BaseNode.hh:403
void set_plane(const Vec3f &_position, const Vec3f &_normal, float _eps=0.0)
set position and normal of plane
Definition: ClippingNode.cc:77
Predefined datatypes.
Definition: DataTypes.hh:83
VectorT< float, 3 > Vec3f
Definition: VectorT.hh:119
void addObjectRenderingNode(ACG::SceneGraph::BaseNode *_node)
Add scenegraph node modifing object rendering.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
QStringList IteratorRestriction
Iterable object range.
const QStringList TARGET_OBJECTS("target")
Iterable object range.
const QStringList ALL_OBJECTS
Iterable object range.