0022380: EDF 2746 GEOM: Accept compounds of points as an input for "Smoothing surface"

This commit is contained in:
skv 2014-03-24 13:13:11 +04:00
parent bae730c25a
commit ef20f40494
7 changed files with 117 additions and 24 deletions

View File

@ -7,6 +7,8 @@ Advanced - > SmoothingSurface </b>
Specify the \b Name of the surface and the list of \b Points, from which it is approximated and press "Apply" or "Apply & Close" button.
\note The dialog accepts compounds of points as well as single nodes.
The result of the operation will be a GEOM_Object(Surface).
<b>TUI Command:</b> <em>geompy.MakeSmoothingSurface(Points)</em>

View File

@ -3429,7 +3429,7 @@ Handle(GEOM_Object) GEOMImpl_IAdvancedOperations::MakeDividedCylinder (double th
//=============================================================================
/*!
* Create a smoothing surface from a set of points
* \param thelPoints list of points
* \param thelPoints list of points or compounds of points
* \return New GEOM_Object, containing the created shape.
*/
//=============================================================================
@ -3454,12 +3454,12 @@ Handle(GEOM_Object) GEOMImpl_IAdvancedOperations::MakeSmoothingSurface (std::lis
int ind = 1;
std::list<Handle(GEOM_Object)>::iterator it = thelPoints.begin();
for (; it != thelPoints.end(); it++, ind++) {
Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
if (aRefPnt.IsNull()) {
SetErrorCode("NULL point for bSplineFaceShape");
Handle(GEOM_Function) aRefObj = (*it)->GetLastFunction();
if (aRefObj.IsNull()) {
SetErrorCode("NULL point or compound for bSplineFaceShape");
return NULL;
}
aData.SetPoint(ind, aRefPnt);
aData.SetPntOrComp(ind, aRefObj);
}

View File

@ -36,8 +36,8 @@ public:
void SetLength(int theLen) { _func->SetInteger(SMOOTHINGSURFACE_ARG_LENG, theLen); }
int GetLength() { return _func->GetInteger(SMOOTHINGSURFACE_ARG_LENG); }
void SetPoint(int theId, Handle(GEOM_Function) theP) { _func->SetReference(SMOOTHINGSURFACE_ARG_LAST + theId, theP); }
Handle(GEOM_Function) GetPoint(int theId) { return _func->GetReference(SMOOTHINGSURFACE_ARG_LAST + theId); }
void SetPntOrComp(int theId, Handle(GEOM_Function) theP) { _func->SetReference(SMOOTHINGSURFACE_ARG_LAST + theId, theP); }
Handle(GEOM_Function) GetPntOrComp(int theId) { return _func->GetReference(SMOOTHINGSURFACE_ARG_LAST + theId); }
private:
Handle(GEOM_Function) _func;

View File

@ -34,6 +34,9 @@
#include <TopoDS_Face.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopTools_MapIteratorOfMapOfShape.hxx>
#include <TopExp_Explorer.hxx>
#include <TColgp_SequenceOfPnt.hxx>
#include <TColgp_Array2OfPnt.hxx>
@ -167,22 +170,43 @@ Standard_Integer GEOMImpl_SmoothingSurfaceDriver::Execute(TFunction_Logbook& log
// cout << "Youhou : " << aType << endl;
GEOMImpl_ISmoothingSurface aData (aFunction);
Standard_Integer nbPoints = aData.GetLength();
Handle(TColgp_HArray1OfPnt) anArrayofPnt = new TColgp_HArray1OfPnt(1,nbPoints);
for (int ind=1;ind<=nbPoints;ind++)
{
Handle(GEOM_Function) aPoint = aData.GetPoint(ind);
TopoDS_Shape aShapePnt = aPoint->GetValue();
TopoDS_Vertex dsPoint;
dsPoint = TopoDS::Vertex( aShapePnt );
gp_Pnt aPnt = BRep_Tool::Pnt( dsPoint );
anArrayofPnt->SetValue(ind,aPnt);
// Fill the map of vertices.
Standard_Integer aNbShapes = aData.GetLength();
TopTools_MapOfShape aMapPoints;
Standard_Integer i;
for (i = 1; i <= aNbShapes; i++) {
Handle(GEOM_Function) aFShape = aData.GetPntOrComp(i);
TopoDS_Shape aShape = aFShape->GetValue();
if (aShape.ShapeType() == TopAbs_VERTEX) {
aMapPoints.Add(aShape);
} else {
TopExp_Explorer anExp(aShape, TopAbs_VERTEX);
for (; anExp.More(); anExp.Next()) {
aMapPoints.Add(anExp.Current());
}
}
}
TopoDS_Shape aShape;
aShape = GEOMImpl_SmoothingSurfaceDriver::MakeSmoothingSurfaceUnClosed(anArrayofPnt);
// Add points to the array of points.
const Standard_Integer aNbPoints = aMapPoints.Extent();
Handle(TColgp_HArray1OfPnt) anArrayofPnt =
new TColgp_HArray1OfPnt(1, aNbPoints);
TopTools_MapIteratorOfMapOfShape anIter(aMapPoints);
for (i = 1; anIter.More(); anIter.Next(), i++) {
TopoDS_Vertex aPoint = TopoDS::Vertex(anIter.Key());
gp_Pnt aPnt = BRep_Tool::Pnt(aPoint);
anArrayofPnt->SetValue(i, aPnt);
}
// Make smoothing surface.
TopoDS_Shape aShape =
GEOMImpl_SmoothingSurfaceDriver::MakeSmoothingSurfaceUnClosed(anArrayofPnt);
if (aShape.IsNull()) return 0;
@ -217,7 +241,7 @@ GetCreationInformation(std::string& theOperationName,
if ( aCI.GetLength() > 1 )
theParams[0] << aCI.GetLength() << " points: ";
for ( int i = 1, nb = aCI.GetLength(); i <= nb; ++i )
theParams[0] << aCI.GetPoint( i ) << " ";
theParams[0] << aCI.GetPntOrComp( i ) << " ";
break;
default:
return false;

View File

@ -31,6 +31,7 @@
// OCCT Includes
#include <TopoDS_Shape.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopExp.hxx>
#include <TColStd_IndexedMapOfInteger.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
@ -208,16 +209,80 @@ bool AdvancedGUI_SmoothingSurfaceDlg::execute (ObjectList& objects)
return res;
}
//=================================================================================
// function : getNbPoints()
// purpose : Returns the number of points in myPoints list.
//=================================================================================
int AdvancedGUI_SmoothingSurfaceDlg::getNbPoints() const
{
TopTools_IndexedMapOfShape aMap;
foreach (GEOM::GeomObjPtr anObj, myPoints) {
TopoDS_Shape aShape;
if(anObj && GEOMBase::GetShape(anObj.get(), aShape) && !aShape.IsNull()) {
if (aShape.ShapeType() == TopAbs_VERTEX) {
aMap.Add(aShape);
} else {
// Compound.
TopExp::MapShapes(aShape, TopAbs_VERTEX, aMap);
}
}
}
const int aNbPoints = aMap.Extent();
return aNbPoints;
}
//=================================================================================
// function : SelectionIntoArgument()
// purpose : Called when selection as changed or other case
//=================================================================================
void AdvancedGUI_SmoothingSurfaceDlg::SelectionIntoArgument()
{
QList<GEOM::GeomObjPtr> points = getSelected( TopAbs_VERTEX, -1 );
QList<TopAbs_ShapeEnum> aTypes;
aTypes << TopAbs_VERTEX << TopAbs_COMPOUND;
QList<GEOM::GeomObjPtr> points = getSelected( aTypes, -1 );
// Check the selected compounds if they consist of points only.
foreach (GEOM::GeomObjPtr anObj, points) {
TopoDS_Shape aShape;
if(anObj && GEOMBase::GetShape(anObj.get(), aShape) && !aShape.IsNull()) {
if (aShape.ShapeType() == TopAbs_COMPOUND) {
// Check if the compound contains vertices only.
TopoDS_Iterator anIter(aShape);
Standard_Boolean isValid = Standard_False;
for (; anIter.More(); anIter.Next()) {
const TopoDS_Shape &aSubShape = anIter.Value();
if (aSubShape.ShapeType() == TopAbs_VERTEX) {
isValid = Standard_True;
} else {
isValid = Standard_False;
break;
}
}
if (!isValid) {
points.clear();
break;
}
}
} else {
// NEVERREACHED
points.clear();
break;
}
}
GEOMBase::Synchronize( myPoints, points );
if ( !myPoints.isEmpty() )
GroupPoints->LineEdit1->setText( QString::number( myPoints.count() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
GroupPoints->LineEdit1->setText( QString::number( getNbPoints() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
else
GroupPoints->LineEdit1->setText( "" );
processPreview();

View File

@ -48,6 +48,7 @@ protected:
private:
void Init();
void enterEvent( QEvent* );
int getNbPoints() const;
private:
DlgRef_1Sel* GroupPoints;

3
src/GEOM_SWIG/geomBuilder.py Normal file → Executable file
View File

@ -12629,7 +12629,8 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
return anObj
## Create a surface from a cloud of points
# @param thelPoints list of points
# @param thelPoints list of points. Compounds of points are
# accepted as well.
# @return New GEOM_Object, containing the created shape.
#
# @ref tui_creation_smoothingsurface "Example"