+ unify DLL export defines to namespace names

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5000 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
wmayer
2011-10-10 13:44:52 +00:00
commit 120ca87015
4155 changed files with 2965978 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
/***************************************************************************
* Copyright (c) 2008 Jürgen Riegel (juergen.riegel@web.de) *
* *
* 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"
#ifndef _PreComp_
# include <Python.h>
#endif
#include <Base/Console.h>
#include <Base/Interpreter.h>
extern struct PyMethodDef MeshPart_methods[];
PyDoc_STRVAR(module_MeshPart_doc,
"This module is the MeshPart module.");
/* Python entry */
extern "C" {
void MeshPartExport initMeshPart()
{
// load dependent module
try {
Base::Interpreter().loadModule("Part");
//Base::Interpreter().loadModule("Mesh");
}
catch(const Base::Exception& e) {
PyErr_SetString(PyExc_ImportError, e.what());
return;
}
Py_InitModule3("MeshPart", MeshPart_methods, module_MeshPart_doc); /* mod name, table ptr */
Base::Console().Log("Loading MeshPart module... done\n");
// NOTE: To finish the initialization of our own type objects we must
// call PyType_Ready, otherwise we run into a segmentation fault, later on.
// This function is responsible for adding inherited slots from a type's base class.
//MeshPart::FeatureViewPart ::init();
}
} // extern "C"

View File

@@ -0,0 +1,172 @@
/***************************************************************************
* Copyright (c) 2008 Jürgen Riegel (juergen.riegel@web.de) *
* *
* 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"
#ifndef _PreComp_
# include <BRepBuilderAPI_MakePolygon.hxx>
#endif
#include <Base/PyObjectBase.h>
#include <Base/Console.h>
#include <Base/Vector3D.h>
#include <Mod/Part/App/TopoShapePy.h>
#include <Mod/Part/App/TopoShapeWirePy.h>
#include <Mod/Mesh/App/Core/Algorithm.h>
#include <Mod/Mesh/App/Core/MeshKernel.h>
#include <Mod/Mesh/App/Mesh.h>
#include <Mod/Mesh/App/MeshPy.h>
#include "MeshAlgos.h"
#include "Mesher.h"
static PyObject *
loftOnCurve(PyObject *self, PyObject *args)
{
Part::TopoShapePy *pcObject;
PyObject *pcTopoObj,*pcListObj;
float x=0.0f,y=0.0f,z=1.0f,size = 0.1f;
if (!PyArg_ParseTuple(args, "O!O(fff)f", &(Part::TopoShapePy::Type), &pcTopoObj,&pcListObj,&x,&y,&z,&size)) // convert args: Python->C
// if (!PyArg_ParseTuple(args, "O!O!", &(App::TopoShapePy::Type), &pcTopoObj,&PyList_Type,&pcListObj,x,y,z,size)) // convert args: Python->C
return NULL; // NULL triggers exception
pcObject = (Part::TopoShapePy*)pcTopoObj;
MeshCore::MeshKernel M;
std::vector<Base::Vector3f> poly;
if (!PyList_Check(pcListObj))
Py_Error(PyExc_Exception,"List of Tuble of three or two floats needed as second parameter!");
int nSize = PyList_Size(pcListObj);
for (int i=0; i<nSize;++i)
{
PyObject* item = PyList_GetItem(pcListObj, i);
if (!PyTuple_Check(item))
Py_Error(PyExc_Exception,"List of Tuble of three or two floats needed as second parameter!");
int nTSize = PyTuple_Size(item);
if(nTSize != 2 && nTSize != 3)
Py_Error(PyExc_Exception,"List of Tuble of three or two floats needed as second parameter!");
Base::Vector3f vec(0,0,0);
for(int l = 0; l < nTSize;l++)
{
PyObject* item2 = PyTuple_GetItem(item, l);
if (!PyFloat_Check(item2))
Py_Error(PyExc_Exception,"List of Tuble of three or two floats needed as second parameter!");
vec[l] = (float)PyFloat_AS_DOUBLE(item2);
}
poly.push_back(vec);
}
PY_TRY {
TopoDS_Shape aShape = pcObject->getTopoShapePtr()->_Shape;
// use the MeshAlgos
MeshPart::MeshAlgos::LoftOnCurve(M,aShape,poly,Base::Vector3f(x,y,z),size);
} PY_CATCH;
return new Mesh::MeshPy(new Mesh::MeshObject(M));
}
PyDoc_STRVAR(loft_doc,
"Loft on curve.");
static PyObject *
wireFromSegment(PyObject *self, PyObject *args)
{
PyObject *o, *m;
if (!PyArg_ParseTuple(args, "O!O!", &(Mesh::MeshPy::Type), &m,&PyList_Type,&o))
return 0;
Py::List list(o);
Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr();
std::vector<unsigned long> segm;
segm.reserve(list.size());
for (unsigned int i=0; i<list.size(); i++) {
segm.push_back((int)Py::Int(list[i]));
}
std::list<std::vector<Base::Vector3f> > bounds;
MeshCore::MeshAlgorithm algo(mesh->getKernel());
algo.GetFacetBorders(segm, bounds);
Py::List wires;
std::list<std::vector<Base::Vector3f> >::iterator bt;
try {
for (bt = bounds.begin(); bt != bounds.end(); ++bt) {
BRepBuilderAPI_MakePolygon mkPoly;
for (std::vector<Base::Vector3f>::reverse_iterator it = bt->rbegin(); it != bt->rend(); ++it) {
mkPoly.Add(gp_Pnt(it->x,it->y,it->z));
}
if (mkPoly.IsDone()) {
PyObject* wire = new Part::TopoShapeWirePy(new Part::TopoShape(mkPoly.Wire()));
wires.append(Py::Object(wire, true));
}
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
return Py::new_reference_to(wires);
}
static PyObject *
meshFromShape(PyObject *self, PyObject *args)
{
PyObject *shape;
float maxLength=1.0f/*0.5f*/;
float maxArea=0/*1.0f*/;
float localLen=0/*0.1f*/;
float deflection=0/*0.01f*/;
if (!PyArg_ParseTuple(args, "O!|ffff", &(Part::TopoShapePy::Type), &shape,
&maxLength,&maxArea,&localLen,&deflection))
return 0;
try {
MeshPart::Mesher mesher(static_cast<Part::TopoShapePy*>(shape)->getTopoShapePtr()->_Shape);
mesher.setMaxLength(maxLength);
mesher.setMaxArea(maxArea);
mesher.setLocalLength(localLen);
mesher.setDeflection(deflection);
mesher.setRegular(true);
return new Mesh::MeshPy(mesher.createMesh());
}
catch (const Base::Exception& e) {
PyErr_SetString(PyExc_Exception, e.what());
return 0;
}
}
/* registration table */
struct PyMethodDef MeshPart_methods[] = {
{"loftOnCurve",loftOnCurve, METH_VARARGS, loft_doc},
{"wireFromSegment",wireFromSegment, METH_VARARGS,
"Create wire(s) from boundary of segment"},
{"meshFromShape",meshFromShape, METH_VARARGS,
"Create mesh from shape"},
{NULL, NULL} /* end of table marker */
};

View File

@@ -0,0 +1,71 @@
if(MSVC)
add_definitions(-DFCAppMeshPart -DHAVE_ACOSH -DHAVE_ASINH -DHAVE_ATANH)
else(MSVC)
add_definitions(-DHAVE_LIMITS_H -DHAVE_CONFIG_H)
endif(MSVC)
if (SMESH_FOUND)
add_definitions(-DHAVE_SMESH)
endif(SMESH_FOUND)
include_directories(
${CMAKE_SOURCE_DIR}/src
${Boost_INCLUDE_DIRS}
${OCC_INCLUDE_DIR}
${ZLIB_INCLUDE_DIR}
${PYTHON_INCLUDE_PATH}
${XERCESC_INCLUDE_DIR}
)
if(SMESH_FOUND)
include_directories(
${SMESH_INCLUDE_DIR}
)
endif(SMESH_FOUND)
link_directories(${OCC_LIBRARY_DIR})
if(SMESH_FOUND)
set(MeshPart_LIBS
Part
Mesh
${SMESH_LIBRARIES}
)
else(SMESH_FOUND)
set(MeshPart_LIBS
Part
Mesh
)
endif(SMESH_FOUND)
SET(MeshPart_SRCS
AppMeshPart.cpp
AppMeshPartPy.cpp
CurveProjector.cpp
CurveProjector.h
MeshAlgos.cpp
MeshAlgos.h
Mesher.cpp
Mesher.h
PreCompiled.cpp
PreCompiled.h
)
add_library(MeshPart SHARED ${MeshPart_SRCS})
target_link_libraries(MeshPart ${MeshPart_LIBS})
fc_copy_script("Mod/MeshPart" "MeshPart" Init.py)
if(MSVC)
set_target_properties(MeshPart PROPERTIES SUFFIX ".pyd")
set_target_properties(MeshPart PROPERTIES DEBUG_OUTPUT_NAME "MeshPart_d")
set_target_properties(MeshPart PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Mod/MeshPart)
set_target_properties(MeshPart PROPERTIES PREFIX "../")
elseif(MINGW)
set_target_properties(MeshPart PROPERTIES SUFFIX ".pyd")
set_target_properties(MeshPart PROPERTIES DEBUG_OUTPUT_NAME "MeshPart_d")
set_target_properties(MeshPart PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Mod/MeshPart)
set_target_properties(MeshPart PROPERTIES PREFIX "")
else(MSVC)
set_target_properties(MeshPart PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Mod/MeshPart)
set_target_properties(MeshPart PROPERTIES PREFIX "")
endif(MSVC)
install(TARGETS MeshPart DESTINATION lib)

View File

@@ -0,0 +1,671 @@
/***************************************************************************
* Copyright (c) Juergen Riegel <juergen.riegel@web.de> *
* *
* 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"
#ifndef _PreComp_
# ifdef FC_OS_LINUX
# include <unistd.h>
# endif
#endif
#include "MeshAlgos.h"
#include "CurveProjector.h"
#include <Mod/Mesh/App/Core/MeshIO.h>
#include <Mod/Mesh/App/Core/MeshKernel.h>
#include <Mod/Mesh/App/Core/Iterator.h>
#include <Mod/Mesh/App/Core/Algorithm.h>
#include <Mod/Mesh/App/Mesh.h>
#include <Base/Exception.h>
#include <Base/Console.h>
#include <Base/Sequencer.h>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <Geom_Curve.hxx>
#include <Geom_Plane.hxx>
#include <BRep_Tool.hxx>
#include <GeomAPI_IntCS.hxx>
using namespace MeshPart;
using namespace MeshCore;
CurveProjector::CurveProjector(const TopoDS_Shape &aShape, const MeshKernel &pMesh)
: _Shape(aShape), _Mesh(pMesh)
{
}
void CurveProjector::writeIntersectionPointsToFile(const char *name)
{
// export points
std::ofstream str(name, std::ios::out | std::ios::binary);
str.precision(4);
str.setf(std::ios::fixed | std::ios::showpoint);
for (result_type::const_iterator it1 = mvEdgeSplitPoints.begin();it1!=mvEdgeSplitPoints.end();++it1) {
for (std::vector<FaceSplitEdge>::const_iterator it2 = it1->second.begin();it2!=it1->second.end();++it2) {
str << it2->p1.x << " " << it2->p1.y << " " << it2->p1.z << std::endl;
}
}
str.close();
}
//**************************************************************************
//**************************************************************************
// Seperator for additional classes
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CurveProjectorShape::CurveProjectorShape(const TopoDS_Shape &aShape, const MeshKernel &pMesh)
: CurveProjector(aShape,pMesh)
{
Do();
}
void CurveProjectorShape::Do(void)
{
TopExp_Explorer Ex;
TopoDS_Shape Edge;
for (Ex.Init(_Shape, TopAbs_EDGE); Ex.More(); Ex.Next())
{
const TopoDS_Edge& aEdge = TopoDS::Edge(Ex.Current());
//std::vector<FaceSplitEdge> vSplitEdges;
projectCurve(aEdge, mvEdgeSplitPoints[aEdge]);
}
}
void CurveProjectorShape::projectCurve( const TopoDS_Edge& aEdge,
std::vector<FaceSplitEdge> &vSplitEdges)
{
Standard_Real fFirst, fLast;
Handle(Geom_Curve) hCurve = BRep_Tool::Curve( aEdge,fFirst,fLast );
// getting start point
gp_Pnt gpPt = hCurve->Value(fFirst);
// projection of the first point
Base::Vector3f cStartPoint = Base::Vector3f((float)gpPt.X(),
(float)gpPt.Y(),
(float)gpPt.Z());
Base::Vector3f cResultPoint, cSplitPoint, cPlanePnt, cPlaneNormal;
unsigned long uStartFacetIdx,uCurFacetIdx;
unsigned long uLastFacetIdx=ULONG_MAX-1; // use another value as ULONG_MAX
unsigned long auNeighboursIdx[3];
bool GoOn;
if( !findStartPoint(_Mesh,cStartPoint,cResultPoint,uStartFacetIdx) )
return;
uCurFacetIdx = uStartFacetIdx;
do{
MeshGeomFacet cCurFacet= _Mesh.GetFacet(uCurFacetIdx);
_Mesh.GetFacetNeighbours ( uCurFacetIdx, auNeighboursIdx[0], auNeighboursIdx[1], auNeighboursIdx[2]);
Base::Vector3f PointOnEdge[3];
GoOn = false;
int NbrOfHits = 0,HitIdx=0;
for(int i=0; i<3; i++)
{
// ignore last visited facet
if ( auNeighboursIdx[i] == uLastFacetIdx )
continue;
// get points of the edge i
const Base::Vector3f& cP0 = cCurFacet._aclPoints[i];
const Base::Vector3f& cP1 = cCurFacet._aclPoints[(i+1)%3];
if ( auNeighboursIdx[i] != ULONG_MAX )
{
// calculate the normal by the edge vector and the middle between the two face normals
MeshGeomFacet N = _Mesh.GetFacet( auNeighboursIdx[i] );
cPlaneNormal = ( N.GetNormal() + cCurFacet.GetNormal() ) % ( cP1 - cP0 );
cPlanePnt = cP0;
}else{
// with no neighbours the face normal is used
cPlaneNormal = cCurFacet.GetNormal() % ( cP1 - cP0 );
cPlanePnt = cP0;
}
Handle(Geom_Plane) hPlane = new Geom_Plane(gp_Pln(gp_Pnt(cPlanePnt.x,cPlanePnt.y,cPlanePnt.z),
gp_Dir(cPlaneNormal.x,cPlaneNormal.y,cPlaneNormal.z)));
GeomAPI_IntCS Alg(hCurve,hPlane);
if ( Alg.IsDone() )
{
// deciding by the number of result points (intersections)
if( Alg.NbPoints() == 1)
{
gp_Pnt P = Alg.Point(1);
float l = ((Base::Vector3f((float)P.X(),(float)P.Y(),(float)P.Z()) - cP0)
* (cP1 - cP0) ) / ((cP1 - cP0) * (cP1 - cP0));
// is the Point on the Edge of the facet?
if(l<0.0 || l>1.0)
PointOnEdge[i] = Base::Vector3f(FLOAT_MAX,0,0);
else{
cSplitPoint = (1-l) * cP0 + l * cP1;
PointOnEdge[i] = (1-l)*cP0 + l * cP1;
NbrOfHits ++;
HitIdx = i;
}
// no intersection
}else if(Alg.NbPoints() == 0){
PointOnEdge[i] = Base::Vector3f(FLOAT_MAX,0,0);
// more the one intersection (@ToDo)
}else if(Alg.NbPoints() > 1){
PointOnEdge[i] = Base::Vector3f(FLOAT_MAX,0,0);
Base::Console().Log("MeshAlgos::projectCurve(): More then one intersection in Facet %ld, Edge %d\n",uCurFacetIdx,i);
}
}
}
uLastFacetIdx = uCurFacetIdx;
if(NbrOfHits == 1)
{
uCurFacetIdx = auNeighboursIdx[HitIdx];
FaceSplitEdge splitEdge;
splitEdge.ulFaceIndex = uCurFacetIdx;
splitEdge.p1 = cResultPoint;
splitEdge.p2 = cSplitPoint;
vSplitEdges.push_back( splitEdge );
cResultPoint = cSplitPoint;
GoOn = true;
}else{
Base::Console().Log("MeshAlgos::projectCurve(): Posibel reentry in Facet %ld\n", uCurFacetIdx);
}
if( uCurFacetIdx == uStartFacetIdx )
GoOn = false;
}while(GoOn);
}
bool CurveProjectorShape::findStartPoint(const MeshKernel &MeshK,const Base::Vector3f &Pnt,Base::Vector3f &Rslt,unsigned long &FaceIndex)
{
Base::Vector3f TempResultPoint;
float MinLength = FLOAT_MAX;
bool bHit = false;
// go through the whole Mesh
MeshFacetIterator It(MeshK);
for(It.Init();It.More();It.Next())
{
// try to project (with angle) to the face
if(It->Foraminate (Pnt, It->GetNormal(), TempResultPoint) )
{
// distance to the projected point
float Dist = (Pnt-TempResultPoint).Length();
if(Dist < MinLength)
{
// remember the point with the closest distance
bHit = true;
MinLength = Dist;
Rslt = TempResultPoint;
FaceIndex = It.Position();
}
}
}
return bHit;
}
//**************************************************************************
//**************************************************************************
// Seperator for CurveProjectorSimple classe
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CurveProjectorSimple::CurveProjectorSimple(const TopoDS_Shape &aShape, const MeshKernel &pMesh)
: CurveProjector(aShape,pMesh)
{
Do();
}
void CurveProjectorSimple::Do(void)
{
TopExp_Explorer Ex;
TopoDS_Shape Edge;
std::vector<Base::Vector3f> vEdgePolygon;
for (Ex.Init(_Shape, TopAbs_EDGE); Ex.More(); Ex.Next())
{
const TopoDS_Edge& aEdge = TopoDS::Edge(Ex.Current());
// GetSampledCurves(aEdge,vEdgePolygon,2000);
//std::vector<FaceSplitEdge> vSplitEdges;
projectCurve(aEdge,vEdgePolygon, mvEdgeSplitPoints[aEdge]);
}
}
void CurveProjectorSimple::GetSampledCurves( const TopoDS_Edge& aEdge, std::vector<Base::Vector3f>& rclPoints, unsigned long ulNbOfPoints)
{
rclPoints.clear();
Standard_Real fBegin, fEnd;
Handle(Geom_Curve) hCurve = BRep_Tool::Curve(aEdge,fBegin,fEnd);
float fLen = float(fEnd - fBegin);
for (unsigned long i = 0; i < ulNbOfPoints; i++)
{
gp_Pnt gpPt = hCurve->Value(fBegin + (fLen * float(i)) / float(ulNbOfPoints-1));
rclPoints.push_back(Base::Vector3f((float)gpPt.X(),
(float)gpPt.Y(),
(float)gpPt.Z()));
}
}
//projectToNeighbours(Handle(Geom_Curve) hCurve,float pos
void CurveProjectorSimple::projectCurve( const TopoDS_Edge& aEdge,
const std::vector<Base::Vector3f> &rclPoints,
std::vector<FaceSplitEdge> &vSplitEdges)
{
Base::Vector3f /*cResultPoint, cSplitPoint, cPlanePnt, cPlaneNormal,*/TempResultPoint;
bool bFirst = true;
//unsigned long auNeighboursIdx[3];
//std::map<unsigned long,std::vector<Base::Vector3f> >::iterator N1,N2,N3;
Standard_Real fBegin, fEnd;
Handle(Geom_Curve) hCurve = BRep_Tool::Curve(aEdge,fBegin,fEnd);
float fLen = float(fEnd - fBegin);
unsigned long ulNbOfPoints = 1000,PointCount=0;
MeshFacetIterator It(_Mesh);
Base::SequencerLauncher seq("Building up projection map...", ulNbOfPoints+1);
std::ofstream str("projected.asc", std::ios::out | std::ios::binary);
str.precision(4);
str.setf(std::ios::fixed | std::ios::showpoint);
std::map<unsigned long,std::vector<Base::Vector3f> > FaceProjctMap;
for (unsigned long i = 0; i <= ulNbOfPoints; i++)
{
seq.next();
gp_Pnt gpPt = hCurve->Value(fBegin + (fLen * float(i)) / float(ulNbOfPoints-1));
// go through the whole Mesh
for(It.Init();It.More();It.Next())
{
// try to project (with angle) to the face
if (It->IntersectWithLine (Base::Vector3f((float)gpPt.X(),(float)gpPt.Y(),(float)gpPt.Z()),
It->GetNormal(), TempResultPoint))
{
FaceProjctMap[It.Position()].push_back(TempResultPoint);
str << TempResultPoint.x << " "
<< TempResultPoint.y << " "
<< TempResultPoint.z << std::endl;
Base::Console().Log("IDX %d\n",It.Position());
if(bFirst){
bFirst = false;
}
PointCount++;
}
}
}
str.close();
Base::Console().Log("Projection map [%d facets with %d points]\n",FaceProjctMap.size(),PointCount);
// estimate the first face
// gp_Pnt gpPt = hCurve->Value(fBegin);
// if( !findStartPoint(MeshK,Base::Vector3f(gpPt.X(),gpPt.Y(),gpPt.Z()),cResultPoint,uCurFacetIdx) )
// uCurFacetIdx = FaceProjctMap.begin()->first;
/*
do{
Base::Console().Log("Grow on %d %d left\n",uCurFacetIdx,FaceProjctMap.size());
if(FaceProjctMap[uCurFacetIdx].size() == 1)
{
Base::Console().Log("Single hit\n");
}else{
}
FaceProjctMap.erase(uCurFacetIdx);
// estimate next facet
MeshGeomFacet cCurFacet= MeshK.GetFacet(uCurFacetIdx);
MeshK.GetFacetNeighbours ( uCurFacetIdx, auNeighboursIdx[0], auNeighboursIdx[1], auNeighboursIdx[2]);
uCurFacetIdx = ULONG_MAX;
PointCount = 0;
for(int i=0; i<3; i++)
{
N1 = FaceProjctMap.find(auNeighboursIdx[i]);
// if the i'th neighbour is valid
if ( N1 != FaceProjctMap.end() )
{
unsigned long temp = N1->second.size();
if(temp >= PointCount){
PointCount = N1->second.size();
uCurFacetIdx = auNeighboursIdx[i];
}
}
}
}while(uCurFacetIdx != ULONG_MAX);
*/
}
/*
void CurveProjectorSimple::projectCurve( const TopoDS_Edge& aEdge,
const std::vector<Base::Vector3f> &rclPoints,
std::vector<FaceSplitEdge> &vSplitEdges)
{
const MeshKernel &MeshK = *(_Mesh.getKernel());
Standard_Real fFirst, fLast, fAct;
Handle(Geom_Curve) hCurve = BRep_Tool::Curve( aEdge,fFirst,fLast );
// getting start point
gp_Pnt gpPt = hCurve->Value(fFirst);
fAct = fFirst;
// projection of the first point
Base::Vector3f cStartPoint = Base::Vector3f(gpPt.X(),gpPt.Y(),gpPt.Z());
Base::Vector3f cResultPoint, cSplitPoint, cPlanePnt, cPlaneNormal,TempResultPoint;
unsigned long uStartFacetIdx,uCurFacetIdx;
unsigned long uLastFacetIdx=ULONG_MAX-1; // use another value as ULONG_MAX
unsigned long auNeighboursIdx[3];
bool GoOn;
// go through the whole Mesh, find the first projection
MeshFacetIterator It(MeshK);
GoOn = false;
for(It.Init();It.More();It.Next())
{
// try to project (with angle) to the face
if(MeshFacetFunc::IntersectWithLine (*It, cStartPoint, It->GetNormal(), cResultPoint) )
{
uCurFacetIdx = It.Position();
GoOn = true;
break;
}
}
if(!GoOn)
{
Base::Console().Log("Starting point not projectable\n");
return;
}
{
float fStep = (fLast-fFirst)/20;
unsigned long HitCount,Sentinel = 0 ;
MeshGeomFacet cCurFacet= MeshK.GetFacet(uCurFacetIdx);
MeshK.GetFacetNeighbours ( uCurFacetIdx, auNeighboursIdx[0], auNeighboursIdx[1], auNeighboursIdx[2]);
do{
// lower the step until you find a neigbourfacet to project...
fStep /= 2.0;
// still on the same facet?
gpPt = hCurve->Value(fAct+fStep);
if(MeshFacetFunc::IntersectWithLine (cCurFacet, Base::Vector3f(gpPt.X(),gpPt.Y(),gpPt.Z()), cCurFacet.GetNormal(), cResultPoint) )
{
fAct += fStep;
fStep *= 2.0;
continue;
}
HitCount = 0;
for(int i=0; i<3; i++)
{
// if the i'th neighbour is valid
if ( auNeighboursIdx[i] != ULONG_MAX )
{
// try to project next intervall
MeshGeomFacet N = MeshK.GetFacet( auNeighboursIdx[i] );
gpPt = hCurve->Value(fAct+fStep);
if(MeshFacetFunc::IntersectWithLine (*It, Base::Vector3f(gpPt.X(),gpPt.Y(),gpPt.Z()), It->GetNormal(), cResultPoint) )
{
HitCount++;
uStartFacetIdx = auNeighboursIdx[i];
}
}
}
Sentinel++;
}while(HitCount!=1 && Sentinel < 20);
}
}
*/
/*
void CurveProjectorSimple::projectCurve( const TopoDS_Edge& aEdge,
const std::vector<Base::Vector3f> &rclPoints,
std::vector<FaceSplitEdge> &vSplitEdges)
{
const MeshKernel &MeshK = *(_Mesh.getKernel());
Standard_Real fFirst, fLast;
Handle(Geom_Curve) hCurve = BRep_Tool::Curve( aEdge,fFirst,fLast );
// getting start point
gp_Pnt gpPt = hCurve->Value(fFirst);
// projection of the first point
Base::Vector3f cStartPoint = Base::Vector3f(gpPt.X(),gpPt.Y(),gpPt.Z());
Base::Vector3f cResultPoint, cSplitPoint, cPlanePnt, cPlaneNormal;
unsigned long uStartFacetIdx,uCurFacetIdx;
unsigned long uLastFacetIdx=ULONG_MAX-1; // use another value as ULONG_MAX
unsigned long auNeighboursIdx[3];
bool GoOn;
if( !findStartPoint(MeshK,cStartPoint,cResultPoint,uStartFacetIdx) )
return;
FILE* file = fopen("projected.asc", "w");
// go through the whole Mesh
MeshFacetIterator It1(MeshK);
for(It1.Init();It1.More();It1.Next())
{
// cycling through the points and find the first projecteble point ( if the curve starts outside the mesh)
for( std::vector<Base::Vector3f>::const_iterator It = rclPoints.begin()+1;It!=rclPoints.end();++It)
{
// MeshGeomFacet facet = MeshK.GetFacet(uStartFacetIdx);
MeshGeomFacet facet = *It1;
if(MeshFacetFunc::IntersectWithLine(facet, *It, facet.GetNormal(), cResultPoint) )
fprintf(file, "%.4f %.4f %.4f\n", cResultPoint.x, cResultPoint.y, cResultPoint.z);
}
}
fclose(file);
}
*/
bool CurveProjectorSimple::findStartPoint(const MeshKernel &MeshK,const Base::Vector3f &Pnt,Base::Vector3f &Rslt,unsigned long &FaceIndex)
{
Base::Vector3f TempResultPoint;
float MinLength = FLOAT_MAX;
bool bHit = false;
// go through the whole Mesh
MeshFacetIterator It(MeshK);
for(It.Init();It.More();It.Next())
{
// try to project (with angle) to the face
if(It->Foraminate (Pnt, It->GetNormal(), TempResultPoint) )
{
// distance to the projected point
float Dist = (Pnt-TempResultPoint).Length();
if(Dist < MinLength)
{
// remember the point with the closest distance
bHit = true;
MinLength = Dist;
Rslt = TempResultPoint;
FaceIndex = It.Position();
}
}
}
return bHit;
}
//**************************************************************************
//**************************************************************************
// Seperator for CurveProjectorSimple classe
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CurveProjectorWithToolMesh::CurveProjectorWithToolMesh(const TopoDS_Shape &aShape, const MeshKernel &pMesh,MeshKernel &rToolMesh)
: CurveProjector(aShape,pMesh),ToolMesh(rToolMesh)
{
Do();
}
void CurveProjectorWithToolMesh::Do(void)
{
TopExp_Explorer Ex;
TopoDS_Shape Edge;
std::vector<MeshGeomFacet> cVAry;
std::vector<Base::Vector3f> vEdgePolygon;
for (Ex.Init(_Shape, TopAbs_EDGE); Ex.More(); Ex.Next())
{
const TopoDS_Edge& aEdge = TopoDS::Edge(Ex.Current());
makeToolMesh(aEdge,cVAry);
}
ToolMesh.AddFacets(cVAry);
}
//projectToNeighbours(Handle(Geom_Curve) hCurve,float pos
void CurveProjectorWithToolMesh::makeToolMesh( const TopoDS_Edge& aEdge,std::vector<MeshGeomFacet> &cVAry )
{
Standard_Real fBegin, fEnd;
Handle(Geom_Curve) hCurve = BRep_Tool::Curve(aEdge,fBegin,fEnd);
float fLen = float(fEnd - fBegin);
Base::Vector3f cResultPoint;
unsigned long ulNbOfPoints = 15,PointCount=0/*,uCurFacetIdx*/;
std::vector<LineSeg> LineSegs;
MeshFacetIterator It(_Mesh);
Base::SequencerLauncher seq("Building up tool mesh...", ulNbOfPoints+1);
std::map<unsigned long,std::vector<Base::Vector3f> > FaceProjctMap;
for (unsigned long i = 0; i < ulNbOfPoints; i++)
{
seq.next();
gp_Pnt gpPt = hCurve->Value(fBegin + (fLen * float(i)) / float(ulNbOfPoints-1));
Base::Vector3f LinePoint((float)gpPt.X(),
(float)gpPt.Y(),
(float)gpPt.Z());
Base::Vector3f ResultNormal;
// go through the whole Mesh
for(It.Init();It.More();It.Next())
{
// try to project (with angle) to the face
if (It->IntersectWithLine (Base::Vector3f((float)gpPt.X(),(float)gpPt.Y(),(float)gpPt.Z()),
It->GetNormal(), cResultPoint) )
{
if(Base::Distance(LinePoint,cResultPoint) < 0.5)
ResultNormal += It->GetNormal();
}
}
LineSeg s;
s.p = Base::Vector3f((float)gpPt.X(),
(float)gpPt.Y(),
(float)gpPt.Z());
s.n = ResultNormal.Normalize();
LineSegs.push_back(s);
}
Base::Console().Log("Projection map [%d facets with %d points]\n",FaceProjctMap.size(),PointCount);
// build up the new mesh
Base::Vector3f lp(FLOAT_MAX,0,0), ln, p1, p2, p3, p4,p5,p6;
float ToolSize = 0.2f;
for (std::vector<LineSeg>::iterator It2=LineSegs.begin(); It2!=LineSegs.end();++It2)
{
if(lp.x != FLOAT_MAX)
{
p1 = lp + (ln * (-ToolSize));
p2 = lp + (ln * ToolSize);
p3 = lp;
p4 = (*It2).p;
p5 = (*It2).p + ((*It2).n * (-ToolSize));
p6 = (*It2).p + ((*It2).n * ToolSize);
cVAry.push_back(MeshGeomFacet(p3,p2,p6));
cVAry.push_back(MeshGeomFacet(p3,p6,p4));
cVAry.push_back(MeshGeomFacet(p1,p3,p4));
cVAry.push_back(MeshGeomFacet(p1,p4,p5));
}
lp = (*It2).p;
ln = (*It2).n;
}
}

View File

@@ -0,0 +1,161 @@
/***************************************************************************
* Copyright (c) Juergen Riegel <juergen.riegel@web.de> *
* *
* 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 _CurveProjector_h_
#define _CurveProjector_h_
#ifdef FC_USE_GTS
# include <gts.h>
#endif
#include <gp_Pln.hxx>
#include <Base/Vector3D.h>
class TopoDS_Edge;
class TopoDS_Shape;
#include <TopoDS_Edge.hxx>
#include <Mod/Mesh/App/Mesh.h>
namespace MeshCore
{
class MeshKernel;
class MeshGeomFacet;
};
using MeshCore::MeshKernel;
using MeshCore::MeshGeomFacet;
namespace MeshPart
{
/** The father of all projection algorithems
*/
class MeshPartExport CurveProjector
{
public:
CurveProjector(const TopoDS_Shape &aShape, const MeshKernel &pMesh);
virtual ~CurveProjector() {}
struct FaceSplitEdge
{
unsigned long ulFaceIndex;
Base::Vector3f p1,p2;
};
template<class T>
struct TopoDSLess : public std::binary_function<T, T, bool> {
bool operator()(const T& x, const T& y) const {
return x.HashCode(INT_MAX-1) < y.HashCode(INT_MAX-1);
}
};
typedef std::map<TopoDS_Edge, std::vector<FaceSplitEdge>,TopoDSLess<TopoDS_Edge> > result_type;
result_type &result(void) {return mvEdgeSplitPoints;}
void writeIntersectionPointsToFile(const char *name="export_pts.asc");
protected:
virtual void Do()=0;
const TopoDS_Shape &_Shape;
const MeshKernel &_Mesh;
result_type mvEdgeSplitPoints;
};
/** Project by intersection face planes with the curve
*/
class MeshPartExport CurveProjectorShape: public CurveProjector
{
public:
CurveProjectorShape(const TopoDS_Shape &aShape, const MeshKernel &pMesh);
virtual ~CurveProjectorShape() {}
void projectCurve(const TopoDS_Edge& aEdge,
std::vector<FaceSplitEdge> &vSplitEdges);
bool findStartPoint(const MeshKernel &MeshK,const Base::Vector3f &Pnt,Base::Vector3f &Rslt,unsigned long &FaceIndex);
protected:
virtual void Do();
};
/** Project by projecting a sampled curve to the mesh
*/
class MeshPartExport CurveProjectorSimple: public CurveProjector
{
public:
CurveProjectorSimple(const TopoDS_Shape &aShape, const MeshKernel &pMesh);
virtual ~CurveProjectorSimple() {}
/// helper to discredicice a Edge...
void GetSampledCurves( const TopoDS_Edge& aEdge, std::vector<Base::Vector3f>& rclPoints, unsigned long ulNbOfPoints = 30);
void projectCurve(const TopoDS_Edge& aEdge,
const std::vector<Base::Vector3f> &rclPoints,
std::vector<FaceSplitEdge> &vSplitEdges);
bool findStartPoint(const MeshKernel &MeshK,const Base::Vector3f &Pnt,Base::Vector3f &Rslt,unsigned long &FaceIndex);
protected:
virtual void Do();
};
/** Project by projecting a sampled curve to the mesh
*/
class MeshPartExport CurveProjectorWithToolMesh: public CurveProjector
{
public:
struct LineSeg {
Base::Vector3f p;
Base::Vector3f n;
};
CurveProjectorWithToolMesh(const TopoDS_Shape &aShape, const MeshKernel &pMesh,MeshKernel &rToolMesh);
virtual ~CurveProjectorWithToolMesh() {}
void makeToolMesh(const TopoDS_Edge& aEdge,std::vector<MeshGeomFacet> &cVAry );
MeshKernel &ToolMesh;
protected:
virtual void Do();
};
} // namespace MeshPart
#endif

View File

@@ -0,0 +1,80 @@
lib_LTLIBRARIES=libMeshPart.la MeshPart.la
libMeshPart_la_SOURCES=\
AppMeshPartPy.cpp \
CurveProjector.cpp \
CurveProjector.h \
MeshAlgos.cpp \
MeshAlgos.h \
Mesher.cpp \
Mesher.h \
PreCompiled.cpp \
PreCompiled.h
# the library search path.
libMeshPart_la_LDFLAGS = -L../../../Base -L../../../App -L../../../Mod/Part/App \
-L../../../Mod/Mesh/App -L$(OCC_LIB) $(all_libraries) \
-version-info @LIB_CURRENT@:@LIB_REVISION@:@LIB_AGE@
libMeshPart_la_CPPFLAGS = -DMeshPartAppExport=
libMeshPart_la_LIBADD = \
@BOOST_REGEX_LIB@ @BOOST_SYSTEM_LIB@ \
-l@PYTHON_LIB@ \
-lxerces-c \
-lFreeCADBase \
-lFreeCADApp \
-lPart \
-lMesh \
-lTKernel \
-lTKG2d \
-lTKG3d \
-lTKMath \
-lTKXSBase \
-lTKBRep \
-lTKTopAlgo \
-lTKGeomAlgo \
-lTKGeomBase
#if HAVE_SALOMESMESH
SMESH_LIBRARY = @top_builddir@/src/3rdParty/salomesmesh
libMeshPart_la_LDFLAGS += -L$(SMESH_LIBRARY)
libMeshPart_la_LIBADD += \
-lSMESH \
-lSMDS \
-lStdMeshers
#endif
#--------------------------------------------------------------------------------------
# Loader of libMeshPart
MeshPart_la_SOURCES=\
AppMeshPart.cpp
# the library search path.
MeshPart_la_LDFLAGS = $(libMeshPart_la_LDFLAGS) -module -avoid-version
MeshPart_la_CPPFLAGS = $(libMeshPart_la_CPPFLAGS)
MeshPart_la_LIBADD = \
$(libMeshPart_la_LIBADD) \
-lMeshPart
MeshPart_la_DEPENDENCIES = libMeshPart.la
#--------------------------------------------------------------------------------------
# set the include path found by configure
AM_CXXFLAGS = -I$(top_srcdir)/src -I$(top_builddir)/src $(all_includes) -I$(OCC_INC)
#if HAVE_SALOMESMESH
SMESH_INCLUDE = @top_srcdir@/src/3rdParty/salomesmesh/inc
AM_CXXFLAGS += -I$(SMESH_INCLUDE) -DHAVE_SMESH
#endif
libdir = $(prefix)/Mod/MeshPart
EXTRA_DIST = \
CMakeLists.txt

View File

@@ -0,0 +1,583 @@
/***************************************************************************
* Copyright (c) Juergen Riegel <juergen.riegel@web.de> *
* *
* 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"
#ifndef _PreComp_
# ifdef FC_OS_LINUX
# include <unistd.h>
# endif
#endif
#include "MeshAlgos.h"
#include <Mod/Mesh/App/Mesh.h>
#include <Mod/Mesh/App/Core/MeshIO.h>
#include <Mod/Mesh/App/Core/MeshKernel.h>
#include <Mod/Mesh/App/Core/Iterator.h>
#include <Mod/Mesh/App/Core/Algorithm.h>
#include <Mod/Mesh/App/Core/TopoAlgorithm.h>
#include <Mod/Mesh/App/Core/Evaluation.h>
#include <Base/Exception.h>
#include <Base/FileInfo.h>
#include <Base/Console.h>
#include <Base/Builder3D.h>
using namespace MeshPart;
using namespace MeshCore;
void MeshAlgos::offset(MeshCore::MeshKernel* Mesh, float fSize)
{
std::vector<Base::Vector3f> normals = Mesh->CalcVertexNormals();
unsigned int i = 0;
// go throug all the Vertex normales
for(std::vector<Base::Vector3f>::iterator It= normals.begin();It != normals.end();It++,i++)
// and move each mesh point in the normal direction
Mesh->MovePoint(i,It->Normalize() * fSize);
Mesh->RecalcBoundBox();
}
void MeshAlgos::offsetSpecial2(MeshCore::MeshKernel* Mesh, float fSize)
{
Base::Builder3D builder;
std::vector<Base::Vector3f> PointNormals= Mesh->CalcVertexNormals();
std::vector<Base::Vector3f> FaceNormals;
std::set<unsigned long> fliped;
MeshFacetIterator it(*Mesh);
for ( it.Init(); it.More(); it.Next() )
FaceNormals.push_back(it->GetNormal().Normalize());
unsigned int i = 0;
// go throug all the Vertex normales
for(std::vector<Base::Vector3f>::iterator It= PointNormals.begin();It != PointNormals.end();It++,i++){
builder.addSingleLine(Mesh->GetPoint(i),Mesh->GetPoint(i)+It->Normalize() * fSize);
// and move each mesh point in the normal direction
Mesh->MovePoint(i,It->Normalize() * fSize);
}
Mesh->RecalcBoundBox();
MeshTopoAlgorithm alg(*Mesh);
for(int l= 0; l<1 ;l++){
for ( it.Init(),i=0; it.More(); it.Next(),i++ )
{
if(it->IsFlag(MeshFacet::INVALID))
continue;
// calculate the angle between them
float angle = acos((FaceNormals[i] * it->GetNormal()) / (it->GetNormal().Length() * FaceNormals[i].Length()));
if(angle > 1.6){
builder.addSinglePoint(it->GetGravityPoint(),4,1,0,0);
fliped.insert(it.Position());
}
}
// if there no flipped triangels -> stop
//int f =fliped.size();
if(fliped.size() == 0)
break;
for(std::set<unsigned long>::iterator It= fliped.begin();It!=fliped.end();++It)
alg.CollapseFacet(*It);
fliped.clear();
}
alg.Cleanup();
// search for intersected facets
MeshCore::MeshEvalSelfIntersection eval(*Mesh);
std::vector<std::pair<unsigned long, unsigned long> > faces;
eval.GetIntersections(faces);
builder.saveToLog();
}
void MeshAlgos::offsetSpecial(MeshCore::MeshKernel* Mesh, float fSize, float zmax, float zmin)
{
std::vector<Base::Vector3f> normals = Mesh->CalcVertexNormals();
unsigned int i = 0;
// go throug all the Vertex normales
for(std::vector<Base::Vector3f>::iterator It= normals.begin();It != normals.end();It++,i++)
{
Base::Vector3f Pnt = Mesh->GetPoint(i);
if(Pnt.z < zmax && Pnt.z > zmin)
{
Pnt.z = 0;
Mesh->MovePoint(i,Pnt.Normalize() * fSize);
}else
// and move each mesh point in the normal direction
Mesh->MovePoint(i,It->Normalize() * fSize);
}
}
void MeshAlgos::coarsen(MeshCore::MeshKernel* Mesh, float f)
{
#ifdef FC_USE_GTS
GtsSurface * surface;
// create a GTS surface
surface = MeshAlgos::createGTSSurface(Mesh);
Mesh->Clear();
guint stop_number=100000;
gdouble fold = 3.1415 / 180.;
gts_surface_coarsen (surface,
NULL, NULL,
NULL, NULL,
(GtsStopFunc)gts_coarsen_stop_number,
&stop_number, fold);
// get the standard mesh
fillMeshFromGTSSurface(Mesh,surface);
#endif
}
MeshCore::MeshKernel* MeshAlgos::boolean(MeshCore::MeshKernel* pMesh1, MeshCore::MeshKernel* pMesh2, MeshCore::MeshKernel* pResult,int Type)
{
#ifdef FC_USE_GTS
GtsSurface * s1, * s2, * s3;
GtsSurfaceInter * si;
GNode * tree1, * tree2;
gboolean check_self_intersection = FALSE;
gboolean closed = TRUE, is_open1, is_open2;
// create a GTS surface
s1 = MeshAlgos::createGTSSurface(pMesh1);
s2 = MeshAlgos::createGTSSurface(pMesh2);
// clear the mesh (mermory)
//Mesh1.clear();
//Mesh2.clear();
/* check that the surfaces are orientable manifolds */
if (!gts_surface_is_orientable (s1)) {
gts_object_destroy (GTS_OBJECT (s1));
gts_object_destroy (GTS_OBJECT (s2));
throw "surface 1 is not an orientable manifold\n" ;
}
if (!gts_surface_is_orientable (s2)) {
gts_object_destroy (GTS_OBJECT (s1));
gts_object_destroy (GTS_OBJECT (s2));
throw "surface 2 is not an orientable manifold\n";
}
/* check that the surfaces are not self-intersecting */
if (check_self_intersection) {
GtsSurface * self_intersects;
self_intersects = gts_surface_is_self_intersecting (s1);
if (self_intersects != NULL) {
// if (verbose)
// gts_surface_print_stats (self_intersects, stderr);
// gts_surface_write (self_intersects, stdout);
gts_object_destroy (GTS_OBJECT (self_intersects));
gts_object_destroy (GTS_OBJECT (s1));
gts_object_destroy (GTS_OBJECT (s2));
throw "surface is self-intersecting\n";
}
self_intersects = gts_surface_is_self_intersecting (s2);
if (self_intersects != NULL) {
// if (verbose)
// gts_surface_print_stats (self_intersects, stderr);
// gts_surface_write (self_intersects, stdout);
gts_object_destroy (GTS_OBJECT (self_intersects));
gts_object_destroy (GTS_OBJECT (s1));
gts_object_destroy (GTS_OBJECT (s2));
throw"surface is self-intersecting\n";
}
}
/* build bounding box tree for first surface */
tree1 = gts_bb_tree_surface (s1);
is_open1 = gts_surface_volume (s1) < 0. ? TRUE : FALSE;
/* build bounding box tree for second surface */
tree2 = gts_bb_tree_surface (s2);
is_open2 = gts_surface_volume (s2) < 0. ? TRUE : FALSE;
si = gts_surface_inter_new (gts_surface_inter_class (),
s1, s2, tree1, tree2, is_open1, is_open2);
g_assert (gts_surface_inter_check (si, &closed));
if (!closed) {
gts_object_destroy (GTS_OBJECT (s1));
gts_object_destroy (GTS_OBJECT (s2));
gts_bb_tree_destroy (tree1, TRUE);
gts_bb_tree_destroy (tree2, TRUE);
throw"the intersection of 1 and 2 is not a closed curve\n";
}
s3 = gts_surface_new (gts_surface_class (),
gts_face_class (),
gts_edge_class (),
gts_vertex_class ());
if (Type==0) { // union
gts_surface_inter_boolean (si, s3, GTS_1_OUT_2);
gts_surface_inter_boolean (si, s3, GTS_2_OUT_1);
}
else if (Type==1) { // inter
gts_surface_inter_boolean (si, s3, GTS_1_IN_2);
gts_surface_inter_boolean (si, s3, GTS_2_IN_1);
}
else if (Type==2) { //diff
gts_surface_inter_boolean (si, s3, GTS_1_OUT_2);
gts_surface_inter_boolean (si, s3, GTS_2_IN_1);
gts_surface_foreach_face (si->s2, (GtsFunc) gts_triangle_revert, NULL);
gts_surface_foreach_face (s2, (GtsFunc) gts_triangle_revert, NULL);
}
else if (Type==3) { // cut inner
gts_surface_inter_boolean (si, s3, GTS_1_IN_2);
}
else if (Type==4) { // cut outer
gts_surface_inter_boolean (si, s3, GTS_1_OUT_2);
}
// check that the resulting surface is not self-intersecting
if (check_self_intersection) {
GtsSurface * self_intersects;
self_intersects = gts_surface_is_self_intersecting (s3);
if (self_intersects != NULL) {
// if (verbose)
// gts_surface_print_stats (self_intersects, stderr);
// gts_surface_write (self_intersects, stdout);
gts_object_destroy (GTS_OBJECT (self_intersects));
gts_object_destroy (GTS_OBJECT (s1));
gts_object_destroy (GTS_OBJECT (s2));
gts_object_destroy (GTS_OBJECT (s3));
gts_object_destroy (GTS_OBJECT (si));
gts_bb_tree_destroy (tree1, TRUE);
gts_bb_tree_destroy (tree2, TRUE);
throw "the resulting surface is self-intersecting\n";
}
}
// display summary information about the resulting surface
// if (verbose)
// gts_surface_print_stats (s3, stderr);
// write resulting surface to standard output
// get the standard mesh
fillMeshFromGTSSurface(pResult,s3);
// destroy surfaces
gts_object_destroy (GTS_OBJECT (s1));
gts_object_destroy (GTS_OBJECT (s2));
// gts_object_destroy (GTS_OBJECT (s3));
// gts_object_destroy (GTS_OBJECT (si));
// destroy bounding box trees (including bounding boxes)
// gts_bb_tree_destroy (tree1, TRUE);
// gts_bb_tree_destroy (tree2, TRUE);
#endif
return pMesh1;
}
#ifdef FC_USE_GTS
/// helper function - construct a Edge out of two Vertexes if not allready there
static GtsEdge * new_edge (GtsVertex * v1, GtsVertex * v2)
{
GtsSegment * s = gts_vertices_are_connected (v1, v2);
if( s == NULL )
return gts_edge_new (gts_edge_class (), v1, v2);
else
return GTS_EDGE (s);
}
GtsSurface* MeshAlgos::createGTSSurface(MeshCore::MeshKernel* Mesh)
{
GtsSurface* Surf = gts_surface_new (gts_surface_class (),
gts_face_class (),
gts_edge_class (),
gts_vertex_class () );
unsigned long p1,p2,p3;
Base::Vector3f Vertex;
// Geting all the points
GtsVertex ** aVertex = (GtsVertex **) malloc(Mesh->CountPoints() * sizeof (GtsVertex *));
for (unsigned int PIter = 0;PIter < Mesh->CountPoints(); PIter++)
{
Vertex = Mesh->GetPoint(PIter);
aVertex[PIter] = gts_vertex_new (gts_vertex_class (), Vertex.x, Vertex.y, Vertex.z);
}
// cycling through the facets
for (unsigned int pFIter = 0;pFIter < Mesh->CountFacets(); pFIter++)
{
// geting the three points of the facet
Mesh->GetFacetPoints(pFIter,p1,p2,p3);
// creating the edges and add the face to the surface
gts_surface_add_face (Surf,
gts_face_new (Surf->face_class,
new_edge (aVertex[p1],aVertex[p2]),
new_edge (aVertex[p2],aVertex[p3]),
new_edge (aVertex[p3],aVertex[p1])));
}
Base::Console().Log("GTS [%d faces, %d Points, %d Edges,%s ,%s]\n",gts_surface_face_number(Surf),
gts_surface_vertex_number(Surf),
gts_surface_edge_number(Surf),
gts_surface_is_orientable (Surf)?"orientable":"not orientable",
gts_surface_is_self_intersecting(Surf)?"self-intersections":"no self-intersection" );
return Surf;
}
/// helper function for the face (triangle iteration
static void onFaces (GtsTriangle * t, std::vector<MeshGeomFacet> *VAry )
{
GtsVertex *mv0,*mv1,*mv2;
gts_triangle_vertices (t,&mv0,&mv1,&mv2);
VAry->push_back(MeshGeomFacet(Base::Vector3f(mv0->p.x,mv0->p.y,mv0->p.z),
Base::Vector3f(mv1->p.x,mv1->p.y,mv1->p.z),
Base::Vector3f(mv2->p.x,mv2->p.y,mv2->p.z)));
}
/*
static void onVertices(GtsVertex *v, MeshKernel *pKernel )
{
Base::Vector3f Point(GTS_POINT(v)->x,GTS_POINT(v)->y,GTS_POINT(v)->z);
}*/
void MeshAlgos::fillMeshFromGTSSurface(MeshCore::MeshKernel* pMesh, GtsSurface* pSurface)
{
std::vector<MeshGeomFacet> VAry;
// remove old mesh
pMesh->Clear();
// gts_surface_foreach_vertex(pSurface,(GtsFunc) onVertices,&MeshK);
gts_surface_foreach_face (pSurface, (GtsFunc) onFaces,&VAry);
// destroy surfaces
gts_object_destroy (GTS_OBJECT (pSurface));
// put the facets the simple way in the mesh, totp is recalculated!
(*pMesh) = VAry;
}
#endif
#include <TopExp_Explorer.hxx>
#include <TopExp.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS.hxx>
#include <Geom_Curve.hxx>
#include <Geom_Plane.hxx>
#include <BRep_Tool.hxx>
#include <GeomAPI_IntCS.hxx>
#include <GeomLProp_CLProps.hxx>
void MeshAlgos::cutByShape(const TopoDS_Shape &aShape,const MeshCore::MeshKernel* pMesh,MeshCore::MeshKernel* pToolMesh)
{
// calculate the projection for each Edge
// CurveProjectorShape Project(aShape,*pMesh);
CurveProjectorWithToolMesh Project(aShape,*pMesh,*pToolMesh);
//IntersectionLine Lines;
// MeshWithProperty *ResultMesh = new MeshWithProperty();
// boolean(pMesh,ToolMesh,ResultMesh,1);
}
/*
void MeshAlgos::doIntersection(const MeshWithProperty &pMesh,const MeshWithProperty ToolMesh,IntersectionLine &Lines)
{
}
*/
void MeshAlgos::cutByCurve(MeshCore::MeshKernel* pMesh,const std::vector<CurveProjector::FaceSplitEdge> &vSplitEdges)
{
MeshTopoAlgorithm cTopAlg(*pMesh);
for (std::vector<CurveProjector::FaceSplitEdge>::const_iterator it = vSplitEdges.begin();it!=vSplitEdges.end();++it)
{
cTopAlg.SplitFacet( it->ulFaceIndex, it->p1, it->p2 );
}
}
class _VertexCompare
{
public:
bool operator () (const TopoDS_Vertex &rclV1, const TopoDS_Vertex &rclV2) const
{
if (rclV1.IsSame(rclV2) == Standard_True)
return false;
gp_XYZ clP1 = BRep_Tool::Pnt(rclV1).XYZ();
gp_XYZ clP2 = BRep_Tool::Pnt(rclV2).XYZ();
if (fabs(clP1.X() - clP2.X()) < dE)
{
if (fabs(clP1.Y() - clP2.Y()) < dE)
return clP1.Z() < clP2.Z();
else
return clP1.Y() < clP2.Y();
}
else
return clP1.X() < clP2.X();
}
_VertexCompare (void) : dE(1.0e-5) {}
double dE;
};
void MeshAlgos::LoftOnCurve(MeshCore::MeshKernel &ResultMesh, const TopoDS_Shape &Shape, const std::vector<Base::Vector3f> &poly, const Base::Vector3f & up, float MaxSize)
{
TopExp_Explorer Ex;
Standard_Real fBegin, fEnd;
std::vector<MeshGeomFacet> cVAry;
std::map<TopoDS_Vertex,std::vector<Base::Vector3f>,_VertexCompare> ConnectMap;
for (Ex.Init(Shape, TopAbs_EDGE); Ex.More(); Ex.Next())
{
// get the edge and the belonging Vertexes
TopoDS_Edge Edge = (TopoDS_Edge&)Ex.Current();
TopoDS_Vertex V1, V2;
TopExp::Vertices(Edge, V1, V2);
bool bBegin = false,bEnd = false;
// geting the geometric curve and the interval
GeomLProp_CLProps prop(BRep_Tool::Curve(Edge,fBegin,fEnd),1,0.0000000001);
int res = int((fEnd - fBegin)/MaxSize);
// do at least 2 segments
if(res < 2)
res = 2;
gp_Dir Tangent;
std::vector<Base::Vector3f> prePoint(poly.size());
std::vector<Base::Vector3f> actPoint(poly.size());
// checking if there is already a end to conect
if(ConnectMap.find(V1) != ConnectMap.end() ){
bBegin = true;
prePoint = ConnectMap[V1];
}
if(ConnectMap.find(V2) != ConnectMap.end() )
bEnd = true;
for (long i = 0; i < res; i++)
{
// get point and tangent at the position, up is fix for the moment
prop.SetParameter(fBegin + ((fEnd - fBegin) * float(i)) / float(res-1));
prop.Tangent(Tangent);
Base::Vector3f Tng((float)Tangent.X(),
(float)Tangent.Y(),
(float)Tangent.Z());
Base::Vector3f Ptn((float)prop.Value().X(),
(float)prop.Value().Y(),
(float)prop.Value().Z());
Base::Vector3f Up (up);
// normalize and calc the third vector of the plane coordinatesystem
Tng.Normalize();
Up.Normalize();
Base::Vector3f Third(Tng%Up);
// Base::Console().Log("Pos: %f %f %f \n",Ptn.x,Ptn.y,Ptn.z);
unsigned int l=0;
std::vector<Base::Vector3f>::const_iterator It;
// got through the profile
for(It=poly.begin();It!=poly.end();++It,l++)
actPoint[l] = ((Third*It->x)+(Up*It->y)+(Tng*It->z)+Ptn);
if(i == res-1 && !bEnd)
// remeber the last row to conect to a otger edge with the same vertex
ConnectMap[V2] = actPoint;
if(i==1 && bBegin)
// using the end of an other edge as start
prePoint = ConnectMap[V1];
if(i==0 && !bBegin)
// remember the first row for conection to a edge with the same vertex
ConnectMap[V1] = actPoint;
if(i ) // not the first row or somthing to conect to
{
for(l=0;l<actPoint.size();l++)
{
if(l) // not first point in row
{
if(i == res-1 && bEnd) // if last row and a end to conect
actPoint = ConnectMap[V2];
Base::Vector3f p1 = prePoint[l-1],
p2 = actPoint[l-1],
p3 = prePoint[l],
p4 = actPoint[l];
cVAry.push_back(MeshGeomFacet(p1,p2,p3));
cVAry.push_back(MeshGeomFacet(p3,p2,p4));
}
}
}
prePoint = actPoint;
}
}
ResultMesh.AddFacets(cVAry);
}

View File

@@ -0,0 +1,112 @@
/***************************************************************************
* Copyright (c) Juergen Riegel <juergen.riegel@web.de> *
* *
* 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 _MeshAlgos_h_
#define _MeshAlgos_h_
#ifdef FC_USE_GTS
# include <gts.h>
#endif
#include <vector>
#include <Base/Vector3D.h>
#include "CurveProjector.h"
class TopoDS_Edge;
class TopoDS_Shape;
namespace MeshCore
{
class MeshKernel;
};
using MeshCore::MeshKernel;
namespace MeshPart
{
/** The mesh algorithems container class
*/
class MeshPartExport MeshAlgos
{
public:
/** Calculate per Vertex normales and adds the Normal property bag
*/
static void offset(MeshCore::MeshKernel* Mesh, float fSize);
static void offsetSpecial2(MeshCore::MeshKernel* Mesh, float fSize);
static void offsetSpecial(MeshCore::MeshKernel* Mesh, float fSize, float zmax, float zmin);
/** Coarsen the mesh
*/
static void coarsen(MeshCore::MeshKernel* Mesh, float f);
/** makes a boolean add
* The int Type stears the boolean oberation: 0=add;1=intersection;2=diff
*/
static MeshCore::MeshKernel* boolean(MeshCore::MeshKernel* Mesh1, MeshCore::MeshKernel* Mesh2, MeshCore::MeshKernel* pResult, int Type=0);
#ifdef FC_USE_GTS
/** Creates a GTS Surface from a MeshKernel
*/
static GtsSurface* createGTSSurface(MeshCore::MeshKernel* Mesh);
/** Creates a GTS Surface from a MeshKernel
*/
static void fillMeshFromGTSSurface(MeshCore::MeshKernel* pMesh, GtsSurface* pSurface);
#endif
static void cutByShape(const TopoDS_Shape &aShape,const MeshCore::MeshKernel* pMesh,MeshCore::MeshKernel* pToolMesh);
/// helper to discredicice a Edge...
static void GetSampledCurves( const TopoDS_Edge& aEdge, std::vector<Base::Vector3f>& rclPoints, unsigned long ulNbOfPoints = 30);
/// creates a mesh loft on base of a curve and an up vector
static void LoftOnCurve(MeshCore::MeshKernel &ResultMesh,const TopoDS_Shape &Shape, const std::vector<Base::Vector3f> &poly,
const Base::Vector3f & up = Base::Vector3f(0,0,1), float MaxSize = 0.1);
/*
struct FaceSplitEdge
{
unsigned long ulFaceIndex;
Base::Vector3f p1,p2;
};
static void projectCurve( MeshWithProperty* pMesh,
const TopoDS_Edge& aEdge,
const std::vector<Base::Vector3f> &rclPoints,
std::vector<FaceSplitEdge> &vSplitEdges);
*/
static void cutByCurve(MeshCore::MeshKernel* pMesh,const std::vector<CurveProjector::FaceSplitEdge> &vSplitEdges);
/*
static bool projectPointToMesh(MeshKernel &MeshK,const Base::Vector3f &Pnt,Base::Vector3f &Rslt,unsigned long &FaceIndex);
*/
};
} // namespace MeshPart
#endif

View File

@@ -0,0 +1,180 @@
/***************************************************************************
* Copyright (c) 2010 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 "Mesher.h"
#include <Base/Exception.h>
#include <Mod/Mesh/App/Mesh.h>
#include <TopoDS_Shape.hxx>
#ifdef HAVE_SMESH
#include <SMESH_Gen.hxx>
#include <StdMeshers_MaxLength.hxx>
#include <StdMeshers_LocalLength.hxx>
#include <StdMeshers_NumberOfSegments.hxx>
#include <StdMeshers_AutomaticLength.hxx>
#include <StdMeshers_TrianglePreference.hxx>
#include <StdMeshers_MEFISTO_2D.hxx>
#include <StdMeshers_Deflection1D.hxx>
#include <StdMeshers_MaxElementArea.hxx>
#include <StdMeshers_Regular_1D.hxx>
#include <StdMeshers_QuadranglePreference.hxx>
#include <StdMeshers_Quadrangle_2D.hxx>
#include <StdMeshers_LengthFromEdges.hxx>
#include <StdMeshers_NotConformAllowed.hxx>
#include <StdMeshers_Arithmetic1D.hxx>
#endif // HAVE_SMESH
using namespace MeshPart;
Mesher::Mesher(const TopoDS_Shape& s)
: shape(s), maxLength(0), maxArea(0), localLength(0),
regular(false)
{
}
Mesher::~Mesher()
{
}
Mesh::MeshObject* Mesher::createMesh() const
{
#ifndef HAVE_SMESH
throw Base::Exception("SMESH is not available on this platform");
#else
std::list<SMESH_Hypothesis*> hypoth;
SMESH_Gen* meshgen = new SMESH_Gen();
SMESH_Mesh* mesh = meshgen->CreateMesh(0, true);
int hyp=0;
if (maxLength > 0) {
StdMeshers_MaxLength* hyp1d = new StdMeshers_MaxLength(hyp++, 0, meshgen);
hyp1d->SetLength(maxLength);
hypoth.push_back(hyp1d);
}
if (localLength > 0) {
StdMeshers_LocalLength* hyp1d = new StdMeshers_LocalLength(hyp++,0,meshgen);
hyp1d->SetLength(localLength);
hypoth.push_back(hyp1d);
}
if (maxArea > 0) {
StdMeshers_MaxElementArea* hyp2d = new StdMeshers_MaxElementArea(hyp++,0,meshgen);
hyp2d->SetMaxArea(1.0f);
hypoth.push_back(hyp2d);
}
{
StdMeshers_NumberOfSegments* hyp1d = new StdMeshers_NumberOfSegments(hyp++,0,meshgen);
hyp1d->SetNumberOfSegments(1);
hypoth.push_back(hyp1d);
}
// if none of the above hypothesis were applied
if (hypoth.empty()) {
StdMeshers_AutomaticLength* hyp1d = new StdMeshers_AutomaticLength(hyp++,0,meshgen);
hypoth.push_back(hyp1d);
}
if (deflection > 0) {
StdMeshers_Deflection1D* hyp1d = new StdMeshers_Deflection1D(hyp++,0,meshgen);
hyp1d->SetDeflection(deflection);
hypoth.push_back(hyp1d);
}
if (regular) {
StdMeshers_Regular_1D* hyp1d = new StdMeshers_Regular_1D(hyp++,0,meshgen);
hypoth.push_back(hyp1d);
}
#if 1
StdMeshers_TrianglePreference* hyp2d_1 = new StdMeshers_TrianglePreference(hyp++,0,meshgen);
hypoth.push_back(hyp2d_1);
StdMeshers_MEFISTO_2D* alg2d = new StdMeshers_MEFISTO_2D(hyp++,0,meshgen);
hypoth.push_back(alg2d);
#else
StdMeshers_QuadranglePreference hyp2d_1(hyp++,0,meshgen);
StdMeshers_Quadrangle_2D alg2d(hyp++,0,meshgen);
#endif
// Apply the hypothesis and create the mesh
mesh->ShapeToMesh(shape);
for (int i=0; i<hyp;i++)
mesh->AddHypothesis(shape, i);
meshgen->Compute(*mesh, mesh->GetShapeToMesh());
// build up the mesh structure
SMDS_FaceIteratorPtr aFaceIter = mesh->GetMeshDS()->facesIterator();
SMDS_NodeIteratorPtr aNodeIter = mesh->GetMeshDS()->nodesIterator();
MeshCore::MeshPointArray verts;
MeshCore::MeshFacetArray faces;
verts.reserve(mesh->NbNodes());
faces.reserve(mesh->NbFaces());
int index=0;
std::map<const SMDS_MeshNode*, int> mapNodeIndex;
for (;aNodeIter->more();) {
const SMDS_MeshNode* aNode = aNodeIter->next();
MeshCore::MeshPoint p;
p.Set((float)aNode->X(), (float)aNode->Y(), (float)aNode->Z());
verts.push_back(p);
mapNodeIndex[aNode] = index++;
}
for (;aFaceIter->more();) {
const SMDS_MeshFace* aFace = aFaceIter->next();
MeshCore::MeshFacet f;
for (int i=0; i<3;i++) {
const SMDS_MeshNode* node = aFace->GetNode(i);
//int index = node->GetID() - 1;
f._aulPoints[i] = /*index*/mapNodeIndex[node];
}
faces.push_back(f);
}
// clean up
//FIXME: Why can't we delete this object?
#if defined(__GNUC__)
delete meshgen; // crashes with MSVC
#endif
TopoDS_Shape aNull;
mesh->ShapeToMesh(aNull);
mesh->Clear();
delete mesh;
for (std::list<SMESH_Hypothesis*>::iterator it = hypoth.begin(); it != hypoth.end(); ++it)
delete *it;
MeshCore::MeshKernel kernel;
kernel.Adopt(verts, faces, true);
Mesh::MeshObject* meshdata = new Mesh::MeshObject();
meshdata->swap(kernel);
return meshdata;
#endif // HAVE_SMESH
}

View File

@@ -0,0 +1,71 @@
/***************************************************************************
* Copyright (c) 2010 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 MESHPART_MESHER_H
#define MESHPART_MESHER_H
class TopoDS_Shape;
namespace Mesh { class MeshObject; }
namespace MeshPart {
class Mesher
{
public:
Mesher(const TopoDS_Shape&);
~Mesher();
void setMaxLength(float s)
{ maxLength = s; }
float getMaxLength() const
{ return maxLength; }
void setMaxArea(float s)
{ maxArea = s; }
float getMaxArea() const
{ return maxArea; }
void setLocalLength(float s)
{ localLength = s; }
float getLocalLength() const
{ return localLength; }
void setDeflection(float s)
{ deflection = s; }
float getDeflection() const
{ return deflection; }
void setRegular(bool s)
{ regular = s; }
bool isRegular() const
{ return regular; }
Mesh::MeshObject* createMesh() const;
private:
const TopoDS_Shape& shape;
float maxLength;
float maxArea;
float localLength;
float deflection;
bool regular;
};
} // namespace MeshPart
#endif // MESHPART_MESHER_H

View File

@@ -0,0 +1,24 @@
/***************************************************************************
* Copyright (c) 2008 Jürgen Riegel (juergen.riegel@web.de) *
* *
* 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"

View File

@@ -0,0 +1,237 @@
/***************************************************************************
* Copyright (c) 2008 Jürgen Riegel (juergen.riegel@web.de) *
* *
* 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 __PRECOMPILED__
#define __PRECOMPILED__
#include <FCConfig.h>
// Exporting of App classes
#ifdef FC_OS_WIN32
# define MeshPartExport __declspec(dllexport)
# define PartExport __declspec(dllimport)
# define MeshExport __declspec(dllimport)
#else // for Linux
# define MeshPartExport
# define PartExport
# define MeshExport
#endif
#ifdef _MSC_VER
# pragma warning(disable : 4275)
# pragma warning(disable : 4290)
#endif
#ifdef _PreComp_
// standard
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <assert.h>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <bitset>
// OpenCasCade =====================================================================================
// Base
#include <Standard_Failure.hxx>
#include <Standard_GUID.hxx>
#include <Standard_AbortiveTransaction.hxx>
#include <Standard_Address.hxx>
#include <Standard_AncestorIterator.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_Byte.hxx>
#include <Standard_Character.hxx>
#include <Standard_ConstructionError.hxx>
#include <Standard_CString.hxx>
#include <Standard_ctype.hxx>
#include <Standard_DefineHandle.hxx>
#include <Standard_DimensionError.hxx>
#include <Standard_DimensionMismatch.hxx>
#include <Standard_DivideByZero.hxx>
#include <Standard_DomainError.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_ExtCharacter.hxx>
#include <Standard_ExtString.hxx>
#include <Standard_Failure.hxx>
#include <Standard_GUID.hxx>
#include <Standard_ImmutableObject.hxx>
#include <Standard_Integer.hxx>
#include <Standard_InternalType.hxx>
#include <Standard_IStream.hxx>
#include <Standard_KindOfType.hxx>
#include <Standard_LicenseError.hxx>
#include <Standard_LicenseNotFound.hxx>
#include <Standard_Macro.hxx>
#include <Standard_math.hxx>
#include <Standard_MultiplyDefined.hxx>
#include <Standard_NegativeValue.hxx>
#include <Standard_NoMoreObject.hxx>
#include <Standard_NoSuchObject.hxx>
#include <Standard_NotImplemented.hxx>
#include <Standard_NullObject.hxx>
#include <Standard_NullValue.hxx>
#include <Standard_NumericError.hxx>
#include <Standard_OId.hxx>
#include <Standard_OStream.hxx>
#include <Standard_OutOfMemory.hxx>
#include <Standard_OutOfRange.hxx>
#include <Standard_Overflow.hxx>
#include <Standard_Persistent.hxx>
#include <Standard_Persistent_proto.hxx>
#include <Standard_PrimitiveTypes.hxx>
#include <Standard_ProgramError.hxx>
#include <Standard_RangeError.hxx>
#include <Standard_Real.hxx>
#include <Standard_ShortReal.hxx>
#include <Standard_SStream.hxx>
#include <Standard_Static.hxx>
#include <Standard_Storable.hxx>
#include <Standard_Stream.hxx>
#include <Standard_String.hxx>
#include <Standard_TooManyUsers.hxx>
#include <Standard_Transient.hxx>
#include <Standard_Transient_proto.hxx>
#include <Standard_Type.hxx>
#include <Standard_TypeDef.hxx>
#include <Standard_TypeMismatch.hxx>
#include <Standard_Underflow.hxx>
#include <Standard_UUID.hxx>
#include <Standard_WayOfLife.hxx>
#include <TCollection_ExtendedString.hxx>
#include <TCollection_AsciiString.hxx>
#include <TColStd_SequenceOfExtendedString.hxx>
#include <BRep_Builder.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <BRepBuilderAPI.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakePolygon.hxx>
#include <BRepTools.hxx>
#include <BRepTools_ShapeSet.hxx>
#include <BRepBuilderAPI_Copy.hxx>
#include <BRepCheck_Analyzer.hxx>
#include <BRepCheck_Result.hxx>
#include <BRepCheck_ListIteratorOfListOfStatus.hxx>
#include <BRepTools.hxx>
#include <Standard_DefineHandle.hxx>
#include <GCE2d_MakeSegment.hxx>
#include <GCPnts_TangentialDeflection.hxx>
#include <Geom_Axis2Placement.hxx>
#include <Geom_CartesianPoint.hxx>
#include <Geom_Line.hxx>
#include <Geom_Surface.hxx>
#include <Geom2d_BezierCurve.hxx>
#include <Geom2d_BSplineCurve.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <Geom2dAdaptor_Curve.hxx>
#include <GeomAbs_CurveType.hxx>
#include <GeomAdaptor_Curve.hxx>
#include <Geom_BezierCurve.hxx>
#include <Geom_BezierSurface.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom_BSplineSurface.hxx>
#include <Geom_Circle.hxx>
#include <Geom_ConicalSurface.hxx>
#include <Geom_CylindricalSurface.hxx>
#include <Geom_Ellipse.hxx>
#include <Geom_Hyperbola.hxx>
#include <Geom_SphericalSurface.hxx>
#include <Geom_SurfaceOfLinearExtrusion.hxx>
#include <Geom_SurfaceOfRevolution.hxx>
#include <Geom_Parabola.hxx>
#include <Geom_Plane.hxx>
#include <Geom_ToroidalSurface.hxx>
#include <GeomTools_Curve2dSet.hxx>
#include <gp_Ax2d.hxx>
#include <gp_Circ.hxx>
#include <gp_Circ2d.hxx>
#include <gp_Cone.hxx>
#include <gp_Cylinder.hxx>
#include <gp_Dir2d.hxx>
#include <gp_Elips.hxx>
#include <gp_Hypr.hxx>
#include <gp_Lin2d.hxx>
#include <gp_Lin.hxx>
#include <gp_Parab.hxx>
#include <gp_Pnt2d.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pln.hxx>
#include <gp_Sphere.hxx>
#include <gp_Torus.hxx>
#include <gp_Vec.hxx>
#include <gp_Vec2d.hxx>
#include <MMgt_TShared.hxx>
#include <Precision.hxx>
#include <Quantity_Factor.hxx>
#include <Quantity_Length.hxx>
#include <Quantity_NameOfColor.hxx>
#include <Quantity_PhysicalQuantity.hxx>
#include <Quantity_PlaneAngle.hxx>
#include <Quantity_TypeOfColor.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_CString.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_Integer.hxx>
#include <Standard_IStream.hxx>
#include <Standard_Macro.hxx>
#include <Standard_NotImplemented.hxx>
#include <Standard_OStream.hxx>
#include <Standard_Real.hxx>
#include <TCollection_AsciiString.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
#include <TColgp_HArray1OfPnt2d.hxx>
#include <TCollection_AsciiString.hxx>
#include <TColStd_HSequenceOfTransient.hxx>
#include <TColStd_MapIteratorOfMapOfTransient.hxx>
#include <TColStd_MapOfTransient.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopoDS_ListIteratorOfListOfShape.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Solid.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopExp.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_HSequenceOfShape.hxx>
#include <TopTools_MapOfShape.hxx>
#include <UnitsAPI.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <Python.h>
#endif // _PreComp_
#endif