App: changes in ComplexGeoData:
* rename some methods * distinguish between Point and Vector * support of arrays of Point or Vector
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#ifndef _AppComplexGeoData_h_
|
||||
#define _AppComplexGeoData_h_
|
||||
|
||||
#include <algorithm>
|
||||
#include <Base/Handle.h>
|
||||
#include <Base/Matrix.h>
|
||||
#include <Base/Persistence.h>
|
||||
@@ -199,14 +200,52 @@ public:
|
||||
protected:
|
||||
|
||||
/// from local to outside
|
||||
inline Base::Vector3d transformToOutside(const Base::Vector3f& vec) const
|
||||
inline Base::Vector3d transformPointToOutside(const Base::Vector3f& vec) const
|
||||
{
|
||||
return getTransform() * Base::Vector3d(static_cast<double>(vec.x),
|
||||
static_cast<double>(vec.y),
|
||||
static_cast<double>(vec.z));
|
||||
}
|
||||
/// from local to outside
|
||||
template<typename Vec>
|
||||
inline std::vector<Base::Vector3d> transformPointsToOutside(const std::vector<Vec>& input) const
|
||||
{
|
||||
std::vector<Base::Vector3d> output;
|
||||
output.reserve(input.size());
|
||||
Base::Matrix4D mat(getTransform());
|
||||
std::transform(input.cbegin(), input.cend(), std::back_inserter(output), [&mat](const Vec& vec) {
|
||||
return mat * Base::Vector3d(static_cast<double>(vec.x),
|
||||
static_cast<double>(vec.y),
|
||||
static_cast<double>(vec.z));
|
||||
});
|
||||
|
||||
return output;
|
||||
}
|
||||
inline Base::Vector3d transformVectorToOutside(const Base::Vector3f& vec) const
|
||||
{
|
||||
Base::Matrix4D mat(getTransform());
|
||||
mat.setCol(3, Base::Vector3d());
|
||||
return mat * Base::Vector3d(static_cast<double>(vec.x),
|
||||
static_cast<double>(vec.y),
|
||||
static_cast<double>(vec.z));
|
||||
}
|
||||
template<typename Vec>
|
||||
std::vector<Base::Vector3d> transformVectorsToOutside(const std::vector<Vec>& input) const
|
||||
{
|
||||
std::vector<Base::Vector3d> output;
|
||||
output.reserve(input.size());
|
||||
Base::Matrix4D mat(getTransform());
|
||||
mat.setCol(3, Base::Vector3d());
|
||||
std::transform(input.cbegin(), input.cend(), std::back_inserter(output), [&mat](const Vec& vec) {
|
||||
return mat * Base::Vector3d(static_cast<double>(vec.x),
|
||||
static_cast<double>(vec.y),
|
||||
static_cast<double>(vec.z));
|
||||
});
|
||||
|
||||
return output;
|
||||
}
|
||||
/// from local to inside
|
||||
inline Base::Vector3f transformToInside(const Base::Vector3d& vec) const
|
||||
inline Base::Vector3f transformPointToInside(const Base::Vector3d& vec) const
|
||||
{
|
||||
Base::Matrix4D tmpM(getTransform());
|
||||
tmpM.inverse();
|
||||
|
||||
@@ -537,6 +537,9 @@ public:
|
||||
/// Rebuilds up data structure
|
||||
void Rebuild ();
|
||||
const Base::Vector3f& operator[] (PointIndex) const;
|
||||
const std::vector<Base::Vector3f>& GetValues() const {
|
||||
return _norm;
|
||||
}
|
||||
|
||||
protected:
|
||||
const MeshKernel &_rclMesh; /**< The mesh kernel. */
|
||||
|
||||
@@ -174,7 +174,7 @@ Base::BoundBox3d MeshObject::getBoundBox()const
|
||||
Base::BoundBox3d Bnd2;
|
||||
if (Bnd.IsValid()) {
|
||||
for (int i =0 ;i<=7;i++)
|
||||
Bnd2.Add(transformToOutside(Bnd.CalcPoint(i)));
|
||||
Bnd2.Add(transformPointToOutside(Bnd.CalcPoint(i)));
|
||||
}
|
||||
|
||||
return Bnd2;
|
||||
@@ -184,7 +184,7 @@ bool MeshObject::getCenterOfGravity(Base::Vector3d& center) const
|
||||
{
|
||||
MeshCore::MeshAlgorithm alg(_kernel);
|
||||
Base::Vector3f pnt = alg.GetGravityPoint();
|
||||
center = transformToOutside(pnt);
|
||||
center = transformPointToOutside(pnt);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -311,26 +311,9 @@ void MeshObject::getPoints(std::vector<Base::Vector3d> &Points,
|
||||
std::vector<Base::Vector3d> &Normals,
|
||||
float /*Accuracy*/, uint16_t /*flags*/) const
|
||||
{
|
||||
Base::Matrix4D mat = _Mtrx;
|
||||
|
||||
unsigned long ctpoints = _kernel.CountPoints();
|
||||
Points.reserve(ctpoints);
|
||||
for (unsigned long i=0; i<ctpoints; i++) {
|
||||
Points.push_back(getPoint(i));
|
||||
}
|
||||
|
||||
// nullify translation part
|
||||
mat[0][3] = 0.0;
|
||||
mat[1][3] = 0.0;
|
||||
mat[2][3] = 0.0;
|
||||
Normals.reserve(ctpoints);
|
||||
Points = transformPointsToOutside(_kernel.GetPoints());
|
||||
MeshCore::MeshRefNormalToPoints ptNormals(_kernel);
|
||||
for (unsigned long i=0; i<ctpoints; i++) {
|
||||
Base::Vector3f normalf = ptNormals[i];
|
||||
Base::Vector3d normald(normalf.x, normalf.y, normalf.z);
|
||||
normald = mat * normald;
|
||||
Normals.push_back(normald);
|
||||
}
|
||||
Normals = transformVectorsToOutside(ptNormals.GetValues());
|
||||
}
|
||||
|
||||
Mesh::Facet MeshObject::getMeshFacet(FacetIndex index) const
|
||||
@@ -1001,12 +984,12 @@ void MeshObject::movePoint(PointIndex index, const Base::Vector3d& v)
|
||||
vec.x += _Mtrx[0][3];
|
||||
vec.y += _Mtrx[1][3];
|
||||
vec.z += _Mtrx[2][3];
|
||||
_kernel.MovePoint(index,transformToInside(vec));
|
||||
_kernel.MovePoint(index, transformPointToInside(vec));
|
||||
}
|
||||
|
||||
void MeshObject::setPoint(PointIndex index, const Base::Vector3d& p)
|
||||
{
|
||||
_kernel.SetPoint(index,transformToInside(p));
|
||||
_kernel.SetPoint(index, transformPointToInside(p));
|
||||
}
|
||||
|
||||
void MeshObject::smooth(int iterations, float d_max)
|
||||
@@ -1029,13 +1012,7 @@ void MeshObject::decimate(int targetSize)
|
||||
Base::Vector3d MeshObject::getPointNormal(PointIndex index) const
|
||||
{
|
||||
std::vector<Base::Vector3f> temp = _kernel.CalcVertexNormals();
|
||||
Base::Vector3d normal = transformToOutside(temp[index]);
|
||||
|
||||
// the normal is a vector, hence we must not apply the translation part
|
||||
// of the transformation to the vector
|
||||
normal.x -= _Mtrx[0][3];
|
||||
normal.y -= _Mtrx[1][3];
|
||||
normal.z -= _Mtrx[2][3];
|
||||
Base::Vector3d normal = transformVectorToOutside(temp[index]);
|
||||
normal.Normalize();
|
||||
return normal;
|
||||
}
|
||||
@@ -1044,19 +1021,10 @@ std::vector<Base::Vector3d> MeshObject::getPointNormals() const
|
||||
{
|
||||
std::vector<Base::Vector3f> temp = _kernel.CalcVertexNormals();
|
||||
|
||||
std::vector<Base::Vector3d> normals;
|
||||
normals.reserve(temp.size());
|
||||
for (std::vector<Base::Vector3f>::iterator it = temp.begin(); it != temp.end(); ++it) {
|
||||
Base::Vector3d normal = transformToOutside(*it);
|
||||
// the normal is a vector, hence we must not apply the translation part
|
||||
// of the transformation to the vector
|
||||
normal.x -= _Mtrx[0][3];
|
||||
normal.y -= _Mtrx[1][3];
|
||||
normal.z -= _Mtrx[2][3];
|
||||
normal.Normalize();
|
||||
normals.push_back(normal);
|
||||
std::vector<Base::Vector3d> normals = transformVectorsToOutside(temp);
|
||||
for (auto& n : normals) {
|
||||
n.Normalize();
|
||||
}
|
||||
|
||||
return normals;
|
||||
}
|
||||
|
||||
|
||||
@@ -130,15 +130,15 @@ public:
|
||||
|
||||
/// get the points
|
||||
inline const Base::Vector3d getPoint(const int idx) const {
|
||||
return transformToOutside(_Points[idx]);
|
||||
return transformPointToOutside(_Points[idx]);
|
||||
}
|
||||
/// set the points
|
||||
inline void setPoint(const int idx,const Base::Vector3d& point) {
|
||||
_Points[idx] = transformToInside(point);
|
||||
_Points[idx] = transformPointToInside(point);
|
||||
}
|
||||
/// insert the points
|
||||
inline void push_back(const Base::Vector3d& point) {
|
||||
_Points.push_back(transformToInside(point));
|
||||
_Points.push_back(transformPointToInside(point));
|
||||
}
|
||||
|
||||
class PointsExport const_point_iterator
|
||||
|
||||
Reference in New Issue
Block a user