SelectionByBoxWithScalar.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 "ExtractFields.hpp"
27 
28 namespace mimmo{
29 
34  m_name = "mimmo.SelectionByBoxWithScalar";
35 };
36 
41 SelectionByBoxWithScalar::SelectionByBoxWithScalar(const bitpit::Config::Section & rootXML){
42 
43  m_name = "mimmo.SelectionByBoxWithScalar";
44 
45  std::string fallback_name = "ClassNONE";
46  std::string input = rootXML.get("ClassName", fallback_name);
47  input = bitpit::utils::string::trim(input);
48  if(input == "mimmo.SelectionByBoxWithScalar"){
49  absorbSectionXML(rootXML);
50  }else{
52  };
53 }
54 
62  m_name = "mimmo.SelectionByBoxWithScalar";
64  setGeometry(target);
65  setOrigin(origin);
66  setSpan(span[0],span[1],span[2]);
67 };
68 
73 
78  m_field = other.m_field;
79 };
80 
85  swap(other);
86  return *this;
87 };
88 
95 {
96  m_field.swap(x.m_field);
98 
99 }
100 
104 void
106 
108  bool built = m_arePortsBuilt;
109 
110  built = (built && createPortIn<dmpvector1D*, SelectionByBoxWithScalar>(this, &SelectionByBoxWithScalar::setField, M_SCALARFIELD));
111  built = (built && createPortOut<dmpvector1D*, SelectionByBoxWithScalar>(this, &SelectionByBoxWithScalar::getField, M_SCALARFIELD));
112 
113  m_arePortsBuilt = built;
114 };
115 
119 void
121  m_field.clear();
123 };
124 
128 void
130  if(!field) return;
131  m_field = *field;
132 }
133 
137 dmpvector1D *
139  return &m_field;
140 }
141 
142 
150 void
152 
154 
155  //check m_field in input if coherent with the linked geometry
156  if(m_field.getGeometry() != getGeometry()) {
157  throw std::runtime_error(m_name+" : linked scalar field is not referred to target geometry");
158  }
159  if(getPatch()->getType()==3 && m_field.getDataLocation()!= MPVLocation::POINT){
160  (*m_log)<<"warning in "<<m_name<<" : Attempting to extract a non POINT located field on a Point Cloud target geometry. Do Nothing."<<std::endl;
161  return;
162  }
163 
164  ExtractScalarField * extractorField = new ExtractScalarField();
165  extractorField->setGeometry(getPatch());
166  extractorField->setMode(ExtractMode::ID);
167  extractorField->setField(&m_field);
168  extractorField->execute();
169  m_field = *(extractorField->getExtractedField());
170  delete extractorField;
171 }
172 
173 
178 void
180 
181  m_field.setName("field");
183 
184 }
185 
191 void
192 SelectionByBoxWithScalar::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
193 
194  BITPIT_UNUSED(name);
195  SelectionByBox::absorbSectionXML(slotXML, name);
196 };
197 
203 void
204 SelectionByBoxWithScalar::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
205 
206  BITPIT_UNUSED(name);
207  SelectionByBox::flushSectionXML(slotXML, name);
208 };
209 
210 }
void setOrigin(darray3E)
ExtractScalarField is specialized derived class of ExtractField to extract a scalar field of doubles.
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
void setName(std::string name)
void warningXML(bitpit::Logger *log, std::string name)
void swap(SelectionByBox &) noexcept
MimmoSharedPointer< MimmoObject > getGeometry() const
void setGeometry(MimmoSharedPointer< MimmoObject > geometry)
void write(MimmoSharedPointer< MimmoObject > geometry)
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
Selection through volume box primitive.
Selection through volume box primitive.
void setField(dmpvector1D *field)
const mimmo::MimmoSharedPointer< MimmoObject > getPatch() const
#define M_SCALARFIELD
std::array< double, 3 > darray3E
void swap(SelectionByBoxWithScalar &) noexcept
SelectionByBoxWithScalar & operator=(SelectionByBoxWithScalar other)
virtual void setGeometry(mimmo::MimmoSharedPointer< MimmoObject >)
void setSpan(double, double, double)
MimmoSharedPointer is a custom implementation of shared pointer.
MimmoSharedPointer< MimmoObject > getGeometry()
void setMode(ExtractMode mode)