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