MCPcopy Create free account
hub / github.com/CloudCompare/CloudCompare / sfAddConstant

Function sfAddConstant

qCC/ccEntityAction.cpp:1175–1249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1173 }
1174
1175 bool sfAddConstant(ccPointCloud* cloud, QString sfName, bool integerValue, QWidget* parent/*=nullptr*/)
1176 {
1177 if (!cloud)
1178 {
1179 assert(false);
1180 return false;
1181 }
1182
1183 if (sfName.isNull())
1184 {
1185 ccLog::Error(QT_TR_NOOP("Invalid name"));
1186 return false;
1187 }
1188
1189 if (cloud->getScalarFieldIndexByName(qPrintable(sfName)) >= 0)
1190 {
1191 ccLog::Error(QT_TR_NOOP("A SF with a similar name already exists!"));
1192 return false;
1193 }
1194
1195 ScalarType sfValue = 0;
1196 bool ok = false;
1197 if (integerValue)
1198 {
1199 static int s_constantIntSFValue = 0;
1200 int iValue = QInputDialog::getInt(parent, QT_TR_NOOP("Add classification SF"), QT_TR_NOOP("value"), s_constantIntSFValue, -1000000, 1000000, 1, &ok);
1201 if (ok)
1202 {
1203 s_constantIntSFValue = iValue;
1204 sfValue = static_cast<ScalarType>(iValue);
1205 }
1206 }
1207 else
1208 {
1209 static double s_constantDoubleSFValue = 0.0;
1210 double dValue = static_cast<ScalarType>(QInputDialog::getDouble(parent, QT_TR_NOOP("Add constant value"), QT_TR_NOOP("value"), s_constantDoubleSFValue, -1.0e9, 1.0e9, 8, &ok));
1211 if (ok)
1212 {
1213 s_constantDoubleSFValue = dValue;
1214 sfValue = static_cast<ScalarType>(dValue);
1215 }
1216 }
1217
1218 if (!ok)
1219 {
1220 // cancelled by the user
1221 return false;
1222 }
1223
1224 int sfIdx = cloud->getScalarFieldIndexByName(qPrintable(sfName));
1225 if (sfIdx < 0)
1226 sfIdx = cloud->addScalarField(qPrintable(sfName));
1227 if (sfIdx < 0)
1228 {
1229 ccLog::Error(QT_TR_NOOP("An error occurred! (see console)"));
1230 return false;
1231 }
1232

Callers 2

doActionAddConstantSFMethod · 0.85

Calls 7

isNullMethod · 0.80
addScalarFieldMethod · 0.80
computeMinAndMaxMethod · 0.80
showSFMethod · 0.80
fillMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected