OpenStructure
alg_transform.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 // Copyright (C) 2003-2010 by the IPLT authors
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 3.0 of the License, or (at your option)
10 // any later version.
11 // This library is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 // details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this library; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //------------------------------------------------------------------------------
20 
21 #ifndef IMG_ALG_TRANSFORM_ALG_TRANSFORM_HH
22 #define IMG_ALG_TRANSFORM_ALG_TRANSFORM_HH
23 
24 #include <ost/img/image_state.hh>
25 #include <ost/img/value_util.hh>
26 #include "transformations.hh"
28 
29 namespace ost { namespace img { namespace alg {
30 
32 
33  TransformFnc(): tf_() {}
34  TransformFnc(const Transformation& tf, const Vec3 o=Vec3(0.0,0.0,0.0)): tf_(tf), offset_(o) {}
35 
36  template <typename T, class D>
38  /*
39  old extent code, needs re-implementation
40  Extent src_extent = isi.GetExtent();
41  Extent dst_extent = (r==Transformer::ORIGINAL) ? src_extent : tf::Transform(src_extent,t);
42  ImageStateImpl<V,DP> *nisi = new ImageStateImpl<V,DP>(dst_extent);
43 
44  Extent dst_extent = src_extent;
45  */
46 
47  boost::shared_ptr<ImageStateImpl<T,D> > nisi = isi.CloneState(false);
48 
49  Mat4 imat = tf_.InverseMatrix();
50 
51  if(offset_==Vec3(0.0,0.0,0.0)) {
52  for(ExtentIterator it(nisi->GetExtent()); !it.AtEnd(); ++it) {
53  Point p(it);
54  Vec3 vold_norm=Vec3(imat * Vec4(p.ToVec3()));
55  nisi->Value(it) = isi.CalcIntpolValue(vold_norm);
56  }
57  } else {
58  for(ExtentIterator it(nisi->GetExtent()); !it.AtEnd(); ++it) {
59  Point p(it);
60  Vec3 vold_norm=Vec3(imat * Vec4(p.ToVec3()-offset_))+offset_;
61  nisi->Value(it) = isi.CalcIntpolValue(vold_norm);
62  }
63  }
64 
65  return nisi;
66  }
67 
68  static String GetAlgorithmName() {return "Transform";}
69 
70 private:
71  Transformation tf_;
72  Vec3 offset_;
73 };
74 
76 
77 }}} // ns
78 
79 #endif
80 
bool AtEnd() const
Returns true if iterator has reached end.
class encapsulating 1D to 3D point
Definition: point.hh:47
Vec3 ToVec3() const
transformation base class
out-of-place modifying image state const visitor plus op algorithm
T CalcIntpolValue(const Vec3 &v) const
SharedPtrType CloneState(bool cc=true) const
#define DLLEXPORT_IMG_ALG
std::string String
Definition: base.hh:54
ImageStateConstModOPAlgorithm< TransformFnc > Transform
boost::shared_ptr< ImageStateBase > ImageStateBasePtr
Definition: base.dox:1
ImageStateBasePtr VisitState(const ImageStateImpl< T, D > &isi) const
TransformFnc(const Transformation &tf, const Vec3 o=Vec3(0.0, 0.0, 0.0))
static String GetAlgorithmName()