Merge remote-tracking branch 'refs/remotes/origin/wmayer/pcl-testing' into jriegel/NewWinBuild
Conflicts: src/Mod/Points/App/CMakeLists.txt src/Mod/ReverseEngineering/App/AppReverseEngineeringPy.cpp
This commit is contained in:
commit
7183cda616
|
@ -521,6 +521,10 @@ else(FREECAD_LIBPACK_USE)
|
||||||
|
|
||||||
find_package(Eigen3)
|
find_package(Eigen3)
|
||||||
|
|
||||||
|
# -------------------------------- pcl ----------------------------------
|
||||||
|
|
||||||
|
find_package(PCL COMPONENTS common kdtree features surface)
|
||||||
|
|
||||||
# -------------------------------- ODE ----------------------------------
|
# -------------------------------- ODE ----------------------------------
|
||||||
|
|
||||||
# find_package(ODE)
|
# find_package(ODE)
|
||||||
|
|
|
@ -168,3 +168,4 @@ struct PyMethodDef Points_Import_methods[] = {
|
||||||
|
|
||||||
{NULL, NULL} /* end of table marker */
|
{NULL, NULL} /* end of table marker */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,12 @@
|
||||||
#include <Base/Console.h>
|
#include <Base/Console.h>
|
||||||
|
|
||||||
#include <Mod/Part/App/BSplineSurfacePy.h>
|
#include <Mod/Part/App/BSplineSurfacePy.h>
|
||||||
|
#include <Mod/Mesh/App/Mesh.h>
|
||||||
|
#include <Mod/Mesh/App/MeshPy.h>
|
||||||
|
#include <Mod/Points/App/PointsPy.h>
|
||||||
|
|
||||||
#include "ApproxSurface.h"
|
#include "ApproxSurface.h"
|
||||||
|
#include "SurfaceTriangulation.h"
|
||||||
|
|
||||||
using namespace Reen;
|
using namespace Reen;
|
||||||
|
|
||||||
|
@ -75,8 +79,31 @@ static PyObject * approxSurface(PyObject *self, PyObject *args)
|
||||||
} PY_CATCH;
|
} PY_CATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(PCL_FOUND)
|
||||||
|
static PyObject *
|
||||||
|
triangulate(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject *pcObj;
|
||||||
|
if (!PyArg_ParseTuple(args, "O!", &(Points::PointsPy::Type), &pcObj))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
Points::PointsPy* pPoints = static_cast<Points::PointsPy*>(pcObj);
|
||||||
|
Points::PointKernel* points = pPoints->getPointKernelPtr();
|
||||||
|
|
||||||
|
Mesh::MeshObject* mesh = new Mesh::MeshObject();
|
||||||
|
SurfaceTriangulation tria(*points, *mesh);
|
||||||
|
tria.perform();
|
||||||
|
|
||||||
|
return new Mesh::MeshPy(mesh);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* registration table */
|
/* registration table */
|
||||||
struct PyMethodDef ReverseEngineering_methods[] = {
|
struct PyMethodDef ReverseEngineering_methods[] = {
|
||||||
{"approxSurface" , approxSurface, 1},
|
{"approxSurface" , approxSurface, 1},
|
||||||
|
#if defined(PCL_FOUND)
|
||||||
|
{"triangulate" , triangulate, 1},
|
||||||
|
#endif
|
||||||
{NULL, NULL} /* end of table marker */
|
{NULL, NULL} /* end of table marker */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,10 @@ else(MSVC)
|
||||||
add_definitions(-DHAVE_LIMITS_H -DHAVE_CONFIG_H)
|
add_definitions(-DHAVE_LIMITS_H -DHAVE_CONFIG_H)
|
||||||
endif(MSVC)
|
endif(MSVC)
|
||||||
|
|
||||||
|
if (PCL_FOUND)
|
||||||
|
add_definitions(-DPCL_FOUND)
|
||||||
|
endif(PCL_FOUND)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
${CMAKE_SOURCE_DIR}/src
|
${CMAKE_SOURCE_DIR}/src
|
||||||
${Boost_INCLUDE_DIRS}
|
${Boost_INCLUDE_DIRS}
|
||||||
|
@ -11,6 +15,8 @@ include_directories(
|
||||||
${PYTHON_INCLUDE_PATH}
|
${PYTHON_INCLUDE_PATH}
|
||||||
${XERCESC_INCLUDE_DIR}
|
${XERCESC_INCLUDE_DIR}
|
||||||
${ZLIB_INCLUDE_DIR}
|
${ZLIB_INCLUDE_DIR}
|
||||||
|
${EIGEN3_INCLUDE_DIR}
|
||||||
|
${PCL_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
link_directories(${OCC_LIBRARY_DIR})
|
link_directories(${OCC_LIBRARY_DIR})
|
||||||
|
@ -18,7 +24,12 @@ link_directories(${OCC_LIBRARY_DIR})
|
||||||
set(Reen_LIBS
|
set(Reen_LIBS
|
||||||
Part
|
Part
|
||||||
Mesh
|
Mesh
|
||||||
|
Points
|
||||||
FreeCADApp
|
FreeCADApp
|
||||||
|
${PCL_COMMON_LIBRARIES}
|
||||||
|
${PCL_KDTREE_LIBRARIES}
|
||||||
|
${PCL_FEATURES_LIBRARIES}
|
||||||
|
${PCL_SURFACE_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(Reen_SRCS
|
SET(Reen_SRCS
|
||||||
|
@ -26,6 +37,8 @@ SET(Reen_SRCS
|
||||||
AppReverseEngineeringPy.cpp
|
AppReverseEngineeringPy.cpp
|
||||||
ApproxSurface.cpp
|
ApproxSurface.cpp
|
||||||
ApproxSurface.h
|
ApproxSurface.h
|
||||||
|
SurfaceTriangulation.cpp
|
||||||
|
SurfaceTriangulation.h
|
||||||
PreCompiled.cpp
|
PreCompiled.cpp
|
||||||
PreCompiled.h
|
PreCompiled.h
|
||||||
)
|
)
|
||||||
|
|
|
@ -29,12 +29,14 @@
|
||||||
// Exporting of App classes
|
// Exporting of App classes
|
||||||
#ifdef FC_OS_WIN32
|
#ifdef FC_OS_WIN32
|
||||||
# define ReenExport __declspec(dllexport)
|
# define ReenExport __declspec(dllexport)
|
||||||
# define PartExport __declspec(dllimport)
|
# define PartExport __declspec(dllimport)
|
||||||
# define MeshExport __declspec(dllimport)
|
# define MeshExport __declspec(dllimport)
|
||||||
|
# define PointsExport __declspec(dllimport)
|
||||||
#else // for Linux
|
#else // for Linux
|
||||||
# define ReenExport
|
# define ReenExport
|
||||||
# define PartExport
|
# define PartExport
|
||||||
# define MeshExport
|
# define MeshExport
|
||||||
|
# define PointsExport
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _PreComp_
|
#ifdef _PreComp_
|
||||||
|
|
159
src/Mod/ReverseEngineering/App/SurfaceTriangulation.cpp
Normal file
159
src/Mod/ReverseEngineering/App/SurfaceTriangulation.cpp
Normal file
|
@ -0,0 +1,159 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* Copyright (c) 2012 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||||
|
* *
|
||||||
|
* This file is part of the FreeCAD CAx development system. *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Library General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 Library General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Library General Public *
|
||||||
|
* License along with this library; see the file COPYING.LIB. If not, *
|
||||||
|
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||||
|
* Suite 330, Boston, MA 02111-1307, USA *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#include "PreCompiled.h"
|
||||||
|
|
||||||
|
#include "SurfaceTriangulation.h"
|
||||||
|
#include <Mod/Points/App/Points.h>
|
||||||
|
#include <Mod/Mesh/App/Mesh.h>
|
||||||
|
#include <Mod/Mesh/App/Core/Elements.h>
|
||||||
|
#include <Mod/Mesh/App/Core/MeshKernel.h>
|
||||||
|
|
||||||
|
// http://svn.pointclouds.org/pcl/tags/pcl-1.5.1/test/
|
||||||
|
#if defined(PCL_FOUND)
|
||||||
|
#include <pcl/point_types.h>
|
||||||
|
#include <pcl/features/normal_3d.h>
|
||||||
|
#include <pcl/surface/mls.h>
|
||||||
|
#include <pcl/surface/mls_omp.h>
|
||||||
|
#include <pcl/surface/gp3.h>
|
||||||
|
#include <pcl/surface/grid_projection.h>
|
||||||
|
#include <pcl/surface/convex_hull.h>
|
||||||
|
#include <pcl/surface/concave_hull.h>
|
||||||
|
#include <pcl/surface/organized_fast_mesh.h>
|
||||||
|
#include <pcl/surface/ear_clipping.h>
|
||||||
|
#include <pcl/common/common.h>
|
||||||
|
#include <boost/random.hpp>
|
||||||
|
|
||||||
|
using namespace pcl;
|
||||||
|
using namespace pcl::io;
|
||||||
|
using namespace std;
|
||||||
|
using namespace Reen;
|
||||||
|
|
||||||
|
SurfaceTriangulation::SurfaceTriangulation(const Points::PointKernel& pts, Mesh::MeshObject& mesh)
|
||||||
|
: myPoints(pts), myMesh(mesh)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SurfaceTriangulation::perform()
|
||||||
|
{
|
||||||
|
PointCloud<PointXYZ>::Ptr cloud (new PointCloud<PointXYZ>);
|
||||||
|
PointCloud<PointNormal>::Ptr cloud_with_normals (new PointCloud<PointNormal>);
|
||||||
|
search::KdTree<PointXYZ>::Ptr tree;
|
||||||
|
search::KdTree<PointNormal>::Ptr tree2;
|
||||||
|
|
||||||
|
for (Points::PointKernel::const_iterator it = myPoints.begin(); it != myPoints.end(); ++it) {
|
||||||
|
cloud->push_back(PointXYZ(it->x, it->y, it->z));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create search tree
|
||||||
|
tree.reset (new search::KdTree<PointXYZ> (false));
|
||||||
|
tree->setInputCloud (cloud);
|
||||||
|
|
||||||
|
// Normal estimation
|
||||||
|
NormalEstimation<PointXYZ, Normal> n;
|
||||||
|
PointCloud<Normal>::Ptr normals (new PointCloud<Normal> ());
|
||||||
|
n.setInputCloud (cloud);
|
||||||
|
//n.setIndices (indices[B);
|
||||||
|
n.setSearchMethod (tree);
|
||||||
|
n.setKSearch (20);
|
||||||
|
n.compute (*normals);
|
||||||
|
|
||||||
|
// Concatenate XYZ and normal information
|
||||||
|
pcl::concatenateFields (*cloud, *normals, *cloud_with_normals);
|
||||||
|
|
||||||
|
// Create search tree
|
||||||
|
tree2.reset (new search::KdTree<PointNormal>);
|
||||||
|
tree2->setInputCloud (cloud_with_normals);
|
||||||
|
|
||||||
|
// Init objects
|
||||||
|
GreedyProjectionTriangulation<PointNormal> gp3;
|
||||||
|
|
||||||
|
// Set parameters
|
||||||
|
gp3.setInputCloud (cloud_with_normals);
|
||||||
|
gp3.setSearchMethod (tree2);
|
||||||
|
gp3.setSearchRadius (2.025);
|
||||||
|
gp3.setMu (2.5);
|
||||||
|
gp3.setMaximumNearestNeighbors (100);
|
||||||
|
gp3.setMaximumSurfaceAngle(M_PI/4); // 45 degrees
|
||||||
|
gp3.setMinimumAngle(M_PI/18); // 10 degrees
|
||||||
|
gp3.setMaximumAngle(2*M_PI/3); // 120 degrees
|
||||||
|
gp3.setNormalConsistency(false);
|
||||||
|
|
||||||
|
// Reconstruct
|
||||||
|
PolygonMesh mesh;
|
||||||
|
gp3.reconstruct (mesh);
|
||||||
|
|
||||||
|
// number of points
|
||||||
|
int nr_points = mesh.cloud.width * mesh.cloud.height;
|
||||||
|
int point_size = mesh.cloud.data.size () / nr_points;
|
||||||
|
// number of faces for header
|
||||||
|
int nr_faces = mesh.polygons.size ();
|
||||||
|
|
||||||
|
MeshCore::MeshPointArray points;
|
||||||
|
points.reserve(nr_points);
|
||||||
|
MeshCore::MeshFacetArray facets;
|
||||||
|
facets.reserve(nr_faces);
|
||||||
|
|
||||||
|
// get vertices
|
||||||
|
MeshCore::MeshPoint vertex;
|
||||||
|
for (int i = 0; i < nr_points; ++i) {
|
||||||
|
int xyz = 0;
|
||||||
|
for (size_t d = 0; d < mesh.cloud.fields.size(); ++d) {
|
||||||
|
int c = 0;
|
||||||
|
// adding vertex
|
||||||
|
if ((mesh.cloud.fields[d].datatype == sensor_msgs::PointField::FLOAT32) && (
|
||||||
|
mesh.cloud.fields[d].name == "x" ||
|
||||||
|
mesh.cloud.fields[d].name == "y" ||
|
||||||
|
mesh.cloud.fields[d].name == "z"))
|
||||||
|
{
|
||||||
|
float value;
|
||||||
|
memcpy (&value, &mesh.cloud.data[i * point_size + mesh.cloud.fields[d].offset + c * sizeof (float)], sizeof (float));
|
||||||
|
vertex[xyz] = value;
|
||||||
|
if (++xyz == 3) {
|
||||||
|
points.push_back(vertex);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// get faces
|
||||||
|
MeshCore::MeshFacet face;
|
||||||
|
for(int i = 0; i < nr_faces; i++) {
|
||||||
|
face._aulPoints[0] = mesh.polygons[i].vertices[0];
|
||||||
|
face._aulPoints[1] = mesh.polygons[i].vertices[1];
|
||||||
|
face._aulPoints[2] = mesh.polygons[i].vertices[2];
|
||||||
|
facets.push_back(face);
|
||||||
|
}
|
||||||
|
|
||||||
|
MeshCore::MeshKernel kernel;
|
||||||
|
kernel.Adopt(points, facets, true);
|
||||||
|
myMesh.swap(kernel);
|
||||||
|
myMesh.harmonizeNormals();
|
||||||
|
|
||||||
|
// Additional vertex information
|
||||||
|
//std::vector<int> parts = gp3.getPartIDs();
|
||||||
|
//std::vector<int> states = gp3.getPointStates();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // PCL_FOUND
|
||||||
|
|
46
src/Mod/ReverseEngineering/App/SurfaceTriangulation.h
Normal file
46
src/Mod/ReverseEngineering/App/SurfaceTriangulation.h
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* Copyright (c) 2012 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||||
|
* *
|
||||||
|
* This file is part of the FreeCAD CAx development system. *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Library General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 Library General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Library General Public *
|
||||||
|
* License along with this library; see the file COPYING.LIB. If not, *
|
||||||
|
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||||
|
* Suite 330, Boston, MA 02111-1307, USA *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef REEN_SURFACETRIANGULATION_H
|
||||||
|
#define REEN_SURFACETRIANGULATION_H
|
||||||
|
|
||||||
|
namespace Points {class PointKernel;}
|
||||||
|
namespace Mesh {class MeshObject;}
|
||||||
|
|
||||||
|
namespace Reen {
|
||||||
|
|
||||||
|
class SurfaceTriangulation
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SurfaceTriangulation(const Points::PointKernel&, Mesh::MeshObject&);
|
||||||
|
void perform();
|
||||||
|
|
||||||
|
private:
|
||||||
|
const Points::PointKernel& myPoints;
|
||||||
|
Mesh::MeshObject& myMesh;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Reen
|
||||||
|
|
||||||
|
#endif // REEN_SURFACETRIANGULATION_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user