| 1 |
//########################################################################## |
| 2 |
//# # |
| 3 |
//# CLOUDCOMPARE PLUGIN: qFacets # |
| 4 |
//# # |
| 5 |
//# This program is free software; you can redistribute it and/or modify # |
| 6 |
//# it under the terms of the GNU General Public License as published by # |
| 7 |
//# the Free Software Foundation; version 2 or later of the License. # |
| 8 |
//# # |
| 9 |
//# This program is distributed in the hope that it will be useful, # |
| 10 |
//# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
| 11 |
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
| 12 |
//# GNU General Public License for more details. # |
| 13 |
//# # |
| 14 |
//# COPYRIGHT: Thomas Dewez, BRGM # |
| 15 |
//# # |
| 16 |
//########################################################################## |
| 17 |
|
| 18 |
#include "stereogramDlg.h" |
| 19 |
|
| 20 |
//Local |
| 21 |
#include "facetsClassifier.h" |
| 22 |
|
| 23 |
// Qt |
| 24 |
#include <QPainter> |
| 25 |
#include <QMainWindow> |
| 26 |
#include <QMouseEvent> |
| 27 |
#include <QSpacerItem> |
| 28 |
|
| 29 |
//qCC_plugins |
| 30 |
#include <ccMainAppInterface.h> |
| 31 |
|
| 32 |
//qCC_db |
| 33 |
#include <ccColorScalesManager.h> |
| 34 |
#include <ccColorScaleSelector.h> |
| 35 |
#include <ccColorScaleEditorDlg.h> |
| 36 |
#include <ccMesh.h> |
| 37 |
#include <ccProgressDialog.h> |
| 38 |
|
| 39 |
//! Density grid |
| 40 |
class FacetDensityGrid |
| 41 |
{ |
| 42 |
public: |
| 43 |
|
| 44 |
//! Default constructor |
| 45 |
FacetDensityGrid() |
| 46 |
: grid(nullptr) |
| 47 |
, rSteps(0) |
| 48 |
, ddSteps(0) |
| 49 |
, step_R(0) |
| 50 |
, step_deg(0) |
| 51 |
{ |
| 52 |
minMaxDensity[0] = minMaxDensity[1] = 0; |
| 53 |
} |
| 54 |
|
| 55 |
//! Destructor |
| 56 |
~FacetDensityGrid() |
| 57 |
{ |
| 58 |
if (grid) |
| 59 |
delete[] grid; |
| 60 |
} |
| 61 |
|
| 62 |
//! Grid |
| 63 |
double* grid; |
| 64 |
|
| 65 |
//! Dimension (X) |
| 66 |
unsigned rSteps; |
| 67 |
//! Dimension (Y) |
| 68 |
unsigned ddSteps; |
| 69 |
|
| 70 |
//! Grid step along X (in unit) |
| 71 |
double step_R; |
| 72 |
//! Grid step along Y (in degrees) |
| 73 |
double step_deg; |
| 74 |
|
| 75 |
//! Min/max density |
| 76 |
double minMaxDensity[2]; |
| 77 |
}; |
| 78 |
|
| 79 |
StereogramWidget::StereogramWidget(QWidget *parent) |
| 80 |
: QLabel(QString(), parent) |
| 81 |
, m_angularStep_deg(0) |
| 82 |
, m_densityGrid(nullptr) |
| 83 |
, m_meanDipDir_deg(-1.0) |
| 84 |
, m_meanDip_deg(-1.0) |
| 85 |
, m_densityColorScale(nullptr) |
| 86 |
, m_densityColorScaleSteps(ccColorScale::MAX_STEPS < 256 ? ccColorScale::MAX_STEPS : 256) //DGM: we can't pass a constant initializer (MAX_STEPS) by reference |
| 87 |
, m_ticksFreq(3) |
| 88 |
, m_showHSVRing(false) |
| 89 |
, m_trackMouseClick(false) |
| 90 |
, m_clickDip_deg(0.0) |
| 91 |
, m_clickDipDir_deg(0.0) |
| 92 |
, m_clickDipSpan_deg(30.0) |
| 93 |
, m_clickDipDirSpan_deg(30.0) |
| 94 |
, m_center(0, 0) |
| 95 |
, m_radius(0) |
| 96 |
{ |
| 97 |
setVisible(true); |
| 98 |
QSizePolicy policy = sizePolicy(); |
| 99 |
policy.setHeightForWidth(true); |
| 100 |
setSizePolicy(policy); |
| 101 |
//setFixedSize(256,256); |
| 102 |
} |
| 103 |
|
| 104 |
StereogramWidget::~StereogramWidget() |
| 105 |
{ |
| 106 |
if (m_densityGrid) |
| 107 |
delete m_densityGrid; |
| 108 |
} |
| 109 |
|
| 110 |
bool StereogramWidget::init(double angularStep_deg, |
| 111 |
ccHObject* entity, |
| 112 |
double resolution_deg/*=2.0*/) |
| 113 |
{ |
| 114 |
m_angularStep_deg = angularStep_deg; |
| 115 |
|
| 116 |
if (m_densityGrid) |
| 117 |
delete m_densityGrid; |
| 118 |
m_densityGrid = nullptr; |
| 119 |
|
| 120 |
if (!entity) |
| 121 |
return false; |
| 122 |
|
| 123 |
ccProgressDialog pDlg(true); |
| 124 |
pDlg.setMethodTitle(QObject::tr("Stereogram")); |
| 125 |
pDlg.setInfo(QObject::tr("Preparing polar display...")); |
| 126 |
pDlg.start(); |
| 127 |
QApplication::processEvents(); |
| 128 |
|
| 129 |
size_t count = 0; |
| 130 |
ccHObject::Container facets; |
| 131 |
ccHObject::Container planes; |
| 132 |
ccPointCloud* cloud = nullptr; |
| 133 |
|
| 134 |
//a set of facets or planes? |
| 135 |
if (entity->isA(CC_TYPES::HIERARCHY_OBJECT)) |
| 136 |
{ |
| 137 |
//check for facets first |
| 138 |
entity->filterChildren(facets,true,CC_TYPES::FACET); |
| 139 |
count = facets.size(); |
| 140 |
if (count == 0) //if no facets, look for planes instead |
| 141 |
{ |
| 142 |
entity->filterChildren(planes, true, CC_TYPES::PLANE); |
| 143 |
count = planes.size(); |
| 144 |
} |
| 145 |
} |
| 146 |
//or a cloud? |
| 147 |
else if (entity->isA(CC_TYPES::POINT_CLOUD)) |
| 148 |
{ |
| 149 |
cloud = static_cast<ccPointCloud*>(entity); |
| 150 |
if (cloud->hasNormals()) |
| 151 |
count = cloud->size(); |
| 152 |
} |
| 153 |
|
| 154 |
if (!count) |
| 155 |
return false; |
| 156 |
|
| 157 |
//pDlg.setMaximum(static_cast<int>(count)); |
| 158 |
CCCoreLib::NormalizedProgress nProgress(&pDlg,static_cast<unsigned>(count)); |
| 159 |
|
| 160 |
//create the density grid |
| 161 |
FacetDensityGrid* densityGrid = new FacetDensityGrid(); |
| 162 |
densityGrid->step_deg = resolution_deg; |
| 163 |
densityGrid->step_R = 0.02; |
| 164 |
|
| 165 |
//dip steps (dip in [0,90]) |
| 166 |
//densityGrid->dSteps = static_cast<unsigned>(ceil(90.0 / densityGrid->step_deg)); |
| 167 |
//R steps (R in [0,1]) |
| 168 |
densityGrid->rSteps = static_cast<unsigned>(ceil(1.0 / densityGrid->step_R)); |
| 169 |
//dip direction steps (dip dir. in [0,360]) |
| 170 |
densityGrid->ddSteps = static_cast<unsigned>(ceil(360.0 / densityGrid->step_deg)); |
| 171 |
|
| 172 |
unsigned cellCount = densityGrid->rSteps * densityGrid->ddSteps; |
| 173 |
densityGrid->grid = new double[cellCount]; |
| 174 |
if (densityGrid->grid) |
| 175 |
{ |
| 176 |
memset(densityGrid->grid,0,sizeof(double)*cellCount); |
| 177 |
|
| 178 |
CCVector3d Nmean(0,0,0); |
| 179 |
double surfaceSum = 0.0; |
| 180 |
|
| 181 |
for (size_t i=0; i<count; ++i) |
| 182 |
{ |
| 183 |
CCVector3 N; |
| 184 |
double weight = 1.0; |
| 185 |
if (cloud) //we're using cloud normals |
| 186 |
{ |
| 187 |
N = cloud->getPointNormal(static_cast<unsigned>(i)); |
| 188 |
} |
| 189 |
else if (facets.size() != 0) //we're using facets |
| 190 |
{ |
| 191 |
ccFacet* facet = static_cast<ccFacet*>(facets[i]); |
| 192 |
N = facet->getNormal(); |
| 193 |
weight = facet->getSurface(); |
| 194 |
} |
| 195 |
else if (planes.size() != 0) //we're using planes |
| 196 |
{ |
| 197 |
ccPlane* p = static_cast<ccPlane*>(planes[i]); |
| 198 |
N = p->getNormal(); |
| 199 |
//n.b. planes all carry equal weight |
| 200 |
} |
| 201 |
|
| 202 |
Nmean.x += static_cast<double>(N.x) * weight; |
| 203 |
Nmean.y += static_cast<double>(N.y) * weight; |
| 204 |
Nmean.z += static_cast<double>(N.z) * weight; |
| 205 |
surfaceSum += weight; |
| 206 |
|
| 207 |
PointCoordinateType dipDir = 0; |
| 208 |
PointCoordinateType dip = 0; |
| 209 |
ccNormalVectors::ConvertNormalToDipAndDipDir(N,dip,dipDir); |
| 210 |
|
| 211 |
//unsigned iDip = static_cast<unsigned>(static_cast<double>(dip) / densityGrid->step_deg); //static_cast is equivalent to floor if value >= 0 |
| 212 |
//if (iDip == densityGrid->dSteps) |
| 213 |
// iDip--; |
| 214 |
unsigned iDipDir = static_cast<unsigned>(dipDir / densityGrid->step_deg); //static_cast is equivalent to floor if value >= 0 |
| 215 |
if (iDipDir == densityGrid->ddSteps) |
| 216 |
{ |
| 217 |
iDipDir--; |
| 218 |
} |
| 219 |
|
| 220 |
double dip_rad = CCCoreLib::DegreesToRadians( dip ); |
| 221 |
double R = sin(dip_rad) / (1.0 + cos(dip_rad)); |
| 222 |
|
| 223 |
unsigned iR = static_cast<unsigned>(R / densityGrid->step_R); //static_cast is equivalent to floor if value >= 0 |
| 224 |
if (iR == densityGrid->rSteps) |
| 225 |
{ |
| 226 |
iR--; |
| 227 |
} |
| 228 |
|
| 229 |
densityGrid->grid[iR + iDipDir * densityGrid->rSteps] += weight; |
| 230 |
|
| 231 |
//pDlg.setValue(static_cast<int>(i)); |
| 232 |
if (!nProgress.oneStep()) |
| 233 |
{ |
| 234 |
//process cancelled by user |
| 235 |
delete densityGrid; |
| 236 |
return false; |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
if (surfaceSum > 0) |
| 241 |
{ |
| 242 |
Nmean.normalize(); |
| 243 |
CCVector3 N(static_cast<PointCoordinateType>(Nmean.x), |
| 244 |
static_cast<PointCoordinateType>(Nmean.y), |
| 245 |
static_cast<PointCoordinateType>(Nmean.z)); |
| 246 |
|
| 247 |
PointCoordinateType dipDir = 0; |
| 248 |
PointCoordinateType dip = 0; |
| 249 |
ccNormalVectors::ConvertNormalToDipAndDipDir(N, dip, dipDir); |
| 250 |
|
| 251 |
m_meanDipDir_deg = static_cast<double>(dipDir); |
| 252 |
m_meanDip_deg = static_cast<double>(dip); |
| 253 |
|
| 254 |
//set same value for the "filter" center |
| 255 |
m_clickDipDir_deg = m_meanDipDir_deg; |
| 256 |
m_clickDip_deg = m_meanDip_deg; |
| 257 |
} |
| 258 |
|
| 259 |
//compute min and max density |
| 260 |
{ |
| 261 |
//DGM: only supported on C++x11! |
| 262 |
//std::pair<double*, double*> minmax = std::minmax_element(densityGrid->grid, densityGrid->grid + cellCount); |
| 263 |
//densityGrid->minMaxDensity[0] = *minmax.first; |
| 264 |
//densityGrid->minMaxDensity[1] = *minmax.second; |
| 265 |
|
| 266 |
densityGrid->minMaxDensity[0] = densityGrid->grid[0]; |
| 267 |
densityGrid->minMaxDensity[1] = densityGrid->grid[0]; |
| 268 |
for (unsigned j = 1; j < cellCount; ++j) |
| 269 |
{ |
| 270 |
if (densityGrid->grid[j] < densityGrid->minMaxDensity[0]) |
| 271 |
densityGrid->minMaxDensity[0] = densityGrid->grid[j]; |
| 272 |
else if (densityGrid->grid[j] > densityGrid->minMaxDensity[1]) |
| 273 |
densityGrid->minMaxDensity[1] = densityGrid->grid[j]; |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
//pDlg.hide(); |
| 278 |
pDlg.stop(); |
| 279 |
QApplication::processEvents(); |
| 280 |
} |
| 281 |
else |
| 282 |
{ |
| 283 |
//not enough memory! |
| 284 |
delete densityGrid; |
| 285 |
densityGrid = nullptr; |
| 286 |
} |
| 287 |
|
| 288 |
//replace old grid by new one! (even in case of failure! See below) |
| 289 |
m_densityGrid = densityGrid; |
| 290 |
|
| 291 |
update(); |
| 292 |
|
| 293 |
return true; |
| 294 |
} |
| 295 |
|
| 296 |
void StereogramWidget::mousePressEvent(QMouseEvent* e) |
| 297 |
{ |
| 298 |
if (m_trackMouseClick && m_radius > 0) |
| 299 |
{ |
| 300 |
if (e->button() == Qt::LeftButton) |
| 301 |
{ |
| 302 |
QRect contentRect = contentsRect(); |
| 303 |
QPoint pos = e->pos() - contentRect.topLeft(); |
| 304 |
QPoint AB = pos - m_center; |
| 305 |
int squareDistToCenter = AB.x() * AB.x() + AB.y() * AB.y(); |
| 306 |
if (squareDistToCenter <= m_radius * m_radius) |
| 307 |
{ |
| 308 |
//compute equivalent positions |
| 309 |
m_clickDip_deg = std::min(90.0, 90.0 * sqrt(static_cast<double>(squareDistToCenter)) / static_cast<double>(m_radius)); |
| 310 |
m_clickDipDir_deg = CCCoreLib::RadiansToDegrees( atan2(static_cast<double>(AB.y()), static_cast<double>(AB.x())) ); |
| 311 |
if (m_clickDipDir_deg < 0) |
| 312 |
m_clickDipDir_deg += 360.0; |
| 313 |
m_clickDipDir_deg += 90.0; //stereogram starts at 12 o'clock (not 3) |
| 314 |
if (m_clickDipDir_deg >= 360.0) |
| 315 |
m_clickDipDir_deg -= 360.0; |
| 316 |
|
| 317 |
Q_EMIT pointClicked(m_clickDip_deg, m_clickDipDir_deg); |
| 318 |
e->accept(); |
| 319 |
return; |
| 320 |
} |
| 321 |
} |
| 322 |
} |
| 323 |
|
| 324 |
e->ignore(); |
| 325 |
} |
| 326 |
|
| 327 |
void StereogramWidget::enableMouseTracking(bool state, double dipSpan_deg/*=30*/, double dipDirSpan_deg/*=30*/) |
| 328 |
{ |
| 329 |
m_trackMouseClick = state; |
| 330 |
if (state) |
| 331 |
{ |
| 332 |
m_clickDipSpan_deg = dipSpan_deg; |
| 333 |
m_clickDipDirSpan_deg = dipDirSpan_deg; |
| 334 |
//to give to the parent dialog some feedback about the current marker position! |
| 335 |
Q_EMIT pointClicked(m_clickDip_deg, m_clickDipDir_deg); |
| 336 |
} |
| 337 |
} |
| 338 |
|
| 339 |
void StereogramWidget::setTrackedCenter(double dip_deg, double dipDir_deg) |
| 340 |
{ |
| 341 |
m_clickDip_deg = dip_deg; |
| 342 |
m_clickDipDir_deg = dipDir_deg; |
| 343 |
} |
| 344 |
|
| 345 |
void StereogramWidget::paintEvent(QPaintEvent* event) |
| 346 |
{ |
| 347 |
m_radius = 0; //means that nothing has been drawn (yet ;) |
| 348 |
|
| 349 |
QLabel::paintEvent(event); |
| 350 |
QPainter painter(this); |
| 351 |
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing, true); |
| 352 |
|
| 353 |
//pen |
| 354 |
QPen pen; |
| 355 |
pen.setStyle(Qt::SolidLine); |
| 356 |
pen.setBrush(Qt::black); |
| 357 |
|
| 358 |
int diameter = std::min(width(), height()); |
| 359 |
int halfW = width() / 2; |
| 360 |
int halfH = height() / 2; |
| 361 |
QPoint center(halfW, halfH); |
| 362 |
|
| 363 |
int hsvThickness = 0; |
| 364 |
if (m_showHSVRing) |
| 365 |
{ |
| 366 |
int newDiameter = static_cast<int>(ceil(0.9 * diameter)); |
| 367 |
hsvThickness = diameter - newDiameter; |
| 368 |
|
| 369 |
//TODO |
| 370 |
if (hsvThickness > 0) |
| 371 |
{ |
| 372 |
QRect rectangle(center.x() - diameter / 2 + 1, center.y() - diameter / 2 + 1, diameter - 2, diameter - 2); |
| 373 |
int angle_span = static_cast<int>(m_angularStep_deg * 16.0); //see QPainter::drawPie |
| 374 |
QBrush brush; |
| 375 |
brush.setStyle(Qt::SolidPattern); |
| 376 |
painter.setPen(Qt::NoPen); |
| 377 |
|
| 378 |
//dip direction steps (dip dir. in [0,360]) |
| 379 |
unsigned ddSteps = static_cast<unsigned>(ceil(360.0 / std::max(m_angularStep_deg,1.0))); |
| 380 |
for (unsigned j = 0; j < ddSteps; ++j) |
| 381 |
{ |
| 382 |
double dipDir_deg = static_cast<double>(j) * m_angularStep_deg; |
| 383 |
|
| 384 |
//set family color |
| 385 |
ccColor::Rgb col; |
| 386 |
FacetsClassifier::GenerateSubfamilyColor(col, 90.0, dipDir_deg + 0.5 * m_angularStep_deg, 0, 1); |
| 387 |
brush.setColor(QColor( static_cast<int>(col.r), |
| 388 |
static_cast<int>(col.g), |
| 389 |
static_cast<int>(col.b), |
| 390 |
255)); |
| 391 |
painter.setBrush(brush); |
| 392 |
|
| 393 |
int angle_start = static_cast<int>((360.0 - dipDir_deg - m_angularStep_deg + 90.0) * 16.0); //see QPainter::drawPie |
| 394 |
painter.drawPie(rectangle, angle_start, angle_span); |
| 395 |
} |
| 396 |
} |
| 397 |
|
| 398 |
diameter = newDiameter; |
| 399 |
} |
| 400 |
|
| 401 |
//outer circle |
| 402 |
pen.setWidth(2); |
| 403 |
painter.setPen(pen); |
| 404 |
painter.setBrush(Qt::white); |
| 405 |
int radius = diameter / 2 - 2; |
| 406 |
painter.drawEllipse(center,radius,radius); |
| 407 |
painter.setBrush(Qt::NoBrush); |
| 408 |
|
| 409 |
//keep track of the circle position |
| 410 |
m_radius = radius; |
| 411 |
m_center = center; |
| 412 |
|
| 413 |
//main axes |
| 414 |
painter.drawLine(center - QPoint(radius, 0), center + QPoint(radius, 0)); |
| 415 |
painter.drawLine(center - QPoint(0, radius), center + QPoint(0, radius)); |
| 416 |
|
| 417 |
//draw circles |
| 418 |
if (m_angularStep_deg > 0) |
| 419 |
{ |
| 420 |
//dip steps (dip in [0,90]) |
| 421 |
unsigned dSteps = static_cast<unsigned>(ceil(90.0 / m_angularStep_deg)); |
| 422 |
//dip direction steps (dip dir. in [0,360]) |
| 423 |
unsigned ddSteps = static_cast<unsigned>(ceil(360.0 / m_angularStep_deg)); |
| 424 |
|
| 425 |
//draw inner circles |
| 426 |
pen.setWidth(1); |
| 427 |
pen.setColor(Qt::gray); |
| 428 |
painter.setPen(pen); |
| 429 |
for (unsigned i = 1; i < dSteps; ++i) |
| 430 |
{ |
| 431 |
double dip_deg = i * m_angularStep_deg; |
| 432 |
if (dip_deg < 90.0) |
| 433 |
{ |
| 434 |
int R = static_cast<int>(radius * (dip_deg / 90.0)); |
| 435 |
if (R > 1) |
| 436 |
painter.drawEllipse(center, R - 1, R - 1); |
| 437 |
} |
| 438 |
} |
| 439 |
|
| 440 |
//draw rays (+ 'm_ticksFreq' times more ticks) |
| 441 |
int ticksFreq = std::max(m_ticksFreq, 1); |
| 442 |
for (unsigned j = 1; j <= ddSteps*ticksFreq; ++j) |
| 443 |
{ |
| 444 |
double dipDir_deg = j * m_angularStep_deg / ticksFreq; |
| 445 |
if (dipDir_deg < 360.0) |
| 446 |
{ |
| 447 |
const double dipDir_rad = CCCoreLib::DegreesToRadians( dipDir_deg ); |
| 448 |
|
| 449 |
QPoint X( static_cast<int>(sin( dipDir_rad ) * radius), |
| 450 |
-static_cast<int>(cos( dipDir_rad ) * radius) ); |
| 451 |
|
| 452 |
if ((j % ticksFreq) == 0) //long ticks |
| 453 |
painter.drawLine(center, center + X); |
| 454 |
else |
| 455 |
painter.drawLine(center + X*0.93, center + X); |
| 456 |
} |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
//draw density map |
| 461 |
if (m_densityGrid && m_densityColorScale && m_densityGrid->grid && m_densityGrid->minMaxDensity[1] != 0) |
| 462 |
{ |
| 463 |
QBrush brush; |
| 464 |
brush.setStyle(Qt::SolidPattern); |
| 465 |
painter.setPen(Qt::NoPen); |
| 466 |
QPolygon poly(4); |
| 467 |
|
| 468 |
const double* d = m_densityGrid->grid; |
| 469 |
const double step_rad = CCCoreLib::DegreesToRadians( m_densityGrid->step_deg ); |
| 470 |
|
| 471 |
for (unsigned j = 0; j < m_densityGrid->ddSteps; ++j) |
| 472 |
{ |
| 473 |
double dipDir0_rad = (j ) * step_rad; |
| 474 |
double dipDir1_rad = (j + 1) * step_rad; |
| 475 |
double cos_dipDir0 = cos(dipDir0_rad); |
| 476 |
double sin_dipDir0 = sin(dipDir0_rad); |
| 477 |
double cos_dipDir1 = cos(dipDir1_rad); |
| 478 |
double sin_dipDir1 = sin(dipDir1_rad); |
| 479 |
|
| 480 |
for (unsigned i = 0; i < m_densityGrid->rSteps; ++i, ++d) |
| 481 |
{ |
| 482 |
if (*d != 0) |
| 483 |
{ |
| 484 |
double relPos = (*d) / m_densityGrid->minMaxDensity[1]; |
| 485 |
const ccColor::Rgb* col = m_densityColorScale->getColorByRelativePos(relPos, m_densityColorScaleSteps); |
| 486 |
if (col) |
| 487 |
{ |
| 488 |
brush.setColor(QColor( static_cast<int>(col->r), |
| 489 |
static_cast<int>(col->g), |
| 490 |
static_cast<int>(col->b), |
| 491 |
255)); |
| 492 |
} |
| 493 |
else |
| 494 |
{ |
| 495 |
assert(false); |
| 496 |
} |
| 497 |
painter.setBrush(brush); |
| 498 |
|
| 499 |
//stereographic projection |
| 500 |
double R0 = radius * ((i ) * m_densityGrid->step_R); |
| 501 |
double R1 = radius * ((i + 1) * m_densityGrid->step_R); |
| 502 |
|
| 503 |
poly.setPoint(0, center + QPoint(static_cast<int>(sin_dipDir0 * R0), -static_cast<int>(cos_dipDir0 * R0))); |
| 504 |
poly.setPoint(1, center + QPoint(static_cast<int>(sin_dipDir0 * R1), -static_cast<int>(cos_dipDir0 * R1))); |
| 505 |
poly.setPoint(2, center + QPoint(static_cast<int>(sin_dipDir1 * R1), -static_cast<int>(cos_dipDir1 * R1))); |
| 506 |
poly.setPoint(3, center + QPoint(static_cast<int>(sin_dipDir1 * R0), -static_cast<int>(cos_dipDir1 * R0))); |
| 507 |
|
| 508 |
painter.drawPolygon(poly); |
| 509 |
} |
| 510 |
} |
| 511 |
} |
| 512 |
} |
| 513 |
|
| 514 |
//draw main 'dip direction' |
| 515 |
if (m_meanDipDir_deg >= 0) |
| 516 |
{ |
| 517 |
pen.setWidth(2); |
| 518 |
pen.setColor(Qt::red); |
| 519 |
painter.setPen(pen); |
| 520 |
|
| 521 |
const double meanDipDir_rad = CCCoreLib::DegreesToRadians( m_meanDipDir_deg ); |
| 522 |
|
| 523 |
//draw main direction |
| 524 |
QPoint X( static_cast<int>(sin( meanDipDir_rad ) * radius), |
| 525 |
-static_cast<int>(cos( meanDipDir_rad ) * radius) ); |
| 526 |
pen.setStyle(Qt::DashLine); |
| 527 |
painter.setPen(pen); |
| 528 |
painter.drawLine(center,center+X); |
| 529 |
|
| 530 |
//draw orthogonal to main direction |
| 531 |
QPoint Y( static_cast<int>(cos( meanDipDir_rad ) * radius), |
| 532 |
static_cast<int>(sin( meanDipDir_rad ) * radius) ); |
| 533 |
pen.setStyle(Qt::SolidLine); |
| 534 |
painter.setPen(pen); |
| 535 |
painter.drawLine(center-Y,center+Y); |
| 536 |
} |
| 537 |
|
| 538 |
//draw filter window around last cliked point |
| 539 |
if (m_trackMouseClick) |
| 540 |
{ |
| 541 |
pen.setWidth(2); |
| 542 |
pen.setColor(Qt::magenta); |
| 543 |
painter.setPen(pen); |
| 544 |
//QBrush brush; |
| 545 |
//brush.setStyle(Qt::Dense6Pattern); |
| 546 |
//brush.setColor(Qt::red); |
| 547 |
//painter.setBrush(brush); |
| 548 |
painter.setBrush(Qt::NoBrush); |
| 549 |
|
| 550 |
double R0 = radius * (std::max(0.0, m_clickDip_deg - m_clickDipSpan_deg / 2) / 90.0); |
| 551 |
double R1 = radius * (std::min(90.0, m_clickDip_deg + m_clickDipSpan_deg / 2) / 90.0); |
| 552 |
|
| 553 |
const double angle_rad = CCCoreLib::DegreesToRadians( m_clickDipDir_deg - m_clickDipDirSpan_deg / 2 ); |
| 554 |
|
| 555 |
//draw radial limits |
| 556 |
{ |
| 557 |
QPoint X0( static_cast<int>(sin( angle_rad ) * R0), |
| 558 |
-static_cast<int>(cos( angle_rad ) * R0)); |
| 559 |
QPoint X1( static_cast<int>(sin( angle_rad ) * R1), |
| 560 |
-static_cast<int>(cos( angle_rad ) * R1)); |
| 561 |
painter.drawLine(center + X0, center + X1); |
| 562 |
} |
| 563 |
{ |
| 564 |
QPoint X0( static_cast<int>(sin( angle_rad ) * R0), |
| 565 |
-static_cast<int>(cos( angle_rad ) * R0)); |
| 566 |
QPoint X1( static_cast<int>(sin( angle_rad ) * R1), |
| 567 |
-static_cast<int>(cos( angle_rad ) * R1)); |
| 568 |
painter.drawLine(center + X0, center + X1); |
| 569 |
} |
| 570 |
|
| 571 |
//draw concentric limits |
| 572 |
{ |
| 573 |
int angle_start = static_cast<int>((360.0 - m_clickDipDir_deg - m_clickDipDirSpan_deg/2 + 90.0) * 16.0); //see QPainter::drawPie |
| 574 |
int angle_span = static_cast<int>(m_clickDipDirSpan_deg * 16.0); //see QPainter::drawPie |
| 575 |
|
| 576 |
QRectF rect0( center.x() - R0, |
| 577 |
center.y() - R0, |
| 578 |
2*R0, 2*R0); |
| 579 |
painter.drawArc(rect0, angle_start, angle_span); |
| 580 |
|
| 581 |
QRectF rect1( center.x() - R1, |
| 582 |
center.y() - R1, |
| 583 |
2*R1, 2*R1); |
| 584 |
painter.drawArc(rect1, angle_start, angle_span); |
| 585 |
} |
| 586 |
} |
| 587 |
} |
| 588 |
|
| 589 |
StereogramDialog::StereogramDialog(ccMainAppInterface* app) |
| 590 |
: QDialog( app->getMainWindow() ) |
| 591 |
, Ui::StereogramDialog() |
| 592 |
, m_classifWidget(nullptr) |
| 593 |
, m_colorScaleSelector(nullptr) |
| 594 |
, m_app(app) |
| 595 |
, m_facetGroupUniqueID(0) |
| 596 |
{ |
| 597 |
setupUi(this); |
| 598 |
|
| 599 |
//create classification widget (stereogram) |
| 600 |
m_classifWidget = new StereogramWidget(this); |
| 601 |
{ |
| 602 |
if (!frame->layout()) |
| 603 |
frame->setLayout(new QHBoxLayout()); |
| 604 |
frame->layout()->addWidget(m_classifWidget); |
| 605 |
m_classifWidget->setTicksFreq(ticksFreqSpinBox->value()); |
| 606 |
} |
| 607 |
|
| 608 |
//add color ramp selector widget |
| 609 |
if (m_app) |
| 610 |
{ |
| 611 |
ccColorScalesManager* csManager = m_app->getColorScalesManager(); |
| 612 |
m_colorScaleSelector = new ccColorScaleSelector(csManager, this, QString::fromUtf8(":/CC/plugin/qFacets/images/gearIcon.png")); |
| 613 |
m_colorScaleSelector->init(); |
| 614 |
ccColorScale::Shared scale = csManager->getDefaultScale(ccColorScalesManager::HIGH_CONTRAST); |
| 615 |
if (scale) |
| 616 |
{ |
| 617 |
m_colorScaleSelector->setSelectedScale(scale->getUuid()); |
| 618 |
m_classifWidget->setDensityColorScale(scale); |
| 619 |
} |
| 620 |
connect(m_colorScaleSelector, &ccColorScaleSelector::colorScaleSelected, this, &StereogramDialog::colorScaleChanged); |
| 621 |
connect(m_colorScaleSelector, &ccColorScaleSelector::colorScaleEditorSummoned, this, &StereogramDialog::spawnColorScaleEditor); |
| 622 |
//add selector to group's layout |
| 623 |
if (!colorRampGroupBox->layout()) |
| 624 |
colorRampGroupBox->setLayout(new QHBoxLayout()); |
| 625 |
colorRampGroupBox->layout()->addItem(new QSpacerItem(20, 20, QSizePolicy::Preferred, QSizePolicy::Minimum)); |
| 626 |
colorRampGroupBox->layout()->addWidget(m_colorScaleSelector); |
| 627 |
colorScaleStepsSpinBox->setRange(ccColorScale::MIN_STEPS, ccColorScale::MAX_STEPS); |
| 628 |
} |
| 629 |
else |
| 630 |
{ |
| 631 |
m_classifWidget->setDensityColorScale(ccColorScalesManager::GetDefaultScale()); |
| 632 |
} |
| 633 |
|
| 634 |
connect(colorScaleStepsSpinBox, qOverload<int>(&QSpinBox::valueChanged), this, &StereogramDialog::onDensityColorStepsChanged); |
| 635 |
connect(ticksFreqSpinBox, qOverload<int>(&QSpinBox::valueChanged), this, &StereogramDialog::onTicksFreqChanged); |
| 636 |
connect(showHSVColorsCheckBox, &QAbstractButton::toggled, this, &StereogramDialog::onHSVColorsToggled); |
| 637 |
|
| 638 |
//interactive filtering mechanism |
| 639 |
connect(filterFacetsGroupBox, &QGroupBox::toggled, this, &StereogramDialog::onFilterEnabled); |
| 640 |
connect(dipSpanDoubleSpinBox, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &StereogramDialog::onFilterSizeChanged); |
| 641 |
connect(dipDirSpanDoubleSpinBox, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &StereogramDialog::onFilterSizeChanged); |
| 642 |
connect(dipDoubleSpinBox, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &StereogramDialog::onFilterCenterChanged); |
| 643 |
connect(dipDirDoubleSpinBox, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &StereogramDialog::onFilterCenterChanged); |
| 644 |
connect(m_classifWidget, &StereogramWidget::pointClicked, this, &StereogramDialog::onPointClicked); |
| 645 |
connect(exportPushButton, &QAbstractButton::clicked, this, &StereogramDialog::exportCurrentSelection); |
| 646 |
} |
| 647 |
|
| 648 |
bool StereogramDialog::init(double angularStep_deg, |
| 649 |
ccHObject* facetGroup, |
| 650 |
double resolution_deg/*=2.0*/) |
| 651 |
{ |
| 652 |
if (!m_classifWidget) |
| 653 |
return false; |
| 654 |
|
| 655 |
if (!m_classifWidget->init(angularStep_deg, facetGroup, resolution_deg)) |
| 656 |
return false; |
| 657 |
|
| 658 |
double meanDipDir_deg = 0.0; |
| 659 |
double meanDip_deg = 0.0; |
| 660 |
//set stereogram subtitle (i.e. mean direction) |
| 661 |
m_classifWidget->getMeanDir(meanDip_deg, meanDipDir_deg); |
| 662 |
meanDirLabel->setText( QString("[Mean] ") |
| 663 |
+ ccNormalVectors::ConvertDipAndDipDirToString( static_cast<PointCoordinateType>(meanDip_deg), |
| 664 |
static_cast<PointCoordinateType>(meanDipDir_deg)) ); |
| 665 |
|
| 666 |
//restore any old set state before forgetting it! |
| 667 |
bool filterModeEnabled = filterFacetsGroupBox->isChecked(); |
| 668 |
if (m_facetGroupUniqueID != 0 && filterModeEnabled) |
| 669 |
{ |
| 670 |
updateFacetsFilter(false); |
| 671 |
} |
| 672 |
m_facetGroupUniqueID = facetGroup->getUniqueID(); |
| 673 |
if (filterModeEnabled) |
| 674 |
{ |
| 675 |
updateFacetsFilter(true); |
| 676 |
} |
| 677 |
|
| 678 |
return true; |
| 679 |
} |
| 680 |
|
| 681 |
void StereogramDialog::closeEvent(QCloseEvent* e) |
| 682 |
{ |
| 683 |
//filter mode enabled? |
| 684 |
if (filterFacetsGroupBox->isChecked()) |
| 685 |
{ |
| 686 |
updateFacetsFilter(false); |
| 687 |
} |
| 688 |
|
| 689 |
QDialog::closeEvent(e); |
| 690 |
} |
| 691 |
|
| 692 |
void StereogramDialog::onFilterEnabled(bool state) |
| 693 |
{ |
| 694 |
if (m_classifWidget) |
| 695 |
{ |
| 696 |
m_classifWidget->enableMouseTracking(state, dipSpanDoubleSpinBox->value(), dipDirSpanDoubleSpinBox->value()); |
| 697 |
m_classifWidget->update(); |
| 698 |
} |
| 699 |
|
| 700 |
updateFacetsFilter(state); |
| 701 |
} |
| 702 |
|
| 703 |
void StereogramDialog::onFilterSizeChanged(double) |
| 704 |
{ |
| 705 |
if (m_classifWidget) |
| 706 |
{ |
| 707 |
m_classifWidget->enableMouseTracking(filterFacetsGroupBox->isChecked(), dipSpanDoubleSpinBox->value(), dipDirSpanDoubleSpinBox->value()); |
| 708 |
|
| 709 |
updateFacetsFilter(true); |
| 710 |
} |
| 711 |
} |
| 712 |
|
| 713 |
void StereogramDialog::onFilterCenterChanged(double) |
| 714 |
{ |
| 715 |
if (m_classifWidget) |
| 716 |
{ |
| 717 |
m_classifWidget->setTrackedCenter(dipDoubleSpinBox->value(), dipDirDoubleSpinBox->value()); |
| 718 |
m_classifWidget->update(); |
| 719 |
|
| 720 |
updateFacetsFilter(true); |
| 721 |
} |
| 722 |
} |
| 723 |
|
| 724 |
void StereogramDialog::onPointClicked(double dip_deg, double dipDir_deg) |
| 725 |
{ |
| 726 |
//filter mode enabled? |
| 727 |
if (filterFacetsGroupBox->isChecked()) |
| 728 |
{ |
| 729 |
dipDoubleSpinBox->blockSignals(true); |
| 730 |
dipDirDoubleSpinBox->blockSignals(true); |
| 731 |
|
| 732 |
dipDoubleSpinBox->setValue(dip_deg); |
| 733 |
dipDirDoubleSpinBox->setValue(dipDir_deg); |
| 734 |
|
| 735 |
dipDoubleSpinBox->blockSignals(false); |
| 736 |
dipDirDoubleSpinBox->blockSignals(false); |
| 737 |
|
| 738 |
if (m_classifWidget) |
| 739 |
m_classifWidget->update(); |
| 740 |
|
| 741 |
updateFacetsFilter(true); |
| 742 |
} |
| 743 |
} |
| 744 |
|
| 745 |
void StereogramDialog::updateFacetsFilter(bool enable) |
| 746 |
{ |
| 747 |
if (!m_app) |
| 748 |
return; |
| 749 |
|
| 750 |
//try to find the associated entity |
| 751 |
ccHObject* root = m_app->dbRootObject(); |
| 752 |
ccHObject* entity = (root ? root->find(m_facetGroupUniqueID) : nullptr); |
| 753 |
if (!entity) |
| 754 |
return; |
| 755 |
|
| 756 |
PointCoordinateType dipFilter = static_cast<PointCoordinateType>(dipDoubleSpinBox->value()); |
| 757 |
PointCoordinateType dipDirFilter = static_cast<PointCoordinateType>(dipDirDoubleSpinBox->value()); |
| 758 |
|
| 759 |
PointCoordinateType halfDipSpan = static_cast<PointCoordinateType>(dipSpanDoubleSpinBox->value())/2; |
| 760 |
PointCoordinateType halfDipDirSpan = static_cast<PointCoordinateType>(dipDirSpanDoubleSpinBox->value())/2; |
| 761 |
|
| 762 |
//a set of facets? |
| 763 |
if (entity->isA(CC_TYPES::HIERARCHY_OBJECT)) |
| 764 |
{ |
| 765 |
ccHObject::Container facets; |
| 766 |
entity->filterChildren(facets, true, CC_TYPES::FACET); |
| 767 |
if (facets.empty()) |
| 768 |
return; |
| 769 |
|
| 770 |
for (size_t i = 0; i < facets.size(); ++i) |
| 771 |
{ |
| 772 |
ccFacet* facet = static_cast<ccFacet*>(facets[i]); |
| 773 |
|
| 774 |
bool visible = true; |
| 775 |
if (enable) |
| 776 |
{ |
| 777 |
CCVector3 N = facet->getNormal(); |
| 778 |
PointCoordinateType dip = 0; |
| 779 |
PointCoordinateType dipDir = 0; |
| 780 |
ccNormalVectors::ConvertNormalToDipAndDipDir(N, dip, dipDir); |
| 781 |
|
| 782 |
double dDip = std::abs(dip - dipFilter); |
| 783 |
double dDipDir = std::abs(dipDir - dipDirFilter); |
| 784 |
|
| 785 |
visible = ( ( dDip <= halfDipSpan || dDip >= 360.0 - halfDipSpan) |
| 786 |
&& ( dDipDir <= halfDipDirSpan || dDipDir >= 360.0 - halfDipDirSpan) ); |
| 787 |
} |
| 788 |
|
| 789 |
//facet->setEnabled(visible); |
| 790 |
ccMesh* polygon = facet->getPolygon(); |
| 791 |
if (polygon) |
| 792 |
{ |
| 793 |
polygon->setVisible(visible); |
| 794 |
} |
| 795 |
ccPolyline* polyline = facet->getContour(); |
| 796 |
if (polyline) |
| 797 |
{ |
| 798 |
//polyline->showColors(visible); |
| 799 |
polyline->setWidth(static_cast<PointCoordinateType>(visible ? 2 : 1)); |
| 800 |
} |
| 801 |
} |
| 802 |
} |
| 803 |
//or a cloud? |
| 804 |
else if (entity->isA(CC_TYPES::POINT_CLOUD)) |
| 805 |
{ |
| 806 |
ccPointCloud* cloud = static_cast<ccPointCloud*>(entity); |
| 807 |
if (!cloud->hasNormals()) |
| 808 |
return; |
| 809 |
|
| 810 |
if (enable) |
| 811 |
{ |
| 812 |
unsigned count = cloud->size(); |
| 813 |
if (count == 0) |
| 814 |
return; |
| 815 |
if (!cloud->resetVisibilityArray()) |
| 816 |
{ |
| 817 |
m_app->dispToConsole("Not enough memory!"); |
| 818 |
return; |
| 819 |
} |
| 820 |
ccPointCloud::VisibilityTableType& visTable = cloud->getTheVisibilityArray(); |
| 821 |
assert(!visTable.empty()); |
| 822 |
|
| 823 |
for (unsigned i = 0; i < static_cast<unsigned>(count); ++i) |
| 824 |
{ |
| 825 |
CCVector3 N = cloud->getPointNormal(i); |
| 826 |
PointCoordinateType dip = 0; |
| 827 |
PointCoordinateType dipDir = 0; |
| 828 |
ccNormalVectors::ConvertNormalToDipAndDipDir(N, dip, dipDir); |
| 829 |
|
| 830 |
double dDip = std::abs(dip - dipFilter); |
| 831 |
double dDipDir = std::abs(dipDir - dipDirFilter); |
| 832 |
|
| 833 |
bool visible = ( ( dDip <= halfDipSpan || dDip >= 360.0 - halfDipSpan) |
| 834 |
&& ( dDipDir <= halfDipDirSpan || dDipDir >= 360.0 - halfDipDirSpan) ); |
| 835 |
|
| 836 |
visTable[i] = (visible ? CCCoreLib::POINT_VISIBLE : CCCoreLib::POINT_HIDDEN); |
| 837 |
} |
| 838 |
} |
| 839 |
else |
| 840 |
{ |
| 841 |
cloud->unallocateVisibilityArray(); |
| 842 |
} |
| 843 |
} |
| 844 |
|
| 845 |
if (m_app) |
| 846 |
m_app->redrawAll(); |
| 847 |
} |
| 848 |
|
| 849 |
void StereogramDialog::exportCurrentSelection() |
| 850 |
{ |
| 851 |
if (!m_app) |
| 852 |
return; |
| 853 |
|
| 854 |
//try to find the associated entity |
| 855 |
ccHObject* root = m_app->dbRootObject(); |
| 856 |
ccHObject* entity = (root ? root->find(m_facetGroupUniqueID) : nullptr); |
| 857 |
if (!entity) |
| 858 |
return; |
| 859 |
|
| 860 |
PointCoordinateType dipFilter = static_cast<PointCoordinateType>(dipDoubleSpinBox->value()); |
| 861 |
PointCoordinateType dipDirFilter = static_cast<PointCoordinateType>(dipDirDoubleSpinBox->value()); |
| 862 |
|
| 863 |
PointCoordinateType halfDipSpan = static_cast<PointCoordinateType>(dipSpanDoubleSpinBox->value()) / 2; |
| 864 |
PointCoordinateType halfDipDirSpan = static_cast<PointCoordinateType>(dipDirSpanDoubleSpinBox->value()) / 2; |
| 865 |
|
| 866 |
QString selectionSuffix = QString(" [dip=(%1 - %2)][dipDir=(%3 - %4)]").arg(dipFilter - halfDipSpan).arg(dipFilter + halfDipSpan).arg(dipDirFilter - halfDipDirSpan).arg(dipDirFilter + halfDipDirSpan); |
| 867 |
|
| 868 |
//a set of facets? |
| 869 |
if (entity->isA(CC_TYPES::HIERARCHY_OBJECT)) |
| 870 |
{ |
| 871 |
ccHObject::Container facets; |
| 872 |
entity->filterChildren(facets,true,CC_TYPES::FACET); |
| 873 |
if (facets.empty()) |
| 874 |
return; |
| 875 |
ccHObject* newGroup = new ccHObject(entity->getName() + selectionSuffix); |
| 876 |
|
| 877 |
for (size_t i = 0; i < facets.size(); ++i) |
| 878 |
{ |
| 879 |
ccFacet* facet = static_cast<ccFacet*>(facets[i]); |
| 880 |
|
| 881 |
CCVector3 N = facet->getNormal(); |
| 882 |
PointCoordinateType dip = 0; |
| 883 |
PointCoordinateType dipDir = 0; |
| 884 |
ccNormalVectors::ConvertNormalToDipAndDipDir(N, dip, dipDir); |
| 885 |
|
| 886 |
double dDip = std::abs(dip - dipFilter); |
| 887 |
double dDipDir = std::abs(dipDir - dipDirFilter); |
| 888 |
|
| 889 |
bool visible = ( ( dDip <= halfDipSpan || dDip >= 360.0 - halfDipSpan) |
| 890 |
&& ( dDipDir <= halfDipDirSpan || dDipDir >= 360.0 - halfDipDirSpan) ); |
| 891 |
|
| 892 |
if (visible) |
| 893 |
{ |
| 894 |
ccFacet* facetClone = facet->clone(); |
| 895 |
if (facetClone) |
| 896 |
newGroup->addChild(facetClone); |
| 897 |
} |
| 898 |
} |
| 899 |
|
| 900 |
if (newGroup->getChildrenNumber() != 0) |
| 901 |
{ |
| 902 |
m_app->addToDB(newGroup); |
| 903 |
} |
| 904 |
else |
| 905 |
{ |
| 906 |
delete newGroup; |
| 907 |
newGroup = nullptr; |
| 908 |
} |
| 909 |
} |
| 910 |
//or a cloud? |
| 911 |
else if (entity->isA(CC_TYPES::POINT_CLOUD)) |
| 912 |
{ |
| 913 |
ccPointCloud* cloud = static_cast<ccPointCloud*>(entity); |
| 914 |
if (!cloud->isVisibilityTableInstantiated()) |
| 915 |
return; |
| 916 |
|
| 917 |
ccGenericPointCloud* subset = cloud->createNewCloudFromVisibilitySelection(); |
| 918 |
if (subset) |
| 919 |
{ |
| 920 |
if (subset == cloud) |
| 921 |
{ |
| 922 |
ccLog::Warning("All points fall inside the selection"); |
| 923 |
} |
| 924 |
else |
| 925 |
{ |
| 926 |
if (subset->size() != 0) |
| 927 |
{ |
| 928 |
subset->setName(cloud->getName() + selectionSuffix); |
| 929 |
m_app->addToDB(subset); |
| 930 |
} |
| 931 |
else |
| 932 |
{ |
| 933 |
ccLog::Warning("No point falls inside the selection"); |
| 934 |
delete subset; |
| 935 |
subset = nullptr; |
| 936 |
} |
| 937 |
} |
| 938 |
} |
| 939 |
} |
| 940 |
|
| 941 |
if (m_app) |
| 942 |
m_app->redrawAll(); |
| 943 |
} |
| 944 |
|
| 945 |
void StereogramDialog::onDensityColorStepsChanged(int value) |
| 946 |
{ |
| 947 |
if (m_classifWidget && value >= ccColorScale::MIN_STEPS) |
| 948 |
{ |
| 949 |
m_classifWidget->setDensityColorScaleSteps(static_cast<unsigned>(value)); |
| 950 |
m_classifWidget->update(); |
| 951 |
} |
| 952 |
} |
| 953 |
|
| 954 |
void StereogramDialog::onTicksFreqChanged(int value) |
| 955 |
{ |
| 956 |
if (m_classifWidget) |
| 957 |
{ |
| 958 |
m_classifWidget->setTicksFreq(value); |
| 959 |
m_classifWidget->update(); |
| 960 |
} |
| 961 |
} |
| 962 |
|
| 963 |
void StereogramDialog::onHSVColorsToggled(bool state) |
| 964 |
{ |
| 965 |
if (m_classifWidget) |
| 966 |
{ |
| 967 |
m_classifWidget->showHSVRing(state); |
| 968 |
m_classifWidget->update(); |
| 969 |
} |
| 970 |
} |
| 971 |
|
| 972 |
void StereogramDialog::colorScaleChanged(int) |
| 973 |
{ |
| 974 |
if (!m_classifWidget || !m_colorScaleSelector) |
| 975 |
return; |
| 976 |
|
| 977 |
ccColorScale::Shared colorScale = m_colorScaleSelector->getSelectedScale(); |
| 978 |
unsigned steps = static_cast<unsigned>(colorScaleStepsSpinBox->value()); |
| 979 |
|
| 980 |
m_classifWidget->setDensityColorScale(colorScale); |
| 981 |
m_classifWidget->setDensityColorScaleSteps(steps); |
| 982 |
m_classifWidget->update(); |
| 983 |
} |
| 984 |
|
| 985 |
void StereogramDialog::spawnColorScaleEditor() |
| 986 |
{ |
| 987 |
if (!m_app || !m_app->getColorScalesManager()) |
| 988 |
return; |
| 989 |
|
| 990 |
ccColorScale::Shared colorScale = (m_colorScaleSelector ? m_colorScaleSelector->getSelectedScale() : m_app->getColorScalesManager()->getDefaultScale(ccColorScalesManager::BGYR)); |
| 991 |
ccColorScaleEditorDialog cseDlg(m_app->getColorScalesManager(), m_app, colorScale, m_app->getMainWindow()); |
| 992 |
if (cseDlg.exec()) |
| 993 |
{ |
| 994 |
colorScale = cseDlg.getActiveScale(); |
| 995 |
if (colorScale && m_colorScaleSelector) |
| 996 |
{ |
| 997 |
m_colorScaleSelector->init(); //in fact it's a 're-init' |
| 998 |
m_colorScaleSelector->setSelectedScale(colorScale->getUuid()); |
| 999 |
} |
| 1000 |
|
| 1001 |
//save current scale manager state to persistent settings |
| 1002 |
m_app->getColorScalesManager()->toPersistentSettings(); |
| 1003 |
} |
| 1004 |
} |