typedef boost::geometry::model::d2::point_xy<double> boostPoint;
How to use boost::geometry::distance with opencv cv::Point without convertion to boostPoint?
double EuclideanDistance(const cv::Point2d &pt1, const cv::Point2d &pt2)
{
boostPoint boostPt1(pt1.x, pt1.y);
boostPoint boostPt2(pt2.x, pt2.y);
double distance= boost::geometry::distance(boostPt1, boostPt2);
return distance;
}
Update:
I tried this code, but it complaines to x error: ‘x’ has not been declared
BOOST_GEOMETRY_REGISTER_POINT_2D(cv::Point2d, double, boost::geometry::cs::cartesian, x, y)
Make sure you include the necessary header as indicated by the doc:
#include <boost/geometry/geometries/register/point.hpp>
If you want to make the code more elegant, just use the proper way. Boost is not a advantage if you added to your code. Since your points are OpenCV points, compute the distance using OpenCV like this:
double EuclideanDistance(const cv::Point2d &pt1, const cv::Point2d &pt2)
{
return cv::norm(pt1-pt2,cv::NORM_L2);
}
EDIT:
Since the OP need to do it in this way, I may suggest this solution: Create your own Point Class let us call it MyPoint. In MyPoint define copy constructors and conversation from and to cv::Point, boostPoint. In your code just use YourPoint everywhere. If you need help in implementing this just comment.
Related
I'm trying to implement a function to calculate inverse_chi_squared_distribution, boost has a container named inverse_chi_squared_distribution, however, when I try to create an instance of the class I get this error too few template arguments for class template 'inverse_chi_squared_distribution'.
I'm on wsl:ubuntu-18.04 and other boost functions/containers work fine.
Here's the code generating the error:
boost::math::inverse_chi_squared_distribution<double> invChi(degValue);
Not exactly sure how to calculate it even if this instance is created (was gonna just hit and miss till I get it) so help using this to calculate the function would be much appreciated, thanks.
OK, do you want the inverse of a chi-squared distribution (ie its quantile) or do you want the "inverse chi squared distribution" which is a distribution in it's own right, also with an inverse/quantile!
If the former, then assuming v degrees of freedom, and probability p then this would do it:
#include <boost/math/distributions/chi_squared.hpp>
double chi_squared_quantile(double v, double p)
{
return quantile(boost::math::chi_squared(v), p);
}
If the latter, then example usages might be:
#include <boost/math/distributions/inverse_chi_squared.hpp>
double inverse_chi_squared_quantile(double v, double p)
{
return quantile(boost::math::inverse_chi_squared(v), p);
}
double inverse_chi_squared_pdf(double v, double x)
{
return pdf(boost::math::inverse_chi_squared(v), x);
}
double inverse_chi_squared_cdf(double v, double x)
{
return cdf(boost::math::inverse_chi_squared(v), x);
}
There are other options - you can calculate with types other than double then you would use boost::math::inverse_chi_squared_distribution<MyType> in place of the convenience typedef inverse_chi_squared.
I have begun using CGAL and encountered an issue I am not able to solve. I load a model as a list of triangles and want to store additional information for each triangle - a color. I also want to use the AABB tree from CGAL but I have noticed that I have basically two options:
class DataTriangle {
public:
Point_3 x;
Point_3 y;
Point_3 z;
int color;
}
Follow the "AABB_custom_example.cpp" example and create a functor that converts my DataTriangle to a CGAL::Simple_cartesian::Triangle_3 every time. This wastes computation time because it constructs new Triangle_3 object every time.
I can make my own triangle and include Triangle_3 as a member:
class MyTriangle {
Triangle mTriangleCgal;
int color;
const Triangle& getTri() const { return mTriangleCgal; }
}
Then again declare a My_triangle_primitive functor, define
typedef K::Point_3 Point;
typedef K::Triangle_3 Datum;
typedef const K::Triangle_3& Datum_reference;
and reference the underlying triangle as such.
Datum_reference datum() { return tri->getTri(); }
Is this solution okay? I feel it should not waste time by constructing any new objects. Am I right?
The third idea I came up with is simply creating a custom iterator that will go through the vector of MyTriangles and instead of the class itself, return the Triangle_3 class. I should be able to pass this iterator into the AABB tree constructor and get the tree constructed from plain Triangle_3 objects, which should work just fine.
Is there another way of approach that I missed that is prefered to these three? Is number 2 okay to use if there is not another way?
Thank you
I can't find something like CCWaves(or CCLiquid etc) class in cocos2d v3.x.
but they are exist in cocos2d-x v2.x
so, is it really disappear in cocos2d v3.x? and are there some replaceable class i can use?
thanks! ;)
In my practice I have not used this effect. But in project ccp-tests can be found EffectsTest.cpp file. This file contains Waves::create() and Liquid::create() methods.
If you go over to the definition of a method, you can find such implementation in CCActionGrid3D.cpp:
Waves* Waves::create(float duration, const Size& gridSize, unsigned int waves, float amplitude, bool horizontal, bool vertical)
Liquid* Liquid::create(float duration, const Size& gridSize, unsigned int waves, float amplitude)
EDIT:
Oh, I just noticed, you compare cocos2d-X v.2.x and cocos2d v.3.x.
According to the Class Reference, no similar class in cocos2d. But you can find examples of such effect here, or migrate to cocos2d-x :)
i'm new to C++ trying to learn parallel programming (coming from Basic), got stuck fairly early on.
class Particle{
private:
double p_x, p_y, v_x, v_y, mass
public:
Particle(double px, double py, double vx, double vy, double m) : p_x(px), p_y(px), v_x(vx), v_y(vx), mass(m) {};
vector<int> pos () {p_x, p_y}; //doesn't work, expects ';'
vector<int> vel () {v_x, v_y}; //doesn't work, expects ';'
};
I'm trying to create a class with properties pos and vel, both vectors. HNothing worked with what i'm trying to do - initializing vectors i guess.
Can anyone tell me how to make that work? Or if not that something like this:
class Particle{
private:
double p_x, p_y, v_x, v_y, mass
public:
Particle(double px, double py, double vx, double vy, double m) : p_x(px), p_y(px), v_x(vx), v_y(vx), mass(m) {};
void SetPos(int x, int y) //pseudo code based on Basic
void GetPos() as Vector //pseudo code based on Basic
};
Thanks in advance for your time, this has been a brick wall for me for a while. I've looked trough many other threads like this one around here but I don't know enough to adapt any of it to my needs i guess. To complicate things I'm using VS2012 Cuda 6.0 project which sometimes even acts differently than the standard C++ project. Reverted to 6.0 because chrono refused to work in 6.5. Would use the standard project but I don't know how (if possible) to integrate Cuda into it.
The () indicates that they're functions, not variables; and the rest of the syntax isn't valid for a function definition. Either make them variables:
vector<int> pos {p_x, p_y};
or valid functions:
vector<int> pos () {return {p_x, p_y};}
You probably want them to be functions, so that they don't duplicate the values of the other members, and give the expected results if the other members are modified.
I'm writing an API for internal needs and so ease of use is one of the top priorities. I wonder if I'm pushing it too far as in the following example.
The function to solve the inverse geodetic problem takes in geocoordinates of two points and calculates distance between them and asimuths (angles) from each of the points to the other.
Ease-of-use-optimised conventional solution might look something like (please don't mind the length of the names, I know there's room for improvement):
class Angle;
class GeoCoordinate;
...
struct InverseGeodeticOut
{
Angle forwardAzimuth;
Angle backAzimuth;
double distance;
};
InverseGeodeticOut inverseGeodetic(const GeoCoordinate &firstPoint,
const GeoCoordinate &secondPoint);
// or
void inverseGeodetic(const GeoCoordinate &firstPoint,
const GeoCoordinate &secondPoint,
InverseGeodeticOut *result);
My question is how reasonable would it be to take it one step further to save user some typing:
class Angle;
class GeoCoordinate;
...
struct InverseGeodetic
{
InverseGeodetic();
InverseGeodetic(const GeoCoordinate &firstPoint,
const GeoCoordinate &secondPoint);
Angle forwardAzimuth;
Angle backAzimuth;
double distance;
};
// so the usages would be
InverseGeodeticOut inverse = inverseGeodetic(firstPoint, secondPoint);
InverseGeodeticOut inverse;
inverseGeodetic(firstPoint, secondPoint, &inverse);
InverseGeodetic inverse(firstPoint, secondPoint);
Perhaps in this particular example the difference is too small to be worth talking about but I wonder if such constructs are okay in general.
I like your 2nd code example, though I find the public constructor a bit confusing. Especially if there are other ways to construct an InverseGeodetic. I'd rather use a static factory method to construct it. That way you can give a more meaningful name to the method:
struct InverseGeodetic
{
Angle forwardAzimuth;
Angle backAzimuth;
double distance;
static InverseGeodetic FromTwoPoints(const GeoCoordinate &, const GeoCoordinate &);
};
// usage
auto inverse = InverseGeodetic::FromTwoPoints(a, b);
But then that might be my C# background bleeding through.