PeriDyno 1.0.0
Loading...
Searching...
No Matches
WMainApp.cpp
Go to the documentation of this file.
1#include "WMainApp.h"
2#include "WMainWindow.h"
3#include "WSimulationCanvas.h"
4
5#include <Wt/WLinkedCssStyleSheet.h>
6#include <Wt/WEnvironment.h>
7#include <Wt/WHBoxLayout.h>
8#include <Wt/WBootstrapTheme.h>
9
10// for test data
11#include <SceneGraphFactory.h>
12// #include <ParticleSystem/ParticleFluid.h>
13// #include <ParticleSystem/GhostParticles.h>
14// #include <ParticleSystem/StaticBoundary.h>
15// #include <ParticleSystem/GhostFluid.h>
16// #include <Module/CalculateNorm.h>
17// #include <GLPointVisualModule.h>
18// #include <ColorMapping.h>
19
20using namespace dyno;
21
22// std::shared_ptr<GhostParticles<DataType3f>> createGhostParticles()
23// {
24// auto ghost = std::make_shared<GhostParticles<DataType3f>>();
25
26// std::vector<Vec3f> host_pos;
27// std::vector<Vec3f> host_vel;
28// std::vector<Vec3f> host_force;
29// std::vector<Vec3f> host_normal;
30// std::vector<Attribute> host_attribute;
31
32// Vec3f low(-0.2, -0.015, -0.2);
33// Vec3f high(0.2, -0.005, 0.2);
34
35// Real s = 0.005f;
36// int m_iExt = 0;
37
38// float omega = 1.0f;
39// float half_s = -s / 2.0f;
40
41// int num = 0;
42
43// for (float x = low.x - m_iExt * s; x <= high.x + m_iExt * s; x += s) {
44// for (float y = low.y - m_iExt * s; y <= high.y + m_iExt * s; y += s) {
45// for (float z = low.z - m_iExt * s; z <= high.z + m_iExt * s; z += s) {
46// Attribute attri;
47// attri.setFluid();
48// attri.setDynamic();
49
50// host_pos.push_back(Vec3f(x, y, z));
51// host_vel.push_back(Vec3f(0));
52// host_force.push_back(Vec3f(0));
53// host_normal.push_back(Vec3f(0, 1, 0));
54// host_attribute.push_back(attri);
55// }
56// }
57// }
58
59// ghost->statePosition()->assign(host_pos);
60// ghost->stateVelocity()->assign(host_vel);
61// ghost->stateForce()->assign(host_force);
62// ghost->stateNormal()->assign(host_normal);
63// ghost->stateAttribute()->assign(host_attribute);
64
65// host_pos.clear();
66// host_vel.clear();
67// host_force.clear();
68// host_normal.clear();
69// host_attribute.clear();
70
71// return ghost;
72// }
73
74// std::shared_ptr<SceneGraph> createScene()
75// {
76// std::shared_ptr<SceneGraph> scn = std::make_shared<SceneGraph>();
77// scn->setUpperBound(Vec3f(0.5, 1, 0.5));
78// scn->setLowerBound(Vec3f(-0.5, 0, -0.5));
79
80// auto boundary = scn->addNode(std::make_shared<StaticBoundary<DataType3f>>());
81// boundary->loadCube(Vec3f(-0.1f, 0.0f, -0.1f), Vec3f(0.1f, 1.0f, 0.1f), 0.005, true);
82// //root->loadSDF(getAssetPath() + "bowl/bowl.sdf", false);
83
84// auto fluid = scn->addNode(std::make_shared<ParticleSystem<DataType3f>>());
85// fluid->loadParticles(Vec3f(-0.1, 0.0, -0.1), Vec3f(0.105, 0.1, 0.105), 0.005);
86
87// auto ghost = scn->addNode(createGhostParticles());
88
89// auto incompressibleFluid = scn->addNode(std::make_shared<GhostFluid<DataType3f>>());
90// fluid->connect(incompressibleFluid->importFluidParticles());
91// ghost->connect(incompressibleFluid->importBoundaryParticles());
92// // incompressibleFluid->setFluidParticles(fluid);
93// // incompressibleFluid->setBoundaryParticles(ghost);
94
95// // root->addAncestor(incompressibleFluid.get());
96// // root->addParticleSystem(fluid);
97// incompressibleFluid->connect(boundary->importParticleSystems());
98
99// {
100// auto calculateNorm = std::make_shared<CalculateNorm<DataType3f>>();
101// auto colorMapper = std::make_shared<ColorMapping<DataType3f>>();
102// colorMapper->varMax()->setValue(5.0f);
103
104// fluid->stateVelocity()->connect(calculateNorm->inVec());
105// calculateNorm->outNorm()->connect(colorMapper->inScalar());
106
107// fluid->graphicsPipeline()->pushModule(calculateNorm);
108// fluid->graphicsPipeline()->pushModule(colorMapper);
109
110// auto ptRender = std::make_shared<GLPointVisualModule>();
111// ptRender->setColor(Color(1, 0, 0));
112// ptRender->setColorMapMode(GLPointVisualModule::PER_VERTEX_SHADER);
113
114// fluid->statePointSet()->connect(ptRender->inPointSet());
115// colorMapper->outColor()->connect(ptRender->inColor());
116
117// fluid->graphicsPipeline()->pushModule(ptRender);
118// }
119
120// {
121// auto ghostRender = std::make_shared<GLPointVisualModule>();
122// ghostRender->setColor(Color(1, 0.5, 0));
123// ghostRender->setColorMapMode(GLPointVisualModule::PER_OBJECT_SHADER);
124
125// ghost->statePointSet()->connect(ghostRender->inPointSet());
126
127// ghost->graphicsPipeline()->pushModule(ghostRender);
128// }
129
130// return scn;
131// }
132
133WMainApp::WMainApp(const Wt::WEnvironment& env) : Wt::WApplication(env)
134{
135 // ace editor
136 this->require("lib/ace.js");
137
138 // use default bootstrap theme
139 auto theme = std::make_shared<Wt::WBootstrapTheme>();
140 theme->setVersion(Wt::BootstrapVersion::v3);
141 theme->setResponsive(true);
142 this->setTheme(theme);
143
144 this->setTitle("PeriDyno: An AI-targeted physics simulation platform");
145
146 // style sheet for the canvas
147 this->styleSheet().addRule(
148 ".remote-framebuffer",
149 // flip
150 "transform: scaleY(-1) !important;"
151 // disable drag...
152 "-webkit-user-drag: none !important;"
153 "-khtml-user-drag: none !important;"
154 "-moz-user-drag: none !important;"
155 "-o-user-drag: none !important;"
156 "user-drag: none !important;"
157 // hack for brightness
158 "filter: brightness(2);"
159 );
160
161 // override internal padding for panel...
162 this->styleSheet().addRule(
163 ".panel-body",
164 "padding: 0!important;"
165 );
166
167 this->styleSheet().addRule(
168 ".sample-item",
169 "border-radius: 5px;"
170 );
171
172 // add logo to navbar
173 this->styleSheet().addRule(
174 ".navbar-header",
175 "background-image: url(\"logo.png\");"
176 "background-repeat: no-repeat;"
177 "background-size: 36px 36px;"
178 "background-position: 12px 6px;"
179 "padding-left: 36px;"
180 );
181
182 // color picker button style
183 this->styleSheet().addRule(
184 ".color-picker",
185 "border: 0!important;"
186 "padding: 0!important;"
187 );
188
189 // scrollable style
190 this->styleSheet().addRule(
191 ".scrollable-content",
192 "overflow: auto;"
193 "max-height: 200px;"
194 "border: 1px solid #ccc;"
195 "padding: 10px;"
196 "box-sizing: border-box;"
197 );
198
199 // set layout and add main window
200 auto layout = this->root()->setLayout(std::make_unique<Wt::WHBoxLayout>());
201 layout->setContentsMargins(0, 0, 0, 0);
202
203 window = layout->addWidget(std::make_unique<WMainWindow>());
204
205 window->setScene(SceneGraphFactory::instance()->createDefaultScene());
206
207 this->globalKeyWentDown().connect(window->simCanvas(), &WSimulationCanvas::onKeyWentDown);
208 this->globalKeyWentUp().connect(window->simCanvas(), &WSimulationCanvas::onKeyWentUp);
209}
210
212{
213 Wt::log("warning") << "stop WApplication";
214}
WMainApp(const Wt::WEnvironment &env)
Definition WMainApp.cpp:133
WMainWindow * window
Definition WMainApp.h:17
void onKeyWentUp(const Wt::WKeyEvent &evt)
void onKeyWentDown(const Wt::WKeyEvent &evt)
static SceneGraphFactory * instance()
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25