Trying to run ofxClipper on 0.9.8


#1

Hey y’all,

I’m trying to run Baker’s ofxClipper example on version 0.9.8
( https://github.com/bakercp/ofxClipper ) and I’m getting two errors:

"No matching member function for call to ‘push_back’ " which occurs when the following are called:

  1. clipMasks.getOutline().push_back( p )
  2. clipSubjects.getOutline().push_back( r )

Binding value of type ‘const vector<…>’ to reference to type ‘vector<…>’ drops ‘const’ qualifier” which occurs when the following are called:

  1. clips.getOutline()
  2. simplifiedPath.getOutline()

Any idea on how to fix this?


#2

I’m writting without seeing code but seems like getOutlime() function returns “const vector” type which is read-only. So you can not push_back().
You could copy returning vector into your local vector variable. This copy operation could cost expensive but depends on your logic.

Qucik dirty hack is removing “const” from addon.
Or use “const_cast” on your app side.


#3

Also if those methods return are marked as const it’s usually because the original author doesn’t want you to modify them. If you modify them by removing const from the addon it’ll probably break down cause the internal logic relies upon those vectors not being modified externally


#4

Could you give a bit more context for your code? As @arturo notes, if it’s const then I intended it not to be modified for some reason, but I’m unsure what you are trying to do.


#5

Hey y’all, thanks for your responses!

@bakercp , I’m trying to run https://github.com/bakercp/ofxClipper/tree/master/example . In the actual ofxClipper.cpp I’m getting

“Binding value of type ‘const vector<…>’ to reference to type ‘vector<…>’ drops ‘const’ qualifier” error for this code:

void ofxClipper::ofPath_to_Polygons(ofPath&amp; path,ClipperLib::Paths&amp; polygons) {
    return ofxPolylines_to_Polygons(path.getOutline(),polygons);
} 

and

“No matching member function for call to ‘push_back’” for this code:

void ofxClipper::polygons_to_ofPath(ClipperLib::Paths& polygons,ofPath& path) {
    vector<ClipperLib::Path>::iterator iter;
    for(iter = polygons.begin(); iter != polygons.end(); iter++) {
        path.getOutline().push_back(polygon_to_ofPolyline((*iter)));
    }
}

I’m also getting several errors in the example code, where it’s trying to push back a polyline onto an ofPath

clipSubjects.push_back(r);

I tried adding the points manually to the ofPath in cases such as this^ and I eventually got rid of some of the errors but it didn’t fully work.


#6

I think this is because ofPath changed in 0.10 . See this old issue in the forum Add ofPolyline to ofPath


#7

I just pushed updates of ofxClipper including an updated API. Please check it out if you’re still having issues.


#8

sick! I’ll check it out