Skip to content

Commit

Permalink
use '.' to cycle thru iterations.
Browse files Browse the repository at this point in the history
`./splatapult.exe /c/Users/hyperlogic/Downloads/point_cloud/point_cloud/iteration_#/point_cloud.ply`

Will first load iteration_0, then when '.' is pressed iteration_1 will be loaded etc.
  • Loading branch information
hyperlogic committed Apr 9, 2024
1 parent 7b0416a commit a3c88bc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
51 changes: 42 additions & 9 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ const int TEXT_NUM_ROWS = 25;
#include <filesystem>
#include <iostream>

static std::string replaceHashWithNumber(const std::string& input, int number)
{
// Find the first occurrence of '#'
size_t pos = input.find('#');
if (pos != std::string::npos)
{
// If '#' is found, create a new string with '#' replaced by `number`
return input.substr(0, pos) + std::to_string(number) + input.substr(pos + 1);
}
// If '#' is not found, return the original string
return input;
}

// searches for file named configFilename, dir that contains plyFilename, it's parent and grandparent dirs.
static std::string FindConfigFile(const std::string& plyFilename, const std::string& configFilename)
{
Expand Down Expand Up @@ -262,6 +275,7 @@ App::App(MainContext& mainContextIn):
virtualRoll = 0.0f;
virtualUp = 0.0f;
frameNum = 0;
currentIteration = 0;
}

App::ParseResult App::ParseArguments(int argc, const char* argv[])
Expand Down Expand Up @@ -322,17 +336,20 @@ App::ParseResult App::ParseArguments(int argc, const char* argv[])
}
else
{
plyFilename = parse.nonOption(0);
plyFilenamePattern = parse.nonOption(0);
}

Log::SetLevel(opt.debugLogging ? Log::Debug : Log::Warning);

// AJT: VINS disable checking
/*
std::filesystem::path plyPath(plyFilename);
if (!std::filesystem::exists(plyPath) || !std::filesystem::is_regular_file(plyPath))
{
Log::E("Invalid file \"%s\"\n", plyFilename.c_str());
return ERROR_RESULT;
}
*/

return SUCCESS_RESULT;
}
Expand All @@ -341,6 +358,10 @@ bool App::Init()
{
bool isFramebufferSRGBEnabled = opt.vrMode;

// AJT: VINS HACK:
plyFilename = replaceHashWithNumber(plyFilenamePattern, currentIteration);
currentIteration++;

#ifndef __ANDROID__
// AJT: ANDROID: TODO: make sure colors are accurate on android.
if (isFramebufferSRGBEnabled)
Expand Down Expand Up @@ -462,13 +483,15 @@ bool App::Init()
glm::quat flyCamRot;
floorMatUp = glm::vec3(floorMat[1]);
Decompose(flyCamMat, &flyCamScale, &flyCamRot, &flyCamPos);
flyCam = std::make_shared<FlyCam>(floorMatUp, flyCamPos, flyCamRot, MOVE_SPEED, ROT_SPEED);

magicCarpet = std::make_shared<MagicCarpet>(floorMat, MOVE_SPEED);
if (!magicCarpet->Init(isFramebufferSRGBEnabled))
if (currentIteration == 1) // AJT: VINS HACK
{
Log::E("Error initalizing MagicCarpet\n");
return false;
flyCam = std::make_shared<FlyCam>(floorMatUp, flyCamPos, flyCamRot, MOVE_SPEED, ROT_SPEED);
magicCarpet = std::make_shared<MagicCarpet>(floorMat, MOVE_SPEED);
if (!magicCarpet->Init(isFramebufferSRGBEnabled))
{
Log::E("Error initalizing MagicCarpet\n");
return false;
}
}

std::string pointCloudFilename = FindConfigFile(plyFilename, "input.ply");
Expand Down Expand Up @@ -722,6 +745,15 @@ bool App::Init()
virtualUp += down ? -1.0f : 1.0f;
});

inputBuddy->OnKey(SDLK_PERIOD, [this](bool down, uint16_t mod)
{
// AJT: VINS hack
if (down)
{
Init();
}
});

inputBuddy->OnMouseButton([this](uint8_t button, bool down, glm::ivec2 pos)
{
if (button == 3) // right button
Expand All @@ -745,7 +777,8 @@ bool App::Init()
});
#endif // USE_SDL

fpsText = textRenderer->AddScreenTextWithDropShadow(glm::ivec2(0, 0), (int)TEXT_NUM_ROWS, WHITE, BLACK, "fps:");
std::string text = "iter: " + std::to_string(currentIteration - 1);
fpsText = textRenderer->AddScreenTextWithDropShadow(glm::ivec2(0, 0), (int)TEXT_NUM_ROWS, WHITE, BLACK, text);

return true;
}
Expand All @@ -759,7 +792,7 @@ void App::ProcessEvent(const SDL_Event& event)

void App::UpdateFps(float fps)
{
std::string text = "fps: " + std::to_string((int)fps);
std::string text = "iter: " + std::to_string(currentIteration - 1) + " fps: " + std::to_string((int)fps);
textRenderer->RemoveText(fpsText);
fpsText = textRenderer->AddScreenTextWithDropShadow(glm::ivec2(0, 0), TEXT_NUM_ROWS, WHITE, BLACK, text);

Expand Down
3 changes: 3 additions & 0 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class App

MainContext& mainContext;
Options opt;
std::string plyFilenamePattern;
std::string plyFilename;
std::shared_ptr<DebugRenderer> debugRenderer;
std::shared_ptr<TextRenderer> textRenderer;
Expand Down Expand Up @@ -101,4 +102,6 @@ class App
ResizeCallback resizeCallback;

std::vector<float> fpsVec;

int currentIteration;
};
1 change: 1 addition & 0 deletions src/sdl_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ int main(int argc, char *argv[])
Log::SetAppName("splataplut");
MainContext mainContext;
App app(mainContext);

App::ParseResult parseResult = app.ParseArguments(argc, (const char**)argv);
switch (parseResult)
{
Expand Down

0 comments on commit a3c88bc

Please sign in to comment.