1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : StdMeshers_CartesianParameters3D.cxx
24 // Author : Edward AGAPOV
27 #include "StdMeshers_CartesianParameters3D.hxx"
29 #include "StdMeshers_NumberOfSegments.hxx"
30 #include "StdMeshers_Distribution.hxx"
31 #include "SMESH_Gen.hxx"
33 #include "utilities.h"
38 #include <BRepGProp.hxx>
39 #include <BRep_Tool.hxx>
40 #include <Bnd_Box.hxx>
41 #include <GProp_GProps.hxx>
42 #include <GeomLib_IsPlanarSurface.hxx>
43 #include <Geom_Surface.hxx>
44 #include <Precision.hxx>
45 #include <TopExp_Explorer.hxx>
46 #include <TopLoc_Location.hxx>
47 #include <TopTools_MapIteratorOfMapOfShape.hxx>
48 #include <TopTools_MapOfShape.hxx>
50 #include <TopoDS_Face.hxx>
58 //=======================================================================
59 //function : StdMeshers_CartesianParameters3D
60 //purpose : Constructor
61 //=======================================================================
63 StdMeshers_CartesianParameters3D::StdMeshers_CartesianParameters3D(int hypId,
66 : SMESH_Hypothesis(hypId, studyId, gen),
67 _sizeThreshold( 4.0 ), // default according to the customer specification
70 _name = "CartesianParameters3D"; // used by "Cartesian_3D"
71 _param_algo_dim = 3; // 3D
88 SetFixedPoint( _fixedPoint, /*toUnset=*/true );
94 const char* axisName[3] = { "X", "Y", "Z" };
96 typedef std::pair< double, std::pair< double, double > > TCooTriple;
98 #define gpXYZ( cTriple ) gp_XYZ( (cTriple).first, (cTriple).second.first, (cTriple).second.second )
100 //================================================================================
102 * \brief Compare two normals
104 //================================================================================
106 bool sameDir( const TCooTriple& n1, const TCooTriple& n2 )
108 gp_XYZ xyz1 = gpXYZ( n1 ), xyz2 = gpXYZ( n2 );
109 return ( xyz1 - xyz2 ).Modulus() < 0.01;
112 //================================================================================
114 * \brief Checks validity of an axis index, throws in case of invalidity
116 //================================================================================
118 void checkAxis(const int axis)
120 if ( axis < 0 || axis > 2 )
121 throw SALOME_Exception(SMESH_Comment("Invalid axis index ") << axis <<
122 ". Valid axis indices are 0, 1 and 2");
125 //================================================================================
127 * \brief Checks validity of spacing data, throws in case of invalidity
129 //================================================================================
131 void checkGridSpacing(std::vector<std::string>& spaceFunctions,
132 std::vector<double>& internalPoints,
133 const std::string& axis)
134 throw ( SALOME_Exception )
136 if ( spaceFunctions.empty() )
137 throw SALOME_Exception(SMESH_Comment("Empty space function for ") << axis );
139 for ( size_t i = 1; i < internalPoints.size(); ++i )
140 if ( internalPoints[i] - internalPoints[i-1] < 0 )
141 throw SALOME_Exception(SMESH_Comment("Wrong order of internal points along ") << axis);
142 else if ( internalPoints[i] - internalPoints[i-1] < 1e-3 )
143 throw SALOME_Exception(SMESH_Comment("Too close internal points along ") << axis );
145 const double tol = Precision::Confusion();
146 if ( !internalPoints.empty() &&
147 ( internalPoints.front() < -tol || internalPoints.back() > 1 + tol ))
148 throw SALOME_Exception(SMESH_Comment("Invalid internal points along ") << axis);
150 if ( internalPoints.empty() || internalPoints.front() > tol )
151 internalPoints.insert( internalPoints.begin(), 0. );
152 if ( internalPoints.size() < 2 || internalPoints.back() < 1 - tol )
153 internalPoints.push_back( 1. );
155 if ( internalPoints.size() != spaceFunctions.size() + 1 )
156 throw SALOME_Exception
157 (SMESH_Comment("Numbre of internal points mismatch number of functions for ") << axis);
159 for ( size_t i = 0; i < spaceFunctions.size(); ++i )
161 StdMeshers_NumberOfSegments::CheckExpressionFunction( spaceFunctions[i], -1 );
165 //=======================================================================
167 //purpose : Sets coordinates of node positions along an axes
168 //=======================================================================
170 void StdMeshers_CartesianParameters3D::SetGrid(std::vector<double>& coords, int axis)
171 throw ( SALOME_Exception )
175 if ( coords.size() < 2 )
176 throw SALOME_Exception(LOCALIZED("Wrong number of grid coordinates"));
178 std::sort( coords.begin(), coords.end() );
180 bool changed = ( _coords[axis] != coords );
183 _coords[axis] = coords;
184 NotifySubMeshesHypothesisModification();
187 _spaceFunctions[axis].clear();
188 _internalPoints[axis].clear();
191 //=======================================================================
192 //function : SetGridSpacing
193 //purpose : Set grid spacing along the three axes
194 //=======================================================================
196 void StdMeshers_CartesianParameters3D::SetGridSpacing(std::vector<string>& xSpaceFuns,
197 std::vector<double>& xInternalPoints,
199 throw ( SALOME_Exception )
203 checkGridSpacing( xSpaceFuns, xInternalPoints, axisName[axis] );
205 bool changed = ( xSpaceFuns != _spaceFunctions[axis] ||
206 xInternalPoints != _internalPoints[axis] );
208 _spaceFunctions[axis] = xSpaceFuns;
209 _internalPoints[axis] = xInternalPoints;
210 _coords[axis].clear();
213 NotifySubMeshesHypothesisModification();
216 //=======================================================================
217 //function : SetFixedPoint
218 //purpose : * Set/unset a fixed point, at which a node will be created provided that grid
219 // * is defined by spacing in all directions
220 //=======================================================================
222 void StdMeshers_CartesianParameters3D::SetFixedPoint(const double p[3], bool toUnset)
224 if ( toUnset != Precision::IsInfinite( _fixedPoint[0] ))
225 NotifySubMeshesHypothesisModification();
228 _fixedPoint[0] = Precision::Infinite();
230 std::copy( &p[0], &p[0]+3, &_fixedPoint[0] );
233 //=======================================================================
234 //function : GetFixedPoint
235 //purpose : Returns either false or (true + point coordinates)
236 //=======================================================================
238 bool StdMeshers_CartesianParameters3D::GetFixedPoint(double p[3]) const
240 if ( Precision::IsInfinite( _fixedPoint[0] ))
242 std::copy( &_fixedPoint[0], &_fixedPoint[0]+3, &p[0] );
247 //=======================================================================
248 //function : SetSizeThreshold
249 //purpose : Set size threshold
250 //=======================================================================
252 void StdMeshers_CartesianParameters3D::SetSizeThreshold(const double threshold)
253 throw ( SALOME_Exception )
255 if ( threshold <= 1.0 )
256 throw SALOME_Exception(LOCALIZED("threshold must be > 1.0"));
258 bool changed = fabs( _sizeThreshold - threshold ) > 1e-6;
259 _sizeThreshold = threshold;
262 NotifySubMeshesHypothesisModification();
265 //=======================================================================
266 //function : GetGridSpacing
267 //purpose : return spacing
268 //=======================================================================
270 void StdMeshers_CartesianParameters3D::GetGridSpacing(std::vector<std::string>& spaceFunctions,
271 std::vector<double>& internalPoints,
272 const int axis) const
273 throw ( SALOME_Exception )
275 if ( !IsGridBySpacing(axis) )
276 throw SALOME_Exception(LOCALIZED("The grid is defined by coordinates and not by spacing"));
278 spaceFunctions = _spaceFunctions[axis];
279 internalPoints = _internalPoints[axis];
282 //=======================================================================
283 //function : IsGridBySpacing
284 //=======================================================================
286 bool StdMeshers_CartesianParameters3D::IsGridBySpacing(const int axis) const
287 throw ( SALOME_Exception )
290 return !_spaceFunctions[axis].empty();
294 //=======================================================================
295 //function : ComputeCoordinates
296 //purpose : Computes node coordinates by spacing functions
297 //=======================================================================
299 void StdMeshers_CartesianParameters3D::ComputeCoordinates(const double x0,
301 vector<string>& theSpaceFuns,
302 vector<double>& thePoints,
303 vector<double>& coords,
305 const double* xForced )
306 throw ( SALOME_Exception )
308 checkGridSpacing( theSpaceFuns, thePoints, axis );
310 vector<string> spaceFuns = theSpaceFuns;
311 vector<double> points = thePoints;
314 if (( forced = ( xForced && ( x0 < *xForced ) && ( *xForced < x1 ))))
316 // divide a range at xForced
318 // find a range to insert xForced
319 double pos = ( *xForced - x0 ) / ( x1 - x0 );
321 while ( pos > points[ iR ] ) ++iR;
324 vector<double>::iterator pntIt = points.begin() + iR;
325 points.insert( pntIt, pos );
326 vector<string>::iterator funIt = spaceFuns.begin() + iR;
327 spaceFuns.insert( funIt, spaceFuns[ iR-1 ]);
331 for ( size_t i = 0; i < spaceFuns.size(); ++i )
333 StdMeshers::FunctionExpr fun( spaceFuns[i].c_str(), /*convMode=*/-1 );
335 const double p0 = x0 * ( 1. - points[i]) + x1 * points[i];
336 const double p1 = x0 * ( 1. - points[i+1]) + x1 * points[i+1];
337 const double length = p1 - p0;
339 const size_t nbSections = 1000;
340 const double sectionLen = ( p1 - p0 ) / nbSections;
341 vector< double > nbSegments( nbSections + 1 );
342 nbSegments[ 0 ] = 0.;
344 double t, spacing = 0;
345 for ( size_t i = 1; i <= nbSections; ++i )
347 t = double( i ) / nbSections;
348 if ( !fun.value( t, spacing ) || spacing < std::numeric_limits<double>::min() )
349 throw SALOME_Exception(LOCALIZED("Invalid spacing function"));
350 nbSegments[ i ] = nbSegments[ i-1 ] + std::min( 1., sectionLen / spacing );
353 const int nbCells = max (1, int(floor(nbSegments.back()+0.5)));
354 const double corr = nbCells / nbSegments.back();
356 if ( coords.empty() ) coords.push_back( p0 );
358 for ( size_t iCell = 1, i = 1; i <= nbSections; ++i )
360 if ( nbSegments[i]*corr >= iCell )
362 t = (i - ( nbSegments[i] - iCell/corr )/( nbSegments[i] - nbSegments[i-1] )) / nbSections;
363 coords.push_back( p0 + t * length );
367 const double lastCellLen = coords.back() - coords[ coords.size() - 2 ];
368 if ( fabs( coords.back() - p1 ) > 0.5 * lastCellLen )
369 coords.push_back ( p1 );
372 // correct coords if a forced point is too close to a neighbor node
376 double minLen = ( x1 - x0 );
377 for ( size_t i = 1; i < coords.size(); ++i )
379 if ( !iF && Abs( coords[i] - *xForced ) < 1e-20 )
380 iF = i++; // xForced found
382 minLen = Min( minLen, coords[i] - coords[i-1] );
384 const double tol = minLen * 1e-3;
386 if (( iF > 1 ) && ( coords[iF] - coords[iF-1] < tol ))
388 else if (( iF < coords.size()-2 ) && ( coords[iF+1] - coords[iF] < tol ))
391 coords.erase( coords.begin() + iRem );
395 //=======================================================================
396 //function : GetCoordinates
397 //purpose : Return coordinates of node positions along the three axes.
398 // If the grid is defined by spacing functions, the coordinates are computed
399 //=======================================================================
401 void StdMeshers_CartesianParameters3D::GetCoordinates(std::vector<double>& xNodes,
402 std::vector<double>& yNodes,
403 std::vector<double>& zNodes,
404 const Bnd_Box& bndBox) const
405 throw ( SALOME_Exception )
407 double x0,y0,z0, x1,y1,z1;
408 if ( IsGridBySpacing(0) || IsGridBySpacing(1) || IsGridBySpacing(2))
410 if ( bndBox.IsVoid() ||
411 bndBox.IsXThin( Precision::Confusion() ) ||
412 bndBox.IsYThin( Precision::Confusion() ) ||
413 bndBox.IsZThin( Precision::Confusion() ) )
414 throw SALOME_Exception(LOCALIZED("Invalid bounding box"));
415 bndBox.Get(x0,y0,z0, x1,y1,z1);
418 double fp[3], *pfp[3] = { NULL, NULL, NULL };
419 if ( GetFixedPoint( fp ))
421 // convert fp into a basis defined by _axisDirs
422 gp_XYZ axis[3] = { gp_XYZ( _axisDirs[0], _axisDirs[1], _axisDirs[2] ),
423 gp_XYZ( _axisDirs[3], _axisDirs[4], _axisDirs[5] ),
424 gp_XYZ( _axisDirs[6], _axisDirs[7], _axisDirs[8] ) };
429 gp_Mat basis( axis[0], axis[1], axis[2] );
430 gp_Mat bi = basis.Inverted();
432 gp_XYZ p( fp[0], fp[1], fp[2] );
434 p.Coord( fp[0], fp[1], fp[2] );
441 StdMeshers_CartesianParameters3D* me = const_cast<StdMeshers_CartesianParameters3D*>(this);
442 if ( IsGridBySpacing(0) )
444 ( x0, x1, me->_spaceFunctions[0], me->_internalPoints[0], xNodes, "X", pfp[0] );
448 if ( IsGridBySpacing(1) )
450 ( y0, y1, me->_spaceFunctions[1], me->_internalPoints[1], yNodes, "Y", pfp[1] );
454 if ( IsGridBySpacing(2) )
456 ( z0, z1, me->_spaceFunctions[2], me->_internalPoints[2], zNodes, "Z", pfp[2] );
461 //=======================================================================
462 //function : ComputeOptimalAxesDirs
463 //purpose : Returns axes at which number of hexahedra is maximal
464 //=======================================================================
466 void StdMeshers_CartesianParameters3D::
467 ComputeOptimalAxesDirs(const TopoDS_Shape& shape,
468 const bool isOrthogonal,
471 for ( int i = 0; i < 9; ++i ) dirCoords[i] = 0.;
472 dirCoords[0] = dirCoords[4] = dirCoords[8] = 1.;
474 if ( shape.IsNull() ) return;
479 // get external FACEs of the shape
480 TopTools_MapOfShape faceMap;
481 for ( exp.Init( shape, TopAbs_FACE ); exp.More(); exp.Next() )
482 if ( !faceMap.Add( exp.Current() ))
483 faceMap.Remove( exp.Current() );
485 // sort areas of planar faces by normal direction
487 std::multimap< TCooTriple, double > areasByNormal;
489 TopTools_MapIteratorOfMapOfShape fIt ( faceMap );
490 for ( ; fIt.More(); fIt.Next() )
492 const TopoDS_Face& face = TopoDS::Face( fIt.Key() );
493 Handle(Geom_Surface) surf = BRep_Tool::Surface( face, loc );
494 if ( surf.IsNull() ) continue;
496 GeomLib_IsPlanarSurface check( surf, 1e-5 );
497 if ( !check.IsPlanar() ) continue;
500 BRepGProp::SurfaceProperties( face, SProps );
501 double area = SProps.Mass();
503 gp_Pln pln = check.Plan();
504 gp_Dir norm = pln.Axis().Direction().Transformed( loc );
505 if ( norm.X() < -1e-3 ) { // negative X
507 } else if ( norm.X() < 1e-3 ) { // zero X
508 if ( norm.Y() < -1e-3 ) { // negative Y
510 } else if ( norm.Y() < 1e-3 ) { // zero X && zero Y
511 if ( norm.Y() < -1e-3 ) // negative Z
515 TCooTriple coo3( norm.X(), make_pair( norm.Y(), norm.Z() ));
516 areasByNormal.insert( make_pair( coo3, area ));
519 // group coplanar normals and sort groups by sum area
521 std::multimap< double, vector< const TCooTriple* > > normsByArea;
522 std::multimap< TCooTriple, double >::iterator norm2a = areasByNormal.begin();
523 const TCooTriple* norm1 = 0;
525 vector< const TCooTriple* > norms;
526 for ( size_t iF = 1; norm2a != areasByNormal.end(); ++norm2a, ++iF )
528 if ( !norm1 || !sameDir( *norm1, norm2a->first ))
530 if ( !norms.empty() )
532 normsByArea.insert( make_pair( sumArea, norms ));
535 norm1 = & norm2a->first;
536 sumArea = norm2a->second;
537 norms.push_back( norm1 );
541 sumArea += norm2a->second;
542 norms.push_back( & norm2a->first );
544 if ( iF == areasByNormal.size() )
545 normsByArea.insert( make_pair( sumArea, norms ));
548 // try to set dirs by planar faces
550 gp_XYZ normDirs[3]; // normals to largest planes
552 if ( !normsByArea.empty() )
554 norm1 = normsByArea.rbegin()->second[0];
555 normDirs[0] = gpXYZ( *norm1 );
557 if ( normsByArea.size() == 1 )
559 normDirs[1] = normDirs[0];
560 if ( Abs( normDirs[0].Y() ) < 1e-100 &&
561 Abs( normDirs[0].Z() ) < 1e-100 ) // normDirs[0] || OX
562 normDirs[1].SetY( normDirs[0].Y() + 1. );
564 normDirs[1].SetX( normDirs[0].X() + 1. );
568 // look for 2 other directions
569 gp_XYZ testDir = normDirs[0], minDir, maxDir;
570 for ( int is2nd = 0; is2nd < 2; ++is2nd )
572 double maxMetric = 0, minMetric = 1e100;
573 std::multimap< double, vector< const TCooTriple* > >::iterator a2n;
574 for ( a2n = normsByArea.begin(); a2n != normsByArea.end(); ++a2n )
576 gp_XYZ n = gpXYZ( *( a2n->second[0]) );
577 double dot = Abs( n * testDir );
578 double metric = ( 1. - dot ) * ( isOrthogonal ? 1 : a2n->first );
579 if ( metric > maxMetric )
584 if ( metric < minMetric )
592 normDirs[2] = minDir;
596 normDirs[1] = maxDir;
597 normDirs[2] = normDirs[0] ^ normDirs[1];
598 if ( isOrthogonal || normsByArea.size() < 3 )
600 testDir = normDirs[2];
604 if ( isOrthogonal || normsByArea.size() == 1 )
606 normDirs[2] = normDirs[0] ^ normDirs[1];
607 normDirs[1] = normDirs[2] ^ normDirs[0];
616 dirs[0] = normDirs[0] ^ normDirs[1];
617 dirs[1] = normDirs[1] ^ normDirs[2];
618 dirs[2] = normDirs[2] ^ normDirs[0];
624 // Select dirs for X, Y and Z axes
625 int iX = ( Abs( dirs[0].X() ) > Abs( dirs[1].X() )) ? 0 : 1;
626 if ( Abs( dirs[iX].X() ) < Abs( dirs[2].X() ))
628 int iY = ( iX == 0 ) ? 1 : (( Abs( dirs[0].Y() ) > Abs( dirs[1].Y() )) ? 0 : 1 );
629 if ( Abs( dirs[iY].Y() ) < Abs( dirs[2].Y() ) && iX != 2 )
631 int iZ = 3 - iX - iY;
633 if ( dirs[iX].X() < 0 ) dirs[iX].Reverse();
634 if ( dirs[iY].Y() < 0 ) dirs[iY].Reverse();
635 gp_XYZ zDir = dirs[iX] ^ dirs[iY];
636 if ( dirs[iZ] * zDir < 0 )
639 dirCoords[0] = dirs[iX].X();
640 dirCoords[1] = dirs[iX].Y();
641 dirCoords[2] = dirs[iX].Z();
642 dirCoords[3] = dirs[iY].X();
643 dirCoords[4] = dirs[iY].Y();
644 dirCoords[5] = dirs[iY].Z();
645 dirCoords[6] = dirs[iZ].X();
646 dirCoords[7] = dirs[iZ].Y();
647 dirCoords[8] = dirs[iZ].Z();
650 //=======================================================================
651 //function : SetAxisDirs
652 //purpose : Sets custom direction of axes
653 //=======================================================================
655 void StdMeshers_CartesianParameters3D::SetAxisDirs(const double* the9DirComps)
656 throw ( SALOME_Exception )
658 gp_Vec x( the9DirComps[0],
661 gp_Vec y( the9DirComps[3],
664 gp_Vec z( the9DirComps[6],
667 if ( x.Magnitude() < RealSmall() ||
668 y.Magnitude() < RealSmall() ||
669 z.Magnitude() < RealSmall() )
670 throw SALOME_Exception("Zero magnitude of axis direction");
672 if ( x.IsParallel( y, M_PI / 180. ) ||
673 x.IsParallel( z, M_PI / 180. ) ||
674 y.IsParallel( z, M_PI / 180. ))
675 throw SALOME_Exception("Parallel axis directions");
677 gp_Vec normXY = x ^ y, normYZ = y ^ z;
678 if ( normXY.IsParallel( normYZ, M_PI / 180. ))
679 throw SALOME_Exception("Axes lie in one plane");
681 bool isChanged = false;
682 for ( int i = 0; i < 9; ++i )
684 if ( Abs( _axisDirs[i] - the9DirComps[i] ) > 1e-7 )
686 _axisDirs[i] = the9DirComps[i];
689 NotifySubMeshesHypothesisModification();
692 //=======================================================================
694 //purpose : Return coordinates of node positions along the three axes
695 //=======================================================================
697 void StdMeshers_CartesianParameters3D::GetGrid(std::vector<double>& coords, int axis) const
698 throw ( SALOME_Exception )
700 if ( IsGridBySpacing(axis) )
701 throw SALOME_Exception(LOCALIZED("The grid is defined by spacing and not by coordinates"));
703 coords = _coords[axis];
706 //=======================================================================
707 //function : GetSizeThreshold
708 //purpose : Return size threshold
709 //=======================================================================
711 double StdMeshers_CartesianParameters3D::GetSizeThreshold() const
713 return _sizeThreshold;
716 //=======================================================================
717 //function : SetToAddEdges
718 //purpose : Enables implementation of geometrical edges into the mesh. If this feature
719 // is disabled, sharp edges of the shape are lost ("smoothed") in the mesh if
720 // they don't coincide with the grid lines
721 //=======================================================================
723 void StdMeshers_CartesianParameters3D::SetToAddEdges(bool toAdd)
725 if ( _toAddEdges != toAdd )
728 NotifySubMeshesHypothesisModification();
732 //=======================================================================
733 //function : GetToAddEdges
734 //purpose : Returns true if implementation of geometrical edges into the
736 //=======================================================================
738 bool StdMeshers_CartesianParameters3D::GetToAddEdges() const
743 //=======================================================================
744 //function : IsDefined
745 //purpose : Return true if parameters are well defined
746 //=======================================================================
748 bool StdMeshers_CartesianParameters3D::IsDefined() const
750 for ( int i = 0; i < 3; ++i )
751 if (_coords[i].empty() && (_spaceFunctions[i].empty() || _internalPoints[i].empty()))
754 return ( _sizeThreshold > 1.0 );
757 //=======================================================================
759 //purpose : store my parameters into a stream
760 //=======================================================================
762 std::ostream & StdMeshers_CartesianParameters3D::SaveTo(std::ostream & save)
764 save << _sizeThreshold << " ";
766 for ( int i = 0; i < 3; ++i )
768 save << _coords[i].size() << " ";
769 for ( size_t j = 0; j < _coords[i].size(); ++j )
770 save << _coords[i][j] << " ";
772 save << _internalPoints[i].size() << " ";
773 for ( size_t j = 0; j < _internalPoints[i].size(); ++j )
774 save << _internalPoints[i][j] << " ";
776 save << _spaceFunctions[i].size() << " ";
777 for ( size_t j = 0; j < _spaceFunctions[i].size(); ++j )
778 save << _spaceFunctions[i][j] << " ";
780 save << _toAddEdges << " ";
782 save.setf( save.scientific );
783 save.precision( 12 );
784 for ( int i = 0; i < 9; ++i )
785 save << _axisDirs[i] << " ";
787 for ( int i = 0; i < 3; ++i )
788 save << _fixedPoint[i] << " ";
793 //=======================================================================
794 //function : LoadFrom
795 //purpose : resore my parameters from a stream
796 //=======================================================================
798 std::istream & StdMeshers_CartesianParameters3D::LoadFrom(std::istream & load)
802 ok = static_cast<bool>( load >> _sizeThreshold );
803 for ( int ax = 0; ax < 3; ++ax )
808 ok = static_cast<bool>(load >> i );
811 _coords[ax].resize( i );
812 for ( i = 0; i < _coords[ax].size() && ok; ++i )
813 ok = static_cast<bool>(load >> _coords[ax][i] );
819 ok = static_cast<bool>(load >> i );
822 _internalPoints[ax].resize( i );
823 for ( i = 0; i < _internalPoints[ax].size() && ok; ++i )
824 ok = static_cast<bool>(load >> _internalPoints[ax][i] );
830 ok = static_cast<bool>(load >> i );
833 _spaceFunctions[ax].resize( i );
834 for ( i = 0; i < _spaceFunctions[ax].size() && ok; ++i )
835 ok = static_cast<bool>(load >> _spaceFunctions[ax][i] );
840 ok = static_cast<bool>( load >> _toAddEdges );
842 for ( int i = 0; i < 9 && ok; ++i )
843 ok = static_cast<bool>( load >> _axisDirs[i]);
845 for ( int i = 0; i < 3 && ok ; ++i )
846 ok = static_cast<bool>( load >> _fixedPoint[i]);
851 //=======================================================================
852 //function : SetParametersByMesh
853 //=======================================================================
855 bool StdMeshers_CartesianParameters3D::SetParametersByMesh(const SMESH_Mesh* ,
856 const TopoDS_Shape& )
861 //=======================================================================
862 //function : SetParametersByDefaults
863 //=======================================================================
865 bool StdMeshers_CartesianParameters3D::SetParametersByDefaults(const TDefaults& dflts,
866 const SMESH_Mesh* /*theMesh*/)
868 if ( dflts._elemLength > 1e-100 )
870 vector<string> spacing( 1, SMESH_Comment(dflts._elemLength));
871 vector<double> intPnts;
872 SetGridSpacing( spacing, intPnts, 0 );
873 SetGridSpacing( spacing, intPnts, 1 );
874 SetGridSpacing( spacing, intPnts, 2 );