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

@@ -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();
}