ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ccScalarField.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include <pybind11/pybind11.h>
9 #include <pybind11/stl.h>
10 #include <pybind11/stl_bind.h>
11 
12 #include <ecvScalarField.h>
13 
14 #include "../../cccorelib/src/wrappers.h"
15 
16 namespace py = pybind11;
17 using namespace pybind11::literals;
18 
19 void define_ccScalarField(py::module &m)
20 {
21  py::class_<ccScalarField, cloudViewer::ScalarField, CCShareableHolder<ccScalarField>>
22  pyScalarField(m, "ccScalarField");
23 
24  py::class_<ccScalarField::Range>(pyScalarField, "Range")
25  .def(py::init<>())
26  .def("min", &ccScalarField::Range::min)
27  .def("start", &ccScalarField::Range::start)
28  .def("stop", &ccScalarField::Range::stop)
29  .def("max", &ccScalarField::Range::max)
30  .def("range", &ccScalarField::Range::range)
31  .def("maxRange", &ccScalarField::Range::maxRange)
32  .def("setBounds",
34  "minVal"_a,
35  "maxVal"_a,
36  "resetStartStop"_a = true)
37  .def("setStart", &ccScalarField::Range::setStart, "value"_a)
38  .def("setStop", &ccScalarField::Range::setStop, "value"_a)
39  .def("inbound", &ccScalarField::Range::inbound, "value"_a)
40  .def("isInbound", &ccScalarField::Range::isInbound, "value"_a)
41  .def("isInRange", &ccScalarField::Range::isInRange, "value"_a);
42 
43  pyScalarField.def("displayRange", &ccScalarField::displayRange)
44  .def("saturationRange", &ccScalarField::saturationRange)
45  .def("logSaturationRange", &ccScalarField::logSaturationRange)
46  .def("setMinDisplayed", &ccScalarField::setMinDisplayed, "value"_a)
47  .def("setMaxDisplayed", &ccScalarField::setMaxDisplayed, "value"_a)
48  .def("setSaturationStart", &ccScalarField::setSaturationStart, "value"_a)
49  .def("setSaturationStop", &ccScalarField::setSaturationStop, "value"_a)
50  .def("getColor",
52  "value"_a,
53  py::return_value_policy::reference_internal)
54  .def("getValueColor",
56  "index"_a,
57  py::return_value_policy::reference_internal)
58  .def("showNaNValuesInGrey", &ccScalarField::showNaNValuesInGrey, "state"_a)
59  .def("areNaNValuesShownInGrey", &ccScalarField::areNaNValuesShownInGrey)
60  .def("alwaysShowZero", &ccScalarField::alwaysShowZero, "state"_a)
61  .def("isZeroAlwaysShown", &ccScalarField::isZeroAlwaysShown)
62  .def("setSymmetricalScale", &ccScalarField::setSymmetricalScale, "state"_a)
63  .def("symmetricalScale", &ccScalarField::symmetricalScale)
64  .def("setLogScale", &ccScalarField::setLogScale, "state"_a)
65  .def("logScale", &ccScalarField::logScale)
66  .def("getColorScale", &ccScalarField::getColorScale)
67  .def("setColorScale", &ccScalarField::setColorScale, "scale"_a)
68  .def("getColorRampSteps", &ccScalarField::getColorRampSteps)
69  .def("setColorRampSteps", &ccScalarField::setColorRampSteps, "steps"_a)
70  .def("getHistogram",
71  [](const ccScalarField &sf)
72  {
73  // To keep the bindings manageable, we make this wrapper for
74  // getHistogram returns the std::vector<unsigned> and not the
75  // `Histogram` class that inherits from it.
76  // Because if we were to return a `Histogram` instance, we would need to wrap
77  // this class and use py::bind_vector, but doing seems to cause problems
78  // about because the std::vector<unsigned> is bound multiple times.
79  //
80  // We could also not use py::bind_vector and write more .def in the Histogram
81  // class but we chose not to.
82  //
83  // And as the Histogram class does not offer anything significant we just
84  // return the vector directly and pybind will convert it to a list.
85  const ccScalarField::Histogram &hist = sf.getHistogram();
86 
87  const std::vector<unsigned> bins = hist;
88  return bins;
89  })
90  .def("mayHaveHiddenValues", &ccScalarField::mayHaveHiddenValues)
91  .def("setModificationFlag", &ccScalarField::setModificationFlag, "state"_a)
92  .def("getModificationFlag", &ccScalarField::getModificationFlag)
93  .def("importParametersFrom", &ccScalarField::importParametersFrom, "sf"_a)
94  .def("getGlobalShift", &ccScalarField::getGlobalShift)
95  .def("setGlobalShift", &ccScalarField::setGlobalShift, "state"_a);
96 }
void define_ccScalarField(py::module &m)
void setStop(ScalarType value)
ScalarType stop() const
bool isInbound(ScalarType val) const
Returns whether a value is inbound or not.
ScalarType min() const
ScalarType maxRange() const
ScalarType inbound(ScalarType val) const
Returns the nearest inbound value.
bool isInRange(ScalarType val) const
Returns whether a value is inside range or not.
ScalarType max() const
void setBounds(ScalarType minVal, ScalarType maxVal, bool resetStartStop=true)
void setStart(ScalarType value)
ScalarType range() const
ScalarType start() const
A scalar field associated to display-related parameters.
const ccColorScale::Shared & getColorScale() const
Returns associated color scale.
void setSaturationStop(ScalarType val)
Sets the value at which to stop color gradient.
void setColorRampSteps(unsigned steps)
Sets number of color ramp steps used for display.
bool getModificationFlag() const
Returns modification flag state.
void setMinDisplayed(ScalarType val)
Sets the minimum displayed value.
bool logScale() const
Returns whether scalar field is logarithmic or not.
void alwaysShowZero(bool state)
Sets whether 0 should always appear in associated color ramp or not.
void setGlobalShift(double shift)
Sets the global shift.
unsigned getColorRampSteps() const
Returns number of color ramp steps.
void setLogScale(bool state)
Sets whether scale is logarithmic or not.
void setColorScale(ccColorScale::Shared scale)
Sets associated color scale.
double getGlobalShift() const
Returns the global shift (if any)
void setSymmetricalScale(bool state)
Sets whether the color scale should be symmetrical or not.
const Range & saturationRange() const
Access to the range of saturation values.
const Histogram & getHistogram() const
Returns associated histogram values (for display)
void showNaNValuesInGrey(bool state)
const Range & displayRange() const
Access to the range of displayed values.
const ecvColor::Rgb * getColor(ScalarType value) const
void setModificationFlag(bool state)
Sets modification flag state.
bool symmetricalScale() const
Returns whether the color scale s symmetrical or not.
const Range & logSaturationRange() const
Access to the range of log scale saturation values.
void importParametersFrom(const ccScalarField *sf)
Imports the parameters from another scalar field.
bool mayHaveHiddenValues() const
const ecvColor::Rgb * getValueColor(unsigned index) const
Shortcut to getColor.
void setSaturationStart(ScalarType val)
Sets the value at which to start color gradient.
void setMaxDisplayed(ScalarType val)
Sets the maximum displayed value.
bool areNaNValuesShownInGrey() const
Returns whether NaN values are displayed in gray or hidden.
bool isZeroAlwaysShown() const
Returns whether 0 should always appear in associated color ramp or not.
Simple histogram structure.