void igs::hls_add::change( unsigned char *image_array, const int height, const int width, const int channels, const int bits , const unsigned char *noi_image_array, const int noi_height, const int noi_width, const int noi_channels, const int noi_bits , const unsigned char *ref /* 求める画像と同じ高、幅、channels数 */ , const int ref_bits /* refがゼロのときはここもゼロ */ , const int ref_mode /* 0=R,1=G,2=B,3=A,4=Luminance,5=Nothing */ , const int xoffset, const int yoffset, const int from_rgba, const double offset, const double hue_scale, const double lig_scale, const double sat_scale, const double alp_scale , const bool add_blend_sw) { if ((0.0 == hue_scale) && (0.0 == lig_scale) && (0.0 == sat_scale) && (0.0 == alp_scale)) { return; } if ((igs::image::rgba::siz != channels) && (igs::image::rgb::siz != channels) && (1 != channels) /* grayscale */ ) { throw std::domain_error("Bad channels,Not rgba/rgb/grayscale"); } /* ノイズ参照画像を作成する */ noise_ref_ noi( noi_image_array , noi_height, noi_width, noi_channels, noi_bits , xoffset, yoffset, from_rgba); /* rgb(a)画像にhls(a)でドットノイズを加える */ if ((std::numeric_limits<unsigned char>::digits == bits) && ((std::numeric_limits<unsigned char>::digits == ref_bits) || (0 == ref_bits))) { change_template_( image_array, height, width, channels, noi, ref, ref_mode, offset, hue_scale, lig_scale, sat_scale, alp_scale, add_blend_sw); } else if ((std::numeric_limits<unsigned short>::digits == bits) && ((std::numeric_limits<unsigned char>::digits == ref_bits) || (0 == ref_bits))) { change_template_( reinterpret_cast<unsigned short *>(image_array), height, width, channels, noi, ref, ref_mode, offset, hue_scale, lig_scale, sat_scale, alp_scale, add_blend_sw); } else if ((std::numeric_limits<unsigned short>::digits == bits) && (std::numeric_limits<unsigned short>::digits == ref_bits)) { change_template_( reinterpret_cast<unsigned short *>(image_array), height, width, channels, noi, reinterpret_cast<const unsigned short *>(ref), ref_mode, offset, hue_scale, lig_scale, sat_scale, alp_scale, add_blend_sw); } else if ((std::numeric_limits<unsigned char>::digits == bits) && (std::numeric_limits<unsigned short>::digits == ref_bits)) { change_template_( image_array, height, width, channels, noi, reinterpret_cast<const unsigned short *>(ref), ref_mode, offset, hue_scale, lig_scale, sat_scale, alp_scale, add_blend_sw); } else { throw std::domain_error("Bad bits,Not uchar/ushort"); } }
// if fwd, C,N,CA are C,N,CA, else assumed to be N,C,CA void InformedPhipsiSampler::sample( vector<float>& curC, vector<float>& curN, vector<float>& curCA, float & phi, float & psi, float & omega, float & r, float & a, float & t) { float d0 = calcDist(target, curCA); float cisdist = 2.8, transdist = 3.81; bool cis = false, trans = false; if(cisdist > d0 - targetTol && cisdist < d0 + targetTol) cis = true; if(transdist > d0 - targetTol && transdist < d0 + targetTol) trans = true; if(cis && trans) { // if both cis and trans are possible, choose one if(ran01() > 0.95) trans = false; } else if(!cis && !trans) { cout << "target unreachable " <<curCA[0]<<" "<<curCA[1]<<" "<<curCA[2] << " : " << d0 <<" : "<< targetTol <<" : "<< target[0]<<" "<<target[1]<<" "<<target[2] << endl; exit(0); } // now either cis or trans is true float interCA; if(cis) { omega = 0; interCA = cisdist; } if(trans) { omega = -180; interCA = transdist; } phi = -999; psi = -999; // find a,t which take u into restraint sphere with this interCA vector<float> tar(3,0), noi(3,0); while(1) { // add some noise to target, proportional to noise randomNormalVector(noi); linear_combination(tar, 1, target, targetTol*ran01(), noi); // for this interCA, find a,t that takes you closest to target r = calcDist(curCA, tar); a = calcAngle(curN, curCA, tar); t = calcDihed(curC, curN, curCA, tar); find4thPoint(tar, curC, curN, curCA, interCA, a, t); if( calcDist(target, tar) <= targetTol ) break; } // return a phi-psi value for this a,t if available if(fwd) { RATdata & ratdata = RATdata::fwdinstance(RATdataPath.c_str()); vector<PSO>::iterator bi, ei; ratdata.range(resn, interCA, a, t, bi, ei); int rs = ei - bi; assert(rs >= 0); if(rs == 0) { return; } int incr = (int) floor ( (0.+rs) * ran01() ); bi += incr; phi = bi->r; psi = bi->a; omega = bi->t; } else { RATdata & ratdata = RATdata::bwdinstance(RATdataPath.c_str()); vector<PSO>::iterator bi, ei; ratdata.range(resn, interCA, a, t, bi, ei); int rs = ei - bi; assert(rs >= 0); if(rs == 0) { return; } int incr = (int) floor ( (0.+rs) * ran01() ); bi += incr; psi = bi->r; phi = bi->a; omega = bi->t; } //cout << phi <<" "<< psi <<" "<< omega << " shd take u from ("<< curCA[0]<<" "<< curCA[1]<<" "<< curCA[2] <<" "; //vector<float> exppt(3,0); //find4thPoint(exppt, curC, curN, curCA, interCA, a, t); //cout << ") to ("<< exppt[0]<<" "<< exppt[1]<<" "<< exppt[2] <<") " << endl;; }