void CMarchingCubeRenderer::Process() { if(m_bInitialized) return; m_bInitialized = true; int sizeX = m_displayData->GetSizeX(); int sizeY = m_displayData->GetSizeY(); int sizeZ = m_displayData->GetSizeZ(); //计算三个方向的长度,将它缩放到 1x1x1的范围内 //中心在(0.5,0.5,0.5) vector3df * _3dPosition = new vector3df[sizeX*sizeY*sizeZ]; int posIndex = 0; //#define max(a,b) ((a)>(b)?(a):(b)) //float voxelSize = 1.0f/(max(max(sizeX,sizeY),sizeZ)); float voxelSize = 1.0f; //#undef max float fscale = 1.0f/(std::max(sizeX*m_displayData->GetScaleX(),std::max(sizeY*m_displayData->GetScaleY(),sizeZ*m_displayData->GetScaleZ()))); kk::core::vector3df min_pos(0,0,0); kk::core::vector3df max_pos(sizeX*m_displayData->GetScaleX()*fscale, sizeY*m_displayData->GetScaleY()*fscale, sizeZ*m_displayData->GetScaleZ()*fscale); float maxValue = 1.0f/std::max(std::max(max_pos.X,max_pos.Y),max_pos.Z); max_pos *= maxValue; //中心为 kk::core::vector3df center = (min_pos + max_pos)*0.5f; //是要移动到(0.5,0.5,0.5),所以偏移量为: kk::core::vector3df offset=kk::core::vector3df(0.5,0.5,0.5) - center; for(int x=0;x<sizeX;x++) for(int y=0;y<sizeY;y++) for(int z=0;z<sizeZ;z++) { posIndex = x+y*sizeX+z*sizeX*sizeY; //最大轴变为了1 _3dPosition[posIndex].X = x*m_displayData->GetScaleX()*fscale +offset.X; _3dPosition[posIndex].Y = y*m_displayData->GetScaleY()*fscale +offset.Y; _3dPosition[posIndex].Z = z*m_displayData->GetScaleZ()*fscale +offset.Z; //移动到中心来 //就加上了偏移 //posIndex++; } vector3df origin;//(-10,-10,-10); origin.X=0; origin.Y=0; origin.Z=0; //if(mc) // delete mc; mc = new MarchingCube(sizeX, sizeY, sizeZ, (float*)(m_displayData->GetRawData()), _3dPosition, origin, voxelSize, 0.95f); //delete[] _3dPosition; }
INLINE_IF_HEADER_ONLY Annotation const DomainGraph:: annotate ( Component const& vertices ) const { uint64_t D = data_ ->parameter_ . network() . size (); std::vector<uint64_t> limits = data_ -> parameter_ . network() . domains (); std::vector<uint64_t> domain_indices ( vertices.begin(), vertices.end() ); std::vector<uint64_t> min_pos(D); std::vector<uint64_t> max_pos(D); for ( int d = 0; d < D; ++ d ) { min_pos[d] = limits[d]; max_pos[d] = 0; } for ( int d = 0; d < D; ++ d ) { for ( uint64_t & v : domain_indices ) { uint64_t pos = v % limits[d]; v = v / limits[d]; min_pos[d] = std::min(min_pos[d], pos); max_pos[d] = std::max(max_pos[d], pos); } } std::vector<uint64_t> signature; for ( int d = 0; d < D; ++ d ) { if ( min_pos[d] != max_pos[d] ) { signature . push_back ( d ); } } Annotation a; std::stringstream ss; if ( signature . size () == 0 ) { ss << "FP"; bool all_on = true; bool all_off = true; for ( int d = 0; d < D; ++ d ) { if ( min_pos[d] == 0 ) all_on = false; else all_off = false; } if ( all_on ) ss << " ON"; if ( all_off) ss << " OFF"; } else if ( signature . size () == D ) { ss << "FC"; } else { ss << "XC {"; bool first_term = true; for ( uint64_t d : signature ) { if ( first_term ) first_term = false; else ss << ", "; ss << data_ ->parameter_ . network() . name ( d ); } ss << "}"; } a . append ( ss . str () ); return a; }
int Ca_Axis_::update(){ double _k=k_; double _q=q_; min_pos_=min_pos(); max_pos_=max_pos(); if (min_==max_) k_=0; else if(scale_ & CA_LOG){ k_=(max_pos_-min_pos_)/(log(max_)-log(min_)); q_=min_pos_-k_*log(min_); }else{ k_=(max_pos_-min_pos_)/(max_-min_); q_=min_pos_; } if((_k!=k_)||(_q!=q_)) return 1; else return 0; };
sf::Vector2i ShipTemplate::interiorSize() { sf::Vector2i min_pos(1000, 1000); sf::Vector2i max_pos(0, 0); for(unsigned int n=0; n<rooms.size(); n++) { min_pos.x = std::min(min_pos.x, rooms[n].position.x); min_pos.y = std::min(min_pos.y, rooms[n].position.y); max_pos.x = std::max(max_pos.x, rooms[n].position.x + rooms[n].size.x); max_pos.y = std::max(max_pos.y, rooms[n].position.y + rooms[n].size.y); } if (min_pos != sf::Vector2i(1, 1)) { sf::Vector2i offset = sf::Vector2i(1, 1) - min_pos; for(unsigned int n=0; n<rooms.size(); n++) rooms[n].position += offset; for(unsigned int n=0; n<doors.size(); n++) doors[n].position += offset; max_pos += offset; } max_pos += sf::Vector2i(1, 1); return max_pos; }
void CompNovoIdentificationBase::selectPivotIons_(vector<Size> & pivots, Size left, Size right, Map<DoubleReal, CompNovoIonScoringBase::IonScore> & ion_scores, const PeakSpectrum & CID_spec, DoubleReal precursor_weight, bool full_range) { #ifdef SELECT_PIVOT_DEBUG cerr << "void selectPivotIons(pivots[" << pivots.size() << "], " << left << "[" << CID_spec[left].getPosition()[0] << "]" << ", " << right << "[" << CID_spec[right].getPosition()[0] << "])" << endl; #endif Size max_number_pivot(param_.getValue("max_number_pivot")); // TODO better heuristic, MAX_PIVOT dynamic from range if (right - left > 1) { right -= 1; left += 1; if (right - left < 1 || CID_spec[right].getPosition()[0] - CID_spec[left].getPosition()[0] < 57.0 - fragment_mass_tolerance_) { return; } // use more narrow window // diff between border and new pivot should be at least 57 - fragment_mass_tolerance (smallest aa) Size new_right(right), new_left(left); for (Size i = left - 1; i < right && CID_spec[i].getPosition()[0] - CID_spec[left - 1].getPosition()[0] < 57.0 - fragment_mass_tolerance_; ++i) { new_left = i; } for (Size i = right + 1; i > new_left && CID_spec[right + 1].getPosition()[0] - CID_spec[i].getPosition()[0] < 57.0 - fragment_mass_tolerance_; --i) { new_right = i; } #ifdef SELECT_PIVOT_DEBUG cerr << "new_left=" << new_left << "(" << CID_spec[new_left].getPosition()[0] << "), new_right=" << new_right << "(" << CID_spec[new_right].getPosition()[0] << ")" << endl; #endif left = new_left; right = new_right; if (!(right - left > 1)) { return; } Size old_num_used(0); set<Size> used_pos; for (Size p = 0; p != min(right - left - 1, max_number_pivot); ++p) { DoubleReal max(0); Size max_pos(0); bool found_pivot(false); for (Size i = left + 1; i < right; ++i) { DoubleReal score = ion_scores[CID_spec[i].getPosition()[0]].score; DoubleReal position = CID_spec[i].getPosition()[0]; #ifdef SELECT_PIVOT_DEBUG cerr << position << " " << precursor_weight << " " << full_range << " " << score; #endif if (score >= max && used_pos.find(i) == used_pos.end()) { // now check if a very similar ion is already selected +/- 3Da //bool has_similar(false); /* for (set<Size>::const_iterator it = used_pos.begin(); it != used_pos.end(); ++it) { if (fabs(CID_spec[*it].getPosition()[0] - CID_spec[i].getPosition()[0]) < 1.5) { has_similar = true; } }*/ // TODO this rule should be toggable if (!(full_range && (position < precursor_weight / 4.0 || position > precursor_weight / 4.0 * 3.0))) { #ifdef SELECT_PIVOT_DEBUG cerr << " max score greater"; #endif max = score; max_pos = i; found_pivot = true; } } #ifdef SELECT_PIVOT_DEBUG cerr << endl; #endif } used_pos.insert(max_pos); // no pivot ion was added if (!found_pivot || (old_num_used == used_pos.size() && old_num_used != 0)) { return; } else { old_num_used = used_pos.size(); } pivots.push_back(max_pos); max = 0; } } return; }
Vector<Vector<double> > DepthDetector::EvaluateTemplate(const Matrix<double> &upper_body_template, const Matrix<double> &depth_map, Vector<Vector<double> > &close_range_BBoxes, Vector<Vector<double> > distances) { int stride = Globals::evaluation_stride; int nr_scales = Globals::evaluation_nr_scales; int inc_cropped_height = Globals::evaluation_inc_cropped_height; // performance helper variables: just for avoiding recalculation int int_half_template_size = Globals::template_size / 2; double double_half_template_size = Globals::template_size / 2.0; Vector<Vector<double> > final_result; // generate the scales Vector<double> all_scales(nr_scales, 1.0); all_scales(0) = 1; for(int sc = 1; sc < nr_scales; ++sc) { all_scales(sc) = pow(Globals::evaluation_scale_stride,sc); } ////////////////////////////////////////////// if(visualize_roi) roi_image = Matrix<int>(Globals::dImWidth, Globals::dImHeight, 0); ////////////////////////////////////////////// for (int i = 0; i < close_range_BBoxes.getSize(); i++) { Vector<Vector<double> > result; int cropped_height = (int)(close_range_BBoxes(i)(3)/2.0); close_range_BBoxes(i)(1) -= (close_range_BBoxes(i)(3) * Globals::evaluation_inc_height_ratio)/2.0; if( close_range_BBoxes(i)(1)+cropped_height >= Globals::dImHeight) cropped_height = Globals::dImHeight - (int)close_range_BBoxes(i)(1) - 1; if(Globals::verbose) cout << "(distances(i) " << distances(i)(0) << " radius " << distances(i)(1)/2.0 << endl; // Cropped and Filter depth_map with respect to distance from camera int start_column = (int)close_range_BBoxes(i)(0); int end_column = (int)(close_range_BBoxes(i)(0) + close_range_BBoxes(i)(2)); int start_row = (int)max(0.0, close_range_BBoxes(i)(1)); int end_row = (int)close_range_BBoxes(i)(1) + cropped_height; Matrix<double> cropped(end_column-start_column+1, end_row-start_row+1); double min_distance_threshold = distances(i)(0)- (distances(i)(1)+0.2)/2.0; double max_distance_threshold = distances(i)(0)+ (distances(i)(1)+0.2)/2.0; for(int ii = 0, ii_depth = start_column; ii < cropped.x_size(); ii++, ii_depth++) { for(int jj = 0, jj_depth = start_row; jj < cropped.y_size(); jj++, jj_depth++) { if(depth_map(ii_depth,jj_depth) <= min_distance_threshold || depth_map(ii_depth,jj_depth) >= max_distance_threshold) { cropped(ii, jj) = 0; } else { cropped(ii, jj) = depth_map(ii_depth, jj_depth); } } } //////////////// just for test (must be removed) if(visualize_roi) { for(int tmpx=start_column, tmpxx=0; tmpxx<cropped.x_size(); tmpx++,tmpxx++) { for(int tmpy=start_row, tmpyy=0; tmpyy<cropped.y_size(); tmpy++,tmpyy++) { if(tmpyy==0 || tmpyy==cropped.y_size()-1 || tmpxx==0 || tmpxx==cropped.x_size()-1) roi_image(tmpx,tmpy)=i+1; if(cropped(tmpxx,tmpyy)!=0) roi_image(tmpx,tmpy)=i+1; } } } ////////////////////////////////////////////////// // Resize Cropped - with respect to template double ratio = close_range_BBoxes(i)(3) / (Globals::template_size * 3.0); int new_height = (int)(cropped.y_size() * all_scales(nr_scales-1) / ratio); int new_width = (int)(cropped.x_size() * all_scales(nr_scales-1) / ratio); if(ratio > 1) { cropped.DownSample(new_width, new_height); } else if(ratio < 1) { cropped.UpSample(new_width, new_height); } Matrix<double> copy_cropped = cropped; for(int scale_index = 0; scale_index < all_scales.getSize(); scale_index++) { cropped = copy_cropped; // Resize Cropped in loop with different scales int xSizeCropped = (int)(cropped.x_size() / all_scales(scale_index)); int ySizeCropped = (int)(cropped.y_size() / all_scales(scale_index)); if(all_scales(scale_index) != 1) cropped.DownSample(xSizeCropped , ySizeCropped); Matrix<double> extended_cropped(xSizeCropped + Globals::template_size, ySizeCropped+inc_cropped_height, 0.0); extended_cropped.insert(cropped, (int)(double_half_template_size)-1, 0); int distance_x_size = ceil((extended_cropped.x_size()-Globals::template_size)/(double)stride); int distance_y_size = ceil((ySizeCropped + inc_cropped_height - Globals::template_size - 1)/(double)stride); Matrix<double> resulted_distances(distance_x_size, distance_y_size); Matrix<double> resulted_medians(distance_x_size, distance_y_size); for(int y = 0, yyy = 0; yyy<distance_y_size; y=y+stride, yyy++) { for(int x = 0, xxx = 0; xxx<distance_x_size; x=x+stride, xxx++) { double sum = 0; int x_size = min(extended_cropped.x_size()-1, x+Globals::template_size) - x; int y_size = min(extended_cropped.y_size()-1, y+Globals::template_size) - y; int start_row = (int)max(0.0, y + y_size/2.0-5); int end_row = (int)min((double)Globals::dImHeight-1, y + y_size/2.0+5); int start_column = (int)max(0.0, x + x_size/2.0-5); int end_column = (int)min((double)Globals::dImWidth-1, x + x_size/2.0+5); // Normalize the cropped part of the image. regarding the current position of the template; // Crop only some pixels in the middle double median = AncillaryMethods::MedianOfMatrixRejectZero(extended_cropped, start_row, end_row, start_column, end_column); if(median == 0) { resulted_distances(xxx,yyy) = 1000; continue; } int x_start_of_temp = max(0, int_half_template_size - x); double x_end_of_temp = min(Globals::template_size, extended_cropped.x_size() - int_half_template_size -x); int evaluating_area = (x_end_of_temp - x_start_of_temp)*Globals::template_size+1; if(evaluating_area > Globals::template_size * double_half_template_size) { for(int x_of_temp = x_start_of_temp; x_of_temp < x_end_of_temp; x_of_temp++) { int x_of_extended_cropp = x + x_of_temp; for(int y_of_temp = 0; y_of_temp < Globals::template_size; y_of_temp++) { double difference = upper_body_template(x_of_temp, y_of_temp)-extended_cropped(x_of_extended_cropp, y_of_temp+y)/median; sum += difference*difference; } } resulted_distances(xxx,yyy) = sum/(double)evaluating_area; resulted_medians(xxx,yyy) = median; } else { resulted_distances(xxx,yyy) = 1000; } } } Vector<Vector<double> > max_pos; AncillaryMethods::NonMinSuppression2d(resulted_distances, max_pos, Globals::evaluation_NMS_threshold); int n_xSizeTemp = (int)(Globals::template_size*ratio/all_scales(scale_index)); for(int j = 0; j < max_pos.getSize(); j++) { Vector<double> bbox(6); bbox(0) = (max_pos(j)(0)*stride-double_half_template_size)*ratio/all_scales(scale_index) + close_range_BBoxes(i)(0); bbox(1) = (max_pos(j)(1)*stride)*ratio/all_scales(scale_index) +close_range_BBoxes(i)(1); bbox(2) = n_xSizeTemp; bbox(3) = n_xSizeTemp; bbox(4) = resulted_distances((int)max_pos(j)(0),(int)max_pos(j)(1)); bbox(5) = resulted_medians((int)max_pos(j)(0),(int)max_pos(j)(1)); result.pushBack(bbox); } } static int oo=0; char pp[300]; sprintf(pp,"/home/hosseini/r_%08d_0.txt",oo++); Matrix<double>(result).WriteToTXT(pp); AncillaryMethods::GreedyNonMaxSuppression(result, Globals::evaluation_greedy_NMS_overlap_threshold, Globals::evaluation_greedy_NMS_threshold, upper_body_template, final_result); } return final_result; }
void SubThreadStage() { ResIdentifierPtr psmm_input = ResLoader::Instance().Open(ps_desc_.res_name); KlayGE::XMLDocument doc; XMLNodePtr root = doc.Parse(psmm_input); { XMLNodePtr particle_node = root->FirstNode("particle"); { XMLNodePtr alpha_node = particle_node->FirstNode("alpha"); ps_desc_.ps_data->particle_alpha_from_tex = alpha_node->Attrib("from")->ValueString(); ps_desc_.ps_data->particle_alpha_to_tex = alpha_node->Attrib("to")->ValueString(); } { XMLNodePtr color_node = particle_node->FirstNode("color"); { Color from; XMLAttributePtr attr = color_node->Attrib("from"); if (attr) { std::vector<std::string> strs; boost::algorithm::split(strs, attr->ValueString(), boost::is_any_of(" ")); for (size_t i = 0; i < 3; ++ i) { if (i < strs.size()) { boost::algorithm::trim(strs[i]); from[i] = static_cast<float>(atof(strs[i].c_str())); } else { from[i] = 0; } } } from.a() = 1; ps_desc_.ps_data->particle_color_from = from; Color to; attr = color_node->Attrib("to"); if (attr) { std::vector<std::string> strs; boost::algorithm::split(strs, attr->ValueString(), boost::is_any_of(" ")); for (size_t i = 0; i < 3; ++ i) { if (i < strs.size()) { boost::algorithm::trim(strs[i]); to[i] = static_cast<float>(atof(strs[i].c_str())); } else { to[i] = 0; } } } to.a() = 1; ps_desc_.ps_data->particle_color_to = to; } } } { XMLNodePtr emitter_node = root->FirstNode("emitter"); XMLAttributePtr type_attr = emitter_node->Attrib("type"); if (type_attr) { ps_desc_.ps_data->emitter_type = type_attr->ValueString(); } else { ps_desc_.ps_data->emitter_type = "point"; } XMLNodePtr freq_node = emitter_node->FirstNode("frequency"); if (freq_node) { XMLAttributePtr attr = freq_node->Attrib("value"); ps_desc_.ps_data->frequency = attr->ValueFloat(); } XMLNodePtr angle_node = emitter_node->FirstNode("angle"); if (angle_node) { XMLAttributePtr attr = angle_node->Attrib("value"); ps_desc_.ps_data->angle = attr->ValueInt() * DEG2RAD; } XMLNodePtr pos_node = emitter_node->FirstNode("pos"); if (pos_node) { float3 min_pos(0, 0, 0); XMLAttributePtr attr = pos_node->Attrib("min"); if (attr) { std::vector<std::string> strs; boost::algorithm::split(strs, attr->ValueString(), boost::is_any_of(" ")); for (size_t i = 0; i < 3; ++ i) { if (i < strs.size()) { boost::algorithm::trim(strs[i]); min_pos[i] = static_cast<float>(atof(strs[i].c_str())); } else { min_pos[i] = 0; } } } ps_desc_.ps_data->min_pos = min_pos; float3 max_pos(0, 0, 0); attr = pos_node->Attrib("max"); if (attr) { std::vector<std::string> strs; boost::algorithm::split(strs, attr->ValueString(), boost::is_any_of(" ")); for (size_t i = 0; i < 3; ++ i) { if (i < strs.size()) { boost::algorithm::trim(strs[i]); max_pos[i] = static_cast<float>(atof(strs[i].c_str())); } else { max_pos[i] = 0; } } } ps_desc_.ps_data->max_pos = max_pos; } XMLNodePtr vel_node = emitter_node->FirstNode("vel"); if (vel_node) { XMLAttributePtr attr = vel_node->Attrib("min"); ps_desc_.ps_data->min_vel = attr->ValueFloat(); attr = vel_node->Attrib("max"); ps_desc_.ps_data->max_vel = attr->ValueFloat(); } XMLNodePtr life_node = emitter_node->FirstNode("life"); if (life_node) { XMLAttributePtr attr = life_node->Attrib("min"); ps_desc_.ps_data->min_life = attr->ValueFloat(); attr = life_node->Attrib("max"); ps_desc_.ps_data->max_life = attr->ValueFloat(); } } { XMLNodePtr updater_node = root->FirstNode("updater"); XMLAttributePtr type_attr = updater_node->Attrib("type"); if (type_attr) { ps_desc_.ps_data->updater_type = type_attr->ValueString(); } else { ps_desc_.ps_data->updater_type = "polyline"; } if ("polyline" == ps_desc_.ps_data->updater_type) { for (XMLNodePtr node = updater_node->FirstNode("curve"); node; node = node->NextSibling("curve")) { std::vector<float2> xys; for (XMLNodePtr ctrl_point_node = node->FirstNode("ctrl_point"); ctrl_point_node; ctrl_point_node = ctrl_point_node->NextSibling("ctrl_point")) { XMLAttributePtr attr_x = ctrl_point_node->Attrib("x"); XMLAttributePtr attr_y = ctrl_point_node->Attrib("y"); xys.push_back(float2(attr_x->ValueFloat(), attr_y->ValueFloat())); } XMLAttributePtr attr = node->Attrib("name"); size_t const name_hash = RT_HASH(attr->ValueString().c_str()); if (CT_HASH("size_over_life") == name_hash) { ps_desc_.ps_data->size_over_life_ctrl_pts = xys; } else if (CT_HASH("mass_over_life") == name_hash) { ps_desc_.ps_data->mass_over_life_ctrl_pts = xys; } else if (CT_HASH("opacity_over_life") == name_hash) { ps_desc_.ps_data->opacity_over_life_ctrl_pts = xys; } } } } RenderFactory& rf = Context::Instance().RenderFactoryInstance(); RenderDeviceCaps const & caps = rf.RenderEngineInstance().DeviceCaps(); if (caps.multithread_res_creating_support) { this->MainThreadStage(); } }