예제 #1
0
void *VMMemory::getArrayData(unsigned dstocEntry)
{
	if (dstocEntry >= programData->getDSTOCCount()) throw std::range_error("Not a DSTOC entry");
	
	int32_t dopeVector = getScalarValue(dstocEntry);
	
	return arrays[dopeVector];
}
예제 #2
0
double PvaClientPutData::getDouble()
{
    PVScalarPtr pvScalar = getScalarValue();
    ScalarType scalarType = pvScalar->getScalar()->getScalarType();
    if(scalarType==pvDouble) {
        PVDoublePtr pvDouble = static_pointer_cast<PVDouble>(pvScalar);
        return pvDouble->get();
    }
    if(!ScalarTypeFunc::isNumeric(scalarType)) {
        throw std::runtime_error(messagePrefix  + notCompatibleScalar);
    }
    return convert->toDouble(pvScalar);
}
예제 #3
0
void VMMemory::setArrayLength(unsigned dstocEntry, unsigned newLength)
{
	if (dstocEntry >= programData->getDSTOCCount()) throw std::range_error("Not a DSTOC entry");
	
	int32_t dopeVector = getScalarValue(dstocEntry);
	
	// Bail if the array size does not need to be changed.
	if (newLength == SwapU16LittleToHost(dopeVectors[dopeVector].elementCount)) return;
	
	unsigned newByteLength = newLength * SwapU16LittleToHost(dopeVectors[dopeVector].elementSize);
	arrays[dopeVector] = reinterpret_cast<char *>(realloc(arrays[dopeVector], newByteLength));
	dopeVectors[dopeVector].elementCount = SwapU16HostToLittle(newLength);
}
예제 #4
0
int32_t VMMemory::getArrayElement(unsigned arrayDSTOC, unsigned arrayIndex)
{
	if (arrayDSTOC >= programData->getDSTOCCount()) throw std::range_error("Not a DSTOC entry");
	
	// Check element type.
	RXEFile::dstocType elementType = programData->getTypeAtDSTOCIndex(arrayDSTOC + 1);
	if (elementType == RXEFile::TC_VOID || elementType == RXEFile::TC_CLUSTER) return -1;

	// Get dope vector
	int32_t dopeVector = getScalarValue(arrayDSTOC);
	if (arrayIndex >= SwapU16LittleToHost(dopeVectors[dopeVector].elementCount)) throw std::range_error("Array element not in range");
	
	// Get size of an element.
	unsigned size = SwapU16LittleToHost(dopeVectors[dopeVector].elementSize);
	
	return getScalar(elementType, &(arrays[dopeVector][size*arrayIndex]));
}
예제 #5
0
void VMMemory::setArrayElement(unsigned dstocEntry, unsigned arrayIndex, int32_t newValue)
{
	if (dstocEntry >= programData->getDSTOCCount()) throw std::range_error("Not a DSTOC entry");
	
	// Get element type (which is the DSTOC field right after the one for the
	// array)
	RXEFile::dstocType elementType = programData->getTypeAtDSTOCIndex(dstocEntry + 1);
	
	// Get dope vector
	int32_t dopeVector = getScalarValue(dstocEntry);
	if (arrayIndex >= SwapU16LittleToHost(dopeVectors[dopeVector].elementCount)) throw std::range_error("Array element not in range");
	
	// Get size of an element.
	unsigned size = SwapU16LittleToHost(dopeVectors[dopeVector].elementSize);
	
	// Set element
	setScalar(elementType, &(arrays[dopeVector][size*arrayIndex]), newValue);
}
예제 #6
0
bool isDictScalar(ExpressionPtr exp) {
  if (!exp) return true;
  assertx(exp->is(Expression::KindOfExpressionList));

  auto list = static_pointer_cast<ExpressionList>(exp);
  assertx(list->getListKind() == ExpressionList::ListKindParam);

  for (int i = 0; i < list->getCount(); ++i) {
    auto& itemExp = (*list)[i];
    if (!itemExp) continue;
    assertx(itemExp->is(Expression::KindOfArrayPairExpression));

    auto pair = static_pointer_cast<ArrayPairExpression>(itemExp);
    auto name = pair->getName();

    Variant val;
    if (!name || !name->getScalarValue(val)) return false;
    if (!val.isString() && !val.isInteger()) return false;
  }
  return true;
}
예제 #7
0
double PViewDataList::getMax(int step, bool onlyVisible, int tensorRep,
                             int forceNumComponents, int componentMap[9])
{
  if(step >= (int)TimeStepMax.size()) return Max;

  if(forceNumComponents || tensorRep) {
    double vmax = -VAL_INF;
    for(int ent = 0; ent < getNumEntities(step); ent++) {
      for(int ele = 0; ele < getNumElements(step, ent); ele++) {
        for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++) {
          double val;
          getScalarValue(step, ent, ele, nod, val, tensorRep,
                         forceNumComponents, componentMap);
          vmax = std::max(vmax, val);
        }
      }
    }
    return vmax;
  }

  if(step < 0) return Max;
  return TimeStepMax[step];
}
예제 #8
0
double tele2d::get_penalty(std::vector<double2> samples, int endp1, int endp2 ){

	int i = endp1 ;
	int j = endp2;
	
	// reduce samples to make the sampling step equal to 1.0/resolution
	std::vector<double2> reduced_samples ;
	reduced_samples.push_back( samples[0] ) ;
	double length = 0;
	for( int id=1; id<samples.size(); ++id){
		length += ( samples[id] - samples[id-1] ).norm() ;
		if( length > 0.25 / resolution ){
			reduced_samples.push_back( samples[id] ) ;
			length = 0;
		}

	}


	double penalty  =  0;
	for( int id=1; id<reduced_samples.size(); ++id){
		// get x index of nearest vertex
		double x = reduced_samples[id].x * resolution - 0.5 ;
		int ix ;
		if( x-floor(x) < 0.5 ) ix = floor(x) ;
		else	ix = ceil( x ) ;
		// get y index of nearest vertex
		double y = reduced_samples[id].y * resolution - 0.5 ;
		int iy ;
		if( y-floor(y) < 0.5 ) iy = floor(y) ;
		else	iy = ceil( y ) ;

		/*
		// if any points in a curve are out of boundaries, return a large penaty value 
		if( ix > resolution-1) return 2.0 ;
		if( iy > resolution-1) return 2.0;
		if( ix < 0 ) return 2.0 ;
		if( iy < 0 ) return 2.0 ;
		*/

		if( ix>resolution-1 || iy > resolution-1 || ix < 0 || iy < 0){
			penalty+=2 ;
			continue;
		}

		// if the nearest vertex is a constrained vertex, then the penelty is Overlap_Penalty
		if( constrained_vertices_mark[ix][iy]  && 0){
			penalty += Overlap_Penalty ;
		}
		else{
			// get the direction vector of the nearest vertex
			double2 vec = vector_field[ ix + iy * resolution] ;

			// compute the direction vector of current sample
			double2 dir = reduced_samples[id] - reduced_samples[id-1] ;

			// compute penalty of this sample
			double costheta = (dir * vec) *(   1/(dir.norm()*vec.norm())   ) ;
			
			//std::cout << "costheta = " << costheta <<std::endl;

			if( costheta > 1 ){

				;
			}
			assert(1 - costheta*costheta >= 0 && 1 - costheta*costheta <= 1) ;

			//penalty += sqrt( 1 - costheta*costheta) ;
			penalty += 1 - costheta;



		}

		double2 c1 = osculatingCircles[ i ].first ;
		double2 c2 = osculatingCircles[ j ].first ;

		double r1 = osculatingCircles[ i ].second ;
		double r2 = osculatingCircles[ j ].second ;


		penalty += (1 - getScalarValue( osculatingCircles , correspondence,  reduced_samples[id] ))  * scalar_weight;

	}
	penalty /= reduced_samples.size() ;




	return penalty ;
}
예제 #9
0
unsigned VMMemory::getArrayLength(unsigned dstocEntry) const
{
	if (dstocEntry >= programData->getDSTOCCount()) throw std::range_error("Not a DSTOC entry");
	
	return SwapU16LittleToHost(dopeVectors[getScalarValue(dstocEntry)].elementCount);
}
예제 #10
0
void PvaClientPutData::putString(std::string const & value)
{
    PVScalarPtr pvScalar = getScalarValue();
    convert->fromString(pvScalar,value);
}
예제 #11
0
string PvaClientPutData::getString()
{
    PVScalarPtr pvScalar = getScalarValue();
    return convert->toString(pvScalar);
}