5 #include <RobotAPI/interface/ArViz/Elements.h>
7 #include <Inventor/nodes/SoCoordinate3.h>
8 #include <Inventor/nodes/SoDrawStyle.h>
9 #include <Inventor/nodes/SoMaterialBinding.h>
10 #include <Inventor/nodes/SoPointSet.h>
12 #include <x86intrin.h>
24 SoMaterialBinding* pclMatBind =
new SoMaterialBinding;
25 pclMatBind->value = SoMaterialBinding::PER_PART;
31 node->addChild(pclMatBind);
34 node->addChild(
new SoPointSet);
40 data::ColoredPoint
const* pclData = (data::ColoredPoint
const*)element.points.data();
41 int pclSize = element.points.size() /
sizeof(data::ColoredPoint);
43 int singleBufferSize = pclSize * 3;
44 buffer.resize(singleBufferSize * 2);
46 const float conv = 1.0f / 255.0f;
47 float* coordsData =
buffer.data();
48 float* colorsData =
buffer.data() + singleBufferSize;
50 for (
int i = 0; i < pclSize; ++i)
52 data::ColoredPoint point = pclData[i];
53 colorsData[i * 3 + 0] = point.color.r * conv;
54 colorsData[i * 3 + 1] = point.color.g * conv;
55 colorsData[i * 3 + 2] = point.color.b * conv;
57 coordsData[i * 3 + 0] = point.x;
58 coordsData[i * 3 + 1] = point.y;
59 coordsData[i * 3 + 2] = point.z;
62 pclMat->diffuseColor.setValuesPointer(pclSize, colorsData);
63 pclMat->ambientColor.setValuesPointer(pclSize, colorsData);
64 pclMat->transparency = element.transparency;
66 pclCoords->point.setValuesPointer(pclSize, coordsData);
68 pclStyle->pointSize = element.pointSizeInPixels;
76 float* pclIn = (
float*)element.points.data();
77 int pclSize = element.points.size() /
sizeof(data::ColoredPoint);
80 int singleBufferSize = (pclSize + 3) * 3;
81 if (singleBufferSize % 16 != 0)
83 singleBufferSize += 16 - singleBufferSize % 16;
85 buffer.resize(singleBufferSize * 2);
87 float* positionsData =
buffer.data();
88 float* colorsData =
buffer.data() + singleBufferSize;
90 float* colorsOut = colorsData;
91 float* positionsOut = positionsData;
93 __m128 convColor = _mm_set1_ps(1.0f / 255.0f);
94 __m128i offsetBase = _mm_set_epi32(12, 8, 4, 0);
95 __m128i offsetIncrement = _mm_set1_epi32(16);
96 __m128i maxOffset = _mm_set1_epi32(4 * (pclSize - 1));
97 __m128 floatMax = _mm_set1_ps(FLT_MAX);
102 for (
int i = 0; i < pclSize; i += 4)
105 __m128i offsets = _mm_min_epi32(offsetBase, maxOffset);
109 __m128 cp0 = _mm_loadu_ps(pclIn + _mm_extract_epi32(offsets, 0));
110 __m128 cp1 = _mm_loadu_ps(pclIn + _mm_extract_epi32(offsets, 1));
111 __m128 cp2 = _mm_loadu_ps(pclIn + _mm_extract_epi32(offsets, 2));
112 __m128 cp3 = _mm_loadu_ps(pclIn + _mm_extract_epi32(offsets, 3));
118 __m128i shiftedP0 = (__m128i)cp0;
120 __m128i shiftedP1 = _mm_shuffle_epi32((__m128i)cp1, _MM_SHUFFLE(0, 3, 2, 1));
122 __m128i shiftedP2 = _mm_shuffle_epi32((__m128i)cp2, _MM_SHUFFLE(1, 0, 3, 2));
124 __m128i shiftedP3 = _mm_shuffle_epi32((__m128i)cp3, _MM_SHUFFLE(2, 1, 0, 3));
128 __m128 p0 = _mm_blend_ps((__m128)shiftedP0, (__m128)shiftedP1, 8);
130 __m128 p1 = _mm_blend_ps((__m128)shiftedP1, (__m128)shiftedP2, 12);
132 __m128 p2 = _mm_blend_ps((__m128)shiftedP2, (__m128)shiftedP3, 14);
135 p0 = _mm_and_ps(p0, _mm_cmplt_ps(p0, floatMax));
136 p1 = _mm_and_ps(p1, _mm_cmplt_ps(p1, floatMax));
137 p2 = _mm_and_ps(p2, _mm_cmplt_ps(p2, floatMax));
140 _mm_storeu_ps(positionsOut + 0, p0);
141 _mm_storeu_ps(positionsOut + 4, p1);
142 _mm_storeu_ps(positionsOut + 8, p2);
146 __m128 c01 = _mm_blend_ps((__m128)shiftedP0, (__m128)shiftedP1, 7);
148 __m128 c23 = _mm_blend_ps((__m128)shiftedP2, (__m128)shiftedP3, 1);
150 __m128i c0123 = _mm_castps_si128(_mm_blend_ps(c01, c23, 3));
155 __m128i redI = _mm_and_si128(_mm_bsrli_si128(c0123, 1), _mm_set1_epi32(0xFF));
156 __m128i greenI = _mm_and_si128(_mm_bsrli_si128(c0123, 2), _mm_set1_epi32(0xFF));
157 __m128i blueI = _mm_and_si128(_mm_bsrli_si128(c0123, 3), _mm_set1_epi32(0xFF));
161 __m128
red = _mm_mul_ps(_mm_cvtepi32_ps(redI), convColor);
162 __m128
green = _mm_mul_ps(_mm_cvtepi32_ps(greenI), convColor);
163 __m128 blue = _mm_mul_ps(_mm_cvtepi32_ps(blueI), convColor);
169 __m128 c0 = _mm_setr_ps(
red[3],
green[3], blue[3],
red[2]);
170 __m128 c1 = _mm_setr_ps(
green[2], blue[2],
red[1],
green[1]);
171 __m128 c2 = _mm_setr_ps(blue[1],
red[0],
green[0], blue[0]);
174 _mm_storeu_ps(colorsOut + 0, c0);
175 _mm_storeu_ps(colorsOut + 4, c1);
176 _mm_storeu_ps(colorsOut + 8, c2);
183 offsetBase = _mm_add_epi32(offsetBase, offsetIncrement);
190 pclMat->diffuseColor.setValuesPointer(pclSize, colorsData);
191 pclMat->ambientColor.setValuesPointer(pclSize, colorsData);
192 pclMat->transparency = element.transparency;
194 pclCoords->point.setValuesPointer(pclSize, positionsData);
196 pclStyle->pointSize = element.pointSizeInPixels;