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


C++ Array2D::allocate方法代码示例

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


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

示例1: ssfeatures

int ssfeatures(FILE* infile, FILE* outfile, const QMap<QString, QVariant>& params)
{
    int nfeatures = params["nfeatures"].toInt();
    int niterations = params["niterations"].toInt();

    //get the input file header
    MDAIO_HEADER HH_infile;
    if (!mda_read_header(&HH_infile, infile))
        return 0;
    int32_t M = HH_infile.dims[0];
    int32_t T = HH_infile.dims[1];
    int32_t N = HH_infile.dims[2];
    if (M <= 0)
        return 0;
    if (T <= 0)
        return 0;
    if (N <= 0)
        return 0;

    Array2D X;
    X.allocate(M * T, N);
    float* inbuf = (float*)malloc(sizeof(float) * M * T);
    for (int i = 0; i < N; i++) {
        mda_read_float32(inbuf, &HH_infile, M * T, infile);
        for (int j = 0; j < M * T; j++) {
            X.setValue(inbuf[j], j, i);
        }
    }
    free(inbuf);

    PCASolver SS;
    SS.setVectors(X);
    SS.setNumIterations(niterations);
    SS.setComponentCount(nfeatures);
    SS.solve();
    Array2D features = SS.coefficients();

    //write the output header
    MDAIO_HEADER HH_outfile;
    mda_copy_header(&HH_outfile, &HH_infile);
    HH_outfile.num_dims = 2;
    HH_outfile.dims[0] = nfeatures;
    HH_outfile.dims[1] = N;
    HH_outfile.dims[2] = 1;
    HH_outfile.data_type = MDAIO_TYPE_FLOAT32;
    mda_write_header(&HH_outfile, outfile);

    float* outbuf = (float*)malloc(sizeof(float) * nfeatures);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < nfeatures; j++) {
            outbuf[j] = features.value(j, i);
        }
        mda_write_float32(outbuf, &HH_outfile, nfeatures, outfile);
    }
    free(outbuf);

    return 1;
}
开发者ID:magland,项目名称:mountainlab,代码行数:58,代码来源:ssfeatures.cpp

示例2: compute_median_filter

Array2D FMSegViewPrivate::compute_median_filter(const Array2D &array,int radius) {
	Array2D ret; ret.allocate(array.N1(),array.N2());
	for (int y=0; y<array.N2(); y++)
	for (int x=0; x<array.N1(); x++) {
		QList<float> list;
		for (int dy=-radius; dy<=radius; dy++)
		for (int dx=-radius; dx<=radius; dx++) {
			list << array.getValue(x+dx,y+dy);
		}
		qSort(list);
		ret.setValue(list[list.count()/2],x,y);
	}
	return ret;
}
开发者ID:magland,项目名称:fmseg,代码行数:14,代码来源:fmsegview.cpp

示例3: compute_mask_boundary

Array2D FMSegViewPrivate::compute_mask_boundary(const Array2D &mask) {
	Array2D B;
	int N1=mask.N1();
	int N2=mask.N2();
	B.allocate(N1,N2);
	for (int y=0; y<N2; y++)
	for (int x=0; x<N1; x++) {
		if (mask.getValue(x,y)) {
			for (int dy=-1; dy<=1; dy++)
			for (int dx=-1; dx<=1; dx++) {
				if ((!mask.getValue(x+dx,y+dy))&&(!B.getValue(x,y))) {
					B.setValue(1,x,y);
				}
			}
		}
	}
	return B;
}
开发者ID:magland,项目名称:fmseg,代码行数:18,代码来源:fmsegview.cpp

示例4: if

void Strand2dFCBlockMesh::initialize(const int& level0,
				     const int& meshOrder0,
				     const int& nSurfElem0,
				     const int& nSurfNodeG,
				     const int& nBndNode0,
				     const int& nStrandNodeG,
				     const int& nCompBd0,
				     int** surfElemG,
				     const Array1D<int>& bndNodeG,
				     const Array2D<double>& surfXG,
				     const Array1D<double>& strandXG,
				     const Array1D<int>& surfElemTagG,
				     const Array1D<int>& bndNodeTagG,
				     const Array2D<double>& bndNodeNormalG)
{
  // copy dimensions for this block
  level = level0;
  meshOrder = meshOrder0;
  nSurfElem = nSurfElem0;
  nBndNode = nBndNode0;
  nCompBd = nCompBd0;


  // allocate space for the mesh data, and copy the known data
  surfElem.allocate(nSurfElem,meshOrder+1);
  surfElemTag.allocate(nSurfElem);
  bndNode.allocate(nBndNode);
  bndNodeTag.allocate(nBndNode);
  bndNodeNormal.allocate(nBndNode,2);
  for (int n=0; n<nSurfElem; n++) surfElemTag(n) = surfElemTagG(n);
  for (int n=0; n<nBndNode; n++){
    bndNodeTag(n)      = bndNodeTagG(n);
    bndNodeNormal(n,0) = bndNodeNormalG(n,0);
    bndNodeNormal(n,1) = bndNodeNormalG(n,1);
  }


  // form surface elements of the desired order, count surface nodes
  int n1,n2;
  Array1D<int> flag(nSurfNodeG);
  flag.set(-1);
  nSurfNode = 0;
  for (int n=0; n<nSurfElem; n++){ //add element end points first
    n1 = surfElemG[n][1];
    n2 = surfElemG[n][2];
    if (flag(n1) == -1) flag(n1) = nSurfNode++;
    if (flag(n2) == -1) flag(n2) = nSurfNode++;
    surfElem(n,0) = flag(n1);
    surfElem(n,1) = flag(n2);
  }
  for (int n=0; n<nSurfElem; n++) //add interior dofs next
    for (int j=2; j<meshOrder+1; j++) surfElem(n,j) = nSurfNode++;


  // point the bndNode array to the new node numbers
  for (int n=0; n<nBndNode; n++) bndNode(n) = flag(bndNodeG(n));


  // find surface mesh coordinates based on mappings from the mesh file
  Array1D<double> ss(meshOrder+1);
  int spacing=0; // assume equal spacing for now
  solutionPoints1D(meshOrder, //find s-locations based on desired spacing
		   spacing,
		   &ss(0));
  surfX.allocate(nSurfNode,2);
  surfX.set(0.);
  bool test=false;
  int orderM;
  double lm;
  Array1D<double> sM;
  Array2D<double> lcM;
  flag.deallocate();
  flag.allocate(nSurfNode);
  flag.set(-1);
  for (int n=0; n<nSurfElem; n++){
    orderM = surfElemG[n][0];

    // s-locations using numbering consistent with the mesh
    sM.allocate(orderM+1);
    solutionPoints1D(orderM,
		     spacing,
		     &sM(0));

    // lagrange polynomials at the sM locations
    lcM.allocate(orderM+1,orderM+1);
    lagrangePoly1D(test,
                   orderM,
                   &sM(0),
                   &lcM(0,0));

    // evaluate the x-coordinates at the local solution points
    for (int i=0; i<meshOrder+1; i++) //ith local point
      if (flag(surfElem(n,i)) == -1){//haven't computed this location yet
        for (int m=0; m<orderM+1; m++){ //mth Lagrange poly. used in mapping
          lm = 0.;
          for (int k=0; k<orderM+1; k++) lm += pow(ss(i),k)*lcM(m,k);
          surfX(surfElem(n,i),0) += lm*surfXG(surfElemG[n][m+1],0);
          surfX(surfElem(n,i),1) += lm*surfXG(surfElemG[n][m+1],1);
        }
        flag(surfElem(n,i)) = 0;
//.........这里部分代码省略.........
开发者ID:srharris91,项目名称:Katz_Work,代码行数:101,代码来源:initializeMesh.C


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