mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-11-02 20:51:23 -07:00 
			
		
		
		
	Unite cancel callback and status function
This commit is contained in:
		
							parent
							
								
									de8bb00fa9
								
							
						
					
					
						commit
						46fd722f3c
					
				
					 3 changed files with 20 additions and 18 deletions
				
			
		| 
						 | 
				
			
			@ -92,10 +92,9 @@ Transform3f to_transform3f(const XYRotation &rot)
 | 
			
		|||
 | 
			
		||||
} // namespace
 | 
			
		||||
 | 
			
		||||
Vec2d find_best_rotation(const SLAPrintObject &        po,
 | 
			
		||||
                         float                         accuracy,
 | 
			
		||||
                         std::function<void(unsigned)> statuscb,
 | 
			
		||||
                         std::function<bool()>         stopcond)
 | 
			
		||||
Vec2d find_best_rotation(const SLAPrintObject &   po,
 | 
			
		||||
                         float                    accuracy,
 | 
			
		||||
                         std::function<bool(int)> statuscb)
 | 
			
		||||
{
 | 
			
		||||
    static const unsigned MAX_TRIES = 1000;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -108,7 +107,7 @@ Vec2d find_best_rotation(const SLAPrintObject &        po,
 | 
			
		|||
    mesh.require_shared_vertices();
 | 
			
		||||
 | 
			
		||||
    // To keep track of the number of iterations
 | 
			
		||||
    unsigned status = 0;
 | 
			
		||||
    int status = 0;
 | 
			
		||||
 | 
			
		||||
    // The maximum number of iterations
 | 
			
		||||
    auto max_tries = unsigned(accuracy * MAX_TRIES);
 | 
			
		||||
| 
						 | 
				
			
			@ -118,7 +117,11 @@ Vec2d find_best_rotation(const SLAPrintObject &        po,
 | 
			
		|||
 | 
			
		||||
    auto statusfn = [&statuscb, &status, &max_tries] {
 | 
			
		||||
        // report status
 | 
			
		||||
        statuscb(unsigned(++status * 100.0/max_tries) );
 | 
			
		||||
        statuscb(++status * 100.0/max_tries);
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    auto stopcond = [&statuscb] {
 | 
			
		||||
        return ! statuscb(-1);
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    // Preparing the optimizer.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,19 +19,19 @@ namespace sla {
 | 
			
		|||
  * @param accuracy The optimization accuracy from 0.0f to 1.0f. Currently,
 | 
			
		||||
  * the nlopt genetic optimizer is used and the number of iterations is
 | 
			
		||||
  * accuracy * 100000. This can change in the future.
 | 
			
		||||
  * @param statuscb A status indicator callback called with the unsigned
 | 
			
		||||
  * @param statuscb A status indicator callback called with the int
 | 
			
		||||
  * argument spanning from 0 to 100. May not reach 100 if the optimization finds
 | 
			
		||||
  * an optimum before max iterations are reached.
 | 
			
		||||
  * @param stopcond A function that if returns true, the search process will be
 | 
			
		||||
  * terminated and the best solution found will be returned.
 | 
			
		||||
  * an optimum before max iterations are reached. It should return a boolean
 | 
			
		||||
  * signaling if the operation may continue (true) or not (false). A status
 | 
			
		||||
  * value lower than 0 shall not update the status but still return a valid
 | 
			
		||||
  * continuation indicator.
 | 
			
		||||
  *
 | 
			
		||||
  * @return Returns the rotations around each axis (x, y, z)
 | 
			
		||||
  */
 | 
			
		||||
Vec2d find_best_rotation(
 | 
			
		||||
        const SLAPrintObject& modelobj,
 | 
			
		||||
        float accuracy = 1.0f,
 | 
			
		||||
        std::function<void(unsigned)> statuscb = [] (unsigned) {},
 | 
			
		||||
        std::function<bool()> stopcond = [] () { return false; }
 | 
			
		||||
        std::function<bool(int)> statuscb = [] (int) { return true; }
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
double get_model_supportedness(const SLAPrintObject &mesh,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,13 +21,12 @@ void RotoptimizeJob::process()
 | 
			
		|||
 | 
			
		||||
    if (!o || !po) return;
 | 
			
		||||
 | 
			
		||||
    Vec2d r = sla::find_best_rotation(*po, 0.75f,
 | 
			
		||||
        [this](unsigned s) {
 | 
			
		||||
            if (s < 100)
 | 
			
		||||
                update_status(int(s), _(L("Searching for optimal orientation")));
 | 
			
		||||
        },
 | 
			
		||||
        [this] () { return was_canceled(); });
 | 
			
		||||
    Vec2d r = sla::find_best_rotation(*po, 0.75f, [this](int s) {
 | 
			
		||||
        if (s > 0 && s < 100)
 | 
			
		||||
            update_status(s, _(L("Searching for optimal orientation")));
 | 
			
		||||
 | 
			
		||||
        return !was_canceled();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    double mindist = 6.0; // FIXME
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue