Skip to content

Commit

Permalink
Merge pull request #102 from Tom94/image-server
Browse files Browse the repository at this point in the history
Allow tev to be remote-controlled over the network
  • Loading branch information
Tom94 authored Jun 2, 2020
2 parents 8a6a4b0 + 98fabcc commit 045831d
Show file tree
Hide file tree
Showing 22 changed files with 956 additions and 147 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
[submodule "dependencies/clip"]
path = dependencies/clip
url = https://github.com/Tom94/clip
[submodule "dependencies/enet"]
path = dependencies/enet
url = https://github.com/lsalzman/enet
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "
endif()
endif()

set(TEV_LIBS clip IlmImf nanogui ${NANOGUI_EXTRA_LIBS})
set(TEV_LIBS clip IlmImf nanogui enet ${NANOGUI_EXTRA_LIBS})
if (MSVC)
set(TEV_LIBS ${TEV_LIBS} zlibstatic wsock32 ws2_32)
set(TEV_LIBS ${TEV_LIBS} zlibstatic winmm ws2_32)
endif()

set(TEV_SOURCES
include/tev/imageio/ClipboardImageLoader.h src/imageio/ClipboardImageLoader.cpp
include/tev/imageio/EmptyImageLoader.h src/imageio/EmptyImageLoader.cpp
include/tev/imageio/ExrImageLoader.h src/imageio/ExrImageLoader.cpp
include/tev/imageio/ExrImageSaver.h src/imageio/ExrImageSaver.cpp
include/tev/imageio/ImageLoader.h src/imageio/ImageLoader.cpp
Expand Down Expand Up @@ -147,6 +148,7 @@ include_directories(
${ARGS_INCLUDE}
${CLIP_INCLUDE}
${EIGEN_INCLUDE}
${ENET_INCLUDE}
${FILESYSTEM_INCLUDE}
${GLFW_INCLUDE}
${NANOGUI_EXTRA_INCS}
Expand Down
5 changes: 5 additions & 0 deletions dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ set(CLIP_EXAMPLES OFF CACHE BOOL " " FORCE)
set(CLIP_TESTS OFF CACHE BOOL " " FORCE)
add_subdirectory(clip)

# Conpile enet
add_subdirectory(enet)

# Manually populate locations of our included dependencies.
set(ARGS_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/args PARENT_SCOPE)

set(CLIP_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/clip PARENT_SCOPE)

set(EIGEN_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/nanogui/ext/eigen PARENT_SCOPE)

set(ENET_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/enet/include PARENT_SCOPE)

if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
set(GLFW_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/nanogui/ext/glfw/include PARENT_SCOPE)
endif()
Expand Down
1 change: 1 addition & 0 deletions dependencies/enet
Submodule enet added at 224f31
8 changes: 8 additions & 0 deletions include/tev/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class Channel {
return at(index.x() + index.y() * mData.cols());
}

float at(Eigen::Vector2i index) const {
return at(index.x() + index.y() * mData.cols());
}

Eigen::DenseIndex count() const {
return mData.size();
}
Expand All @@ -64,6 +68,10 @@ class Channel {
void divideByAsync(const Channel& other, ThreadPool& pool);
void multiplyWithAsync(const Channel& other, ThreadPool& pool);

void setZero() { mData.setZero(); }

void updateTile(int x, int y, int width, int height, const std::vector<float>& newData);

static std::pair<std::string, std::string> split(const std::string& fullChannel);

static std::string tail(const std::string& fullChannel);
Expand Down
4 changes: 3 additions & 1 deletion include/tev/GlTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ class GlTexture {
}
}

GLuint id() const { return mId; }
const std::vector<float>& data() const { return mData; }
const Eigen::Vector2i& size() const { return mSize; }

void bind();
void setData(const std::vector<float>& data, const Eigen::Vector2i& size, int numChannels);
void setDataSub(const std::vector<float>& data, const Eigen::Vector2i& origin, const Eigen::Vector2i& size, int numChannels);

private:
GLuint mId = 0;
GLint mClamping;
GLint mFiltering;
bool mMipmap;
bool mRequiresMipmapping = false;

Eigen::Vector2i mSize = Eigen::Vector2i::Constant(0);
int mNumChannels = 0;
Expand Down
21 changes: 15 additions & 6 deletions include/tev/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ struct ChannelGroup {
std::vector<std::string> channels;
};

struct ImageTexture {
GlTexture glTexture;
std::vector<std::string> channels;
};

class Image {
public:
Image(const filesystem::path& path, std::istream& iStream, const std::string& channelSelector);
Expand Down Expand Up @@ -60,8 +65,8 @@ class Image {
}
}

const GlTexture* texture(const std::string& channelGroupName);
const GlTexture* texture(const std::vector<std::string>& channelNames);
GlTexture* texture(const std::string& channelGroupName);
GlTexture* texture(const std::vector<std::string>& channelNames);

std::vector<std::string> channelsInGroup(const std::string& groupName) const;
std::vector<std::string> getSortedChannels(const std::string& layerName) const;
Expand All @@ -78,12 +83,16 @@ class Image {
return mChannelGroups;
}

const ChannelGroup& channelGroup(const std::string& groupName) const;

int id() const {
return mId;
}

void bumpId() {
mId = sId++;
}

void updateChannel(const std::string& channelName, int x, int y, int width, int height, const std::vector<float>& data);

std::string toString() const;

private:
Expand Down Expand Up @@ -113,13 +122,13 @@ class Image {

std::string mName;

std::map<std::string, GlTexture> mTextures;
std::map<std::string, ImageTexture> mTextures;

ImageData mData;

std::vector<ChannelGroup> mChannelGroups;

const int mId;
int mId;
};

std::shared_ptr<Image> tryLoadImage(filesystem::path path, std::istream& iStream, std::string channelSelector);
Expand Down
28 changes: 27 additions & 1 deletion include/tev/ImageViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <nanogui/textbox.h>

#include <memory>
#include <set>
#include <vector>

TEV_NAMESPACE_BEGIN
Expand All @@ -34,6 +35,8 @@ class ImageViewer : public nanogui::Screen {

bool keyboardEvent(int key, int scancode, int action, int modifiers) override;

void focusWindow();

void drawContents() override;

void insertImage(std::shared_ptr<Image> image, size_t index, bool shallSelect = false);
Expand All @@ -44,11 +47,26 @@ class ImageViewer : public nanogui::Screen {
}

void removeImage(std::shared_ptr<Image> image);
void removeImage(const std::string& imageName) {
removeImage(imageByName(imageName));
}
void removeAllImages();

void reloadImage(std::shared_ptr<Image> image);
void reloadImage(std::shared_ptr<Image> image, bool shallSelect = false);
void reloadImage(const std::string& imageName, bool shallSelect = false) {
reloadImage(imageByName(imageName), shallSelect);
}
void reloadAllImages();

void updateImage(
const std::string& imageName,
bool shallSelect,
const std::string& channel,
int x, int y,
int width, int height,
const std::vector<float>& imageData
);

void selectImage(const std::shared_ptr<Image>& image, bool stopPlayback = true);

void selectGroup(std::string name);
Expand Down Expand Up @@ -113,6 +131,11 @@ class ImageViewer : public nanogui::Screen {
mRequiresLayoutUpdate = true;
}

template <typename T>
void scheduleToUiThread(const T& fun) {
mTaskQueue.push(fun);
}

private:
void updateFilter();
void updateLayout();
Expand All @@ -121,12 +144,14 @@ class ImageViewer : public nanogui::Screen {

int groupId(const std::string& groupName) const;
int imageId(const std::shared_ptr<Image>& image) const;
int imageId(const std::string& imageName) const;

std::string nextGroup(const std::string& groupName, EDirection direction);
std::string nthVisibleGroup(size_t n);

std::shared_ptr<Image> nextImage(const std::shared_ptr<Image>& image, EDirection direction);
std::shared_ptr<Image> nthVisibleImage(size_t n);
std::shared_ptr<Image> imageByName(const std::string& imageName);

bool canDragSidebarFrom(const Eigen::Vector2i& p) {
return mSidebar->visible() && p.x() - mSidebar->fixedWidth() < 10 && p.x() - mSidebar->fixedWidth() > -5;
Expand Down Expand Up @@ -173,6 +198,7 @@ class ImageViewer : public nanogui::Screen {
std::vector<std::shared_ptr<Image>> mImages;

MultiGraph* mHistogram;
std::set<std::shared_ptr<Image>> mToBump;

nanogui::TextBox* mFilter;
nanogui::Button* mRegexButton;
Expand Down
Loading

0 comments on commit 045831d

Please sign in to comment.