TranslationPoint.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 #include "TranslationPoint.hpp"
25 
26 namespace mimmo{
27 
32  setDirection(direction);
33  m_alpha = 0.0;
34  m_name = "mimmo.TranslationPoint";
35 };
36 
41 TranslationPoint::TranslationPoint(const bitpit::Config::Section & rootXML){
42 
43  m_direction.fill(0.0);
44  m_alpha = 0.0;
45  m_name = "mimmo.TranslationPoint";
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.TranslationPoint"){
51  absorbSectionXML(rootXML);
52  }else{
54  };
55 }
56 
60 
64  m_origin = other.m_origin;
65  m_alpha = other.m_alpha;
66  m_direction = other.m_direction;
67 };
68 
74 {
75  std::swap(m_origin, x.m_origin);
76  std::swap(m_alpha, x.m_alpha);
77  std::swap(m_direction, x.m_direction);
78  std::swap(m_translated, x.m_translated);
79 
81 }
82 
85 void
87  bool built = true;
88  built = (built && createPortIn<darray3E, TranslationPoint>(this, &mimmo::TranslationPoint::setOrigin, M_POINT));
89  built = (built && createPortIn<darray3E, TranslationPoint>(this, &mimmo::TranslationPoint::setDirection, M_AXIS));
90  built = (built && createPortIn<double, TranslationPoint>(this, &mimmo::TranslationPoint::setTranslation, M_VALUED));
91  built = (built && createPortOut<darray3E, TranslationPoint>(this, &mimmo::TranslationPoint::getTranslatedOrigin, M_POINT));
92  // built = (built && createPortOut<darray3E, TranslationPoint>(this, &mimmo::TranslationPoint::getDirection, M_AXIS));
93  // built = (built && createPortOut<double, TranslationPoint>(this, &mimmo::TranslationPoint::getTranslation, M_VALUED));
94  m_arePortsBuilt = built;
95 };
96 
100 darray3E
102  return(m_direction);
103 }
104 
108 double
110  return(m_alpha);
111 }
112 
116 darray3E
118  return(m_origin);
119 }
120 
124 darray3E
126  return(m_translated);
127 }
128 
132 void
134  m_direction = direction;
135  double norm = norm2(m_direction);
136  if(norm < std::numeric_limits<double>::min()){
137  m_direction /= norm;
138  }
139 }
140 
144 void
146  m_alpha = alpha;
147 }
148 
152 void
154  m_origin = origin;
155 }
156 
163 void
166 };
167 
173 void
174 TranslationPoint::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
175 
176  BITPIT_UNUSED(name);
177 
178  BaseManipulation::absorbSectionXML(slotXML, name);
179 
180  if(slotXML.hasOption("Origin")){
181  std::string input = slotXML.get("Origin");
182  input = bitpit::utils::string::trim(input);
183  darray3E temp = {{0.0,0.0,0.0}};
184  if(!input.empty()){
185  std::stringstream ss(input);
186  for(auto &val : temp) ss>>val;
187  }
188  setOrigin(temp);
189  }
190 
191  if(slotXML.hasOption("Direction")){
192  std::string input = slotXML.get("Direction");
193  input = bitpit::utils::string::trim(input);
194  darray3E temp = {{0.0,0.0,0.0}};
195  if(!input.empty()){
196  std::stringstream ss(input);
197  for(auto &val : temp) ss>>val;
198  }
199  setDirection(temp);
200  }
201 
202  if(slotXML.hasOption("Translation")){
203  std::string input = slotXML.get("Translation");
204  input = bitpit::utils::string::trim(input);
205  double temp = 0.0;
206  if(!input.empty()){
207  std::stringstream ss(input);
208  ss>>temp;
209  }
210  setTranslation(temp);
211  }
212 
213 };
214 
220 void
221 TranslationPoint::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
222 
223  BITPIT_UNUSED(name);
224 
225  BaseManipulation::flushSectionXML(slotXML, name);
226 
227  {
228  std::stringstream ss;
229  ss<<std::scientific<<m_origin[0]<<'\t'<<m_origin[1]<<'\t'<<m_origin[2];
230  slotXML.set("Origin", ss.str());
231  }
232 
233  {
234  std::stringstream ss;
235  ss<<std::scientific<<m_direction[0]<<'\t'<<m_direction[1]<<'\t'<<m_direction[2];
236  slotXML.set("Direction", ss.str());
237  }
238 
239  slotXML.set("Translation", std::to_string(m_alpha));
240 
241 };
242 
243 
244 }
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
void setTranslation(double alpha)
#define M_POINT
void warningXML(bitpit::Logger *log, std::string name)
TranslationPoint(darray3E direction={ {0, 0, 0} })
BaseManipulation is the base class of any manipulation object of the library.
TranslationPoint is the class that applies the a translation to a point.
void setDirection(darray3E direction)
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
#define M_VALUED
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
void setOrigin(darray3E origin)
std::array< double, 3 > darray3E
#define M_AXIS
void swap(TranslationPoint &x) noexcept
void swap(BaseManipulation &x) noexcept