131 typedef std::vector< RegionMarker > RegionMarkerList;
132 typedef RVector3 HoleMarker;
133 typedef PosVector HoleMarkerList;
147 Mesh & operator = (
const Mesh & mesh);
165 void setGeometry(
bool b);
171 void geometryChanged();
180 uint
dim()
const {
return dimension_; }
183 Node * createNode(
double x,
double y,
double z,
int marker=0);
184 Node * createNode(
const Node & node);
185 Node * createNode(
const RVector3 & pos,
int marker=0);
190 Node * createSecondaryNode(
const RVector3 & pos,
double tol=-1);
194 Node * createNodeWithCheck(
const RVector3 & pos,
double tol=1e-6,
195 bool warn=
false,
bool edgeCheck=
false);
197 Boundary * createBoundary(std::vector < Node * > & nodes,
int marker=0,
bool check=
true);
199 Boundary * createBoundary(
const IndexArray & nodes,
int marker=0,
bool check=
true);
201 Boundary * createBoundary(
const Cell & cell,
bool check=
true);
202 Boundary * createNodeBoundary(
Node & n1,
int marker=0,
bool check=
true);
207 Boundary * createPolygonFace(std::vector < Node * > & nodes,
int marker,
bool check=
true);
210 Cell * createCell(
int marker=0);
211 Cell * createCell(std::vector < Node * > & nodes,
int marker=0);
213 Cell * createCell(
const IndexArray & nodes,
int marker=0);
214 Cell * createCell(
const Cell & cell);
223 Cell * copyCell(
const Cell & cell,
double tol=1e-6);
228 Boundary * copyBoundary(
const Boundary & bound,
double tol=1e-6,
bool check=
true);
230 void create1DGrid(
const RVector &
x);
234 void create2DGrid(
const RVector &
x,
const RVector &
y,
int markerType=0,
235 bool worldBoundaryMarker=
false);
240 void create3DGrid(
const RVector &
x,
const RVector &
y,
const RVector &
z,
241 int markerType=0,
bool worldBoundaryMarker=
false);
251 int markerType=0,
bool worldBoundaryMarker=
false) {
258 int markerType=0,
bool worldBoundaryMarker=
false){
262 void createHull_(
const Mesh & mesh);
266 Mesh createHull()
const;
269 Mesh createH2()
const;
272 Mesh createP2()
const;
275 void createMeshByCells(
const Mesh & mesh,
const std::vector < Cell * > & cells);
278 void createMeshByBoundaries(
const Mesh & mesh,
const std::vector < Boundary * > & bounds);
281 Mesh createMeshByCellIdx(
const IndexArray & idxList);
284 void createMeshByCellIdx(
const Mesh & mesh,
const IndexArray & idxList);
288 void createMeshByMarker(
const Mesh & mesh,
int from,
int to=-1);
291 Mesh createSubMesh(
const std::vector< Cell * > & cells)
const;
294 Mesh createSubMesh(
const std::vector< Boundary * > & bounds)
const;
298 Mesh createSubMesh(
const std::vector< Node * > & nodes)
const;
305 const std::vector< Node * > & nodes()
const {
return nodeVector_; }
307 const std::vector< Cell * > & cells()
const {
return cellVector_; }
310 const std::vector< Boundary * > &
boundaries()
const {
return boundaryVector_; }
313 std::vector< Node * > nodes(
const IndexArray & ids)
const;
316 std::vector< Node * > nodes(
const BVector & b)
const;
319 std::vector< Cell * > cells(
const IndexArray & ids)
const;
322 std::vector< Cell * > cells(
const BVector & b)
const;
325 std::vector< Boundary * > boundaries(
const IndexArray & ids)
const;
328 std::vector< Boundary * > boundaries(
const BVector & b)
const;
330 Index nodeCount(
bool withSecNodes=
false)
const;
331 Node & node(Index i)
const;
332 Node & node(Index i);
334 inline Index secondaryNodeCount()
const {
return secNodeVector_.size(); }
335 Node & secondaryNode(Index
id)
const;
336 Node & secondaryNode(Index
id);
339 IndexArray nodeIDs(
bool withSecNodes=
false)
const;
343 void setNodeIDs(IndexArray & ids);
345 Index cellCount()
const {
return cellVector_.size(); }
346 Cell & cell(Index i)
const;
347 Cell & cell(Index i);
349 Index boundaryCount()
const {
return boundaryVector_.size(); }
350 Boundary & boundary(Index i)
const;
351 Boundary & boundary(Index i);
354 PosVector positions(
bool withSecNodes=
false)
const;
357 PosVector positions(
const IndexArray & idx)
const;
360 PosVector cellCenters()
const;
361 PosVector cellCenter()
const {
return cellCenters(); }
364 PosVector boundaryCenters()
const;
367 RVector & cellSizes()
const;
370 RVector & boundarySizes()
const;
378 PosVector & boundarySizedNormals()
const;
381 void setBoundaryMarkers(
const IndexArray & ids,
int marker);
384 void setBoundaryMarkers(
const IVector & marker);
387 IVector boundaryMarkers()
const;
390 IVector nodeMarkers()
const;
393 IndexArray findNodesIdxByMarker(
int marker)
const;
399 std::vector < Boundary * > findBoundaryByMarker(
int marker)
const;
403 std::vector < Boundary * > findBoundaryByMarker(
int from,
int to)
const;
408 Cell * findCell(
const RVector3 & pos,
size_t & counter,
bool extensive)
const ;
412 size_t counter;
return findCell(pos, counter, extensive); }
415 Index findNearestNode(
const RVector3 & pos);
419 std::vector < Cell * > findCellByMarker(
int from,
int to=0)
const;
423 std::vector < Cell * > findCellByAttribute(
double from,
double to=0.0)
const;
430 std::vector < Cell * > findCellsAlongRay(
const RVector3 & start,
431 const RVector3 & dir,
432 PosVector & pos)
const;
444 void prolongateEmptyCellsValues(RVector & vals,
double background=-9e99)
const;
448 void sortNodes(
const IndexArray & perm);
454 void cleanNeighborInfos();
457 void createNeighborInfos(
bool force=
false);
460 void createNeighborInfosCell_(
Cell *c);
465 void smooth(
bool nodeMoving=
true,
bool edgeSwapping=
true, uint smoothFunction=1, uint smoothIteration=10);
469 Mesh & scale(
const RVector3 & s);
477 Mesh & translate(
const RVector3 & t);
482 Mesh & rotate(
const RVector3 & r);
486 Mesh & transform(
const RMatrix & mat);
490 Mesh & deform(
const R3Vector & eps,
double magnify=1.0);
495 Mesh & deform(
const RVector & eps,
double magnify=1.0);
499 void swapCoordinates(Index i, Index j);
503 int save(
const std::string & fileName,
IOFormat format = Binary)
const;
504 int saveAscii(
const std::string & fileName)
const;
509 int saveBinary(
const std::string & fileName)
const;
514 void load(
const std::string & fileName,
515 bool createNeighbors=
true,
IOFormat format=Binary);
517 void loadAscii(
const std::string & fileName);
519 void importMod(
const std::string & fileName);
521 void importVTK(
const std::string & fbody);
523 void importVTU(
const std::string & fbody);
527 void importSTL(
const std::string & fileName,
bool isBinary=
false,
532 void loadBinary(
const std::string & fileName);
538 void saveBinaryV2(
const std::string & fbody)
const;
542 void loadBinaryV2(
const std::string & fbody);
544 int exportSimple(
const std::string & fbody,
const RVector & data)
const ;
551 int exportMidCellValue(
const std::string & fileName,
const RVector & data1,
const RVector & data2)
const ;
553 int exportMidCellValue(
const std::string & fileName,
const RVector & data1)
const{
555 return exportMidCellValue(fileName, data1, data2);
558 void exportVTK(
const std::string & fbody,
559 const std::map< std::string, RVector > & data,
560 const PosVector & vec,
561 bool writeCells=
true)
const;
563 void exportVTK(
const std::string & fbody,
564 const std::map< std::string, RVector > & data,
565 bool writeCells=
true)
const;
568 void exportVTK(
const std::string & fbody,
bool writeCells=
true)
const;
571 void exportVTK(
const std::string & fbody,
572 const PosVector & vec,
573 bool writeCells=
true)
const;
576 void exportVTK(
const std::string & fbody,
const RVector & arr)
const;
578 void readVTKPoints_(std::fstream & file,
const std::vector < std::string > & row);
579 void readVTKCells_(std::fstream & file,
const std::vector < std::string > & row);
580 void readVTKScalars_(std::fstream & file,
const std::vector < std::string > & row);
581 void readVTKPolygons_(std::fstream & file,
const std::vector < std::string > & row);
588 void exportVTU(
const std::string & filename,
bool binary =
false)
const ;
591 void exportBoundaryVTU(
const std::string & fbody,
bool binary =
false)
const ;
594 void addVTUPiece_(std::fstream & file,
const Mesh & mesh,
595 const std::map < std::string, RVector > & data)
const;
597 void exportAsTetgenPolyFile(
const std::string & filename);
601 void fixBoundaryDirections();
603 void addData(
const std::string & name,
const CVector & data){
604 this->addData(name+
"_Re", real(data));
605 this->addData(name+
"_Im", imag(data));
612 void addData(
const std::string & name,
const RVector & data);
619 this->addData(name+
"_x",
x(
data));
620 this->addData(name+
"_y",
y(
data));
621 this->addData(name+
"_z",
z(
data));
626 RVector data(
const std::string & name)
const;
630 return dataMap_.count(name) > 0;
634 const std::map< std::string, RVector > &
dataMap()
const {
635 return this->dataMap_;
642 void dataInfo()
const;
653 void mapCellAttributes(
const std::map < float, float > & aMap);
657 void mapBoundaryMarker(
const std::map < int, int > & aMap);
660 void setCellAttributes(
const RVector & attribute);
663 void setCellAttributes(
double attribute);
666 RVector cellAttributes()
const;
669 void setCellMarkers(
const IndexArray & ids,
int marker);
672 void setCellMarkers(
const IVector & marker);
675 void setCellMarkers(
const RVector & attribute);
678 IVector cellMarkers()
const;
689 double xMin()
const { findRange_();
return minRange_[0]; }
690 double yMin()
const { findRange_();
return minRange_[1]; }
691 double zMin()
const { findRange_();
return minRange_[2]; }
692 double xMax()
const { findRange_();
return maxRange_[0]; }
693 double yMax()
const { findRange_();
return maxRange_[1]; }
694 double zMax()
const { findRange_();
return maxRange_[2]; }
697 const BoundingBox boundingBox()
const { findRange_();
return BoundingBox(minRange_, maxRange_);}
703 RSparseMapMatrix interpolationMatrix(
const PosVector & q);
706 void interpolationMatrix(
const PosVector & q, RSparseMapMatrix & I);
709 RSparseMapMatrix & cellToBoundaryInterpolation()
const;
718 RVector divergence(
const PosVector & V)
const;
721 PosVector boundaryDataToCellGradient(
const RVector & boundaryData)
const;
724 PosVector cellDataToBoundaryGradient(
const RVector & cellData)
const;
727 PosVector cellDataToBoundaryGradient(
const RVector & cellData,
728 const PosVector & cellGradient)
const;
732 void addRegionMarker(
const RVector3 & pos,
int marker,
double area=0);
733 void addRegionMarker(
const RegionMarker & reg);
735 const RegionMarkerList & regionMarkers()
const {
return regionMarker_; }
739 RegionMarker * regionMarker(SIndex i);
743 void addHoleMarker(
const RVector3 & pos);
746 const HoleMarkerList &
holeMarker()
const {
return holeMarker_; }
751 void copy_(
const Mesh & mesh);
753 void findRange_()
const ;
756 Node * createNodeGC_(
const RVector3 & pos,
int marker);
758 Node * createNode_(
const RVector3 & pos,
int marker);
760 Node * createSecondaryNode_(
const RVector3 & pos);
762 template <
class B >
Boundary * createBoundary_(
763 std::vector < Node * > & nodes,
int marker,
int id){
765 if (
id == -1)
id = boundaryCount();
766 boundaryVector_.push_back(
new B(nodes));
767 boundaryVector_.back()->setMarker(marker);
768 boundaryVector_.back()->setId(
id);
769 return boundaryVector_.back();
772 template <
class B > Boundary * createBoundaryChecked_(
773 std::vector < Node * > & nodes,
int marker,
bool check=
true){
775 if (!check)
return createBoundary_< B >(nodes, marker, boundaryCount());
777 Boundary * b = findBoundary(nodes);
779 b = createBoundary_< B >(nodes, marker, boundaryCount());
781 if (marker != 0) b->setMarker(marker);
786 template <
class C > Cell * createCell_(
787 std::vector < Node * > & nodes,
int marker,
int id){
789 if (
id == -1)
id = cellCount();
790 cellVector_.push_back(
new C(nodes));
791 cellVector_.back()->setMarker(marker);
792 cellVector_.back()->setId(
id);
793 return cellVector_.back();
797 Node * createRefinementNode_(Node * n0, Node * n1, std::map< std::pair < Index, Index >, Node * > & nodeMatrix);
799 void createRefined_(
const Mesh & mesh,
bool p2,
bool r2);
801 Cell * findCellBySlopeSearch_(
const RVector3 & pos, Cell * start,
size_t & count,
bool tagging)
const;
803 void fillKDTree_()
const;
805 std::vector< Node * > nodeVector_;
806 std::vector< Node * > secNodeVector_;
807 std::vector< Boundary * > boundaryVector_;
808 std::vector< Cell * > cellVector_;
812 mutable RVector3 minRange_;
813 mutable RVector3 maxRange_;
814 mutable bool rangesKnown_;
816 bool neighborsKnown_;
818 mutable KDTreeWrapper * tree_;
823 mutable RVector cellSizesCache_;
824 mutable RVector boundarySizesCache_;
825 mutable PosVector boundarySizedNormCache_;
827 mutable RSparseMapMatrix * cellToBoundaryInterpolationCache_;
829 bool oldTet10NumberingStyle_;
831 std::map< std::string, RVector > dataMap_;
832 std::string commentString_;
835 RegionMarkerList regionMarker_;
836 HoleMarkerList holeMarker_;