Commit 9caba41f authored by Jan Möbius's avatar Jan Möbius
Browse files

Merge branch 'track_image_usage' into 'master'

keep tracking image usage for drawing(do not tracking usage

See merge request !4
parents c0787ef8 7ab5c068
......@@ -118,6 +118,10 @@ QwtFunctionPlot::QwtFunctionPlot(QWidget* _parent) :
image_ = 0;
}
QwtFunctionPlot::~QwtFunctionPlot()
{
delete histogram_;
}
//------------------------------------------------------------------------------
void QwtFunctionPlot::setFunction( std::vector<double>& _values)
......
......@@ -105,7 +105,7 @@ public:
explicit QwtFunctionPlot( QWidget* _parent = 0 );
/// Destructor
~QwtFunctionPlot() {}
~QwtFunctionPlot();
// set the function to plot
void setFunction( std::vector<double>& _values );
......
......@@ -426,8 +426,9 @@ void texturePropertiesWidget::slotButtonBoxClicked(QAbstractButton* _button){
texture.filename( currentImage_ );
// Add it to the imagestore and set the index in the texture description
texture.textureImageId( imageStore().addImageFile(currentImage_) );
int newImageId = imageStore().addImageFile(currentImage_);
texture.textureImageId( newImageId );
texData_->addManagedImageId( newImageId );
changed = true;
}
......
......@@ -66,6 +66,11 @@ class ImageStore {
void removeImage(int _id);
inline const QMap<int,QImage>& imageMap() const{return imageMap_;}
inline const QMap< QString,QPair<int,QDateTime> >& filenameMap() const {return filenameMap_;}
inline const QMap<int,QString>& reverseFilenameMap() const {return reverseFilenameMap_;}
inline const QMap<int,unsigned int>& refCount() const {return refCount_;}
private:
QMap<int,QImage> imageMap_;
QMap< QString,QPair<int,QDateTime> > filenameMap_;
......
......@@ -96,6 +96,7 @@ void TextureControlPlugin::slotTextureAdded(QString _textureName , QString _file
newId = imageStore().addImage(_image);
else
newId = imageStore().addImageFile(_fileName);
texData->addManagedImageId(newId);
if ( newId == -1 ) {
emit log(LOGERR,imageStore().error());
......@@ -163,6 +164,7 @@ void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _fil
newImageId = imageStore().addImage(_image);
else
newImageId = imageStore().addImageFile(_filename);
globalTextures_.addManagedImageId(newImageId);
if ( newImageId == -1 ) {
emit log(LOGERR,imageStore().error());
......@@ -221,21 +223,21 @@ void TextureControlPlugin::slotMultiTextureAdded( QString _textureGroup , QStrin
//hide the texture (its accessible through the multiTexture)
texData->texture(_name).hidden( true );
// Add to image store
int newImageId;
if(_filename.isEmpty())
newImageId = imageStore().addImage(_image);
else
newImageId = imageStore().addImageFile(_filename);
if ( newImageId == -1 ) {
emit log(LOGERR,imageStore().error());
return;
}
// Add to texture description
texData->texture(_name).textureImageId(newImageId);
//
// // Add to image store
// int newImageId;
// if(_filename.isEmpty())
// newImageId = imageStore().addImage(_image);
// else
// newImageId = imageStore().addImageFile(_filename);
//
// if ( newImageId == -1 ) {
// emit log(LOGERR,imageStore().error());
// return;
// }
//
// // Add to texture description
// texData->texture(_name).textureImageId(newImageId);
// Store the new texture in the list of this textureGroup
if ( _textureId != -1 ) {
......@@ -283,7 +285,7 @@ void TextureControlPlugin::addedEmptyObject( int _id ) {
// Add to image store
int newImageId = imageStore().addImageFile(globalTextures_.textures()[i].filename());
texData->addManagedImageId(newImageId);
if ( newImageId == -1 ) {
emit log(LOGERR,imageStore().error());
continue;
......@@ -1390,7 +1392,7 @@ void TextureControlPlugin::pluginsInitialized() {
// ================================================================================
// Create action group and menu for global textures
// ================================================================================
actionGroup_ = new QActionGroup( 0 );
actionGroup_ = new QActionGroup(this);
actionGroup_->setExclusive( true );
connect( actionGroup_, SIGNAL( triggered( QAction * ) ),
this, SLOT( slotTextureMenu( QAction * ) ) );
......@@ -1400,6 +1402,11 @@ void TextureControlPlugin::pluginsInitialized() {
connect(AC_Texture_Settings, SIGNAL(triggered()), this, SLOT(slotSetTextureProperties()));
textureMenu_->addAction(AC_Texture_Settings);
QAction *AC_Print_Pool_Info = new QAction(tr("&Print Image Pool Info"), this);
AC_Print_Pool_Info->setStatusTip(tr("Print stats info of image pool"));
connect(AC_Print_Pool_Info, SIGNAL(triggered()), this, SLOT(slotPrintImagePoolInfo()));
textureMenu_->addAction(AC_Print_Pool_Info);
textureMenu_->addSeparator();
textureMenu_->addActions(actionGroup_->actions());
......@@ -1431,7 +1438,32 @@ void TextureControlPlugin::slotSetTextureProperties() {
settingsDialog_->show( &globalTextures_, -1);
}
void TextureControlPlugin::applyDialogSettings(TextureData* _texData, QString _textureName, int _id) {
void TextureControlPlugin::slotPrintImagePoolInfo() {
size_t sumRefCount=0;
for(auto it=imageStore().refCount().begin(),end=imageStore().refCount().end();it!=end;++it)
{
sumRefCount+=it.value();
}
size_t sumBytes = 0;
for(auto it=imageStore().imageMap().begin(),end=imageStore().imageMap().end();it!=end;++it)
{
sumBytes+=it.value().byteCount();
}
QString poolInfo = tr("PoolInfo:[%1 images][%2 files][%3 refs][%4 KB]").arg(imageStore().imageMap().size())
.arg(imageStore().filenameMap().size()).arg(sumRefCount).arg(sumBytes/1024);
for(auto it=imageStore().refCount().begin(),end=imageStore().refCount().end();it!=end;++it)
{
emit log(LOGSTATUS,tr("%1 %2").arg(imageStore().reverseFilenameMap()[it.key()]).arg(it.value()));
}
emit log(LOGINFO, poolInfo);
}
void TextureControlPlugin::applyDialogSettings(TextureData *_texData, QString _textureName, int _id) {
if (_id != -1)
{
......@@ -1843,7 +1875,7 @@ void TextureControlPlugin::slotUpdateContextMenu( int _objectId ) {
// Prepare Texture menu
// ================================================================================
contextMenu_->clear();
QActionGroup* actionGroup = new QActionGroup(0);
QActionGroup* actionGroup = new QActionGroup(this);
actionGroup->setExclusive( true );
connect( actionGroup, SIGNAL( triggered( QAction * ) ),
this, SLOT( slotTextureContextMenu( QAction * ) ) );
......
......@@ -163,6 +163,9 @@ class TextureControlPlugin : public QObject, BaseInterface, BackupInterface, Tex
/// Slot for showing the TextureProperties Dialog
void slotSetTextureProperties();
/// Print Pool Info
void slotPrintImagePoolInfo();
public :
/// Constructor
TextureControlPlugin();
......
......@@ -42,6 +42,7 @@
#include "TextureData.hh"
#include "ImageStorage.hh"
#include <iostream>
//-----------------------------------------------------------------------------------
......@@ -74,7 +75,10 @@ TextureData::TextureData() :
//-----------------------------------------------------------------------------------
TextureData::~TextureData() {
for(const int& id:managedImageId_)
{
imageStore().removeImage(id);
}
}
//-----------------------------------------------------------------------------------
......@@ -331,3 +335,6 @@ std::map< int, std::string>* TextureData::propertyMap(){
return &propertyMap_;
}
void TextureData::addManagedImageId(int _imageId){
managedImageId_.push_back(_imageId);
}
\ No newline at end of file
......@@ -52,9 +52,9 @@
#include <ACG/GL/gl.hh>
#include <vector>
#include <map>
#include <set>
#include <cfloat>
enum TextureType { UNSET = 1 << 0,
/// Texture Coordinates are stored on a per Vertex basis
VERTEXBASED = 1 << 1,
......@@ -265,8 +265,9 @@ class TextureData : public PerObjectData
*/
std::map< int, std::string >* propertyMap();
void addManagedImageId(int _imageId);
private :
std::vector<int> managedImageId_;
std::map< int, GLuint> textureMap_;
std::map< int, std::string> propertyMap_;
......
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