From c91b82db0b32c3f69b7558905f2702fa387f930a Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 1 Sep 2023 17:33:18 +0200 Subject: [PATCH] Points: apply clang-formatting --- src/Mod/Points/App/AppPoints.cpp | 27 +- src/Mod/Points/App/AppPointsPy.cpp | 151 ++- src/Mod/Points/App/Points.cpp | 168 ++- src/Mod/Points/App/Points.h | 118 +- src/Mod/Points/App/PointsAlgos.cpp | 1244 +++++++++-------- src/Mod/Points/App/PointsAlgos.h | 56 +- src/Mod/Points/App/PointsFeature.cpp | 26 +- src/Mod/Points/App/PointsFeature.h | 25 +- src/Mod/Points/App/PointsGrid.cpp | 1432 +++++++++++--------- src/Mod/Points/App/PointsGrid.h | 451 +++--- src/Mod/Points/App/PointsPyImp.cpp | 99 +- src/Mod/Points/App/PreCompiled.h | 35 +- src/Mod/Points/App/Properties.cpp | 274 ++-- src/Mod/Points/App/Properties.h | 136 +- src/Mod/Points/App/PropertyPointKernel.cpp | 69 +- src/Mod/Points/App/PropertyPointKernel.h | 30 +- src/Mod/Points/App/Structured.cpp | 22 +- src/Mod/Points/App/Structured.h | 11 +- src/Mod/Points/App/Tools.h | 16 +- src/Mod/Points/Gui/AppPointsGui.cpp | 21 +- src/Mod/Points/Gui/Command.cpp | 247 ++-- src/Mod/Points/Gui/DlgPointsReadImp.cpp | 8 +- src/Mod/Points/Gui/DlgPointsReadImp.h | 23 +- src/Mod/Points/Gui/PreCompiled.h | 38 +- src/Mod/Points/Gui/ViewProvider.cpp | 252 ++-- src/Mod/Points/Gui/ViewProvider.h | 65 +- src/Mod/Points/Gui/Workbench.cpp | 6 +- src/Mod/Points/Gui/Workbench.h | 19 +- src/Mod/Points/Init.py | 48 +- src/Mod/Points/InitGui.py | 54 +- src/Mod/Points/PointsGlobal.h | 10 +- src/Mod/Points/pointscommands/commands.py | 7 +- 32 files changed, 2829 insertions(+), 2359 deletions(-) diff --git a/src/Mod/Points/App/AppPoints.cpp b/src/Mod/Points/App/AppPoints.cpp index 38e8051678..fbdc5c8a57 100644 --- a/src/Mod/Points/App/AppPoints.cpp +++ b/src/Mod/Points/App/AppPoints.cpp @@ -32,13 +32,15 @@ #include "Structured.h" -namespace Points { - extern PyObject* initModule(); +namespace Points +{ +extern PyObject* initModule(); } /* Python entry */ PyMOD_INIT_FUNC(Points) { + // clang-format off PyObject* pointsModule = Points::initModule(); Base::Console().Log("Loading Points module... done\n"); @@ -46,17 +48,18 @@ PyMOD_INIT_FUNC(Points) Base::Interpreter().addType(&Points::PointsPy::Type, pointsModule, "Points"); // add properties - Points::PropertyGreyValue ::init(); - Points::PropertyGreyValueList ::init(); - Points::PropertyNormalList ::init(); - Points::PropertyCurvatureList ::init(); - Points::PropertyPointKernel ::init(); + Points::PropertyGreyValue ::init(); + Points::PropertyGreyValueList ::init(); + Points::PropertyNormalList ::init(); + Points::PropertyCurvatureList ::init(); + Points::PropertyPointKernel ::init(); // add data types - Points::Feature ::init(); - Points::Structured ::init(); - Points::FeatureCustom ::init(); - Points::StructuredCustom ::init(); - Points::FeaturePython ::init(); + Points::Feature ::init(); + Points::Structured ::init(); + Points::FeatureCustom ::init(); + Points::StructuredCustom ::init(); + Points::FeaturePython ::init(); PyMOD_Return(pointsModule); + // clang-format on } diff --git a/src/Mod/Points/App/AppPointsPy.cpp b/src/Mod/Points/App/AppPointsPy.cpp index 3ab0473d7c..ee0e000965 100644 --- a/src/Mod/Points/App/AppPointsPy.cpp +++ b/src/Mod/Points/App/AppPointsPy.cpp @@ -22,7 +22,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include @@ -31,8 +31,8 @@ #include #include #include -#include #include +#include #include "Points.h" #include "PointsAlgos.h" @@ -41,29 +41,32 @@ #include "Structured.h" -namespace Points { -class Module : public Py::ExtensionModule +namespace Points +{ +class Module: public Py::ExtensionModule { public: - Module() : Py::ExtensionModule("Points") + Module() + : Py::ExtensionModule("Points") { - add_varargs_method("open", &Module::open - ); - add_varargs_method("insert", &Module::importer - ); - add_varargs_method("export", &Module::exporter - ); - add_varargs_method("show", &Module::show, - "show(points,[string]) -- Add the points to the active document or create one if no document exists." - ); - initialize("This module is the Points module."); // register with Python + add_varargs_method("open", &Module::open); + add_varargs_method("insert", &Module::importer); + add_varargs_method("export", &Module::exporter); + add_varargs_method("show", + &Module::show, + "show(points,[string]) -- Add the points to the active document or " + "create one if no document exists."); + initialize("This module is the Points module.");// register with Python } private: std::tuple readE57Settings() const { - Base::Reference hGrp = App::GetApplication().GetUserParameter() - .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Points/E57"); + Base::Reference hGrp = App::GetApplication() + .GetUserParameter() + .GetGroup("BaseApp") + ->GetGroup("Preferences") + ->GetGroup("Mod/Points/E57"); bool useColor = hGrp->GetBool("UseColor", true); bool checkState = hGrp->GetBool("CheckInvalidState", true); double minDistance = hGrp->GetFloat("MinDistance", -1.); @@ -73,8 +76,9 @@ private: Py::Object open(const Py::Tuple& args) { char* Name; - if (!PyArg_ParseTuple(args.ptr(), "et", "utf-8", &Name)) + if (!PyArg_ParseTuple(args.ptr(), "et", "utf-8", &Name)) { throw Py::Exception(); + } std::string EncodedName = std::string(Name); PyMem_Free(Name); @@ -83,8 +87,9 @@ private: Base::FileInfo file(EncodedName.c_str()); // extract ending - if (file.extension().empty()) + if (file.extension().empty()) { throw Py::RuntimeError("No file extension"); + } std::unique_ptr reader; if (file.hasExtension("asc")) { @@ -92,7 +97,9 @@ private: } else if (file.hasExtension("e57")) { auto setting = readE57Settings(); - reader = std::make_unique(std::get<0>(setting), std::get<1>(setting), std::get<2>(setting)); + reader = std::make_unique(std::get<0>(setting), + std::get<1>(setting), + std::get<2>(setting)); } else if (file.hasExtension("ply")) { reader = std::make_unique(); @@ -114,13 +121,13 @@ private: if (reader->isStructured()) { pcFeature = new Points::StructuredCustom(); - App::PropertyInteger* width = static_cast - (pcFeature->getPropertyByName("Width")); + App::PropertyInteger* width = + static_cast(pcFeature->getPropertyByName("Width")); if (width) { width->setValue(reader->getWidth()); } - App::PropertyInteger* height = static_cast - (pcFeature->getPropertyByName("Height")); + App::PropertyInteger* height = + static_cast(pcFeature->getPropertyByName("Height")); if (height) { height->setValue(reader->getHeight()); } @@ -132,24 +139,26 @@ private: pcFeature->Points.setValue(reader->getPoints()); // add gray values if (reader->hasIntensities()) { - Points::PropertyGreyValueList* prop = static_cast - (pcFeature->addDynamicProperty("Points::PropertyGreyValueList", "Intensity")); + Points::PropertyGreyValueList* prop = + static_cast( + pcFeature->addDynamicProperty("Points::PropertyGreyValueList", + "Intensity")); if (prop) { prop->setValues(reader->getIntensities()); } } // add colors if (reader->hasColors()) { - App::PropertyColorList* prop = static_cast - (pcFeature->addDynamicProperty("App::PropertyColorList", "Color")); + App::PropertyColorList* prop = static_cast( + pcFeature->addDynamicProperty("App::PropertyColorList", "Color")); if (prop) { prop->setValues(reader->getColors()); } } // add normals if (reader->hasNormals()) { - Points::PropertyNormalList* prop = static_cast - (pcFeature->addDynamicProperty("Points::PropertyNormalList", "Normal")); + Points::PropertyNormalList* prop = static_cast( + pcFeature->addDynamicProperty("Points::PropertyNormalList", "Normal")); if (prop) { prop->setValues(reader->getNormals()); } @@ -189,8 +198,9 @@ private: { char* Name; const char* DocName; - if (!PyArg_ParseTuple(args.ptr(), "ets", "utf-8", &Name, &DocName)) + if (!PyArg_ParseTuple(args.ptr(), "ets", "utf-8", &Name, &DocName)) { throw Py::Exception(); + } std::string EncodedName = std::string(Name); PyMem_Free(Name); @@ -199,8 +209,9 @@ private: Base::FileInfo file(EncodedName.c_str()); // extract ending - if (file.extension().empty()) + if (file.extension().empty()) { throw Py::RuntimeError("No file extension"); + } std::unique_ptr reader; if (file.hasExtension("asc")) { @@ -208,7 +219,9 @@ private: } else if (file.hasExtension("e57")) { auto setting = readE57Settings(); - reader = std::make_unique(std::get<0>(setting), std::get<1>(setting), std::get<2>(setting)); + reader = std::make_unique(std::get<0>(setting), + std::get<1>(setting), + std::get<2>(setting)); } else if (file.hasExtension("ply")) { reader = std::make_unique(); @@ -233,13 +246,13 @@ private: if (reader->isStructured()) { pcFeature = new Points::StructuredCustom(); - App::PropertyInteger* width = static_cast - (pcFeature->getPropertyByName("Width")); + App::PropertyInteger* width = + static_cast(pcFeature->getPropertyByName("Width")); if (width) { width->setValue(reader->getWidth()); } - App::PropertyInteger* height = static_cast - (pcFeature->getPropertyByName("Height")); + App::PropertyInteger* height = + static_cast(pcFeature->getPropertyByName("Height")); if (height) { height->setValue(reader->getHeight()); } @@ -251,24 +264,26 @@ private: pcFeature->Points.setValue(reader->getPoints()); // add gray values if (reader->hasIntensities()) { - Points::PropertyGreyValueList* prop = static_cast - (pcFeature->addDynamicProperty("Points::PropertyGreyValueList", "Intensity")); + Points::PropertyGreyValueList* prop = + static_cast( + pcFeature->addDynamicProperty("Points::PropertyGreyValueList", + "Intensity")); if (prop) { prop->setValues(reader->getIntensities()); } } // add colors if (reader->hasColors()) { - App::PropertyColorList* prop = static_cast - (pcFeature->addDynamicProperty("App::PropertyColorList", "Color")); + App::PropertyColorList* prop = static_cast( + pcFeature->addDynamicProperty("App::PropertyColorList", "Color")); if (prop) { prop->setValues(reader->getColors()); } } // add normals if (reader->hasNormals()) { - Points::PropertyNormalList* prop = static_cast - (pcFeature->addDynamicProperty("Points::PropertyNormalList", "Normal")); + Points::PropertyNormalList* prop = static_cast( + pcFeature->addDynamicProperty("Points::PropertyNormalList", "Normal")); if (prop) { prop->setValues(reader->getNormals()); } @@ -280,8 +295,8 @@ private: pcFeature->purgeTouched(); } else { - Points::Feature* pcFeature = static_cast - (pcDoc->addObject("Points::Feature", file.fileNamePure().c_str())); + Points::Feature* pcFeature = static_cast( + pcDoc->addObject("Points::Feature", file.fileNamePure().c_str())); pcFeature->Points.setValue(reader->getPoints()); pcDoc->recomputeFeature(pcFeature); pcFeature->purgeTouched(); @@ -299,8 +314,9 @@ private: PyObject* object; char* Name; - if (!PyArg_ParseTuple(args.ptr(), "Oet", &object, "utf-8", &Name)) + if (!PyArg_ParseTuple(args.ptr(), "Oet", &object, "utf-8", &Name)) { throw Py::Exception(); + } std::string encodedName = std::string(Name); PyMem_Free(Name); @@ -308,15 +324,17 @@ private: Base::FileInfo file(encodedName); // extract ending - if (file.extension().empty()) + if (file.extension().empty()) { throw Py::RuntimeError("No file extension"); + } Py::Sequence list(object); Base::Type pointsId = Base::Type::fromName("Points::Feature"); for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { PyObject* item = (*it).ptr(); if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) { - App::DocumentObject* obj = static_cast(item)->getDocumentObjectPtr(); + App::DocumentObject* obj = + static_cast(item)->getDocumentObjectPtr(); if (obj->getTypeId().isDerivedFrom(pointsId)) { // get relative placement Points::Feature* fea = static_cast(obj); @@ -338,31 +356,32 @@ private: } // get additional properties if there - App::PropertyInteger* width = dynamic_cast - (fea->getPropertyByName("Width")); + App::PropertyInteger* width = + dynamic_cast(fea->getPropertyByName("Width")); if (width) { writer->setWidth(width->getValue()); } - App::PropertyInteger* height = dynamic_cast - (fea->getPropertyByName("Height")); + App::PropertyInteger* height = + dynamic_cast(fea->getPropertyByName("Height")); if (height) { writer->setHeight(height->getValue()); } // get gray values - Points::PropertyGreyValueList* grey = dynamic_cast - (fea->getPropertyByName("Intensity")); + Points::PropertyGreyValueList* grey = + dynamic_cast( + fea->getPropertyByName("Intensity")); if (grey) { writer->setIntensities(grey->getValues()); } // get colors - App::PropertyColorList* col = dynamic_cast - (fea->getPropertyByName("Color")); + App::PropertyColorList* col = + dynamic_cast(fea->getPropertyByName("Color")); if (col) { writer->setColors(col->getValues()); } // get normals - Points::PropertyNormalList* nor = dynamic_cast - (fea->getPropertyByName("Normal")); + Points::PropertyNormalList* nor = + dynamic_cast(fea->getPropertyByName("Normal")); if (nor) { writer->setNormals(nor->getValues()); } @@ -373,7 +392,8 @@ private: break; } else { - Base::Console().Message("'%s' is not a point object, export will be ignored.\n", obj->Label.getValue()); + Base::Console().Message("'%s' is not a point object, export will be ignored.\n", + obj->Label.getValue()); } } } @@ -385,18 +405,21 @@ private: { PyObject* pcObj; char* name = "Points"; - if (!PyArg_ParseTuple(args.ptr(), "O!|s", &(PointsPy::Type), &pcObj, &name)) + if (!PyArg_ParseTuple(args.ptr(), "O!|s", &(PointsPy::Type), &pcObj, &name)) { throw Py::Exception(); + } try { App::Document* pcDoc = App::GetApplication().getActiveDocument(); - if (!pcDoc) + if (!pcDoc) { pcDoc = App::GetApplication().newDocument(); + } PointsPy* pPoints = static_cast(pcObj); - Points::Feature* pcFeature = static_cast(pcDoc->addObject("Points::Feature", name)); + Points::Feature* pcFeature = + static_cast(pcDoc->addObject("Points::Feature", name)); // copy the data pcFeature->Points.setValue(*(pPoints->getPointKernelPtr())); - return Py::asObject(pcFeature->getPyObject()); + return Py::asObject(pcFeature->getPyObject()); } catch (const Base::Exception& e) { throw Py::RuntimeError(e.what()); @@ -411,4 +434,4 @@ PyObject* initModule() return Base::Interpreter().addModule(new Module); } -} // namespace Points +}// namespace Points diff --git a/src/Mod/Points/App/Points.cpp b/src/Mod/Points/App/Points.cpp index 2ad629226e..731dedb295 100644 --- a/src/Mod/Points/App/Points.cpp +++ b/src/Mod/Points/App/Points.cpp @@ -22,10 +22,10 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include +#include +#include +#include +#include #endif #include @@ -37,7 +37,7 @@ #ifdef _MSC_VER -# include +#include #endif using namespace Points; @@ -46,16 +46,14 @@ using namespace std; TYPESYSTEM_SOURCE(Points::PointKernel, Data::ComplexGeoData) PointKernel::PointKernel(const PointKernel& pts) - : _Mtrx(pts._Mtrx) - , _Points(pts._Points) -{ - -} + : _Mtrx(pts._Mtrx) + , _Points(pts._Points) +{} std::vector PointKernel::getElementTypes() const { std::vector temp; - //temp.push_back("Segment"); + // temp.push_back("Segment"); return temp; } @@ -67,24 +65,25 @@ unsigned long PointKernel::countSubElements(const char* /*Type*/) const Data::Segment* PointKernel::getSubElement(const char* /*Type*/, unsigned long /*n*/) const { - //unsigned long i = 1; + // unsigned long i = 1; - //if (strcmp(Type,"Segment") == 0) { - // // not implemented - // assert(0); - // return 0; - //} + // if (strcmp(Type,"Segment") == 0) { + // // not implemented + // assert(0); + // return 0; + // } return nullptr; } -void PointKernel::transformGeometry(const Base::Matrix4D &rclMat) +void PointKernel::transformGeometry(const Base::Matrix4D& rclMat) { std::vector& kernel = getBasicPoints(); #ifdef _MSC_VER - // Win32-only at the moment since ppl.h is a Microsoft library. Points is not using Qt so we cannot use QtConcurrent - // We could also rewrite Points to leverage SIMD instructions - // Other option: openMP. But with VC2013 results in high CPU usage even after computation (busy-waits for >100ms) + // Win32-only at the moment since ppl.h is a Microsoft library. Points is not using Qt so we + // cannot use QtConcurrent We could also rewrite Points to leverage SIMD instructions Other + // option: openMP. But with VC2013 results in high CPU usage even after computation (busy-waits + // for >100ms) Concurrency::parallel_for_each(kernel.begin(), kernel.end(), [rclMat](value_type& value) { value = rclMat * value; }); @@ -95,31 +94,34 @@ void PointKernel::transformGeometry(const Base::Matrix4D &rclMat) #endif } -Base::BoundBox3d PointKernel::getBoundBox()const +Base::BoundBox3d PointKernel::getBoundBox() const { Base::BoundBox3d bnd; #ifdef _MSC_VER // Thread-local bounding boxes Concurrency::combinable bbs; - // Cannot use a const_point_iterator here as it is *not* a proper iterator (fails the for_each template) - Concurrency::parallel_for_each(_Points.begin(), _Points.end(), [this, &bbs](const value_type& value) { - Base::Vector3d vertd(value.x, value.y, value.z); - bbs.local().Add(this->_Mtrx * vertd); - }); + // Cannot use a const_point_iterator here as it is *not* a proper iterator (fails the for_each + // template) + Concurrency::parallel_for_each(_Points.begin(), + _Points.end(), + [this, &bbs](const value_type& value) { + Base::Vector3d vertd(value.x, value.y, value.z); + bbs.local().Add(this->_Mtrx * vertd); + }); // Combine each thread-local bounding box in the final bounding box bbs.combine_each([&bnd](const Base::BoundBox3d& lbb) { bnd.Add(lbb); }); #else - for (const auto & it : *this) { + for (const auto& it : *this) { bnd.Add(it); } #endif return bnd; } -void PointKernel::operator = (const PointKernel& Kernel) +void PointKernel::operator=(const PointKernel& Kernel) { if (this != &Kernel) { // copy the mesh structure @@ -128,7 +130,7 @@ void PointKernel::operator = (const PointKernel& Kernel) } } -unsigned int PointKernel::getMemSize () const +unsigned int PointKernel::getMemSize() const { return _Points.size() * sizeof(value_type); } @@ -136,10 +138,8 @@ unsigned int PointKernel::getMemSize () const PointKernel::size_type PointKernel::countValid() const { size_type num = 0; - for (const auto & it : *this) { - if (!(boost::math::isnan(it.x) || - boost::math::isnan(it.y) || - boost::math::isnan(it.z))) { + for (const auto& it : *this) { + if (!(boost::math::isnan(it.x) || boost::math::isnan(it.y) || boost::math::isnan(it.z))) { num++; } } @@ -150,29 +150,26 @@ std::vector PointKernel::getValidPoints() const { std::vector valid; valid.reserve(countValid()); - for (const auto & it : *this) { - if (!(boost::math::isnan(it.x) || - boost::math::isnan(it.y) || - boost::math::isnan(it.z))) { - valid.emplace_back( - static_cast(it.x), - static_cast(it.y), - static_cast(it.z)); + for (const auto& it : *this) { + if (!(boost::math::isnan(it.x) || boost::math::isnan(it.y) || boost::math::isnan(it.z))) { + valid.emplace_back(static_cast(it.x), + static_cast(it.y), + static_cast(it.z)); } } return valid; } -void PointKernel::Save (Base::Writer &writer) const +void PointKernel::Save(Base::Writer& writer) const { if (!writer.isForceXML()) { - writer.Stream() << writer.ind() - << "" << std::endl; + writer.Stream() << writer.ind() << "" << std::endl; } } -void PointKernel::SaveDocFile (Base::Writer &writer) const +void PointKernel::SaveDocFile(Base::Writer& writer) const { Base::OutputStream str(writer.Stream()); uint32_t uCt = (uint32_t)size(); @@ -183,35 +180,35 @@ void PointKernel::SaveDocFile (Base::Writer &writer) const } } -void PointKernel::Restore(Base::XMLReader &reader) +void PointKernel::Restore(Base::XMLReader& reader) { clear(); reader.readElement("Points"); - std::string file (reader.getAttribute("file") ); + std::string file(reader.getAttribute("file")); if (!file.empty()) { // initiate a file read - reader.addFile(file.c_str(),this); + reader.addFile(file.c_str(), this); } if (reader.DocumentSchema > 3) { - std::string Matrix (reader.getAttribute("mtrx") ); + std::string Matrix(reader.getAttribute("mtrx")); _Mtrx.fromString(Matrix); } } -void PointKernel::RestoreDocFile(Base::Reader &reader) +void PointKernel::RestoreDocFile(Base::Reader& reader) { Base::InputStream str(reader); uint32_t uCt = 0; str >> uCt; _Points.resize(uCt); - for (unsigned long i=0; i < uCt; i++) { + for (unsigned long i = 0; i < uCt; i++) { float x; float y; float z; str >> x >> y >> z; - _Points[i].Set(x,y,z); + _Points[i].Set(x, y, z); } } @@ -223,7 +220,7 @@ void PointKernel::save(const char* file) const void PointKernel::load(const char* file) { - PointsAlgos::Load(*this,file); + PointsAlgos::Load(*this, file); } void PointKernel::save(std::ostream& out) const @@ -234,38 +231,39 @@ void PointKernel::save(std::ostream& out) const } } -void PointKernel::getPoints(std::vector &Points, - std::vector &/*Normals*/, - double /*Accuracy*/, uint16_t /*flags*/) const +void PointKernel::getPoints(std::vector& Points, + std::vector& /*Normals*/, + double /*Accuracy*/, + uint16_t /*flags*/) const { unsigned long ctpoints = _Points.size(); Points.reserve(ctpoints); - for (unsigned long i=0; igetPoint(i)); } } // ---------------------------------------------------------------------------- -PointKernel::const_point_iterator::const_point_iterator -(const PointKernel* kernel, std::vector::const_iterator index) - : _kernel(kernel), _p_it(index) +PointKernel::const_point_iterator::const_point_iterator( + const PointKernel* kernel, + std::vector::const_iterator index) + : _kernel(kernel) + , _p_it(index) { - if(_p_it != kernel->_Points.end()) - { + if (_p_it != kernel->_Points.end()) { value_type vertd(_p_it->x, _p_it->y, _p_it->z); this->_point = _kernel->_Mtrx * vertd; } } -PointKernel::const_point_iterator::const_point_iterator -(const PointKernel::const_point_iterator& fi) = default; +PointKernel::const_point_iterator::const_point_iterator( + const PointKernel::const_point_iterator& fi) = default; PointKernel::const_point_iterator::~const_point_iterator() = default; PointKernel::const_point_iterator& -PointKernel::const_point_iterator::operator= -(const PointKernel::const_point_iterator& pi) = default; +PointKernel::const_point_iterator::operator=(const PointKernel::const_point_iterator& pi) = default; void PointKernel::const_point_iterator::dereference() { @@ -273,54 +271,50 @@ void PointKernel::const_point_iterator::dereference() this->_point = _kernel->_Mtrx * vertd; } -const PointKernel::const_point_iterator::value_type& -PointKernel::const_point_iterator::operator*() +const PointKernel::const_point_iterator::value_type& PointKernel::const_point_iterator::operator*() { dereference(); return this->_point; } -const PointKernel::const_point_iterator::value_type* -PointKernel::const_point_iterator::operator->() +const PointKernel::const_point_iterator::value_type* PointKernel::const_point_iterator::operator->() { dereference(); return &(this->_point); } -bool PointKernel::const_point_iterator::operator==(const PointKernel::const_point_iterator& pi) const +bool PointKernel::const_point_iterator::operator==( + const PointKernel::const_point_iterator& pi) const { return (this->_kernel == pi._kernel) && (this->_p_it == pi._p_it); } -bool PointKernel::const_point_iterator::operator!=(const PointKernel::const_point_iterator& pi) const +bool PointKernel::const_point_iterator::operator!=( + const PointKernel::const_point_iterator& pi) const { return !operator==(pi); } -PointKernel::const_point_iterator& -PointKernel::const_point_iterator::operator++() +PointKernel::const_point_iterator& PointKernel::const_point_iterator::operator++() { ++(this->_p_it); return *this; } -PointKernel::const_point_iterator -PointKernel::const_point_iterator::operator++(int) +PointKernel::const_point_iterator PointKernel::const_point_iterator::operator++(int) { PointKernel::const_point_iterator tmp = *this; ++(this->_p_it); return tmp; } -PointKernel::const_point_iterator& -PointKernel::const_point_iterator::operator--() +PointKernel::const_point_iterator& PointKernel::const_point_iterator::operator--() { --(this->_p_it); return *this; } -PointKernel::const_point_iterator -PointKernel::const_point_iterator::operator--(int) +PointKernel::const_point_iterator PointKernel::const_point_iterator::operator--(int) { PointKernel::const_point_iterator tmp = *this; --(this->_p_it); @@ -328,17 +322,17 @@ PointKernel::const_point_iterator::operator--(int) } PointKernel::const_point_iterator -PointKernel::const_point_iterator::operator+ (difference_type off) const +PointKernel::const_point_iterator::operator+(difference_type off) const { PointKernel::const_point_iterator tmp = *this; - return (tmp+=off); + return (tmp += off); } PointKernel::const_point_iterator -PointKernel::const_point_iterator::operator- (difference_type off) const +PointKernel::const_point_iterator::operator-(difference_type off) const { PointKernel::const_point_iterator tmp = *this; - return (tmp-=off); + return (tmp -= off); } PointKernel::const_point_iterator& @@ -356,7 +350,7 @@ PointKernel::const_point_iterator::operator-=(difference_type off) } PointKernel::difference_type -PointKernel::const_point_iterator::operator- (const PointKernel::const_point_iterator& right) const +PointKernel::const_point_iterator::operator-(const PointKernel::const_point_iterator& right) const { return this->_p_it - right._p_it; } diff --git a/src/Mod/Points/App/Points.h b/src/Mod/Points/App/Points.h index 7dcd593339..e35826a412 100644 --- a/src/Mod/Points/App/Points.h +++ b/src/Mod/Points/App/Points.h @@ -24,8 +24,8 @@ #ifndef POINTS_POINT_H #define POINTS_POINT_H -#include #include +#include #include #include @@ -42,7 +42,7 @@ namespace Points /** Point kernel */ -class PointsExport PointKernel : public Data::ComplexGeoData +class PointsExport PointKernel: public Data::ComplexGeoData { TYPESYSTEM_HEADER_WITH_OVERRIDE(); @@ -60,7 +60,7 @@ public: PointKernel(const PointKernel&); ~PointKernel() override = default; - void operator = (const PointKernel&); + void operator=(const PointKernel&); /** @name Subelement management */ //@{ @@ -74,31 +74,46 @@ public: Data::Segment* getSubElement(const char* Type, unsigned long) const override; //@} - inline void setTransform(const Base::Matrix4D& rclTrf) override{_Mtrx = rclTrf;} - inline Base::Matrix4D getTransform() const override{return _Mtrx;} + inline void setTransform(const Base::Matrix4D& rclTrf) override + { + _Mtrx = rclTrf; + } + inline Base::Matrix4D getTransform() const override + { + return _Mtrx; + } std::vector& getBasicPoints() - { return this->_Points; } + { + return this->_Points; + } const std::vector& getBasicPoints() const - { return this->_Points; } + { + return this->_Points; + } void setBasicPoints(const std::vector& pts) - { this->_Points = pts; } + { + this->_Points = pts; + } void swap(std::vector& pts) - { this->_Points.swap(pts); } + { + this->_Points.swap(pts); + } - void getPoints(std::vector &Points, - std::vector &Normals, - double Accuracy, uint16_t flags=0) const override; - void transformGeometry(const Base::Matrix4D &rclMat) override; - Base::BoundBox3d getBoundBox()const override; + void getPoints(std::vector& Points, + std::vector& Normals, + double Accuracy, + uint16_t flags = 0) const override; + void transformGeometry(const Base::Matrix4D& rclMat) override; + Base::BoundBox3d getBoundBox() const override; /** @name I/O */ //@{ // Implemented from Persistence - unsigned int getMemSize () const override; - void Save (Base::Writer &writer) const override; - void SaveDocFile (Base::Writer &writer) const override; - void Restore(Base::XMLReader &reader) override; - void RestoreDocFile(Base::Reader &reader) override; + unsigned int getMemSize() const override; + void Save(Base::Writer& writer) const override; + void SaveDocFile(Base::Writer& writer) const override; + void Restore(Base::XMLReader& reader) override; + void RestoreDocFile(Base::Reader& reader) override; void save(const char* file) const; void save(std::ostream&) const; void load(const char* file); @@ -111,28 +126,44 @@ private: public: /// number of points stored - size_type size() const {return this->_Points.size();} + size_type size() const + { + return this->_Points.size(); + } size_type countValid() const; std::vector getValidPoints() const; - void resize(size_type n){_Points.resize(n);} - void reserve(size_type n){_Points.reserve(n);} - inline void erase(size_type first, size_type last) { - _Points.erase(_Points.begin()+first,_Points.begin()+last); + void resize(size_type n) + { + _Points.resize(n); + } + void reserve(size_type n) + { + _Points.reserve(n); + } + inline void erase(size_type first, size_type last) + { + _Points.erase(_Points.begin() + first, _Points.begin() + last); } - void clear(){_Points.clear();} + void clear() + { + _Points.clear(); + } /// get the points - inline const Base::Vector3d getPoint(const int idx) const { + inline const Base::Vector3d getPoint(const int idx) const + { return transformPointToOutside(_Points[idx]); } /// set the points - inline void setPoint(const int idx,const Base::Vector3d& point) { + inline void setPoint(const int idx, const Base::Vector3d& point) + { _Points[idx] = transformPointToInside(point); } /// insert the points - inline void push_back(const Base::Vector3d& point) { + inline void push_back(const Base::Vector3d& point) + { _Points.push_back(transformPointToInside(point)); } @@ -157,14 +188,15 @@ public: bool operator==(const const_point_iterator& fi) const; bool operator!=(const const_point_iterator& fi) const; const_point_iterator& operator++(); - const_point_iterator operator++(int); + const_point_iterator operator++(int); const_point_iterator& operator--(); - const_point_iterator operator--(int); - const_point_iterator operator+ (difference_type off) const; - const_point_iterator operator- (difference_type off) const; + const_point_iterator operator--(int); + const_point_iterator operator+(difference_type off) const; + const_point_iterator operator-(difference_type off) const; const_point_iterator& operator+=(difference_type off); const_point_iterator& operator-=(difference_type off); - difference_type operator- (const const_point_iterator& right) const; + difference_type operator-(const const_point_iterator& right) const; + private: void dereference(); const PointKernel* _kernel; @@ -178,17 +210,25 @@ public: /** @name Iterator */ //@{ const_point_iterator begin() const - { return {this, _Points.begin()}; } + { + return {this, _Points.begin()}; + } const_point_iterator end() const - { return {this, _Points.end()}; } + { + return {this, _Points.end()}; + } const_reverse_iterator rbegin() const - { return const_reverse_iterator(end()); } + { + return const_reverse_iterator(end()); + } const_reverse_iterator rend() const - { return const_reverse_iterator(begin()); } + { + return const_reverse_iterator(begin()); + } //@} }; -} // namespace Points +}// namespace Points -#endif // POINTS_POINTPROPERTIES_H +#endif// POINTS_POINTPROPERTIES_H diff --git a/src/Mod/Points/App/PointsAlgos.cpp b/src/Mod/Points/App/PointsAlgos.cpp index 1d04b78691..8775f32eb1 100644 --- a/src/Mod/Points/App/PointsAlgos.cpp +++ b/src/Mod/Points/App/PointsAlgos.cpp @@ -22,16 +22,16 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# ifdef FC_OS_LINUX -# include -# endif -# include -# include +#ifdef FC_OS_LINUX +#include +#endif +#include +#include -# include -# include -# include -# include // needed for compilation on some systems +#include +#include +#include // needed for compilation on some systems +#include #endif #include @@ -47,44 +47,49 @@ using namespace Points; -void PointsAlgos::Load(PointKernel &points, const char *FileName) +void PointsAlgos::Load(PointKernel& points, const char* FileName) { Base::FileInfo File(FileName); // checking on the file - if (!File.isReadable()) + if (!File.isReadable()) { throw Base::FileException("File to load not existing or not readable", FileName); + } - if (File.hasExtension("asc")) - LoadAscii(points,FileName); - else + if (File.hasExtension("asc")) { + LoadAscii(points, FileName); + } + else { throw Base::RuntimeError("Unknown ending"); + } } -void PointsAlgos::LoadAscii(PointKernel &points, const char *FileName) +void PointsAlgos::LoadAscii(PointKernel& points, const char* FileName) { boost::regex rx("^\\s*([-+]?[0-9]*)\\.?([0-9]+([eE][-+]?[0-9]+)?)" - "\\s+([-+]?[0-9]*)\\.?([0-9]+([eE][-+]?[0-9]+)?)" - "\\s+([-+]?[0-9]*)\\.?([0-9]+([eE][-+]?[0-9]+)?)\\s*$"); - //boost::regex rx("(\\b[0-9]+\\.([0-9]+\\b)?|\\.[0-9]+\\b)"); - //boost::regex rx("^\\s*(-?[0-9]*)\\.([0-9]+)\\s+(-?[0-9]*)\\.([0-9]+)\\s+(-?[0-9]*)\\.([0-9]+)\\s*$"); + "\\s+([-+]?[0-9]*)\\.?([0-9]+([eE][-+]?[0-9]+)?)" + "\\s+([-+]?[0-9]*)\\.?([0-9]+([eE][-+]?[0-9]+)?)\\s*$"); + // boost::regex rx("(\\b[0-9]+\\.([0-9]+\\b)?|\\.[0-9]+\\b)"); + // boost::regex + // rx("^\\s*(-?[0-9]*)\\.([0-9]+)\\s+(-?[0-9]*)\\.([0-9]+)\\s+(-?[0-9]*)\\.([0-9]+)\\s*$"); boost::cmatch what; Base::Vector3d pt; - int LineCnt=0; + int LineCnt = 0; std::string line; Base::FileInfo fi(FileName); Base::ifstream tmp_str(fi, std::ios::in); // estimating size - while (std::getline(tmp_str,line)) + while (std::getline(tmp_str, line)) { LineCnt++; + } // resize the PointKernel points.resize(LineCnt); - Base::SequencerLauncher seq( "Loading points...", LineCnt ); + Base::SequencerLauncher seq("Loading points...", LineCnt); // again to the beginning Base::ifstream file(fi, std::ios::in); @@ -98,7 +103,7 @@ void PointsAlgos::LoadAscii(PointKernel &points, const char *FileName) pt.y = std::atof(what[4].first); pt.z = std::atof(what[7].first); - points.setPoint(LineCnt,pt); + points.setPoint(LineCnt, pt); seq.next(); LineCnt++; } @@ -112,8 +117,9 @@ void PointsAlgos::LoadAscii(PointKernel &points, const char *FileName) // now remove the last points from the kernel // Note: first we allocate memory corresponding to the number of lines (points and comments) // and read in the file twice. But then the size of the kernel is too high - if (LineCnt < (int)points.size()) + if (LineCnt < (int)points.size()) { points.erase(LineCnt, points.size()); + } } // ---------------------------------------------------------------------------- @@ -199,8 +205,10 @@ void AscReader::read(const std::string& filename) // ---------------------------------------------------------------------------- -namespace Points { -class Converter { +namespace Points +{ +class Converter +{ public: Converter() = default; virtual ~Converter() = default; @@ -210,13 +218,15 @@ public: Converter(const Converter&) = delete; Converter(Converter&&) = delete; - Converter& operator= (const Converter&) = delete; - Converter& operator= (Converter&&) = delete; + Converter& operator=(const Converter&) = delete; + Converter& operator=(Converter&&) = delete; }; -template -class ConverterT : public Converter { +template +class ConverterT: public Converter +{ public: - std::string toString(double f) const override { + std::string toString(double f) const override + { T c = static_cast(f); std::ostringstream oss; oss.precision(7); @@ -224,22 +234,26 @@ public: oss << c; return oss.str(); } - double toDouble(Base::InputStream& str) const override { + double toDouble(Base::InputStream& str) const override + { T c; str >> c; return static_cast(c); } - int getSizeOf() const override { + int getSizeOf() const override + { return sizeof(T); } }; using ConverterPtr = std::shared_ptr; -class DataStreambuf : public std::streambuf +class DataStreambuf: public std::streambuf { public: - explicit DataStreambuf(const std::vector& data) : _buffer(data) { + explicit DataStreambuf(const std::vector& data) + : _buffer(data) + { _beg = 0; _end = data.size(); _cur = 0; @@ -247,52 +261,64 @@ public: ~DataStreambuf() override = default; protected: - int_type uflow() override { - if (_cur == _end) + int_type uflow() override + { + if (_cur == _end) { return traits_type::eof(); + } return static_cast(_buffer[_cur++]) & 0x000000ff; } - int_type underflow() override { - if (_cur == _end) + int_type underflow() override + { + if (_cur == _end) { return traits_type::eof(); + } return static_cast(_buffer[_cur]) & 0x000000ff; } - int_type pbackfail(int_type ch) override { - if (_cur == _beg || (ch != traits_type::eof() && ch != _buffer[_cur-1])) + int_type pbackfail(int_type ch) override + { + if (_cur == _beg || (ch != traits_type::eof() && ch != _buffer[_cur - 1])) { return traits_type::eof(); + } return static_cast(_buffer[--_cur]) & 0x000000ff; } - std::streamsize showmanyc() override { + std::streamsize showmanyc() override + { return _end - _cur; } pos_type seekoff(std::streambuf::off_type off, - std::ios_base::seekdir way, - std::ios_base::openmode = - std::ios::in | std::ios::out) override { - int p_pos=-1; - if (way == std::ios_base::beg) + std::ios_base::seekdir way, + std::ios_base::openmode = std::ios::in | std::ios::out) override + { + int p_pos = -1; + if (way == std::ios_base::beg) { p_pos = _beg; - else if (way == std::ios_base::end) + } + else if (way == std::ios_base::end) { p_pos = _end; - else if (way == std::ios_base::cur) + } + else if (way == std::ios_base::cur) { p_pos = _cur; + } - if (p_pos > _end) + if (p_pos > _end) { return traits_type::eof(); + } - if (((p_pos + off) > _end) || ((p_pos + off) < _beg)) + if (((p_pos + off) > _end) || ((p_pos + off) < _beg)) { return traits_type::eof(); + } - _cur = p_pos+ off; + _cur = p_pos + off; - return ((p_pos+off) - _beg); + return ((p_pos + off) - _beg); } pos_type seekpos(std::streambuf::pos_type pos, - std::ios_base::openmode which = - std::ios::in | std::ios::out) override { + std::ios_base::openmode which = std::ios::in | std::ios::out) override + { (void)which; return seekoff(pos, std::ios_base::beg); } @@ -308,191 +334,216 @@ private: int _beg, _end, _cur; }; -//Taken from https://github.com/PointCloudLibrary/pcl/blob/master/io/src/lzf.cpp +// Taken from https://github.com/PointCloudLibrary/pcl/blob/master/io/src/lzf.cpp unsigned int -lzfDecompress (const void *const in_data, unsigned int in_len, - void *out_data, unsigned int out_len) +lzfDecompress(const void* const in_data, unsigned int in_len, void* out_data, unsigned int out_len) { - unsigned char const *ip = static_cast (in_data); - unsigned char *op = static_cast (out_data); - unsigned char const *const in_end = ip + in_len; - unsigned char *const out_end = op + out_len; + unsigned char const* ip = static_cast(in_data); + unsigned char* op = static_cast(out_data); + unsigned char const* const in_end = ip + in_len; + unsigned char* const out_end = op + out_len; - do - { - unsigned int ctrl = *ip++; + do { + unsigned int ctrl = *ip++; - // Literal run - if (ctrl < (1 << 5)) - { - ctrl++; + // Literal run + if (ctrl < (1 << 5)) { + ctrl++; - if (op + ctrl > out_end) - { - errno = E2BIG; - return (0); - } + if (op + ctrl > out_end) { + errno = E2BIG; + return (0); + } - // Check for overflow - if (ip + ctrl > in_end) - { - errno = EINVAL; - return (0); - } - switch (ctrl) - { - case 32: *op++ = *ip++; - /* FALLTHRU */ - case 31: *op++ = *ip++; - /* FALLTHRU */ - case 30: *op++ = *ip++; - /* FALLTHRU */ - case 29: *op++ = *ip++; - /* FALLTHRU */ - case 28: *op++ = *ip++; - /* FALLTHRU */ - case 27: *op++ = *ip++; - /* FALLTHRU */ - case 26: *op++ = *ip++; - /* FALLTHRU */ - case 25: *op++ = *ip++; - /* FALLTHRU */ - case 24: *op++ = *ip++; - /* FALLTHRU */ - case 23: *op++ = *ip++; - /* FALLTHRU */ - case 22: *op++ = *ip++; - /* FALLTHRU */ - case 21: *op++ = *ip++; - /* FALLTHRU */ - case 20: *op++ = *ip++; - /* FALLTHRU */ - case 19: *op++ = *ip++; - /* FALLTHRU */ - case 18: *op++ = *ip++; - /* FALLTHRU */ - case 17: *op++ = *ip++; - /* FALLTHRU */ - case 16: *op++ = *ip++; - /* FALLTHRU */ - case 15: *op++ = *ip++; - /* FALLTHRU */ - case 14: *op++ = *ip++; - /* FALLTHRU */ - case 13: *op++ = *ip++; - /* FALLTHRU */ - case 12: *op++ = *ip++; - /* FALLTHRU */ - case 11: *op++ = *ip++; - /* FALLTHRU */ - case 10: *op++ = *ip++; - /* FALLTHRU */ - case 9: *op++ = *ip++; - /* FALLTHRU */ - case 8: *op++ = *ip++; - /* FALLTHRU */ - case 7: *op++ = *ip++; - /* FALLTHRU */ - case 6: *op++ = *ip++; - /* FALLTHRU */ - case 5: *op++ = *ip++; - /* FALLTHRU */ - case 4: *op++ = *ip++; - /* FALLTHRU */ - case 3: *op++ = *ip++; - /* FALLTHRU */ - case 2: *op++ = *ip++; - /* FALLTHRU */ - case 1: *op++ = *ip++; - } - } - // Back reference - else - { - unsigned int len = ctrl >> 5; - - unsigned char *ref = op - ((ctrl & 0x1f) << 8) - 1; - - // Check for overflow - if (ip >= in_end) - { - errno = EINVAL; - return (0); - } - if (len == 7) - { - len += *ip++; - // Check for overflow - if (ip >= in_end) - { - errno = EINVAL; - return (0); + // Check for overflow + if (ip + ctrl > in_end) { + errno = EINVAL; + return (0); + } + switch (ctrl) { + case 32: + *op++ = *ip++; + /* FALLTHRU */ + case 31: + *op++ = *ip++; + /* FALLTHRU */ + case 30: + *op++ = *ip++; + /* FALLTHRU */ + case 29: + *op++ = *ip++; + /* FALLTHRU */ + case 28: + *op++ = *ip++; + /* FALLTHRU */ + case 27: + *op++ = *ip++; + /* FALLTHRU */ + case 26: + *op++ = *ip++; + /* FALLTHRU */ + case 25: + *op++ = *ip++; + /* FALLTHRU */ + case 24: + *op++ = *ip++; + /* FALLTHRU */ + case 23: + *op++ = *ip++; + /* FALLTHRU */ + case 22: + *op++ = *ip++; + /* FALLTHRU */ + case 21: + *op++ = *ip++; + /* FALLTHRU */ + case 20: + *op++ = *ip++; + /* FALLTHRU */ + case 19: + *op++ = *ip++; + /* FALLTHRU */ + case 18: + *op++ = *ip++; + /* FALLTHRU */ + case 17: + *op++ = *ip++; + /* FALLTHRU */ + case 16: + *op++ = *ip++; + /* FALLTHRU */ + case 15: + *op++ = *ip++; + /* FALLTHRU */ + case 14: + *op++ = *ip++; + /* FALLTHRU */ + case 13: + *op++ = *ip++; + /* FALLTHRU */ + case 12: + *op++ = *ip++; + /* FALLTHRU */ + case 11: + *op++ = *ip++; + /* FALLTHRU */ + case 10: + *op++ = *ip++; + /* FALLTHRU */ + case 9: + *op++ = *ip++; + /* FALLTHRU */ + case 8: + *op++ = *ip++; + /* FALLTHRU */ + case 7: + *op++ = *ip++; + /* FALLTHRU */ + case 6: + *op++ = *ip++; + /* FALLTHRU */ + case 5: + *op++ = *ip++; + /* FALLTHRU */ + case 4: + *op++ = *ip++; + /* FALLTHRU */ + case 3: + *op++ = *ip++; + /* FALLTHRU */ + case 2: + *op++ = *ip++; + /* FALLTHRU */ + case 1: + *op++ = *ip++; + } } - } - ref -= *ip++; + // Back reference + else { + unsigned int len = ctrl >> 5; - if (op + len + 2 > out_end) - { - errno = E2BIG; - return (0); - } + unsigned char* ref = op - ((ctrl & 0x1f) << 8) - 1; - if (ref < static_cast (out_data)) - { - errno = EINVAL; - return (0); - } + // Check for overflow + if (ip >= in_end) { + errno = EINVAL; + return (0); + } + if (len == 7) { + len += *ip++; + // Check for overflow + if (ip >= in_end) { + errno = EINVAL; + return (0); + } + } + ref -= *ip++; - switch (len) - { - default: - { - len += 2; + if (op + len + 2 > out_end) { + errno = E2BIG; + return (0); + } - if (op >= ref + len) - { - // Disjunct areas - memcpy (op, ref, len); - op += len; - } - else - { - // Overlapping, use byte by byte copying - do - *op++ = *ref++; - while (--len); - } + if (ref < static_cast(out_data)) { + errno = EINVAL; + return (0); + } - break; + switch (len) { + default: { + len += 2; + + if (op >= ref + len) { + // Disjunct areas + memcpy(op, ref, len); + op += len; + } + else { + // Overlapping, use byte by byte copying + do { + *op++ = *ref++; + } while (--len); + } + + break; + } + case 9: + *op++ = *ref++; + /* FALLTHRU */ + case 8: + *op++ = *ref++; + /* FALLTHRU */ + case 7: + *op++ = *ref++; + /* FALLTHRU */ + case 6: + *op++ = *ref++; + /* FALLTHRU */ + case 5: + *op++ = *ref++; + /* FALLTHRU */ + case 4: + *op++ = *ref++; + /* FALLTHRU */ + case 3: + *op++ = *ref++; + /* FALLTHRU */ + case 2: + *op++ = *ref++; + /* FALLTHRU */ + case 1: + *op++ = *ref++; + /* FALLTHRU */ + case 0: + *op++ = *ref++;// two octets more + *op++ = *ref++; + } } - case 9: *op++ = *ref++; - /* FALLTHRU */ - case 8: *op++ = *ref++; - /* FALLTHRU */ - case 7: *op++ = *ref++; - /* FALLTHRU */ - case 6: *op++ = *ref++; - /* FALLTHRU */ - case 5: *op++ = *ref++; - /* FALLTHRU */ - case 4: *op++ = *ref++; - /* FALLTHRU */ - case 3: *op++ = *ref++; - /* FALLTHRU */ - case 2: *op++ = *ref++; - /* FALLTHRU */ - case 1: *op++ = *ref++; - /* FALLTHRU */ - case 0: *op++ = *ref++; // two octets more - *op++ = *ref++; - } - } - } - while (ip < in_end); + } while (ip < in_end); - return (static_cast (op - static_cast (out_data))); -} + return (static_cast(op - static_cast(out_data))); } +}// namespace Points PlyReader::PlyReader() = default; @@ -529,68 +580,82 @@ void PlyReader::read(const std::string& filename) // x field std::size_t x = max_size; it = std::find(fields.begin(), fields.end(), "x"); - if (it != fields.end()) + if (it != fields.end()) { x = std::distance(fields.begin(), it); + } // y field std::size_t y = max_size; it = std::find(fields.begin(), fields.end(), "y"); - if (it != fields.end()) + if (it != fields.end()) { y = std::distance(fields.begin(), it); + } // z field std::size_t z = max_size; it = std::find(fields.begin(), fields.end(), "z"); - if (it != fields.end()) + if (it != fields.end()) { z = std::distance(fields.begin(), it); + } // normal x field std::size_t normal_x = max_size; it = std::find(fields.begin(), fields.end(), "normal_x"); - if (it == fields.end()) + if (it == fields.end()) { it = std::find(fields.begin(), fields.end(), "nx"); - if (it != fields.end()) + } + if (it != fields.end()) { normal_x = std::distance(fields.begin(), it); + } // normal y field std::size_t normal_y = max_size; it = std::find(fields.begin(), fields.end(), "normal_y"); - if (it == fields.end()) + if (it == fields.end()) { it = std::find(fields.begin(), fields.end(), "ny"); - if (it != fields.end()) + } + if (it != fields.end()) { normal_y = std::distance(fields.begin(), it); + } // normal z field std::size_t normal_z = max_size; it = std::find(fields.begin(), fields.end(), "normal_z"); - if (it == fields.end()) + if (it == fields.end()) { it = std::find(fields.begin(), fields.end(), "nz"); - if (it != fields.end()) + } + if (it != fields.end()) { normal_z = std::distance(fields.begin(), it); + } // intensity field std::size_t greyvalue = max_size; it = std::find(fields.begin(), fields.end(), "intensity"); - if (it != fields.end()) + if (it != fields.end()) { greyvalue = std::distance(fields.begin(), it); + } // rgb(a) field std::size_t red = max_size, green = max_size, blue = max_size, alpha = max_size; it = std::find(fields.begin(), fields.end(), "red"); - if (it != fields.end()) + if (it != fields.end()) { red = std::distance(fields.begin(), it); + } it = std::find(fields.begin(), fields.end(), "green"); - if (it != fields.end()) + if (it != fields.end()) { green = std::distance(fields.begin(), it); + } it = std::find(fields.begin(), fields.end(), "blue"); - if (it != fields.end()) + if (it != fields.end()) { blue = std::distance(fields.begin(), it); + } it = std::find(fields.begin(), fields.end(), "alpha"); - if (it != fields.end()) + if (it != fields.end()) { alpha = std::distance(fields.begin(), it); + } // transfer the data bool hasData = (x != max_size && y != max_size && z != max_size); @@ -600,22 +665,22 @@ void PlyReader::read(const std::string& filename) if (hasData) { points.reserve(numPoints); - for (std::size_t i=0; i(r)/255.0f, - static_cast(g)/255.0f, - static_cast(b)/255.0f, - static_cast(a)/255.0f); + } + colors.emplace_back(static_cast(r) / 255.0f, + static_cast(g) / 255.0f, + static_cast(b) / 255.0f, + static_cast(a) / 255.0f); } } else if (types[red] == "float") { - for (std::size_t i=0; i list; std::size_t numPoints = 0; // a pair of numbers of elements and the total size of the properties - std::vector > count_props; + std::vector> count_props; // read in the first three characters char ply[3]; in.read(ply, 3); in.ignore(1); - if (!in || (ply[0] != 'p') || (ply[1] != 'l') || (ply[2] != 'y')) - throw Base::BadFormatError("Not a ply file"); // wrong header + if (!in || (ply[0] != 'p') || (ply[1] != 'l') || (ply[2] != 'y')) { + throw Base::BadFormatError("Not a ply file");// wrong header + } while (std::getline(in, line)) { - if (line.empty()) + if (line.empty()) { continue; + } // since the file is loaded in binary mode we may get the CR at the end boost::trim(line); - boost::split(list, line, boost::is_any_of ("\t\r "), boost::token_compress_on); + boost::split(list, line, boost::is_any_of("\t\r "), boost::token_compress_on); std::istringstream str(line); str.imbue(std::locale::classic()); @@ -738,15 +807,15 @@ std::size_t PlyReader::readHeader(std::istream& in, std::list number; if (list[1] == "list") { number.insert(number.end(), list.begin(), list.end()); - number.pop_front(); // property - number.pop_front(); // list + number.pop_front();// property + number.pop_front();// list number.pop_back(); } else { number.push_back(list[1]); } - for (const auto & it : number) { + for (const auto& it : number) { int size = 0; if (it == "char" || it == "int8") { size = 1; @@ -793,21 +862,20 @@ std::size_t PlyReader::readHeader(std::istream& in, } } - if (fields.size() != sizes.size() || - fields.size() != types.size()) { + if (fields.size() != sizes.size() || fields.size() != types.size()) { throw Base::BadFormatError(""); } offset = 0; if (format == "ascii") { // just sum up the number of lines to ignore - std::vector >::iterator it; + std::vector>::iterator it; for (it = count_props.begin(); it != count_props.end(); ++it) { offset += it->first; } } else { - std::vector >::iterator it; + std::vector>::iterator it; for (it = count_props.begin(); it != count_props.end(); ++it) { offset += it->first * it->second; } @@ -824,8 +892,9 @@ void PlyReader::readAscii(std::istream& inp, std::size_t offset, Eigen::MatrixXd std::size_t numFields = data.cols(); std::vector list; while (std::getline(inp, line) && row < numPoints) { - if (line.empty()) + if (line.empty()) { continue; + } if (offset > 0) { offset--; @@ -834,7 +903,7 @@ void PlyReader::readAscii(std::istream& inp, std::size_t offset, Eigen::MatrixXd // since the file is loaded in binary mode we may get the CR at the end boost::trim(line); - boost::split(list, line, boost::is_any_of ("\t\r "), boost::token_compress_on); + boost::split(list, line, boost::is_any_of("\t\r "), boost::token_compress_on); std::istringstream str(line); @@ -868,43 +937,55 @@ void PlyReader::readBinary(bool swapByteOrder, ConverterPtr convert_uint32(new ConverterT); std::vector converters; - for (std::size_t j=0; jgetSizeOf(); @@ -917,14 +998,15 @@ void PlyReader::readBinary(bool swapByteOrder, ulCurr = buf->pubseekoff(static_cast(offset), std::ios::cur, std::ios::in); ulSize = buf->pubseekoff(0, std::ios::end, std::ios::in); buf->pubseekoff(ulCurr, std::ios::beg, std::ios::in); - if (ulCurr + neededSize*static_cast(numPoints) > ulSize) + if (ulCurr + neededSize * static_cast(numPoints) > ulSize) { throw Base::BadFormatError("File expects too many elements"); + } } Base::InputStream str(inp); str.setByteOrder(swapByteOrder ? Base::Stream::BigEndian : Base::Stream::LittleEndian); - for (std::size_t i=0; itoDouble(str); data(i, j) = value; } @@ -982,58 +1064,70 @@ void PcdReader::read(const std::string& filename) // x field std::size_t x = max_size; it = std::find(fields.begin(), fields.end(), "x"); - if (it != fields.end()) + if (it != fields.end()) { x = std::distance(fields.begin(), it); + } // y field std::size_t y = max_size; it = std::find(fields.begin(), fields.end(), "y"); - if (it != fields.end()) + if (it != fields.end()) { y = std::distance(fields.begin(), it); + } // z field std::size_t z = max_size; it = std::find(fields.begin(), fields.end(), "z"); - if (it != fields.end()) + if (it != fields.end()) { z = std::distance(fields.begin(), it); + } // normal x field std::size_t normal_x = max_size; it = std::find(fields.begin(), fields.end(), "normal_x"); - if (it == fields.end()) + if (it == fields.end()) { it = std::find(fields.begin(), fields.end(), "nx"); - if (it != fields.end()) + } + if (it != fields.end()) { normal_x = std::distance(fields.begin(), it); + } // normal y field std::size_t normal_y = max_size; it = std::find(fields.begin(), fields.end(), "normal_y"); - if (it == fields.end()) + if (it == fields.end()) { it = std::find(fields.begin(), fields.end(), "ny"); - if (it != fields.end()) + } + if (it != fields.end()) { normal_y = std::distance(fields.begin(), it); + } // normal z field std::size_t normal_z = max_size; it = std::find(fields.begin(), fields.end(), "normal_z"); - if (it == fields.end()) + if (it == fields.end()) { it = std::find(fields.begin(), fields.end(), "nz"); - if (it != fields.end()) + } + if (it != fields.end()) { normal_z = std::distance(fields.begin(), it); + } // intensity field std::size_t greyvalue = max_size; it = std::find(fields.begin(), fields.end(), "intensity"); - if (it != fields.end()) + if (it != fields.end()) { greyvalue = std::distance(fields.begin(), it); + } // rgb(a) field std::size_t rgba = max_size; it = std::find(fields.begin(), fields.end(), "rgb"); - if (it == fields.end()) + if (it == fields.end()) { it = std::find(fields.begin(), fields.end(), "rgba"); - if (it != fields.end()) + } + if (it != fields.end()) { rgba = std::distance(fields.begin(), it); + } // transfer the data bool hasData = (x != max_size && y != max_size && z != max_size); @@ -1043,39 +1137,40 @@ void PcdReader::read(const std::string& filename) if (hasData) { points.reserve(numPoints); - for (std::size_t i=0; i(data(i,rgba)); + for (std::size_t i = 0; i < numPoints; i++) { + uint32_t packed = static_cast(data(i, rgba)); App::Color col; col.setPackedARGB(packed); colors.emplace_back(col); } } else if (types[rgba] == "F") { - static_assert(sizeof(float) == sizeof(uint32_t), "float and uint32_t have different sizes"); - for (std::size_t i=0; i(data(i,rgba)); + static_assert(sizeof(float) == sizeof(uint32_t), + "float and uint32_t have different sizes"); + for (std::size_t i = 0; i < numPoints; i++) { + float f = static_cast(data(i, rgba)); uint32_t packed; std::memcpy(&packed, &f, sizeof(packed)); App::Color col; @@ -1098,12 +1193,13 @@ std::size_t PcdReader::readHeader(std::istream& in, std::size_t points = 0; while (std::getline(in, line)) { - if (line.empty()) + if (line.empty()) { continue; + } // since the file is loaded in binary mode we may get the CR at the end boost::trim(line); - boost::split(list, line, boost::is_any_of ("\t\r "), boost::token_compress_on); + boost::split(list, line, boost::is_any_of("\t\r "), boost::token_compress_on); std::istringstream str(line); str.imbue(std::locale::classic()); @@ -1111,22 +1207,22 @@ std::size_t PcdReader::readHeader(std::istream& in, std::string kw; str >> kw; if (kw == "FIELDS") { - for (std::size_t i=1; i(list[i])); } } else if (kw == "TYPE") { - for (std::size_t i=1; i(this->width); std::size_t h = static_cast(this->height); std::size_t size = w * h; - if (fields.size() != sizes.size() || - fields.size() != types.size() || - fields.size() != counts.size() || - points != size) { + if (fields.size() != sizes.size() || fields.size() != types.size() + || fields.size() != counts.size() || points != size) { throw Base::BadFormatError(""); } @@ -1166,12 +1260,13 @@ void PcdReader::readAscii(std::istream& inp, Eigen::MatrixXd& data) std::size_t numFields = data.cols(); std::vector list; while (std::getline(inp, line) && row < numPoints) { - if (line.empty()) + if (line.empty()) { continue; + } // since the file is loaded in binary mode we may get the CR at the end boost::trim(line); - boost::split(list, line, boost::is_any_of ("\t\r "), boost::token_compress_on); + boost::split(list, line, boost::is_any_of("\t\r "), boost::token_compress_on); std::istringstream str(line); @@ -1204,43 +1299,55 @@ void PcdReader::readBinary(bool transpose, ConverterPtr convert_uint32(new ConverterT); std::vector converters; - for (std::size_t j=0; jgetSizeOf(); @@ -1253,22 +1360,23 @@ void PcdReader::readBinary(bool transpose, ulCurr = buf->pubseekoff(0, std::ios::cur, std::ios::in); ulSize = buf->pubseekoff(0, std::ios::end, std::ios::in); buf->pubseekoff(ulCurr, std::ios::beg, std::ios::in); - if (ulCurr + neededSize*static_cast(numPoints) > ulSize) + if (ulCurr + neededSize * static_cast(numPoints) > ulSize) { throw Base::BadFormatError("File expects too many elements"); + } } Base::InputStream str(inp); if (transpose) { - for (std::size_t j=0; jtoDouble(str); data(i, j) = value; } } } else { - for (std::size_t i=0; itoDouble(str); data(i, j) = value; } @@ -1278,17 +1386,17 @@ void PcdReader::readBinary(bool transpose, // ---------------------------------------------------------------------------- -namespace { +namespace +{ class E57ReaderImp { public: E57ReaderImp(const std::string& filename, bool color, bool state, double distance) : imfi(filename, "r") - , useColor{color} - , checkState{state} - , minDistance{distance} - { - } + , useColor {color} + , checkState {state} + , minDistance {distance} + {} void read() { @@ -1320,15 +1428,15 @@ public: } private: - void readData3D(const e57::VectorNode& data3D) + void readData3D(const e57::VectorNode& data3D) { for (int child = 0; child < data3D.childCount(); ++child) { e57::StructureNode scan_data(data3D.get(child)); Base::Placement plm; bool hasPlacement = getPlacement(scan_data, plm); - e57::CompressedVectorNode cvn(scan_data.get("points")); - e57::StructureNode prototype(cvn.prototype()); + e57::CompressedVectorNode cvn(scan_data.get("points")); + e57::StructureNode prototype(cvn.prototype()); Proto proto = readProto(prototype); processProto(cvn, proto, hasPlacement, plm); } @@ -1369,26 +1477,16 @@ private: for (int i = 0; i < prototype.childCount(); ++i) { e57::Node node(prototype.get(i)); if ((node.type() == e57::E57_FLOAT) || (node.type() == e57::E57_SCALED_INTEGER)) { - if (readCartesian(node, proto)) { - - } - else if (readNormal(node, proto)) { - - } - else if (readItensity(node, proto)) { - - } + if (readCartesian(node, proto)) {} + else if (readNormal(node, proto)) {} + else if (readItensity(node, proto)) {} else { readOther(node, proto); } } else if (node.type() == e57::E57_INTEGER) { - if (readColor(node, proto)) { - - } - else if (readCartesianInvalidState(node, proto)) { - - } + if (readColor(node, proto)) {} + else if (readCartesianInvalidState(node, proto)) {} else { readOther(node, proto); } @@ -1402,41 +1500,26 @@ private: { if (node.elementName() == "cartesianX") { proto.cnt_xyz++; - proto.sdb.emplace_back( - imfi - , node.elementName() - , proto.xData.data() - , buf_size - , true - , true + proto.sdb + .emplace_back(imfi, node.elementName(), proto.xData.data(), buf_size, true, true - ); + ); return true; } else if (node.elementName() == "cartesianY") { proto.cnt_xyz++; - proto.sdb.emplace_back( - imfi - , node.elementName() - , proto.yData.data() - , buf_size - , true - , true + proto.sdb + .emplace_back(imfi, node.elementName(), proto.yData.data(), buf_size, true, true - ); + ); return true; } else if (node.elementName() == "cartesianZ") { proto.cnt_xyz++; - proto.sdb.emplace_back( - imfi - , node.elementName() - , proto.zData.data() - , buf_size - , true - , true + proto.sdb + .emplace_back(imfi, node.elementName(), proto.zData.data(), buf_size, true, true - ); + ); return true; } @@ -1447,41 +1530,26 @@ private: { if (node.elementName() == "nor:normalX") { proto.cnt_nor++; - proto.sdb.emplace_back( - imfi - , node.elementName() - , proto.xNormal.data() - , buf_size - , true - , true + proto.sdb + .emplace_back(imfi, node.elementName(), proto.xNormal.data(), buf_size, true, true - ); + ); return true; } else if (node.elementName() == "nor:normalY") { proto.cnt_nor++; - proto.sdb.emplace_back( - imfi - , node.elementName() - , proto.yNormal.data() - , buf_size - , true - , true + proto.sdb + .emplace_back(imfi, node.elementName(), proto.yNormal.data(), buf_size, true, true - ); + ); return true; } else if (node.elementName() == "nor:normalZ") { proto.cnt_nor++; - proto.sdb.emplace_back( - imfi - , node.elementName() - , proto.zNormal.data() - , buf_size - , true - , true + proto.sdb + .emplace_back(imfi, node.elementName(), proto.zNormal.data(), buf_size, true, true - ); + ); return true; } @@ -1492,15 +1560,10 @@ private: { if (node.elementName() == "cartesianInvalidState") { proto.inv_state = true; - proto.sdb.emplace_back( - imfi - , node.elementName() - , proto.state.data() - , buf_size - , true - , true + proto.sdb + .emplace_back(imfi, node.elementName(), proto.state.data(), buf_size, true, true - ); + ); return true; } @@ -1511,41 +1574,26 @@ private: { if (node.elementName() == "colorRed") { proto.cnt_rgb++; - proto.sdb.emplace_back( - imfi - , node.elementName() - , proto.redData.data() - , buf_size - , true - , true + proto.sdb + .emplace_back(imfi, node.elementName(), proto.redData.data(), buf_size, true, true - ); + ); return true; } else if (node.elementName() == "colorGreen") { proto.cnt_rgb++; - proto.sdb.emplace_back( - imfi - , node.elementName() - , proto.greenData.data() - , buf_size - , true - , true + proto.sdb + .emplace_back(imfi, node.elementName(), proto.greenData.data(), buf_size, true, true - ); + ); return true; } else if (node.elementName() == "colorBlue") { proto.cnt_rgb++; - proto.sdb.emplace_back( - imfi - , node.elementName() - , proto.blueData.data() - , buf_size - , true - , true + proto.sdb + .emplace_back(imfi, node.elementName(), proto.blueData.data(), buf_size, true, true - ); + ); return true; } @@ -1556,15 +1604,10 @@ private: { if (node.elementName() == "intensity") { proto.inty = true; - proto.sdb.emplace_back( - imfi - , node.elementName() - , proto.intensity.data() - , buf_size - , true - , true + proto.sdb + .emplace_back(imfi, node.elementName(), proto.intensity.data(), buf_size, true, true - ); + ); return true; } @@ -1573,18 +1616,15 @@ private: void readOther(const e57::Node& node, Proto& proto) { - proto.sdb.emplace_back( - imfi - , node.elementName() - , proto.nil.data() - , buf_size - , true - , true + proto.sdb.emplace_back(imfi, node.elementName(), proto.nil.data(), buf_size, true, true ); } - void processProto(e57::CompressedVectorNode& cvn, const Proto& proto, bool hasPlacement, const Base::Placement& plm) + void processProto(e57::CompressedVectorNode& cvn, + const Proto& proto, + bool hasPlacement, + const Base::Placement& plm) { if (proto.cnt_xyz != 3) { throw Base::BadFormatError("Missing channels xyz"); @@ -1603,7 +1643,9 @@ private: for (size_t i = 0; i < count; ++i) { filter = false; if (hasState) { - if (proto.state[i] != 0) { filter = true; } + if (proto.state[i] != 0) { + filter = true; + } } pt = getCoord(proto, i, hasPlacement, plm); @@ -1631,7 +1673,8 @@ private: } } - Base::Vector3d getCoord(const Proto& proto, size_t index, bool hasPlacement, const Base::Placement& plm) const + Base::Vector3d + getCoord(const Proto& proto, size_t index, bool hasPlacement, const Base::Placement& plm) const { Base::Vector3d pt; pt.x = proto.xData[index]; @@ -1643,7 +1686,8 @@ private: return pt; } - Base::Vector3f getNormal(const Proto& proto, size_t index, bool hasPlacement, const Base::Rotation& rot) const + Base::Vector3f + getNormal(const Proto& proto, size_t index, bool hasPlacement, const Base::Rotation& rot) const { Base::Vector3f pt; pt.x = proto.xNormal[index]; @@ -1685,7 +1729,7 @@ private: bool getPlacement(const e57::StructureNode& scan_data, Base::Placement& plm) const { - bool hasPlacement{false}; + bool hasPlacement {false}; if (scan_data.isDefined("pose")) { e57::StructureNode pose(scan_data.get("pose")); if (pose.isDefined("rotation")) { @@ -1724,14 +1768,13 @@ private: PointKernel points; std::vector normals; }; -} +}// namespace -E57Reader::E57Reader(bool Color, bool State, double Distance) - : useColor{Color} - , checkState{State} - , minDistance{Distance} -{ -} +E57Reader::E57Reader(bool Color, bool State, double Distance) + : useColor {Color} + , checkState {State} + , minDistance {Distance} +{} void E57Reader::read(const std::string& filename) { @@ -1753,7 +1796,8 @@ void E57Reader::read(const std::string& filename) // ---------------------------------------------------------------------------- -Writer::Writer(const PointKernel& p) : points(p) +Writer::Writer(const PointKernel& p) + : points(p) { width = p.size(); height = 1; @@ -1793,9 +1837,9 @@ void Writer::setPlacement(const Base::Placement& p) // ---------------------------------------------------------------------------- -AscWriter::AscWriter(const PointKernel& p) : Writer(p) -{ -} +AscWriter::AscWriter(const PointKernel& p) + : Writer(p) +{} void AscWriter::write(const std::string& filename) { @@ -1811,9 +1855,9 @@ void AscWriter::write(const std::string& filename) // ---------------------------------------------------------------------------- -PlyWriter::PlyWriter(const PointKernel& p) : Writer(p) -{ -} +PlyWriter::PlyWriter(const PointKernel& p) + : Writer(p) +{} void PlyWriter::write(const std::string& filename) { @@ -1862,55 +1906,54 @@ void PlyWriter::write(const std::string& filename) std::size_t numPoints = points.size(); std::size_t numValid = 0; const std::vector& pts = points.getBasicPoints(); - for (std::size_t i=0; i(pts[i]); placement.multVec(tmp, tmp); - data(i,0) = static_cast(tmp.x); - data(i,1) = static_cast(tmp.y); - data(i,2) = static_cast(tmp.z); + data(i, 0) = static_cast(tmp.x); + data(i, 1) = static_cast(tmp.y); + data(i, 2) = static_cast(tmp.z); } } std::size_t col = 3; if (hasNormals) { int col0 = col; - int col1 = col+1; - int col2 = col+2; + int col1 = col + 1; + int col2 = col + 2; Base::Rotation rot = placement.getRotation(); if (rot.isIdentity()) { - for (std::size_t i=0; i(normals[i]); rot.multVec(tmp, tmp); - data(i,col0) = static_cast(tmp.x); - data(i,col1) = static_cast(tmp.y); - data(i,col2) = static_cast(tmp.z); + data(i, col0) = static_cast(tmp.x); + data(i, col1) = static_cast(tmp.y); + data(i, col2) = static_cast(tmp.z); } } col += 3; @@ -1918,22 +1961,22 @@ void PlyWriter::write(const std::string& filename) if (hasColors) { int col0 = col; - int col1 = col+1; - int col2 = col+2; - int col3 = col+3; - for (std::size_t i=0; itoString(value) << " "; } out << std::endl; @@ -1966,9 +2013,9 @@ void PlyWriter::write(const std::string& filename) // ---------------------------------------------------------------------------- -PcdWriter::PcdWriter(const PointKernel& p) : Writer(p) -{ -} +PcdWriter::PcdWriter(const PointKernel& p) + : Writer(p) +{} void PcdWriter::write(const std::string& filename) { @@ -2024,91 +2071,94 @@ void PcdWriter::write(const std::string& filename) Eigen::MatrixXd data(numPoints, fields.size()); if (placement.isIdentity()) { - for (std::size_t i=0; i(pts[i]); placement.multVec(tmp, tmp); - data(i,0) = static_cast(tmp.x); - data(i,1) = static_cast(tmp.y); - data(i,2) = static_cast(tmp.z); + data(i, 0) = static_cast(tmp.x); + data(i, 1) = static_cast(tmp.y); + data(i, 2) = static_cast(tmp.z); } } std::size_t col = 3; if (hasNormals) { int col0 = col; - int col1 = col+1; - int col2 = col+2; + int col1 = col + 1; + int col2 = col + 2; Base::Rotation rot = placement.getRotation(); if (rot.isIdentity()) { - for (std::size_t i=0; i(normals[i]); rot.multVec(tmp, tmp); - data(i,col0) = static_cast(tmp.x); - data(i,col1) = static_cast(tmp.y); - data(i,col2) = static_cast(tmp.z); + data(i, col0) = static_cast(tmp.x); + data(i, col1) = static_cast(tmp.y); + data(i, col2) = static_cast(tmp.z); } } col += 3; } if (hasColors) { - for (std::size_t i=0; itoString(value) << " "; + } } out << std::endl; } diff --git a/src/Mod/Points/App/PointsAlgos.h b/src/Mod/Points/App/PointsAlgos.h index 0518c67f52..d3ebf88c28 100644 --- a/src/Mod/Points/App/PointsAlgos.h +++ b/src/Mod/Points/App/PointsAlgos.h @@ -39,10 +39,10 @@ class PointsExport PointsAlgos public: /** Load a point cloud */ - static void Load(PointKernel&, const char *FileName); + static void Load(PointKernel&, const char* FileName); /** Load a point cloud */ - static void LoadAscii(PointKernel&, const char *FileName); + static void LoadAscii(PointKernel&, const char* FileName); }; class Reader @@ -73,51 +73,61 @@ protected: int width, height; }; -class AscReader : public Reader +class AscReader: public Reader { public: AscReader(); void read(const std::string& filename) override; }; -class PlyReader : public Reader +class PlyReader: public Reader { public: PlyReader(); void read(const std::string& filename) override; private: - std::size_t readHeader(std::istream&, std::string& format, std::size_t& offset, - std::vector& fields, std::vector& types, - std::vector& sizes); + std::size_t readHeader(std::istream&, + std::string& format, + std::size_t& offset, + std::vector& fields, + std::vector& types, + std::vector& sizes); void readAscii(std::istream&, std::size_t offset, Eigen::MatrixXd& data); - void readBinary(bool swapByteOrder, std::istream&, std::size_t offset, - const std::vector& types, - const std::vector& sizes, - Eigen::MatrixXd& data); + void readBinary(bool swapByteOrder, + std::istream&, + std::size_t offset, + const std::vector& types, + const std::vector& sizes, + Eigen::MatrixXd& data); }; -class PcdReader : public Reader +class PcdReader: public Reader { public: PcdReader(); void read(const std::string& filename) override; private: - std::size_t readHeader(std::istream&, std::string& format, std::vector& fields, - std::vector& types, std::vector& sizes); + std::size_t readHeader(std::istream&, + std::string& format, + std::vector& fields, + std::vector& types, + std::vector& sizes); void readAscii(std::istream&, Eigen::MatrixXd& data); - void readBinary(bool transpose, std::istream&, - const std::vector& types, - const std::vector& sizes, - Eigen::MatrixXd& data); + void readBinary(bool transpose, + std::istream&, + const std::vector& types, + const std::vector& sizes, + Eigen::MatrixXd& data); }; -class E57Reader : public Reader +class E57Reader: public Reader { public: E57Reader(bool Color, bool State, double Distance); void read(const std::string& filename) override; + protected: bool useColor, checkState; double minDistance; @@ -146,28 +156,28 @@ protected: Base::Placement placement; }; -class AscWriter : public Writer +class AscWriter: public Writer { public: explicit AscWriter(const PointKernel&); void write(const std::string& filename) override; }; -class PlyWriter : public Writer +class PlyWriter: public Writer { public: explicit PlyWriter(const PointKernel&); void write(const std::string& filename) override; }; -class PcdWriter : public Writer +class PcdWriter: public Writer { public: explicit PcdWriter(const PointKernel&); void write(const std::string& filename) override; }; -} // namespace Points +}// namespace Points #endif diff --git a/src/Mod/Points/App/PointsFeature.cpp b/src/Mod/Points/App/PointsFeature.cpp index ffb1ec73bb..85facab185 100644 --- a/src/Mod/Points/App/PointsFeature.cpp +++ b/src/Mod/Points/App/PointsFeature.cpp @@ -23,7 +23,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include "PointsFeature.h" @@ -47,18 +47,18 @@ short Feature::mustExecute() const return 0; } -App::DocumentObjectExecReturn *Feature::execute() +App::DocumentObjectExecReturn* Feature::execute() { this->Points.touch(); return App::DocumentObject::StdReturn; } -void Feature::Restore(Base::XMLReader &reader) +void Feature::Restore(Base::XMLReader& reader) { GeoFeature::Restore(reader); } -void Feature::RestoreDocFile(Base::Reader &reader) +void Feature::RestoreDocFile(Base::Reader& reader) { // This gets only invoked if a points file has been added from Restore() Points.RestoreDocFile(reader); @@ -75,8 +75,9 @@ void Feature::onChanged(const App::Property* prop) try { Base::Placement p; p.fromMatrix(this->Points.getTransform()); - if (p != this->Placement.getValue()) + if (p != this->Placement.getValue()) { this->Placement.setValue(p); + } } catch (const Base::ValueError&) { } @@ -87,26 +88,29 @@ void Feature::onChanged(const App::Property* prop) // --------------------------------------------------------- -namespace App { +namespace App +{ /// @cond DOXERR PROPERTY_SOURCE_TEMPLATE(Points::FeatureCustom, Points::Feature) /// @endcond // explicit template instantiation template class PointsExport FeatureCustomT; -} +}// namespace App // --------------------------------------------------------- -namespace App { +namespace App +{ /// @cond DOXERR PROPERTY_SOURCE_TEMPLATE(Points::FeaturePython, Points::Feature) -template<> const char* Points::FeaturePython::getViewProviderName() const { +template<> +const char* Points::FeaturePython::getViewProviderName() const +{ return "PointsGui::ViewProviderPython"; } /// @endcond // explicit template instantiation template class PointsExport FeaturePythonT; -} - +}// namespace App diff --git a/src/Mod/Points/App/PointsFeature.h b/src/Mod/Points/App/PointsFeature.h index 3ccc82ffa0..b4a465ae49 100644 --- a/src/Mod/Points/App/PointsFeature.h +++ b/src/Mod/Points/App/PointsFeature.h @@ -23,20 +23,22 @@ #ifndef POINTS_FEATURE_H #define POINTS_FEATURE_H -#include // must be first include #include #include +#include // must be first include #include #include "Points.h" #include "PropertyPointKernel.h" -namespace Base{ +namespace Base +{ class Writer; } -namespace App{ +namespace App +{ class Color; } @@ -48,7 +50,7 @@ class PointsFeaturePy; /** Base class of all Points feature classes in FreeCAD. * This class holds an PointsKernel object. */ -class PointsExport Feature : public App::GeoFeature +class PointsExport Feature: public App::GeoFeature { PROPERTY_HEADER_WITH_OVERRIDE(Points::Feature); @@ -58,19 +60,22 @@ public: /** @name methods override Feature */ //@{ - void Restore(Base::XMLReader &reader) override; - void RestoreDocFile(Base::Reader &reader) override; + void Restore(Base::XMLReader& reader) override; + void RestoreDocFile(Base::Reader& reader) override; short mustExecute() const override; /// recalculate the Feature - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; /// returns the type name of the ViewProvider - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "PointsGui::ViewProviderScattered"; } - const App::PropertyComplexGeoData* getPropertyOfGeometry() const override { + const App::PropertyComplexGeoData* getPropertyOfGeometry() const override + { return &Points; } + protected: void onChanged(const App::Property* prop) override; //@} @@ -82,7 +87,7 @@ public: using FeatureCustom = App::FeatureCustomT; using FeaturePython = App::FeaturePythonT; -} //namespace Points +}// namespace Points #endif diff --git a/src/Mod/Points/App/PointsGrid.cpp b/src/Mod/Points/App/PointsGrid.cpp index 0f624efda4..088bb165d9 100644 --- a/src/Mod/Points/App/PointsGrid.cpp +++ b/src/Mod/Points/App/PointsGrid.cpp @@ -27,284 +27,347 @@ using namespace Points; -PointsGrid::PointsGrid (const PointKernel &rclM) -: _pclPoints(&rclM), - _ulCtElements(0), - _ulCtGridsX(0), _ulCtGridsY(0), _ulCtGridsZ(0), - _fGridLenX(0.0f), _fGridLenY(0.0f), _fGridLenZ(0.0f), - _fMinX(0.0f), _fMinY(0.0f), _fMinZ(0.0f) +PointsGrid::PointsGrid(const PointKernel& rclM) + : _pclPoints(&rclM) + , _ulCtElements(0) + , _ulCtGridsX(0) + , _ulCtGridsY(0) + , _ulCtGridsZ(0) + , _fGridLenX(0.0f) + , _fGridLenY(0.0f) + , _fGridLenZ(0.0f) + , _fMinX(0.0f) + , _fMinY(0.0f) + , _fMinZ(0.0f) { - RebuildGrid(); + RebuildGrid(); } -PointsGrid::PointsGrid () -: _pclPoints(nullptr), - _ulCtElements(0), - _ulCtGridsX(POINTS_CT_GRID), _ulCtGridsY(POINTS_CT_GRID), _ulCtGridsZ(POINTS_CT_GRID), - _fGridLenX(0.0f), _fGridLenY(0.0f), _fGridLenZ(0.0f), - _fMinX(0.0f), _fMinY(0.0f), _fMinZ(0.0f) +PointsGrid::PointsGrid() + : _pclPoints(nullptr) + , _ulCtElements(0) + , _ulCtGridsX(POINTS_CT_GRID) + , _ulCtGridsY(POINTS_CT_GRID) + , _ulCtGridsZ(POINTS_CT_GRID) + , _fGridLenX(0.0f) + , _fGridLenY(0.0f) + , _fGridLenZ(0.0f) + , _fMinX(0.0f) + , _fMinY(0.0f) + , _fMinZ(0.0f) +{} + +PointsGrid::PointsGrid(const PointKernel& rclM, + unsigned long ulX, + unsigned long ulY, + unsigned long ulZ) + : _pclPoints(&rclM) + , _ulCtElements(0) + , _ulCtGridsX(0) + , _ulCtGridsY(0) + , _ulCtGridsZ(0) + , _fGridLenX(0.0f) + , _fGridLenY(0.0f) + , _fGridLenZ(0.0f) + , _fMinX(0.0f) + , _fMinY(0.0f) + , _fMinZ(0.0f) { + Rebuild(ulX, ulY, ulZ); } -PointsGrid::PointsGrid (const PointKernel &rclM, unsigned long ulX, unsigned long ulY, unsigned long ulZ) -: _pclPoints(&rclM), - _ulCtElements(0), - _ulCtGridsX(0), _ulCtGridsY(0), _ulCtGridsZ(0), - _fGridLenX(0.0f), _fGridLenY(0.0f), _fGridLenZ(0.0f), - _fMinX(0.0f), _fMinY(0.0f), _fMinZ(0.0f) +PointsGrid::PointsGrid(const PointKernel& rclM, int iCtGridPerAxis) + : _pclPoints(&rclM) + , _ulCtElements(0) + , _ulCtGridsX(0) + , _ulCtGridsY(0) + , _ulCtGridsZ(0) + , _fGridLenX(0.0f) + , _fGridLenY(0.0f) + , _fGridLenZ(0.0f) + , _fMinX(0.0f) + , _fMinY(0.0f) + , _fMinZ(0.0f) { - Rebuild(ulX, ulY, ulZ); + Rebuild(iCtGridPerAxis); } -PointsGrid::PointsGrid (const PointKernel &rclM, int iCtGridPerAxis) -: _pclPoints(&rclM), - _ulCtElements(0), - _ulCtGridsX(0), _ulCtGridsY(0), _ulCtGridsZ(0), - _fGridLenX(0.0f), _fGridLenY(0.0f), _fGridLenZ(0.0f), - _fMinX(0.0f), _fMinY(0.0f), _fMinZ(0.0f) +PointsGrid::PointsGrid(const PointKernel& rclM, double fGridLen) + : _pclPoints(&rclM) + , _ulCtElements(0) + , _ulCtGridsX(0) + , _ulCtGridsY(0) + , _ulCtGridsZ(0) + , _fGridLenX(0.0f) + , _fGridLenY(0.0f) + , _fGridLenZ(0.0f) + , _fMinX(0.0f) + , _fMinY(0.0f) + , _fMinZ(0.0f) { - Rebuild(iCtGridPerAxis); + Base::BoundBox3d clBBPts;// = _pclPoints->GetBoundBox(); + for (const auto& pnt : *_pclPoints) { + clBBPts.Add(pnt); + } + Rebuild(std::max((unsigned long)(clBBPts.LengthX() / fGridLen), 1), + std::max((unsigned long)(clBBPts.LengthY() / fGridLen), 1), + std::max((unsigned long)(clBBPts.LengthZ() / fGridLen), 1)); } -PointsGrid::PointsGrid (const PointKernel &rclM, double fGridLen) -: _pclPoints(&rclM), - _ulCtElements(0), - _ulCtGridsX(0), _ulCtGridsY(0), _ulCtGridsZ(0), - _fGridLenX(0.0f), _fGridLenY(0.0f), _fGridLenZ(0.0f), - _fMinX(0.0f), _fMinY(0.0f), _fMinZ(0.0f) +void PointsGrid::Attach(const PointKernel& rclM) { - Base::BoundBox3d clBBPts;// = _pclPoints->GetBoundBox(); - for (const auto & pnt : *_pclPoints) - clBBPts.Add(pnt); - Rebuild(std::max((unsigned long)(clBBPts.LengthX() / fGridLen), 1), - std::max((unsigned long)(clBBPts.LengthY() / fGridLen), 1), - std::max((unsigned long)(clBBPts.LengthZ() / fGridLen), 1)); + _pclPoints = &rclM; + RebuildGrid(); } -void PointsGrid::Attach (const PointKernel &rclM) +void PointsGrid::Clear() { - _pclPoints = &rclM; - RebuildGrid(); + _aulGrid.clear(); + _pclPoints = nullptr; } -void PointsGrid::Clear () +void PointsGrid::Rebuild(unsigned long ulX, unsigned long ulY, unsigned long ulZ) { - _aulGrid.clear(); - _pclPoints = nullptr; + _ulCtGridsX = ulX; + _ulCtGridsY = ulY; + _ulCtGridsZ = ulZ; + _ulCtElements = HasElements(); + RebuildGrid(); } -void PointsGrid::Rebuild (unsigned long ulX, unsigned long ulY, unsigned long ulZ) +void PointsGrid::Rebuild(unsigned long ulPerGrid, unsigned long ulMaxGrid) { - _ulCtGridsX = ulX; - _ulCtGridsY = ulY; - _ulCtGridsZ = ulZ; - _ulCtElements = HasElements(); - RebuildGrid(); + _ulCtElements = HasElements(); + CalculateGridLength(ulPerGrid, ulMaxGrid); + RebuildGrid(); } -void PointsGrid::Rebuild (unsigned long ulPerGrid, unsigned long ulMaxGrid) +void PointsGrid::Rebuild(int iCtGridPerAxis) { - _ulCtElements = HasElements(); - CalculateGridLength(ulPerGrid, ulMaxGrid); - RebuildGrid(); + _ulCtElements = HasElements(); + CalculateGridLength(iCtGridPerAxis); + RebuildGrid(); } -void PointsGrid::Rebuild (int iCtGridPerAxis) +void PointsGrid::InitGrid() { - _ulCtElements = HasElements(); - CalculateGridLength(iCtGridPerAxis); - RebuildGrid(); -} + assert(_pclPoints); -void PointsGrid::InitGrid () -{ - assert(_pclPoints); + unsigned long i, j; - unsigned long i, j; - - // Calculate grid lengths if not initialized - // - if ((_ulCtGridsX == 0) || (_ulCtGridsY == 0) || (_ulCtGridsZ == 0)) - CalculateGridLength(POINTS_CT_GRID, POINTS_MAX_GRIDS); - - // Determine the grid length and offset - // - { - Base::BoundBox3d clBBPts;// = _pclPoints->GetBoundBox(); - for (const auto & pnt : *_pclPoints) - clBBPts.Add(pnt); - - double fLengthX = clBBPts.LengthX(); - double fLengthY = clBBPts.LengthY(); - double fLengthZ = clBBPts.LengthZ(); - - { - // Offset fGridLen/2 + // Calculate grid lengths if not initialized // - unsigned long num = _ulCtGridsX; - if (num == 0) - num = 1; - _fGridLenX = (1.0f + fLengthX) / double(num); - _fMinX = clBBPts.MinX - 0.5f; - } - - { - unsigned long num = _ulCtGridsY; - if (num == 0) - num = 1; - _fGridLenY = (1.0f + fLengthY) / double(num); - _fMinY = clBBPts.MinY - 0.5f; - } - - { - unsigned long num = _ulCtGridsZ; - if (num == 0) - num = 1; - _fGridLenZ = (1.0f + fLengthZ) / double(num); - _fMinZ = clBBPts.MinZ - 0.5f; - } - } - - // Create data structure - _aulGrid.clear(); - _aulGrid.resize(_ulCtGridsX); - for (i = 0; i < _ulCtGridsX; i++) - { - _aulGrid[i].resize(_ulCtGridsY); - for (j = 0; j < _ulCtGridsY; j++) - _aulGrid[i][j].resize(_ulCtGridsZ); - } -} - -unsigned long PointsGrid::InSide (const Base::BoundBox3d &rclBB, std::vector &raulElements, bool bDelDoubles) const -{ - unsigned long i, j, k, ulMinX, ulMinY, ulMinZ, ulMaxX, ulMaxY, ulMaxZ; - - raulElements.clear(); - - // Grid boxes for a more detailed selection - Position(Base::Vector3d(rclBB.MinX, rclBB.MinY, rclBB.MinZ), ulMinX, ulMinY, ulMinZ); - Position(Base::Vector3d(rclBB.MaxX, rclBB.MaxY, rclBB.MaxZ), ulMaxX, ulMaxY, ulMaxZ); - - for (i = ulMinX; i <= ulMaxX; i++) - { - for (j = ulMinY; j <= ulMaxY; j++) - { - for (k = ulMinZ; k <= ulMaxZ; k++) - { - raulElements.insert(raulElements.end(), _aulGrid[i][j][k].begin(), _aulGrid[i][j][k].end()); - } + if ((_ulCtGridsX == 0) || (_ulCtGridsY == 0) || (_ulCtGridsZ == 0)) { + CalculateGridLength(POINTS_CT_GRID, POINTS_MAX_GRIDS); } - } - if (bDelDoubles) - { - // remove duplicate mentions - std::sort(raulElements.begin(), raulElements.end()); - raulElements.erase(std::unique(raulElements.begin(), raulElements.end()), raulElements.end()); - } - - return raulElements.size(); -} - -unsigned long PointsGrid::InSide (const Base::BoundBox3d &rclBB, std::vector &raulElements, const Base::Vector3d &rclOrg, double fMaxDist, bool bDelDoubles) const -{ - unsigned long i, j, k, ulMinX, ulMinY, ulMinZ, ulMaxX, ulMaxY, ulMaxZ; - double fGridDiag = GetBoundBox(0, 0, 0).CalcDiagonalLength(); - double fMinDistP2 = (fGridDiag * fGridDiag) + (fMaxDist * fMaxDist); - - raulElements.clear(); - - // Grid boxes for a more detailed selection - Position(Base::Vector3d(rclBB.MinX, rclBB.MinY, rclBB.MinZ), ulMinX, ulMinY, ulMinZ); - Position(Base::Vector3d(rclBB.MaxX, rclBB.MaxY, rclBB.MaxZ), ulMaxX, ulMaxY, ulMaxZ); - - for (i = ulMinX; i <= ulMaxX; i++) - { - for (j = ulMinY; j <= ulMaxY; j++) + // Determine the grid length and offset + // { - for (k = ulMinZ; k <= ulMaxZ; k++) - { - if (Base::DistanceP2(GetBoundBox(i, j, k).GetCenter(), rclOrg) < fMinDistP2) - raulElements.insert(raulElements.end(), _aulGrid[i][j][k].begin(), _aulGrid[i][j][k].end()); - } + Base::BoundBox3d clBBPts;// = _pclPoints->GetBoundBox(); + for (const auto& pnt : *_pclPoints) { + clBBPts.Add(pnt); + } + + double fLengthX = clBBPts.LengthX(); + double fLengthY = clBBPts.LengthY(); + double fLengthZ = clBBPts.LengthZ(); + + { + // Offset fGridLen/2 + // + unsigned long num = _ulCtGridsX; + if (num == 0) { + num = 1; + } + _fGridLenX = (1.0f + fLengthX) / double(num); + _fMinX = clBBPts.MinX - 0.5f; + } + + { + unsigned long num = _ulCtGridsY; + if (num == 0) { + num = 1; + } + _fGridLenY = (1.0f + fLengthY) / double(num); + _fMinY = clBBPts.MinY - 0.5f; + } + + { + unsigned long num = _ulCtGridsZ; + if (num == 0) { + num = 1; + } + _fGridLenZ = (1.0f + fLengthZ) / double(num); + _fMinZ = clBBPts.MinZ - 0.5f; + } } - } - if (bDelDoubles) - { - // remove duplicate mentions - std::sort(raulElements.begin(), raulElements.end()); - raulElements.erase(std::unique(raulElements.begin(), raulElements.end()), raulElements.end()); - } - - return raulElements.size(); -} - -unsigned long PointsGrid::InSide (const Base::BoundBox3d &rclBB, std::set &raulElements) const -{ - unsigned long i, j, k, ulMinX, ulMinY, ulMinZ, ulMaxX, ulMaxY, ulMaxZ; - - raulElements.clear(); - - // Grid boxes for a more detailed selection - Position(Base::Vector3d(rclBB.MinX, rclBB.MinY, rclBB.MinZ), ulMinX, ulMinY, ulMinZ); - Position(Base::Vector3d(rclBB.MaxX, rclBB.MaxY, rclBB.MaxZ), ulMaxX, ulMaxY, ulMaxZ); - - for (i = ulMinX; i <= ulMaxX; i++) - { - for (j = ulMinY; j <= ulMaxY; j++) - { - for (k = ulMinZ; k <= ulMaxZ; k++) - { - raulElements.insert(_aulGrid[i][j][k].begin(), _aulGrid[i][j][k].end()); - } + // Create data structure + _aulGrid.clear(); + _aulGrid.resize(_ulCtGridsX); + for (i = 0; i < _ulCtGridsX; i++) { + _aulGrid[i].resize(_ulCtGridsY); + for (j = 0; j < _ulCtGridsY; j++) { + _aulGrid[i][j].resize(_ulCtGridsZ); + } } - } - - return raulElements.size(); } -void PointsGrid::Position (const Base::Vector3d &rclPoint, unsigned long &rulX, unsigned long &rulY, unsigned long &rulZ) const +unsigned long PointsGrid::InSide(const Base::BoundBox3d& rclBB, + std::vector& raulElements, + bool bDelDoubles) const { - if (rclPoint.x <= _fMinX) - rulX = 0; - else - rulX = std::min((unsigned long)((rclPoint.x - _fMinX) / _fGridLenX), _ulCtGridsX - 1); + unsigned long i, j, k, ulMinX, ulMinY, ulMinZ, ulMaxX, ulMaxY, ulMaxZ; - if (rclPoint.y <= _fMinY) - rulY = 0; - else - rulY = std::min((unsigned long)((rclPoint.y - _fMinY) / _fGridLenY), _ulCtGridsY - 1); + raulElements.clear(); - if (rclPoint.z <= _fMinZ) - rulZ = 0; - else - rulZ = std::min((unsigned long)((rclPoint.z - _fMinZ) / _fGridLenZ), _ulCtGridsZ - 1); + // Grid boxes for a more detailed selection + Position(Base::Vector3d(rclBB.MinX, rclBB.MinY, rclBB.MinZ), ulMinX, ulMinY, ulMinZ); + Position(Base::Vector3d(rclBB.MaxX, rclBB.MaxY, rclBB.MaxZ), ulMaxX, ulMaxY, ulMaxZ); + + for (i = ulMinX; i <= ulMaxX; i++) { + for (j = ulMinY; j <= ulMaxY; j++) { + for (k = ulMinZ; k <= ulMaxZ; k++) { + raulElements.insert(raulElements.end(), + _aulGrid[i][j][k].begin(), + _aulGrid[i][j][k].end()); + } + } + } + + if (bDelDoubles) { + // remove duplicate mentions + std::sort(raulElements.begin(), raulElements.end()); + raulElements.erase(std::unique(raulElements.begin(), raulElements.end()), + raulElements.end()); + } + + return raulElements.size(); } -void PointsGrid::CalculateGridLength (unsigned long ulCtGrid, unsigned long ulMaxGrids) +unsigned long PointsGrid::InSide(const Base::BoundBox3d& rclBB, + std::vector& raulElements, + const Base::Vector3d& rclOrg, + double fMaxDist, + bool bDelDoubles) const +{ + unsigned long i, j, k, ulMinX, ulMinY, ulMinZ, ulMaxX, ulMaxY, ulMaxZ; + double fGridDiag = GetBoundBox(0, 0, 0).CalcDiagonalLength(); + double fMinDistP2 = (fGridDiag * fGridDiag) + (fMaxDist * fMaxDist); + + raulElements.clear(); + + // Grid boxes for a more detailed selection + Position(Base::Vector3d(rclBB.MinX, rclBB.MinY, rclBB.MinZ), ulMinX, ulMinY, ulMinZ); + Position(Base::Vector3d(rclBB.MaxX, rclBB.MaxY, rclBB.MaxZ), ulMaxX, ulMaxY, ulMaxZ); + + for (i = ulMinX; i <= ulMaxX; i++) { + for (j = ulMinY; j <= ulMaxY; j++) { + for (k = ulMinZ; k <= ulMaxZ; k++) { + if (Base::DistanceP2(GetBoundBox(i, j, k).GetCenter(), rclOrg) < fMinDistP2) { + raulElements.insert(raulElements.end(), + _aulGrid[i][j][k].begin(), + _aulGrid[i][j][k].end()); + } + } + } + } + + if (bDelDoubles) { + // remove duplicate mentions + std::sort(raulElements.begin(), raulElements.end()); + raulElements.erase(std::unique(raulElements.begin(), raulElements.end()), + raulElements.end()); + } + + return raulElements.size(); +} + +unsigned long PointsGrid::InSide(const Base::BoundBox3d& rclBB, + std::set& raulElements) const +{ + unsigned long i, j, k, ulMinX, ulMinY, ulMinZ, ulMaxX, ulMaxY, ulMaxZ; + + raulElements.clear(); + + // Grid boxes for a more detailed selection + Position(Base::Vector3d(rclBB.MinX, rclBB.MinY, rclBB.MinZ), ulMinX, ulMinY, ulMinZ); + Position(Base::Vector3d(rclBB.MaxX, rclBB.MaxY, rclBB.MaxZ), ulMaxX, ulMaxY, ulMaxZ); + + for (i = ulMinX; i <= ulMaxX; i++) { + for (j = ulMinY; j <= ulMaxY; j++) { + for (k = ulMinZ; k <= ulMaxZ; k++) { + raulElements.insert(_aulGrid[i][j][k].begin(), _aulGrid[i][j][k].end()); + } + } + } + + return raulElements.size(); +} + +void PointsGrid::Position(const Base::Vector3d& rclPoint, + unsigned long& rulX, + unsigned long& rulY, + unsigned long& rulZ) const +{ + if (rclPoint.x <= _fMinX) { + rulX = 0; + } + else { + rulX = std::min((unsigned long)((rclPoint.x - _fMinX) / _fGridLenX), + _ulCtGridsX - 1); + } + + if (rclPoint.y <= _fMinY) { + rulY = 0; + } + else { + rulY = std::min((unsigned long)((rclPoint.y - _fMinY) / _fGridLenY), + _ulCtGridsY - 1); + } + + if (rclPoint.z <= _fMinZ) { + rulZ = 0; + } + else { + rulZ = std::min((unsigned long)((rclPoint.z - _fMinZ) / _fGridLenZ), + _ulCtGridsZ - 1); + } +} + +void PointsGrid::CalculateGridLength(unsigned long ulCtGrid, unsigned long ulMaxGrids) { // Calculate grid lengths or number of grids per dimension // There should be about 10 (?!?!) facets per grid // or max grids should not exceed 10000 Base::BoundBox3d clBBPtsEnlarged;// = _pclPoints->GetBoundBox(); - for (const auto & pnt : *_pclPoints) + for (const auto& pnt : *_pclPoints) { clBBPtsEnlarged.Add(pnt); + } double fVolElem; - if (_ulCtElements > (ulMaxGrids * ulCtGrid)) - fVolElem = (clBBPtsEnlarged.LengthX() * clBBPtsEnlarged.LengthY() * clBBPtsEnlarged.LengthZ()) / float(ulMaxGrids * ulCtGrid); - else - fVolElem = (clBBPtsEnlarged.LengthX() * clBBPtsEnlarged.LengthY() * clBBPtsEnlarged.LengthZ()) / float(_ulCtElements); + if (_ulCtElements > (ulMaxGrids * ulCtGrid)) { + fVolElem = + (clBBPtsEnlarged.LengthX() * clBBPtsEnlarged.LengthY() * clBBPtsEnlarged.LengthZ()) + / float(ulMaxGrids * ulCtGrid); + } + else { + fVolElem = + (clBBPtsEnlarged.LengthX() * clBBPtsEnlarged.LengthY() * clBBPtsEnlarged.LengthZ()) + / float(_ulCtElements); + } - double fVol = fVolElem * float(ulCtGrid); - double fGridLen = float(pow((float)fVol,(float) 1.0f / 3.0f)); + double fVol = fVolElem * float(ulCtGrid); + double fGridLen = float(pow((float)fVol, (float)1.0f / 3.0f)); if (fGridLen > 0) { - _ulCtGridsX = std::max((unsigned long)(clBBPtsEnlarged.LengthX() / fGridLen), 1); - _ulCtGridsY = std::max((unsigned long)(clBBPtsEnlarged.LengthY() / fGridLen), 1); - _ulCtGridsZ = std::max((unsigned long)(clBBPtsEnlarged.LengthZ() / fGridLen), 1); + _ulCtGridsX = + std::max((unsigned long)(clBBPtsEnlarged.LengthX() / fGridLen), 1); + _ulCtGridsY = + std::max((unsigned long)(clBBPtsEnlarged.LengthY() / fGridLen), 1); + _ulCtGridsZ = + std::max((unsigned long)(clBBPtsEnlarged.LengthZ() / fGridLen), 1); } else { // Degenerated grid @@ -314,511 +377,534 @@ void PointsGrid::CalculateGridLength (unsigned long ulCtGrid, unsigned long ulMa } } -void PointsGrid::CalculateGridLength (int iCtGridPerAxis) +void PointsGrid::CalculateGridLength(int iCtGridPerAxis) { - if (iCtGridPerAxis<=0) - { - CalculateGridLength(POINTS_CT_GRID, POINTS_MAX_GRIDS); - return; - } - - // Calculate grid lengths or number of grids per dimension - // There should be about 10 (?!?!) facets per grid - // or max grids should not exceed 10000 - Base::BoundBox3d clBBPts;// = _pclPoints->GetBoundBox(); - for (const auto & pnt : *_pclPoints) - clBBPts.Add(pnt); - - double fLenghtX = clBBPts.LengthX(); - double fLenghtY = clBBPts.LengthY(); - double fLenghtZ = clBBPts.LengthZ(); - - double fLenghtD = clBBPts.CalcDiagonalLength(); - - double fLengthTol = 0.05f * fLenghtD; - - bool bLenghtXisZero = (fLenghtX <= fLengthTol); - bool bLenghtYisZero = (fLenghtY <= fLengthTol); - bool bLenghtZisZero = (fLenghtZ <= fLengthTol); - - int iFlag = 0; - - int iMaxGrids = 1; - - if (bLenghtXisZero) - iFlag += 1; - else - iMaxGrids *= iCtGridPerAxis; - - if (bLenghtYisZero) - iFlag += 2; - else - iMaxGrids *= iCtGridPerAxis; - - if (bLenghtZisZero) - iFlag += 4; - else - iMaxGrids *= iCtGridPerAxis; - - unsigned long ulGridsFacets = 10; - - double fFactorVolumen = 40.0; - double fFactorArea = 10.0; - - switch (iFlag) - { - case 0: - { - double fVolumen = fLenghtX * fLenghtY * fLenghtZ; - - double fVolumenGrid = (fVolumen * ulGridsFacets) / (fFactorVolumen * _ulCtElements); - - if ((fVolumenGrid * iMaxGrids) < fVolumen) - fVolumenGrid = fVolumen / (float)iMaxGrids; - - double fLengthGrid = float(pow((float)fVolumenGrid,(float) 1.0f / 3.0f)); - - _ulCtGridsX = std::max((unsigned long)(fLenghtX / fLengthGrid), 1); - _ulCtGridsY = std::max((unsigned long)(fLenghtY / fLengthGrid), 1); - _ulCtGridsZ = std::max((unsigned long)(fLenghtZ / fLengthGrid), 1); - - } break; - case 1: - { - _ulCtGridsX = 1; // bLenghtXisZero - - double fArea = fLenghtY * fLenghtZ; - - double fAreaGrid = (fArea * ulGridsFacets) / (fFactorArea * _ulCtElements); - - if ((fAreaGrid * iMaxGrids) < fArea) - fAreaGrid = fArea / (double)iMaxGrids; - - double fLengthGrid = double(sqrt(fAreaGrid)); - - _ulCtGridsY = std::max((unsigned long)(fLenghtY / fLengthGrid), 1); - _ulCtGridsZ = std::max((unsigned long)(fLenghtZ / fLengthGrid), 1); - } break; - case 2: - { - _ulCtGridsY = 1; // bLenghtYisZero - - double fArea = fLenghtX * fLenghtZ; - - double fAreaGrid = (fArea * ulGridsFacets) / (fFactorArea * _ulCtElements); - - if ((fAreaGrid * iMaxGrids) < fArea) - fAreaGrid = fArea / (double)iMaxGrids; - - double fLengthGrid = double(sqrt(fAreaGrid)); - - _ulCtGridsX = std::max((unsigned long)(fLenghtX / fLengthGrid), 1); - _ulCtGridsZ = std::max((unsigned long)(fLenghtZ / fLengthGrid), 1); - } break; - case 3: - { - _ulCtGridsX = 1; // bLenghtXisZero - _ulCtGridsY = 1; // bLenghtYisZero - _ulCtGridsZ = iMaxGrids; // bLenghtYisZero - } break; - case 4: - { - _ulCtGridsZ = 1; // bLenghtZisZero - - double fArea = fLenghtX * fLenghtY; - - double fAreaGrid = (fArea * ulGridsFacets) / (fFactorArea * _ulCtElements); - - if ((fAreaGrid * iMaxGrids) < fArea) - fAreaGrid = fArea / (float)iMaxGrids; - - double fLengthGrid = double(sqrt(fAreaGrid)); - - _ulCtGridsX = std::max((unsigned long)(fLenghtX / fLengthGrid), 1); - _ulCtGridsY = std::max((unsigned long)(fLenghtY / fLengthGrid), 1); - } break; - case 5: - { - _ulCtGridsX = 1; // bLenghtXisZero - _ulCtGridsZ = 1; // bLenghtZisZero - _ulCtGridsY = iMaxGrids; // bLenghtYisZero - } break; - case 6: - { - _ulCtGridsY = 1; // bLenghtYisZero - _ulCtGridsZ = 1; // bLenghtZisZero - _ulCtGridsX = iMaxGrids; // bLenghtYisZero - } break; - case 7: - { - _ulCtGridsX = iMaxGrids; // bLenghtXisZero - _ulCtGridsY = iMaxGrids; // bLenghtYisZero - _ulCtGridsZ = iMaxGrids; // bLenghtZisZero - } break; - } -} - -void PointsGrid::SearchNearestFromPoint (const Base::Vector3d &rclPt, std::set &raclInd) const -{ - raclInd.clear(); - Base::BoundBox3d clBB = GetBoundBox(); - - if (clBB.IsInBox(rclPt)) - { // Point lies within - unsigned long ulX, ulY, ulZ; - Position(rclPt, ulX, ulY, ulZ); - //int nX = ulX, nY = ulY, nZ = ulZ; - unsigned long ulLevel = 0; - while (raclInd.empty()) - GetHull(ulX, ulY, ulZ, ulLevel++, raclInd); - GetHull(ulX, ulY, ulZ, ulLevel, raclInd); - } - else - { // Point outside - Base::BoundBox3d::SIDE tSide = clBB.GetSideFromRay(rclPt, clBB.GetCenter() - rclPt); - switch (tSide) - { - case Base::BoundBox3d::RIGHT: - { - int nX = 0; - while (raclInd.empty()) - { - for (unsigned long i = 0; i < _ulCtGridsY; i++) - { - for (unsigned long j = 0; j < _ulCtGridsZ; j++) - raclInd.insert(_aulGrid[nX][i][j].begin(), _aulGrid[nX][i][j].end()); - } - nX++; - } - break; - } - case Base::BoundBox3d::LEFT: - { - int nX = _ulCtGridsX - 1; - while (raclInd.empty()) - { - for (unsigned long i = 0; i < _ulCtGridsY; i++) - { - for (unsigned long j = 0; j < _ulCtGridsZ; j++) - raclInd.insert(_aulGrid[nX][i][j].begin(), _aulGrid[nX][i][j].end()); - } - nX++; - } - break; - } - case Base::BoundBox3d::TOP: - { - int nY = 0; - while (raclInd.empty()) - { - for (unsigned long i = 0; i < _ulCtGridsX; i++) - { - for (unsigned long j = 0; j < _ulCtGridsZ; j++) - raclInd.insert(_aulGrid[i][nY][j].begin(), _aulGrid[i][nY][j].end()); - } - nY++; - } - break; - } - case Base::BoundBox3d::BOTTOM: - { - int nY = _ulCtGridsY - 1; - while (raclInd.empty()) - { - for (unsigned long i = 0; i < _ulCtGridsX; i++) - { - for (unsigned long j = 0; j < _ulCtGridsZ; j++) - raclInd.insert(_aulGrid[i][nY][j].begin(), _aulGrid[i][nY][j].end()); - } - nY--; - } - break; - } - case Base::BoundBox3d::BACK: - { - int nZ = 0; - while (raclInd.empty()) - { - for (unsigned long i = 0; i < _ulCtGridsX; i++) - { - for (unsigned long j = 0; j < _ulCtGridsY; j++) - raclInd.insert(_aulGrid[i][j][nZ].begin(), _aulGrid[i][j][nZ].end()); - } - nZ++; - } - break; - } - case Base::BoundBox3d::FRONT: - { - int nZ = _ulCtGridsZ - 1; - while (raclInd.empty()) - { - for (unsigned long i = 0; i < _ulCtGridsX; i++) - { - for (unsigned long j = 0; j < _ulCtGridsY; j++) - raclInd.insert(_aulGrid[i][j][nZ].begin(), _aulGrid[i][j][nZ].end()); - } - nZ--; - } - break; - } - - default: - break; + if (iCtGridPerAxis <= 0) { + CalculateGridLength(POINTS_CT_GRID, POINTS_MAX_GRIDS); + return; + } + + // Calculate grid lengths or number of grids per dimension + // There should be about 10 (?!?!) facets per grid + // or max grids should not exceed 10000 + Base::BoundBox3d clBBPts;// = _pclPoints->GetBoundBox(); + for (const auto& pnt : *_pclPoints) { + clBBPts.Add(pnt); + } + + double fLenghtX = clBBPts.LengthX(); + double fLenghtY = clBBPts.LengthY(); + double fLenghtZ = clBBPts.LengthZ(); + + double fLenghtD = clBBPts.CalcDiagonalLength(); + + double fLengthTol = 0.05f * fLenghtD; + + bool bLenghtXisZero = (fLenghtX <= fLengthTol); + bool bLenghtYisZero = (fLenghtY <= fLengthTol); + bool bLenghtZisZero = (fLenghtZ <= fLengthTol); + + int iFlag = 0; + + int iMaxGrids = 1; + + if (bLenghtXisZero) { + iFlag += 1; + } + else { + iMaxGrids *= iCtGridPerAxis; + } + + if (bLenghtYisZero) { + iFlag += 2; + } + else { + iMaxGrids *= iCtGridPerAxis; + } + + if (bLenghtZisZero) { + iFlag += 4; + } + else { + iMaxGrids *= iCtGridPerAxis; + } + + unsigned long ulGridsFacets = 10; + + double fFactorVolumen = 40.0; + double fFactorArea = 10.0; + + switch (iFlag) { + case 0: { + double fVolumen = fLenghtX * fLenghtY * fLenghtZ; + + double fVolumenGrid = (fVolumen * ulGridsFacets) / (fFactorVolumen * _ulCtElements); + + if ((fVolumenGrid * iMaxGrids) < fVolumen) { + fVolumenGrid = fVolumen / (float)iMaxGrids; + } + + double fLengthGrid = float(pow((float)fVolumenGrid, (float)1.0f / 3.0f)); + + _ulCtGridsX = std::max((unsigned long)(fLenghtX / fLengthGrid), 1); + _ulCtGridsY = std::max((unsigned long)(fLenghtY / fLengthGrid), 1); + _ulCtGridsZ = std::max((unsigned long)(fLenghtZ / fLengthGrid), 1); + + } break; + case 1: { + _ulCtGridsX = 1;// bLenghtXisZero + + double fArea = fLenghtY * fLenghtZ; + + double fAreaGrid = (fArea * ulGridsFacets) / (fFactorArea * _ulCtElements); + + if ((fAreaGrid * iMaxGrids) < fArea) { + fAreaGrid = fArea / (double)iMaxGrids; + } + + double fLengthGrid = double(sqrt(fAreaGrid)); + + _ulCtGridsY = std::max((unsigned long)(fLenghtY / fLengthGrid), 1); + _ulCtGridsZ = std::max((unsigned long)(fLenghtZ / fLengthGrid), 1); + } break; + case 2: { + _ulCtGridsY = 1;// bLenghtYisZero + + double fArea = fLenghtX * fLenghtZ; + + double fAreaGrid = (fArea * ulGridsFacets) / (fFactorArea * _ulCtElements); + + if ((fAreaGrid * iMaxGrids) < fArea) { + fAreaGrid = fArea / (double)iMaxGrids; + } + + double fLengthGrid = double(sqrt(fAreaGrid)); + + _ulCtGridsX = std::max((unsigned long)(fLenghtX / fLengthGrid), 1); + _ulCtGridsZ = std::max((unsigned long)(fLenghtZ / fLengthGrid), 1); + } break; + case 3: { + _ulCtGridsX = 1; // bLenghtXisZero + _ulCtGridsY = 1; // bLenghtYisZero + _ulCtGridsZ = iMaxGrids;// bLenghtYisZero + } break; + case 4: { + _ulCtGridsZ = 1;// bLenghtZisZero + + double fArea = fLenghtX * fLenghtY; + + double fAreaGrid = (fArea * ulGridsFacets) / (fFactorArea * _ulCtElements); + + if ((fAreaGrid * iMaxGrids) < fArea) { + fAreaGrid = fArea / (float)iMaxGrids; + } + + double fLengthGrid = double(sqrt(fAreaGrid)); + + _ulCtGridsX = std::max((unsigned long)(fLenghtX / fLengthGrid), 1); + _ulCtGridsY = std::max((unsigned long)(fLenghtY / fLengthGrid), 1); + } break; + case 5: { + _ulCtGridsX = 1; // bLenghtXisZero + _ulCtGridsZ = 1; // bLenghtZisZero + _ulCtGridsY = iMaxGrids;// bLenghtYisZero + } break; + case 6: { + _ulCtGridsY = 1; // bLenghtYisZero + _ulCtGridsZ = 1; // bLenghtZisZero + _ulCtGridsX = iMaxGrids;// bLenghtYisZero + } break; + case 7: { + _ulCtGridsX = iMaxGrids;// bLenghtXisZero + _ulCtGridsY = iMaxGrids;// bLenghtYisZero + _ulCtGridsZ = iMaxGrids;// bLenghtZisZero + } break; } - } } -void PointsGrid::GetHull (unsigned long ulX, unsigned long ulY, unsigned long ulZ, - unsigned long ulDistance, std::set &raclInd) const +void PointsGrid::SearchNearestFromPoint(const Base::Vector3d& rclPt, + std::set& raclInd) const { - int nX1 = std::max(0, int(ulX) - int(ulDistance)); - int nY1 = std::max(0, int(ulY) - int(ulDistance)); - int nZ1 = std::max(0, int(ulZ) - int(ulDistance)); - int nX2 = std::min(int(_ulCtGridsX) - 1, int(ulX) + int(ulDistance)); - int nY2 = std::min(int(_ulCtGridsY) - 1, int(ulY) + int(ulDistance)); - int nZ2 = std::min(int(_ulCtGridsZ) - 1, int(ulZ) + int(ulDistance)); + raclInd.clear(); + Base::BoundBox3d clBB = GetBoundBox(); - int i, j; + if (clBB.IsInBox(rclPt)) {// Point lies within + unsigned long ulX, ulY, ulZ; + Position(rclPt, ulX, ulY, ulZ); + // int nX = ulX, nY = ulY, nZ = ulZ; + unsigned long ulLevel = 0; + while (raclInd.empty()) { + GetHull(ulX, ulY, ulZ, ulLevel++, raclInd); + } + GetHull(ulX, ulY, ulZ, ulLevel, raclInd); + } + else {// Point outside + Base::BoundBox3d::SIDE tSide = clBB.GetSideFromRay(rclPt, clBB.GetCenter() - rclPt); + switch (tSide) { + case Base::BoundBox3d::RIGHT: { + int nX = 0; + while (raclInd.empty()) { + for (unsigned long i = 0; i < _ulCtGridsY; i++) { + for (unsigned long j = 0; j < _ulCtGridsZ; j++) { + raclInd.insert(_aulGrid[nX][i][j].begin(), _aulGrid[nX][i][j].end()); + } + } + nX++; + } + break; + } + case Base::BoundBox3d::LEFT: { + int nX = _ulCtGridsX - 1; + while (raclInd.empty()) { + for (unsigned long i = 0; i < _ulCtGridsY; i++) { + for (unsigned long j = 0; j < _ulCtGridsZ; j++) { + raclInd.insert(_aulGrid[nX][i][j].begin(), _aulGrid[nX][i][j].end()); + } + } + nX++; + } + break; + } + case Base::BoundBox3d::TOP: { + int nY = 0; + while (raclInd.empty()) { + for (unsigned long i = 0; i < _ulCtGridsX; i++) { + for (unsigned long j = 0; j < _ulCtGridsZ; j++) { + raclInd.insert(_aulGrid[i][nY][j].begin(), _aulGrid[i][nY][j].end()); + } + } + nY++; + } + break; + } + case Base::BoundBox3d::BOTTOM: { + int nY = _ulCtGridsY - 1; + while (raclInd.empty()) { + for (unsigned long i = 0; i < _ulCtGridsX; i++) { + for (unsigned long j = 0; j < _ulCtGridsZ; j++) { + raclInd.insert(_aulGrid[i][nY][j].begin(), _aulGrid[i][nY][j].end()); + } + } + nY--; + } + break; + } + case Base::BoundBox3d::BACK: { + int nZ = 0; + while (raclInd.empty()) { + for (unsigned long i = 0; i < _ulCtGridsX; i++) { + for (unsigned long j = 0; j < _ulCtGridsY; j++) { + raclInd.insert(_aulGrid[i][j][nZ].begin(), _aulGrid[i][j][nZ].end()); + } + } + nZ++; + } + break; + } + case Base::BoundBox3d::FRONT: { + int nZ = _ulCtGridsZ - 1; + while (raclInd.empty()) { + for (unsigned long i = 0; i < _ulCtGridsX; i++) { + for (unsigned long j = 0; j < _ulCtGridsY; j++) { + raclInd.insert(_aulGrid[i][j][nZ].begin(), _aulGrid[i][j][nZ].end()); + } + } + nZ--; + } + break; + } - // top plane - for (i = nX1; i <= nX2; i++) - { - for (j = nY1; j <= nY2; j++) - GetElements(i, j, nZ1, raclInd); - } - // bottom plane - for (i = nX1; i <= nX2; i++) - { - for (j = nY1; j <= nY2; j++) - GetElements(i, j, nZ2, raclInd); - } - // left plane - for (i = nY1; i <= nY2; i++) - { - for (j = (nZ1+1); j <= (nZ2-1); j++) - GetElements(nX1, i, j, raclInd); - } - // right plane - for (i = nY1; i <= nY2; i++) - { - for (j = (nZ1+1); j <= (nZ2-1); j++) - GetElements(nX2, i, j, raclInd); - } - // front plane - for (i = (nX1+1); i <= (nX2-1); i++) - { - for (j = (nZ1+1); j <= (nZ2-1); j++) - GetElements(i, nY1, j, raclInd); - } - // back plane - for (i = (nX1+1); i <= (nX2-1); i++) - { - for (j = (nZ1+1); j <= (nZ2-1); j++) - GetElements(i, nY2, j, raclInd); - } + default: + break; + } + } } -unsigned long PointsGrid::GetElements (unsigned long ulX, unsigned long ulY, unsigned long ulZ, - std::set &raclInd) const +void PointsGrid::GetHull(unsigned long ulX, + unsigned long ulY, + unsigned long ulZ, + unsigned long ulDistance, + std::set& raclInd) const { - const std::set &rclSet = _aulGrid[ulX][ulY][ulZ]; - if (!rclSet.empty()) - { - raclInd.insert(rclSet.begin(), rclSet.end()); - return rclSet.size(); - } + int nX1 = std::max(0, int(ulX) - int(ulDistance)); + int nY1 = std::max(0, int(ulY) - int(ulDistance)); + int nZ1 = std::max(0, int(ulZ) - int(ulDistance)); + int nX2 = std::min(int(_ulCtGridsX) - 1, int(ulX) + int(ulDistance)); + int nY2 = std::min(int(_ulCtGridsY) - 1, int(ulY) + int(ulDistance)); + int nZ2 = std::min(int(_ulCtGridsZ) - 1, int(ulZ) + int(ulDistance)); - return 0; + int i, j; + + // top plane + for (i = nX1; i <= nX2; i++) { + for (j = nY1; j <= nY2; j++) { + GetElements(i, j, nZ1, raclInd); + } + } + // bottom plane + for (i = nX1; i <= nX2; i++) { + for (j = nY1; j <= nY2; j++) { + GetElements(i, j, nZ2, raclInd); + } + } + // left plane + for (i = nY1; i <= nY2; i++) { + for (j = (nZ1 + 1); j <= (nZ2 - 1); j++) { + GetElements(nX1, i, j, raclInd); + } + } + // right plane + for (i = nY1; i <= nY2; i++) { + for (j = (nZ1 + 1); j <= (nZ2 - 1); j++) { + GetElements(nX2, i, j, raclInd); + } + } + // front plane + for (i = (nX1 + 1); i <= (nX2 - 1); i++) { + for (j = (nZ1 + 1); j <= (nZ2 - 1); j++) { + GetElements(i, nY1, j, raclInd); + } + } + // back plane + for (i = (nX1 + 1); i <= (nX2 - 1); i++) { + for (j = (nZ1 + 1); j <= (nZ2 - 1); j++) { + GetElements(i, nY2, j, raclInd); + } + } } -void PointsGrid::AddPoint (const Base::Vector3d &rclPt, unsigned long ulPtIndex, float /*fEpsilon*/) +unsigned long PointsGrid::GetElements(unsigned long ulX, + unsigned long ulY, + unsigned long ulZ, + std::set& raclInd) const { - unsigned long ulX, ulY, ulZ; - Pos(Base::Vector3d(rclPt.x, rclPt.y, rclPt.z), ulX, ulY, ulZ); - if ( (ulX < _ulCtGridsX) && (ulY < _ulCtGridsY) && (ulZ < _ulCtGridsZ) ) - _aulGrid[ulX][ulY][ulZ].insert(ulPtIndex); + const std::set& rclSet = _aulGrid[ulX][ulY][ulZ]; + if (!rclSet.empty()) { + raclInd.insert(rclSet.begin(), rclSet.end()); + return rclSet.size(); + } + + return 0; } -void PointsGrid::Validate (const PointKernel &rclPoints) +void PointsGrid::AddPoint(const Base::Vector3d& rclPt, unsigned long ulPtIndex, float /*fEpsilon*/) { - if (_pclPoints != &rclPoints) - Attach(rclPoints); - else if (rclPoints.size() != _ulCtElements) - RebuildGrid(); + unsigned long ulX, ulY, ulZ; + Pos(Base::Vector3d(rclPt.x, rclPt.y, rclPt.z), ulX, ulY, ulZ); + if ((ulX < _ulCtGridsX) && (ulY < _ulCtGridsY) && (ulZ < _ulCtGridsZ)) { + _aulGrid[ulX][ulY][ulZ].insert(ulPtIndex); + } } -void PointsGrid::Validate () +void PointsGrid::Validate(const PointKernel& rclPoints) { - if (!_pclPoints) - return; + if (_pclPoints != &rclPoints) { + Attach(rclPoints); + } + else if (rclPoints.size() != _ulCtElements) { + RebuildGrid(); + } +} - if (_pclPoints->size() != _ulCtElements) - RebuildGrid(); +void PointsGrid::Validate() +{ + if (!_pclPoints) { + return; + } + + if (_pclPoints->size() != _ulCtElements) { + RebuildGrid(); + } } bool PointsGrid::Verify() const { - if ( !_pclPoints ) - return false; // no point cloud attached - if (_pclPoints->size() != _ulCtElements) - return false; // not up-to-date - - PointsGridIterator it(*this); - for ( it.Init(); it.More(); it.Next() ) - { - std::vector aulElements; - it.GetElements( aulElements ); - for (unsigned long element : aulElements) - { - const Base::Vector3d& cP = _pclPoints->getPoint(element); - if (!it.GetBoundBox().IsInBox(cP)) - return false; // point doesn't lie inside the grid element + if (!_pclPoints) { + return false;// no point cloud attached + } + if (_pclPoints->size() != _ulCtElements) { + return false;// not up-to-date } - } - return true; + PointsGridIterator it(*this); + for (it.Init(); it.More(); it.Next()) { + std::vector aulElements; + it.GetElements(aulElements); + for (unsigned long element : aulElements) { + const Base::Vector3d& cP = _pclPoints->getPoint(element); + if (!it.GetBoundBox().IsInBox(cP)) { + return false;// point doesn't lie inside the grid element + } + } + } + + return true; } -void PointsGrid::RebuildGrid () +void PointsGrid::RebuildGrid() { - _ulCtElements = _pclPoints->size(); + _ulCtElements = _pclPoints->size(); - InitGrid(); + InitGrid(); - // Fill data structure + // Fill data structure - unsigned long i = 0; - for (const auto & pnt : *_pclPoints) - { - AddPoint(pnt, i++); - } + unsigned long i = 0; + for (const auto& pnt : *_pclPoints) { + AddPoint(pnt, i++); + } } -void PointsGrid::Pos (const Base::Vector3d &rclPoint, unsigned long &rulX, unsigned long &rulY, unsigned long &rulZ) const +void PointsGrid::Pos(const Base::Vector3d& rclPoint, + unsigned long& rulX, + unsigned long& rulY, + unsigned long& rulZ) const { - rulX = (unsigned long)((rclPoint.x - _fMinX) / _fGridLenX); - rulY = (unsigned long)((rclPoint.y - _fMinY) / _fGridLenY); - rulZ = (unsigned long)((rclPoint.z - _fMinZ) / _fGridLenZ); + rulX = (unsigned long)((rclPoint.x - _fMinX) / _fGridLenX); + rulY = (unsigned long)((rclPoint.y - _fMinY) / _fGridLenY); + rulZ = (unsigned long)((rclPoint.z - _fMinZ) / _fGridLenZ); } -unsigned long PointsGrid::FindElements (const Base::Vector3d &rclPoint, std::set& aulElements) const +unsigned long PointsGrid::FindElements(const Base::Vector3d& rclPoint, + std::set& aulElements) const { - unsigned long ulX, ulY, ulZ; - Pos(rclPoint, ulX, ulY, ulZ); + unsigned long ulX, ulY, ulZ; + Pos(rclPoint, ulX, ulY, ulZ); - // check if the given point is inside the grid structure - if ( (ulX < _ulCtGridsX) && (ulY < _ulCtGridsY) && (ulZ < _ulCtGridsZ) ) - { - return GetElements(ulX, ulY, ulZ, aulElements); - } + // check if the given point is inside the grid structure + if ((ulX < _ulCtGridsX) && (ulY < _ulCtGridsY) && (ulZ < _ulCtGridsZ)) { + return GetElements(ulX, ulY, ulZ, aulElements); + } - return 0; + return 0; } // ---------------------------------------------------------------- -PointsGridIterator::PointsGridIterator (const PointsGrid &rclG) -: _rclGrid(rclG), - _clPt(0.0f, 0.0f, 0.0f), _clDir(0.0f, 0.0f, 0.0f) +PointsGridIterator::PointsGridIterator(const PointsGrid& rclG) + : _rclGrid(rclG) + , _clPt(0.0f, 0.0f, 0.0f) + , _clDir(0.0f, 0.0f, 0.0f) +{} + +bool PointsGridIterator::InitOnRay(const Base::Vector3d& rclPt, + const Base::Vector3d& rclDir, + float fMaxSearchArea, + std::vector& raulElements) { + bool ret = InitOnRay(rclPt, rclDir, raulElements); + _fMaxSearchArea = fMaxSearchArea; + return ret; } -bool PointsGridIterator::InitOnRay (const Base::Vector3d &rclPt, const Base::Vector3d &rclDir, float fMaxSearchArea, - std::vector &raulElements) +bool PointsGridIterator::InitOnRay(const Base::Vector3d& rclPt, + const Base::Vector3d& rclDir, + std::vector& raulElements) { - bool ret = InitOnRay (rclPt, rclDir, raulElements); - _fMaxSearchArea = fMaxSearchArea; - return ret; -} + // needed in NextOnRay() to avoid an infinite loop + _cSearchPositions.clear(); -bool PointsGridIterator::InitOnRay (const Base::Vector3d &rclPt, const Base::Vector3d &rclDir, - std::vector &raulElements) -{ - // needed in NextOnRay() to avoid an infinite loop - _cSearchPositions.clear(); + _fMaxSearchArea = FLOAT_MAX; - _fMaxSearchArea = FLOAT_MAX; + raulElements.clear(); - raulElements.clear(); + _clPt = rclPt; + _clDir = rclDir; + _bValidRay = false; - _clPt = rclPt; - _clDir = rclDir; - _bValidRay = false; - - // point lies within global BB - if (_rclGrid.GetBoundBox().IsInBox(rclPt)) - { // determine the voxel by the starting point - _rclGrid.Position(rclPt, _ulX, _ulY, _ulZ); - raulElements.insert(raulElements.end(), _rclGrid._aulGrid[_ulX][_ulY][_ulZ].begin(), _rclGrid._aulGrid[_ulX][_ulY][_ulZ].end()); - _bValidRay = true; - } - else - { // StartPoint outside - Base::Vector3d cP0, cP1; - if (_rclGrid.GetBoundBox().IntersectWithLine(rclPt, rclDir, cP0, cP1)) - { // determine the next point - if ((cP0 - rclPt).Length() < (cP1 - rclPt).Length()) - _rclGrid.Position(cP0, _ulX, _ulY, _ulZ); - else - _rclGrid.Position(cP1, _ulX, _ulY, _ulZ); - - raulElements.insert(raulElements.end(), _rclGrid._aulGrid[_ulX][_ulY][_ulZ].begin(), _rclGrid._aulGrid[_ulX][_ulY][_ulZ].end()); - _bValidRay = true; + // point lies within global BB + if (_rclGrid.GetBoundBox().IsInBox(rclPt)) {// determine the voxel by the starting point + _rclGrid.Position(rclPt, _ulX, _ulY, _ulZ); + raulElements.insert(raulElements.end(), + _rclGrid._aulGrid[_ulX][_ulY][_ulZ].begin(), + _rclGrid._aulGrid[_ulX][_ulY][_ulZ].end()); + _bValidRay = true; } - } + else {// StartPoint outside + Base::Vector3d cP0, cP1; + if (_rclGrid.GetBoundBox().IntersectWithLine(rclPt, + rclDir, + cP0, + cP1)) {// determine the next point + if ((cP0 - rclPt).Length() < (cP1 - rclPt).Length()) { + _rclGrid.Position(cP0, _ulX, _ulY, _ulZ); + } + else { + _rclGrid.Position(cP1, _ulX, _ulY, _ulZ); + } - return _bValidRay; -} - -bool PointsGridIterator::NextOnRay (std::vector &raulElements) -{ - if (!_bValidRay) - return false; // not initialized or beam exited - - raulElements.clear(); - - Base::Vector3d clIntersectPoint; - - // Look for the next adjacent BB on the search beam - Base::BoundBox3d::SIDE tSide = _rclGrid.GetBoundBox(_ulX, _ulY, _ulZ).GetSideFromRay(_clPt, _clDir, clIntersectPoint); - - // Search area - // - if ((_clPt-clIntersectPoint).Length() > _fMaxSearchArea) - { - _bValidRay = false; - } - else - { - switch (tSide) - { - case Base::BoundBox3d::LEFT: _ulX--; break; - case Base::BoundBox3d::RIGHT: _ulX++; break; - case Base::BoundBox3d::BOTTOM: _ulY--; break; - case Base::BoundBox3d::TOP: _ulY++; break; - case Base::BoundBox3d::FRONT: _ulZ--; break; - case Base::BoundBox3d::BACK: _ulZ++; break; - - default: - case Base::BoundBox3d::INVALID: - _bValidRay = false; - break; + raulElements.insert(raulElements.end(), + _rclGrid._aulGrid[_ulX][_ulY][_ulZ].begin(), + _rclGrid._aulGrid[_ulX][_ulY][_ulZ].end()); + _bValidRay = true; + } } - GridElement pos(_ulX, _ulY, _ulZ); - if ( _cSearchPositions.find( pos ) != _cSearchPositions.end() ) - _bValidRay = false; // grid element already visited => result from GetSideFromRay invalid - } - - if (_bValidRay && _rclGrid.CheckPos(_ulX, _ulY, _ulZ)) - { - GridElement pos(_ulX, _ulY, _ulZ); _cSearchPositions.insert(pos); - raulElements.insert(raulElements.end(), _rclGrid._aulGrid[_ulX][_ulY][_ulZ].begin(), _rclGrid._aulGrid[_ulX][_ulY][_ulZ].end()); - } - else { - _bValidRay = false; // ray exited - } - - return _bValidRay; + return _bValidRay; +} + +bool PointsGridIterator::NextOnRay(std::vector& raulElements) +{ + if (!_bValidRay) { + return false;// not initialized or beam exited + } + + raulElements.clear(); + + Base::Vector3d clIntersectPoint; + + // Look for the next adjacent BB on the search beam + Base::BoundBox3d::SIDE tSide = + _rclGrid.GetBoundBox(_ulX, _ulY, _ulZ).GetSideFromRay(_clPt, _clDir, clIntersectPoint); + + // Search area + // + if ((_clPt - clIntersectPoint).Length() > _fMaxSearchArea) { + _bValidRay = false; + } + else { + switch (tSide) { + case Base::BoundBox3d::LEFT: + _ulX--; + break; + case Base::BoundBox3d::RIGHT: + _ulX++; + break; + case Base::BoundBox3d::BOTTOM: + _ulY--; + break; + case Base::BoundBox3d::TOP: + _ulY++; + break; + case Base::BoundBox3d::FRONT: + _ulZ--; + break; + case Base::BoundBox3d::BACK: + _ulZ++; + break; + + default: + case Base::BoundBox3d::INVALID: + _bValidRay = false; + break; + } + + GridElement pos(_ulX, _ulY, _ulZ); + if (_cSearchPositions.find(pos) != _cSearchPositions.end()) { + _bValidRay = false;// grid element already visited => result from GetSideFromRay invalid + } + } + + if (_bValidRay && _rclGrid.CheckPos(_ulX, _ulY, _ulZ)) { + GridElement pos(_ulX, _ulY, _ulZ); + _cSearchPositions.insert(pos); + raulElements.insert(raulElements.end(), + _rclGrid._aulGrid[_ulX][_ulY][_ulZ].begin(), + _rclGrid._aulGrid[_ulX][_ulY][_ulZ].end()); + } + else { + _bValidRay = false;// ray exited + } + + return _bValidRay; } diff --git a/src/Mod/Points/App/PointsGrid.h b/src/Mod/Points/App/PointsGrid.h index 56128b7e91..8b80927ae4 100644 --- a/src/Mod/Points/App/PointsGrid.h +++ b/src/Mod/Points/App/PointsGrid.h @@ -30,141 +30,179 @@ #include "Points.h" -#define POINTS_CT_GRID 256 // Default value for number of elements per grid -#define POINTS_MAX_GRIDS 100000 // Default value for maximum number of grids -#define POINTS_CT_GRID_PER_AXIS 20 -#define PONTSGRID_BBOX_EXTENSION 10.0f +#define POINTS_CT_GRID 256 // Default value for number of elements per grid +#define POINTS_MAX_GRIDS 100000// Default value for maximum number of grids +#define POINTS_CT_GRID_PER_AXIS 20 +#define PONTSGRID_BBOX_EXTENSION 10.0f -namespace Points { +namespace Points +{ class PointsGrid; /** - * The PointsGrid allows to divide a global point cloud into smaller regions of elements depending on the resolution of the grid. - * All grid elements in the grid structure have the same size. + * The PointsGrid allows to divide a global point cloud into smaller regions of elements depending + * on the resolution of the grid. All grid elements in the grid structure have the same size. * - * Grids can be used within algorithms to avoid to iterate through all elements, so grids can speed up algorithms dramatically. + * Grids can be used within algorithms to avoid to iterate through all elements, so grids can speed + * up algorithms dramatically. * @author Werner Mayer */ class PointsExport PointsGrid { public: - /** @name Construction */ - //@{ - /// Construction - explicit PointsGrid (const PointKernel &rclM); - /// Construction - PointsGrid (); - /// Construction - PointsGrid (const PointKernel &rclM, int iCtGridPerAxis); - /// Construction - PointsGrid (const PointKernel &rclM, double fGridLen); - /// Construction - PointsGrid (const PointKernel &rclM, unsigned long ulX, unsigned long ulY, unsigned long ulZ); - /// Destruction - virtual ~PointsGrid () = default; - //@} + /** @name Construction */ + //@{ + /// Construction + explicit PointsGrid(const PointKernel& rclM); + /// Construction + PointsGrid(); + /// Construction + PointsGrid(const PointKernel& rclM, int iCtGridPerAxis); + /// Construction + PointsGrid(const PointKernel& rclM, double fGridLen); + /// Construction + PointsGrid(const PointKernel& rclM, unsigned long ulX, unsigned long ulY, unsigned long ulZ); + /// Destruction + virtual ~PointsGrid() = default; + //@} public: - /** Attaches the point kernel to this grid, an already attached point cloud gets detached. The grid gets rebuilt - * automatically. */ - virtual void Attach (const PointKernel &rclM); - /** Rebuilds the grid structure. */ - virtual void Rebuild (unsigned long ulPerGrid = POINTS_CT_GRID, unsigned long ulMaxGrid = POINTS_MAX_GRIDS); - /** Rebuilds the grid structure. */ - virtual void Rebuild (int iCtGridPerAxis = POINTS_CT_GRID_PER_AXIS); - /** Rebuilds the grid structure. */ - virtual void Rebuild (unsigned long ulX, unsigned long ulY, unsigned long ulZ); + /** Attaches the point kernel to this grid, an already attached point cloud gets detached. The + * grid gets rebuilt automatically. */ + virtual void Attach(const PointKernel& rclM); + /** Rebuilds the grid structure. */ + virtual void Rebuild(unsigned long ulPerGrid = POINTS_CT_GRID, + unsigned long ulMaxGrid = POINTS_MAX_GRIDS); + /** Rebuilds the grid structure. */ + virtual void Rebuild(int iCtGridPerAxis = POINTS_CT_GRID_PER_AXIS); + /** Rebuilds the grid structure. */ + virtual void Rebuild(unsigned long ulX, unsigned long ulY, unsigned long ulZ); - /** @name Search */ - //@{ - /** Searches for elements lying in the intersection area of the grid and the bounding box. */ - virtual unsigned long InSide (const Base::BoundBox3d &rclBB, std::vector &raulElements, bool bDelDoubles = true) const; - /** Searches for elements lying in the intersection area of the grid and the bounding box. */ - virtual unsigned long InSide (const Base::BoundBox3d &rclBB, std::set &raulElementss) const; - /** Searches for elements lying in the intersection area of the grid and the bounding box. */ - virtual unsigned long InSide (const Base::BoundBox3d &rclBB, std::vector &raulElements, - const Base::Vector3d &rclOrg, double fMaxDist, bool bDelDoubles = true) const; - /** Searches for the nearest grids that contain elements from a point, the result are grid indices. */ - void SearchNearestFromPoint (const Base::Vector3d &rclPt, std::set &rclInd) const; - //@} + /** @name Search */ + //@{ + /** Searches for elements lying in the intersection area of the grid and the bounding box. */ + virtual unsigned long InSide(const Base::BoundBox3d& rclBB, + std::vector& raulElements, + bool bDelDoubles = true) const; + /** Searches for elements lying in the intersection area of the grid and the bounding box. */ + virtual unsigned long InSide(const Base::BoundBox3d& rclBB, + std::set& raulElementss) const; + /** Searches for elements lying in the intersection area of the grid and the bounding box. */ + virtual unsigned long InSide(const Base::BoundBox3d& rclBB, + std::vector& raulElements, + const Base::Vector3d& rclOrg, + double fMaxDist, + bool bDelDoubles = true) const; + /** Searches for the nearest grids that contain elements from a point, the result are grid + * indices. */ + void SearchNearestFromPoint(const Base::Vector3d& rclPt, std::set& rclInd) const; + //@} - /** Returns the lengths of the grid elements in x,y and z direction. */ - virtual void GetGridLengths (double &rfLenX, double &rfLenY, double &rfLenZ) const - { rfLenX = _fGridLenX; rfLenY = _fGridLenY; rfLenZ = _fGridLenZ; } - /** Returns the number of grid elements in x,y and z direction. */ - virtual void GetCtGrids (unsigned long &rulX, unsigned long &rulY, unsigned long &rulZ) const - { rulX = _ulCtGridsX; rulY = _ulCtGridsY; rulZ = _ulCtGridsZ; } + /** Returns the lengths of the grid elements in x,y and z direction. */ + virtual void GetGridLengths(double& rfLenX, double& rfLenY, double& rfLenZ) const + { + rfLenX = _fGridLenX; + rfLenY = _fGridLenY; + rfLenZ = _fGridLenZ; + } + /** Returns the number of grid elements in x,y and z direction. */ + virtual void GetCtGrids(unsigned long& rulX, unsigned long& rulY, unsigned long& rulZ) const + { + rulX = _ulCtGridsX; + rulY = _ulCtGridsY; + rulZ = _ulCtGridsZ; + } - /** @name Boundings */ - //@{ - /** Returns the bounding box of a given grid element. */ - inline Base::BoundBox3d GetBoundBox (unsigned long ulX, unsigned long ulY, unsigned long ulZ) const; - /** Returns the bounding box of the whole. */ - inline Base::BoundBox3d GetBoundBox () const; - //@} - /** Returns the number of elements in a given grid. */ - unsigned long GetCtElements(unsigned long ulX, unsigned long ulY, unsigned long ulZ) const - { return _aulGrid[ulX][ulY][ulZ].size(); } - /** Finds all points that lie in the same grid as the point \a rclPoint. */ - unsigned long FindElements(const Base::Vector3d &rclPoint, std::set& aulElements) const; - /** Validates the grid structure and rebuilds it if needed. */ - virtual void Validate (const PointKernel &rclM); - /** Validates the grid structure and rebuilds it if needed. */ - virtual void Validate (); - /** Verifies the grid structure and returns false if inconsistencies are found. */ - virtual bool Verify() const; - /** Returns the indices of the grid this point lies in. If the point is outside the grid then the indices of - * the nearest grid element are taken.*/ - virtual void Position (const Base::Vector3d &rclPoint, unsigned long &rulX, unsigned long &rulY, unsigned long &rulZ) const; - /** Returns the indices of the elements in the given grid. */ - unsigned long GetElements (unsigned long ulX, unsigned long ulY, unsigned long ulZ, std::set &raclInd) const; + /** @name Boundings */ + //@{ + /** Returns the bounding box of a given grid element. */ + inline Base::BoundBox3d + GetBoundBox(unsigned long ulX, unsigned long ulY, unsigned long ulZ) const; + /** Returns the bounding box of the whole. */ + inline Base::BoundBox3d GetBoundBox() const; + //@} + /** Returns the number of elements in a given grid. */ + unsigned long GetCtElements(unsigned long ulX, unsigned long ulY, unsigned long ulZ) const + { + return _aulGrid[ulX][ulY][ulZ].size(); + } + /** Finds all points that lie in the same grid as the point \a rclPoint. */ + unsigned long FindElements(const Base::Vector3d& rclPoint, + std::set& aulElements) const; + /** Validates the grid structure and rebuilds it if needed. */ + virtual void Validate(const PointKernel& rclM); + /** Validates the grid structure and rebuilds it if needed. */ + virtual void Validate(); + /** Verifies the grid structure and returns false if inconsistencies are found. */ + virtual bool Verify() const; + /** Returns the indices of the grid this point lies in. If the point is outside the grid then + * the indices of the nearest grid element are taken.*/ + virtual void Position(const Base::Vector3d& rclPoint, + unsigned long& rulX, + unsigned long& rulY, + unsigned long& rulZ) const; + /** Returns the indices of the elements in the given grid. */ + unsigned long GetElements(unsigned long ulX, + unsigned long ulY, + unsigned long ulZ, + std::set& raclInd) const; protected: - /** Checks if this is a valid grid position. */ - inline bool CheckPos (unsigned long ulX, unsigned long ulY, unsigned long ulZ) const; - /** Initializes the size of the internal structure. */ - virtual void InitGrid (); - /** Deletes the grid structure. */ - virtual void Clear (); - /** Calculates the grid length dependent on maximum number of grids. */ - virtual void CalculateGridLength (unsigned long ulCtGrid, unsigned long ulMaxGrids); - /** Calculates the grid length dependent on the number of grids per axis. */ - virtual void CalculateGridLength (int iCtGridPerAxis); - /** Rebuilds the grid structure. */ - virtual void RebuildGrid (); - /** Returns the number of stored elements. */ - unsigned long HasElements () const - { return _pclPoints->size(); } - /** Get the indices of all elements lying in the grids around a given grid with distance \a ulDistance. */ - void GetHull (unsigned long ulX, unsigned long ulY, unsigned long ulZ, unsigned long ulDistance, std::set &raclInd) const; + /** Checks if this is a valid grid position. */ + inline bool CheckPos(unsigned long ulX, unsigned long ulY, unsigned long ulZ) const; + /** Initializes the size of the internal structure. */ + virtual void InitGrid(); + /** Deletes the grid structure. */ + virtual void Clear(); + /** Calculates the grid length dependent on maximum number of grids. */ + virtual void CalculateGridLength(unsigned long ulCtGrid, unsigned long ulMaxGrids); + /** Calculates the grid length dependent on the number of grids per axis. */ + virtual void CalculateGridLength(int iCtGridPerAxis); + /** Rebuilds the grid structure. */ + virtual void RebuildGrid(); + /** Returns the number of stored elements. */ + unsigned long HasElements() const + { + return _pclPoints->size(); + } + /** Get the indices of all elements lying in the grids around a given grid with distance \a + * ulDistance. */ + void GetHull(unsigned long ulX, + unsigned long ulY, + unsigned long ulZ, + unsigned long ulDistance, + std::set& raclInd) const; protected: - std::vector > > > _aulGrid; /**< Grid data structure. */ - const PointKernel* _pclPoints; /**< The point kernel. */ - unsigned long _ulCtElements;/**< Number of grid elements for validation issues. */ - unsigned long _ulCtGridsX; /**< Number of grid elements in z. */ - unsigned long _ulCtGridsY; /**< Number of grid elements in z. */ - unsigned long _ulCtGridsZ; /**< Number of grid elements in z. */ - double _fGridLenX; /**< Length of grid elements in x. */ - double _fGridLenY; /**< Length of grid elements in y. */ - double _fGridLenZ; /**< Length of grid elements in z. */ - double _fMinX; /**< Grid null position in x. */ - double _fMinY; /**< Grid null position in y. */ - double _fMinZ; /**< Grid null position in z. */ + std::vector>>> + _aulGrid; /**< Grid data structure. */ + const PointKernel* _pclPoints; /**< The point kernel. */ + unsigned long _ulCtElements; /**< Number of grid elements for validation issues. */ + unsigned long _ulCtGridsX; /**< Number of grid elements in z. */ + unsigned long _ulCtGridsY; /**< Number of grid elements in z. */ + unsigned long _ulCtGridsZ; /**< Number of grid elements in z. */ + double _fGridLenX; /**< Length of grid elements in x. */ + double _fGridLenY; /**< Length of grid elements in y. */ + double _fGridLenZ; /**< Length of grid elements in z. */ + double _fMinX; /**< Grid null position in x. */ + double _fMinY; /**< Grid null position in y. */ + double _fMinZ; /**< Grid null position in z. */ - // friends - friend class PointsGridIterator; - friend class PointsGridIteratorStatistic; + // friends + friend class PointsGridIterator; + friend class PointsGridIteratorStatistic; public: - protected: - /** Adds a new point element to the grid structure. \a rclPt is the geometric point and \a ulPtIndex - * the corresponding index in the point kernel. */ - void AddPoint (const Base::Vector3d &rclPt, unsigned long ulPtIndex, float fEpsilon = 0.0f); - /** Returns the grid numbers to the given point \a rclPoint. */ - void Pos(const Base::Vector3d &rclPoint, unsigned long &rulX, unsigned long &rulY, unsigned long &rulZ) const; + /** Adds a new point element to the grid structure. \a rclPt is the geometric point and \a + * ulPtIndex the corresponding index in the point kernel. */ + void AddPoint(const Base::Vector3d& rclPt, unsigned long ulPtIndex, float fEpsilon = 0.0f); + /** Returns the grid numbers to the given point \a rclPoint. */ + void Pos(const Base::Vector3d& rclPoint, + unsigned long& rulX, + unsigned long& rulY, + unsigned long& rulZ) const; }; /** @@ -174,99 +212,144 @@ protected: class PointsExport PointsGridIterator { public: - /// Construction - explicit PointsGridIterator (const PointsGrid &rclG); - /** Returns the bounding box of the current grid element. */ - Base::BoundBox3d GetBoundBox () const - { return _rclGrid.GetBoundBox(_ulX, _ulY, _ulZ); } - /** Returns indices of the elements in the current grid. */ - void GetElements (std::vector &raulElements) const - { - raulElements.insert(raulElements.end(), _rclGrid._aulGrid[_ulX][_ulY][_ulZ].begin(), _rclGrid._aulGrid[_ulX][_ulY][_ulZ].end()); - } - /** @name Iteration */ - //@{ - /** Sets the iterator to the first element*/ - void Init () - { _ulX = _ulY = _ulZ = 0; } - /** Checks if the iterator has not yet reached the end position. */ - bool More () const - { return (_ulZ < _rclGrid._ulCtGridsZ); } - /** Go to the next grid. */ - void Next () - { - if (++_ulX >= (_rclGrid._ulCtGridsX)) _ulX = 0; else return; - if (++_ulY >= (_rclGrid._ulCtGridsY)) { _ulY = 0; _ulZ++; } else return; - } - //@} + /// Construction + explicit PointsGridIterator(const PointsGrid& rclG); + /** Returns the bounding box of the current grid element. */ + Base::BoundBox3d GetBoundBox() const + { + return _rclGrid.GetBoundBox(_ulX, _ulY, _ulZ); + } + /** Returns indices of the elements in the current grid. */ + void GetElements(std::vector& raulElements) const + { + raulElements.insert(raulElements.end(), + _rclGrid._aulGrid[_ulX][_ulY][_ulZ].begin(), + _rclGrid._aulGrid[_ulX][_ulY][_ulZ].end()); + } + /** @name Iteration */ + //@{ + /** Sets the iterator to the first element*/ + void Init() + { + _ulX = _ulY = _ulZ = 0; + } + /** Checks if the iterator has not yet reached the end position. */ + bool More() const + { + return (_ulZ < _rclGrid._ulCtGridsZ); + } + /** Go to the next grid. */ + void Next() + { + if (++_ulX >= (_rclGrid._ulCtGridsX)) { + _ulX = 0; + } + else { + return; + } + if (++_ulY >= (_rclGrid._ulCtGridsY)) { + _ulY = 0; + _ulZ++; + } + else { + return; + } + } + //@} - /** @name Tests with rays */ - //@{ - /** Searches for facets around the ray. */ - bool InitOnRay (const Base::Vector3d &rclPt, const Base::Vector3d &rclDir, std::vector &raulElements); - /** Searches for facets around the ray. */ - bool InitOnRay (const Base::Vector3d &rclPt, const Base::Vector3d &rclDir, float fMaxSearchArea, std::vector &raulElements); - /** Searches for facets around the ray. */ - bool NextOnRay (std::vector &raulElements); - //@} + /** @name Tests with rays */ + //@{ + /** Searches for facets around the ray. */ + bool InitOnRay(const Base::Vector3d& rclPt, + const Base::Vector3d& rclDir, + std::vector& raulElements); + /** Searches for facets around the ray. */ + bool InitOnRay(const Base::Vector3d& rclPt, + const Base::Vector3d& rclDir, + float fMaxSearchArea, + std::vector& raulElements); + /** Searches for facets around the ray. */ + bool NextOnRay(std::vector& raulElements); + //@} - /** Returns the grid number of the current position. */ - void GetGridPos (unsigned long &rulX, unsigned long &rulY, unsigned long &rulZ) const - { rulX = _ulX; rulY = _ulY; rulZ = _ulZ; } + /** Returns the grid number of the current position. */ + void GetGridPos(unsigned long& rulX, unsigned long& rulY, unsigned long& rulZ) const + { + rulX = _ulX; + rulY = _ulY; + rulZ = _ulZ; + } protected: - const PointsGrid& _rclGrid; /**< The point grid. */ - unsigned long _ulX{0}; /**< Number of grids in x. */ - unsigned long _ulY{0}; /**< Number of grids in y. */ - unsigned long _ulZ{0}; /**< Number of grids in z. */ - Base::Vector3d _clPt; /**< Base point of search ray. */ - Base::Vector3d _clDir; /**< Direction of search ray. */ - bool _bValidRay{false}; /**< Search ray ok? */ - float _fMaxSearchArea{FLOAT_MAX}; - /** Checks if a grid position is already visited by NextOnRay(). */ - struct GridElement - { - GridElement( unsigned long x, unsigned long y, unsigned long z) - { this->x = x; this->y = y; this->z = z; } - bool operator < (const GridElement& pos) const + const PointsGrid& _rclGrid; /**< The point grid. */ + unsigned long _ulX {0}; /**< Number of grids in x. */ + unsigned long _ulY {0}; /**< Number of grids in y. */ + unsigned long _ulZ {0}; /**< Number of grids in z. */ + Base::Vector3d _clPt; /**< Base point of search ray. */ + Base::Vector3d _clDir; /**< Direction of search ray. */ + bool _bValidRay {false}; /**< Search ray ok? */ + float _fMaxSearchArea {FLOAT_MAX}; + /** Checks if a grid position is already visited by NextOnRay(). */ + struct GridElement { - if ( x == pos.x) - { if ( y == pos.y) return z < pos.z; else return y < pos.y; } - else - { return x < pos.x; } - } - private: - unsigned long x,y,z; - }; - std::set _cSearchPositions; + GridElement(unsigned long x, unsigned long y, unsigned long z) + { + this->x = x; + this->y = y; + this->z = z; + } + bool operator<(const GridElement& pos) const + { + if (x == pos.x) { + if (y == pos.y) { + return z < pos.z; + } + else { + return y < pos.y; + } + } + else { + return x < pos.x; + } + } + + private: + unsigned long x, y, z; + }; + std::set _cSearchPositions; }; // -------------------------------------------------------------- -inline Base::BoundBox3d PointsGrid::GetBoundBox (unsigned long ulX, unsigned long ulY, unsigned long ulZ) const +inline Base::BoundBox3d +PointsGrid::GetBoundBox(unsigned long ulX, unsigned long ulY, unsigned long ulZ) const { - double fX, fY, fZ; + double fX, fY, fZ; - fX = _fMinX + (double(ulX) * _fGridLenX); - fY = _fMinY + (double(ulY) * _fGridLenY); - fZ = _fMinZ + (double(ulZ) * _fGridLenZ); + fX = _fMinX + (double(ulX) * _fGridLenX); + fY = _fMinY + (double(ulY) * _fGridLenY); + fZ = _fMinZ + (double(ulZ) * _fGridLenZ); - return Base::BoundBox3d(fX, fY, fZ, fX + _fGridLenX, fY + _fGridLenY, fZ + _fGridLenZ); + return Base::BoundBox3d(fX, fY, fZ, fX + _fGridLenX, fY + _fGridLenY, fZ + _fGridLenZ); } -inline Base::BoundBox3d PointsGrid::GetBoundBox () const +inline Base::BoundBox3d PointsGrid::GetBoundBox() const { - return Base::BoundBox3d(_fMinX, _fMinY, _fMinZ, _fMinX + (_fGridLenX * double(_ulCtGridsX)), - _fMinY + (_fGridLenY * double(_ulCtGridsY)), _fMinZ + (_fGridLenZ * double(_ulCtGridsZ))); + return Base::BoundBox3d(_fMinX, + _fMinY, + _fMinZ, + _fMinX + (_fGridLenX * double(_ulCtGridsX)), + _fMinY + (_fGridLenY * double(_ulCtGridsY)), + _fMinZ + (_fGridLenZ * double(_ulCtGridsZ))); } -inline bool PointsGrid::CheckPos (unsigned long ulX, unsigned long ulY, unsigned long ulZ) const +inline bool PointsGrid::CheckPos(unsigned long ulX, unsigned long ulY, unsigned long ulZ) const { - return ((ulX < _ulCtGridsX) && (ulY < _ulCtGridsY) && (ulZ < _ulCtGridsZ)); + return ((ulX < _ulCtGridsX) && (ulY < _ulCtGridsY) && (ulZ < _ulCtGridsZ)); } // -------------------------------------------------------------- -} // namespace Points +}// namespace Points -#endif // POINTS_GRID_H +#endif// POINTS_GRID_H diff --git a/src/Mod/Points/App/PointsPyImp.cpp b/src/Mod/Points/App/PointsPyImp.cpp index 454ea0267f..16fb08bd0a 100644 --- a/src/Mod/Points/App/PointsPyImp.cpp +++ b/src/Mod/Points/App/PointsPyImp.cpp @@ -22,7 +22,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include @@ -32,8 +32,10 @@ #include "Points.h" // inclusion of the generated files (generated out of PointsPy.xml) +// clang-format off #include "PointsPy.h" #include "PointsPy.cpp" +// clang-format on using namespace Points; @@ -44,7 +46,7 @@ std::string PointsPy::representation() const return {""}; } -PyObject *PointsPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +PyObject* PointsPy::PyMake(struct _typeobject*, PyObject*, PyObject*) { // create a new instance of PointsPy and the Twin object return new PointsPy(new PointKernel); @@ -53,23 +55,27 @@ PyObject *PointsPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Pyt // constructor method int PointsPy::PyInit(PyObject* args, PyObject* /*kwd*/) { - PyObject *pcObj=nullptr; - if (!PyArg_ParseTuple(args, "|O", &pcObj)) + PyObject* pcObj = nullptr; + if (!PyArg_ParseTuple(args, "|O", &pcObj)) { return -1; + } // if no mesh is given - if (!pcObj) + if (!pcObj) { return 0; + } if (PyObject_TypeCheck(pcObj, &(PointsPy::Type))) { *getPointKernelPtr() = *(static_cast(pcObj)->getPointKernelPtr()); } else if (PyList_Check(pcObj)) { - if (!addPoints(args)) + if (!addPoints(args)) { return -1; + } } else if (PyTuple_Check(pcObj)) { - if (!addPoints(args)) + if (!addPoints(args)) { return -1; + } } else if (PyUnicode_Check(pcObj)) { getPointKernelPtr()->load(PyUnicode_AsUTF8(pcObj)); @@ -82,10 +88,11 @@ int PointsPy::PyInit(PyObject* args, PyObject* /*kwd*/) return 0; } -PyObject* PointsPy::copy(PyObject *args) +PyObject* PointsPy::copy(PyObject* args) { - if (!PyArg_ParseTuple(args, "")) + if (!PyArg_ParseTuple(args, "")) { return nullptr; + } PointKernel* kernel = new PointKernel(); // assign data @@ -93,36 +100,43 @@ PyObject* PointsPy::copy(PyObject *args) return new PointsPy(kernel); } -PyObject* PointsPy::read(PyObject * args) +PyObject* PointsPy::read(PyObject* args) { const char* Name; - if (!PyArg_ParseTuple(args, "s",&Name)) + if (!PyArg_ParseTuple(args, "s", &Name)) { return nullptr; + } - PY_TRY { + PY_TRY + { getPointKernelPtr()->load(Name); - } PY_CATCH; + } + PY_CATCH; Py_Return; } -PyObject* PointsPy::write(PyObject * args) +PyObject* PointsPy::write(PyObject* args) { const char* Name; - if (!PyArg_ParseTuple(args, "s",&Name)) + if (!PyArg_ParseTuple(args, "s", &Name)) { return nullptr; + } - PY_TRY { + PY_TRY + { getPointKernelPtr()->save(Name); - } PY_CATCH; + } + PY_CATCH; Py_Return; } -PyObject* PointsPy::writeInventor(PyObject * args) +PyObject* PointsPy::writeInventor(PyObject* args) { - if (!PyArg_ParseTuple(args, "")) + if (!PyArg_ParseTuple(args, "")) { return nullptr; + } std::stringstream result; Base::InventorBuilder builder(result); @@ -130,21 +144,22 @@ PyObject* PointsPy::writeInventor(PyObject * args) std::vector points; PointKernel* kernel = getPointKernelPtr(); points.reserve(kernel->size()); - for (const auto & it : *kernel) { + for (const auto& it : *kernel) { points.push_back(Base::convertTo(it)); } - builder.addNode(Base::Coordinate3Item{points}); - builder.addNode(Base::PointSetItem{}); + builder.addNode(Base::Coordinate3Item {points}); + builder.addNode(Base::PointSetItem {}); builder.endSeparator(); return Py::new_reference_to(Py::String(result.str())); } -PyObject* PointsPy::addPoints(PyObject * args) +PyObject* PointsPy::addPoints(PyObject* args) { - PyObject *obj; - if (!PyArg_ParseTuple(args, "O", &obj)) + PyObject* obj; + if (!PyArg_ParseTuple(args, "O", &obj)) { return nullptr; + } try { Py::Sequence list(obj); @@ -166,20 +181,22 @@ PyObject* PointsPy::addPoints(PyObject * args) } } catch (const Py::Exception&) { - PyErr_SetString(PyExc_TypeError, "either expect\n" - "-- [Vector,...] \n" - "-- [(x,y,z),...]"); + PyErr_SetString(PyExc_TypeError, + "either expect\n" + "-- [Vector,...] \n" + "-- [(x,y,z),...]"); return nullptr; } Py_Return; } -PyObject* PointsPy::fromSegment(PyObject * args) +PyObject* PointsPy::fromSegment(PyObject* args) { - PyObject *obj; - if (!PyArg_ParseTuple(args, "O", &obj)) + PyObject* obj; + if (!PyArg_ParseTuple(args, "O", &obj)) { return nullptr; + } try { const PointKernel* points = getPointKernelPtr(); @@ -189,8 +206,9 @@ PyObject* PointsPy::fromSegment(PyObject * args) int numPoints = static_cast(points->size()); for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { long index = static_cast(Py::Long(*it)); - if (index >= 0 && index < numPoints) + if (index >= 0 && index < numPoints) { pts->push_back(points->getPoint(index)); + } } return new PointsPy(pts.release()); @@ -201,18 +219,21 @@ PyObject* PointsPy::fromSegment(PyObject * args) } } -PyObject* PointsPy::fromValid(PyObject * args) +PyObject* PointsPy::fromValid(PyObject* args) { - if (!PyArg_ParseTuple(args, "")) + if (!PyArg_ParseTuple(args, "")) { return nullptr; + } try { const PointKernel* points = getPointKernelPtr(); std::unique_ptr pts(new PointKernel()); pts->reserve(points->size()); - for (const auto & point : *points) { - if (!boost::math::isnan(point.x) && !boost::math::isnan(point.y) && !boost::math::isnan(point.z)) + for (const auto& point : *points) { + if (!boost::math::isnan(point.x) && !boost::math::isnan(point.y) + && !boost::math::isnan(point.z)) { pts->push_back(point); + } } return new PointsPy(pts.release()); @@ -232,13 +253,13 @@ Py::List PointsPy::getPoints() const { Py::List PointList; const PointKernel* points = getPointKernelPtr(); - for (const auto & point : *points) { + for (const auto& point : *points) { PointList.append(Py::asObject(new Base::VectorPy(point))); } return PointList; } -PyObject *PointsPy::getCustomAttributes(const char* /*attr*/) const +PyObject* PointsPy::getCustomAttributes(const char* /*attr*/) const { return nullptr; } @@ -247,5 +268,3 @@ int PointsPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) { return 0; } - - diff --git a/src/Mod/Points/App/PreCompiled.h b/src/Mod/Points/App/PreCompiled.h index 9e42e5ad7a..0e7e89812f 100644 --- a/src/Mod/Points/App/PreCompiled.h +++ b/src/Mod/Points/App/PreCompiled.h @@ -27,35 +27,34 @@ // point at which warnings of overly long specifiers disabled (needed for VC6) #ifdef _MSC_VER -# pragma warning( disable : 4181 ) -# pragma warning( disable : 4305 ) -# pragma warning( disable : 4522 ) +#pragma warning(disable : 4181) +#pragma warning(disable : 4305) +#pragma warning(disable : 4522) #endif #ifdef _PreComp_ // standard -# include +#include // STL -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include // boost -# include -# include -# include -# include +#include +#include +#include +#include // Qt -# include +#include -#endif //_PreComp_ +#endif//_PreComp_ #endif - diff --git a/src/Mod/Points/App/Properties.cpp b/src/Mod/Points/App/Properties.cpp index 93408b7363..81d262e397 100644 --- a/src/Mod/Points/App/Properties.cpp +++ b/src/Mod/Points/App/Properties.cpp @@ -22,10 +22,10 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include +#include +#include +#include +#include #endif #include @@ -35,11 +35,11 @@ #include #include -#include "Properties.h" #include "Points.h" +#include "Properties.h" #ifdef _MSC_VER -# include +#include #endif @@ -49,7 +49,7 @@ using namespace std; TYPESYSTEM_SOURCE(Points::PropertyGreyValue, App::PropertyFloat) TYPESYSTEM_SOURCE(Points::PropertyGreyValueList, App::PropertyLists) TYPESYSTEM_SOURCE(Points::PropertyNormalList, App::PropertyLists) -TYPESYSTEM_SOURCE(Points::PropertyCurvatureList , App::PropertyLists) +TYPESYSTEM_SOURCE(Points::PropertyCurvatureList, App::PropertyLists) PropertyGreyValueList::PropertyGreyValueList() = default; @@ -67,7 +67,7 @@ void PropertyGreyValueList::setValue(float lValue) { aboutToSetValue(); _lValueList.resize(1); - _lValueList[0]=lValue; + _lValueList[0] = lValue; hasSetValue(); } @@ -78,29 +78,30 @@ void PropertyGreyValueList::setValues(const std::vector& values) hasSetValue(); } -PyObject *PropertyGreyValueList::getPyObject() +PyObject* PropertyGreyValueList::getPyObject() { PyObject* list = PyList_New(getSize()); - for (int i = 0;i values; values.resize(nSize); - for (Py_ssize_t i=0; iob_type->tp_name; throw Py::TypeError(error); } - + values[i] = (float)PyFloat_AsDouble(item); } @@ -108,7 +109,7 @@ void PropertyGreyValueList::setPyObject(PyObject *value) } else if (PyFloat_Check(value)) { setValue((float)PyFloat_AsDouble(value)); - } + } else { std::string error = std::string("type must be float or list of float, not "); error += value->ob_type->tp_name; @@ -116,34 +117,35 @@ void PropertyGreyValueList::setPyObject(PyObject *value) } } -void PropertyGreyValueList::Save (Base::Writer &writer) const +void PropertyGreyValueList::Save(Base::Writer& writer) const { if (writer.isForceXML()) { - writer.Stream() << writer.ind() << "" << endl; + writer.Stream() << writer.ind() << "" << endl; writer.incInd(); - for(int i = 0;i" << endl; ; + for (int i = 0; i < getSize(); i++) { + writer.Stream() << writer.ind() << "" << endl; + }; writer.decInd(); - writer.Stream() << writer.ind() <<"" << endl ; + writer.Stream() << writer.ind() << "" << endl; } else { - writer.Stream() << writer.ind() << "" << std::endl; + writer.Stream() << writer.ind() << "" << std::endl; } } -void PropertyGreyValueList::Restore(Base::XMLReader &reader) +void PropertyGreyValueList::Restore(Base::XMLReader& reader) { reader.readElement("FloatList"); - string file (reader.getAttribute("file") ); + string file(reader.getAttribute("file")); if (!file.empty()) { // initiate a file read - reader.addFile(file.c_str(),this); + reader.addFile(file.c_str(), this); } } -void PropertyGreyValueList::SaveDocFile (Base::Writer &writer) const +void PropertyGreyValueList::SaveDocFile(Base::Writer& writer) const { Base::OutputStream str(writer.Stream()); uint32_t uCt = (uint32_t)getSize(); @@ -153,38 +155,38 @@ void PropertyGreyValueList::SaveDocFile (Base::Writer &writer) const } } -void PropertyGreyValueList::RestoreDocFile(Base::Reader &reader) +void PropertyGreyValueList::RestoreDocFile(Base::Reader& reader) { Base::InputStream str(reader); - uint32_t uCt=0; + uint32_t uCt = 0; str >> uCt; std::vector values(uCt); - for (float & value : values) { + for (float& value : values) { str >> value; } setValues(values); } -App::Property *PropertyGreyValueList::Copy() const +App::Property* PropertyGreyValueList::Copy() const { - PropertyGreyValueList *p= new PropertyGreyValueList(); + PropertyGreyValueList* p = new PropertyGreyValueList(); p->_lValueList = _lValueList; return p; } -void PropertyGreyValueList::Paste(const App::Property &from) +void PropertyGreyValueList::Paste(const App::Property& from) { aboutToSetValue(); _lValueList = dynamic_cast(from)._lValueList; hasSetValue(); } -unsigned int PropertyGreyValueList::getMemSize () const +unsigned int PropertyGreyValueList::getMemSize() const { return static_cast(_lValueList.size() * sizeof(float)); } -void PropertyGreyValueList::removeIndices( const std::vector& uIndices ) +void PropertyGreyValueList::removeIndices(const std::vector& uIndices) { // We need a sorted array std::vector uSortedInds = uIndices; @@ -192,22 +194,26 @@ void PropertyGreyValueList::removeIndices( const std::vector& uIn const std::vector& rValueList = getValues(); - assert( uSortedInds.size() <= rValueList.size() ); - if ( uSortedInds.size() > rValueList.size() ) + assert(uSortedInds.size() <= rValueList.size()); + if (uSortedInds.size() > rValueList.size()) { return; + } std::vector remainValue; remainValue.reserve(rValueList.size() - uSortedInds.size()); std::vector::iterator pos = uSortedInds.begin(); - for ( std::vector::const_iterator it = rValueList.begin(); it != rValueList.end(); ++it ) { + for (std::vector::const_iterator it = rValueList.begin(); it != rValueList.end(); ++it) { unsigned long index = it - rValueList.begin(); - if (pos == uSortedInds.end()) - remainValue.push_back( *it ); - else if (index != *pos) - remainValue.push_back( *it ); - else + if (pos == uSortedInds.end()) { + remainValue.push_back(*it); + } + else if (index != *pos) { + remainValue.push_back(*it); + } + else { ++pos; + } } setValues(remainValue); @@ -229,7 +235,7 @@ void PropertyNormalList::setValue(const Base::Vector3f& lValue) { aboutToSetValue(); _lValueList.resize(1); - _lValueList[0]=lValue; + _lValueList[0] = lValue; hasSetValue(); } @@ -237,7 +243,7 @@ void PropertyNormalList::setValue(float x, float y, float z) { aboutToSetValue(); _lValueList.resize(1); - _lValueList[0].Set(x,y,z); + _lValueList[0].Set(x, y, z); hasSetValue(); } @@ -248,40 +254,41 @@ void PropertyNormalList::setValues(const std::vector& values) hasSetValue(); } -PyObject *PropertyNormalList::getPyObject() +PyObject* PropertyNormalList::getPyObject() { PyObject* list = PyList_New(getSize()); - for (int i = 0;i values; values.resize(nSize); - for (Py_ssize_t i=0; i(val.getValue()); } setValues(values); } else if (PyObject_TypeCheck(value, &(Base::VectorPy::Type))) { - Base::VectorPy *pcObject = static_cast(value); + Base::VectorPy* pcObject = static_cast(value); Base::Vector3d* val = pcObject->getVectorPtr(); setValue(Base::convertTo(*val)); } else if (PyTuple_Check(value) && PyTuple_Size(value) == 3) { App::PropertyVector val; - val.setPyObject( value ); + val.setPyObject(value); setValue(Base::convertTo(val.getValue())); } else { @@ -291,25 +298,26 @@ void PropertyNormalList::setPyObject(PyObject *value) } } -void PropertyNormalList::Save (Base::Writer &writer) const +void PropertyNormalList::Save(Base::Writer& writer) const { if (!writer.isForceXML()) { - writer.Stream() << writer.ind() << "" << std::endl; + writer.Stream() << writer.ind() << "" << std::endl; } } -void PropertyNormalList::Restore(Base::XMLReader &reader) +void PropertyNormalList::Restore(Base::XMLReader& reader) { reader.readElement("VectorList"); - std::string file (reader.getAttribute("file") ); + std::string file(reader.getAttribute("file")); if (!file.empty()) { // initiate a file read - reader.addFile(file.c_str(),this); + reader.addFile(file.c_str(), this); } } -void PropertyNormalList::SaveDocFile (Base::Writer &writer) const +void PropertyNormalList::SaveDocFile(Base::Writer& writer) const { Base::OutputStream str(writer.Stream()); uint32_t uCt = (uint32_t)getSize(); @@ -319,38 +327,38 @@ void PropertyNormalList::SaveDocFile (Base::Writer &writer) const } } -void PropertyNormalList::RestoreDocFile(Base::Reader &reader) +void PropertyNormalList::RestoreDocFile(Base::Reader& reader) { Base::InputStream str(reader); - uint32_t uCt=0; + uint32_t uCt = 0; str >> uCt; std::vector values(uCt); - for (auto & value : values) { + for (auto& value : values) { str >> value.x >> value.y >> value.z; } setValues(values); } -App::Property *PropertyNormalList::Copy() const +App::Property* PropertyNormalList::Copy() const { - PropertyNormalList *p= new PropertyNormalList(); + PropertyNormalList* p = new PropertyNormalList(); p->_lValueList = _lValueList; return p; } -void PropertyNormalList::Paste(const App::Property &from) +void PropertyNormalList::Paste(const App::Property& from) { aboutToSetValue(); _lValueList = dynamic_cast(from)._lValueList; hasSetValue(); } -unsigned int PropertyNormalList::getMemSize () const +unsigned int PropertyNormalList::getMemSize() const { return static_cast(_lValueList.size() * sizeof(Base::Vector3f)); } -void PropertyNormalList::transformGeometry(const Base::Matrix4D &mat) +void PropertyNormalList::transformGeometry(const Base::Matrix4D& mat) { // A normal vector is only a direction with unit length, so we only need to rotate it // (no translations or scaling) @@ -376,9 +384,11 @@ void PropertyNormalList::transformGeometry(const Base::Matrix4D &mat) // Rotate the normal vectors #ifdef _MSC_VER - Concurrency::parallel_for_each(_lValueList.begin(), _lValueList.end(), [rot](Base::Vector3f& value) { - value = rot * value; - }); + Concurrency::parallel_for_each(_lValueList.begin(), + _lValueList.end(), + [rot](Base::Vector3f& value) { + value = rot * value; + }); #else QtConcurrent::blockingMap(_lValueList, [rot](Base::Vector3f& value) { rot.multVec(value, value); @@ -388,7 +398,7 @@ void PropertyNormalList::transformGeometry(const Base::Matrix4D &mat) hasSetValue(); } -void PropertyNormalList::removeIndices( const std::vector& uIndices ) +void PropertyNormalList::removeIndices(const std::vector& uIndices) { // We need a sorted array std::vector uSortedInds = uIndices; @@ -396,22 +406,28 @@ void PropertyNormalList::removeIndices( const std::vector& uIndic const std::vector& rValueList = getValues(); - assert( uSortedInds.size() <= rValueList.size() ); - if ( uSortedInds.size() > rValueList.size() ) + assert(uSortedInds.size() <= rValueList.size()); + if (uSortedInds.size() > rValueList.size()) { return; + } std::vector remainValue; remainValue.reserve(rValueList.size() - uSortedInds.size()); std::vector::iterator pos = uSortedInds.begin(); - for ( std::vector::const_iterator it = rValueList.begin(); it != rValueList.end(); ++it ) { + for (std::vector::const_iterator it = rValueList.begin(); + it != rValueList.end(); + ++it) { unsigned long index = it - rValueList.begin(); - if (pos == uSortedInds.end()) - remainValue.push_back( *it ); - else if (index != *pos) - remainValue.push_back( *it ); - else + if (pos == uSortedInds.end()) { + remainValue.push_back(*it); + } + else if (index != *pos) { + remainValue.push_back(*it); + } + else { ++pos; + } } setValues(remainValue); @@ -423,18 +439,18 @@ void PropertyCurvatureList::setValue(const CurvatureInfo& lValue) { aboutToSetValue(); _lValueList.resize(1); - _lValueList[0]=lValue; + _lValueList[0] = lValue; hasSetValue(); } void PropertyCurvatureList::setValues(const std::vector& lValues) { aboutToSetValue(); - _lValueList=lValues; + _lValueList = lValues; hasSetValue(); } -std::vector PropertyCurvatureList::getCurvature( int mode ) const +std::vector PropertyCurvatureList::getCurvature(int mode) const { const std::vector& fCurvInfo = getValues(); std::vector fValues; @@ -442,42 +458,44 @@ std::vector PropertyCurvatureList::getCurvature( int mode ) const // Mean curvature if (mode == MeanCurvature) { - for (const auto & it : fCurvInfo) { - fValues.push_back( 0.5f*(it.fMaxCurvature+it.fMinCurvature) ); + for (const auto& it : fCurvInfo) { + fValues.push_back(0.5f * (it.fMaxCurvature + it.fMinCurvature)); } } // Gaussian curvature else if (mode == GaussCurvature) { - for (const auto & it : fCurvInfo) { - fValues.push_back( it.fMaxCurvature * it.fMinCurvature ); + for (const auto& it : fCurvInfo) { + fValues.push_back(it.fMaxCurvature * it.fMinCurvature); } } // Maximum curvature else if (mode == MaxCurvature) { - for (const auto & it : fCurvInfo) { - fValues.push_back( it.fMaxCurvature ); + for (const auto& it : fCurvInfo) { + fValues.push_back(it.fMaxCurvature); } } // Minimum curvature else if (mode == MinCurvature) { - for (const auto & it : fCurvInfo) { - fValues.push_back( it.fMinCurvature ); + for (const auto& it : fCurvInfo) { + fValues.push_back(it.fMinCurvature); } } // Absolute curvature else if (mode == AbsCurvature) { - for (const auto & it : fCurvInfo) { - if (fabs(it.fMaxCurvature) > fabs(it.fMinCurvature)) - fValues.push_back( it.fMaxCurvature ); - else - fValues.push_back( it.fMinCurvature ); + for (const auto& it : fCurvInfo) { + if (fabs(it.fMaxCurvature) > fabs(it.fMinCurvature)) { + fValues.push_back(it.fMaxCurvature); + } + else { + fValues.push_back(it.fMinCurvature); + } } } return fValues; } -void PropertyCurvatureList::transformGeometry(const Base::Matrix4D &mat) +void PropertyCurvatureList::transformGeometry(const Base::Matrix4D& mat) { // The principal direction is only a vector with unit length, so we only need to rotate it // (no translations or scaling) @@ -502,7 +520,7 @@ void PropertyCurvatureList::transformGeometry(const Base::Matrix4D &mat) aboutToSetValue(); // Rotate the principal directions - for (int ii=0; ii& uIndices ) +void PropertyCurvatureList::removeIndices(const std::vector& uIndices) { // We need a sorted array std::vector uSortedInds = uIndices; std::sort(uSortedInds.begin(), uSortedInds.end()); - assert( uSortedInds.size() <= _lValueList.size() ); - if ( uSortedInds.size() > _lValueList.size() ) + assert(uSortedInds.size() <= _lValueList.size()); + if (uSortedInds.size() > _lValueList.size()) { return; + } std::vector remainValue; remainValue.reserve(_lValueList.size() - uSortedInds.size()); std::vector::iterator pos = uSortedInds.begin(); - for ( std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it ) { + for (std::vector::const_iterator it = _lValueList.begin(); + it != _lValueList.end(); + ++it) { unsigned long index = it - _lValueList.begin(); - if (pos == uSortedInds.end()) - remainValue.push_back( *it ); - else if (index != *pos) - remainValue.push_back( *it ); - else + if (pos == uSortedInds.end()) { + remainValue.push_back(*it); + } + else if (index != *pos) { + remainValue.push_back(*it); + } + else { ++pos; + } } setValues(remainValue); } -PyObject *PropertyCurvatureList::getPyObject() +PyObject* PropertyCurvatureList::getPyObject() { throw Py::NotImplementedError("Not yet implemented"); } -void PropertyCurvatureList::setPyObject(PyObject *) +void PropertyCurvatureList::setPyObject(PyObject*) { throw Py::NotImplementedError("Not yet implemented"); } -void PropertyCurvatureList::Save (Base::Writer &writer) const +void PropertyCurvatureList::Save(Base::Writer& writer) const { if (!writer.isForceXML()) { - writer.Stream() << writer.ind() << "" << std::endl; + writer.Stream() << writer.ind() << "" << std::endl; } } -void PropertyCurvatureList::Restore(Base::XMLReader &reader) +void PropertyCurvatureList::Restore(Base::XMLReader& reader) { reader.readElement("CurvatureList"); - std::string file (reader.getAttribute("file") ); + std::string file(reader.getAttribute("file")); if (!file.empty()) { // initiate a file read - reader.addFile(file.c_str(),this); + reader.addFile(file.c_str(), this); } } -void PropertyCurvatureList::SaveDocFile (Base::Writer &writer) const +void PropertyCurvatureList::SaveDocFile(Base::Writer& writer) const { Base::OutputStream str(writer.Stream()); uint32_t uCt = (uint32_t)getSize(); str << uCt; - if (uCt > 0) - for (const auto & it : _lValueList) { - str << it.fMaxCurvature << it.fMinCurvature; - str << it.cMaxCurvDir.x << it.cMaxCurvDir.y << it.cMaxCurvDir.z; - str << it.cMinCurvDir.x << it.cMinCurvDir.y << it.cMinCurvDir.z; + if (uCt > 0) { + for (const auto& it : _lValueList) { + str << it.fMaxCurvature << it.fMinCurvature; + str << it.cMaxCurvDir.x << it.cMaxCurvDir.y << it.cMaxCurvDir.z; + str << it.cMinCurvDir.x << it.cMinCurvDir.y << it.cMinCurvDir.z; + } } } -void PropertyCurvatureList::RestoreDocFile(Base::Reader &reader) +void PropertyCurvatureList::RestoreDocFile(Base::Reader& reader) { Base::InputStream str(reader); - uint32_t uCt=0; + uint32_t uCt = 0; str >> uCt; std::vector values(uCt); - for (auto & value : values) { + for (auto& value : values) { str >> value.fMaxCurvature >> value.fMinCurvature; str >> value.cMaxCurvDir.x >> value.cMaxCurvDir.y >> value.cMaxCurvDir.z; str >> value.cMinCurvDir.x >> value.cMinCurvDir.y >> value.cMinCurvDir.z; @@ -595,14 +621,14 @@ void PropertyCurvatureList::RestoreDocFile(Base::Reader &reader) setValues(values); } -App::Property *PropertyCurvatureList::Copy() const +App::Property* PropertyCurvatureList::Copy() const { PropertyCurvatureList* prop = new PropertyCurvatureList(); prop->_lValueList = this->_lValueList; return prop; } -void PropertyCurvatureList::Paste(const App::Property &from) +void PropertyCurvatureList::Paste(const App::Property& from) { aboutToSetValue(); const PropertyCurvatureList& prop = dynamic_cast(from); @@ -610,7 +636,7 @@ void PropertyCurvatureList::Paste(const App::Property &from) hasSetValue(); } -unsigned int PropertyCurvatureList::getMemSize () const +unsigned int PropertyCurvatureList::getMemSize() const { return sizeof(CurvatureInfo) * this->_lValueList.size(); } diff --git a/src/Mod/Points/App/Properties.h b/src/Mod/Points/App/Properties.h index be9cc54112..ecf355c4ae 100644 --- a/src/Mod/Points/App/Properties.h +++ b/src/Mod/Points/App/Properties.h @@ -38,7 +38,7 @@ namespace Points /** Greyvalue property. */ -class PointsExport PropertyGreyValue : public App::PropertyFloat +class PointsExport PropertyGreyValue: public App::PropertyFloat { TYPESYSTEM_HEADER_WITH_OVERRIDE(); @@ -52,44 +52,47 @@ class PointsExport PropertyGreyValueList: public App::PropertyLists public: PropertyGreyValueList(); - + void setSize(int newSize) override; int getSize() const override; - /** Sets the property + /** Sets the property */ void setValue(float); - + /// index operator - float operator[] (const int idx) const { + float operator[](const int idx) const + { return _lValueList[idx]; } - void set1Value (const int idx, float value) { + void set1Value(const int idx, float value) + { _lValueList[idx] = value; } - void setValues (const std::vector& values); - - const std::vector &getValues() const { + void setValues(const std::vector& values); + + const std::vector& getValues() const + { return _lValueList; } - PyObject *getPyObject() override; - void setPyObject(PyObject *) override; - - void Save (Base::Writer &writer) const override; - void Restore(Base::XMLReader &reader) override; - - void SaveDocFile (Base::Writer &writer) const override; - void RestoreDocFile(Base::Reader &reader) override; - - App::Property *Copy() const override; - void Paste(const App::Property &from) override; - unsigned int getMemSize () const override; + PyObject* getPyObject() override; + void setPyObject(PyObject*) override; + + void Save(Base::Writer& writer) const override; + void Restore(Base::XMLReader& reader) override; + + void SaveDocFile(Base::Writer& writer) const override; + void RestoreDocFile(Base::Reader& reader) override; + + App::Property* Copy() const override; + void Paste(const App::Property& from) override; + unsigned int getMemSize() const override; /** @name Modify */ //@{ - void removeIndices( const std::vector& ); + void removeIndices(const std::vector&); //@} private: @@ -109,38 +112,41 @@ public: void setValue(const Base::Vector3f&); void setValue(float x, float y, float z); - const Base::Vector3f& operator[] (const int idx) const { + const Base::Vector3f& operator[](const int idx) const + { return _lValueList[idx]; } - void set1Value (const int idx, const Base::Vector3f& value) { + void set1Value(const int idx, const Base::Vector3f& value) + { _lValueList[idx] = value; } - void setValues (const std::vector& values); + void setValues(const std::vector& values); - const std::vector &getValues() const { + const std::vector& getValues() const + { return _lValueList; } - PyObject *getPyObject() override; - void setPyObject(PyObject *) override; + PyObject* getPyObject() override; + void setPyObject(PyObject*) override; - void Save (Base::Writer &writer) const override; - void Restore(Base::XMLReader &reader) override; + void Save(Base::Writer& writer) const override; + void Restore(Base::XMLReader& reader) override; - void SaveDocFile (Base::Writer &writer) const override; - void RestoreDocFile(Base::Reader &reader) override; + void SaveDocFile(Base::Writer& writer) const override; + void RestoreDocFile(Base::Reader& reader) override; - App::Property *Copy() const override; - void Paste(const App::Property &from) override; + App::Property* Copy() const override; + void Paste(const App::Property& from) override; - unsigned int getMemSize () const override; + unsigned int getMemSize() const override; /** @name Modify */ //@{ - void transformGeometry(const Base::Matrix4D &rclMat); - void removeIndices( const std::vector& ); + void transformGeometry(const Base::Matrix4D& rclMat); + void removeIndices(const std::vector&); //@} private: @@ -161,70 +167,76 @@ class PointsExport PropertyCurvatureList: public App::PropertyLists TYPESYSTEM_HEADER_WITH_OVERRIDE(); public: - enum { - MeanCurvature = 0, /**< Mean curvature */ - GaussCurvature = 1, /**< Gaussian curvature */ - MaxCurvature = 2, /**< Maximum curvature */ - MinCurvature = 3, /**< Minimum curvature */ - AbsCurvature = 4 /**< Absolute curvature */ + enum + { + MeanCurvature = 0, /**< Mean curvature */ + GaussCurvature = 1, /**< Gaussian curvature */ + MaxCurvature = 2, /**< Maximum curvature */ + MinCurvature = 3, /**< Minimum curvature */ + AbsCurvature = 4 /**< Absolute curvature */ }; public: PropertyCurvatureList(); - void setSize(int newSize) override { + void setSize(int newSize) override + { _lValueList.resize(newSize); } - int getSize() const override { + int getSize() const override + { return _lValueList.size(); } void setValue(const CurvatureInfo&); void setValues(const std::vector&); - std::vector getCurvature( int tMode) const; + std::vector getCurvature(int tMode) const; /// index operator - const CurvatureInfo& operator[] (const int idx) const { + const CurvatureInfo& operator[](const int idx) const + { return _lValueList[idx]; } - void set1Value (const int idx, const CurvatureInfo& value) { + void set1Value(const int idx, const CurvatureInfo& value) + { _lValueList[idx] = value; } - const std::vector &getValues() const { + const std::vector& getValues() const + { return _lValueList; } - PyObject *getPyObject() override; - void setPyObject(PyObject *) override; + PyObject* getPyObject() override; + void setPyObject(PyObject*) override; /** @name Save/restore */ //@{ - void Save (Base::Writer &writer) const override; - void Restore(Base::XMLReader &reader) override; + void Save(Base::Writer& writer) const override; + void Restore(Base::XMLReader& reader) override; - void SaveDocFile (Base::Writer &writer) const override; - void RestoreDocFile(Base::Reader &reader) override; + void SaveDocFile(Base::Writer& writer) const override; + void RestoreDocFile(Base::Reader& reader) override; //@} /** @name Undo/Redo */ //@{ /// returns a new copy of the property (mainly for Undo/Redo and transactions) - App::Property *Copy() const override; + App::Property* Copy() const override; /// paste the value from the property (mainly for Undo/Redo and transactions) - void Paste(const App::Property &from) override; - unsigned int getMemSize () const override; + void Paste(const App::Property& from) override; + unsigned int getMemSize() const override; //@} /** @name Modify */ //@{ - void transformGeometry(const Base::Matrix4D &rclMat); - void removeIndices( const std::vector& ); + void transformGeometry(const Base::Matrix4D& rclMat); + void removeIndices(const std::vector&); //@} private: std::vector _lValueList; }; -} // namespace Points +}// namespace Points -#endif // POINTS_POINTPROPERTIES_H +#endif// POINTS_POINTPROPERTIES_H diff --git a/src/Mod/Points/App/PropertyPointKernel.cpp b/src/Mod/Points/App/PropertyPointKernel.cpp index f87eeec0c9..51720a4a20 100644 --- a/src/Mod/Points/App/PropertyPointKernel.cpp +++ b/src/Mod/Points/App/PropertyPointKernel.cpp @@ -23,27 +23,25 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include +#include +#include +#include #endif #include #include -#include "PropertyPointKernel.h" #include "PointsPy.h" +#include "PropertyPointKernel.h" using namespace Points; -TYPESYSTEM_SOURCE(Points::PropertyPointKernel , App::PropertyComplexGeoData) +TYPESYSTEM_SOURCE(Points::PropertyPointKernel, App::PropertyComplexGeoData) PropertyPointKernel::PropertyPointKernel() : _cPoints(new PointKernel()) -{ - -} +{} void PropertyPointKernel::setValue(const PointKernel& m) { @@ -77,18 +75,18 @@ Base::BoundBox3d PropertyPointKernel::getBoundingBox() const return _cPoints->getBoundBox(); } -PyObject *PropertyPointKernel::getPyObject() +PyObject* PropertyPointKernel::getPyObject() { PointsPy* points = new PointsPy(&*_cPoints); - points->setConst(); // set immutable + points->setConst();// set immutable return points; } -void PropertyPointKernel::setPyObject(PyObject *value) +void PropertyPointKernel::setPyObject(PyObject* value) { if (PyObject_TypeCheck(value, &(PointsPy::Type))) { - PointsPy *pcObject = static_cast(value); - setValue( *(pcObject->getPointKernelPtr())); + PointsPy* pcObject = static_cast(value); + setValue(*(pcObject->getPointKernelPtr())); } else { std::string error = std::string("type must be 'Points', not "); @@ -97,23 +95,22 @@ void PropertyPointKernel::setPyObject(PyObject *value) } } -void PropertyPointKernel::Save (Base::Writer &writer) const +void PropertyPointKernel::Save(Base::Writer& writer) const { _cPoints->Save(writer); } -void PropertyPointKernel::Restore(Base::XMLReader &reader) +void PropertyPointKernel::Restore(Base::XMLReader& reader) { reader.readElement("Points"); - std::string file (reader.getAttribute("file") ); + std::string file(reader.getAttribute("file")); if (!file.empty()) { // initiate a file read - reader.addFile(file.c_str(),this); + reader.addFile(file.c_str(), this); } - if(reader.DocumentSchema > 3) - { - std::string Matrix (reader.getAttribute("mtrx") ); + if (reader.DocumentSchema > 3) { + std::string Matrix(reader.getAttribute("mtrx")); Base::Matrix4D mtrx; mtrx.fromString(Matrix); @@ -123,27 +120,27 @@ void PropertyPointKernel::Restore(Base::XMLReader &reader) } } -void PropertyPointKernel::SaveDocFile (Base::Writer &writer) const +void PropertyPointKernel::SaveDocFile(Base::Writer& writer) const { // does nothing (void)writer; } -void PropertyPointKernel::RestoreDocFile(Base::Reader &reader) +void PropertyPointKernel::RestoreDocFile(Base::Reader& reader) { aboutToSetValue(); _cPoints->RestoreDocFile(reader); hasSetValue(); } -App::Property *PropertyPointKernel::Copy() const +App::Property* PropertyPointKernel::Copy() const { PropertyPointKernel* prop = new PropertyPointKernel(); (*prop->_cPoints) = (*this->_cPoints); return prop; } -void PropertyPointKernel::Paste(const App::Property &from) +void PropertyPointKernel::Paste(const App::Property& from) { aboutToSetValue(); const PropertyPointKernel& prop = dynamic_cast(from); @@ -151,7 +148,7 @@ void PropertyPointKernel::Paste(const App::Property &from) hasSetValue(); } -unsigned int PropertyPointKernel::getMemSize () const +unsigned int PropertyPointKernel::getMemSize() const { return sizeof(Base::Vector3f) * this->_cPoints->size(); } @@ -167,15 +164,16 @@ void PropertyPointKernel::finishEditing() hasSetValue(); } -void PropertyPointKernel::removeIndices( const std::vector& uIndices ) +void PropertyPointKernel::removeIndices(const std::vector& uIndices) { // We need a sorted array std::vector uSortedInds = uIndices; std::sort(uSortedInds.begin(), uSortedInds.end()); - assert( uSortedInds.size() <= _cPoints->size() ); - if ( uSortedInds.size() > _cPoints->size() ) + assert(uSortedInds.size() <= _cPoints->size()); + if (uSortedInds.size() > _cPoints->size()) { return; + } PointKernel kernel; kernel.setTransform(_cPoints->getTransform()); @@ -184,18 +182,21 @@ void PropertyPointKernel::removeIndices( const std::vector& uIndi std::vector::iterator pos = uSortedInds.begin(); unsigned long index = 0; for (PointKernel::const_iterator it = _cPoints->begin(); it != _cPoints->end(); ++it, ++index) { - if (pos == uSortedInds.end()) - kernel.push_back( *it ); - else if (index != *pos) - kernel.push_back( *it ); - else + if (pos == uSortedInds.end()) { + kernel.push_back(*it); + } + else if (index != *pos) { + kernel.push_back(*it); + } + else { ++pos; + } } setValue(kernel); } -void PropertyPointKernel::transformGeometry(const Base::Matrix4D &rclMat) +void PropertyPointKernel::transformGeometry(const Base::Matrix4D& rclMat) { aboutToSetValue(); _cPoints->transformGeometry(rclMat); diff --git a/src/Mod/Points/App/PropertyPointKernel.h b/src/Mod/Points/App/PropertyPointKernel.h index e1f055f768..942c037db2 100644 --- a/src/Mod/Points/App/PropertyPointKernel.h +++ b/src/Mod/Points/App/PropertyPointKernel.h @@ -31,7 +31,7 @@ namespace Points /** The point kernel property */ -class PointsExport PropertyPointKernel : public App::PropertyComplexGeoData +class PointsExport PropertyPointKernel: public App::PropertyComplexGeoData { TYPESYSTEM_HEADER_WITH_OVERRIDE(); @@ -41,9 +41,9 @@ public: /** @name Getter/setter */ //@{ /// Sets the points to the property - void setValue( const PointKernel& m); + void setValue(const PointKernel& m); /// get the points (only const possible!) - const PointKernel &getValue() const; + const PointKernel& getValue() const; const Data::ComplexGeoData* getComplexData() const override; void setTransform(const Base::Matrix4D& rclTrf) override; Base::Matrix4D getTransform() const override; @@ -58,24 +58,24 @@ public: /** @name Python interface */ //@{ PyObject* getPyObject() override; - void setPyObject(PyObject *value) override; + void setPyObject(PyObject* value) override; //@} /** @name Undo/Redo */ //@{ /// returns a new copy of the property (mainly for Undo/Redo and transactions) - App::Property *Copy() const override; + App::Property* Copy() const override; /// paste the value from the property (mainly for Undo/Redo and transactions) - void Paste(const App::Property &from) override; - unsigned int getMemSize () const override; + void Paste(const App::Property& from) override; + unsigned int getMemSize() const override; //@} /** @name Save/restore */ //@{ - void Save (Base::Writer &writer) const override; - void Restore(Base::XMLReader &reader) override; - void SaveDocFile (Base::Writer &writer) const override; - void RestoreDocFile(Base::Reader &reader) override; + void Save(Base::Writer& writer) const override; + void Restore(Base::XMLReader& reader) override; + void SaveDocFile(Base::Writer& writer) const override; + void RestoreDocFile(Base::Reader& reader) override; //@} /** @name Modification */ @@ -83,15 +83,15 @@ public: PointKernel* startEditing(); void finishEditing(); /// Transform the real 3d point kernel - void transformGeometry(const Base::Matrix4D &rclMat) override; - void removeIndices( const std::vector& ); + void transformGeometry(const Base::Matrix4D& rclMat) override; + void removeIndices(const std::vector&); //@} private: Base::Reference _cPoints; }; -} // namespace Points +}// namespace Points -#endif // POINTS_PROPERTYPOINTKERNEL_H +#endif// POINTS_PROPERTYPOINTKERNEL_H diff --git a/src/Mod/Points/App/Structured.cpp b/src/Mod/Points/App/Structured.cpp index 5f7f036831..e084f362c4 100644 --- a/src/Mod/Points/App/Structured.cpp +++ b/src/Mod/Points/App/Structured.cpp @@ -23,7 +23,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include "Structured.h" @@ -62,30 +62,32 @@ PROPERTY_SOURCE(Points::Structured, Points::Feature) Structured::Structured() { -// App::PropertyType type = static_cast(App::Prop_None); + // App::PropertyType type = static_cast(App::Prop_None); App::PropertyType type = static_cast(App::Prop_ReadOnly); - ADD_PROPERTY_TYPE(Width,(1),"Structured points", type, "Width of the image"); - ADD_PROPERTY_TYPE(Height,(1),"Structured points", type, "Height of the image"); - //Width.setStatus(App::Property::ReadOnly, true); - //Height.setStatus(App::Property::ReadOnly, true); + ADD_PROPERTY_TYPE(Width, (1), "Structured points", type, "Width of the image"); + ADD_PROPERTY_TYPE(Height, (1), "Structured points", type, "Height of the image"); + // Width.setStatus(App::Property::ReadOnly, true); + // Height.setStatus(App::Property::ReadOnly, true); } -App::DocumentObjectExecReturn *Structured::execute() +App::DocumentObjectExecReturn* Structured::execute() { std::size_t size = Height.getValue() * Width.getValue(); - if (size != Points.getValue().size()) + if (size != Points.getValue().size()) { throw Base::ValueError("(Width * Height) doesn't match with number of points"); + } this->Points.touch(); return App::DocumentObject::StdReturn; } // --------------------------------------------------------- -namespace App { +namespace App +{ /// @cond DOXERR PROPERTY_SOURCE_TEMPLATE(Points::StructuredCustom, Points::Structured) /// @endcond // explicit template instantiation template class PointsExport FeatureCustomT; -} +}// namespace App diff --git a/src/Mod/Points/App/Structured.h b/src/Mod/Points/App/Structured.h index c388c8b34b..65b9097b51 100644 --- a/src/Mod/Points/App/Structured.h +++ b/src/Mod/Points/App/Structured.h @@ -34,7 +34,7 @@ namespace Points and that with respect to their x,y coordinates they are ordered in a grid structure. If a point is marked invalid then one of its coordinates is set to NaN. */ -class PointsExport Structured : public Feature +class PointsExport Structured: public Feature { PROPERTY_HEADER_WITH_OVERRIDE(Points::Structured); @@ -42,15 +42,16 @@ public: /// Constructor Structured(); - App::PropertyInteger Width; /**< The width of the structured cloud. */ + App::PropertyInteger Width; /**< The width of the structured cloud. */ App::PropertyInteger Height; /**< The height of the structured cloud. */ /** @name methods override Feature */ //@{ /// recalculate the Feature - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; /// returns the type name of the ViewProvider - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "PointsGui::ViewProviderStructured"; } //@} @@ -58,7 +59,7 @@ public: using StructuredCustom = App::FeatureCustomT; -} //namespace Points +}// namespace Points #endif diff --git a/src/Mod/Points/App/Tools.h b/src/Mod/Points/App/Tools.h index 48be0fd033..16295693d8 100644 --- a/src/Mod/Points/App/Tools.h +++ b/src/Mod/Points/App/Tools.h @@ -24,10 +24,11 @@ #ifndef POINTS_TOOLS_H #define POINTS_TOOLS_H -#include #include +#include -namespace Points { +namespace Points +{ template bool copyProperty(App::DocumentObject* target, @@ -39,13 +40,12 @@ bool copyProperty(App::DocumentObject* target, return dynamic_cast(obj->getPropertyByName(propertyName)) != nullptr; })) { - auto target_prop = dynamic_cast - (target->addDynamicProperty(PropertyT::getClassTypeId().getName(), propertyName)); + auto target_prop = dynamic_cast( + target->addDynamicProperty(PropertyT::getClassTypeId().getName(), propertyName)); if (target_prop) { auto values = target_prop->getValues(); for (auto it : source) { - auto source_prop = dynamic_cast - (it->getPropertyByName(propertyName)); + auto source_prop = dynamic_cast(it->getPropertyByName(propertyName)); if (source_prop) { auto source_values = source_prop->getValues(); values.insert(values.end(), source_values.begin(), source_values.end()); @@ -60,6 +60,6 @@ bool copyProperty(App::DocumentObject* target, return false; } -} +}// namespace Points -#endif // POINTS_TOOLS_H +#endif// POINTS_TOOLS_H diff --git a/src/Mod/Points/Gui/AppPointsGui.cpp b/src/Mod/Points/Gui/AppPointsGui.cpp index f2ddcd41b7..3d6abf35c8 100644 --- a/src/Mod/Points/Gui/AppPointsGui.cpp +++ b/src/Mod/Points/Gui/AppPointsGui.cpp @@ -44,13 +44,15 @@ void loadPointsResource() Gui::Translator::instance()->refresh(); } -namespace PointsGui { -class Module : public Py::ExtensionModule +namespace PointsGui +{ +class Module: public Py::ExtensionModule { public: - Module() : Py::ExtensionModule("PointsGui") + Module() + : Py::ExtensionModule("PointsGui") { - initialize("This module is the PointsGui module."); // register with Python + initialize("This module is the PointsGui module.");// register with Python } }; @@ -59,7 +61,7 @@ PyObject* initModule() return Base::Interpreter().addModule(new Module); } -} // namespace PointsGui +}// namespace PointsGui /* Python entry */ @@ -74,7 +76,7 @@ PyMOD_INIT_FUNC(PointsGui) try { Base::Interpreter().loadModule("Points"); } - catch(const Base::Exception& e) { + catch (const Base::Exception& e) { PyErr_SetString(PyExc_ImportError, e.what()); PyMOD_Return(nullptr); } @@ -85,14 +87,15 @@ PyMOD_INIT_FUNC(PointsGui) // instantiating the commands CreatePointsCommands(); + // clang-format off PointsGui::ViewProviderPoints ::init(); PointsGui::ViewProviderScattered ::init(); PointsGui::ViewProviderStructured ::init(); PointsGui::ViewProviderPython ::init(); PointsGui::Workbench ::init(); - Gui::ViewProviderBuilder::add( - Points::PropertyPointKernel::getClassTypeId(), - PointsGui::ViewProviderPoints::getClassTypeId()); + // clang-format on + Gui::ViewProviderBuilder::add(Points::PropertyPointKernel::getClassTypeId(), + PointsGui::ViewProviderPoints::getClassTypeId()); // add resources and reloads the translators loadPointsResource(); diff --git a/src/Mod/Points/Gui/Command.cpp b/src/Mod/Points/Gui/Command.cpp index 98b3bb5800..07e2a3ba3b 100644 --- a/src/Mod/Points/Gui/Command.cpp +++ b/src/Mod/Points/Gui/Command.cpp @@ -22,9 +22,9 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include +#include +#include +#include #endif #include @@ -45,8 +45,8 @@ #include #include "../App/PointsFeature.h" -#include "../App/Structured.h" #include "../App/Properties.h" +#include "../App/Structured.h" #include "../App/Tools.h" #include "DlgPointsReadImp.h" @@ -61,34 +61,40 @@ DEF_STD_CMD_A(CmdPointsImport) CmdPointsImport::CmdPointsImport() - : Command("Points_Import") + : Command("Points_Import") { - sAppModule = "Points"; - sGroup = QT_TR_NOOP("Points"); - sMenuText = QT_TR_NOOP("Import points..."); - sToolTipText = QT_TR_NOOP("Imports a point cloud"); - sWhatsThis = "Points_Import"; - sStatusTip = QT_TR_NOOP("Imports a point cloud"); - sPixmap = "Points_Import_Point_cloud"; + sAppModule = "Points"; + sGroup = QT_TR_NOOP("Points"); + sMenuText = QT_TR_NOOP("Import points..."); + sToolTipText = QT_TR_NOOP("Imports a point cloud"); + sWhatsThis = "Points_Import"; + sStatusTip = QT_TR_NOOP("Imports a point cloud"); + sPixmap = "Points_Import_Point_cloud"; } void CmdPointsImport::activated(int iMsg) { Q_UNUSED(iMsg); - QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), - QString(), QString(), QString::fromLatin1("%1 (*.asc *.pcd *.ply);;%2 (*.*)") - .arg(QObject::tr("Point formats"), QObject::tr("All Files"))); - if (fn.isEmpty()) + QString fn = Gui::FileDialog::getOpenFileName( + Gui::getMainWindow(), + QString(), + QString(), + QString::fromLatin1("%1 (*.asc *.pcd *.ply);;%2 (*.*)") + .arg(QObject::tr("Point formats"), QObject::tr("All Files"))); + if (fn.isEmpty()) { return; + } if (!fn.isEmpty()) { fn = Base::Tools::escapeEncodeFilename(fn); Gui::Document* doc = getActiveGuiDocument(); openCommand(QT_TRANSLATE_NOOP("Command", "Import points")); addModule(Command::App, "Points"); - doCommand(Command::Doc, "Points.insert(\"%s\", \"%s\")", - fn.toUtf8().data(), doc->getDocument()->getName()); + doCommand(Command::Doc, + "Points.insert(\"%s\", \"%s\")", + fn.toUtf8().data(), + doc->getDocument()->getName()); commitCommand(); updateActive(); @@ -97,24 +103,26 @@ void CmdPointsImport::activated(int iMsg) bool CmdPointsImport::isActive() { - if (getActiveGuiDocument()) + if (getActiveGuiDocument()) { return true; - else + } + else { return false; + } } DEF_STD_CMD_A(CmdPointsExport) CmdPointsExport::CmdPointsExport() - : Command("Points_Export") + : Command("Points_Export") { - sAppModule = "Points"; - sGroup = QT_TR_NOOP("Points"); - sMenuText = QT_TR_NOOP("Export points..."); - sToolTipText = QT_TR_NOOP("Exports a point cloud"); - sWhatsThis = "Points_Export"; - sStatusTip = QT_TR_NOOP("Exports a point cloud"); - sPixmap = "Points_Export_Point_cloud"; + sAppModule = "Points"; + sGroup = QT_TR_NOOP("Points"); + sMenuText = QT_TR_NOOP("Export points..."); + sToolTipText = QT_TR_NOOP("Exports a point cloud"); + sWhatsThis = "Points_Export"; + sStatusTip = QT_TR_NOOP("Exports a point cloud"); + sPixmap = "Points_Export_Point_cloud"; } void CmdPointsExport::activated(int iMsg) @@ -122,18 +130,25 @@ void CmdPointsExport::activated(int iMsg) Q_UNUSED(iMsg); addModule(Command::App, "Points"); - std::vector points = getSelection().getObjectsOfType(Points::Feature::getClassTypeId()); + std::vector points = + getSelection().getObjectsOfType(Points::Feature::getClassTypeId()); for (auto point : points) { - QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), - QString(), QString(), QString::fromLatin1("%1 (*.asc *.pcd *.ply);;%2 (*.*)") - .arg(QObject::tr("Point formats"), QObject::tr("All Files"))); - if (fn.isEmpty()) + QString fn = Gui::FileDialog::getSaveFileName( + Gui::getMainWindow(), + QString(), + QString(), + QString::fromLatin1("%1 (*.asc *.pcd *.ply);;%2 (*.*)") + .arg(QObject::tr("Point formats"), QObject::tr("All Files"))); + if (fn.isEmpty()) { break; + } if (!fn.isEmpty()) { fn = Base::Tools::escapeEncodeFilename(fn); - doCommand(Command::Doc, "Points.export([App.ActiveDocument.%s], \"%s\")", - point->getNameInDocument(), fn.toUtf8().data()); + doCommand(Command::Doc, + "Points.export([App.ActiveDocument.%s], \"%s\")", + point->getNameInDocument(), + fn.toUtf8().data()); } } } @@ -146,15 +161,15 @@ bool CmdPointsExport::isActive() DEF_STD_CMD_A(CmdPointsTransform) CmdPointsTransform::CmdPointsTransform() - :Command("Points_Transform") + : Command("Points_Transform") { - sAppModule = "Points"; - sGroup = QT_TR_NOOP("Points"); - sMenuText = QT_TR_NOOP("Transform Points"); - sToolTipText = QT_TR_NOOP("Test to transform a point cloud"); - sWhatsThis = "Points_Transform"; - sStatusTip = QT_TR_NOOP("Test to transform a point cloud"); - sPixmap = "Test1"; + sAppModule = "Points"; + sGroup = QT_TR_NOOP("Points"); + sMenuText = QT_TR_NOOP("Transform Points"); + sToolTipText = QT_TR_NOOP("Test to transform a point cloud"); + sWhatsThis = "Points_Transform"; + sStatusTip = QT_TR_NOOP("Test to transform a point cloud"); + sPixmap = "Test1"; } void CmdPointsTransform::activated(int iMsg) @@ -166,12 +181,14 @@ void CmdPointsTransform::activated(int iMsg) trans.setRotation(Base::Rotation(Base::Vector3d(0.0, 0.0, 1.0), 1.570796)); openCommand(QT_TRANSLATE_NOOP("Command", "Transform points")); - //std::vector points = getSelection().getObjectsOfType(Points::Feature::getClassTypeId()); - //for (std::vector::const_iterator it = points.begin(); it != points.end(); ++it) { - // Base::Placement p = static_cast(*it)->Placement.getValue(); - // p._rot *= Base::Rotation(Base::Vector3d(0.0, 0.0, 1.0), 1.570796); - // static_cast(*it)->Placement.setValue(p); - //} + // std::vector points = + // getSelection().getObjectsOfType(Points::Feature::getClassTypeId()); for + // (std::vector::const_iterator it = points.begin(); it != points.end(); + // ++it) { + // Base::Placement p = static_cast(*it)->Placement.getValue(); + // p._rot *= Base::Rotation(Base::Vector3d(0.0, 0.0, 1.0), 1.570796); + // static_cast(*it)->Placement.setValue(p); + // } commitCommand(); } @@ -183,15 +200,15 @@ bool CmdPointsTransform::isActive() DEF_STD_CMD_A(CmdPointsConvert) CmdPointsConvert::CmdPointsConvert() - :Command("Points_Convert") + : Command("Points_Convert") { - sAppModule = "Points"; - sGroup = QT_TR_NOOP("Points"); - sMenuText = QT_TR_NOOP("Convert to points..."); - sToolTipText = QT_TR_NOOP("Convert to points"); - sWhatsThis = "Points_Convert"; - sStatusTip = QT_TR_NOOP("Convert to points"); - sPixmap = "Points_Convert"; + sAppModule = "Points"; + sGroup = QT_TR_NOOP("Points"); + sMenuText = QT_TR_NOOP("Convert to points..."); + sToolTipText = QT_TR_NOOP("Convert to points"); + sWhatsThis = "Points_Convert"; + sStatusTip = QT_TR_NOOP("Convert to points"); + sPixmap = "Points_Convert"; } void CmdPointsConvert::activated(int iMsg) @@ -202,13 +219,22 @@ void CmdPointsConvert::activated(int iMsg) int decimals = Base::UnitsApi::getDecimals(); double tolerance_from_decimals = pow(10., -decimals); - double minimal_tolerance = tolerance_from_decimals < STD_OCC_TOLERANCE ? STD_OCC_TOLERANCE : tolerance_from_decimals; + double minimal_tolerance = + tolerance_from_decimals < STD_OCC_TOLERANCE ? STD_OCC_TOLERANCE : tolerance_from_decimals; bool ok; - double tol = QInputDialog::getDouble(Gui::getMainWindow(), QObject::tr("Distance"), - QObject::tr("Enter maximum distance:"), 0.1, minimal_tolerance, 10.0, decimals, &ok, Qt::MSWindowsFixedSizeDialogHint); - if (!ok) + double tol = QInputDialog::getDouble(Gui::getMainWindow(), + QObject::tr("Distance"), + QObject::tr("Enter maximum distance:"), + 0.1, + minimal_tolerance, + 10.0, + decimals, + &ok, + Qt::MSWindowsFixedSizeDialogHint); + if (!ok) { return; + } Gui::WaitCursor wc; openCommand(QT_TRANSLATE_NOOP("Command", "Convert to points")); @@ -230,7 +256,8 @@ void CmdPointsConvert::activated(int iMsg) } Py::Module commands(module, true); - commands.callMemberFunction("make_points_from_geometry", Py::TupleN(list, Py::Float(tol))); + commands.callMemberFunction("make_points_from_geometry", + Py::TupleN(list, Py::Float(tol))); return true; } @@ -239,10 +266,12 @@ void CmdPointsConvert::activated(int iMsg) Base::PyGILStateLocker lock; try { - if (run_python(geoObject, tol)) + if (run_python(geoObject, tol)) { commitCommand(); - else + } + else { abortCommand(); + } } catch (const Py::Exception&) { abortCommand(); @@ -259,23 +288,25 @@ bool CmdPointsConvert::isActive() DEF_STD_CMD_A(CmdPointsPolyCut) CmdPointsPolyCut::CmdPointsPolyCut() - :Command("Points_PolyCut") + : Command("Points_PolyCut") { - sAppModule = "Points"; - sGroup = QT_TR_NOOP("Points"); - sMenuText = QT_TR_NOOP("Cut point cloud"); - sToolTipText = QT_TR_NOOP("Cuts a point cloud with a picked polygon"); - sWhatsThis = "Points_PolyCut"; - sStatusTip = QT_TR_NOOP("Cuts a point cloud with a picked polygon"); - sPixmap = "PolygonPick"; + sAppModule = "Points"; + sGroup = QT_TR_NOOP("Points"); + sMenuText = QT_TR_NOOP("Cut point cloud"); + sToolTipText = QT_TR_NOOP("Cuts a point cloud with a picked polygon"); + sWhatsThis = "Points_PolyCut"; + sStatusTip = QT_TR_NOOP("Cuts a point cloud with a picked polygon"); + sPixmap = "PolygonPick"; } void CmdPointsPolyCut::activated(int iMsg) { Q_UNUSED(iMsg); - std::vector docObj = Gui::Selection().getObjectsOfType(Points::Feature::getClassTypeId()); - for (std::vector::iterator it = docObj.begin(); it != docObj.end(); ++it) { + std::vector docObj = + Gui::Selection().getObjectsOfType(Points::Feature::getClassTypeId()); + for (std::vector::iterator it = docObj.begin(); it != docObj.end(); + ++it) { if (it == docObj.begin()) { Gui::Document* doc = getActiveGuiDocument(); Gui::MDIView* view = doc->getActiveView(); @@ -283,14 +314,15 @@ void CmdPointsPolyCut::activated(int iMsg) Gui::View3DInventorViewer* viewer = ((Gui::View3DInventor*)view)->getViewer(); viewer->setEditing(true); viewer->startSelection(Gui::View3DInventorViewer::Lasso); - viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), PointsGui::ViewProviderPoints::clipPointsCallback); + viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), + PointsGui::ViewProviderPoints::clipPointsCallback); } else { return; } } - Gui::ViewProvider* pVP = getActiveGuiDocument()->getViewProvider( *it ); + Gui::ViewProvider* pVP = getActiveGuiDocument()->getViewProvider(*it); pVP->startEditing(Gui::ViewProvider::Cutting); } } @@ -304,15 +336,15 @@ bool CmdPointsPolyCut::isActive() DEF_STD_CMD_A(CmdPointsMerge) CmdPointsMerge::CmdPointsMerge() - :Command("Points_Merge") + : Command("Points_Merge") { - sAppModule = "Points"; - sGroup = QT_TR_NOOP("Points"); - sMenuText = QT_TR_NOOP("Merge point clouds"); - sToolTipText = QT_TR_NOOP("Merge several point clouds into one"); - sWhatsThis = "Points_Merge"; - sStatusTip = QT_TR_NOOP("Merge several point clouds into one"); - sPixmap = "Points_Merge"; + sAppModule = "Points"; + sGroup = QT_TR_NOOP("Points"); + sMenuText = QT_TR_NOOP("Merge point clouds"); + sToolTipText = QT_TR_NOOP("Merge several point clouds into one"); + sWhatsThis = "Points_Merge"; + sStatusTip = QT_TR_NOOP("Merge several point clouds into one"); + sPixmap = "Points_Merge"; } void CmdPointsMerge::activated(int iMsg) @@ -321,16 +353,18 @@ void CmdPointsMerge::activated(int iMsg) App::Document* doc = App::GetApplication().getActiveDocument(); doc->openTransaction("Merge point clouds"); - Points::Feature* pts = static_cast(doc->addObject("Points::Feature", "Merged Points")); + Points::Feature* pts = + static_cast(doc->addObject("Points::Feature", "Merged Points")); Points::PointKernel* kernel = pts->Points.startEditing(); - std::vector docObj = Gui::Selection().getObjectsOfType(Points::Feature::getClassTypeId()); + std::vector docObj = + Gui::Selection().getObjectsOfType(Points::Feature::getClassTypeId()); for (auto it : docObj) { const Points::PointKernel& k = static_cast(it)->Points.getValue(); std::size_t numPts = kernel->size(); kernel->resize(numPts + k.size()); - for (std::size_t i=0; isetPoint(i+numPts, k.getPoint(i)); + for (std::size_t i = 0; i < k.size(); ++i) { + kernel->setPoint(i + numPts, k.getPoint(i)); } } @@ -348,8 +382,8 @@ void CmdPointsMerge::activated(int iMsg) displayMode = "Intensity"; } - if (auto vp = dynamic_cast - (Gui::Application::Instance->getViewProvider(pts))) { + if (auto vp = dynamic_cast( + Gui::Application::Instance->getViewProvider(pts))) { vp->DisplayMode.setValue(displayMode.c_str()); } @@ -365,15 +399,15 @@ bool CmdPointsMerge::isActive() DEF_STD_CMD_A(CmdPointsStructure) CmdPointsStructure::CmdPointsStructure() - :Command("Points_Structure") + : Command("Points_Structure") { - sAppModule = "Points"; - sGroup = QT_TR_NOOP("Points"); - sMenuText = QT_TR_NOOP("Structured point cloud"); - sToolTipText = QT_TR_NOOP("Convert points to structured point cloud"); - sWhatsThis = "Points_Structure"; - sStatusTip = QT_TR_NOOP("Convert points to structured point cloud"); - sPixmap = "Points_Structure"; + sAppModule = "Points"; + sGroup = QT_TR_NOOP("Points"); + sMenuText = QT_TR_NOOP("Structured point cloud"); + sToolTipText = QT_TR_NOOP("Convert points to structured point cloud"); + sWhatsThis = "Points_Structure"; + sStatusTip = QT_TR_NOOP("Convert points to structured point cloud"); + sPixmap = "Points_Structure"; } void CmdPointsStructure::activated(int iMsg) @@ -383,11 +417,13 @@ void CmdPointsStructure::activated(int iMsg) App::Document* doc = App::GetApplication().getActiveDocument(); doc->openTransaction("Structure point cloud"); - std::vector docObj = Gui::Selection().getObjectsOfType(Points::Feature::getClassTypeId()); + std::vector docObj = + Gui::Selection().getObjectsOfType(Points::Feature::getClassTypeId()); for (auto it : docObj) { std::string name = it->Label.getValue(); name += " (Structured)"; - Points::Structured* output = static_cast(doc->addObject("Points::Structured", name.c_str())); + Points::Structured* output = + static_cast(doc->addObject("Points::Structured", name.c_str())); output->Label.setValue(name); // Already sorted, so just make a copy @@ -398,7 +434,7 @@ void CmdPointsStructure::activated(int iMsg) const Points::PointKernel& k = input->Points.getValue(); kernel->resize(k.size()); - for (std::size_t i=0; isetPoint(i, k.getPoint(i)); } output->Points.finishEditing(); @@ -418,7 +454,7 @@ void CmdPointsStructure::activated(int iMsg) // Count the number of different x or y values to get the size std::set countX, countY; - for (std::size_t i=0; i points and afterwards replace them // with valid point coordinates double nan = std::numeric_limits::quiet_NaN(); - std::vector sortedPoints(width_l * height_l, Base::Vector3d(nan, nan, nan)); + std::vector sortedPoints(width_l * height_l, + Base::Vector3d(nan, nan, nan)); - for (std::size_t i=0; icommandManager(); + Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager(); rcCmdMgr.addCommand(new CmdPointsImport()); rcCmdMgr.addCommand(new CmdPointsExport()); rcCmdMgr.addCommand(new CmdPointsTransform()); diff --git a/src/Mod/Points/Gui/DlgPointsReadImp.cpp b/src/Mod/Points/Gui/DlgPointsReadImp.cpp index badb36b6ff..1d42bc04b7 100644 --- a/src/Mod/Points/Gui/DlgPointsReadImp.cpp +++ b/src/Mod/Points/Gui/DlgPointsReadImp.cpp @@ -28,12 +28,12 @@ using namespace PointsGui; -DlgPointsReadImp::DlgPointsReadImp(const char *FileName, QWidget* parent, Qt::WindowFlags fl ) - : QDialog( parent, fl ) +DlgPointsReadImp::DlgPointsReadImp(const char* FileName, QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) , ui(new Ui_DlgPointsRead) { - ui->setupUi(this); - _FileName = FileName; + ui->setupUi(this); + _FileName = FileName; } /* diff --git a/src/Mod/Points/Gui/DlgPointsReadImp.h b/src/Mod/Points/Gui/DlgPointsReadImp.h index 3f8dfc53f5..2a58fb1f81 100644 --- a/src/Mod/Points/Gui/DlgPointsReadImp.h +++ b/src/Mod/Points/Gui/DlgPointsReadImp.h @@ -23,28 +23,31 @@ #ifndef POINTSGUI_DLGREADPOINTS_H #define POINTSGUI_DLGREADPOINTS_H -#include #include +#include -namespace PointsGui { +namespace PointsGui +{ class Ui_DlgPointsRead; /** The points read dialog */ -class DlgPointsReadImp : public QDialog +class DlgPointsReadImp: public QDialog { - Q_OBJECT + Q_OBJECT public: - explicit DlgPointsReadImp(const char *FileName, QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags() ); - ~DlgPointsReadImp() override; + explicit DlgPointsReadImp(const char* FileName, + QWidget* parent = nullptr, + Qt::WindowFlags fl = Qt::WindowFlags()); + ~DlgPointsReadImp() override; private: - std::unique_ptr ui; - std::string _FileName; + std::unique_ptr ui; + std::string _FileName; }; -} // namespace PointsGui +}// namespace PointsGui -#endif // POINTSGUI_DLGREADPOINTS_H +#endif// POINTSGUI_DLGREADPOINTS_H diff --git a/src/Mod/Points/Gui/PreCompiled.h b/src/Mod/Points/Gui/PreCompiled.h index bcfbb39e3c..99fc073187 100644 --- a/src/Mod/Points/Gui/PreCompiled.h +++ b/src/Mod/Points/Gui/PreCompiled.h @@ -28,30 +28,30 @@ #ifdef _PreComp_ // STL -# include -# include -# include +#include +#include +#include // boost -# include +#include // Qt -# include -# include +#include +#include // Inventor -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#endif //_PreComp_ +#endif//_PreComp_ -#endif // POINTSGUI_PRECOMPILED_H +#endif// POINTSGUI_PRECOMPILED_H diff --git a/src/Mod/Points/Gui/ViewProvider.cpp b/src/Mod/Points/Gui/ViewProvider.cpp index e9fa723855..9ad17fad70 100644 --- a/src/Mod/Points/Gui/ViewProvider.cpp +++ b/src/Mod/Points/Gui/ViewProvider.cpp @@ -22,19 +22,19 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif #include @@ -56,11 +56,11 @@ using namespace Points; PROPERTY_SOURCE_ABSTRACT(PointsGui::ViewProviderPoints, Gui::ViewProviderGeometryObject) -App::PropertyFloatConstraint::Constraints ViewProviderPoints::floatRange = {1.0,64.0,1.0}; +App::PropertyFloatConstraint::Constraints ViewProviderPoints::floatRange = {1.0, 64.0, 1.0}; ViewProviderPoints::ViewProviderPoints() { - static const char *osgroup = "Object Style"; + static const char* osgroup = "Object Style"; ADD_PROPERTY_TYPE(PointSize, (2.0f), osgroup, App::Prop_None, "Set point size"); PointSize.setConstraints(&floatRange); @@ -68,8 +68,9 @@ ViewProviderPoints::ViewProviderPoints() // Create the selection node pcHighlight = Gui::ViewProviderBuilder::createSelection(); pcHighlight->ref(); - if (pcHighlight->selectionMode.getValue() == Gui::SoFCSelection::SEL_OFF) + if (pcHighlight->selectionMode.getValue() == Gui::SoFCSelection::SEL_OFF) { Selectable.setValue(false); + } // BBOX SelectionStyle.setValue(1); @@ -102,8 +103,8 @@ void ViewProviderPoints::onChanged(const App::Property* prop) pcPointStyle->pointSize = PointSize.getValue(); } else if (prop == &SelectionStyle) { - pcHighlight->style = SelectionStyle.getValue() ? Gui::SoFCSelection::BOX - : Gui::SoFCSelection::EMISSIVE; + pcHighlight->style = + SelectionStyle.getValue() ? Gui::SoFCSelection::BOX : Gui::SoFCSelection::EMISSIVE; } else { ViewProviderGeometryObject::onChanged(prop); @@ -117,7 +118,7 @@ void ViewProviderPoints::setVertexColorMode(App::PropertyColorList* pcProperty) pcColorMat->diffuseColor.setNum(val.size()); SbColor* col = pcColorMat->diffuseColor.startEditing(); - std::size_t i=0; + std::size_t i = 0; for (const auto& it : val) { col[i++].setValue(it.r, it.g, it.b); } @@ -132,7 +133,7 @@ void ViewProviderPoints::setVertexGreyvalueMode(Points::PropertyGreyValueList* p pcColorMat->diffuseColor.setNum(val.size()); SbColor* col = pcColorMat->diffuseColor.startEditing(); - std::size_t i=0; + std::size_t i = 0; for (float it : val) { col[i++].setValue(it, it, it); } @@ -147,7 +148,7 @@ void ViewProviderPoints::setVertexNormalMode(Points::PropertyNormalList* pcPrope pcPointsNormal->vector.setNum(val.size()); SbVec3f* norm = pcPointsNormal->vector.startEditing(); - std::size_t i=0; + std::size_t i = 0; for (const auto& it : val) { norm[i++].setValue(it.x, it.y, it.z); } @@ -159,17 +160,20 @@ void ViewProviderPoints::setDisplayMode(const char* ModeName) { int numPoints = pcPointsCoord->point.getNum(); - if (strcmp("Color",ModeName) == 0) { - std::map Map; + if (strcmp("Color", ModeName) == 0) { + std::map Map; pcObject->getPropertyMap(Map); - for (auto & it : Map) { + for (auto& it : Map) { Base::Type type = it.second->getTypeId(); if (type == App::PropertyColorList::getClassTypeId()) { App::PropertyColorList* colors = static_cast(it.second); if (numPoints != colors->getSize()) { #ifdef FC_DEBUG - SoDebugError::postWarning("ViewProviderPoints::setDisplayMode", - "The number of points (%d) doesn't match with the number of colors (%d).", numPoints, colors->getSize()); + SoDebugError::postWarning( + "ViewProviderPoints::setDisplayMode", + "The number of points (%d) doesn't match with the number of colors (%d).", + numPoints, + colors->getSize()); #endif // fallback setDisplayMaskMode("Point"); @@ -182,17 +186,21 @@ void ViewProviderPoints::setDisplayMode(const char* ModeName) } } } - else if (strcmp("Intensity",ModeName) == 0) { - std::map Map; + else if (strcmp("Intensity", ModeName) == 0) { + std::map Map; pcObject->getPropertyMap(Map); for (const auto& it : Map) { Base::Type type = it.second->getTypeId(); if (type == Points::PropertyGreyValueList::getClassTypeId()) { - Points::PropertyGreyValueList* greyValues = static_cast(it.second); + Points::PropertyGreyValueList* greyValues = + static_cast(it.second); if (numPoints != greyValues->getSize()) { #ifdef FC_DEBUG SoDebugError::postWarning("ViewProviderPoints::setDisplayMode", - "The number of points (%d) doesn't match with the number of grey values (%d).", numPoints, greyValues->getSize()); + "The number of points (%d) doesn't match with the " + "number of grey values (%d).", + numPoints, + greyValues->getSize()); #endif // Intensity mode is not possible then set the default () mode instead. setDisplayMaskMode("Point"); @@ -205,17 +213,21 @@ void ViewProviderPoints::setDisplayMode(const char* ModeName) } } } - else if (strcmp("Shaded",ModeName) == 0) { - std::map Map; + else if (strcmp("Shaded", ModeName) == 0) { + std::map Map; pcObject->getPropertyMap(Map); for (const auto& it : Map) { Base::Type type = it.second->getTypeId(); if (type == Points::PropertyNormalList::getClassTypeId()) { - Points::PropertyNormalList* normals = static_cast(it.second); + Points::PropertyNormalList* normals = + static_cast(it.second); if (numPoints != normals->getSize()) { #ifdef FC_DEBUG - SoDebugError::postWarning("ViewProviderPoints::setDisplayMode", - "The number of points (%d) doesn't match with the number of normals (%d).", numPoints, normals->getSize()); + SoDebugError::postWarning( + "ViewProviderPoints::setDisplayMode", + "The number of points (%d) doesn't match with the number of normals (%d).", + numPoints, + normals->getSize()); #endif // fallback setDisplayMaskMode("Point"); @@ -228,7 +240,7 @@ void ViewProviderPoints::setDisplayMode(const char* ModeName) } } } - else if (strcmp("Points",ModeName) == 0) { + else if (strcmp("Points", ModeName) == 0) { setDisplayMaskMode("Point"); } @@ -251,17 +263,21 @@ std::vector ViewProviderPoints::getDisplayModes() const #else if (pcObject) { - std::map Map; + std::map Map; pcObject->getPropertyMap(Map); - for (std::map::iterator it = Map.begin(); it != Map.end(); ++it) { + for (std::map::iterator it = Map.begin(); it != Map.end(); + ++it) { Base::Type type = it->second->getTypeId(); - if (type == Points::PropertyNormalList::getClassTypeId()) + if (type == Points::PropertyNormalList::getClassTypeId()) { StrList.push_back("Shaded"); - else if (type == Points::PropertyGreyValueList::getClassTypeId()) + } + else if (type == Points::PropertyGreyValueList::getClassTypeId()) { StrList.push_back("Intensity"); - else if (type == App::PropertyColorList::getClassTypeId()) + } + else if (type == App::PropertyColorList::getClassTypeId()) { StrList.push_back("Color"); + } } } #endif @@ -271,6 +287,7 @@ std::vector ViewProviderPoints::getDisplayModes() const QIcon ViewProviderPoints::getIcon() const { + // clang-format off static const char * const Points_Feature_xpm[] = { "16 16 4 1", ". c none", @@ -295,38 +312,45 @@ QIcon ViewProviderPoints::getIcon() const "rr.......rr..rr."}; QPixmap px(Points_Feature_xpm); return px; + // clang-format on } bool ViewProviderPoints::setEdit(int ModNum) { - if (ModNum == ViewProvider::Transform) + if (ModNum == ViewProvider::Transform) { return ViewProviderGeometryObject::setEdit(ModNum); - else if (ModNum == ViewProvider::Cutting) + } + else if (ModNum == ViewProvider::Cutting) { return true; + } return false; } void ViewProviderPoints::unsetEdit(int ModNum) { - if (ModNum == ViewProvider::Transform) + if (ModNum == ViewProvider::Transform) { ViewProviderGeometryObject::unsetEdit(ModNum); + } } -void ViewProviderPoints::clipPointsCallback(void *, SoEventCallback * n) +void ViewProviderPoints::clipPointsCallback(void*, SoEventCallback* n) { // When this callback function is invoked we must in either case leave the edit mode - Gui::View3DInventorViewer* view = static_cast(n->getUserData()); + Gui::View3DInventorViewer* view = static_cast(n->getUserData()); view->setEditing(false); view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), clipPointsCallback); n->setHandled(); std::vector clPoly = view->getGLPolygon(); - if (clPoly.size() < 3) + if (clPoly.size() < 3) { return; - if (clPoly.front() != clPoly.back()) + } + if (clPoly.front() != clPoly.back()) { clPoly.push_back(clPoly.front()); + } - std::vector views = view->getViewProvidersOfType(ViewProviderPoints::getClassTypeId()); + std::vector views = + view->getViewProvidersOfType(ViewProviderPoints::getClassTypeId()); for (auto it : views) { ViewProviderPoints* that = static_cast(it); if (that->getEditingMode() > -1) { @@ -386,8 +410,8 @@ void ViewProviderScattered::attach(App::DocumentObject* pcObj) } // color shaded ------------------------------------------ - if (std::find(modes.begin(), modes.end(), std::string("Color")) != modes.end() || - std::find(modes.begin(), modes.end(), std::string("Intensity")) != modes.end()) { + if (std::find(modes.begin(), modes.end(), std::string("Color")) != modes.end() + || std::find(modes.begin(), modes.end(), std::string("Intensity")) != modes.end()) { SoGroup* pcColorShadedRoot = new SoGroup(); pcColorShadedRoot->addChild(pcPointStyle); SoMaterialBinding* pcMatBinding = new SoMaterialBinding; @@ -420,12 +444,13 @@ void ViewProviderScattered::updateData(const App::Property* prop) } } -void ViewProviderScattered::cut(const std::vector& picked, Gui::View3DInventorViewer &Viewer) +void ViewProviderScattered::cut(const std::vector& picked, + Gui::View3DInventorViewer& Viewer) { // create the polygon from the picked points Base::Polygon2d cPoly; for (const auto& it : picked) { - cPoly.Add(Base::Vector2d(it[0],it[1])); + cPoly.Add(Base::Vector2d(it[0], it[1])); } // get a reference to the point feature @@ -433,32 +458,36 @@ void ViewProviderScattered::cut(const std::vector& picked, Gui::View3DI const Points::PointKernel& points = fea->Points.getValue(); SoCamera* pCam = Viewer.getSoRenderManager()->getCamera(); - SbViewVolume vol = pCam->getViewVolume(); + SbViewVolume vol = pCam->getViewVolume(); // search for all points inside/outside the polygon std::vector removeIndices; removeIndices.reserve(points.size()); unsigned long index = 0; - for (Points::PointKernel::const_iterator jt = points.begin(); jt != points.end(); ++jt, ++index) { - SbVec3f pt(jt->x,jt->y,jt->z); + for (Points::PointKernel::const_iterator jt = points.begin(); jt != points.end(); + ++jt, ++index) { + SbVec3f pt(jt->x, jt->y, jt->z); // project from 3d to 2d vol.projectToScreen(pt, pt); - if (cPoly.Contains(Base::Vector2d(pt[0],pt[1]))) + if (cPoly.Contains(Base::Vector2d(pt[0], pt[1]))) { removeIndices.push_back(index); + } } - if (removeIndices.empty()) - return; // nothing needs to be done + if (removeIndices.empty()) { + return;// nothing needs to be done + } - //Remove the points from the cloud and open a transaction object for the undo/redo stuff - Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Cut points")); + // Remove the points from the cloud and open a transaction object for the undo/redo stuff + Gui::Application::Instance->activeDocument()->openCommand( + QT_TRANSLATE_NOOP("Command", "Cut points")); // sets the points outside the polygon to update the Inventor node fea->Points.removeIndices(removeIndices); - std::map Map; + std::map Map; pcObject->getPropertyMap(Map); for (const auto& it : Map) { @@ -470,24 +499,30 @@ void ViewProviderScattered::cut(const std::vector& picked, Gui::View3DI static_cast(it.second)->removeIndices(removeIndices); } else if (type == App::PropertyColorList::getClassTypeId()) { - //static_cast(it->second)->removeIndices(removeIndices); - const std::vector& colors = static_cast(it.second)->getValues(); + // static_cast(it->second)->removeIndices(removeIndices); + const std::vector& colors = + static_cast(it.second)->getValues(); - if (removeIndices.size() > colors.size()) + if (removeIndices.size() > colors.size()) { break; + } std::vector remainValue; remainValue.reserve(colors.size() - removeIndices.size()); std::vector::iterator pos = removeIndices.begin(); - for (std::vector::const_iterator jt = colors.begin(); jt != colors.end(); ++jt) { + for (std::vector::const_iterator jt = colors.begin(); jt != colors.end(); + ++jt) { unsigned long index = jt - colors.begin(); - if (pos == removeIndices.end()) - remainValue.push_back( *jt ); - else if (index != *pos) - remainValue.push_back( *jt ); - else + if (pos == removeIndices.end()) { + remainValue.push_back(*jt); + } + else if (index != *pos) { + remainValue.push_back(*jt); + } + else { ++pos; + } } static_cast(it.second)->setValues(remainValue); @@ -547,8 +582,8 @@ void ViewProviderStructured::attach(App::DocumentObject* pcObj) } // color shaded ------------------------------------------ - if (std::find(modes.begin(), modes.end(), std::string("Color")) != modes.end() || - std::find(modes.begin(), modes.end(), std::string("Intensity")) != modes.end()) { + if (std::find(modes.begin(), modes.end(), std::string("Color")) != modes.end() + || std::find(modes.begin(), modes.end(), std::string("Intensity")) != modes.end()) { SoGroup* pcColorShadedRoot = new SoGroup(); pcColorShadedRoot->addChild(pcPointStyle); SoMaterialBinding* pcMatBinding = new SoMaterialBinding; @@ -572,12 +607,13 @@ void ViewProviderStructured::updateData(const App::Property* prop) } } -void ViewProviderStructured::cut(const std::vector& picked, Gui::View3DInventorViewer &Viewer) +void ViewProviderStructured::cut(const std::vector& picked, + Gui::View3DInventorViewer& Viewer) { // create the polygon from the picked points Base::Polygon2d cPoly; for (const auto& it : picked) { - cPoly.Add(Base::Vector2d(it[0],it[1])); + cPoly.Add(Base::Vector2d(it[0], it[1])); } // get a reference to the point feature @@ -585,7 +621,7 @@ void ViewProviderStructured::cut(const std::vector& picked, Gui::View3D const Points::PointKernel& points = fea->Points.getValue(); SoCamera* pCam = Viewer.getSoRenderManager()->getCamera(); - SbViewVolume vol = pCam->getViewVolume(); + SbViewVolume vol = pCam->getViewVolume(); // search for all points inside/outside the polygon Points::PointKernel newKernel; @@ -593,15 +629,16 @@ void ViewProviderStructured::cut(const std::vector& picked, Gui::View3D bool invalidatePoints = false; double nan = std::numeric_limits::quiet_NaN(); - for (const auto & point : points) { + for (const auto& point : points) { // valid point? Base::Vector3d vec(point); - if (!(boost::math::isnan(point.x) || boost::math::isnan(point.y) || boost::math::isnan(point.z))) { - SbVec3f pt(point.x,point.y,point.z); + if (!(boost::math::isnan(point.x) || boost::math::isnan(point.y) + || boost::math::isnan(point.z))) { + SbVec3f pt(point.x, point.y, point.z); // project from 3d to 2d vol.projectToScreen(pt, pt); - if (cPoly.Contains(Base::Vector2d(pt[0],pt[1]))) { + if (cPoly.Contains(Base::Vector2d(pt[0], pt[1]))) { invalidatePoints = true; vec.Set(nan, nan, nan); } @@ -611,8 +648,9 @@ void ViewProviderStructured::cut(const std::vector& picked, Gui::View3D } if (invalidatePoints) { - //Remove the points from the cloud and open a transaction object for the undo/redo stuff - Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Cut points")); + // Remove the points from the cloud and open a transaction object for the undo/redo stuff + Gui::Application::Instance->activeDocument()->openCommand( + QT_TRANSLATE_NOOP("Command", "Cut points")); // sets the points outside the polygon to update the Inventor node fea->Points.setValue(newKernel); @@ -625,21 +663,23 @@ void ViewProviderStructured::cut(const std::vector& picked, Gui::View3D // ------------------------------------------------- -namespace Gui { +namespace Gui +{ /// @cond DOXERR PROPERTY_SOURCE_TEMPLATE(PointsGui::ViewProviderPython, PointsGui::ViewProviderScattered) /// @endcond // explicit template instantiation template class PointsGuiExport ViewProviderPythonFeatureT; -} +}// namespace Gui // ------------------------------------------------- -void ViewProviderPointsBuilder::buildNodes(const App::Property* prop, std::vector& nodes) const +void ViewProviderPointsBuilder::buildNodes(const App::Property* prop, + std::vector& nodes) const { - SoCoordinate3 *pcPointsCoord=nullptr; - SoPointSet *pcPoints=nullptr; + SoCoordinate3* pcPointsCoord = nullptr; + SoPointSet* pcPoints = nullptr; if (nodes.empty()) { pcPointsCoord = new SoCoordinate3(); @@ -648,28 +688,36 @@ void ViewProviderPointsBuilder::buildNodes(const App::Property* prop, std::vecto nodes.push_back(pcPoints); } else if (nodes.size() == 2) { - if (nodes[0]->getTypeId() == SoCoordinate3::getClassTypeId()) + if (nodes[0]->getTypeId() == SoCoordinate3::getClassTypeId()) { pcPointsCoord = static_cast(nodes[0]); - if (nodes[1]->getTypeId() == SoPointSet::getClassTypeId()) + } + if (nodes[1]->getTypeId() == SoPointSet::getClassTypeId()) { pcPoints = static_cast(nodes[1]); + } } - if (pcPointsCoord && pcPoints) + if (pcPointsCoord && pcPoints) { createPoints(prop, pcPointsCoord, pcPoints); + } } -void ViewProviderPointsBuilder::createPoints(const App::Property* prop, SoCoordinate3* coords, SoPointSet* points) const +void ViewProviderPointsBuilder::createPoints(const App::Property* prop, + SoCoordinate3* coords, + SoPointSet* points) const { - const Points::PropertyPointKernel* prop_points = static_cast(prop); + const Points::PropertyPointKernel* prop_points = + static_cast(prop); const Points::PointKernel& cPts = prop_points->getValue(); coords->point.setNum(cPts.size()); SbVec3f* vec = coords->point.startEditing(); // get all points - std::size_t idx=0; + std::size_t idx = 0; const std::vector& kernel = cPts.getBasicPoints(); - for (std::vector::const_iterator it = kernel.begin(); it != kernel.end(); ++it, idx++) { + for (std::vector::const_iterator it = kernel.begin(); + it != kernel.end(); + ++it, idx++) { vec[idx].setValue(it->x, it->y, it->z); } @@ -677,30 +725,36 @@ void ViewProviderPointsBuilder::createPoints(const App::Property* prop, SoCoordi coords->point.finishEditing(); } -void ViewProviderPointsBuilder::createPoints(const App::Property* prop, SoCoordinate3* coords, SoIndexedPointSet* points) const +void ViewProviderPointsBuilder::createPoints(const App::Property* prop, + SoCoordinate3* coords, + SoIndexedPointSet* points) const { - const Points::PropertyPointKernel* prop_points = static_cast(prop); + const Points::PropertyPointKernel* prop_points = + static_cast(prop); const Points::PointKernel& cPts = prop_points->getValue(); coords->point.setNum(cPts.size()); SbVec3f* vec = coords->point.startEditing(); // get all points - std::size_t idx=0; + std::size_t idx = 0; std::vector indices; indices.reserve(cPts.size()); const std::vector& kernel = cPts.getBasicPoints(); - for (std::vector::const_iterator it = kernel.begin(); it != kernel.end(); ++it, idx++) { + for (std::vector::const_iterator it = kernel.begin(); + it != kernel.end(); + ++it, idx++) { vec[idx].setValue(it->x, it->y, it->z); // valid point? - if (!(boost::math::isnan(it->x) || boost::math::isnan(it->y) || boost::math::isnan(it->z))) { + if (!(boost::math::isnan(it->x) || boost::math::isnan(it->y) + || boost::math::isnan(it->z))) { indices.push_back(idx); } } coords->point.finishEditing(); // get all point indices - idx=0; + idx = 0; points->coordIndex.setNum(indices.size()); int32_t* pos = points->coordIndex.startEditing(); for (int32_t index : indices) { diff --git a/src/Mod/Points/Gui/ViewProvider.h b/src/Mod/Points/Gui/ViewProvider.h index 3ee49e304f..f0ab7b003e 100644 --- a/src/Mod/Points/Gui/ViewProvider.h +++ b/src/Mod/Points/Gui/ViewProvider.h @@ -39,24 +39,28 @@ class SoCoordinate3; class SoNormal; class SoEventCallback; -namespace App { - class PropertyColorList; +namespace App +{ +class PropertyColorList; } -namespace Gui { - class SoFCSelection; +namespace Gui +{ +class SoFCSelection; } -namespace Points { - class PropertyGreyValueList; - class PropertyNormalList; - class PointKernel; - class Feature; -} +namespace Points +{ +class PropertyGreyValueList; +class PropertyNormalList; +class PointKernel; +class Feature; +}// namespace Points -namespace PointsGui { +namespace PointsGui +{ -class ViewProviderPointsBuilder : public Gui::ViewProviderBuilder +class ViewProviderPointsBuilder: public Gui::ViewProviderBuilder { public: ViewProviderPointsBuilder() = default; @@ -71,7 +75,7 @@ public: * a node representing the point data structure. * @author Werner Mayer */ -class PointsGuiExport ViewProviderPoints : public Gui::ViewProviderGeometryObject +class PointsGuiExport ViewProviderPoints: public Gui::ViewProviderGeometryObject { PROPERTY_HEADER_WITH_OVERRIDE(PointsGui::ViewProviderPoints); @@ -93,21 +97,21 @@ public: void unsetEdit(int ModNum) override; public: - static void clipPointsCallback(void * ud, SoEventCallback * n); + static void clipPointsCallback(void* ud, SoEventCallback* n); protected: void onChanged(const App::Property* prop) override; void setVertexColorMode(App::PropertyColorList*); void setVertexGreyvalueMode(Points::PropertyGreyValueList*); void setVertexNormalMode(Points::PropertyNormalList*); - virtual void cut(const std::vector& picked, Gui::View3DInventorViewer &Viewer) = 0; + virtual void cut(const std::vector& picked, Gui::View3DInventorViewer& Viewer) = 0; protected: - Gui::SoFCSelection * pcHighlight; - SoCoordinate3 * pcPointsCoord; - SoMaterial * pcColorMat; - SoNormal * pcPointsNormal; - SoDrawStyle * pcPointStyle; + Gui::SoFCSelection* pcHighlight; + SoCoordinate3* pcPointsCoord; + SoMaterial* pcColorMat; + SoNormal* pcPointsNormal; + SoDrawStyle* pcPointStyle; private: static App::PropertyFloatConstraint::Constraints floatRange; @@ -118,7 +122,7 @@ private: * a node representing the scattered point cloud. * @author Werner Mayer */ -class PointsGuiExport ViewProviderScattered : public ViewProviderPoints +class PointsGuiExport ViewProviderScattered: public ViewProviderPoints { PROPERTY_HEADER_WITH_OVERRIDE(PointsGui::ViewProviderScattered); @@ -130,15 +134,15 @@ public: * Extracts the point data from the feature \a pcFeature and creates * an Inventor node \a SoNode with these data. */ - void attach(App::DocumentObject *) override; + void attach(App::DocumentObject*) override; /// Update the point representation void updateData(const App::Property*) override; protected: - void cut(const std::vector& picked, Gui::View3DInventorViewer &Viewer) override; + void cut(const std::vector& picked, Gui::View3DInventorViewer& Viewer) override; protected: - SoPointSet * pcPoints; + SoPointSet* pcPoints; }; /** @@ -146,7 +150,7 @@ protected: * a node representing the structured points. * @author Werner Mayer */ -class PointsGuiExport ViewProviderStructured : public ViewProviderPoints +class PointsGuiExport ViewProviderStructured: public ViewProviderPoints { PROPERTY_HEADER_WITH_OVERRIDE(PointsGui::ViewProviderStructured); @@ -158,21 +162,20 @@ public: * Extracts the point data from the feature \a pcFeature and creates * an Inventor node \a SoNode with these data. */ - void attach(App::DocumentObject *) override; + void attach(App::DocumentObject*) override; /// Update the point representation void updateData(const App::Property*) override; protected: - void cut(const std::vector& picked, Gui::View3DInventorViewer &Viewer) override; + void cut(const std::vector& picked, Gui::View3DInventorViewer& Viewer) override; protected: - SoIndexedPointSet * pcPoints; + SoIndexedPointSet* pcPoints; }; using ViewProviderPython = Gui::ViewProviderPythonFeatureT; -} // namespace PointsGui +}// namespace PointsGui -#endif // POINTSGUI_VIEWPROVIDERPOINTS_H - +#endif// POINTSGUI_VIEWPROVIDERPOINTS_H diff --git a/src/Mod/Points/Gui/Workbench.cpp b/src/Mod/Points/Gui/Workbench.cpp index cc84a176b1..c2b386b8b5 100644 --- a/src/Mod/Points/Gui/Workbench.cpp +++ b/src/Mod/Points/Gui/Workbench.cpp @@ -30,7 +30,7 @@ using namespace PointsGui; -#if 0 // needed for Qt's lupdate utility +#if 0// needed for Qt's lupdate utility qApp->translate("Workbench", "Points tools"); qApp->translate("Workbench", "&Points"); #endif @@ -45,7 +45,7 @@ Workbench::~Workbench() = default; Gui::ToolBarItem* Workbench::setupToolBars() const { Gui::ToolBarItem* root = StdWorkbench::setupToolBars(); - Gui::ToolBarItem* pnt = new Gui::ToolBarItem( root ); + Gui::ToolBarItem* pnt = new Gui::ToolBarItem(root); pnt->setCommand("Points tools"); *pnt << "Points_Import" << "Points_Export" @@ -61,7 +61,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const { // point tools Gui::ToolBarItem* root = new Gui::ToolBarItem; - Gui::ToolBarItem* pnt = new Gui::ToolBarItem( root ); + Gui::ToolBarItem* pnt = new Gui::ToolBarItem(root); pnt->setCommand("Points tools"); *pnt << "Points_Import" << "Points_Export" diff --git a/src/Mod/Points/Gui/Workbench.h b/src/Mod/Points/Gui/Workbench.h index 79628e5142..16d7172d00 100644 --- a/src/Mod/Points/Gui/Workbench.h +++ b/src/Mod/Points/Gui/Workbench.h @@ -27,26 +27,27 @@ #include #include -namespace PointsGui { +namespace PointsGui +{ /** * @author Werner Mayer */ -class PointsGuiExport Workbench : public Gui::StdWorkbench +class PointsGuiExport Workbench: public Gui::StdWorkbench { TYPESYSTEM_HEADER_WITH_OVERRIDE(); public: - Workbench(); - ~Workbench() override; + Workbench(); + ~Workbench() override; protected: - Gui::ToolBarItem* setupToolBars() const override; - Gui::ToolBarItem* setupCommandBars() const override; - Gui::MenuItem* setupMenuBar() const override; + Gui::ToolBarItem* setupToolBars() const override; + Gui::ToolBarItem* setupCommandBars() const override; + Gui::MenuItem* setupMenuBar() const override; }; -} // namespace PointsGui +}// namespace PointsGui -#endif // POINTS_WORKBENCH_H +#endif// POINTS_WORKBENCH_H diff --git a/src/Mod/Points/Init.py b/src/Mod/Points/Init.py index c2e0a6f0e2..ea3e1bd2f8 100644 --- a/src/Mod/Points/Init.py +++ b/src/Mod/Points/Init.py @@ -1,28 +1,28 @@ -#*************************************************************************** -#* Copyright (c) 2004,2005 Juergen Riegel * -#* * -#* This file is part of the FreeCAD CAx development system. * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* FreeCAD is distributed in the hope that it will be useful, * -#* but WITHOUT ANY WARRANTY; without even the implied warranty of * -#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -#* GNU Lesser General Public License for more details. * -#* * -#* You should have received a copy of the GNU Library General Public * -#* License along with FreeCAD; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#***************************************************************************/ +# *************************************************************************** +# * Copyright (c) 2004,2005 Juergen Riegel * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * FreeCAD is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Lesser General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with FreeCAD; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# ***************************************************************************/ # FreeCAD init script of the Points module # Append the open handler -FreeCAD.addImportType("Point formats (*.asc *.pcd *.ply *.e57)","Points") -FreeCAD.addExportType("Point formats (*.asc *.pcd *.ply)","Points") +FreeCAD.addImportType("Point formats (*.asc *.pcd *.ply *.e57)", "Points") +FreeCAD.addExportType("Point formats (*.asc *.pcd *.ply)", "Points") diff --git a/src/Mod/Points/InitGui.py b/src/Mod/Points/InitGui.py index 9bbcf39b0f..c54214f071 100644 --- a/src/Mod/Points/InitGui.py +++ b/src/Mod/Points/InitGui.py @@ -1,25 +1,25 @@ -#*************************************************************************** -#* Copyright (c) 2002,2003 Juergen Riegel * -#* * -#* This file is part of the FreeCAD CAx development system. * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* FreeCAD is distributed in the hope that it will be useful, * -#* but WITHOUT ANY WARRANTY; without even the implied warranty of * -#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -#* GNU Lesser General Public License for more details. * -#* * -#* You should have received a copy of the GNU Library General Public * -#* License along with FreeCAD; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#***************************************************************************/ +# *************************************************************************** +# * Copyright (c) 2002,2003 Juergen Riegel * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * FreeCAD is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Lesser General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with FreeCAD; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# ***************************************************************************/ # Points gui init module # @@ -27,17 +27,23 @@ # This is the second one of three init scripts, the third one # runs when the gui is up -class PointsWorkbench ( Workbench ): + +class PointsWorkbench(Workbench): "Points workbench object" + def __init__(self): - self.__class__.Icon = FreeCAD.getResourceDir() + "Mod/Points/Resources/icons/PointsWorkbench.svg" + self.__class__.Icon = ( + FreeCAD.getResourceDir() + "Mod/Points/Resources/icons/PointsWorkbench.svg" + ) self.__class__.MenuText = "Points" self.__class__.ToolTip = "Points workbench" def Initialize(self): # load the module import PointsGui + def GetClassName(self): return "PointsGui::Workbench" + Gui.addWorkbench(PointsWorkbench()) diff --git a/src/Mod/Points/PointsGlobal.h b/src/Mod/Points/PointsGlobal.h index 5ba83d6b96..36f3ac3783 100644 --- a/src/Mod/Points/PointsGlobal.h +++ b/src/Mod/Points/PointsGlobal.h @@ -29,19 +29,19 @@ // Points #ifndef PointsExport #ifdef Points_EXPORTS -# define PointsExport FREECAD_DECL_EXPORT +#define PointsExport FREECAD_DECL_EXPORT #else -# define PointsExport FREECAD_DECL_IMPORT +#define PointsExport FREECAD_DECL_IMPORT #endif #endif // PointsGui #ifndef PointsGuiExport #ifdef PointsGui_EXPORTS -# define PointsGuiExport FREECAD_DECL_EXPORT +#define PointsGuiExport FREECAD_DECL_EXPORT #else -# define PointsGuiExport FREECAD_DECL_IMPORT +#define PointsGuiExport FREECAD_DECL_IMPORT #endif #endif -#endif //POINTS_GLOBAL_H +#endif// POINTS_GLOBAL_H diff --git a/src/Mod/Points/pointscommands/commands.py b/src/Mod/Points/pointscommands/commands.py index 408ed76a40..890cf9e7c4 100644 --- a/src/Mod/Points/pointscommands/commands.py +++ b/src/Mod/Points/pointscommands/commands.py @@ -32,6 +32,7 @@ __url__ = "https://www.freecad.org" import FreeCAD import Points + def make_points_from_geometry(geometries, distance): for geom in geometries: global_plm = geom.getGlobalPlacement() @@ -54,8 +55,10 @@ def make_points_from_geometry(geometries, distance): points.Points = kernel points.Placement = plm - if len(points_and_normals[1]) > 0 and len(points_and_normals[0]) == len(points_and_normals[1]): + if len(points_and_normals[1]) > 0 and len(points_and_normals[0]) == len( + points_and_normals[1] + ): points.addProperty("Points::PropertyNormalList", "Normal") points.Normal = points_and_normals[1] - points.purgeTouched() \ No newline at end of file + points.purgeTouched()