错误C2227:' - > width'的左边必须指向class / struct / union / generic类型,光线投射渲染

时间:2016-12-06 16:57:00

标签: c++ raycasting

我遇到错误C2227,这是我的代码

我不知道如何从MyWindow访问volume-> voxel-> width,我必须得到一个体积数据的宽度。

我已经编辑了一篇文章。我在Volume类型中创建了一个指针,但它也没有用。

MyWindow.cpp

  #include "MainWindow.h"

#include <QFileDialog>

#include <QPainter>
#include "Volume.h"


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), m_Volume(0), m_VectorField(0)
{
    m_Ui = new Ui_MainWindow();
    m_Ui->setupUi(this);

    connect(m_Ui->actionOpen, SIGNAL(triggered()), this, SLOT(openFileAction()));
    connect(m_Ui->actionClose, SIGNAL(triggered()), this, SLOT(closeAction()));






    float width = m_Ui->label->width();
    float height = m_Ui->label->height();




 (float i = 0; i < m_Volume->voxel->width; i++) // HERE IS ERROR
    {
        m_Ui->label->width();
    }

    QPixmap map(width, height);
    map.fill(QColor(255, 0, 0, 0));








}

volume.h

// Voxel
//-------------------------------------------------------------------------------------------------

class Voxel
{
    public:

        Voxel();
        Voxel(const Voxel &other);
        Voxel(const float value);

        ~Voxel();


        // VOXEL VALUE

        void                    setValue(const float value);
        const float             getValue() const;


        // OPERATORS

        const bool              operator==(const Voxel &other) const;
        const bool              operator!=(const Voxel &other) const;
        const bool              operator>(const Voxel &other) const;
        const bool              operator>=(const Voxel &other) const;
        const bool              operator<(const Voxel &other) const;
        const bool              operator<=(const Voxel &other) const;

        const Voxel             operator+(const Voxel &other) const;
        const Voxel             operator-(const Voxel &other) const;
        const Voxel             operator*(const float &value) const;
        const Voxel             operator/(const float &value) const;

        const Voxel&            operator+=(const Voxel &other);
        const Voxel&            operator-=(const Voxel &other);
        const Voxel&            operator*=(const float &value);
        const Voxel&            operator/=(const float &value);


    private:

        float                   m_Value;

};


//-------------------------------------------------------------------------------------------------
// Volume
//-------------------------------------------------------------------------------------------------

class Volume
{

    public:

        Volume();
        ~Volume();


        // VOLUME DATA

        const Voxel&            voxel(const int i) const;
        const Voxel&            voxel(const int x, const int y, const int z) const;
        const Voxel*            voxels() const;

        const int               width() const;
        const int               height() const;
        const int               depth() const;

        const int               size() const;

        bool                    loadFromFile(QString filename, QProgressBar* progressBar);


    private:

        std::vector<Voxel>      m_Voxels;

        int                     m_Width;
        int                     m_Height;
        int                     m_Depth;

        int                     m_Size;

};

1 个答案:

答案 0 :(得分:-1)

m_Ui->label->width();

我正在获得labe的宽度,用于映射。

我是用Mainwindow :: MainWindow()

完成的

但我也有错误。

void MainWindow::paintEvent(QPaintEvent *)
{
    QPainter painter(this);

    float width = m_Ui->label->width();
    float height = m_Ui->label->height();


    QPixmap map(width, height);
    map.fill(QColor(255, 0, 0, 0));





    for (int i = 0; i < m_Volume->width(); i++)
    {
        for (int j = 0; i < m_Volume->height(); j++)
        {
            for (int k = 0; i < m_Volume->depth(); k++)
            {
                m_Ui->label->setPixmap(map);
            }
        }
    }


}