Alternaria
fit cylinders and ellipsoids to fungus
|
00001 /* 00002 * This work is licensed under a Creative Commons 00003 * Attribution-Noncommercial-Share Alike 3.0 United States License. 00004 * 00005 * http://creativecommons.org/licenses/by-nc-sa/3.0/us/ 00006 * 00007 * You are free: 00008 * 00009 * to Share - to copy, distribute, display, and perform the work 00010 * to Remix - to make derivative works 00011 * 00012 * Under the following conditions: 00013 * 00014 * Attribution. You must attribute the work in the manner specified by the 00015 * author or licensor (but not in any way that suggests that they endorse you 00016 * or your use of the work). 00017 * 00018 * Noncommercial. You may not use this work for commercial purposes. 00019 * 00020 * Share Alike. If you alter, transform, or build upon this work, you may 00021 * distribute the resulting work only under the same or similar license to 00022 * this one. 00023 * 00024 * For any reuse or distribution, you must make clear to others the license 00025 * terms of this work. The best way to do this is by including this header. 00026 * 00027 * Any of the above conditions can be waived if you get permission from the 00028 * copyright holder. 00029 * 00030 * Apart from the remix rights granted under this license, nothing in this 00031 * license impairs or restricts the author's moral rights. 00032 */ 00033 00034 00046 #include <config.h> 00047 00048 #include <iostream> 00049 00050 #include <jwsc++/base/exception.h> 00051 00052 #include "density.h" 00053 00054 00055 using std::ostream; 00056 using std::istream; 00057 using jwscxx::base::Arg_error; 00058 00059 00066 Density::Uniform_params::Uniform_params(float min, float max) throw (Arg_error) 00067 { 00068 set(min, max); 00069 } 00070 00071 00078 void Density::Uniform_params::set(float min, float max) throw (Arg_error) 00079 { 00080 if (min > max) 00081 { 00082 throw Arg_error("Minimum larger than maximum"); 00083 } 00084 00085 this->min = min; 00086 this->max = max; 00087 } 00088 00089 00094 ostream& Density::operator<< 00095 ( 00096 ostream& out, 00097 const Density::Uniform_params& params 00098 ) 00099 { 00100 return out << params.min << ' ' << params.max; 00101 } 00102 00103 00108 istream& Density::operator>> 00109 ( 00110 istream& in, 00111 Density::Uniform_params& params 00112 ) 00113 { 00114 in >> params.min; 00115 in >> params.max; 00116 return in; 00117 } 00118 00119 00129 Density::Gaussian_params::Gaussian_params 00130 ( 00131 float mu, 00132 float sigma, 00133 float min, 00134 float max 00135 ) 00136 throw (Arg_error) 00137 { 00138 set(mu, sigma, min, max); 00139 } 00140 00141 00151 void Density::Gaussian_params::set 00152 ( 00153 float mu, 00154 float sigma, 00155 float min, 00156 float max 00157 ) 00158 throw (Arg_error) 00159 { 00160 if (min > max) 00161 { 00162 throw Arg_error("Minimum larger than maximum"); 00163 } 00164 if (mu < min || mu > max) 00165 { 00166 throw Arg_error("Mean not in min/max range"); 00167 } 00168 if (sigma < 1.0e-8) 00169 { 00170 throw Arg_error("Sigma too small"); 00171 } 00172 00173 this->mu = mu; 00174 this->sigma = sigma; 00175 this->min = min; 00176 this->max = max; 00177 } 00178 00179 00184 ostream& Density::operator<< 00185 ( 00186 ostream& out, 00187 const Density::Gaussian_params& params 00188 ) 00189 { 00190 return out << params.mu << ' ' << params.sigma << ' ' 00191 << params.min << ' ' << params.max; 00192 } 00193 00194 00199 istream& Density::operator>> 00200 ( 00201 istream& in, 00202 Density::Gaussian_params& params 00203 ) 00204 { 00205 in >> params.mu; 00206 in >> params.sigma; 00207 in >> params.min; 00208 in >> params.max; 00209 return in; 00210 }