nmwsharp / variational-surface-cutting

Codebase for "Variational Surface Cutting" by Sharp & Crane, SIGGRAPH 2018
GNU General Public License v2.0
94 stars 16 forks source link

Running from command line #2

Open lukkio88 opened 4 years ago

lukkio88 commented 4 years ago

Hi, is it possible to run your tool from command line without passing through the GUI?

nmwsharp commented 4 years ago

Hi!

No, no command line options are implemented at this time.

Could certainly be done though. Just a matter of writing some argument-parsing code and calling the same methods the buttons in the UI call.

lukkio88 commented 4 years ago

Can you just point out what's the main function (not the void main(...) but the function that actually does the cutting) and how do I pass the options (like the optimizer options and everything)? So I have a starting point.

Thank you

nmwsharp commented 4 years ago

Sure! The project structure is a bit hard to follow here; it's been extracted from a multi-project repo which is no longer in use :sweat_smile: I'd love to refactor all this, but just don't have the time at the moment.

The main class is the EulerianShapeOptimizer, which has all the parameters and main logic. It's not quuiiiite as simple as calling a single function in EulerianShapeOptimizer to generate results---you will need to call a small handful of functions to mimic the way the GUI interacts with the class.

You can see the GUI interacting with the class here. That also includes the headers you should need for any other functions.

Off the top of my head, you'll want something like:

Geometry<Euclidean> geometry = /* load your geometry from file */

EulerianShapeOptimizer shapeOpt(geometry);

// set some parameters
shapeOpt.weightLengthRegularization = 1.0;
shapeOpt.weightHenckyDistortion = 3.0;

// initialize with normal clustering
VertexData<LabelVec> normalPhi = normalClusterMSDF(geometry, PI/3.0);
shapeOpt.setState(normalPhi);
shapeOpt.iIter = 0;

// step the optimization
for(size_t iter = 0; iter < 300; iter++) {
  shapeOpt.doStep();
}

// save resulting patches
CornerData<Vector2> paramCoords;
Geometry<Euclidean>* cutGeodesicGeom = shapeOpt.getGeodesicFlattenedGeometry(paramCoords); 
FaceData<int> faceComponents = computeFaceComponents(cutGeodesicGeom, paramCoords);
WavefrontOBJ::write("out.obj", *cutGeodesicGeom, paramCoords);

(I haven't run that code, so it almost certainly has problems, but hopefully it can get you started)

lukkio88 commented 4 years ago

Thank you! Let me give it a go and I'll get back to you.

lukkio88 commented 4 years ago

Hi, this was really helpful. Thank you so much, one very last question... Is there a way to normalize the texture coordiantes generated in the interval [0,1]? I know this is obviously an easy thing to do but maybe you've an API for this already.

Thank you

nmwsharp commented 4 years ago

Great! Glad it's been helpful.

It doesn't look like there's any built-in function here for normalizing to the unit interval. But as you say that shouldn't be too difficult!

Best, Nick