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

View File

@@ -44,13 +44,15 @@ void loadPointsResource()
Gui::Translator::instance()->refresh();
}
namespace PointsGui {
class Module : public Py::ExtensionModule<Module>
namespace PointsGui
{
class Module: public Py::ExtensionModule<Module>
{
public:
Module() : Py::ExtensionModule<Module>("PointsGui")
Module()
: Py::ExtensionModule<Module>("PointsGui")
{
initialize("This module is the PointsGui module."); // register with Python
initialize("This module is the PointsGui module.");// register with Python
}
};
@@ -59,7 +61,7 @@ PyObject* initModule()
return Base::Interpreter().addModule(new Module);
}
} // namespace PointsGui
}// namespace PointsGui
/* Python entry */
@@ -74,7 +76,7 @@ PyMOD_INIT_FUNC(PointsGui)
try {
Base::Interpreter().loadModule("Points");
}
catch(const Base::Exception& e) {
catch (const Base::Exception& e) {
PyErr_SetString(PyExc_ImportError, e.what());
PyMOD_Return(nullptr);
}
@@ -85,14 +87,15 @@ PyMOD_INIT_FUNC(PointsGui)
// instantiating the commands
CreatePointsCommands();
// clang-format off
PointsGui::ViewProviderPoints ::init();
PointsGui::ViewProviderScattered ::init();
PointsGui::ViewProviderStructured ::init();
PointsGui::ViewProviderPython ::init();
PointsGui::Workbench ::init();
Gui::ViewProviderBuilder::add(
Points::PropertyPointKernel::getClassTypeId(),
PointsGui::ViewProviderPoints::getClassTypeId());
// clang-format on
Gui::ViewProviderBuilder::add(Points::PropertyPointKernel::getClassTypeId(),
PointsGui::ViewProviderPoints::getClassTypeId());
// add resources and reloads the translators
loadPointsResource();

View File

@@ -22,9 +22,9 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <algorithm>
# include <QInputDialog>
# include <Inventor/events/SoMouseButtonEvent.h>
#include <Inventor/events/SoMouseButtonEvent.h>
#include <QInputDialog>
#include <algorithm>
#endif
#include <App/Application.h>
@@ -45,8 +45,8 @@
#include <Gui/WaitCursor.h>
#include "../App/PointsFeature.h"
#include "../App/Structured.h"
#include "../App/Properties.h"
#include "../App/Structured.h"
#include "../App/Tools.h"
#include "DlgPointsReadImp.h"
@@ -61,34 +61,40 @@
DEF_STD_CMD_A(CmdPointsImport)
CmdPointsImport::CmdPointsImport()
: Command("Points_Import")
: Command("Points_Import")
{
sAppModule = "Points";
sGroup = QT_TR_NOOP("Points");
sMenuText = QT_TR_NOOP("Import points...");
sToolTipText = QT_TR_NOOP("Imports a point cloud");
sWhatsThis = "Points_Import";
sStatusTip = QT_TR_NOOP("Imports a point cloud");
sPixmap = "Points_Import_Point_cloud";
sAppModule = "Points";
sGroup = QT_TR_NOOP("Points");
sMenuText = QT_TR_NOOP("Import points...");
sToolTipText = QT_TR_NOOP("Imports a point cloud");
sWhatsThis = "Points_Import";
sStatusTip = QT_TR_NOOP("Imports a point cloud");
sPixmap = "Points_Import_Point_cloud";
}
void CmdPointsImport::activated(int iMsg)
{
Q_UNUSED(iMsg);
QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(),
QString(), QString(), QString::fromLatin1("%1 (*.asc *.pcd *.ply);;%2 (*.*)")
.arg(QObject::tr("Point formats"), QObject::tr("All Files")));
if (fn.isEmpty())
QString fn = Gui::FileDialog::getOpenFileName(
Gui::getMainWindow(),
QString(),
QString(),
QString::fromLatin1("%1 (*.asc *.pcd *.ply);;%2 (*.*)")
.arg(QObject::tr("Point formats"), QObject::tr("All Files")));
if (fn.isEmpty()) {
return;
}
if (!fn.isEmpty()) {
fn = Base::Tools::escapeEncodeFilename(fn);
Gui::Document* doc = getActiveGuiDocument();
openCommand(QT_TRANSLATE_NOOP("Command", "Import points"));
addModule(Command::App, "Points");
doCommand(Command::Doc, "Points.insert(\"%s\", \"%s\")",
fn.toUtf8().data(), doc->getDocument()->getName());
doCommand(Command::Doc,
"Points.insert(\"%s\", \"%s\")",
fn.toUtf8().data(),
doc->getDocument()->getName());
commitCommand();
updateActive();
@@ -97,24 +103,26 @@ void CmdPointsImport::activated(int iMsg)
bool CmdPointsImport::isActive()
{
if (getActiveGuiDocument())
if (getActiveGuiDocument()) {
return true;
else
}
else {
return false;
}
}
DEF_STD_CMD_A(CmdPointsExport)
CmdPointsExport::CmdPointsExport()
: Command("Points_Export")
: Command("Points_Export")
{
sAppModule = "Points";
sGroup = QT_TR_NOOP("Points");
sMenuText = QT_TR_NOOP("Export points...");
sToolTipText = QT_TR_NOOP("Exports a point cloud");
sWhatsThis = "Points_Export";
sStatusTip = QT_TR_NOOP("Exports a point cloud");
sPixmap = "Points_Export_Point_cloud";
sAppModule = "Points";
sGroup = QT_TR_NOOP("Points");
sMenuText = QT_TR_NOOP("Export points...");
sToolTipText = QT_TR_NOOP("Exports a point cloud");
sWhatsThis = "Points_Export";
sStatusTip = QT_TR_NOOP("Exports a point cloud");
sPixmap = "Points_Export_Point_cloud";
}
void CmdPointsExport::activated(int iMsg)
@@ -122,18 +130,25 @@ void CmdPointsExport::activated(int iMsg)
Q_UNUSED(iMsg);
addModule(Command::App, "Points");
std::vector<App::DocumentObject*> points = getSelection().getObjectsOfType(Points::Feature::getClassTypeId());
std::vector<App::DocumentObject*> points =
getSelection().getObjectsOfType(Points::Feature::getClassTypeId());
for (auto point : points) {
QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(),
QString(), QString(), QString::fromLatin1("%1 (*.asc *.pcd *.ply);;%2 (*.*)")
.arg(QObject::tr("Point formats"), QObject::tr("All Files")));
if (fn.isEmpty())
QString fn = Gui::FileDialog::getSaveFileName(
Gui::getMainWindow(),
QString(),
QString(),
QString::fromLatin1("%1 (*.asc *.pcd *.ply);;%2 (*.*)")
.arg(QObject::tr("Point formats"), QObject::tr("All Files")));
if (fn.isEmpty()) {
break;
}
if (!fn.isEmpty()) {
fn = Base::Tools::escapeEncodeFilename(fn);
doCommand(Command::Doc, "Points.export([App.ActiveDocument.%s], \"%s\")",
point->getNameInDocument(), fn.toUtf8().data());
doCommand(Command::Doc,
"Points.export([App.ActiveDocument.%s], \"%s\")",
point->getNameInDocument(),
fn.toUtf8().data());
}
}
}
@@ -146,15 +161,15 @@ bool CmdPointsExport::isActive()
DEF_STD_CMD_A(CmdPointsTransform)
CmdPointsTransform::CmdPointsTransform()
:Command("Points_Transform")
: Command("Points_Transform")
{
sAppModule = "Points";
sGroup = QT_TR_NOOP("Points");
sMenuText = QT_TR_NOOP("Transform Points");
sToolTipText = QT_TR_NOOP("Test to transform a point cloud");
sWhatsThis = "Points_Transform";
sStatusTip = QT_TR_NOOP("Test to transform a point cloud");
sPixmap = "Test1";
sAppModule = "Points";
sGroup = QT_TR_NOOP("Points");
sMenuText = QT_TR_NOOP("Transform Points");
sToolTipText = QT_TR_NOOP("Test to transform a point cloud");
sWhatsThis = "Points_Transform";
sStatusTip = QT_TR_NOOP("Test to transform a point cloud");
sPixmap = "Test1";
}
void CmdPointsTransform::activated(int iMsg)
@@ -166,12 +181,14 @@ void CmdPointsTransform::activated(int iMsg)
trans.setRotation(Base::Rotation(Base::Vector3d(0.0, 0.0, 1.0), 1.570796));
openCommand(QT_TRANSLATE_NOOP("Command", "Transform points"));
//std::vector<App::DocumentObject*> points = getSelection().getObjectsOfType(Points::Feature::getClassTypeId());
//for (std::vector<App::DocumentObject*>::const_iterator it = points.begin(); it != points.end(); ++it) {
// Base::Placement p = static_cast<Points::Feature*>(*it)->Placement.getValue();
// p._rot *= Base::Rotation(Base::Vector3d(0.0, 0.0, 1.0), 1.570796);
// static_cast<Points::Feature*>(*it)->Placement.setValue(p);
//}
// std::vector<App::DocumentObject*> points =
// getSelection().getObjectsOfType(Points::Feature::getClassTypeId()); for
// (std::vector<App::DocumentObject*>::const_iterator it = points.begin(); it != points.end();
// ++it) {
// Base::Placement p = static_cast<Points::Feature*>(*it)->Placement.getValue();
// p._rot *= Base::Rotation(Base::Vector3d(0.0, 0.0, 1.0), 1.570796);
// static_cast<Points::Feature*>(*it)->Placement.setValue(p);
// }
commitCommand();
}
@@ -183,15 +200,15 @@ bool CmdPointsTransform::isActive()
DEF_STD_CMD_A(CmdPointsConvert)
CmdPointsConvert::CmdPointsConvert()
:Command("Points_Convert")
: Command("Points_Convert")
{
sAppModule = "Points";
sGroup = QT_TR_NOOP("Points");
sMenuText = QT_TR_NOOP("Convert to points...");
sToolTipText = QT_TR_NOOP("Convert to points");
sWhatsThis = "Points_Convert";
sStatusTip = QT_TR_NOOP("Convert to points");
sPixmap = "Points_Convert";
sAppModule = "Points";
sGroup = QT_TR_NOOP("Points");
sMenuText = QT_TR_NOOP("Convert to points...");
sToolTipText = QT_TR_NOOP("Convert to points");
sWhatsThis = "Points_Convert";
sStatusTip = QT_TR_NOOP("Convert to points");
sPixmap = "Points_Convert";
}
void CmdPointsConvert::activated(int iMsg)
@@ -202,13 +219,22 @@ void CmdPointsConvert::activated(int iMsg)
int decimals = Base::UnitsApi::getDecimals();
double tolerance_from_decimals = pow(10., -decimals);
double minimal_tolerance = tolerance_from_decimals < STD_OCC_TOLERANCE ? STD_OCC_TOLERANCE : tolerance_from_decimals;
double minimal_tolerance =
tolerance_from_decimals < STD_OCC_TOLERANCE ? STD_OCC_TOLERANCE : tolerance_from_decimals;
bool ok;
double tol = QInputDialog::getDouble(Gui::getMainWindow(), QObject::tr("Distance"),
QObject::tr("Enter maximum distance:"), 0.1, minimal_tolerance, 10.0, decimals, &ok, Qt::MSWindowsFixedSizeDialogHint);
if (!ok)
double tol = QInputDialog::getDouble(Gui::getMainWindow(),
QObject::tr("Distance"),
QObject::tr("Enter maximum distance:"),
0.1,
minimal_tolerance,
10.0,
decimals,
&ok,
Qt::MSWindowsFixedSizeDialogHint);
if (!ok) {
return;
}
Gui::WaitCursor wc;
openCommand(QT_TRANSLATE_NOOP("Command", "Convert to points"));
@@ -230,7 +256,8 @@ void CmdPointsConvert::activated(int iMsg)
}
Py::Module commands(module, true);
commands.callMemberFunction("make_points_from_geometry", Py::TupleN(list, Py::Float(tol)));
commands.callMemberFunction("make_points_from_geometry",
Py::TupleN(list, Py::Float(tol)));
return true;
}
@@ -239,10 +266,12 @@ void CmdPointsConvert::activated(int iMsg)
Base::PyGILStateLocker lock;
try {
if (run_python(geoObject, tol))
if (run_python(geoObject, tol)) {
commitCommand();
else
}
else {
abortCommand();
}
}
catch (const Py::Exception&) {
abortCommand();
@@ -259,23 +288,25 @@ bool CmdPointsConvert::isActive()
DEF_STD_CMD_A(CmdPointsPolyCut)
CmdPointsPolyCut::CmdPointsPolyCut()
:Command("Points_PolyCut")
: Command("Points_PolyCut")
{
sAppModule = "Points";
sGroup = QT_TR_NOOP("Points");
sMenuText = QT_TR_NOOP("Cut point cloud");
sToolTipText = QT_TR_NOOP("Cuts a point cloud with a picked polygon");
sWhatsThis = "Points_PolyCut";
sStatusTip = QT_TR_NOOP("Cuts a point cloud with a picked polygon");
sPixmap = "PolygonPick";
sAppModule = "Points";
sGroup = QT_TR_NOOP("Points");
sMenuText = QT_TR_NOOP("Cut point cloud");
sToolTipText = QT_TR_NOOP("Cuts a point cloud with a picked polygon");
sWhatsThis = "Points_PolyCut";
sStatusTip = QT_TR_NOOP("Cuts a point cloud with a picked polygon");
sPixmap = "PolygonPick";
}
void CmdPointsPolyCut::activated(int iMsg)
{
Q_UNUSED(iMsg);
std::vector<App::DocumentObject*> docObj = Gui::Selection().getObjectsOfType(Points::Feature::getClassTypeId());
for (std::vector<App::DocumentObject*>::iterator it = docObj.begin(); it != docObj.end(); ++it) {
std::vector<App::DocumentObject*> docObj =
Gui::Selection().getObjectsOfType(Points::Feature::getClassTypeId());
for (std::vector<App::DocumentObject*>::iterator it = docObj.begin(); it != docObj.end();
++it) {
if (it == docObj.begin()) {
Gui::Document* doc = getActiveGuiDocument();
Gui::MDIView* view = doc->getActiveView();
@@ -283,14 +314,15 @@ void CmdPointsPolyCut::activated(int iMsg)
Gui::View3DInventorViewer* viewer = ((Gui::View3DInventor*)view)->getViewer();
viewer->setEditing(true);
viewer->startSelection(Gui::View3DInventorViewer::Lasso);
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), PointsGui::ViewProviderPoints::clipPointsCallback);
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
PointsGui::ViewProviderPoints::clipPointsCallback);
}
else {
return;
}
}
Gui::ViewProvider* pVP = getActiveGuiDocument()->getViewProvider( *it );
Gui::ViewProvider* pVP = getActiveGuiDocument()->getViewProvider(*it);
pVP->startEditing(Gui::ViewProvider::Cutting);
}
}
@@ -304,15 +336,15 @@ bool CmdPointsPolyCut::isActive()
DEF_STD_CMD_A(CmdPointsMerge)
CmdPointsMerge::CmdPointsMerge()
:Command("Points_Merge")
: Command("Points_Merge")
{
sAppModule = "Points";
sGroup = QT_TR_NOOP("Points");
sMenuText = QT_TR_NOOP("Merge point clouds");
sToolTipText = QT_TR_NOOP("Merge several point clouds into one");
sWhatsThis = "Points_Merge";
sStatusTip = QT_TR_NOOP("Merge several point clouds into one");
sPixmap = "Points_Merge";
sAppModule = "Points";
sGroup = QT_TR_NOOP("Points");
sMenuText = QT_TR_NOOP("Merge point clouds");
sToolTipText = QT_TR_NOOP("Merge several point clouds into one");
sWhatsThis = "Points_Merge";
sStatusTip = QT_TR_NOOP("Merge several point clouds into one");
sPixmap = "Points_Merge";
}
void CmdPointsMerge::activated(int iMsg)
@@ -321,16 +353,18 @@ void CmdPointsMerge::activated(int iMsg)
App::Document* doc = App::GetApplication().getActiveDocument();
doc->openTransaction("Merge point clouds");
Points::Feature* pts = static_cast<Points::Feature*>(doc->addObject("Points::Feature", "Merged Points"));
Points::Feature* pts =
static_cast<Points::Feature*>(doc->addObject("Points::Feature", "Merged Points"));
Points::PointKernel* kernel = pts->Points.startEditing();
std::vector<App::DocumentObject*> docObj = Gui::Selection().getObjectsOfType(Points::Feature::getClassTypeId());
std::vector<App::DocumentObject*> docObj =
Gui::Selection().getObjectsOfType(Points::Feature::getClassTypeId());
for (auto it : docObj) {
const Points::PointKernel& k = static_cast<Points::Feature*>(it)->Points.getValue();
std::size_t numPts = kernel->size();
kernel->resize(numPts + k.size());
for (std::size_t i=0; i<k.size(); ++i) {
kernel->setPoint(i+numPts, k.getPoint(i));
for (std::size_t i = 0; i < k.size(); ++i) {
kernel->setPoint(i + numPts, k.getPoint(i));
}
}
@@ -348,8 +382,8 @@ void CmdPointsMerge::activated(int iMsg)
displayMode = "Intensity";
}
if (auto vp = dynamic_cast<Gui::ViewProviderDocumentObject*>
(Gui::Application::Instance->getViewProvider(pts))) {
if (auto vp = dynamic_cast<Gui::ViewProviderDocumentObject*>(
Gui::Application::Instance->getViewProvider(pts))) {
vp->DisplayMode.setValue(displayMode.c_str());
}
@@ -365,15 +399,15 @@ bool CmdPointsMerge::isActive()
DEF_STD_CMD_A(CmdPointsStructure)
CmdPointsStructure::CmdPointsStructure()
:Command("Points_Structure")
: Command("Points_Structure")
{
sAppModule = "Points";
sGroup = QT_TR_NOOP("Points");
sMenuText = QT_TR_NOOP("Structured point cloud");
sToolTipText = QT_TR_NOOP("Convert points to structured point cloud");
sWhatsThis = "Points_Structure";
sStatusTip = QT_TR_NOOP("Convert points to structured point cloud");
sPixmap = "Points_Structure";
sAppModule = "Points";
sGroup = QT_TR_NOOP("Points");
sMenuText = QT_TR_NOOP("Structured point cloud");
sToolTipText = QT_TR_NOOP("Convert points to structured point cloud");
sWhatsThis = "Points_Structure";
sStatusTip = QT_TR_NOOP("Convert points to structured point cloud");
sPixmap = "Points_Structure";
}
void CmdPointsStructure::activated(int iMsg)
@@ -383,11 +417,13 @@ void CmdPointsStructure::activated(int iMsg)
App::Document* doc = App::GetApplication().getActiveDocument();
doc->openTransaction("Structure point cloud");
std::vector<App::DocumentObject*> docObj = Gui::Selection().getObjectsOfType(Points::Feature::getClassTypeId());
std::vector<App::DocumentObject*> docObj =
Gui::Selection().getObjectsOfType(Points::Feature::getClassTypeId());
for (auto it : docObj) {
std::string name = it->Label.getValue();
name += " (Structured)";
Points::Structured* output = static_cast<Points::Structured*>(doc->addObject("Points::Structured", name.c_str()));
Points::Structured* output =
static_cast<Points::Structured*>(doc->addObject("Points::Structured", name.c_str()));
output->Label.setValue(name);
// Already sorted, so just make a copy
@@ -398,7 +434,7 @@ void CmdPointsStructure::activated(int iMsg)
const Points::PointKernel& k = input->Points.getValue();
kernel->resize(k.size());
for (std::size_t i=0; i<k.size(); ++i) {
for (std::size_t i = 0; i < k.size(); ++i) {
kernel->setPoint(i, k.getPoint(i));
}
output->Points.finishEditing();
@@ -418,7 +454,7 @@ void CmdPointsStructure::activated(int iMsg)
// Count the number of different x or y values to get the size
std::set<double> countX, countY;
for (std::size_t i=0; i<k.size(); ++i) {
for (std::size_t i = 0; i < k.size(); ++i) {
Base::Vector3d pnt = k.getPoint(i);
countX.insert(pnt.x);
countY.insert(pnt.y);
@@ -433,9 +469,10 @@ void CmdPointsStructure::activated(int iMsg)
// Pre-fill the vector with <nan, nan, nan> points and afterwards replace them
// with valid point coordinates
double nan = std::numeric_limits<double>::quiet_NaN();
std::vector<Base::Vector3d> sortedPoints(width_l * height_l, Base::Vector3d(nan, nan, nan));
std::vector<Base::Vector3d> sortedPoints(width_l * height_l,
Base::Vector3d(nan, nan, nan));
for (std::size_t i=0; i<k.size(); ++i) {
for (std::size_t i = 0; i < k.size(); ++i) {
Base::Vector3d pnt = k.getPoint(i);
double xi = (pnt.x - bbox.MinX) / dx;
double yi = (pnt.y - bbox.MinY) / dy;
@@ -472,7 +509,7 @@ bool CmdPointsStructure::isActive()
void CreatePointsCommands()
{
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager();
rcCmdMgr.addCommand(new CmdPointsImport());
rcCmdMgr.addCommand(new CmdPointsExport());
rcCmdMgr.addCommand(new CmdPointsTransform());

View File

@@ -28,12 +28,12 @@
using namespace PointsGui;
DlgPointsReadImp::DlgPointsReadImp(const char *FileName, QWidget* parent, Qt::WindowFlags fl )
: QDialog( parent, fl )
DlgPointsReadImp::DlgPointsReadImp(const char* FileName, QWidget* parent, Qt::WindowFlags fl)
: QDialog(parent, fl)
, ui(new Ui_DlgPointsRead)
{
ui->setupUi(this);
_FileName = FileName;
ui->setupUi(this);
_FileName = FileName;
}
/*

View File

@@ -23,28 +23,31 @@
#ifndef POINTSGUI_DLGREADPOINTS_H
#define POINTSGUI_DLGREADPOINTS_H
#include <memory>
#include <QDialog>
#include <memory>
namespace PointsGui {
namespace PointsGui
{
class Ui_DlgPointsRead;
/** The points read dialog
*/
class DlgPointsReadImp : public QDialog
class DlgPointsReadImp: public QDialog
{
Q_OBJECT
Q_OBJECT
public:
explicit DlgPointsReadImp(const char *FileName, QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags() );
~DlgPointsReadImp() override;
explicit DlgPointsReadImp(const char* FileName,
QWidget* parent = nullptr,
Qt::WindowFlags fl = Qt::WindowFlags());
~DlgPointsReadImp() override;
private:
std::unique_ptr<Ui_DlgPointsRead> ui;
std::string _FileName;
std::unique_ptr<Ui_DlgPointsRead> ui;
std::string _FileName;
};
} // namespace PointsGui
}// namespace PointsGui
#endif // POINTSGUI_DLGREADPOINTS_H
#endif// POINTSGUI_DLGREADPOINTS_H

View File

@@ -28,30 +28,30 @@
#ifdef _PreComp_
// STL
# include <algorithm>
# include <limits>
# include <memory>
#include <algorithm>
#include <limits>
#include <memory>
// boost
# include <boost/math/special_functions/fpclassify.hpp>
#include <boost/math/special_functions/fpclassify.hpp>
// Qt
# include <QDialog>
# include <QInputDialog>
#include <QDialog>
#include <QInputDialog>
// Inventor
# include <Inventor/SbVec2f.h>
# include <Inventor/errors/SoDebugError.h>
# include <Inventor/events/SoMouseButtonEvent.h>
# include <Inventor/nodes/SoCamera.h>
# include <Inventor/nodes/SoCoordinate3.h>
# include <Inventor/nodes/SoDrawStyle.h>
# include <Inventor/nodes/SoIndexedPointSet.h>
# include <Inventor/nodes/SoMaterial.h>
# include <Inventor/nodes/SoMaterialBinding.h>
# include <Inventor/nodes/SoNormal.h>
# include <Inventor/nodes/SoPointSet.h>
#include <Inventor/SbVec2f.h>
#include <Inventor/errors/SoDebugError.h>
#include <Inventor/events/SoMouseButtonEvent.h>
#include <Inventor/nodes/SoCamera.h>
#include <Inventor/nodes/SoCoordinate3.h>
#include <Inventor/nodes/SoDrawStyle.h>
#include <Inventor/nodes/SoIndexedPointSet.h>
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoMaterialBinding.h>
#include <Inventor/nodes/SoNormal.h>
#include <Inventor/nodes/SoPointSet.h>
#endif //_PreComp_
#endif//_PreComp_
#endif // POINTSGUI_PRECOMPILED_H
#endif// POINTSGUI_PRECOMPILED_H

View File

@@ -22,19 +22,19 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <limits>
# include <boost/math/special_functions/fpclassify.hpp>
#include <boost/math/special_functions/fpclassify.hpp>
#include <limits>
# include <Inventor/errors/SoDebugError.h>
# include <Inventor/events/SoMouseButtonEvent.h>
# include <Inventor/nodes/SoCamera.h>
# include <Inventor/nodes/SoCoordinate3.h>
# include <Inventor/nodes/SoDrawStyle.h>
# include <Inventor/nodes/SoIndexedPointSet.h>
# include <Inventor/nodes/SoMaterial.h>
# include <Inventor/nodes/SoMaterialBinding.h>
# include <Inventor/nodes/SoNormal.h>
# include <Inventor/nodes/SoPointSet.h>
#include <Inventor/errors/SoDebugError.h>
#include <Inventor/events/SoMouseButtonEvent.h>
#include <Inventor/nodes/SoCamera.h>
#include <Inventor/nodes/SoCoordinate3.h>
#include <Inventor/nodes/SoDrawStyle.h>
#include <Inventor/nodes/SoIndexedPointSet.h>
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoMaterialBinding.h>
#include <Inventor/nodes/SoNormal.h>
#include <Inventor/nodes/SoPointSet.h>
#endif
#include <App/Document.h>
@@ -56,11 +56,11 @@ using namespace Points;
PROPERTY_SOURCE_ABSTRACT(PointsGui::ViewProviderPoints, Gui::ViewProviderGeometryObject)
App::PropertyFloatConstraint::Constraints ViewProviderPoints::floatRange = {1.0,64.0,1.0};
App::PropertyFloatConstraint::Constraints ViewProviderPoints::floatRange = {1.0, 64.0, 1.0};
ViewProviderPoints::ViewProviderPoints()
{
static const char *osgroup = "Object Style";
static const char* osgroup = "Object Style";
ADD_PROPERTY_TYPE(PointSize, (2.0f), osgroup, App::Prop_None, "Set point size");
PointSize.setConstraints(&floatRange);
@@ -68,8 +68,9 @@ ViewProviderPoints::ViewProviderPoints()
// Create the selection node
pcHighlight = Gui::ViewProviderBuilder::createSelection();
pcHighlight->ref();
if (pcHighlight->selectionMode.getValue() == Gui::SoFCSelection::SEL_OFF)
if (pcHighlight->selectionMode.getValue() == Gui::SoFCSelection::SEL_OFF) {
Selectable.setValue(false);
}
// BBOX
SelectionStyle.setValue(1);
@@ -102,8 +103,8 @@ void ViewProviderPoints::onChanged(const App::Property* prop)
pcPointStyle->pointSize = PointSize.getValue();
}
else if (prop == &SelectionStyle) {
pcHighlight->style = SelectionStyle.getValue() ? Gui::SoFCSelection::BOX
: Gui::SoFCSelection::EMISSIVE;
pcHighlight->style =
SelectionStyle.getValue() ? Gui::SoFCSelection::BOX : Gui::SoFCSelection::EMISSIVE;
}
else {
ViewProviderGeometryObject::onChanged(prop);
@@ -117,7 +118,7 @@ void ViewProviderPoints::setVertexColorMode(App::PropertyColorList* pcProperty)
pcColorMat->diffuseColor.setNum(val.size());
SbColor* col = pcColorMat->diffuseColor.startEditing();
std::size_t i=0;
std::size_t i = 0;
for (const auto& it : val) {
col[i++].setValue(it.r, it.g, it.b);
}
@@ -132,7 +133,7 @@ void ViewProviderPoints::setVertexGreyvalueMode(Points::PropertyGreyValueList* p
pcColorMat->diffuseColor.setNum(val.size());
SbColor* col = pcColorMat->diffuseColor.startEditing();
std::size_t i=0;
std::size_t i = 0;
for (float it : val) {
col[i++].setValue(it, it, it);
}
@@ -147,7 +148,7 @@ void ViewProviderPoints::setVertexNormalMode(Points::PropertyNormalList* pcPrope
pcPointsNormal->vector.setNum(val.size());
SbVec3f* norm = pcPointsNormal->vector.startEditing();
std::size_t i=0;
std::size_t i = 0;
for (const auto& it : val) {
norm[i++].setValue(it.x, it.y, it.z);
}
@@ -159,17 +160,20 @@ void ViewProviderPoints::setDisplayMode(const char* ModeName)
{
int numPoints = pcPointsCoord->point.getNum();
if (strcmp("Color",ModeName) == 0) {
std::map<std::string,App::Property*> Map;
if (strcmp("Color", ModeName) == 0) {
std::map<std::string, App::Property*> Map;
pcObject->getPropertyMap(Map);
for (auto & it : Map) {
for (auto& it : Map) {
Base::Type type = it.second->getTypeId();
if (type == App::PropertyColorList::getClassTypeId()) {
App::PropertyColorList* colors = static_cast<App::PropertyColorList*>(it.second);
if (numPoints != colors->getSize()) {
#ifdef FC_DEBUG
SoDebugError::postWarning("ViewProviderPoints::setDisplayMode",
"The number of points (%d) doesn't match with the number of colors (%d).", numPoints, colors->getSize());
SoDebugError::postWarning(
"ViewProviderPoints::setDisplayMode",
"The number of points (%d) doesn't match with the number of colors (%d).",
numPoints,
colors->getSize());
#endif
// fallback
setDisplayMaskMode("Point");
@@ -182,17 +186,21 @@ void ViewProviderPoints::setDisplayMode(const char* ModeName)
}
}
}
else if (strcmp("Intensity",ModeName) == 0) {
std::map<std::string,App::Property*> Map;
else if (strcmp("Intensity", ModeName) == 0) {
std::map<std::string, App::Property*> Map;
pcObject->getPropertyMap(Map);
for (const auto& it : Map) {
Base::Type type = it.second->getTypeId();
if (type == Points::PropertyGreyValueList::getClassTypeId()) {
Points::PropertyGreyValueList* greyValues = static_cast<Points::PropertyGreyValueList*>(it.second);
Points::PropertyGreyValueList* greyValues =
static_cast<Points::PropertyGreyValueList*>(it.second);
if (numPoints != greyValues->getSize()) {
#ifdef FC_DEBUG
SoDebugError::postWarning("ViewProviderPoints::setDisplayMode",
"The number of points (%d) doesn't match with the number of grey values (%d).", numPoints, greyValues->getSize());
"The number of points (%d) doesn't match with the "
"number of grey values (%d).",
numPoints,
greyValues->getSize());
#endif
// Intensity mode is not possible then set the default () mode instead.
setDisplayMaskMode("Point");
@@ -205,17 +213,21 @@ void ViewProviderPoints::setDisplayMode(const char* ModeName)
}
}
}
else if (strcmp("Shaded",ModeName) == 0) {
std::map<std::string,App::Property*> Map;
else if (strcmp("Shaded", ModeName) == 0) {
std::map<std::string, App::Property*> Map;
pcObject->getPropertyMap(Map);
for (const auto& it : Map) {
Base::Type type = it.second->getTypeId();
if (type == Points::PropertyNormalList::getClassTypeId()) {
Points::PropertyNormalList* normals = static_cast<Points::PropertyNormalList*>(it.second);
Points::PropertyNormalList* normals =
static_cast<Points::PropertyNormalList*>(it.second);
if (numPoints != normals->getSize()) {
#ifdef FC_DEBUG
SoDebugError::postWarning("ViewProviderPoints::setDisplayMode",
"The number of points (%d) doesn't match with the number of normals (%d).", numPoints, normals->getSize());
SoDebugError::postWarning(
"ViewProviderPoints::setDisplayMode",
"The number of points (%d) doesn't match with the number of normals (%d).",
numPoints,
normals->getSize());
#endif
// fallback
setDisplayMaskMode("Point");
@@ -228,7 +240,7 @@ void ViewProviderPoints::setDisplayMode(const char* ModeName)
}
}
}
else if (strcmp("Points",ModeName) == 0) {
else if (strcmp("Points", ModeName) == 0) {
setDisplayMaskMode("Point");
}
@@ -251,17 +263,21 @@ std::vector<std::string> ViewProviderPoints::getDisplayModes() const
#else
if (pcObject) {
std::map<std::string,App::Property*> Map;
std::map<std::string, App::Property*> Map;
pcObject->getPropertyMap(Map);
for (std::map<std::string,App::Property*>::iterator it = Map.begin(); it != Map.end(); ++it) {
for (std::map<std::string, App::Property*>::iterator it = Map.begin(); it != Map.end();
++it) {
Base::Type type = it->second->getTypeId();
if (type == Points::PropertyNormalList::getClassTypeId())
if (type == Points::PropertyNormalList::getClassTypeId()) {
StrList.push_back("Shaded");
else if (type == Points::PropertyGreyValueList::getClassTypeId())
}
else if (type == Points::PropertyGreyValueList::getClassTypeId()) {
StrList.push_back("Intensity");
else if (type == App::PropertyColorList::getClassTypeId())
}
else if (type == App::PropertyColorList::getClassTypeId()) {
StrList.push_back("Color");
}
}
}
#endif
@@ -271,6 +287,7 @@ std::vector<std::string> ViewProviderPoints::getDisplayModes() const
QIcon ViewProviderPoints::getIcon() const
{
// clang-format off
static const char * const Points_Feature_xpm[] = {
"16 16 4 1",
". c none",
@@ -295,38 +312,45 @@ QIcon ViewProviderPoints::getIcon() const
"rr.......rr..rr."};
QPixmap px(Points_Feature_xpm);
return px;
// clang-format on
}
bool ViewProviderPoints::setEdit(int ModNum)
{
if (ModNum == ViewProvider::Transform)
if (ModNum == ViewProvider::Transform) {
return ViewProviderGeometryObject::setEdit(ModNum);
else if (ModNum == ViewProvider::Cutting)
}
else if (ModNum == ViewProvider::Cutting) {
return true;
}
return false;
}
void ViewProviderPoints::unsetEdit(int ModNum)
{
if (ModNum == ViewProvider::Transform)
if (ModNum == ViewProvider::Transform) {
ViewProviderGeometryObject::unsetEdit(ModNum);
}
}
void ViewProviderPoints::clipPointsCallback(void *, SoEventCallback * n)
void ViewProviderPoints::clipPointsCallback(void*, SoEventCallback* n)
{
// When this callback function is invoked we must in either case leave the edit mode
Gui::View3DInventorViewer* view = static_cast<Gui::View3DInventorViewer*>(n->getUserData());
Gui::View3DInventorViewer* view = static_cast<Gui::View3DInventorViewer*>(n->getUserData());
view->setEditing(false);
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), clipPointsCallback);
n->setHandled();
std::vector<SbVec2f> clPoly = view->getGLPolygon();
if (clPoly.size() < 3)
if (clPoly.size() < 3) {
return;
if (clPoly.front() != clPoly.back())
}
if (clPoly.front() != clPoly.back()) {
clPoly.push_back(clPoly.front());
}
std::vector<Gui::ViewProvider*> views = view->getViewProvidersOfType(ViewProviderPoints::getClassTypeId());
std::vector<Gui::ViewProvider*> views =
view->getViewProvidersOfType(ViewProviderPoints::getClassTypeId());
for (auto it : views) {
ViewProviderPoints* that = static_cast<ViewProviderPoints*>(it);
if (that->getEditingMode() > -1) {
@@ -386,8 +410,8 @@ void ViewProviderScattered::attach(App::DocumentObject* pcObj)
}
// color shaded ------------------------------------------
if (std::find(modes.begin(), modes.end(), std::string("Color")) != modes.end() ||
std::find(modes.begin(), modes.end(), std::string("Intensity")) != modes.end()) {
if (std::find(modes.begin(), modes.end(), std::string("Color")) != modes.end()
|| std::find(modes.begin(), modes.end(), std::string("Intensity")) != modes.end()) {
SoGroup* pcColorShadedRoot = new SoGroup();
pcColorShadedRoot->addChild(pcPointStyle);
SoMaterialBinding* pcMatBinding = new SoMaterialBinding;
@@ -420,12 +444,13 @@ void ViewProviderScattered::updateData(const App::Property* prop)
}
}
void ViewProviderScattered::cut(const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer &Viewer)
void ViewProviderScattered::cut(const std::vector<SbVec2f>& picked,
Gui::View3DInventorViewer& Viewer)
{
// create the polygon from the picked points
Base::Polygon2d cPoly;
for (const auto& it : picked) {
cPoly.Add(Base::Vector2d(it[0],it[1]));
cPoly.Add(Base::Vector2d(it[0], it[1]));
}
// get a reference to the point feature
@@ -433,32 +458,36 @@ void ViewProviderScattered::cut(const std::vector<SbVec2f>& picked, Gui::View3DI
const Points::PointKernel& points = fea->Points.getValue();
SoCamera* pCam = Viewer.getSoRenderManager()->getCamera();
SbViewVolume vol = pCam->getViewVolume();
SbViewVolume vol = pCam->getViewVolume();
// search for all points inside/outside the polygon
std::vector<unsigned long> removeIndices;
removeIndices.reserve(points.size());
unsigned long index = 0;
for (Points::PointKernel::const_iterator jt = points.begin(); jt != points.end(); ++jt, ++index) {
SbVec3f pt(jt->x,jt->y,jt->z);
for (Points::PointKernel::const_iterator jt = points.begin(); jt != points.end();
++jt, ++index) {
SbVec3f pt(jt->x, jt->y, jt->z);
// project from 3d to 2d
vol.projectToScreen(pt, pt);
if (cPoly.Contains(Base::Vector2d(pt[0],pt[1])))
if (cPoly.Contains(Base::Vector2d(pt[0], pt[1]))) {
removeIndices.push_back(index);
}
}
if (removeIndices.empty())
return; // nothing needs to be done
if (removeIndices.empty()) {
return;// nothing needs to be done
}
//Remove the points from the cloud and open a transaction object for the undo/redo stuff
Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Cut points"));
// Remove the points from the cloud and open a transaction object for the undo/redo stuff
Gui::Application::Instance->activeDocument()->openCommand(
QT_TRANSLATE_NOOP("Command", "Cut points"));
// sets the points outside the polygon to update the Inventor node
fea->Points.removeIndices(removeIndices);
std::map<std::string,App::Property*> Map;
std::map<std::string, App::Property*> Map;
pcObject->getPropertyMap(Map);
for (const auto& it : Map) {
@@ -470,24 +499,30 @@ void ViewProviderScattered::cut(const std::vector<SbVec2f>& picked, Gui::View3DI
static_cast<Points::PropertyGreyValueList*>(it.second)->removeIndices(removeIndices);
}
else if (type == App::PropertyColorList::getClassTypeId()) {
//static_cast<App::PropertyColorList*>(it->second)->removeIndices(removeIndices);
const std::vector<App::Color>& colors = static_cast<App::PropertyColorList*>(it.second)->getValues();
// static_cast<App::PropertyColorList*>(it->second)->removeIndices(removeIndices);
const std::vector<App::Color>& colors =
static_cast<App::PropertyColorList*>(it.second)->getValues();
if (removeIndices.size() > colors.size())
if (removeIndices.size() > colors.size()) {
break;
}
std::vector<App::Color> remainValue;
remainValue.reserve(colors.size() - removeIndices.size());
std::vector<unsigned long>::iterator pos = removeIndices.begin();
for (std::vector<App::Color>::const_iterator jt = colors.begin(); jt != colors.end(); ++jt) {
for (std::vector<App::Color>::const_iterator jt = colors.begin(); jt != colors.end();
++jt) {
unsigned long index = jt - colors.begin();
if (pos == removeIndices.end())
remainValue.push_back( *jt );
else if (index != *pos)
remainValue.push_back( *jt );
else
if (pos == removeIndices.end()) {
remainValue.push_back(*jt);
}
else if (index != *pos) {
remainValue.push_back(*jt);
}
else {
++pos;
}
}
static_cast<App::PropertyColorList*>(it.second)->setValues(remainValue);
@@ -547,8 +582,8 @@ void ViewProviderStructured::attach(App::DocumentObject* pcObj)
}
// color shaded ------------------------------------------
if (std::find(modes.begin(), modes.end(), std::string("Color")) != modes.end() ||
std::find(modes.begin(), modes.end(), std::string("Intensity")) != modes.end()) {
if (std::find(modes.begin(), modes.end(), std::string("Color")) != modes.end()
|| std::find(modes.begin(), modes.end(), std::string("Intensity")) != modes.end()) {
SoGroup* pcColorShadedRoot = new SoGroup();
pcColorShadedRoot->addChild(pcPointStyle);
SoMaterialBinding* pcMatBinding = new SoMaterialBinding;
@@ -572,12 +607,13 @@ void ViewProviderStructured::updateData(const App::Property* prop)
}
}
void ViewProviderStructured::cut(const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer &Viewer)
void ViewProviderStructured::cut(const std::vector<SbVec2f>& picked,
Gui::View3DInventorViewer& Viewer)
{
// create the polygon from the picked points
Base::Polygon2d cPoly;
for (const auto& it : picked) {
cPoly.Add(Base::Vector2d(it[0],it[1]));
cPoly.Add(Base::Vector2d(it[0], it[1]));
}
// get a reference to the point feature
@@ -585,7 +621,7 @@ void ViewProviderStructured::cut(const std::vector<SbVec2f>& picked, Gui::View3D
const Points::PointKernel& points = fea->Points.getValue();
SoCamera* pCam = Viewer.getSoRenderManager()->getCamera();
SbViewVolume vol = pCam->getViewVolume();
SbViewVolume vol = pCam->getViewVolume();
// search for all points inside/outside the polygon
Points::PointKernel newKernel;
@@ -593,15 +629,16 @@ void ViewProviderStructured::cut(const std::vector<SbVec2f>& picked, Gui::View3D
bool invalidatePoints = false;
double nan = std::numeric_limits<double>::quiet_NaN();
for (const auto & point : points) {
for (const auto& point : points) {
// valid point?
Base::Vector3d vec(point);
if (!(boost::math::isnan(point.x) || boost::math::isnan(point.y) || boost::math::isnan(point.z))) {
SbVec3f pt(point.x,point.y,point.z);
if (!(boost::math::isnan(point.x) || boost::math::isnan(point.y)
|| boost::math::isnan(point.z))) {
SbVec3f pt(point.x, point.y, point.z);
// project from 3d to 2d
vol.projectToScreen(pt, pt);
if (cPoly.Contains(Base::Vector2d(pt[0],pt[1]))) {
if (cPoly.Contains(Base::Vector2d(pt[0], pt[1]))) {
invalidatePoints = true;
vec.Set(nan, nan, nan);
}
@@ -611,8 +648,9 @@ void ViewProviderStructured::cut(const std::vector<SbVec2f>& picked, Gui::View3D
}
if (invalidatePoints) {
//Remove the points from the cloud and open a transaction object for the undo/redo stuff
Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Cut points"));
// Remove the points from the cloud and open a transaction object for the undo/redo stuff
Gui::Application::Instance->activeDocument()->openCommand(
QT_TRANSLATE_NOOP("Command", "Cut points"));
// sets the points outside the polygon to update the Inventor node
fea->Points.setValue(newKernel);
@@ -625,21 +663,23 @@ void ViewProviderStructured::cut(const std::vector<SbVec2f>& picked, Gui::View3D
// -------------------------------------------------
namespace Gui {
namespace Gui
{
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(PointsGui::ViewProviderPython, PointsGui::ViewProviderScattered)
/// @endcond
// explicit template instantiation
template class PointsGuiExport ViewProviderPythonFeatureT<PointsGui::ViewProviderScattered>;
}
}// namespace Gui
// -------------------------------------------------
void ViewProviderPointsBuilder::buildNodes(const App::Property* prop, std::vector<SoNode*>& nodes) const
void ViewProviderPointsBuilder::buildNodes(const App::Property* prop,
std::vector<SoNode*>& nodes) const
{
SoCoordinate3 *pcPointsCoord=nullptr;
SoPointSet *pcPoints=nullptr;
SoCoordinate3* pcPointsCoord = nullptr;
SoPointSet* pcPoints = nullptr;
if (nodes.empty()) {
pcPointsCoord = new SoCoordinate3();
@@ -648,28 +688,36 @@ void ViewProviderPointsBuilder::buildNodes(const App::Property* prop, std::vecto
nodes.push_back(pcPoints);
}
else if (nodes.size() == 2) {
if (nodes[0]->getTypeId() == SoCoordinate3::getClassTypeId())
if (nodes[0]->getTypeId() == SoCoordinate3::getClassTypeId()) {
pcPointsCoord = static_cast<SoCoordinate3*>(nodes[0]);
if (nodes[1]->getTypeId() == SoPointSet::getClassTypeId())
}
if (nodes[1]->getTypeId() == SoPointSet::getClassTypeId()) {
pcPoints = static_cast<SoPointSet*>(nodes[1]);
}
}
if (pcPointsCoord && pcPoints)
if (pcPointsCoord && pcPoints) {
createPoints(prop, pcPointsCoord, pcPoints);
}
}
void ViewProviderPointsBuilder::createPoints(const App::Property* prop, SoCoordinate3* coords, SoPointSet* points) const
void ViewProviderPointsBuilder::createPoints(const App::Property* prop,
SoCoordinate3* coords,
SoPointSet* points) const
{
const Points::PropertyPointKernel* prop_points = static_cast<const Points::PropertyPointKernel*>(prop);
const Points::PropertyPointKernel* prop_points =
static_cast<const Points::PropertyPointKernel*>(prop);
const Points::PointKernel& cPts = prop_points->getValue();
coords->point.setNum(cPts.size());
SbVec3f* vec = coords->point.startEditing();
// get all points
std::size_t idx=0;
std::size_t idx = 0;
const std::vector<Points::PointKernel::value_type>& kernel = cPts.getBasicPoints();
for (std::vector<Points::PointKernel::value_type>::const_iterator it = kernel.begin(); it != kernel.end(); ++it, idx++) {
for (std::vector<Points::PointKernel::value_type>::const_iterator it = kernel.begin();
it != kernel.end();
++it, idx++) {
vec[idx].setValue(it->x, it->y, it->z);
}
@@ -677,30 +725,36 @@ void ViewProviderPointsBuilder::createPoints(const App::Property* prop, SoCoordi
coords->point.finishEditing();
}
void ViewProviderPointsBuilder::createPoints(const App::Property* prop, SoCoordinate3* coords, SoIndexedPointSet* points) const
void ViewProviderPointsBuilder::createPoints(const App::Property* prop,
SoCoordinate3* coords,
SoIndexedPointSet* points) const
{
const Points::PropertyPointKernel* prop_points = static_cast<const Points::PropertyPointKernel*>(prop);
const Points::PropertyPointKernel* prop_points =
static_cast<const Points::PropertyPointKernel*>(prop);
const Points::PointKernel& cPts = prop_points->getValue();
coords->point.setNum(cPts.size());
SbVec3f* vec = coords->point.startEditing();
// get all points
std::size_t idx=0;
std::size_t idx = 0;
std::vector<int32_t> indices;
indices.reserve(cPts.size());
const std::vector<Points::PointKernel::value_type>& kernel = cPts.getBasicPoints();
for (std::vector<Points::PointKernel::value_type>::const_iterator it = kernel.begin(); it != kernel.end(); ++it, idx++) {
for (std::vector<Points::PointKernel::value_type>::const_iterator it = kernel.begin();
it != kernel.end();
++it, idx++) {
vec[idx].setValue(it->x, it->y, it->z);
// valid point?
if (!(boost::math::isnan(it->x) || boost::math::isnan(it->y) || boost::math::isnan(it->z))) {
if (!(boost::math::isnan(it->x) || boost::math::isnan(it->y)
|| boost::math::isnan(it->z))) {
indices.push_back(idx);
}
}
coords->point.finishEditing();
// get all point indices
idx=0;
idx = 0;
points->coordIndex.setNum(indices.size());
int32_t* pos = points->coordIndex.startEditing();
for (int32_t index : indices) {

View File

@@ -39,24 +39,28 @@ class SoCoordinate3;
class SoNormal;
class SoEventCallback;
namespace App {
class PropertyColorList;
namespace App
{
class PropertyColorList;
}
namespace Gui {
class SoFCSelection;
namespace Gui
{
class SoFCSelection;
}
namespace Points {
class PropertyGreyValueList;
class PropertyNormalList;
class PointKernel;
class Feature;
}
namespace Points
{
class PropertyGreyValueList;
class PropertyNormalList;
class PointKernel;
class Feature;
}// namespace Points
namespace PointsGui {
namespace PointsGui
{
class ViewProviderPointsBuilder : public Gui::ViewProviderBuilder
class ViewProviderPointsBuilder: public Gui::ViewProviderBuilder
{
public:
ViewProviderPointsBuilder() = default;
@@ -71,7 +75,7 @@ public:
* a node representing the point data structure.
* @author Werner Mayer
*/
class PointsGuiExport ViewProviderPoints : public Gui::ViewProviderGeometryObject
class PointsGuiExport ViewProviderPoints: public Gui::ViewProviderGeometryObject
{
PROPERTY_HEADER_WITH_OVERRIDE(PointsGui::ViewProviderPoints);
@@ -93,21 +97,21 @@ public:
void unsetEdit(int ModNum) override;
public:
static void clipPointsCallback(void * ud, SoEventCallback * n);
static void clipPointsCallback(void* ud, SoEventCallback* n);
protected:
void onChanged(const App::Property* prop) override;
void setVertexColorMode(App::PropertyColorList*);
void setVertexGreyvalueMode(Points::PropertyGreyValueList*);
void setVertexNormalMode(Points::PropertyNormalList*);
virtual void cut(const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer &Viewer) = 0;
virtual void cut(const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer& Viewer) = 0;
protected:
Gui::SoFCSelection * pcHighlight;
SoCoordinate3 * pcPointsCoord;
SoMaterial * pcColorMat;
SoNormal * pcPointsNormal;
SoDrawStyle * pcPointStyle;
Gui::SoFCSelection* pcHighlight;
SoCoordinate3* pcPointsCoord;
SoMaterial* pcColorMat;
SoNormal* pcPointsNormal;
SoDrawStyle* pcPointStyle;
private:
static App::PropertyFloatConstraint::Constraints floatRange;
@@ -118,7 +122,7 @@ private:
* a node representing the scattered point cloud.
* @author Werner Mayer
*/
class PointsGuiExport ViewProviderScattered : public ViewProviderPoints
class PointsGuiExport ViewProviderScattered: public ViewProviderPoints
{
PROPERTY_HEADER_WITH_OVERRIDE(PointsGui::ViewProviderScattered);
@@ -130,15 +134,15 @@ public:
* Extracts the point data from the feature \a pcFeature and creates
* an Inventor node \a SoNode with these data.
*/
void attach(App::DocumentObject *) override;
void attach(App::DocumentObject*) override;
/// Update the point representation
void updateData(const App::Property*) override;
protected:
void cut(const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer &Viewer) override;
void cut(const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer& Viewer) override;
protected:
SoPointSet * pcPoints;
SoPointSet* pcPoints;
};
/**
@@ -146,7 +150,7 @@ protected:
* a node representing the structured points.
* @author Werner Mayer
*/
class PointsGuiExport ViewProviderStructured : public ViewProviderPoints
class PointsGuiExport ViewProviderStructured: public ViewProviderPoints
{
PROPERTY_HEADER_WITH_OVERRIDE(PointsGui::ViewProviderStructured);
@@ -158,21 +162,20 @@ public:
* Extracts the point data from the feature \a pcFeature and creates
* an Inventor node \a SoNode with these data.
*/
void attach(App::DocumentObject *) override;
void attach(App::DocumentObject*) override;
/// Update the point representation
void updateData(const App::Property*) override;
protected:
void cut(const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer &Viewer) override;
void cut(const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer& Viewer) override;
protected:
SoIndexedPointSet * pcPoints;
SoIndexedPointSet* pcPoints;
};
using ViewProviderPython = Gui::ViewProviderPythonFeatureT<ViewProviderScattered>;
} // namespace PointsGui
}// namespace PointsGui
#endif // POINTSGUI_VIEWPROVIDERPOINTS_H
#endif// POINTSGUI_VIEWPROVIDERPOINTS_H

View File

@@ -30,7 +30,7 @@
using namespace PointsGui;
#if 0 // needed for Qt's lupdate utility
#if 0// needed for Qt's lupdate utility
qApp->translate("Workbench", "Points tools");
qApp->translate("Workbench", "&Points");
#endif
@@ -45,7 +45,7 @@ Workbench::~Workbench() = default;
Gui::ToolBarItem* Workbench::setupToolBars() const
{
Gui::ToolBarItem* root = StdWorkbench::setupToolBars();
Gui::ToolBarItem* pnt = new Gui::ToolBarItem( root );
Gui::ToolBarItem* pnt = new Gui::ToolBarItem(root);
pnt->setCommand("Points tools");
*pnt << "Points_Import"
<< "Points_Export"
@@ -61,7 +61,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const
{
// point tools
Gui::ToolBarItem* root = new Gui::ToolBarItem;
Gui::ToolBarItem* pnt = new Gui::ToolBarItem( root );
Gui::ToolBarItem* pnt = new Gui::ToolBarItem(root);
pnt->setCommand("Points tools");
*pnt << "Points_Import"
<< "Points_Export"

View File

@@ -27,26 +27,27 @@
#include <Gui/Workbench.h>
#include <Mod/Points/PointsGlobal.h>
namespace PointsGui {
namespace PointsGui
{
/**
* @author Werner Mayer
*/
class PointsGuiExport Workbench : public Gui::StdWorkbench
class PointsGuiExport Workbench: public Gui::StdWorkbench
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
Workbench();
~Workbench() override;
Workbench();
~Workbench() override;
protected:
Gui::ToolBarItem* setupToolBars() const override;
Gui::ToolBarItem* setupCommandBars() const override;
Gui::MenuItem* setupMenuBar() const override;
Gui::ToolBarItem* setupToolBars() const override;
Gui::ToolBarItem* setupCommandBars() const override;
Gui::MenuItem* setupMenuBar() const override;
};
} // namespace PointsGui
}// namespace PointsGui
#endif // POINTS_WORKBENCH_H
#endif// POINTS_WORKBENCH_H

View File

@@ -1,28 +1,28 @@
#***************************************************************************
#* Copyright (c) 2004,2005 Juergen Riegel <juergen.riegel@web.de> *
#* *
#* This file is part of the FreeCAD CAx development system. *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* FreeCAD is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU Lesser General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with FreeCAD; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************/
# ***************************************************************************
# * Copyright (c) 2004,2005 Juergen Riegel <juergen.riegel@web.de> *
# * *
# * This file is part of the FreeCAD CAx development system. *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * FreeCAD is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Lesser General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with FreeCAD; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************/
# FreeCAD init script of the Points module
# Append the open handler
FreeCAD.addImportType("Point formats (*.asc *.pcd *.ply *.e57)","Points")
FreeCAD.addExportType("Point formats (*.asc *.pcd *.ply)","Points")
FreeCAD.addImportType("Point formats (*.asc *.pcd *.ply *.e57)", "Points")
FreeCAD.addExportType("Point formats (*.asc *.pcd *.ply)", "Points")

View File

@@ -1,25 +1,25 @@
#***************************************************************************
#* Copyright (c) 2002,2003 Juergen Riegel <juergen.riegel@web.de> *
#* *
#* This file is part of the FreeCAD CAx development system. *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* FreeCAD is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU Lesser General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with FreeCAD; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************/
# ***************************************************************************
# * Copyright (c) 2002,2003 Juergen Riegel <juergen.riegel@web.de> *
# * *
# * This file is part of the FreeCAD CAx development system. *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * FreeCAD is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Lesser General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with FreeCAD; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************/
# Points gui init module
#
@@ -27,17 +27,23 @@
# This is the second one of three init scripts, the third one
# runs when the gui is up
class PointsWorkbench ( Workbench ):
class PointsWorkbench(Workbench):
"Points workbench object"
def __init__(self):
self.__class__.Icon = FreeCAD.getResourceDir() + "Mod/Points/Resources/icons/PointsWorkbench.svg"
self.__class__.Icon = (
FreeCAD.getResourceDir() + "Mod/Points/Resources/icons/PointsWorkbench.svg"
)
self.__class__.MenuText = "Points"
self.__class__.ToolTip = "Points workbench"
def Initialize(self):
# load the module
import PointsGui
def GetClassName(self):
return "PointsGui::Workbench"
Gui.addWorkbench(PointsWorkbench())

View File

@@ -29,19 +29,19 @@
// Points
#ifndef PointsExport
#ifdef Points_EXPORTS
# define PointsExport FREECAD_DECL_EXPORT
#define PointsExport FREECAD_DECL_EXPORT
#else
# define PointsExport FREECAD_DECL_IMPORT
#define PointsExport FREECAD_DECL_IMPORT
#endif
#endif
// PointsGui
#ifndef PointsGuiExport
#ifdef PointsGui_EXPORTS
# define PointsGuiExport FREECAD_DECL_EXPORT
#define PointsGuiExport FREECAD_DECL_EXPORT
#else
# define PointsGuiExport FREECAD_DECL_IMPORT
#define PointsGuiExport FREECAD_DECL_IMPORT
#endif
#endif
#endif //POINTS_GLOBAL_H
#endif// POINTS_GLOBAL_H

View File

@@ -32,6 +32,7 @@ __url__ = "https://www.freecad.org"
import FreeCAD
import Points
def make_points_from_geometry(geometries, distance):
for geom in geometries:
global_plm = geom.getGlobalPlacement()
@@ -54,8 +55,10 @@ def make_points_from_geometry(geometries, distance):
points.Points = kernel
points.Placement = plm
if len(points_and_normals[1]) > 0 and len(points_and_normals[0]) == len(points_and_normals[1]):
if len(points_and_normals[1]) > 0 and len(points_and_normals[0]) == len(
points_and_normals[1]
):
points.addProperty("Points::PropertyNormalList", "Normal")
points.Normal = points_and_normals[1]
points.purgeTouched()
points.purgeTouched()