//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void TrimRegions(const region::REGIONS ®s, const size_t nregs, region::REGIONS &newregs, size_t &new_nregs) { new_nregs=0; for (size_t i=0;i<nregs;i++) { if (regs[i].size()>region::MINREGIONSIZE) { newregs[new_nregs++]=regs[i]; } } if (new_nregs>=region::MAXNOREGIONS) { std::vector<bool> sampled(new_nregs); region::REGIONS newnewregs(region::MAXNOREGIONSB4TRIM); for (size_t i=0;i<new_nregs;i++) sampled[i]=false; size_t newnew_nregs=0; std::srand(time(NULL)); size_t nloops=0,maxnloops=region::MAXNOREGIONSB4TRIM; do { size_t sidx=std::rand()%new_nregs; if (!sampled[sidx]) { sampled[sidx]=true; newnewregs[newnew_nregs]=newregs[sidx]; newnew_nregs++; } nloops++; }while (newnew_nregs<(region::MAXNOREGIONS-1) && nloops<maxnloops); newregs=newnewregs; new_nregs=newnew_nregs; } }
void downsampling_fractal_animation::downsampling_worker::render(double t) { fullres_worker->render(t); image_RGB &fullres = fullres_worker->get_color_image(); size_t factor = fullres.x() / sampled_sum.x(); size_t factor2 = factor * factor; std::fill(sampled_sum.begin(), sampled_sum.end(), vec3{0, 0, 0}); for (size_t i = 0; i < fullres.x(); i++) { for (size_t j = 0; j < fullres.y(); j++) { RGB color = fullres(i, j); sampled_sum(i / factor, j / factor) += vec3{ double(color.r), double(color.g), double(color.b), }; } } for (size_t z = 0; z < sampled_sum.size(); z++) { sampled(z) = RGB{ (unsigned char) (sampled_sum(z)[0] / factor2), (unsigned char) (sampled_sum(z)[1] / factor2), (unsigned char) (sampled_sum(z)[2] / factor2), }; } }
void AnalogPin::setRawValue(int v) { if(v != d->value) { d->value = v; emit valueChanged(); } emit sampled(); }
ZSwcTree* ZSwcGenerator::createSwcByRegionSampling( const ZVoxelArray &voxelArray, double radiusAdjustment) { #ifdef _DEBUG_2 voxelArray.print(); #endif ZDoubleVector voxelSizeArray(voxelArray.size()); const std::vector<ZVoxel> &voxelData = voxelArray.getInternalData(); //Retrieve voxel size for (size_t i = 0; i < voxelSizeArray.size(); ++i) { voxelSizeArray[i] = -voxelData[i].value(); } std::vector<int> indexArray; voxelSizeArray.sort(indexArray); std::vector<bool> sampled(voxelArray.size(), true); for (size_t i = 1; i < voxelArray.size(); ++i) { size_t currentVoxelIndex = indexArray[i]; const ZVoxel ¤tVoxel = voxelData[currentVoxelIndex]; for (size_t j = 0; j < i; ++j) { size_t prevVoxelIndex = indexArray[j]; if (sampled[prevVoxelIndex]) { const ZVoxel &prevVoxel = voxelData[prevVoxelIndex]; double dist = currentVoxel.distanceTo(prevVoxel); if (dist < prevVoxel.value()) { sampled[currentVoxelIndex] = false; break; } } } } Swc_Tree_Node *prevTn = NULL; for (size_t i = 0; i < voxelArray.size(); ++i) { if (sampled[i]) { Swc_Tree_Node *tn = SwcTreeNode::makePointer(); SwcTreeNode::setPos( tn, voxelData[i].x(), voxelData[i].y(), voxelData[i].z()); SwcTreeNode::setRadius( tn, voxelData[i].value() + radiusAdjustment); Swc_Tree_Node_Set_Parent(tn, prevTn); prevTn = tn; } } ZSwcTree *tree = new ZSwcTree; tree->setDataFromNodeRoot(prevTn); return tree; }
void sampling (std::vector<Patch*>& patches, double threhold) { //collect all the edges.. //typedef std::pair<Vertex*, Vertex*> VertexPair; //std::set< VertexPair > pairset; typedef std::pair< std::pair<Vertex*, Vertex*>, int> SampledPoint; std::map<SampledPoint, Vertex*> spmap; for (auto p : patches) { std::cout << "patch!\n"; size_t cornerSize = p->corners.size(); for (size_t i = 0 ; i < cornerSize; ++i) { Vertex *v0 = p->corners[i]; Vertex *v1 = p->corners[(i + 1) % cornerSize]; std::cout <<"v0: " << v0->point()[0] << " " << v0->point()[1] << " " << v0->point()[2] << "\n"; std::cout <<"v1: " << v1->point()[0] << " " << v1->point()[1] << " " << v1->point()[2] << "\n"; const Point p0 = v0->point(); const Point p1 = v1->point(); double length = (p0 - p1).norm(); p->sampledPoints.push_back(v0); if (length > threhold) { int numpt = length / threhold; for (int j = 1; j < numpt; ++j) { SampledPoint sp = std::make_pair( std::make_pair(v0, v1), j); //well, looking for the vertex is it's been created. Vertex *v_new = spmap[sp]; if (!v_new) { double lambda = (double) j / numpt; Point newp = p0 * (1- lambda) + p1 * lambda; v_new = new Vertex; v_new->index() = -1; v_new->point() = newp; spmap[sp] = v_new; sp = std::make_pair(std::make_pair(v1, v0), numpt - j); spmap[sp] = v_new; } else { std::cout << "found match! "; } std::cout << " new pt" << v_new->point()[0] << " " <<v_new->point()[1] << " " << v_new->point()[2] << "\n"; for (int j = 0; j < p->sampledPoints.size(); ++j) { Point chkp = p->sampledPoints[j]->point(); if ( (chkp - v_new->point()).norm() < 1e-6) { std::cout << "cat!\n"; } } p->sampledPoints.push_back(v_new); } } } } //okay, let's save out all the patches.. char buf[128]; for (size_t i = 0; i < patches.size(); ++i) { Patch *p = patches[i]; sprintf_s(buf, "patch_%02d", i + 1); std::ofstream output(buf); int vid = 0; size_t spSize = p->sampledPoints.size(); for (size_t j = 0; j < spSize; ++j) { Vertex *v = p->sampledPoints[j]; output << "Vertex " << ++vid << " " << v->point()[0] << " " << v->point()[1] << " " << v->point()[2]; if (v->index() < 0) { output << " {new}"; } output << "\n"; } for (size_t j = 0; j < spSize; ++j) { output << "Edge " << j + 1 << " " << (j + 1) % spSize + 1 << "\n"; } output.close(); } std::ofstream sampled("sampled.m"); std::set<Vertex*> verset; std::map<Vertex*, int> nowOrder; int vid = 0; for (auto p : patches) { for (auto v: p->sampledPoints) { auto it = verset.insert(v); if (it.second) { nowOrder[v] = ++vid; sampled << "Vertex " << vid << " " << v->point()[0] << " " << v->point()[1] << " " << v->point()[2] << "\n"; } } } int fid = 0; for (auto p : patches) { sampled << "Face " << ++fid << " "; for (auto v : p->sampledPoints) { sampled << nowOrder[v] << " "; } sampled << "\n"; } sampled.close(); }