MeshSelection.hpp
1 /*---------------------------------------------------------------------------*\
2  *
3  * mimmo
4  *
5  * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6  *
7  * -------------------------------------------------------------------------
8  * License
9  * This file is part of mimmo.
10  *
11  * mimmo is free software: you can redistribute it and/or modify it
12  * under the terms of the GNU Lesser General Public License v3 (LGPL)
13  * as published by the Free Software Foundation.
14  *
15  * mimmo is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with mimmo. If not, see <http://www.gnu.org/licenses/>.
22  *
23  \ *---------------------------------------------------------------------------*/
24 
25 #ifndef __MESHSELECTION_HPP__
26 #define __MESHSELECTION_HPP__
27 
28 #include <BaseManipulation.hpp>
29 #include <BasicShapes.hpp>
30 
31 #include <memory>
32 #include <unordered_map>
33 #include <unordered_set>
34 #include <utility>
35 
36 namespace mimmo{
37 
43 enum class SelectionType{
44  UNDEFINED = 0,
45  BOX = 1,
46  CYLINDER = 2,
47  SPHERE = 3,
48  MAPPING = 4,
49  PID = 5,
50  BOXwSCALAR = 11
51 };
52 
81 
82 protected:
83 
86  int m_topo;
87  bool m_dual;
88 public:
89 
91  virtual ~GenericSelection();
92  GenericSelection(const GenericSelection & other);
94 
95  void buildPorts();
96 
99  void setDual(bool flag=false);
100 
103  bool isDual();
104 
106 
107  void execute();
108 
109  virtual void plotOptionalResults();
110 
111 protected:
115  virtual livector1D extractSelection() = 0;
116  void swap(GenericSelection &x) noexcept;
117 };
118 
119 
185 
186 public:
187  SelectionByBox();
188  SelectionByBox(const bitpit::Config::Section & rootXML);
190  virtual ~SelectionByBox();
191  SelectionByBox(const SelectionByBox & other);
193 
194  void buildPorts();
195 
196  void clear();
197 
198  virtual void absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name="" );
199  virtual void flushSectionXML(bitpit::Config::Section & slotXML, std::string name="" );
200 
201 protected:
203  void swap(SelectionByBox &) noexcept;
204 };
205 
273 
274 public:
276  SelectionByCylinder(const bitpit::Config::Section & rootXML);
277  SelectionByCylinder(darray3E origin, darray3E span, double infLimTheta, darray3E mainAxis, mimmo::MimmoSharedPointer<MimmoObject> target);
278  virtual ~SelectionByCylinder();
281 
282  void buildPorts();
283 
284  void clear();
285 
286  virtual void absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name="" );
287  virtual void flushSectionXML(bitpit::Config::Section & slotXML, std::string name="" );
288 
289 protected:
291  void swap(SelectionByCylinder &) noexcept;
292 };
293 
364 
365 public:
367  SelectionBySphere(const bitpit::Config::Section & rootXML);
368  SelectionBySphere(darray3E origin, darray3E span, double infLimTheta, double infLimPhi, mimmo::MimmoSharedPointer<MimmoObject> target);
369  virtual ~SelectionBySphere();
370  SelectionBySphere(const SelectionBySphere & other);
372 
373  void buildPorts();
374 
375  void clear();
376 
377  virtual void absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name="" );
378  virtual void flushSectionXML(bitpit::Config::Section & slotXML, std::string name="" );
379 
380 protected:
382  void swap(SelectionBySphere &) noexcept;
383 };
384 
459 
460 private:
461  double m_tolerance;
462  std::unordered_map<std::string, int> m_geolist;
463  std::unordered_set<mimmo::MimmoSharedPointer<MimmoObject>> m_mimmolist;
464  std::vector<std::set< int > > m_allowedType;
465  std::vector<std::set< int > > m_allowedTopology;
467 public:
468  SelectionByMapping(int topo = 1);
469  SelectionByMapping(const bitpit::Config::Section & rootXML);
470  SelectionByMapping(std::unordered_map<std::string, int> & geolist, mimmo::MimmoSharedPointer<MimmoObject> target, double tolerance);
471  virtual ~SelectionByMapping();
472  SelectionByMapping(const SelectionByMapping & other);
474 
475  void buildPorts();
476 
477  double getTolerance();
478  void setTolerance(double tol=1.e-8);
479 
481 
482  const std::unordered_map<std::string, int> & getFiles() const;
483  void setFiles(std::unordered_map<std::string,int> );
484  void addFile(std::pair<std::string,int> );
485  void removeFile(std::string);
486  void removeFiles();
489 
490  void clear();
491 
492  virtual void absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name="" );
493  virtual void flushSectionXML(bitpit::Config::Section & slotXML, std::string name="" );
494 
495 protected:
497  void swap(SelectionByMapping &) noexcept;
498 
499 private:
500  livector1D getProximity(std::pair<std::string, int> val);
502  svector1D extractInfo(std::string);
503 };
504 
564 
565 private:
566  std::unordered_set<long> m_setPID;
567  std::unordered_map<long,bool> m_activePID;
569 public:
570  SelectionByPID();
571  SelectionByPID(const bitpit::Config::Section & rootXML);
573  virtual ~SelectionByPID();
574  SelectionByPID(const SelectionByPID & other);
576 
577  void buildPorts();
578 
579  livector1D getPID();
580  livector1D getActivePID(bool active= true);
581 
583  void setPID(long i = -1);
584  void setPID(livector1D);
585 
586  void removePID(long i = -1);
587  void removePID(livector1D);
588 
589  void syncPIDList();
590  void clear();
591 
592  virtual void absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name="" );
593  virtual void flushSectionXML(bitpit::Config::Section & slotXML, std::string name="" );
594 
595 protected:
597  void swap(SelectionByPID &) noexcept;
598 
599 };
600 
679 protected:
684 public:
686  SelectionByBoxWithScalar(const bitpit::Config::Section & rootXML);
688  virtual ~SelectionByBoxWithScalar();
691 
692  void buildPorts();
693 
694  void clear();
695 
696  void setField(dmpvector1D *);
697  dmpvector1D * getField();
698 
699  void execute();
700 
701  virtual void absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name="" );
702  virtual void flushSectionXML(bitpit::Config::Section & slotXML, std::string name="" );
703 
704  void plotOptionalResults();
705 protected:
706  void swap(SelectionByBoxWithScalar &) noexcept;
707 
708 };
709 
770 
771 public:
773  SelectionByElementList(const bitpit::Config::Section & rootXML);
774  virtual ~SelectionByElementList();
775 
776  void buildPorts();
779  void addRawCellList(std::vector<long> celldata);
780  void addRawVertexList(std::vector<long> vertexdata);
781 
782  void clear();
783 
784  virtual void absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name="" );
785  virtual void flushSectionXML(bitpit::Config::Section & slotXML, std::string name="" );
786 
787 protected:
788 
789  std::vector<MimmoPiercedVector<long> *> m_annotatedcells;
790  std::vector<MimmoPiercedVector<long> *> m_annotatedvertices;
791  std::vector<std::vector<long>> m_rawcells;
792  std::vector<std::vector<long>> m_rawvertices;
795  void swap(SelectionByElementList &) noexcept;
796 };
797 
798 
799 
800 
801 
802 
803 REGISTER_PORT(M_GEOM, MC_SCALAR, MD_MIMMO_, __MESHSELECTION_HPP__)
804 REGISTER_PORT(M_VALUEB, MC_SCALAR, MD_BOOL, __MESHSELECTION_HPP__)
805 REGISTER_PORT(M_VECTORLI, MC_VECTOR, MD_LONG, __MESHSELECTION_HPP__)
806 REGISTER_PORT(M_VECTORLI2, MC_VECTOR, MD_LONG, __MESHSELECTION_HPP__)
807 REGISTER_PORT(M_VECTORLI3, MC_VECTOR, MD_LONG, __MESHSELECTION_HPP__)
808 REGISTER_PORT(M_POINT, MC_ARRAY3, MD_FLOAT, __MESHSELECTION_HPP__)
809 REGISTER_PORT(M_AXES, MC_ARR3ARR3, MD_FLOAT, __MESHSELECTION_HPP__)
810 REGISTER_PORT(M_SPAN, MC_ARRAY3, MD_FLOAT, __MESHSELECTION_HPP__)
811 REGISTER_PORT(M_INFLIMITS, MC_ARRAY3, MD_FLOAT, __MESHSELECTION_HPP__)
812 REGISTER_PORT(M_GEOM2, MC_SCALAR, MD_MIMMO_, __MESHSELECTION_HPP__)
813 REGISTER_PORT(M_VALUELI, MC_SCALAR, MD_LONG, __MESHSELECTION_HPP__)
814 REGISTER_PORT(M_SCALARFIELD, MC_SCALAR, MD_MPVECFLOAT_, __MESHSELECTION_HPP__)
815 REGISTER_PORT(M_LONGFIELD, MC_SCALAR, MD_MPVECLONG_, __MESHSELECTION_HPP__)
816 REGISTER_PORT(M_LONGFIELD2, MC_SCALAR, MD_MPVECLONG_, __MESHSELECTION_HPP__)
817 
818 
819 REGISTER(BaseManipulation, SelectionByBox,"mimmo.SelectionByBox")
826 
827 };
828 
829 
830 #endif /* __MESHSELECTION_HPP__ */
Abstract Interface for selection classes.
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
void setPID(long i=-1)
void setTolerance(double tol=1.e-8)
livector1D extractSelection()
#define M_LONGFIELD
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
void addRawVertexList(std::vector< long > vertexdata)
void removePID(long i=-1)
void setGeometry(mimmo::MimmoSharedPointer< MimmoObject > geometry)
void addFile(std::pair< std::string, int >)
#define M_GEOM
SelectionByPID & operator=(SelectionByPID other)
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
std::vector< std::string > svector1D
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
#define MC_ARRAY3
#define MD_FLOAT
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
void swap(SelectionByMapping &) noexcept
Selection through list of cells/vertices of the target mesh.
const std::unordered_map< std::string, int > & getFiles() const
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
std::vector< long > livector1D
#define M_VECTORLI3
#define M_GEOM2
#define MC_ARR3ARR3
mimmo::MimmoSharedPointer< MimmoObject > m_subpatch
Elementary Shape Representation of a Sphere or portion of it.
#define M_POINT
#define M_LONGFIELD2
std::vector< MimmoPiercedVector< long > * > m_annotatedvertices
Elementary Shape Representation of a Cylinder or portion of it.
SelectionType
Enum class for choiche of method to select sub-patch of a MimmoObject tessellated mesh.
Selection mapping external surfaces/volume/3D curves on a target mesh of the same topology.
std::vector< MimmoPiercedVector< long > * > m_annotatedcells
BaseManipulation is the base class of any manipulation object of the library.
void swap(SelectionByBox &) noexcept
livector1D getActivePID(bool active=true)
#define M_INFLIMITS
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
#define MC_SCALAR
SelectionByMapping & operator=(SelectionByMapping other)
void swap(SelectionByElementList &) noexcept
Selection through cylinder primitive.
void setFiles(std::unordered_map< std::string, int >)
#define REGISTER_PORT(Name, Container, Datatype, ManipBlock)
Elementary Shape Representation of a Cube.
void swap(SelectionByPID &) noexcept
Selection using target mesh Part Identifiers.
#define MD_LONG
Selection through sphere primitive.
#define M_SPAN
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
#define M_AXES
void swap(SelectionByCylinder &) noexcept
Selection through volume box primitive.
#define MC_VECTOR
#define MD_BOOL
void addMappingGeometry(mimmo::MimmoSharedPointer< MimmoObject > obj)
void swap(GenericSelection &x) noexcept
Selection through volume box primitive.
void addAnnotatedVertexList(MimmoPiercedVector< long > *vertexdata)
#define M_VALUELI
const mimmo::MimmoSharedPointer< MimmoObject > getPatch() const
virtual void plotOptionalResults()
void addAnnotatedCellList(MimmoPiercedVector< long > *celldata)
#define M_VECTORLI2
#define MD_MIMMO_
SelectionBySphere & operator=(SelectionBySphere other)
std::vector< std::vector< long > > m_rawvertices
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
SelectionByCylinder & operator=(SelectionByCylinder other)
#define MD_MPVECFLOAT_
#define M_SCALARFIELD
void setDual(bool flag=false)
std::array< double, 3 > darray3E
std::vector< std::vector< long > > m_rawcells
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
SelectionByBox & operator=(SelectionByBox other)
void swap(SelectionByBoxWithScalar &) noexcept
SelectionByBoxWithScalar & operator=(SelectionByBoxWithScalar other)
void setGeometry(mimmo::MimmoSharedPointer< MimmoObject >)
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
virtual void setGeometry(mimmo::MimmoSharedPointer< MimmoObject >)
GenericSelection & operator=(const GenericSelection &other)
MimmoSharedPointer is a custom implementation of shared pointer.
virtual livector1D extractSelection()=0
void swap(SelectionBySphere &) noexcept
#define MD_MPVECLONG_
livector1D extractSelection()
void addRawCellList(std::vector< long > celldata)
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
#define M_VALUEB
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
#define M_VECTORLI
#define REGISTER(Base, Derived, name)
Definition: factory.hpp:206