ON_NurbsSurface Split Method

Having trouble getting the ON_NurbsSurface srf.Split method to work. Parameter 3 is looking for a reference to a pointer(??) so getting compiler error. I implemented code from the example in the opennurbs_nurbssurface.h file and can’t get it to work.
Example:
int dir = 1;
ON_NurbsSurface* south_side = 0;
ON_NurbsSurface* north_side = 0;
nurbs_srf->Split( dir, nurbs_srf->Domain(dir).Mid(), south_side, north_side );
Compiler error I’m getting is: error C2664: ‘ON_NurbsSurface::Split’ : cannot convert parameter 3 from ‘ON_NurbsSurface *’ to ‘ON_Surface *&’

After googeling references to pointers in function arguments I implemented the code as suggested:
int dir = 1;
ON_NurbsSurface south_side = 0;
ON_NurbsSurface* psouth_side = &south_side;
ON_NurbsSurface* north_side = 0;
nurbs_srf->Split( dir, nurbs_srf->Domain(dir).Mid(), &psouth_side, north_side ); and still doesn’t work.

Compiler doesn’t like the reference to pointer:
error C2664: ‘ON_NurbsSurface::Split’ : cannot convert parameter 3 from ‘ON_NurbsSurface **’ to ‘ON_Surface *&’

Can’t figure out what to do. Have any suggestions?

Steve

ON_NurbsSurface::Split wants a reference to a ON_Surface pointer, not a ON_NurbsSurface pointer. So, you can do this:

  int dir = 1; 
  ON_Surface* south_side = 0; 
  ON_Surface* north_side = 0; 
  ON_BOOL32 rc = nurbs_srf->Split( 
    dir, 
    nurbs_srf->Domain(dir).Mid(), 
    south_side, 
    north_side 
    ); 

  if( rc && south_side && north_side )
  {
    // TODO..

    // Don't leak...
    delete south_side;
    delete north_side;
  }

Does this help?

Yes, it does thank you! Code is compiling now.
Sort of an oversight on my part since the function is asking for these parameters:
ON_BOOL32 Split(
int dir,
double c,
ON_Surface*& west_or_south_side,
ON_Surface*& east_or_north_side
) const;

However, the example right above it shows using ON_NurbsSurface* south_side = 0;. Might want to clean up the .h file before next release.
I thought since ON_NurbsSurface is an inherited class from ON_Surface it would work.

Thanks for the prompt reply!

Steve

Dale,
Again thank you. Now I would like a different point other than the Mid() point. I have points on the surface I have evaluated using EvPoint and would like to use one of those points as the location to split the surface. Unsuccessful in implementation. Is there a method that does this?

ON_Surface::EvPoint evaluates a surface at a u,v parameter and returns a 3-D point. ON_Surface::Split want, as input either a u or v parameter depending on the direction of the splitting. So if you have a 3-D point that you want to split at, you will need to use ON_Surface::GetClosestPoint to obtain the u,v parameter that is closest to the test point.

If you are using the standalone openNURBS toolkit, this will be a problem as ON_Surface::GetClosestPoint is not implemented.

http://wiki.mcneel.com/developer/opennurbs/limitations

If you just using openNURBS within the context of the Rhino SDK, then this sample might be helpful.

https://github.com/mcneel/Rhino5Samples_CPP/blob/master/SampleCommands/cmdSampleSplitSurface.cpp

Let me know if you have questions.