COPASI API  4.16.103
Public Member Functions | Protected Member Functions | List of all members
CQQtImageTexturizer Class Reference

#include <CQQtImageTexturizer.h>

Inheritance diagram for CQQtImageTexturizer:
Inheritance graph
[legend]
Collaboration diagram for CQQtImageTexturizer:
Collaboration graph
[legend]

Public Member Functions

virtual CLTextureSpecoperator() (const std::string &filename, const std::string &basedir)
 

Protected Member Functions

CLTextureSpeccreate_texture_for_image (const std::string &filename, const char *format=NULL)
 

Additional Inherited Members

- Static Protected Member Functions inherited from CLImageTexturizer
static std::string to_absolute_path (const std::string &filename, const std::string &basedir)
 

Detailed Description

Definition at line 23 of file CQQtImageTexturizer.h.

Member Function Documentation

CLTextureSpec * CQQtImageTexturizer::create_texture_for_image ( const std::string &  filename,
const char *  format = NULL 
)
protected

Definition at line 60 of file CQQtImageTexturizer.cpp.

References CCopasiMessage::ERROR, FROM_UTF8, GL_CLAMP_TO_EDGE, MCLayout, CLTextureSpec::mNumComponents, CLTextureSpec::mTextHeight, CLTextureSpec::mTextureHeight, CLTextureSpec::mTextureName, CLTextureSpec::mTextureWidth, CLTextureSpec::mTextWidth, and pResult.

Referenced by operator()().

61 {
62  CLTextureSpec* pResult = NULL;
63  // use UTF8 strings for filenames since this seems to be safer across platforms
64  QImage image(FROM_UTF8(filename), format);
65 
66  if (!image.isNull())
67  {
68  image = image.mirrored();
69  QImage glImage = QGLWidget::convertToGLFormat(image);
70  pResult = new CLTextureSpec;
71  pResult->mTextureWidth = pResult->mTextWidth = glImage.width();
72  pResult->mTextureHeight = pResult->mTextHeight = glImage.height();
73  pResult->mNumComponents = 4;
74  glGenTextures(1, &pResult->mTextureName);
75  assert(pResult->mTextureName != 0);
76  glBindTexture(GL_TEXTURE_2D, pResult->mTextureName);
77  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
78  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
79  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
80  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
81  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
82  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)pResult->mTextureWidth, (GLsizei)pResult->mTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, glImage.bits());
83  }
84  else
85  {
86  CCopasiMessage(CCopasiMessage::ERROR, MCLayout + 1, filename.c_str());
87  }
88 
89  return pResult;
90 }
#define MCLayout
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
#define GL_CLAMP_TO_EDGE
Definition: glext.h:95
double mTextureWidth
const CArrayAnnotation * pResult
double mTextureHeight
unsigned int mNumComponents
CLTextureSpec * CQQtImageTexturizer::operator() ( const std::string &  filename,
const std::string &  basedir 
)
virtual

Implements CLImageTexturizer.

Definition at line 30 of file CQQtImageTexturizer.cpp.

References create_texture_for_image(), CLImageTexturizer::to_absolute_path(), and transform().

31 {
32  std::string reference = to_absolute_path(filename, basedir);
33  CLTextureSpec* pTexture = NULL;
34  // test if the filename ends in "JPG","JPEG","jpeg" or "jpg"
35  std::string::size_type pos = reference.rfind(".");
36  std::string ending;
37 
38  if (pos != std::string::npos)
39  {
40  ++pos;
41  ending = reference.substr(pos);
42  std::transform(ending.begin(), ending.end(), ending.begin(), &tolower);
43  }
44 
45  if (!ending.empty())
46  {
47  if (ending == "jpeg" || ending == "jpg")
48  {
49  pTexture = create_texture_for_image(reference/*,"JPG"*/);
50  }
51  else if (ending == "png")
52  {
53  pTexture = create_texture_for_image(reference/*,"PNG"*/);
54  }
55  }
56 
57  return pTexture;
58 }
static std::string to_absolute_path(const std::string &filename, const std::string &basedir)
void transform(QGraphicsItem *item, const CLTransformation2D *trans, const CLGroup *group)
CLTextureSpec * create_texture_for_image(const std::string &filename, const char *format=NULL)

The documentation for this class was generated from the following files: