Skip to content
This repository has been archived by the owner on Mar 19, 2020. It is now read-only.

Commit

Permalink
moved sobolmat.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
shiinamiyuki committed Nov 8, 2019
1 parent 3a6abc3 commit 5e6dcf5
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 53 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ add_subdirectory(external/glfw)
add_subdirectory(external/gl3w)
add_subdirectory(external/fmt)

include_directories(external/sobol)
include_directories(external/pybind11/include)
include_directories(external/linalg)
include_directories(external/cereal/include)
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions src/api/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <api/camera.h>
#include <api/entity.hpp>
#include <api/integrator.h>
#include <api/property.hpp>
#include <api/sampler.h>
#include <api/scene.h>
#include <api/serialize.hpp>
Expand All @@ -47,6 +48,8 @@ namespace miyuki::core {

MYK_AUTO_INIT(camera, sampler, integrator, shapes, filmDimension)

MYK_PROP(camera, sampler, integrator)

MYK_DECL_CLASS(SceneGraph, "SceneGraph")

void render(const std::string &outImageFile);
Expand Down
27 changes: 22 additions & 5 deletions src/api/property.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ namespace miyuki {
} // namespace detail
using IntProperty = detail::BasicProperty<int>;
using FloatProperty = detail::BasicProperty<float>;
using Vec3fProperty = detail::BasicProperty<Vec3f>;
using Float3Property = detail::BasicProperty<Vec3f>;
using Float2Property = detail::BasicProperty<Point2f>;
using Int2Property = detail::BasicProperty<Point2i>;

using EntityProperty = detail::BasicProperty<std::shared_ptr<Entity>>;
// using VectorProperty = detail::BasicProperty<std::vector<std::shared_ptr<Entity>>>;
using FileProperty = detail::BasicProperty<fs::path>;
Expand All @@ -63,14 +66,16 @@ namespace miyuki {
virtual void visit(Property *prop) { prop->accept(this); }
virtual void visit(IntProperty *) = 0;
virtual void visit(FloatProperty *) = 0;
virtual void visit(Vec3fProperty *) = 0;
virtual void visit(Float3Property *) = 0;
virtual void visit(EntityProperty *) = 0;
virtual void visit(FileProperty *) = 0;
virtual void visit(Int2Property *) = 0;
virtual void visit(Float2Property *) = 0;
};

struct ReflPropertyVisitor {
PropertyVisitor *visitor;

ReflPropertyVisitor(PropertyVisitor *visitor) : visitor(visitor) {}
void visit(int &v, const char *name) {
IntProperty prop(name, v);
prop.accept(visitor);
Expand All @@ -82,14 +87,26 @@ namespace miyuki {
}

void visit(Vec3f &v, const char *name) {
Vec3fProperty prop(name, v);
Float3Property prop(name, v);
prop.accept(visitor);
}

void visit(Point2f &v, const char *name) {
Float2Property prop(name, v);
prop.accept(visitor);
}

void visit(Point2i &v, const char *name) {
Int2Property prop(name, v);
prop.accept(visitor);
}

template <class T>
std::enable_if_t<std::is_base_of_v<Entity, T>, void> visit(std::shared_ptr<T> &v, const char *name) {
EntityProperty prop(name, v);
std::shared_ptr<Entity> p = v;
EntityProperty prop(name, p);
prop.accept(visitor);
v = std::dynamic_pointer_cast<T>(p);
}
};
#define MYK_PROP(...) \
Expand Down
2 changes: 1 addition & 1 deletion src/core/samplers/sobol-sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <api/rng.h>
#include "sobol-sampler.h"
#include "sobolmat.hpp"
#include <sobolmat.hpp>


namespace miyuki::core {
Expand Down
124 changes: 77 additions & 47 deletions src/ui/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
// SOFTWARE.

#include <api/graph.h>
#include <api/log.hpp>
#include <api/property.hpp>
#include <api/ui/ui.h>
#include <api/log.hpp>

#ifndef NOMINMAX
#define NOMINMAX
Expand Down Expand Up @@ -169,11 +169,85 @@ namespace miyuki::ui {

ImGui::End();
}
class MainWindow : public AbstractMainWindow, public PropertyVisitor {

class InspectorPropertyVisitor : public PropertyVisitor {
public:
// Inherited via PropertyVisitor
virtual void visit(IntProperty *prop) override {
auto value = prop->getConstRef();
if (ImGui::InputInt(prop->name(), &value, 1, 100, ImGuiInputTextFlags_EnterReturnsTrue)) {
prop->getRef() = value;
}
}

virtual void visit(FloatProperty *prop) override {
auto value = prop->getConstRef();
if (ImGui::InputFloat(prop->name(), &value, 0.0f, 0.0f, "%.3f", ImGuiInputTextFlags_EnterReturnsTrue)) {
prop->getRef() = value;
}
}

virtual void visit(Float3Property *prop) override {
auto value = prop->getConstRef();
if (ImGui::InputFloat3(prop->name(), (float *)&value, "%.3f", ImGuiInputTextFlags_EnterReturnsTrue)) {
prop->getRef() = value;
}
}

virtual void visit(EntityProperty *prop) override {
if (ImGui::TreeNodeEx(prop->name(), ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::PushID(prop->name());

if (prop->getConstRef()) {
prop->getRef()->accept(this);
}
ImGui::TreePop();

ImGui::PopID();
}
}
virtual void visit(FileProperty *prop) override {
ImGui::PushID(prop->name());
if (ImGui::Button("select")) {
auto filename = GetOpenFileNameWithDialog(nullptr);
if (!filename.empty()) {
prop->getRef() = fs::path(filename);
}
}
ImGui::PopID();
}
};

class ExplorerPropertyVisitor : public PropertyVisitor {
public:
// Inherited via PropertyVisitor
virtual void visit(IntProperty *) override {}
virtual void visit(FloatProperty *) override {}
virtual void visit(Float3Property *) override {}
virtual void visit(EntityProperty *prop) override {
if (ImGui::TreeNodeEx(prop->name(), ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::PushID(prop->name());

if (prop->getConstRef()) {
prop->getRef()->accept(this);
}
ImGui::TreePop();

ImGui::PopID();
}
}
virtual void visit(FileProperty *) override {}
virtual void visit(Int2Property *) override {}
virtual void visit(Float2Property *) override {}
};
class MainWindow : public AbstractMainWindow {
std::shared_ptr<core::SceneGraph> graph;
void showExplorer() {
if (ImGui::Begin("Explorer")) {

if (graph) {
ExplorerPropertyVisitor visitor;
graph->accept(&visitor);
}
ImGui::End();
}
}
Expand Down Expand Up @@ -223,50 +297,6 @@ namespace miyuki::ui {
showExplorer();
showInspector();
}

// Inherited via PropertyVisitor
virtual void visit(IntProperty *prop) override {
auto value = prop->getConstRef();
if (ImGui::InputInt(prop->name(), &value, 1, 100, ImGuiInputTextFlags_EnterReturnsTrue)) {
prop->getRef() = value;
}
}

virtual void visit(FloatProperty *prop) override {
auto value = prop->getConstRef();
if (ImGui::InputFloat(prop->name(), &value, 0.0f, 0.0f, "%.3f", ImGuiInputTextFlags_EnterReturnsTrue)) {
prop->getRef() = value;
}
}

virtual void visit(Vec3fProperty *prop) override {
auto value = prop->getConstRef();
if (ImGui::InputFloat3(prop->name(), (float *)&value, "%.3f", ImGuiInputTextFlags_EnterReturnsTrue)) {
prop->getRef() = value;
}
}

virtual void visit(EntityProperty *prop) override {
if (ImGui::TreeNodeEx(prop->name(), ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::PushID(prop->name());

if (prop->getConstRef()) {
prop->getRef()->accept(this);
}

ImGui::PopID();
}
}
virtual void visit(FileProperty *prop) override {
ImGui::PushID(prop->name());
if (ImGui::Button("select")) {
auto filename = GetOpenFileNameWithDialog(nullptr);
if (!filename.empty()) {
prop->getRef() = fs::path(filename);
}
}
ImGui::PopID();
}
};

std::shared_ptr<AbstractMainWindow> MakeMainWindow(int width, int height, const std::string &title) {
Expand Down

0 comments on commit 5e6dcf5

Please sign in to comment.