comparison src/graphics.cc @ 7836:4fb2db9c87dd

Turn cdata properties into array_property. Add min/max computation to array_property.
author Michael Goffioul <michael.goffioul@gmail.com>
date Thu, 21 Feb 2008 13:45:04 +0100
parents ca8b97bb952c
children d3dcfdfdc434
comparison
equal deleted inserted replaced
7835:ca8b97bb952c 7836:4fb2db9c87dd
424 av[i+lda] = cmapv[idx+nc]; 424 av[i+lda] = cmapv[idx+nc];
425 av[i+2*lda] = cmapv[idx+2*nc]; 425 av[i+2*lda] = cmapv[idx+2*nc];
426 } 426 }
427 427
428 return octave_value (a); 428 return octave_value (a);
429 }
430
431 template<class T>
432 static void
433 get_array_limits (const Array<T>& m, double& emin, double& emax,
434 double& eminp)
435 {
436 const T *data = m.data ();
437 int n = m.numel ();
438
439 for (int i = 0; i < n; i++)
440 {
441 double e = double (data[i]);
442
443 if (! (xisinf (e) || xisnan (e)))
444 {
445 if (e < emin)
446 emin = e;
447
448 if (e > emax)
449 emax = e;
450
451 if (e >= 0 && e < eminp)
452 eminp = e;
453 }
454 }
429 } 455 }
430 456
431 // --------------------------------------------------------------------- 457 // ---------------------------------------------------------------------
432 458
433 radio_values::radio_values (const std::string& opt_string) 459 radio_values::radio_values (const std::string& opt_string)
567 // check value type 593 // check value type
568 if (type_constraints.size () > 0) 594 if (type_constraints.size () > 0)
569 { 595 {
570 for (std::list<std::string>::const_iterator it = type_constraints.begin (); 596 for (std::list<std::string>::const_iterator it = type_constraints.begin ();
571 ! xok && it != type_constraints.end (); ++it) 597 ! xok && it != type_constraints.end (); ++it)
572 if ((*it) == v.type_name ()) 598 if ((*it) == v.class_name ())
573 xok = true; 599 xok = true;
574 } 600 }
575 else 601 else
576 xok = v.is_double_type (); 602 xok = v.is_double_type ();
577 603
601 else 627 else
602 return true; 628 return true;
603 } 629 }
604 630
605 return xok; 631 return xok;
632 }
633
634 void
635 array_property::get_data_limits (void)
636 {
637 xmin = xminp = octave_Inf;
638 xmax = -octave_Inf;
639
640 if (! data.is_empty ())
641 {
642 if (data.is_integer_type ())
643 {
644 if (data.is_int8_type ())
645 get_array_limits (data.int8_array_value (), xmin, xmax, xminp);
646 else if (data.is_uint8_type ())
647 get_array_limits (data.uint8_array_value (), xmin, xmax, xminp);
648 else if (data.is_int16_type ())
649 get_array_limits (data.int16_array_value (), xmin, xmax, xminp);
650 else if (data.is_uint16_type ())
651 get_array_limits (data.uint16_array_value (), xmin, xmax, xminp);
652 else if (data.is_int32_type ())
653 get_array_limits (data.int32_array_value (), xmin, xmax, xminp);
654 else if (data.is_uint32_type ())
655 get_array_limits (data.uint32_array_value (), xmin, xmax, xminp);
656 else if (data.is_int64_type ())
657 get_array_limits (data.int64_array_value (), xmin, xmax, xminp);
658 else if (data.is_uint64_type ())
659 get_array_limits (data.uint64_array_value (), xmin, xmax, xminp);
660 }
661 else
662 get_array_limits (data.array_value (), xmin, xmax, xminp);
663 }
606 } 664 }
607 665
608 void 666 void
609 handle_property::set (const octave_value& v) 667 handle_property::set (const octave_value& v)
610 { 668 {
2376 } 2434 }
2377 2435
2378 return retval; 2436 return retval;
2379 } 2437 }
2380 2438
2439 // FIXME: Remove in case all data_property are converted into
2440 // array_property
2381 static void 2441 static void
2382 check_limit_vals (double& min_val, double& max_val, double& min_pos, 2442 check_limit_vals (double& min_val, double& max_val, double& min_pos,
2383 const data_property& data) 2443 const data_property& data)
2444 {
2445 double val = data.min_val ();
2446 if (! (xisinf (val) || xisnan (val)) && val < min_val)
2447 min_val = val;
2448 val = data.max_val ();
2449 if (! (xisinf (val) || xisnan (val)) && val > max_val)
2450 max_val = val;
2451 val = data.min_pos ();
2452 if (! (xisinf (val) || xisnan (val)) && val > 0 && val < min_pos)
2453 min_pos = val;
2454 }
2455
2456 // FIXME: Maybe this should go into array_property class?
2457 static void
2458 check_limit_vals (double& min_val, double& max_val, double& min_pos,
2459 const array_property& data)
2384 { 2460 {
2385 double val = data.min_val (); 2461 double val = data.min_val ();
2386 if (! (xisinf (val) || xisnan (val)) && val < min_val) 2462 if (! (xisinf (val) || xisnan (val)) && val < min_val)
2387 min_val = val; 2463 min_val = val;
2388 val = data.max_val (); 2464 val = data.max_val ();
2679 { 2755 {
2680 graphics_object obj = gh_manager::get_object (kids(i)); 2756 graphics_object obj = gh_manager::get_object (kids(i));
2681 2757
2682 if (obj.isa ("image") || obj.isa ("patch") || obj.isa ("surface")) 2758 if (obj.isa ("image") || obj.isa ("patch") || obj.isa ("surface"))
2683 { 2759 {
2684 data_property cdata = obj.get_cdata_property (); 2760 array_property cdata = obj.get_cdata_property ();
2685 2761
2686 check_limit_vals (min_val, max_val, min_pos, cdata); 2762 check_limit_vals (min_val, max_val, min_pos, cdata);
2687 } 2763 }
2688 } 2764 }
2689 2765