256 SM_MF_VEC_FIELD_TYPE &mfvecField,
258 bool duplicateColors=
false,
259 bool mapToRainbow=
false,
260 bool useCurvatureForColor=
false,
261 bool scaleFromInputRange=
false,
262 float inRangeMin=0.f,
263 float inRangeMax=1.f)
266 if (!scaleFromInputRange){
271 const float scaleWidth =
fabs(inRangeMax-inRangeMin) < 10e-6f ? 10e-6f : inRangeMax-inRangeMin;
272 const float scaleWidthInv = 1.f/scaleWidth;
275 const size_t numPoints = pointCloud.points.size();
276 if ((numPoints * (
CopyDataAndData_n == storageType ? 2 : 1)) <= ML_NAMESPACE::PCLSupportTools::getSigned32BitMaximumLimit()){
277 const unsigned int numPointsAsUInt = mlrange_cast<unsigned int>(numPoints);
280 mfvecField.setNum(mlrange_cast<int>(numPoints));
283 auto dataPtr = mfvecField.startEditing();
285 for (
unsigned int c=0; c < numPointsAsUInt; ++c){
289 mfvecField.finishEditing();
294 mfvecField.setNum(mlrange_cast<int>(numPoints * (duplicateColors ? 2u:1u)));
295 auto dataPtr = mfvecField.startEditing();
297 for (
unsigned int c=0; c < numPointsAsUInt; ++c){
298 const unsigned int rgbaVal = ML_NAMESPACE::PCLSupportTools::getPointRGBA(pointCloud.points[c]);
300 if (duplicateColors){
308 mfvecField.finishEditing();
314 mfvecField.setNum(mlrange_cast<int>(numPoints * (duplicateColors ? 2u:1u)));
315 auto dataPtr = mfvecField.startEditing();
318 float data[4]={0,0,0,255.9f};
323 const bool allChannelsAreTheSame = isRGBAAssignment && !useCurvatureForColor && !mapToRainbow;
325 float curvatureVal = 0.f;
326 for (
unsigned int c=0; c < numPointsAsUInt; ++c){
327 float dataVal = ML_NAMESPACE::PCLSupportTools::getIntensityReplacement(pointCloud.points[c]);
328 if (dataVal < inRangeMin){ dataVal = inRangeMin; }
329 else if (dataVal > inRangeMax){ dataVal = inRangeMax; }
330 if (scaleFromInputRange){
331 dataVal = (dataVal-inRangeMin)*scaleWidthInv;
334 if (!allChannelsAreTheSame){
336 float intensityVal = dataVal;
337 float alphaVal = dataVal;
340 if (useCurvatureForColor){
342 curvatureVal = ML_NAMESPACE::PCLSupportTools::getCurvature(pointCloud.points[c]);
343 if (curvatureVal < inRangeMin){ curvatureVal = inRangeMin; }
344 else if (curvatureVal > inRangeMax){ curvatureVal = inRangeMax; }
345 if (scaleFromInputRange){
346 curvatureVal = (curvatureVal-inRangeMin)*scaleWidthInv;
348 intensityVal = curvatureVal;
353 float retRGB[3]={0.f, 0.f, 0.f};
355 data[0] = retRGB[0]*255.999f;
356 data[1] = retRGB[1]*255.999f;
357 data[2] = retRGB[2]*255.999f;
361 data[0] = data[1] = data[2] = intensityVal*255.999f;
364 if (isRGBAAssignment){
366 data[3] = alphaVal*255.999f;
372 if (duplicateColors){
383 if (duplicateColors){
392 mfvecField.finishEditing();
397 mfvecField.setNum(mlrange_cast<int>(numPoints*2u));
398 auto dataPtr = mfvecField.startEditing();
399 for (
unsigned int c=0; c < numPointsAsUInt; ++c){
403 mfvecField.finishEditing();
408 "Bad enumerator value passed. Not setting any MField values.");
413 "Inventor cannot handle field sets with more than ML_INT32_MAX points which, "
414 "however, are required for the current input data conversion. Not setting the MField values.");
417 mfvecField.deleteValues(0);
419 return isSet ? numPoints : 0u;