1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : StdMeshers_HexaFromSkin_3D.cxx
21 // Created : Wed Jan 27 12:28:07 2010
22 // Author : Edward AGAPOV (eap)
24 #include "StdMeshers_HexaFromSkin_3D.hxx"
26 #include "SMDS_VolumeOfNodes.hxx"
27 #include "SMDS_VolumeTool.hxx"
28 #include "SMESHDS_Mesh.hxx"
29 #include "SMESH_Block.hxx"
30 #include "SMESH_Mesh.hxx"
31 #include "SMESH_MeshAlgos.hxx"
32 #include "SMESH_MesherHelper.hxx"
40 // Define error message and _MYDEBUG_ if needed
42 #define BAD_MESH_ERR \
43 error(SMESH_Comment("Can't detect block-wise structure of the input 2D mesh.\n" \
44 __FILE__ ":" )<<__LINE__)
47 #define BAD_MESH_ERR \
48 error(SMESH_Comment("Can't detect block-wise structure of the input 2D mesh"))
54 #define _DUMP_(msg) cout << msg << endl
62 enum EBoxSides //!< sides of the block
64 B_BOTTOM=0, B_RIGHT, B_TOP, B_LEFT, B_FRONT, B_BACK, NB_BLOCK_SIDES
67 const char* SBoxSides[] = //!< names of block sides -- needed for DEBUG only
69 "BOTTOM", "RIGHT", "TOP", "LEFT", "FRONT", "BACK", "UNDEFINED"
72 enum EQuadEdge //!< edges of quadrangle side
74 Q_BOTTOM = 0, Q_RIGHT, Q_TOP, Q_LEFT, NB_QUAD_SIDES
78 //================================================================================
80 * \brief return logical coordinates (i.e. min or max) of ends of edge
82 //================================================================================
84 bool getEdgeEnds(EQuadEdge edge, bool& xMax1, bool& yMax1, bool& xMax2, bool& yMax2 )
86 xMax1=0, yMax1=0, xMax2=1, yMax2=1;
89 case Q_BOTTOM: yMax2 = 0; break;
90 case Q_RIGHT: xMax1 = 1; break;
91 case Q_TOP: yMax1 = 1; break;
92 case Q_LEFT: xMax2 = 0; break;
99 //================================================================================
101 * \brief return true if a node is at block corner
103 * This check is valid for simple cases only
105 //================================================================================
107 bool isCornerNode( const SMDS_MeshNode* n )
109 int nbF = n ? n->NbInverseElements( SMDSAbs_Face ) : 1;
113 set<const SMDS_MeshNode*> nodesInInverseFaces;
114 SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator( SMDSAbs_Face );
115 while ( fIt->more() )
117 const SMDS_MeshElement* face = fIt->next();
118 nodesInInverseFaces.insert( face->begin_nodes(), face->end_nodes() );
121 return (int)nodesInInverseFaces.size() != ( 6 + (nbF/2-1)*3 );
124 //================================================================================
126 * \brief check element type
128 //================================================================================
130 bool isQuadrangle(const SMDS_MeshElement* e)
132 return ( e && e->NbCornerNodes() == 4 );
135 //================================================================================
137 * \brief return opposite node of a quadrangle face
139 //================================================================================
141 const SMDS_MeshNode* oppositeNode(const SMDS_MeshElement* quad, int iNode)
143 return quad->GetNode( (iNode+2) % 4 );
146 //================================================================================
148 * \brief Convertor of a pair of integers to a sole index
153 _Indexer( int xSize=0, int ySize=0 ): _xSize(xSize), _ySize(ySize) {}
154 int size() const { return _xSize * _ySize; }
155 int operator()(int x, int y) const { return y * _xSize + x; }
157 //================================================================================
159 * \brief Oriented convertor of a pair of integers to a sole index
161 class _OrientedIndexer : public _Indexer
164 enum OriFlags //!< types of block side orientation
166 REV_X = 1, REV_Y = 2, SWAP_XY = 4, MAX_ORI = REV_X|REV_Y|SWAP_XY
168 _OrientedIndexer( const _Indexer& indexer, const int oriFlags ):
169 _Indexer( indexer._xSize, indexer._ySize ),
170 _xSize (indexer._xSize), _ySize(indexer._ySize),
171 _xRevFun((oriFlags & REV_X) ? & reverse : & lazy),
172 _yRevFun((oriFlags & REV_Y) ? & reverse : & lazy),
173 _swapFun((oriFlags & SWAP_XY ) ? & swap : & lazy)
175 (*_swapFun)( _xSize, _ySize );
177 //!< Return index by XY
178 int operator()(int x, int y) const
180 (*_xRevFun)( x, const_cast<int&>( _xSize ));
181 (*_yRevFun)( y, const_cast<int&>( _ySize ));
183 return _Indexer::operator()(x,y);
185 //!< Return index for a corner
186 int corner(bool xMax, bool yMax) const
188 int x = xMax, y = yMax, size = 2;
189 (*_xRevFun)( x, size );
190 (*_yRevFun)( y, size );
192 return _Indexer::operator()(x ? _Indexer::_xSize-1 : 0 , y ? _Indexer::_ySize-1 : 0);
194 int xSize() const { return _xSize; }
195 int ySize() const { return _ySize; }
200 typedef void (*TFun)(int& x, int& y);
201 TFun _xRevFun, _yRevFun, _swapFun;
203 static void lazy (int&, int&) {}
204 static void reverse(int& x, int& size) { x = size - x - 1; }
205 static void swap (int& x, int& y) { std::swap(x,y); }
207 //================================================================================
209 * \brief Structure corresponding to the meshed side of block
213 vector<const SMDS_MeshNode*> _grid;
215 int _nbBlocksExpected;
218 #ifdef _DEBUG_ // want to get SIGSEGV in case of invalid index
219 #define _grid_access_(pobj, i) pobj->_grid[ ((i) < (int)pobj->_grid.size()) ? i : int(1e100)]
221 #define _grid_access_(pobj, i) pobj->_grid[ i ]
223 //!< Return node at XY
224 const SMDS_MeshNode* getNode(int x, int y) const { return _grid_access_(this, _index( x,y ));}
226 void setNode(int x, int y, const SMDS_MeshNode* n) { _grid_access_(this, _index( x,y )) = n; }
228 SMESH_OrientedLink getEdge(EQuadEdge edge) const
230 bool x1, y1, x2, y2; getEdgeEnds( edge, x1, y1, x2, y2 );
231 return SMESH_OrientedLink( getCornerNode ( x1, y1 ), getCornerNode( x2, y2 ));
233 //!< Return a corner node
234 const SMDS_MeshNode* getCornerNode(bool isXMax, bool isYMax) const
236 return getNode( isXMax ? _index._xSize-1 : 0 , isYMax ? _index._ySize-1 : 0 );
238 const SMDS_MeshElement* getCornerFace(const SMDS_MeshNode* cornerNode) const;
239 //!< True if all blocks this side belongs to have been found
240 bool isBound() const { return _nbBlocksExpected <= _nbBlocksFound; }
241 //!< Return coordinates of node at XY
242 gp_XYZ getXYZ(int x, int y) const { return SMESH_TNodeXYZ( getNode( x, y )); }
243 //!< Return gravity center of the four corners and the middle node
248 getXYZ( _index._xSize-1, 0 ) +
249 getXYZ( 0, _index._ySize-1 ) +
250 getXYZ( _index._xSize-1, _index._ySize-1 ) +
251 getXYZ( _index._xSize/2, _index._ySize/2 );
254 //!< Return number of mesh faces
255 int getNbFaces() const { return (_index._xSize-1) * (_index._ySize-1); }
257 //================================================================================
259 * \brief _BlockSide with changed orientation
261 struct _OrientedBlockSide
264 _OrientedIndexer _index;
266 _OrientedBlockSide( _BlockSide* side=0, const int oriFlags=0 ):
267 _side(side), _index(side ? side->_index : _Indexer(), oriFlags ) {}
268 //!< return coordinates by XY
269 gp_XYZ xyz(int x, int y) const
271 return SMESH_TNodeXYZ( _grid_access_(_side, _index( x, y )) );
273 //!< safely return a node by XY
274 const SMDS_MeshNode* node(int x, int y) const
276 size_t i = _index( x, y );
277 return ( i >= _side->_grid.size() ) ? 0 : _side->_grid[i];
280 SMESH_OrientedLink edge(EQuadEdge edge) const
282 bool x1, y1, x2, y2; getEdgeEnds( edge, x1, y1, x2, y2 );
283 return SMESH_OrientedLink( cornerNode ( x1, y1 ), cornerNode( x2, y2 ));
285 //!< Return a corner node
286 const SMDS_MeshNode* cornerNode(bool isXMax, bool isYMax) const
288 return _grid_access_(_side, _index.corner( isXMax, isYMax ));
290 //!< return its size in nodes
291 int getHoriSize() const { return _index.xSize(); }
292 int getVertSize() const { return _index.ySize(); }
293 //!< True if _side has been initialized
294 operator bool() const { return _side; }
295 //! Direct access to _side
296 const _BlockSide* operator->() const { return _side; }
297 _BlockSide* operator->() { return _side; }
299 //================================================================================
301 * \brief Meshed skin of block
305 _OrientedBlockSide _side[6]; // 6 sides of a sub-block
306 set<const SMDS_MeshNode*> _corners;
308 const _OrientedBlockSide& getSide(int i) const { return _side[i]; }
309 bool setSide( int i, const _OrientedBlockSide& s)
311 if (( _side[i] = s ))
313 _corners.insert( s.cornerNode(0,0));
314 _corners.insert( s.cornerNode(1,0));
315 _corners.insert( s.cornerNode(0,1));
316 _corners.insert( s.cornerNode(1,1));
320 void clear() { for (int i=0;i<6;++i) _side[i]=0; _corners.clear(); }
321 bool hasSide( const _OrientedBlockSide& s) const
323 if ( s ) for (int i=0;i<6;++i) if ( _side[i] && _side[i]._side == s._side ) return true;
326 int nbSides() const { int n=0; for (int i=0;i<6;++i) if ( _side[i] ) ++n; return n; }
327 bool isValid() const;
329 //================================================================================
331 * \brief Skin mesh possibly containing several meshed blocks
337 int findBlocks(SMESH_Mesh& mesh);
338 //!< return i-th block
339 const _Block& getBlock(int i) const { return _blocks[i]; }
340 //!< return error description
341 const SMESH_Comment& error() const { return _error; }
344 bool fillSide( _BlockSide& side,
345 const SMDS_MeshElement* cornerQuad,
346 const SMDS_MeshNode* cornerNode);
347 bool fillRowsUntilCorner(const SMDS_MeshElement* quad,
348 const SMDS_MeshNode* n1,
349 const SMDS_MeshNode* n2,
350 vector<const SMDS_MeshNode*>& verRow1,
351 vector<const SMDS_MeshNode*>& verRow2,
353 _OrientedBlockSide findBlockSide( EBoxSides startBlockSide,
354 EQuadEdge sharedSideEdge1,
355 EQuadEdge sharedSideEdge2,
356 bool withGeometricAnalysis,
357 set< _BlockSide* >& sidesAround);
358 //!< update own data and data of the side bound to block
359 void setSideBoundToBlock( _BlockSide& side )
361 if ( side._nbBlocksFound++, side.isBound() )
362 for ( int e = 0; e < int(NB_QUAD_SIDES); ++e )
363 _edge2sides[ side.getEdge( (EQuadEdge) e ) ].erase( &side );
365 //!< store reason of error
366 int error(const SMESH_Comment& reason) { _error = reason; return 0; }
368 SMESH_Comment _error;
370 list< _BlockSide > _allSides;
371 vector< _Block > _blocks;
373 //map< const SMDS_MeshNode*, set< _BlockSide* > > _corner2sides;
374 map< SMESH_OrientedLink, set< _BlockSide* > > _edge2sides;
377 //================================================================================
379 * \brief Find blocks and return their number
381 //================================================================================
383 int _Skin::findBlocks(SMESH_Mesh& mesh)
385 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
387 // Find a node at any block corner
389 SMDS_NodeIteratorPtr nIt = meshDS->nodesIterator(/*idInceasingOrder=*/true);
390 if ( !nIt->more() ) return error("Empty mesh");
392 const SMDS_MeshNode* nCorner = 0;
393 while ( nIt->more() )
395 nCorner = nIt->next();
396 if ( isCornerNode( nCorner ))
404 // --------------------------------------------------------------------
405 // Find all block sides starting from mesh faces sharing the corner node
406 // --------------------------------------------------------------------
408 int nbFacesOnSides = 0;
409 TIDSortedElemSet cornerFaces; // corner faces of found _BlockSide's
410 list< const SMDS_MeshNode* > corners( 1, nCorner );
411 list< const SMDS_MeshNode* >::iterator corner = corners.begin();
412 while ( corner != corners.end() )
414 SMDS_ElemIteratorPtr faceIt = (*corner)->GetInverseElementIterator( SMDSAbs_Face );
415 while ( faceIt->more() )
417 const SMDS_MeshElement* face = faceIt->next();
418 if ( !cornerFaces.insert( face ).second )
419 continue; // already loaded block side
421 if ( !isQuadrangle( face ))
422 return error("Non-quadrangle elements in the input mesh");
424 if ( _allSides.empty() || !_allSides.back()._grid.empty() )
425 _allSides.push_back( _BlockSide() );
427 _BlockSide& side = _allSides.back();
428 if ( !fillSide( side, face, *corner ))
430 if ( !_error.empty() )
435 for ( int isXMax = 0; isXMax < 2; ++isXMax )
436 for ( int isYMax = 0; isYMax < 2; ++isYMax )
438 const SMDS_MeshNode* nCorner = side.getCornerNode(isXMax,isYMax );
439 corners.push_back( nCorner );
440 cornerFaces.insert( side.getCornerFace( nCorner ));
442 for ( int e = 0; e < int(NB_QUAD_SIDES); ++e )
443 _edge2sides[ side.getEdge( (EQuadEdge) e ) ].insert( &side );
445 nbFacesOnSides += side.getNbFaces();
450 // find block sides of other domains if any
451 if ( corner == corners.end() && nbFacesOnSides < mesh.NbQuadrangles() )
453 while ( nIt->more() )
455 nCorner = nIt->next();
456 if ( isCornerNode( nCorner ))
457 corner = corners.insert( corner, nCorner );
459 nbFacesOnSides = mesh.NbQuadrangles();
463 if ( _allSides.empty() )
465 if ( _allSides.back()._grid.empty() )
466 _allSides.pop_back();
467 _DUMP_("Nb detected sides "<< _allSides.size());
469 // ---------------------------
470 // Organize sides into blocks
471 // ---------------------------
473 // analyse sharing of sides by blocks and sort sides by nb of adjacent sides
474 int nbBlockSides = 0; // total nb of block sides taking into account their sharing
475 multimap<int, _BlockSide* > sortedSides;
477 list < _BlockSide >::iterator sideIt = _allSides.begin();
478 for ( ; sideIt != _allSides.end(); ++sideIt )
480 _BlockSide& side = *sideIt;
481 bool isSharedSide = true;
483 for ( int e = 0; e < int(NB_QUAD_SIDES) && isSharedSide; ++e )
485 int nbAdj = _edge2sides[ side.getEdge( (EQuadEdge) e ) ].size();
487 isSharedSide = ( nbAdj > 2 );
489 side._nbBlocksFound = 0;
490 side._nbBlocksExpected = isSharedSide ? 2 : 1;
491 nbBlockSides += side._nbBlocksExpected;
492 sortedSides.insert( make_pair( nbAdjacent, & side ));
496 // find sides of each block
498 while ( nbBlockSides >= 6 )
500 // get any side not bound to all blocks it belongs to
501 multimap<int, _BlockSide*>::iterator i_side = sortedSides.begin();
502 while ( i_side != sortedSides.end() && i_side->second->isBound())
505 // start searching for block sides from the got side
507 if ( _blocks.empty() || _blocks.back()._side[B_FRONT] )
508 _blocks.resize( _blocks.size() + 1 );
510 _Block& block = _blocks.back();
511 block.setSide( B_FRONT, i_side->second );
512 setSideBoundToBlock( *i_side->second );
515 // edges of adjacent sides of B_FRONT corresponding to front's edges
516 EQuadEdge edgeOfFront[4] = { Q_BOTTOM, Q_RIGHT, Q_TOP, Q_LEFT };
517 EQuadEdge edgeOfAdj [4] = { Q_BOTTOM, Q_LEFT, Q_BOTTOM, Q_LEFT };
518 // first find all sides detectable w/o advanced analysis,
519 // then repeat the search, which then may pass without advanced analysis
520 set< _BlockSide* > sidesAround;
521 for ( int advAnalys = 0; advAnalys < 2; ++advAnalys )
523 // try to find 4 sides adjacent to a FRONT side
524 for ( int i = 0; (ok || !advAnalys) && i < NB_QUAD_SIDES; ++i )
525 if ( !block._side[i] )
526 ok = block.setSide( i, findBlockSide( B_FRONT, edgeOfFront[i], edgeOfAdj[i],
527 advAnalys, sidesAround));
528 // try to find a BACK side by a TOP one
529 if ( ok || !advAnalys )
530 if ( !block._side[B_BACK] && block._side[B_TOP] )
531 ok = block.setSide( B_BACK, findBlockSide( B_TOP, Q_TOP, Q_TOP,
532 advAnalys, sidesAround ));
533 if ( !advAnalys ) ok = true;
535 ok = block.isValid();
538 // check if just found block is same as one of previously found blocks
540 for ( size_t i = 1; i < _blocks.size() && !isSame; ++i )
541 isSame = ( block._corners == _blocks[i-1]._corners );
545 // count the found sides
546 _DUMP_(endl << "** Block " << _blocks.size() << " valid: " << block.isValid());
547 for (int i = 0; i < NB_BLOCK_SIDES; ++i )
549 _DUMP_("\tSide "<< SBoxSides[i] <<" "<< block._side[ i ]._side);
550 if ( block._side[ i ] )
552 if ( ok && i != B_FRONT)
554 setSideBoundToBlock( *block._side[ i ]._side );
557 _DUMP_("\t corners "<<
558 block._side[ i ].cornerNode(0,0)->GetID() << ", " <<
559 block._side[ i ].cornerNode(1,0)->GetID() << ", " <<
560 block._side[ i ].cornerNode(1,1)->GetID() << ", " <<
561 block._side[ i ].cornerNode(0,1)->GetID() << ", "<<endl);
565 _DUMP_("\t not found"<<endl);
573 _DUMP_("Nb found blocks "<< nbBlocks <<endl);
575 if ( nbBlocks == 0 && _error.empty() )
581 //================================================================================
583 * \brief Fill block side data starting from its corner quadrangle
585 //================================================================================
587 bool _Skin::fillSide( _BlockSide& side,
588 const SMDS_MeshElement* cornerQuad,
589 const SMDS_MeshNode* nCorner)
591 // Find out size of block side mesured in nodes and by the way find two rows
592 // of nodes in two directions.
595 const SMDS_MeshElement* firstQuad = cornerQuad;
597 // get a node on block edge
598 int iCorner = firstQuad->GetNodeIndex( nCorner );
599 const SMDS_MeshNode* nOnEdge = firstQuad->GetNode( (iCorner+1) % 4);
601 // find out size of block side
602 vector<const SMDS_MeshNode*> horRow1, horRow2, verRow1, verRow2;
603 if ( !fillRowsUntilCorner( firstQuad, nCorner, nOnEdge, horRow1, horRow2, true ) ||
604 !fillRowsUntilCorner( firstQuad, nCorner, nOnEdge, verRow1, verRow2, false ))
606 nbX = horRow1.size(), nbY = verRow1.size();
609 side._index._xSize = horRow1.size();
610 side._index._ySize = verRow1.size();
611 side._grid.resize( side._index.size(), NULL );
613 for ( x = 0; x < nbX; ++x )
615 side.setNode( x, 0, horRow1[x] );
616 side.setNode( x, 1, horRow2[x] );
618 for ( y = 0; y < nbY; ++y )
620 side.setNode( 0, y, verRow1[y] );
621 side.setNode( 1, y, verRow2[y] );
624 // Find the rest nodes
626 y = 1; // y of the row to fill
627 TIDSortedElemSet emptySet, avoidSet;
630 // get next firstQuad in the next row of quadrangles
635 // o---o o o o o <- found nodes
638 int i1down, i2down, i2up;
639 const SMDS_MeshNode* n1down = side.getNode( 0, y-1 );
640 const SMDS_MeshNode* n2down = side.getNode( 1, y-1 );
641 avoidSet.clear(); avoidSet.insert( firstQuad );
642 firstQuad = SMESH_MeshAlgos::FindFaceInSet( n1down, n2down, emptySet, avoidSet,
644 if ( !isQuadrangle( firstQuad ))
647 const SMDS_MeshNode* n2up = oppositeNode( firstQuad, i1down );
648 avoidSet.clear(); avoidSet.insert( firstQuad );
650 // find the rest nodes in the y-th row by faces in the row
655 const SMDS_MeshElement* quad = SMESH_MeshAlgos::FindFaceInSet( n2up, n2down, emptySet,
656 avoidSet, &i2up, &i2down);
657 if ( !isQuadrangle( quad ))
660 n2up = oppositeNode( quad, i2down );
661 n2down = oppositeNode( quad, i2up );
662 avoidSet.clear(); avoidSet.insert( quad );
664 side.setNode( x, y, n2up );
668 // check side validity
670 side.getCornerFace( side.getCornerNode( 0, 0 )) &&
671 side.getCornerFace( side.getCornerNode( 1, 0 )) &&
672 side.getCornerFace( side.getCornerNode( 0, 1 )) &&
673 side.getCornerFace( side.getCornerNode( 1, 1 ));
678 //================================================================================
680 * \brief Return true if it's possible to make a loop over corner2Sides starting
683 //================================================================================
685 bool isClosedChainOfSides( _BlockSide* startSide,
686 map< const SMDS_MeshNode*, list< _BlockSide* > > & corner2Sides )
688 // get start and end nodes
689 const SMDS_MeshNode *n1 = 0, *n2 = 0, *n;
690 for ( int y = 0; y < 2; ++y )
691 for ( int x = 0; x < 2; ++x )
693 n = startSide->getCornerNode(x,y);
694 if ( !corner2Sides.count( n )) continue;
700 if ( !n2 ) return false;
702 map< const SMDS_MeshNode*, list< _BlockSide* > >::iterator
703 c2sides = corner2Sides.find( n1 );
704 if ( c2sides == corner2Sides.end() ) return false;
706 int nbChainLinks = 1;
708 _BlockSide* prevSide = startSide;
711 // get the next side sharing n
712 list< _BlockSide* > & sides = c2sides->second;
713 _BlockSide* nextSide = ( sides.back() == prevSide ? sides.front() : sides.back() );
714 if ( nextSide == prevSide ) return false;
716 // find the next corner of the nextSide being in corner2Sides
719 for ( int y = 0; y < 2 && !n; ++y )
720 for ( int x = 0; x < 2; ++x )
722 n = nextSide->getCornerNode(x,y);
723 c2sides = corner2Sides.find( n );
724 if ( n == n1 || c2sides == corner2Sides.end() )
729 if ( !n ) return false;
733 if ( ++nbChainLinks > NB_QUAD_SIDES )
737 return ( n == n2 && nbChainLinks == NB_QUAD_SIDES );
740 //================================================================================
742 * \brief Try to find a block side adjacent to the given side by given edge
744 //================================================================================
746 _OrientedBlockSide _Skin::findBlockSide( EBoxSides startBlockSide,
747 EQuadEdge sharedSideEdge1,
748 EQuadEdge sharedSideEdge2,
749 bool withGeometricAnalysis,
750 set< _BlockSide* >& sidesAround)
752 _Block& block = _blocks.back();
753 _OrientedBlockSide& side1 = block._side[ startBlockSide ];
755 // get corner nodes of the given block edge
756 SMESH_OrientedLink edge = side1.edge( sharedSideEdge1 );
757 const SMDS_MeshNode* n1 = edge.node1();
758 const SMDS_MeshNode* n2 = edge.node2();
759 if ( edge._reversed ) swap( n1, n2 );
761 // find all sides sharing both nodes n1 and n2
762 set< _BlockSide* > sidesOnEdge = _edge2sides[ edge ]; // copy a set
764 // exclude loaded sides of block from sidesOnEdge
765 for (int i = 0; i < NB_BLOCK_SIDES; ++i )
766 if ( block._side[ i ] )
767 sidesOnEdge.erase( block._side[ i ]._side );
769 int nbSidesOnEdge = sidesOnEdge.size();
770 _DUMP_("nbSidesOnEdge "<< nbSidesOnEdge << " " << n1->GetID() << "-" << n2->GetID() );
771 if ( nbSidesOnEdge == 0 )
774 _BlockSide* foundSide = 0;
775 if ( nbSidesOnEdge == 1 )
777 foundSide = *sidesOnEdge.begin();
781 set< _BlockSide* >::iterator sideIt = sidesOnEdge.begin();
782 int nbLoadedSides = block.nbSides();
783 if ( nbLoadedSides > 1 )
785 // Find the side having more than 2 corners common with already loaded sides
786 for (; !foundSide && sideIt != sidesOnEdge.end(); ++sideIt )
788 _BlockSide* sideI = *sideIt;
789 int nbCommonCorners =
790 block._corners.count( sideI->getCornerNode(0,0)) +
791 block._corners.count( sideI->getCornerNode(1,0)) +
792 block._corners.count( sideI->getCornerNode(0,1)) +
793 block._corners.count( sideI->getCornerNode(1,1));
794 if ( nbCommonCorners > 2 )
801 if ( !withGeometricAnalysis )
803 sidesAround.insert( sidesOnEdge.begin(), sidesOnEdge.end() );
806 if ( nbLoadedSides == 1 )
808 // Issue 0021529. There are at least 2 sides by each edge and
809 // position of block gravity center is undefined.
810 // Find a side starting from which we can walk around the startBlockSide
812 // fill in corner2Sides
813 map< const SMDS_MeshNode*, list< _BlockSide* > > corner2Sides;
814 for ( sideIt = sidesAround.begin(); sideIt != sidesAround.end(); ++sideIt )
816 _BlockSide* sideI = *sideIt;
817 corner2Sides[ sideI->getCornerNode(0,0) ].push_back( sideI );
818 corner2Sides[ sideI->getCornerNode(1,0) ].push_back( sideI );
819 corner2Sides[ sideI->getCornerNode(0,1) ].push_back( sideI );
820 corner2Sides[ sideI->getCornerNode(1,1) ].push_back( sideI );
822 // remove corners of startBlockSide from corner2Sides
823 set<const SMDS_MeshNode*>::iterator nIt = block._corners.begin();
824 for ( ; nIt != block._corners.end(); ++nIt )
825 corner2Sides.erase( *nIt );
828 for ( sideIt = sidesOnEdge.begin(); sideIt != sidesOnEdge.end(); ++sideIt )
830 if ( isClosedChainOfSides( *sideIt, corner2Sides ))
841 // Select one of found sides most close to startBlockSide
843 gp_XYZ p1 ( n1->X(),n1->Y(),n1->Z()), p2 (n2->X(),n2->Y(),n2->Z());
844 gp_Vec p1p2( p1, p2 );
846 const SMDS_MeshElement* face1 = side1->getCornerFace( n1 );
847 gp_XYZ p1Op = SMESH_TNodeXYZ( oppositeNode( face1, face1->GetNodeIndex(n1)));
848 gp_Vec side1Dir( p1, p1Op );
849 gp_Ax2 pln( p1, p1p2, side1Dir ); // plane with normal p1p2 and X dir side1Dir
850 _DUMP_(" Select adjacent for "<< side1._side << " - side dir ("
851 << side1Dir.X() << ", " << side1Dir.Y() << ", " << side1Dir.Z() << ")" );
853 map < double , _BlockSide* > angleOfSide;
854 for (sideIt = sidesOnEdge.begin(); sideIt != sidesOnEdge.end(); ++sideIt )
856 _BlockSide* sideI = *sideIt;
857 const SMDS_MeshElement* faceI = sideI->getCornerFace( n1 );
858 gp_XYZ p1Op = SMESH_TNodeXYZ( oppositeNode( faceI, faceI->GetNodeIndex(n1)));
859 gp_Vec sideIDir( p1, p1Op );
860 // compute angle of (sideIDir projection to pln) and (X dir of pln)
861 gp_Vec2d sideIDirProj( sideIDir * pln.XDirection(), sideIDir * pln.YDirection());
862 double angle = sideIDirProj.Angle( gp::DX2d() );
863 if ( angle < 0 ) angle += 2. * M_PI; // angle [0-2*PI]
864 angleOfSide.insert( make_pair( angle, sideI ));
865 _DUMP_(" "<< sideI << " - side dir ("
866 << sideIDir.X() << ", " << sideIDir.Y() << ", " << sideIDir.Z() << ")"
867 << " angle " << angle);
870 gp_XYZ gc(0,0,0); // gravity center of already loaded block sides
871 for (int i = 0; i < NB_BLOCK_SIDES; ++i )
872 if ( block._side[ i ] )
873 gc += block._side[ i ]._side->getGC();
876 gp_Vec gcDir( p1, gc );
877 gp_Vec2d gcDirProj( gcDir * pln.XDirection(), gcDir * pln.YDirection());
878 double gcAngle = gcDirProj.Angle( gp::DX2d() );
879 foundSide = gcAngle < 0 ? angleOfSide.rbegin()->second : angleOfSide.begin()->second;
882 _DUMP_(" selected "<< foundSide );
885 // Orient the found side correctly
887 // corners of found side corresponding to nodes n1 and n2
888 bool xMax1, yMax1, xMax2, yMax2;
889 if ( !getEdgeEnds( sharedSideEdge2, xMax1, yMax1, xMax2, yMax2 ))
890 return error(SMESH_Comment("Internal error at ")<<__FILE__<<":"<<__LINE__),
891 _OrientedBlockSide(0);
893 for ( int ori = 0; ori < _OrientedIndexer::MAX_ORI+1; ++ori )
895 _OrientedBlockSide orientedSide( foundSide, ori );
896 const SMDS_MeshNode* n12 = orientedSide.cornerNode( xMax1, yMax1);
897 const SMDS_MeshNode* n22 = orientedSide.cornerNode( xMax2, yMax2);
898 if ( n1 == n12 && n2 == n22 )
901 error(SMESH_Comment("Failed to orient a block side found by edge ")<<sharedSideEdge1
902 << " of side " << startBlockSide
903 << " of block " << _blocks.size());
907 //================================================================================
909 * \brief: Fill rows (which are actually columns,if !alongN1N2) of nodes starting
910 * from the given quadrangle until another block corner encounters.
911 * n1 and n2 are at bottom of quad, n1 is at block corner.
913 //================================================================================
915 bool _Skin::fillRowsUntilCorner(const SMDS_MeshElement* quad,
916 const SMDS_MeshNode* n1,
917 const SMDS_MeshNode* n2,
918 vector<const SMDS_MeshNode*>& row1,
919 vector<const SMDS_MeshNode*>& row2,
920 const bool alongN1N2 )
922 const SMDS_MeshNode* corner1 = n1;
924 // Store nodes of quad in the rows and find new n1 and n2 to get
925 // the next face so that new n2 is on block edge
926 int i1 = quad->GetNodeIndex( n1 );
927 int i2 = quad->GetNodeIndex( n2 );
928 row1.clear(); row2.clear();
929 row1.push_back( n1 );
932 row1.push_back( n2 );
933 row2.push_back( oppositeNode( quad, i2 ));
934 row2.push_back( n1 = oppositeNode( quad, i1 ));
938 row2.push_back( n2 );
939 row1.push_back( n2 = oppositeNode( quad, i2 ));
940 row2.push_back( n1 = oppositeNode( quad, i1 ));
943 if ( isCornerNode( row1[1] ))
946 // Find the rest nodes
947 TIDSortedElemSet emptySet, avoidSet;
948 while ( !isCornerNode( n2 ) )
950 avoidSet.clear(); avoidSet.insert( quad );
951 quad = SMESH_MeshAlgos::FindFaceInSet( n1, n2, emptySet, avoidSet, &i1, &i2 );
952 if ( !isQuadrangle( quad ))
955 row1.push_back( n2 = oppositeNode( quad, i1 ));
956 row2.push_back( n1 = oppositeNode( quad, i2 ));
958 return n1 != corner1;
961 //================================================================================
963 * \brief Return a corner face by a corner node
965 //================================================================================
967 const SMDS_MeshElement* _BlockSide::getCornerFace(const SMDS_MeshNode* cornerNode) const
969 int x, y, isXMax, isYMax, found = 0;
970 for ( isXMax = 0; isXMax < 2; ++isXMax )
972 for ( isYMax = 0; isYMax < 2; ++isYMax )
974 x = isXMax ? _index._xSize-1 : 0;
975 y = isYMax ? _index._ySize-1 : 0;
976 found = ( getNode(x,y) == cornerNode );
981 if ( !found ) return 0;
982 int dx = isXMax ? -1 : +1;
983 int dy = isYMax ? -1 : +1;
984 const SMDS_MeshNode* n1 = getNode(x,y);
985 const SMDS_MeshNode* n2 = getNode(x+dx,y);
986 const SMDS_MeshNode* n3 = getNode(x,y+dy);
987 const SMDS_MeshNode* n4 = getNode(x+dx,y+dy);
988 return SMDS_Mesh::FindFace(n1, n2, n3, n4 );
991 //================================================================================
993 * \brief Checks own validity
995 //================================================================================
997 bool _Block::isValid() const
999 bool ok = ( nbSides() == 6 );
1001 // check only corners depending on side selection
1002 EBoxSides adjacent[4] = { B_BOTTOM, B_RIGHT, B_TOP, B_LEFT };
1003 EQuadEdge edgeAdj [4] = { Q_TOP, Q_RIGHT, Q_TOP, Q_RIGHT };
1004 EQuadEdge edgeBack[4] = { Q_BOTTOM, Q_RIGHT, Q_TOP, Q_LEFT };
1006 for ( int i=0; ok && i < NB_QUAD_SIDES; ++i )
1008 SMESH_OrientedLink eBack = _side[ B_BACK ].edge( edgeBack[i] );
1009 SMESH_OrientedLink eAdja = _side[ adjacent[i] ].edge( edgeAdj[i] );
1010 ok = ( eBack == eAdja );
1012 ok = ok && ( _side[ B_BOTTOM ]._index.size() == _side[ B_TOP ]._index.size() &&
1013 _side[ B_RIGHT ]._index.size() == _side[ B_LEFT ]._index.size() &&
1014 _side[ B_FRONT ]._index.size() == _side[ B_BACK ]._index.size() );
1020 //=======================================================================
1021 //function : StdMeshers_HexaFromSkin_3D
1023 //=======================================================================
1025 StdMeshers_HexaFromSkin_3D::StdMeshers_HexaFromSkin_3D(int hypId, int studyId, SMESH_Gen* gen)
1026 :SMESH_3D_Algo(hypId, studyId, gen)
1028 MESSAGE("StdMeshers_HexaFromSkin_3D::StdMeshers_HexaFromSkin_3D");
1029 _name = "HexaFromSkin_3D";
1032 StdMeshers_HexaFromSkin_3D::~StdMeshers_HexaFromSkin_3D()
1034 MESSAGE("StdMeshers_HexaFromSkin_3D::~StdMeshers_HexaFromSkin_3D");
1037 //================================================================================
1039 * \brief Main method, which generates hexaheda
1041 //================================================================================
1043 bool StdMeshers_HexaFromSkin_3D::Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHelper)
1046 int nbBlocks = skin.findBlocks(aMesh);
1047 if ( nbBlocks == 0 )
1048 return error( skin.error());
1050 vector< vector< const SMDS_MeshNode* > > columns;
1051 int x, xSize, y, ySize, z, zSize;
1054 for ( int i = 0; i < nbBlocks; ++i )
1056 const _Block& block = skin.getBlock( i );
1058 // ------------------------------------------
1059 // Fill columns of nodes with existing nodes
1060 // ------------------------------------------
1062 xSize = block.getSide(B_BOTTOM).getHoriSize();
1063 ySize = block.getSide(B_BOTTOM).getVertSize();
1064 zSize = block.getSide(B_FRONT ).getVertSize();
1065 int X = xSize - 1, Y = ySize - 1, Z = zSize - 1;
1066 colIndex = _Indexer( xSize, ySize );
1067 columns.resize( colIndex.size() );
1069 // fill node columns by front and back box sides
1070 for ( x = 0; x < xSize; ++x ) {
1071 vector< const SMDS_MeshNode* >& column0 = columns[ colIndex( x, 0 )];
1072 vector< const SMDS_MeshNode* >& column1 = columns[ colIndex( x, Y )];
1073 column0.resize( zSize );
1074 column1.resize( zSize );
1075 for ( z = 0; z < zSize; ++z ) {
1076 column0[ z ] = block.getSide(B_FRONT).node( x, z );
1077 column1[ z ] = block.getSide(B_BACK) .node( x, z );
1080 // fill node columns by left and right box sides
1081 for ( y = 1; y < ySize-1; ++y ) {
1082 vector< const SMDS_MeshNode* >& column0 = columns[ colIndex( 0, y )];
1083 vector< const SMDS_MeshNode* >& column1 = columns[ colIndex( X, y )];
1084 column0.resize( zSize );
1085 column1.resize( zSize );
1086 for ( z = 0; z < zSize; ++z ) {
1087 column0[ z ] = block.getSide(B_LEFT) .node( y, z );
1088 column1[ z ] = block.getSide(B_RIGHT).node( y, z );
1091 // get nodes from top and bottom box sides
1092 for ( x = 1; x < xSize-1; ++x ) {
1093 for ( y = 1; y < ySize-1; ++y ) {
1094 vector< const SMDS_MeshNode* >& column = columns[ colIndex( x, y )];
1095 column.resize( zSize );
1096 column.front() = block.getSide(B_BOTTOM).node( x, y );
1097 column.back() = block.getSide(B_TOP) .node( x, y );
1101 // ----------------------------
1102 // Add internal nodes of a box
1103 // ----------------------------
1104 // projection points of internal nodes on box sub-shapes by which
1105 // coordinates of internal nodes are computed
1106 vector<gp_XYZ> pointOnShape( SMESH_Block::ID_Shell );
1108 // projections on vertices are constant
1109 pointOnShape[ SMESH_Block::ID_V000 ] = block.getSide(B_BOTTOM).xyz( 0, 0 );
1110 pointOnShape[ SMESH_Block::ID_V100 ] = block.getSide(B_BOTTOM).xyz( X, 0 );
1111 pointOnShape[ SMESH_Block::ID_V010 ] = block.getSide(B_BOTTOM).xyz( 0, Y );
1112 pointOnShape[ SMESH_Block::ID_V110 ] = block.getSide(B_BOTTOM).xyz( X, Y );
1113 pointOnShape[ SMESH_Block::ID_V001 ] = block.getSide(B_TOP).xyz( 0, 0 );
1114 pointOnShape[ SMESH_Block::ID_V101 ] = block.getSide(B_TOP).xyz( X, 0 );
1115 pointOnShape[ SMESH_Block::ID_V011 ] = block.getSide(B_TOP).xyz( 0, Y );
1116 pointOnShape[ SMESH_Block::ID_V111 ] = block.getSide(B_TOP).xyz( X, Y );
1118 for ( x = 1; x < xSize-1; ++x )
1120 gp_XYZ params; // normalized parameters of internal node within a unit box
1121 params.SetCoord( 1, x / double(X) );
1122 for ( y = 1; y < ySize-1; ++y )
1124 params.SetCoord( 2, y / double(Y) );
1125 // column to fill during z loop
1126 vector< const SMDS_MeshNode* >& column = columns[ colIndex( x, y )];
1127 // projections on horizontal edges
1128 pointOnShape[ SMESH_Block::ID_Ex00 ] = block.getSide(B_BOTTOM).xyz( x, 0 );
1129 pointOnShape[ SMESH_Block::ID_Ex10 ] = block.getSide(B_BOTTOM).xyz( x, Y );
1130 pointOnShape[ SMESH_Block::ID_E0y0 ] = block.getSide(B_BOTTOM).xyz( 0, y );
1131 pointOnShape[ SMESH_Block::ID_E1y0 ] = block.getSide(B_BOTTOM).xyz( X, y );
1132 pointOnShape[ SMESH_Block::ID_Ex01 ] = block.getSide(B_TOP).xyz( x, 0 );
1133 pointOnShape[ SMESH_Block::ID_Ex11 ] = block.getSide(B_TOP).xyz( x, Y );
1134 pointOnShape[ SMESH_Block::ID_E0y1 ] = block.getSide(B_TOP).xyz( 0, y );
1135 pointOnShape[ SMESH_Block::ID_E1y1 ] = block.getSide(B_TOP).xyz( X, y );
1136 // projections on horizontal sides
1137 pointOnShape[ SMESH_Block::ID_Fxy0 ] = block.getSide(B_BOTTOM).xyz( x, y );
1138 pointOnShape[ SMESH_Block::ID_Fxy1 ] = block.getSide(B_TOP) .xyz( x, y );
1139 for ( z = 1; z < zSize-1; ++z ) // z loop
1141 params.SetCoord( 3, z / double(Z) );
1142 // projections on vertical edges
1143 pointOnShape[ SMESH_Block::ID_E00z ] = block.getSide(B_FRONT).xyz( 0, z );
1144 pointOnShape[ SMESH_Block::ID_E10z ] = block.getSide(B_FRONT).xyz( X, z );
1145 pointOnShape[ SMESH_Block::ID_E01z ] = block.getSide(B_BACK).xyz( 0, z );
1146 pointOnShape[ SMESH_Block::ID_E11z ] = block.getSide(B_BACK).xyz( X, z );
1147 // projections on vertical sides
1148 pointOnShape[ SMESH_Block::ID_Fx0z ] = block.getSide(B_FRONT).xyz( x, z );
1149 pointOnShape[ SMESH_Block::ID_Fx1z ] = block.getSide(B_BACK) .xyz( x, z );
1150 pointOnShape[ SMESH_Block::ID_F0yz ] = block.getSide(B_LEFT) .xyz( y, z );
1151 pointOnShape[ SMESH_Block::ID_F1yz ] = block.getSide(B_RIGHT).xyz( y, z );
1153 // compute internal node coordinates
1155 SMESH_Block::ShellPoint( params, pointOnShape, coords );
1156 column[ z ] = aHelper->AddNode( coords.X(), coords.Y(), coords.Z() );
1160 //cout << "----------------------------------------------------------------------"<<endl;
1161 //for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id)
1163 // gp_XYZ p = pointOnShape[ id ];
1164 // SMESH_Block::DumpShapeID( id,cout)<<" ( "<<p.X()<<", "<<p.Y()<<", "<<p.Z()<<" )"<<endl;
1166 //cout << "Params: ( "<< params.X()<<", "<<params.Y()<<", "<<params.Z()<<" )"<<endl;
1167 //cout << "coords: ( "<< coords.X()<<", "<<coords.Y()<<", "<<coords.Z()<<" )"<<endl;
1176 // find out orientation by a least distorted hexahedron (issue 0020855);
1177 // the last is defined by evaluating sum of face normals of 8 corner hexahedrons
1178 double badness = numeric_limits<double>::max();
1180 for ( int xMax = 0; xMax < 2; ++xMax )
1181 for ( int yMax = 0; yMax < 2; ++yMax )
1182 for ( int zMax = 0; zMax < 2; ++zMax )
1184 x = xMax ? xSize-1 : 1;
1185 y = yMax ? ySize-1 : 1;
1186 z = zMax ? zSize-1 : 1;
1187 vector< const SMDS_MeshNode* >& col00 = columns[ colIndex( x-1, y-1 )];
1188 vector< const SMDS_MeshNode* >& col10 = columns[ colIndex( x , y-1 )];
1189 vector< const SMDS_MeshNode* >& col01 = columns[ colIndex( x-1, y )];
1190 vector< const SMDS_MeshNode* >& col11 = columns[ colIndex( x , y )];
1192 const SMDS_MeshNode* n000 = col00[z-1];
1193 const SMDS_MeshNode* n100 = col10[z-1];
1194 const SMDS_MeshNode* n010 = col01[z-1];
1195 const SMDS_MeshNode* n110 = col11[z-1];
1196 const SMDS_MeshNode* n001 = col00[z];
1197 const SMDS_MeshNode* n101 = col10[z];
1198 const SMDS_MeshNode* n011 = col01[z];
1199 const SMDS_MeshNode* n111 = col11[z];
1200 SMDS_VolumeOfNodes probeVolume (n000,n010,n110,n100,
1201 n001,n011,n111,n101);
1202 SMDS_VolumeTool volTool( &probeVolume );
1203 double Nx=0.,Ny=0.,Nz=0.;
1204 for ( int iFace = 0; iFace < volTool.NbFaces(); ++iFace )
1207 volTool.GetFaceNormal( iFace, nx,ny,nz );
1212 double quality = Nx*Nx + Ny*Ny + Nz*Nz;
1213 if ( quality < badness )
1216 isForw = volTool.IsForward();
1221 for ( x = 0; x < xSize-1; ++x ) {
1222 for ( y = 0; y < ySize-1; ++y ) {
1223 vector< const SMDS_MeshNode* >& col00 = columns[ colIndex( x, y )];
1224 vector< const SMDS_MeshNode* >& col10 = columns[ colIndex( x+1, y )];
1225 vector< const SMDS_MeshNode* >& col01 = columns[ colIndex( x, y+1 )];
1226 vector< const SMDS_MeshNode* >& col11 = columns[ colIndex( x+1, y+1 )];
1227 // bottom face normal of a hexa mush point outside the volume
1229 for ( z = 0; z < zSize-1; ++z )
1230 aHelper->AddVolume(col00[z], col01[z], col11[z], col10[z],
1231 col00[z+1], col01[z+1], col11[z+1], col10[z+1]);
1233 for ( z = 0; z < zSize-1; ++z )
1234 aHelper->AddVolume(col00[z], col10[z], col11[z], col01[z],
1235 col00[z+1], col10[z+1], col11[z+1], col01[z+1]);
1243 //================================================================================
1245 * \brief Evaluate nb of hexa
1247 //================================================================================
1249 bool StdMeshers_HexaFromSkin_3D::Evaluate(SMESH_Mesh & aMesh,
1250 const TopoDS_Shape & aShape,
1251 MapShapeNbElems& aResMap)
1254 int nbBlocks = skin.findBlocks(aMesh);
1255 if ( nbBlocks == 0 )
1256 return error( skin.error());
1258 bool secondOrder = aMesh.NbFaces( ORDER_QUADRATIC );
1260 int entity = secondOrder ? SMDSEntity_Quad_Hexa : SMDSEntity_Hexa;
1261 vector<int>& nbByType = aResMap[ aMesh.GetSubMesh( aShape )];
1262 if ( entity >= (int) nbByType.size() )
1263 nbByType.resize( SMDSEntity_Last, 0 );
1265 for ( int i = 0; i < nbBlocks; ++i )
1267 const _Block& block = skin.getBlock( i );
1269 int nbX = block.getSide(B_BOTTOM).getHoriSize();
1270 int nbY = block.getSide(B_BOTTOM).getVertSize();
1271 int nbZ = block.getSide(B_FRONT ).getVertSize();
1273 int nbHexa = (nbX-1) * (nbY-1) * (nbZ-1);
1274 int nbNodes = (nbX-2) * (nbY-2) * (nbZ-2);
1277 (nbX-2) * (nbY-2) * (nbZ-1) +
1278 (nbX-2) * (nbY-1) * (nbZ-2) +
1279 (nbX-1) * (nbY-2) * (nbZ-2);
1282 nbByType[ entity ] += nbHexa;
1283 nbByType[ SMDSEntity_Node ] += nbNodes;
1289 //================================================================================
1291 * \brief Abstract method must be defined but does nothing
1293 //================================================================================
1295 bool StdMeshers_HexaFromSkin_3D::CheckHypothesis(SMESH_Mesh&, const TopoDS_Shape&,
1296 Hypothesis_Status& aStatus)
1298 aStatus = SMESH_Hypothesis::HYP_OK;
1302 //================================================================================
1304 * \brief Abstract method must be defined but just reports an error as this
1305 * algo is not intended to work with shapes
1307 //================================================================================
1309 bool StdMeshers_HexaFromSkin_3D::Compute(SMESH_Mesh&, const TopoDS_Shape&)
1311 return error("Algorithm can't work with geometrical shapes");