SelectionByCylinder.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 "MeshSelection.hpp"
26 #include <bitpit_common.hpp>
27 
28 namespace mimmo{
29 
34  m_name = "mimmo.SelectionByCylinder";
36 };
37 
42 SelectionByCylinder::SelectionByCylinder(const bitpit::Config::Section & rootXML){
43 
44  m_name = "mimmo.SelectionByCylinder";
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.SelectionByCylinder"){
51  absorbSectionXML(rootXML);
52  }else{
54  };
55 }
56 
66  m_name = "mimmo.SelectionByCylinder";
68  setGeometry(target);
69  setOrigin(origin);
70  setSpan(span[0],span[1],span[2]);
71  setInfLimits(infLimTheta,1);
72  setRefSystem(2, mainAxis);
73 };
74 
79 
84 };
85 
90  swap(other);
91  return *this;
92 };
93 
100 {
102  Cylinder::swap(x);
103 }
104 
108 void
110 
111 
113  bool built = m_arePortsBuilt;
114 
115  built = (built && createPortIn<darray3E, SelectionByCylinder>(this, &SelectionByCylinder::setOrigin,M_POINT));
116  built = (built && createPortIn<darray3E, SelectionByCylinder>(this, &SelectionByCylinder::setSpan, M_SPAN));
117  built = (built && createPortIn<dmatrix33E, SelectionByCylinder>(this, &SelectionByCylinder::setRefSystem, M_AXES));
118  built = (built && createPortIn<darray3E, SelectionByCylinder>(this, &SelectionByCylinder::setInfLimits, M_INFLIMITS));
119 
120  m_arePortsBuilt = built;
121 };
122 
126 void
128  m_subpatch.reset();
130 };
131 
139  switch(m_topo){
140  case 3:
141  if(m_dual) return excludeCloudPoints(getGeometry());
142  else return includeCloudPoints(getGeometry());
143  break;
144  default:
145  if(m_dual) return excludeGeometry(getGeometry());
146  else return includeGeometry(getGeometry());
147  break;
148  }
149 };
150 
151 
152 
158 void
159 SelectionByCylinder::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
160 
161  BITPIT_UNUSED(name);
162 
163  BaseManipulation::absorbSectionXML(slotXML, name);
164 
165  if(slotXML.hasOption("Dual")){
166  std::string input = slotXML.get("Dual");
167  input = bitpit::utils::string::trim(input);
168  bool value = false;
169  if(!input.empty()){
170  std::stringstream ss(input);
171  ss >> value;
172  }
173  setDual(value);
174  }
175 
176  if(slotXML.hasOption("Origin")){
177  std::string input = slotXML.get("Origin");
178  input = bitpit::utils::string::trim(input);
179  darray3E temp = {{0.0,0.0,0.0}};
180  if(!input.empty()){
181  std::stringstream ss(input);
182  ss>>temp[0]>>temp[1]>>temp[2];
183  setOrigin(temp);
184  }else{
185  setOrigin(temp);
186  }
187  }
188 
189  if(slotXML.hasOption("Span")){
190  std::string input = slotXML.get("Span");
191  input = bitpit::utils::string::trim(input);
192  darray3E temp = {{1.0,2.0*BITPIT_PI,1.0}};
193  if(!input.empty()){
194  std::stringstream ss(input);
195  ss>>temp[0]>>temp[1]>>temp[2];
196  setSpan(temp);
197  }else{
198  setSpan(temp);
199  }
200  }
201 
202  if(slotXML.hasSection("RefSystem")){
203 
204  const bitpit::Config::Section & axesXML = slotXML.getSection("RefSystem");
205  dmatrix33E axes;
206  for(int i=0; i<3; ++i){
207  axes[i].fill(0.0);
208  axes[i][i] = 1.0;
209  }
210 
211  if(axesXML.hasOption("axis0")){
212  std::string input = axesXML.get("axis0");
213  input = bitpit::utils::string::trim(input);
214  if(!input.empty()){
215  std::stringstream ss(input);
216  ss>>axes[0][0]>>axes[0][1]>>axes[0][2];
217  }
218  }
219 
220  if(axesXML.hasOption("axis1")){
221  std::string input = axesXML.get("axis1");
222  input = bitpit::utils::string::trim(input);
223  if(!input.empty()){
224  std::stringstream ss(input);
225  ss>>axes[1][0]>>axes[1][1]>>axes[1][2];
226  }
227  }
228 
229  if(axesXML.hasOption("axis2")){
230  std::string input = axesXML.get("axis2");
231  input = bitpit::utils::string::trim(input);
232  if(!input.empty()){
233  std::stringstream ss(input);
234  ss>>axes[2][0]>>axes[2][1]>>axes[2][2];
235  }
236  }
237  setRefSystem(axes);
238  }
239 
240  if(slotXML.hasOption("InfLimits")){
241  std::string input = slotXML.get("InfLimits");
242  input = bitpit::utils::string::trim(input);
243  darray3E temp = {{0.0,0.0,0.0}};
244  if(!input.empty()){
245  std::stringstream ss(input);
246  ss>>temp[0]>>temp[1]>>temp[2];
247  setInfLimits(temp);
248  }else{
249  setInfLimits(temp);
250  }
251  }
252 
253 };
254 
260 void
261 SelectionByCylinder::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
262 
263  BITPIT_UNUSED(name);
264 
265  BaseManipulation::flushSectionXML(slotXML, name);
266 
267  int value = m_dual;
268  slotXML.set("Dual", std::to_string(value));
269 
270 
271  {
272  darray3E org = getOrigin();
273  std::stringstream ss;
274  ss<<std::scientific<<org[0]<<'\t'<<org[1]<<'\t'<<org[2];
275  slotXML.set("Origin",ss.str());
276  }
277 
278  {
279  darray3E span = getSpan();
280  std::stringstream ss;
281  ss<<std::scientific<<span[0]<<'\t'<<span[1]<<'\t'<<span[2];
282  slotXML.set("Span",ss.str());
283  }
284 
285  {
286  dmatrix33E axes = getRefSystem();
287  bitpit::Config::Section & axesXML = slotXML.addSection("RefSystem");
288 
289  for(int i=0; i<3; ++i){
290  std::string name = "axis"+std::to_string(i);
291  std::stringstream ss;
292  ss<<std::scientific<<axes[i][0]<<'\t'<<axes[i][1]<<'\t'<<axes[i][2];
293  axesXML.set(name, ss.str());
294  }
295  }
296 
297  {
298  darray3E inflim = getInfLimits();
299  std::stringstream ss;
300  ss<<std::scientific<<inflim[0]<<'\t'<<inflim[1]<<'\t'<<inflim[2];
301  slotXML.set("InfLimits",ss.str());
302  }
303 
304 };
305 
306 }
darray3E getInfLimits()
Abstract Interface for selection classes.
livector1D includeGeometry(MimmoSharedPointer< MimmoObject >)
void setOrigin(darray3E)
void setInfLimits(double val, int dir)
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
std::vector< long > livector1D
mimmo::MimmoSharedPointer< MimmoObject > m_subpatch
#define M_POINT
Elementary Shape Representation of a Cylinder or portion of it.
void warningXML(bitpit::Logger *log, std::string name)
livector1D includeCloudPoints(const dvecarr3E &)
#define M_INFLIMITS
Selection through cylinder primitive.
void setRefSystem(darray3E, darray3E, darray3E)
void swap(BasicShape &) noexcept
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
std::array< darray3E, 3 > dmatrix33E
#define M_SPAN
#define M_AXES
darray3E getOrigin()
void swap(SelectionByCylinder &) noexcept
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
void swap(GenericSelection &x) noexcept
livector1D excludeGeometry(MimmoSharedPointer< MimmoObject >)
darray3E getSpan()
SelectionByCylinder & operator=(SelectionByCylinder other)
void setDual(bool flag=false)
std::array< double, 3 > darray3E
dmatrix33E getRefSystem()
virtual void setGeometry(mimmo::MimmoSharedPointer< MimmoObject >)
void setSpan(double, double, double)
MimmoSharedPointer is a custom implementation of shared pointer.
livector1D excludeCloudPoints(const dvecarr3E &)
MimmoSharedPointer< MimmoObject > getGeometry()
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")