45 #include "TextureControl.hh" 47 #include "ImageStorage.hh" 49 #include <QMessageBox> 52 #if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT) 55 #define TEXTUREDATA "TextureData" 68 void TextureControlPlugin::slotTextureAdded(QString _textureName , QString _fileName , QImage _image, uint _dimension ,
int _id)
73 emit log(
LOGERR,
"slotTextureAdded: Unable to get Object for id " + QString::number(_id) );
85 emit log(
LOGERR,
"slotTextureAdded: Trying to add already existing texture " + _textureName +
" for object " + QString::number(_id) );
95 if(_fileName.isEmpty())
96 newId = imageStore().addImage(_image);
98 newId = imageStore().addImageFile(_fileName);
101 emit log(
LOGERR,imageStore().error());
117 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 121 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 126 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 136 emit log(
LOGERR,
"slotTextureAdded: Unable to bind texture!");
140 if(_fileName.isEmpty())
141 texData->
addTexture(_textureName,_dimension,glName);
143 texData->
addTexture(_textureName,_fileName,_dimension,glName);
146 texData->
setImage(_textureName,newId);
148 texData->
texture(_textureName).disable();
151 void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _filename , QImage _image , uint _dimension)
155 if(_filename.isEmpty())
156 globalTextures_.
addTexture(_textureName,_dimension,0);
158 globalTextures_.
addTexture(_textureName,_filename,_dimension,0);
159 globalTextures_.
texture(_textureName).disable();
162 if(_filename.isEmpty())
163 newImageId = imageStore().addImage(_image);
165 newImageId = imageStore().addImageFile(_filename);
167 if ( newImageId == -1 ) {
168 emit log(
LOGERR,imageStore().error());
172 globalTextures_.
texture(_textureName).textureImageId(newImageId);
175 emit log(
LOGERR,
"slotTextureAdded: Trying to add already existing global texture " + _textureName );
180 QAction* new_texture =
new QAction(_textureName,
this);
181 new_texture->setStatusTip(tr(
"slotTextureAdded: Switch all objects to this Texture ( if available )"));
182 new_texture->setCheckable(
true);
183 actionGroup_->addAction(new_texture);
184 textureMenu_->addAction(new_texture);
185 new_texture->setChecked(
true);
186 textureActions_.push_back(new_texture);
190 void TextureControlPlugin::slotMultiTextureAdded( QString _textureGroup , QString _name , QString _filename , QImage _image ,
int _id ,
int& _textureId ) {
194 emit log(
LOGERR,
"slotMultiTextureAdded: Unable to get Object for id " + QString::number(_id) );
199 emit log(
LOGERR,
"slotMultiTextureAdded: Trying to add textures to object failed because of unsupported object type");
214 if(_filename.isEmpty())
215 slotTextureAdded( _name , _image , 2 , _id);
217 slotTextureAdded( _name , _filename , 2 , _id);
220 _textureId = texData->
texture(_name).id();
223 texData->
texture(_name).hidden(
true );
227 if(_filename.isEmpty())
228 newImageId = imageStore().addImage(_image);
230 newImageId = imageStore().addImageFile(_filename);
232 if ( newImageId == -1 ) {
233 emit log(
LOGERR,imageStore().error());
238 texData->
texture(_name).textureImageId(newImageId);
241 if ( _textureId != -1 ) {
244 emit log(
LOGERR,
"slotMultiTextureAdded: Error when getting internal id of new multitexture!");
249 void TextureControlPlugin::addedEmptyObject(
int _id ) {
260 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 263 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 266 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 282 for ( uint i = 0 ; i < globalTextures_.
textures().size() ; ++i) {
285 int newImageId = imageStore().addImageFile(globalTextures_.
textures()[i].filename());
287 if ( newImageId == -1 ) {
288 emit log(
LOGERR,imageStore().error());
304 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 308 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 313 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 328 imageStore().removeImage(newImageId);
329 emit log(
LOGERR,
"addedEmptyObject: Unable to bind Texture");
348 template<
typename MeshT >
357 if ( _mesh->has_vertex_texcoords2D() ){
358 slotTextureAdded(
"Original Per Vertex Texture Coords",
"unknown.png",2,_objectId);
359 slotSetTextureMode(
"Original Per Vertex Texture Coords",
"type=vertexbased",_objectId);
362 if ( _mesh->has_halfedge_texcoords2D() ){
363 slotTextureAdded(
"Original Per Face Texture Coords",
"unknown.png",2,_objectId);
364 slotSetTextureMode(
"Original Per Face Texture Coords",
"type=halfedgebased",_objectId);
369 #if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT) 370 template<
typename VolumeMeshObjectT >
371 void TextureControlPlugin::handleFileOpenTexturesOVM( VolumeMeshObjectT* _obj,
int _objectId ) {
373 if ( _obj->texcoords().vertex_texcoords_available() ){
374 slotTextureAdded(
"Original Per Vertex Texture Coords",
"unknown.png",2,_objectId);
375 slotSetTextureMode(
"Original Per Vertex Texture Coords",
"type=vertexbased",_objectId);
381 void TextureControlPlugin::fileOpened(
int _id ) {
387 emit log(
LOGERR,
"fileOpened: Unable to get Object for id " + QString::number(_id) );
393 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 396 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 407 emit log(
LOGERR,tr(
"fileOpened: Unable to get texture object data for id %1.").arg(_id) );
421 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 424 handleFileOpenTexturesOVM(ovm_obj, _id);
427 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 430 handleFileOpenTexturesOVM(ovm_obj, _id);
436 void TextureControlPlugin::slotTextureChangeImage( QString _textureName , QImage& _image ,
int _id ) {
443 emit log(
LOGERR,
"slotTextureChangeImage: Unable to get Object for id " + QString::number(_id) );
451 if ( texData == 0 || ( !texData->
textureExists(_textureName)) ) {
452 emit log(
LOGERR,
"slotTextureChangeImage: Texture does not exist: " + _textureName +
" (objectid=" + QString::number(_id) +
")");
462 int newImageId = imageStore().addImage(_image);
465 texture.textureImageId(newImageId);
476 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 481 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 487 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 497 void TextureControlPlugin::slotTextureChangeImage( QString _textureName , QImage& _image ) {
503 emit log(
LOGERR,
"slotTextureChangeImage: Global texture does not exist: " + _textureName);
513 int newImageId = imageStore().addImage(_image);
516 texture.textureImageId(newImageId);
527 localTex.textureImageId(newImageId);
534 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 539 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 544 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 556 void TextureControlPlugin::slotTextureGetImage( QString _textureName, QImage& _image,
int _id ){
561 emit log(
LOGERR,
"slotTextureGetImage: Unable to get Object for id " + QString::number(_id) );
569 emit log(
LOGERR, tr(
"slotTextureGetImage: Object has no texture data! Object: %1").arg(_id) );
577 emit log(
LOGERR,
"slotTextureGetImage: Texture not available! " + _textureName );
581 if ( texData->
texture(_textureName).type() == MULTITEXTURE )
584 _image = imageStore().getImage(texData->
texture(_textureName).textureImageId(),0 );
588 void TextureControlPlugin::slotTextureGetImage( QString _textureName, QImage& _image ){
591 emit log(
LOGERR,
"slotTextureGetImage: Global texture does not exist: " + _textureName);
595 if ( globalTextures_.
texture(_textureName).type() == MULTITEXTURE )
598 _image = imageStore().getImage(globalTextures_.
texture(_textureName).textureImageId(),0);
601 void TextureControlPlugin::slotTextureIndex( QString _textureName,
int _id,
int& _index){
606 emit log(
LOGERR,
"slotTextureIndex: Unable to get Object for id " + QString::number(_id) );
614 emit log(
LOGERR, tr(
"slotTextureIndex: Object has no texture data! Object: %1").arg(_id) );
622 emit log(
LOGERR,
"slotTextureIndex: Texture not available! " + _textureName );
626 _index = texData->
texture(_textureName).id();
629 void TextureControlPlugin::slotTextureIndexPropertyName(
int _id, QString& _propertyName) {
634 emit log(
LOGERR,
"slotTextureIndexPropertyName: Unable to get Object for id " + QString::number(_id) );
644 emit log(
LOGERR,
"slotTextureIndexPropertyName: Unable to access mesh for object with id " + QString::number(_id) );
648 void TextureControlPlugin::slotTextureName(
int _id,
int _textureIndex, QString& _textureName){
653 emit log(
LOGERR,
"slotTextureName: Unable to get Object for id " + QString::number(_id) );
661 emit log(
LOGERR, tr(
"slotTextureName: Object has no texture data! Object: %1").arg(_id) );
665 for (uint i=0; i < texData->
textures().size(); i++ )
666 if ( (texData->
textures()[i]).
id() == _textureIndex ){
671 emit log(
LOGERR,
"slotTextureName: TextureIndex not available! (" + QString::number(_textureIndex) +
")" );
672 _textureName =
"NOT_FOUND";
676 void TextureControlPlugin::slotTextureFilename(
int _id, QString _textureName, QString& _textureFilename){
681 emit log(
LOGERR,
"slotTextureFilename: Unable to get Object for id " + QString::number(_id) );
689 emit log(
LOGERR, tr(
"slotTextureFilename: Object has no texture data! Object: %1").arg(_id) );
694 for (uint i=0; i < texData->
textures().size(); i++ ) {
695 for (
int j=0; j < texData->
textures()[i].multiTextureList.size(); j++ ) {
698 _textureFilename = tex.filename();
700 }
else if ( (texData->
textures()[i]).multiTextureList[j] == _textureName ){
702 _textureFilename = tex.filename();
708 _textureFilename = OpenFlipper::Options::textureDir().path() +
709 QDir::separator().toLatin1() + (globalTextures_.
texture(_textureName)).filename();
711 QFile f(_textureFilename);
712 if(!f.exists()) _textureFilename =
"NOT_FOUND";
717 void TextureControlPlugin::slotGetCurrentTexture(
int _id, QString& _textureName ){
719 _textureName =
"NONE";
724 emit log(
LOGERR,
"slotGetCurrentTexture: Unable to get Object for id " + QString::number(_id) );
735 QMap<QString, PerObjectData*>::const_iterator mapIter = obj->
getPerObjectDataMap().begin();
745 for ( uint i = 0 ; i < texData->
textures().size() ; ++i) {
747 if ( (texData->
textures()[i]).enabled() ){
750 if ( (texData->
textures()[i]).type() == MULTITEXTURE ) {
757 void TextureControlPlugin::slotGetSubTextures(
int _id, QString _multiTextureName, QStringList& _subTextures ){
761 emit log(
LOGERR,
"slotGetSubTextures: Unable to get Object for id " + QString::number(_id) );
769 emit log(
LOGERR, tr(
"slotGetSubTextures: Object has no texture data! Object: %1").arg(_id) );
777 emit log(
LOGERR,
"slotGetSubTextures: Texture not available! " + _multiTextureName );
781 if ( texData->
texture(_multiTextureName).type() == MULTITEXTURE )
784 _subTextures = QStringList();
787 void TextureControlPlugin::slotTextureUpdated( QString _textureName ,
int _identifier ){
794 emit log(
LOGERR,
"slotTextureUpdated: Unable to get Object for id " + QString::number(_identifier) );
800 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 803 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 806 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 817 emit log(
LOGERR,tr(
"slotTextureUpdated: Texture data not found: Object %1" ).arg(_identifier) );
825 emit log(
LOGERR,
"slotTextureUpdated: Texture " + _textureName +
" not found on object " + QString::number(_identifier) );
832 if ( ! texData->
texture(_textureName).enabled() ) {
833 texData->
texture(_textureName).setDirty();
855 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 859 doUpdateTextureOVM(texData->
texture(_textureName), *mesh, *meshObj);
866 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 870 doUpdateTextureOVM(texData->
texture(_textureName), *mesh, *meshObj);
877 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 890 texData->
texture(_textureName).clean();
899 void TextureControlPlugin::slotUpdateTexture( QString _textureName ,
int _identifier) {
900 if ( _textureName ==
"Reflection Lines" )
901 slotTextureUpdated( _textureName , _identifier );
905 template<
typename MeshT >
909 if ( _texture.type() == HALFEDGEBASED ) {
910 if (_texture.dimension() == 1) {
913 if ( ! _mesh.get_property_handle(texture, _texture.name().toStdString() ) ) {
914 emit log(
LOGERR,tr(
"doUpdateTexture: HALFEDGEBASED dimension 1: Unable to get property %1").arg(_texture.name()) );
920 }
else if ( _texture.dimension() == 2 ) {
923 if ( ! _mesh.get_property_handle( texture2D, _texture.name().toStdString() ) ) {
924 emit log(
LOGERR,tr(
"doUpdateTexture: HALFEDGEBASED dimension 2: Unable to get property %1").arg(_texture.name()) );
931 emit log(
LOGERR,
"doUpdateTexture: Unsupported Texture Dimension " + QString::number(_texture.dimension() ) );
932 }
else if ( _texture.type() == VERTEXBASED ) {
933 if ( _texture.dimension() == 1 ) {
936 if ( ! _mesh.get_property_handle(texture,_texture.name().toStdString() ) ) {
937 emit log(
LOGERR,tr(
"doUpdateTexture: VERTEXBASED dimension 1: Unable to get property %1").arg(_texture.name()) );
943 }
else if ( _texture.dimension() == 2 ) {
946 if ( ! _mesh.get_property_handle(texture2D,_texture.name().toStdString() ) ) {
947 emit log(
LOGERR,tr(
"doUpdateTexture: VERTEXBASED dimension 2: Unable to get property %1").arg(_texture.name()) );
964 emit log(
LOGERR,
"doUpdateTexture: Unsupported Texture Dimension " + QString::number(_texture.dimension() ) );
967 emit log(
LOGERR,
"doUpdateTexture: Unsupported Texture type");
972 #if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT) 973 template<
typename VolumeMeshT,
typename VolumeMeshObjectT >
974 void TextureControlPlugin::doUpdateTextureOVM (
Texture& _texture, VolumeMeshT& _mesh, VolumeMeshObjectT& _obj )
976 if ( _texture.type() == VERTEXBASED ) {
977 if ( _texture.dimension() == 1 ) {
979 if (!_mesh.template vertex_property_exists<double>(_texture.name().toStdString())){
980 emit log(
LOGERR,tr(
"doUpdateTexture: VERTEXBASED dimension 1: Unable to get property %1").arg(_texture.name()) );
988 _obj.setObjectDrawMode(drawModesVolumeMesh.facesTextured);
991 else if ( _texture.dimension() == 2 )
994 if (!_mesh.template vertex_property_exists<ACG::Vec2d>(_texture.name().toStdString())){
995 emit log(
LOGERR,tr(
"doUpdateTexture: VERTEXBASED dimension 2: Unable to get property %1").arg(_texture.name()) );
1002 _obj.setObjectDrawMode(drawModesVolumeMesh.facesTextured);
1006 emit log(
LOGERR,
"doUpdateTexture: Unsupported Texture Dimension " + QString::number(_texture.dimension() ) );
1009 emit log(
LOGERR,
"doUpdateTexture: Unsupported Texture type");
1014 void TextureControlPlugin::slotDrawModeChanged(
int _viewerId ) {
1016 #ifdef ENABLE_OPENVLUMEMESH_SUPPORT 1026 #ifdef ENABLE_OPENVLUMEMESH_SUPPORT
1047 for ( uint i = 0; i < texData->
textures().size(); ++i ) {
1048 if ( texData->
textures()[i].enabled() && texData->
textures()[i].dirty() ) {
1049 emit updateTexture( texData->
textures()[i].name() , o_it->id() );
1060 void TextureControlPlugin::slotObjectUpdated(
int _identifier,
const UpdateType& _type)
1068 if ( _identifier == -1 )
1077 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 1080 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 1083 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 1103 for ( uint i = 0; i < texData->
textures().size(); ++i ) {
1106 bool update =
false;
1113 #if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT) 1120 if ( update && texData->
textures()[i].enabled() )
1121 emit updateTexture( texData->
textures()[i].name() , _identifier );
1126 void TextureControlPlugin::slotUpdateAllTextures( ) {
1127 std::cerr <<
"slotUpdateAllTextures: not implemented yet ... might be removed" << std::endl;
1137 bool changed =
false;
1140 QString nextString = _mode.section(
',',i,i);
1141 while ( nextString !=
"" ) {
1142 QString sectionName = nextString.section(
'=',0,0);
1143 QString value = nextString.section(
'=',1,1);
1146 value = value.trimmed();
1147 sectionName = sectionName.trimmed();
1148 sectionName = sectionName.toLower();
1150 if ( sectionName ==
"clamp" ) {
1151 if ( StringToBool(value) != _texture.
parameters.clamp ) {
1152 _texture.
parameters.clamp = StringToBool(value);
1155 }
else if ( sectionName ==
"clamp_max" ) {
1156 if (value.toDouble() != _texture.
parameters.clampMax){
1157 _texture.
parameters.clampMax = value.toDouble();
1160 }
else if ( sectionName ==
"clamp_min" ) {
1161 if (value.toDouble() != _texture.
parameters.clampMin){
1162 _texture.
parameters.clampMin = value.toDouble();
1165 }
else if ( sectionName ==
"max_val" ) {
1166 if (value.toDouble() != _texture.
parameters.repeatMax){
1167 _texture.
parameters.repeatMax = value.toDouble();
1170 }
else if ( sectionName ==
"min_val" ) {
1171 if (value.toDouble() != _texture.
parameters.repeatMin){
1172 _texture.
parameters.repeatMin = value.toDouble();
1175 }
else if ( sectionName ==
"repeat" ) {
1176 if ( StringToBool(value) != _texture.
parameters.repeat ) {
1177 _texture.
parameters.repeat = StringToBool(value);
1180 }
else if ( sectionName ==
"center" ) {
1181 if ( StringToBool(value) != _texture.
parameters.center ) {
1182 _texture.
parameters.center = StringToBool(value);
1185 }
else if ( sectionName ==
"scale" ) {
1186 if ( StringToBool(value) != _texture.
parameters.scale ) {
1187 _texture.
parameters.scale = StringToBool(value);
1190 }
else if ( sectionName ==
"abs" ) {
1191 if ( StringToBool(value) != _texture.
parameters.abs ) {
1192 _texture.
parameters.abs = StringToBool(value);
1195 }
else if ( sectionName ==
"indexproperty" ) {
1196 if ( value != _texture.indexMappingProperty() ) {
1197 _texture.indexMappingProperty( value );
1200 }
else if ( sectionName ==
"visiblename" ) {
1201 if ( value != _texture.visibleName() ) {
1202 _texture.visibleName( value );
1205 }
else if ( sectionName ==
"type" ) {
1206 if ( ( value ==
"halfedgebased" ) && ( _texture.type() != HALFEDGEBASED ) ) {
1207 _texture.type( HALFEDGEBASED );
1209 }
else if ( (value ==
"vertexbased") && (_texture.type() != HALFEDGEBASED) ) {
1210 _texture.type( VERTEXBASED );
1212 }
else if ( (value ==
"environmentmap") && (_texture.type() != ENVIRONMENT) ) {
1213 _texture.type( ENVIRONMENT );
1216 emit log(
LOGERR,
"parseMode: Unknown texture type : " + value +
" for texture: " + _texture.name() );
1219 emit log(
LOGERR,
"parseMode: Unknown texture mode : " + sectionName);
1222 nextString = _mode.section(
',',i,i);
1228 void TextureControlPlugin::slotSetTextureMode(QString _textureName ,QString _mode) {
1234 emit log(
LOGERR,
"slotSetTextureMode: Global texture does not exist: " + _textureName);
1245 _mode = _mode.toLower();
1265 bool changed =
false;
1272 if ( _mode.contains(
"clamp_max") && (texture.
parameters.clampMax != localTex.
parameters.clampMax) ){
1277 if ( _mode.contains(
"clamp_min") && (texture.
parameters.clampMin != localTex.
parameters.clampMin) ){
1282 if ( _mode.contains(
"max_val") && (texture.
parameters.repeatMax != localTex.
parameters.repeatMax) ){
1287 if ( _mode.contains(
"min_val") && (texture.
parameters.repeatMin != localTex.
parameters.repeatMin) ){
1307 if ( _mode.contains(
"type") && (texture.type() != localTex.type() ) ){
1308 localTex.type( texture.type() );
1312 if ( _mode.contains(
"visiblename") && (texture.visibleName() != localTex.visibleName() ) ){
1313 localTex.visibleName( texture.visibleName() );
1320 emit updateTexture( _textureName, o_it->id() );
1322 localTex.setDirty();
1329 bool TextureControlPlugin::StringToBool(QString _value){
1330 if (_value ==
"false")
1336 void TextureControlPlugin::slotSetTextureMode(QString _textureName, QString _mode,
int _id) {
1341 emit log(
LOGERR,
"slotSetTextureMode: Unable to get Object for id " + QString::number(_id) );
1347 if ( texData == 0 || ( !texData->
textureExists(_textureName)) ) {
1348 emit log(
LOGERR,
"slotSetTextureMode: Texture does not exist: " + _textureName +
" (object=" + QString::number(_id) +
")");
1358 bool changed =
parseMode(_mode,texture);
1363 emit updateTexture( _textureName, _id );
1369 void TextureControlPlugin::pluginsInitialized() {
1373 textureMenu_ =
new QMenu(tr(
"&Texture Control"));
1374 textureMenu_->setTearOffEnabled(
true);
1375 emit addMenubarAction(textureMenu_->menuAction(),
VIEWMENU );
1382 connect( settingsDialog_, SIGNAL( applyProperties(
TextureData*,QString,
int) ),
1383 this, SLOT( applyDialogSettings(
TextureData*,QString,
int) ));
1385 connect( settingsDialog_, SIGNAL( getCoordinates1D(QString,
int,std::vector< double >&)),
1386 this, SLOT( getCoordinates1D(QString,
int,std::vector< double >&)));
1388 settingsDialog_->installEventFilter(
this );
1393 actionGroup_ =
new QActionGroup( 0 );
1394 actionGroup_->setExclusive(
true );
1395 connect( actionGroup_, SIGNAL( triggered( QAction * ) ),
1398 QAction* AC_Texture_Settings =
new QAction(tr(
"&Texture Settings"),
this);
1399 AC_Texture_Settings->setStatusTip(tr(
"Set the texture visualization properties"));
1401 textureMenu_->addAction(AC_Texture_Settings);
1403 textureMenu_->addSeparator();
1404 textureMenu_->addActions(actionGroup_->actions());
1414 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 1417 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 1421 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 1425 slotTextureAdded(
"Reflection Lines",
"reflection_map.png",2);
1426 slotSetTextureMode(
"Reflection Lines",
"type=environmentmap");
1431 settingsDialog_->show( &globalTextures_, -1);
1434 void TextureControlPlugin::applyDialogSettings(
TextureData* _texData, QString _textureName,
int _id) {
1443 emit log(
LOGERR,
"applyDialogSettings: Unable to get Object for id " + QString::number(_id) );
1447 emit log(
LOGERR,
"applyDialogSettings: Texture does not exist in applyDialogSettings " + _textureName );
1457 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 1462 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 1468 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 1475 _texData->
texture( _textureName ).setDirty();
1479 for ( uint i=0; i < _texData->
textures().size(); i++ )
1480 if ( _texData->
textures()[i].enabled() ){
1481 doSwitchTexture( _texData->
textures()[i].name(), _id);
1492 _texData->
texture( _textureName ).setDirty();
1501 if ( texData != 0 && texData->
textureExists(_textureName) ){
1506 bool changed =
false;
1544 slotTextureUpdated( _textureName , o_it->id() );
1546 texData->
texture( _textureName ).setDirty();
1555 slotSwitchTexture( _action->text() );
1571 void TextureControlPlugin::doSwitchTexture( QString _textureName ,
int _id ) {
1576 emit log(
LOGERR,
"doSwitchTexture: Unable to get Object for id " + QString::number(_id) );
1588 emit log(
LOGERR, tr(
"doSwitchTexture: Object has no texture data! Object: %1").arg(_id) );
1596 emit log(
LOGERR,
"doSwitchTexture: Texture not available! " + _textureName );
1603 QStringList textureList;
1604 switch (texData->
texture(_textureName).type()) {
1613 for ( uint i = 0 ; i < texData->
textures().size() ; ++i ) {
1614 if ( textureList.contains( texData->
textures()[i].name() ) || (texData->
textures()[i].name() == _textureName) )
1627 emit log(
LOGERR,
"doSwitchTexture: Failed to enabled VERTEXBASED or HALFEDGEBASED Texture " + _textureName );
1630 if ( texData->
texture( _textureName).dirty() ) {
1632 emit updateTexture( texData->
texture( _textureName ).name() , obj->
id() );
1640 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 1644 doUpdateTextureOVM(texData->
texture(_textureName), *mesh, *meshObj);
1647 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 1651 doUpdateTextureOVM(texData->
texture(_textureName), *mesh, *meshObj);
1655 emit log(
LOGERR,
"doSwitchTexture: HALFEDGEBASED or VERTEXBASED type require poly or trimesh to work! Texture: " + _textureName );
1663 emit log(
LOGERR,
"doSwitchTexture: Failed to enabled ENVIRONMENT Texture " + _textureName );
1668 emit log(
LOGERR,
"doSwitchTexture. Texture Type is unset! This should never happen! " + _textureName );
1675 if ( texData->
texture(_textureName).type() == MULTITEXTURE ) {
1700 emit log(
LOGERR,
"doSwitchTexture: MultiTexture Error: Only supported on Tri or Poly Mesh for Texture: " + _textureName );
1710 if ( texData->
texture(_textureName).type() == HALFEDGEBASED ) {
1724 if ( texData->
texture(_textureName).type() == HALFEDGEBASED ) {
1732 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 1738 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 1744 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 1751 emit log(
LOGERR,
"doSwitchTexture: Texture Error ( mesh required) for Texture: " + _textureName );
1764 emit log(
LOGERR,
"doSwitchTexture: Unable to get Object for id " + QString::number(_id));
1779 emit log(
LOGERR,
"doSwitchTexture: Switching drawmode for unknonw Texture Type!");
1786 void TextureControlPlugin::slotSwitchTexture( QString _textureName ,
int _id ) {
1788 doSwitchTexture(_textureName, _id);
1791 void TextureControlPlugin::slotSwitchTexture( QString _textureName ) {
1797 doSwitchTexture(_textureName, o_it->id() );
1807 if ( _objectId == -1 )
1812 emit log(
LOGERR,
"slotUpdateContextMenu: Unable to get Object for id " + QString::number(_objectId) );
1818 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 1821 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 1824 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 1838 emit log(
LOGERR,tr(
"slotUpdateContextMenu: Texture data not found! Object %1 ").arg(_objectId) );
1846 QActionGroup* actionGroup =
new QActionGroup(0);
1847 actionGroup->setExclusive(
true );
1848 connect( actionGroup, SIGNAL( triggered( QAction * ) ),
1851 QAction* action = actionGroup->addAction(
"Texture Settings" );
1856 for ( uint i = 0 ; i < texData->
textures().size() ; ++i ) {
1858 if ( texData->
textures()[i].hidden() )
1861 if ( !texData->
textures()[i].visibleName().isEmpty() )
1862 action = actionGroup->addAction( texData->
textures()[i].visibleName() );
1864 action = actionGroup->addAction( texData->
textures()[i].name() );
1866 action->setCheckable(
true);
1868 if ( texData->
textures()[i].enabled() )
1869 action->setChecked(
true);
1879 QVariant idVariant = _action->data( );
1880 int id = idVariant.toInt();
1885 emit log(
LOGERR,
"slotTextureContextMenu: Unable to get Object for id " + QString::number(
id) );
1892 if (_action->text() ==
"Texture Settings"){
1897 msgBox.setText(
"Cannot show Properties. No Textures available!");
1902 settingsDialog_->show( texData,
id, obj->
name() );
1907 if ( texData != 0) {
1908 slotSwitchTexture( _action->text() , id );
1918 void TextureControlPlugin::getCoordinates1D(QString _textureName,
int _id, std::vector< double >& _x ){
1923 emit log(
LOGERR,
"getCoordinates1D: Unable to get Object for id " + QString::number(_id) );
1931 emit log(
LOGERR,tr(
"getCoordinates1D: Object %1 has no texture data ").arg(_id) );
1939 emit log(
LOGERR,
"getCoordinates1D: Texture not available! " + _textureName );
1943 if ( texData->
texture( _textureName ).dirty() )
1944 emit updateTexture( _textureName , _id );
1954 if ( texData->
texture(_textureName).type() == VERTEXBASED )
1958 if ( !mesh->get_property_handle(coordProp, _textureName.toStdString() ) )
1960 emit log(
LOGERR,tr(
"getCoordinates1D: Texture Property not found: Object %1 , TextureName %2").arg(_id).arg(_textureName) );
1964 for ( TriMesh::VertexIter v_it = mesh->vertices_begin() ; v_it != mesh->vertices_end(); ++v_it)
1965 _x.push_back( mesh->property(coordProp,*v_it) );
1968 else if ( texData->
texture(_textureName).type() == HALFEDGEBASED )
1972 if ( !mesh->get_property_handle(coordProp, _textureName.toStdString() ) )
1974 emit log(
LOGERR,tr(
"getCoordinates1D: Texture Property not found: Object %1 , TextureName %2").arg(_id).arg(_textureName) );
1978 for ( TriMesh::HalfedgeIter h_it = mesh->halfedges_begin() ; h_it != mesh->halfedges_end(); ++h_it)
1979 _x.push_back( mesh->property(coordProp,*h_it) );
1987 if ( texData->
texture(_textureName).type() == VERTEXBASED )
1991 if ( !mesh->get_property_handle(coordProp, _textureName.toStdString() ) )
1993 emit log(
LOGERR,tr(
"getCoordinates1D: Texture Property not found: Object %1 , TextureName %2").arg(_id).arg(_textureName) );
1997 for ( PolyMesh::VertexIter v_it = mesh->vertices_begin() ; v_it != mesh->vertices_end(); ++v_it)
1998 _x.push_back( mesh->property(coordProp,*v_it) );
2000 else if ( texData->
texture(_textureName).type() == HALFEDGEBASED )
2004 if ( !mesh->get_property_handle(coordProp, _textureName.toStdString() ) )
2006 emit log(
LOGERR,tr(
"getCoordinates1D: Texture Property not found: Object %1 , TextureName %2").arg(_id).arg(_textureName) );
2010 for ( PolyMesh::HalfedgeIter h_it = mesh->halfedges_begin() ; h_it != mesh->halfedges_end(); ++h_it)
2011 _x.push_back( mesh->property(coordProp,*h_it) );
2014 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 2019 if ( texData->
texture(_textureName).type() == VERTEXBASED )
2021 if ( !mesh->vertex_property_exists<
double>(_textureName.toStdString()) )
2023 emit log(
LOGERR,tr(
"getCoordinates1D: Texture Property not found: Object %1 , TextureName %2").arg(_id).arg(_textureName) );
2030 _x.push_back( coordProp[*v_it] );
2034 emit log(
LOGERR,tr(
"getCoordinates1D: Only VERTEXBASED texture type supported for OpenVolumeMesh") );
2038 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 2043 if ( texData->
texture(_textureName).type() == VERTEXBASED )
2046 if ( !mesh->vertex_property_exists<
double>(_textureName.toStdString()) )
2048 emit log(
LOGERR,tr(
"getCoordinates1D: Texture Property not found: Object %1 , TextureName %2").arg(_id).arg(_textureName) );
2055 _x.push_back( coordProp[*v_it] );
2059 emit log(
LOGERR,tr(
"getCoordinates1D: Only VERTEXBASED texture type supported for OpenVolumeMesh") );
2066 void TextureControlPlugin::slotAboutToRestore(
int _objectid ) {
2073 emit log(
LOGERR,
"slotAboutToRestore: Unable to get Object for id " + QString::number(_objectid) );
2097 void TextureControlPlugin::slotRestored(
int _objectid ) {
2101 QString currentTexture;
2102 slotGetCurrentTexture(_objectid,currentTexture);
2107 slotSwitchTexture(currentTexture,_objectid);
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
int addTexture(QString _textureName, uint _dimension, GLuint _glName)
Add a Texture without file backing.
ACG::SceneGraph::TextureNode * textureNode()
Return pointer to the texture node.
void slotUpdateContextMenu(int _objectId)
Slot from the context menu interface.
GLuint add_texture(const QImage &_image)
Add a texture to this node.
QStringList multiTextureList
If this is a multiTexture, the list will contain all textures for this multi Texture node...
void set_texture(const QImage &_image)
Uses a QImage to set the texture.
ACG::SceneGraph::EnvMapNode * textureNode()
Get the TextureNode of the current mesh.
DrawMode SOLID_ENV_MAPPED
draw environment mapped
PolyMeshObject * polyMeshObject(BaseObjectData *_object)
Cast an BaseObject to a PolyMeshObject if possible.
const UpdateType UPDATE_TEXTURE(UpdateTypeSet(1)<< 11)
Textures have changed.
TexParameters parameters
Parameters of the texture.
bool addMultiTexture(QString _textureName)
Adds a new multiTexture ( This texture will only contain a list of enabled textures for multitexturin...
bool dataType(DataType _type) const
MeshT * mesh()
return a pointer to the mesh
TriMeshObject * triMeshObject(BaseObjectData *_object)
Cast an BaseObject to a TriMeshObject if possible.
bool parseMode(QString _mode, Texture &_texture)
parse texture mode settings Parses the string _mode and changes the settings in _texture according to...
void setTextureMap(std::map< int, GLuint > *_map)
Setup a mapping between internal texture ids on the mesh and the ids for the loaded textures in openg...
int viewers()
Get the number of viewers.
void doUpdateTexture(Texture &_texture, MeshT &_mesh)
Calls the correct copyTexture() function to copy the texture property into the displayed OM property...
std::vector< Texture > & textures()
Get reference to the texture vector.
PolyhedralMeshObject * polyhedralMeshObject(BaseObjectData *_object)
Cast an BaseObject to an PolyhedralMeshObject if possible.
void handleFileOpenTextures(MeshT *&_mesh, int _objectId)
Handles data stored in new opened files ( e.g. Texture Information )
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
const QStringList ALL_OBJECTS
Iterable object range.
bool setImage(QString _textureName, int _id)
Stores the given image in the texture information.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
PolyhedralMesh * polyhedralMesh(BaseObjectData *_object)
Get an PolyhedralMesh from an object.
HexahedralMesh * hexahedralMesh(BaseObjectData *_object)
Get an HexahedralMesh from an object.
HexahedralMeshObject * hexahedralMeshObject(BaseObjectData *_object)
Cast an BaseObject to an HexahedralMeshObject if possible.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
bool enableTexture(QString _textureName, bool _exclusive=false)
Enable a given texture.
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
#define DATA_BSPLINE_SURFACE
DrawMode SOLID_TEXTURED_SHADED
draw smooth shaded textured faces
#define DATA_HEXAHEDRAL_MESH
ACG::SceneGraph::DrawModes::DrawMode drawMode(int _viewer)
Get the current draw Mode of a Viewer.
DrawMode SOLID_2DTEXTURED_FACE
draw per halfedge textured faces
std::map< int, GLuint > * textureMap()
Get pointer to the textureMap.
void setObjectData(QString _dataName, PerObjectData *_data)
ACG::SceneGraph::MeshNodeT< MeshT > * meshNode()
Get the Scenegraph Mesh Node.
void set_repeat(bool _status)
set texture repeat status
QMenu * contextMenu_
Stores the per object context menu.
#define VIEWMENU
The Menu will be added inside the View Menu.
void setHalfedgeTextcoordPropertyName(std::string _halfedgeTextcoordPropertyName)
Set the name of the per face texture coordinate property.
const std::string & indexPropertyName() const
Get current texture index property name.
void slotSetTextureProperties()
Slot for showing the TextureProperties Dialog.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
bool activateTexture(GLuint _id)
Set active Texture.
#define DATA_POLYHEDRAL_MESH
QString name()
Return a name for the plugin.
void setObjectDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, const bool &_force=false)
Set the draw mode for the object.
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
DrawMode SOLID_2DTEXTURED_FACE_SHADED
draw per halfedge textured faces
const UpdateType UPDATE_TOPOLOGY(UpdateTypeSet(1)<< 3)
Topology updated.
This class provides easy access to DrawModes supported by OpenVolumeMesh.
PerObjectData * objectData(QString _dataName)
Returns the object data pointer.
ACG::SceneGraph::EnvMapNode * textureNode()
Get the TextureNode (actually its an environment map node) of the bspline surface.
#define DATA_TRIANGLE_MESH
void copyTexture(Texture &_texture, MeshT &_mesh, OpenMesh::VPropHandleT< double > _texProp)
Copy the supplied 1D vertex property to both coordinates of the 2D vertex OM texture property...
void switchDrawMode(TextureType _type, int _id)
Checks for a correct drawmode and changes if necessary.
bool isEnabled(QString _textureName)
Check if a texture is enabled.
DrawMode SOLID_TEXTURED
draw textured faces
void slotTextureMenu(QAction *_action)
Called when an action in the TextureMenu is triggered.
BSplineSurfaceObject * bsplineSurfaceObject(BaseObjectData *_object)
Cast an BaseObject to a BSplineSurfaceObject if possible.
QMap< QString, PerObjectData * > & getPerObjectDataMap()
get reference to map of all perObject Datas
The Menu will be shown when an object was picked.
TextureControlPlugin()
Constructor.
Texture & texture(QString _textureName)
Get the texture object.
DLLEXPORT DataType typeId(QString _name)
Given a dataType Identifier string this function will return the id of the datatype.
void setIndexPropertyName(std::string _indexPropertyName)
set the name of the property used for texture index specification
void slotTextureContextMenu(QAction *_action)
Called when the context menu has been triggered.
bool textureExists(QString _textureName)
Check if a texture exists.
void disableTexture(QString _textureName)
Disable a given texture.