Beispiel #1
0
void vert_smooth_mat(Mesh & m,
                float wS, CCS&ccs, std::vector<double >&bb)
{
  //std::vector<Vec3> nbrPos(m.v.size());
  //avgNbrPos(m,nbrPos);
  std::vector<std::set<int> > vadj;
  vertAdjList(m,vadj);

  for(int axis=0; axis<3; axis++) {
  for(size_t idx=0;idx<m.v.size();idx++){

/*
    std::map<int,real>val;
    val[idx]=wS;
    addrow(val,ccs,axis*nvar);
    bb.push_back(wS*nbrPos[idx][axis]);
    */
    std::map<int,real>val;
    val[idx]=wS;
    std::set<int>::iterator it;
    std::set<int> &neibors=vadj[idx];
    size_t n_neibor=neibors.size();
    for(it = neibors.begin();it!=neibors.end();it++){
      int nbrIdx= (*it);
      val[nbrIdx]=-wS/n_neibor;
    }
    addrow(val,ccs,axis*nvar);
    bb.push_back(0);
  }
  }
}
Beispiel #2
0
int main() {
	const int MAXETB = 8;
	int etb_n, dim_n;
	int cmds, cmd, tid, score[128], sort_order[128];
	char sid[32];
	ExamTable *etb = (ExamTable*) malloc(sizeof(ExamTable)*MAXETB);
	scanf("%d", &etb_n);
	for (int i = 0; i < etb_n; i++) {
		scanf("%d", &dim_n);
		init(&etb[i], dim_n);
	}
	scanf("%d", &cmds);
	for (int i = 0; i < cmds; i++) {
		scanf("%d %d", &cmd, &tid);
		if (cmd == 1) {
			scanf("%s", sid);
			for (int j = 0; j < etb[tid].dim_n; j++)
				scanf("%d", &score[j]);
			addrow(&etb[tid], sid, score);
		} else {
			for (int j = 0; j < etb[tid].dim_n; j++)
				scanf("%d", &sort_order[j]);
			print(&etb[tid], sort_order);
		}
	}
	return 0;
}
Beispiel #3
0
/**@brief
  @param b will be filled with 1 0 0 0 1 0 0 0 1
*/
void identity_mat(Mesh & m , std::vector<Mat3> &mat, float wI, CCS&ccs, std::vector<double > & bb)
{
 // int nvar = m.v.size()+m.t.size();
  for(int axis=0; axis<3; axis++) {

  for(size_t ii=0; ii<m.t.size(); ii++) {
    for(int jj=0; jj<3; jj++) {
        double val;
        if(jj==axis) {
          val=wI;
        } else {
          val=0;
        }
        bb.push_back(val);
      }
    }
  }
  for(int axis=0; axis<3; axis++) {

  for(size_t ii=0; ii<m.t.size(); ii++) {
    for(int jj=0; jj<3; jj++) {
      std::map<int,real>val;
      add_coef(m.t[ii],jj,mat[ii],val);
      scale(val,wI);

      addrow(val, ccs, nvar*axis);
    }
    }
  }
}
Beispiel #4
0
/**@brief neighboring transformations
should be similar
@param tIdx index of the triangle being proecssed
@param mat vector of transformations for each triangle

assumes m already contains adjacency matrix
*/
void smooth_mat(Mesh & m,
                std::vector<Mat3>&mat,
                float wS, CCS&ccs)
{
  //each triangle has 9 constraints for
  //each number in the transformation matrix
for(int axis=0; axis<3; axis++) {

    for(size_t tIdx=0; tIdx<m.t.size(); tIdx++) {

      for(int ii=0; ii<3; ii++) {
        std::map<int,real>rowVal;
        std::map<int,real>neiborRowVal;
        add_coef(m.t[tIdx],ii,mat[tIdx],rowVal);
        for(size_t nbr =0; nbr<m.adjMat[tIdx].size(); nbr++) {
          int nbrIdx = m.adjMat[tIdx][nbr];
          add_coef(m.t[nbrIdx],ii,mat[nbrIdx],neiborRowVal);
        }
        add_times(rowVal, neiborRowVal,-(1.0/m.adjMat[tIdx].size()));
        scale(rowVal, wS);
//if(axis==0 && ii==0 && tIdx==0){	
//	  std::cout<<"rowVal"<<rowVal[m.t[0][0]]<<"\n";
//	}
        addrow(rowVal, ccs, nvar*axis);
      }
    }
  }
}
Beispiel #5
0
il_mat il_mat_invert(il_mat a)
{
    il_mat res = il_mat_identity();

    // for every column ..
    for (int col = 0; col < 4; ++col) {
        float diagonalfield = a.data[col*4+col];
        // if we have a weird matrix with zero on the diagonal ..
        float eps = 0.0001;
        if (fabs(diagonalfield) < eps) {
            // SIIIGH.
            // Okay, let's go hunting for a row with a better diagonal to use
            // keep in mind, row swapping is also a linear operation!
            for (int row = 0; row < 4; ++row) if (row != col) if (fabs(a.data[row*4+col]) >= eps) {
                swaprow(&a, row, col);
                swaprow(&res,row, col);
            }
            diagonalfield = a.data[col*4+col]; // recompute
            // if it still fails, we probably have a denatured matrix and are proper f****d.
            assert(fabs(diagonalfield) >= eps);
        }
        // for every row ..
        for (int row = 0; row < 4; ++row) {
            // if it's not on the diagonal ..
            if (row != col) {
                float field = a.data[row*4+col];
                // bring this field to 0 by subtracting the row that's on the diagonal for this column
                addrow(&a,  /* src */ col, /* dst */ row, /* factor */ -field/diagonalfield);
                // do the same to identity
                addrow(&res,/* src */ col, /* dst */ row, /* factor */ -field/diagonalfield);
            }
        }
        // and finally, bring the diagonal to 1
        mulrow(&a,  col, 1/diagonalfield);
        mulrow(&res,col, 1/diagonalfield);
    }
    // Success! Because a is now id, res is now a^-1. Math is fun!
    return res;
}
void dataeditfrm::contmenu()
{
    QMenu* contextMenu = new QMenu( this );
    Q_CHECK_PTR( contextMenu );

    QAction* add_row = new QAction( tr("&Add supplier"), this );
	connect(add_row , SIGNAL(triggered()), this, SLOT(addrow()));
	contextMenu->addAction(add_row);
    QAction* del_row = new QAction( tr("&Delete supplier"), this );
	connect(del_row , SIGNAL(triggered()), this, SLOT(removerow()));
	contextMenu->addAction(del_row);
	contextMenu->addSeparator();
    QAction* checkaddr = new QAction( tr("&Check address"), this );
	connect(checkaddr , SIGNAL(triggered()), this, SLOT(seladdress()));
	contextMenu->addAction(checkaddr);
	contextMenu->addSeparator();
	QAction* sel_sup = new QAction( tr("&Select this supplier"), this );
	connect(sel_sup , SIGNAL(triggered()), this, SLOT(acceptsp()));
	contextMenu->addAction(sel_sup);

    contextMenu->exec( QCursor::pos() );
    delete contextMenu;
}
Beispiel #7
0
void planar_mat(Mesh & m, std::vector<Plane>&plane, float wPt, CCS& ccs)
{
//  int nvar = m.t.size()+ m.v.size();
for(size_t tIdx=0; tIdx<m.t.size(); tIdx++) {

  Plane & p = plane[m.t[tIdx].label];
  for(int row = 0; row<2; row++) {
    std::map<int, real> val;
    for(int axis=0; axis<3; axis++) {
      int idx= VAR_IDX(m.t[tIdx][row]);
      val[idx]=p.n.x[axis]   * wPt;

      idx= VAR_IDX(m.t[tIdx][row+1]);
      val[idx]=-p.n.x[axis]  * wPt;
//       if( tIdx==0){	
// 	  std::cout<<"val"<<val[idx]<<"\n";
// 	  std::cout<<"plane"<<p.n.x[axis]<<"\n";
// 	}
    }
    addrow(val,ccs);
  }
  }
}
void dcDataFrame::addrow(string varname,double value)
{
	vector<double> tmp;
	tmp.push_back(value);
	addrow(varname,tmp);
}
Beispiel #9
0
static int attributes_walk(RBinJavaObj *bin, struct r_bin_java_attr_t *attr, int sz2, int fields) {
	ut32 symaddr = 0;
	char buf[0xffff+1]; // that's kinda ugly :)
	int sz3, sz4;
	int j=0,k;
	char *name;

	for (j=0; j<sz2; j++) {
		if (r_buf_read_at (bin->b, R_BUF_CUR, (ut8*)buf, 6) != 6) {
			eprintf ("Cannot read 6 bytes in class file\n");
			return R_FALSE;
		}
		attr->name_idx = R_BIN_JAVA_USHORT (buf,0);
		name = get_CP (bin, attr->name_idx-1)->value;
		if (!name) {
			eprintf ("Attribute name is null\n");
			return R_FALSE;
		}
		// XXX: if name is null.. wat?
		attr->name = strdup (name? name: "");
		name = (get_CP (bin, attr->name_idx-1))->value;//cp_items[R_BIN_JAVA_USHORT(buf,0)-1].value;
		IFDBG printf("   %2d: Name Index: %d (%s)\n", j, attr->name_idx, name);
		// TODO add comment with constant pool index
		sz3 = R_BIN_JAVA_UINT (buf, 2);
		if (sz3<0) {
			// XXX: this is a hack. this parser must be fixed
			sz3 = -sz3;
		}
		if (fields) {
			attr->type = R_BIN_JAVA_TYPE_FIELD;
			eprintf ("FIELD\n");
		} else if (sz3 > 0) {
			attr->length = sz3;
			IFDBG printf ("     Length: %d\n", sz3); //R_BIN_JAVA_UINT(buf, 2));
			if (!name) {
				IFDBG printf ("**ERROR ** Cannot identify attribute name into constant pool\n");
				continue;
			}
			if (!strcmp (name, "Code")) {
				attr->type = R_BIN_JAVA_TYPE_CODE;
				r_buf_read_at (bin->b, R_BUF_CUR, (ut8*)buf, 8);

				attr->info.code.max_stack = R_BIN_JAVA_USHORT(buf, 0);
				IFDBG printf("      Max Stack: %d\n", attr->info.code.max_stack);
				attr->info.code.max_locals = R_BIN_JAVA_USHORT(buf, 2);
				IFDBG printf("      Max Locals: %d\n", attr->info.code.max_locals);
				attr->info.code.code_length = R_BIN_JAVA_UINT(buf, 4);
				IFDBG printf("      Code Length: %d\n", attr->info.code.code_length);
				attr->info.code.code_offset = (ut64)bin->b->cur;
				IFDBG printf("      Code At Offset: 0x%08"PFMT64x"\n", (ut64)attr->info.code.code_offset);

				r_buf_read_at (bin->b, R_BUF_CUR, (ut8*)buf, R_BIN_JAVA_UINT (buf, 4)); // READ CODE
				sz4 = read_short (bin);
				attr->info.code.exception_table_length = sz4;
				IFDBG printf("      Exception table length: %d\n",
					attr->info.code.exception_table_length);
				for (k=0; k<sz4; k++) {
					r_buf_read_at(bin->b, R_BUF_CUR, (ut8*)buf, 8);
					attr->info.code.start_pc = R_BIN_JAVA_USHORT(buf,0);
					IFDBG printf("       start_pc:   0x%04x\n", attr->info.code.start_pc);
					attr->info.code.end_pc = R_BIN_JAVA_USHORT(buf,2);
					IFDBG printf("       end_pc:     0x%04x\n", attr->info.code.end_pc);
					attr->info.code.handler_pc = R_BIN_JAVA_USHORT(buf,4);
					IFDBG printf("       handler_pc: 0x%04x\n", attr->info.code.handler_pc);
					attr->info.code.catch_type = R_BIN_JAVA_USHORT(buf,6);
					IFDBG printf("       catch_type: %d\n", attr->info.code.catch_type);
				}
				sz4 = (unsigned int)read_short(bin);
				IFDBG printf("      code Attributes_count: %d\n", sz4);

				if (sz4>0) {
					attr->attributes = malloc(1+sz4 * sizeof(struct r_bin_java_attr_t));
					attributes_walk(bin, attr->attributes, sz4, fields);
				}
			} else
			if (!strcmp (name, "LocalVariableTypeTable")) {
				eprintf ("TODO: LOCAL VARIABLE TYPE TABLE\n");
				sz4 = (unsigned int)read_short (bin);
			} else
			if (!strcmp (name, "LineNumberTable")) {
				attr->type = R_BIN_JAVA_TYPE_LINENUM;
				sz4 = (unsigned int)read_short (bin);
				attr->info.linenum.table_length = sz4;
				IFDBG printf("     Table Length: %d\n", attr->info.linenum.table_length);
//eprintf ("line.%d.sym=%s\n", bin->midx, bin->methods[bin->midx].name);
				symaddr = bin->methods[bin->midx].attributes->info.code.code_offset;
				for (k=0; k<sz4; k++) {
					r_buf_read_at (bin->b, R_BUF_CUR, (ut8*)buf, 4);
					attr->info.linenum.start_pc = R_BIN_JAVA_USHORT (buf, 0);
					//eprintf ("     %2d: start_pc:    0x%04x\n", k, attr->info.linenum.start_pc);
					attr->info.linenum.line_number = R_BIN_JAVA_USHORT (buf, 2);
					//eprintf ("         line_number: %d\n", attr->info.linenum.line_number);
					addrow (bin, symaddr + attr->info.linenum.start_pc, attr->info.linenum.line_number);
#if 0
					eprintf ("line.%d.%d.%d=%d\n", bin->midx, k,
							attr->info.linenum.line_number,
							attr->info.linenum.start_pc);
#endif
				}
			} else
			if (!strcmp (name, "StackMapTable")) {
				r_buf_read_at (bin->b, R_BUF_CUR, (ut8*)buf, 2); // XXX: this is probably wrong
				//printf("     StackMapTable: %d\n", USHORT(buf, 0));
			} else
			if (!strcmp (name, "LocalVariableTable")) {
				int i;
				ut32 lvtl = (ut32)read_short (bin);
//eprintf ("local.%d.sym=%s\n", bin->midx, bin->methods[bin->midx].name);
				for (i=0; i<lvtl; i++) {
					int start_pc = start_pc = read_short (bin);
					int length = length = read_short (bin);
					int name_idx = name_idx = read_short (bin);
					int desc_idx = desc_idx = read_short (bin);
					int index = index = read_short (bin);

#if 0
					const char *name = get_CP (bin, name_idx-1)->value;
					const char *desc = get_CP (bin, desc_idx-1)->value;
eprintf ("local.%d.%d.type=%s\n", bin->midx, i, desc);
eprintf ("local.%d.%d.name=%s\n", bin->midx, i, name);
#endif
				}
			} else
			if (!strcmp (name, "ConstantValue")) {
				attr->type = R_BIN_JAVA_TYPE_CONST;
				r_buf_read_at (bin->b, R_BUF_CUR, (ut8*)buf, 2);
	#if 0
				printf("     Name Index: %d\n", R_BIN_JAVA_USHORT(buf, 0)); // %s\n", R_BIN_JAVA_USHORT(buf, 0), cp_items[R_BIN_JAVA_USHORT(buf,0)-1].value);
				printf("     AttributeLength: %d\n", R_BIN_JAVA_UINT(buf, 2));
	#endif
				attr->info.const_value_idx = R_BIN_JAVA_USHORT(buf, 0);
				IFDBG printf ("     ConstValueIndex: %d\n", attr->info.const_value_idx);
			} else {
				eprintf ("** ERROR ** Unknown section '%s'\n", name);
				return R_FALSE;
			}
		}
	}
	return R_TRUE;
}
Beispiel #10
0
void
getzoomrow(zoom * z, short *buf, int y)
{
    float fy;
    int ay;
    FILTER *f;
    int i, max;
    short *row;

    if (y == 0) {
        z->curay = -1;
        z->y = 0;
        z->ay = 0;
    }
    if (z->type == IMPULSE) {
        fy = GRIDTOFLOAT(z->y, z->bny);
        ay = FLOATTOGRID(fy, z->any);
        if (z->anx == z->bnx) {
            if (z->curay != ay) {
                z->getfunc(z->abuf, ay);
                z->curay = ay;
                if (xfiltfunc)
                    xfiltfunc(z->abuf, z->bnx);
            }
            memcpy(buf, z->abuf, z->bnx * sizeof(short));
        } else {
            if (z->curay != ay) {
                z->getfunc(z->abuf, ay);
                xscalebuf(z->xmap, z->bbuf, z->bnx);
                z->curay = ay;
                if (xfiltfunc)
                    xfiltfunc(z->bbuf, z->bnx);
            }
            memcpy(buf, z->bbuf, z->bnx * sizeof(short));
        }
    } else if (z->any == 1 && z->bny == 1) {
        z->getfunc(z->abuf, z->ay++);
        applyxfilt(z->filtrows[0], z->xfilt, z->bnx);
        if (xfiltfunc)
            xfiltfunc(z->filtrows[0], z->bnx);
        if (z->clamp) {
            clamprow(z->filtrows[0], z->tbuf, z->bnx);
            memcpy(buf, z->tbuf, z->bnx * sizeof(short));
        } else {
            memcpy(buf, z->filtrows[0], z->bnx * sizeof(short));
        }
    } else {
        f = z->yfilt + z->y;
        max = (int) (sizeof(f->dat) / sizeof(short) + (f->n - 1));
        while (z->ay <= max) {
            z->getfunc(z->abuf, z->ay++);
            row = z->filtrows[0];
            for (i = 0; i < (z->nrows - 1); i++)
                z->filtrows[i] = z->filtrows[i + 1];
            z->filtrows[z->nrows - 1] = row;
            applyxfilt(z->filtrows[z->nrows - 1], z->xfilt, z->bnx);
            if (xfiltfunc)
                xfiltfunc(z->filtrows[z->nrows - 1], z->bnx);
        }
        if (f->n == 1) {
            if (z->clamp) {
                clamprow(z->filtrows[z->nrows - 1], z->tbuf, z->bnx);
                memcpy(buf, z->tbuf, z->bnx * sizeof(short));
            } else {
                memcpy(buf, z->filtrows[z->nrows - 1], z->bnx * sizeof(short));
            }
        } else {
            setintrow(z->accrow, f->halftotw, z->bnx);
            for (i = 0; i < f->n; i++)
                addrow(z->accrow, z->filtrows[i + (z->nrows - 1) - (f->n - 1)],
                       f->w[i], z->bnx);
            divrow(z->accrow, z->bbuf, f->totw, z->bnx);
            if (z->clamp) {
                clamprow(z->bbuf, z->tbuf, z->bnx);
                memcpy(buf, z->tbuf, z->bnx * sizeof(short));
            } else {
                memcpy(buf, z->bbuf, z->bnx * sizeof(short));
            }
        }
    }
    z->y++;
}
Beispiel #11
0
void vertex_mat(Mesh &m , float vW0, CCS& ccs , std::vector<double> & bb)
{
  //weight for vertices at the intersection of at least three clusters
  //weight for regular vertices is 1

  //maximum number of clusters adjacent to a vertex
  size_t maxLabel=3;

  std::vector<bool>processed (m.v.size());
  std::vector<bool>important(m.v.size());
  std::vector<real_t > vertArea(m.v.size());
  for(size_t ii=0; ii<m.t.size(); ii++) {
    for(int vidx = 0; vidx<3; vidx++) {
      int idx = m.t[ii][vidx];
      vertArea[idx]+=m.t[ii].A;
      if(processed[idx]) {
        continue;
      }
      std::set<int>labels;
      processed[idx]=1;
      labels.insert(m.t[ii].label);
      bool found = 1;
      std::set<int>visited_t;
      visited_t.insert(ii);
      int cur=ii;
      while(found) {
        found =0 ;
        for (size_t nbr = 0; nbr<m.adjMat[cur].size(); nbr++) {
          size_t nbrIdx = m.adjMat[cur][nbr];
          if(visited_t.find(nbrIdx)!=visited_t.end()) {
            continue;
          }
          if(find(m.t[nbrIdx].x,idx,3)>=0) {
            found=1;
            cur=nbrIdx;
            visited_t.insert(nbrIdx);
            break;
          }
        }
        if(found) {
          int lab = m.t[cur].label;
          labels.insert(lab);
          if(labels.size()>=maxLabel) {
            break;
          }
        }
      }

      if(labels.size()>=maxLabel) {
        important[idx]=true;
      }

    }
  }
  for(int axis=0; axis<3; axis++) {

  for(size_t idx=0;idx<m.v.size();idx++){
    real_t f;
    std::map<int,real_t>val;
    if(important[idx]){
      f=vW*vW0;
    } else {
       f=vW0;
    }
    f*=vertArea[idx];
    val[idx]=f;
    addrow(val,ccs,axis*nvar);
    bb.push_back(f*m.v0[idx][axis]);

  }
  }
}