Exemple #1
0
double fullMatrix<double>::determinant() const
{
  fullMatrix<double> tmp(*this);
  int M = size1(), N = size2(), lda = size1(), info;
  int *ipiv = new int[std::min(M, N)];
  F77NAME(dgetrf)(&M, &N, tmp._data, &lda, ipiv, &info);
  double det = 1.;
  if(info == 0){
    for(int i = 0; i < size1(); i++){
      det *= tmp(i, i);
      if(ipiv[i] != i + 1) det = -det;
    }
  }
  else if(info > 0)
    det = 0.;
  else
    Msg::Error("Wrong %d-th argument in matrix factorization", -info);
  delete [] ipiv;
  return det;
}
Exemple #2
0
vcl_size_t size(vector_expression<LHS, const int, op_matrix_diag> const & proxy)
{
  int k = proxy.rhs();
  int A_size1 = static_cast<int>(size1(proxy.lhs()));
  int A_size2 = static_cast<int>(size2(proxy.lhs()));

  int row_depth = std::min(A_size1, A_size1 + k);
  int col_depth = std::min(A_size2, A_size2 - k);

  return vcl_size_t(std::min(row_depth, col_depth));
}
int CRSSparsity::getNZ(int i, int j){
  casadi_assert_message(i<size1() && j<size2(),"Indices out of bounds");

  if (i<0) i += size1();
  if (j<0) j += size2();
  
  // Quick return if matrix is dense
  if(numel()==size())
    return j+i*size2();
  
  // Quick return if we are adding an element to the end
  if(rowind(i)==size() || (rowind(i+1)==size() && col().back()<j)){
    vector<int>& colv = colRef();
    vector<int>& rowindv = rowindRef();
    colv.push_back(j);
    for(int ii=i; ii<size1(); ++ii){
      rowindv[ii+1]++;
    }
    return colv.size()-1;
  }

  // go to the place where the element should be
  int ind;
  for(ind=rowind(i); ind<rowind(i+1); ++ind){ // better: loop from the back to the front
    if(col(ind) == j){
      return ind; // element exists
    } else if(col(ind) > j)
      break;                // break at the place where the element should be added
  }
  
  // Make sure that there no other objects are affected
  makeUnique();
  
  // insert the element
  colRef().insert(colRef().begin()+ind,j);
  for(int row=i+1; row<size1()+1; ++row)
    rowindRef()[row]++;
  
  // Return the location of the new element
  return ind;
}
Exemple #4
0
// CMainFrame message handlers
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext *pContext)
  {
  if(!m_wndSplitter.CreateStatic(this, 1, 2))
    {
    TRACE0("Failed to create split bar ");
    return FALSE; // failed to create
    }

  CRect rect;
  GetClientRect(&rect);

  CSize size(rect.Size());
  CSize size1(size);
  size.cx /= 4;
  if(size.cx > 120)
    size.cx = 120;

  if(!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CDeviceView), size, pContext))
    {
    TRACE0("Failed to create device pane");
    return FALSE; // failed to create
    }

  if(!m_wndSplitter2.CreateStatic(&m_wndSplitter, 2, 1,
    WS_CHILD | WS_VISIBLE | WS_BORDER,  // style, WS_BORDER is needed
    m_wndSplitter.IdFromRowCol(0, 1)
    ))
    {
    TRACE0("Failed to create split bar ");
    return FALSE; // failed to create
    }

  size.cx = size1.cx - size.cx;
  size.cy = (size1.cy*3)/4;


  if(!m_wndSplitter2.CreateView(0, 0, RUNTIME_CLASS(CTagView), size, pContext))
    {
    TRACE0("Failed to create device pane");
    return FALSE; // failed to create
    }

  if(!m_wndSplitter2.CreateView(1, 0, RUNTIME_CLASS(CErrorView), size, pContext))
    {
    TRACE0("Failed to create device pane");
    return FALSE; // failed to create
    }

  return TRUE;

  //return CFrameWnd::OnCreateClient(lpcs, pContext);
  }
Exemple #5
0
double spectral_norm_diag(const M &mat) {
  typedef Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic> matrix_t;
  const double cutoff = 1E-15;
  const int rows = size1(mat);
  const int cols = size2(mat);
  if (rows == 0 || cols == 0) {
    return 0.0;
  }
  matrix_t mat_tmp(rows, cols);
  double max_abs = -1;
  for (int j = 0; j < cols; ++j) {
    for (int i = 0; i < rows; ++i) {
      mat_tmp(i, j) = mat(i, j);
      max_abs = std::max(max_abs, std::abs(mat_tmp(i, j)));
    }
  }
  if (std::abs(max_abs) < 1E-300) {
    return 0.0;
  } else {
    const double coeff = 1.0 / max_abs;
    for (int j = 0; j < cols; ++j) {
      for (int i = 0; i < rows; ++i) {
        mat_tmp(i, j) *= coeff;
        if (std::abs(mat_tmp(i, j)) < cutoff) {
          mat_tmp(i, j) = 0.0;
        }
      }
    }
    if (mat_tmp.rows() > mat_tmp.cols()) {
      mat_tmp = mat_tmp.adjoint() * mat_tmp;
    } else {
      mat_tmp = mat_tmp * mat_tmp.adjoint();
    }
    const double max_abs2 = mat_tmp.cwiseAbs().maxCoeff();
    for (int j = 0; j < mat_tmp.cols(); ++j) {
      for (int i = 0; i < mat_tmp.rows(); ++i) {
        if (std::abs(mat_tmp(i, j)) < cutoff) {
          mat_tmp(i, j) = 0.0;
        }
      }
    }
    Eigen::SelfAdjointEigenSolver<matrix_t> esolv(mat_tmp, false);
    const double norm = std::sqrt(esolv.eigenvalues().cwiseAbs().maxCoeff()) / coeff;
    if (std::isnan(norm)) {
      std::cout << "Warning: spectral_norm_diag is NaN. max_abs = " << max_abs << " max_abs2 = " << max_abs2
                << std::endl;
      return 0.0;
    }
    //assert(!isnan(norm));
    return norm;
  }
}
Exemple #6
0
Stream& pretty_print( Stream& os, const T& t ) {
    namespace bindings = ::boost::numeric::bindings;
    os << "[" << size1(t) << "] ";
    typename bindings::result_of::begin< const T >::type i = bindings::begin(t);
    if ( i != bindings::end(t) ) {
        os << *i;
        ++i;
    }
    for( ; i != bindings::end(t); ++i ) {
        os << " " << *i;
    }
    return os;
}
Exemple #7
0
void GuiManager::generateSquareGrid() {

    std::cout << getUi()->label->text().toStdString() << std::endl;
    Sound::instance().playSoundTrack();

    ui->gameLayout->setContentsMargins(100,100,100,100);
    vector<vector<Square*>> squaresList = Game::instance().getSquares();


    vector<vector<Square*>> squares = Game::instance().getSquares();

    if ( squares.size() == 0) {
        return;
    }


    int border=5;
    int size = ui->gridLayoutWidget->width()/squares.size()/2;

    Square::setSize(size);
    Square::setBorder(border);

    for(size_t index = 0;index<squares.size();index++){
        for (size_t sub_index = 0; sub_index <squares.at(index).size(); sub_index++ ) {

            Square *proc = squares.at(index).at(sub_index);

            SquareLabel *lbl = new SquareLabel(proc,ui->gridLayoutWidget);

            proc->setLabel(lbl);
            QSize size1(size,size);
            QPixmap map = setmap(proc, size1);
            lbl->setPixmap(map);
            lbl->setFixedHeight(size);
            lbl->setFixedWidth(size);
            Player *owner = proc->getOwner();
            std::string color = owner == NULL ? "black" : owner->getColor();
            lbl->setStyleSheet("border:" + QString::fromStdString(to_string(border)) +  "px solid " + QString::fromStdString(color) + ";\n");
            ui->gameLayout->addWidget(lbl,index,sub_index,0);
            lbl->setAlignment(Qt::AlignCenter);
            proc->setX(index);
            proc->setY(sub_index);
            lbl->show();
        }
        //ui->gameLayout->set(index,size);
        //ui->gameLayout->setRowMinimumHeight(index,size);

    }
    ui->gameLayout->setSpacing(0);
}
Exemple #8
0
bool Brush::operator==(const Brush& brush) const
{
	return size1() == brush.size1() && size2() == brush.size2() &&
			qAbs(hardness1() - brush.hardness1()) <= 1.0/256.0 &&
			qAbs(hardness2() - brush.hardness2()) <= 1.0/256.0 &&
			qAbs(opacity1() - brush.opacity1()) <= 1.0/256.0 &&
			qAbs(opacity2() - brush.opacity2()) <= 1.0/256.0 &&
			color1() == brush.color1() &&
			color2() == brush.color2() &&
			spacing() == brush.spacing() &&
			subpixel() == brush.subpixel() &&
			incremental() == brush.incremental() &&
			blendingMode() == brush.blendingMode();
}
Exemple #9
0
  void Reshape::evaluateMX(const MXPtrV& input, MXPtrV& output, const MXPtrVV& fwdSeed, MXPtrVV& fwdSens, const MXPtrVV& adjSeed, MXPtrVV& adjSens, bool output_given){
    // Quick return if inplace
    if(input[0]==output[0]) return;

    if(!output_given){
      *output[0] = reshape(*input[0],size1(),size2());
    }

    // Forward sensitivities
    int nfwd = fwdSens.size();
    for(int d = 0; d<nfwd; ++d){
      *fwdSens[d][0] = reshape(*fwdSeed[d][0],size1(),size2());
    }
    
    // Adjoint sensitivities
    int nadj = adjSeed.size();
    for(int d=0; d<nadj; ++d){
      MX& aseed = *adjSeed[d][0];
      MX& asens = *adjSens[d][0];
      asens += reshape(aseed,dep().size1(),dep().size2());
      aseed = MX();
    }
  }
Exemple #10
0
/// Solve system of linear equations M*x == rhs, M is this matrix
/// This matrix is destroyed.
/// @param rhs :: The right-hand-side vector
/// @param x :: The solution vector
/// @throws std::invalid_argument if the input vectors have wrong sizes.
/// @throws std::runtime_error if the GSL fails to solve the equations.
void GSLMatrix::solve(const GSLVector &rhs, GSLVector &x) {
  if (size1() != size2()) {
    throw std::invalid_argument(
        "System of linear equations: the matrix must be square.");
  }
  size_t n = size1();
  if (rhs.size() != n) {
    throw std::invalid_argument(
        "System of linear equations: right-hand side vector has wrong size.");
  }
  x.resize(n);
  int s;
  gsl_permutation *p = gsl_permutation_alloc(n);
  gsl_linalg_LU_decomp(gsl(), p, &s); // matrix is modified at this moment
  int res = gsl_linalg_LU_solve(gsl(), p, rhs.gsl(), x.gsl());
  gsl_permutation_free(p);
  if (res != GSL_SUCCESS) {
    std::string message = "Failed to solve system of linear equations.\n"
                          "Error message returned by the GSL:\n" +
                          std::string(gsl_strerror(res));
    throw std::runtime_error(message);
  }
}
Exemple #11
0
int main()
{
  int s1, s2;

  printf("size1: %d\n", s1=size1());
  printf("size2: %d\n", s2=size2());
  printf("(correct output is 8, then 12)\n");
  
  if (s1==8 && s2==12) {
    return 0;
  }
  else {
    return 2;
  }
}
Exemple #12
0
double spectral_norm_SVD(const M &mat) {
  typedef Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic> matrix_t;
  const double cutoff = 1E-15;
  const int rows = size1(mat);
  const int cols = size2(mat);
  if (rows == 0 || cols == 0) {
    return 0.0;
  }
  matrix_t mat_tmp(rows, cols);
  double max_abs = -1;
  for (int j = 0; j < cols; ++j) {
    for (int i = 0; i < rows; ++i) {
      mat_tmp(i, j) = mat(i, j);
      max_abs = std::max(max_abs, std::abs(mat_tmp(i, j)));
    }
  }
  if (max_abs == 0.0) {
    return 0.0;
  }
  const double coeff = 1.0 / max_abs;
  for (int j = 0; j < cols; ++j) {
    for (int i = 0; i < rows; ++i) {
      mat_tmp(i, j) *= coeff;
      if (std::abs(mat_tmp(i, j)) < cutoff) {
        mat_tmp(i, j) = 0.0;
      }
    }
  }
  //const double tmp = mat_tmp.squaredNorm();
  Eigen::JacobiSVD<matrix_t> svd(mat_tmp);
#ifndef NDEBUG
  const int size_SVD = svd.singularValues().size();
  for (int i = 0; i < size_SVD - 1; ++i) {
    assert(std::abs(svd.singularValues()[i]) >= std::abs(svd.singularValues()[i + 1]));
  }
  if (isnan(std::abs(svd.singularValues()[0]) / coeff)) {
    std::cout << "Norm is Nan" << std::endl;
    std::cout << "max_abs is " << max_abs << std::endl;
    std::cout << "coeff is " << coeff << std::endl;
    std::cout << "mat is " << std::endl << mat << std::endl;
    std::cout << "mat_tmp is " << std::endl << mat_tmp << std::endl;
    exit(-1);
  }
#endif
  const double norm = std::abs(svd.singularValues()[0]) / coeff;
  assert(!isnan(norm));
  return norm;
}
Exemple #13
0
/// Matrix by vector multiplication
/// @param v :: A vector to multiply by. Must have the same size as size2().
/// @returns A vector - the result of the multiplication. Size of the returned
/// vector equals size1().
/// @throws std::invalid_argument if the input vector has a wrong size.
/// @throws std::runtime_error if the underlying GSL routine fails.
GSLVector GSLMatrix::operator*(const GSLVector &v) const {
  if (v.size() != size2()) {
    throw std::invalid_argument(
        "Matrix by vector multiplication: wrong size of vector.");
  }
  GSLVector res(size1());
  auto status =
      gsl_blas_dgemv(CblasNoTrans, 1.0, gsl(), v.gsl(), 0.0, res.gsl());
  if (status != GSL_SUCCESS) {
    std::string message = "Failed to multiply matrix by a vector.\n"
                          "Error message returned by the GSL:\n" +
                          std::string(gsl_strerror(status));
    throw std::runtime_error(message);
  }
  return res;
}
dgVector dgCollisionBox::SupportVertexSpecial(const dgVector& dir, dgInt32* const vertexIndex) const
{
	dgAssert(dgAbsf(dir.DotProduct3(dir) - dgFloat32(1.0f)) < dgFloat32(1.0e-3f));
	dgAssert(dir.m_w == dgFloat32(0.0f));
	dgVector mask(dir < dgVector(dgFloat32(0.0f)));
	if (vertexIndex) {
		dgVector index(m_indexMark.CompProduct4(mask & dgVector::m_one));
		index = (index.AddHorizontal()).GetInt();
		*vertexIndex = dgInt32 (index.m_ix);
	}

	dgVector padd (D_BOX_SKIN_THINCKNESS);
	padd = padd & dgVector::m_triplexMask;
	dgVector size0 (m_size[0] - padd);
	dgVector size1 (m_size[1] + padd);
	return (size1 & mask) + size0.AndNot(mask);
}
Exemple #15
0
bool fullMatrix<double>::eig(fullVector<double> &DR, fullVector<double> &DI,
                             fullMatrix<double> &VL, fullMatrix<double> &VR,
                             bool sortRealPart)
{
  int N = size1(), info;
  int lwork = 10 * N;
  double *work = new double[lwork];
  F77NAME(dgeev)("V", "V", &N, _data, &N, DR._data, DI._data,
                 VL._data, &N, VR._data, &N, work, &lwork, &info);
  delete [] work;

  if(info > 0)
    Msg::Error("QR Algorithm failed to compute all the eigenvalues", info, info);
  else if(info < 0)
    Msg::Error("Wrong %d-th argument in eig", -info);
  else if(sortRealPart)
    eigSort(N, DR._data, DI._data, VL._data, VR._data);

  return true;
}
void NonUniformScaledCollision(DemoEntityManager* const scene)
{
	// load the skybox
	scene->CreateSkyBox();

	// load the scene from a ngd file format
	CreateLevelMesh(scene, "flatPlane.ngd", 1);
	//	CreateLevelMesh (scene, "sponza.ngd", 1);
	//	CreateLevelMesh (scene, "cattle.ngd", fileName);
	//	CreateLevelMesh (scene, "playground.ngd", 1);

	dMatrix camMatrix(dRollMatrix(-20.0f * 3.1416f / 180.0f) * dYawMatrix(-45.0f * 3.1416f / 180.0f));
	dQuaternion rot(camMatrix);
	//	dVector origin (-30.0f, 40.0f, -15.0f, 0.0f);
	dVector origin(-10.0f, 5.0f, -15.0f, 0.0f);
	scene->SetCameraMatrix(rot, origin);

	NewtonWorld* const world = scene->GetNewton();
	int defaultMaterialID = NewtonMaterialGetDefaultGroupID(world);
	dVector location(0.0f, 0.0f, 0.0f, 0.0f);
	dVector size0(0.5f, 0.5f, 1.0f, 0.0f);
	dVector size1(0.5f, 0.5f, 0.5f, 0.0f);

	int count = 5;
	dMatrix shapeOffsetMatrix(dRollMatrix(3.141592f / 2.0f));
	shapeOffsetMatrix.m_posit.m_y = 0.0f;

	AddNonUniformScaledPrimitives(scene, 10.0f, location, size0, count, count, 4.0f, _SPHERE_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size0, count, count, 4.0f, _BOX_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size0, count, count, 4.0f, _CAPSULE_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size1, count, count, 4.0f, _CAPSULE_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size1, count, count, 4.0f, _CYLINDER_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size0, count, count, 4.0f, _CYLINDER_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size0, count, count, 4.0f, _CHAMFER_CYLINDER_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size0, count, count, 4.0f, _CONE_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size0, count, count, 4.0f, _REGULAR_CONVEX_HULL_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size0, count, count, 4.0f, _RANDOM_CONVEX_HULL_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size0, count, count, 4.0f, _COMPOUND_CONVEX_CRUZ_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
}
Exemple #17
0
bool fullMatrix<double>::invertInPlace()
{
  int N = size1(), nrhs = N, lda = N, ldb = N, info;
  int *ipiv = new int[N];
  double * invA = new double[N*N];

  for (int i = 0; i < N * N; i++) invA[i] = 0.;
  for (int i = 0; i < N; i++) invA[i * N + i] = 1.;

  F77NAME(dgesv)(&N, &nrhs, _data, &lda, ipiv, invA, &ldb, &info);
  memcpy(_data, invA, N * N * sizeof(double));

  delete [] invA;
  delete [] ipiv;

  if(info == 0) return true;
  if(info > 0)
    Msg::Error("U(%d,%d)=0 in matrix in place inversion", info, info);
  else
    Msg::Error("Wrong %d-th argument in matrix inversion", -info);
  return false;
}
Exemple #18
0
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
   if (!m_wndSplitter.CreateStatic(this, 1, 2))
      {
      TRACE0("Failed to create split bar ");
      return FALSE;    // failed to create
      }

   CRect rect;
   GetClientRect( &rect );
   CSize size( rect.Size() );
   CSize size1( size );
   size.cx /= 4;
   if (size.cx>150)
     size.cx=150;

   if( !m_wndSplitter.CreateView(0, 0,
                                 RUNTIME_CLASS(CDeviceView),
                                 size,
                                 pContext))
      {
      TRACE0("Failed to create device pane");
      return FALSE;    // failed to create
      }

   size.cx = size1.cx-size.cx;
   if( !m_wndSplitter.CreateView(0, 1,
                                 RUNTIME_CLASS(CTagView),
                                 size,
                                 pContext))
      {
      TRACE0("Failed to create device pane");
      return FALSE;    // failed to create
      }

   return TRUE;
}
Exemple #19
0
 static typename result_of::end_value< T >::type end_value( Id& id ) {
     return bindings::begin_value( id.get() ) +
            offset( id.get(), id.m_index, size1(id) );
 }
Exemple #20
0
KBBGame::KBBGame() : KTopLevelWidget()     
{
  int i;

  setCaption(QString("KBlackBox ")+KBVERSION);

  menu                = new KMenuBar(this, "menu");
  QPopupMenu *game    = new QPopupMenu;
  QPopupMenu *file    = new QPopupMenu;
  sizesm  = new QPopupMenu;
  ballsm  = new QPopupMenu;
  QPopupMenu *help = new QPopupMenu;
  options = new QPopupMenu;
 
  CHECK_PTR( file );
  CHECK_PTR( game );
  CHECK_PTR( help );
  CHECK_PTR( sizesm );
  CHECK_PTR( ballsm );
  CHECK_PTR( options );
  CHECK_PTR( menu );

  help->insertItem( trans->translate("&Help"), ID_HELP );
  help->setAccel( CTRL+Key_H, ID_HELP );
  help->insertSeparator();
  help->insertItem( trans->translate("&About KBlackBox"), ID_ABOUT );
  help->setAccel( CTRL+Key_A, ID_ABOUT );
  help->insertItem( trans->translate("About &Qt"), ID_ABOUT_QT );

		    
  file->insertItem( trans->translate("&Quit"), ID_QUIT );
  file->setAccel( CTRL+Key_Q, ID_QUIT );

  game->insertItem( trans->translate("&New"), ID_NEW );
  game->insertItem( trans->translate("&Give up"), ID_GIVEUP );
  game->insertItem( trans->translate("&Done"), ID_DONE );
  game->insertSeparator();
  game->insertItem( trans->translate("&Resize"), ID_RESIZE );

  sizes1id = sizesm->insertItem( "  8 x 8  ", this, SLOT(size1()) );
  sizes2id = sizesm->insertItem( " 10 x 10 ", this, SLOT(size2()) );
  sizes3id = sizesm->insertItem( " 12 x 12 ", this, SLOT(size3()) );
  sizesm->setCheckable( TRUE );

  balls1id = ballsm->insertItem( " 4 ", this, SLOT(balls1()) );
  balls2id = ballsm->insertItem( " 6 ", this, SLOT(balls2()) );
  balls3id = ballsm->insertItem( " 8 ", this, SLOT(balls3()) );
  ballsm->setCheckable( TRUE );

  options->insertItem( trans->translate("&Size"), sizesm );  
  options->insertItem( trans->translate("&Balls"), ballsm );
  tut1id = options->insertItem( trans->translate("&Tutorial"),
				this, SLOT(tutorialSwitch()) );
  options->setCheckable( TRUE );

  connect( file, SIGNAL(activated(int)), SLOT(callBack(int)) );
  connect( help, SIGNAL(activated(int)), SLOT(callBack(int)) );
  connect( game, SIGNAL(activated(int)), SLOT(callBack(int)) );
 
  menu->insertItem( trans->translate("&File"), file );
  menu->insertItem( trans->translate("&Game"), game );
  menu->insertItem( trans->translate("&Options"), options );
  menu->insertSeparator();
  menu->insertItem( trans->translate("&Help"), help );

  menu->show(); 
  setMenu( menu );

  KIconLoader *loader = kapp->getIconLoader();
  QPixmap **pix = new QPixmap*[NROFTYPES];
  pix[0] = new QPixmap();
  *pix[0] = loader->loadIcon( pFNames[0] );
  if (!pix[0]->isNull()) {
    debug( "Pixmap \"%s\" loaded.", pFNames[0] );
    for (i = 1; i < NROFTYPES; i++) {
      pix[i] = new QPixmap;
      *pix[i] = loader->loadIcon( pFNames[i] );
      if (!pix[i]->isNull()) {
	debug( "Pixmap \"%s\" loaded.", pFNames[i] );
      } else {
	pix[i] = pix[i-1];
	pix[i]->detach();
	debug( "Cannot find pixmap \"%s\". Using previous one.", pFNames[i] );
      }
    }
  } else {
    debug( "Cannot find pixmap \"%s\". Pixmaps will not be loaded.",
	   pFNames[0] );
    delete pix[0];
    delete pix;
    pix = NULL;
  }
  gr = new KBBGraphic( pix, this );
  connect( gr, SIGNAL(inputAt(int,int,int)),
	  this, SLOT(gotInputAt(int,int,int)) );
  connect( this, SIGNAL(gameRuns(bool)),
	  gr, SLOT(setInputAccepted(bool)) );
  connect( gr, SIGNAL(endMouseClicked()),
	  this, SLOT(gameFinished()) );
  
  /*
  QToolTip::add( doneButton, trans->translate(
		 "Click here when you think you placed all the balls.") );
		 */

  QString tmps;
  stat = new KStatusBar( this );
  tmps.sprintf( "aaaaaaaa" );
  stat->insertItem( (const char *) tmps, SSCORE );
  tmps.sprintf( "aaaaaaaaaaa" );
  stat->insertItem( (const char *) tmps, SBALLS );
  tmps.sprintf( "aaaaaaa" );
  stat->insertItem( (const char *) tmps, SRUN );
  tmps.sprintf( "aaaaaaaaaa" );
  stat->insertItem( (const char *) tmps, SSIZE );
  setStatusBar( stat );

  tool = new KToolBar( this );
  tool->insertButton( loader->loadIcon("exit.xpm"),
		      ID_QUIT, TRUE, trans->translate("Quit") );
  tool->insertButton( loader->loadIcon("reload.xpm"),
		      ID_NEW, TRUE, trans->translate("New") );
  tool->insertButton( loader->loadIcon("giveup.xpm"),
		      ID_GIVEUP, TRUE, trans->translate("Give up") );
  tool->insertButton( loader->loadIcon("done.xpm"),
		      ID_DONE, TRUE, trans->translate("Done") );
  tool->insertSeparator();
  tool->insertButton( loader->loadIcon("help.xpm"), ID_HELP, TRUE,
		      trans->translate("Help") );
  connect( tool, SIGNAL(clicked(int)), SLOT(callBack(int)) );
  addToolBar( tool );
  tool->setBarPos( KToolBar::Top );
  tool->show();
  
  /*
     Game initializations
  */
  running = FALSE;
  gameBoard = NULL;

  KConfig *kConf;
  int j;
  kConf = KApplication::getKApplication()->getConfig();
  kConf->setGroup( "KBlackBox Setup" );
  if (kConf->hasKey( "Balls" )) {
    i = kConf->readNumEntry( "Balls" );
    balls = i;
    switch (i) {
    case 4: ballsm->setItemChecked( balls1id, TRUE ); break;
    case 6: ballsm->setItemChecked( balls2id, TRUE ); break;
    case 8: ballsm->setItemChecked( balls3id, TRUE ); break;
    }
  } else {
    balls = 4;
    ballsm->setItemChecked( balls1id, TRUE );
  }
  if ((kConf->hasKey( "Width" )) &&
      (kConf->hasKey( "Balls" ))) {
    i = kConf->readNumEntry( "Width" );
    j = kConf->readNumEntry( "Height" );
    gr->setSize( i+4, j+4 ); // +4 is the space for "lasers" and an edge...
    gameBoard = new RectOnArray( gr->numC(), gr->numR() );
    switch (i) {
    case 8: sizesm->setItemChecked( sizes1id, TRUE ); break;
    case 10: sizesm->setItemChecked( sizes2id, TRUE ); break;
    case 12: sizesm->setItemChecked( sizes3id, TRUE ); break;
    }
  } else {
    gr->setSize( 8+4, 8+4 ); // +4 is the space for "lasers" and an edge...
    gameBoard = new RectOnArray( gr->numC(), gr->numR() );
    sizesm->setItemChecked( sizes1id, TRUE );
  }
  if (kConf->hasKey( "tutorial" )) {
    tutorial = (bool) kConf->readNumEntry( "tutorial" );
  } else tutorial = FALSE;
  options->setItemChecked( tut1id, tutorial );

  QString s, s1;
  int pos;
  setMinSize();
  gameResize();
  if (kConf->hasKey( "appsize" )) {
    s = kConf->readEntry( "appsize" );
    debug("%s", (const char *) s);
    pos = s.find( 'x' );
    s1 = s.right( s.length() - pos - 1 );
    s.truncate( pos - 1 );
    //    debug("%s", (const char *) s);
    //    debug("%s", (const char *) s1);
    resize( s.toInt(), s1.toInt() );
  }

  setScore( 0 );
  ballsPlaced = 0;
  updateStats();

  setView( gr );

  newGame();
}
void ScaledMeshCollision (DemoEntityManager* const scene)
{
	// load the skybox
	scene->CreateSkyBox();

	// load the scene from a ngd file format
	CreateLevelMesh (scene, "flatPlane.ngd", 1);
	//CreateLevelMesh (scene, "flatPlaneDoubleFace.ngd", 1);
	//CreateLevelMesh (scene, "sponza.ngd", 0);
	//CreateLevelMesh (scene, "cattle.ngd", fileName);
	//CreateLevelMesh (scene, "playground.ngd", 0);

	//dMatrix camMatrix (dRollMatrix(-20.0f * 3.1416f /180.0f) * dYawMatrix(-45.0f * 3.1416f /180.0f));
	dMatrix camMatrix (dGetIdentityMatrix());
	dQuaternion rot (camMatrix);
	dVector origin (-15.0f, 5.0f, 0.0f, 0.0f);
	//origin = origin.Scale (0.25f);
	scene->SetCameraMatrix(rot, origin);


	NewtonWorld* const world = scene->GetNewton();
	int defaultMaterialID = NewtonMaterialGetDefaultGroupID (world);
	dVector location (0.0f, 0.0f, 0.0f, 0.0f);

	dMatrix matrix (dGetIdentityMatrix());
	matrix.m_posit = location;
	matrix.m_posit.m_x = 0.0f;
	matrix.m_posit.m_y = 0.0f;
	matrix.m_posit.m_z = 0.0f;
	matrix.m_posit.m_w = 1.0f;

	DemoEntity teaPot (dGetIdentityMatrix(), NULL);
	teaPot.LoadNGD_mesh("teapot.ngd", world);
	//teaPot.LoadNGD_mesh("box.ngd", world);

	NewtonCollision* const staticCollision = CreateCollisionTree (world, &teaPot, 0, true);
	CreateScaleStaticMesh (&teaPot, staticCollision, scene, matrix, dVector (1.0f, 1.0f, 1.0f, 0.0f));
//	CreateScaleStaticMesh (&teaPot, staticCollision, scene, matrix, dVector (0.5f, 0.5f, 2.0f, 0.0f));

	matrix.m_posit.m_z = -5.0f;
	CreateScaleStaticMesh (&teaPot, staticCollision, scene, matrix, dVector (0.5f, 0.5f, 2.0f, 0.0f));

	matrix.m_posit.m_z = 5.0f;
	CreateScaleStaticMesh (&teaPot, staticCollision, scene, matrix, dVector (3.0f, 3.0f, 1.5f, 0.0f));

	matrix.m_posit.m_z = 0.0f;
	matrix.m_posit.m_x = -5.0f;
	CreateScaleStaticMesh (&teaPot, staticCollision, scene, matrix, dVector (0.5f, 0.5f, 0.5f, 0.0f));

	matrix.m_posit.m_x = 5.0f;
	CreateScaleStaticMesh (&teaPot, staticCollision, scene, matrix, dVector (2.0f, 2.0f, 2.0f, 0.0f));

	// do not forget to destroy the collision mesh helper
	NewtonDestroyCollision(staticCollision);

	dVector size0 (1.0f, 1.0f, 1.0f, 0.0f);
	dVector size1 (0.5f, 1.0f, 1.0f, 0.0f);
	dMatrix shapeOffsetMatrix (dRollMatrix(3.141592f/2.0f));

	int count = 3;
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size0, count, count, 5.0f, _SPHERE_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size0, count, count, 5.0f, _BOX_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size0, count, count, 5.0f, _CAPSULE_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size1, count, count, 5.0f, _CAPSULE_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size1, count, count, 5.0f, _CYLINDER_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size0, count, count, 5.0f, _CYLINDER_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size0, count, count, 5.0f, _CHAMFER_CYLINDER_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size0, count, count, 5.0f, _CONE_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size0, count, count, 5.0f, _REGULAR_CONVEX_HULL_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);
	AddNonUniformScaledPrimitives(scene, 10.0f, location, size0, count, count, 5.0f, _RANDOM_CONVEX_HULL_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix);

	origin.m_x -= 4.0f;
	origin.m_y += 1.0f;
	scene->SetCameraMatrix(rot, origin);	
}
Exemple #22
0
 const_iterator1 end1() const   { return const_iterator1(mat_, static_cast<int>(size1()), static_cast<int>(size2())); }
Exemple #23
0
/// Create a new matrix and move the data to it.
GSLMatrix GSLMatrix::move() {
  return GSLMatrix(std::move(m_data), size1(), size2());
}
        /**
         * @brief Read access to a element of the matrix
         *
         * @param row_index  Row index of accessed element
         * @param col_index  Column index of accessed element
         * @return Proxy for matrix entry
         */
        SCALARTYPE operator()(vcl_size_t row_index, vcl_size_t col_index) const
        {
            assert(row_index < size1() && col_index < size2() && bool("Invalid access"));

            return pow(elements_[row_index], static_cast<int>(col_index));
        }
Exemple #25
0
 /** \brief Get required length of w field */
 size_t sz_w() const override { return size1();}
Exemple #26
0
/**
 * @brief Get the real size for the given pressure
 * @param pressure
 * @return size
 * @pre 0 <= pressure <= 1
 * @post 0.5 <= RESULT
 */
qreal Brush::fsize(qreal pressure) const
{
	//return qMax(0.5, interpolate(size1(), size2(), pressure));
	return interpolate(size1(), size2(), pressure);
}
Exemple #27
0
 const_iterator2 end2() const   { return const_iterator2(mat_, size1(), size2()); }
Exemple #28
0
 vcl_size_t size(vector_expression<LHS, const unsigned int, op_column> const & proxy)
 {
   return size1(proxy.lhs());
 }
void wxJigsawShape::DrawShapeHeader(wxDC & dc, const wxPoint & pos, 
		const wxSize & size, const wxJigsawShapeStyle style)
{
	wxPoint * points(NULL);
	bool bDrawBevel = true;
	wxColour bevelBright(200,200,200), bevelDarker(50,50,50);	
	if(dc.GetPen() == *wxTRANSPARENT_PEN)
	{
		wxColour aux;
		aux = bevelBright;
		bevelBright = bevelDarker;
		bevelDarker = aux;		
	}

	switch(style)
	{
	case wxJigsawShapeStyle::wxJS_TYPE_NUMERIC:

		

		if(bDrawBevel)
		{
			wxPoint pos1(pos);
			wxSize size1(size);

			dc.SetPen(bevelDarker); 
			dc.DrawRoundedRectangle(pos1, size1, size1.GetHeight()/2);

			dc.SetPen(bevelBright); 			
			pos1.x += 1;
			pos1.y += 1;			
			dc.DrawRoundedRectangle(pos1, size1, size1.GetHeight()/2);

			dc.SetPen(*wxTRANSPARENT_PEN); 
			pos1.y -= 1;
			dc.DrawRoundedRectangle(pos1, size, size.GetHeight()/2);

			dc.SetPen(bevelDarker); 
			dc.DrawLine(pos1.x + size.GetHeight()/2, pos1.y, pos1.x + size.GetWidth() - size.GetHeight()/2, pos1.y);
		} 
		else 
		{
			dc.DrawRoundedRectangle(pos, size, size.GetHeight()/2);
		}

		break;
	case wxJigsawShapeStyle::wxJS_TYPE_BOOLEAN:
		// If it is possible to draw a shape then we will draw it
		if(size.GetWidth() >= size.GetHeight())
		{
			points = new wxPoint[7];
			points[0] = wxPoint(0, size.GetHeight()/2);
			points[1] = wxPoint(size.GetHeight()/2, 0);
			points[2] = wxPoint(size.GetWidth()-size.GetHeight()/2, 0);			
			points[3] = wxPoint(size.GetWidth(), size.GetHeight()/2);
			points[4] = wxPoint(size.GetWidth()-size.GetHeight()/2, size.GetHeight());
			points[5] = wxPoint(size.GetHeight()/2, size.GetHeight());
			points[6] = wxPoint(0, size.GetHeight()/2);
			dc.DrawPolygon(7, points, pos.x, pos.y);			

			if(bDrawBevel)
			{
				dc.SetPen(bevelDarker); 
				dc.DrawLines(3, points, pos.x, pos.y);	

				dc.SetPen(bevelBright); 
				dc.DrawLines(4, &points[3], pos.x, pos.y);	
			} 

			wxDELETEA(points);
		}
		else // If it is impossible to draw a shape then we will draw a rectangle
		{
			dc.DrawRectangle(pos, size);
		}
		break;
	case wxJigsawShapeStyle::wxJS_TYPE_STRING:
		// If it is possible to draw a shape then we will draw it
		if(size.GetWidth() >= size.GetHeight())
		{
			/*
			1/3,1
			1/3,2/3
			0,2/3
			0,1/3
			1/3,1/3
			1/3,0
			*/
			points = new wxPoint[13];

			points[0] = wxPoint(size.GetHeight()/3.0, size.GetHeight());
			points[1] = wxPoint(size.GetHeight()/3.0, 2*size.GetHeight()/3.0);
			points[2] = wxPoint(0, 2*size.GetHeight()/3.0);
			points[3] = wxPoint(0, size.GetHeight()/3.0);
			points[4] = wxPoint(size.GetHeight()/3.0, size.GetHeight()/3.0);
			points[5] = wxPoint(size.GetHeight()/3.0, 0);

			points[6] = wxPoint(size.GetWidth()-points[5].x, points[5].y);
			points[7] = wxPoint(size.GetWidth()-points[4].x, points[4].y);
			points[8] = wxPoint(size.GetWidth()-points[3].x, points[3].y);
			points[9] = wxPoint(size.GetWidth()-points[2].x, points[2].y);
			points[10] = wxPoint(size.GetWidth()-points[1].x, points[1].y);
			points[11] = wxPoint(size.GetWidth()-points[0].x, points[0].y);

			points[12] = points[0];

			dc.DrawPolygon(13, points, pos.x, pos.y);			

			if(bDrawBevel)
			{
				dc.SetPen(bevelDarker); 
				dc.DrawLines(7, points, pos.x, pos.y);	

				dc.SetPen(bevelBright); 
				dc.DrawLines(6, &points[7], pos.x, pos.y);	
			} 

			wxDELETEA(points);
		}
		else // If it is impossible to draw a shape then we will draw a rectangle
		{
			dc.DrawRectangle(pos, size);
		}
		break;
	case wxJigsawShapeStyle::wxJS_TYPE_NONE:
	default:
		dc.DrawRoundedRectangle(pos, size, 4);
		break;
	}
}
Exemple #30
0
 const_reverse_iterator1 rbegin1() const { return const_reverse_iterator1(mat_, static_cast<int>(size1() - 1), 0); }