Example #1
0
void addThresholdFilterOutput(double *outputRI, double *inputRI, long frequencies, double dfrequency, THRESHOLD_FILTER *filter)
{
    long i, i1, i2;
    double level2, level2q, level2o;
    double max2, mag2;

    i1 = 0;
    if (filter->flags&FILT_START_GIVEN)
        i1 = computeIndex(filter->start, dfrequency, frequencies);
    i2 = frequencies-1;
    if (filter->flags&FILT_END_GIVEN)
        i2 = computeIndex(filter->end, dfrequency, frequencies);

    if (filter->flags&FILT_FRACTHRES_GIVEN) {
        max2 = -DBL_MAX;
        for (i=i1; i<=i2; i++) 
            if ((mag2=inputRI[2*i]*inputRI[2*i] + inputRI[2*i+1]*inputRI[2*i+1])>max2)
                max2 = mag2;
        level2o = max2*sqr(filter->level);
        }
    else
        level2o = sqr(filter->level);
    level2q = level2o/4;

    for (i=i1; i<=i2; i++) {
        level2 = level2q;   /* only half the amplitude is in positive frequencies */
        if (i==0 || i==frequencies-1)
            level2 = level2o;
        if ((inputRI[2*i]*inputRI[2*i] + inputRI[2*i+1]*inputRI[2*i+1])>=level2) {
            outputRI[2*i  ] += inputRI[2*i  ];
            outputRI[2*i+1] += inputRI[2*i+1];
            }
        }
    }
Example #2
0
void addNotchFilterOutput(double *outputRI, double *inputRI, long frequencies, double dfrequency, NHBP_FILTER *filter)
{
    long i1, i2, i;
    double fraction, dfraction;

    i1 = computeIndex(filter->center-filter->fullwidth/2, dfrequency, frequencies);
    i2 = computeIndex(filter->center-filter->flatwidth/2, dfrequency, frequencies);
    for (i=0; i<i1; i++) {
        outputRI[2*i  ] += inputRI[2*i  ];
        outputRI[2*i+1] += inputRI[2*i+1];
        }
    dfraction = i1==i2 ? 0 : 1./(i2-i1);
    fraction = 1;
    for (i=i1; i<=i2; i++) {
        outputRI[2*i  ] += inputRI[2*i  ]*fraction;
        outputRI[2*i+1] += inputRI[2*i+1]*fraction;
        if ((fraction -= dfraction)<0)
            fraction = 0;
        }

    i1 = computeIndex(filter->center+filter->flatwidth/2, dfrequency, frequencies);
    i2 = computeIndex(filter->center+filter->fullwidth/2, dfrequency, frequencies);
    for (i=i2; i<frequencies; i++) {
        outputRI[2*i  ] += inputRI[2*i  ];
        outputRI[2*i+1] += inputRI[2*i+1];
        }
    dfraction = i1==i2 ? 0 : 1./(i2-i1);
    fraction = 0;
    for (i=i1; i<=i2; i++) {
        outputRI[2*i  ] += inputRI[2*i  ]*fraction;
        outputRI[2*i+1] += inputRI[2*i+1]*fraction;
        if ((fraction += dfraction)>1)
            fraction = 1;
        }
    }
Example #3
0
ambisonicWeight::ambisonicWeight(int anOrder, int aVectorSize, std::string anOptimMode)
{
	m_order					= anOrder;
	m_number_of_harmonics	= m_order * 2 + 1;
	m_number_of_outputs		= m_number_of_harmonics;
	m_number_of_inputs		= m_number_of_harmonics;
	m_vector_size			= aVectorSize;
	
	m_speakers_angles		= new double[m_order];
	m_index_of_harmonics	= new int[m_number_of_harmonics];
	m_optimVector			=  new double[m_number_of_harmonics];

	m_input_vector			= gsl_vector_alloc(m_number_of_harmonics * m_number_of_harmonics);
	m_input_vector_view		= new gsl_vector_view[m_number_of_harmonics];
	m_output_vector			= gsl_vector_alloc(m_number_of_harmonics * m_number_of_harmonics);
	m_output_vector_view	= new gsl_vector_view[m_number_of_harmonics];
	
	gsl_vector_set_zero(m_input_vector);
	gsl_vector_set_zero(m_output_vector);
	for (int j = 0; j < m_number_of_harmonics; j++)
	{
		m_input_vector_view[j]	= gsl_vector_subvector(m_input_vector, j * m_number_of_harmonics, m_number_of_harmonics);
		m_output_vector_view[j]	= gsl_vector_subvector(m_output_vector, j * m_number_of_harmonics, m_number_of_harmonics);
	}
	computeIndex();
	computeAngles();
	computePseudoInverse();
	setOptimMode(anOptimMode);
	

}
Example #4
0
AmbisonicJcverb::AmbisonicJcverb(long anOrder)
{

    m_order					= Tools::clip_min(anOrder, (long)1);
	m_number_of_harmonics	= m_order * 2 + 1;
	m_number_of_inputs		= m_number_of_harmonics;
	m_number_of_outputs		= m_number_of_harmonics;
    computeIndex();
    
    ambisonicRecomposer* recomposer  = new ambisonicRecomposer(m_order, m_number_of_harmonics +1, m_number_of_harmonics);
    double* myReverbForm = new double[m_number_of_harmonics +1];
    double* theCoeffresult = new double[m_number_of_harmonics];
    
    for(int i = 0; i < (m_number_of_harmonics + 1) / 2; i++)
    {
        myReverbForm[i] = 0.3 * ((double)i / ((m_number_of_harmonics + 1) / 2)) + 0.7;
        myReverbForm[(m_number_of_harmonics + 1) / 2 - 1 - i] = 0.3 * ((double)(i - 0.25)/ ((m_number_of_harmonics + 1) / 2)) + 0.7;
    }
    recomposer->process(myReverbForm, theCoeffresult);
    double factor = 0;
    for(int i = 0; i < m_number_of_harmonics; i++)
    {
        if (fabs(theCoeffresult[i]) > factor)
        {
            factor = fabs(theCoeffresult[i]);
        }
    }

    for(int i = 0; i < m_number_of_harmonics; i++)
    {
        m_Jcverb.push_back(new Jcverb(abs(m_index_of_harmonics[i]), m_order * theCoeffresult[i] / factor));
    }
    delete recomposer;
}
double MarginalCovarianceCholesky::computeEntry(int r, int c)
{
  assert(r <= c);
  int idx = computeIndex(r, c);

  LookupMap::const_iterator foundIt = _map.find(idx);
  if (foundIt != _map.end()) {
    return foundIt->second;
  }

  // compute the summation over column r
  double s = 0.;
  const int& sc = _Ap[r];
  const int& ec = _Ap[r+1];
  for (int j = sc+1; j < ec; ++j) { // sum over row r while skipping the element on the diagonal
    const int& rr = _Ai[j];
    double val = rr < c ? computeEntry(rr, c) : computeEntry(c, rr);
    s += val * _Ax[j];
  }

  double result;
  if (r == c) {
    const double& diagElem = _diag[r];
    result = diagElem * (diagElem - s);
  } else {
    result = -s * _diag[r];
  }
  _map[idx] = result;
  return result;
}
Example #6
0
 bool lookup ( K key ) {
   ++hashset_lookup_ops;
   if (FLAGS_flat_combining) {
     ResultEntry re{false,nullptr};
     DVLOG(3) << "lookup[" << key << "] = " << &re;
     
     proxy.combine([&re,key,this](Proxy& p){
       // if (p.keys_to_insert.count(key) > 0) {
       //   ++hashset_matched_lookups;
       //   re.result = true;
       //   return FCStatus::SATISFIED;
       // } else {
         if (p.lookups.count(key) == 0) p.lookups[key] = nullptr;
         re.next = p.lookups[key];
         p.lookups[key] = &re;
         DVLOG(3) << "p.lookups[" << key << "] = " << &re;
         return FCStatus::BLOCKED;
       // }
     });
     return re.result;
   } else {
     ++hashset_lookup_msgs;
     return delegate::call(base+computeIndex(key), [key](Cell* c){
       for (auto& e : c->entries) if (e.key == key) return true;
       return false;
     });
   }
 }
Example #7
0
    void update( K key, UV val ) {
      uint64_t index = computeIndex( key );
      GlobalAddress< Cell > target = base + index; 

      Grappa::delegate::call( target.core(), [key, val, target]() {   // TODO: upgrade to call_async; using GCE
        // list of entries in this cell
        std::list<DHT_TYPE(Entry)> * entries = target.pointer()->entries;

        // if first time the cell is hit then initialize
        if ( entries == NULL ) {
          entries = new std::list<Entry>();
          target.pointer()->entries = entries;
        }

        // find matching key in the list
        typename std::list<DHT_TYPE(Entry)>::iterator i;
        for (i = entries->begin(); i!=entries->end(); ++i) {
          if ( i->key == key ) {
            // key found so update
            i->value = UpF(i->value, val);
            hash_tables_size+=1;
            return 0;
          }
        }

        // this is the first time the key has been seen
        // so add it to the list
        Entry newe( key, UpF(Init, val));

        return 0; 
      });
    }
Example #8
0
AmbisonicEncode::AmbisonicEncode(int anOrder, std::string aMode, int aVectorSize)
{	
	m_order					= anOrder;
	m_number_of_harmonics	= m_order * 2 + 1;
	m_mode					= aMode;
	m_number_of_outputs		= m_number_of_harmonics;
	m_ambiCoeffs			= new double[m_number_of_harmonics];
	if(aMode == "split")
		m_number_of_inputs	= m_order + 2;
	else
		m_number_of_inputs	= 2;	
	
	computeIndex();
	
	m_cosLookUp = new double[NUMBEROFCIRCLEPOINTS];
	m_sinLookUp = new double[NUMBEROFCIRCLEPOINTS];
	
	for (int i = 0; i < NUMBEROFCIRCLEPOINTS; i++) 
	{
		m_cosLookUp[i] = cos((double)i * M_2PI / (double)NUMBEROFCIRCLEPOINTS);
		m_sinLookUp[i] = sin((double)i * M_2PI / (double)NUMBEROFCIRCLEPOINTS);
	}
	computeCoefs(0.);
	setVectorSize(aVectorSize);
}
Example #9
0
void BBHandleLayer::createIdleBlock()
{
    auto idleBlockSpt = BBBlockSprite::create("IdleBlock.png");
    
    float blockX = m_relativeX + m_blockLength * 0 + idleBlockSpt->getContentSize().width/2;
    float blockY = m_relativeY +m_blockLength * (m_row - 0) + idleBlockSpt->getContentSize().height/2;
    
    idleBlockSpt->setPosition(Point(blockX, blockY));
    idleBlockSpt->setTag(computeIndex(blockX, blockY));
    idleBlockSpt->setOrder(computeIndex(blockX, blockY));
    m_blockContainer->addChild(idleBlockSpt);
    
    idleBlockSpt->setOpacity(0);
    
    // 加入到集合末尾
    m_blockArr->addObject(idleBlockSpt);
}
Example #10
0
const uint32 IImage::computeIndex( const vgm::Vec3i position ) const
{
    assert( isValid(position) );

    const uint32 index = computeIndex( position[0], position[1], position[2] );

    return index;
}
Example #11
0
const float IImage::getPixel1( const vgm::Vec3i position ) const
{
    assert( components() == 1 );
    assert( isValid(position) );

    const uint32 index = computeIndex( position );

    return getPixel1(index);
}
Example #12
0
void IImage::setPixel1( const vgm::Vec3i position, const float color )
{
    assert( components() == 1 );
    assert( isValid(position) );

    const uint32 index = computeIndex( position );

    setPixel1(index, color);
}
Example #13
0
const uint32 IImage::computeOffset( const uint32 x, const uint32 y, const uint32 z ) const
{
    assert( x < width() );
    assert( y < height() );
    assert( z < depth() );

    const uint32 index = computeIndex(x, y, z);

    return index*sizeOfPixel();
}
Example #14
0
void Resizer::computeCellAndFaceRelationship()
{
	float (*vertex)[3] = polyMesh->vertex;     //获取多边形网格的所有顶点三维坐标
	int (*face)[3] = polyMesh->face;           //获取多边形网格中face的具体三个顶点的坐标
	int faceN = polyMesh->getFaceN();          //获取多边形网格中face的个数
	facePassthroughCell = new int[faceN][200];
	facePassthroughCellNum = new int[faceN];
	cellIncludingFace = new int[ALLCELLNUM][200];
	cellIncludingFaceNum = new int[ALLCELLNUM];
	//计算出grid的边界和每个cell的三个方向上棱长
	this->computeBoundingBoxAndEdgeLength();
	float cellHalfSize[3];                 //记录所有cell在三个方向上的边长的一半
	for(int i=0;i<3;i++)
		cellHalfSize[i] = edgeLength[i]/2.0f;
	//以face为考虑基准
	for(int i=0;i<faceN;i++)
	{
		//每个face有3个顶点
		float tempVertex[3][3];         //临时存放当前face的3个顶点
		for(int j=0;j<3;j++)
		{
			tempVertex[j][0] = vertex[face[i][j]][0];
			tempVertex[j][1] = vertex[face[i][j]][1];
			tempVertex[j][2] = vertex[face[i][j]][2];
		}
		float max[3],min[3];            //记录tempVertex[][]在三个方向的最大值和最小值
		//计算出当前face的边界
		computeFaceBoundingBox(tempVertex,min,max);
		//计算min[]和max[]在grid中对应的cell的三个方向的下标
		int indexMin[3];                //记录min[]在grid中对应的cell的三个方向的下标
		int indexMax[3];                //记录max[]在grid中对应的cell的三个方向的下标
		for(int j=0;j<3;j++)            //分别计算三个方向
		{
			indexMin[j] = computeIndex(edgeLength[j],min[j],minBoundingBox[j]);
			indexMax[j] = computeIndex(edgeLength[j],max[j],minBoundingBox[j]);
		}
		//对indexMin[3]和indexMax[3]进行全方位的考虑,从而计算出第i个面的facePassthroughCell[i][]和facePassthroughCellNum[i]的值
		computeFacePassthroughingCell(i,tempVertex,indexMin,indexMax,cellHalfSize);
	}
	//根据facePassthroughCell[i][]和facePassthroughCellNum[i]的值计算出cellIncludingFace[][]和cellIncludingFaceNum[]的值
	computeCellIncludingFace();
}
Example #15
0
void addLowPassFilterOutput(double *outputRI, double *inputRI, long frequencies, double dfrequency, HILO_FILTER *filter)
{
    long i, i1, i2;
    double fraction, dfraction;

    i1 = computeIndex(filter->start, dfrequency, frequencies);
    i2 = computeIndex(filter->end, dfrequency, frequencies);

    dfraction = i1==i2? 0 : 1./(i2-i1);
    fraction = 1;
    for (i=i1; i<=i2; i++) {
        outputRI[2*i  ] += inputRI[2*i  ]*fraction;
        outputRI[2*i+1] += inputRI[2*i+1]*fraction;
        if ((fraction -= dfraction)<0)
            fraction = 0;
        }
    for (i=0; i<i1; i++) {
        outputRI[2*i  ] += inputRI[2*i  ];
        outputRI[2*i+1] += inputRI[2*i+1];
        }
    }
Example #16
0
int main() 
{
	// Annahme: Alle Strings haben höchstens 10 Buchstaben.
	char text[1];
	while (1) {
		printf("String: ");
		scanf("%s", text);
		unsigned idx = computeIndex(text, 22);
		printf("Index(%s) = %u\n", text, idx);
	}
	return 0;
}
Example #17
0
void BBHandleLayer::createBlocks()
{
    m_texture = TextureCache::sharedTextureCache()->addImage("puzzel.png");
    
    int i = 0;
    for (int r = 1; r <= m_row; r++) {
        for (int c = 1; c <= m_col; c++) {
            auto frame = SpriteFrame::createWithTexture(m_texture, Rect(m_blockLength*(c - 1), m_blockLength*(m_row - r), m_blockLength, m_blockLength));
            auto blockSpt = BBBlockSprite::create("bg_block.png");
            float blockX = m_relativeX + m_blockLength * (c - 1) + blockSpt->getContentSize().width/2;
            float blockY = m_relativeY +m_blockLength * (r - 1) + blockSpt->getContentSize().height/2;
            blockSpt->setPosition(Point(blockX, blockY));
            blockSpt->setOrder(computeIndex(blockX, blockY));
            blockSpt->setTag(computeIndex(blockX, blockY));
            m_blockContainer->addChild(blockSpt);
            
            auto spt = Sprite::createWithSpriteFrame(frame);
            float scaleRate = 129.0 / 130.0;
            spt->setScale(scaleRate, scaleRate);
            spt->setPosition(Point(blockSpt->getContentSize().width/2, blockSpt->getContentSize().height/2));
            blockSpt->addChild(spt);
            
            blockSpt->setCascadeOpacityEnabled(true);
            blockSpt->setOpacity(0);
            
            if (r == m_row && c == m_col) {
                // 最后一个
                blockSpt->runAction(Sequence::create(DelayTime::create(0.05 * i), JumpTo::create(0.3f, Point(blockX, blockY), 30, 1), FadeIn::create(.3), CallFunc::create(CC_CALLBACK_0(BBHandleLayer::beginCountDown, this)), NULL));
            } else {
                blockSpt->runAction(Sequence::create(DelayTime::create(0.05 * i), JumpTo::create(0.3f, Point(blockX, blockY), 30, 1), FadeIn::create(.3), NULL));
            }
            
            m_blockArr->addObject(blockSpt);
            
            i++;
        }
    }
}
Example #18
0
void MarginalCovarianceCholesky::computeCovariance(double** covBlocks, const std::vector<int>& blockIndices)
{
  _map.clear();
  int base = 0;
  vector<MatrixElem> elemsToCompute;
  for (size_t i = 0; i < blockIndices.size(); ++i) {
    int nbase = blockIndices[i];
    int vdim = nbase - base;
    for (int rr = 0; rr < vdim; ++rr)
      for (int cc = rr; cc < vdim; ++cc) {
        int r = _perm ? _perm[rr + base] : rr + base; // apply permutation
        int c = _perm ? _perm[cc + base] : cc + base;
        if (r > c) // make sure it's still upper triangular after applying the permutation
          swap(r, c);
        elemsToCompute.push_back(MatrixElem(r, c));
      }
    base = nbase;
  }

  // sort the elems to reduce the recursive calls
  sort(elemsToCompute.begin(), elemsToCompute.end());

  // compute the inverse elements we need
  for (size_t i = 0; i < elemsToCompute.size(); ++i) {
    const MatrixElem& me = elemsToCompute[i];
    computeEntry(me.r, me.c);
  }

  // set the marginal covariance for the vertices, by writing to the blocks memory
  base = 0;
  for (size_t i = 0; i < blockIndices.size(); ++i) {
    int nbase = blockIndices[i];
    int vdim = nbase - base;
    double* cov = covBlocks[i];
    for (int rr = 0; rr < vdim; ++rr)
      for (int cc = rr; cc < vdim; ++cc) {
        int r = _perm ? _perm[rr + base] : rr + base; // apply permutation
        int c = _perm ? _perm[cc + base] : cc + base;
        if (r > c) // upper triangle
          swap(r, c);
        int idx = computeIndex(r, c);
        LookupMap::const_iterator foundIt = _map.find(idx);
        assert(foundIt != _map.end());
        cov[rr*vdim + cc] = foundIt->second;
        if (rr != cc)
          cov[cc*vdim + rr] = foundIt->second;
      }
    base = nbase;
  }
}
Example #19
0
void Resizer::computeVertexInCell()
{
	int vertexN = polyMesh->getVertexN();
	vertexInCell = new int *[vertexN];
	for(int i=0;i<vertexN;i++)
		vertexInCell[i] = new int[2];
	//得到每个顶点的3维坐标
	float (*vertex)[3] = polyMesh->vertex;
	for(int i=0;i<vertexN;i++)
	{
		//X方向的下标
		int xx = computeIndex(edgeLength[0],vertex[i][0],minBoundingBox[0]);
		int yy = computeIndex(edgeLength[1],vertex[i][1],minBoundingBox[1]);
		int zz = computeIndex(edgeLength[2],vertex[i][2],minBoundingBox[2]);
		vertexInCell[i][0] = computeCellIndex(xx,yy,zz);        //CELLNUM
		vertexInCell[i][1] = computeCellIndex1(xx,yy,zz);       //CELLNUM+1
		if(xx < 0 || yy < 0 || zz < 0)
		{
			printf("Something is error!\n");
			return;
		}
	}
}
Example #20
0
    void lookup ( K key, CF f ) {
      uint64_t index = computeIndex( key );
      GlobalAddress< Cell > target = base + index; 

      // FIXME: remove 'this' capture when using gcc4.8, this is just a bug in 4.7
      //TODO optimization where only need to do remotePrivateTask instead of call_async
      //if you are going to do more suspending ops (comms) inside the loop
      Grappa::spawnRemote<GCE>( target.core(), [key, target, f, this]() {
        Entry e;
        if (lookup_local( key, target.pointer(), &e)) {
          f(e.value);
        }
      });
    }
bool ExtractValueInstrumenter::CheckAndInstrument(Instruction* inst) { 
  ExtractValueInst* evInst = dyn_cast<ExtractValueInst>(inst); 

  if (evInst == NULL) {
    return false;
  }

  safe_assert(parent_ != NULL);

  count_++;

  InstrPtrVector instrs;

  Constant* iidC = IID_CONSTANT(evInst);

  Constant* inxC = computeIndex(evInst);

  Value* aggOp = evInst->getAggregateOperand();

  Constant* aggOpInxC = computeIndex(aggOp);

  KVALUE_STRUCTVALUE(aggOp, instrs);

  for (ExtractValueInst::idx_iterator idx = evInst->idx_begin(); idx != evInst->idx_end(); idx++) {
    Constant* idxOp = INT32_CONSTANT(*idx, UNSIGNED);
    Instruction* call = CALL_INT("llvm_push_getelementptr_inx2", idxOp);
    instrs.push_back(call);
  } 

  Instruction* call = CALL_IID_INT_INT("llvm_extractvalue", iidC, inxC, aggOpInxC);

  instrs.push_back(call);

  InsertAllBefore(instrs, evInst);

  return true;
}
Example #22
0
 // Inserts the key if not already in the set
 //
 // returns true if the set already contains the key
 //
 // synchronous operation
 void insert( K key ) {
   ++hashset_insert_ops;
   if (FLAGS_flat_combining) {
     proxy.combine([key](Proxy& p){ p.insert(key); return FCStatus::BLOCKED; });
   } else {
     ++hashset_insert_msgs;
     delegate::call(base+computeIndex(key), [key](Cell * c) {
       // find matching key in the list, if found, no insert necessary
       for (auto& e : c->entries) if (e.key == key) return;
       
       // this is the first time the key has been seen so add it to the list
       c->entries.emplace_back( key );
       return;
     });
   }
 }
Example #23
0
AmbisonicRotate::AmbisonicRotate(long anOrder, long aVectorSize)
{
	m_order					= Tools::clip_min(anOrder, (long)1);
	m_number_of_harmonics	= 2 * m_order + 1;
	m_number_of_inputs		= m_number_of_harmonics + 1;
	m_number_of_outputs		= m_number_of_harmonics;
	
	m_harmonicCos = new double[m_order];
	m_harmonicSin = new double[m_order];
	computeIndex();
	m_cosLookUp = new double[NUMBEROFCIRCLEPOINTS];
	m_sinLookUp = new double[NUMBEROFCIRCLEPOINTS];
	
	for (int i = 0; i < NUMBEROFCIRCLEPOINTS; i++) 
	{
		m_cosLookUp[i] = cos((double)i * CICM_2PI / (double)NUMBEROFCIRCLEPOINTS);
		m_sinLookUp[i] = sin((double)i * CICM_2PI / (double)NUMBEROFCIRCLEPOINTS);
	}
	setAzimuth(0.);
	setVectorSize(aVectorSize);
}
Example #24
0
    bool lookup ( K key, V * val ) {          
      uint64_t index = computeIndex( key );
      GlobalAddress< Cell > target = base + index; 

      // FIXME: remove 'this' capture when using gcc4.8, this is just a bug in 4.7
      lookup_result result = Grappa::delegate::call( target.core(), [key,target,this]() {

        DHT_TYPE(lookup_result) lr;

        Entry e;
        if (lookup_local( key, target.pointer(), &e)) {
          lr.valid = true;
          lr.result = e.value;
        }

        return lr;
      });

      *val = result.result;
      return result.valid;
    } 
bool SelectInstrumenter::CheckAndInstrument(Instruction* inst) {
  SelectInst* selectInst = dyn_cast<SelectInst>(inst);

  if (selectInst != NULL) {

    safe_assert(parent_ != NULL);

    count_++;

    InstrPtrVector instrs;

    Constant* iidC = IID_CONSTANT(selectInst);

    Constant* inxC = computeIndex(selectInst);

    Value* condition = KVALUE_VALUE(selectInst->getCondition(), instrs, NOSIGN);
    if(condition == NULL) return false;

    Value* tvalue = KVALUE_VALUE(selectInst->getTrueValue(), instrs, NOSIGN);
    if(tvalue == NULL) return false;
    
    Value* fvalue = KVALUE_VALUE(selectInst->getFalseValue(), instrs, NOSIGN);
    if(fvalue == NULL) return false;
    
    Instruction* call = CALL_IID_KVALUE_KVALUE_KVALUE_INT("llvm_select", iidC, condition, tvalue, fvalue, inxC);
    
    instrs.push_back(call);

    // instrument
    InsertAllBefore(instrs, selectInst);

    return true;
  } 

  return false;
}
Example #26
0
// x,y: pixel position on the screen
void rayCasting::castRay(int x, int y){
	glm::vec4 rayDir = getRay(x,y);
    glm::vec4 destColor = glm::vec4(0.0);
	
	float tmin, tmax;
	if (intersect(rayDir,tmin, tmax) == true){
		glm::vec4 pos = eye + tmin*rayDir;

		int index[3], indices[8], indexLow[3], indexHigh[3];
		float offset[3], distToCellCenter[3];
		getVolumePosition(index,offset, pos);

        indexLow[0] = index[0];     indexLow[1] = index[1];     indexLow[2] = index[2];
        indexHigh[0] = index[0];    indexHigh[1] = index[1];    indexHigh[2] = index[2];

		if (pos.x < 0.5){
        	indexLow[0] = indexLow[0]-1;
            distToCellCenter[0] = 0.5 + pos.x;
		}else{
            indexHigh[0] = indexHigh[0]+1;
            distToCellCenter[0] = pos.x - 0.5;
        }
        
        if (pos.y < 0.5){
            indexLow[1] = indexLow[1]-1;
            distToCellCenter[1] = 0.5 + pos.y;
        }else{
            indexHigh[1] = indexHigh[1]+1;
            distToCellCenter[1] = pos.y - 0.5;
        }

        if (pos.z < 0.5){
            indexLow[2] = indexLow[2]-1;
            distToCellCenter[1] = 0.5 + pos.z;
        }else{
            indexHigh[2] = indexHigh[2]+1;
            distToCellCenter[1] = pos.z - 0.5;
        }
        
        // Compute indices
        indices[0] = computeIndex(logicalBounds,indexLow[0] ,indexLow[1] ,indexLow[2]);
        indices[1] = computeIndex(logicalBounds,indexHigh[0],indexLow[1] ,indexLow[2]);
        indices[2] = computeIndex(logicalBounds,indexLow[0] ,indexHigh[1],indexLow[2]);
        indices[3] = computeIndex(logicalBounds,indexHigh[0],indexHigh[1],indexLow[2]);

        indices[4] = computeIndex(logicalBounds,indexLow[0] ,indexLow[1] ,indexHigh[2]);
        indices[5] = computeIndex(logicalBounds,indexHigh[0],indexLow[1] ,indexHigh[2]);
        indices[6] = computeIndex(logicalBounds,indexLow[0] ,indexHigh[1],indexHigh[2]);
        indices[7] = computeIndex(logicalBounds,indexHigh[0],indexHigh[1],indexHigh[2]);

        // Get the scalar values of the 8 surrounding cells
        float scalarValues[8];
        assignEight(scalarValues, indices);
        float scalar = trilinearInterpolate(scalarValues, 1.0-distToCellCenter[0], 1.0-distToCellCenter[1], 1.0-distToCellCenter[2]);

        // Get the color for that scalar value
        glm::vec4 srcColor = glm::vec4(0.0);
        QueryTF(scalar, srcColor);

        // lighting
        glm::vec3 gradient = glm::vec3(0.0);
        
        // compute gradient
        destColor = colorScalar(gradient, rayDir.xyz(), srcColor, destColor);
	}
}
Example #27
0
    static void
bevalCB(
	BalloonEval	*beval,
	int		 state)
{
    char_u	*filename;
    char_u	*text;
    int		 type;
    int		 line;
    int		 col;
    int		 idx;
    char	 buf[MAXPATHLEN * 2];
    static int	 serialNo = -1;

    if (!p_beval)
	return;

    if (gui_mch_get_beval_info(beval, &filename, &line, &text, &col) == OK)
    {
	if (text && text[0])
	{
	    /* Send debugger request */
	    if (strlen((char *) text) > (MAXPATHLEN/2))
	    {
		/*
		 * The user has probably selected the entire
		 * buffer or something like that - don't attempt
		 * to evaluate it
		 */
		return;
	    }

	    /*
	     * WorkShop expects the col to be a character index, not
	     * a column number. Compute the index from col. Also set
	     * line to 0 because thats what dbx expects.
	     */
	    idx = computeIndex(col, text, beval->ts);
	    if (idx > 0)
	    {
		line = 0;

		/*
		 * If successful, it will respond with a balloon cmd.
		 */
		if (state & ControlMask)
		    /* Evaluate *(expression) */
		    type = (int)GPLineEval_INDIRECT;
		else if (state & ShiftMask)
		    /* Evaluate type(expression) */
		    type = (int)GPLineEval_TYPE;
		else
		    /* Evaluate value(expression) */
		    type = (int)GPLineEval_EVALUATE;

		/* Send request to dbx */
		sprintf(buf, "toolVerb debug.balloonEval "
			"%s %d,0 %d,0 %d,%d %d %s\n", (char *) filename,
			line, idx, type, serialNo++,
			strlen((char *) text), (char *) text);
		balloonEval = beval;
		workshop_send_message(buf);
	    }
	}
    }
}
Example #28
0
void SplineBase::computeIndex(float s, int& i, float& u) const {
    int N = time.size();
    debugAssertM(N > 0, "No control points");
    float t0 = time[0];
    float tn = time[N - 1];
    
    if (N < 2) {
        // No control points to work with
        i = 0;
        u = 0.0;
    } else if (cyclic) {
        float fi = getFinalInterval();
        
        // Cyclic spline
        if ((s < t0) || (s >= tn + fi)) {
            // Cyclic, off the bottom or top
            
            // Compute offset and reduce to the in-bounds case

            float d = duration();
            // Number of times we wrapped around the cyclic array
            int wraps = iFloor((s - t0) / d);
            
            debugAssert(s - d * wraps >= t0);
            debugAssert(s - d * wraps < tn + getFinalInterval());

            computeIndex(s - d * wraps, i, u);
            i += wraps * N;
            
        } else if (s >= tn) {
            debugAssert(s < tn + fi);
            // Cyclic, off the top but before the end of the last interval
            i = N - 1;
            u = (s - tn) / fi;
            
        } else {
            // Cyclic, in bounds
            computeIndexInBounds(s, i, u);
        }
        
    } else {
        // Non-cyclic
        
        if (s < t0) {
            // Non-cyclic, off the bottom.  Assume points are spaced
            // following the first time interval.
            
            float dt = time[1] - t0;
            float x = (s - t0) / dt;
            i = iFloor(x);
            u = x - i;
            
        } else if (s >= tn) {
            // Non-cyclic, off the top.  Assume points are spaced following
            // the last time interval.
            
            float dt = tn - time[N - 2];
            float x = N - 1 + (s - tn) / dt;
            i = iFloor(x);
            u = x - i;  
            
        } else {
            // In bounds, non-cyclic.  Assume a regular
            // distribution (which gives O(1) for uniform spacing)
            // and then binary search to handle the general case
            // efficiently.
            computeIndexInBounds(s, i, u);
            
        } // if in bounds
    } // if cyclic
}
//-----------------------------------------------------------------------------
void ParticleHashGrid::AddParticlePosition (const Wm5::Vector3f& position) 
{
    Wm5::Tuple<3, int> coordinate = computeCoordinate(position);
    unsigned int index = computeIndex(coordinate);
    mHashGrid[index].insert(position);
}
Example #30
0
void MarginalCovarianceCholesky::computeCovariance(SparseBlockMatrix<MatrixXD>& spinv, const std::vector<int>& rowBlockIndices, const std::vector< std::pair<int, int> >& blockIndices)
{
  // allocate the sparse
  spinv = SparseBlockMatrix<MatrixXD>(&rowBlockIndices[0], 
              &rowBlockIndices[0], 
              rowBlockIndices.size(),
              rowBlockIndices.size(), true);
  _map.clear();
  vector<MatrixElem> elemsToCompute;
  for (size_t i = 0; i < blockIndices.size(); ++i) {
    int blockRow=blockIndices[i].first;    
    int blockCol=blockIndices[i].second;
    assert(blockRow>=0);
    assert(blockRow < (int)rowBlockIndices.size());
    assert(blockCol>=0);
    assert(blockCol < (int)rowBlockIndices.size());

    int rowBase=spinv.rowBaseOfBlock(blockRow);
    int colBase=spinv.colBaseOfBlock(blockCol);
    
    MatrixXD *block=spinv.block(blockRow, blockCol, true);
    assert(block);
    for (int iRow=0; iRow<block->rows(); ++iRow)
      for (int iCol=0; iCol<block->cols(); ++iCol){
        int rr=rowBase+iRow;
        int cc=colBase+iCol;
        int r = _perm ? _perm[rr] : rr; // apply permutation
        int c = _perm ? _perm[cc] : cc;
        if (r > c)
          swap(r, c);
        elemsToCompute.push_back(MatrixElem(r, c));
      }
  }

  // sort the elems to reduce the number of recursive calls
  sort(elemsToCompute.begin(), elemsToCompute.end());

  // compute the inverse elements we need
  for (size_t i = 0; i < elemsToCompute.size(); ++i) {
    const MatrixElem& me = elemsToCompute[i];
    computeEntry(me.r, me.c);
  }

  // set the marginal covariance 
  for (size_t i = 0; i < blockIndices.size(); ++i) {
    int blockRow=blockIndices[i].first;    
    int blockCol=blockIndices[i].second;
    int rowBase=spinv.rowBaseOfBlock(blockRow);
    int colBase=spinv.colBaseOfBlock(blockCol);
    
    MatrixXD *block=spinv.block(blockRow, blockCol);
    assert(block);
    for (int iRow=0; iRow<block->rows(); ++iRow)
      for (int iCol=0; iCol<block->cols(); ++iCol){
        int rr=rowBase+iRow;
        int cc=colBase+iCol;
        int r = _perm ? _perm[rr] : rr; // apply permutation
        int c = _perm ? _perm[cc] : cc;
        if (r > c)
          swap(r, c);
        int idx = computeIndex(r, c);
        LookupMap::const_iterator foundIt = _map.find(idx);
        assert(foundIt != _map.end());
        (*block)(iRow, iCol) = foundIt->second;
      }
  }
}