Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions include/polyscope/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class Widget;
class TransformationGizmo;
class FloatingQuantityStructure;
namespace view {
extern const double defaultNearClipRatio;
extern const double defaultFarClipRatio;
extern const double defaultFov;
extern const float defaultNearClipRatio;
extern const float defaultFarClipRatio;
extern const float defaultFov;
} // namespace view

// A context object wrapping all global state used by Polyscope.
Expand Down Expand Up @@ -85,12 +85,13 @@ struct Context {
NavigateStyle navigateStyle = NavigateStyle::Turntable;
UpDir upDir = UpDir::YUp;
FrontDir frontDir = FrontDir::ZFront;
double moveScale = 1.0;
double nearClipRatio = view::defaultNearClipRatio;
double farClipRatio = view::defaultFarClipRatio;
float moveScale = 1.0;
ViewRelativeMode viewRelativeMode = ViewRelativeMode::CenterRelative;
float nearClip = view::defaultNearClipRatio;
float farClip = view::defaultFarClipRatio;
std::array<float, 4> bgColor{{1.0, 1.0, 1.0, 0.0}};
glm::mat4x4 viewMat{std::numeric_limits<float>::quiet_NaN()};
double fov = view::defaultFov;
float fov = view::defaultFov;
ProjectionMode projectionMode = ProjectionMode::Perspective;
glm::vec3 viewCenter;
bool midflight = false;
Expand Down
185 changes: 185 additions & 0 deletions include/polyscope/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,206 @@

#pragma once

#include "polyscope/utilities.h"

// Various types / enums / forward declarations which are broadly useful

// The string templates allow to/from string like:
// to_string(ProjectionMode::Perspective)
// from_string<ProjectionMode>("Perspective")
// bool success = try_from_string<ProjectionMode>("Perspective", val_out);
// see utilities.h for implementation

// clang-format off

namespace polyscope {

// Navigate Style
enum class NavigateStyle { Turntable = 0, Free, Planar, Arcball, None, FirstPerson };
POLYSCOPE_DEFINE_ENUM_NAMES(NavigateStyle,
{NavigateStyle::Turntable, "Turntable"},
{NavigateStyle::Free, "Free"},
{NavigateStyle::Planar, "Planar"},
{NavigateStyle::Arcball, "Arcball"},
{NavigateStyle::None, "None"},
{NavigateStyle::FirstPerson, "First Person"}
);

// Up Direction
enum class UpDir { XUp = 0, YUp, ZUp, NegXUp, NegYUp, NegZUp };
POLYSCOPE_DEFINE_ENUM_NAMES(UpDir,
{UpDir::XUp, "X Up"},
{UpDir::YUp, "Y Up"},
{UpDir::ZUp, "Z Up"},
{UpDir::NegXUp, "NegX Up"},
{UpDir::NegYUp, "NegY Up"},
{UpDir::NegZUp, "NegZ Up"},
);

enum class FrontDir { XFront = 0, YFront, ZFront, NegXFront, NegYFront, NegZFront };
POLYSCOPE_DEFINE_ENUM_NAMES(FrontDir,
{FrontDir::XFront, "X Forward"},
{FrontDir::YFront, "Y Forward"},
{FrontDir::ZFront, "Z Forward"},
{FrontDir::NegXFront, "NegX Forward"},
{FrontDir::NegYFront, "NegY Forward"},
{FrontDir::NegZFront, "NegZ Forward"},
);

enum class BackgroundView { None = 0 };
POLYSCOPE_DEFINE_ENUM_NAMES(BackgroundView,
{BackgroundView::None, "None"}
);


// Projection Mode
enum class ProjectionMode { Perspective = 0, Orthographic };
POLYSCOPE_DEFINE_ENUM_NAMES(ProjectionMode,
{ProjectionMode::Perspective, "Perspective"},
{ProjectionMode::Orthographic, "Orthographic"}
);

enum class ViewRelativeMode { CenterRelative = 0, LengthRelative };
POLYSCOPE_DEFINE_ENUM_NAMES(ViewRelativeMode,
{ViewRelativeMode::CenterRelative, "Center Relative"},
{ViewRelativeMode::LengthRelative, "Length Relative"}
);

enum class TransparencyMode { None = 0, Simple, Pretty };
POLYSCOPE_DEFINE_ENUM_NAMES(TransparencyMode,
{TransparencyMode::None, "None"},
{TransparencyMode::Simple, "Simple"},
{TransparencyMode::Pretty, "Pretty"}
);

enum class GroundPlaneMode { None, Tile, TileReflection, ShadowOnly };
POLYSCOPE_DEFINE_ENUM_NAMES(GroundPlaneMode,
{GroundPlaneMode::None, "None"},
{GroundPlaneMode::Tile, "Tile"},
{GroundPlaneMode::TileReflection, "Tile Reflection"},
{GroundPlaneMode::ShadowOnly, "Shadow Only"}
);

enum class GroundPlaneHeightMode { Automatic = 0, Manual };
POLYSCOPE_DEFINE_ENUM_NAMES(GroundPlaneHeightMode,
{GroundPlaneHeightMode::Automatic, "Automatic"},
{GroundPlaneHeightMode::Manual, "Manual"}
);

enum class BackFacePolicy { Identical, Different, Custom, Cull };
POLYSCOPE_DEFINE_ENUM_NAMES(BackFacePolicy,
{BackFacePolicy::Identical, "Identical"},
{BackFacePolicy::Different, "Different"},
{BackFacePolicy::Custom, "Custom"},
{BackFacePolicy::Cull, "Cull"}
);

enum class LimitFPSMode { IgnoreLimits = 0, BlockToHitTarget, SkipFramesToHitTarget };
POLYSCOPE_DEFINE_ENUM_NAMES(LimitFPSMode,
{LimitFPSMode::IgnoreLimits, "Ignore Limits"},
{LimitFPSMode::BlockToHitTarget, "Block To Hit Target"},
{LimitFPSMode::SkipFramesToHitTarget, "Skip Frames To Hit Target"}
);

enum class PointRenderMode { Sphere = 0, Quad };
POLYSCOPE_DEFINE_ENUM_NAMES(PointRenderMode,
{PointRenderMode::Sphere, "Sphere"},
{PointRenderMode::Quad, "Quad"}
);

enum class MeshElement { VERTEX = 0, FACE, EDGE, HALFEDGE, CORNER };
POLYSCOPE_DEFINE_ENUM_NAMES(MeshElement,
{MeshElement::VERTEX, "Vertex"},
{MeshElement::FACE, "Face"},
{MeshElement::EDGE, "Edge"},
{MeshElement::HALFEDGE, "Half-Edge"},
{MeshElement::CORNER, "Corner"}
);

enum class MeshShadeStyle { Smooth = 0, Flat, TriFlat };
POLYSCOPE_DEFINE_ENUM_NAMES(MeshShadeStyle,
{MeshShadeStyle::Smooth, "Smooth"},
{MeshShadeStyle::Flat, "Flat"},
{MeshShadeStyle::TriFlat, "Tri-Flat"}
);

enum class MeshSelectionMode { Auto = 0, VerticesOnly, FacesOnly };
POLYSCOPE_DEFINE_ENUM_NAMES(MeshSelectionMode,
{MeshSelectionMode::Auto, "Auto"},
{MeshSelectionMode::VerticesOnly, "Vertices Only"},
{MeshSelectionMode::FacesOnly, "Faces Only"}
);

enum class CurveNetworkElement { NODE = 0, EDGE };
POLYSCOPE_DEFINE_ENUM_NAMES(CurveNetworkElement,
{CurveNetworkElement::NODE, "Node"},
{CurveNetworkElement::EDGE, "Edge"}
);

enum class VolumeMeshElement { VERTEX = 0, EDGE, FACE, CELL };
POLYSCOPE_DEFINE_ENUM_NAMES(VolumeMeshElement,
{VolumeMeshElement::VERTEX, "Vertex"},
{VolumeMeshElement::EDGE, "Edge"},
{VolumeMeshElement::FACE, "Face"},
{VolumeMeshElement::CELL, "Cell"}
);

enum class VolumeCellType { TET = 0, HEX };
POLYSCOPE_DEFINE_ENUM_NAMES(VolumeCellType,
{VolumeCellType::TET, "Tet"},
{VolumeCellType::HEX, "Hex"}
);

enum class VolumeGridElement { NODE = 0, CELL };
POLYSCOPE_DEFINE_ENUM_NAMES(VolumeGridElement,
{VolumeGridElement::NODE, "Node"},
{VolumeGridElement::CELL, "Cell"}
);

enum class IsolineStyle { Stripe = 0, Contour };
POLYSCOPE_DEFINE_ENUM_NAMES(IsolineStyle,
{IsolineStyle::Stripe, "Stripe"},
{IsolineStyle::Contour, "Contour"}
);

enum class ImplicitRenderMode { SphereMarch, FixedStep };
POLYSCOPE_DEFINE_ENUM_NAMES(ImplicitRenderMode,
{ImplicitRenderMode::SphereMarch, "Sphere March"},
{ImplicitRenderMode::FixedStep, "Fixed Step"}
);

enum class ImageOrigin { LowerLeft, UpperLeft };
POLYSCOPE_DEFINE_ENUM_NAMES(ImageOrigin,
{ImageOrigin::LowerLeft, "Lower Left"},
{ImageOrigin::UpperLeft, "Upper Left"}
);

enum class FilterMode { Nearest = 0, Linear };
POLYSCOPE_DEFINE_ENUM_NAMES(FilterMode,
{FilterMode::Nearest, "Nearest"},
{FilterMode::Linear, "Linear"}
);

enum class ParamCoordsType { UNIT = 0, WORLD }; // UNIT -> [0,1], WORLD -> length-valued
POLYSCOPE_DEFINE_ENUM_NAMES(ParamCoordsType,
{ParamCoordsType::UNIT, "Unit"},
{ParamCoordsType::WORLD, "World"}
);

enum class ParamVizStyle {
CHECKER = 0,
GRID,
LOCAL_CHECK,
LOCAL_RAD,
CHECKER_ISLANDS
}; // TODO add "UV" with test UV map
POLYSCOPE_DEFINE_ENUM_NAMES(ParamVizStyle,
{ParamVizStyle::CHECKER, "Checker"},
{ParamVizStyle::GRID, "Grid"},
{ParamVizStyle::LOCAL_CHECK, "Local Check"},
{ParamVizStyle::LOCAL_RAD, "Local Rad"},
{ParamVizStyle::CHECKER_ISLANDS, "Checker Islands"}
);

enum class ManagedBufferType {
Float,
Expand All @@ -55,6 +218,21 @@ enum class ManagedBufferType {
UVec3,
UVec4
};
POLYSCOPE_DEFINE_ENUM_NAMES(ManagedBufferType,
{ManagedBufferType::Float, "Float"},
{ManagedBufferType::Double, "Double"},
{ManagedBufferType::Vec2, "Vec2"},
{ManagedBufferType::Vec3, "Vec3"},
{ManagedBufferType::Vec4, "Vec4"},
{ManagedBufferType::Arr2Vec3, "Arr2Vec3"},
{ManagedBufferType::Arr3Vec3, "Arr3Vec3"},
{ManagedBufferType::Arr4Vec3, "Arr4Vec3"},
{ManagedBufferType::UInt32, "UInt32"},
{ManagedBufferType::Int32, "Int32"},
{ManagedBufferType::UVec2, "UVec2"},
{ManagedBufferType::UVec3, "UVec3"},
{ManagedBufferType::UVec4, "UVec4"}
);


// What is the meaningful range of these values?
Expand All @@ -64,6 +242,13 @@ enum class ManagedBufferType {
// MAGNITUDE: [0, inf], zero is special (ie, length of a vector)
// CATEGORICAL: data is integers corresponding to labels, etc
enum class DataType { STANDARD = 0, SYMMETRIC, MAGNITUDE, CATEGORICAL };
POLYSCOPE_DEFINE_ENUM_NAMES(DataType,
{DataType::STANDARD, "Standard"},
{DataType::SYMMETRIC, "Symmetric"},
{DataType::MAGNITUDE, "Magnitude"},
{DataType::CATEGORICAL, "Categorical"}
);

// clang-format on

}; // namespace polyscope
79 changes: 78 additions & 1 deletion include/polyscope/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <string>
#include <tuple>


#include <glm/glm.hpp>


Expand Down Expand Up @@ -166,6 +165,84 @@ inline double randomNormal(double mean = 0.0, double stddev = 1.0) {
return dist(util_mersenne_twister);
}

// === Helpers for enum to/from string
template <typename E>
struct EnumMapping {
E value;
const char* name;
};

// Forward declaration
template <typename E>
struct EnumTraits;

// Convert enum to string
template <typename E>
std::string enum_to_string(E value) {
const EnumMapping<E>* mappings = EnumTraits<E>::get_mappings();
size_t count = EnumTraits<E>::get_count();

for (size_t i = 0; i < count; i++) {
if (mappings[i].value == value) {
return mappings[i].name;
}
}

throw std::invalid_argument("Unknown enum value");
}

// Convert string to enum
template <typename E>
E from_string(const std::string& str) {
const EnumMapping<E>* mappings = EnumTraits<E>::get_mappings();
size_t count = EnumTraits<E>::get_count();

for (size_t i = 0; i < count; i++) {
if (mappings[i].name == str) {
return mappings[i].value;
}
}

std::stringstream ss;
ss << "Unknown enum string: " << str << ". Valid options are: ";
for (size_t i = 0; i < count; i++) {
ss << mappings[i].name;
if (i < count - 1) {
ss << ", ";
}
}
throw std::invalid_argument(ss.str());
}

// Safe conversion - returns true if successful
template <typename E>
bool try_enum_from_string(const std::string& str, E& out) {
const EnumMapping<E>* mappings = EnumTraits<E>::get_mappings();
size_t count = EnumTraits<E>::get_count();
for (size_t i = 0; i < count; i++) {
if (mappings[i].name == str) {
out = mappings[i].value;
return true;
}
}
return false;
}

// Macro to define enum traits - use inside namespace
#define POLYSCOPE_DEFINE_ENUM_NAMES(EnumType, ...) \
template <> \
struct EnumTraits<EnumType> { \
static const EnumMapping<EnumType>* get_mappings() { \
static const EnumMapping<EnumType> mappings[] = {__VA_ARGS__}; \
return mappings; \
} \
static size_t get_count() { \
static const EnumMapping<EnumType> mappings[] = {__VA_ARGS__}; \
return sizeof(mappings) / sizeof(mappings[0]); \
} \
};


// === ImGui utilities

// Displays a little helper icon which shows the text on hover
Expand Down
Loading