-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#include "LogWindow.h" | ||
#include "imgui_internal.h" | ||
#include "Utilities/Logger.h" | ||
|
||
|
||
using namespace std; | ||
using namespace SPH; | ||
using namespace Utilities; | ||
|
||
|
||
LogWindow::LogWindow() | ||
{ | ||
m_lastSize = 0; | ||
m_selectedFilter = 1; | ||
} | ||
|
||
LogWindow::~LogWindow(void) | ||
{ | ||
} | ||
|
||
void LogWindow::drawWindow(ImFont* textFont) | ||
{ | ||
if (m_bufferSink != 0) | ||
{ | ||
std::vector<std::pair<Utilities::LogLevel, std::string>>& buffer = m_bufferSink->getBuffer(); | ||
|
||
float alpha = 0.8f; | ||
if (ImGui::IsWindowDocked()) | ||
alpha = 1.0f; | ||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.1f, 0.1f, 0.1f, alpha)); | ||
|
||
ImGui::Begin("Log"); | ||
|
||
if (ImGui::Button("Clear")) | ||
m_bufferSink->clearBuffer(); | ||
ImGui::SameLine(); | ||
bool copy = ImGui::Button("Copy"); | ||
ImGui::SameLine(); | ||
|
||
const char* items[] = { "Debug", "Info", "Warning", "Error" }; | ||
const char* currentItem = items[m_selectedFilter]; | ||
ImGui::PushItemWidth(200.0f); | ||
if (ImGui::BeginCombo("Filter", currentItem)) | ||
{ | ||
for (int n = 0; n < IM_ARRAYSIZE(items); n++) | ||
{ | ||
const bool is_selected = (m_selectedFilter == n); | ||
if (ImGui::Selectable(items[n], is_selected)) | ||
{ | ||
if (n != m_selectedFilter) | ||
m_selectedFilter = n; | ||
} | ||
if (is_selected) | ||
ImGui::SetItemDefaultFocus(); | ||
} | ||
ImGui::EndCombo(); | ||
} | ||
ImGui::PopItemWidth(); | ||
|
||
|
||
ImGui::Separator(); | ||
ImGui::BeginChild("Scrolling"); | ||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 1)); | ||
if (copy) | ||
ImGui::LogToClipboard(); | ||
|
||
ImGui::PushFont(textFont); | ||
for (size_t i = 0; i < buffer.size(); i++) | ||
{ | ||
if ((m_selectedFilter == 0) && (buffer[i].first == LogLevel::DEBUG)) | ||
ImGui::TextColored(ImVec4(0.4f, 1.0f, 0.4f, 1.0f), buffer[i].second.c_str()); | ||
else if ((m_selectedFilter <= 1) && (buffer[i].first == LogLevel::INFO)) | ||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 1.0f), buffer[i].second.c_str()); | ||
else if ((m_selectedFilter <= 2) && (buffer[i].first == LogLevel::WARN)) | ||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), buffer[i].second.c_str()); | ||
else if ((m_selectedFilter <= 3) && (buffer[i].first == LogLevel::ERR)) | ||
ImGui::TextColored(ImVec4(1.0f, 0.5f, 0.5f, 1.0f), buffer[i].second.c_str()); | ||
} | ||
ImGui::PopFont(); | ||
// if there are new lines, scroll to bottom | ||
if (buffer.size() > m_lastSize) | ||
{ | ||
m_lastSize = buffer.size(); | ||
ImGui::SetScrollHereY(1.0f); | ||
} | ||
ImGui::PopStyleVar(); | ||
ImGui::EndChild(); | ||
ImGui::PopStyleColor(1); | ||
ImGui::End(); | ||
} | ||
else | ||
{ | ||
auto& sinks = Utilities::logger.getSinks(); | ||
for (auto it = sinks.begin(); it != sinks.end(); it++) | ||
{ | ||
m_bufferSink = dynamic_pointer_cast<BufferSink>(*it); | ||
if (m_bufferSink != 0) | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef __LogWindow_h__ | ||
#define __LogWindow_h__ | ||
|
||
#include "SPlisHSPlasH/Common.h" | ||
#include "Utilities/Logger.h" | ||
#include <vector> | ||
#include "imgui.h" | ||
|
||
struct ImFont; | ||
|
||
namespace SPH | ||
{ | ||
class LogWindow | ||
{ | ||
protected: | ||
std::shared_ptr<Utilities::BufferSink> m_bufferSink; | ||
bool m_scrollToBottom; | ||
size_t m_lastSize; | ||
int m_selectedFilter; | ||
|
||
public: | ||
LogWindow(); | ||
~LogWindow(); | ||
|
||
void drawWindow(ImFont *textFont); | ||
int getSelectedFilter() const { return m_selectedFilter; } | ||
void setSelectedFilter(const int i) { m_selectedFilter = i; } | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef __PLYLoader_h__ | ||
#define __PLYLoader_h__ | ||
|
||
#include <string> | ||
#include "Logger.h" | ||
#include "extern/happly/happly.h" | ||
#include <array> | ||
|
||
namespace Utilities | ||
{ | ||
/** \brief Read for PLY files. | ||
*/ | ||
class PLYLoader | ||
{ | ||
public: | ||
/** This function loads an PLY file. | ||
* Only triangulated meshes are supported. | ||
*/ | ||
|
||
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) | ||
{ | ||
LOG_INFO << "Loading " << filename; | ||
|
||
happly::PLYData plyIn(filename.c_str()); | ||
std::vector<std::array<double, 3>> vPos = plyIn.getVertexPositions(); | ||
std::vector<std::vector<int>> fInd = plyIn.getFaceIndices<int>(); | ||
|
||
x.resize(vPos.size()); | ||
for (unsigned int i = 0; i < vPos.size(); i++) | ||
{ | ||
x[i] = { | ||
scale[0] * static_cast<float>(vPos[i][0]), | ||
scale[1] * static_cast<float>(vPos[i][1]), | ||
scale[2] * static_cast<float>(vPos[i][2]) | ||
}; | ||
} | ||
|
||
faces.resize(fInd.size()); | ||
for (unsigned int i = 0; i < fInd.size(); i++) | ||
faces[i] = { static_cast<int>(fInd[i][0]), static_cast<int>(fInd[i][1]), static_cast<int>(fInd[i][2]) }; | ||
} | ||
|
||
}; | ||
} | ||
|
||
#endif |