Skip to content

Commit 66afb4a

Browse files
committed
- added missing files
1 parent 5936ce9 commit 66afb4a

File tree

3 files changed

+178
-0
lines changed

3 files changed

+178
-0
lines changed

Simulator/GUI/imgui/LogWindow.cpp

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#include "LogWindow.h"
2+
#include "imgui_internal.h"
3+
#include "Utilities/Logger.h"
4+
5+
6+
using namespace std;
7+
using namespace SPH;
8+
using namespace Utilities;
9+
10+
11+
LogWindow::LogWindow()
12+
{
13+
m_lastSize = 0;
14+
m_selectedFilter = 1;
15+
}
16+
17+
LogWindow::~LogWindow(void)
18+
{
19+
}
20+
21+
void LogWindow::drawWindow(ImFont* textFont)
22+
{
23+
if (m_bufferSink != 0)
24+
{
25+
std::vector<std::pair<Utilities::LogLevel, std::string>>& buffer = m_bufferSink->getBuffer();
26+
27+
float alpha = 0.8f;
28+
if (ImGui::IsWindowDocked())
29+
alpha = 1.0f;
30+
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.1f, 0.1f, 0.1f, alpha));
31+
32+
ImGui::Begin("Log");
33+
34+
if (ImGui::Button("Clear"))
35+
m_bufferSink->clearBuffer();
36+
ImGui::SameLine();
37+
bool copy = ImGui::Button("Copy");
38+
ImGui::SameLine();
39+
40+
const char* items[] = { "Debug", "Info", "Warning", "Error" };
41+
const char* currentItem = items[m_selectedFilter];
42+
ImGui::PushItemWidth(200.0f);
43+
if (ImGui::BeginCombo("Filter", currentItem))
44+
{
45+
for (int n = 0; n < IM_ARRAYSIZE(items); n++)
46+
{
47+
const bool is_selected = (m_selectedFilter == n);
48+
if (ImGui::Selectable(items[n], is_selected))
49+
{
50+
if (n != m_selectedFilter)
51+
m_selectedFilter = n;
52+
}
53+
if (is_selected)
54+
ImGui::SetItemDefaultFocus();
55+
}
56+
ImGui::EndCombo();
57+
}
58+
ImGui::PopItemWidth();
59+
60+
61+
ImGui::Separator();
62+
ImGui::BeginChild("Scrolling");
63+
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 1));
64+
if (copy)
65+
ImGui::LogToClipboard();
66+
67+
ImGui::PushFont(textFont);
68+
for (size_t i = 0; i < buffer.size(); i++)
69+
{
70+
if ((m_selectedFilter == 0) && (buffer[i].first == LogLevel::DEBUG))
71+
ImGui::TextColored(ImVec4(0.4f, 1.0f, 0.4f, 1.0f), buffer[i].second.c_str());
72+
else if ((m_selectedFilter <= 1) && (buffer[i].first == LogLevel::INFO))
73+
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 1.0f), buffer[i].second.c_str());
74+
else if ((m_selectedFilter <= 2) && (buffer[i].first == LogLevel::WARN))
75+
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), buffer[i].second.c_str());
76+
else if ((m_selectedFilter <= 3) && (buffer[i].first == LogLevel::ERR))
77+
ImGui::TextColored(ImVec4(1.0f, 0.5f, 0.5f, 1.0f), buffer[i].second.c_str());
78+
}
79+
ImGui::PopFont();
80+
// if there are new lines, scroll to bottom
81+
if (buffer.size() > m_lastSize)
82+
{
83+
m_lastSize = buffer.size();
84+
ImGui::SetScrollHereY(1.0f);
85+
}
86+
ImGui::PopStyleVar();
87+
ImGui::EndChild();
88+
ImGui::PopStyleColor(1);
89+
ImGui::End();
90+
}
91+
else
92+
{
93+
auto& sinks = Utilities::logger.getSinks();
94+
for (auto it = sinks.begin(); it != sinks.end(); it++)
95+
{
96+
m_bufferSink = dynamic_pointer_cast<BufferSink>(*it);
97+
if (m_bufferSink != 0)
98+
break;
99+
}
100+
}
101+
}

Simulator/GUI/imgui/LogWindow.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef __LogWindow_h__
2+
#define __LogWindow_h__
3+
4+
#include "SPlisHSPlasH/Common.h"
5+
#include "Utilities/Logger.h"
6+
#include <vector>
7+
#include "imgui.h"
8+
9+
struct ImFont;
10+
11+
namespace SPH
12+
{
13+
class LogWindow
14+
{
15+
protected:
16+
std::shared_ptr<Utilities::BufferSink> m_bufferSink;
17+
bool m_scrollToBottom;
18+
size_t m_lastSize;
19+
int m_selectedFilter;
20+
21+
public:
22+
LogWindow();
23+
~LogWindow();
24+
25+
void drawWindow(ImFont *textFont);
26+
int getSelectedFilter() const { return m_selectedFilter; }
27+
void setSelectedFilter(const int i) { m_selectedFilter = i; }
28+
};
29+
}
30+
31+
#endif

Utilities/PLYLoader.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#ifndef __PLYLoader_h__
2+
#define __PLYLoader_h__
3+
4+
#include <string>
5+
#include "Logger.h"
6+
#include "extern/happly/happly.h"
7+
#include <array>
8+
9+
namespace Utilities
10+
{
11+
/** \brief Read for PLY files.
12+
*/
13+
class PLYLoader
14+
{
15+
public:
16+
/** This function loads an PLY file.
17+
* Only triangulated meshes are supported.
18+
*/
19+
20+
static void loadPly(const std::string &filename, std::vector<std::array<float, 3>> &x, std::vector<std::array<int, 3>> &faces, const std::array<float, 3>&scale)
21+
{
22+
LOG_INFO << "Loading " << filename;
23+
24+
happly::PLYData plyIn(filename.c_str());
25+
std::vector<std::array<double, 3>> vPos = plyIn.getVertexPositions();
26+
std::vector<std::vector<int>> fInd = plyIn.getFaceIndices<int>();
27+
28+
x.resize(vPos.size());
29+
for (unsigned int i = 0; i < vPos.size(); i++)
30+
{
31+
x[i] = {
32+
scale[0] * static_cast<float>(vPos[i][0]),
33+
scale[1] * static_cast<float>(vPos[i][1]),
34+
scale[2] * static_cast<float>(vPos[i][2])
35+
};
36+
}
37+
38+
faces.resize(fInd.size());
39+
for (unsigned int i = 0; i < fInd.size(); i++)
40+
faces[i] = { static_cast<int>(fInd[i][0]), static_cast<int>(fInd[i][1]), static_cast<int>(fInd[i][2]) };
41+
}
42+
43+
};
44+
}
45+
46+
#endif

0 commit comments

Comments
 (0)