iRoCS Toolbox  1.1.0
ShellCoordinateTransform.hh
Go to the documentation of this file.
1 /**************************************************************************
2  *
3  * Copyright (C) 2015 Kun Liu, Thorsten Falk
4  *
5  * Image Analysis Lab, University of Freiburg, Germany
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  **************************************************************************/
22 
23 #ifndef SHELLCOORDINATETRANSFORM_HH
24 #define SHELLCOORDINATETRANSFORM_HH
25 
26 #ifdef HAVE_CONFIG_H
27 #include <config.hh>
28 #endif
29 
30 #include <vector>
31 #include <blitz/array.h>
32 #include <opencv2/core/core.hpp>
33 #include <opencv2/imgproc/imgproc.hpp>
34 
36 
38 
40 
42 {
43 
44 public:
45 
47 
49  std::vector< blitz::TinyVector<double,3> > const &points,
50  double lSegments, double margin,
51  bool QCset, blitz::TinyVector<double,3> const &QC,
52  bool Xset, blitz::TinyVector<double,3> const &X,
53  iRoCS::ProgressReporter *pr = NULL);
54 
56 
57  void fitModel(
58  std::vector< blitz::TinyVector<double,3> > const &points,
59  double lSegments, double margin,
60  bool QCset, blitz::TinyVector<double,3> const &QC,
61  bool Xset, blitz::TinyVector<double,3> const &X,
62  iRoCS::ProgressReporter *pr = NULL);
63 
64  void refineModel(
65  std::vector< blitz::TinyVector<double,3> > const &points,
66  iRoCS::ProgressReporter *pr = NULL);
67 
68  blitz::TinyVector<double,3> getAxisPosition(double u) const;
69  blitz::TinyMatrix<double,3,3> getAxisCoordinateSystem(double u) const;
70  blitz::TinyMatrix<double,2,2> getAxisEllipse(double u) const;
71  blitz::TinyVector<double,3> getAxisDirection(double u) const;
72  double axisLengthUm() const;
73 
74  blitz::TinyVector<double,3> getCoordinates(
75  blitz::TinyVector<double,3> const &pos) const;
76 
77  blitz::TinyVector<double,3> getCoordinatesWithNormalizedRadius(
78  blitz::TinyVector<double,3> const &pos) const;
79 
80  blitz::Array<blitz::TinyVector<double,3>,1> const &controlPoints() const;
81 
82  int nLatitudes() const;
83  void setNLatitudes(int nLatitudes);
84  int nLongitudes() const;
85  void setNLongitudes(int nLongitudes);
86  atb::SurfaceGeometry const &surface() const;
87 
88  void save(BlitzH5File &outfile, std::string const &groupName) const;
89  void save(std::string const &fileName, std::string const &groupName) const;
90  void load(BlitzH5File const &infile, std::string const &groupName);
91  void load(std::string const &fileName, std::string const &groupName);
92 
93 private:
94 
95  blitz::TinyVector<double,3> normalizedCoordinates(
96  blitz::TinyVector<double,3> const &pos, int controlPoint) const;
97 
98  blitz::TinyVector<double,3> denormalizedCoordinates(
99  blitz::TinyVector<double,3> const &pos, int controlPoint) const;
100 
101  double computeDistanceToLine(
102  blitz::TinyVector<double,3> const &pos, int segment,
103  double &offset, double &radialDistance, double &angle) const;
104 
105  double computeDistanceToLineSegment(
106  blitz::TinyVector<double,3> const &pos, int segment,
107  double &offset, double &radialDistance, double &angle) const;
108 
109  void updateDerivedVariables();
110 
111  void smoothControlPoints(int tail);
112 
113  void smoothControlEllipses(int tail);
114 
115  // The number of control points (equals the length of all following Arrays)
116  int _nControlPoint;
117 
118  // The axis control point positions
119  blitz::Array<blitz::TinyVector<double,3>,1> _controlPoints;
120 
121  // The local coordinate systems at the control points
122  blitz::Array<blitz::TinyMatrix<double,3,3>,1> _controlAxes;
123 
124  // The vectors from control point i to control point i+1
125  blitz::Array<blitz::TinyVector<double,3>,1> _segments;
126 
127  // The cummulated curve length up to control point i
128  blitz::Array<double,1> _controlPointOffset;
129 
130  // The directions of the segment vectors
131  blitz::Array<blitz::TinyVector<double,3>,1> _segmentDirection;
132 
133  // The magnitudes of the segment vectors
134  blitz::Array<double,1> _segmentLength;
135 
136  // The orthonormal direction to the plane spanned by the segment vector
137  // and the (0,0,1) vector
138  blitz::Array<blitz::TinyVector<double,3>,1> _axis;
139 
140  // The angle between the (0,0,1) vector and the segment direction
141  blitz::Array<double,1> _angle;
142 
143  // The data extreme points in axis direction, the control point step and
144  // the margin (for whatever it is used)
145  double _minX, _maxX, _step, _margin;
146 
147  //Ellipse
148  blitz::Array<double,1> _ra;
149  blitz::Array<double,1> _rb;
150  blitz::Array<double,1> _angleToAxis;
151  blitz::Array<blitz::TinyMatrix<double,2,2>,1> _controlEllipses;
152 
153  ptrdiff_t _nLatitudes, _nLongitudes;
154  mutable atb::SurfaceGeometry _surface;
155 
156 };
157 
158 #endif
blitz::TinyMatrix< double, 2, 2 > getAxisEllipse(double u) const
void setNLatitudes(int nLatitudes)
void load(BlitzH5File const &infile, std::string const &groupName)
atb::SurfaceGeometry const & surface() const
blitz::TinyVector< double, 3 > getCoordinates(blitz::TinyVector< double, 3 > const &pos) const
Storage and rendering of Triangulated surfaces.
blitz::TinyVector< double, 3 > getAxisPosition(double u) const
double axisLengthUm() const
blitz::Array< blitz::TinyVector< double, 3 >, 1 > const & controlPoints() const
void refineModel(std::vector< blitz::TinyVector< double, 3 > > const &points, iRoCS::ProgressReporter *pr=NULL)
Lightweight alternative to libBlitzHDF5 providing its basic functionality.
blitz::TinyVector< double, 3 > getCoordinatesWithNormalizedRadius(blitz::TinyVector< double, 3 > const &pos) const
blitz::TinyVector< double, 3 > getAxisDirection(double u) const
blitz::TinyMatrix< double, 3, 3 > getAxisCoordinateSystem(double u) const
void setNLongitudes(int nLongitudes)
The SurfaceGeometry struct provides data structures required for the storage of triangulated surface ...
void fitModel(std::vector< blitz::TinyVector< double, 3 > > const &points, double lSegments, double margin, bool QCset, blitz::TinyVector< double, 3 > const &QC, bool Xset, blitz::TinyVector< double, 3 > const &X, iRoCS::ProgressReporter *pr=NULL)
void save(BlitzH5File &outfile, std::string const &groupName) const