view src/conndef.h @ 893:f34897bc944f

connectivity: move the validate() static methods into the constructor. * conndef.cc (Fiptconncheck): this function performs a bunch of logic that is useful for a constructor from octave_value. But if we move it there, then all the validate static methods are no longer needed, and we can just check by calling the constructor. (invalid_connectivity): an exception class so we can give meaningful error messages on why the constructor failed (and the check failed). (Fconncheck): make the position arg optional. * conndef.h: declare new exception class for incorrect connectivity arguments, remove the validate methods and add them to the constructor
author Carnë Draug <carandraug@octave.org>
date Thu, 02 Oct 2014 16:39:05 +0100
parents a2140b980079
children
line wrap: on
line source

// Copyright (C) 2014 Carnë Draug <carandraug@octave.org>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see
// <http://www.gnu.org/licenses/>.

#ifndef OCTAVE_IMAGE_CONNDEF
#define OCTAVE_IMAGE_CONNDEF

#include <stdexcept>

#include <octave/oct.h>

namespace octave
{
  namespace image
  {
    class connectivity
    {
      public:
        connectivity ();

        //! Will throw if val is bad
        connectivity (const octave_value& val);
        connectivity (const boolNDArray& mask);
        connectivity (const octave_idx_type& conn);
        connectivity (const octave_idx_type& ndims, const std::string& type);

        boolNDArray mask;

        // For a matrix of size `size', what are the offsets for all of its
        // connected elements (will have negative and positive values).
        Array<octave_idx_type> offsets (const dim_vector& size) const;

      private:
        void ctor (const boolNDArray& mask);
        void ctor (const octave_idx_type& conn);

        //! Like octave_value::double_value() but actually checks if scalar.
        static double double_value (const octave_value& val);

        //! Like octave_value::bool_array_value() but actually checks if
        //! all values are zeros and one.
        static boolNDArray bool_array_value (const octave_value& val);
    };

    class invalid_connectivity : public std::invalid_argument
    {
      public:
        invalid_connectivity (const std::string& what_arg)
          : std::invalid_argument (what_arg) { }
    };
  }
}

#endif