Commit 7628069b authored by Jan Möbius's avatar Jan Möbius

Some factorization


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@3735 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 5421915b
......@@ -172,7 +172,7 @@ void TextureControlPlugin::doUpdateTexture ( int _textureid, MeshT& _mesh )
} else if ( textures_[_textureid].dimension == 2 ) {
OpenMesh::VPropHandleT< OpenMesh::Vec2d > texture2D;
if ( ! _mesh.get_property_handle(texture2D,textures_[_textureid].name.toStdString() ) ) {
if ( ! _mesh.get_property_handle(texture2D,textures_[_textureid].name.toStdString() ) ) {
emit log(LOGERR,"Unable to get property " + textures_[_textureid].name );
return;
}
......@@ -197,108 +197,6 @@ void TextureControlPlugin::doUpdateTexture ( int _textureid, MeshT& _mesh )
}
template< typename MeshT >
void TextureControlPlugin::copyTexture ( int _textureid, MeshT& _mesh, OpenMesh::VPropHandleT< double > _texProp )
{
double max,min;
computeMinMaxScalar(_textureid, _mesh, _texProp, min, max);
for ( typename MeshT::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it) {
double value = _mesh.property(_texProp, v_it);
computeValue(_textureid, min, max, value);
_mesh.set_texcoord2D( v_it, ACG::Vec2f(float(value), float(value) ) );
}
}
template< typename MeshT >
void TextureControlPlugin::copyTexture ( int /*_textureid*/, MeshT& _mesh, OpenMesh::VPropHandleT< OpenMesh::Vec2d > _texProp )
{
for ( typename MeshT::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it) {
OpenMesh::Vec2d value = _mesh.property(_texProp, v_it);
_mesh.set_texcoord2D( v_it, ACG::Vec2f(float(value[0]), float(value[1]) ) );
}
}
template< typename MeshT >
void TextureControlPlugin::copyTexture ( int _textureid, MeshT& _mesh, OpenMesh::HPropHandleT< double > _texProp )
{
double max,min;
computeMinMaxScalar(_textureid, _mesh, _texProp, min, max);
for ( typename MeshT::HalfedgeIter h_it = _mesh.halfedges_begin(); h_it != _mesh.halfedges_end(); ++h_it) {
double value = _mesh.property(_texProp, h_it);
computeValue(_textureid, min, max, value);
_mesh.set_texcoord2D( h_it, ACG::Vec2f(float(value), float(value) ) );
}
}
template< typename MeshT >
void TextureControlPlugin::copyTexture ( int /*_textureid*/, MeshT& _mesh, OpenMesh::HPropHandleT< OpenMesh::Vec2d > _texProp )
{
for ( typename MeshT::HalfedgeIter h_it = _mesh.halfedges_begin(); h_it != _mesh.halfedges_end(); ++h_it) {
OpenMesh::Vec2d value = _mesh.property(_texProp, h_it);
_mesh.set_texcoord2D( h_it, ACG::Vec2f(float(value[0]), float(value[1]) ) );
}
}
template< typename MeshT >
void TextureControlPlugin::computeMinMaxScalar(int _textureid, MeshT& _mesh,OpenMesh::VPropHandleT< double > _texture,
double& _min , double& _max) {
const bool abs = textures_[_textureid].abs;
const bool clamp = textures_[_textureid].clamp ;
const double clamp_max = textures_[_textureid].clamp_max;
const double clamp_min = textures_[_textureid].clamp_min;
_max = FLT_MIN;
_min = FLT_MAX;
for ( typename MeshT::VertexIter v_it = _mesh.vertices_begin() ; v_it != _mesh.vertices_end(); ++v_it) {
if ( abs ) {
_max = std::max( fabs(_mesh.property(_texture,v_it)) , _max);
_min = std::min( fabs(_mesh.property(_texture,v_it)) , _min);
} else {
_max = std::max( _mesh.property(_texture,v_it) , _max);
_min = std::min( _mesh.property(_texture,v_it) , _min);
}
}
if ( clamp ) {
if ( _max > clamp_max )
_max = clamp_max;
if (_min < clamp_min)
_min = clamp_min;
}
}
template< typename MeshT >
void TextureControlPlugin::computeMinMaxScalar(int _textureid, MeshT& _mesh,OpenMesh::HPropHandleT< double > _texture,
double& _min , double& _max) {
const bool abs = textures_[_textureid].abs;
const bool clamp = textures_[_textureid].clamp ;
const double clamp_max = textures_[_textureid].clamp_max;
const double clamp_min = textures_[_textureid].clamp_min;
_max = FLT_MIN;
_min = FLT_MAX;
for ( typename MeshT::HalfedgeIter h_it = _mesh.halfedges_begin() ; h_it != _mesh.halfedges_end(); ++h_it) {
if ( abs ) {
_max = std::max( fabs(_mesh.property(_texture,h_it)) , _max);
_min = std::min( fabs(_mesh.property(_texture,h_it)) , _min);
} else {
_max = std::max( _mesh.property(_texture,h_it) , _max);
_min = std::min( _mesh.property(_texture,h_it) , _min);
}
}
if ( clamp ) {
if ( _max > clamp_max )
_max = clamp_max;
if (_min < clamp_min)
_min = clamp_min;
}
}
void TextureControlPlugin::computeValue(int _textureid, double _min, double _max, double& _value) {
const bool clamp = textures_[_textureid].clamp ;
const bool center = textures_[_textureid].center;
......@@ -474,95 +372,116 @@ void TextureControlPlugin::pluginsInitialized() {
textureMenu_->addActions(actionGroup_->actions());
}
void TextureControlPlugin::updateDialog() {
if ( textures_.size() == 0 )
return;
void TextureControlPlugin::updateDialog() {
if ( textures_.size() == 0 )
return;
int textureid = -1;
for ( int i = 0 ; i < (int)textures_.size() ; ++i ) {
if ( textures_[i].name == activeTexture_ ) {
textureid = i;
break;
}
}
int textureid = -1;
for ( int i = 0 ; i < (int)textures_.size() ; ++i ) {
if ( textures_[i].name == activeTexture_ ) {
textureid = i;
break;
}
}
if ( textureid == -1 ) {
emit log(LOGERR,"Active Texture not found");
return;
emit log(LOGERR,"Active Texture not found");
return;
}
settingsDialog_->repeatBox->setChecked(textures_[textureid].repeat);
settingsDialog_->clampBox->setChecked(textures_[textureid].clamp);
settingsDialog_->centerBox->setChecked(textures_[textureid].center);
settingsDialog_->absBox->setChecked(textures_[textureid].abs);
QString tmp;
tmp.setNum(textures_[textureid].max_val);
settingsDialog_->max_val->setText( tmp );
tmp.setNum(textures_[textureid].clamp_min);
settingsDialog_->clamp_min->setText(tmp);
tmp.setNum(textures_[textureid].clamp_max);
settingsDialog_->clamp_max->setText(tmp);
}
void TextureControlPlugin::slotSetTextureProperties() {
updateDialog();
if ( textures_.size() == 0 )
settingsDialog_->repeatBox->setChecked(textures_[textureid].repeat);
settingsDialog_->clampBox->setChecked(textures_[textureid].clamp);
settingsDialog_->centerBox->setChecked(textures_[textureid].center);
settingsDialog_->absBox->setChecked(textures_[textureid].abs);
QString tmp;
tmp.setNum(textures_[textureid].max_val);
settingsDialog_->max_val->setText( tmp );
tmp.setNum(textures_[textureid].clamp_min);
settingsDialog_->clamp_min->setText(tmp);
tmp.setNum(textures_[textureid].clamp_max);
settingsDialog_->clamp_max->setText(tmp);
// // update plot only when dimension is 1
// if ( textures_[textureid].dimension == 1) {
// std::vector< double > x,y;
//
// // getOriginalHistogram();
//
// }
}
// template< typename MeshT >
// void TextureControlPlugin::getOriginalHistogram(std::vector< double>& _x, std::vector< double>& _y,
// int _textureid, MeshT& _mesh,
// OpenMesh::VPropHandleT< double > _texProp) {
// _x.clear();
// _y.clear();
//
// for ( typename MeshT::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it) {
// double value = _mesh.property(_texProp, v_it);
// }
//
// }
void TextureControlPlugin::slotSetTextureProperties() {
updateDialog();
if ( textures_.size() == 0 )
return;
settingsDialog_->show();
}
settingsDialog_->show();
}
void TextureControlPlugin::applyDialogSettings() {
if ( textures_.size() == 0 )
if ( textures_.size() == 0 )
return;
int textureid = -1;
for ( int i = 0 ; i < (int)textures_.size() ; ++i ) {
if ( textures_[i].name == activeTexture_ ) {
textureid = i;
break;
}
}
int textureid = -1;
for ( int i = 0 ; i < (int)textures_.size() ; ++i ) {
if ( textures_[i].name == activeTexture_ ) {
textureid = i;
break;
}
}
if (textureid == -1) {
if (textureid == -1) {
emit log(LOGERR,"Unable to get active Texture");
}
}
textures_[textureid].repeat=settingsDialog_->repeatBox->isChecked();
textures_[textureid].clamp=settingsDialog_->clampBox->isChecked();
textures_[textureid].center=settingsDialog_->centerBox->isChecked();
textures_[textureid].abs=settingsDialog_->absBox->isChecked();
textures_[textureid].scale=settingsDialog_->scaleBox->isChecked();
textures_[textureid].repeat=settingsDialog_->repeatBox->isChecked();
textures_[textureid].clamp=settingsDialog_->clampBox->isChecked();
textures_[textureid].center=settingsDialog_->centerBox->isChecked();
textures_[textureid].abs=settingsDialog_->absBox->isChecked();
textures_[textureid].scale=settingsDialog_->scaleBox->isChecked();
QString tmp;
tmp = settingsDialog_->max_val->text();
textures_[textureid].max_val = tmp.toDouble();
QString tmp;
tmp = settingsDialog_->max_val->text();
textures_[textureid].max_val = tmp.toDouble();
tmp = settingsDialog_->clamp_min->text();
textures_[textureid].clamp_min = tmp.toDouble();
tmp = settingsDialog_->clamp_min->text();
textures_[textureid].clamp_min = tmp.toDouble();
tmp = settingsDialog_->clamp_max->text();
textures_[textureid].clamp_max = tmp.toDouble();
tmp = settingsDialog_->clamp_max->text();
textures_[textureid].clamp_max = tmp.toDouble();
// Update the corresponding meshes
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it)
// Update the corresponding meshes
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it)
slotTextureUpdated( activeTexture_ , o_it->id() );
emit update_view();
emit update_view();
}
void TextureControlPlugin::slotTexturePropertiesOk() {
applyDialogSettings();
settingsDialog_->hide();
void TextureControlPlugin::slotTexturePropertiesOk() {
applyDialogSettings();
settingsDialog_->hide();
}
void TextureControlPlugin::slotTexturePropertiesApply() {
applyDialogSettings();
}
applyDialogSettings();
}
void TextureControlPlugin::slotTexturePropertiesCancel() {
void TextureControlPlugin::slotTexturePropertiesCancel() {
settingsDialog_->hide();
}
}
void TextureControlPlugin::slotTextureMenu(QAction* _action) {
......@@ -571,7 +490,7 @@ void TextureControlPlugin::slotTextureMenu(QAction* _action) {
// Force an update of all objects
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it)
slotTextureUpdated( _action->text() , o_it->id() );
slotTextureUpdated( _action->text() , o_it->id() );
updateDialog();
......
......@@ -139,7 +139,6 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me
void updateDialog();
/// Take a scalar value and return a clamped,... depending on texture settings
inline
void computeValue(int _textureid, double _min, double _max, double& _value);
......
......@@ -12,12 +12,12 @@
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
......@@ -39,7 +39,12 @@ texturePropertiesWidget::texturePropertiesWidget(QWidget *parent)
: QDialog(parent)
{
setupUi(this);
// QGridLayout* layout = new QGridLayout( originalData);
// originalDataHistogram_ = new QwtPlot(0);
//
// layout->addWidget( originalDataHistogram_ , 0,0 );
// connect(distanceCheckBox,SIGNAL(stateChanged ( int ) ) , this , SLOT (slotDistanceCheckbox(int)) );
// connect(normalCheckBox,SIGNAL(stateChanged ( int ) ) , this , SLOT (slotNormalCheckbox(int)) );
}
......@@ -12,12 +12,12 @@
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
......@@ -34,6 +34,7 @@
#include "ui_textureProperties.hh"
#include <QtGui>
// #include <qwt_plot.h>
class texturePropertiesWidget : public QDialog, public Ui::Dialog
{
......@@ -41,6 +42,7 @@ class texturePropertiesWidget : public QDialog, public Ui::Dialog
public:
texturePropertiesWidget(QWidget *parent = 0);
// QwtPlot* originalDataHistogram_;
};
......@@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>257</width>
<height>272</height>
<width>675</width>
<height>359</height>
</rect>
</property>
<property name="minimumSize" >
......@@ -24,188 +24,169 @@
<property name="windowTitle" >
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" >
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QCheckBox" name="repeatBox" >
<property name="text" >
<string>Repeat Texture</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" >
<item>
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Max Value</string>
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<string>Properties</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<widget class="QCheckBox" name="repeatBox" >
<property name="text" >
<string>Repeat Texture</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Max Value</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="max_val" />
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="clampBox" >
<property name="text" >
<string>Clamp Texture</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label" >
<property name="text" >
<string>Clamp Min</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Clamp Max</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="clamp_min" />
</item>
<item>
<widget class="QLineEdit" name="clamp_max" />
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="centerBox" >
<property name="text" >
<string>center</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="absBox" >
<property name="text" >
<string>Use Absolute values</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="scaleBox" >
<property name="text" >
<string>Scale</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLineEdit" name="max_val" />
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="clampBox" >
<property name="text" >
<string>Clamp Texture</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" >
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label" >
<widget class="QPushButton" name="okButton" >
<property name="text" >
<string>Clamp Min</string>
<string>Ok</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2" >
<widget class="QPushButton" name="applyButton" >
<property name="text" >
<string>Clamp Max</string>
<string>Apply</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="clamp_min" />
</item>
<item>
<widget class="QLineEdit" name="clamp_max" />
<widget class="QPushButton" name="cancelButton" >
<property name="text" >
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="centerBox" >
<property name="text" >
<string>center</string>
<widget class="QGroupBox" name="originalData" >
<property name="minimumSize" >
<size>
<width>400</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="absBox" >
<property name="text" >
<string>Use Absolute values</string>
<property name="title" >
<string>original Data</string>