VAPOR3 3.9.4
ModelRenderer.h
Go to the documentation of this file.
1//************************************************************************
2// *
3// Copyright (C) 2018 *
4// University Corporation for Atmospheric Research *
5// All Rights Reserved *
6// *
7//************************************************************************/
8//
9// File: ModelRenderer.cpp
10//
11// Author: Stas Jaroszynski
12// National Center for Atmospheric Research
13// PO 3000, Boulder, Colorado
14//
15// Date: March 2018
16//
17// Description:
18// Definition of ModelRenderer
19//
20#pragma once
21
22#include <vapor/glutil.h>
23
24#include <vapor/Renderer.h>
25#include <vapor/ModelParams.h>
26
27#include <glm/glm.hpp>
28
29#include <assimp/Importer.hpp>
30#include <assimp/scene.h>
31
32#include <memory>
33#include <string>
34
35namespace VAPoR {
36
37class DataMgr;
38
45public:
46 ModelRenderer(const ParamsMgr *pm, string winName, string dataSetName, string instName, DataMgr *dataMgr);
47
48 static string GetClassType() { return ("Model"); }
49
51 virtual int _initializeGL();
53 virtual int _paintGL(bool fast);
54 virtual void _clearCache() {}
55
56private:
57 class Model {
58 Assimp::Importer _importer;
59 const aiScene * _scene;
60 glm::vec3 _min, _max;
61
62 void renderNode(GLManager *gl, const aiNode *nd) const;
63 void calculateBounds(const aiNode *nd, glm::mat4 transform = glm::mat4(1.0f));
64 glm::mat4 getMatrix(const aiNode *nd) const;
65
66 public:
67 void Render(GLManager *gl) const;
68 void DrawBoundingBox(GLManager *gl) const;
69 int Load(const std::string &path);
70 glm::vec3 BoundsMin() const { return _min; }
71 glm::vec3 BoundsMax() const { return _max; }
72 glm::vec3 Center() const { return (_min + _max) / 2.f; }
73 };
74
75 class Scene {
76 struct ModelInstance {
77 std::string name;
78 std::string file;
79 glm::vec3 translate = glm::vec3(0.f);
80 glm::vec3 rotate = glm::vec3(0.f);
81 glm::vec3 scale = glm::vec3(1.f);
82 glm::vec3 origin = glm::vec3(0.f);
83 };
84
85 std::vector<ModelInstance> _instances;
86 std::map<int, std::vector<ModelInstance>> _keyframes;
87 std::map<std::string, Model *> _models;
88
89 public:
90 ~Scene();
91 int Load(const std::string &path);
92 void Render(GLManager *gl, const int ts = 0);
93 glm::vec3 Center() const;
94
95 private:
96 std::vector<ModelInstance> getInstances(const int ts) const;
97 int createSceneFromModelFile(const std::string &path);
98 int loadSceneFile(const std::string &path);
99 int handleInstanceNode(XmlNode *node, ModelInstance *instance);
100 int handleTimeNode(XmlNode *node);
101 int handleVectorNode(XmlNode *node, glm::vec3 *v);
102 int handleFloatAttribute(XmlNode *node, const std::string &name, float *f);
103 int parseIntString(const std::string &str, int *i) const;
104 ModelInstance getInitInstance(const std::string &name) const;
105 bool doesInstanceExist(const std::string &name) const;
106 bool isModelCached(const std::string &file) const;
107 };
108
109 Scene _scene;
110 std::string _cachedFile;
111
112 void _renderNode(const aiNode *node);
113};
114
115}; // namespace VAPoR
A cache based data reader.
Definition: DataMgr.h:110
Class that draws the contours (contours) as specified by IsolineParams.
Definition: ModelRenderer.h:44
virtual int _paintGL(bool fast)
All OpenGL rendering is performed in the pure virtual paintGL method.
static string GetClassType()
Definition: ModelRenderer.h:48
ModelRenderer(const ParamsMgr *pm, string winName, string dataSetName, string instName, DataMgr *dataMgr)
virtual int _initializeGL()
virtual void _clearCache()
Definition: ModelRenderer.h:54
A singleton class for managing Params instances.
Definition: ParamsMgr.h:53
A class that performs rendering in a Visualizer.
Definition: Renderer.h:121
#define RENDER_API
Definition: common.h:78
Contains references to context scope OpenGL data.
Definition: GLManager.h:18