37 #include <vtkSmartPointer.h> 38 #include <vtkPolyData.h> 39 #include <vtkCellArray.h> 40 #include <vtkPolyDataMapper.h> 41 #include <vtkPoints.h> 43 #include <vtkProperty.h> 44 #include <vtkPointData.h> 45 #include <vtkFloatArray.h> 46 #include <vtkIdFilter.h> 47 #include <vtkDataSetSurfaceFilter.h> 100 return col1.
r == col2.
r && col1.
g == col2.
g && col1.
b == col2.
b;
133 vtkSmartPointer<vtkUnsignedCharArray> scalars = vtkSmartPointer<vtkUnsignedCharArray>::New();
134 scalars->SetNumberOfComponents(3);
135 scalars->SetName(
"Colors");
136 scalars->SetNumberOfTuples(n);
138 #pragma omp parallel for 139 for (vtkIdType i = 0; i < n; i++)
141 int specIndex = n_channels * i;
142 unsigned char speccolor[3];
148 #if VTK_MAJOR_VERSION < 7 149 scalars->SetTupleValue(i, speccolor);
151 scalars->SetTypedTuple(i, speccolor);
210 #pragma omp parallel for reduction(max : ndviMax), reduction(min : ndviMin) 211 for (
int i = 0; i < n; i++)
214 float nearRedTotal = 0;
215 unsigned char* specPixel = spec.get() + n_channels * i;
218 for (
int channel = redStart; channel < redEnd; channel++)
220 redTotal += specPixel[channel];
222 for (
int channel = nearRedStart; channel < nearRedEnd; channel++)
224 nearRedTotal += specPixel[channel];
228 float red = redTotal / (redEnd - redStart);
229 float nearRed = nearRedTotal / (nearRedEnd - nearRedStart);
231 float val = (nearRed - red) / (nearRed + red);
236 if (val < ndviMin) ndviMin = val;
237 if (val > ndviMax) ndviMax = val;
242 vtkSmartPointer<vtkUnsignedCharArray> scalars = vtkSmartPointer<vtkUnsignedCharArray>::New();
243 scalars->SetNumberOfComponents(3);
244 scalars->SetName(
"Colors");
245 scalars->SetNumberOfTuples(n);
248 unsigned char min = 0;
249 unsigned char max = 255;
254 #pragma omp parallel for reduction(max : max_val), reduction(min : min_val) 255 for (
int i = 0; i < n; i++)
258 if(spec[specIndex] > max_val)
260 max_val = spec[specIndex];
262 if(spec[specIndex] < min_val)
264 min_val = spec[specIndex];
281 #pragma omp parallel for 282 for (
int i = 0; i < n; i++)
284 int specIndex = n_channels * i;
297 unsigned char speccolor[3];
298 speccolor[0] = color[0] * 255;
299 speccolor[1] = color[1] * 255;
300 speccolor[2] = color[2] * 255;
302 #if VTK_MAJOR_VERSION < 7 303 scalars->SetTupleValue(i, speccolor);
305 scalars->SetTypedTuple(i, speccolor);
367 vtkSmartPointer<vtkPolyData> vtk_polyData = vtkSmartPointer<vtkPolyData>::New();
368 vtkSmartPointer<vtkPoints> vtk_points = vtkSmartPointer<vtkPoints>::New();
377 size_t n, n_c, n_s_p;
378 size_t n_s_channels, w_color;
382 floatArr points = pc->getPointArray();
384 ucharArr spec = pc->getUCharArray(
"spectral_channels", n_s_p, n_s_channels);
385 floatArr normals = pc->getNormalArray();
389 vtkSmartPointer<vtkFloatArray> pts_data = vtkSmartPointer<vtkFloatArray>::New();
390 pts_data->SetNumberOfComponents(3);
391 pts_data->SetVoidArray(points.get(), n * 3, 1);
392 vtk_points->SetData(pts_data);
395 vtkSmartPointer<vtkCellArray> vtk_cells = vtkSmartPointer<vtkCellArray>::New();
396 vtkSmartPointer<vtkIdTypeArray> cells = vtkSmartPointer<vtkIdTypeArray>::New();
397 vtkIdType* cell_buf =
new vtkIdType[n * 2];
398 for(
size_t i = 0; i < n; i++)
401 cell_buf[i2 + 0] =
static_cast<vtkIdType
>(1);
402 cell_buf[i2 + 1] = i;
409 cells->SetVoidArray(cell_buf, n * 2, 0, vtkIdTypeArray::VTK_DATA_ARRAY_DELETE);
411 vtk_cells->SetCells(n, cells);
413 vtkSmartPointer<vtkUnsignedCharArray> scalars = vtkSmartPointer<vtkUnsignedCharArray>::New();
414 scalars->SetNumberOfComponents(3);
415 scalars->SetName(
"Colors");
435 unsigned char* spec_buf =
new unsigned char[n * 3];
436 for(
size_t i = 0; i < n; ++i)
438 size_t specIndex = n_s_channels * i;
445 scalars->SetVoidArray(spec_buf, n * 3, vtkIdTypeArray::VTK_DATA_ARRAY_DELETE);
451 scalars->SetVoidArray(colors.get(), n * w_color, 1);
464 double* normal_buf =
new double[n * 3];
465 for(
size_t i = 0; i < n; ++i)
467 size_t index = 3 * i;
468 normal_buf[index + 0] = normals[index + 0];
469 normal_buf[index + 1] = normals[index + 1];
470 normal_buf[index + 2] = normals[index + 2];
473 m_vtk_normals->SetVoidArray(normal_buf, n * 3, vtkIdTypeArray::VTK_DATA_ARRAY_DELETE);
482 vtkSmartPointer<vtkIdFilter> pointFilter =
483 vtkSmartPointer<vtkIdFilter>::New();
487 pointFilter->SetCellIdsArrayName(
"OriginalIds");
488 pointFilter->SetPointIdsArrayName(
"OriginalIds");
490 pointFilter->SetIdsArrayName(
"OriginalIds");
492 pointFilter->Update();
509 vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
544 p->SetPointSize(pointSize);
550 p->SetOpacity(opacityValue);
void useGradient(bool useGradient)
switch between spectral mapping and gradient
void computePointCloudActor(PointBufferPtr pc)
void setPointSize(int pointSize)
void getSpectralColorGradient(GradientType &gradient, size_t &channel, bool &normalized, bool &useNDVI) const
get the gradienttype, channel, normalizend and ndvi flags
void getColor(float *color, size_t bucket, GradientType gradient=GREY)
Returns three float values for the color of the given bucket.
static int getSpectralChannel(int wavelength, PointBufferPtr p, int fallback=-1)
Returns the spectral channel index for a given wavelength.
vtkSmartPointer< vtkPolyData > getPolyIDData()
static Timestamp timestamp
A global time stamp object for program runtime measurement.
void setVisibility(bool visible)
void setOpacity(float opacityValue)
color< bool > m_useSpectralChannel
vtkSmartPointer< vtkDoubleArray > m_vtk_normals
boost::shared_array< unsigned char > ucharArr
void setSpectralColorGradient(GradientType gradient, size_t channel, bool normalized=false, bool ndvi=false)
set the gradienttype, desired channel, if the outputcolor should be normalized and if the NDVI should...
std::shared_ptr< PointBuffer > PointBufferPtr
vtkSmartPointer< vtkActor > m_pointCloudActor
void setBaseColor(float r, float g, float b)
color< size_t > m_spectralChannels
__kf_device__ float3 normalized(const float3 &v)
void refreshSpectralChannel()
update the view with channel mappings
void getSpectralChannels(color< size_t > &channels, color< bool > &use_channel) const
get spectral channel mappings
boost::shared_array< float > floatArr
GradientType
Identifies a color gradient.
void refreshSpectralGradient()
update the view with gradient information
void setSpectralChannels(color< size_t > channels, color< bool > use_channel)
set the spectral channel for (r, g, b) and set if it is used
size_t m_spectralGradientChannel
void setColorsVisibility(bool visible)
PointBufferPtr m_pointBuffer
virtual ~LVRPointBufferBridge()
void setNormalsVisibility(bool visible)
vtkSmartPointer< vtkPolyData > getPolyData()
vtkSmartPointer< vtkPolyData > m_vtk_polyData
LVRPointBufferBridge(PointBufferPtr pointcloud)
vtkSmartPointer< vtkActor > getPointCloudActor()
bool m_useNormalizedGradient
bool color_equal(const color< T > &col1, const color< T > &col2)
vtkSmartPointer< vtkPolyData > m_id_polyData
GradientType m_spectralGradient
PointBufferPtr getPointBuffer()
get the point buffer