| 1 |
//########################################################################## |
| 2 |
//# # |
| 3 |
//# CLOUDCOMPARE PLUGIN: qMPlane # |
| 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 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: AIT Austrian Institute of Technology GmbH # |
| 15 |
//# # |
| 16 |
//########################################################################## |
| 17 |
|
| 18 |
|
| 19 |
// Local dependencies |
| 20 |
#include "ccMeasurementRecorder.h" |
| 21 |
#include "ccItemTree.h" |
| 22 |
|
| 23 |
// CC |
| 24 |
#include "ccScalarField.h" |
| 25 |
|
| 26 |
|
| 27 |
constexpr char *ROOT_FOLDER_NAME = "MPlane"; |
| 28 |
constexpr char *FITTING_POINT_FOLDER_NAME = "Fitting-points"; |
| 29 |
constexpr char *MEASUREMENT_FOLDER_NAME = "Measurements"; |
| 30 |
constexpr char *MPLANE_PLANE_NAME = "Fitting-plane"; |
| 31 |
constexpr char * MPLANE_SCALARFIELD_NAME = "MPlane Distance"; |
| 32 |
|
| 33 |
const std::vector<ccMPlanePoint>& ccMeasurementRecorder::getFittingPoints() const |
| 34 |
{ |
| 35 |
return m_fittingPoints; |
| 36 |
} |
| 37 |
|
| 38 |
const std::vector<ccMPlanePoint>& ccMeasurementRecorder::getMeasurementPoints() const |
| 39 |
{ |
| 40 |
return m_measurementPoints; |
| 41 |
} |
| 42 |
|
| 43 |
unsigned int ccMeasurementRecorder::getActualFittingPointIndex() const |
| 44 |
{ |
| 45 |
return static_cast<unsigned int>(m_fittingPoints.size()); |
| 46 |
} |
| 47 |
|
| 48 |
unsigned int ccMeasurementRecorder::getFittingPointAmount() const |
| 49 |
{ |
| 50 |
return static_cast<unsigned int>(m_fittingPoints.size()); |
| 51 |
} |
| 52 |
|
| 53 |
void ccMeasurementRecorder::loadDataFromSelectedCloud() |
| 54 |
{ |
| 55 |
loadFolders(); |
| 56 |
loadFittingPoints(); |
| 57 |
loadMeasurementPoints(); |
| 58 |
loadAndDeleteFittingPlane(); |
| 59 |
} |
| 60 |
|
| 61 |
void ccMeasurementRecorder::addFittingPoint(const ccPickingListener::PickedItem & item) |
| 62 |
{ |
| 63 |
cc2DLabel *newLabel = CC_ITEM_TREE::createPointLabel2D( |
| 64 |
QString("Point %1").arg(getActualFittingPointIndex()), |
| 65 |
m_rootCloud, |
| 66 |
item.clickPoint, |
| 67 |
item.itemIndex |
| 68 |
); |
| 69 |
m_fittingPointFolder->addChild(newLabel); |
| 70 |
m_app->addToDB(newLabel, false, true, false, false); |
| 71 |
m_fittingPoints.push_back(ccMPlanePoint(newLabel)); |
| 72 |
} |
| 73 |
|
| 74 |
void ccMeasurementRecorder::addMeasurementPoint(const ccPickingListener::PickedItem & item, float distance) |
| 75 |
{ |
| 76 |
QString measurementName = QString("#%1").arg(m_measurementPoints.size()); |
| 77 |
cc2DLabel *measureLabel = CC_ITEM_TREE::createPointLabel2D(measurementName, m_rootCloud, item.clickPoint, item.itemIndex); |
| 78 |
m_measurementFolder->addChild(measureLabel); |
| 79 |
m_app->addToDB(measureLabel, false, true, false, false); |
| 80 |
|
| 81 |
m_measurementPoints.push_back(ccMPlanePoint(measureLabel)); |
| 82 |
m_measurementPoints.back().setDistance(distance); |
| 83 |
} |
| 84 |
|
| 85 |
void ccMeasurementRecorder::loadFolders() |
| 86 |
{ |
| 87 |
m_rootFolder = CC_ITEM_TREE::findOrCreateContainer(m_rootCloud, ROOT_FOLDER_NAME, m_app); |
| 88 |
m_fittingPointFolder = CC_ITEM_TREE::findOrCreateContainer(m_rootFolder, FITTING_POINT_FOLDER_NAME, m_app); |
| 89 |
m_measurementFolder = CC_ITEM_TREE::findOrCreateContainer(m_rootFolder, MEASUREMENT_FOLDER_NAME, m_app); |
| 90 |
} |
| 91 |
|
| 92 |
void ccMeasurementRecorder::loadFittingPoints() |
| 93 |
{ |
| 94 |
std::vector<ccHObject*> fittingPointLabels; |
| 95 |
m_fittingPointFolder->filterChildren(fittingPointLabels, false, CC_TYPES::LABEL_2D); |
| 96 |
std::transform(std::begin(fittingPointLabels), |
| 97 |
std::end(fittingPointLabels), |
| 98 |
std::back_inserter(m_fittingPoints), |
| 99 |
[](ccHObject* item) { return ccMPlanePoint(static_cast<cc2DLabel*>(item)); }); |
| 100 |
|
| 101 |
} |
| 102 |
|
| 103 |
void ccMeasurementRecorder::loadMeasurementPoints() |
| 104 |
{ |
| 105 |
std::vector<ccHObject*> measurementLabels; |
| 106 |
m_measurementFolder->filterChildren(measurementLabels, false, CC_TYPES::LABEL_2D); |
| 107 |
std::transform(std::begin(measurementLabels), |
| 108 |
std::end(measurementLabels), |
| 109 |
std::back_inserter(m_measurementPoints), |
| 110 |
[](ccHObject* item) { return ccMPlanePoint(static_cast<cc2DLabel*>(item)); }); |
| 111 |
} |
| 112 |
|
| 113 |
void ccMeasurementRecorder::loadAndDeleteFittingPlane() |
| 114 |
{ |
| 115 |
m_plane = static_cast<ccPlane*>(CC_ITEM_TREE::findItemInHierarchy(m_rootFolder, CC_ITEM_TREE::CC_TYPES_MAP::PLANE, MPLANE_PLANE_NAME)); |
| 116 |
deletePlane(); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
bool ccMeasurementRecorder::renameMeasurement(const QString& newName, unsigned int measurementIndex) |
| 121 |
{ |
| 122 |
auto element = std::find_if( |
| 123 |
std::begin(m_measurementPoints), |
| 124 |
std::end(m_measurementPoints), |
| 125 |
[&newName](const ccMPlanePoint& point) { |
| 126 |
return point.getName() == newName; |
| 127 |
} |
| 128 |
); |
| 129 |
|
| 130 |
if (element != std::end(m_measurementPoints)) { |
| 131 |
return false; |
| 132 |
} |
| 133 |
|
| 134 |
m_measurementPoints[measurementIndex].setName(newName); |
| 135 |
m_measurementPoints[measurementIndex].getLabel()->redrawDisplay(); |
| 136 |
return true; |
| 137 |
} |
| 138 |
|
| 139 |
void ccMeasurementRecorder::updateMeasurement(float distance, unsigned int measurementIndex) |
| 140 |
{ |
| 141 |
m_measurementPoints[measurementIndex].setDistance(distance); |
| 142 |
} |
| 143 |
|
| 144 |
ccPlane * ccMeasurementRecorder::getPlane() const |
| 145 |
{ |
| 146 |
return m_plane; |
| 147 |
} |
| 148 |
|
| 149 |
void ccMeasurementRecorder::setPlane(const ccPlane *plane) |
| 150 |
{ |
| 151 |
deletePlane(); |
| 152 |
m_plane = const_cast<ccPlane*>(plane); |
| 153 |
|
| 154 |
CCVector3 bbMin, bbMax; |
| 155 |
m_rootCloud->getBoundingBox(bbMin, bbMax); |
| 156 |
float length = std::max(abs(bbMax.x - bbMin.x), std::max(abs(bbMax.y - bbMin.y), abs(bbMax.z - bbMin.z))); |
| 157 |
m_plane->setXWidth(PointCoordinateType(length)); |
| 158 |
m_plane->setYWidth(PointCoordinateType(length)); |
| 159 |
|
| 160 |
m_measurementFolder->addChild(m_plane); |
| 161 |
m_plane->setDisplay(m_rootCloud->getDisplay()); |
| 162 |
m_plane->prepareDisplayForRefresh_recursive(); |
| 163 |
m_app->addToDB(m_plane); |
| 164 |
} |
| 165 |
|
| 166 |
void ccMeasurementRecorder::deletePlane() |
| 167 |
{ |
| 168 |
if (m_plane) { |
| 169 |
m_app->removeFromDB(m_plane); |
| 170 |
m_plane = nullptr; |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
void ccMeasurementRecorder::deleteFittingPoint(unsigned int index) |
| 175 |
{ |
| 176 |
m_app->removeFromDB(m_fittingPoints[index].getLabel()); |
| 177 |
m_fittingPoints.erase(m_fittingPoints.begin() + index); |
| 178 |
} |
| 179 |
|
| 180 |
void ccMeasurementRecorder::renameFittingPoint(const QString& newName, unsigned int fittingPointIndex) |
| 181 |
{ |
| 182 |
m_fittingPoints[fittingPointIndex].getLabel()->setName(QString("Point %1").arg(fittingPointIndex)); |
| 183 |
} |