Points: apply clang-formatting

This commit is contained in:
wmayer
2023-09-01 17:33:18 +02:00
committed by wwmayer
parent 047c39cb4c
commit c91b82db0b
32 changed files with 2829 additions and 2359 deletions

View File

@@ -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
}

View File

@@ -22,7 +22,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <memory>
#include <memory>
#endif
#include <App/Application.h>
@@ -31,8 +31,8 @@
#include <App/DocumentObjectPy.h>
#include <App/Property.h>
#include <Base/Console.h>
#include <Base/Interpreter.h>
#include <Base/FileInfo.h>
#include <Base/Interpreter.h>
#include "Points.h"
#include "PointsAlgos.h"
@@ -41,29 +41,32 @@
#include "Structured.h"
namespace Points {
class Module : public Py::ExtensionModule<Module>
namespace Points
{
class Module: public Py::ExtensionModule<Module>
{
public:
Module() : Py::ExtensionModule<Module>("Points")
Module()
: Py::ExtensionModule<Module>("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<bool, bool, double> readE57Settings() const
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Points/E57");
Base::Reference<ParameterGrp> 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> reader;
if (file.hasExtension("asc")) {
@@ -92,7 +97,9 @@ private:
}
else if (file.hasExtension("e57")) {
auto setting = readE57Settings();
reader = std::make_unique<E57Reader>(std::get<0>(setting), std::get<1>(setting), std::get<2>(setting));
reader = std::make_unique<E57Reader>(std::get<0>(setting),
std::get<1>(setting),
std::get<2>(setting));
}
else if (file.hasExtension("ply")) {
reader = std::make_unique<PlyReader>();
@@ -114,13 +121,13 @@ private:
if (reader->isStructured()) {
pcFeature = new Points::StructuredCustom();
App::PropertyInteger* width = static_cast<App::PropertyInteger*>
(pcFeature->getPropertyByName("Width"));
App::PropertyInteger* width =
static_cast<App::PropertyInteger*>(pcFeature->getPropertyByName("Width"));
if (width) {
width->setValue(reader->getWidth());
}
App::PropertyInteger* height = static_cast<App::PropertyInteger*>
(pcFeature->getPropertyByName("Height"));
App::PropertyInteger* height =
static_cast<App::PropertyInteger*>(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<Points::PropertyGreyValueList*>
(pcFeature->addDynamicProperty("Points::PropertyGreyValueList", "Intensity"));
Points::PropertyGreyValueList* prop =
static_cast<Points::PropertyGreyValueList*>(
pcFeature->addDynamicProperty("Points::PropertyGreyValueList",
"Intensity"));
if (prop) {
prop->setValues(reader->getIntensities());
}
}
// add colors
if (reader->hasColors()) {
App::PropertyColorList* prop = static_cast<App::PropertyColorList*>
(pcFeature->addDynamicProperty("App::PropertyColorList", "Color"));
App::PropertyColorList* prop = static_cast<App::PropertyColorList*>(
pcFeature->addDynamicProperty("App::PropertyColorList", "Color"));
if (prop) {
prop->setValues(reader->getColors());
}
}
// add normals
if (reader->hasNormals()) {
Points::PropertyNormalList* prop = static_cast<Points::PropertyNormalList*>
(pcFeature->addDynamicProperty("Points::PropertyNormalList", "Normal"));
Points::PropertyNormalList* prop = static_cast<Points::PropertyNormalList*>(
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> reader;
if (file.hasExtension("asc")) {
@@ -208,7 +219,9 @@ private:
}
else if (file.hasExtension("e57")) {
auto setting = readE57Settings();
reader = std::make_unique<E57Reader>(std::get<0>(setting), std::get<1>(setting), std::get<2>(setting));
reader = std::make_unique<E57Reader>(std::get<0>(setting),
std::get<1>(setting),
std::get<2>(setting));
}
else if (file.hasExtension("ply")) {
reader = std::make_unique<PlyReader>();
@@ -233,13 +246,13 @@ private:
if (reader->isStructured()) {
pcFeature = new Points::StructuredCustom();
App::PropertyInteger* width = static_cast<App::PropertyInteger*>
(pcFeature->getPropertyByName("Width"));
App::PropertyInteger* width =
static_cast<App::PropertyInteger*>(pcFeature->getPropertyByName("Width"));
if (width) {
width->setValue(reader->getWidth());
}
App::PropertyInteger* height = static_cast<App::PropertyInteger*>
(pcFeature->getPropertyByName("Height"));
App::PropertyInteger* height =
static_cast<App::PropertyInteger*>(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<Points::PropertyGreyValueList*>
(pcFeature->addDynamicProperty("Points::PropertyGreyValueList", "Intensity"));
Points::PropertyGreyValueList* prop =
static_cast<Points::PropertyGreyValueList*>(
pcFeature->addDynamicProperty("Points::PropertyGreyValueList",
"Intensity"));
if (prop) {
prop->setValues(reader->getIntensities());
}
}
// add colors
if (reader->hasColors()) {
App::PropertyColorList* prop = static_cast<App::PropertyColorList*>
(pcFeature->addDynamicProperty("App::PropertyColorList", "Color"));
App::PropertyColorList* prop = static_cast<App::PropertyColorList*>(
pcFeature->addDynamicProperty("App::PropertyColorList", "Color"));
if (prop) {
prop->setValues(reader->getColors());
}
}
// add normals
if (reader->hasNormals()) {
Points::PropertyNormalList* prop = static_cast<Points::PropertyNormalList*>
(pcFeature->addDynamicProperty("Points::PropertyNormalList", "Normal"));
Points::PropertyNormalList* prop = static_cast<Points::PropertyNormalList*>(
pcFeature->addDynamicProperty("Points::PropertyNormalList", "Normal"));
if (prop) {
prop->setValues(reader->getNormals());
}
@@ -280,8 +295,8 @@ private:
pcFeature->purgeTouched();
}
else {
Points::Feature* pcFeature = static_cast<Points::Feature*>
(pcDoc->addObject("Points::Feature", file.fileNamePure().c_str()));
Points::Feature* pcFeature = static_cast<Points::Feature*>(
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<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
App::DocumentObject* obj =
static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
if (obj->getTypeId().isDerivedFrom(pointsId)) {
// get relative placement
Points::Feature* fea = static_cast<Points::Feature*>(obj);
@@ -338,31 +356,32 @@ private:
}
// get additional properties if there
App::PropertyInteger* width = dynamic_cast<App::PropertyInteger*>
(fea->getPropertyByName("Width"));
App::PropertyInteger* width =
dynamic_cast<App::PropertyInteger*>(fea->getPropertyByName("Width"));
if (width) {
writer->setWidth(width->getValue());
}
App::PropertyInteger* height = dynamic_cast<App::PropertyInteger*>
(fea->getPropertyByName("Height"));
App::PropertyInteger* height =
dynamic_cast<App::PropertyInteger*>(fea->getPropertyByName("Height"));
if (height) {
writer->setHeight(height->getValue());
}
// get gray values
Points::PropertyGreyValueList* grey = dynamic_cast<Points::PropertyGreyValueList*>
(fea->getPropertyByName("Intensity"));
Points::PropertyGreyValueList* grey =
dynamic_cast<Points::PropertyGreyValueList*>(
fea->getPropertyByName("Intensity"));
if (grey) {
writer->setIntensities(grey->getValues());
}
// get colors
App::PropertyColorList* col = dynamic_cast<App::PropertyColorList*>
(fea->getPropertyByName("Color"));
App::PropertyColorList* col =
dynamic_cast<App::PropertyColorList*>(fea->getPropertyByName("Color"));
if (col) {
writer->setColors(col->getValues());
}
// get normals
Points::PropertyNormalList* nor = dynamic_cast<Points::PropertyNormalList*>
(fea->getPropertyByName("Normal"));
Points::PropertyNormalList* nor =
dynamic_cast<Points::PropertyNormalList*>(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<PointsPy*>(pcObj);
Points::Feature* pcFeature = static_cast<Points::Feature*>(pcDoc->addObject("Points::Feature", name));
Points::Feature* pcFeature =
static_cast<Points::Feature*>(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

View File

@@ -22,10 +22,10 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <cmath>
# include <iostream>
# include <QtConcurrentMap>
# include <boost/math/special_functions/fpclassify.hpp>
#include <QtConcurrentMap>
#include <boost/math/special_functions/fpclassify.hpp>
#include <cmath>
#include <iostream>
#endif
#include <Base/Matrix.h>
@@ -37,7 +37,7 @@
#ifdef _MSC_VER
# include <ppl.h>
#include <ppl.h>
#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<const char*> PointKernel::getElementTypes() const
{
std::vector<const char*> 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<value_type>& 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<Base::BoundBox3d> 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::value_type> PointKernel::getValidPoints() const
{
std::vector<PointKernel::value_type> 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<float_type>(it.x),
static_cast<float_type>(it.y),
static_cast<float_type>(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<float_type>(it.x),
static_cast<float_type>(it.y),
static_cast<float_type>(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()
<< "<Points file=\"" << writer.addFile(writer.ObjectName.c_str(), this) << "\" "
<< "mtrx=\"" << _Mtrx.toString() << "\"/>" << std::endl;
writer.Stream() << writer.ind() << "<Points file=\""
<< writer.addFile(writer.ObjectName.c_str(), this) << "\" "
<< "mtrx=\"" << _Mtrx.toString() << "\"/>" << 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<Base::Vector3d> &Points,
std::vector<Base::Vector3d> &/*Normals*/,
double /*Accuracy*/, uint16_t /*flags*/) const
void PointKernel::getPoints(std::vector<Base::Vector3d>& Points,
std::vector<Base::Vector3d>& /*Normals*/,
double /*Accuracy*/,
uint16_t /*flags*/) const
{
unsigned long ctpoints = _Points.size();
Points.reserve(ctpoints);
for (unsigned long i=0; i<ctpoints; i++) {
for (unsigned long i = 0; i < ctpoints; i++) {
Points.push_back(this->getPoint(i));
}
}
// ----------------------------------------------------------------------------
PointKernel::const_point_iterator::const_point_iterator
(const PointKernel* kernel, std::vector<kernel_type>::const_iterator index)
: _kernel(kernel), _p_it(index)
PointKernel::const_point_iterator::const_point_iterator(
const PointKernel* kernel,
std::vector<kernel_type>::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;
}

View File

@@ -24,8 +24,8 @@
#ifndef POINTS_POINT_H
#define POINTS_POINT_H
#include <vector>
#include <iterator>
#include <vector>
#include <App/ComplexGeoData.h>
#include <App/PropertyGeo.h>
@@ -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<value_type>& getBasicPoints()
{ return this->_Points; }
{
return this->_Points;
}
const std::vector<value_type>& getBasicPoints() const
{ return this->_Points; }
{
return this->_Points;
}
void setBasicPoints(const std::vector<value_type>& pts)
{ this->_Points = pts; }
{
this->_Points = pts;
}
void swap(std::vector<value_type>& pts)
{ this->_Points.swap(pts); }
{
this->_Points.swap(pts);
}
void getPoints(std::vector<Base::Vector3d> &Points,
std::vector<Base::Vector3d> &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<Base::Vector3d>& Points,
std::vector<Base::Vector3d>& 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<value_type> 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

File diff suppressed because it is too large Load Diff

View File

@@ -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<std::string>& fields, std::vector<std::string>& types,
std::vector<int>& sizes);
std::size_t readHeader(std::istream&,
std::string& format,
std::size_t& offset,
std::vector<std::string>& fields,
std::vector<std::string>& types,
std::vector<int>& 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<std::string>& types,
const std::vector<int>& sizes,
Eigen::MatrixXd& data);
void readBinary(bool swapByteOrder,
std::istream&,
std::size_t offset,
const std::vector<std::string>& types,
const std::vector<int>& 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<std::string>& fields,
std::vector<std::string>& types, std::vector<int>& sizes);
std::size_t readHeader(std::istream&,
std::string& format,
std::vector<std::string>& fields,
std::vector<std::string>& types,
std::vector<int>& sizes);
void readAscii(std::istream&, Eigen::MatrixXd& data);
void readBinary(bool transpose, std::istream&,
const std::vector<std::string>& types,
const std::vector<int>& sizes,
Eigen::MatrixXd& data);
void readBinary(bool transpose,
std::istream&,
const std::vector<std::string>& types,
const std::vector<int>& 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

View File

@@ -23,7 +23,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <vector>
#include <vector>
#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<Points::Feature>;
}
}// 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<Points::Feature>;
}
}// namespace App

View File

@@ -23,20 +23,22 @@
#ifndef POINTS_FEATURE_H
#define POINTS_FEATURE_H
#include <App/GeoFeature.h> // must be first include
#include <App/FeatureCustom.h>
#include <App/FeaturePython.h>
#include <App/GeoFeature.h>// must be first include
#include <App/PropertyGeo.h>
#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<Feature>;
using FeaturePython = App::FeaturePythonT<Feature>;
} //namespace Points
}// namespace Points
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -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<unsigned long> &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<unsigned long> &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<unsigned long> &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<unsigned long> &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<unsigned long>& 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<unsigned long>& 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<unsigned long>& 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<unsigned long>& 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<unsigned long>& 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<unsigned long> &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<unsigned long>& 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<unsigned long>& 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<unsigned long> &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<unsigned long>& raclInd) const;
protected:
std::vector<std::vector<std::vector<std::set<unsigned long> > > > _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<std::vector<std::vector<std::set<unsigned long>>>>
_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<unsigned long> &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<unsigned long>& 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<unsigned long> &raulElements);
/** Searches for facets around the ray. */
bool InitOnRay (const Base::Vector3d &rclPt, const Base::Vector3d &rclDir, float fMaxSearchArea, std::vector<unsigned long> &raulElements);
/** Searches for facets around the ray. */
bool NextOnRay (std::vector<unsigned long> &raulElements);
//@}
/** @name Tests with rays */
//@{
/** Searches for facets around the ray. */
bool InitOnRay(const Base::Vector3d& rclPt,
const Base::Vector3d& rclDir,
std::vector<unsigned long>& raulElements);
/** Searches for facets around the ray. */
bool InitOnRay(const Base::Vector3d& rclPt,
const Base::Vector3d& rclDir,
float fMaxSearchArea,
std::vector<unsigned long>& raulElements);
/** Searches for facets around the ray. */
bool NextOnRay(std::vector<unsigned long>& 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<GridElement> _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<GridElement> _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

View File

@@ -22,7 +22,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <boost/math/special_functions/fpclassify.hpp>
#include <boost/math/special_functions/fpclassify.hpp>
#endif
#include <Base/Builder3D.h>
@@ -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 {"<PointKernel object>"};
}
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<PointsPy*>(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<Base::Vector3f> points;
PointKernel* kernel = getPointKernelPtr();
points.reserve(kernel->size());
for (const auto & it : *kernel) {
for (const auto& it : *kernel) {
points.push_back(Base::convertTo<Base::Vector3f>(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<int>(points->size());
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
long index = static_cast<long>(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<PointKernel> 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;
}

View File

@@ -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 <cstdio>
#include <cstdio>
// STL
# include <algorithm>
# include <cmath>
# include <iostream>
# include <memory>
# include <set>
# include <sstream>
# include <vector>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <memory>
#include <set>
#include <sstream>
#include <vector>
// boost
# include <boost/lexical_cast.hpp>
# include <boost/regex.hpp>
# include <boost/algorithm/string.hpp>
# include <boost/math/special_functions/fpclassify.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/math/special_functions/fpclassify.hpp>
#include <boost/regex.hpp>
// Qt
# include <QtConcurrentMap>
#include <QtConcurrentMap>
#endif //_PreComp_
#endif//_PreComp_
#endif

View File

@@ -22,10 +22,10 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <algorithm>
# include <cmath>
# include <iostream>
# include <QtConcurrentMap>
#include <QtConcurrentMap>
#include <algorithm>
#include <cmath>
#include <iostream>
#endif
#include <Base/Converter.h>
@@ -35,11 +35,11 @@
#include <Base/VectorPy.h>
#include <Base/Writer.h>
#include "Properties.h"
#include "Points.h"
#include "Properties.h"
#ifdef _MSC_VER
# include <ppl.h>
#include <ppl.h>
#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<float>& values)
hasSetValue();
}
PyObject *PropertyGreyValueList::getPyObject()
PyObject* PropertyGreyValueList::getPyObject()
{
PyObject* list = PyList_New(getSize());
for (int i = 0;i<getSize(); i++)
PyList_SetItem( list, i, PyFloat_FromDouble(_lValueList[i]));
for (int i = 0; i < getSize(); i++) {
PyList_SetItem(list, i, PyFloat_FromDouble(_lValueList[i]));
}
return list;
}
void PropertyGreyValueList::setPyObject(PyObject *value)
{
void PropertyGreyValueList::setPyObject(PyObject* value)
{
if (PyList_Check(value)) {
Py_ssize_t nSize = PyList_Size(value);
std::vector<float> values;
values.resize(nSize);
for (Py_ssize_t i=0; i<nSize;++i) {
for (Py_ssize_t i = 0; i < nSize; ++i) {
PyObject* item = PyList_GetItem(value, i);
if (!PyFloat_Check(item)) {
std::string error = std::string("type in list must be float, not ");
error += item->ob_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() << "<FloatList count=\"" << getSize() <<"\">" << endl;
writer.Stream() << writer.ind() << "<FloatList count=\"" << getSize() << "\">" << endl;
writer.incInd();
for(int i = 0;i<getSize(); i++)
writer.Stream() << writer.ind() << "<F v=\"" << _lValueList[i] <<"\"/>" << endl; ;
for (int i = 0; i < getSize(); i++) {
writer.Stream() << writer.ind() << "<F v=\"" << _lValueList[i] << "\"/>" << endl;
};
writer.decInd();
writer.Stream() << writer.ind() <<"</FloatList>" << endl ;
writer.Stream() << writer.ind() << "</FloatList>" << endl;
}
else {
writer.Stream() << writer.ind() << "<FloatList file=\"" <<
writer.addFile(getName(), this) << "\"/>" << std::endl;
writer.Stream() << writer.ind() << "<FloatList file=\"" << writer.addFile(getName(), this)
<< "\"/>" << 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<float> 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<const PropertyGreyValueList&>(from)._lValueList;
hasSetValue();
}
unsigned int PropertyGreyValueList::getMemSize () const
unsigned int PropertyGreyValueList::getMemSize() const
{
return static_cast<unsigned int>(_lValueList.size() * sizeof(float));
}
void PropertyGreyValueList::removeIndices( const std::vector<unsigned long>& uIndices )
void PropertyGreyValueList::removeIndices(const std::vector<unsigned long>& uIndices)
{
// We need a sorted array
std::vector<unsigned long> uSortedInds = uIndices;
@@ -192,22 +194,26 @@ void PropertyGreyValueList::removeIndices( const std::vector<unsigned long>& uIn
const std::vector<float>& 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<float> remainValue;
remainValue.reserve(rValueList.size() - uSortedInds.size());
std::vector<unsigned long>::iterator pos = uSortedInds.begin();
for ( std::vector<float>::const_iterator it = rValueList.begin(); it != rValueList.end(); ++it ) {
for (std::vector<float>::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<Base::Vector3f>& values)
hasSetValue();
}
PyObject *PropertyNormalList::getPyObject()
PyObject* PropertyNormalList::getPyObject()
{
PyObject* list = PyList_New(getSize());
for (int i = 0;i<getSize(); i++)
for (int i = 0; i < getSize(); i++) {
PyList_SetItem(list, i, new Base::VectorPy(_lValueList[i]));
}
return list;
}
void PropertyNormalList::setPyObject(PyObject *value)
void PropertyNormalList::setPyObject(PyObject* value)
{
if (PyList_Check(value)) {
Py_ssize_t nSize = PyList_Size(value);
std::vector<Base::Vector3f> values;
values.resize(nSize);
for (Py_ssize_t i=0; i<nSize;++i) {
for (Py_ssize_t i = 0; i < nSize; ++i) {
PyObject* item = PyList_GetItem(value, i);
App::PropertyVector val;
val.setPyObject( item );
val.setPyObject(item);
values[i] = Base::convertTo<Base::Vector3f>(val.getValue());
}
setValues(values);
}
else if (PyObject_TypeCheck(value, &(Base::VectorPy::Type))) {
Base::VectorPy *pcObject = static_cast<Base::VectorPy*>(value);
Base::VectorPy* pcObject = static_cast<Base::VectorPy*>(value);
Base::Vector3d* val = pcObject->getVectorPtr();
setValue(Base::convertTo<Base::Vector3f>(*val));
}
else if (PyTuple_Check(value) && PyTuple_Size(value) == 3) {
App::PropertyVector val;
val.setPyObject( value );
val.setPyObject(value);
setValue(Base::convertTo<Base::Vector3f>(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() << "<VectorList file=\"" << writer.addFile(getName(), this) << "\"/>" << std::endl;
writer.Stream() << writer.ind() << "<VectorList file=\"" << writer.addFile(getName(), this)
<< "\"/>" << 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<Base::Vector3f> 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<const PropertyNormalList&>(from)._lValueList;
hasSetValue();
}
unsigned int PropertyNormalList::getMemSize () const
unsigned int PropertyNormalList::getMemSize() const
{
return static_cast<unsigned int>(_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<unsigned long>& uIndices )
void PropertyNormalList::removeIndices(const std::vector<unsigned long>& uIndices)
{
// We need a sorted array
std::vector<unsigned long> uSortedInds = uIndices;
@@ -396,22 +406,28 @@ void PropertyNormalList::removeIndices( const std::vector<unsigned long>& uIndic
const std::vector<Base::Vector3f>& 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<Base::Vector3f> remainValue;
remainValue.reserve(rValueList.size() - uSortedInds.size());
std::vector<unsigned long>::iterator pos = uSortedInds.begin();
for ( std::vector<Base::Vector3f>::const_iterator it = rValueList.begin(); it != rValueList.end(); ++it ) {
for (std::vector<Base::Vector3f>::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<CurvatureInfo>& lValues)
{
aboutToSetValue();
_lValueList=lValues;
_lValueList = lValues;
hasSetValue();
}
std::vector<float> PropertyCurvatureList::getCurvature( int mode ) const
std::vector<float> PropertyCurvatureList::getCurvature(int mode) const
{
const std::vector<Points::CurvatureInfo>& fCurvInfo = getValues();
std::vector<float> fValues;
@@ -442,42 +458,44 @@ std::vector<float> 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<getSize(); ii++) {
for (int ii = 0; ii < getSize(); ii++) {
CurvatureInfo ci = operator[](ii);
ci.cMaxCurvDir = rot * ci.cMaxCurvDir;
ci.cMinCurvDir = rot * ci.cMinCurvDir;
@@ -512,81 +530,89 @@ void PropertyCurvatureList::transformGeometry(const Base::Matrix4D &mat)
hasSetValue();
}
void PropertyCurvatureList::removeIndices( const std::vector<unsigned long>& uIndices )
void PropertyCurvatureList::removeIndices(const std::vector<unsigned long>& uIndices)
{
// We need a sorted array
std::vector<unsigned long> 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<CurvatureInfo> remainValue;
remainValue.reserve(_lValueList.size() - uSortedInds.size());
std::vector<unsigned long>::iterator pos = uSortedInds.begin();
for ( std::vector<CurvatureInfo>::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it ) {
for (std::vector<CurvatureInfo>::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() << "<CurvatureList file=\"" << writer.addFile(getName(), this) << "\"/>" << std::endl;
writer.Stream() << writer.ind() << "<CurvatureList file=\""
<< writer.addFile(getName(), this) << "\"/>" << 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<CurvatureInfo> 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<const PropertyCurvatureList&>(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();
}

View File

@@ -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<float>& values);
const std::vector<float> &getValues() const {
void setValues(const std::vector<float>& values);
const std::vector<float>& 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<unsigned long>& );
void removeIndices(const std::vector<unsigned long>&);
//@}
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<Base::Vector3f>& values);
void setValues(const std::vector<Base::Vector3f>& values);
const std::vector<Base::Vector3f> &getValues() const {
const std::vector<Base::Vector3f>& 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<unsigned long>& );
void transformGeometry(const Base::Matrix4D& rclMat);
void removeIndices(const std::vector<unsigned long>&);
//@}
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<CurvatureInfo>&);
std::vector<float> getCurvature( int tMode) const;
std::vector<float> 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<CurvatureInfo> &getValues() const {
const std::vector<CurvatureInfo>& 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<unsigned long>& );
void transformGeometry(const Base::Matrix4D& rclMat);
void removeIndices(const std::vector<unsigned long>&);
//@}
private:
std::vector<CurvatureInfo> _lValueList;
};
} // namespace Points
}// namespace Points
#endif // POINTS_POINTPROPERTIES_H
#endif// POINTS_POINTPROPERTIES_H

View File

@@ -23,27 +23,25 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <algorithm>
# include <cmath>
# include <iostream>
#include <algorithm>
#include <cmath>
#include <iostream>
#endif
#include <Base/Matrix.h>
#include <Base/Writer.h>
#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<PointsPy*>(value);
setValue( *(pcObject->getPointKernelPtr()));
PointsPy* pcObject = static_cast<PointsPy*>(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<const PropertyPointKernel&>(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<unsigned long>& uIndices )
void PropertyPointKernel::removeIndices(const std::vector<unsigned long>& uIndices)
{
// We need a sorted array
std::vector<unsigned long> 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<unsigned long>& uIndi
std::vector<unsigned long>::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);

View File

@@ -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<unsigned long>& );
void transformGeometry(const Base::Matrix4D& rclMat) override;
void removeIndices(const std::vector<unsigned long>&);
//@}
private:
Base::Reference<PointKernel> _cPoints;
};
} // namespace Points
}// namespace Points
#endif // POINTS_PROPERTYPOINTKERNEL_H
#endif// POINTS_PROPERTYPOINTKERNEL_H

View File

@@ -23,7 +23,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <vector>
#include <vector>
#endif
#include "Structured.h"
@@ -62,30 +62,32 @@ PROPERTY_SOURCE(Points::Structured, Points::Feature)
Structured::Structured()
{
// App::PropertyType type = static_cast<App::PropertyType>(App::Prop_None);
// App::PropertyType type = static_cast<App::PropertyType>(App::Prop_None);
App::PropertyType type = static_cast<App::PropertyType>(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<Points::Structured>;
}
}// namespace App

View File

@@ -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<Structured>;
} //namespace Points
}// namespace Points
#endif

View File

@@ -24,10 +24,11 @@
#ifndef POINTS_TOOLS_H
#define POINTS_TOOLS_H
#include <algorithm>
#include <App/DocumentObject.h>
#include <algorithm>
namespace Points {
namespace Points
{
template<typename PropertyT>
bool copyProperty(App::DocumentObject* target,
@@ -39,13 +40,12 @@ bool copyProperty(App::DocumentObject* target,
return dynamic_cast<PropertyT*>(obj->getPropertyByName(propertyName)) != nullptr;
})) {
auto target_prop = dynamic_cast<PropertyT*>
(target->addDynamicProperty(PropertyT::getClassTypeId().getName(), propertyName));
auto target_prop = dynamic_cast<PropertyT*>(
target->addDynamicProperty(PropertyT::getClassTypeId().getName(), propertyName));
if (target_prop) {
auto values = target_prop->getValues();
for (auto it : source) {
auto source_prop = dynamic_cast<PropertyT*>
(it->getPropertyByName(propertyName));
auto source_prop = dynamic_cast<PropertyT*>(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