Commit b717c5ec authored by Jan Möbius's avatar Jan Möbius

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9604 383ad7c9-94d9-4d36-a494-682f7c89f535
parents
include (plugin)
openflipper_plugin ()
################################################################################
#
################################################################################
include( $$TOPDIR/qmake/all.include )
Plugin()
DIRECTORIES = .
# Input
HEADERS += $$getFilesFromDir($$DIRECTORIES,*.hh)
SOURCES += $$getFilesFromDir($$DIRECTORIES,*.cc)
FORMS += $$getFilesFromDir($$DIRECTORIES,*.ui)
################################################################################
#include <QtGui>
#include "SlicePlugin.hh"
#include <iostream>
#include "OpenFlipper/BasePlugin/PluginFunctions.hh"
void SlicePlugin::initializePlugin(){
//init the slice node
node_ = new ACG::SceneGraph::ClippingNode(0,"Clipping Node");
PluginFunctions::addObjectRenderingNode( node_ );
node_->set_status( ACG::SceneGraph::BaseNode::HideNode );
node_->setMultipassStatus(ACG::SceneGraph::BaseNode::NOPASS);
tool_ = new SliceToolBox();
QSize size(300, 300);
tool_->resize(size);
bbGroup = new QButtonGroup();
bbGroup->setExclusive( true );
bbGroup->addButton( tool_->radioAll );
bbGroup->addButton( tool_->radioTarget );
axisGroup = new QButtonGroup();
axisGroup->setExclusive( true );
axisGroup->addButton( tool_->radioX );
axisGroup->addButton( tool_->radioY );
axisGroup->addButton( tool_->radioZ );
tool_->radioAll->setChecked( true );
tool_->radioX->setChecked( true );
connect(tool_->radioAll, SIGNAL( released() ), this, SLOT( updateSlice() ) );
connect(tool_->radioTarget, SIGNAL( released() ), this, SLOT( updateSlice() ) );
connect(tool_->resetButton, SIGNAL( released() ), this, SLOT( resetParameters() ) );
connect(tool_->enabled, SIGNAL( released() ), this, SLOT( updateSlice() ) );
connect(tool_->radioX, SIGNAL( released() ), this, SLOT( updateSlice() ) );
connect(tool_->radioY, SIGNAL( released() ), this, SLOT( updateSlice() ) );
connect(tool_->radioZ, SIGNAL( released() ), this, SLOT( updateSlice() ) );
connect(tool_->posSlider, SIGNAL( sliderMoved(int) ), this, SLOT( updateSlice(int) ) );
connect(tool_->sizeSlider, SIGNAL( sliderMoved(int) ), this, SLOT( updateSlice(int) ) );
emit addToolbox( tr("Slice") , tool_ );
}
void SlicePlugin::resetParameters(){
tool_->posSlider->setValue(0);
tool_->sizeSlider->setValue(102);
updateSlice();
}
void SlicePlugin::updateSlice(int /*bla*/){
updateSlice();
}
void SlicePlugin::updateSlice(){
if ( tool_->enabled->isChecked() ) {
node_->set_status( ACG::SceneGraph::BaseNode::Active );
node_->setMultipassStatus(BaseNode::ALLPASSES);
} else {
node_->set_status( ACG::SceneGraph::BaseNode::HideNode );
node_->setMultipassStatus(ACG::SceneGraph::BaseNode::NOPASS);
}
if ( tool_->enabled->isChecked() ){
ACG::Vec3d bbmin;
ACG::Vec3d bbmax;
getBoundingBox( bbmin, bbmax);
ACG::Vec3d center = (bbmin + bbmax) * 0.5;
ACG::Vec3f pos (center[0], center[1], center[2]);
//get the normal
ACG::Vec3f normal(1.0, 0.0, 0.0);
float eps;
float offset = 0.0;
eps = tool_->sizeSlider->value() / 100.0;
if (eps == 0.0)
eps = 0.01;
if (tool_->radioX->isChecked()){
normal = ACG::Vec3f(1.0, 0.0, 0.0);
eps *= (bbmax[0] - bbmin[0]);
offset = (bbmax[0] - bbmin[0]) * 0.5;
}else
if (tool_->radioY->isChecked()){
normal = ACG::Vec3f(0.0, 1.0, 0.0);
eps *= (bbmax[1] - bbmin[1]);
offset = (bbmax[1] - bbmin[1]) * 0.5;
}else
if (tool_->radioZ->isChecked()){
normal = ACG::Vec3f(0.0, 0.0, 1.0);
eps *= (bbmax[2] - bbmin[2]);
offset = (bbmax[2] - bbmin[2]) * 0.5;
}
pos += normal * ( (float)tool_->posSlider->value() / 100.0 ) * (offset + 0.1); //0.1 is just a little workarround
node_->set_plane(pos, normal, eps);
}
emit updateView();
}
void SlicePlugin::getBoundingBox(ACG::Vec3d& bbmin, ACG::Vec3d& bbmax){
bool firstRound = true;
PluginFunctions::IteratorRestriction restriction;
if (tool_->radioTarget->isChecked())
restriction = PluginFunctions::TARGET_OBJECTS;
else
restriction = PluginFunctions::ALL_OBJECTS;
for ( PluginFunctions::ObjectIterator o_it(restriction,DataType(DATA_ALL)) ;
o_it != PluginFunctions::objectsEnd(); ++o_it) {
// get scene size
ACG::Vec3d cur_min;
ACG::Vec3d cur_max;
o_it->getBoundingBox(cur_min, cur_max);
if (firstRound){
bbmin = cur_min;
bbmax = cur_max;
firstRound = false;
}else{
bbmin[0] = std::min( bbmin[0], cur_min[0]);
bbmin[1] = std::min( bbmin[1], cur_min[1]);
bbmin[2] = std::min( bbmin[2], cur_min[2]);
bbmax[0] = std::max( bbmax[0], cur_max[0]);
bbmax[1] = std::max( bbmax[1], cur_max[1]);
bbmax[2] = std::max( bbmax[2], cur_max[2]);
}
}
if ((bbmin[0] > bbmax[0]) || (bbmin[1] > bbmax[1]) || (bbmin[2] > bbmax[2]))
std::cerr << "Error while computing bounding box!";
}
Q_EXPORT_PLUGIN2( slicePlugin , SlicePlugin );
#ifndef SLICEPLUGIN_HH
#define SLICEPLUGIN_HH
#include <QObject>
#include <QtGui>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/KeyInterface.hh>
#include <ACG/Scenegraph/ClippingNode.hh>
// #include <OpenFlipper/common/Types.hh>
#include "SliceToolbox.hh"
class SlicePlugin : public QObject, BaseInterface, ToolboxInterface, LoggingInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(ToolboxInterface)
Q_INTERFACES(LoggingInterface)
//BaseInterface
signals:
void updateView();
void updatedObject(int);
//LoggingInterface:
void log( Logtype _type, QString _message );
void log( QString _message );
// ToolboxInterface
void addToolbox( QString _name , QWidget* _widget );
private slots:
void initializePlugin(); // BaseInterface
public :
~SlicePlugin() {};
QString name() { return (QString("Slice")); };
QString description( ) { return (QString("Slice objects")); };
private :
SliceToolBox* tool_;
QButtonGroup* bbGroup;
QButtonGroup* axisGroup;
void getBoundingBox(ACG::Vec3d& bbmin, ACG::Vec3d& bbmax);
private slots:
void resetParameters();
void updateSlice();
void updateSlice(int bla);
private:
ACG::SceneGraph::ClippingNode* node_;
public slots:
QString version() { return QString("1.0"); };
};
#endif //SLICEPLUGIN_HH
#include "SliceToolbox.hh"
#include <QtGui>
SliceToolBox::SliceToolBox(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
}
#include "ui_toolbox.hh"
#include <QtGui>
class SliceToolBox : public QWidget, public Ui::SliceTool
{
Q_OBJECT
public:
SliceToolBox(QWidget *parent = 0);
};
<ui version="4.0" >
<class>SliceTool</class>
<widget class="QWidget" name="SliceTool" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>339</width>
<height>210</height>
</rect>
</property>
<property name="windowTitle" >
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<layout class="QFormLayout" name="formLayout" >
<item row="0" column="0" >
<widget class="QLabel" name="label_4" >
<property name="text" >
<string>Bounding Box:</string>
</property>
</widget>
</item>
<item row="0" column="1" >
<layout class="QHBoxLayout" name="horizontalLayout_2" >
<item>
<widget class="QRadioButton" name="radioTarget" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="toolTip" >
<string>Use only target objects to determine the bounding box for the slice</string>
</property>
<property name="statusTip" >
<string>Use only target objects to determine the bounding box for the slice</string>
</property>
<property name="text" >
<string>Target Objects</string>
</property>
<property name="autoExclusive" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioAll" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="toolTip" >
<string>Use all objects to determine the bounding box for the slice</string>
</property>
<property name="statusTip" >
<string>Use all objects to determine the bounding box for the slice</string>
</property>
<property name="text" >
<string>All Objects</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
<property name="autoExclusive" >
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Axis:</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QRadioButton" name="radioX" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="toolTip" >
<string>Uses X as slicing axis</string>
</property>
<property name="statusTip" >
<string>Uses X as slicing axis</string>
</property>
<property name="text" >
<string>X</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
<property name="autoExclusive" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QRadioButton" name="radioY" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="toolTip" >
<string>Uses Y as slicing axis</string>
</property>
<property name="statusTip" >
<string>Uses Y as slicing axis</string>
</property>
<property name="text" >
<string>Y</string>
</property>
<property name="autoExclusive" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QRadioButton" name="radioZ" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="toolTip" >
<string>Uses Z as slicing axis</string>
</property>
<property name="statusTip" >
<string>Uses Z as slicing axis</string>
</property>
<property name="text" >
<string>Z</string>
</property>
<property name="autoExclusive" >
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>Position:</string>
</property>
</widget>
</item>
<item row="2" column="1" >
<widget class="QSlider" name="posSlider" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="toolTip" >
<string>Adjust the position of the slice</string>
</property>
<property name="statusTip" >
<string>Adjust the position of the slice</string>
</property>
<property name="minimum" >
<number>-101</number>
</property>
<property name="maximum" >
<number>101</number>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="3" column="0" >
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Size:</string>
</property>
</widget>
</item>
<item row="3" column="1" >
<widget class="QSlider" name="sizeSlider" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="toolTip" >
<string>Adjust the size of the slice</string>
</property>
<property name="statusTip" >
<string>Adjust the size of the slice</string>
</property>
<property name="minimum" >
<number>0</number>
</property>
<property name="maximum" >
<number>102</number>
</property>
<property name="value" >
<number>102</number>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="1" >
<widget class="QPushButton" name="resetButton" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="toolTip" >
<string>Reset the above parameters</string>
</property>
<property name="statusTip" >
<string>Reset the above parameters</string>
</property>
<property name="text" >
<string>Reset</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="enabled" >
<property name="toolTip" >
<string>Enable slicing for the current scene</string>
</property>
<property name="statusTip" >
<string>Enable slicing for the current scene</string>
</property>
<property name="text" >
<string>Enable Slicing</string>
</property>
<property name="checkable" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>enabled</sender>
<signal>toggled(bool)</signal>
<receiver>sizeSlider</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>154</x>
<y>196</y>
</hint>
<hint type="destinationlabel" >
<x>251</x>
<y>105</y>
</hint>
</hints>
</connection>
<connection>
<sender>enabled</sender>
<signal>toggled(bool)</signal>
<receiver>posSlider</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>278</x>
<y>196</y>
</hint>
<hint type="destinationlabel" >
<x>325</x>
<y>83</y>
</hint>
</hints>
</connection>
<connection>
<sender>enabled</sender>
<signal>toggled(bool)</signal>
<receiver>radioZ</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>249</x>
<y>196</y>
</hint>
<hint type="destinationlabel" >
<x>324</x>
<y>60</y>
</hint>
</hints>
</connection>
<connection>
<sender>enabled</sender>
<signal>toggled(bool)</signal>
<receiver>radioX</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>95</x>
<y>196</y>
</hint>
<hint type="destinationlabel" >
<x>129</x>
<y>56</y>
</hint>
</hints>
</connection>
<connection>
<sender>enabled</sender>
<signal>toggled(bool)</signal>
<receiver>radioY</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>146</x>
<y>196</y>
</hint>
<hint type="destinationlabel" >
<x>227</x>
<y>60</y>
</hint>
</hints>
</connection>
<connection>
<sender>enabled</sender>
<signal>toggled(bool)</signal>
<receiver>radioTarget</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>194</x>
<y>185</y>
</hint>
<hint type="destinationlabel" >
<x>170</x>
<y>21</y>
</hint>
</hints>
</connection>
<connection>
<sender>enabled</sender>
<signal>toggled(bool)</signal>
<receiver>radioAll</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>224</x>
<y>171</y>
</hint>
<hint type="destinationlabel" >
<x>230</x>
<y>24</y>
</hint>
</hints>
</connection>
<connection>
<sender>enabled</sender>
<signal>toggled(bool)</signal>
<receiver>resetButton</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>284</x>
<y>188</y>
</hint>
<hint type="destinationlabel" >
<x>289</x>
<y>130</y>
</hint>
</hints>