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);
99 texData->addManagedImageId(newId);
102 emit log(
LOGERR,imageStore().error());
118 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 122 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 127 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 137 emit log(
LOGERR,
"slotTextureAdded: Unable to bind texture!");
141 if(_fileName.isEmpty())
142 texData->
addTexture(_textureName,_dimension,glName);
144 texData->
addTexture(_textureName,_fileName,_dimension,glName);
147 texData->
setImage(_textureName,newId);
149 texData->
texture(_textureName).disable();
152 void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _filename , QImage _image , uint _dimension)
156 if(_filename.isEmpty())
157 globalTextures_.
addTexture(_textureName,_dimension,0);
159 globalTextures_.
addTexture(_textureName,_filename,_dimension,0);
160 globalTextures_.
texture(_textureName).disable();
163 if(_filename.isEmpty())
164 newImageId = imageStore().addImage(_image);
166 newImageId = imageStore().addImageFile(_filename);
167 globalTextures_.addManagedImageId(newImageId);
169 if ( newImageId == -1 ) {
170 emit log(
LOGERR,imageStore().error());
174 globalTextures_.
texture(_textureName).textureImageId(newImageId);
177 emit log(
LOGERR,
"slotTextureAdded: Trying to add already existing global texture " + _textureName );
182 QAction* new_texture =
new QAction(_textureName,
this);
183 new_texture->setStatusTip(tr(
"slotTextureAdded: Switch all objects to this Texture ( if available )"));
184 new_texture->setCheckable(
true);
185 actionGroup_->addAction(new_texture);
186 textureMenu_->addAction(new_texture);
187 new_texture->setChecked(
true);
188 textureActions_.push_back(new_texture);
192 void TextureControlPlugin::slotMultiTextureAdded( QString _textureGroup , QString _name , QString _filename , QImage _image ,
int _id ,
int& _textureId ) {
196 emit log(
LOGERR,
"slotMultiTextureAdded: Unable to get Object for id " + QString::number(_id) );
201 emit log(
LOGERR,
"slotMultiTextureAdded: Trying to add textures to object failed because of unsupported object type");
216 if(_filename.isEmpty())
217 slotTextureAdded( _name , _image , 2 , _id);
219 slotTextureAdded( _name , _filename , 2 , _id);
222 _textureId = texData->
texture(_name).id();
225 texData->
texture(_name).hidden(
true );
243 if ( _textureId != -1 ) {
246 emit log(
LOGERR,
"slotMultiTextureAdded: Error when getting internal id of new multitexture!");
251 void TextureControlPlugin::addedEmptyObject(
int _id ) {
262 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 265 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 268 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 284 for ( uint i = 0 ; i < globalTextures_.
textures().size() ; ++i) {
287 int newImageId = imageStore().addImageFile(globalTextures_.
textures()[i].filename());
288 texData->addManagedImageId(newImageId);
289 if ( newImageId == -1 ) {
290 emit log(
LOGERR,imageStore().error());
306 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 310 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 315 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 330 imageStore().removeImage(newImageId);
331 emit log(
LOGERR,
"addedEmptyObject: Unable to bind Texture");
350 template<
typename MeshT >
359 if ( _mesh->has_vertex_texcoords2D() ){
360 slotTextureAdded(
"Original Per Vertex Texture Coords",
"unknown.png",2,_objectId);
361 slotSetTextureMode(
"Original Per Vertex Texture Coords",
"type=vertexbased",_objectId);
364 if ( _mesh->has_halfedge_texcoords2D() ){
365 slotTextureAdded(
"Original Per Face Texture Coords",
"unknown.png",2,_objectId);
366 slotSetTextureMode(
"Original Per Face Texture Coords",
"type=halfedgebased",_objectId);
371 #if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT) 372 template<
typename VolumeMeshObjectT >
373 void TextureControlPlugin::handleFileOpenTexturesOVM( VolumeMeshObjectT* _obj,
int _objectId ) {
375 if ( _obj->texcoords().vertex_texcoords_available() ){
376 slotTextureAdded(
"Original Per Vertex Texture Coords",
"unknown.png",2,_objectId);
377 slotSetTextureMode(
"Original Per Vertex Texture Coords",
"type=vertexbased",_objectId);
383 void TextureControlPlugin::fileOpened(
int _id ) {
389 emit log(
LOGERR,
"fileOpened: Unable to get Object for id " + QString::number(_id) );
395 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 398 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 409 emit log(
LOGERR,tr(
"fileOpened: Unable to get texture object data for id %1.").arg(_id) );
423 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 426 handleFileOpenTexturesOVM(ovm_obj, _id);
429 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 432 handleFileOpenTexturesOVM(ovm_obj, _id);
438 void TextureControlPlugin::slotTextureChangeImage( QString _textureName , QImage& _image ,
int _id ) {
445 emit log(
LOGERR,
"slotTextureChangeImage: Unable to get Object for id " + QString::number(_id) );
453 if ( texData == 0 || ( !texData->
textureExists(_textureName)) ) {
454 emit log(
LOGERR,
"slotTextureChangeImage: Texture does not exist: " + _textureName +
" (objectid=" + QString::number(_id) +
")");
464 int newImageId = imageStore().addImage(_image);
467 texture.textureImageId(newImageId);
478 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 483 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 489 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 499 void TextureControlPlugin::slotTextureChangeImage( QString _textureName , QImage& _image ) {
505 emit log(
LOGERR,
"slotTextureChangeImage: Global texture does not exist: " + _textureName);
515 int newImageId = imageStore().addImage(_image);
518 texture.textureImageId(newImageId);
529 localTex.textureImageId(newImageId);
536 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 541 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 546 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 558 void TextureControlPlugin::slotTextureGetImage( QString _textureName, QImage& _image,
int _id ){
563 emit log(
LOGERR,
"slotTextureGetImage: Unable to get Object for id " + QString::number(_id) );
571 emit log(
LOGERR, tr(
"slotTextureGetImage: Object has no texture data! Object: %1").arg(_id) );
579 emit log(
LOGERR,
"slotTextureGetImage: Texture not available! " + _textureName );
583 if ( texData->
texture(_textureName).type() == MULTITEXTURE )
586 _image = imageStore().getImage(texData->
texture(_textureName).textureImageId(),0 );
590 void TextureControlPlugin::slotTextureGetImage( QString _textureName, QImage& _image ){
593 emit log(
LOGERR,
"slotTextureGetImage: Global texture does not exist: " + _textureName);
597 if ( globalTextures_.
texture(_textureName).type() == MULTITEXTURE )
600 _image = imageStore().getImage(globalTextures_.
texture(_textureName).textureImageId(),0);
603 void TextureControlPlugin::slotTextureIndex( QString _textureName,
int _id,
int& _index){
608 emit log(
LOGERR,
"slotTextureIndex: Unable to get Object for id " + QString::number(_id) );
616 emit log(
LOGERR, tr(
"slotTextureIndex: Object has no texture data! Object: %1").arg(_id) );
624 emit log(
LOGERR,
"slotTextureIndex: Texture not available! " + _textureName );
628 _index = texData->
texture(_textureName).id();
631 void TextureControlPlugin::slotTextureIndexPropertyName(
int _id, QString& _propertyName) {
636 emit log(
LOGERR,
"slotTextureIndexPropertyName: Unable to get Object for id " + QString::number(_id) );
646 emit log(
LOGERR,
"slotTextureIndexPropertyName: Unable to access mesh for object with id " + QString::number(_id) );
650 void TextureControlPlugin::slotTextureName(
int _id,
int _textureIndex, QString& _textureName){
655 emit log(
LOGERR,
"slotTextureName: Unable to get Object for id " + QString::number(_id) );
663 emit log(
LOGERR, tr(
"slotTextureName: Object has no texture data! Object: %1").arg(_id) );
667 for (uint i=0; i < texData->
textures().size(); i++ )
668 if ( (texData->
textures()[i]).
id() == _textureIndex ){
673 emit log(
LOGERR,
"slotTextureName: TextureIndex not available! (" + QString::number(_textureIndex) +
")" );
674 _textureName =
"NOT_FOUND";
678 void TextureControlPlugin::slotTextureFilename(
int _id, QString _textureName, QString& _textureFilename){
683 emit log(
LOGERR,
"slotTextureFilename: Unable to get Object for id " + QString::number(_id) );
691 emit log(
LOGERR, tr(
"slotTextureFilename: Object has no texture data! Object: %1").arg(_id) );
696 for (uint i=0; i < texData->
textures().size(); i++ ) {
697 for (
int j=0; j < texData->
textures()[i].multiTextureList.size(); j++ ) {
700 _textureFilename = tex.filename();
702 }
else if ( (texData->
textures()[i]).multiTextureList[j] == _textureName ){
704 _textureFilename = tex.filename();
710 _textureFilename = OpenFlipper::Options::textureDir().path() +
711 QDir::separator().toLatin1() + (globalTextures_.
texture(_textureName)).filename();
713 QFile f(_textureFilename);
714 if(!f.exists()) _textureFilename =
"NOT_FOUND";
719 void TextureControlPlugin::slotGetCurrentTexture(
int _id, QString& _textureName ){
721 _textureName =
"NONE";
726 emit log(
LOGERR,
"slotGetCurrentTexture: Unable to get Object for id " + QString::number(_id) );
737 QMap<QString, PerObjectData*>::const_iterator mapIter = obj->
getPerObjectDataMap().begin();
747 for ( uint i = 0 ; i < texData->
textures().size() ; ++i) {
749 if ( (texData->
textures()[i]).enabled() ){
752 if ( (texData->
textures()[i]).type() == MULTITEXTURE ) {
759 void TextureControlPlugin::slotGetSubTextures(
int _id, QString _multiTextureName, QStringList& _subTextures ){
763 emit log(
LOGERR,
"slotGetSubTextures: Unable to get Object for id " + QString::number(_id) );
771 emit log(
LOGERR, tr(
"slotGetSubTextures: Object has no texture data! Object: %1").arg(_id) );
779 emit log(
LOGERR,
"slotGetSubTextures: Texture not available! " + _multiTextureName );
783 if ( texData->
texture(_multiTextureName).type() == MULTITEXTURE )
786 _subTextures = QStringList();
789 void TextureControlPlugin::slotTextureUpdated( QString _textureName ,
int _identifier ){
796 emit log(
LOGERR,
"slotTextureUpdated: Unable to get Object for id " + QString::number(_identifier) );
802 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 805 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 808 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 819 emit log(
LOGERR,tr(
"slotTextureUpdated: Texture data not found: Object %1" ).arg(_identifier) );
827 emit log(
LOGERR,
"slotTextureUpdated: Texture " + _textureName +
" not found on object " + QString::number(_identifier) );
834 if ( ! texData->
texture(_textureName).enabled() ) {
835 texData->
texture(_textureName).setDirty();
857 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 861 doUpdateTextureOVM(texData->
texture(_textureName), *mesh, *meshObj);
868 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 872 doUpdateTextureOVM(texData->
texture(_textureName), *mesh, *meshObj);
879 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 892 texData->
texture(_textureName).clean();
901 void TextureControlPlugin::slotUpdateTexture( QString _textureName ,
int _identifier) {
902 if ( _textureName ==
"Reflection Lines" )
903 slotTextureUpdated( _textureName , _identifier );
907 template<
typename MeshT >
911 if ( _texture.type() == HALFEDGEBASED ) {
912 if (_texture.dimension() == 1) {
915 if ( ! _mesh.get_property_handle(texture, _texture.name().toStdString() ) ) {
916 emit log(
LOGERR,tr(
"doUpdateTexture: HALFEDGEBASED dimension 1: Unable to get property %1").arg(_texture.name()) );
922 }
else if ( _texture.dimension() == 2 ) {
925 if ( ! _mesh.get_property_handle( texture2D, _texture.name().toStdString() ) ) {
926 emit log(
LOGERR,tr(
"doUpdateTexture: HALFEDGEBASED dimension 2: Unable to get property %1").arg(_texture.name()) );
933 emit log(
LOGERR,
"doUpdateTexture: Unsupported Texture Dimension " + QString::number(_texture.dimension() ) );
934 }
else if ( _texture.type() == VERTEXBASED ) {
935 if ( _texture.dimension() == 1 ) {
938 if ( ! _mesh.get_property_handle(texture,_texture.name().toStdString() ) ) {
939 emit log(
LOGERR,tr(
"doUpdateTexture: VERTEXBASED dimension 1: Unable to get property %1").arg(_texture.name()) );
945 }
else if ( _texture.dimension() == 2 ) {
948 if ( ! _mesh.get_property_handle(texture2D,_texture.name().toStdString() ) ) {
949 emit log(
LOGERR,tr(
"doUpdateTexture: VERTEXBASED dimension 2: Unable to get property %1").arg(_texture.name()) );
966 emit log(
LOGERR,
"doUpdateTexture: Unsupported Texture Dimension " + QString::number(_texture.dimension() ) );
969 emit log(
LOGERR,
"doUpdateTexture: Unsupported Texture type");
974 #if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT) 975 template<
typename VolumeMeshT,
typename VolumeMeshObjectT >
976 void TextureControlPlugin::doUpdateTextureOVM (
Texture& _texture, VolumeMeshT& _mesh, VolumeMeshObjectT& _obj )
978 if ( _texture.type() == VERTEXBASED ) {
979 if ( _texture.dimension() == 1 ) {
981 if (!_mesh.template vertex_property_exists<double>(_texture.name().toStdString())){
982 emit log(
LOGERR,tr(
"doUpdateTexture: VERTEXBASED dimension 1: Unable to get property %1").arg(_texture.name()) );
990 _obj.setObjectDrawMode(drawModesVolumeMesh.facesTextured);
993 else if ( _texture.dimension() == 2 )
996 if (!_mesh.template vertex_property_exists<ACG::Vec2d>(_texture.name().toStdString())){
997 emit log(
LOGERR,tr(
"doUpdateTexture: VERTEXBASED dimension 2: Unable to get property %1").arg(_texture.name()) );
1004 _obj.setObjectDrawMode(drawModesVolumeMesh.facesTextured);
1008 emit log(
LOGERR,
"doUpdateTexture: Unsupported Texture Dimension " + QString::number(_texture.dimension() ) );
1011 emit log(
LOGERR,
"doUpdateTexture: Unsupported Texture type");
1016 void TextureControlPlugin::slotDrawModeChanged(
int _viewerId ) {
1018 #ifdef ENABLE_OPENVLUMEMESH_SUPPORT 1028 #ifdef ENABLE_OPENVLUMEMESH_SUPPORT
1049 for ( uint i = 0; i < texData->
textures().size(); ++i ) {
1050 if ( texData->
textures()[i].enabled() && texData->
textures()[i].dirty() ) {
1051 emit updateTexture( texData->
textures()[i].name() , o_it->id() );
1062 void TextureControlPlugin::slotObjectUpdated(
int _identifier,
const UpdateType& _type)
1070 if ( _identifier == -1 )
1079 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 1082 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 1085 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 1105 for ( uint i = 0; i < texData->
textures().size(); ++i ) {
1108 bool update =
false;
1115 #if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT) 1122 if ( update && texData->
textures()[i].enabled() )
1123 emit updateTexture( texData->
textures()[i].name() , _identifier );
1128 void TextureControlPlugin::slotUpdateAllTextures( ) {
1129 std::cerr <<
"slotUpdateAllTextures: not implemented yet ... might be removed" << std::endl;
1139 bool changed =
false;
1142 QString nextString = _mode.section(
',',i,i);
1143 while ( nextString !=
"" ) {
1144 QString sectionName = nextString.section(
'=',0,0);
1145 QString value = nextString.section(
'=',1,1);
1148 value = value.trimmed();
1149 sectionName = sectionName.trimmed();
1150 sectionName = sectionName.toLower();
1152 if ( sectionName ==
"clamp" ) {
1153 if ( StringToBool(value) != _texture.
parameters.clamp ) {
1154 _texture.
parameters.clamp = StringToBool(value);
1157 }
else if ( sectionName ==
"clamp_max" ) {
1158 if (value.toDouble() != _texture.
parameters.clampMax){
1159 _texture.
parameters.clampMax = value.toDouble();
1162 }
else if ( sectionName ==
"clamp_min" ) {
1163 if (value.toDouble() != _texture.
parameters.clampMin){
1164 _texture.
parameters.clampMin = value.toDouble();
1167 }
else if ( sectionName ==
"max_val" ) {
1168 if (value.toDouble() != _texture.
parameters.repeatMax){
1169 _texture.
parameters.repeatMax = value.toDouble();
1172 }
else if ( sectionName ==
"min_val" ) {
1173 if (value.toDouble() != _texture.
parameters.repeatMin){
1174 _texture.
parameters.repeatMin = value.toDouble();
1177 }
else if ( sectionName ==
"repeat" ) {
1178 if ( StringToBool(value) != _texture.
parameters.repeat ) {
1179 _texture.
parameters.repeat = StringToBool(value);
1182 }
else if ( sectionName ==
"center" ) {
1183 if ( StringToBool(value) != _texture.
parameters.center ) {
1184 _texture.
parameters.center = StringToBool(value);
1187 }
else if ( sectionName ==
"scale" ) {
1188 if ( StringToBool(value) != _texture.
parameters.scale ) {
1189 _texture.
parameters.scale = StringToBool(value);
1192 }
else if ( sectionName ==
"abs" ) {
1193 if ( StringToBool(value) != _texture.
parameters.abs ) {
1194 _texture.
parameters.abs = StringToBool(value);
1197 }
else if ( sectionName ==
"indexproperty" ) {
1198 if ( value != _texture.indexMappingProperty() ) {
1199 _texture.indexMappingProperty( value );
1202 }
else if ( sectionName ==
"visiblename" ) {
1203 if ( value != _texture.visibleName() ) {
1204 _texture.visibleName( value );
1207 }
else if ( sectionName ==
"type" ) {
1208 if ( ( value ==
"halfedgebased" ) && ( _texture.type() != HALFEDGEBASED ) ) {
1209 _texture.type( HALFEDGEBASED );
1211 }
else if ( (value ==
"vertexbased") && (_texture.type() != HALFEDGEBASED) ) {
1212 _texture.type( VERTEXBASED );
1214 }
else if ( (value ==
"environmentmap") && (_texture.type() != ENVIRONMENT) ) {
1215 _texture.type( ENVIRONMENT );
1218 emit log(
LOGERR,
"parseMode: Unknown texture type : " + value +
" for texture: " + _texture.name() );
1221 emit log(
LOGERR,
"parseMode: Unknown texture mode : " + sectionName);
1224 nextString = _mode.section(
',',i,i);
1230 void TextureControlPlugin::slotSetTextureMode(QString _textureName ,QString _mode) {
1236 emit log(
LOGERR,
"slotSetTextureMode: Global texture does not exist: " + _textureName);
1247 _mode = _mode.toLower();
1267 bool changed =
false;
1274 if ( _mode.contains(
"clamp_max") && (texture.
parameters.clampMax != localTex.
parameters.clampMax) ){
1279 if ( _mode.contains(
"clamp_min") && (texture.
parameters.clampMin != localTex.
parameters.clampMin) ){
1284 if ( _mode.contains(
"max_val") && (texture.
parameters.repeatMax != localTex.
parameters.repeatMax) ){
1289 if ( _mode.contains(
"min_val") && (texture.
parameters.repeatMin != localTex.
parameters.repeatMin) ){
1309 if ( _mode.contains(
"type") && (texture.type() != localTex.type() ) ){
1310 localTex.type( texture.type() );
1314 if ( _mode.contains(
"visiblename") && (texture.visibleName() != localTex.visibleName() ) ){
1315 localTex.visibleName( texture.visibleName() );
1322 emit updateTexture( _textureName, o_it->id() );
1324 localTex.setDirty();
1331 bool TextureControlPlugin::StringToBool(QString _value){
1332 if (_value ==
"false")
1338 void TextureControlPlugin::slotSetTextureMode(QString _textureName, QString _mode,
int _id) {
1343 emit log(
LOGERR,
"slotSetTextureMode: Unable to get Object for id " + QString::number(_id) );
1349 if ( texData == 0 || ( !texData->
textureExists(_textureName)) ) {
1350 emit log(
LOGERR,
"slotSetTextureMode: Texture does not exist: " + _textureName +
" (object=" + QString::number(_id) +
")");
1360 bool changed =
parseMode(_mode,texture);
1365 emit updateTexture( _textureName, _id );
1371 void TextureControlPlugin::pluginsInitialized() {
1375 textureMenu_ =
new QMenu(tr(
"&Texture Control"));
1376 textureMenu_->setTearOffEnabled(
true);
1377 emit addMenubarAction(textureMenu_->menuAction(),
VIEWMENU );
1384 connect( settingsDialog_, SIGNAL( applyProperties(
TextureData*,QString,
int) ),
1385 this, SLOT( applyDialogSettings(
TextureData*,QString,
int) ));
1387 connect( settingsDialog_, SIGNAL( getCoordinates1D(QString,
int,std::vector< double >&)),
1388 this, SLOT( getCoordinates1D(QString,
int,std::vector< double >&)));
1390 settingsDialog_->installEventFilter(
this );
1395 actionGroup_ =
new QActionGroup(
this);
1396 actionGroup_->setExclusive(
true );
1397 connect( actionGroup_, SIGNAL( triggered( QAction * ) ),
1400 QAction* AC_Texture_Settings =
new QAction(tr(
"&Texture Settings"),
this);
1401 AC_Texture_Settings->setStatusTip(tr(
"Set the texture visualization properties"));
1403 textureMenu_->addAction(AC_Texture_Settings);
1405 QAction *AC_Print_Pool_Info =
new QAction(tr(
"&Print Image Pool Info"),
this);
1406 AC_Print_Pool_Info->setStatusTip(tr(
"Print stats info of image pool"));
1408 textureMenu_->addAction(AC_Print_Pool_Info);
1410 textureMenu_->addSeparator();
1411 textureMenu_->addActions(actionGroup_->actions());
1421 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 1424 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 1428 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 1432 slotTextureAdded(
"Reflection Lines",
"reflection_map.png",2);
1433 slotSetTextureMode(
"Reflection Lines",
"type=environmentmap");
1438 settingsDialog_->show( &globalTextures_, -1);
1443 size_t sumRefCount=0;
1444 for(
auto it=imageStore().refCount().begin(),end=imageStore().refCount().end();it!=end;++it)
1446 sumRefCount+=it.value();
1449 size_t sumBytes = 0;
1450 for(
auto it=imageStore().imageMap().begin(),end=imageStore().imageMap().end();it!=end;++it)
1452 sumBytes+=it.value().sizeInBytes();
1454 QString poolInfo = tr(
"PoolInfo:[%1 images][%2 files][%3 refs][%4 KB]").arg(imageStore().imageMap().size())
1455 .arg(imageStore().filenameMap().size()).arg(sumRefCount).arg(sumBytes/1024);
1457 for(
auto it=imageStore().refCount().begin(),end=imageStore().refCount().end();it!=end;++it)
1459 emit log(
LOGSTATUS,tr(
"%1 %2").arg(imageStore().reverseFilenameMap()[it.key()]).arg(it.value()));
1466 void TextureControlPlugin::applyDialogSettings(
TextureData *_texData, QString _textureName,
int _id) {
1475 emit log(
LOGERR,
"applyDialogSettings: Unable to get Object for id " + QString::number(_id) );
1479 emit log(
LOGERR,
"applyDialogSettings: Texture does not exist in applyDialogSettings " + _textureName );
1489 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 1494 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 1500 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 1507 _texData->
texture( _textureName ).setDirty();
1511 for ( uint i=0; i < _texData->
textures().size(); i++ )
1512 if ( _texData->
textures()[i].enabled() ){
1513 doSwitchTexture( _texData->
textures()[i].name(), _id);
1524 _texData->
texture( _textureName ).setDirty();
1533 if ( texData != 0 && texData->
textureExists(_textureName) ){
1538 bool changed =
false;
1576 slotTextureUpdated( _textureName , o_it->id() );
1578 texData->
texture( _textureName ).setDirty();
1587 slotSwitchTexture( _action->text() );
1603 void TextureControlPlugin::doSwitchTexture( QString _textureName ,
int _id ) {
1608 emit log(
LOGERR,
"doSwitchTexture: Unable to get Object for id " + QString::number(_id) );
1620 emit log(
LOGERR, tr(
"doSwitchTexture: Object has no texture data! Object: %1").arg(_id) );
1628 emit log(
LOGERR,
"doSwitchTexture: Texture not available! " + _textureName );
1635 QStringList textureList;
1636 switch (texData->
texture(_textureName).type()) {
1645 for ( uint i = 0 ; i < texData->
textures().size() ; ++i ) {
1646 if ( textureList.contains( texData->
textures()[i].name() ) || (texData->
textures()[i].name() == _textureName) )
1659 emit log(
LOGERR,
"doSwitchTexture: Failed to enabled VERTEXBASED or HALFEDGEBASED Texture " + _textureName );
1662 if ( texData->
texture( _textureName).dirty() ) {
1664 emit updateTexture( texData->
texture( _textureName ).name() , obj->
id() );
1672 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 1676 doUpdateTextureOVM(texData->
texture(_textureName), *mesh, *meshObj);
1679 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 1683 doUpdateTextureOVM(texData->
texture(_textureName), *mesh, *meshObj);
1687 emit log(
LOGERR,
"doSwitchTexture: HALFEDGEBASED or VERTEXBASED type require poly or trimesh to work! Texture: " + _textureName );
1695 emit log(
LOGERR,
"doSwitchTexture: Failed to enabled ENVIRONMENT Texture " + _textureName );
1700 emit log(
LOGERR,
"doSwitchTexture. Texture Type is unset! This should never happen! " + _textureName );
1707 if ( texData->
texture(_textureName).type() == MULTITEXTURE ) {
1732 emit log(
LOGERR,
"doSwitchTexture: MultiTexture Error: Only supported on Tri or Poly Mesh for Texture: " + _textureName );
1742 if ( texData->
texture(_textureName).type() == HALFEDGEBASED ) {
1756 if ( texData->
texture(_textureName).type() == HALFEDGEBASED ) {
1764 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 1770 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 1776 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 1783 emit log(
LOGERR,
"doSwitchTexture: Texture Error ( mesh required) for Texture: " + _textureName );
1796 emit log(
LOGERR,
"doSwitchTexture: Unable to get Object for id " + QString::number(_id));
1811 emit log(
LOGERR,
"doSwitchTexture: Switching drawmode for unknonw Texture Type!");
1818 void TextureControlPlugin::slotSwitchTexture( QString _textureName ,
int _id ) {
1820 doSwitchTexture(_textureName, _id);
1823 void TextureControlPlugin::slotSwitchTexture( QString _textureName ) {
1829 doSwitchTexture(_textureName, o_it->id() );
1839 if ( _objectId == -1 )
1844 emit log(
LOGERR,
"slotUpdateContextMenu: Unable to get Object for id " + QString::number(_objectId) );
1850 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 1853 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 1856 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 1870 emit log(
LOGERR,tr(
"slotUpdateContextMenu: Texture data not found! Object %1 ").arg(_objectId) );
1878 QActionGroup* actionGroup =
new QActionGroup(
this);
1879 actionGroup->setExclusive(
true );
1880 connect( actionGroup, SIGNAL( triggered( QAction * ) ),
1883 QAction* action = actionGroup->addAction(
"Texture Settings" );
1888 for ( uint i = 0 ; i < texData->
textures().size() ; ++i ) {
1890 if ( texData->
textures()[i].hidden() )
1893 if ( !texData->
textures()[i].visibleName().isEmpty() )
1894 action = actionGroup->addAction( texData->
textures()[i].visibleName() );
1896 action = actionGroup->addAction( texData->
textures()[i].name() );
1898 action->setCheckable(
true);
1900 if ( texData->
textures()[i].enabled() )
1901 action->setChecked(
true);
1911 QVariant idVariant = _action->data( );
1912 int id = idVariant.toInt();
1917 emit log(
LOGERR,
"slotTextureContextMenu: Unable to get Object for id " + QString::number(
id) );
1924 if (_action->text() ==
"Texture Settings"){
1929 msgBox.setText(
"Cannot show Properties. No Textures available!");
1934 settingsDialog_->show( texData,
id, obj->
name() );
1939 if ( texData != 0) {
1940 slotSwitchTexture( _action->text() , id );
1950 void TextureControlPlugin::getCoordinates1D(QString _textureName,
int _id, std::vector< double >& _x ){
1955 emit log(
LOGERR,
"getCoordinates1D: Unable to get Object for id " + QString::number(_id) );
1963 emit log(
LOGERR,tr(
"getCoordinates1D: Object %1 has no texture data ").arg(_id) );
1971 emit log(
LOGERR,
"getCoordinates1D: Texture not available! " + _textureName );
1975 if ( texData->
texture( _textureName ).dirty() )
1976 emit updateTexture( _textureName , _id );
1986 if ( texData->
texture(_textureName).type() == VERTEXBASED )
1990 if ( !mesh->get_property_handle(coordProp, _textureName.toStdString() ) )
1992 emit log(
LOGERR,tr(
"getCoordinates1D: Texture Property not found: Object %1 , TextureName %2").arg(_id).arg(_textureName) );
1996 for ( TriMesh::VertexIter v_it = mesh->vertices_begin() ; v_it != mesh->vertices_end(); ++v_it)
1997 _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 ( TriMesh::HalfedgeIter h_it = mesh->halfedges_begin() ; h_it != mesh->halfedges_end(); ++h_it)
2011 _x.push_back( mesh->property(coordProp,*h_it) );
2019 if ( texData->
texture(_textureName).type() == VERTEXBASED )
2023 if ( !mesh->get_property_handle(coordProp, _textureName.toStdString() ) )
2025 emit log(
LOGERR,tr(
"getCoordinates1D: Texture Property not found: Object %1 , TextureName %2").arg(_id).arg(_textureName) );
2029 for ( PolyMesh::VertexIter v_it = mesh->vertices_begin() ; v_it != mesh->vertices_end(); ++v_it)
2030 _x.push_back( mesh->property(coordProp,*v_it) );
2032 else if ( texData->
texture(_textureName).type() == HALFEDGEBASED )
2036 if ( !mesh->get_property_handle(coordProp, _textureName.toStdString() ) )
2038 emit log(
LOGERR,tr(
"getCoordinates1D: Texture Property not found: Object %1 , TextureName %2").arg(_id).arg(_textureName) );
2042 for ( PolyMesh::HalfedgeIter h_it = mesh->halfedges_begin() ; h_it != mesh->halfedges_end(); ++h_it)
2043 _x.push_back( mesh->property(coordProp,*h_it) );
2046 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 2051 if ( texData->
texture(_textureName).type() == VERTEXBASED )
2053 if ( !mesh->vertex_property_exists<
double>(_textureName.toStdString()) )
2055 emit log(
LOGERR,tr(
"getCoordinates1D: Texture Property not found: Object %1 , TextureName %2").arg(_id).arg(_textureName) );
2062 _x.push_back( coordProp[*v_it] );
2066 emit log(
LOGERR,tr(
"getCoordinates1D: Only VERTEXBASED texture type supported for OpenVolumeMesh") );
2070 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 2075 if ( texData->
texture(_textureName).type() == VERTEXBASED )
2078 if ( !mesh->vertex_property_exists<
double>(_textureName.toStdString()) )
2080 emit log(
LOGERR,tr(
"getCoordinates1D: Texture Property not found: Object %1 , TextureName %2").arg(_id).arg(_textureName) );
2087 _x.push_back( coordProp[*v_it] );
2091 emit log(
LOGERR,tr(
"getCoordinates1D: Only VERTEXBASED texture type supported for OpenVolumeMesh") );
2098 void TextureControlPlugin::slotAboutToRestore(
int _objectid ) {
2105 emit log(
LOGERR,
"slotAboutToRestore: Unable to get Object for id " + QString::number(_objectid) );
2129 void TextureControlPlugin::slotRestored(
int _objectid ) {
2133 QString currentTexture;
2134 slotGetCurrentTexture(_objectid,currentTexture);
2139 slotSwitchTexture(currentTexture,_objectid);
bool parseMode(QString _mode, Texture &_texture)
parse texture mode settings Parses the string _mode and changes the settings in _texture according to...
DrawMode SOLID_2DTEXTURED_FACE
draw per halfedge textured faces
BSplineSurfaceObject * bsplineSurfaceObject(BaseObjectData *_object)
Cast an BaseObject to a BSplineSurfaceObject if possible.
void disableTexture(QString _textureName)
Disable a given texture.
const UpdateType UPDATE_TOPOLOGY(UpdateTypeSet(8))
Topology updated.
#define DATA_POLYHEDRAL_MESH
#define DATA_TRIANGLE_MESH
bool enableTexture(QString _textureName, bool _exclusive=false)
Enable a given texture.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void setObjectData(QString _dataName, PerObjectData *_data)
PolyhedralMeshObject * polyhedralMeshObject(BaseObjectData *_object)
Cast an BaseObject to an PolyhedralMeshObject if possible.
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
DrawMode SOLID_ENV_MAPPED
draw environment mapped
void slotUpdateContextMenu(int _objectId)
Slot from the context menu interface.
bool textureExists(QString _textureName)
Check if a texture exists.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
ACG::SceneGraph::TextureNode * textureNode()
Return pointer to the texture node.
HexahedralMesh * hexahedralMesh(BaseObjectData *_object)
Get an HexahedralMesh from an object.
#define DATA_HEXAHEDRAL_MESH
ACG::SceneGraph::DrawModes::DrawMode drawMode(int _viewer)
Get the current draw Mode of a Viewer.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
DrawMode SOLID_2DTEXTURED_FACE_SHADED
draw per halfedge textured faces
const QStringList ALL_OBJECTS
Iterable object range.
This class provides easy access to DrawModes supported by OpenVolumeMesh.
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...
QMap< QString, PerObjectData * > & getPerObjectDataMap()
get reference to map of all perObject Datas
const UpdateType UPDATE_TEXTURE(UpdateTypeSet(2048))
Textures have changed.
void setHalfedgeTextcoordPropertyName(std::string _halfedgeTextcoordPropertyName)
Set the name of the per face texture coordinate property.
MeshT * mesh()
return a pointer to the mesh
const std::string & indexPropertyName() const
Get current texture index property name.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(4))
Geometry updated.
void setIndexPropertyName(std::string _indexPropertyName)
set the name of the property used for texture index specification
bool dataType(DataType _type) const
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
#define DATA_BSPLINE_SURFACE
void doUpdateTexture(Texture &_texture, MeshT &_mesh)
Calls the correct copyTexture() function to copy the texture property into the displayed OM property...
int viewers()
Get the number of viewers.
void setObjectDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, const bool &_force=false)
Set the draw mode for the object.
QMenu * contextMenu_
Stores the per object context menu.
DrawMode SOLID_TEXTURED
draw textured faces
QString name() const
return the name of the object. The name defaults to NONAME if unset.
PolyMeshObject * polyMeshObject(BaseObjectData *_object)
Cast an BaseObject to a PolyMeshObject if possible.
std::map< int, GLuint > * textureMap()
Get pointer to the textureMap.
QStringList multiTextureList
If this is a multiTexture, the list will contain all textures for this multi Texture node...
ACG::SceneGraph::EnvMapNode * textureNode()
Get the TextureNode (actually its an environment map node) of the bspline surface.
TriMeshObject * triMeshObject(BaseObjectData *_object)
Cast an BaseObject to a TriMeshObject if possible.
bool activateTexture(GLuint _id)
Set active Texture.
void slotPrintImagePoolInfo()
Print Pool Info.
void slotSetTextureProperties()
Slot for showing the TextureProperties Dialog.
std::vector< Texture > & textures()
Get reference to the texture vector.
TextureControlPlugin()
Constructor.
void set_texture(const QImage &_image)
Uses a QImage to set the texture.
int addTexture(QString _textureName, uint _dimension, GLuint _glName)
Add a Texture without file backing.
ACG::SceneGraph::MeshNodeT< MeshT > * meshNode()
Get the Scenegraph Mesh Node.
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
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...
void switchDrawMode(TextureType _type, int _id)
Checks for a correct drawmode and changes if necessary.
bool addMultiTexture(QString _textureName)
Adds a new multiTexture ( This texture will only contain a list of enabled textures for multitexturin...
void handleFileOpenTextures(MeshT *&_mesh, int _objectId)
Handles data stored in new opened files ( e.g. Texture Information )
ACG::SceneGraph::EnvMapNode * textureNode()
Get the TextureNode of the current mesh.
PerObjectData * objectData(QString _dataName)
Returns the object data pointer.
PolyhedralMesh * polyhedralMesh(BaseObjectData *_object)
Get an PolyhedralMesh from an object.
void slotTextureMenu(QAction *_action)
Called when an action in the TextureMenu is triggered.
TexParameters parameters
Parameters of the texture.
HexahedralMeshObject * hexahedralMeshObject(BaseObjectData *_object)
Cast an BaseObject to an HexahedralMeshObject if possible.
QString name()
Return a name for the plugin.
DrawMode SOLID_TEXTURED_SHADED
draw smooth shaded textured faces
void slotTextureContextMenu(QAction *_action)
Called when the context menu has been triggered.
bool isEnabled(QString _textureName)
Check if a texture is enabled.
Texture & texture(QString _textureName)
Get the texture object.
GLuint add_texture(const QImage &_image)
Add a texture to this node.
DLLEXPORT DataType typeId(QString _name)
Given a dataType Identifier string this function will return the id of the datatype.
bool setImage(QString _textureName, int _id)
Stores the given image in the texture information.
void set_repeat(bool _status)
set texture repeat status