Hello!
I have the following data structure:
typedef vector< vector<int> > MxInt2d;
typedef vector< vector<double> > MxDouble2d;
class QSweep{
public:
....
static MxDouble2d myPoints_;
MxInt2d myEdges_;
MxInt2d sweepEvents;
class order{
public:
bool operator() (const vector<int>& edge1, const vector<int>& edge2){
return (myPoints_[edge1[0]][0]<myPoints_[edge2[0]][0])||
(myPoints_[edge1[0]][0]==myPoints_[edge2[0]][0]&&
myPoints_[edge1[0]][1]<myPoints_[edge2[0]][1])
||
(myPoints_[edge1[0]][0]==myPoints_[edge2[0]][0]&&
myPoints_[edge1[0]][1]==myPoints_[edge2[0]][1]&&
getSlope(myPoints_[edge1[0]][0],myPoints_[edge1[0][1],
myPoints_[edge1[1]][0],myPoints_[edge1[1]][1])
<
getSlope(myPoints_[edge2[0][0],myPoints_[edge2[0][1],
myPoints_[edge2[1]][0],myPoints_[edge2[1]][1]));
}
};
static double getSlope(double a, double b, double c, double d);
static double computeDet(double a, double b, double c, double d, double x, double y);
};
I use the functor for order() when defining the constructor in the following way:
QSweep::QSweep(const MxDouble2d& myPoints, const MxInt2d& myEdges){
....
//code here for initializing myPoints_, myEdges_
sort(myEdges_.begin(),myEdges_.end(),order());
}
In this way my data myEdges_ are arranged when initialized using the functor order(). Now I want to arrange the data sweepEvents (which has the same type as myEdges_ using the predefined data type from C++ vector) using a totally different criteria, that is I do not want to use the function getSlope(...) but the function computeDet(...) for sweepEvents. So I was thinking I still need other functor for redefining the < of sort() for the vector data type right? So I would have to write a new functor order1() in which I use the data computed with computeDet(...) and then I call the sort on my sweepEvents data types:
sort(sweepEvents.begin(),sweepEvents.end(),order1());
I am not sure if this is the good solution? can I redefine in several ways < if I use different names for the functor? Is someone has some suggestions I would be really grateful. Thank you in advance, madalina
No the two functors does not use any common code. I have written the second functor insede the QSweep class as this:
class orderDet{
public:
bool operator() (const vector<int>& edgeSW1, const vector<int>& edgeSW2
,const vector<int>& edgeC){
return
(
computeDet(myPoints_[edgeSW1[0]],myPoints_[edgeSW1[1]],myPoints_[edgeC[0]])
<
computeDet(myPoints_[edgeSW2[0]],myPoints_[edgeSW2[1]],myPoints_[edgeC[0]])
);
}}
and I called it like:
sort(sweepEvents.begin(), sweepEvents.end(), orderDet());
But I got the following compilation error:
error: no match for call to '(QSweepComplete::orderDet) (std::vector<int,
std::allocator<int> >&, std::vector<int, std::allocator<int> >&)'
./QSweepComplete.h:68: note: candidates are: bool
QSweepComplete::orderDet::operator()(const std::vector<int, std::allocator<int>>&,
const std::vector<int, std::allocator<int> >&, const std::vector<int,
std::allocator<int> >&)
I am guessing the parameter do not match, as the third parameter of orderDet(...., edgeC) is not part of sweepEvents list as the others are but is part of the variable myEdges_... Maybe one can give me some suggestions on how to implement this functor?
thank you in advance. best wishes, madalina