Diverse visualization techniques and applications

This is my first SO question, so please bear with me.

We are developing an application that collects data and we have methods that allow us to visualize data in different ways. With the increasing number of methods, we decided to separate the application and rendering methods. I am wondering what is the best way to do this. I came up with the following code that somewhat tries to separate the two, but still ...

Is there a better way to do this?

// forward declaration
class App;

// Interface to all visualization methods
struct Methods {
    virtual void show(App * a) = 0;
};

// Some visualization method
struct Method0 : public Methods {
    void show(App * a) {
        a->getData();
    }
};

class App {
public:
    vector<Methods *> methods;

    void run() {
        // draw all registered methods
        for (auto m : methods)
            m->show(this);
    }

    int getData() {
        // parse and precompute data (time-consuming, thus do it only once)
        // return the required data (not just an int..)
        return 42;
    }
};

void main() {
    App a;

    // register some methods
    a.methods.push_back(new Method0());

    // run the application
    a.run();

    // clean up
    for (auto m : a.methods) delete(m);
}

      

EDIT

I think Alexander and Peter pointed me in the right direction, thanks. I will follow Peter's suggestion and try to separate the data from another class.

Referring to comment from Spektre:

  • Designed on Windows (MSVC), otherwise platform independent.
  • The visualization is mostly static and changes based on user input. I think 10 updates per second is the upper bound for the refresh rate.
  • What do you mean by data transfer time?
  • Memory is not a problem.

The data is a bunch of feature vectors containing other feature vectors, 5 dimensions in total.

One visualization is like a ROC curve containing multiple curves, so we need to go through part / all of the measurements and calculate some statistics. The result is shown in the following figure. visualization example

+3


source to share


2 answers


In addition to Alexander's answer, I mentioned that you didn't actually completely separate data and visualization. The class Application

still knows about both the internal data structure and the vector of rendering methods. What you are better off doing is to have a separate class, say Data

, will do all the calculations you need, and then have a main class (for example App

) that will only handle registering methods and passing data to them.

Something like



class Data;

struct Methods {
    virtual void show(Data * a) = 0;
};

struct Method0 : public Methods {
    void show(Data * d) {
        d->getData();
    }
};

class Data {
    public:
    int getData() {
        // parse and precompute data (time-consuming, thus do it only once)
        // return the required data (not just an int..)
        return 42;
    }
}

class App {
public:
    vector<Methods *> methods;
    Data* data;

    void run() {
        // draw all registered methods
        for (auto m : methods)
            m->show(data);
    }

};

      

+1


source


What you have there already looks good. As you probably already guessed, you are not the first person to have this problem. The standard solution for separating your data from your visualization is known as the Model Control Controller Pattern (MVC) , which not only separates the view of your data from the data itself, but also makes it easy to manipulate data from the display.



If you just want to display your data, you might need to look at the observer template . Again, what you have is pretty close to this pattern already.

+2


source







All Articles