NOX::Abstract::MultiVector& 
LOCA::Extended::MultiVector::update(double alpha, 
				    const LOCA::Extended::MultiVector& a, 
				    double beta, 
				    const LOCA::Extended::MultiVector& b,
				    double gamma)
{
  // Verify dimensions are consistent
  checkDimensions("LOCA::Extended::MultiVector::update()", a);
  checkDimensions("LOCA::Extended::MultiVector::update()", b);

  // update each multivec
  for (int i=0; i<numMultiVecRows; i++)
    multiVectorPtrs[i]->update(alpha, *(a.multiVectorPtrs[i]), 
			       beta, *(b.multiVectorPtrs[i]),
			       gamma);

  // update scalars
  for (int j=0; j<numColumns; j++)
    for (int i=0; i<numScalarRows; i++)
      (*scalarsPtr)(i,j) = 
	gamma * (*scalarsPtr)(i,j) + alpha * (*a.scalarsPtr)(i,j) + 
	beta * (*b.scalarsPtr)(i,j);

  return *this;
}
Ejemplo n.º 2
0
void SurfaceAtlas::addSurface(SurfaceInfo *si) {
	if(si == NULL) {
		throw megaglest_runtime_error("Bad surface info (NULL)");
	}
	
	//check dimensions
	if(si->getCenter() != NULL){
		checkDimensions(si->getCenter());
	}
	else{
		checkDimensions(si->getLeftUp());
		checkDimensions(si->getLeftDown());
		checkDimensions(si->getRightUp());
		checkDimensions(si->getRightDown());
	}

	//add info
	SurfaceInfos::iterator it = find(surfaceInfos.begin(), surfaceInfos.end(), *si);
	if(it == surfaceInfos.end()) {
		//add new texture
		Texture2D *t= Renderer::getInstance().newTexture2D(rsGame);
		if(t) {
		//if(t == NULL) {
		//	throw megaglest_runtime_error("Could not create new texture (NULL)");
		//}
			t->setWrapMode(Texture::wmClampToEdge);
			t->getPixmap()->init(surfaceSize, surfaceSize, 3);
		}
		
		si->setCoord(Vec2f(0.f, 0.f));
		si->setTexture(t);
		surfaceInfos.push_back(*si);
		
		//copy texture to pixmap
		if(si->getCenter() != NULL) {
			if(t) {
				t->getPixmap()->copy(si->getCenter());
			}
		}
		else {
			if(t) {
				t->getPixmap()->splat(si->getLeftUp(), si->getRightUp(), si->getLeftDown(), si->getRightDown());
			}
		}
	}
	else{
		si->setCoord(it->getCoord());
		si->setTexture(it->getTexture());
	}
}
Ejemplo n.º 3
0
void Solver::reset(double t0, const PosVec& X0, const ForceVec& F, double step) {
    mt = t0;
    mX = X0;
    mF = F;
    mstep = step;
    checkDimensions();
}
Ejemplo n.º 4
0
void CLinearMean::aEvaluate(MatrixXd* outY)
{
	checkDimensions(weights,fixedEffects,Y, true, true, true);
	*outY = this->Y;
	if (!isnull(this->weights))
		*outY -= (this->fixedEffects * this->weights);
}
hkResult hkvTextureTransformationSettings::validate(hkArray<hkvAssetLogMessage>& out_messages)
{
  if (m_valid)
  {
    return HK_SUCCESS;
  }

  m_validationMinSize = 0;
  m_validationWarnSize = 0;
  m_validationMaxSize = 0;
  m_validationNeedsPowerOfTwo = false;
  m_validationNeedsSquare = false;
  m_validationNeedsMultipleOf = 1;

  bool ok = true;
  if (!m_ignoreTargetFormatRestrictions)
  {
    ok &= checkFormatCompatibility(out_messages);
  }
  ok &= determineRestrictions(out_messages);
  ok &= checkDimensions(out_messages);
  ok &= checkAlpha(out_messages);

  if (!ok)
  {
    return HK_FAILURE;
  }

  m_valid = true;
  return HK_SUCCESS;
}
Ejemplo n.º 6
0
void Framebuffer::setRenderbufferAttachement(gl::GLenum attachement,
                                             Renderbuffer &renderbuffer) {
  checkDimensions(renderbuffer.width(), renderbuffer.height());
  ensureInitialized();
  gl::NamedFramebufferRenderbuffer(obj_.get(), attachement, gl::RENDERBUFFER,
                                 renderbuffer.object());
}
Ejemplo n.º 7
0
void testPlacement(const SurfaceConfig& surface, const QSize& expectedSize)
{
    const auto window = LauncherPlacer{surface}.getCoordinates();
    checkMargins(window, surface.getTotalSize());
    checkDimensions(window, surface.getTotalSize());
    checkVerticalPosition(window, surface);
    BOOST_CHECK_EQUAL(window.size(), expectedSize);
}
Ejemplo n.º 8
0
Exception RgbeWrite
(
   int32u          width,
   int32u          height,
   int32u          iterations,
   const Vector3f* aPixels,
   FILE*           pFileOut_o
)
{
   /* write header */
   {
      /* precondition */
      if( !checkDimensions( width, height ) ) return ERROR_RGBE_SIZE;

      /* ID */
      if( 0 > fprintf( pFileOut_o, "#?RADIANCE\n" ) ) return ERROR_WRITE_IO;

      /* other header things */
      if( 0 > fprintf( pFileOut_o, "FORMAT=32-bit_rgbe\n" ) )
         return ERROR_WRITE_IO;
      if( 0 > fprintf( pFileOut_o, "SOFTWARE=%s\n", MINILIGHT_URI ) )
         return ERROR_WRITE_IO;
      if( 0 > fprintf( pFileOut_o, "ITERATION=%i\n\n", iterations ) )
         return ERROR_WRITE_IO;

      /* width, height */
      if( 0 > fprintf( pFileOut_o, "-Y %i +X %i\n", height, width ) )
         return ERROR_WRITE_IO;
   }

   /* write pixels */
   {
      int32u i, j;
      /* (top left first) */
      for( i = 0;  i < (width * height);  ++i )
      {
         const int32u rgbe = toRgbe( &aPixels[(int)i] );

         /* write rgbe bytes */
         for( j = 4;  j-- > 0; )
         {
            if( 0 > fprintf( pFileOut_o, "%c",
               (byteu)((rgbe >> (j * 8)) & 0xFFu) ) )
               return ERROR_WRITE_IO;
         }
      }
   }

   return 0;
}
Ejemplo n.º 9
0
 // calcSingleSubscript
 // gets linear index from matrix subscripts. Note matrix subscripts 
 // should be zero-based not one-based
 mwIndex calcSingleSubscript (std::vector<mwSize> index)
 {
     // check dimensions are within range
     checkDimensions (index);
     
     // make an array of the appropriate size to hold the indices
     mwIndex* subs = new mwIndex[_dimensions.size ()];
     // copy the index into the subs array
     for (int i=0; i < index.size (); i++) { *(subs+i) = index[i]; }
     // get the linear index into the underlying data array
     mwIndex linindex = mxCalcSingleSubscript(wMxArray, (mwSize)(_dimensions.size ()), subs);
     // delete the memory allocated for the index
     delete[] subs;
     
     return linindex;
 }
Ejemplo n.º 10
0
    bool WarningsCheckingWorker::processOneItem(WarningsItem *item) {
        Q_ASSERT(item != NULL);

        int warningsFlags = 0;

        initValuesFromSettings();

        IWarningsCheckable *checkableItem = item->getCheckableItem();
        warningsFlags |= checkDimensions(checkableItem);
        warningsFlags |= checkDescriptionLength(checkableItem);
        warningsFlags |= checkTitleWordsCount(checkableItem);
        warningsFlags |= checkKeywordsCount(checkableItem);
        warningsFlags |= checkSpellCheckErrors(checkableItem);

        checkableItem->setWarningsFlags(warningsFlags);

        return true;
    }
Ejemplo n.º 11
0
Exception RgbeReadHeader
(
   FILE*   pFileIn,
   int32u* pWidth_o,
   int32u* pHeight_o,
   int32u* pIterations_o
)
{
   bool b;
   Exception e = RgbeIsRecognised( pFileIn, &b );
   if( e || !b ) return e ? e : ERROR_RGBE_INVALID;

   {
      /* read iterations */
      char s[ 11 ];
      do
      {
         /* find key */
         if( !fgets( s, sizeof(s), pFileIn ) ) return ERROR_FILE;

         if( !strcmp( s, "ITERATION=" ) )
         {
            /* read value */
            if( EOF == fscanf( pFileIn, "%u", pIterations_o ) )
               return ERROR_FILE;
         }

         e = nextLine( pFileIn, s[strlen( s ) - 1] );
         if( e ) return e;

      /* blank line is end of header */
      } while( s[0] != '\n' );

      /* read dimensions */
      if( EOF == fscanf( pFileIn, "-Y %u +X %u\n", pHeight_o, pWidth_o ) )
         return ERROR_FILE;

      /* conditioning */
      if( !checkDimensions( *pWidth_o, *pHeight_o ) ) return ERROR_RGBE_SIZE;
   }

   return 0;
}
LOCA::Extended::MultiVector& 
LOCA::Extended::MultiVector::operator=(
				   const LOCA::Extended::MultiVector& source)
{
  if (this != &source) {

    // Verify dimensions are consistent
    checkDimensions("LOCA::Extended::MultiVector::operator=()", source);

    globalData = source.globalData;

    // Copy multivecs
    for (int i=0; i<numMultiVecRows; i++)
      *(multiVectorPtrs[i]) = *(source.multiVectorPtrs[i]);

    // Copy scalars (don't use operator= since it destroys views)
    scalarsPtr->assign(*source.scalarsPtr);
  }

  return *this;
}
Ejemplo n.º 13
0
bool System::rebuild(void){
	setDimenciones(A->rows,B->cols,C->rows);

	if ( Phi ) delete Phi;
	if ( Psi ) delete Psi;
	if ( cntrl ) delete cntrl;	
	if ( obser ) delete obser;
	Phi = Psi = cntrl = obser = 0;
	
	bool ret_val = checkDimensions();
	if( ret_val == true ){
		Phi = computePhi(A,Ts);
		Psi = computePsi(A,B,Phi);
		cntrl = Cntrl(A,B);
		obser = Obser(A,C);
		ret_val &= testCntrl();
		ret_val &= testObser();
	}
	if ( notify && ret_val )
		notify->reportStatus(__func__,"");
	return ret_val;
}
Ejemplo n.º 14
0
Archivo: main.cpp Proyecto: thomas7/hw5
int main(int argc, char* argv[]) {
    try {
        /***************************Process Command line arguments********************************/
        QCoreApplication app(argc, argv);
        QStringList argList = app.arguments(); //argList holds all arguements from the command line
        /*****************************************************************************************/

        inFile1.setFileName(argList[1]);
        inFile2.setFileName(argList[2]);

        // Create the thread for the first input file
        pthread_create(&tid, NULL, readFile, (void*)"1");
        //Create the thread for the second input file
        pthread_create(&tid2, NULL, readFile, (void*)"2");

        //wait until the readFile threads finish before checking values in A and B
        pthread_join(tid, NULL);
        pthread_join(tid2, NULL);

        //handle file could not be opened case. Must be placed here since errors cannot be thrown
        //from the threads for whatever reason
        if(infile1Flag)
            throw "The first input file could not be opened. Check to make sure that it exists.";
        if(infile2Flag)
            throw "The second input file could not be opened. Check to make sure that it exists.";


        typeIdA = checkValues(A);
        typeIdB = checkValues(B);

        if (typeIdA != typeIdB)
            throw "Types for the two matrices do not match.";

        checkDimensions(A, B);

        //initialize correct size for C
        //create matrix of position numbers
        for (int i =0; i < A.length(); i++) {
            QStringList cTemp;
            for (int j=0; j< B[0].length(); j++) {
                cTemp.append("0");
                positions.append(QString::number(i)+ "," + QString::number(j));
            }
            C.append(cTemp);
        }

        pthread_t threads[A.length() * B[0].length()];

        for(int i=0; i < A.length()*B[0].length(); i++) {
            pthread_create(&threads[i], NULL, multiplyMatrices, (void*)&positions[i]);
        }

        for(int i=0; i < A.length()*B[0].length(); i++) {
            pthread_join(threads[i], NULL);
        }

        //Write the output matrix in C to the output file
        outFile.setFileName(argList[3]);
        QTextStream fileOutStream(&outFile);
        if (isFloat) {
            fileOutStream.setRealNumberPrecision(4);
            fileOutStream.setRealNumberNotation(QTextStream::FixedNotation);
        }

        //If it doesn't exist it will be created. not sure how this error will be thrown
        //but its here as a precaution
        if (!outFile.open(QIODevice::WriteOnly))
            throw "Something went wrong in trying to open the output file.";

        fileOutStream << C << endl;

    }
    catch (const char *err){
        qDebug() << err;
    }
    return 0;
}
Ejemplo n.º 15
0
void ofxColorPicker :: setSize( float x, float y, float w, float h )
{
	checkDimensions( x, y, w, h );
}
Ejemplo n.º 16
0
Archivo: atlas.c Proyecto: Jzone/chck
int chckAtlasPack(chckAtlas *atlas, const int forcePowerOfTwo, const int onePixelBorder, unsigned int *outWidth, unsigned int *outHeight)
{
   assert(atlas);

   if (onePixelBorder) {
      unsigned int i;
      for (i = 0; i != atlas->textureCount; ++i) {
         struct texture *t = &atlas->textures[i];
         t->rect.w += 2;
         t->rect.h += 2;
      }
      atlas->longestEdge += 2;
   }

   if (forcePowerOfTwo)
      atlas->longestEdge = nextPow2(atlas->longestEdge);

   unsigned int width = atlas->longestEdge;
   unsigned int count = (unsigned int)((float)atlas->totalArea/(atlas->longestEdge * atlas->longestEdge) + 0.5f);
   unsigned int height = (count + 2) * atlas->longestEdge;

   if (forcePowerOfTwo)
      height = nextPow2(height);

   if (width > height && height != width * 0.5f) {
      height = width * 0.5f;
      width *= 0.5f;
      checkDimensions(atlas, &width, &height);
   } else if (height > width && width != height * 0.5f) {
      width = height * 0.5f;
      height *= 0.5f;
      checkDimensions(atlas, &width, &height);
   }

   atlas->debugCount = 0;
   atlasNodeNew(atlas, 0, 0, width, height);

   unsigned int i;
   for (i = 0; i != atlas->textureCount; ++i) {
      unsigned int i2;
      unsigned int longestEdge = 0, mostArea = 0, index = 0;
      for(i2 = 0; i2 != atlas->textureCount; ++i2) {
         struct texture *t = &atlas->textures[i2];
         if (t->placed)
            continue;

         if (t->longestEdge > longestEdge) {
            mostArea = t->area;
            longestEdge = t->longestEdge;
            index = i2;
         } else if (t->longestEdge == longestEdge && t->area > mostArea) {
            mostArea = t->area;
            index = i2;
         }
      }

      unsigned int edgeCount = 0;
      unsigned int leastY = UINT_MAX;
      unsigned int leastX = UINT_MAX;
      struct texture *t = &atlas->textures[index];
      struct node *previousBestFit = NULL;
      struct node *bestFit = NULL;
      struct node *previous = NULL;
      struct node *search = atlas->freeList;

      while (search) {
         unsigned int ec;
         if (nodeFits(search, t->rect.w, t->rect.h, &ec)) {
            if (ec == 2) {
               previousBestFit = previous;
               bestFit = search;
               edgeCount = ec;
               break;
            } else if (search->rect.y < leastY) {
               leastY = search->rect.y;
               leastX = search->rect.x;
               previousBestFit = previous;
               bestFit = search;
               edgeCount = ec;
            } else if (search->rect.y == leastY && search->rect.x < leastX) {
               leastX = search->rect.x;
               previousBestFit = previous;
               bestFit = search;
               edgeCount = ec;
            }
         }
         previous = search;
         search = search->next;
      }

      /* should always find a fit */
      assert(bestFit);

      switch (edgeCount) {
         case 0:
            if (t->longestEdge <= bestFit->rect.w) {
               int flipped = 0;
               unsigned int width = t->rect.w;
               unsigned int height = t->rect.h;

               if (width > height) {
                  width = t->rect.h;
                  height = t->rect.w;
                  flipped  = 1;
               }

               texturePlace(t, bestFit->rect.x, bestFit->rect.y, flipped);
               atlasNodeNew(atlas, bestFit->rect.x, bestFit->rect.y + height, bestFit->rect.w, bestFit->rect.h - height);

               bestFit->rect.x += width;
               bestFit->rect.w -= width;
               bestFit->rect.h = height;
            } else {
               assert(t->longestEdge <= bestFit->rect.h);
               int flipped  = 0;
               unsigned int width = t->rect.w;
               unsigned int height = t->rect.h;

               if (width > height) {
                  width = t->rect.h;
                  height = t->rect.w;
                  flipped  = 1;
               }

               texturePlace(t, bestFit->rect.x, bestFit->rect.y, flipped);
               atlasNodeNew(atlas, bestFit->rect.x + width, bestFit->rect.y, bestFit->rect.w - width, bestFit->rect.h);

               bestFit->rect.y += height;
               bestFit->rect.h -= height;
               bestFit->rect.w = width;
            }
            break;
         case 1:
            if (t->rect.w == bestFit->rect.w) {
               texturePlace(t, bestFit->rect.x, bestFit->rect.y, 0);
               bestFit->rect.y += t->rect.h;
               bestFit->rect.h -= t->rect.h;
            } else if (t->rect.h == bestFit->rect.h) {
               texturePlace(t, bestFit->rect.x, bestFit->rect.y, 0);
               bestFit->rect.x += t->rect.w;
               bestFit->rect.w -= t->rect.w;
            } else if (t->rect.w == bestFit->rect.h) {
               texturePlace(t, bestFit->rect.x, bestFit->rect.y, 1);
               bestFit->rect.x += t->rect.h;
               bestFit->rect.w -= t->rect.h;
            } else if (t->rect.h == bestFit->rect.w) {
               texturePlace(t, bestFit->rect.x, bestFit->rect.y, 1);
               bestFit->rect.y += t->rect.w;
               bestFit->rect.h -= t->rect.w;
            }
            break;
         case 2:
            {
               int flipped = (t->rect.w != bestFit->rect.w || t->rect.h != bestFit->rect.h);
               texturePlace(t, bestFit->rect.x, bestFit->rect.y, flipped);

               if (previousBestFit) {
                  previousBestFit->next = bestFit->next;
               } else {
                  atlas->freeList = bestFit->next;
               }

               if (bestFit)
                  free(bestFit);
            }
            break;
      }

      /* merge as much as we can */
      while (mergeNodes(atlas));
   }

   width = 0, height = 0;
   for(i = 0; i < atlas->textureCount; ++i) {
      struct texture *t = &atlas->textures[i];
      if (onePixelBorder) {
         t->rect.w -= 2;
         t->rect.h -= 2;
         t->rect.x += 1;
         t->rect.y += 1;
      }

      unsigned int x = (t->flipped ? t->rect.x + t->rect.h : t->rect.x + t->rect.w);
      unsigned int y = (t->flipped ? t->rect.y + t->rect.w : t->rect.y + t->rect.h);
      width = (x > width ? x : width);
      height = (y > height ? y : height);
   }

   if (forcePowerOfTwo) {
      width = nextPow2(width);
      height = nextPow2(height);
   }

   if (outWidth) *outWidth = width;
   if (outHeight) *outHeight = height;
   return (width * height) - atlas->totalArea;
}
Ejemplo n.º 17
0
void Framebuffer::setAttachement(gl::GLenum attachement, Texture &tex) {
  checkDimensions(tex.width(), tex.height());
  setAttachement(attachement, tex.object());
}
Ejemplo n.º 18
0
void CLinearMean::zeroInitWeights()
{
	checkDimensions(MatrixXd(),this->Y,this->fixedEffects, false, true, true);
	this->weights = MatrixXd::Zero(this->fixedEffects.cols(), this->Y.cols());
	propagateSync(false);
}
Ejemplo n.º 19
0
void ofxColorPicker :: setPos( float x, float y )
{
	checkDimensions( x, y, dimensions.width, dimensions.height );
}
Ejemplo n.º 20
0
Solver::Solver(double t0, const PosVec& X0, const ForceVec& F, double step) :
    mt(t0), mX(X0), mF(F), mstep(step) {
    checkDimensions();
}