Commit 0341530d authored by Jan Möbius's avatar Jan Möbius

Show texture image in texturesettings dialog

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5708 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 533ba0eb
...@@ -51,6 +51,8 @@ void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _fil ...@@ -51,6 +51,8 @@ void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _fil
{ {
std::cerr << "slotLocalTextureAdded " << _textureName.toStdString() << std::endl; std::cerr << "slotLocalTextureAdded " << _textureName.toStdString() << std::endl;
// TODO: Load texture?! ...
// Get the new object // Get the new object
BaseObjectData* obj; BaseObjectData* obj;
if (! PluginFunctions::getObject( _id , obj ) ) { if (! PluginFunctions::getObject( _id , obj ) ) {
...@@ -77,12 +79,26 @@ void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _fil ...@@ -77,12 +79,26 @@ void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _fil
void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _filename , uint _dimension) void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _filename , uint _dimension)
{ {
std::cerr << "slotGlobalTextureAdded " << _textureName.toStdString() << std::endl;
// Add this texture to the list of global textures // Add this texture to the list of global textures
if ( ! globalTextures_.textureExists(_textureName) ) { if ( ! globalTextures_.textureExists(_textureName) ) {
globalTextures_.addTexture(_textureName,_filename,_dimension,0); globalTextures_.addTexture(_textureName,_filename,_dimension,0);
globalTextures_.texture(_textureName).enabled = false; globalTextures_.texture(_textureName).enabled = false;
QString loadFilename;
if ( _filename.startsWith("/") )
loadFilename = _filename;
else
loadFilename = OpenFlipper::Options::textureDirStr() + QDir::separator() + _filename;
QImage textureImage;
if ( !textureImage.load( loadFilename ) ){
emit log(LOGERR, "Cannot load texture " + _filename );
textureImage.load(OpenFlipper::Options::textureDirStr() + QDir::separator() + "unknown.png");
}
globalTextures_.texture(_textureName).textureImage = textureImage;
} else { } else {
emit log(LOGERR,"Trying to add already existing global texture " + _textureName ); emit log(LOGERR,"Trying to add already existing global texture " + _textureName );
return; return;
...@@ -97,13 +113,13 @@ void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _fil ...@@ -97,13 +113,13 @@ void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _fil
new_texture->setChecked(true); new_texture->setChecked(true);
textureActions_.push_back(new_texture); textureActions_.push_back(new_texture);
} }
void TextureControlPlugin::fileOpened( int _id ) { void TextureControlPlugin::fileOpened( int _id ) {
// TODO:: Store original texture coords in a new property! // TODO:: Store original texture coords in a new property!
std::cerr << "File opened : " << _id << std::endl;
// Get the new object // Get the new object
BaseObjectData* obj; BaseObjectData* obj;
if (! PluginFunctions::getObject( _id , obj ) ) { if (! PluginFunctions::getObject( _id , obj ) ) {
...@@ -126,20 +142,22 @@ void TextureControlPlugin::fileOpened( int _id ) { ...@@ -126,20 +142,22 @@ void TextureControlPlugin::fileOpened( int _id ) {
// Iterate over all available global textures and add them to the object // Iterate over all available global textures and add them to the object
for ( uint i = 0 ; i < globalTextures_.textures().size() ; ++i) { for ( uint i = 0 ; i < globalTextures_.textures().size() ; ++i) {
std::cerr << "Adding texture " << i << " " << globalTextures_.textures()[i].name.toStdString() << std::endl;
// ================================================================================ // ================================================================================
// Get the image file // Get the image file
// ================================================================================ // ================================================================================
// TODO: support arbitrary paths! // TODO: support arbitrary paths!
QString filename = OpenFlipper::Options::textureDir().absolutePath() +
OpenFlipper::Options::dirSeparator() + QString loadFilename;
globalTextures_.textures()[i].filename;
if ( globalTextures_.textures()[i].filename.startsWith("/") )
loadFilename = globalTextures_.textures()[i].filename;
else
loadFilename = OpenFlipper::Options::textureDirStr() + QDir::separator() + globalTextures_.textures()[i].filename;
QImage textureImage; QImage textureImage;
if ( !textureImage.load( filename ) ){ if ( !textureImage.load( loadFilename ) ){
emit log(LOGERR, "Cannot load texture " + filename ); emit log(LOGERR, "Cannot load texture " + globalTextures_.textures()[i].filename );
continue; textureImage.load(OpenFlipper::Options::textureDirStr() + QDir::separator() + "unknown.png");
} }
// ================================================================================ // ================================================================================
...@@ -158,8 +176,15 @@ void TextureControlPlugin::fileOpened( int _id ) { ...@@ -158,8 +176,15 @@ void TextureControlPlugin::fileOpened( int _id ) {
// Store texture information in objects metadata // Store texture information in objects metadata
// ================================================================================ // ================================================================================
if (glName != 0) if (glName != 0) {
texData->addTexture(globalTextures_.textures()[i], glName); texData->addTexture(globalTextures_.textures()[i], glName);
texData->setImage(globalTextures_.textures()[i].name,textureImage);
}
else {
emit log(LOGERR,"Unable to bind Texture");
continue;
}
// ================================================================================ // ================================================================================
// Update texture mapping in meshNode // Update texture mapping in meshNode
......
...@@ -155,6 +155,20 @@ int TextureData::addTexture ( Texture _texture, GLuint _glName ) { ...@@ -155,6 +155,20 @@ int TextureData::addTexture ( Texture _texture, GLuint _glName ) {
return _texture.id; return _texture.id;
} }
/// Stores the given image in the texture information
bool TextureData::setImage( QString _textureName , QImage& _image ) {
int textureid = -1;
textureid = getTextureIndex(_textureName);
if ( textureid == -1) {
std::cerr << "setImage: Unknown Texture!" << std::endl;
return true;
}
textures_[textureid].textureImage = _image;
return false;
}
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
/** \brief Delete a given texture /** \brief Delete a given texture
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <OpenFlipper/common/perObjectData.hh> #include <OpenFlipper/common/perObjectData.hh>
#include <QString> #include <QString>
#include <QImage>
#include <ACG/GL/gl.hh> #include <ACG/GL/gl.hh>
#include <vector> #include <vector>
#include <map> #include <map>
...@@ -90,6 +91,8 @@ struct Texture { ...@@ -90,6 +91,8 @@ struct Texture {
uint type; uint type;
// Parameters // Parameters
TexParameters parameters; TexParameters parameters;
QImage textureImage;
}; };
class TextureData : public PerObjectData class TextureData : public PerObjectData
...@@ -123,6 +126,9 @@ class TextureData : public PerObjectData ...@@ -123,6 +126,9 @@ class TextureData : public PerObjectData
/// Add a Texture ( Based on an existing specification ) /// Add a Texture ( Based on an existing specification )
int addTexture ( Texture _texture, GLuint _glName ); int addTexture ( Texture _texture, GLuint _glName );
/// Stores the given image in the texture information
bool setImage( QString _textureName , QImage& _image );
/* /*
/// Delete a given texture /// Delete a given texture
void deleteTexture(QString _textureName); void deleteTexture(QString _textureName);
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <float.h> #include <float.h>
#include <QtGui> #include <QtGui>
#include <OpenFlipper/common/GlobalOptions.hh>
texturePropertiesWidget::texturePropertiesWidget(QWidget *parent) texturePropertiesWidget::texturePropertiesWidget(QWidget *parent)
: QDialog(parent) : QDialog(parent)
...@@ -184,6 +185,15 @@ void texturePropertiesWidget::textureChanged(QListWidgetItem* _item){ ...@@ -184,6 +185,15 @@ void texturePropertiesWidget::textureChanged(QListWidgetItem* _item){
clamp_min->setValue( texture.parameters.clamp_min ); clamp_min->setValue( texture.parameters.clamp_min );
clamp_max->setValue( texture.parameters.clamp_max ); clamp_max->setValue( texture.parameters.clamp_max );
// Show the texture Image
imageLabel->setPixmap(QPixmap::fromImage(texture.textureImage));
imageLabel->setScaledContents(true);
if ( !texture.filename.startsWith("/") )
fileLabel->setText( "File: " + texture.filename );
else
fileLabel->setText( "File: " + OpenFlipper::Options::textureDirStr() + QDir::separator() + texture.filename );
// update plot only when dimension is 1 // update plot only when dimension is 1
if ( texture.dimension == 1) { if ( texture.dimension == 1) {
std::vector< double > x,y; std::vector< double > x,y;
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>666</width> <width>1186</width>
<height>548</height> <height>633</height>
</rect> </rect>
</property> </property>
<property name="minimumSize" > <property name="minimumSize" >
...@@ -24,141 +24,199 @@ ...@@ -24,141 +24,199 @@
<property name="windowTitle" > <property name="windowTitle" >
<string>Dialog</string> <string>Dialog</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_4" > <layout class="QGridLayout" name="gridLayout_2" >
<item> <item rowspan="2" row="0" column="0" >
<widget class="QSplitter" name="splitter" > <widget class="QSplitter" name="splitter" >
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<widget class="QWidget" name="" > <widget class="QWidget" name="" >
<layout class="QVBoxLayout" name="verticalLayout_2" > <layout class="QGridLayout" name="gridLayout" >
<item> <item row="0" column="0" >
<widget class="QLabel" name="textureLabel" > <layout class="QVBoxLayout" name="verticalLayout_2" >
<property name="text" > <item>
<string>Textures:</string> <widget class="QLabel" name="textureLabel" >
</property> <property name="text" >
</widget> <string>Textures:</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="textureList" >
<property name="alternatingRowColors" >
<bool>false</bool>
</property>
<property name="selectionBehavior" >
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
</layout>
</item> </item>
<item> <item row="0" column="1" >
<widget class="QListWidget" name="textureList" > <layout class="QVBoxLayout" name="verticalLayout_3" >
<property name="alternatingRowColors" > <item>
<bool>false</bool> <widget class="QGroupBox" name="groupBox" >
</property> <property name="title" >
<property name="selectionBehavior" > <string>Properties</string>
<enum>QAbstractItemView::SelectRows</enum> </property>
</property> <layout class="QVBoxLayout" name="verticalLayout" >
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="" >
<layout class="QVBoxLayout" name="verticalLayout_3" >
<item>
<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" name="horizontalLayout_2" >
<item> <item>
<widget class="QLabel" name="label_3" > <widget class="QCheckBox" name="repeatBox" >
<property name="text" > <property name="text" >
<string>Maximum:</string> <string>Repeat Texture</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QDoubleSpinBox" name="max_val" /> <layout class="QHBoxLayout" name="horizontalLayout_2" >
<item>
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Maximum:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="max_val" />
</item>
</layout>
</item> </item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="clampBox" >
<property name="text" >
<string>Clamp Texture</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" >
<item> <item>
<widget class="QLabel" name="label" > <widget class="QCheckBox" name="clampBox" >
<property name="text" > <property name="text" >
<string>Minimum:</string> <string>Clamp Texture</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QDoubleSpinBox" name="clamp_min" /> <layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QLabel" name="label" >
<property name="text" >
<string>Minimum:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="clamp_min" />
</item>
<item>
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Maximum:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="clamp_max" />
</item>
</layout>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_2" > <widget class="QCheckBox" name="centerBox" >
<property name="text" > <property name="text" >
<string>Maximum:</string> <string>Center</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QDoubleSpinBox" name="clamp_max" /> <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> </item>
</layout> </layout>
</item> </widget>
<item> </item>
<widget class="QCheckBox" name="centerBox" > <item>
<property name="text" > <widget class="QGroupBox" name="originalData" >
<string>Center</string> <property name="minimumSize" >
</property> <size>
</widget> <width>400</width>
</item> <height>0</height>
<item> </size>
<widget class="QCheckBox" name="absBox" > </property>
<property name="text" > <property name="title" >
<string>Use Absolute values</string> <string>original Data</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> </layout>
<widget class="QCheckBox" name="scaleBox" >
<property name="text" >
<string>Scale</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="originalData" >
<property name="minimumSize" >
<size>
<width>400</width>
<height>0</height>
</size>
</property>
<property name="title" >
<string>original Data</string>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
</item> </item>
<item> <item row="1" column="1" >
<spacer name="verticalSpacer" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>277</width>
<height>250</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" >
<widget class="QDialogButtonBox" name="buttonBox" > <widget class="QDialogButtonBox" name="buttonBox" >
<property name="standardButtons" > <property name="standardButtons" >
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> <set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1" >
<widget class="QGroupBox" name="imageBox" >
<property name="minimumSize" >
<size>
<width>280</width>
<height>280</height>
</size>
</property>
<property name="title" >
<string>Image</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4" >
<item>
<widget class="QLabel" name="imageLabel" >
<property name="minimumSize" >
<size>
<width>250</width>
<height>250</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>250</width>
<height>250</height>
</size>
</property>
<property name="text" >
<string>Image</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="fileLabel" >
<property name="text" >
<string>File:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment