I am trying to calculate the overlap area between two ellipses. I am approximating the ellipses with polygons now and I have found an example that apparently used an old version of Boost.Geometry, as per this answer. From the second answer to this question, I can see that this is an old example as well, since some of the header files are not there in v1.53.
I have replaced those with:
#include <boost/geometry/geometries/adapted/c_array.hpp>
#include <boost/geometry/multi/multi.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/io/wkt/wkt.hpp>
#include <boost/geometry/multi/geometries/multi_polygon.hpp>
and also added this code:
typedef boost::geometry::model::d2::point_xy<double,
boost::geometry::cs::cartesian> point_2d;
typedef boost::geometry::model::polygon<point_2d> polygon_2d;
and almost everything works. The only problem is with this:
polygon_2d poly, poly2;
typedef std::vector<polygon_2d > polygon_list;
polygon_list v;
intersection_inserter<polygon_2d >(poly2, poly, std::back_inserter(v));
I am getting an error:
intersection_inserter was not declared in this scope
expected primary expression before '>' token
The documentation of boost on the matter here is from 2009, so I guess it does not apply anymore... Their example is written the same as mine, as far as I can tell. I have found the place on the header file intersection.hpp where intersection_inserter is defined but I cannot make heads or tails of it...
I am getting the same error both in VS2012 in win7 and Qt 4.7.4 in Linux Mint 14. Any help would be greatly appreciated!
I cannot find any reference to intersection_inserter in the current boost documentation. Perhaps this functionality has been removed?
It seems that the "official" way to calculate intersections in boost::geometry is through the intersection function, as documented (with example) here
Related
The error
The exact error is the title of the question.
It happens when I use vectorName.push_back() function.
I recreated it with just this simple code:
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector <int> vec = {};
vec.push_back(2);
return 0;
}
Compiler and setup information
Im using msys2, and
I set it up using this guide
I have no idea if this is relevant or not, but I used tdm-gcc before this.
Research
A fix is almost nowhere to be found, or i just didn't look hard enough. I have found some posts about the _ZSt28__throw_bad_array_new_lengthv, but not with entry point. And because I didn't find anything about this exact issue, I didn't try anything.
This is a weird one, I was hoping to use boost::random_spanning_tree in an existing function which also calls boost::strong_components but simply including boost/graph/random_spanning_tree.hpp without otherwise modifying the code causes gcc to produce a compilation error.
The function looks something like this:
#include "boost/graph/adjacency_list.hpp"
#include "boost/graph/strong_components.hpp"
//#include "boost/graph/random_spanning_tree.hpp" // can't include this!
void foo() {
boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS> g;
// TODO: add some vertices
std::vector<unsigned> component(boost::num_vertices(g));
unsigned num = boost::strong_components(g, &component[0]);
}
and gcc complains:
error: no matching function for call to ‘get(unsigned int*&, boost::graph_traits<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS> >::vertex_descriptor&)’
if (get(comp, w) == (std::numeric_limits<comp_type>::max)())
Is the code itself flawed or is this an issue with Boost?
EDIT:
I must apologize, I have made a slight mistake in my minimal example, the code above only fails to compile on my system (Linus, g++ 8.2.1, Boost 1.67) if boost/graph/random_spanning_tree.hpp is included before boost/graph/strong_components.hpp. Using wandbox, I have found no combination of compiler / Boost version for which this does not happen.
I would file a ticket for this but Boost makes this needlessly difficult (I don't have TICKET_CREATE rights for Boost's Trac but how to obtain those is not specified anywhere).
It's no problem here: Live On Coliru
Also try
https://wandbox.org/permlink/jDIYB9oCjAP2wxHo wandbox which lets you switch compiler versions, flags and every possible boost version
Which leads me to believe it's a problem with the rest of your code/compiler config.
Are you on windows? I see max which is a MACRO in windows.h. Be sure to not include that (also check stdafx.h if you use it)
UPDATE
After your edit I was able to repro the error. That's a bug in boost, and I've created a ticket for it at the bug tracker
I am fairly new to c++ and boost.
I want to create a set of numbers that derived from a skewed distribution using Boost's skewed_normal_distribution class.
I'm not sure how to even start. I want to define a distribution with mean 0.05, variance 0.95, but a skew of 0.5. The following code doesn't work and I realise I need to set up a variate_generator as well.
Can anyone provide some pointers? I am not finding the boost documentation page on skew_normal_distribution very intuitive but that might be because of my inexperience.
Note the main problem I am getting is the message:
‘skew_normal_distribution’ is not a member of ‘boost’
Many thanks
#include <boost/random.hpp>
#include <boost/random/normal_distribution.hpp>
#include <boost/math/distributions/skew_normal.hpp>
int main () {
boost::skew_normal_distribution<> normal(0.05, 0.95, 0.5);
return 0;
}
Use boost::math::skew_normal_distribution instead of boost::skew_normal_distribution for the message
skew_normal_distribution is not a member of boost
I've gone through questions, the source code, and other examples, and I can't for the life of me understand what the Distance d = Distance() parameter means in the function
template<typename Distance> int flann::hierarchicalClustering(const Mat& features, Mat& centers, const cvflann::KMeansIndexParams& params, Distance d=Distance())
It's addressed in the comments of this question, but I can't find the Distance type anywhere. I've imported the following files:
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/tracking.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/flann/flann.hpp"
I've checked the cv, cvflann, and cv::flann namespaces and can't find anything.
Here's my code:
int tmp = cv::flann::hierarchicalClustering<cv::L2<float>>(descriptors, centers, params, ______ );
The ___ is obviously where this last parameter goes. I've tried something like cv::L2<float>() but that doesn't work either.
In the source code it looks like a template.
I've also tried:
int tmp = cv::flann::hierarchicalClustering<float, float>(descriptors, centers, params);
and I get the error "no instance of overloaded function "cv::flann::hierachicalClustering" matches the argument list. Argument types are: (cv::Mat, cv::Mat, cv::KMeansIndexParams).
I am using OpenCV 2.4.11.
Any ideas?
There's also more documentation in the FLANN user manual. It looks like it was copied verbatim into OpenCV.
The parameter Distance d = Distance() is a default method argument that sets a distance algorithm. Usually, this will be FLANN_DIST_L2. Why you can't find the Distance "type" anywhere is because it's actually a typename. OpenCV opted to use C++ specialization (via templates) instead of inheritance to make sure that different distance functions have the same traits.
This is a nontrivial subject, so http://www.gotw.ca/publications/mxc++-item-4.htm should provide a fairly painless introduction. If I whet your appetite, check out Andrei Alexandrescu's seminal Modern C++ Design.
Adding this for future reference, since I was just struggling with the OpenCV FLANN classes myself
This worked for me:
// define parameters
cvflann::KMeansIndexParams kmeansParams(10, 100, cvflann::FLANN_CENTERS_KMEANSPP);
// note cvflann - not cv::flann - namespace there
int nClusters = flann::hierarchicalClustering<flann::L2<float>>(samples, centers, kmeansParams );
// note regular flann namespace here
the issue was that marcman was using <cv::L2<float>> instead of <flann::L2<float>>
The flann namespaces are super confusing, and documentation is lacking
and it's a struggle to figure it out in the IDE due to the templating.
I've done my best recently to set up boost's numeric bindings to allow me to use LAPACK from C++, but I've run into some roadblocks. First off, I have confirmed that boost is working fine, so it's something to do with my LAPACK libraries or the boost numeric bindings.
Here's a bit of code to test what I'm trying to do:
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/bindings/lapack/gesvd.hpp>
#include <boost/numeric/bindings/traits/ublas_matrix.hpp>
//#include <boost/numeric/bindings/traits/ublas_vector2.hpp>
//#include <boost/numeric/bindings/traits/matrix_traits.hpp>
typedef boost::numeric::ublas::matrix<int> iMatrix;
typedef boost::numeric::ublas::matrix<double> dMatrix;
typedef boost::numeric::ublas::vector<int> iVector;
typedef boost::numeric::ublas::vector<double> dVector;
namespace ublas = boost::numeric::ublas;
namespace lapack = boost::numeric::bindings::lapack;
void function() {
int n = 10;
dMatrix jacobi(n,n); // then actually initialize it
dVector eigenvals(n);
dMatrix eigenvects(n);
dVector work(n);
int error = lapack::gesvd('N', 'A', jacobi, eigenvals, eigenvects, work);
std::cout << eigenvals << std::endl;
}
Now while I'm not 100% correct that this code should compile when everything is set up correctly, the errors I've been getting when building don't seem to make much sense to me.
In file included from C:\MinGW\boost\boost_1_57_0/boost/serialization/tracking.hpp:20:0,
In file included from C:\MinGW\boost\boost_1_57_0/boost/serialization/tracking.hpp:20:0,
.............
from ..\Solver.cpp:6:
C:\MinGW\boost\boost_1_57_0/boost/numeric/bindings/traits/ublas_matrix.hpp: In instantiation of 'struct boost::numeric::bindings::traits::matrix_detail_traits, boost::numeric::ublas::matrix >':
C:\MinGW\boost\boost_1_57_0/boost/numeric/bindings/traits/matrix_traits.hpp:48:10: required from 'struct boost::numeric::bindings::traits::matrix_traits >'
C:\MinGW\boost\boost_1_57_0/boost/numeric/bindings/lapack/gesvd.hpp:167:7: required from 'int boost::numeric::bindings::lapack::gesvd(char, char, char, MatrA&, VecS&, MatrU&, MatrV&) '
C:\MinGW\boost\boost_1_57_0/boost/numeric/bindings/lapack/gesvd.hpp:477:50: required from 'int boost::numeric::bindings::lapack::gesvd(char, char, MatrA&, VecS&, MatrU&, MatrV&)'
..\Solver.cpp:85:77: required from here
C:\MinGW\boost\boost_1_57_0/boost/numeric/bindings/traits/ublas_matrix.hpp:46:5: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE'
BOOST_STATIC_ASSERT((boost::is_same<
Again, I have tested that boost and ublas by itself is working fine. When I comment out the lapack::gesvd line of code, everything compiles and runs fine. As far as I can tell, these errors means that I have correctly linked LAPACK to the program (there are no unresolved symbols), and my program is able to find the correct binding files (calling lapack::gesvd returns a different error when you give it incorrect input). So I'm at a loss.
I'm on Windows 64 bit, using Eclipse, C++, boost, ublas, and LAPACK. Information about the boost numeric bindings to LAPACK can be found here: http://git.tiker.net/boost-numeric-bindings.git/blob_plain/be4a548307f3e95786acb3487e571bdffe738e4a:/libs/numeric/bindings/lapack/doc/index.html
Any advice about the overall linking/compiling process using boost numeric bindings+LAPACK would be appreciated. I honestly haven't been able to find any good examples online.
So I figured out my problem(s) -- there were several,-- and I thought I should answer my own question so that others might benefit.
First off, my LAPACK installation was incorrect. I had downloaded the 64-bit version instead of the 32-bit version. Even though it's 2015, somehow I'm stuck using a 32-bit version of the lapack dll...
Secondly, linking in Eclipse works a little differently than I thought. Going to the project properties, C/C++ Build -> Settings -> Tool Settings -> MinGW C++ Linker -> Libraries allows you to link libraries. Under the top libraries option (-l), I added lapack and blas. Under the bottom Library search path (-L), I added the location of the .dll files.
At this point, I could run sample LAPACK code, just not use the boost numeric bindings. Thirdly, I figured out what the numeric bindings traits includes were. From the traits overview page, I was able to figure out that in order to use particular vector or matrix class in bindings to LAPACK, I had to include proper traits specialization. For instance, using the boost::numeric::ublas::matrix object and sending it to LAPACK required including the trait header file <boost/numeric/bindings/traits/ublas_matrix.hpp>.
This solved my error that you see from the original post, and I could use the boost numeric bindings. Finally, I had messed up my example code because I didn't actually understand what gesvd was doing. It was just a test program, so it's no big deal, but I'll attach the working code below to show the singular value decomposition that I had initially attempted.
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/bindings/lapack/gesvd.hpp>
#include <boost/numeric/bindings/traits/ublas_matrix.hpp>
#include <boost/numeric/bindings/traits/ublas_vector.hpp>
#include <boost/numeric/bindings/traits/ublas_vector2.hpp>
typedef boost::numeric::ublas::matrix<int> iMatrix;
typedef boost::numeric::ublas::matrix<double> dMatrix;
typedef boost::numeric::ublas::vector<int> iVector;
typedef boost::numeric::ublas::vector<double> dVector;
namespace ublas = boost::numeric::ublas;
namespace lapack = boost::numeric::bindings::lapack;
void function() {
int n = 10;
dMatrix jacobi(n,n); // then actually initialize it
dVector eigenvals(n);
//int error = lapack::gesvd('S','S', jacobi, eigenvals, eigenvects1, eigenvects2);
int error = lapack::syevd('V','L', jacobi, eigenvals, lapack::optimal_workspace() );
std::cout << eigenvals << std::endl;
std::cout << jacobi << std::endl;
}