Skip to content

Commit

Permalink
partial work on mega refactor without gc
Browse files Browse the repository at this point in the history
  • Loading branch information
nmwsharp committed May 29, 2018
1 parent 6c90b61 commit e0ce26e
Show file tree
Hide file tree
Showing 29 changed files with 393 additions and 379 deletions.
7 changes: 3 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
path = deps/imgui/imgui
url = https://github.com/ocornut/imgui.git
branch = master
[submodule "deps/geometry-central"]
path = deps/geometry-central
url = https://github.com/nmwsharp/geometry-central.git
branch = master
[submodule "deps/glm"]
path = deps/glm
url = https://github.com/g-truc/glm.git
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STR
# using Clang (linux or apple) or GCC
message("Using clang/gcc compiler flags")
SET(BASE_CXX_FLAGS "-std=c++11 -Wall -Wextra -Werror -g3")
SET(DISABLED_WARNINGS " -Wno-unused-parameter -Wno-unused-variable -Wno-unused-private-field -Wno-unused-function -Wno-deprecated-declarations")
SET(DISABLED_WARNINGS " -Wno-unused-parameter -Wno-unused-variable -Wno-unused-private-field -Wno-unused-function -Wno-deprecated-declarations -Wno-missing-braces")
SET(TRACE_INCLUDES " -H -Wno-error=unused-command-line-argument")

# clang-specific things
Expand Down
8 changes: 0 additions & 8 deletions deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,5 @@ add_subdirectory(glfw)
## Imgui
add_subdirectory(imgui)

## Geometry Central
add_subdirectory(geometry-central)
set(GEOMETRY_CENTRAL_INCLUDE_DIRS ${GEOMETRY_CENTRAL_INCLUDE_DIRS} PARENT_SCOPE)

if(HAVE_SUITESPARSE)
SET(HAVE_SUITESPARSE TRUE PARENT_SCOPE)
endif()

## Argparse

1 change: 0 additions & 1 deletion deps/geometry-central
Submodule geometry-central deleted from 9574e2
1 change: 1 addition & 0 deletions deps/glm
Submodule glm added at 20b3f4
14 changes: 7 additions & 7 deletions include/polyscope/affine_remapper.ipp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "geometrycentral/vector3.h"
#include "glm/glm.hpp"

namespace polyscope {

Expand All @@ -13,8 +13,8 @@ double FIELD_BIGNESS(T x) {
return x;
}
template <>
double FIELD_BIGNESS(geometrycentral::Vector3 x) {
return geometrycentral::norm(x);
double FIELD_BIGNESS(glm::vec3 x) {
return glm::length(x);
}

// Multiplicative identity
Expand All @@ -23,8 +23,8 @@ T FIELD_ONE() {
return 1;
}
template <>
geometrycentral::Vector3 FIELD_ONE() {
return geometrycentral::Vector3{1., 1., 1.};
glm::vec3 FIELD_ONE() {
return glm::vec3{1., 1., 1.};
}

// Additive identity
Expand All @@ -33,8 +33,8 @@ T FIELD_ZERO() {
return 0;
}
template <>
geometrycentral::Vector3 FIELD_ZERO() {
return geometrycentral::Vector3::zero();
glm::vec3 FIELD_ZERO() {
return glm::vec3{0., 0., 0.};
}
}; // namespace

Expand Down
27 changes: 9 additions & 18 deletions include/polyscope/camera_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

#include <vector>

#include "geometrycentral/vector3.h"

#include "polyscope/camera_parameters.h"
#include "polyscope/gl/gl_utils.h"
#include "polyscope/structure.h"
#include "polyscope/camera_parameters.h"


namespace polyscope {
Expand All @@ -21,11 +19,10 @@ class Image {
std::string name;
size_t width, height;
unsigned char* data;

};

class CameraView : public Structure {
public:
public:
// === Member functions ===

// Construct a new camera view structure
Expand All @@ -51,25 +48,24 @@ class CameraView : public Structure {
virtual double lengthScale() override;

// Axis-aligned bounding box for the structure
virtual std::tuple<geometrycentral::Vector3, geometrycentral::Vector3>
boundingBox() override;
virtual std::tuple<glm::vec3, glm::vec3> boundingBox() override;

// === Quantity-related
// Add an image with RGB components
void setActiveImage(std::string name);
void clearActiveImage();
void addImage(std::string name, unsigned char* I, size_t width, size_t height);
void removeImage(std::string name, bool errorIfNotPresent=false);
void removeImage(std::string name, bool errorIfNotPresent = false);

// === Helpers
void prepareCameraSkeleton();

// Get the points that describe the "skeleton" in world space. Frame is CCW, starting with upper right.
// dirFrame is {lookDir, upDir, rightDir}
void getCameraPoints(Vector3& root, std::array<Vector3, 4>& framePoints, std::array<Vector3, 3>& dirFrame);
Vector3 location();
void getCameraPoints(glm::vec3& root, std::array<glm::vec3, 4>& framePoints, std::array<glm::vec3, 3>& dirFrame);
glm::vec3 location();



void drawWireframe();
void drawImageView();

Expand All @@ -81,21 +77,16 @@ class CameraView : public Structure {
// The camera parameters
CameraParameters parameters;

private:

private:
// Quantities
std::map<std::string, Image*> images;

// Drawing related things
gl::GLProgram* cameraSkeletonProgram = nullptr;
gl::GLProgram* pickProgram = nullptr;
Image* activeImage = nullptr;
gl::GLProgram* imageViewProgram = nullptr;
static float globalImageTransparency;
float cameraSkeletonScale; // the lengthscale cameras were first drawn with


};


}
8 changes: 3 additions & 5 deletions include/polyscope/gl/colormaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

#include <vector>

#include "geometrycentral/vector3.h"

using namespace geometrycentral;
#include "polyscope/color_management.h"

namespace polyscope {
namespace gl {
Expand Down Expand Up @@ -45,11 +43,11 @@ namespace gl {
struct Colormap {

std::string name;
std::vector<Vector3> values;
std::vector<Color3f> values;

// Samples "val" from the colormap, where val is clamped to [0,1].
// Returns a vector3 of rgb values, each from [0,1]
Vector3 getValue(double val) const;
Color3f getValue(double val) const;
};


Expand Down
24 changes: 10 additions & 14 deletions include/polyscope/gl/colors.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
#pragma once

#include "geometrycentral/vector3.h"

using namespace geometrycentral;

namespace polyscope {
namespace gl {

const Vector3 RGB_TEAL = {0., 178./255., 178./255.};
const Vector3 RGB_BLUE = {150./255., 154./255., 255./255.};
const Vector3 RGB_SKYBLUE = {152./255., 158./255., 200./255.};
const Vector3 RGB_ORANGE = {1., 0.5, 0.};
const Vector3 RGB_BLACK = {0., 0., 0.};
const Vector3 RGB_WHITE = {1., 1., 1.};
const Vector3 RGB_RED = {0.8, 0., 0.};
const Vector3 RGB_DARKGRAY = { .2, .2, .2 };
const Vector3 RGB_LIGHTGRAY = { .8, .8, .8 };
const Vector3 RGB_DARKRED = { .2, .0, .0 };
const Color3f RGB_TEAL = {0., 178./255., 178./255.};
const Color3f RGB_BLUE = {150./255., 154./255., 255./255.};
const Color3f RGB_SKYBLUE = {152./255., 158./255., 200./255.};
const Color3f RGB_ORANGE = {1., 0.5, 0.};
const Color3f RGB_BLACK = {0., 0., 0.};
const Color3f RGB_WHITE = {1., 1., 1.};
const Color3f RGB_RED = {0.8, 0., 0.};
const Color3f RGB_DARKGRAY = { .2, .2, .2 };
const Color3f RGB_LIGHTGRAY = { .8, .8, .8 };
const Color3f RGB_DARKRED = { .2, .0, .0 };

} // namespace gl
} // namespace polyscope
16 changes: 6 additions & 10 deletions include/polyscope/gl/gl_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
#include "polyscope/gl/shaders.h"
#include "polyscope/view.h"

#include "geometrycentral/utilities.h"
#include "geometrycentral/vector2.h"
#include "geometrycentral/vector3.h"

namespace polyscope {
namespace gl {

Expand Down Expand Up @@ -70,15 +66,15 @@ class GLProgram {
void setUniform(std::string name, float val);
void setUniform(std::string name, double val); // WARNING casts down to float
void setUniform(std::string name, float* val);
void setUniform(std::string name, Vector2 val);
void setUniform(std::string name, Vector3 val);
void setUniform(std::string name, glm::vec2 val);
void setUniform(std::string name, glm::vec3 val);
void setUniform(std::string name, std::array<float, 3> val);
void setUniform(std::string name, float x, float y, float z, float w);

// = Attributes
void setAttribute(std::string name, const std::vector<Vector2>& data, bool update = false, int offset = 0,
void setAttribute(std::string name, const std::vector<glm::vec2>& data, bool update = false, int offset = 0,
int size = -1);
void setAttribute(std::string name, const std::vector<Vector3>& data, bool update = false, int offset = 0,
void setAttribute(std::string name, const std::vector<glm::vec3>& data, bool update = false, int offset = 0,
int size = -1);
void setAttribute(std::string name, const std::vector<double>& data, bool update = false, int offset = 0,
int size = -1);
Expand All @@ -101,8 +97,8 @@ class GLProgram {


// Indices
void setIndex(std::vector<uint3> indices);
void setIndex(std::vector<unsigned int> indices);
void setIndex(std::vector<std::array<unsigned int, 3>>& indices);
void setIndex(std::vector<unsigned int>& indices);
void setPrimitiveRestartIndex(GLuint restartIndex);

// Call once to initialize GLSL code used by multiple shaders
Expand Down
11 changes: 5 additions & 6 deletions include/polyscope/point_cloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <vector>

#include "geometrycentral/vector3.h"
#include "polyscope/affine_remapper.h"
#include "polyscope/color_management.h"
#include "polyscope/gl/gl_utils.h"
Expand Down Expand Up @@ -56,7 +55,7 @@ class PointCloud : public Structure {
// === Member functions ===

// Construct a new point cloud structure
PointCloud(std::string name, const std::vector<geometrycentral::Vector3>& points);
PointCloud(std::string name, const std::vector<glm::vec3>& points);
~PointCloud();

// Render the the structure on screen
Expand All @@ -78,7 +77,7 @@ class PointCloud : public Structure {
virtual double lengthScale() override;

// Axis-aligned bounding box for the structure
virtual std::tuple<geometrycentral::Vector3, geometrycentral::Vector3> boundingBox() override;
virtual std::tuple<glm::vec3, glm::vec3> boundingBox() override;


// === Quantities
Expand All @@ -92,14 +91,14 @@ class PointCloud : public Structure {
void addScalarQuantity(std::string name, const std::vector<double>& value, DataType type = DataType::STANDARD);

// Colors
void addColorQuantity(std::string name, const std::vector<Vector3>& value);
void addColorQuantity(std::string name, const std::vector<glm::vec3>& value);

// Subsets
// void addSubsetQuantity(std::string name, const std::vector<char>& subsetIndicators);
// void addSubsetQuantity(std::string name, const std::vector<size_t>& subsetIndices);

// Vectors
void addVectorQuantity(std::string name, const std::vector<Vector3>& value,
void addVectorQuantity(std::string name, const std::vector<glm::vec3>& value,
VectorType vectorType = VectorType::STANDARD);


Expand All @@ -110,7 +109,7 @@ class PointCloud : public Structure {
void removeAllQuantities();

// The points that make up this point cloud
std::vector<geometrycentral::Vector3> points;
std::vector<glm::vec3> points;

// Misc data
bool enabled = true;
Expand Down
9 changes: 5 additions & 4 deletions include/polyscope/polyscope.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ extern std::map<std::string, std::map<std::string, Structure*>> structures;
extern double lengthScale;

// axis-aligned bounding box for all registered structures
extern std::tuple<geometrycentral::Vector3, geometrycentral::Vector3> boundingBox;
extern std::tuple<glm::vec3, glm::vec3> boundingBox;

// representative center for all registered structures
extern Vector3 center;
extern glm::vec3 center;

// A callback function used to render a "user" gui
extern std::function<void()> userCallback;
Expand All @@ -60,8 +60,9 @@ extern size_t screenshotInd;
// Register a structure with polyscope
// `name` is a globally unique identifier for the structure
bool registerStructure(Structure* structure, bool replaceIfPresent = true);
void registerPointCloud(std::string name, const std::vector<Vector3>& points, bool replaceIfPresent = true);
void registerSurfaceMesh(std::string name, Geometry<Euclidean>* geom, bool replaceIfPresent = true);
void registerPointCloud(std::string name, const std::vector<glm::vec3>& points, bool replaceIfPresent = true);
void registerSurfaceMesh(std::string name, const std::vector<glm::vec3>& vertexPositions,
const std::vector<std::vector<size_t>>& faceIndices, bool replaceIfPresent = true);
void registerCameraView(std::string name, CameraParameters p, bool replaceIfPresent = true);
void registerRaySet(std::string name, const std::vector<std::vector<RayPoint>>& r, bool replaceIfPresent = true);

Expand Down
7 changes: 3 additions & 4 deletions include/polyscope/ray_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

#include <vector>

#include "geometrycentral/vector3.h"
#include "polyscope/gl/gl_utils.h"
#include "polyscope/structure.h"
#include "polyscope/color_management.h"

namespace polyscope {

struct RayPoint {
RayPoint(geometrycentral::Vector3 v_, bool isInf = false)
RayPoint(glm::vec3 v_, bool isInf = false)
: v(v_), isInfiniteDirection(isInf) {}

geometrycentral::Vector3 v;
glm::vec3 v;

// if true, rather than being a point on a path this is a direction, along
// which the ray heads to infinity
Expand Down Expand Up @@ -47,7 +46,7 @@ class RaySet : public Structure {
virtual double lengthScale() override;

// Axis-aligned bounding box for the structure
virtual std::tuple<geometrycentral::Vector3, geometrycentral::Vector3>
virtual std::tuple<glm::vec3, glm::vec3>
boundingBox() override;

bool enabled = false;
Expand Down
4 changes: 2 additions & 2 deletions include/polyscope/ribbon_artist.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RibbonArtist {
// Input ribbon is a collection of lines; each line is a list of (position, normal) pairs.
// - normalOffsetFraction is an offset, relative to polyscope::state::lengthScale, along which ribbons are offset in
// the normal direction.
RibbonArtist(const std::vector<std::vector<std::array<geometrycentral::Vector3, 2>>>& ribbons,
RibbonArtist(const std::vector<std::vector<std::array<glm::vec3, 2>>>& ribbons,
double normalOffsetFraction = 1e-4);
~RibbonArtist();

Expand All @@ -27,7 +27,7 @@ class RibbonArtist {
private:

// Data
std::vector<std::vector<std::array<geometrycentral::Vector3, 2>>> ribbons;
std::vector<std::vector<std::array<glm::vec3, 2>>> ribbons;
double normalOffsetFraction;

gl::GLProgram* program = nullptr;
Expand Down
Loading

0 comments on commit e0ce26e

Please sign in to comment.