SelectionByBox.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 
27 namespace mimmo{
28 
33  m_name = "mimmo.SelectionByBox";
35 };
36 
41 SelectionByBox::SelectionByBox(const bitpit::Config::Section & rootXML){
42 
43  m_name = "mimmo.SelectionByBox";
45 
46  std::string fallback_name = "ClassNONE";
47  std::string input = rootXML.get("ClassName", fallback_name);
48  input = bitpit::utils::string::trim(input);
49  if(input == "mimmo.SelectionByBox"){
50  absorbSectionXML(rootXML);
51  }else{
53  };
54 }
55 
63  m_name = "mimmo.SelectionByBox";
65  setGeometry(target);
66  setOrigin(origin);
67  setSpan(span[0],span[1],span[2]);
68 };
69 
74 
79 };
80 
85  swap(other);
86  return *this;
87 };
88 
95 {
97  Cube::swap(x);
98 }
99 
103 void
105 
107  bool built = m_arePortsBuilt;
108 
109  built = (built && createPortIn<darray3E, SelectionByBox>(this, &SelectionByBox::setOrigin, M_POINT ));
110  built = (built && createPortIn<darray3E, SelectionByBox>(this, &SelectionByBox::setSpan, M_SPAN));
111  built = (built && createPortIn<dmatrix33E, SelectionByBox>(this, &SelectionByBox::setRefSystem, M_AXES));
112 
113  m_arePortsBuilt = built;
114 };
115 
119 void
121  m_subpatch.reset();
123 };
124 
125 
126 
134  switch(m_topo){
135  case 3:
136  if(m_dual) return excludeCloudPoints(getGeometry());
137  else return includeCloudPoints(getGeometry());
138  break;
139  default:
140  if(m_dual) return excludeGeometry(getGeometry());
141  else return includeGeometry(getGeometry());
142  break;
143  }
144 };
145 
146 
152 void
153 SelectionByBox::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
154 
155  BITPIT_UNUSED(name);
156  BaseManipulation::absorbSectionXML(slotXML, name);
157 
158  if(slotXML.hasOption("Dual")){
159  std::string input = slotXML.get("Dual");
160  input = bitpit::utils::string::trim(input);
161  bool value = false;
162  if(!input.empty()){
163  std::stringstream ss(input);
164  ss >> value;
165  }
166  setDual(value);
167  }
168 
169  if(slotXML.hasOption("Origin")){
170  std::string input = slotXML.get("Origin");
171  input = bitpit::utils::string::trim(input);
172  darray3E temp = {{0.0,0.0,0.0}};
173  if(!input.empty()){
174  std::stringstream ss(input);
175  ss>>temp[0]>>temp[1]>>temp[2];
176  setOrigin(temp);
177  }else{
178  setOrigin(temp);
179  }
180  }
181 
182  if(slotXML.hasOption("Span")){
183  std::string input = slotXML.get("Span");
184  input = bitpit::utils::string::trim(input);
185  darray3E temp = {{1.0,1.0,1.0}};
186  if(!input.empty()){
187  std::stringstream ss(input);
188  ss>>temp[0]>>temp[1]>>temp[2];
189  setSpan(temp);
190  }else{
191  setSpan(temp);
192  }
193  }
194 
195  if(slotXML.hasSection("RefSystem")){
196 
197  const bitpit::Config::Section & axesXML = slotXML.getSection("RefSystem");
198  dmatrix33E axes;
199  for(int i=0; i<3; ++i){
200  axes[i].fill(0.0);
201  axes[i][i] = 1.0;
202  }
203 
204  if(axesXML.hasOption("axis0")){
205  std::string input = axesXML.get("axis0");
206  input = bitpit::utils::string::trim(input);
207  if(!input.empty()){
208  std::stringstream ss(input);
209  ss>>axes[0][0]>>axes[0][1]>>axes[0][2];
210  }
211  }
212 
213  if(axesXML.hasOption("axis1")){
214  std::string input = axesXML.get("axis1");
215  input = bitpit::utils::string::trim(input);
216  if(!input.empty()){
217  std::stringstream ss(input);
218  ss>>axes[1][0]>>axes[1][1]>>axes[1][2];
219  }
220  }
221 
222  if(axesXML.hasOption("axis2")){
223  std::string input = axesXML.get("axis2");
224  input = bitpit::utils::string::trim(input);
225  if(!input.empty()){
226  std::stringstream ss(input);
227  ss>>axes[2][0]>>axes[2][1]>>axes[2][2];
228  }
229  }
230 
231  setRefSystem(axes);
232  }
233 };
234 
240 void
241 SelectionByBox::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
242 
243  BITPIT_UNUSED(name);
244 
245  BaseManipulation::flushSectionXML(slotXML,name);
246 
247  int value = m_dual;
248  slotXML.set("Dual", std::to_string(value));
249 
250  {
251  darray3E org = getOrigin();
252  std::stringstream ss;
253  ss<<std::scientific<<org[0]<<'\t'<<org[1]<<'\t'<<org[2];
254  slotXML.set("Origin",ss.str());
255  }
256 
257  {
258  darray3E span = getSpan();
259  std::stringstream ss;
260  ss<<std::scientific<<span[0]<<'\t'<<span[1]<<'\t'<<span[2];
261  slotXML.set("Span",ss.str());
262  }
263 
264  {
265  dmatrix33E axes = getRefSystem();
266  bitpit::Config::Section & axesXML = slotXML.addSection("RefSystem");
267 
268  for(int i=0; i<3; ++i){
269  std::string name = "axis"+std::to_string(i);
270  std::stringstream ss;
271  ss<<std::scientific<<axes[i][0]<<'\t'<<axes[i][1]<<'\t'<<axes[i][2];
272  axesXML.set(name, ss.str());
273  }
274  }
275 
276 };
277 
278 }
Abstract Interface for selection classes.
livector1D includeGeometry(MimmoSharedPointer< MimmoObject >)
void setOrigin(darray3E)
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
std::vector< long > livector1D
mimmo::MimmoSharedPointer< MimmoObject > m_subpatch
#define M_POINT
void warningXML(bitpit::Logger *log, std::string name)
livector1D includeCloudPoints(const dvecarr3E &)
void swap(SelectionByBox &) noexcept
void setRefSystem(darray3E, darray3E, darray3E)
void swap(BasicShape &) noexcept
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
Elementary Shape Representation of a Cube.
std::array< darray3E, 3 > dmatrix33E
#define M_SPAN
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
#define M_AXES
darray3E getOrigin()
Selection through volume box primitive.
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
void swap(GenericSelection &x) noexcept
livector1D excludeGeometry(MimmoSharedPointer< MimmoObject >)
darray3E getSpan()
void setDual(bool flag=false)
std::array< double, 3 > darray3E
SelectionByBox & operator=(SelectionByBox other)
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()
livector1D extractSelection()