boost::geometry multi_point can't be constructed like polygon - c++

First off, a big thanks to the people behind the new boost::geometry library!
This question replaces an earlier one which I have now split into two as two separate issues have become clearer.
I have read http://www.boost.org/doc/libs/1_47_0/libs/geometry/doc/html/geometry/design.html which explains the traits mechanism but am none the wiser as to why this code doesn't compile...
//code to calculate area of convex hull from a set of points
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/multi/geometries/multi_point.hpp>
double convex_hull_area()
{
using boost::geometry::model::d2::point_xy;
using boost::geometry::append;
using boost::geometry::make;
//this bit works if I use a polygon instead of multi_point
boost::geometry::model::multi_point<point_xy<float> > all_points_in_radius;
append(all_points_in_radius,make<point_xy<float> >(0,0));
append(all_points_in_radius,make<point_xy<float> >(3,0));
append(all_points_in_radius,make<point_xy<float> >(3,3));
append(all_points_in_radius,make<point_xy<float> >(2,1));
boost::geometry::model::polygon<point_xy<float> > hull;
boost::geometry::convex_hull(all_points_in_radius,hull);
return boost::geometry::area(hull);
}
The first error is
Error 1 error C2039: 'apply' : is not a member of 'boost::geometry::dispatch::for_each_range<Tag,Geometry,Actor,IsConst>' d:\boost\boost_1_47_0\boost\geometry\algorithms\detail\for_each_range.hpp 115 boost_geom_test
If I use a polygon instead of a multipoint, the code works just fine, though presumably with overheads I don't need. What is going on?

This turned out to be a bug in boost. It is now fixed in the head revision and should roll out in 1.49.0.

Related

How to proper set up a destructor in C++ with Xcode?

there is something that has been bugging me for a while.
I cannot create a destructor using Xcode (with other IDEs like VS2021 that is no issue).
I get the error:
1. Constructor cannot be redeclared
2. Missing return type for function '˜Pointer'; did you mean the constructor name 'Pointer'?
If I try to declare outside of the class and uncomment the lines in *.cpp and *.hpp the errors get even crazier.
My Pointers.hpp is the following:
#ifndef Pointers_hpp
#define Pointers_hpp
#include <iostream>
class Pointer{
public:
Pointer(void);
˜Pointer(void){};
//˜Pointer(void);
};
#endif /* Pointers_hpp */
and my Pointers.cpp is this one:
#include "Pointers.hpp"
Pointer::Pointer(void){};
//Pointer::˜Pointer(void){};
After several research in the internet, I could not find a solution to that, could any one give me a light on this?
Many thanks in advance,
Raphael
Solved thanks to user4581301:
For those having the same problem I did.
The issue here was the similarity between ˜ and ~
The correct one should be ~
If you are using MacBook Pro the short-key is Option-N.

How to export STEP to STL into separate files using OpenCascade and C++

I'm looking for methods to export a STEP file into separate STL ones, and extracting relevant information from each of the parts (such as position in the whole model, rotation [if any], colors, and material [if possible]), so I use those in another program that needs STL inputs.
So far I have been trying to work with OpenCascade, but I'm a complete newbie there, and haven't had the proper progress. The code I've been working with so far is shown below (it's just a sample I found in the examples, but I don't really understand the outputs).
#include <iostream>
#include <STEPControl_Reader.hxx>
//#include <STEPCAFControl_Reader.hxx>
#include <Interface_Static.hxx>
#include <string>
int main(){
STEPControl_Reader CAFReader;
IFSelect_ReturnStatus Status = CAFReader.ReadFile("/home/User/Geometry/Module.step");
Standard_Integer ic = Interface_Static::SetIVal("read.precision.mode",1);
Standard_Real rp = Interface_Static::SetRVal("read.precision.val",0.0001);
cout<<ic<<endl;
cout<<rp<<endl;
What I would really need would be the export separate files in .stl and ideally vector(s) containing (for each of the parts):
Position
Rotation
Color
Material
Any inputs would be highly appreciated :)
Thank you in advance.

Unit test for a vector

Please,I was searching it here, but couldn't do it correctly.
So I have a function which returns to me the vector of sortig numbers. Then I tried to create a using test for this very vector.
Here is what I have right now:
#include "stdafx.h"
#include "CppUnitTest.h"
#include "Finder.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace FinderUnitTest
{
TEST_CLASS(UnitTest1)
{
public:
TEST_METHOD(TestMethod1)
{
Finder f;
std::vector<int> v1 = f.find_words();
//find_words(); is working okay without tests
for (int i=0;i<1;i++)
Assert::AreEqual(57,v1[i]);
}
};
}
It really doesn't matter, how many time for goes. I'd like to get the unit test without mistake, I have one right now, it is:
Message: Invalid parameter detected in function std::vector >::operator [], c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\vector line 1795. Expression: "vector subscript out of range"
How I get that when I build my two projects, my fuction, which returns the vector of sorting numbers,doesn't have any data because when I run the test,there is empty. Am I right?
I just want to compare two first numbers of my vector with 57.
If you are expecting find_words to return a vector like [57, 57, ...] then this test should fail. However, it should not error, but rather it should Assert. You want to fix your checks so they detect the problem as an assert violation.
Finder f;
std::vector<int> v1 = f.find_words();
Assert::IsTrue(v1.size() >= 2); // there are at least two entries
Assert::AreEqual(57,v1[0]); // the first is 57
Assert::AreEqual(57,v1[1]); // the second is 57
I don't see where you gave finder anything to search, but if you say it should find 57's, you're the boss. Just be sure to check that. Once the unittest gives this assert, the unittest has done its job, and you can go back and see if you gave Finder the right inputs, or if there is a bug inside Finder.
X21's comment was good programming practice about how to detect and avoid the crash. It fixes the crash by not checking the values at all, since to do so would be an error. It was not directed at writing a unit test. The unit test must detect and assert when the output is not what you expect. Crashing would be better than not checking at all, inside a test.

'MSize' is not a member of cv::Mat

I'm trying to run this repo for curiosity: https://github.com/jzeimen/PuzzleSolver/tree/master/PuzzleSolver
Eclipse throws the title error "'MSize' is not a member of cv::Mat' whenever I try to run the following line of code from PuzzleDisjointSet.cpp:
cv::Mat::MSize size_of_a = sets[rep_a].locations.size;
Where locations is defined like so:
struct forest{
cv::Mat_<int> locations;
cv::Mat_<int> rotations;
int representative;
int id;
};
and sets is a vector version of the forest structure. I'm mainly confused as to why this is occurring, when documentation clearly refutes this.
I believe the header files I am including are the correct ones (PuzzleDisjointSet.h includes the above forest structure definition as well as the sets definition.
#include "PuzzleDisjointSet.h"
#include <algorithm>
#include <opencv2/core.hpp>
#include <opencv/cv.h>
#include <opencv2/core/mat.hpp>
the struct was removed in this commit
https://github.com/Itseez/opencv/commit/d8c8339bec83b77978d2a0e1a62b764fb9d9c599#diff-bc1d784738cd852f5b1e95ce10a56d06
maybe you can checkout a version before that and use it, or i suspect it may have been moved to a different class, you can try looking for that
OpenCV version: 4.3.0
cv::MatSize size_of_a = sets[rep_a].locations.size;

How to predict class of a instance in Waffles c++ API

my name is titiri and happy that I found waffle library to classification. I think waffle is a good library for machine learning algorithms.
I have a question about waffle library.
After training a model, I want print a prediction, for a instance:
my code is:
GMatrix Instance(1,8);//instance have 8 real attribute and
double out;// value in attribute 'class' is nomial
Instance[0][0]=6;
Instance[0][1]=148;
Instance[0][2]=72;
Instance[0][3]=35;
Instance[0][4]=0;
Instance[0][5]=33.6;
Instance[0][6]=0.62;
Instance[0][7]=50;
modell->predict(Instance[0],&out);
cout<<&out;
This code do not work true and does not print anything.
Please help me!
What do I need to predict class of a instance , then print its class,
have a good performance 'predict' method for classify a instance?
Or is there a better method for this work ?
thanks,
Be happy and win
I suspect the reason your code does not print anything is because you forgot the endl. (This is what Joachim Pileborg mentioned in his comment.)
If you are using Visual Studio, you may want to add a breakpoint at the end of your code (maybe on the return statement) because in certain modes it can close your application before you get to see the output, which can make it seem as if nothing happened.
Example
What follows is a full example that works fine for me. It includes your instance. It loads a K-nearest neighbors learner from 2blobs_knn.json and then evaluates your instance on it. You can replace that file name with the name of any trained supervised model generated by the waffles tools.
With the model I used, the program prints "1" and exits.
If you want to use the exact model that I tested my code with (in case your method of constructing your learner is the problem) see the section after the example code.
#include <GClasses/GMatrix.h>
#include <GClasses/GHolders.h>
#include <GClasses/GRand.h>
#include <GClasses/GLearner.h>
#include <GClasses/GDom.h>
#include <iostream>
#include <cassert>
using namespace GClasses;
using std::cout; using std::endl;
int main(int argc, char *argv[])
{
//Load my trained learner from a file named 2blobs_knn.json and put
//it in hModel which is a shared-pointer class.
GLearnerLoader ll(GRand::global());
GDom dom;
dom.loadJson("2blobs_knn.json");
Holder<GSupervisedLearner> hModel(ll.loadSupervisedLearner(dom.root()));
assert(hModel.get() != NULL);
//Here is your code
GMatrix Instance(1,8);// Instance has 8 real attributes and one row
double out; // The value in attribute 'class' is nominal
Instance[0][0]=6;
Instance[0][1]=148;
Instance[0][2]=72;
Instance[0][3]=35;
Instance[0][4]=0;
Instance[0][5]=33.6;
Instance[0][6]=0.62;
Instance[0][7]=50;
hModel.get()->predict(Instance[0],&out);
cout << out << endl;
return 0;
}
How the learner I used in the example was constructed
To get the learner, I used Matlab (Octave is the free imitator) to generate a CSV file in which class 0 was an 8-dimensional spherical unit Gaussian centered at (0,0,0,0,0,0,0,0) and class 1 had the same distribution but centered at (2,2,2,2,2,2,2,2)
m=[[randn(200,8);randn(200,8)+2], [repmat(0,200,1);repmat(1,200,1)]];
csvwrite('2blobs.csv',m)
Then, I took that CSV, converted it to ARFF using
waffles_transform import 2blobs.csv > 2blobs.arff
Next, I changed the last attribute from #ATTRIBUTE attr8 real to
#ATTRIBUTE class {0,1} in a text editor so it would be nominal.
Finally, I trained the model with
waffles_learn train 2blobs.arff knn -neighbors 10 > 2blobs_knn.json