Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store scalar buffers as float32 for consistency with others #242

Merged
merged 2 commits into from
Nov 26, 2023
Merged
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
4 changes: 2 additions & 2 deletions include/polyscope/curve_network.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ class CurveNetwork : public QuantityStructure<CurveNetwork> {

// === Quantity adder implementations
// clang-format off
CurveNetworkNodeScalarQuantity* addNodeScalarQuantityImpl(std::string name, const std::vector<double>& data, DataType type);
CurveNetworkEdgeScalarQuantity* addEdgeScalarQuantityImpl(std::string name, const std::vector<double>& data, DataType type);
CurveNetworkNodeScalarQuantity* addNodeScalarQuantityImpl(std::string name, const std::vector<float>& data, DataType type);
CurveNetworkEdgeScalarQuantity* addEdgeScalarQuantityImpl(std::string name, const std::vector<float>& data, DataType type);
CurveNetworkNodeColorQuantity* addNodeColorQuantityImpl(std::string name, const std::vector<glm::vec3>& colors);
CurveNetworkEdgeColorQuantity* addEdgeColorQuantityImpl(std::string name, const std::vector<glm::vec3>& colors);
CurveNetworkNodeVectorQuantity* addNodeVectorQuantityImpl(std::string name, const std::vector<glm::vec3>& vectors, VectorType vectorType);
Expand Down
4 changes: 2 additions & 2 deletions include/polyscope/curve_network.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ CurveNetworkEdgeColorQuantity* CurveNetwork::addEdgeColorQuantity(std::string na
template <class T>
CurveNetworkNodeScalarQuantity* CurveNetwork::addNodeScalarQuantity(std::string name, const T& data, DataType type) {
validateSize(data, nNodes(), "curve network node scalar quantity " + name);
return addNodeScalarQuantityImpl(name, standardizeArray<double, T>(data), type);
return addNodeScalarQuantityImpl(name, standardizeArray<float, T>(data), type);
}

template <class T>
CurveNetworkEdgeScalarQuantity* CurveNetwork::addEdgeScalarQuantity(std::string name, const T& data, DataType type) {
validateSize(data, nEdges(), "curve network edge scalar quantity " + name);
return addEdgeScalarQuantityImpl(name, standardizeArray<double, T>(data), type);
return addEdgeScalarQuantityImpl(name, standardizeArray<float, T>(data), type);
}


Expand Down
6 changes: 3 additions & 3 deletions include/polyscope/curve_network_scalar_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace polyscope {
class CurveNetworkScalarQuantity : public CurveNetworkQuantity, public ScalarQuantity<CurveNetworkScalarQuantity> {
public:
CurveNetworkScalarQuantity(std::string name, CurveNetwork& network_, std::string definedOn,
const std::vector<double>& values, DataType dataType);
const std::vector<float>& values, DataType dataType);

virtual void draw() override;
virtual void buildCustomUI() override;
Expand All @@ -36,7 +36,7 @@ class CurveNetworkScalarQuantity : public CurveNetworkQuantity, public ScalarQua

class CurveNetworkNodeScalarQuantity : public CurveNetworkScalarQuantity {
public:
CurveNetworkNodeScalarQuantity(std::string name, const std::vector<double>& values_, CurveNetwork& network_,
CurveNetworkNodeScalarQuantity(std::string name, const std::vector<float>& values_, CurveNetwork& network_,
DataType dataType_ = DataType::STANDARD);

virtual void createProgram() override;
Expand All @@ -51,7 +51,7 @@ class CurveNetworkNodeScalarQuantity : public CurveNetworkScalarQuantity {

class CurveNetworkEdgeScalarQuantity : public CurveNetworkScalarQuantity {
public:
CurveNetworkEdgeScalarQuantity(std::string name, const std::vector<double>& values_, CurveNetwork& network_,
CurveNetworkEdgeScalarQuantity(std::string name, const std::vector<float>& values_, CurveNetwork& network_,
DataType dataType_ = DataType::STANDARD);

virtual void createProgram() override;
Expand Down
6 changes: 3 additions & 3 deletions include/polyscope/histogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ namespace polyscope {
// A histogram that shows up in ImGUI
class Histogram {
public:
Histogram(); // must call buildHistogram() with data after
Histogram(std::vector<double>& values); // internally calls buildHistogram()
Histogram(); // must call buildHistogram() with data after
Histogram(std::vector<float>& values); // internally calls buildHistogram()

~Histogram();

void buildHistogram(const std::vector<double>& values);
void buildHistogram(const std::vector<float>& values);
void updateColormap(const std::string& newColormap);

// Width = -1 means set automatically
Expand Down
6 changes: 1 addition & 5 deletions include/polyscope/implicit_helpers.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,7 @@ ScalarRenderImageQuantity* renderImplicitSurfaceScalarBatch(QuantityStructure<S>
// rather than creating a whole new one

// here, we bypass the conversion adaptor since we have explicitly filled matching types
std::vector<double> scalarOutD(rayPosOut.size());
for (size_t i = 0; i < scalarOut.size(); i++) {
scalarOutD[i] = scalarOut[i];
}
return parent->addScalarRenderImageQuantityImpl(name, opts.dimX, opts.dimY, rayDepthOut, normalOut, scalarOutD,
return parent->addScalarRenderImageQuantityImpl(name, opts.dimX, opts.dimY, rayDepthOut, normalOut, scalarOut,
ImageOrigin::UpperLeft, dataType);
}

Expand Down
2 changes: 1 addition & 1 deletion include/polyscope/point_cloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class PointCloud : public QuantityStructure<PointCloud> {
void ensurePickProgramPrepared();

// === Quantity adder implementations
PointCloudScalarQuantity* addScalarQuantityImpl(std::string name, const std::vector<double>& data, DataType type);
PointCloudScalarQuantity* addScalarQuantityImpl(std::string name, const std::vector<float>& data, DataType type);
PointCloudParameterizationQuantity*
addParameterizationQuantityImpl(std::string name, const std::vector<glm::vec2>& param, ParamCoordsType type);
PointCloudParameterizationQuantity*
Expand Down
2 changes: 1 addition & 1 deletion include/polyscope/point_cloud.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ PointCloudColorQuantity* PointCloud::addColorQuantity(std::string name, const T&
template <class T>
PointCloudScalarQuantity* PointCloud::addScalarQuantity(std::string name, const T& data, DataType type) {
validateSize(data, nPoints(), "point cloud scalar quantity " + name);
return addScalarQuantityImpl(name, standardizeArray<double, T>(data), type);
return addScalarQuantityImpl(name, standardizeArray<float, T>(data), type);
}


Expand Down
2 changes: 1 addition & 1 deletion include/polyscope/point_cloud_scalar_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace polyscope {
class PointCloudScalarQuantity : public PointCloudQuantity, public ScalarQuantity<PointCloudScalarQuantity> {

public:
PointCloudScalarQuantity(std::string name, const std::vector<double>& values, PointCloud& pointCloud_,
PointCloudScalarQuantity(std::string name, const std::vector<float>& values, PointCloud& pointCloud_,
DataType dataType);

virtual void draw() override;
Expand Down
2 changes: 1 addition & 1 deletion include/polyscope/scalar_image_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace polyscope {
class ScalarImageQuantity : public ImageQuantity, public ScalarQuantity<ScalarImageQuantity> {

public:
ScalarImageQuantity(Structure& parent_, std::string name, size_t dimX, size_t dimY, const std::vector<double>& data,
ScalarImageQuantity(Structure& parent_, std::string name, size_t dimX, size_t dimY, const std::vector<float>& data,
ImageOrigin imageOrigin, DataType dataType);

virtual void buildCustomUI() override;
Expand Down
6 changes: 3 additions & 3 deletions include/polyscope/scalar_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace polyscope {
template <typename QuantityT>
class ScalarQuantity {
public:
ScalarQuantity(QuantityT& quantity, const std::vector<double>& values, DataType dataType);
ScalarQuantity(QuantityT& quantity, const std::vector<float>& values, DataType dataType);

// Build the ImGUI UIs for scalars
void buildScalarUI();
Expand All @@ -38,7 +38,7 @@ class ScalarQuantity {

// Wrapper around the actual buffer of scalar data stored in the class.
// Interaction with the data (updating it on CPU or GPU side, accessing it, etc) happens through this wrapper.
render::ManagedBuffer<double> values;
render::ManagedBuffer<float> values;

// === Get/set visualization parameters

Expand All @@ -61,7 +61,7 @@ class ScalarQuantity {
double getIsolineDarkness();

protected:
std::vector<double> valuesData;
std::vector<float> valuesData;
const DataType dataType;

// === Visualization parameters
Expand Down
4 changes: 2 additions & 2 deletions include/polyscope/scalar_quantity.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace polyscope {

template <typename QuantityT>
ScalarQuantity<QuantityT>::ScalarQuantity(QuantityT& quantity_, const std::vector<double>& values_, DataType dataType_)
ScalarQuantity<QuantityT>::ScalarQuantity(QuantityT& quantity_, const std::vector<float>& values_, DataType dataType_)
: quantity(quantity_), values(&quantity, quantity.uniquePrefix() + "values", valuesData), valuesData(values_),
dataType(dataType_), dataRange(robustMinMax(values.data, 1e-5)),
cMap(quantity.uniquePrefix() + "cmap", defaultColorMap(dataType)),
Expand Down Expand Up @@ -194,7 +194,7 @@ template <typename QuantityT>
template <class V>
void ScalarQuantity<QuantityT>::updateData(const V& newValues) {
validateSize(newValues, values.size(), "scalar quantity " + quantity.name);
values.data = standardizeArray<double, V>(newValues);
values.data = standardizeArray<float, V>(newValues);
values.markHostBufferUpdated();
}

Expand Down
4 changes: 2 additions & 2 deletions include/polyscope/scalar_render_image_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ScalarRenderImageQuantity : public RenderImageQuantityBase, public ScalarQ
public:
ScalarRenderImageQuantity(Structure& parent_, std::string name, size_t dimX, size_t dimY,
const std::vector<float>& depthData, const std::vector<glm::vec3>& normalData,
const std::vector<double>& scalarData, ImageOrigin imageOrigin, DataType dataType);
const std::vector<float>& scalarData, ImageOrigin imageOrigin, DataType dataType);

virtual void draw() override;
virtual void drawDelayed() override;
Expand Down Expand Up @@ -52,7 +52,7 @@ void ScalarRenderImageQuantity::updateBuffers(const T1& depthData, const T2& nor
// standardize
std::vector<float> standardDepth(standardizeArray<float>(depthData));
std::vector<glm::vec3> standardNormal(standardizeVectorArray<glm::vec3, 3>(normalData));
std::vector<double> standardScalar(standardizeArray<double>(scalarData));
std::vector<float> standardScalar(standardizeArray<float>(scalarData));

values.data = standardScalar;
values.markHostBufferUpdated();
Expand Down
4 changes: 2 additions & 2 deletions include/polyscope/structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class QuantityStructure : public Structure {

// === Floating Quantity impls
ScalarImageQuantity* addScalarImageQuantityImpl(std::string name, size_t dimX, size_t dimY,
const std::vector<double>& values, ImageOrigin imageOrigin,
const std::vector<float>& values, ImageOrigin imageOrigin,
DataType type);

ColorImageQuantity* addColorImageQuantityImpl(std::string name, size_t dimX, size_t dimY,
Expand All @@ -270,7 +270,7 @@ class QuantityStructure : public Structure {
ScalarRenderImageQuantity* addScalarRenderImageQuantityImpl(std::string name, size_t dimX, size_t dimY,
const std::vector<float>& depthData,
const std::vector<glm::vec3>& normalData,
const std::vector<double>& scalarData,
const std::vector<float>& scalarData,
ImageOrigin imageOrigin, DataType type);

RawColorRenderImageQuantity* addRawColorRenderImageQuantityImpl(std::string name, size_t dimX, size_t dimY,
Expand Down
12 changes: 6 additions & 6 deletions include/polyscope/structure.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ ScalarImageQuantity* QuantityStructure<S>::addScalarImageQuantity(std::string na
const T& values, ImageOrigin imageOrigin,
DataType type) {
validateSize(values, dimX * dimY, "floating scalar image " + name);
return this->addScalarImageQuantityImpl(name, dimX, dimY, standardizeArray<double, T>(values), imageOrigin, type);
return this->addScalarImageQuantityImpl(name, dimX, dimY, standardizeArray<float, T>(values), imageOrigin, type);
}


Expand Down Expand Up @@ -271,7 +271,7 @@ QuantityStructure<S>::addScalarRenderImageQuantity(std::string name, size_t dimX
// standardize
std::vector<float> standardDepth(standardizeArray<float>(depthData));
std::vector<glm::vec3> standardNormal(standardizeVectorArray<glm::vec3, 3>(normalData));
std::vector<double> standardScalar(standardizeArray<double>(scalarData));
std::vector<float> standardScalar(standardizeArray<float>(scalarData));

return this->addScalarRenderImageQuantityImpl(name, dimX, dimY, standardDepth, standardNormal, standardScalar,
imageOrigin, type);
Expand Down Expand Up @@ -314,7 +314,7 @@ RawColorAlphaRenderImageQuantity* QuantityStructure<S>::addRawColorAlphaRenderIm
// Otherwise, we would have to include their respective headers here, and create some really gnarly header dependency
// chains.
ScalarImageQuantity* createScalarImageQuantity(Structure& parent, std::string name, size_t dimX, size_t dimY,
const std::vector<double>& data, ImageOrigin imageOrigin,
const std::vector<float>& data, ImageOrigin imageOrigin,
DataType dataType);
ColorImageQuantity* createColorImageQuantity(Structure& parent, std::string name, size_t dimX, size_t dimY,
const std::vector<glm::vec4>& data, ImageOrigin imageOrigin);
Expand Down Expand Up @@ -342,12 +342,12 @@ RawColorAlphaRenderImageQuantity* createRawColorAlphaRenderImage(Structure& pare
ScalarRenderImageQuantity* createScalarRenderImage(Structure& parent, std::string name, size_t dimX, size_t dimY,
const std::vector<float>& depthData,
const std::vector<glm::vec3>& normalData,
const std::vector<double>& scalarData, ImageOrigin imageOrigin,
const std::vector<float>& scalarData, ImageOrigin imageOrigin,
DataType type);

template <typename S>
ScalarImageQuantity* QuantityStructure<S>::addScalarImageQuantityImpl(std::string name, size_t dimX, size_t dimY,
const std::vector<double>& values,
const std::vector<float>& values,
ImageOrigin imageOrigin, DataType type) {
checkForQuantityWithNameAndDeleteOrError(name);
ScalarImageQuantity* q = createScalarImageQuantity(*this, name, dimX, dimY, values, imageOrigin, type);
Expand Down Expand Up @@ -389,7 +389,7 @@ ColorRenderImageQuantity* QuantityStructure<S>::addColorRenderImageQuantityImpl(
template <typename S>
ScalarRenderImageQuantity* QuantityStructure<S>::addScalarRenderImageQuantityImpl(
std::string name, size_t dimX, size_t dimY, const std::vector<float>& depthData,
const std::vector<glm::vec3>& normalData, const std::vector<double>& scalarData, ImageOrigin imageOrigin,
const std::vector<glm::vec3>& normalData, const std::vector<float>& scalarData, ImageOrigin imageOrigin,
DataType type) {
checkForQuantityWithNameAndDeleteOrError(name);
ScalarRenderImageQuantity* q =
Expand Down
Loading