failed_at_this_configuration.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2019. Toyota Research Institute
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of CNRS-LAAS and AIST nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
37 #ifndef FCL_FAILED_AT_THIS_CONFIGURATION_H
38 #define FCL_FAILED_AT_THIS_CONFIGURATION_H
39 
40 #include <exception>
41 #include <iomanip>
42 #include <ostream>
43 #include <sstream>
44 #include <stdexcept>
45 #include <string>
46 
47 #include "fcl/common/types.h"
48 #include "fcl/export.h"
49 
50 namespace fcl {
51 namespace detail {
52 
65 class FCL_EXPORT FailedAtThisConfiguration final
66  : public std::exception {
67  public:
68  FailedAtThisConfiguration(const std::string& message)
69  : std::exception(), message_(message) {}
70 
71  const char* what() const noexcept final { return message_.c_str(); }
72 
73  private:
74  std::string message_;
75 };
76 
86 FCL_EXPORT void ThrowFailedAtThisConfiguration(
87  const std::string& message, const char* func, const char* file, int line);
88 
108 template <typename S>
109 void WriteCommaSeparated(std::stringstream* sstream, const Transform3<S>& p) {
110  const auto& m = p.matrix();
111  std::stringstream& ss = *sstream;
112  for (int row = 0; row < 4; ++row) {
113  for (int col = 0; col < 4; ++col) {
114  ss << m(row, col);
115  if (col < 3) {
116  ss << ", ";
117  }
118  }
119  if (row < 3) {
120  ss << ",\n";
121  } else {
122  ss << ";";
123  }
124  }
125 }
126 
141 template <typename Shape1, typename Shape2, typename Solver, typename S>
142 void ThrowDetailedConfiguration(const Shape1& s1, const Transform3<S>& X_FS1,
143  const Shape2& s2, const Transform3<S>& X_FS2,
144  const Solver& solver, const std::exception& e) {
145  std::stringstream ss;
146  const int digits = 20;
147  ss << std::setprecision(digits);
148  ss << "Error with configuration"
149  << "\n Original error message: " << e.what()
150  << "\n Shape 1:\n" << s1.representation(digits)
151  << "\n X_FS1\n";
152  WriteCommaSeparated(&ss, X_FS1);
153  ss << "\n Shape 2:\n" << s2.representation(digits)
154  << "\n X_FS2\n";
155  WriteCommaSeparated(&ss, X_FS2);
156  ss << "\n Solver: " << solver;
157  throw std::logic_error(ss.str());
158 }
159 
160 } // namespace detail
161 } // namespace fcl
162 
163 #define FCL_THROW_FAILED_AT_THIS_CONFIGURATION(message) \
164  ::fcl::detail::ThrowFailedAtThisConfiguration(message, __func__, __FILE__, \
165  __LINE__)
166 
167 #endif // FCL_FAILED_AT_THIS_CONFIGURATION_H
fcl::Transform3
Eigen::Transform< S, 3, Eigen::Isometry > Transform3
Definition: types.h:91
fcl::detail::FailedAtThisConfiguration::what
const char * what() const noexcept final
Definition: failed_at_this_configuration.h:71
types.h
fcl::detail::WriteCommaSeparated
void WriteCommaSeparated(std::stringstream *sstream, const Transform3< S > &p)
Definition: failed_at_this_configuration.h:109
fcl::detail::ThrowFailedAtThisConfiguration
FCL_EXPORT void ThrowFailedAtThisConfiguration(const std::string &message, const char *func, const char *file, int line)
Definition: failed_at_this_configuration.cpp:8
fcl::detail::FailedAtThisConfiguration::message_
std::string message_
Definition: failed_at_this_configuration.h:74
fcl::detail::FailedAtThisConfiguration::FailedAtThisConfiguration
FailedAtThisConfiguration(const std::string &message)
Definition: failed_at_this_configuration.h:68
Solver
Definition: svm.cpp:434
fcl::detail::ThrowDetailedConfiguration
void ThrowDetailedConfiguration(const Shape1 &s1, const Transform3< S > &X_FS1, const Shape2 &s2, const Transform3< S > &X_FS2, const Solver &solver, const std::exception &e)
Definition: failed_at_this_configuration.h:142
line
static char * line
Definition: svm.cpp:2902
fcl
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
fcl::detail::FailedAtThisConfiguration
Definition: failed_at_this_configuration.h:65


fcl
Author(s):
autogenerated on Tue Dec 5 2023 03:40:48