当前位置: 首页>>代码示例>>C++>>正文


C++ Array2D类代码示例

本文整理汇总了C++中Array2D的典型用法代码示例。如果您正苦于以下问题:C++ Array2D类的具体用法?C++ Array2D怎么用?C++ Array2D使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Array2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: saveArrayAsImage

void saveArrayAsImage( const Array2D< float >& array, QString prefix, float ss, float sr )
{
	Image4f im( array.width(), array.height() );

	for( int y = 0; y < im.height(); ++y )
	{
		for( int x = 0; x < im.width(); ++x )
		{
			float v = array( x, y );
			im.setPixel( x, y, Vector4f( v, v, v, 1 ) );
		}
	}

	QString filename = QString( "%1_%2_%3.png" ).arg( prefix ).arg( ss ).arg( sr );
	printf( "saving output: %s...", qPrintable( filename ) );
	im.flipUD().save( filename );
	printf( "done.\n\n" );
}
开发者ID:autumnm1981,项目名称:Halide,代码行数:18,代码来源:main2.cpp

示例2: outputExcel

  /*
   * @param s          output stream 
   * @param title      plot title 
   * @param names      vector of variable names
   * @param data       N x M data array.
   *                        data(n,m) is the m^th value of the n^th variable.
   */
  void outputExcel(std::ostream &s, const std::string &title, 
		   const std::vector<std::string>& names,  
		   const Array2D& data) {
    int i,j;
    int npts = static_cast<int>(data.nColumns());
    int nv = static_cast<int>(data.nRows());
    s << title + "," << endl;
    for (i = 0; i < nv; i++) {
      s << names[i] << ",";
    }
    s << endl;
    for (i = 0; i < npts; i++) {
      for (j = 0; j < nv; j++) {
	s << data(j,i) << ",";
      }
      s << endl;
    }
  }
开发者ID:anujg1991,项目名称:cantera,代码行数:25,代码来源:plots.cpp

示例3: GetSelfCollisionPairs

void RobotWithGeometry::GetSelfCollisionPairs(Array2D<bool>& collision) const
{
  collision.resize(geometry.size(),geometry.size(),false);
  for(int i=0;i<collision.m;i++)
    for(int j=0;j<collision.n;j++)
      if(selfCollisions(i,j) != NULL)
	collision(i,j) = true;

}
开发者ID:,项目名称:,代码行数:9,代码来源:

示例4: setArray

void FMSegView::setArray(const Array2D &X) {
	d->m_array=X;
	if (d->m_window_max==0) {
		d->m_window_min=0;
		d->m_window_max=X.max()*0.6;
	}
	d->m_array_filtered=d->compute_median_filter(d->m_array,d->m_median_filter_radius);
	refresh();
}
开发者ID:magland,项目名称:fmseg,代码行数:9,代码来源:fmsegview.cpp

示例5: adjust_data

	void adjust_data(Array2D<double>& d, Array1D<double>& means) {
	   for (int i=0; i<d.dim2(); ++i) { 
		   double mean = 0;
		   for (int j=0; j<d.dim1(); ++j) {
			   mean += d[j][i];
		   }

		   mean /= d.dim1();

		   // store the mean
		   means[i] = mean;

		   // subtract the mean
		   for (int j=0; j<d.dim1(); ++j) {
			   d[j][i] -= mean;
		   }
	   }
	}
开发者ID:DheerajPurohit,项目名称:Principal-component-analysis-,代码行数:18,代码来源:pca.cpp

示例6: GammaTable

	ImageData::ImageData(const string & filename, Array2D<Color4f> & rgbaBuffer) :
			filename(filename) {
		totalXRes = xRes = rgbaBuffer.getSizeX();
		totalYRes = yRes = rgbaBuffer.getSizeY();

		xOffset = yOffset = 0;
		gTable = GammaTable(1,1);

		color = new float[xRes*yRes*3];
		alpha = NULL;

		for (int x = 0; x < xRes; x++) {
			for (int y = 0; y < yRes; y++) {
				for (int i = 0; i < 3; i++) 
					color[3*(y*xRes+x)+i] = rgbaBuffer(x,yRes-y-1)[i];
			}
		}
	}
开发者ID:gostefan,项目名称:imageSynthesis,代码行数:18,代码来源:ImageIO.cpp

示例7: quantise_subbands

// Quantise a subband in in-place transform order
// This version of quantise_subbands assumes multiple quantisers per subband.
// It may be used for either quantising slices or for quantising subbands with codeblocks
const Array2D quantise_subbands(const Array2D& coefficients, const BlockVector& qIndices) {
  const Index transformHeight = coefficients.shape()[0];
  const Index transformWidth = coefficients.shape()[1];
  // TO DO: Check numberOfSubbands=3n+1 ?
  const int numberOfSubbands = qIndices.size();
  const int waveletDepth = (numberOfSubbands-1)/3;
  Index stride, offset; // stride is subsampling factor, offset is subsampling phase
  Array2D result(coefficients.ranges());

  // Create a view of the coefficients, representing the LL subband, quantise it,
  // then assign the result a view of the results array. This puts the quantised
  // LL subband into the result array in in-place transform order.
  // ArrayIndices2D objects specify the subset of array elements within a view,
  // that is they specify the subsampling factor and subsampling phase.
  stride = pow(2, waveletDepth);
  const ArrayIndices2D LLindices = // LLindices specifies the samples in the LL subband
    indices[Range(0,transformHeight,stride)][Range(0,transformWidth,stride)];
  result[LLindices] =
    quantise_LLSubband(coefficients[LLindices], qIndices[0]);

  // Next quantise the other subbands
  // Note: Level numbers go from zero for the lowest ("DC") frequencies to depth for
  // the high frequencies. This corresponds to the convention in the VC-2 specification.
  // Subands go from zero ("DC") to numberOfSubbands-1 for HH at the highest level
  for (char level=1, band=1; level<=waveletDepth; ++level) {
    stride = pow(2, waveletDepth+1-level);
    offset = stride/2;
    // Create a view of coefficients corresponding to a subband, then quantise it
    //Quantise HL subband
    const ArrayIndices2D HLindices = // HLindices specifies the samples in the HL subband
      indices[Range(0,transformHeight,stride)][Range(offset,transformWidth,stride)];
    result[HLindices] = quantise_block(coefficients[HLindices], qIndices[band++]);
    //Quantise LH subband
    const ArrayIndices2D LHindices = // LHindices specifies the samples in the LH subband
      indices[Range(offset,transformHeight,stride)][Range(0,transformWidth,stride)];
    result[LHindices] = quantise_block(coefficients[LHindices], qIndices[band++]);
    //Quantise HH subband
    const ArrayIndices2D HHindices = // HHindices specifies the samples in the HH subband
      indices[Range(offset,transformHeight,stride)][Range(offset,transformWidth,stride)];
    result[HHindices] = quantise_block(coefficients[HHindices], qIndices[band++]);
  }

  return result;
}
开发者ID:GrokImageCompression,项目名称:vc2-reference,代码行数:47,代码来源:Quantisation.cpp

示例8: readRgba1

static void readRgba1(const std::string& filename, Array2D<Rgba>& pixels,
                      int& width, int& height) {
  RgbaInputFile file{filename.c_str()};
  Box2i dw = file.dataWindow();
  width    = dw.max.x - dw.min.x + 1;
  height = dw.max.y - dw.min.y + 1;
  pixels.resizeErase(height, width);
  file.setFrameBuffer(&pixels[0][0] - dw.min.x - dw.min.y * width, 1, width);
  file.readPixels(dw.min.y, dw.max.y);
}
开发者ID:skaslev,项目名称:EncinoWaves,代码行数:10,代码来源:OceanTestTextureSky.cpp

示例9: readRgba

void Exr::readRgba(const string inf, Array2D<Rgba> &pix, int &w, int &h)
{
    RgbaInputFile file (inf.c_str());
    Box2i dw = file.dataWindow();
    w  = dw.max.x - dw.min.x + 1;
    h = dw.max.y - dw.min.y + 1;
    pix.resizeErase (h, w);
    file.setFrameBuffer (&pix[0][0] - dw.min.x - dw.min.y * w, 1, w);
    file.readPixels (dw.min.y, dw.max.y);
}
开发者ID:GPUOpen-Tools,项目名称:Compressonator,代码行数:10,代码来源:cExr.cpp

示例10: bicChangeSearch

// This function finds the next change in matrix
int SBic::bicChangeSearch(const Array2D<Real>& matrix, int inc, int current) const {
  int nFeatures = matrix.dim1();
  int nFrames = matrix.dim2();

  Real d, dmin, penalty;
  Real s, s1, s2;
  Array2D<Real> half;
  int n1, n2, seg = 0, shift = inc-1;

  // according to the paper the penalty coefficient should be the following:
  // penalty = 0.5*(3*nFeatures + nFeatures*nFeatures);

  penalty = _cpw * _cp * log(Real(nFrames));
  dmin = numeric_limits<Real>::max();

  // log-determinant for the entire window
  s = logDet(matrix);

  // loop on all mid positions
  while (shift < nFrames - inc) {
    // first part
    n1 = shift + 1;
    half = subarray(matrix, 0, nFeatures-1, 0, shift);
    s1 = logDet(half);

    // second part
    n2 = nFrames - n1;
    half = subarray(matrix, 0, nFeatures-1, shift+1, nFrames-1);
    s2 = logDet(half);

    d = 0.5 * (n1*s1 + n2*s2 - nFrames*s + penalty);

    if (d < dmin) {
      seg = shift;
      dmin = d;
    }
    shift += inc;
  }

  if (dmin > 0) return 0;

  return current + seg;
}
开发者ID:MTG,项目名称:essentia,代码行数:44,代码来源:sbic.cpp

示例11: compute_covariance_matrix

	void compute_covariance_matrix(const Array2D<double> & d, Array2D<double> & covar_matrix) {
		int dim = d.dim2();
		assert(dim == covar_matrix.dim1());
		assert(dim == covar_matrix.dim2());
		for (int i=0; i<dim; ++i) {
			for (int j=i; j<dim; ++j) {
				covar_matrix[i][j] = compute_covariance(d, i, j);
			}
		}


		// fill the Left triangular matrix
		for (int i=1; i<dim; i++) {
			for (int j=0; j<i; ++j) {
				covar_matrix[i][j] = covar_matrix[j][i];
			}
		}

	}
开发者ID:jaeha1223,项目名称:Principal-component-analysis-,代码行数:19,代码来源:pca.cpp

示例12: split_into_blocks

// Splits a large 2D array into an array of smaller 2D arrays (blocks)
// Note that if the number of blocks is not a sub-multiple of the input array dimensions then
// the blocks will have different sizes!
// yBlocks and xBlocks are the number of blocks in the vertical and horizontal dimension respectively.
// Splits a picture into slices or a subband into codeblocks.
const BlockArray split_into_blocks(const Array2D& picture, int yBlocks, int xBlocks) {
  // Define array of yBlocks by xBlocks
  BlockArray blocks(extents[yBlocks][xBlocks]);
  const int pictureHeight = picture.shape()[0];
  const int pictureWidth = picture.shape()[1];
  // Note Range(left, right) defines the half open range [left, right),
  // i.e. the rightmost element is not included
  for (int y=0, top=0, bottom=pictureHeight/yBlocks;
       y<yBlocks;
       ++y, top=bottom, bottom=((y+1)*pictureHeight/yBlocks) ) {
    for (int x=0, left=0, right=pictureWidth/xBlocks;
         x<xBlocks;
         ++x, left=right, right=((x+1)*pictureWidth/xBlocks) ) {
      // Assign region of picture to block
      blocks[y][x] = picture[indices[Range(top,bottom)][Range(left,right)]];
    }
  }
  return blocks;
}
开发者ID:GrokImageCompression,项目名称:vc2-reference,代码行数:24,代码来源:Arrays.cpp

示例13: ComputeIDX

Array2D ComputeIDX(const Mat& IDX) {
    assert(IDX.type() == CV_32S);
    assert(IDX.rows > 0 && IDX.cols > 0);

    std::unordered_map<int, Array1D> hash;
    std::vector<int> hash_keys;
    int idx_num = 0;
    for (int i = 0; i < IDX.cols; i++) {
        if (!hash.count(IDX.at<int>(i))) {
            hash_keys.push_back(IDX.at<int>(i));
        }
        hash[IDX.at<int>(i)].push_back(i + 1);
    }
    std::sort(hash_keys.begin(), hash_keys.end());
    Array2D result;
    for (int i = 0; i < hash_keys.size(); i++) {
        result.push_back(hash[hash_keys[i]]);
    }
    return result;
}
开发者ID:xiejianhe,项目名称:SPDA,代码行数:20,代码来源:segment_data_by_idx.cpp

示例14: delta_bic

// This function computes the delta bic. It is actually used to determine
// whether two consecutive segments have the same probability distribution
// or not. In such case, these segments are joined.
Real SBic::delta_bic(const Array2D<Real>& matrix, Real segPoint) const{

  int nFeatures = matrix.dim1();
  int nFrames = matrix.dim2();
  Array2D<Real> half;
  Real s, s1, s2;

  // entire segment
  s = logDet(matrix);

  // first half
  half = subarray(matrix, 0, nFeatures-1, 0, int(segPoint));
  s1 = logDet(half);

  // second half
  half = subarray(matrix, 0, nFeatures-1, int(segPoint + 1), nFrames-1);
  s2 = logDet(half);

  return 0.5 * ( segPoint*s1 + (nFrames - segPoint)*s2 - nFrames*s + _cpw*_cp*log(Real(nFrames)) );
}
开发者ID:MTG,项目名称:essentia,代码行数:23,代码来源:sbic.cpp

示例15: vert_line

static bool vert_line(double _x0, double _y0, double _x1, double _y1, int NX,
		      vector<int>& imin, vector<int>& imax,
		      bool draw, npy_uint32 col, Array2D<npy_uint32>& D)
{
    int x0 = lrint(_x0);
    int y0 = lrint(_y0);
    int x1 = lrint(_x1);
    int y1 = lrint(_y1);
    int dx = abs(x1-x0);
    int dy = abs(y1-y0);
    int sx, sy;
    int NY=imin.size()-1;
    int err, e2;
    bool visible=false;
    NX = NX-1;
    if (x0 < x1)
	sx = 1;
    else
	sx = -1;
    if (y0 < y1)
	sy = 1;
    else
	sy = -1;
    err = dx-dy;

    do {
	if (y0>=0 && y0<=NY) {
	    int _min = min(imin[y0],x0);
	    int _max = max(imax[y0],x0);
	    if (draw) {
		if (x0>=0 && x0<=NX) {
		    D.value(x0,y0) = col;
		}
	    }
	    imin[y0] = max( 0,_min);
	    imax[y0] = min(NX,_max);
	    if (_min<=NX && _max>=0) {
		visible=true;
	    }
	}
	if ((x0 == x1) && (y0 == y1))
	    break;
	e2 = 2*err;
	if (e2 > -dy) {
	    err = err - dy;
	    x0 = x0 + sx;
	}
	if (e2 <  dx) {
	    err = err + dx;
	    y0 = y0 + sy;
	}
    } while(true);
    return visible;
}
开发者ID:PierreRaybaut,项目名称:plotpy,代码行数:54,代码来源:pcolor.cpp


注:本文中的Array2D类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。