8 #include "../include/ccCloudLayersHelper.h"
10 #include "../include/ccMouseCircle.h"
18 #include <QStringList>
27 m_formerCloudColors(nullptr),
28 m_formerCloudColorsWereShown(false),
29 m_formerCloudSFWasShown(false),
30 m_scalarFieldIndex(0),
33 m_projectedPoints.resize(m_cloud->
size());
34 m_pointInFrustum.resize(m_cloud->
size());
37 m_formerCloudColorsWereShown = m_cloud->
colorsShown();
38 m_formerCloudSFWasShown = m_cloud->
sfShown();
43 if (!m_formerCloudColors) {
44 CVLog::Error(
"Not enough memory to backup previous colors");
60 if (m_formerCloudColors) {
66 delete m_formerCloudColors;
67 m_formerCloudColors =
nullptr;
72 m_cloud->
showColors(m_formerCloudColorsWereShown);
73 m_cloud->
showSF(m_formerCloudSFWasShown);
81 QStringList scalarFields;
83 for (
unsigned i = 0; i < sfCount; ++i) {
91 m_scalarFieldIndex = index;
95 m_formerCloudSFWasShown =
true;
100 unsigned pointCount = m_cloud->
size();
101 for (
unsigned i = 0; i < pointCount; ++i) {
114 for (
int i = 0; i < items.size(); ++i) {
115 items[i].count =
apply(items[i]);
122 bool redrawDisplay) {
128 ScalarType code =
static_cast<ScalarType
>(item.
code);
131 for (
auto it = sf->begin(); it != sf->end(); ++it, ++counter) {
144 ScalarType oldCode) {
148 ScalarType code =
static_cast<ScalarType
>(item.
code);
150 for (
auto it = sf->begin(); it != sf->end(); ++it, ++counter) {
151 if ((*it) == oldCode) {
159 bool redrawDisplay) {
163 ScalarType code =
static_cast<ScalarType
>(from.
code);
164 ScalarType emptyCode = to !=
nullptr ?
static_cast<ScalarType
>(to->
code)
165 :
static_cast<ScalarType
>(0);
171 for (
auto it = sf->begin(); it != sf->end(); ++it, ++counter) {
188 unsigned cloudSize = m_cloud->
size();
189 m_cloudState.resize(cloudSize);
190 for (
unsigned i = 0; i < cloudSize; ++i) {
197 (m_cloud ? m_cloud->
getScalarField(m_scalarFieldIndex) :
nullptr);
203 unsigned cloudSize = m_cloud->
size();
204 if (m_cloudState.size() != cloudSize) {
209 for (
unsigned i = 0; i < cloudSize; ++i) {
210 const CloudState& state = m_cloudState[i];
219 const double half_w = camera.
viewport[2] / 2.0;
220 const double half_h = camera.
viewport[3] / 2.0;
223 bool pointInFrustum =
false;
224 for (
unsigned i = start; i < end; ++i) {
226 camera.
project(*P3D, Q2D, &pointInFrustum);
227 m_projectedPoints[i] =
230 m_pointInFrustum[i] = pointInFrustum;
236 return (b - a).norm2();
241 std::map<ScalarType, int>& affected) {
242 if (m_parameters.
output ==
nullptr ||
244 m_parameters.
input ==
nullptr)) {
251 ScalarType inputCode =
252 m_parameters.
input !=
nullptr
253 ?
static_cast<ScalarType
>(m_parameters.
input->
code)
255 ScalarType outputCode =
static_cast<ScalarType
>(m_parameters.
output->
code);
261 unsigned cloudSize = m_cloud->
size();
262 for (
unsigned i = 0; i < cloudSize; ++i) {
264 if (!m_pointInFrustum[i])
continue;
274 if (m_parameters.
input && code != inputCode)
continue;
277 if (ComputeSquaredEuclideanDistance(center, m_projectedPoints[i]) >
281 if (code != outputCode) {
286 ++affected[outputCode];
309 m_cameraParameters = camera;
310 unsigned cloudSize = m_cloud->
size();
312 unsigned processorCount = std::thread::hardware_concurrency();
313 if (processorCount == 0) processorCount = 1;
315 const size_t part_size = cloudSize / processorCount;
316 std::vector<std::thread*> threads;
317 threads.resize(processorCount,
nullptr);
318 for (
unsigned i = 0; i < processorCount; ++i) {
319 size_t start = i * part_size;
320 size_t end = start + part_size;
322 if (i == processorCount - 1) end = cloudSize;
324 threads[i] =
new std::thread(&ccCloudLayersHelper::project,
this,
328 for (
auto it = threads.begin(); it != threads.end(); ++it) (*it)->join();
330 for (
auto it = threads.begin(); it != threads.end(); ++it)
delete (*it);
Vector2Tpl< PointCoordinateType > CCVector2
Default 2D Vector.
float PointCoordinateType
Type of the coordinates of a (N-D) point.
static bool Error(const char *format,...)
Display an error dialog with formatted message.
ColorsTableType * clone() override
Duplicates array (overloaded from ccArray::clone)
bool copy(Base &dest) const
Copies the content of this array in another one.
void projectCloud(const ccGLCameraParameters &camera)
void apply(QList< ccAsprsModel::AsprsItem > &items)
int moveItem(const ccAsprsModel::AsprsItem &from, const ccAsprsModel::AsprsItem *to, bool redrawDisplay=false)
void keepCurrentSFVisible()
void mouseMove(const CCVector2 ¢er, float squareDist, std::map< ScalarType, int > &affected)
void changeCode(const ccAsprsModel::AsprsItem &item, ScalarType oldCode)
void setScalarFieldIndex(int index)
ccCloudLayersHelper(ecvMainAppInterface *app, ccPointCloud *cloud)
void setVisible(bool value)
QStringList getScalarFields()
Parameters & getParameters()
virtual bool colorsShown() const
Returns whether colors are shown or not.
virtual bool isVisible() const
Returns whether entity is visible or not.
virtual void setVisible(bool state)
Sets entity visibility.
virtual bool sfShown() const
Returns whether active scalar field is visible.
virtual void showColors(bool state)
Sets colors visibility.
virtual void showSF(bool state)
Sets active scalarfield visibility.
T * data()
Returns a pointer to internal data.
virtual void redrawDisplay(bool forceRedraw=true, bool only2D=false)
Redraws associated display.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
void setCurrentDisplayedScalarField(int index)
Sets the currently displayed scalar field.
ColorsTableType * rgbColors() const
Returns pointer on RGB colors table.
void unallocateColors()
Erases the cloud colors.
bool resizeTheRGBTable(bool fillWithWhite=false)
Resizes the RGB colors array.
bool hasColors() const override
Returns whether colors are enabled or not.
void setPointColor(size_t pointIndex, const ecvColor::Rgb &col)
Sets a particular point color.
const ecvColor::Rgb & getPointColor(unsigned pointIndex) const override
Returns color corresponding to a given point.
bool setRGBColor(ColorCompType r, ColorCompType g, ColorCompType b)
Set a unique color for the whole cloud (shortcut)
bool hasScalarFields() const override
Returns whether one or more scalar fields are instantiated.
ScalarField * getScalarField(int index) const
Returns a pointer to a specific scalar field.
unsigned getNumberOfScalarFields() const
Returns the number of associated (and active) scalar fields.
unsigned size() const override
const char * getScalarFieldName(int index) const
Returns the name of a specific scalar field.
const CCVector3 * getPoint(unsigned index) const override
A simple scalar field (to be associated to a point cloud)
ScalarType & getValue(std::size_t index)
void setValue(std::size_t index, ScalarType value)
Main application interface (for plugins)
__host__ __device__ int2 abs(int2 v)
static const unsigned OPENGL_MATRIX_SIZE
Model view matrix size (OpenGL)
constexpr Rgb black(0, 0, 0)
constexpr ColorCompType MAX
Max value of a single color component (default type)
Rgb FromQColor(QColor qColor)
Conversion from QColor.
Rgba FromQColora(QColor qColor)
Conversion from QColor'a'.
RgbaTpl< ColorCompType > Rgba
4 components, default type
ccAsprsModel::AsprsItem * output
ccAsprsModel::AsprsItem * input
OpenGL camera parameters.
ccGLMatrixd modelViewMat
Model view matrix (GL_MODELVIEW)
bool project(const CCVector3d &input3D, CCVector3d &output2D, bool *inFrustum=nullptr) const
Projects a 3D point in 2D (+ normalized 'z' coordinate)
int viewport[4]
Viewport (GL_VIEWPORT)