26 m_showNaNValuesInGrey(true),
27 m_symmetricalScale(false),
29 m_alwaysShowZero(false),
30 m_colorScale(nullptr),
41 m_displayRange(sf.m_displayRange),
42 m_saturationRange(sf.m_saturationRange),
43 m_logSaturationRange(sf.m_logSaturationRange),
44 m_showNaNValuesInGrey(sf.m_showNaNValuesInGrey),
45 m_symmetricalScale(sf.m_symmetricalScale),
46 m_logScale(sf.m_logScale),
47 m_alwaysShowZero(sf.m_alwaysShowZero),
48 m_colorScale(sf.m_colorScale),
49 m_colorRampSteps(sf.m_colorRampSteps),
50 m_histogram(sf.m_histogram),
51 m_modified(sf.m_modified),
52 m_globalShift(sf.m_globalShift) {
60 return static_cast<ScalarType
>(-1);
69 return static_cast<ScalarType
>(1);
74 return static_cast<ScalarType
>(0.5);
78 return static_cast<ScalarType
>(1);
79 return (
static_cast<ScalarType
>(1) +
85 return (
static_cast<ScalarType
>(1) +
93 ScalarType dLog = log10(std::max(
static_cast<ScalarType
>(fabs(d)),
98 return static_cast<ScalarType
>(1);
105 return static_cast<ScalarType
>(-1);
111 bool isAbsolute = (scale && !scale->isRelative());
137 "[ccScalarField] Scalar field contains negative values! "
138 "Log scale will only consider absolute values...");
146 ScalarField::computeMinAndMax();
157 unsigned numberOfClasses =
static_cast<unsigned>(
159 numberOfClasses = std::max<unsigned>(
167 }
catch (
const std::bad_alloc&) {
169 "[ccScalarField::computeMinAndMax] Failed to update "
170 "associated histogram!");
179 ScalarType step =
static_cast<ScalarType
>(numberOfClasses) /
181 for (
unsigned i = 0; i <
count; ++i) {
182 const ScalarType& val =
getValue(i);
184 unsigned bin =
static_cast<unsigned>(
206 ScalarType minAbsVal =
208 : std::max<ScalarType>(
m_minVal, 0));
220 ScalarType minSatLog =
222 ScalarType maxSatLog =
231 double minVal = 0, maxVal = 0;
235 static_cast<ScalarType
>(maxVal));
240 ScalarType minAbsVal =
static_cast<ScalarType
>(
241 maxVal < 0 ? std::min(-maxVal, -minVal)
242 : std::max(minVal, 0.0));
243 ScalarType maxAbsVal =
static_cast<ScalarType
>(
244 std::max(fabs(minVal), fabs(maxVal)));
245 ScalarType minSatLog =
247 ScalarType maxSatLog =
296 assert(out.isOpen() && (out.openMode() & QIODevice::WriteOnly));
298 if (dataVersion < 20) {
307 if (!ccSerializationHelper::GenericArrayToFile<ScalarType, 1, ScalarType>(
313 if (out.write((
const char*)&dValue,
sizeof(
double)) < 0)
316 if (out.write((
const char*)&dValue,
sizeof(double)) < 0)
319 if (out.write((
const char*)&dValue,
sizeof(double)) < 0)
322 if (out.write((
const char*)&dValue,
sizeof(double)) < 0)
325 if (out.write((
const char*)&dValue,
sizeof(double)) < 0)
328 if (out.write((
const char*)&dValue,
sizeof(double)) < 0)
332 if (out.write((
const char*)&
m_logScale,
sizeof(bool)) < 0)
336 if (dataVersion >= 27) {
351 if (out.write((
const char*)&hasColorScale,
sizeof(bool)) < 0)
362 if (out.write((
const char*)&colorRampSteps, 4) < 0)
return WriteError();
365 if (dataVersion >= 42) {
366 if (out.write((
const char*)&
m_globalShift,
sizeof(
double)) < 0)
377 if (strlen(
m_name) > 255) {
379 minVersion = std::max(minVersion,
static_cast<short>(52));
385 minVersion = std::max(minVersion,
m_colorScale->minimumFileVersion());
394 assert(in.isOpen() && (in.openMode() & QIODevice::ReadOnly));
402 bool onlyPositiveValues =
false;
403 if (dataVersion < 26) {
404 if (in.read((
char*)&onlyPositiveValues,
sizeof(
bool)) < 0)
411 QString sfDescription =
"SF " + QString(
m_name);
412 double baseOffset = 0.0;
413 bool fileScalarIsFloat =
415 if (fileScalarIsFloat)
419 *
this, in, dataVersion, sfDescription);
425 ScalarType, 1, ScalarType,
double>(
426 *
this, in, dataVersion, sfDescription, &baseOffset);
435 if (dataVersion < 26) {
436 const ScalarType FORMER_BIG_VALUE =
437 static_cast<ScalarType
>(sqrt(3.4e38f) - 1.0f);
442 if ((onlyPositiveValues && val < 0) ||
443 (!onlyPositiveValues && val >= FORMER_BIG_VALUE)) {
452 double minDisplayed = 0;
453 if (in.read((
char*)&minDisplayed,
sizeof(
double)) < 0)
return ReadError();
454 double maxDisplayed = 0;
455 if (in.read((
char*)&maxDisplayed,
sizeof(
double)) < 0)
return ReadError();
456 double minSaturation = 0;
457 if (in.read((
char*)&minSaturation,
sizeof(
double)) < 0)
return ReadError();
458 double maxSaturation = 0;
459 if (in.read((
char*)&maxSaturation,
sizeof(
double)) < 0)
return ReadError();
460 double minLogSaturation = 0;
461 if (in.read((
char*)&minLogSaturation,
sizeof(
double)) < 0)
463 double maxLogSaturation = 0;
464 if (in.read((
char*)&maxLogSaturation,
sizeof(
double)) < 0)
467 if (dataVersion < 27) {
469 bool absSaturation =
false;
470 if (in.read((
char*)&absSaturation,
sizeof(
bool)) < 0)
477 if (in.read((
char*)&
m_logScale,
sizeof(
bool)) < 0) {
481 if (dataVersion < 27) {
482 bool autoBoundaries =
false;
484 if (in.read((
char*)&autoBoundaries,
sizeof(
bool)) < 0) {
488 if (!autoBoundaries) {
490 "[ccScalarField] Former 'released' boundaries are "
493 "[ccScalarField] You'll have to create the corresponding "
494 "'absolute' color scale (see the Color Scale Manager) and "
495 "replace the file.");
500 if (dataVersion >= 27) {
518 if (!colorScalesManager) {
520 "[ccScalarField::fromFile] Failed to access color scales "
526 if (dataVersion < 27) {
527 uint32_t activeColorScale = 0;
528 if (in.read((
char*)&activeColorScale, 4) < 0)
return ReadError();
533 switch (activeColorScale) {
551 "[ccScalarField::fromFile] Color scale is no more "
559 bool hasColorScale =
false;
560 if (in.read((
char*)&hasColorScale,
sizeof(
bool)) < 0)
565 if (!colorScale->fromFile(in, dataVersion, flags,
570 if (colorScalesManager) {
572 colorScalesManager->
getScale(colorScale->getUuid());
573 if (!existingColorScale) {
574 colorScalesManager->
addScale(colorScale);
590 uint32_t colorRampSteps = 0;
591 if (in.read((
char*)&colorRampSteps, 4) < 0)
return ReadError();
595 if (dataVersion >= 42) {
constexpr ScalarType ZERO_TOLERANCE_SCALAR
constexpr ScalarType NAN_VALUE
NaN as a ScalarType value.
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
static const unsigned DEFAULT_STEPS
Default number of steps for display.
static const unsigned MIN_STEPS
Minimum number of steps.
QSharedPointer< ccColorScale > Shared
Shared pointer type.
static ccColorScale::Shared Create(const QString &name)
Creates a new color scale (with auto-generated unique id)
static const unsigned MAX_STEPS
Maximum number of steps (internal representation)
Color scales manager/container.
ccColorScale::Shared getScale(QString UUID) const
Returns a color scale based on its UUID.
void addScale(ccColorScale::Shared scale)
Adds a new color scale.
static ccColorScale::Shared GetDefaultScale(DEFAULT_SCALES scale=BGYR)
Returns a pre-defined color scale (static shortcut)
DEFAULT_SCALES
Pre-defined color scales (all relative - i.e. expand to actual SF)
static ccColorScalesManager * GetUniqueInstance()
Returns unique instance.
void setStop(ScalarType value)
ScalarType maxRange() const
bool isInRange(ScalarType val) const
Returns whether a value is inside range or not.
void setBounds(ScalarType minVal, ScalarType maxVal, bool resetStartStop=true)
void setStart(ScalarType value)
A scalar field associated to display-related parameters.
const ccColorScale::Shared & getColorScale() const
Returns associated color scale.
Range m_logSaturationRange
saturation values range (log scale mode)
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.
double m_globalShift
Global shift.
short minimumFileVersion() const override
Returns the minimum file version required to save this instance.
void setMinDisplayed(ScalarType val)
Sets the minimum displayed value.
bool m_showNaNValuesInGrey
Whether NaN values are shown in grey or are hidden.
void updateSaturationBounds()
Updates saturation values.
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.
unsigned getColorRampSteps() const
Returns number of color ramp steps.
Range m_displayRange
Displayed values range.
void setLogScale(bool state)
Sets whether scale is logarithmic or not.
void setColorScale(ccColorScale::Shared scale)
Sets associated color scale.
bool toFile(QFile &out, short dataVersion) const override
Saves data to binary stream.
double getGlobalShift() const
Returns the global shift (if any)
Histogram m_histogram
Associated histogram values (for display)
void setSymmetricalScale(bool state)
Sets whether the color scale should be symmetrical or not.
bool fromFile(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads data from binary stream.
unsigned m_colorRampSteps
Number of color ramps steps (for display)
bool m_alwaysShowZero
Whether 0 should always appear in associated color ramp.
const Range & saturationRange() const
Access to the range of saturation values.
ScalarType normalize(ScalarType val) const
Normalizes a scalar value between 0 and 1 (wrt to current parameters)
bool m_symmetricalScale
Whether color scale is symmetrical or not.
void showNaNValuesInGrey(bool state)
const Range & displayRange() const
Access to the range of displayed values.
bool m_logScale
Whether scale is logarithmic or not.
void computeMinAndMax() override
Determines the min and max values.
bool symmetricalScale() const
Returns whether the color scale s symmetrical or not.
void importParametersFrom(const ccScalarField *sf)
Imports the parameters from another scalar field.
bool m_modified
Modification flag.
bool mayHaveHiddenValues() const
void setSaturationStart(ScalarType val)
Sets the value at which to start color gradient.
void setMaxDisplayed(ScalarType val)
Sets the maximum displayed value.
Range m_saturationRange
Saturation values range.
ccScalarField(const char *name=nullptr)
Default constructor.
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.
ccColorScale::Shared m_colorScale
Active color ramp (for display)
static bool CorruptError()
Sends a custom error message (corrupted file) and returns 'false'.
QMultiMap< unsigned, unsigned > LoadedIDMap
Map of loaded unique IDs (old ID --> new ID)
static bool ReadError()
Sends a custom error message (read error) and returns 'false'.
static bool WriteError()
Sends a custom error message (write error) and returns 'false'.
static bool GenericArrayFromFile(std::vector< Type > &data, QFile &in, short dataVersion, const QString &verboseDescription)
Helper: loads a vector structure from file.
static bool GenericArrayFromTypedFile(std::vector< Type > &data, QFile &in, short dataVersion, const QString &verboseDescription, FileComponentType *_autoOffset=nullptr)
A simple scalar field (to be associated to a point cloud)
ScalarType & getValue(std::size_t index)
char m_name[256]
Scalar field name.
ScalarType m_maxVal
Maximum value.
unsigned currentSize() const
ScalarType m_minVal
Minimum value.
const unsigned MAX_HISTOGRAM_SIZE
Default number of classes for associated histogram.
MiniVec< float, N > floor(const MiniVec< float, N > &a)
MiniVec< float, N > ceil(const MiniVec< float, N > &a)
Generic file read and write utility for python interface.
unsigned maxValue
Max histogram value.