using namespace std;
#include "StdMeshers_Regular_1D.hxx"
+#include "StdMeshers_Distribution.hxx"
#include "SMESH_Gen.hxx"
#include "SMESH_Mesh.hxx"
+#include <OSD.hxx>
+
#include "StdMeshers_LocalLength.hxx"
#include "StdMeshers_NumberOfSegments.hxx"
#include "StdMeshers_Arithmetic1D.hxx"
#include "StdMeshers_StartEndLength.hxx"
#include "StdMeshers_Deflection1D.hxx"
+#include <StdMeshers_AutomaticLength.hxx>
#include "SMDS_MeshElement.hxx"
#include "SMDS_MeshNode.hxx"
#include "SMDS_EdgePosition.hxx"
#include "SMESH_subMesh.hxx"
+#include "Utils_SALOME_Exception.hxx"
#include "utilities.h"
#include <BRep_Tool.hxx>
#include <GCPnts_UniformDeflection.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Precision.hxx>
+#include <Expr_GeneralExpression.hxx>
+#include <Expr_NamedUnknown.hxx>
+#include <Expr_Array1OfNamedUnknown.hxx>
+#include <TColStd_Array1OfReal.hxx>
+#include <ExprIntrp_GenExp.hxx>
#include <string>
-//#include <algorithm>
+#include <math.h>
//=============================================================================
/*!
_compatibleHypothesis.push_back("StartEndLength");
_compatibleHypothesis.push_back("Deflection1D");
_compatibleHypothesis.push_back("Arithmetic1D");
+ _compatibleHypothesis.push_back("AutomaticLength");
}
//=============================================================================
const StdMeshers_NumberOfSegments * hyp =
dynamic_cast <const StdMeshers_NumberOfSegments * >(theHyp);
ASSERT(hyp);
- _value[ NB_SEGMENTS_IND ] = hyp->GetNumberOfSegments();
- _value[ SCALE_FACTOR_IND ] = hyp->GetScaleFactor();
- ASSERT( _value[ NB_SEGMENTS_IND ] > 0 );
+ _ivalue[ NB_SEGMENTS_IND ] = hyp->GetNumberOfSegments();
+ ASSERT( _ivalue[ NB_SEGMENTS_IND ] > 0 );
+ _ivalue[ DISTR_TYPE_IND ] = (int) hyp->GetDistrType();
+ switch (_ivalue[ DISTR_TYPE_IND ])
+ {
+ case StdMeshers_NumberOfSegments::DT_Scale:
+ _value[ SCALE_FACTOR_IND ] = hyp->GetScaleFactor();
+ break;
+ case StdMeshers_NumberOfSegments::DT_TabFunc:
+ _vvalue[ TAB_FUNC_IND ] = hyp->GetTableFunction();
+ break;
+ case StdMeshers_NumberOfSegments::DT_ExprFunc:
+ _svalue[ EXPR_FUNC_IND ] = hyp->GetExpressionFunction();
+ break;
+ case StdMeshers_NumberOfSegments::DT_Regular:
+ break;
+ default:
+ ASSERT(0);
+ break;
+ }
+ if (_ivalue[ DISTR_TYPE_IND ] == StdMeshers_NumberOfSegments::DT_TabFunc ||
+ _ivalue[ DISTR_TYPE_IND ] == StdMeshers_NumberOfSegments::DT_ExprFunc)
+ _ivalue[ CONV_MODE_IND ] = hyp->ConversionMode();
_hypType = NB_SEGMENTS;
aStatus = SMESH_Hypothesis::HYP_OK;
}
_hypType = DEFLECTION;
aStatus = SMESH_Hypothesis::HYP_OK;
}
+
+ else if (hypName == "AutomaticLength")
+ {
+ StdMeshers_AutomaticLength * hyp = const_cast<StdMeshers_AutomaticLength *>
+ (dynamic_cast <const StdMeshers_AutomaticLength * >(theHyp));
+ ASSERT(hyp);
+ _value[ BEG_LENGTH_IND ] = _value[ END_LENGTH_IND ] = hyp->GetLength( &aMesh, aShape );
+ ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
+ _hypType = LOCAL_LENGTH;
+ aStatus = SMESH_Hypothesis::HYP_OK;
+ }
else
aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
double dLn = an - Ln; // error of <an>
if ( Abs( dLn ) <= Precision::Confusion() )
return;
- double dU = Ul - *itU; // parametric length of the last but one segment
- double dUn = dLn * ( Un - U1 ) / length; // modificator of the last parameter
- if ( dUn < 0.5 * dU ) { // last segment is a bit shorter than dU
+ double dU = Abs( Ul - *itU ); // parametric length of the last but one segment
+ double dUn = dLn * Abs( Un - U1 ) / length; // parametric error of <an>
+ if ( dUn < 0.5 * dU ) { // last segment is a bit shorter than it should
dUn = -dUn; // move the last parameter to the edge beginning
}
- else { // last segment is much shorter than dU -> remove the last param and
- theParams.pop_back(); // move the rest points toward the edge end
+ else { // last segment is much shorter than it should -> remove the last param and
+ theParams.pop_back(); nPar--; // move the rest points toward the edge end
Ln = GCPnts_AbscissaPoint::Length( C3d, theParams.back(), Un );
- dUn = ( an - Ln ) * ( Un - U1 ) / length;
+ dUn = ( an - Ln ) * Abs( Un - U1 ) / length;
if ( dUn < 0.5 * dU )
dUn = -dUn;
}
+ if ( U1 > Un )
+ dUn = -dUn;
double q = dUn / ( nPar - 1 );
for ( itU = theParams.rbegin(), i = 1; i < nPar; itU++, i++ ) {
(*itU) += dUn;
}
}
+static bool computeParamByFunc(Adaptor3d_Curve& C3d, double first, double last,
+ double length, bool theReverse,
+ int nbSeg, Function& func,
+ list<double>& theParams)
+{
+ OSD::SetSignal( true );
+
+ if( nbSeg<=0 )
+ return false;
+
+ MESSAGE( "computeParamByFunc" );
+
+ int nbPnt = 1 + nbSeg;
+ vector<double> x(nbPnt, 0.);
+
+ if( !buildDistribution( func, 0.0, 1.0, nbSeg, x, 1E-4 ) )
+ return false;
+
+ MESSAGE( "Points:\n" );
+ char buf[1024];
+ for( int i=0; i<=nbSeg; i++ )
+ {
+ sprintf( buf, "%f\n", float(x[i] ) );
+ MESSAGE( buf );
+ }
+
+
+
+ // apply parameters in range [0,1] to the space of the curve
+ double prevU = first;
+ double sign = 1.;
+ if (theReverse)
+ {
+ prevU = last;
+ sign = -1.;
+ }
+ for( int i = 1; i < nbSeg; i++ )
+ {
+ double curvLength = length * (x[i] - x[i-1]) * sign;
+ GCPnts_AbscissaPoint Discret( C3d, curvLength, prevU );
+ if ( !Discret.IsDone() )
+ return false;
+ double U = Discret.Parameter();
+ if ( U > first && U < last )
+ theParams.push_back( U );
+ else
+ return false;
+ prevU = U;
+ }
+ return true;
+}
+
//=============================================================================
/*!
*
double eltSize = 1;
if ( _hypType == LOCAL_LENGTH )
{
+ // Local Length hypothesis
double nbseg = ceil(length / _value[ BEG_LENGTH_IND ]); // integer sup
if (nbseg <= 0)
nbseg = 1; // degenerated edge
}
else
{
- double epsilon = 0.001;
- if (fabs(_value[ SCALE_FACTOR_IND ] - 1.0) > epsilon)
+ // Number Of Segments hypothesis
+ switch (_ivalue[ DISTR_TYPE_IND ])
{
- double scale = _value[ SCALE_FACTOR_IND ];
- if ( theReverse )
- scale = 1. / scale;
- double alpha = pow( scale , 1.0 / (_value[ NB_SEGMENTS_IND ] - 1));
- double factor = (l - f) / (1 - pow( alpha,_value[ NB_SEGMENTS_IND ]));
-
- int i, NbPoints = 1 + (int) _value[ NB_SEGMENTS_IND ];
- for ( i = 2; i < NbPoints; i++ )
+ case StdMeshers_NumberOfSegments::DT_Scale:
{
- double param = factor * (1 - pow(alpha, i - 1));
- theParams.push_back( param );
+ double scale = _value[ SCALE_FACTOR_IND ];
+ if ( theReverse )
+ scale = 1. / scale;
+ double alpha = pow( scale , 1.0 / (_ivalue[ NB_SEGMENTS_IND ] - 1));
+ double factor = (l - f) / (1 - pow( alpha,_ivalue[ NB_SEGMENTS_IND ]));
+
+ int i, NbPoints = 1 + _ivalue[ NB_SEGMENTS_IND ];
+ for ( i = 2; i < NbPoints; i++ )
+ {
+ double param = f + factor * (1 - pow(alpha, i - 1));
+ theParams.push_back( param );
+ }
+ return true;
}
- return true;
- }
- else
- {
- eltSize = length / _value[ NB_SEGMENTS_IND ];
+ break;
+ case StdMeshers_NumberOfSegments::DT_TabFunc:
+ {
+ FunctionTable func(_vvalue[ TAB_FUNC_IND ], _ivalue[ CONV_MODE_IND ]);
+ return computeParamByFunc(C3d, f, l, length, theReverse,
+ _ivalue[ NB_SEGMENTS_IND ], func,
+ theParams);
+ }
+ break;
+ case StdMeshers_NumberOfSegments::DT_ExprFunc:
+ {
+ FunctionExpr func(_svalue[ EXPR_FUNC_IND ].c_str(), _ivalue[ CONV_MODE_IND ]);
+ return computeParamByFunc(C3d, f, l, length, theReverse,
+ _ivalue[ NB_SEGMENTS_IND ], func,
+ theParams);
+ }
+ break;
+ case StdMeshers_NumberOfSegments::DT_Regular:
+ eltSize = length / _ivalue[ NB_SEGMENTS_IND ];
+ break;
+ default:
+ return false;
}
}
double param = Discret.Parameter(i);
theParams.push_back( param );
}
+ compensateError( eltSize, eltSize, f, l, length, C3d, theParams ); // for PAL9899
return true;
}
// geometric progression: SUM(n) = ( a1 - an * q ) / ( 1 - q ) = length
- double a1 = theReverse ? _value[ END_LENGTH_IND ] : _value[ BEG_LENGTH_IND ];
- double an = theReverse ? _value[ BEG_LENGTH_IND ] : _value[ END_LENGTH_IND ];
+ double a1 = _value[ BEG_LENGTH_IND ];
+ double an = _value[ END_LENGTH_IND ];
double q = ( length - a1 ) / ( length - an );
- double U1 = Min ( f, l );
- double Un = Max ( f, l );
+ double U1 = theReverse ? l : f;
+ double Un = theReverse ? f : l;
double param = U1;
- double eltSize = a1;
+ double eltSize = theReverse ? -a1 : a1;
while ( 1 ) {
// computes a point on a curve <C3d> at the distance <eltSize>
// from the point of parameter <param>.
GCPnts_AbscissaPoint Discret( C3d, eltSize, param );
if ( !Discret.IsDone() ) break;
param = Discret.Parameter();
- if ( param < Un )
+ if ( param > f && param < l )
theParams.push_back( param );
else
break;
// arithmetic progression: SUM(n) = ( an - a1 + q ) * ( a1 + an ) / ( 2 * q ) = length
- double a1 = theReverse ? _value[ END_LENGTH_IND ] : _value[ BEG_LENGTH_IND ];
- double an = theReverse ? _value[ BEG_LENGTH_IND ] : _value[ END_LENGTH_IND ];
+ double a1 = _value[ BEG_LENGTH_IND ];
+ double an = _value[ END_LENGTH_IND ];
- double q = ( an - a1 ) / ( 2 *length/( a1 + an ) - 1 );
- int n = int( 1 + ( an - a1 ) / q );
+ double q = ( an - a1 ) / ( 2 *length/( a1 + an ) - 1 );
+ int n = int( 1 + ( an - a1 ) / q );
- double U1 = Min ( f, l );
- double Un = Max ( f, l );
+ double U1 = theReverse ? l : f;
+ double Un = theReverse ? f : l;
double param = U1;
double eltSize = a1;
-
- while ( eltSize > 0. && n-- > 0) {
+ if ( theReverse ) {
+ eltSize = -eltSize;
+ q = -q;
+ }
+ while ( n-- > 0 && eltSize * ( Un - U1 ) > 0 ) {
// computes a point on a curve <C3d> at the distance <eltSize>
// from the point of parameter <param>.
GCPnts_AbscissaPoint Discret( C3d, eltSize, param );
if ( !Discret.IsDone() ) break;
param = Discret.Parameter();
- if ( param < Un )
+ if ( param > f && param < l )
theParams.push_back( param );
else
break;
- eltSize += q; // eltSize may become negative here
+ eltSize += q;
}
compensateError( a1, an, U1, Un, length, C3d, theParams );
const TopoDS_Edge & EE = TopoDS::Edge(aShape);
TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
+ int shapeID = meshDS->ShapeToIndex( E );
double f, l;
Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
//Add the Node in the DataStructure
SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
- meshDS->SetNodeOnEdge(node, E);
-
- // **** edgePosition associe au point = param.
- SMDS_EdgePosition* epos =
- dynamic_cast<SMDS_EdgePosition *>(node->GetPosition().get());
- epos->SetUParameter(param);
+ meshDS->SetNodeOnEdge(node, shapeID, param);
SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
- meshDS->SetMeshElementOnShape(edge, E);
+ meshDS->SetMeshElementOnShape(edge, shapeID);
idPrev = node;
}
SMDS_MeshEdge* edge = meshDS->AddEdge(idPrev, idLast);
- meshDS->SetMeshElementOnShape(edge, E);
+ meshDS->SetMeshElementOnShape(edge, shapeID);
}
else
{
{
double param = f + (i - 1) * du;
SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
- meshDS->SetNodeOnEdge(node, E);
-
- SMDS_EdgePosition* epos =
- dynamic_cast<SMDS_EdgePosition*>(node->GetPosition().get());
- epos->SetUParameter(param);
+ meshDS->SetNodeOnEdge(node, shapeID, param);
SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
- meshDS->SetMeshElementOnShape(edge, E);
+ meshDS->SetMeshElementOnShape(edge, shapeID);
idPrev = node;
}
SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast);
- meshDS->SetMeshElementOnShape(edge, E);
+ meshDS->SetMeshElementOnShape(edge, shapeID);
}
return true;
}