Ejemplo n.º 1
0
MSC_NAMESPACE_BEGIN

void RayBoundingbox::operator()(const tbb::blocked_range< size_t >& r)
{
  size_t begin = r.begin();
  size_t end = r.end();

  m_value.min[0] = m_data[begin].org[0];
  m_value.min[1] = m_data[begin].org[1];
  m_value.min[2] = m_data[begin].org[2];
  m_value.max[0] = m_data[begin].org[0];
  m_value.max[1] = m_data[begin].org[1];
  m_value.max[2] = m_data[begin].org[2];

  for(size_t index = begin; index < end; ++index)
  {
    if(m_data[index].org[0] < m_value.min[0])
      m_value.min[0] = m_data[index].org[0];
    if(m_data[index].org[1] < m_value.min[1])
      m_value.min[1] = m_data[index].org[1];
    if(m_data[index].org[2] < m_value.min[2])
      m_value.min[2] = m_data[index].org[2];

    if(m_data[index].org[0] > m_value.max[0])
      m_value.max[0] = m_data[index].org[0];
    if(m_data[index].org[1] > m_value.max[1])
      m_value.max[1] = m_data[index].org[1];
    if(m_data[index].org[2] > m_value.max[2])
      m_value.max[2] = m_data[index].org[2];
  }
}
Ejemplo n.º 2
0
    void operator () (const tbb::blocked_range<int> &range) const {
        for(int i=range.begin(); i<range.end(); i++) {
            list_node *node;
            if (addok(head, i, column)) {
                // add the node

#ifdef QUIT_ON_SOLUTION // QUIT as soon as a solution is found
                if (node!=NULL && solution == NULL) {
#endif
                    list_node new_node;
                    new_node.next = head;
                    new_node.row  = i;
                    if (column+1<SIZE) {
#ifdef CUTOFF
                        if (column+1>=CUTOFF_LEVEL)
                            ser_nqueens_rec(column+1, &new_node);
                        else
                            nqueens_rec(column+1, &new_node);
#else
                        nqueens_rec(column+1, &new_node);
#endif

                    } else { // found a solution 
                        //solution = &new_node;
                        solution_count++; //atomic
                        //abort()
                    }
#ifdef QUIT_ON_SOLUTION // QUIT as soon as a solution is found
                }
#endif
            } // end if addok
        // else do nothing -- dead computation branch
        }
    }
Ejemplo n.º 3
0
 void operator()( tbb::blocked_range<size_t>& range ) const {
     for( size_t i=range.begin(); i!=range.end(); ++i ) {
         typename M::scoped_lock lock(m_mutex);
         for ( size_t j = 0; j!=range.end(); ++j )
             s_anchor = (s_anchor - i) / 2 + (s_anchor + j) / 2;
     }
 }
Ejemplo n.º 4
0
  void operator()(const tbb::blocked_range<int>& range) const {
    GraphType::SrcSeedList seed_remove_list[2];

    /* compute cuts for each seed using the precomputation graph */
    for (int fg_idx = range.begin(); fg_idx != range.end(); ++fg_idx) {
      // copy the precomputation graph
      GraphType* g_fg_precomp = new GraphType(*g_precomp);
      (*g_fgs_precomp)[fg_idx] = g_fg_precomp;

      // get the fg seeds sans the current seed
      generate_seed_fix_list(seed_remove_list, *fg_nodes, fg_idx);
      // transform all S trees (sans the current seed) to sink
      g_fg_precomp->transform_seed_trees(fg_idx, seed_remove_list);

      g_fg_precomp->check_tree_integrity();

      // generate visualization after the seed tree transformation
      g_fg_precomp->generate_graph_visualization(
          node_rows, ((boost::format("graph1_%d") % (fg_idx + 1)).str()));

      // compute the cut after the precomputation for this seed
      int flow_fg_precomp = run_print_maxflow(g_fg_precomp, *fg_nodes,
                                              node_rows, true);

      // generate visualization after cut computation (and generate final pdf)
      g_fg_precomp->generate_graph_visualization(
          node_rows, ((boost::format("graph2_%d") % (fg_idx + 1)).str()));
      g_fg_precomp->generate_pdf_graphs(
          (boost::format("fg%d_precomp") % (fg_idx + 1)).str());
    }
  }
	void operator()(const tbb::blocked_range<int>& r) const
	{
		int begin = r.begin(),
			end = r.end();

		double dmax;
		
		//
		// Define precision(epsilon value)
		double e = .001;
		
		do
		{
			dmax = .0;
			for(int i = begin; i != end; ++i){
				for (int j = 1; j < N; ++j){
					temp_matrix[i][j] = 0.25*(tmatrix[i][j - 1] + tmatrix[i][j + 1] + tmatrix[i - 1][j] + tmatrix[i + 1][j]);
					double diff = fabs(temp_matrix[i][j] - tmatrix[i][j]);
					if (dmax < diff)
						dmax = diff;
					
					tmatrix[i][j] = temp_matrix[i][j];
				}
			}
		} while (dmax > e);
	}
Ejemplo n.º 6
0
template <typename PointInT, typename PointOutT> void
pcl::TBB_NormalEstimationTBB<PointInT, PointOutT>::operator () (const tbb::blocked_range <size_t> &r) const
{
  float vpx, vpy, vpz;
  feature_->getViewPoint (vpx, vpy, vpz);
  // Iterating over the entire index vector
  for (size_t idx = r.begin (); idx != r.end (); ++idx)
  {
    std::vector<int> nn_indices (feature_->getKSearch ());
    std::vector<float> nn_dists (feature_->getKSearch ());

    feature_->searchForNeighbors ((*feature_->getIndices ())[idx], feature_->getSearchParameter (), nn_indices, nn_dists);

    // 16-bytes aligned placeholder for the XYZ centroid of a surface patch
    Eigen::Vector4f xyz_centroid;
    // Estimate the XYZ centroid
    compute3DCentroid (*feature_->getSearchSurface (), nn_indices, xyz_centroid);

    // Placeholder for the 3x3 covariance matrix at each surface patch
    EIGEN_ALIGN16 Eigen::Matrix3f covariance_matrix;
    // Compute the 3x3 covariance matrix
    computeCovarianceMatrix (*feature_->getSearchSurface (), nn_indices, xyz_centroid, covariance_matrix);

    // Get the plane normal and surface curvature
    solvePlaneParameters (covariance_matrix,
                          output_.points[idx].normal[0], output_.points[idx].normal[1], output_.points[idx].normal[2], output_.points[idx].curvature);

    flipNormalTowardsViewpoint<PointInT> (feature_->getSearchSurface ()->points[idx], vpx, vpy, vpz,
                                          output_.points[idx].normal[0], output_.points[idx].normal[1], output_.points[idx].normal[2]);
  }
}
Ejemplo n.º 7
0
  void operator()(const tbb::blocked_range<int> &range) const {
    fptype price;
    int begin = range.begin();
    int end = range.end();

    for (int i=begin; i!=end; i++) {
      /* Calling main function to calculate option value based on 
       * Black & Scholes's equation.
       */

      price = BlkSchlsEqEuroNoDiv( sptprice[i], strike[i],
                                   rate[i], volatility[i], otime[i], 
                                   otype[i], 0);
      prices[i] = price;

#ifdef ERR_CHK 
      fptype priceDelta = data[i].DGrefval - price;
      if( fabs(priceDelta) >= 1e-5 ){
        fprintf(stderr,"Error on %d. Computed=%.5f, Ref=%.5f, Delta=%.5f\n",
               i, price, data[i].DGrefval, priceDelta);
        numError ++;
      }
#endif
    }
  }
Ejemplo n.º 8
0
 void operator()(const tbb::blocked_range<uint32>& range) const
 {
     //build index map
     for(uint32 i = range.begin();i != range.end();++i)
     {
         uint16 position = 0;
         uint8 *pBlock = (m_pData + (INDEX_BLOCK_SIZE * i));
         
         //read record
         for(;;)
         {
             if(position > IMAX_RECORD_POS)
                 break;
             
             //get record
             DREC *pDREC = (DREC*)(pBlock + position);
             
             //has data
             if(!IndexBlock::IsEmptyDREC(pDREC))
             {
                 //add key
                 m_pXKeys->push_back(pDREC->m_key);
             }
             
             //update position
             position += sizeof(DREC);
         }
     }
 }
Ejemplo n.º 9
0
 /** Increments counter once for each iteration in the iteration space. */
 void operator()( tbb::blocked_range<size_t>& range ) const {
     for( size_t i=range.begin(); i!=range.end(); ++i ) {
         //! Every 8th access is a write access
         const bool write = (i%8)==7;
         bool okay = true;
         bool lock_kept = true;
         if( (i/8)&1 ) {
             // Try implicit acquire and explicit release
             typename I::mutex_type::scoped_lock lock(invariant.mutex,write);
             execute_aux(lock, i, write, /*ref*/okay, /*ref*/lock_kept);
             lock.release();
         } else {
             // Try explicit acquire and implicit release
             typename I::mutex_type::scoped_lock lock;
             lock.acquire(invariant.mutex,write);
             execute_aux(lock, i, write, /*ref*/okay, /*ref*/lock_kept);
         }
         if( !okay ) {
             REPORT( "ERROR for %s at %ld: %s %s %s %s\n",invariant.mutex_name, long(i),
                     write     ? "write,"                  : "read,",
                     write     ? (i%16==7?"downgrade,":"") : (i%8==3?"upgrade,":""),
                     lock_kept ? "lock kept,"              : "lock not kept,", // TODO: only if downgrade/upgrade
                     (i/8)&1   ? "impl/expl"               : "expl/impl" );
         }
     }
 }
Ejemplo n.º 10
0
  void operator()(const tbb::blocked_range<int> &r) const
  {
    u32 numSamples = settings.numSamples;
    numSamples = 1;

    // r contains the scan lines to process
    Color* pp = &buffer[r.begin() * windowSize.x];
    Vector3 p;
    Vector3 tmp2 = tmp;
    tmp2.y += yInc * r.begin();

    for (int y = r.begin(); y < r.end(); ++y)
    {
      p = tmp2;

      for (u32 x = 0; x < windowSize.x; ++x)
      {
        // TODO: all the samples are uniform over the whole pixel. Try a stratisfied approach
        Color col(0,0,0);
        for (u32 i = 0; i < numSamples; ++i)
        {
          // construct ray from eye pos through the image plane
          Vector2 ofs = samples[(sampleIdx++) & 0xff];
          Ray r(cam.frame.origin, Normalize((p + Vector3(ofs.x * xInc, ofs.y * yInc, 0)) - cam.frame.origin));

          col += Radiance(r, 0);
        }

        *pp++ = col / (float)numSamples;

        p.x += xInc;
      }
    }
  }
Ejemplo n.º 11
0
  void operator()(const tbb::blocked_range<unsigned>& r) const
  {
    unsigned col, row;
    const int num_ghost = rp_grid_params.num_ghost;
    const int num_eqn = rp_grid_params.num_eqn;
    const int num_aux = rp_grid_params.num_aux;
    const int num_wave = rp_grid_params.num_wave;

    FieldIndexer fi(nx, ny, num_ghost, num_eqn);
    FieldIndexer fi_aux(nx, ny, num_ghost, num_aux);
    EdgeFieldIndexer efi(nx, ny, num_ghost, num_eqn, num_wave);

    for(col = r.begin(); col != std::min(r.end(), efi.num_col_edge_transverse()); ++col) {
      row = efi.num_row_edge_transverse();
      rp(q + fi.idx(row - 1, col), q + fi.idx(row, col),
         aux + fi_aux.idx(row - 1, col), aux + fi_aux.idx(row, col), aux_global, 1,
         amdq + efi.down_edge(row, col), apdq + efi.down_edge(row, col),
         wave + efi.down_edge(row, col), wave_speed + efi.down_edge(row, col));
    }

    for(row = r.begin(); row != std::min(r.end(), efi.num_row_edge_transverse()); ++row){
      col = efi.num_col_edge_transverse();
      rp(q + fi.idx(row, col - 1), q + fi.idx(row, col),
         aux + fi_aux.idx(row, col - 1), aux + fi_aux.idx(row, col), aux_global, 0,
         amdq + efi.left_edge(row, col), apdq + efi.left_edge(row, col),
         wave + efi.left_edge(row, col), wave_speed + efi.left_edge(row, col));
    }
  }
Ejemplo n.º 12
0
    void operator () (const tbb::blocked_range<int> &range) const {
        int i; 
        PARTITIONER partitioner;
        for (i=range.begin(); i<range.end(); i++) {
            //printf("Outer Loop Body[%d<=%d<%d]=[0,%d]\n", range.begin(), i, range.end(), degrees[currentLevelSet[i]]);
#ifdef SEQUENTIAL_INNER
            for(int j=0; j<degrees[currentLevelSet[i]]; j++) {
                int oldGatek;
                int freshNode,currentEdge;

                currentEdge = vertices[currentLevelSet[i]]+j;
                // let's handle one edge
#ifdef XBOFILE
                freshNode = edges[currentEdge][1]; // 0 RTM, value was prefetched
#else
                freshNode = edges[currentEdge];    // 0 RTM, value was prefetched
#endif
                oldGatek = -1;
                // test gatekeeper 
                oldGatek = gatekeeper[freshNode].fetch_and_increment();
                if (oldGatek == 0) { // destination vertex unvisited!
                    // increment newLevelIndex atomically
                    int myIndex = newLevelIndex.fetch_and_increment();
                    // store fresh node in new level
                    newLevelSet[myIndex] = freshNode;
 
                    level[freshNode] = currentLevel + 1;
                } // end if freshNode
            }
#else
            tbb::parallel_for (tbb::blocked_range<int>(0,degrees[currentLevelSet[i]],INNER_GRAINSIZE), innerLoopBody(i), partitioner);
#endif
        }
    }
Ejemplo n.º 13
0
 void operator()(const tbb::blocked_range<IntType> &block)
 {
     long r = res_;
     for (IntType i = block.begin(); i != block.end(); ++i)
         r += i;
     res_ = r;
 }
Ejemplo n.º 14
0
  void operator()(const tbb::blocked_range<int> &range) const {
    fptype price[NCO];
    fptype priceDelta;
    int begin = range.begin();
    int end = range.end();

    for (int i=begin; i!=end; i+=NCO) {
      /* Calling main function to calculate option value based on 
       * Black & Scholes's equation.
       */

      BlkSchlsEqEuroNoDiv( price, NCO, &(sptprice[i]), &(strike[i]),
                           &(rate[i]), &(volatility[i]), &(otime[i]), 
                           &(otype[i]), 0);
      for (int k=0; k<NCO; k++) {
        prices[i+k] = price[k];

#ifdef ERR_CHK 
        priceDelta = data[i+k].DGrefval - price[k];
        if( fabs(priceDelta) >= 1e-5 ){
          fprintf(stderr,"Error on %d. Computed=%.5f, Ref=%.5f, Delta=%.5f\n",
                 i+k, price, data[i+k].DGrefval, priceDelta);
          numError ++;
        }
#endif
      }
    }
  }
  void operator()(const tbb::blocked_range<size_t>& r) const
  {
    float sum;
    
    const float* __restrict p = &m_data[0] + r.begin();
    float* __restrict d = &m_output[0]+r.begin();

    float k[n];
    float c[n];
    k[0] = m_kernel[0];
    for (int i = 1; i < n; ++i)
    {
      c[i] = p[i-1];
      k[i] = m_kernel[i];
    }

    for (int i = 0, e = r.size()-n-1; i < e ; i += n) {
      d[i+0] = (c[0] = p[i+0]) * k[0] + c[1]*k[2]+c[2]*k[2]+c[3]*k[3]+c[4]*k[4]+c[5]*k[5]+c[6]*k[6];
      d[i+1] = (c[6] = p[i+1]) * k[0] + c[0]*k[2]+c[1]*k[2]+c[2]*k[3]+c[3]*k[4]+c[4]*k[5]+c[5]*k[6];
      d[i+2] = (c[5] = p[i+2]) * k[0] + c[6]*k[2]+c[0]*k[2]+c[1]*k[3]+c[2]*k[4]+c[3]*k[5]+c[4]*k[6];
      d[i+3] = (c[4] = p[i+3]) * k[0] + c[5]*k[2]+c[6]*k[2]+c[0]*k[3]+c[1]*k[4]+c[2]*k[5]+c[3]*k[6];
      d[i+4] = (c[3] = p[i+4]) * k[0] + c[4]*k[2]+c[5]*k[2]+c[6]*k[3]+c[0]*k[4]+c[1]*k[5]+c[2]*k[6];
      d[i+5] = (c[2] = p[i+5]) * k[0] + c[3]*k[2]+c[4]*k[2]+c[5]*k[3]+c[6]*k[4]+c[0]*k[5]+c[1]*k[6];
      d[i+6] = (c[1] = p[i+6]) * k[0] + c[2]*k[2]+c[3]*k[2]+c[4]*k[3]+c[5]*k[4]+c[6]*k[5]+c[0]*k[6];
    }


  }
Ejemplo n.º 16
0
    void operator() (const tbb::blocked_range<size_t>& range)
    {
        complex<REAL> localsum(0,0);
        const BIESpec* spec = s_->spec_;
        const complex<REAL> ik = complex<REAL>(0,s_->k_);

        for(size_t ii = range.begin(); ii != range.end(); ++ ii)
        {
            const complex<REAL>& P  = s_->x_(ii);
            const complex<REAL>& dP = spec->normalVel(ii)*ik*s_->crho_;

            // triangle ii
            for(size_t gi = 0; gi < spec->nGaussPts; ++ gi)
            {
                // gaussian point --> tri[rId] center
                Vector3<REAL> r  = pt_ - spec->gaussPts[ii][gi];
                const REAL lenr  = r.length();
                const REAL lenr2 = r.length_sqr();                              // r^2
                const complex<REAL> expikr = std::exp(complex<REAL>(0,s_->k_*lenr));

                localsum += expikr*dP * spec->gaussWeights[ii][gi] / (4.*M_PI*lenr);

                const REAL rdotny = r.dot(spec->triNormals[ii]);
                localsum += complex<REAL>(-1,s_->k_*lenr) * expikr * P * rdotny *
                            spec->gaussWeights[ii][gi] / (4.*M_PI*lenr2*lenr);
            }
        }

        this->ret = localsum;
    }
    void ImageFilterMedian::operator()(const tbb::blocked_range<size_t>& range) const {
        size_t halfKernelDim = static_cast<size_t>(_kernelSize / 2);
        const cgt::svec3& size = _input->getSize();
        
        for (size_t index = range.begin(); index < range.end(); ++index) {
            cgt::svec3 position = _input->getParent()->indexToPosition(index);

            size_t zmin = position.z >= halfKernelDim ? position.z - halfKernelDim : 0;
            size_t zmax = std::min(position.z+halfKernelDim, size.z-1);
            size_t ymin = position.y >= halfKernelDim ? position.y - halfKernelDim : 0;
            size_t ymax = std::min(position.y+halfKernelDim, size.y-1);
            size_t xmin = position.x >= halfKernelDim ? position.x - halfKernelDim : 0;
            size_t xmax = std::min(position.x+halfKernelDim, size.x-1);

            cgt::svec3 npos;
            std::vector<float> values;
            for (npos.z=zmin; npos.z<=zmax; npos.z++) {
                for (npos.y=ymin; npos.y<=ymax; npos.y++) {
                    for (npos.x=xmin; npos.x<=xmax; npos.x++) {
                        values.push_back(_input->getElementNormalized(npos, 0));
                    }
                }
            }
            size_t medianPosition = values.size() / 2;
            std::nth_element(values.begin(), values.begin() + medianPosition, values.end());
            _output->setElementNormalized(index, 0, values[medianPosition]);
        }
    }
Ejemplo n.º 18
0
    void operator () (const tbb::blocked_range<int> &range) const {
        int j;
        for(j=range.begin(); j<range.end(); j++) {
            //printf("Inner Loop Body (x,y)=(%d,%d) where y in [%d,%d)\n", i,j,range.begin(), range.end() );
	    int oldGatek;
            int freshNode,currentEdge;

            currentEdge = vertices[currentLevelSet[i]]+j;
            // let's handle one edge
#ifdef XBOFILE
            freshNode = edges[currentEdge][1]; // 0 RTM, value was prefetched
#else
            freshNode = edges[currentEdge];    // 0 RTM, value was prefetched
#endif
            oldGatek = -1;
            // test gatekeeper 
            oldGatek = gatekeeper[freshNode].fetch_and_increment();
	    if (oldGatek == 0) { // destination vertex unvisited!
                // increment newLevelIndex atomically
                int myIndex = newLevelIndex.fetch_and_increment();
	        // store fresh node in new level
	        newLevelSet[myIndex] = freshNode;

	        level[freshNode] = currentLevel + 1;
	    } // end if freshNode
        } // end for j
    }
Ejemplo n.º 19
0
void RayMarcher::operator() (const tbb::blocked_range<size_t>& r) const {
	for (size_t j = r.begin(), je = r.end(); j < je; ++j) {
		for (size_t i = 0, ie = mImpl->image->Width(); i < ie; ++i) {
			MeshPotato::MPUtils::MPRay ray;
			double x = (double)i/(mImpl->image->Width() - 1.0);
               		double y = (double)j/(mImpl->image->Height() - 1.0);
			ray = mImpl->camera->getRay(x,y);

//			const DeepPixelBuffer deepColor = deepL(ray, intersector2, interpolator2);
			// Bounding Box Check)
			double t0, t1;
			if (ray.intersects(mImpl->bbox,t0, t1)) {
				ray.setMinTime(t0);
				ray.setMaxTime(t1);
			const Color c = L(ray);
			std::vector<float> &pixel = mImpl->image->pixel(i,j);
			pixel[0] = c[0];
			pixel[1] = c[1];
			pixel[2] = c[2];
			pixel[3] = c[3];
		}
//			deepimage->value(i,j) = deepColor;
		}
	}
}
Ejemplo n.º 20
0
    void operator()( const tbb::blocked_range<int> &r ) const {
        T one = 1;

        for (int i = r.begin(); i < r.end(); ++i) {
            locals.local().push_back( one );
        }
    }
    void operator() (tbb::blocked_range<int> const &r) const {

            int idx = r.begin()*_numVertices;

            for (int i=r.begin(); i<r.end(); ++i, idx+=_numVertices) {

                float const * p0 = _iBuffer + _vertIndices[idx+0]*_iStride,
                            * p1 = _iBuffer + _vertIndices[idx+1]*_iStride,
                            * p2 = _iBuffer + _vertIndices[idx+2]*_iStride;

                // compute face normal
                float n[3];
                cross( n, p0, p1, p2 );

                // add normal to all vertices of the face
                for (int j=0; j<_numVertices; ++j) {

                    float * dst = _oBuffer + _vertIndices[idx+j]*_oStride;

                    dst[0] += n[0];
                    dst[1] += n[1];
                    dst[2] += n[2];
                }
            }
    }
Ejemplo n.º 22
0
 void operator() ( const tbb::blocked_range<int>& r ) {
     Harness::ConcurrencyTracker ct;
     for ( int i = r.begin(); i != r.end(); ++i ) {
         Op op;
         my_value = op(my_value, i);
     }
 }
 void operator()( const tbb::blocked_range<Number>& r ) const {
     for( Number i=r.begin(); i!=r.end(); ++i ) {
         if( i%2 && is_prime(i) ) {
             Primes[Primes.grow_by(1)] = i;
         }
     }
 }
Ejemplo n.º 24
0
 void operator()( const tbb::blocked_range<T*>& r ) {
     T temp = value;
     for( T* a=r.begin(); a!=r.end(); ++a ) {
         temp += *a;
     }
     value = temp;
 }
Ejemplo n.º 25
0
 /*!
 * @brief functor to apply
 * @param[in] r range of polygons to intersect from map1
 */
 void operator()( const tbb::blocked_range<int> & r) const {
     PRINT_DEBUG("From " << r.begin() << " to " << r.end());
     for(int i=r.begin(); i != r.end(); i++) {
         RPolygon *myPoly = (*m_map1)[i];
         OverlayOnePolygonWithMap(m_resultMap, myPoly, m_map2, m_rMutex);
     }
 }
Ejemplo n.º 26
0
	void operator()( tbb::blocked_range<int> rng ){
		double samples_per_image = 1.0*n_samples / lab_images.count();
	
		// Collect some statistics on mean and variance of each feature
		for( int i=rng.begin(), n_features=rng.begin()*samples_per_image; i<rng.end(); i++ ){
			Image< float > feature_response = feature->evaluate( lab_images[i], names[i] );
			for( int j=0; j<feature_response.height(); j++ )
				for( int i=0; i<feature_response.width(); i++ ){
					VectorXd x( feature_size );
					for( int k=0; k<feature_size; k++ )
						x[k] = feature_response(i,j,k);
					
					count += 1;
					VectorXd delta = x - mean;
					mean += delta / count;
					covariance += delta * (x-mean).transpose();
				}
			
			for(;n_features < (i+1)*samples_per_image; n_features++){
				int x = random() % feature_response.width();
				int y = random() % feature_response.height();
				for( int i=0; i<feature_size; i++ )
					features.append( feature_response( x, y, i ) );
			}
		}
	}
Ejemplo n.º 27
0
 void operator() ( const tbb::blocked_range<unsigned int> &_r ) const {
   unsigned int index;
   for ( index = _r.begin(); index != _r.end(); index++ ) {
     if ( readers[ index ] )
       ( *readers[ index ] ) ( *buffers[ index ] );
   }
 }
Ejemplo n.º 28
0
void colorx_node_t::do_expression( const tbb::blocked_range<int>& range, const Imath::Box2i& area, const render::context_t& context)
{
	std::string color_expr = get_value<std::string>( param( expr_param_name()));
	image_expression_t expr( color_expr, this, color_context);
	RAMEN_ASSERT( expr.isValid());

	expr.setup_variables( this, context);
	image::const_image_view_t src = input_as<image_node_t>()->const_subimage_view( area);
	image::image_view_t dst = subimage_view( area);
	
	SeVec3d& cvar = expr.vec_vars["Cs"].val;
	double& avar = expr.vars["As"].val;
	double *out_avar = expr.get_local_var_ref( "Ao", &avar);

	for( int y = range.begin(); y < range.end(); ++y)
	{
		image::const_image_view_t::x_iterator src_it( src.row_begin( y));
		image::image_view_t::x_iterator dst_it( dst.row_begin( y));

		for( int x = 0, xe = src.width(); x < xe; ++x)
		{
			cvar[0] = boost::gil::get_color( *src_it, boost::gil::red_t());
			cvar[1] = boost::gil::get_color( *src_it, boost::gil::green_t());
			cvar[2] = boost::gil::get_color( *src_it, boost::gil::blue_t());
			avar = boost::gil::get_color( *src_it, boost::gil::alpha_t());

			SeVec3d result = expr.evaluate();
			*dst_it++ = image::pixel_t( result[0], result[1], result[2], *out_avar);
			++src_it;
		}
	}
}
Ejemplo n.º 29
0
	void operator()(const tbb::blocked_range<short>& range) const {
		for (short labelid=range.begin(); labelid!=range.end(); ++labelid) {
			// Compute mask.
			// For big images it might make sense to parallelize this on a
			// smaller granularity (pixel ranges).
			// And it might be a good idea to cache these.
			cv::Mat1b mask(labels == labelid);

			if(tbb::task::self().is_cancelled()) {
				//GGDBGM("aborted through tbb cancel." << endl);
				return;
			}

			// transform mask into icon
			cv::Mat1b masktrf = cv::Mat1b::zeros(iconSizecv);
			cv::warpAffine(mask, masktrf, trafo, iconSizecv, CV_INTER_AREA);

			if(tbb::task::self().is_cancelled()) {
				//GGDBGM("aborted through tbb cancel." << endl);
				return;
			}
			// The rest is probably too fast to allow checking for cancellation.

			QColor color = ctx.colors.at(labelid);

			// Fill icon with solid color in ARGB format.
			cv::Vec4b argb(0, color.red(), color.green(), color.blue());
			cv::Mat4b icon = cv::Mat4b(iconSizecv.height,
									   iconSizecv.width,
									   argb);

			// Now apply alpha channel.
			// Note: this is better than OpenCV's mask functionality as it
			// preserves the antialiasing!

			// Make ARGB 'array' which is interleaved to a true ARGB image
			// using mixChannels.
			const cv::Mat1b zero = cv::Mat1b::zeros(iconSizecv.height,
													iconSizecv.width);
			const cv::Mat in[] = {masktrf, zero, zero, zero};
			// Copy only the alpha channel (0) of the in array into the
			// alpha channel (0) of the ARGB icon.
			const int mix[] = {0,0};
			// 4 input matrices, 1 dest, 1 mix-pair
			cv::mixChannels(in,4, &icon,1, mix,1);
			// convert the result to a QImage
			QImage qimage = Mat2QImage(icon);

			/* draw a border (alternative: the icon view could do this) */
			QPainter p(&qimage);
			QPen pen(color);
			// ensure border visibility, fixed to 1px
			pen.setWidthF(1.f);
			p.setPen(pen);
			p.drawRect(brect);

			ctx.icons[labelid] = qimage;
		}
	}
Ejemplo n.º 30
0
    void computeWithDerivative(tbb::blocked_range<int> const &r) const {
        float wP[20], wDs[20], wDt[20];
        BufferAdapter<const float> srcT(_src + _srcDesc.offset,
                                        _srcDesc.length,
                                        _srcDesc.stride);
        BufferAdapter<float> dstT(_dst + _dstDesc.offset
                                       + r.begin() * _dstDesc.stride,
                                  _dstDesc.length,
                                  _dstDesc.stride);
        BufferAdapter<float> dstDuT(_dstDu + _dstDuDesc.offset
                                       + r.begin() * _dstDuDesc.stride,
                                  _dstDuDesc.length,
                                  _dstDuDesc.stride);
        BufferAdapter<float> dstDvT(_dstDv + _dstDvDesc.offset
                                       + r.begin() * _dstDvDesc.stride,
                                  _dstDvDesc.length,
                                  _dstDvDesc.stride);

        for (int i = r.begin(); i < r.end(); ++i) {
            PatchCoord const &coord = _patchCoords[i];
            PatchArray const &array = _patchArrayBuffer[coord.handle.arrayIndex];

            int patchType = array.GetPatchType();
            Far::PatchParam const & param =
                _patchParamBuffer[coord.handle.patchIndex];

            int numControlVertices = 0;
            if (patchType == Far::PatchDescriptor::REGULAR) {
                Far::internal::GetBSplineWeights(param,
                                                 coord.s, coord.t, wP, wDs, wDt);
                numControlVertices = 16;
            } else if (patchType == Far::PatchDescriptor::GREGORY_BASIS) {
                Far::internal::GetGregoryWeights(param,
                                                 coord.s, coord.t, wP, wDs, wDt);
                numControlVertices = 20;
            } else if (patchType == Far::PatchDescriptor::QUADS) {
                Far::internal::GetBilinearWeights(param,
                                                  coord.s, coord.t, wP, wDs, wDt);
                numControlVertices = 4;
            } else {
                assert(0);
            }

            const int *cvs =
                &_patchIndexBuffer[array.indexBase + coord.handle.vertIndex];

            dstT.Clear();
            dstDuT.Clear();
            dstDvT.Clear();
            for (int j = 0; j < numControlVertices; ++j) {
                dstT.AddWithWeight(srcT[cvs[j]], wP[j]);
                dstDuT.AddWithWeight(srcT[cvs[j]], wDs[j]);
                dstDvT.AddWithWeight(srcT[cvs[j]], wDt[j]);
            }
            ++dstT;
            ++dstDuT;
            ++dstDvT;
        }
    }