SurfaceTriangulator.cpp
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 #include "SurfaceTriangulator.hpp"
26 
27 namespace mimmo{
28 
33  m_name = "mimmo.SurfaceTriangulator";
34  m_workOnTarget = false;
35 
36 };
37 
42 SurfaceTriangulator::SurfaceTriangulator(const bitpit::Config::Section & rootXML){
43 
44  m_name = "mimmo.SurfaceTriangulator";
45  m_workOnTarget = false;
46 
47  std::string fallback_name = "ClassNONE";
48  std::string input = rootXML.get("ClassName", fallback_name);
49  input = bitpit::utils::string::trim(input);
50  if(input == "mimmo.SurfaceTriangulator"){
51  absorbSectionXML(rootXML);
52  }else{
54  };
55 }
56 
61 
66  m_workOnTarget = other.m_workOnTarget;
67 };
68 
73  swap(other);
74  return *this;
75 };
76 
82 {
83  std::swap(m_workOnTarget, x.m_workOnTarget);
84  std::swap(m_intPatch, x.m_intPatch);
86 }
87 
92 
93  bool built = true;
94  built = (built && createPortIn<mimmo::MimmoSharedPointer<MimmoObject>, SurfaceTriangulator>(this, &mimmo::SurfaceTriangulator::setGeometry,M_GEOM, true));
95  built = (built && createPortOut<mimmo::MimmoSharedPointer<MimmoObject>, SurfaceTriangulator>(this, &mimmo::SurfaceTriangulator::getGeometry, M_GEOM));
96  m_arePortsBuilt = built;
97 };
98 
99 
104  if(m_workOnTarget) return BaseManipulation::getGeometry();
105  else return m_intPatch;
106 };
107 
113  return m_workOnTarget;
114 };
115 
122  if(!geo) return;
124 };
125 
133  m_workOnTarget = flag;
134 };
135 
140 
142 
143  if (target == nullptr){
144  throw std::runtime_error (m_name + " : nullptr pointer to linked geometry");
145  }
146 
147  if(!m_workOnTarget){
148  //create internal patch as clone of the linked geometry and set target pointing to it
149  m_intPatch = mimmo::MimmoSharedPointer<MimmoObject>(target->clone());
150  target = m_intPatch;
151  }
152 
153  target->triangulate();
154 };
155 
160 
161  write(getGeometry());
162 
163 }
164 
170 void SurfaceTriangulator::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
171 
172  BITPIT_UNUSED(name);
173 
174  //start absorbing
175  BaseManipulation::absorbSectionXML(slotXML, name);
176 
177  if(slotXML.hasOption("WorkOnTarget")){
178  std::string input = slotXML.get("WorkOnTarget");
179  input = bitpit::utils::string::trim(input);
180  bool value = false;
181  if(!input.empty()){
182  std::stringstream ss(input);
183  ss >> value;
184  }
185  setWorkOnTarget(value);
186  }
187 
188 };
189 
195 void SurfaceTriangulator::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
196 
197  BITPIT_UNUSED(name);
198 
199  BaseManipulation::flushSectionXML(slotXML,name);
200  slotXML.set("WorkOnTarget", std::to_string(int(m_workOnTarget)));
201 };
202 
203 }
#define M_GEOM
void swap(SurfaceTriangulator &x) noexcept
SurfaceTriangulator & operator=(SurfaceTriangulator other)
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
void warningXML(bitpit::Logger *log, std::string name)
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
BaseManipulation is the base class of any manipulation object of the library.
void write(MimmoSharedPointer< MimmoObject > geometry)
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
void setGeometry(mimmo::MimmoSharedPointer< MimmoObject > geo)
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
void setGeometry(MimmoSharedPointer< MimmoObject > geometry)
Triangulate a target MimmoObject non-homogeneous and/or non-triangular surface mesh.
void setWorkOnTarget(bool flag=false)
MimmoSharedPointer is a custom implementation of shared pointer.
MimmoSharedPointer< MimmoObject > getGeometry()
mimmo::MimmoSharedPointer< MimmoObject > getGeometry()
void swap(BaseManipulation &x) noexcept