Chemical Data Processing Library C++ API - Version 1.1.1
GaussianShapeFunctionAlignment.hpp
Go to the documentation of this file.
1 /*
2  * GaussianShapeFunctionAlignment.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_SHAPE_GAUSSIANSHAPEFUNCTIONALIGNMENT_HPP
30 #define CDPL_SHAPE_GAUSSIANSHAPEFUNCTIONALIGNMENT_HPP
31 
32 #include <cstddef>
33 #include <vector>
34 #include <memory>
35 
36 #include "CDPL/Shape/APIPrefix.hpp"
40 #include "CDPL/Math/Matrix.hpp"
43 
44 
45 namespace CDPL
46 {
47 
48  namespace Shape
49  {
50 
52  {
53 
54  public:
55  class Result;
56 
57  private:
58  typedef std::vector<Result> ResultList;
59 
60  public:
61  static constexpr double DEF_OPTIMIZATION_STOP_GRADIENT = 1.0;
62  static constexpr std::size_t DEF_MAX_OPTIMIZATION_ITERATIONS = 20;
63 
64  typedef std::shared_ptr<GaussianShapeFunctionAlignment> SharedPointer;
65 
66  typedef ResultList::const_iterator ConstResultIterator;
67 
70 
71  class Result
72  {
73 
74  public:
75  Result(const Math::Matrix4D& xform, double overlap, double col_overlap):
76  transform(xform), overlap(overlap), colOverlap(col_overlap) {}
77 
79  {
80  return transform;
81  }
82 
83  double getOverlap() const
84  {
85  return overlap;
86  }
87 
88  double getColorOverlap() const
89  {
90  return colOverlap;
91  }
92 
93  private:
95 
96  Result():
97  transform(), overlap(0.0), colOverlap(0.0) {}
98 
100  double overlap;
101  double colOverlap;
102  };
103 
105 
106  GaussianShapeFunctionAlignment(const GaussianShapeFunction& ref_func, unsigned int sym_class);
107 
109 
111 
113 
115 
117 
119 
121 
123 
125 
127 
129 
131 
133 
134  void performAlignment(bool perf_align);
135 
136  bool performAlignment() const;
137 
138  void optimizeOverlap(bool optimize);
139 
140  bool optimizeOverlap() const;
141 
142  void greedyOptimization(bool greedy);
143 
144  bool greedyOptimization() const;
145 
146  void setMaxNumOptimizationIterations(std::size_t max_iter);
147 
148  std::size_t getMaxNumOptimizationIterations() const;
149 
150  void setOptimizationStopGradient(double grad_norm);
151 
153 
154  unsigned int setupReference(GaussianShapeFunction& func, Math::Matrix4D& xform) const;
155 
156  unsigned int setupAligned(GaussianShapeFunction& func, Math::Matrix4D& xform) const;
157 
158  void setReference(const GaussianShapeFunction& func, unsigned int sym_class);
159 
161 
163 
165 
166  void calcColorOverlaps(bool calc);
167 
168  bool calcColorOverlaps() const;
169 
170  bool align(const GaussianShapeFunction& func, unsigned int sym_class);
171 
172  std::size_t getNumResults() const;
173 
174  const Result& getResult(std::size_t idx) const;
175 
177 
179 
181 
183 
184  private:
186 
188 
189  bool checkValidity(const GaussianShapeFunction& func) const;
190 
191  double calcAlignmentFunctionValue(const QuaternionTransformation& xform_quat);
192  double calcAlignmentFunctionGradient(const QuaternionTransformation& xform_quat, QuaternionTransformation& xform_grad);
193 
195 
196  FastGaussianShapeOverlapFunction defOverlapFunc;
198  GaussianShapeOverlapFunction* overlapFunc;
200  const GaussianShapeFunction* refShapeFunc;
201  unsigned int refShapeSymClass;
202  bool perfAlignment;
203  bool calcColOverlaps;
204  bool optOverlap;
205  bool greedyOpt;
206  std::size_t maxNumOptIters;
207  double optStopGrad;
208  Math::Vector3DArray startPoseCoords;
209  Math::Vector3DArray optPoseCoords;
210  Math::Vector3DArray optPoseCoordsGrad;
211  BFGSMinimizer minimizer;
212  ResultList results;
213  };
214  } // namespace Shape
215 } // namespace CDPL
216 
217 #endif // CDPL_SHAPE_GAUSSIANSHAPEFUNCTIONALIGNMENT_HPP
CDPL::Shape::GaussianShapeFunctionAlignment::calcSelfOverlap
double calcSelfOverlap(const GaussianShapeFunction &func)
CDPL::Shape::GaussianShapeAlignmentStartGenerator
Definition: GaussianShapeAlignmentStartGenerator.hpp:49
CDPL::Shape::GaussianShapeFunctionAlignment::align
bool align(const GaussianShapeFunction &func, unsigned int sym_class)
CDPL::Shape::GaussianShapeFunctionAlignment::Result
Definition: GaussianShapeFunctionAlignment.hpp:72
CDPL::Shape::GaussianShapeFunctionAlignment::performAlignment
void performAlignment(bool perf_align)
CMatrix< double, 4, 4 >
VectorArray.hpp
Definition of the class CDPL::Math::VectorArray.
CDPL::Shape::GaussianShapeFunctionAlignment::Result::getOverlap
double getOverlap() const
Definition: GaussianShapeFunctionAlignment.hpp:83
CDPL::Shape::GaussianShapeFunctionAlignment::setMaxNumOptimizationIterations
void setMaxNumOptimizationIterations(std::size_t max_iter)
CDPL::Shape::GaussianShapeFunctionAlignment
Definition: GaussianShapeFunctionAlignment.hpp:52
CDPL::Shape::GaussianShapeFunctionAlignment::Result::getColorOverlap
double getColorOverlap() const
Definition: GaussianShapeFunctionAlignment.hpp:88
CDPL::Shape::PrincipalAxesAlignmentStartGenerator
Definition: PrincipalAxesAlignmentStartGenerator.hpp:49
CDPL::Shape::GaussianShapeFunctionAlignment::GaussianShapeFunctionAlignment
GaussianShapeFunctionAlignment(const GaussianShapeFunction &ref_func, unsigned int sym_class)
CDPL::Shape::GaussianShapeFunctionAlignment::getDefaultOverlapFunction
FastGaussianShapeOverlapFunction & getDefaultOverlapFunction()
CDPL::Shape::GaussianShapeFunctionAlignment::getDefaultStartGenerator
PrincipalAxesAlignmentStartGenerator & getDefaultStartGenerator()
CDPL::Shape::transform
CDPL_SHAPE_API void transform(GaussianShape &shape, const Math::Matrix4D &xform)
CDPL::Shape::GaussianShapeFunctionAlignment::setColorMatchFunction
void setColorMatchFunction(const ColorMatchFunction &func)
CDPL::Shape::GaussianShapeFunctionAlignment::optimizeOverlap
void optimizeOverlap(bool optimize)
QuaternionTransformation.hpp
Definition of the type CDPL::Shape::QuaternionTransformation.
CDPL::Shape::GaussianShapeFunctionAlignment::greedyOptimization
bool greedyOptimization() const
CDPL::Shape::GaussianShapeFunctionAlignment::setOptimizationStopGradient
void setOptimizationStopGradient(double grad_norm)
CDPL::Shape::GaussianShapeOverlapFunction::ColorMatchFunction
std::function< bool(std::size_t, std::size_t)> ColorMatchFunction
Definition: GaussianShapeOverlapFunction.hpp:55
CDPL::Shape::GaussianShapeFunctionAlignment::getStartGenerator
GaussianShapeAlignmentStartGenerator & getStartGenerator() const
CDPL::Shape::GaussianShapeFunctionAlignment::~GaussianShapeFunctionAlignment
~GaussianShapeFunctionAlignment()
BFGSMinimizer.hpp
Implementation of the BFGS optimization algorithm.
VectorArray< Vector3D >
PrincipalAxesAlignmentStartGenerator.hpp
Definition of the class CDPL::Shape::PrincipalAxesAlignmentStartGenerator.
CDPL::Shape::GaussianShapeFunctionAlignment::ColorFilterFunction
GaussianShapeOverlapFunction::ColorFilterFunction ColorFilterFunction
Definition: GaussianShapeFunctionAlignment.hpp:68
CDPL::Shape::GaussianShapeFunctionAlignment::calcColorOverlaps
void calcColorOverlaps(bool calc)
CDPL::Shape::GaussianShapeFunctionAlignment::getColorMatchFunction
const ColorMatchFunction & getColorMatchFunction() const
CDPL::Shape::GaussianShapeFunctionAlignment::getReference
const GaussianShapeFunction * getReference() const
CDPL::Shape::GaussianShapeFunctionAlignment::calcColorOverlaps
bool calcColorOverlaps() const
CDPL::Shape::GaussianShapeFunctionAlignment::ConstResultIterator
ResultList::const_iterator ConstResultIterator
Definition: GaussianShapeFunctionAlignment.hpp:66
CDPL::Shape::GaussianShapeFunctionAlignment::getMaxNumOptimizationIterations
std::size_t getMaxNumOptimizationIterations() const
CDPL::Math::CVector
Definition: Vector.hpp:1053
CDPL::Shape::GaussianShapeFunctionAlignment::greedyOptimization
void greedyOptimization(bool greedy)
CDPL::Shape::GaussianShapeFunctionAlignment::getOverlapFunction
GaussianShapeOverlapFunction & getOverlapFunction() const
CDPL::Math::BFGSMinimizer< QuaternionTransformation >
CDPL::Shape::GaussianShapeFunctionAlignment::performAlignment
bool performAlignment() const
CDPL::Shape::GaussianShapeFunctionAlignment::setColorFilterFunction
void setColorFilterFunction(const ColorFilterFunction &func)
CDPL::Shape::GaussianShapeFunctionAlignment::getOptimizationStopGradient
double getOptimizationStopGradient() const
CDPL::Shape::GaussianShapeOverlapFunction
Definition: GaussianShapeOverlapFunction.hpp:49
CDPL::Shape::GaussianShapeFunctionAlignment::setupReference
unsigned int setupReference(GaussianShapeFunction &func, Math::Matrix4D &xform) const
CDPL::Shape::GaussianShapeFunction
Definition: GaussianShapeFunction.hpp:53
CDPL_SHAPE_API
#define CDPL_SHAPE_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
CDPL::Shape::GaussianShapeFunctionAlignment::begin
ConstResultIterator begin() const
CDPL::Shape::GaussianShapeFunctionAlignment::setStartGenerator
void setStartGenerator(GaussianShapeAlignmentStartGenerator &gen)
CDPL::Shape::GaussianShapeFunctionAlignment::Result::Result
Result(const Math::Matrix4D &xform, double overlap, double col_overlap)
Definition: GaussianShapeFunctionAlignment.hpp:75
CDPL::Shape::FastGaussianShapeOverlapFunction
Definition: FastGaussianShapeOverlapFunction.hpp:47
CDPL
The namespace of the Chemical Data Processing Library.
APIPrefix.hpp
Definition of the preprocessor macro CDPL_SHAPE_API.
CDPL::Shape::GaussianShapeFunctionAlignment::setReference
void setReference(const GaussianShapeFunction &func, unsigned int sym_class)
CDPL::Shape::GaussianShapeFunctionAlignment::GaussianShapeFunctionAlignment
GaussianShapeFunctionAlignment()
FastGaussianShapeOverlapFunction.hpp
Definition of the class CDPL::Shape::FastGaussianShapeOverlapFunction.
CDPL::Shape::GaussianShapeFunctionAlignment::calcColorSelfOverlap
double calcColorSelfOverlap(const GaussianShapeFunction &func)
CDPL::Shape::GaussianShapeFunctionAlignment::getResultsEnd
ConstResultIterator getResultsEnd() const
CDPL::Shape::GaussianShapeFunctionAlignment::getDefaultStartGenerator
const PrincipalAxesAlignmentStartGenerator & getDefaultStartGenerator() const
CDPL::Shape::GaussianShapeFunctionAlignment::setupAligned
unsigned int setupAligned(GaussianShapeFunction &func, Math::Matrix4D &xform) const
CDPL::Shape::GaussianShapeFunctionAlignment::getNumResults
std::size_t getNumResults() const
CDPL::Shape::GaussianShapeFunctionAlignment::ColorMatchFunction
GaussianShapeOverlapFunction::ColorMatchFunction ColorMatchFunction
Definition: GaussianShapeFunctionAlignment.hpp:69
Matrix.hpp
Definition of matrix data types.
CDPL::Shape::GaussianShapeFunctionAlignment::getResultsBegin
ConstResultIterator getResultsBegin() const
CDPL::Shape::GaussianShapeFunctionAlignment::SharedPointer
std::shared_ptr< GaussianShapeFunctionAlignment > SharedPointer
Definition: GaussianShapeFunctionAlignment.hpp:64
CDPL::Shape::GaussianShapeFunctionAlignment::Result::getTransform
const Math::Matrix4D & getTransform() const
Definition: GaussianShapeFunctionAlignment.hpp:78
CDPL::Shape::GaussianShapeOverlapFunction::ColorFilterFunction
std::function< bool(std::size_t)> ColorFilterFunction
Definition: GaussianShapeOverlapFunction.hpp:54
CDPL::Shape::GaussianShapeFunctionAlignment::getDefaultOverlapFunction
const FastGaussianShapeOverlapFunction & getDefaultOverlapFunction() const
CDPL::Shape::GaussianShapeFunctionAlignment::end
ConstResultIterator end() const
CDPL::Shape::GaussianShapeFunctionAlignment::setOverlapFunction
void setOverlapFunction(GaussianShapeOverlapFunction &func)
CDPL::Shape::GaussianShapeFunctionAlignment::getColorFilterFunction
const ColorFilterFunction & getColorFilterFunction() const
CDPL::Shape::GaussianShapeFunctionAlignment::getResult
const Result & getResult(std::size_t idx) const
CDPL::Shape::GaussianShapeFunctionAlignment::optimizeOverlap
bool optimizeOverlap() const