1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
#pragma once
#include <QString>
#include <QMap>
#include <QSet>
#include <QStringList>
#include <QFile>
#include <QDomDocument>
#include "Renderer.h"
#include "../../../SyntopiaCore/Math/Vector3.h"
namespace StructureSynth {
namespace Model {
namespace Rendering {
using namespace SyntopiaCore::Math;
/// A TemplatePrimitive is the definition for a single primitive (like Box or Sphere).
/// It is a simple text string with placeholders for stuff like coordinates and color.
class TemplatePrimitive {
public:
TemplatePrimitive() {};
TemplatePrimitive(QString def) : def(def) {};
TemplatePrimitive(const TemplatePrimitive& t) { this->def = t.def; };
QString getText() { return def; }
void substitute(QString before, QString after) {
def.replace(before, after);
};
bool contains(QString input) {
return def.contains(input);
};
private:
QString def;
};
// A Template contains a number of TemplatePrimitives:
// text definitions for each of the standard primitives (box, sphere, ...) with placeholders
// for stuff like coordinates and color.
class Template {
public:
Template() {};
Template(QFile& file) { read(file); }
Template(QString xmlString) { read(xmlString); }
void read(QFile& file);
void read(QString xmlString);
void parse(QDomDocument& doc);
QMap<QString, TemplatePrimitive>& getPrimitives() { return primitives; }
TemplatePrimitive get(QString name) { return primitives[name]; }
QString getDescription() { return description; }
QString getFullText() { return fullText; }
QString getName() { return name; }
QString getDefaultExtension() { return defaultExtension; }
QString getRunAfter() { return runAfter; }
private:
QMap<QString, TemplatePrimitive> primitives;
QString description;
QString name;
QString defaultExtension;
QString fullText;
QString runAfter;
};
/// A renderer implementation based on the SyntopiaCore POV widget.
class TemplateRenderer : public Renderer {
public:
TemplateRenderer();
TemplateRenderer(QString xmlDefinitionFile);
TemplateRenderer(Template myTemplate);
virtual ~TemplateRenderer();
virtual QString renderClass() { return "template"; }
/// The primitives
virtual void drawBox(SyntopiaCore::Math::Vector3f base,
SyntopiaCore::Math::Vector3f dir1 ,
SyntopiaCore::Math::Vector3f dir2,
SyntopiaCore::Math::Vector3f dir3,
const QString& classID);
virtual void drawSphere(SyntopiaCore::Math::Vector3f center, float radius,
const QString& classID);
virtual void drawMesh( SyntopiaCore::Math::Vector3f startBase,
SyntopiaCore::Math::Vector3f startDir1,
SyntopiaCore::Math::Vector3f startDir2,
SyntopiaCore::Math::Vector3f endBase,
SyntopiaCore::Math::Vector3f endDir1,
SyntopiaCore::Math::Vector3f endDir2,
const QString& classID);
virtual void drawGrid(SyntopiaCore::Math::Vector3f base,
SyntopiaCore::Math::Vector3f dir1,
SyntopiaCore::Math::Vector3f dir2,
SyntopiaCore::Math::Vector3f dir3,
const QString& classID);
virtual void drawLine(SyntopiaCore::Math::Vector3f from,
SyntopiaCore::Math::Vector3f to,
const QString& classID);
virtual void drawDot(SyntopiaCore::Math::Vector3f pos,
const QString& classID);
virtual void drawTriangle(SyntopiaCore::Math::Vector3f p1,
SyntopiaCore::Math::Vector3f p2,
SyntopiaCore::Math::Vector3f p3,
const QString& classID);
virtual void callGeneric(const QString& classID);
virtual void begin();
virtual void end();
virtual void setColor(SyntopiaCore::Math::Vector3f rgb) { this->rgb = rgb; }
virtual void setBackgroundColor(SyntopiaCore::Math::Vector3f rgb);
virtual void setAlpha(double alpha) { this->alpha = alpha; }
QString getOutput() ;
// Issues a command for a specific renderclass such as 'template' or 'opengl'
virtual void callCommand(const QString& renderClass, const QString& command);
bool assertPrimitiveExists(QString templateName);
void setCamera(Vector3f cameraPosition, Vector3f cameraUp, Vector3f cameraRight, Vector3f cameraTarget, int width, int height, double aspect, double fov) {
this->cameraPosition = cameraPosition;
this->cameraUp = cameraUp;
this->cameraRight = cameraRight;
this->cameraTarget = cameraTarget;
this->width = width;
this->height = height;
this->aspect = aspect;
this->fov = fov;
}
void doStandardSubstitutions(SyntopiaCore::Math::Vector3f base,
SyntopiaCore::Math::Vector3f dir1,
SyntopiaCore::Math::Vector3f dir2,
SyntopiaCore::Math::Vector3f dir3,
TemplatePrimitive& t);
private:
SyntopiaCore::Math::Vector3f cameraPosition;
SyntopiaCore::Math::Vector3f cameraUp;
SyntopiaCore::Math::Vector3f cameraRight;
SyntopiaCore::Math::Vector3f cameraTarget;
SyntopiaCore::Math::Vector3f rgb;
SyntopiaCore::Math::Vector3f backRgb;
double alpha;
Template workingTemplate;
QStringList output;
int counter;
int width;
int height;
double aspect;
double fov;
QSet<QString> missingTypes;
};
}
}
}
|